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

Re: How would I make an iNES header?

Post by DementedPurple »

Okay, So I've compiled my iNES header, then copied the binary file and pasted it after the header in a HEX editor, then I created a .BIN with the CHR and PRG including the header, then tried running it in an emulator and it doesn't work. And yes, I've changed the file extension from .BIN to .NES.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: How would I make an iNES header?

Post by dougeff »

I see you have perseverance. That is a good skill.

Communication skills, needs improvement.

Or perhaps you vastly overestimate our ability to understand your issue.

I don't know what your header looks like, nor what PRG ROM you are using, nor what CHR, nor which assembler, nor which emulator. It doesn't sound like you are using source code, but posting that would be useful, if you were.

And 'doesn't work', doesn't work in a forum. Error message? Blank screen? Screen full of gibberish tiles? What are isn't working?

Building a functional NES file takes a lot of technical knowledge. Working from a working source code is probably where you should start.
nesdoug.com -- blog/tutorial on programming for the NES
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How would I make an iNES header?

Post by Pokun »

No need to paste anything in a hex editor, you assemble your source files into a complete binary .nes file, header and all. The iNES header is defined in the source of those example programs.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru »

When NES homebrewing was in its infancy, it was somewhat common for programmers to create the header separately using an hex editor and join everything in the end. But we've come to realize that having the assembler spit out a complete NES file is more convenient, so nearly everyone does it like that now.

Seriously, if you want an example that "just works" for ASM6, get one of the templates I linked to in my previous post. Just provide the CHR file (if using a CHR-ROM template) and you should get a valid ROM after assembling. It won't do anything because there's no code, but the result will be a valid NES file emulators will accept. From there you can start writing the actual code so your program can do things.
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 »

This is what my iNES header looked like: (The game was Super Mario Bros.)

Code: Select all

.db "NES",$1a
.db $02
.db $01
.db $00|$01
.db $00
.db $00
.db $00
.dsb 6,$00
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru »

And what did you do with it? How large was the resulting ROM file? What happened when you opened it in the emulator?
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 »

The resulting ROM file was 120 kilobytes, and when I load it in Nestopia, I get invalid file.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru »

You need to be more precise with the file size, since every byte makes a difference. Please find the size in bytes (in Windows you can right click and ask for the file's properties to see the exact byte size).

120KB doesn't sound like a valid size for an NES ROM file though. The closest thing would be an UNROM program, with 16 + 131,072 = 131,088 bytes. UNROM has 8 16KB PRG-ROM banks and no CHR banks (it uses CHR-RAM).
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 »

tokumaru wrote:You need to be more precise with the file size, since every byte makes a difference. Please find the size in bytes (in Windows you can right click and ask for the file's properties to see the exact byte size).

120KB doesn't sound like a valid size for an NES ROM file though. The closest thing would be an UNROM program, with 16 + 131,072 = 131,088 bytes. UNROM has 8 16KB PRG-ROM banks and no CHR banks (it uses CHR-RAM).
It's exactly 119,952 bytes.
User avatar
dustmop
Posts: 136
Joined: Wed Oct 16, 2013 7:55 am

Re: How would I make an iNES header?

Post by dustmop »

DementedPurple wrote:It's exactly 119,952 bytes.
That sounds to me like pasting ASCII instead of HEX, but that's just my random guess. Hard to know without more precise info.
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 »

Well, I've copied and pasted the text in the binary file.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: How would I make an iNES header?

Post by tokumaru »

What kind of ROM are you trying to make? NROM? If so, anything beyond 40,976 bytes is wrong for sure. NROM needs to be either 24,592 or 40,976 bytes, depending on the size of the PRG-ROM.

It seems you're expecting the hex editor to do something it just doesn't do. Hex editors don't convert anything, if you copied text, you can only paste the exact same text, unmodified. File extensions also don't mean anything, they're just text meant to indicate what program should be used to open each file. Changing extensions doesn't modify the files in any way.

But really, you don't need hex editors or anything fancy, you just need an assembler. Write the correct stuff in it and you can generate a proper NES ROM file in one step.
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: How would I make an iNES header?

Post by dougeff »

I know that when I try to cut from FCEUX's hex editor, and paste into another hex editor, it doesn't paste as binary, but rather as a string of ASCII values.

Example...original binary = 0x95 cut pasted, becomes...
0x39,0x35. (The ascii values of '9' and '5'). That is of course wrong.

EDIT. The only way I can cut and paste from FCEUX, is, I can paste into a source code file (asm6) with the directive .hex (example .hex 95). I wouldn't recommend this.
nesdoug.com -- blog/tutorial on programming for the NES
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: How would I make an iNES header?

Post by Pokun »

Hex editors usually have options to copy as ASCII or as "hex string" and so on. The .hex directive is usefull if you have a very large table and you want to type it in a more compact manner.


DementedPurple whatever you are trying now doesn't seem to be working, so why don't you do what people have adviced you to for a long time now? Namely, instead of copying headers from existing games, start with a working example and work from there. I'd recommend to start as small as possible, so Tokumaru's NROM template is your best bet. It is already a minimal working ROM so just assemble it in asm6 and see if you can load it in an emulator without errors. Then you can enter some code to see if that works.

Here is some minimal working code that gives you feedback that it's working by making noise from the TV speakers:

Code: Select all

;Basic init code:
  sei
  cld
  ldx #$40
  stx $4017
  ldx #$FF
  txs
  inx
  stx $2000
  stx $2001
  stx $4010


;Make some noise:
  lda #%00001000
  sta $4015        ;enable noise
  lda #$3F
  sta $400C        ;volume F, disable internal length and volume
  lda #$81
  sta $400E        ;make some noise
  lda #$00
  sta $400F        ;set length


main:
  jmp main
Paste this under the "Reset" label in Tokumaru's NROM template.


Code: Select all

  .dsb 8192, $00 ;no graphics
Paste this line in the CHR-ROM bank (replace ".incbin "tiles.chr" with this line).
User avatar
Myask
Posts: 965
Joined: Sat Jul 12, 2014 3:04 pm

Re: How would I make an iNES header?

Post by Myask »

If you uploaded some of your failed attempts to the forum as attachments, then we might be able to better-understand what's going wrong where.
Post Reply