This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

MAIN loop in an nes assembler program?

MAIN loop in an nes assembler program?
by on (#55206)
I have writte quite a few of my own nes programs. But I have used ready made skeleton programs and most of the processing I do at the moment is inside the controller input handling section of the code(and that is too unstructured).

In High level programming languages the program execution is controlled\started from a function called "main".

My question is : In a 6502 program for NES where exactly does execution start from? Where is the main loop located(or a similar infinite loop) ?

For Instance the answer to this question will let me decide where to place my collision detection code in my program.


by on (#55207)
It's based on wherever the reset vector points to.

by on (#55208)
More specifically, the address that you put in starting at $FFFC will be the first place the CPU goes. $FFFC is at the very end of PRG-ROM and probably one of the last things you'll find in one of your program skeletons. You could theoretically put any address there, from $0000 to $FFFF, and the CPU will begin executing whatever assembly instructions it finds there.

Of course, a majority of those locations are probably not code you want to execute. Most people will use an address somewhere after $C000, which is typically the last block of PRG-ROM and a safe, non-bankswitched area for programming. And the address is usually signified by a "reset" label:
.org $C000


<insert startup code and programs here>

.pad $FFFA
.dw vblank,reset,irq