Page 1 of 1

Trigger breakpoint on PRG bank swap

Posted: Tue Sep 25, 2018 3:36 am
by SusiKette
Is there a way to make breakpoint in FCEUX that gets triggered when the game swaps PRG banks? If it is any of help, I believe the game in question uses MMC3 (iNES 004 iirc).

Re: Trigger breakpoint on PRG bank swap

Posted: Tue Sep 25, 2018 5:19 am
by tepples
A write breakpoint on $8000-$9FFF will catch all MMC3 bank switching, but this includes CHR bank switching as well.

Re: Trigger breakpoint on PRG bank swap

Posted: Tue Sep 25, 2018 6:20 am
by rainwarrior
The debugger doesn't directly have functionality for tracking internal mapper registers, so with something like MMC3 where the internal register gets selected first you can't really do it with a single breakpoint.

However, an execution breakpoint on $8000-FFFF (or any suitable range) with the condition K==#5 will break whenever PRG bank 5 starts executing, that would break on the instruction after the write for that specific bank, for example. (On Mesen you could step backward from here, on FCEUX you'd probably want to start a trace first, then read backward in the trace log from there.)

Another way to do it is keep track of the internal register writes with a Lua script, and have the Lua script call debugger.hitbreakpoint() when it sees the write you want. (Can also do something similar in Mesen, I believe.)

Re: Trigger breakpoint on PRG bank swap

Posted: Tue Sep 25, 2018 8:32 am
by SusiKette
rainwarrior wrote: Another way to do it is keep track of the internal register writes with a Lua script, and have the Lua script call debugger.hitbreakpoint() when it sees the write you want.
This might be the best option. For now I only want to know when the game swaps PRG banks if at all. CHR bank swaps are usually easier to figure out since they appear on PPU Viewer.

And just to confirm: PRG swapping works as follow:
-first write a value to $8000 that has either 6 or 7 written on the bits 0-2
-write the bank number to $8001
-7 will always swap the bank at $A000-$BFFF
-6 will swap the bank at $8000-$9FFF if the value written to $8000 has the 6th bit cleared. If it's set, the swap is done at $C000-$DFFF