From 2d82ec73e6a86ff175658478ac7da0fb88966cd7 Mon Sep 17 00:00:00 2001 From: libretroadmin Date: Sun, 9 Jun 2024 18:27:44 +0200 Subject: [PATCH] Add mapper 430 --- src/boards/430.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ src/boards/mmc3.c | 4 +++ src/boards/mmc3.h | 1 + src/ines.c | 1 + src/ines.h | 1 + 5 files changed, 73 insertions(+) create mode 100644 src/boards/430.c diff --git a/src/boards/430.c b/src/boards/430.c new file mode 100644 index 0000000..8fc0227 --- /dev/null +++ b/src/boards/430.c @@ -0,0 +1,66 @@ +/* FCEUmm - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2023 + * + * 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" +#include "mmc3.h" + +static void M430CW(uint32 A, uint8 V) { + uint8 mask = (EXPREGS[0] & 4) ? 0x7F : 0xFF; + setchr1(A, ((EXPREGS[0] << 6) & ~mask) | (V & mask)); +} + +static void M430PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 8) { + setprg8(0x8000, ((EXPREGS[0] << 4) & 0x30) | ((DRegBuf[6] & ~2) & 0x0F)); + setprg8(0xA000, ((EXPREGS[0] << 4) & 0x30) | ((DRegBuf[7] & ~2) & 0x0F)); + setprg8(0xC000, ((EXPREGS[0] << 4) & 0x30) | ((DRegBuf[6] | 2) & 0x0F)); + setprg8(0xE000, ((EXPREGS[0] << 4) & 0x30) | ((DRegBuf[7] | 2) & 0x0F)); + } else { + setprg8(A, ((EXPREGS[0] << 4) & 0x30) | (V & 0x0F)); + } +} + +static DECLFW(M430Write) { + if (MMC3CanWriteToWRAM()) { + EXPREGS[0] = A & 0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void M430Reset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +static void M430Power(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M430Write); +} + +void Mapper430_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + cwrap = M430CW; + pwrap = M430PW; + info->Reset = M430Reset; + info->Power = M430Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/mmc3.c b/src/boards/mmc3.c index 4e65121..f02fb84 100644 --- a/src/boards/mmc3.c +++ b/src/boards/mmc3.c @@ -70,6 +70,10 @@ void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); * ---------------------------------------------------------------------- */ +int MMC3CanWriteToWRAM(void) { + return ((A001B & 0x80) && !(A001B & 0x40)); +} + void FixMMC3PRG(int V) { if (V & 0x40) { pwrap(0xC000, DRegBuf[6]); diff --git a/src/boards/mmc3.h b/src/boards/mmc3.h index b29a53e..911b635 100644 --- a/src/boards/mmc3.h +++ b/src/boards/mmc3.h @@ -20,6 +20,7 @@ void FixMMC3PRG(int V); void FixMMC3CHR(int V); DECLFW(MMC3_CMDWrite); DECLFW(MMC3_IRQWrite); +int MMC3CanWriteToWRAM(void); void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); diff --git a/src/ines.c b/src/ines.c index 517ec22..cdbdd44 100644 --- a/src/ines.c +++ b/src/ines.c @@ -812,6 +812,7 @@ INES_BOARD_BEGIN() INES_BOARD( "BS-400R/BS-4040", 422, Mapper422_Init ) INES_BOARD( "AB-G1L/WELL-NO-DG450", 428, Mapper428_Init ) INES_BOARD( "LIKO BBG-235-8-1B", 429, Mapper429_Init ) + INES_BOARD( "831031C/T-308", 430, Mapper430_Init ) INES_BOARD( "Realtek GN-91B", 431, Mapper431_Init ) INES_BOARD( "Realtec 8090", 432, Mapper432_Init ) INES_BOARD( "NC-20MB", 433, Mapper433_Init ) diff --git a/src/ines.h b/src/ines.h index 819e5ff..88ead23 100644 --- a/src/ines.h +++ b/src/ines.h @@ -321,6 +321,7 @@ void Mapper421_Init(CartInfo *); void Mapper422_Init(CartInfo *); void Mapper428_Init(CartInfo *); void Mapper429_Init(CartInfo *); +void Mapper430_Init(CartInfo *); void Mapper431_Init(CartInfo *); void Mapper432_Init(CartInfo *); void Mapper433_Init(CartInfo *);