|
| 1 | +/* FCEUmm - NES/Famicom Emulator |
| 2 | + * |
| 3 | + * Copyright notice for this file: |
| 4 | + * Copyright (C) 2025 negativeExponent |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +/* NES 2.0 Mapper 270 denotes OneBus console multicarts that use the consoles' |
| 23 | + * universal input/output (UIO) register $412C to bankswitch higher-order PRG |
| 24 | + * address lines or several PRG chips, and select CHR-RAM via $4242.*/ |
| 25 | + |
| 26 | +/* TODO: Family Pocket 638-in-1 freeze on jumper enable */ |
| 27 | + |
| 28 | +#include "mapinc.h" |
| 29 | +#include "onebus.h" |
| 30 | + |
| 31 | +static uint8 reg4242; /* $4242 */ |
| 32 | +static uint8 dipsw; /* jumper */ |
| 33 | + |
| 34 | +static void Sync(void) { |
| 35 | + uint16 mblock = 0; |
| 36 | + switch (iNESCart.submapper) { |
| 37 | + case 1: |
| 38 | + mblock |= (onebus.cpu41xx[0x2C] & 0x02) << 10; /* PRG/CHR A24 */ |
| 39 | + break; |
| 40 | + case 2: |
| 41 | + mblock |= (onebus.cpu41xx[0x2C] & 0x02) << 10; /* PRG/CHR A24 */ |
| 42 | + mblock |= (onebus.cpu41xx[0x2C] & 0x01) << 11; /* PRG/CHR A25 */ |
| 43 | + break; |
| 44 | + case 3: |
| 45 | + mblock |= (onebus.cpu41xx[0x2C] & 0x04) << 9; /* PRG/CHR A24 */ |
| 46 | + break; |
| 47 | + case 0: |
| 48 | + default: |
| 49 | + mblock |= (onebus.cpu41xx[0x2C] & 0x02) << 10; /* PRG/CHR A24 */ |
| 50 | + mblock |= (onebus.cpu41xx[0x2C] & 0x04) << 9; /* PRG/CHR A24 */ |
| 51 | + mblock |= (onebus.cpu41xx[0x2C] & 0x01) << 11; /* PRG/CHR A25 */ |
| 52 | + break; |
| 53 | + } |
| 54 | + OneBus_FixPRG(0x07FF, mblock); |
| 55 | + if (reg4242 & 0x01) { |
| 56 | + /* CHR-RAM enabled, use 8K unbancked CHR RAM */ |
| 57 | + setchr8(0); |
| 58 | + } else { |
| 59 | + OneBus_FixCHR(0x3FFF, mblock << 3); |
| 60 | + } |
| 61 | + OneBus_FixMIR(); |
| 62 | +} |
| 63 | + |
| 64 | +static DECLFR(M270ReadJumperDetect) { |
| 65 | + return dipsw << 3; |
| 66 | +} |
| 67 | + |
| 68 | +static DECLFW(M270WriteCHRRAMEnable) { |
| 69 | + reg4242 = V; |
| 70 | + if (CHRptr[0] && (reg4242 & 0x01)) { |
| 71 | + SetupCartCHRMapping(0, CHRptr[0], CHRsize[0], TRUE); |
| 72 | + } else { |
| 73 | + SetupCartCHRMapping(0, PRGptr[0], PRGsize[0], FALSE); |
| 74 | + } |
| 75 | + Sync(); |
| 76 | +} |
| 77 | + |
| 78 | +static void M270Power(void) { |
| 79 | + dipsw = 0; |
| 80 | + reg4242 = 0; |
| 81 | + OneBus_Power(); |
| 82 | + SetReadHandler(0x412C, 0x412C, M270ReadJumperDetect); |
| 83 | + SetWriteHandler(0x4242, 0x4242, M270WriteCHRRAMEnable); |
| 84 | +} |
| 85 | + |
| 86 | +static void M270Reset(void) { |
| 87 | + SetupCartCHRMapping(0, PRGptr[0], PRGsize[0], FALSE); |
| 88 | + dipsw = !dipsw; /* toggle jumper */ |
| 89 | + reg4242 = 0; |
| 90 | + onebus.cpu41xx[0x2C] = 0; |
| 91 | + OneBus_Reset(); |
| 92 | +} |
| 93 | + |
| 94 | +void Mapper270_Init(CartInfo *info) { |
| 95 | + int ws = (info->PRGRamSize + info->PRGRamSaveSize) / 1024; |
| 96 | + |
| 97 | + if (!ws) { |
| 98 | + ws = 8; |
| 99 | + } |
| 100 | + |
| 101 | + OneBus_Init(info, Sync, ws, info->battery); |
| 102 | + info->Power = M270Power; |
| 103 | + info->Reset = M270Reset; |
| 104 | + |
| 105 | + AddExState(®4242, 1, 0, "CHRM"); |
| 106 | + AddExState(&dipsw, 1, 0, "DPSW"); |
| 107 | +} |
0 commit comments