Holy Diver Batman MMC1 (M1_P128K.nes)

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158414)
I'm currently implementing WRAM (battery backed and not) for MMC1 using Holy Diver Batman as test roms. However, my emulator dies on M1_128K.nes. I assume that it has no WRAM because there are other MMC1 roms that I think have (M1_P128K_C32K_S8K.nes, M1_P128K_C32K_W8K.nes, etc.)

Debugging my emulator, M1_128K.nes does seem to make a write at $6000-$7FFF although my emulator ignores the write as the test rom has no WRAM.

Can anyone elaborate on this?
Thank you!
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158415)
It's checking to make sure there isn't any RAM.
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158416)
Somewhere I'm not sure yet but when I enable WRAM for M1_P128K.nes (i.e. by honoring the write request), the rom does not crash. Although I'm not sure if honoring the write request is the right thing to do. If I don't honor the write request, the emulator dies on an illegal opcode (probably due to jumping to an uninitialized location).
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158417)
If so, that's a bug. I'd like to see the log of the last few instructions before the crash when emulating missing WRAM.
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158419)
Here is a snippet

Code:
0443  8D 00 A0  STA $A000 = FF                  A:04 X:10 Y:03 P:24 SP:FD
0446  4A        LSR A                           A:04 X:10 Y:03 P:24 SP:FD
0447  88        DEY                             A:02 X:10 Y:03 P:24 SP:FD
0448  D0 F9     BNE $443                        A:02 X:10 Y:02 P:24 SP:FD
0443  8D 00 A0  STA $A000 = FF                  A:02 X:10 Y:02 P:24 SP:FD
0446  4A        LSR A                           A:02 X:10 Y:02 P:24 SP:FD
0447  88        DEY                             A:01 X:10 Y:02 P:24 SP:FD
0448  D0 F9     BNE $443                        A:01 X:10 Y:01 P:24 SP:FD
0443  8D 00 A0  STA $A000 = FF                  A:01 X:10 Y:01 P:24 SP:FD
0446  4A        LSR A                           A:01 X:10 Y:01 P:24 SP:FD
0447  88        DEY                             A:00 X:10 Y:01 P:27 SP:FD
0448  D0 F9     BNE $443                        A:00 X:10 Y:00 P:27 SP:FD
044A  60        RTS                             A:00 X:10 Y:00 P:27 SP:FD
Unsupported opcode encountered $FF, PC=$C01C
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158421)
Here is my read logic for $6000-$7FFF read
Code:
// WRAM/battery backed ram
if (address >= 0x6000 && address <= 0x7FFF)
{
   if (battPRGRAM)
      return battPRGRAM[address & 0x1FFF];
   return 0xFF;
}


And here is my write logic
Code:
// WRAM/Battery backed ram write
if (address >= 0x6000 && address <= 0x7FFF)
{
   if (battPRGRAM && !ramChipDisable)
      battPRGRAM[address & 0x1FFF] = value;
}


I have assumed 8KB WRAMs for now (I think this shouldn't affect M1_128K.nes)
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158422)
It looks like it's returning into la la land right after bankswitching CHR ($A000). Or is it also bankswitching PRG ($E000)?
Re: Holy Diver Batman MMC1 (M1_P128K.nes)
by on (#158482)
Ok got it fixed! :D

It was due to a stupid typo in my PRG bankswitching code as I inadvertently used CHR banking mode as the check for PRG banking mode.
Finally got SGROM to work!

:D

I'm surprised that my emulator got this far considering this was a crucial part in PRG bankswitching..