How would I make an iNES header?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

How would I make an iNES header?

Post by DementedPurple » Wed Feb 22, 2017 8:19 pm

Yeah, my title pretty much says everything. Thanks!


Pokun
Posts: 1273
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How would I make an iNES header?

Post by Pokun » Thu Feb 23, 2017 12:49 am

The simplest way to make a header is to just use .db/.byte directives (depending of the assembler) to enter the bytes that forms the header at the start of the ROM.

Simple example of iNES header for NROM:

Code: Select all

PRG_COUNT = $01 ;$01 = 16 kB ROM, $02 = 32 kB ROM
SCROLL    = $01 ;$01 = Horizontal Nametable Arrangement, $00 = Vertical Nametable Arrangement, $08 = Four-Screen
TVSYSTEM  = $00 ;$00 = NTSC, $01 = PAL

  .db "NES", $1a ;identification of the iNES header
  .db PRG_COUNT  ;number of 16 kB PRG-ROM pages
  .db $01        ;number of 8 kB CHR-ROM pages (0 = CHR-RAM)
  .db $00|SCROLL ;mapper 0 and scroll setting
  .db %00000000  ;mapper 0, iNES header, no arcade
  .db $00        ;no PRG-RAM
  .db TVSYSTEM   ;NTSC or PAL
  .dsb 6, $00    ;reserved bytes in the header
Using macros like Tepples' makes it easy to make any kind of header.

User avatar
dougeff
Posts: 2616
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: How would I make an iNES header?

Post by dougeff » Thu Feb 23, 2017 6:19 am

Ca65 doesn't have a .dsb directive. It does have .repeat and .res directives (either would do the same), but that's unnecessary. Just indicate fill = yes in the cfg definition of the header "segment", and it will pad up to the "size".

The size of the header needs to be exactly 16 bytes, and that is external to the PRG-ROM. It is metadata for the emulator, telling it how big the ROMs are and what map to use.
nesdoug.com -- blog/tutorial on programming for the NES

Pokun
Posts: 1273
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How would I make an iNES header?

Post by Pokun » Thu Feb 23, 2017 8:25 am

dougeff wrote:Ca65 doesn't have a .dsb directive.
Ah yes sorry, I forgot to say my example is using Asm6 syntax.

Also Ca65 would use .byte instead of .db to define bytes. Nesasm uses .db, but it has special directives for defining the header. Manually defining the iNES header using .db in Nesasm might mess with its annoying banking system I guess.

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: How would I make an iNES header?

Post by DementedPurple » Thu Feb 23, 2017 11:30 am

So, if I were to have the iNES header in the text file, then have a hexdump file and write that to an EPROM to use it on a real NES, would it work? Even though I could probably use a simple JMP to get the the section that has all of the code. Also kind of unrelated but I find it funny how this websites spellcheck doesn't count NES as a real word as well as Nintendo.

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: How would I make an iNES header?

Post by DementedPurple » Thu Feb 23, 2017 11:31 am

DementedPurple wrote:So, if I were to have the iNES header in the text file, then have a hexdump file and write that to an EPROM to use it on a real NES, would it work? Even though I could probably use a simple JMP to get the the section that has all of the code. Also kind of unrelated but I find it funny how this websites spellcheck doesn't count NES as a real word as well as Nintendo.
* To the (Somehow spellcheck didn't notice that) :roll:

User avatar
dougeff
Posts: 2616
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: How would I make an iNES header?

Post by dougeff » Thu Feb 23, 2017 11:46 am

So, if I were to have the iNES header in the text file, then have a hexdump file and write that to an EPROM to use it on a real NES, would it work? Even though I could probably use a simple JMP to get the the section that has all of the code. Also kind of unrelated but I find it funny how this websites spellcheck doesn't count NES as a real word as well as Nintendo.
Let's break this down line by line...
iNES header in the text file
The header, is the first 16 bytes of a .NES file. It is binary. You can assemble a header, from a text file, if that's what you mean.
hexdump file
A dump is a term refferring to...when there is a fatal crash of a program, a dump is the contents of RAM at the time of crash, saved to a file, for debugging purposes. I think you mean some other term.
EPROM to use it on a real NES
No. You will never write a header in any ROM. It is just for emulation purposes. You would strip the header off if you wanted to burn it to a file an play in on real hardware. (Unless you mean on a flash cartridge designed to play .NES files, then you would leave the original .NES file intact with the header).

Code: Select all

JMP to get the the section
header has no code.

EDIT: The last 6 bytes of the PRG ROM, has address for important things, the middle 2 bytes of that is the location of the start of the program. It's called the 'reset vector', and needs to be at address $FFFC-$FFFD. It points to the start address. When you press power or reset, the NES gets its program counter from here.


Finally. I still don't know what you are attempting to do.
nesdoug.com -- blog/tutorial on programming for the NES

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: How would I make an iNES header?

Post by DementedPurple » Thu Feb 23, 2017 12:29 pm

So, if I can assemble a header, then how would I assemble with a CHR bank? Would I just make a simple .BIN file with the two files merged and change the extension or is it more complicated than that?

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: How would I make an iNES header?

Post by DementedPurple » Thu Feb 23, 2017 12:39 pm

dougeff wrote:

Finally. I still don't know what you are attempting to do.
I'm attempting to make an NES ROM to test my game.

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: How would I make an iNES header?

Post by DementedPurple » Thu Feb 23, 2017 12:42 pm

And also, buy hexdump I meant a file with my codes OpCodes, not actually the hex values typed out, but the hex values characters.

User avatar
dustmop
Posts: 135
Joined: Wed Oct 16, 2013 7:55 am

Re: How would I make an iNES header?

Post by dustmop » Thu Feb 23, 2017 12:45 pm

DementedPurple wrote:And also, buy hexdump I meant a file with my codes OpCodes, not actually the hex values typed out, but the hex values characters.
This is not what hexdump means. If you say "an object file" (the .o extension) or "a binary file" (the general term), people will understand what you are referring to.

tepples
Posts: 21752
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: How would I make an iNES header?

Post by tepples » Thu Feb 23, 2017 12:47 pm

DementedPurple wrote:this websites spellcheck doesn't count NES as a real word as well as Nintendo.
That's your browser's spell check.
DementedPurple wrote:I'm attempting to make an NES ROM to test my game.
The cc65 toolchain is a bit more flexible than other toolchains, but this also makes it somewhat more complicated to set up. You need to make these:
  • An iNES header
  • Code and data to put in PRG ROM
  • Tile data to put in CHR ROM (optional, required if not using CHR RAM)
  • Linker script to tell ld65 in what order to put all the above
One thing you could try is getting nrom-template to build. Then you can replace various pieces of it with your program.

DementedPurple
Posts: 318
Joined: Mon Jan 30, 2017 5:20 pm
Location: Colorado USA

Re: How would I make an iNES header?

Post by DementedPurple » Thu Feb 23, 2017 7:34 pm

Pokun wrote:The simplest way to make a header is to just use .db/.byte directives (depending of the assembler) to enter the bytes that forms the header at the start of the ROM.

Simple example of iNES header for NROM:

Code: Select all

PRG_COUNT = $01 ;$01 = 16 kB ROM, $02 = 32 kB ROM
SCROLL    = $01 ;$01 = Horizontal Nametable Arrangement, $00 = Vertical Nametable Arrangement, $08 = Four-Screen
TVSYSTEM  = $00 ;$00 = NTSC, $01 = PAL

  .db "NES", $1a ;identification of the iNES header
  .db PRG_COUNT  ;number of 16 kB PRG-ROM pages
  .db $01        ;number of 8 kB CHR-ROM pages (0 = CHR-RAM)
  .db $00|SCROLL ;mapper 0 and scroll setting
  .db %00000000  ;mapper 0, iNES header, no arcade
  .db $00        ;no PRG-RAM
  .db TVSYSTEM   ;NTSC or PAL
  .dsb 6, $00    ;reserved bytes in the header
Using macros like Tepples' makes it easy to make any kind of header.
So how would I tell it what TV System, would I just give the name, would I have to use some quotation marks, would I just give it the name with no quotation marks, or does a number stand for that.

User avatar
dustmop
Posts: 135
Joined: Wed Oct 16, 2013 7:55 am

Re: How would I make an iNES header?

Post by dustmop » Thu Feb 23, 2017 7:37 pm

What tutorial have you been following? I know that at least the Nerdy Nights tutorial covers this topic, and should help you understand what to do.

Post Reply