Getting da65 info files to behave sanely with mapper MMIO

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Getting da65 info files to behave sanely with mapper MMIO

Post by koitsu »

I'm dealing with da65, because disasm6 seems to think it's smarter than it really is (not to mention can't handle CDL files that spread across multiple banks).

MMC1-based game has code like this, located in the last bank (hard-wired to $C000-FFFF):

Code: Select all

  and #$0F                 
  sta $11                  
  sta $FFFF                
  lsr A                    
  sta $FFFF                
  lsr A                    
  sta $FFFF                
  lsr A                    
  sta $FFFF                
  lsr A                    
  sta $FFFF                
  rts                      
How does one "sanely" deal with this in a da65 info file -- specifically the conundrum of the programmer choosing $FFFF for the MMC1 PRG bank select address, which just so happens to be the high byte of the IRQ vector? (The game has no actual IRQ usage, so the IRQ vector ($FFFE-FFFF) itself contains $FFFF as well)

If I use something like this:

Code: Select all

range { start $c2a7; end $c318; type code; name "NMI"; };
range { start $fef4; end $ff0b; type code; name "PRG_BANK_SWAP"; };
range { start $ffd8; end $ffdf; type code; name "RESET"; };
range { start $fffa; end $ffff; type addrtable; };
I end up with this mess:

Code: Select all

PRG_BANK_SWAP:
        and     #$0F
        sta     $11
        sta     LFFFA+5
        lsr     a
        sta     LFFFA+5
        lsr     a
        sta     LFFFA+5
        lsr     a
        sta     LFFFA+5
        lsr     a
        sta     LFFFA+5
        rts

...

LFFFA:  .addr   NMI
        .addr   RESET
        .addr   LFFFA+5
If I add:

Code: Select all

label { addr $ffff; size 1; name "MMC1_PRG_SELECT"; };
I end up with this:

Code: Select all

PRG_BANK_SWAP:
        and     #$0F
        sta     $11
        sta     MMC1_PRG_SELECT
        lsr     a
        sta     MMC1_PRG_SELECT
        lsr     a
        sta     MMC1_PRG_SELECT
        lsr     a
        sta     MMC1_PRG_SELECT
        lsr     a
        sta     MMC1_PRG_SELECT
        rts

...

        .addr   NMI
        .addr   RESET
MMC1_PRG_SELECT := * + 1
        .addr   MMC1_PRG_SELECT
...which makes sense of course, but is perplexing.

One cannot hand-modify the disassembly file because as one works out what's data vs. code, one needs to re-run da65 to get an updated disassembly, losing hand-hacked changes.

Along the same lines: the game reads from ROM regions that contain data/whatever, but obviously writes to those regions go to MMC1; da65 thinks they're essentially one in the same, which makes for some really nasty disassembled results.

This is all with da65 V2.17 - Git c2568d8.

Advice/thoughts?

P.S. -- Do inline comments actually work for labels? I've been futzing around with COMMENT in label and range, but I can't quite get the latter to work how I'd expect, and the former always seems to generate comments like ; thing\nlabelname := $addr rather than what one of the examples shows.

Edit -- minor copy-paste mistake on my part pertaining to the PRG swap routine. Thing has the same routine in several places...
Post Reply