From ff29334f5a87db73cc258f2486aef1a7941975c7 Mon Sep 17 00:00:00 2001 From: NewRisingSun <8vytz1+dhp372pv94ebg@sharklasers.com> Date: Fri, 25 Apr 2025 20:56:51 +0200 Subject: [PATCH] Added mapper 480. --- src/boards/478.c | 2 +- src/boards/480.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++ src/ines.c | 1 + src/ines.h | 1 + 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/boards/480.c diff --git a/src/boards/478.c b/src/boards/478.c index 282e90b..395a9aa 100644 --- a/src/boards/478.c +++ b/src/boards/478.c @@ -30,7 +30,7 @@ static void PRGWrap(uint32 A, uint8 V) { static void CHRWrap(uint32 A, uint8 V) { int chrAND =EXPREGS[0] &8 && EXPREGS[0] &4? 0x1F: 0x7F; - setchr1(A, V &chrAND | EXPREGS[0] << 5&~chrAND); + setchr1(A, V &chrAND | EXPREGS[0] <<5 &~chrAND); } static DECLFW(WriteReg) { diff --git a/src/boards/480.c b/src/boards/480.c new file mode 100644 index 0000000..a7b73a8 --- /dev/null +++ b/src/boards/480.c @@ -0,0 +1,113 @@ +/* FCEUmm - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2025 NewRisingSun + * + * 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" + +uint8 submapper; +static uint8 *CHRRAM =NULL; +static uint32 CHRRAMSIZE; + +static void PRGWrap0(uint32 A, uint8 V) { + int prgAND =EXPREGS[0] &0x20? 0x1F: 0x0F; + setprg8(A, V &prgAND | EXPREGS[0] <<4 &~prgAND); +} + +static void CHRWrap0(uint32 A, uint8 V) { + int chrAND =EXPREGS[0] &0x20? 0xFF: 0x7F; + setchr1(A, V &chrAND | EXPREGS[0] <<7 &~chrAND); +} + +static void PRGWrap1(uint32 A, uint8 V) { + int prgAND =(EXPREGS[0] &0x1F) ==0x1F? 0x1F: 0x0F; + setprg8(A, V &prgAND | EXPREGS[0] <<4 &~prgAND); +} + +static void CHRWrap1(uint32 A, uint8 V) { + int chrAND =(EXPREGS[0] &0x1F) ==0x19? 0xFF: 0x7F; + if (EXPREGS[0] &0x20) + setchr8r(0x10, 0); + else + setchr1(A, V &chrAND | EXPREGS[0] <<7 &~chrAND); +} + +static void PRGWrap2(uint32 A, uint8 V) { + int prgAND =(EXPREGS[0] &0x0E) ==0x0E? 0x1F: 0x0F; + if (EXPREGS[0] &0x20) + setprg32(0x8000, EXPREGS[1] &3 | EXPREGS[0] <<2 &~3); + else + setprg8(A, V &prgAND | EXPREGS[0] <<4 &~prgAND); +} + +static void CHRWrap2(uint32 A, uint8 V) { + int chrAND =(EXPREGS[0] &0x0F) ==0x03 || (EXPREGS[0] &0x0F) ==0x0F? 0xFF: 0x7F; + if (EXPREGS[0] &0x10) { + setchr2(0x0000, DRegBuf[0] &0xFE | 0x400); + setchr2(0x0800, DRegBuf[1] |0x01 | 0x400); + setchr2(0x1000, DRegBuf[2] | 0x400); + setchr2(0x1800, DRegBuf[5] | 0x400); + } else + setchr1(A, V &chrAND | EXPREGS[0] <<7 &~chrAND); +} + +static DECLFW(WriteReg) { + if (submapper ==2 && EXPREGS[0] &0x30) + EXPREGS[1] =A &0x100? (A >>4): (V <<1 &2 | V >>4 &1); + else + EXPREGS[0] =A &0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void Power(void) { + EXPREGS[0] =0; + EXPREGS[1] =3; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, WriteReg); +} + +static void Reset(void) { + EXPREGS[0] =0; + EXPREGS[1] =3; + MMC3RegReset(); +} + +static void Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM =NULL; +} + +void Mapper480_Init(CartInfo *info) { + submapper =info->submapper; + GenMMC3_Init(info, 256, 256, info->iNES2? (info->PRGRamSize + info->PRGRamSaveSize) /1024: 8, info->battery); + pwrap = submapper ==2? PRGWrap2: submapper==1? PRGWrap1: PRGWrap0; + cwrap = submapper ==2? CHRWrap2: submapper==1? CHRWrap1: CHRWrap0; + info->Power = Power; + info->Reset = Reset; + info->Close = Close; + AddExState(EXPREGS, 2, 0, "EXPR"); + if (submapper ==1) { + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + } +} diff --git a/src/ines.c b/src/ines.c index 2affbc5..52514f3 100644 --- a/src/ines.c +++ b/src/ines.c @@ -900,6 +900,7 @@ INES_BOARD_BEGIN() INES_BOARD( "Croaky Karaoke", 476, Mapper476_Init ) INES_BOARD( "15-in-1", 477, Mapper477_Init ) INES_BOARD( "WE7HGX", 478, Mapper478_Init ) + INES_BOARD( "480", 480, Mapper480_Init ) INES_BOARD( "045N", 481, Mapper481_Init ) INES_BOARD( "ESTIQUE", 484, Mapper484_Init ) INES_BOARD( "AVE NINA-08", 487, Mapper487_Init ) diff --git a/src/ines.h b/src/ines.h index f7973a9..899f1e8 100644 --- a/src/ines.h +++ b/src/ines.h @@ -379,6 +379,7 @@ void Mapper475_Init(CartInfo *); void Mapper476_Init(CartInfo *); void Mapper477_Init(CartInfo *); void Mapper478_Init(CartInfo *); +void Mapper480_Init(CartInfo *); void Mapper481_Init(CartInfo *); void Mapper484_Init(CartInfo *); void Mapper487_Init(CartInfo *);