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

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

Re: How would I make an iNES header?

Post by Pokun » Fri Feb 24, 2017 4:46 am

DementedPurple wrote: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.
In my example the header is set to NTSC. If you want to change to PAL you would just change the third line:

Code: Select all

TVSYSTEM  = $00 ;$00 = NTSC, $01 = PAL
into

Code: Select all

TVSYSTEM  = $01 ;$00 = NTSC, $01 = PAL
I set up the three constants PRG_COUNT, SCROLL and TVSYSTEM so that I can quickly change them if I want to without messing with the header.
Note that SCROLL is the same thing as what is popularily called "nametable mirroring" (but mirroring is backwards: H-Scroll is Vertical Mirroring and V-Scroll is Horizontal Mirroring).

The wiki explains iNES and NES 2.0 headers.

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 » Mon Feb 27, 2017 8:42 am

I haven't been following a tutorial, I've been reading a book from the eighties.

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

Re: How would I make an iNES header?

Post by dougeff » Mon Feb 27, 2017 10:25 am

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 » Tue Feb 28, 2017 10:53 am

dougeff wrote:Is it this one?

http://www.atariarchives.org/mlb/
Yeah.

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 » Fri Mar 03, 2017 9:14 am

Would the ines header for the original NESASM assembler work with the newer NESASM3?

User avatar
tokumaru
Posts: 11756
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru » Fri Mar 03, 2017 10:03 am

The problem with building an NES game based only on a 6502 book it that the language is just one little piece of the puzzle... It's kinda like saying "I want to write a book about astrophysics in French": sure, you'll have to learn French in order to actually write the information down, but you do have to master the astrophysics too.

If you have previous game programming knowledge from other projects on other platforms, great, because these concepts (maps, objects, physics, AI, etc.) are generally the same no matter the platform. If you don't, these are subjects you should be researching as well.

As for the hardware-specific stuff, such as video, audio and input, knowledge of other platforms helps a lot too, since being familiar with the general concept allows you to simply look at the documentation (wiki) to know the specifics. If you don't yet know how old computers work (memory mapping, memory-mapped IO, mirroring, interrupts, timing, tiled graphics, etc.), a tutorial might gradually introduce these topics.

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 » Sat Mar 04, 2017 1:15 pm

So I've used every single 6502 assembler out there, And used an example iNES header for every one, and still, none of them work.

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

Re: How would I make an iNES header?

Post by dustmop » Sat Mar 04, 2017 1:30 pm

DementedPurple wrote:So I've used every single 6502 assembler out there, And used an example iNES header for every one, and still, none of them work.
Having made multiple NES games, I can assure you they *do* in fact work, you're just doing something wrong. If you are seeking help, you need to say what you've already tried, and what errors or unexpected behavior you're seeing.

https://opensource.com/life/16/10/how-a ... -questions

User avatar
tokumaru
Posts: 11756
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru » Sat Mar 04, 2017 1:33 pm

The simplest possible way to build an iNES header is to use NESASM and its iNES directives. The second simplest way is to use ASM6 and build the header using .db statements (following the specification from the wiki) right before the .org $8000 statement that starts the PRG-ROM. The third way is to use ca65 and create a segment for the header, that you can fill using .byte statements.

You can download any NES program with source code written for any of these assemblers to see how the iNES header can be generated.

Edit: my old ASM6 templates demonstrate one way to get ASM6 to output correctly formed NES ROMs for a few different mappers, header included.

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

Re: How would I make an iNES header?

Post by dougeff » Sat Mar 04, 2017 3:03 pm

none of them work.
Have you been able to assemble anything (even a broken output file)?

For example, using asm6, write a text file with the conetents....

LDA #01

And asm6 should assemble it into a 2 byte .bin file, when viewed in a hex editor should look like (A9 01).

Can you confirm this much. This is my definition of "works". Also, don't give up yet. I'm an idiot, and I made an NES game. It's doable.

Perhaps you should visit the IRC #nesdev channel and ask more questions there.
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 » Sat Mar 04, 2017 4:48 pm

I get an accurate binary file, but the problem comes when I try to run it in an emulator. All I get is an error message saying "Corrupt file". The emulator I'm using is Nestopia.

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

Re: How would I make an iNES header?

Post by dougeff » Sat Mar 04, 2017 5:19 pm

That's the information I was looking for. The assemblers work, but you don't know how to assemble a functional NES ROM.

I suggest you start by taking some existing (working) example code, and assemble that. Nerdy Nights. Then modify it to learn / try things.

The most standard ROM (NROM256) is...

16 bytes header
32768 bytes program code
8192 bytes graphics.

40976 bytes exactly, total.

You need to write a header that says 2 banks PRG and 1 bank CHR and mapper 0, for that to work.

With a correct header and sized file, you will get a gray screen that does nothing, even if everything else is filled with zeroes.
Last edited by dougeff on Sat Mar 04, 2017 6:10 pm, edited 1 time in total.
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 » Sat Mar 04, 2017 5:47 pm

So I split the CHR and PRG data from a Super Mario Bros. ROM and removed the original iNES header. Now is there a way I could turn the binary file to a text document that can be compiled?

User avatar
tokumaru
Posts: 11756
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru » Sat Mar 04, 2017 6:06 pm

Disassembling binary code back into assembly code is not a trivial thing to do (it may take months or even years to get something usable, depending on the complexity of the game), so this is not a very good approach.

If you want to experiment with existing sugar, use proper source code that's been officially released by the original author.

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

Re: How would I make an iNES header?

Post by dougeff » Sat Mar 04, 2017 6:30 pm

Try one of these...

viewtopic.php?f=22&t=12847

The newest version (0.4), and the asm6 source code.

EDIT, note this is a NROM 128 example.
16 bytes header
16384 bytes program...defined as 1 bank in the header
8192 bytes graphics...defined as 1 bank in the header
24592 bytes total.
nesdoug.com -- blog/tutorial on programming for the NES

Post Reply