It is currently Sat Oct 21, 2017 1:45 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Patching bin to NES rom
PostPosted: Sun Dec 02, 2012 2:53 pm 
Offline

Joined: Sat Dec 01, 2012 6:09 pm
Posts: 15
Ok I have my code all up and ready except... I don't know how to patch the bin file to the rom. How do you do that?


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 3:10 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2257
Don't use the word patch, that means you take a file and change it with another file. Now, what specifically do you have? Do you have BIN files? ROMS files? Source code? What do you need to turn into a ROM?


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:05 pm 
Offline

Joined: Sat Dec 01, 2012 6:09 pm
Posts: 15
I have a dual tile encoding routine that I have assembled into a bin file using ASM6. What I want to do is insert that code into a nes rom file but I have no idea how to do it. I thought of disassembling the rom and putting the routine in but I hear it's a long and painstaking to reassemble a full rom back into working order, especially for a small asm hack. I have the asm file and the bin. I tried FCEUXD but it only takes absolute operations and not branching operations.


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:07 pm 
Offline
Formerly 65024U

Joined: Sat Mar 27, 2010 12:57 pm
Posts: 2257
Dunno what you're talking about trying it in FCEUX without it being a ROM since you can't, but with the ASM6 file, you should have built the header for the file with assembly. I dunno how to do it as I don't and never will use ASM6, but somebody here will know. There should be some examples somewhere.


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:17 pm 
Offline

Joined: Wed Feb 17, 2010 5:42 pm
Posts: 359
Location: Denine's Devil Mansion
I guess he's making a hack of a game. He probably wants to insert his own routine in existing game.
Right?


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:23 pm 
Offline

Joined: Fri May 13, 2011 7:36 pm
Posts: 143
3gengames, he is trying to assemble some code and patch it into an existing game. By doing it with FCEUX, he would open the existing game and modify it with the mini assembler included in the debugger.

As far as disassembling/reassembling the ROM, that would be overkill.

Either manually insert the assembled code with a hex editor, write a simple utility to patch the bin into the rom, or use software with this feature built in.


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:33 pm 
Offline

Joined: Sat Dec 01, 2012 6:09 pm
Posts: 15
@denine right. I am gonna try out snarfblam's program and hopefully it will suit me just so I can get to the fun part and translate the game.


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:35 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
There are two ways to go about this...
Use a Hex editor and manually copy-paste the bytes into the NES file. HXD is a nice hex editor.
or
Make a new ASM6 project that uses a bunch of incbins to include the original code, then put your modified code in there too, then incbin the rest of the rom. First use a hex editor or something to find the empty space for your code.

Example: (hack for SMB1 that makes more koopas appear for some reason)
Code:
.db "NES",$1A,2,1,1,0,0,0,0,0,0,0,0,0

;PRG ROM

.org $8000
$ = $8000
incbin "Super mario bros.nes", $ - $8000 + $10, $C71D - $
nop ;replaces sec instruction
incbin "Super mario bros.nes", $ - $8000 + $10, $10000 - $

;CHR ROM
incbin "Super mario bros.nes", $8010, $2000



Another example for Contra: (get the spread gun when you die)

Code:
;NES header
.db "NES",$1A,8,0,$21,0,0,0,0,0,0,0,0,0

;PRG ROM

;bank 0
.org $8000
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (0*$4000) + $10, $C000 - $
.org $C000

;bank 1
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (1*$4000) + $10, $C000 - $
.org $C000

;bank 2
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (2*$4000) + $10, $C000 - $
.org $C000

;bank 3
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (3*$4000) + $10, $C000 - $
.org $C000

;bank 4
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (4*$4000) + $10, $C000 - $
.org $C000

;bank 5
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (5*$4000) + $10, $C000 - $
.org $C000

;bank 6
$ = $8000
;copy 8000 until C000 of that bank
incbin "contra.nes", $ - $8000 + (6*$4000) + $10, $C000 - $
.org $C000

;bank 7 (fixed bank C000-FFFF)
$ = $C000
;we are changing code at DAD1, so copy code until $DAD1
incbin "contra.nes", $ - $C000 + (7*$4000) + $10, $DAD1 - $
lda #3  ;get spread gun when you die
;rest of the bank until $10000
incbin "contra.nes", $ - $C000 + (7*$4000) + $10, $10000 - $

;finished

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:49 pm 
Offline

Joined: Wed Feb 17, 2010 5:42 pm
Posts: 359
Location: Denine's Devil Mansion
For my DreamWorld Pogie Revival hack, I changed some code to "jsr" instructions, and made them jump to my own code which I assembled beforehand and inserted with hex editor.
You just need to remember to be careful and not forget to do replaced actions in your new code.
For example:
Old code
Quote:
Lda #$09
sta Lives
;;some code;;

Changed into
Quote:
jsr $FF00 ;jump to my own code(inserted earlier with hex editor)
nop

And this code at $FF00
Quote:
lda #$09
sta Lives ;Redo replaced code

;;do my own code;;
rts

That's how I'm doing it.


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 4:54 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
I just noticed that DreamWorld Pogie fails on the newest version of FCEUX, but works on other emulators. Time to send in a bug report I guess.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 5:02 pm 
Offline

Joined: Wed Feb 17, 2010 5:42 pm
Posts: 359
Location: Denine's Devil Mansion
That's odd. Both unpatched and patched games works perfectly for me...
I'm using FCEUX 2.2.0.


Top
 Profile  
 
PostPosted: Sun Dec 02, 2012 11:40 pm 
Offline

Joined: Sat Dec 01, 2012 6:09 pm
Posts: 15
Thank you everyone for the knowledge, that hex editor deal worked like a charm! And thanks for the assembler Snarfblam!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: M_Tee and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group