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

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

Re: How would I make an iNES header?

Post by dougeff » Thu Mar 09, 2017 6:41 pm

I don't want to be an ass, but...

I feel proper forum etiquette requires a follow up post.

Something along the the lines of "I got it to work, thanks", or "I'm still having issues with X", or "I'm too busy to work on this now, but I'm making slow progress"

When you have multiple people trying to help you, and you leave it hanging like this, it tends to generate bitter feelings, and people will likely be less enthusiastic about helping you in the future.
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 Mar 09, 2017 9:16 pm

Sorry, I haven't had time to test it out. I'll get to that right now.

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 Mar 09, 2017 9:20 pm

Yep, it worked! thanks!

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 10, 2017 10:58 am

One question though, how would I know how many PRG banks I'm using? Would I type the code in a different text file, then see how big the binary file is and change the number of PRG banks in the iNES header accordingly, or is there another way.

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

Re: How would I make an iNES header?

Post by Pokun » Fri Mar 10, 2017 11:51 am

No you should be able to see how big the file is even if the header doesn't match the ROM size. But emulators won't be able to run the game properly if the header is wrong.

If you are using NROM you can have only one or two PRG banks. Each PRG bank is 16 kB so if your game is bigger than that (minus the 8 kB CHR-ROM) you need two banks. If your PRG-ROM is bigger than 32 kB you need to consider using another mapper.
Tokumaru's templates automatically calculates the PRG-ROM start address ($C000 or $8000 for NROM) depending on what you set the PRG_COUNT define to (1 or 2 for NROM).

https://wiki.nesdev.com/w/index.php/Programming_NROM

User avatar
tokumaru
Posts: 11561
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 10, 2017 12:04 pm

Well, banking is something you have to plan for, not something that happens automatically and you just change the header to match. An NES program needs to explicitly map the banks it needs to access, so a program can't just grow indefinitely without the programmer planning out *how* it's going to grow and how the interaction between all the different banks will happen.

You have to decide yourself how many and which banks will be dedicated to the main engine, the audio engine, level maps, graphics (in case of CHR-RAM), and so on, and design the code in a way that allows it to access all of this stuff. When you start a project, you need to know the mapper you're gonna use, since there are many different bank layouts across the different mappers, and estimate how much space you're gonna use. These things don't have to be set in stone, as it may be possible to switch to a similar mapper later on or increase the ROM size (as long as the mapper supports it), but more drastic changes may need a lot of refactoring.

Another important thing to note is that ROM sizes bust be powers of 2. you can't have 110KB of PRG-ROM, you have to round it up to the next multiple of 2, which is 128KB. For example, if you currently have 64KB of PRG-ROM that's completely full, and need to implement a new feature that only needs 1 extra byte, you have to double the ROM size to 128KB, even though you only need 1 extra byte, otherwise emulators won't know how to map you ROM file.

In ASM6 you can put the cointents of different banks in separate files, and include them all in a master file that will be assembled. Something like this:

Code: Select all

;PRG-ROM bank 0
.base $8000
.include "bank0.asm"
.org $c000

;PRG-ROM bank 1
.base $8000
.include "bank1.asm"
.org $c000

;PRG-ROM bank 2
.base $8000
.include "bank2.asm"
.org $c000

;PRG-ROM bank 3
.base $c000
.include "bank3.asm"
.org $fffa

;interrupt vectors
.dw NMI
.dw Reset
.dw IRQ
This could be part of a master file for an UNROM program with 64KB of PRG-ROM (4 x 16KB).

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

Re: How would I make an iNES header?

Post by dougeff » Fri Mar 10, 2017 12:28 pm

Note. Number of banks should be a power of 2...

1, 2, 4, 8, 16

Don't worry about how many banks you need yet. Just stick to NROM128 (Donkey Kong, Pacman) or NROM256 (Super Mario Bros) sized right now.

If you have so much code that you overflow past FFFF, the assembler will give you an error. Until that happens, it's not a worry.
nesdoug.com -- blog/tutorial on programming for the NES

Post Reply