diff --git a/src/boards/410.c b/src/boards/410.c new file mode 100644 index 0000000..2c0bfa3 --- /dev/null +++ b/src/boards/410.c @@ -0,0 +1,89 @@ +/* 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 + */ + +/* NES 2.0 Mapper 410 is a variant of mapper 45 where the + * ASIC's PRG A21/CHR A20 output (set by bit 6 of the third write to $6000) + * selects between regularly-banked CHR-ROM (=0) and 8 KiB of unbanked CHR-RAM (=1). + * It is used solely for the Super 8-in-1 - 98格鬥天王+熱血 (JY-302) multicart. + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM; + +static void M410CW(uint32 A, uint8 V) { + if (!(EXPREGS[2] & 0x40)) { + uint32 NV = V; + NV &= (1 << ((EXPREGS[2] & 7) + 1)) - 1; + NV |= EXPREGS[0] | ((EXPREGS[2] & 0xF0) << 4); + setchr1(A, NV); + } else + setchr8r(0x10, 0); +} + +static void M410PW(uint32 A, uint8 V) { + uint32 MV = V & ((EXPREGS[3] & 0x3F) ^ 0x3F); + MV |= EXPREGS[1]; + MV |= ((EXPREGS[2] & 0x40) << 2); + setprg8(A, MV); +/* FCEU_printf("1:%02x 2:%02x 3:%02x A=%04x V=%03x\n",EXPREGS[1],EXPREGS[2],EXPREGS[3],A,MV); */ +} + +static DECLFW(M410Write) { + EXPREGS[EXPREGS[4]] = V; + EXPREGS[4] = (EXPREGS[4] + 1) & 3; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M410Close(void) { + GenMMC3Close(); + if (CHRRAM) + FCEU_free(CHRRAM); + CHRRAM = NULL; +} + +static void M410Reset(void) { + EXPREGS[0] = EXPREGS[1] = EXPREGS[3] = EXPREGS[4] = 0; + EXPREGS[2] = 0x0F; + MMC3RegReset(); +} + +static void M410Power(void) { + GenMMC3Power(); + EXPREGS[0] = EXPREGS[1] = EXPREGS[3] = EXPREGS[4] = 0; + EXPREGS[2] = 0x0F; + SetWriteHandler(0x6000, 0x7FFF, M410Write); +} + +void Mapper410_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M410CW; + pwrap = M410PW; + info->Reset = M410Reset; + info->Power = M410Power; + info->Close = M410Close; + AddExState(EXPREGS, 5, 0, "EXPR"); + + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CRAM"); +} \ No newline at end of file diff --git a/src/ines.c b/src/ines.c index cd95bdd..29b43aa 100644 --- a/src/ines.c +++ b/src/ines.c @@ -797,6 +797,7 @@ INES_BOARD_BEGIN() INES_BOARD( "YY850437C", 396, Mapper396_Init ) INES_BOARD( "YY850439C", 397, Mapper397_Init ) INES_BOARD( "831019C J-2282", 402, J2282_Init ) + INES_BOARD( "JY-302", 410, Mapper410_Init ) INES_BOARD( "SC871115C", 421, Mapper421_Init ) INES_BOARD( "AB-G1L/WELL-NO-DG450", 428, Mapper428_Init ) INES_BOARD( "LIKO BBG-235-8-1B", 429, Mapper429_Init ) diff --git a/src/ines.h b/src/ines.h index fcb7ce5..a211b85 100644 --- a/src/ines.h +++ b/src/ines.h @@ -290,6 +290,7 @@ void Mapper396_Init(CartInfo *); void Mapper397_Init(CartInfo *); void Mapper401_Init(CartInfo *); void Mapper403_Init(CartInfo *); +void Mapper410_Init(CartInfo *); void Mapper411_Init(CartInfo *); void Mapper421_Init(CartInfo *); void Mapper422_Init(CartInfo *);