From ec19b07b4d36cfe784bdac61260e1adb2e45527d Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Fri, 12 Jul 2019 23:35:11 +0800 Subject: [PATCH] Mapper 226: Updated and remove duplicate mapper - Updated mapper 226 to support 1.5mb carts, which in turn makes Unif Ghostbusters63n1 a duplicate. - Unif 42in1ResetSwitch switch to mapper 233 --- src/boards/bmc42in1r.c | 31 +++++++++-- src/boards/ghostbusters63in1.c | 96 ---------------------------------- src/cart.h | 6 ++- src/ines.c | 3 ++ src/unif.c | 11 ++-- 5 files changed, 43 insertions(+), 104 deletions(-) delete mode 100644 src/boards/ghostbusters63in1.c diff --git a/src/boards/bmc42in1r.c b/src/boards/bmc42in1r.c index 6f7a2b3..ce66030 100644 --- a/src/boards/bmc42in1r.c +++ b/src/boards/bmc42in1r.c @@ -3,6 +3,7 @@ * Copyright notice for this file: * Copyright (C) 2005 CaH4e3 * Copyright (C) 2009 qeed + * Copyright (C) 2019 Libretro Team * * 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 @@ -22,10 +23,18 @@ * */ +/* Updated 2019-07-12 + * Mapper 266 - Updated and combine UNIF Ghostbusters63in1 board (1.5 MB carts), different bank order + * - some 1MB carts can switch game lists using Select + * Mapper 233 - UNIF 42in1ResetSwitch - reset-based switching + */ + #include "mapinc.h" +static uint8 reorder_banks = 0; static uint8 isresetbased = 0; static uint8 latche[2], reset; +static uint8 banks[4] = { 0, 0, 1, 2 }; static SFORMAT StateRegs[] = { { &reset, 1, "RST" }, @@ -34,11 +43,17 @@ static SFORMAT StateRegs[] = }; static void Sync(void) { - uint8 bank; + uint8 bank = 0; + uint8 base = ((latche[0] & 0x80) >> 7) | ((latche[1] & 1) << 1); + if (isresetbased) bank = (latche[0] & 0x1f) | (reset << 5) | ((latche[1] & 1) << 6); - else - bank = (latche[0] & 0x1f) | ((latche[0] & 0x80) >> 2) | ((latche[1] & 1) << 6); + else { + if (reorder_banks) /* for 1536 KB prg roms */ + base = banks[base]; + bank = (base << 5) | (latche[0] & 0x1f); + } + if (!(latche[0] & 0x20)) setprg32(0x8000, bank >> 1); else { @@ -65,19 +80,29 @@ static void StateRestore(int version) { Sync(); } +static void M226Reset(void) { + latche[0] = latche[1] = reset = 0; + Sync(); +} + void Mapper226_Init(CartInfo *info) { isresetbased = 0; + /* 1536KiB PRG roms have different bank order */ + reorder_banks = ((info->prgRom * 16) == 1536) ? 1 : 0; info->Power = M226Power; + info->Reset = M226Reset; AddExState(&StateRegs, ~0, 0, 0); GameStateRestore = StateRestore; } static void M233Reset(void) { + latche[0] = latche[1] = 0; reset ^= 1; Sync(); } void Mapper233_Init(CartInfo *info) { + reorder_banks = 0; isresetbased = 1; info->Power = M226Power; info->Reset = M233Reset; diff --git a/src/boards/ghostbusters63in1.c b/src/boards/ghostbusters63in1.c deleted file mode 100644 index bdd1f1e..0000000 --- a/src/boards/ghostbusters63in1.c +++ /dev/null @@ -1,96 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2007 CaH4e3 - * - * 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 - * 63in1 ghostbusters - */ - -#include "mapinc.h" - -static uint8 reg[2], bank; -static uint8 banks[4] = { 0, 0, 1, 2 }; -static uint8 *CHRROM = NULL; -static uint32 CHRROMSIZE; - -static SFORMAT StateRegs[] = -{ - { reg, 2, "REGS" }, - { &bank, 1, "BANK" }, - { 0 } -}; - -static void Sync(void) { - if (reg[0] & 0x20) { - setprg16(0x8000, (banks[bank] << 5) | (reg[0] & 0x1F)); - setprg16(0xC000, (banks[bank] << 5) | (reg[0] & 0x1F)); - } else - setprg32(0x8000, ((banks[bank] << 5) | (reg[0] & 0x1F)) >> 1); - if (reg[1] & 2) - setchr8r(0x10, 0); - else - setchr8(0); - setmirror((reg[0] & 0x40) >> 6); -} - -static DECLFW(BMCGhostbusters63in1Write) { - reg[A & 1] = V; - bank = ((reg[0] & 0x80) >> 7) | ((reg[1] & 1) << 1); -/* FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank); */ - Sync(); -} - -static DECLFR(BMCGhostbusters63in1Read) { - if (bank == 1) - return X.DB; - else - return CartBR(A); -} - -static void BMCGhostbusters63in1Power(void) { - reg[0] = reg[1] = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, BMCGhostbusters63in1Read); - SetWriteHandler(0x8000, 0xFFFF, BMCGhostbusters63in1Write); -} - -static void BMCGhostbusters63in1Reset(void) { - reg[0] = reg[1] = 0; -} - -static void StateRestore(int version) { - Sync(); -} - -static void BMCGhostbusters63in1Close(void) { - if (CHRROM) - FCEU_gfree(CHRROM); - CHRROM = NULL; -} - -void BMCGhostbusters63in1_Init(CartInfo *info) { - info->Reset = BMCGhostbusters63in1Reset; - info->Power = BMCGhostbusters63in1Power; - info->Close = BMCGhostbusters63in1Close; - - CHRROMSIZE = 8192; /* dummy CHRROM, VRAM disable */ - CHRROM = (uint8*)FCEU_gmalloc(CHRROMSIZE); - SetupCartPRGMapping(0x10, CHRROM, CHRROMSIZE, 0); - AddExState(CHRROM, CHRROMSIZE, 0, "CROM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} diff --git a/src/cart.h b/src/cart.h index 66f3e83..56875da 100644 --- a/src/cart.h +++ b/src/cart.h @@ -20,8 +20,10 @@ typedef struct { * set to mapper 4. */ int battery; /* Presence of an actual battery. */ - int prgRam; /* prg ram size (volatile) */ - int chrRam; /* chr ram size (volatile) */ + int prgRom; /* total prg rom size in 16 K chunks */ + int chrRom; /* total chr rom size in 8 K chunks */ + int prgRam; /* prg ram size (volatile) */ + int chrRam; /* chr ram size (volatile) */ int prgRam_battery; /* prg ram size (non-volatile or battery backed) */ int chrRam_battery; /* chr ram size (non-volatile or battery backed) */ int region; /* video system timing (ntsc, pal, dendy */ diff --git a/src/ines.c b/src/ines.c index 1db9530..781f4d3 100644 --- a/src/ines.c +++ b/src/ines.c @@ -819,6 +819,9 @@ int iNESLoad(const char *name, FCEUFILE *fp) { } else if (((prgRom * 0x4000) + (chrRom * 0x2000)) < filesize) FCEU_PrintError(" File contains %llu bytes of unused data\n", filesize - ((prgRom * 0x4000) + (chrRom * 0x2000))); + iNESCart.prgRom = prgRom; + iNESCart.chrRom = chrRom; + ROM_size = uppow2(prgRom); if (chrRom) diff --git a/src/unif.c b/src/unif.c index a4a5fc0..51502a4 100644 --- a/src/unif.c +++ b/src/unif.c @@ -414,7 +414,7 @@ static BMAPPING bmap[] = { { "22211", 132, UNL22211_Init, 0 }, { "3D-BLOCK", 355, UNL3DBlock_Init, 0 }, { "411120-C", 287, BMC411120C_Init, 0 }, - { "42in1ResetSwitch", 226, Mapper226_Init, 0 }, + { "42in1ResetSwitch", 233, Mapper233_Init, 0 }, { "43272", 227, UNL43272_Init, 0 }, { "603-5052", 238, UNL6035052_Init, 0 }, { "64in1NoRepeat", 314, BMC64in1nr_Init, 0 }, @@ -452,7 +452,7 @@ static BMAPPING bmap[] = { { "GK-192", NO_INES, BMCGK192_Init, 0 }, /* mapper 58? */ { "GS-2004", 283, BMCGS2004_Init, 0 }, { "GS-2013", 283, BMCGS2013_Init, 0 }, - { "Ghostbusters63in1", NO_INES, BMCGhostbusters63in1_Init, 0 }, /* similar to 226 but different bank order */ + { "Ghostbusters63in1", 226, Mapper226_Init, 0 }, { "H2288", 123, UNLH2288_Init, 0 }, { "HKROM", 4, HKROM_Init, 0 }, { "KOF97", 263, UNLKOF97_Init, 0 }, @@ -585,7 +585,7 @@ static BMAPPING bmap[] = { { "JC-016-2", 205, Mapper205_Init, 0 }, { "AX-40G", 527, UNLAX40G_Init, 0 }, { " BMC-STREETFIGTER-GAME4IN1", NO_INES, BMCSFGAME4IN1_Init, 0 }, /* mapper 49? submapper 1*/ - { "G631", NO_INES, BMCGhostbusters63in1_Init, 0 }, /* duplicate, probably wrong name */ + { "G631", 226, Mapper226_Init, 0 }, /* duplicate, probably wrong name */ { "BJ-56", 526, UNLBJ56_Init, 0 }, { "L6IN1", 345, BMCL6IN1_Init, 0 }, { "CTC-12IN1", 337, BMCCTC12IN1_Init, 0 }, @@ -731,6 +731,11 @@ int UNIFLoad(const char *name, FCEUFILE *fp) { if (!LoadUNIFChunks(fp)) goto aborto; + UNIFCart.prgRom = (UNIF_PRGROMSize / 0x1000) + ((UNIF_PRGROMSize % 0x1000) ? 1 : 0); + UNIFCart.prgRom = (UNIFCart.prgRom >> 2) + ((UNIFCart.prgRom & 3) ? 1: 0); + UNIFCart.chrRom = (UNIF_CHRROMSize / 0x400) + ((UNIF_CHRROMSize % 0x400) ? 1 : 0); + UNIFCart.chrRom = (UNIFCart.chrRom >> 3) + ((UNIFCart.chrRom & 7) ? 1: 0); + ROM_size = FixRomSize(UNIF_PRGROMSize, 2048); if (UNIF_CHRROMSize) VROM_size = FixRomSize(UNIF_CHRROMSize, 8192);