Zepper wrote:
Currently, the ring is glitched. It's ok for a few frames, but it glitches.
When I was debugging MMC2, I hacked things a tad so that the output was highlighted when the second bank was switched in. You might want to do this to see what bank is being switched in during rendering.
Famicom Wars (MMC4, the CHR switching is identical) switches banks many times per frame, and even switches banks for a few characters to render text.
You must use A5 to select which bank you're going to use, and A4-A13 to trigger the switch. The chip looks for 0P 1111 11XX xxxx (from A13 down to A0). Where P is the page#, XX is the XOR of these two bits, and xxxx are don't care bits.
This corresponds to:
Code:
// PPUREAD is true when the PPU has read the CHR data byte
// PPUADD is the 14 bit PPU address you're reading from
// bank0 returns 0/1 depending on which bank you need to use
// bank1 works similar to bank0
if (PPUREAD)
{
switch(PPUADD & 0x3ff0)
{
case 0x0fd0 : bank0 = 0; break;
case 0x0fe0 : bank0 = 1; break;
case 0x1fd0 : bank1 = 0; break;
case 0x1fe0 : bank1 = 1; break;
}
}
bank0 indicates which of the two banks you must use for PPU addresses 0000-0fff (i.e. mapper register B000 or C000). 0 = B000, 1 = C000
bank1 indicates which of the two banks you must use for PPU addresses 1000-1fff (i.e. mapper register D000 or E000). 0 = D000, 1 = E000
NOTE: you cannot just set the bank inside the case statement. If you do this, it's possible that the game code can select one bank and then clear the screen, select another bank and write graphics without having an FD/FE character. This would result in the wrong bank being displayed, because the game updated the bank # without using switch characters (FD/FE).