Well, you white-belt NES programer you, today we're going to learn the structure a NESASM code file. Unfortunately, our assembler is very finicky about the indentation of our code. All labels start right at the begining of a line and everything else gets tabbed in once. Even though this may sound bad, it really helps with readability and understanding of the code, especially in big programs.
No, banks don't hold your money for you. They hold your program and all it's data. There are 3 banks that we will typically use, they are:
I'm not sure how many banks there are, but it's obvious there's atleast 3. We will use the .bank instruction to move banks. And we'll use .org to tell the assembler where we are starting from in that bank.
The INES header comes at the beginning of every ROM file and tells the emulator several things. The header pieces are:
Our typical settings for these are:
.inesprg 1 ; one (1) bank of program code .ineschr 1 ; one (1) bank of picture data .inesmap 0 ; we use mapper 0 .inesmir 1 ; Mirror setting always 1.
Those four (4) lines will be at the (almost) very beginning of EVERY code file.
We will use Bank 0 to hold our code and start it at location $8000. Here's how we'll do it:
.bank 0 ; bank 0. .org $8000 ; goto location $8000. ; program's code would go here.
That's all there is to that. Note that a semi-colon (;) means comment and the assembler ignores anything past the semi-colon on the line.
Instead of a long paragraph, how 'bout some yummy code:
.bank 1 ; change to bank 1 .org $FFFA ; start at $FFFA .dw 0 ; location of NMI Interrupt .dw Start ; code to run at reset, we give address of Start label that ; we will eventually put in bank 0 .dw 0 ; location of VBlank Interrupt I think. either way, we don't need ; it right now.
Wasn't that easy, that's ALL that goes in bank 1, simple!
Bank 2, we will be starting at $0000 and in it we will include our picture data for backgrounds and sprites. Here goes:
.bank 2 ; change to bank 2 .org $0000 ; start at $0000 .incbin "our.bkg" ; INClude BINary file that will contain our background pic ; data. .incbin "our.spr" ; INClude BINary file that will contain our sprite pic data
That's really all for today. I gotta go slow, as the NES is slightly more a pain in the @$$ to program for than the GBA. Tomorrow, we will find out somemore stuff.
See ya tomorrow!,
-Mike H a.k.a GbaGuy