diff --git a/src/boards/375.c b/src/boards/375.c new file mode 100644 index 0000000..93d9ec1 --- /dev/null +++ b/src/boards/375.c @@ -0,0 +1,125 @@ +/* FCEUmm - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2022 negativeExponent + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "mapinc.h" + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static uint16 addrlatch; +static uint8 datalatch; + +static void Sync(void) { + uint32 S = addrlatch & 1; + uint32 p = ((addrlatch >> 2) & 0x1F) + ((addrlatch & 0x100) >> 3) + ((addrlatch & 0x400) >> 4); + uint32 L = (addrlatch >> 9) & 1; + uint32 p_8000 = p; + + if ((addrlatch >> 11) & 1) + p_8000 = (p & 0x7E) | (datalatch & 7); + + if ((addrlatch >> 7) & 1) { + if (S) { + setprg32(0x8000, p >> 1); + } else { + setprg16(0x8000, p_8000); + setprg16(0xC000, p); + } + } else { + if (S) { + if (L) { + setprg16(0x8000, p_8000 & 0x7E); + setprg16(0xC000, p | 7); + } else { + setprg16(0x8000, p_8000 & 0x7E); + setprg16(0xC000, p & 0x78); + } + } else { + if (L) { + setprg16(0x8000, p_8000); + setprg16(0xC000, p | 7); + } else { + setprg16(0x8000, p_8000); + setprg16(0xC000, p & 0x78); + } + } + } + + if ((addrlatch & 0x80) == 0x80) + /* CHR-RAM write protect hack, needed for some multicarts */ + SetupCartCHRMapping(0, CHRptr[0], 0x2000, 0); + else + SetupCartCHRMapping(0, CHRptr[0], 0x2000, 1); + + setmirror(((addrlatch >> 1) & 1) ^ 1); + setchr8(0); + setprg8r(0x10, 0x6000, 0); +} + +static DECLFR(M375Read) { + return CartBR(A); +} + +static DECLFW(M375Write) { + if (addrlatch & 0x800) + datalatch = V; + else { + addrlatch = A; + datalatch = V; + } + Sync(); +} + +static void M375Reset(void) { + addrlatch = 0; + datalatch = 0; + Sync(); +} + +static void M375Power(void) { + addrlatch = 0; + datalatch = 0; + Sync(); + setchr8(0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M375Write); + if (WRAMSIZE) { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper375_Init(CartInfo *info) { + info->Power = M375Power; + info->Reset = M375Reset; + GameStateRestore = StateRestore; + AddExState(&addrlatch, 2, 0, "ADDR"); + AddExState(&datalatch, 1, 0, "DATA"); + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} diff --git a/src/ines.c b/src/ines.c index 524475e..37b3d1c 100644 --- a/src/ines.c +++ b/src/ines.c @@ -769,6 +769,7 @@ INES_BOARD_BEGIN() INES_BOARD( "Golden Mario Party II - Around the World 6-in-1", 370, Mapper370_Init ) INES_BOARD( "MMC3 PIRATE SFC-12", 372, Mapper372_Init ) INES_BOARD( "95/96 Super HiK 4-in-1", 374, Mapper374_Init ) + INES_BOARD( "135-in-1", 375, Mapper375_Init ) INES_BOARD( "YY841155C", 376, Mapper376_Init ) INES_BOARD( "JY-111/JY-112", 377, Mapper377_Init ) INES_BOARD( "42 to 80,000 (970630C)", 380, Mapper380_Init ) diff --git a/src/ines.h b/src/ines.h index bfcf03c..6307777 100644 --- a/src/ines.h +++ b/src/ines.h @@ -280,6 +280,7 @@ void Mapper369_Init(CartInfo *); void Mapper370_Init(CartInfo *); void Mapper372_Init(CartInfo *); void Mapper374_Init(CartInfo *); +void Mapper375_Init(CartInfo *); void Mapper376_Init(CartInfo *); void Mapper377_Init(CartInfo *); void Mapper380_Init(CartInfo *);