DEV Community

Cover image for Writing a Nes Game Day 3 -starting with the code
Draculinio
Draculinio

Posted on

Writing a Nes Game Day 3 -starting with the code

While looking at all the information that I gathered I saw this video with a great example.

If we look at the Nerdy Nights tutorial, week 1 and week 2 are an explanation on how the NES system works and it is a must to understand what we are going to do.
Starting from week 3 we start to code BUT, in the tutorial, they are using nesasm to assemble, but I will use C65 so for the sample code I have to go to James Sheppard github page

For the next days let's focus on week 3 code. I will be copying the code with some comments that I get from the tutorial, Michael Chiaramonte's video and nesdev wiki

The first part of the code is the **header **and it is written simply to tell the emulator that this is a NES game and give some parameters, so if in the future I make this for a cartridge this can be removed.

.segment "HEADER" ; Setting up the header, needed for emulators to understand what to do with the file, not needed for actual cartridges
.byte "NES" ; The beginning of the HEADER of iNES header
.byte $1a ; Signature of iNES header that the emulator will look for
.byte $02 ; 4 2 * 16KB PRG (program) ROM
.byte $01 ; 5 8KB CHR ROM
.byte %00000000 ; 6 mapper
.byte $0 ; 7
.byte $0 ; 8
.byte $0 ; 9 TV System 0-NTSC / 1-PAL
.byte $0
.byte $0, $0, $0, $0, $0 ; unused

If you want to understand how this works you can check the documentation here, but let's talk a little about this code.
The first byte is always NES, we are indicating that this is a NES program.
Then there is a signature header that the emulator will look
Byte 4 gives information about the program rom and byte 5 gives information about the CHR ROM that is helpful for the graphics.
Byte 6 talks about the mapper and how we are going to do scrolling (we will talk about this in the future, I am trying to understand how it works right now).
Byte 9 defines the type of TV system we are using, 0 is NTSC and 1 is PAL.
Then some unused bytes that we have to fill.

Ok, so now we are starting to put our hands in the code and this is what mostly will happen in the next days of this diary

Top comments (0)