Code:
;NES Programming Tutorial
;Level 2 : iNES Header
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;iNES header data (16bytes)
;32KB PRG + 8KB CHR + NROM-256 + Vertical Mirroring
.db $4E,$45,$53,$1A,$02,$01,$01,$00
.db $00,$00,$00,$00,$00,$00,$00,$00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;PRG codes $8000 ~ $FFFF (32KB)
.base $8000
;user codes
.pad $10000,$FF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;CHR data $0000 ~ $1FFF (8KB)
.base $0000
;graphic data
.pad $2000,$FF
;Level 2 : iNES Header
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;iNES header data (16bytes)
;32KB PRG + 8KB CHR + NROM-256 + Vertical Mirroring
.db $4E,$45,$53,$1A,$02,$01,$01,$00
.db $00,$00,$00,$00,$00,$00,$00,$00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;PRG codes $8000 ~ $FFFF (32KB)
.base $8000
;user codes
.pad $10000,$FF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;CHR data $0000 ~ $1FFF (8KB)
.base $0000
;graphic data
.pad $2000,$FF
Explanation :
* The first 16KB of a nes game is header info which is used just by emulators to run the game. It gives information about PRG size, CHR size, Mapper number, Mirroring, etc.
* I setup the header to : 32KB PRG + 8KB CHR + NROM-256 + Vertical Mirroring.
* Need more info about iNES header? then read this : INES
* lines starting with . are directive commands of assembler
* .db puts a value in the file directly.
* .base $8000 is another directive command. It tells the assembler that the following commands will be loaded into $8000 of CPU. So labels addresses are adjusted according to $8000
* .pad $10000,$FF is another directive command. It fills the remaining empty space of memory up to $10000 with the value of #$FF
* We need an assembler (ASM6) to convert the source code of assembly language (Game.asm) to object code of machine language (Game.nes) so that you can run it on Emulator
/////////////////////////////////////////////////////////////////////////////////////////////////
How to use ASM6 :
* Download ASM6
* Make a new text file
* Write this inside of it :
Code:
ASM6 Game.asm Game.nes
pause
pause
* Save it with this name : Assembler.bat
* Make sure these files are in the same folder :
Code:
asm6.exe
Assembler.bat
Game.asm
Assembler.bat
Game.asm
* Run Assembler.bat to make your FIRST NES GAME!
/////////////////////////////////////////////////////////////////////////////////////////////////
How to use Hex Editor :
* Sometimes we need to see the exact values of 0 and 1 inside of a file (object code of machine language), so we use a Hex Editor program like HxD
* Download HxD
* Open Game.NES with HxD
* You can see the header data on the first line, they should match to the values which you used inside of the Game.asm
* Note that values are in Hexadecimal system
* Each value is one byte
* Each byte has it's own address
* Their address starts from zero, so first byte is in the $0 address second byte is in the $01 address, and so on
/////////////////////////////////////////////////////////////////////////////////////////////////
Exercise :
Find out which byte of iNES data controls Mirroring and then set it to Horizontal (Vertical Arrangement).
/////////////////////////////////////////////////////////////////////////////////////////////////
Files :
asm6.exe
Assembler.bat
Game.asm
/////////////////////////////////////////////////////////////////////////////////////////////////
Former Level : NES Programming Tutorial : Source Code Structure
Next Level : NES Programming Tutorial : Interrupts