From cac8c8fa1cc5fd648d30cb7a7a7f049a81979d16 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Sat, 12 Feb 2022 10:13:30 +0800 Subject: [PATCH] Add mapper 417 --- src/boards/417.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ines.c | 1 + src/ines.h | 1 + 3 files changed, 82 insertions(+) create mode 100644 src/boards/417.c diff --git a/src/boards/417.c b/src/boards/417.c new file mode 100644 index 0000000..bea2e35 --- /dev/null +++ b/src/boards/417.c @@ -0,0 +1,80 @@ +/* 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 preg[4]; +static uint8 creg[8]; +static uint8 nt[4]; +static uint8 IRQa; +static uint16 IRQCount; + +static SFORMAT StateRegs[] = { + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { nt, 4, "NREG" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + int i; + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); + setmirrorw(nt[0] & 1, nt[1] & 1, nt[2] & 1, nt[3] & 1); +} + +static DECLFW(M417Write) { + switch ((A >> 4) & 7) { + case 0: preg[A & 3] = V; Sync(); break; + case 1: creg[0 | (A & 3)] = V; Sync(); break; + case 2: creg[4 | (A & 3)] = V; Sync(); break;break; + case 3: IRQCount = 0; IRQa = 1; break; + case 4: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 5: nt[A & 3] = V; Sync(); break; + } +} + +static void M417Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M417Write); +} + +static void M417IRQHook(int a) { + IRQCount += a; + if (IRQa && IRQCount > 1024) + X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper417_Init(CartInfo *info) { + info->Power = M417Power; + MapIRQHook = M417IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/ines.c b/src/ines.c index ffb8dc3..8c9035d 100644 --- a/src/ines.c +++ b/src/ines.c @@ -714,6 +714,7 @@ INES_BOARD_BEGIN() INES_BOARD( "A88S-1", 411, Mapper411_Init ) INES_BOARD( "0353", 415, Mapper415_Init ) INES_BOARD( "4-in-1/N-32", 416, Mapper416_Init ) + INES_BOARD( "", 417, Mapper417_Init ) INES_BOARD( "BS-400R/BS-4040", 422, Mapper422_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 884fd95..90f3fa6 100644 --- a/src/ines.h +++ b/src/ines.h @@ -298,6 +298,7 @@ void Mapper410_Init(CartInfo *); void Mapper411_Init(CartInfo *); void Mapper415_Init(CartInfo *); void Mapper416_Init(CartInfo *); +void Mapper417_Init(CartInfo *); void Mapper421_Init(CartInfo *); void Mapper422_Init(CartInfo *); void Mapper428_Init(CartInfo *);