I wanted to get some of this straight and list all the essential things that will probably be common to every NES program. There's a lot of good information at nesdev about the 6502 and the NES in particular, but not a lot of practical data for new programs from what I've seen. This forum is the best place for practical info but sometimes it takes some digging!
Anyway, if you want to get picky I'm sure that not all of these things are absolutely necessary, but what I'm looking for is stuff that makes good sense in most situations, such that you could make a pretty good shell of a program from it. A starting template. This is all going to be obvious to the regulars but I thought it might be helpful to lay it out for myself and for others starting out.
- First off you're going to want to use the reset interrupt to initialize everything. The wiki includes good init code for this. This includes ignoring IRQs, disabling decimal mode, waiting two vblanks, resetting the stack pointer, and resetting all RAM to 0.
- You will want to initialize your graphics, input and sound in some way; this depends on the type of program but you may as well set up the jsrs and labels. Don't forget to turn off the display and disable VBLANK before that first write.
- Similarly you'll have subroutines in a main loop for graphics, input and sound. The main loop will be set up to repeat infinitely.
- At the end of your PRG-ROM, pad out to $FFFA and store the pointers to vblank, reset and irq.
- Include your CHR-ROM seperately after PRG-ROM, and make sure you have a standard iNES header.
- You will want to declare at least two general use temporary variables on the zero page. Additionally you'll probably want an additional two bytes for a temporary address to use as a pointer. This is the bare minimum.
- NMI will probably be used in some way. Have an incrementing variable for timekeeping, and if you plan to do anything with the registers, set up three extra temp bytes on the zero page for backing them up.
- You will want a whole page of RAM for DMA sprite transfer. Might as well make this page $0200. Initialize every byte to $FF to make sure nothing is visible.
- A system for dealing with more than 8 sprites per scanline is not manditory but probable, so consider how you will accomplish this.
- Your input handler will probably not deal with each key "on the fly." Declare a variable to store the state of every button and another to store the previous state of every button. In your handler, strobe the joypad and read the data out into your variable, then deal with each button from there.
- This is more general, but it is good game coding practice to have an object system for organizing your sprites and their movement logic. Height and width in tiles and which tiles to use will be needed for defining objects. X and Y position, velocity, and a number of flags are some of the standard bits of information you will need for active instances of those objects.
Did I get any of that wrong? Did I miss anything that should be common to most programs? Something might be said of nametables and pattern tables, and there is more general info that you could include depending on if the game is a platformer, uses scrolling etc.
Just looking for good, time-saving general advice.
Anyway, if you want to get picky I'm sure that not all of these things are absolutely necessary, but what I'm looking for is stuff that makes good sense in most situations, such that you could make a pretty good shell of a program from it. A starting template. This is all going to be obvious to the regulars but I thought it might be helpful to lay it out for myself and for others starting out.
- First off you're going to want to use the reset interrupt to initialize everything. The wiki includes good init code for this. This includes ignoring IRQs, disabling decimal mode, waiting two vblanks, resetting the stack pointer, and resetting all RAM to 0.
- You will want to initialize your graphics, input and sound in some way; this depends on the type of program but you may as well set up the jsrs and labels. Don't forget to turn off the display and disable VBLANK before that first write.
- Similarly you'll have subroutines in a main loop for graphics, input and sound. The main loop will be set up to repeat infinitely.
- At the end of your PRG-ROM, pad out to $FFFA and store the pointers to vblank, reset and irq.
- Include your CHR-ROM seperately after PRG-ROM, and make sure you have a standard iNES header.
- You will want to declare at least two general use temporary variables on the zero page. Additionally you'll probably want an additional two bytes for a temporary address to use as a pointer. This is the bare minimum.
- NMI will probably be used in some way. Have an incrementing variable for timekeeping, and if you plan to do anything with the registers, set up three extra temp bytes on the zero page for backing them up.
- You will want a whole page of RAM for DMA sprite transfer. Might as well make this page $0200. Initialize every byte to $FF to make sure nothing is visible.
- A system for dealing with more than 8 sprites per scanline is not manditory but probable, so consider how you will accomplish this.
- Your input handler will probably not deal with each key "on the fly." Declare a variable to store the state of every button and another to store the previous state of every button. In your handler, strobe the joypad and read the data out into your variable, then deal with each button from there.
- This is more general, but it is good game coding practice to have an object system for organizing your sprites and their movement logic. Height and width in tiles and which tiles to use will be needed for defining objects. X and Y position, velocity, and a number of flags are some of the standard bits of information you will need for active instances of those objects.
Did I get any of that wrong? Did I miss anything that should be common to most programs? Something might be said of nametables and pattern tables, and there is more general info that you could include depending on if the game is a platformer, uses scrolling etc.
Just looking for good, time-saving general advice.