Trigger breakpoint on PRG bank swap

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
SusiKette
Posts: 147
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Trigger breakpoint on PRG bank swap

Post 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).
Avatar is pixel art of Noah Prime from Astral Chain
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Trigger breakpoint on PRG bank swap

Post by tepples »

A write breakpoint on $8000-$9FFF will catch all MMC3 bank switching, but this includes CHR bank switching as well.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Trigger breakpoint on PRG bank swap

Post 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.)
User avatar
SusiKette
Posts: 147
Joined: Fri Mar 16, 2018 1:52 pm
Location: Finland

Re: Trigger breakpoint on PRG bank swap

Post 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
Avatar is pixel art of Noah Prime from Astral Chain
Post Reply