Merge pull request #435 from NRS-NewRisingSun/mapper332

Mapper 332: Add CNROM mode, support larger multicarts
This commit is contained in:
Autechre
2021-04-07 20:11:39 +02:00
committed by GitHub

View File

@@ -23,26 +23,40 @@
#include "mapinc.h" #include "mapinc.h"
static uint8 preg, creg; static uint8 preg, creg, latch, dipSwitch;
static SFORMAT StateRegs[] = static SFORMAT StateRegs[] =
{ {
{ &preg, 1, "PREG" }, { &preg, 1, "PREG" },
{ &creg, 1, "CREG" }, { &creg, 1, "CREG" },
{ &latch, 1, "LATC" },
{ &dipSwitch, 1, "DPSW" },
{ 0 } { 0 }
}; };
static void Sync(void) { static void Sync(void) {
int prg = (preg & 7) | ((preg >> 3) & 0x08); // There is a high bit 3 of the PRG register that applies both to PRG and CHR
if (preg & 8) { if (preg & 8) {
setprg16(0x8000, preg & 7); setprg16(0x8000, prg);
setprg16(0xc000, preg & 7); setprg16(0xc000, prg);
} }
else else
setprg32(0x8000, (preg & 6) >> 1); setprg32(0x8000, prg >> 1);
setchr8(creg);
int chr = (creg & 7) | ((preg >> 3) & 0x08); // There is a high bit 3 of the PRG register that applies both to PRG and CHR
int mask = (creg & 0x10)? 0: (creg & 0x20)? 1: 3; // There is an CNROM mode that takes either two or four inner CHR banks from a CNROM-like latch register at $8000-$FFFF.
setchr8((chr &~mask) | (latch &mask)); // This "inner CHR bank" substitutes the respective bit(s) of the creg register.
setmirror(((preg >> 4) & 1) ^ 1); setmirror(((preg >> 4) & 1) ^ 1);
} }
static DECLFR(BMCWSRead) {
if ((creg >> 6) & (dipSwitch &3))
return X.DB;
else
return CartBR(A);
}
static DECLFW(BMCWSWrite) { static DECLFW(BMCWSWrite) {
if (preg & 0x20) if (preg & 0x20)
return; return;
@@ -53,13 +67,28 @@ static DECLFW(BMCWSWrite) {
} }
} }
static void MBMCWSPower(void) { static DECLFW(LatchWrite) {
latch =V;
Sync(); Sync();
SetReadHandler(0x8000, 0xFFFF, CartBR); }
SetWriteHandler(0x6000, 0x6001, BMCWSWrite);
static void MBMCWSPower(void) {
dipSwitch =0;
Sync();
SetReadHandler(0x8000, 0xFFFF, BMCWSRead);
SetWriteHandler(0x6000, 0x7FFF, BMCWSWrite);
SetWriteHandler(0x8000, 0xFFFF, LatchWrite);
} }
static void BMCWSReset(void) { static void BMCWSReset(void) {
dipSwitch++; // Soft-resetting cycles through solder pad or DIP switch settings
if (dipSwitch == 3) dipSwitch = 0; // Only 00b, 01b and 10b settings are valid
// Always reset to menu
preg =0;
creg =0;
latch =0;
Sync();
} }
static void StateRestore(int version) { static void StateRestore(int version) {