+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  suitable 6502 cross assembler for NES games?
Pages: [1]
Author Topic: suitable 6502 cross assembler for NES games?  (Read 2 times)
smkd
Guest
« on: December 14, 2008, 11:55:27 pm »

i need to implement a hack in a NES game and i'm stuck with finding a suitable assembler.  first a little background: I have a 256k PRG game expanded to 512k, i need to modify existing code and add bits and pieces to the newly expanded area.

-xkas: i was just going to use this first because of how simple and straightforward it is, though it forces SNES address conversion which is enough to look for something else for this.
-ca65: it's a cross assembler apparently, and i have used it for NES homebrew before but god damn if i can figure out how to use it for cross assembling.  i can't locate / understand how to do so in the user's guide.
-wla-6502: don't even suggest this.  it really doesn't look like somehting that will serve well for hacking a banked NES game, and i don't like how broken the assembler is to begin with.

so, any ideas on alternatives?
tomaitheous
Guest
« Reply #1 on: December 15, 2008, 06:02:13 pm »

 I'm not familiar with those others. I used PCEAS to write some NES code.

 What I did:
 
 included the rom (minus the header) as a binary with .incbin "some.rom"
 after the include, I used .bank and .org directives to overwrite the code with my code and/or data
 assembled into a headless rom, then reattach the original NES header.

 Presto.
byuu
Guest
« Reply #2 on: December 16, 2008, 05:35:51 pm »

blargg swears by ca65, so it may be worth the effort to see how it works.

Quote
-xkas: i was just going to use this first because of how simple and straightforward it is, though it forces SNES address conversion which is enough to look for something else for this.

You'd have to use LoROM addressing, and specify the upper 8-bits as your bank selector. If anything gets mapped to $6000-7fff ... you'd be out of luck.

Plus if you program for the SNES, it'd be much too tempting to actually use one of those ops (and indeed it defaults to 24-bit addressing for supported ops if you don't specify); and you wouldn't be able to use any of the "illegal ops" of the 6502.

I'd like to implement NES addressing, but there's like 200+ mappers. The hell if I have that kind of time, sorry.
Disch
Guest
« Reply #3 on: December 16, 2008, 08:31:19 pm »

Quote from: byuu on December 16, 2008, 05:35:51 pm
I'd like to implement NES addressing, but there's like 200+ mappers. The hell if I have that kind of time, sorry.

Mapper details should be unimportant.  Banks are arranged the same way in the ROM regardless of the mapper used:  offset = bank_number * bank_size + 0x10;

Nearly all mappers operate on a single bank size, so if you make that an assembler directive or something, you can use the bank number and CPU address to find the ROM offset:

Code:
.nesbanksize  8  ; 8K banks

.bank $0A
.org $B753   ; or whatever the xkas syntax is for this -- you get the idea

Output ROM offset is:   ( 0xB753 & ((8<<10)-1) ) + 0x0A * (8<<10) + 0x10 = 0x15763

If you want to get fancy you can allow for a configurable header size (instead of a fixed 0x10 byte header) to allow for possible trainers, or for NSFs which have a 0x80 byte header.

All mappers I've seen have either 8, 16, or 32K bank sizes... so nothing really unexpected to bite you in the arse.  NSFs are 4K, so you'd have to go at least that low if you want to support those (but NSF support would introduce a whole new set of problems, since the start of the NSF file doesn't necessarily land clean on a bank boundary -- so you'd have to examine the header to properly get file offsets.  So it probably isn't worth it).

A setup like this would work for any game regardless of the mapper used.  No need to wrap your head around any one of 200+ mappers.

Some complications could arise for some mappers which use multiple bank sizes (VRC6:  024 comes to mind), but the end user can deal with that on their own... as long as you allow the .nesbanksize directive to be changed midway through an asm file.  And even if you don't -- the logic could still be worked out -- it'd just be a minor annoyance.

All and all... it shouldn't be that difficult, IMO.
« Last Edit: December 16, 2008, 08:39:15 pm by Disch »
smkd
Guest
« Reply #4 on: December 16, 2008, 09:50:59 pm »

thanks for the suggestions, though i've realised something that ruins my plan.  the game uses iNES mapper 69 which apparently supports 512k PRG.  Upon expansion the game worked in FCEUXD and Nintendulator and i thought all was well, until Nestopia refused to run it with 512k PRG.  perhaps the sunsoft-5B's board was never made to accomodate more than 256k despite the mapper capability and the nestopia author forced the limit upon it? oh well, i've already made do with the current 256k.

byuu: a 6502 xkas would be fantastic, and my very plan WAS to use 6000-7FFF (since the 5B / FME-7 can bank ROM in there).  yeah i'd have to avoid all those 6c02 / 65816 instructions although i've mostly remembered what's there / what's missing.

@tomaitheous: thanks, i will look into PCEAS the next time i see a need for a hack like this.
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC