diff --git a/src/boards/393.c b/src/boards/393.c new file mode 100644 index 0000000..dc343cc --- /dev/null +++ b/src/boards/393.c @@ -0,0 +1,112 @@ +/* FCE Ultra - 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" +#include "mmc3.h" + +static uint8 *CHRRAM; +static uint32 CHRRAMSIZE; + +static int getPRGBank(int bank) { + if ((~bank & 1) && (MMC3_cmd & 0x40)) bank ^= 2; + return (bank & 2) ? 0xFE | (bank & 1) : DRegBuf[6 | (bank & 1)]; +} + +static void M393CW(uint32 A, uint8 V) { + if (EXPREGS[0] & 8) + setchr8r(0x10, 0); + else + setchr1(A, V & 0xFF | EXPREGS[0] << 8); +} + +static void M393PW(uint32 A, uint8 V) { + switch ((EXPREGS[0] >> 4) & 3) { + case 0: + case 1: + setprg8(A, (V & 0x0F) | (EXPREGS[0] << 4)); + break; + case 2: + setprg32(0x8000, ((getPRGBank(0) >> 2) & 3) | (EXPREGS[0] << 2)); + break; + case 3: + setprg16(0x8000, (EXPREGS[0] << 3) | (EXPREGS[1] &7)); + setprg16(0xC000, (EXPREGS[0] << 3) | 7); + break; + } +} + +static DECLFW(M393Write8) { + switch (A & 0xE000) { + case 0x8000: + case 0xA000: + MMC3_CMDWrite(A, V); + break; + case 0xC000: + case 0xE000: + MMC3_IRQWrite(A, V); + break; + } + + EXPREGS[1] = V; + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); +} + +static DECLFW(M393Write6) { + EXPREGS[0] = A & 0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M393Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M393Write6); + SetWriteHandler(0x8000, 0xFFFF, M393Write8); +} + +static void M393Reset(void) { + EXPREGS[0] = EXPREGS[1] = 0; + MMC3RegReset(); +} + +static void M393lose(void) { + GenMMC3Close(); + if (CHRRAM) + FCEU_free(CHRRAM); + CHRRAM = NULL; +} + +void Mapper393_Init(CartInfo *info) { + GenMMC3_Init(info, 1024, 512, 8, 0); + pwrap = M393PW; + cwrap = M393CW; + info->Power = M393Power; + info->Reset = M393Reset; + info->Close = M393lose; + CHRRAMSIZE = 8192; + CHRRAM = (uint8 *)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/ines.c b/src/ines.c index 0903fc2..8e7a52c 100644 --- a/src/ines.c +++ b/src/ines.c @@ -693,6 +693,7 @@ INES_BOARD_BEGIN() INES_BOARD( "SB-5013/GCL8050/841242C", 359, Mapper359_Init ) INES_BOARD( "Bitcorp 31-in-1", 360, Mapper360_Init ) INES_BOARD( "OK-411", 361, GN45_Init ) /* OK-411 is emulated together with GN-45 */ + INES_BOARD( "JY830832C", 365, Mapper364_Init ) INES_BOARD( "GN-45", 366, GN45_Init ) INES_BOARD( "Yung-08", 368, Mapper368_Init ) INES_BOARD( "Golden Mario Party II - Around the World 6-in-1", 370, Mapper370_Init ) @@ -706,6 +707,7 @@ INES_BOARD_BEGIN() INES_BOARD( "Caltron 9-in-1", 389, Mapper389_Init ) INES_BOARD( "Realtec 8031", 390, Mapper390_Init ) INES_BOARD( "NewStar 12-in-1/7-in-1", 293, Mapper293_Init ) + INES_BOARD( "820720C", 393, Mapper393_Init ) INES_BOARD( "Realtec 8210", 395, Mapper395_Init ) INES_BOARD( "BMC Super 19-in-1 (VIP19)", 401, Mapper401_Init ) INES_BOARD( "89433", 403, Mapper403_Init ) diff --git a/src/ines.h b/src/ines.h index b506702..40356a5 100644 --- a/src/ines.h +++ b/src/ines.h @@ -269,6 +269,7 @@ void Mapper357_Init(CartInfo *); void Mapper358_Init(CartInfo *); void Mapper359_Init(CartInfo *); void Mapper360_Init(CartInfo *); +void Mapper364_Init(CartInfo *); void Mapper368_Init(CartInfo *); void Mapper369_Init(CartInfo *); void Mapper370_Init(CartInfo *); @@ -286,6 +287,7 @@ void Mapper388_Init(CartInfo *); void Mapper389_Init(CartInfo *); void Mapper390_Init(CartInfo *); void Mapper391_Init(CartInfo *); +void Mapper393_Init(CartInfo *); void Mapper395_Init(CartInfo *); void Mapper396_Init(CartInfo *); void Mapper397_Init(CartInfo *);