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/boards/224.c b/src/boards/224.c index 8fd7a19..7c885b7 100644 --- a/src/boards/224.c +++ b/src/boards/224.c @@ -28,7 +28,7 @@ #include "mmc3.h" static void M224PW(uint32 A, uint8 V) { - setprg8(A, V & 0x3f | (EXPREGS[0] << 4) & 0x40); + setprg8(A, (V & 0x3f) | ((EXPREGS[0] << 4) & 0x40)); } static DECLFW(Mapper224Write) { diff --git a/src/boards/28.c b/src/boards/28.c index 2cb95f0..4fdd088 100644 --- a/src/boards/28.c +++ b/src/boards/28.c @@ -72,51 +72,51 @@ static void Sync() { break; case 0x10: case 0x14: - prglo = outb & ~2 | prg << 1 & 2; - prghi = outb & ~2 | prg << 1 & 2 | 1; + prglo = (outb & ~2) | (prg << 1 & 2); + prghi = (outb & ~2) | (prg << 1 & 2) | 1; break; case 0x20: case 0x24: - prglo = outb & ~6 | prg << 1 & 6; - prghi = outb & ~6 | prg << 1 & 6 | 1; + prglo = (outb & ~6) | (prg << 1 & 6); + prghi = (outb & ~6) | (prg << 1 & 6) | 1; break; case 0x30: case 0x34: - prglo = outb & ~14 | prg << 1 & 14; - prghi = outb & ~14 | prg << 1 & 14 | 1; + prglo = (outb & ~14) | (prg << 1 & 14); + prghi = (outb & ~14) | (prg << 1 & 14) | 1; break; /* bottom fixed modes */ case 0x08: prglo = outb; - prghi = outb | prg & 1; + prghi = outb | (prg & 1); break; case 0x18: prglo = outb; - prghi = outb & ~2 | prg & 3; + prghi = (outb & ~2) | (prg & 3); break; case 0x28: prglo = outb; - prghi = outb & ~6 | prg & 7; + prghi = (outb & ~6) | (prg & 7); break; case 0x38: prglo = outb; - prghi = outb & ~14 | prg & 15; + prghi = (outb & ~14) | (prg & 15); break; /* top fixed modes */ case 0x0c: - prglo = outb | prg & 1; + prglo = outb | (prg & 1); prghi = outb | 1; break; case 0x1c: - prglo = outb & ~2 | prg & 3; + prglo = (outb & ~2) | (prg & 3); prghi = outb | 1; break; case 0x2c: - prglo = outb & ~6 | prg & 7; + prglo = (outb & ~6) | (prg & 7); prghi = outb | 1; break; case 0x3c: - prglo = outb & ~14 | prg & 15; + prglo = (outb & ~14) | (prg & 15); prghi = outb | 1; break; } diff --git a/src/boards/KS7032.c b/src/boards/KS7032.c index 7a8bdfc..41739af 100644 --- a/src/boards/KS7032.c +++ b/src/boards/KS7032.c @@ -93,7 +93,7 @@ static DECLFW(UNLKS7032Write) { case 0xF000: { uint8 bank = (cmd - 1); if (bank < 3) - reg[bank] = reg[bank] & 0x10 | V & 0x0F; + reg[bank] = (reg[bank] & 0x10) | (V & 0x0F); else if (bank < 4) reg[bank] = V; Sync(); @@ -101,7 +101,7 @@ static DECLFW(UNLKS7032Write) { case 0xF000: A &= 3; if (A < 3) - reg[bank] = reg[bank] & 0x0F | V & 0x10; + reg[bank] = (reg[bank] & 0x0F) | (V & 0x10); Sync(); break; case 0xF800: diff --git a/src/boards/addrlatch.c b/src/boards/addrlatch.c index ec1a3f1..86a2e72 100644 --- a/src/boards/addrlatch.c +++ b/src/boards/addrlatch.c @@ -223,7 +223,7 @@ static void M63Sync(void) { } void Mapper63_Init(CartInfo *info) { - Latch_Init(info, M63Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); + Latch_Init(info, M63Sync, M63Read, 0x0000, 0x8000, 0xFFFF, 0); } /*------------------ Map 092 ---------------------------*/ diff --git a/src/ines.c b/src/ines.c index ee468e6..94f6087 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 PJ-008", 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 *);