diff --git a/src/boards/380.c b/src/boards/380.c index 912e266..f14ac63 100644 --- a/src/boards/380.c +++ b/src/boards/380.c @@ -26,6 +26,7 @@ static uint16 latche; static uint8 dipswitch; static uint8 isKN35A; +static uint8 is4K1; static SFORMAT StateRegs[] = { { &latche, 2 | FCEUSTATE_RLSB, "LATC" }, @@ -50,13 +51,13 @@ static void Sync(void) setprg16(0x8000, latche >> 2); setprg16(0xC000, (latche >> 2) | 7 | (isKN35A && latche &0x100? 8: 0)); } - setmirror(((latche >> 1) & 1) ^ 1); + setmirror(latche &(is4K1? 0x040: 0x002)? MI_H: MI_V); } static DECLFR(M380Read) { if (latche & 0x100 && !isKN35A) - return dipswitch; + return CartBR(A | dipswitch); return CartBR(A); } @@ -91,6 +92,7 @@ static void StateRestore(int version) void Mapper380_Init(CartInfo *info) { isKN35A = info->iNES2 && info->submapper == 1; + is4K1 = info->iNES2 && info->submapper == 2; info->Power = M380Power; info->Reset = M380Reset; GameStateRestore = StateRestore; diff --git a/src/boards/449.c b/src/boards/449.c index f07ebb4..72e4b4c 100644 --- a/src/boards/449.c +++ b/src/boards/449.c @@ -23,12 +23,14 @@ static uint16 latchAddr; static uint8 latchData; static uint8 dipswitch; +static uint8 dipselect; static SFORMAT StateRegs[] = { { &latchAddr, 2, "ADDR" }, { &latchData, 1, "DATA" }, { &latchData, 1, "DIPS" }, + { &dipselect, 1, "DSEL" }, { 0 } }; @@ -58,12 +60,20 @@ static void Mapper449_Sync(void) static DECLFR(Mapper449_Read) { + if (dipselect) + return dipswitch &0x3; + else if (latchAddr &0x200) - return CartBR(A | dipswitch); + return CartBR(A | dipswitch &0xF); else return CartBR(A); } +static DECLFW(Mapper449_WriteDIPSelect) +{ + dipselect =V &1; +} + static DECLFW(Mapper449_WriteLatch) { latchData =V; @@ -73,15 +83,16 @@ static DECLFW(Mapper449_WriteLatch) static void Mapper449_Reset(void) { - dipswitch =(dipswitch +1) &0xF; + dipswitch++; latchAddr =latchData =0; Mapper449_Sync(); } static void Mapper449_Power(void) { - dipswitch =latchAddr =latchData =0; + dipselect =dipswitch =latchAddr =latchData =0; Mapper449_Sync(); + SetWriteHandler(0x6000, 0x7FFF, Mapper449_WriteDIPSelect); SetWriteHandler(0x8000, 0xFFFF, Mapper449_WriteLatch); SetReadHandler(0x6000, 0x7FFF, CartBR); SetReadHandler(0x8000, 0xFFFF, Mapper449_Read); diff --git a/src/boards/addrlatch.c b/src/boards/addrlatch.c index a989010..a86d426 100644 --- a/src/boards/addrlatch.c +++ b/src/boards/addrlatch.c @@ -194,33 +194,34 @@ void Mapper61_Init(CartInfo *info) { * Mapper 63 NTDEC-Multicart * http://wiki.nesdev.com/w/index.php/INES_Mapper_063 * - Powerful 250-in-1 - * - Hello Kitty 255-in-1 */ + * - Hello Kitty 255-in-1 + * Submapper 1: + * - NTDEC 82-in-1 */ static uint16 openBus; static DECLFR(M63Read) { - if (A < 0xC000) - if (openBus) - return X.DB; + if (openBus) + return X.DB; return CartBR(A); } static void M63Sync(void) { - uint16 mode = latche & 2; - uint16 prg_bank = (latche & 0x3F8) >> 1; - uint16 prg16 = (latche & 4) >> 1; - - openBus = ((latche & 0x300) == 0x300); - setprg8(0x8000, (prg_bank | (mode ? 0 : prg16 | 0))); - setprg8(0xA000, (prg_bank | (mode ? 1 : prg16 | 1))); - setprg8(0xC000, (prg_bank | (mode ? 2 : prg16 | 0))); - setprg8(0xE000, ((latche & 0x800) ? ((latche & 0x7C) | ((latche & 6) ? 3 : 1)) : - (prg_bank | (mode ? 3 : (prg16 | 1))))); + uint16 prg =latche >>2 &(submapper ==1? 0x7F: 0xFF); + if (latche &2) + setprg32(0x8000, prg >>1); + else { + setprg16(0x8000, prg); + setprg16(0xC000, prg); + } + openBus =prg >=ROM_size; + SetupCartCHRMapping(0, CHRptr[0], 0x2000, latche &(submapper ==1? 0x200: 0x400)? 0: 1); setchr8(0); - setmirror((latche & 1) ^ 1); + setmirror(latche &1? MI_H: MI_V); } void Mapper63_Init(CartInfo *info) { + submapper = info->submapper; Latch_Init(info, M63Sync, M63Read, 0x0000, 0x8000, 0xFFFF, 0); } @@ -254,13 +255,14 @@ void Mapper92_Init(CartInfo *info) { /*------------------ Map 200 ---------------------------*/ static void M200Sync(void) { - setprg16(0x8000, latche & 7); - setprg16(0xC000, latche & 7); - setchr8(latche & 7); - setmirror(((latche >> 3) & 1) ^ 1); + setprg16(0x8000, latche); + setprg16(0xC000, latche); + setchr8(latche); + setmirror(latche &(submapper ==1? 4: 8)? MI_H: MI_V); } void Mapper200_Init(CartInfo *info) { + submapper = info->submapper; Latch_Init(info, M200Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); } @@ -413,9 +415,25 @@ static void M227Sync(void) { setprg8r(0x10, 0x6000, 0); } +static DECLFR(M227Read) { + if (latche &0x0400) + return CartBR(A | dipswitch); + else + return CartBR(A); +} + +static void Mapper227_Reset(void) { + dipswitch++; + dipswitch &= 15; + latche = 0; + M227Sync(); +} + void Mapper227_Init(CartInfo *info) { submapper =info->submapper; - Latch_Init(info, M227Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); + Latch_Init(info, M227Sync, M227Read, 0x0000, 0x8000, 0xFFFF, info->iNES2 && (info->PRGRamSize || info->PRGRamSaveSize) || info->battery); + info->Reset = Mapper227_Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); } /*------------------ Map 229 ---------------------------*/ @@ -509,9 +527,25 @@ static void M242Sync(void) { setprg8r(0x10, 0x6000, 0); } +static DECLFR(M242Read) { + if (latche &0x0100) + return CartBR(A | dipswitch); + else + return CartBR(A); +} + +static void Mapper242_Reset(void) { + dipswitch++; + dipswitch &= 31; + latche = 0; + M242Sync(); +} + void Mapper242_Init(CartInfo *info) { M242TwoChips = info->PRGRomSize &0x20000 && info->PRGRomSize >0x20000; - Latch_Init(info, M242Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); + Latch_Init(info, M242Sync, M242Read, 0x0000, 0x8000, 0xFFFF, info->iNES2 && (info->PRGRamSize || info->PRGRamSaveSize) || info->battery); + info->Reset = Mapper242_Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); } /*------------------ Map 288 ---------------------------*/ @@ -745,7 +779,7 @@ static void M435Sync(void) { setprg16(0xC000, p | 7); } - if (latche &0x800) + if (latche &0x200) SetupCartCHRMapping(0, CHRptr[0], 0x2000, 0); else SetupCartCHRMapping(0, CHRptr[0], 0x2000, 1); diff --git a/src/boards/mmc3.c b/src/boards/mmc3.c index 864e498..f45ee11 100644 --- a/src/boards/mmc3.c +++ b/src/boards/mmc3.c @@ -657,7 +657,6 @@ static void M52PW(uint32 A, uint8 V) { static void M52CW(uint32 A, uint8 V) { uint32 mask = 0xFF ^ ((EXPREGS[0] & 0x40) << 1); -/* uint32 bank = (((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; */ uint32 bank = (((EXPREGS[0] >> 4) & 2) | (EXPREGS[0] & 4) | ((EXPREGS[0] >> 6) & (EXPREGS[0] >> 4) & 1)) << 7; /* actually 256K CHR banks index bits is inverted! */ if (CHRRAM && (EXPREGS[0] &3) ==3) setchr1r(0x10, A, bank | (V & mask)); @@ -665,6 +664,15 @@ static void M52CW(uint32 A, uint8 V) { setchr1(A, bank | (V & mask)); } +static void M52S14CW(uint32 A, uint8 V) { + uint32 mask = 0xFF ^ ((EXPREGS[0] & 0x40) << 1); + uint32 bank = EXPREGS[0] <<3 &0x80 | EXPREGS[0] <<7 &0x300; + if (EXPREGS[0] &0x20) + setchr1r(0x10, A, bank | (V & mask)); + else + setchr1(A, bank | (V & mask)); +} + static DECLFW(M52Write) { if (EXPREGS[1]) { WRAM[A - 0x6000] = V; @@ -689,12 +697,13 @@ static void M52Power(void) { void Mapper52_Init(CartInfo *info) { GenMMC3_Init(info, 256, 256, 8, info->battery); - cwrap = M52CW; + isRevB = 0; /* For Aladdin in NT-8062 */ + cwrap = info->submapper ==14? M52S14CW: M52CW; pwrap = M52PW; info->Reset = M52Reset; info->Power = M52Power; AddExState(EXPREGS, 2, 0, "EXPR"); - if (info->iNES2 && info->submapper ==13) { + if (info->iNES2 && (info->submapper ==13 || info->submapper ==14)) { CHRRAMSIZE = 8192; CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); @@ -1086,18 +1095,79 @@ void UNLMaliSB_Init(CartInfo *info) { /* ---------------------------- Mapper 197 ------------------------------- */ -static void M197CW(uint32 A, uint8 V) { - if (A == 0x0000) - setchr4(0x0000, V >> 1); - else if (A == 0x1000) - setchr2(0x1000, V); - else if (A == 0x1400) - setchr2(0x1800, V); +static void M197S0CW(uint32 A, uint8 V) { + switch(A) { + case 0x0000: setchr2(0x0000, V); break; + case 0x0400: setchr2(0x0800, V); break; + case 0x1000: setchr2(0x1000, V); break; + case 0x1400: setchr2(0x1800, V); break; + } +} + +static void M197S1CW(uint32 A, uint8 V) { + switch(A) { + case 0x0800: setchr2(0x0000, V); break; + case 0x0C00: setchr2(0x0800, V); break; + case 0x1800: setchr2(0x1000, V); break; + case 0x1C00: setchr2(0x1800, V); break; + } +} + +static void M197S2CW(uint32 A, uint8 V) { + switch(A) { + case 0x0000: setchr2(0x0000, V); break; + case 0x0C00: setchr2(0x0800, V); break; + case 0x1000: setchr2(0x1000, V); break; + case 0x1C00: setchr2(0x1800, V); break; + } +} + +static void M197S3CW(uint32 A, uint8 V) { + switch(A) { + case 0x0000: setchr2(0x0000, V | EXPREGS[0] <<7 &0x100); break; + case 0x0400: setchr2(0x0800, V | EXPREGS[0] <<7 &0x100); break; + case 0x1000: setchr2(0x1000, V | EXPREGS[0] <<7 &0x100); break; + case 0x1400: setchr2(0x1800, V | EXPREGS[0] <<7 &0x100); break; + } +} + +static void M197S3PW(uint32 A, uint8 V) { + setprg8(A, V &(EXPREGS[0] &8? 0x0F: 0x1F) | EXPREGS[0] <<4); +} + +static DECLFW(Mapper197S3Write) { + if (A001B &0x80) { + EXPREGS[0] =V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void Mapper197S3_Reset(void) { + EXPREGS[0] =0; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void Mapper197S3_Power(void) { + EXPREGS[0] =0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7fff, Mapper197S3Write); } void Mapper197_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 512, 8, 0); - cwrap = M197CW; + GenMMC3_Init(info, 128, 512, 8, 0); + switch(info->submapper) { + case 0: cwrap =M197S0CW; break; + case 1: cwrap =M197S1CW; break; + case 2: cwrap =M197S2CW; break; + case 3: cwrap =M197S3CW; + pwrap =M197S3PW; + info->Power = Mapper197S3_Power; + info->Reset = Mapper197S3_Reset; + break; + } + AddExState(EXPREGS, 1, 0, "EXPR"); } /* ---------------------------- Mapper 198 ------------------------------- */