diff --git a/src/boards/126.c b/src/boards/126.c new file mode 100644 index 0000000..0a93910 --- /dev/null +++ b/src/boards/126.c @@ -0,0 +1,105 @@ +/* FCEUmm - NES/Famicom Emulator + * + * Copyright notice for this file: + * 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 + * 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 + */ + +/* Mapper 126, PowerJoy 84-in-1 Multicart (PJ-008*/ +/* reference from nestopia since not available in nesdev */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint16 GetExChrExBank() { + uint16 bank = (uint16)EXPREGS[0]; + return ((~bank << 0 & 0x080 & ((uint16)EXPREGS[2])) | (bank << 4 & 0x080 & bank) | + (bank << 3 & 0x100) | (bank << 5 & 0x200)); +} + +static void UpdateChrBank(void) { + uint16 bank = (uint16)EXPREGS[2] & 0x0F; + bank |= GetExChrExBank() >> 3; + setchr8(bank); +} + +static void M126CW(uint32 A, uint8 V) { + if (!(EXPREGS[3] & 0x10)) { + uint16 bank = (uint16)V & (((uint16)EXPREGS[0] & 0x80) - 1); + bank |= GetExChrExBank(); + setchr1(A, bank); + } +} + +static void M126PW(uint32 A, uint8 V) { + uint16 bank = (uint16)V; + uint16 preg = (uint16)EXPREGS[0]; + bank &= ((~preg >> 2) & 0x10) | 0x0F; + bank |= ((preg & (0x06 | (preg & 0x40) >> 6)) << 4) | ((preg & 0x10) << 3); + if (!(EXPREGS[3] & 0x03)) + setprg8(A, bank); + else if ((A - 0x8000) == ((MMC3_cmd << 8) & 0x4000)) { /* TODO: Clean this */ + if ((EXPREGS[3] & 0x3) == 0x3) + setprg32(0x8000, (bank >> 2)); + else { + setprg16(0x8000, (bank >> 1)); + setprg16(0xc000, (bank >> 1)); + } + } +} + +static DECLFW(M126Write) { + A &= 0x03; + if(A == 0x01 || A == 0x02 || ((A == 0x00 || A == 0x03) && !(EXPREGS[3] & 0x80))) { + if (EXPREGS[A] != V) { + EXPREGS[A] = V; + if (EXPREGS[3] & 0x10) + UpdateChrBank(); + else + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); + } + } +} + +void M126StateRestore(int v) { + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); + + if (EXPREGS[3] & 0x10) + UpdateChrBank(); +} + +static void M126Reset(void) { + EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0; + MMC3RegReset(); +} + +static void M126Power(void) { + EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, M126Write); +} + +void Mapper126_Init(CartInfo *info) { + GenMMC3_Init(info, 2048, 1023, 0, 0); + cwrap = M126CW; + pwrap = M126PW; + info->Power = M126Power; + info->Reset = M126Reset; + GameStateRestore = M126StateRestore; + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/src/ines.c b/src/ines.c index ee468e6..6ca2069 100644 --- a/src/ines.c +++ b/src/ines.c @@ -515,7 +515,7 @@ static BMAPPINGLocal bmap[] = { {(uint8_t*)"MMC3 PIRATE H2288", 123, UNLH2288_Init}, /* {(uint8_t*)"", 124, Mapper124_Init}, */ {(uint8_t*)"FDS LH32", 125, LH32_Init}, -/* {(uint8_t*)"", 126, Mapper126_Init}, */ + {(uint8_t*)"PowerJoy 84-in-1", 126, Mapper126_Init}, /* {(uint8_t*)"", 127, Mapper127_Init}, */ /* {(uint8_t*)"", 128, Mapper128_Init}, */ /* {(uint8_t*)"", 129, Mapper129_Init}, */ diff --git a/src/ines.h b/src/ines.h index 3e44574..75a801d 100644 --- a/src/ines.h +++ b/src/ines.h @@ -139,6 +139,7 @@ void Mapper119_Init(CartInfo *); void Mapper120_Init(CartInfo *); void Mapper121_Init(CartInfo *); void Mapper125_Init(CartInfo *); +void Mapper126_Init(CartInfo *); void Mapper134_Init(CartInfo *); void Mapper140_Init(CartInfo *); void Mapper144_Init(CartInfo *);