In this post we are going to explore the structure that you need to build to create a NES assembly file to run on the console. It’s extremely important to note that indentation is crucial. The assembler will not recognise the code unless the indentation is correct.
- All labels start right at the beginning of the line and everything gets tabbed in once
This may sound fairly finicky, but it will help with readability and understanding of code. This is essential with larger programs.
These types of banks don’t hold your money. Instead they hold your program and all it’s data. There are three banks that we will use, these are:
- Bank 0 – where our code goes starting at memory address $8000
- Bank 1 – An interrupt table, this generally starts at FFFA
- Bank 2 – Where we place our Sprite and Background data, starting at $0000
We use the .bank instruction to move banks and we use .org to tell the assembler where we are starting from in that bank.
The INES Header
The INES Header comes at the beginning of every ROM file and tells the emulator several things:
- inesprg – how many program code banks there are
- ineschr – how many picture data banks there are
- inesmir – the VRAM mirroring of the banks
- inesmap – This is the mapper specification, generally we use 0 for this.
Our typical settings for this are:
These four lines will almost always be at the beginning of every code file.
Bank 0 and .ORGing
We will use Bank 0 to hold our code and start it at location $8000. Here’s how we will do it:
Bank 1 and the 3 Interrupts
This is how we set up Bank 1 – 3 and the interrupts:
Bank 2 and the Picture Data
Bank 2 will be starting at $0000 and in it we will include our picture data for backgrounds and sprites:
For this code example imagine we have background picture called ‘our.bkg’ and a sprite called ‘our.spr’.