From 2d76eb4a0f5af32f0031a97ac9fa44d21cf618b4 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sun, 17 Dec 2017 13:39:16 +0800 Subject: [PATCH] Change *.c and *.h end-of-line character to LF change eol char to LF using dos2unix --- src/boards/01-222.c | 222 +++--- src/boards/09-034a.c | 194 +++--- src/boards/103.c | 230 +++---- src/boards/106.c | 216 +++--- src/boards/108.c | 128 ++-- src/boards/116.c | 650 +++++++++--------- src/boards/120.c | 124 ++-- src/boards/121.c | 258 +++---- src/boards/12in1.c | 146 ++-- src/boards/15.c | 220 +++--- src/boards/151.c | 118 ++-- src/boards/156.c | 240 +++---- src/boards/168.c | 162 ++--- src/boards/170.c | 124 ++-- src/boards/175.c | 158 ++--- src/boards/177.c | 162 ++--- src/boards/178.c | 354 +++++----- src/boards/18.c | 266 +++---- src/boards/183.c | 222 +++--- src/boards/185.c | 216 +++--- src/boards/186.c | 190 ++--- src/boards/187.c | 176 ++--- src/boards/189.c | 88 +-- src/boards/190.c | 180 ++--- src/boards/193.c | 148 ++-- src/boards/199.c | 194 +++--- src/boards/208.c | 156 ++--- src/boards/222.c | 202 +++--- src/boards/225.c | 178 ++--- src/boards/228.c | 170 ++--- src/boards/230.c | 156 ++--- src/boards/232.c | 138 ++-- src/boards/234.c | 158 ++--- src/boards/235.c | 126 ++-- src/boards/244.c | 154 ++--- src/boards/246.c | 172 ++--- src/boards/252.c | 270 ++++---- src/boards/253.c | 304 ++++---- src/boards/32.c | 204 +++--- src/boards/33.c | 234 +++---- src/boards/34.c | 186 ++--- src/boards/36.c | 126 ++-- src/boards/3d-block.c | 190 ++--- src/boards/40.c | 170 ++--- src/boards/411120-c.c | 128 ++-- src/boards/42.c | 166 ++--- src/boards/43.c | 184 ++--- src/boards/50.c | 168 ++--- src/boards/51.c | 168 ++--- src/boards/57.c | 160 ++--- src/boards/603-5052.c | 98 +-- src/boards/62.c | 138 ++-- src/boards/65.c | 208 +++--- src/boards/67.c | 210 +++--- src/boards/68.c | 328 ++++----- src/boards/69.c | 564 +++++++-------- src/boards/71.c | 128 ++-- src/boards/72.c | 128 ++-- src/boards/77.c | 148 ++-- src/boards/79.c | 122 ++-- src/boards/80.c | 386 +++++------ src/boards/8157.c | 170 ++--- src/boards/82.c | 196 +++--- src/boards/830118C.c | 136 ++-- src/boards/91.c | 170 ++--- src/boards/96.c | 154 ++--- src/boards/99.c | 156 ++--- src/boards/KS7012.c | 174 ++--- src/boards/KS7013.c | 154 ++--- src/boards/KS7017.c | 230 +++---- src/boards/KS7030.c | 284 ++++---- src/boards/KS7031.c | 160 ++--- src/boards/KS7032.c | 182 ++--- src/boards/KS7037.c | 252 +++---- src/boards/KS7057.c | 184 ++--- src/boards/SA-9602B.c | 122 ++-- src/boards/__dummy_mapper.c | 196 +++--- src/boards/__serial.c | 300 ++++---- src/boards/__serial.h | 62 +- src/boards/a9746.c | 150 ++-- src/boards/ac-08.c | 142 ++-- src/boards/addrlatch.c | 1016 +++++++++++++-------------- src/boards/ax5705.c | 232 +++---- src/boards/bandai.c | 928 ++++++++++++------------- src/boards/bb.c | 136 ++-- src/boards/bmc13in1jy110.c | 194 +++--- src/boards/bmc42in1r.c | 172 ++--- src/boards/bmc64in1nr.c | 166 ++--- src/boards/bmc70in1.c | 246 +++---- src/boards/bonza.c | 272 ++++---- src/boards/bs-5.c | 168 ++--- src/boards/cityfighter.c | 248 +++---- src/boards/coolboy.c | 304 ++++---- src/boards/copyfami_emu.c | 710 +++++++++---------- src/boards/copyfami_hwi.c | 1180 ++++++++++++++++---------------- src/boards/dance2000.c | 226 +++--- src/boards/datalatch.c | 1020 +++++++++++++-------------- src/boards/dream.c | 102 +-- src/boards/edu2000.c | 156 ++--- src/boards/famicombox.c | 240 +++---- src/boards/ffe.c | 306 ++++----- src/boards/ghostbusters63in1.c | 192 +++--- src/boards/gs-2004.c | 126 ++-- src/boards/gs-2013.c | 126 ++-- src/boards/h2288.c | 140 ++-- src/boards/kof97.c | 92 +-- src/boards/le05.c | 124 ++-- src/boards/lh32.c | 158 ++--- src/boards/lh53.c | 216 +++--- src/boards/mihunche.c | 136 ++-- src/boards/mmc1.c | 784 ++++++++++----------- src/boards/mmc2and4.c | 304 ++++---- src/boards/mmc3.h | 52 +- src/boards/n625092.c | 190 ++--- src/boards/onebus.c | 600 ++++++++-------- src/boards/pec-586.c | 256 +++---- src/boards/sc-127.c | 246 +++---- src/boards/sheroes.c | 158 ++--- src/boards/sl1632.c | 222 +++--- src/boards/subor.c | 176 ++--- src/boards/t-227-1.c | 200 +++--- src/boards/t-262.c | 146 ++-- src/boards/tf-1201.c | 218 +++--- src/boards/transformer.c | 218 +++--- src/boards/unrom512.c | 498 +++++++------- src/boards/vrc1.c | 140 ++-- src/boards/vrc2and4.c | 562 +++++++-------- src/boards/vrc3.c | 268 ++++---- src/boards/vrc6.c | 754 ++++++++++---------- src/boards/vrc7.c | 400 +++++------ src/boards/vrc7p.c | 240 +++---- src/boards/yoko.c | 474 ++++++------- src/debug.c | 994 +++++++++++++-------------- src/input/bbox.c | 388 +++++------ src/input/fkb.h | 144 ++-- src/input/mouse.c | 172 ++--- src/input/pec586kb.c | 194 +++--- src/misc.c | 40 +- src/ppuview.h | 26 +- 139 files changed, 17041 insertions(+), 17041 deletions(-) diff --git a/src/boards/01-222.c b/src/boards/01-222.c index ea60589..22eea70 100644 --- a/src/boards/01-222.c +++ b/src/boards/01-222.c @@ -1,111 +1,111 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - * TXC mappers, originally much complex banksitching - * - * 01-22111-000 (05-00002-010) (132, 22211) - MGC-001 Qi Wang - * 01-22110-000 (52S ) - MGC-002 2-in-1 Gun - * 01-22111-100 (02-00002-010) (173 ) - MGC-008 Mahjong Block - * (079 ) - MGC-012 Poke Block - * 01-22110-200 (05-00002-010) (036 ) - MGC-014 Strike Wolf - * 01-22000-400 (05-00002-010) (036 ) - MGC-015 Policeman - * 01-22017-000 (05-PT017-080) (189 ) - MGC-017 Thunder Warrior - * 01-11160-000 (04-02310-000) ( , 11160) - MGC-023 6-in-1 - * 01-22270-000 (05-00002-010) (132, 22211) - MGC-xxx Creatom - * 01-22200-400 (------------) (079 ) - ET.03 F-15 City War - * (172 ) - 1991 Du Ma Racing - * - */ - -#include "mapinc.h" - -static uint8 reg[4], cmd, is172, is173; -static SFORMAT StateRegs[] = -{ - { reg, 4, "REGS" }, - { &cmd, 1, "CMD" }, - { 0 } -}; - -static void Sync(void) { - setprg32(0x8000, (reg[2] >> 2) & 1); - if (is172) - setchr8((((cmd ^ reg[2]) >> 3) & 2) | (((cmd ^ reg[2]) >> 5) & 1)); /* 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to - * rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary */ - else - setchr8(reg[2] & 3); -} - -static DECLFW(UNL22211WriteLo) { -/* FCEU_printf("bs %04x %02x\n",A,V); */ - reg[A & 3] = V; -} - -static DECLFW(UNL22211WriteHi) { -/* FCEU_printf("bs %04x %02x\n",A,V); */ - cmd = V; - Sync(); -} - -static DECLFR(UNL22211ReadLo) { - return (reg[1] ^ reg[2]) | (is173 ? 0x01 : 0x40); -#if 0 - if(reg[3]) - return reg[2]; - else - return X.DB; -#endif -} - -static void UNL22211Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetReadHandler(0x4100, 0x4100, UNL22211ReadLo); - SetWriteHandler(0x4100, 0x4103, UNL22211WriteLo); - SetWriteHandler(0x8000, 0xFFFF, UNL22211WriteHi); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNL22211_Init(CartInfo *info) { - is172 = 0; - is173 = 0; - info->Power = UNL22211Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper172_Init(CartInfo *info) { - is172 = 1; - is173 = 0; - info->Power = UNL22211Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper173_Init(CartInfo *info) { - is172 = 0; - is173 = 1; - info->Power = UNL22211Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + * TXC mappers, originally much complex banksitching + * + * 01-22111-000 (05-00002-010) (132, 22211) - MGC-001 Qi Wang + * 01-22110-000 (52S ) - MGC-002 2-in-1 Gun + * 01-22111-100 (02-00002-010) (173 ) - MGC-008 Mahjong Block + * (079 ) - MGC-012 Poke Block + * 01-22110-200 (05-00002-010) (036 ) - MGC-014 Strike Wolf + * 01-22000-400 (05-00002-010) (036 ) - MGC-015 Policeman + * 01-22017-000 (05-PT017-080) (189 ) - MGC-017 Thunder Warrior + * 01-11160-000 (04-02310-000) ( , 11160) - MGC-023 6-in-1 + * 01-22270-000 (05-00002-010) (132, 22211) - MGC-xxx Creatom + * 01-22200-400 (------------) (079 ) - ET.03 F-15 City War + * (172 ) - 1991 Du Ma Racing + * + */ + +#include "mapinc.h" + +static uint8 reg[4], cmd, is172, is173; +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { &cmd, 1, "CMD" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, (reg[2] >> 2) & 1); + if (is172) + setchr8((((cmd ^ reg[2]) >> 3) & 2) | (((cmd ^ reg[2]) >> 5) & 1)); /* 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to + * rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary */ + else + setchr8(reg[2] & 3); +} + +static DECLFW(UNL22211WriteLo) { +/* FCEU_printf("bs %04x %02x\n",A,V); */ + reg[A & 3] = V; +} + +static DECLFW(UNL22211WriteHi) { +/* FCEU_printf("bs %04x %02x\n",A,V); */ + cmd = V; + Sync(); +} + +static DECLFR(UNL22211ReadLo) { + return (reg[1] ^ reg[2]) | (is173 ? 0x01 : 0x40); +#if 0 + if(reg[3]) + return reg[2]; + else + return X.DB; +#endif +} + +static void UNL22211Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x4100, 0x4100, UNL22211ReadLo); + SetWriteHandler(0x4100, 0x4103, UNL22211WriteLo); + SetWriteHandler(0x8000, 0xFFFF, UNL22211WriteHi); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNL22211_Init(CartInfo *info) { + is172 = 0; + is173 = 0; + info->Power = UNL22211Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper172_Init(CartInfo *info) { + is172 = 1; + is173 = 0; + info->Power = UNL22211Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper173_Init(CartInfo *info) { + is172 = 0; + is173 = 1; + info->Power = UNL22211Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/09-034a.c b/src/boards/09-034a.c index fb8cc3f..b39d595 100644 --- a/src/boards/09-034a.c +++ b/src/boards/09-034a.c @@ -1,97 +1,97 @@ -/* 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 - * - * FDS Conversions - * - * Super Mario Bros 2j (Alt Full) is a BAD incomplete dump, should be mapper 43 - * - * Both Voleyball and Zanac by Whirlind Manu shares the same PCB, but with - * some differences: Voleyball has 8K CHR ROM and 8K ROM at 6000K, Zanac - * have 8K CHR RAM and banked 16K ROM mapper at 6000 as two 8K banks. -* - * Super Mario Bros 2j (Alt Small) uses additionally IRQ timer to drive framerate - * - * PCB for this mapper is "09-034A" - */ - -#include "mapinc.h" - -static uint8 prg; -static uint32 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 4, "IRQC" }, - { &IRQa, 4, "IRQA" }, - { &prg, 1, "PRG" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(1, 0x6000, prg); - setprg32(0x8000, 0); - setchr8(0); -} - -static DECLFW(UNLSMB2JWrite1) { - prg = V & 1; - Sync(); -} - -static DECLFW(UNLSMB2JWrite2) { - IRQa = V & 1; - IRQCount = 0; - X6502_IRQEnd(FCEU_IQEXT); -} - -static DECLFR(UNLSMB2JRead) { - return 0xFF; -} - -static void UNLSMB2JPower(void) { - prg = 0; - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetReadHandler(0x4042, 0x4055, UNLSMB2JRead); - SetWriteHandler(0x4068, 0x4068, UNLSMB2JWrite2); - SetWriteHandler(0x4027, 0x4027, UNLSMB2JWrite1); -} - -static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a) { - if (IRQa) - { - if (IRQCount < 5750) /* completely by guess */ - IRQCount += a; - else { - IRQa = 0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLSMB2J_Init(CartInfo *info) { - info->Power = UNLSMB2JPower; - MapIRQHook = UNLSMB2JIRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversions + * + * Super Mario Bros 2j (Alt Full) is a BAD incomplete dump, should be mapper 43 + * + * Both Voleyball and Zanac by Whirlind Manu shares the same PCB, but with + * some differences: Voleyball has 8K CHR ROM and 8K ROM at 6000K, Zanac + * have 8K CHR RAM and banked 16K ROM mapper at 6000 as two 8K banks. +* + * Super Mario Bros 2j (Alt Small) uses additionally IRQ timer to drive framerate + * + * PCB for this mapper is "09-034A" + */ + +#include "mapinc.h" + +static uint8 prg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { &prg, 1, "PRG" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(1, 0x6000, prg); + setprg32(0x8000, 0); + setchr8(0); +} + +static DECLFW(UNLSMB2JWrite1) { + prg = V & 1; + Sync(); +} + +static DECLFW(UNLSMB2JWrite2) { + IRQa = V & 1; + IRQCount = 0; + X6502_IRQEnd(FCEU_IQEXT); +} + +static DECLFR(UNLSMB2JRead) { + return 0xFF; +} + +static void UNLSMB2JPower(void) { + prg = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetReadHandler(0x4042, 0x4055, UNLSMB2JRead); + SetWriteHandler(0x4068, 0x4068, UNLSMB2JWrite2); + SetWriteHandler(0x4027, 0x4027, UNLSMB2JWrite1); +} + +static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a) { + if (IRQa) + { + if (IRQCount < 5750) /* completely by guess */ + IRQCount += a; + else { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLSMB2J_Init(CartInfo *info) { + info->Power = UNLSMB2JPower; + MapIRQHook = UNLSMB2JIRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/103.c b/src/boards/103.c index fc56621..9d35e14 100644 --- a/src/boards/103.c +++ b/src/boards/103.c @@ -1,115 +1,115 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg0, reg1, reg2; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®0, 1, "REG0" }, - { ®1, 1, "REG1" }, - { ®2, 1, "REG2" }, - { 0 } -}; - -static void Sync(void) { - setchr8(0); - setprg8(0x8000, 0xc); - setprg8(0xe000, 0xf); - if (reg2 & 0x10) { - setprg8(0x6000, reg0); - setprg8(0xa000, 0xd); - setprg8(0xc000, 0xe); - } else { - setprg8r(0x10, 0x6000, 0); - setprg4(0xa000, (0xd << 1)); - setprg2(0xb000, (0xd << 2) + 2); - setprg2r(0x10, 0xb800, 4); - setprg2r(0x10, 0xc000, 5); - setprg2r(0x10, 0xc800, 6); - setprg2r(0x10, 0xd000, 7); - setprg2(0xd800, (0xe << 2) + 3); - } - setmirror(reg1 ^ 1); -} - -static DECLFW(M103RamWrite0) { - WRAM[A & 0x1FFF] = V; -} - -static DECLFW(M103RamWrite1) { - WRAM[0x2000 + ((A - 0xB800) & 0x1FFF)] = V; -} - -static DECLFW(M103Write0) { - reg0 = V & 0xf; - Sync(); -} - -static DECLFW(M103Write1) { - reg1 = (V >> 3) & 1; - Sync(); -} - -static DECLFW(M103Write2) { - reg2 = V; - Sync(); -} - -static void M103Power(void) { - reg0 = reg1 = 0; reg2 = 0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, M103RamWrite0); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0xB800, 0xD7FF, M103RamWrite1); - SetWriteHandler(0x8000, 0x8FFF, M103Write0); - SetWriteHandler(0xE000, 0xEFFF, M103Write1); - SetWriteHandler(0xF000, 0xFFFF, M103Write2); -} - -static void M103Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper103_Init(CartInfo *info) { - info->Power = M103Power; - info->Close = M103Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 16384; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg0, reg1, reg2; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®0, 1, "REG0" }, + { ®1, 1, "REG1" }, + { ®2, 1, "REG2" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8(0x8000, 0xc); + setprg8(0xe000, 0xf); + if (reg2 & 0x10) { + setprg8(0x6000, reg0); + setprg8(0xa000, 0xd); + setprg8(0xc000, 0xe); + } else { + setprg8r(0x10, 0x6000, 0); + setprg4(0xa000, (0xd << 1)); + setprg2(0xb000, (0xd << 2) + 2); + setprg2r(0x10, 0xb800, 4); + setprg2r(0x10, 0xc000, 5); + setprg2r(0x10, 0xc800, 6); + setprg2r(0x10, 0xd000, 7); + setprg2(0xd800, (0xe << 2) + 3); + } + setmirror(reg1 ^ 1); +} + +static DECLFW(M103RamWrite0) { + WRAM[A & 0x1FFF] = V; +} + +static DECLFW(M103RamWrite1) { + WRAM[0x2000 + ((A - 0xB800) & 0x1FFF)] = V; +} + +static DECLFW(M103Write0) { + reg0 = V & 0xf; + Sync(); +} + +static DECLFW(M103Write1) { + reg1 = (V >> 3) & 1; + Sync(); +} + +static DECLFW(M103Write2) { + reg2 = V; + Sync(); +} + +static void M103Power(void) { + reg0 = reg1 = 0; reg2 = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, M103RamWrite0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0xB800, 0xD7FF, M103RamWrite1); + SetWriteHandler(0x8000, 0x8FFF, M103Write0); + SetWriteHandler(0xE000, 0xEFFF, M103Write1); + SetWriteHandler(0xF000, 0xFFFF, M103Write2); +} + +static void M103Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper103_Init(CartInfo *info) { + info->Power = M103Power; + info->Close = M103Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 16384; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/106.c b/src/boards/106.c index 3ecdf09..f471ecb 100644 --- a/src/boards/106.c +++ b/src/boards/106.c @@ -1,108 +1,108 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg[16], IRQa; -static uint32 IRQCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &IRQa, 1, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { reg, 16, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setchr1(0x0000, reg[0] & 0xfe); - setchr1(0x0400, reg[1] | 1); - setchr1(0x0800, reg[2] & 0xfe); - setchr1(0x0c00, reg[3] | 1); - setchr1(0x1000, reg[4]); - setchr1(0x1400, reg[5]); - setchr1(0x1800, reg[6]); - setchr1(0x1c00, reg[7]); - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, (reg[0x8] & 0xf) | 0x10); - setprg8(0xA000, (reg[0x9] & 0x1f)); - setprg8(0xC000, (reg[0xa] & 0x1f)); - setprg8(0xE000, (reg[0xb] & 0xf) | 0x10); - setmirror((reg[0xc] & 1) ^ 1); -} - -static DECLFW(M106Write) { - A &= 0xF; - switch (A) { - case 0xD: IRQa = 0; IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xE: IRQCount = (IRQCount & 0xFF00) | V; break; - case 0xF: IRQCount = (IRQCount & 0x00FF) | (V << 8); IRQa = 1; break; - default: reg[A] = V; Sync(); break; - } -} - -static void M106Power(void) { - reg[8] = reg[9] = reg[0xa] = reg[0xb] = -1; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0xFFFF, M106Write); -} - -static void M106Reset(void) { -} - -static void M106Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void FP_FASTAPASS(1) M106CpuHook(int a) { - if (IRQa) { - IRQCount += a; - if (IRQCount > 0x10000) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper106_Init(CartInfo *info) { - info->Reset = M106Reset; - info->Power = M106Power; - info->Close = M106Close; - MapIRQHook = M106CpuHook; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg[16], IRQa; +static uint32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { reg, 16, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setchr1(0x0000, reg[0] & 0xfe); + setchr1(0x0400, reg[1] | 1); + setchr1(0x0800, reg[2] & 0xfe); + setchr1(0x0c00, reg[3] | 1); + setchr1(0x1000, reg[4]); + setchr1(0x1400, reg[5]); + setchr1(0x1800, reg[6]); + setchr1(0x1c00, reg[7]); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, (reg[0x8] & 0xf) | 0x10); + setprg8(0xA000, (reg[0x9] & 0x1f)); + setprg8(0xC000, (reg[0xa] & 0x1f)); + setprg8(0xE000, (reg[0xb] & 0xf) | 0x10); + setmirror((reg[0xc] & 1) ^ 1); +} + +static DECLFW(M106Write) { + A &= 0xF; + switch (A) { + case 0xD: IRQa = 0; IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE: IRQCount = (IRQCount & 0xFF00) | V; break; + case 0xF: IRQCount = (IRQCount & 0x00FF) | (V << 8); IRQa = 1; break; + default: reg[A] = V; Sync(); break; + } +} + +static void M106Power(void) { + reg[8] = reg[9] = reg[0xa] = reg[0xb] = -1; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M106Write); +} + +static void M106Reset(void) { +} + +static void M106Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void FP_FASTAPASS(1) M106CpuHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount > 0x10000) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper106_Init(CartInfo *info) { + info->Reset = M106Reset; + info->Power = M106Power; + info->Close = M106Close; + MapIRQHook = M106CpuHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/108.c b/src/boards/108.c index 0e437d8..a06113b 100644 --- a/src/boards/108.c +++ b/src/boards/108.c @@ -1,64 +1,64 @@ -/* 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 - * - * FDS Conversion - * - * Meikyuu Jin Dababa - * Bubble Bobble Kaiser - * - */ - -#include "mapinc.h" - -static uint8 reg; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, reg); - setprg32(0x8000, ~0); - setchr8(0); -} - -static DECLFW(M108Write) { - reg = V; - Sync(); -} - -static void M108Power(void) { - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0x8FFF, M108Write); /* regular 108 */ - SetWriteHandler(0xF000, 0xFFFF, M108Write); /* simplified Kaiser BB Hack */ -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper108_Init(CartInfo *info) { - info->Power = M108Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + * Meikyuu Jin Dababa + * Bubble Bobble Kaiser + * + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg32(0x8000, ~0); + setchr8(0); +} + +static DECLFW(M108Write) { + reg = V; + Sync(); +} + +static void M108Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, M108Write); /* regular 108 */ + SetWriteHandler(0xF000, 0xFFFF, M108Write); /* simplified Kaiser BB Hack */ +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper108_Init(CartInfo *info) { + info->Power = M108Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/116.c b/src/boards/116.c index b45d924..88f5f00 100644 --- a/src/boards/116.c +++ b/src/boards/116.c @@ -1,325 +1,325 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) - * the same as 603-5052 board (TODO: add reading registers, merge) - * SL1632 2-in-1 protected board, similar to SL12 (TODO: find difference) - * - * Known PCB: - * - * Garou Densetsu Special (G0904.PCB, Huang-1, GAL dip: W conf.) - * Kart Fighter (008, Huang-1, GAL dip: W conf.) - * Somari (008, C5052-13, GAL dip: P conf., GK2-P/GK2-V maskroms) - * Somari (008, Huang-1, GAL dip: W conf., GK1-P/GK1-V maskroms) - * AV Mei Shao Nv Zhan Shi (aka AV Pretty Girl Fighting) (SL-12 PCB, Hunag-1, GAL dip: unk conf. SL-11A/SL-11B maskroms) - * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms) - * Contra Fighter (603-5052 PCB, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) - * - */ - -#include "mapinc.h" - -static uint8 mode; -static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr; -static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr; -static uint8 IRQCount, IRQLatch, IRQa; -static uint8 IRQReload; -static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift; - -static SFORMAT StateRegs[] = -{ - { &mode, 1, "MODE" }, - { vrc2_chr, 8, "VRCC" }, - { vrc2_prg, 2, "VRCP" }, - { &vrc2_mirr, 1, "VRCM" }, - { mmc3_regs, 10, "M3RG" }, - { &mmc3_ctrl, 1, "M3CT" }, - { &mmc3_mirr, 1, "M3MR" }, - { &IRQReload, 1, "IRQR" }, - { &IRQCount, 1, "IRQC" }, - { &IRQLatch, 1, "IRQL" }, - { &IRQa, 1, "IRQA" }, - { mmc1_regs, 4, "M1RG" }, - { &mmc1_buffer, 1, "M1BF" }, - { &mmc1_shift, 1, "M1MR" }, - { 0 } -}; - -static void SyncPRG(void) { - switch (mode & 3) { - case 0: - setprg8(0x8000, vrc2_prg[0]); - setprg8(0xA000, vrc2_prg[1]); - setprg8(0xC000, ~1); - setprg8(0xE000, ~0); - break; - case 1: - { - uint32 swap = (mmc3_ctrl >> 5) & 2; - setprg8(0x8000, mmc3_regs[6 + swap]); - setprg8(0xA000, mmc3_regs[7]); - setprg8(0xC000, mmc3_regs[6 + (swap ^ 2)]); - setprg8(0xE000, mmc3_regs[9]); - break; - } - case 2: - case 3: - { - uint8 bank = mmc1_regs[3] & 0xF; - if (mmc1_regs[0] & 8) { - if (mmc1_regs[0] & 4) { - setprg16(0x8000, bank); - setprg16(0xC000, 0x0F); - } else { - setprg16(0x8000, 0); - setprg16(0xC000, bank); - } - } else - setprg32(0x8000, bank >> 1); - break; - } - } -} - -static void SyncCHR(void) { - uint32 base = (mode & 4) << 6; - switch (mode & 3) { - case 0: - setchr1(0x0000, base | vrc2_chr[0]); - setchr1(0x0400, base | vrc2_chr[1]); - setchr1(0x0800, base | vrc2_chr[2]); - setchr1(0x0c00, base | vrc2_chr[3]); - setchr1(0x1000, base | vrc2_chr[4]); - setchr1(0x1400, base | vrc2_chr[5]); - setchr1(0x1800, base | vrc2_chr[6]); - setchr1(0x1c00, base | vrc2_chr[7]); - break; - case 1: { - uint32 swap = (mmc3_ctrl & 0x80) << 5; - setchr1(0x0000 ^ swap, base | ((mmc3_regs[0]) & 0xFE)); - setchr1(0x0400 ^ swap, base | (mmc3_regs[0] | 1)); - setchr1(0x0800 ^ swap, base | ((mmc3_regs[1]) & 0xFE)); - setchr1(0x0c00 ^ swap, base | (mmc3_regs[1] | 1)); - setchr1(0x1000 ^ swap, base | mmc3_regs[2]); - setchr1(0x1400 ^ swap, base | mmc3_regs[3]); - setchr1(0x1800 ^ swap, base | mmc3_regs[4]); - setchr1(0x1c00 ^ swap, base | mmc3_regs[5]); - break; - } - case 2: - case 3: - if (mmc1_regs[0] & 0x10) { - setchr4(0x0000, mmc1_regs[1]); - setchr4(0x1000, mmc1_regs[2]); - } else - setchr8(mmc1_regs[1] >> 1); - break; - } -} - -static void SyncMIR(void) { - switch (mode & 3) { - case 0: { - setmirror((vrc2_mirr & 1) ^ 1); - break; - } - case 1: { - setmirror((mmc3_mirr & 1) ^ 1); - break; - } - case 2: - case 3: { - switch (mmc1_regs[0] & 3) { - case 0: setmirror(MI_0); break; - case 1: setmirror(MI_1); break; - case 2: setmirror(MI_V); break; - case 3: setmirror(MI_H); break; - } - break; - } - } -} - -static void Sync(void) { - SyncPRG(); - SyncCHR(); - SyncMIR(); -} - -static DECLFW(UNLSL12ModeWrite) { -/* FCEU_printf("%04X:%02X\n",A,V); */ - if ((A & 0x4100) == 0x4100) { - mode = V; - if (A & 1) { /* hacky hacky, there are two configuration modes on SOMARI HUANG-1 PCBs - * Solder pads with P1/P2 shorted called SOMARI P, - * Solder pads with W1/W2 shorted called SOMARI W - * Both identical 3-in-1 but W wanted MMC1 registers - * to be reset when switch to MMC1 mode P one - doesn't - * There is issue with W version of Somari at starting copyrights - */ - mmc1_regs[0] = 0xc; - mmc1_regs[3] = 0; - mmc1_buffer = 0; - mmc1_shift = 0; - } - Sync(); - } -} - -static DECLFW(UNLSL12Write) { -/* FCEU_printf("%04X:%02X\n",A,V); */ - switch (mode & 3) { - case 0: { - if ((A >= 0xB000) && (A <= 0xE003)) { - int32 ind = ((((A & 2) | (A >> 10)) >> 1) + 2) & 7; - int32 sar = ((A & 1) << 2); - vrc2_chr[ind] = (vrc2_chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); - SyncCHR(); - } else - switch (A & 0xF000) { - case 0x8000: vrc2_prg[0] = V; SyncPRG(); break; - case 0xA000: vrc2_prg[1] = V; SyncPRG(); break; - case 0x9000: vrc2_mirr = V; SyncMIR(); break; - } - break; - } - case 1: { - switch (A & 0xE001) { - case 0x8000: { - uint8 old_ctrl = mmc3_ctrl; - mmc3_ctrl = V; - if ((old_ctrl & 0x40) != (mmc3_ctrl & 0x40)) - SyncPRG(); - if ((old_ctrl & 0x80) != (mmc3_ctrl & 0x80)) - SyncCHR(); - break; - } - case 0x8001: - mmc3_regs[mmc3_ctrl & 7] = V; - if ((mmc3_ctrl & 7) < 6) - SyncCHR(); - else - SyncPRG(); - break; - case 0xA000: - mmc3_mirr = V; - SyncMIR(); - break; - case 0xC000: - IRQLatch = V; - break; - case 0xC001: - IRQReload = 1; - break; - case 0xE000: - X6502_IRQEnd(FCEU_IQEXT); - IRQa = 0; - break; - case 0xE001: - IRQa = 1; - break; - } - break; - } - case 2: - case 3: { - if (V & 0x80) { - mmc1_regs[0] |= 0xc; - mmc1_buffer = mmc1_shift = 0; - SyncPRG(); - } else { - uint8 n = (A >> 13) - 4; - mmc1_buffer |= (V & 1) << (mmc1_shift++); - if (mmc1_shift == 5) { - mmc1_regs[n] = mmc1_buffer; - mmc1_buffer = mmc1_shift = 0; - switch (n) { - case 0: SyncMIR(); - case 2: SyncCHR(); - case 3: - case 1: SyncPRG(); - } - } - } - break; - } - } -} - -static void UNLSL12HBIRQ(void) { - if ((mode & 3) == 1) { - int32 count = IRQCount; - if (!count || IRQReload) { - IRQCount = IRQLatch; - IRQReload = 0; - } else - IRQCount--; - if (!IRQCount) { - if (IRQa) - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -static void UNLSL12Power(void) { - mode = 0; - vrc2_chr[0] = ~0; - vrc2_chr[1] = ~0; - vrc2_chr[2] = ~0; - vrc2_chr[3] = ~0; /* W conf. of Somari wanted CHR3 has to be set to BB bank (or similar), but doesn't do that directly */ - vrc2_chr[4] = 4; - vrc2_chr[5] = 5; - vrc2_chr[6] = 6; - vrc2_chr[7] = 7; - vrc2_prg[0] = 0; - vrc2_prg[1] = 1; - vrc2_mirr = 0; - mmc3_regs[0] = 0; - mmc3_regs[1] = 2; - mmc3_regs[2] = 4; - mmc3_regs[3] = 5; - mmc3_regs[4] = 6; - mmc3_regs[5] = 7; - mmc3_regs[6] = ~3; - mmc3_regs[7] = ~2; - mmc3_regs[8] = ~1; - mmc3_regs[9] = ~0; - mmc3_ctrl = mmc3_mirr = IRQCount = IRQLatch = IRQa = 0; - mmc1_regs[0] = 0xc; - mmc1_regs[1] = 0; - mmc1_regs[2] = 0; - mmc1_regs[3] = 0; - mmc1_buffer = 0; - mmc1_shift = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x4100, 0x7FFF, UNLSL12ModeWrite); - SetWriteHandler(0x8000, 0xFFFF, UNLSL12Write); -} - -void UNLSL12_Init(CartInfo *info) { - info->Power = UNLSL12Power; - GameHBIRQHook = UNLSL12HBIRQ; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) + * the same as 603-5052 board (TODO: add reading registers, merge) + * SL1632 2-in-1 protected board, similar to SL12 (TODO: find difference) + * + * Known PCB: + * + * Garou Densetsu Special (G0904.PCB, Huang-1, GAL dip: W conf.) + * Kart Fighter (008, Huang-1, GAL dip: W conf.) + * Somari (008, C5052-13, GAL dip: P conf., GK2-P/GK2-V maskroms) + * Somari (008, Huang-1, GAL dip: W conf., GK1-P/GK1-V maskroms) + * AV Mei Shao Nv Zhan Shi (aka AV Pretty Girl Fighting) (SL-12 PCB, Hunag-1, GAL dip: unk conf. SL-11A/SL-11B maskroms) + * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms) + * Contra Fighter (603-5052 PCB, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) + * + */ + +#include "mapinc.h" + +static uint8 mode; +static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr; +static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr; +static uint8 IRQCount, IRQLatch, IRQa; +static uint8 IRQReload; +static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift; + +static SFORMAT StateRegs[] = +{ + { &mode, 1, "MODE" }, + { vrc2_chr, 8, "VRCC" }, + { vrc2_prg, 2, "VRCP" }, + { &vrc2_mirr, 1, "VRCM" }, + { mmc3_regs, 10, "M3RG" }, + { &mmc3_ctrl, 1, "M3CT" }, + { &mmc3_mirr, 1, "M3MR" }, + { &IRQReload, 1, "IRQR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQa, 1, "IRQA" }, + { mmc1_regs, 4, "M1RG" }, + { &mmc1_buffer, 1, "M1BF" }, + { &mmc1_shift, 1, "M1MR" }, + { 0 } +}; + +static void SyncPRG(void) { + switch (mode & 3) { + case 0: + setprg8(0x8000, vrc2_prg[0]); + setprg8(0xA000, vrc2_prg[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + break; + case 1: + { + uint32 swap = (mmc3_ctrl >> 5) & 2; + setprg8(0x8000, mmc3_regs[6 + swap]); + setprg8(0xA000, mmc3_regs[7]); + setprg8(0xC000, mmc3_regs[6 + (swap ^ 2)]); + setprg8(0xE000, mmc3_regs[9]); + break; + } + case 2: + case 3: + { + uint8 bank = mmc1_regs[3] & 0xF; + if (mmc1_regs[0] & 8) { + if (mmc1_regs[0] & 4) { + setprg16(0x8000, bank); + setprg16(0xC000, 0x0F); + } else { + setprg16(0x8000, 0); + setprg16(0xC000, bank); + } + } else + setprg32(0x8000, bank >> 1); + break; + } + } +} + +static void SyncCHR(void) { + uint32 base = (mode & 4) << 6; + switch (mode & 3) { + case 0: + setchr1(0x0000, base | vrc2_chr[0]); + setchr1(0x0400, base | vrc2_chr[1]); + setchr1(0x0800, base | vrc2_chr[2]); + setchr1(0x0c00, base | vrc2_chr[3]); + setchr1(0x1000, base | vrc2_chr[4]); + setchr1(0x1400, base | vrc2_chr[5]); + setchr1(0x1800, base | vrc2_chr[6]); + setchr1(0x1c00, base | vrc2_chr[7]); + break; + case 1: { + uint32 swap = (mmc3_ctrl & 0x80) << 5; + setchr1(0x0000 ^ swap, base | ((mmc3_regs[0]) & 0xFE)); + setchr1(0x0400 ^ swap, base | (mmc3_regs[0] | 1)); + setchr1(0x0800 ^ swap, base | ((mmc3_regs[1]) & 0xFE)); + setchr1(0x0c00 ^ swap, base | (mmc3_regs[1] | 1)); + setchr1(0x1000 ^ swap, base | mmc3_regs[2]); + setchr1(0x1400 ^ swap, base | mmc3_regs[3]); + setchr1(0x1800 ^ swap, base | mmc3_regs[4]); + setchr1(0x1c00 ^ swap, base | mmc3_regs[5]); + break; + } + case 2: + case 3: + if (mmc1_regs[0] & 0x10) { + setchr4(0x0000, mmc1_regs[1]); + setchr4(0x1000, mmc1_regs[2]); + } else + setchr8(mmc1_regs[1] >> 1); + break; + } +} + +static void SyncMIR(void) { + switch (mode & 3) { + case 0: { + setmirror((vrc2_mirr & 1) ^ 1); + break; + } + case 1: { + setmirror((mmc3_mirr & 1) ^ 1); + break; + } + case 2: + case 3: { + switch (mmc1_regs[0] & 3) { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + } + break; + } + } +} + +static void Sync(void) { + SyncPRG(); + SyncCHR(); + SyncMIR(); +} + +static DECLFW(UNLSL12ModeWrite) { +/* FCEU_printf("%04X:%02X\n",A,V); */ + if ((A & 0x4100) == 0x4100) { + mode = V; + if (A & 1) { /* hacky hacky, there are two configuration modes on SOMARI HUANG-1 PCBs + * Solder pads with P1/P2 shorted called SOMARI P, + * Solder pads with W1/W2 shorted called SOMARI W + * Both identical 3-in-1 but W wanted MMC1 registers + * to be reset when switch to MMC1 mode P one - doesn't + * There is issue with W version of Somari at starting copyrights + */ + mmc1_regs[0] = 0xc; + mmc1_regs[3] = 0; + mmc1_buffer = 0; + mmc1_shift = 0; + } + Sync(); + } +} + +static DECLFW(UNLSL12Write) { +/* FCEU_printf("%04X:%02X\n",A,V); */ + switch (mode & 3) { + case 0: { + if ((A >= 0xB000) && (A <= 0xE003)) { + int32 ind = ((((A & 2) | (A >> 10)) >> 1) + 2) & 7; + int32 sar = ((A & 1) << 2); + vrc2_chr[ind] = (vrc2_chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + SyncCHR(); + } else + switch (A & 0xF000) { + case 0x8000: vrc2_prg[0] = V; SyncPRG(); break; + case 0xA000: vrc2_prg[1] = V; SyncPRG(); break; + case 0x9000: vrc2_mirr = V; SyncMIR(); break; + } + break; + } + case 1: { + switch (A & 0xE001) { + case 0x8000: { + uint8 old_ctrl = mmc3_ctrl; + mmc3_ctrl = V; + if ((old_ctrl & 0x40) != (mmc3_ctrl & 0x40)) + SyncPRG(); + if ((old_ctrl & 0x80) != (mmc3_ctrl & 0x80)) + SyncCHR(); + break; + } + case 0x8001: + mmc3_regs[mmc3_ctrl & 7] = V; + if ((mmc3_ctrl & 7) < 6) + SyncCHR(); + else + SyncPRG(); + break; + case 0xA000: + mmc3_mirr = V; + SyncMIR(); + break; + case 0xC000: + IRQLatch = V; + break; + case 0xC001: + IRQReload = 1; + break; + case 0xE000: + X6502_IRQEnd(FCEU_IQEXT); + IRQa = 0; + break; + case 0xE001: + IRQa = 1; + break; + } + break; + } + case 2: + case 3: { + if (V & 0x80) { + mmc1_regs[0] |= 0xc; + mmc1_buffer = mmc1_shift = 0; + SyncPRG(); + } else { + uint8 n = (A >> 13) - 4; + mmc1_buffer |= (V & 1) << (mmc1_shift++); + if (mmc1_shift == 5) { + mmc1_regs[n] = mmc1_buffer; + mmc1_buffer = mmc1_shift = 0; + switch (n) { + case 0: SyncMIR(); + case 2: SyncCHR(); + case 3: + case 1: SyncPRG(); + } + } + } + break; + } + } +} + +static void UNLSL12HBIRQ(void) { + if ((mode & 3) == 1) { + int32 count = IRQCount; + if (!count || IRQReload) { + IRQCount = IRQLatch; + IRQReload = 0; + } else + IRQCount--; + if (!IRQCount) { + if (IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +static void UNLSL12Power(void) { + mode = 0; + vrc2_chr[0] = ~0; + vrc2_chr[1] = ~0; + vrc2_chr[2] = ~0; + vrc2_chr[3] = ~0; /* W conf. of Somari wanted CHR3 has to be set to BB bank (or similar), but doesn't do that directly */ + vrc2_chr[4] = 4; + vrc2_chr[5] = 5; + vrc2_chr[6] = 6; + vrc2_chr[7] = 7; + vrc2_prg[0] = 0; + vrc2_prg[1] = 1; + vrc2_mirr = 0; + mmc3_regs[0] = 0; + mmc3_regs[1] = 2; + mmc3_regs[2] = 4; + mmc3_regs[3] = 5; + mmc3_regs[4] = 6; + mmc3_regs[5] = 7; + mmc3_regs[6] = ~3; + mmc3_regs[7] = ~2; + mmc3_regs[8] = ~1; + mmc3_regs[9] = ~0; + mmc3_ctrl = mmc3_mirr = IRQCount = IRQLatch = IRQa = 0; + mmc1_regs[0] = 0xc; + mmc1_regs[1] = 0; + mmc1_regs[2] = 0; + mmc1_regs[3] = 0; + mmc1_buffer = 0; + mmc1_shift = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x7FFF, UNLSL12ModeWrite); + SetWriteHandler(0x8000, 0xFFFF, UNLSL12Write); +} + +void UNLSL12_Init(CartInfo *info) { + info->Power = UNLSL12Power; + GameHBIRQHook = UNLSL12HBIRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/120.c b/src/boards/120.c index eabe47d..bdc8dd5 100644 --- a/src/boards/120.c +++ b/src/boards/120.c @@ -1,62 +1,62 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, reg); - setprg32(0x8000, 2); - setchr8(0); -} - -static DECLFW(M120Write) { - if (A == 0x41FF) { - reg = V & 7; - Sync(); - } -} - -static void M120Power(void) { - reg = 0; - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x4100, 0x5FFF, M120Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper120_Init(CartInfo *info) { - info->Power = M120Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg32(0x8000, 2); + setchr8(0); +} + +static DECLFW(M120Write) { + if (A == 0x41FF) { + reg = V & 7; + Sync(); + } +} + +static void M120Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x4100, 0x5FFF, M120Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper120_Init(CartInfo *info) { + info->Power = M120Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/121.c b/src/boards/121.c index c9b3393..be70aaf 100644 --- a/src/boards/121.c +++ b/src/boards/121.c @@ -1,129 +1,129 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2007-2008 Mad Dumper, 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 - * - * Panda prince pirate. - * MK4, MK6, A9711/A9713 board - * 6035052 seems to be the same too, but with prot array in reverse - * A9746 seems to be the same too, check - * 187 seems to be the same too, check (A98402 board) - * - */ - -#include "mapinc.h" -#include "mmc3.h" - -static void Sync() { - switch (EXPREGS[5] & 0x3F) { - case 0x20: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; - case 0x29: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; - case 0x26: EXPREGS[7] = 0; EXPREGS[0] = EXPREGS[6]; break; - case 0x2B: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; - case 0x2C: EXPREGS[7] = 1; if (EXPREGS[6]) EXPREGS[0] = EXPREGS[6]; break; - case 0x3C: - case 0x3F: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; - case 0x28: EXPREGS[7] = 0; EXPREGS[1] = EXPREGS[6]; break; - case 0x2A: EXPREGS[7] = 0; EXPREGS[2] = EXPREGS[6]; break; - case 0x2F: break; - default: EXPREGS[5] = 0; break; - } -} - -static void M121CW(uint32 A, uint8 V) { - if (PRGsize[0] == CHRsize[0]) { /* A9713 multigame extension hack! */ - setchr1(A, V | ((EXPREGS[3] & 0x80) << 1)); - } else { - if ((A & 0x1000) == ((MMC3_cmd & 0x80) << 5)) - setchr1(A, V | 0x100); - else - setchr1(A, V); - } -} - -static void M121PW(uint32 A, uint8 V) { - if (EXPREGS[5] & 0x3F) { -/* FCEU_printf("prot banks: %02x %02x %02x %02x\n",V,EXPREGS[2],EXPREGS[1],EXPREGS[0]); */ - setprg8(A, (V & 0x1F) | ((EXPREGS[3] & 0x80) >> 2)); - setprg8(0xE000, (EXPREGS[0]) | ((EXPREGS[3] & 0x80) >> 2)); - setprg8(0xC000, (EXPREGS[1]) | ((EXPREGS[3] & 0x80) >> 2)); - setprg8(0xA000, (EXPREGS[2]) | ((EXPREGS[3] & 0x80) >> 2)); - } else { -/* FCEU_printf("gen banks: %04x %02x\n",A,V); */ - setprg8(A, (V & 0x1F) | ((EXPREGS[3] & 0x80) >> 2)); - } -} - -static DECLFW(M121Write) { -/* FCEU_printf("write: %04x:%04x\n",A&0xE003,V); */ - switch (A & 0xE003) { - case 0x8000: -/* EXPREGS[5] = 0; */ -/* FCEU_printf("gen: %02x\n",V); */ - MMC3_CMDWrite(A, V); - FixMMC3PRG(MMC3_cmd); - break; - case 0x8001: - EXPREGS[6] = ((V & 1) << 5) | ((V & 2) << 3) | ((V & 4) << 1) | ((V & 8) >> 1) | ((V & 0x10) >> 3) | ((V & 0x20) >> 5); -/* FCEU_printf("bank: %02x (%02x)\n",V,EXPREGS[6]); */ - if (!EXPREGS[7]) Sync(); - MMC3_CMDWrite(A, V); - FixMMC3PRG(MMC3_cmd); - break; - case 0x8003: - EXPREGS[5] = V; -/* EXPREGS[7] = 0; */ -/* FCEU_printf("prot: %02x\n",EXPREGS[5]); */ - Sync(); - MMC3_CMDWrite(0x8000, V); - FixMMC3PRG(MMC3_cmd); - break; - } -} - -static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; -static DECLFW(M121LoWrite) { - EXPREGS[4] = prot_array[V & 3]; /* 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter) */ - if ((A & 0x5180) == 0x5180) { /* A9713 multigame extension */ - EXPREGS[3] = V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } -/* FCEU_printf("write: %04x:%04x\n",A,V); */ -} - -static DECLFR(M121Read) { -/* FCEU_printf("read: %04x->\n",A,EXPREGS[0]); */ - return EXPREGS[4]; -} - -static void M121Power(void) { - EXPREGS[3] = 0x80; - EXPREGS[5] = 0; - GenMMC3Power(); - SetReadHandler(0x5000, 0x5FFF, M121Read); - SetWriteHandler(0x5000, 0x5FFF, M121LoWrite); - SetWriteHandler(0x8000, 0x9FFF, M121Write); -} - -void Mapper121_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 256, 8, 0); - pwrap = M121PW; - cwrap = M121CW; - info->Power = M121Power; - AddExState(EXPREGS, 8, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2008 Mad Dumper, 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 + * + * Panda prince pirate. + * MK4, MK6, A9711/A9713 board + * 6035052 seems to be the same too, but with prot array in reverse + * A9746 seems to be the same too, check + * 187 seems to be the same too, check (A98402 board) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void Sync() { + switch (EXPREGS[5] & 0x3F) { + case 0x20: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x29: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x26: EXPREGS[7] = 0; EXPREGS[0] = EXPREGS[6]; break; + case 0x2B: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x2C: EXPREGS[7] = 1; if (EXPREGS[6]) EXPREGS[0] = EXPREGS[6]; break; + case 0x3C: + case 0x3F: EXPREGS[7] = 1; EXPREGS[0] = EXPREGS[6]; break; + case 0x28: EXPREGS[7] = 0; EXPREGS[1] = EXPREGS[6]; break; + case 0x2A: EXPREGS[7] = 0; EXPREGS[2] = EXPREGS[6]; break; + case 0x2F: break; + default: EXPREGS[5] = 0; break; + } +} + +static void M121CW(uint32 A, uint8 V) { + if (PRGsize[0] == CHRsize[0]) { /* A9713 multigame extension hack! */ + setchr1(A, V | ((EXPREGS[3] & 0x80) << 1)); + } else { + if ((A & 0x1000) == ((MMC3_cmd & 0x80) << 5)) + setchr1(A, V | 0x100); + else + setchr1(A, V); + } +} + +static void M121PW(uint32 A, uint8 V) { + if (EXPREGS[5] & 0x3F) { +/* FCEU_printf("prot banks: %02x %02x %02x %02x\n",V,EXPREGS[2],EXPREGS[1],EXPREGS[0]); */ + setprg8(A, (V & 0x1F) | ((EXPREGS[3] & 0x80) >> 2)); + setprg8(0xE000, (EXPREGS[0]) | ((EXPREGS[3] & 0x80) >> 2)); + setprg8(0xC000, (EXPREGS[1]) | ((EXPREGS[3] & 0x80) >> 2)); + setprg8(0xA000, (EXPREGS[2]) | ((EXPREGS[3] & 0x80) >> 2)); + } else { +/* FCEU_printf("gen banks: %04x %02x\n",A,V); */ + setprg8(A, (V & 0x1F) | ((EXPREGS[3] & 0x80) >> 2)); + } +} + +static DECLFW(M121Write) { +/* FCEU_printf("write: %04x:%04x\n",A&0xE003,V); */ + switch (A & 0xE003) { + case 0x8000: +/* EXPREGS[5] = 0; */ +/* FCEU_printf("gen: %02x\n",V); */ + MMC3_CMDWrite(A, V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8001: + EXPREGS[6] = ((V & 1) << 5) | ((V & 2) << 3) | ((V & 4) << 1) | ((V & 8) >> 1) | ((V & 0x10) >> 3) | ((V & 0x20) >> 5); +/* FCEU_printf("bank: %02x (%02x)\n",V,EXPREGS[6]); */ + if (!EXPREGS[7]) Sync(); + MMC3_CMDWrite(A, V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8003: + EXPREGS[5] = V; +/* EXPREGS[7] = 0; */ +/* FCEU_printf("prot: %02x\n",EXPREGS[5]); */ + Sync(); + MMC3_CMDWrite(0x8000, V); + FixMMC3PRG(MMC3_cmd); + break; + } +} + +static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFW(M121LoWrite) { + EXPREGS[4] = prot_array[V & 3]; /* 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter) */ + if ((A & 0x5180) == 0x5180) { /* A9713 multigame extension */ + EXPREGS[3] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +/* FCEU_printf("write: %04x:%04x\n",A,V); */ +} + +static DECLFR(M121Read) { +/* FCEU_printf("read: %04x->\n",A,EXPREGS[0]); */ + return EXPREGS[4]; +} + +static void M121Power(void) { + EXPREGS[3] = 0x80; + EXPREGS[5] = 0; + GenMMC3Power(); + SetReadHandler(0x5000, 0x5FFF, M121Read); + SetWriteHandler(0x5000, 0x5FFF, M121LoWrite); + SetWriteHandler(0x8000, 0x9FFF, M121Write); +} + +void Mapper121_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 8, 0); + pwrap = M121PW; + cwrap = M121CW; + info->Power = M121Power; + AddExState(EXPREGS, 8, 0, "EXPR"); +} diff --git a/src/boards/12in1.c b/src/boards/12in1.c index f6abf08..64f812a 100644 --- a/src/boards/12in1.c +++ b/src/boards/12in1.c @@ -1,73 +1,73 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1") - * 12-in-1 1991 New Star Co. Ltd. - * - */ - -#include "mapinc.h" - -static uint8 prgchr[2], ctrl; -static SFORMAT StateRegs[] = -{ - { prgchr, 2, "REGS" }, - { &ctrl, 1, "CTRL" }, - { 0 } -}; - -static void Sync(void) { - uint8 bank = (ctrl & 3) << 3; - setchr4(0x0000, (prgchr[0] >> 3) | (bank << 2)); - setchr4(0x1000, (prgchr[1] >> 3) | (bank << 2)); - if (ctrl & 8) { - setprg16(0x8000, bank | (prgchr[0] & 6) | 0); /* actually, both 0 and 1 registers used, but they will switch each PA12 transition */ - setprg16(0xc000, bank | (prgchr[0] & 6) | 1); /* if bits are different for both registers, so they must be programmed strongly the same! */ - } else { - setprg16(0x8000, bank | (prgchr[0] & 7)); - setprg16(0xc000, bank | 7 ); - } - setmirror(((ctrl & 4) >> 2) ^ 1); -} - -static DECLFW(BMC12IN1Write) { - switch (A & 0xE000) { - case 0xA000: prgchr[0] = V; Sync(); break; - case 0xC000: prgchr[1] = V; Sync(); break; - case 0xE000: ctrl = V & 0x0F; Sync(); break; - } -} - -static void BMC12IN1Power(void) { - prgchr[0] = prgchr[1] = ctrl = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, BMC12IN1Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void BMC12IN1_Init(CartInfo *info) { - info->Power = BMC12IN1Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1") + * 12-in-1 1991 New Star Co. Ltd. + * + */ + +#include "mapinc.h" + +static uint8 prgchr[2], ctrl; +static SFORMAT StateRegs[] = +{ + { prgchr, 2, "REGS" }, + { &ctrl, 1, "CTRL" }, + { 0 } +}; + +static void Sync(void) { + uint8 bank = (ctrl & 3) << 3; + setchr4(0x0000, (prgchr[0] >> 3) | (bank << 2)); + setchr4(0x1000, (prgchr[1] >> 3) | (bank << 2)); + if (ctrl & 8) { + setprg16(0x8000, bank | (prgchr[0] & 6) | 0); /* actually, both 0 and 1 registers used, but they will switch each PA12 transition */ + setprg16(0xc000, bank | (prgchr[0] & 6) | 1); /* if bits are different for both registers, so they must be programmed strongly the same! */ + } else { + setprg16(0x8000, bank | (prgchr[0] & 7)); + setprg16(0xc000, bank | 7 ); + } + setmirror(((ctrl & 4) >> 2) ^ 1); +} + +static DECLFW(BMC12IN1Write) { + switch (A & 0xE000) { + case 0xA000: prgchr[0] = V; Sync(); break; + case 0xC000: prgchr[1] = V; Sync(); break; + case 0xE000: ctrl = V & 0x0F; Sync(); break; + } +} + +static void BMC12IN1Power(void) { + prgchr[0] = prgchr[1] = ctrl = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BMC12IN1Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC12IN1_Init(CartInfo *info) { + info->Power = BMC12IN1Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/15.c b/src/boards/15.c index 5e70baf..b8281e6 100644 --- a/src/boards/15.c +++ b/src/boards/15.c @@ -1,110 +1,110 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - */ - -#include "mapinc.h" - -static uint16 latchea; -static uint8 latched; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static SFORMAT StateRegs[] = -{ - { &latchea, 2, "AREG" }, - { &latched, 1, "DREG" }, - { 0 } -}; - -static void Sync(void) { - int i; - setmirror(((latched >> 6) & 1) ^ 1); - switch (latchea) { - case 0x8000: - for (i = 0; i < 4; i++) - setprg8(0x8000 + (i << 13), (((latched & 0x7F) << 1) + i) ^ (latched >> 7)); - break; - case 0x8002: - for (i = 0; i < 4; i++) - setprg8(0x8000 + (i << 13), ((latched & 0x7F) << 1) + (latched >> 7)); - break; - case 0x8001: - case 0x8003: - for (i = 0; i < 4; i++) { - unsigned int b; - b = latched & 0x7F; - if (i >= 2 && !(latchea & 0x2)) - b = 0x7F; - setprg8(0x8000 + (i << 13), (i & 1) + ((b << 1) ^ (latched >> 7))); - } - break; - } -} - -static DECLFW(M15Write) { - latchea = A; - latched = V; - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -static void M15Power(void) { - latchea = 0x8000; - latched = 0; - setchr8(0); - setprg8r(0x10, 0x6000, 0); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0xFFFF, M15Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - Sync(); -} - -static void M15Reset(void) { - latchea = 0x8000; - latched = 0; - Sync(); -} - -static void M15Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void Mapper15_Init(CartInfo *info) { - info->Power = M15Power; - info->Reset = M15Reset; - info->Close = M15Close; - GameStateRestore = StateRestore; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + */ + +#include "mapinc.h" + +static uint16 latchea; +static uint8 latched; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static SFORMAT StateRegs[] = +{ + { &latchea, 2, "AREG" }, + { &latched, 1, "DREG" }, + { 0 } +}; + +static void Sync(void) { + int i; + setmirror(((latched >> 6) & 1) ^ 1); + switch (latchea) { + case 0x8000: + for (i = 0; i < 4; i++) + setprg8(0x8000 + (i << 13), (((latched & 0x7F) << 1) + i) ^ (latched >> 7)); + break; + case 0x8002: + for (i = 0; i < 4; i++) + setprg8(0x8000 + (i << 13), ((latched & 0x7F) << 1) + (latched >> 7)); + break; + case 0x8001: + case 0x8003: + for (i = 0; i < 4; i++) { + unsigned int b; + b = latched & 0x7F; + if (i >= 2 && !(latchea & 0x2)) + b = 0x7F; + setprg8(0x8000 + (i << 13), (i & 1) + ((b << 1) ^ (latched >> 7))); + } + break; + } +} + +static DECLFW(M15Write) { + latchea = A; + latched = V; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +static void M15Power(void) { + latchea = 0x8000; + latched = 0; + setchr8(0); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M15Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + Sync(); +} + +static void M15Reset(void) { + latchea = 0x8000; + latched = 0; + Sync(); +} + +static void M15Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper15_Init(CartInfo *info) { + info->Power = M15Power; + info->Reset = M15Reset; + info->Close = M15Close; + GameStateRestore = StateRestore; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/151.c b/src/boards/151.c index 2d9335f..45b7e2a 100644 --- a/src/boards/151.c +++ b/src/boards/151.c @@ -1,59 +1,59 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 regs[8]; - -static SFORMAT StateRegs[] = -{ - { regs, 8, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x8000, regs[0]); - setprg8(0xA000, regs[2]); - setprg8(0xC000, regs[4]); - setprg8(0xE000, ~0); - setchr4(0x0000, regs[6]); - setchr4(0x1000, regs[7]); -} - -static DECLFW(M151Write) { - regs[(A >> 12) & 7] = V; - Sync(); -} - -static void M151Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M151Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper151_Init(CartInfo *info) { - info->Power = M151Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 regs[8]; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[2]); + setprg8(0xC000, regs[4]); + setprg8(0xE000, ~0); + setchr4(0x0000, regs[6]); + setchr4(0x1000, regs[7]); +} + +static DECLFW(M151Write) { + regs[(A >> 12) & 7] = V; + Sync(); +} + +static void M151Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M151Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper151_Init(CartInfo *info) { + info->Power = M151Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/156.c b/src/boards/156.c index 24ba371..a605e69 100644 --- a/src/boards/156.c +++ b/src/boards/156.c @@ -1,120 +1,120 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * DIS23C01 DAOU ROM CONTROLLER, Korea - * Metal Force (K) - * Buzz and Waldog (K) - * General's Son (K) - * - */ - -#include "mapinc.h" - -static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &prg, 1, "PREG" }, - { chrlo, 8, "CRGL" }, - { chrhi, 8, "CRGH" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - uint32 i; - for (i = 0; i < 8; i++) - setchr1(i << 10, chrlo[i] | (chrhi[i] << 8)); - setprg8r(0x10, 0x6000, 0); - setprg16(0x8000, prg); - setprg16(0xC000, ~0); - if (mirrisused) - setmirror(mirr ^ 1); - else - setmirror(MI_0); -} - -static DECLFW(M156Write) { - switch (A) { - case 0xC000: - case 0xC001: - case 0xC002: - case 0xC003: chrlo[A & 3] = V; Sync(); break; - case 0xC004: - case 0xC005: - case 0xC006: - case 0xC007: chrhi[A & 3] = V; Sync(); break; - case 0xC008: - case 0xC009: - case 0xC00A: - case 0xC00B: chrlo[4 + (A & 3)] = V; Sync(); break; - case 0xC00C: - case 0xC00D: - case 0xC00E: - case 0xC00F: chrhi[4 + (A & 3)] = V; Sync(); break; - case 0xC010: prg = V; Sync(); break; - case 0xC014: mirr = V; mirrisused = 1; Sync(); break; - } -} - -static void M156Reset(void) { - uint32 i; - for (i = 0; i < 8; i++) { - chrlo[i] = 0; - chrhi[i] = 0; - } - prg = 0; - mirr = 0; - mirrisused = 0; -} - -static void M156Power(void) { - M156Reset(); - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0xC000, 0xCFFF, M156Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M156Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper156_Init(CartInfo *info) { - info->Reset = M156Reset; - info->Power = M156Power; - info->Close = M156Close; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * DIS23C01 DAOU ROM CONTROLLER, Korea + * Metal Force (K) + * Buzz and Waldog (K) + * General's Son (K) + * + */ + +#include "mapinc.h" + +static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &prg, 1, "PREG" }, + { chrlo, 8, "CRGL" }, + { chrhi, 8, "CRGH" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + uint32 i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chrlo[i] | (chrhi[i] << 8)); + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, prg); + setprg16(0xC000, ~0); + if (mirrisused) + setmirror(mirr ^ 1); + else + setmirror(MI_0); +} + +static DECLFW(M156Write) { + switch (A) { + case 0xC000: + case 0xC001: + case 0xC002: + case 0xC003: chrlo[A & 3] = V; Sync(); break; + case 0xC004: + case 0xC005: + case 0xC006: + case 0xC007: chrhi[A & 3] = V; Sync(); break; + case 0xC008: + case 0xC009: + case 0xC00A: + case 0xC00B: chrlo[4 + (A & 3)] = V; Sync(); break; + case 0xC00C: + case 0xC00D: + case 0xC00E: + case 0xC00F: chrhi[4 + (A & 3)] = V; Sync(); break; + case 0xC010: prg = V; Sync(); break; + case 0xC014: mirr = V; mirrisused = 1; Sync(); break; + } +} + +static void M156Reset(void) { + uint32 i; + for (i = 0; i < 8; i++) { + chrlo[i] = 0; + chrhi[i] = 0; + } + prg = 0; + mirr = 0; + mirrisused = 0; +} + +static void M156Power(void) { + M156Reset(); + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0xC000, 0xCFFF, M156Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M156Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper156_Init(CartInfo *info) { + info->Reset = M156Reset; + info->Power = M156Power; + info->Close = M156Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/168.c b/src/boards/168.c index 658b6bf..ae3f760 100644 --- a/src/boards/168.c +++ b/src/boards/168.c @@ -1,81 +1,81 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * RacerMate Challenge II - * - */ - -#include "mapinc.h" - -static uint8 reg; -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setchr4r(0x10, 0x0000, 0); - setchr4r(0x10, 0x1000, reg & 0x0f); - setprg16(0x8000, reg >> 6); - setprg16(0xc000, ~0); -} - -static DECLFW(M168Write) { - reg = V; - Sync(); -} - -static DECLFW(M168Dummy) { -} - -static void M168Power(void) { - reg = 0; - Sync(); - SetWriteHandler(0x4020, 0x7fff, M168Dummy); - SetWriteHandler(0xB000, 0xB000, M168Write); - SetWriteHandler(0xF000, 0xF000, M168Dummy); - SetWriteHandler(0xF080, 0xF080, M168Dummy); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void M168Close(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper168_Init(CartInfo *info) { - info->Power = M168Power; - info->Close = M168Close; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); - - CHRRAMSIZE = 8192 * 8; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * RacerMate Challenge II + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setchr4r(0x10, 0x0000, 0); + setchr4r(0x10, 0x1000, reg & 0x0f); + setprg16(0x8000, reg >> 6); + setprg16(0xc000, ~0); +} + +static DECLFW(M168Write) { + reg = V; + Sync(); +} + +static DECLFW(M168Dummy) { +} + +static void M168Power(void) { + reg = 0; + Sync(); + SetWriteHandler(0x4020, 0x7fff, M168Dummy); + SetWriteHandler(0xB000, 0xB000, M168Write); + SetWriteHandler(0xF000, 0xF000, M168Dummy); + SetWriteHandler(0xF080, 0xF080, M168Dummy); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M168Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper168_Init(CartInfo *info) { + info->Power = M168Power; + info->Close = M168Close; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); + + CHRRAMSIZE = 8192 * 8; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); +} diff --git a/src/boards/170.c b/src/boards/170.c index 9a8a8e5..37e8612 100644 --- a/src/boards/170.c +++ b/src/boards/170.c @@ -1,62 +1,62 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - */ - -#include "mapinc.h" - -static uint8 reg; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg16(0x8000, 0); - setprg16(0xc000, ~0); - setchr8(0); -} - -static DECLFW(M170ProtW) { - reg = V << 1 & 0x80; -} - -static DECLFR(M170ProtR) { - return reg | (X.DB & 0x7F); -} - -static void M170Power(void) { - Sync(); - SetWriteHandler(0x6502, 0x6502, M170ProtW); - SetWriteHandler(0x7000, 0x7000, M170ProtW); - SetReadHandler(0x7001, 0x7001, M170ProtR); - SetReadHandler(0x7777, 0x7777, M170ProtR); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper170_Init(CartInfo *info) { - info->Power = M170Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, 0); + setprg16(0xc000, ~0); + setchr8(0); +} + +static DECLFW(M170ProtW) { + reg = V << 1 & 0x80; +} + +static DECLFR(M170ProtR) { + return reg | (X.DB & 0x7F); +} + +static void M170Power(void) { + Sync(); + SetWriteHandler(0x6502, 0x6502, M170ProtW); + SetWriteHandler(0x7000, 0x7000, M170ProtW); + SetReadHandler(0x7001, 0x7001, M170ProtR); + SetReadHandler(0x7777, 0x7777, M170ProtR); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper170_Init(CartInfo *info) { + info->Power = M170Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/175.c b/src/boards/175.c index 8278607..91e52a8 100644 --- a/src/boards/175.c +++ b/src/boards/175.c @@ -1,79 +1,79 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg, delay, mirr; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setchr8(reg); - if (!delay) { - setprg16(0x8000, reg); - setprg8(0xC000, reg << 1); - } - setprg8(0xE000, (reg << 1) + 1); - setmirror(((mirr & 4) >> 2) ^ 1); -} - -static DECLFW(M175Write1) { - mirr = V; - delay = 1; - Sync(); -} - -static DECLFW(M175Write2) { - reg = V & 0x0F; - delay = 1; - Sync(); -} - -static DECLFR(M175Read) { - if (A == 0xFFFC) { - delay = 0; - Sync(); - } - return CartBR(A); -} - -static void M175Power(void) { - reg = mirr = delay = 0; - SetReadHandler(0x8000, 0xFFFF, M175Read); - SetWriteHandler(0x8000, 0x8000, M175Write1); - SetWriteHandler(0xA000, 0xA000, M175Write2); - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper175_Init(CartInfo *info) { - info->Power = M175Power; - GameStateRestore = StateRestore; - - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg, delay, mirr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setchr8(reg); + if (!delay) { + setprg16(0x8000, reg); + setprg8(0xC000, reg << 1); + } + setprg8(0xE000, (reg << 1) + 1); + setmirror(((mirr & 4) >> 2) ^ 1); +} + +static DECLFW(M175Write1) { + mirr = V; + delay = 1; + Sync(); +} + +static DECLFW(M175Write2) { + reg = V & 0x0F; + delay = 1; + Sync(); +} + +static DECLFR(M175Read) { + if (A == 0xFFFC) { + delay = 0; + Sync(); + } + return CartBR(A); +} + +static void M175Power(void) { + reg = mirr = delay = 0; + SetReadHandler(0x8000, 0xFFFF, M175Read); + SetWriteHandler(0x8000, 0x8000, M175Write1); + SetWriteHandler(0xA000, 0xA000, M175Write2); + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper175_Init(CartInfo *info) { + info->Power = M175Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/177.c b/src/boards/177.c index 0416060..bc87196 100644 --- a/src/boards/177.c +++ b/src/boards/177.c @@ -1,81 +1,81 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg; - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setchr8(0); - setprg8r(0x10, 0x6000, 0); - setprg32(0x8000, reg & 0x1f); - setmirror(((reg & 0x20) >> 5) ^ 1); -} - -static DECLFW(M177Write) { - reg = V; - Sync(); -} - -static void M177Power(void) { - reg = 0; - Sync(); - SetReadHandler(0x6000, 0x7fff, CartBR); - SetWriteHandler(0x6000, 0x7fff, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M177Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M177Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper177_Init(CartInfo *info) { - info->Power = M177Power; - info->Close = M177Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, reg & 0x1f); + setmirror(((reg & 0x20) >> 5) ^ 1); +} + +static DECLFW(M177Write) { + reg = V; + Sync(); +} + +static void M177Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M177Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M177Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper177_Init(CartInfo *info) { + info->Power = M177Power; + info->Close = M177Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/178.c b/src/boards/178.c index 64ae5f3..8f2a8d9 100644 --- a/src/boards/178.c +++ b/src/boards/178.c @@ -1,177 +1,177 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2013 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 - * - * DSOUNDV1/FL-TR8MA boards (32K WRAM, 8/16M), 178 mapper boards (8K WRAM, 4/8M) - * Various Education Cartridges - * - */ - -#include "mapinc.h" - -static uint8 reg[4]; - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -/* SND Registers */ -static uint8 pcm_enable = 0; -static int16 pcm_latch = 0x3F6, pcm_clock = 0x3F6; -static writefunc pcmwrite; - -static SFORMAT StateRegs[] = -{ - { reg, 4, "REGS" }, - { 0 } -}; - -static int16 step_size[49] = { - 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, - 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, - 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, - 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, - 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 -}; /* 49 items */ -static int32 step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; - -/* decode stuff */ -static int32 jedi_table[16 * 49]; -static int32 acc = 0; /* ADPCM accumulator, initial condition must be 0 */ -static int32 decstep = 0; /* ADPCM decoding step, initial condition must be 0 */ - -static void jedi_table_init() { - int step, nib; - - for (step = 0; step < 49; step++) { - for (nib = 0; nib < 16; nib++) { - int value = (2 * (nib & 0x07) + 1) * step_size[step] / 8; - jedi_table[step * 16 + nib] = ((nib & 0x08) != 0) ? -value : value; - } - } -} - -static uint8 decode(uint8 code) { - acc += jedi_table[decstep + code]; - if ((acc & ~0x7ff) != 0) /* acc is > 2047 */ - acc |= ~0xfff; - else acc &= 0xfff; - decstep += step_adj[code & 7] * 16; - if (decstep < 0) decstep = 0; - if (decstep > 48 * 16) decstep = 48 * 16; - return (acc >> 8) & 0xff; -} - -static void Sync(void) { - uint32 sbank = reg[1] & 0x7; - uint32 bbank = reg[2]; - setchr8(0); - setprg8r(0x10, 0x6000, reg[3] & 3); - if (reg[0] & 2) { /* UNROM mode */ - setprg16(0x8000, (bbank << 3) | sbank); - if (reg[0] & 4) - setprg16(0xC000, (bbank << 3) | 6 | (reg[1] & 1)); - else - setprg16(0xC000, (bbank << 3) | 7); - } else { /* NROM mode */ - uint32 bank = (bbank << 3) | sbank; - if (reg[0] & 4) { - setprg16(0x8000, bank); - setprg16(0xC000, bank); - } else - setprg32(0x8000, bank >> 1); - } - setmirror((reg[0] & 1) ^ 1); -} - -static DECLFW(M178Write) { - reg[A & 3] = V; -/* FCEU_printf("cmd %04x:%02x\n", A, V); */ - Sync(); -} - -static DECLFW(M178WriteSnd) { - if (A == 0x5800) { - if (V & 0xF0) { - pcm_enable = 1; -/* pcmwrite(0x4011, (V & 0xF) << 3); */ - pcmwrite(0x4011, decode(V & 0xf)); - } else - pcm_enable = 0; - } else - FCEU_printf("misc %04x:%02x\n", A, V); -} - -static DECLFR(M178ReadSnd) { - if (A == 0x5800) - return (X.DB & 0xBF) | ((pcm_enable ^ 1) << 6); - else - return X.DB; -} - -static void M178Power(void) { - reg[0] = reg[1] = reg[2] = reg[3] = 0; - Sync(); - pcmwrite = GetWriteHandler(0x4011); - SetWriteHandler(0x4800, 0x4fff, M178Write); - SetWriteHandler(0x5800, 0x5fff, M178WriteSnd); - SetReadHandler(0x5800, 0x5fff, M178ReadSnd); - SetReadHandler(0x6000, 0x7fff, CartBR); - SetWriteHandler(0x6000, 0x7fff, CartBW); - SetReadHandler(0x8000, 0xffff, CartBR); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M178SndClk(int a) { - if (pcm_enable) { - pcm_latch -= a; - if (pcm_latch <= 0) { - pcm_latch += pcm_clock; - pcm_enable = 0; - } - } -} - -static void M178Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper178_Init(CartInfo *info) { - info->Power = M178Power; - info->Close = M178Close; - GameStateRestore = StateRestore; - MapIRQHook = M178SndClk; - - jedi_table_init(); - - WRAMSIZE = 32768; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2013 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 + * + * DSOUNDV1/FL-TR8MA boards (32K WRAM, 8/16M), 178 mapper boards (8K WRAM, 4/8M) + * Various Education Cartridges + * + */ + +#include "mapinc.h" + +static uint8 reg[4]; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +/* SND Registers */ +static uint8 pcm_enable = 0; +static int16 pcm_latch = 0x3F6, pcm_clock = 0x3F6; +static writefunc pcmwrite; + +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { 0 } +}; + +static int16 step_size[49] = { + 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, + 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, + 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, + 279, 307, 337, 371, 408, 449, 494, 544, 598, 658, + 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552 +}; /* 49 items */ +static int32 step_adj[16] = { -1, -1, -1, -1, 2, 5, 7, 9, -1, -1, -1, -1, 2, 5, 7, 9 }; + +/* decode stuff */ +static int32 jedi_table[16 * 49]; +static int32 acc = 0; /* ADPCM accumulator, initial condition must be 0 */ +static int32 decstep = 0; /* ADPCM decoding step, initial condition must be 0 */ + +static void jedi_table_init() { + int step, nib; + + for (step = 0; step < 49; step++) { + for (nib = 0; nib < 16; nib++) { + int value = (2 * (nib & 0x07) + 1) * step_size[step] / 8; + jedi_table[step * 16 + nib] = ((nib & 0x08) != 0) ? -value : value; + } + } +} + +static uint8 decode(uint8 code) { + acc += jedi_table[decstep + code]; + if ((acc & ~0x7ff) != 0) /* acc is > 2047 */ + acc |= ~0xfff; + else acc &= 0xfff; + decstep += step_adj[code & 7] * 16; + if (decstep < 0) decstep = 0; + if (decstep > 48 * 16) decstep = 48 * 16; + return (acc >> 8) & 0xff; +} + +static void Sync(void) { + uint32 sbank = reg[1] & 0x7; + uint32 bbank = reg[2]; + setchr8(0); + setprg8r(0x10, 0x6000, reg[3] & 3); + if (reg[0] & 2) { /* UNROM mode */ + setprg16(0x8000, (bbank << 3) | sbank); + if (reg[0] & 4) + setprg16(0xC000, (bbank << 3) | 6 | (reg[1] & 1)); + else + setprg16(0xC000, (bbank << 3) | 7); + } else { /* NROM mode */ + uint32 bank = (bbank << 3) | sbank; + if (reg[0] & 4) { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } else + setprg32(0x8000, bank >> 1); + } + setmirror((reg[0] & 1) ^ 1); +} + +static DECLFW(M178Write) { + reg[A & 3] = V; +/* FCEU_printf("cmd %04x:%02x\n", A, V); */ + Sync(); +} + +static DECLFW(M178WriteSnd) { + if (A == 0x5800) { + if (V & 0xF0) { + pcm_enable = 1; +/* pcmwrite(0x4011, (V & 0xF) << 3); */ + pcmwrite(0x4011, decode(V & 0xf)); + } else + pcm_enable = 0; + } else + FCEU_printf("misc %04x:%02x\n", A, V); +} + +static DECLFR(M178ReadSnd) { + if (A == 0x5800) + return (X.DB & 0xBF) | ((pcm_enable ^ 1) << 6); + else + return X.DB; +} + +static void M178Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = 0; + Sync(); + pcmwrite = GetWriteHandler(0x4011); + SetWriteHandler(0x4800, 0x4fff, M178Write); + SetWriteHandler(0x5800, 0x5fff, M178WriteSnd); + SetReadHandler(0x5800, 0x5fff, M178ReadSnd); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xffff, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M178SndClk(int a) { + if (pcm_enable) { + pcm_latch -= a; + if (pcm_latch <= 0) { + pcm_latch += pcm_clock; + pcm_enable = 0; + } + } +} + +static void M178Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper178_Init(CartInfo *info) { + info->Power = M178Power; + info->Close = M178Close; + GameStateRestore = StateRestore; + MapIRQHook = M178SndClk; + + jedi_table_init(); + + WRAMSIZE = 32768; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/18.c b/src/boards/18.c index c0018ca..49f4675 100644 --- a/src/boards/18.c +++ b/src/boards/18.c @@ -1,133 +1,133 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 preg[4], creg[8]; -static uint8 IRQa, mirr; -static int32 IRQCount, IRQLatch; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { preg, 4, "PREG" }, - { creg, 8, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { &IRQLatch, 4, "IRQL" }, - { 0 } -}; - -static void Sync(void) { - int i; - for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, ~0); - if (mirr & 2) - setmirror(MI_0); - else - setmirror(mirr & 1); -} - -static DECLFW(M18WriteIRQ) { - switch (A & 0xF003) { - case 0xE000: IRQLatch &= 0xFFF0; IRQLatch |= (V & 0x0f) << 0x0; break; - case 0xE001: IRQLatch &= 0xFF0F; IRQLatch |= (V & 0x0f) << 0x4; break; - case 0xE002: IRQLatch &= 0xF0FF; IRQLatch |= (V & 0x0f) << 0x8; break; - case 0xE003: IRQLatch &= 0x0FFF; IRQLatch |= (V & 0x0f) << 0xC; break; - case 0xF000: IRQCount = IRQLatch; break; - case 0xF001: IRQa = V & 1; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xF002: mirr = V & 3; Sync(); break; - } -} - -static DECLFW(M18WritePrg) { - uint32 i = ((A >> 1) & 1) | ((A - 0x8000) >> 11); - preg[i] &= (0xF0) >> ((A & 1) << 2); - preg[i] |= (V & 0xF) << ((A & 1) << 2); - Sync(); -} - -static DECLFW(M18WriteChr) { - uint32 i = ((A >> 1) & 1) | ((A - 0xA000) >> 11); - creg[i] &= (0xF0) >> ((A & 1) << 2); - creg[i] |= (V & 0xF) << ((A & 1) << 2); - Sync(); -} - -static void M18Power(void) { - IRQa = 0; - preg[0] = 0; - preg[1] = 1; - preg[2] = ~1; - preg[3] = ~0; - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0x9FFF, M18WritePrg); - SetWriteHandler(0xA000, 0xDFFF, M18WriteChr); - SetWriteHandler(0xE000, 0xFFFF, M18WriteIRQ); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void FP_FASTAPASS(1) M18IRQHook(int a) { - if (IRQa && IRQCount) { - IRQCount -= a; - if (IRQCount <= 0) { - X6502_IRQBegin(FCEU_IQEXT); - IRQCount = 0; - IRQa = 0; - } - } -} - -static void M18Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper18_Init(CartInfo *info) { - info->Power = M18Power; - info->Close = M18Close; - MapIRQHook = M18IRQHook; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 preg[4], creg[8]; +static uint8 IRQa, mirr; +static int32 IRQCount, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + int i; + for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + if (mirr & 2) + setmirror(MI_0); + else + setmirror(mirr & 1); +} + +static DECLFW(M18WriteIRQ) { + switch (A & 0xF003) { + case 0xE000: IRQLatch &= 0xFFF0; IRQLatch |= (V & 0x0f) << 0x0; break; + case 0xE001: IRQLatch &= 0xFF0F; IRQLatch |= (V & 0x0f) << 0x4; break; + case 0xE002: IRQLatch &= 0xF0FF; IRQLatch |= (V & 0x0f) << 0x8; break; + case 0xE003: IRQLatch &= 0x0FFF; IRQLatch |= (V & 0x0f) << 0xC; break; + case 0xF000: IRQCount = IRQLatch; break; + case 0xF001: IRQa = V & 1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF002: mirr = V & 3; Sync(); break; + } +} + +static DECLFW(M18WritePrg) { + uint32 i = ((A >> 1) & 1) | ((A - 0x8000) >> 11); + preg[i] &= (0xF0) >> ((A & 1) << 2); + preg[i] |= (V & 0xF) << ((A & 1) << 2); + Sync(); +} + +static DECLFW(M18WriteChr) { + uint32 i = ((A >> 1) & 1) | ((A - 0xA000) >> 11); + creg[i] &= (0xF0) >> ((A & 1) << 2); + creg[i] |= (V & 0xF) << ((A & 1) << 2); + Sync(); +} + +static void M18Power(void) { + IRQa = 0; + preg[0] = 0; + preg[1] = 1; + preg[2] = ~1; + preg[3] = ~0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0x9FFF, M18WritePrg); + SetWriteHandler(0xA000, 0xDFFF, M18WriteChr); + SetWriteHandler(0xE000, 0xFFFF, M18WriteIRQ); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void FP_FASTAPASS(1) M18IRQHook(int a) { + if (IRQa && IRQCount) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = 0; + IRQa = 0; + } + } +} + +static void M18Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper18_Init(CartInfo *info) { + info->Power = M18Power; + info->Close = M18Close; + MapIRQHook = M18IRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/183.c b/src/boards/183.c index 9ba8c2c..219ccca 100644 --- a/src/boards/183.c +++ b/src/boards/183.c @@ -1,111 +1,111 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * Gimmick Bootleg (VRC4 mapper) - */ - -#include "mapinc.h" - -static uint8 prg[4], chr[8], mirr; -static uint8 IRQCount; -static uint8 IRQPre; -static uint8 IRQa; - -static SFORMAT StateRegs[] = -{ - { prg, 4, "PRG" }, - { chr, 8, "CHR" }, - { &mirr, 1, "MIRR" }, - { &IRQCount, 1, "IRQC" }, - { &IRQPre, 1, "IRQP" }, - { &IRQa, 1, "IRQA" }, - { 0 } -}; - -static void SyncPrg(void) { - setprg8(0x6000, prg[3]); - setprg8(0x8000, prg[0]); - setprg8(0xA000, prg[1]); - setprg8(0xC000, prg[2]); - setprg8(0xE000, ~0); -} - -static void SyncMirr(void) { - switch (mirr) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static void SyncChr(void) { - int i; - for (i = 0; i < 8; i++) - setchr1(i << 10, chr[i]); -} - -static void StateRestore(int version) { - SyncPrg(); - SyncChr(); - SyncMirr(); -} - -static DECLFW(M183Write) { - if ((A & 0xF800) == 0x6800) { - prg[3] = A & 0x3F; - SyncPrg(); - } else if (((A & 0xF80C) >= 0xB000) && ((A & 0xF80C) <= 0xE00C)) { - int index = (((A >> 11) - 6) | (A >> 3)) & 7; - chr[index] = (chr[index] & (0xF0 >> (A & 4))) | ((V & 0x0F) << (A & 4)); - SyncChr(); - } else switch (A & 0xF80C) { - case 0x8800: prg[0] = V; SyncPrg(); break; - case 0xA800: prg[1] = V; SyncPrg(); break; - case 0xA000: prg[2] = V; SyncPrg(); break; - case 0x9800: mirr = V & 3; SyncMirr(); break; - case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; - case 0xF004: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; - case 0xF008: IRQa = V; if (!V) IRQPre = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xF00C: IRQPre = 16; break; - } -} - -static void M183IRQCounter(void) { - if (IRQa) { - IRQCount++; - if ((IRQCount - IRQPre) == 238) - X6502_IRQBegin(FCEU_IQEXT); - } -} - -static void M183Power(void) { - IRQPre = IRQCount = IRQa = 0; - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0xFFFF, M183Write); - SyncPrg(); - SyncChr(); -} - -void Mapper183_Init(CartInfo *info) { - info->Power = M183Power; - GameHBIRQHook = M183IRQCounter; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * Gimmick Bootleg (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg[4], chr[8], mirr; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[] = +{ + { prg, 4, "PRG" }, + { chr, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQPre, 1, "IRQP" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static void SyncPrg(void) { + setprg8(0x6000, prg[3]); + setprg8(0x8000, prg[0]); + setprg8(0xA000, prg[1]); + setprg8(0xC000, prg[2]); + setprg8(0xE000, ~0); +} + +static void SyncMirr(void) { + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static void SyncChr(void) { + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); +} + +static void StateRestore(int version) { + SyncPrg(); + SyncChr(); + SyncMirr(); +} + +static DECLFW(M183Write) { + if ((A & 0xF800) == 0x6800) { + prg[3] = A & 0x3F; + SyncPrg(); + } else if (((A & 0xF80C) >= 0xB000) && ((A & 0xF80C) <= 0xE00C)) { + int index = (((A >> 11) - 6) | (A >> 3)) & 7; + chr[index] = (chr[index] & (0xF0 >> (A & 4))) | ((V & 0x0F) << (A & 4)); + SyncChr(); + } else switch (A & 0xF80C) { + case 0x8800: prg[0] = V; SyncPrg(); break; + case 0xA800: prg[1] = V; SyncPrg(); break; + case 0xA000: prg[2] = V; SyncPrg(); break; + case 0x9800: mirr = V & 3; SyncMirr(); break; + case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; + case 0xF004: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; + case 0xF008: IRQa = V; if (!V) IRQPre = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF00C: IRQPre = 16; break; + } +} + +static void M183IRQCounter(void) { + if (IRQa) { + IRQCount++; + if ((IRQCount - IRQPre) == 238) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void M183Power(void) { + IRQPre = IRQCount = IRQa = 0; + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, M183Write); + SyncPrg(); + SyncChr(); +} + +void Mapper183_Init(CartInfo *info) { + info->Power = M183Power; + GameHBIRQHook = M183IRQCounter; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/185.c b/src/boards/185.c index a0b18d1..cfea494 100644 --- a/src/boards/185.c +++ b/src/boards/185.c @@ -1,108 +1,108 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - */ - -#include "mapinc.h" - -static uint8 *DummyCHR = NULL; -static uint8 datareg; -static void (*Sync)(void); - - -static SFORMAT StateRegs[] = -{ - { &datareg, 1, "DREG" }, - { 0 } -}; - -/* on off -1 0x0F, 0xF0 - Bird Week -2 0x33, 0x00 - B-Wings -3 0x11, 0x00 - Mighty Bomb Jack -4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen -5 0xFF, 0x00 - Sansuu 3 Nen -6 0x21, 0x13 - Spy vs Spy -7 0x20, 0x21 - Seicross -*/ - -static void Sync185(void) { - /* little dirty eh? ;_) */ - if ((datareg & 3) && (datareg != 0x13)) /* 1, 2, 3, 4, 5, 6 */ - setchr8(0); - else - setchr8r(0x10, 0); -} - -static void Sync181(void) { - if (!(datareg & 1)) /* 7 */ - setchr8(0); - else - setchr8r(0x10, 0); -} - -static DECLFW(MWrite) { - datareg = V; - Sync(); -} - -static void MPower(void) { - datareg = 0; - Sync(); - setprg16(0x8000, 0); - setprg16(0xC000, ~0); - SetWriteHandler(0x8000, 0xFFFF, MWrite); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void MClose(void) { - if (DummyCHR) - FCEU_gfree(DummyCHR); - DummyCHR = NULL; -} - -static void MRestore(int version) { - Sync(); -} - -void Mapper185_Init(CartInfo *info) { - int x; - Sync = Sync185; - info->Power = MPower; - info->Close = MClose; - GameStateRestore = MRestore; - DummyCHR = (uint8*)FCEU_gmalloc(8192); - for (x = 0; x < 8192; x++) - DummyCHR[x] = 0xff; - SetupCartCHRMapping(0x10, DummyCHR, 8192, 0); - AddExState(StateRegs, ~0, 0, 0); -} - -void Mapper181_Init(CartInfo *info) { - int x; - Sync = Sync181; - info->Power = MPower; - info->Close = MClose; - GameStateRestore = MRestore; - DummyCHR = (uint8*)FCEU_gmalloc(8192); - for (x = 0; x < 8192; x++) - DummyCHR[x] = 0xff; - SetupCartCHRMapping(0x10, DummyCHR, 8192, 0); - AddExState(StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + */ + +#include "mapinc.h" + +static uint8 *DummyCHR = NULL; +static uint8 datareg; +static void (*Sync)(void); + + +static SFORMAT StateRegs[] = +{ + { &datareg, 1, "DREG" }, + { 0 } +}; + +/* on off +1 0x0F, 0xF0 - Bird Week +2 0x33, 0x00 - B-Wings +3 0x11, 0x00 - Mighty Bomb Jack +4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen +5 0xFF, 0x00 - Sansuu 3 Nen +6 0x21, 0x13 - Spy vs Spy +7 0x20, 0x21 - Seicross +*/ + +static void Sync185(void) { + /* little dirty eh? ;_) */ + if ((datareg & 3) && (datareg != 0x13)) /* 1, 2, 3, 4, 5, 6 */ + setchr8(0); + else + setchr8r(0x10, 0); +} + +static void Sync181(void) { + if (!(datareg & 1)) /* 7 */ + setchr8(0); + else + setchr8r(0x10, 0); +} + +static DECLFW(MWrite) { + datareg = V; + Sync(); +} + +static void MPower(void) { + datareg = 0; + Sync(); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + SetWriteHandler(0x8000, 0xFFFF, MWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void MClose(void) { + if (DummyCHR) + FCEU_gfree(DummyCHR); + DummyCHR = NULL; +} + +static void MRestore(int version) { + Sync(); +} + +void Mapper185_Init(CartInfo *info) { + int x; + Sync = Sync185; + info->Power = MPower; + info->Close = MClose; + GameStateRestore = MRestore; + DummyCHR = (uint8*)FCEU_gmalloc(8192); + for (x = 0; x < 8192; x++) + DummyCHR[x] = 0xff; + SetupCartCHRMapping(0x10, DummyCHR, 8192, 0); + AddExState(StateRegs, ~0, 0, 0); +} + +void Mapper181_Init(CartInfo *info) { + int x; + Sync = Sync181; + info->Power = MPower; + info->Close = MClose; + GameStateRestore = MRestore; + DummyCHR = (uint8*)FCEU_gmalloc(8192); + for (x = 0; x < 8192; x++) + DummyCHR[x] = 0xff; + SetupCartCHRMapping(0x10, DummyCHR, 8192, 0); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/src/boards/186.c b/src/boards/186.c index 10902dc..dddca91 100644 --- a/src/boards/186.c +++ b/src/boards/186.c @@ -1,95 +1,95 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * Family Study Box by Fukutake Shoten - */ - -#include "mapinc.h" - -static uint8 SWRAM[3072]; -static uint8 *WRAM = NULL; -static uint8 regs[4]; - -static SFORMAT StateRegs[] = -{ - { regs, 4, "DREG" }, - { SWRAM, 3072, "SWRM" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0x10, 0x6000, regs[0] >> 6); - setprg16(0x8000, regs[1]); - setprg16(0xc000, 0); -} - -static DECLFW(M186Write) { - if (A & 0x4203) regs[A & 3] = V; - Sync(); -} - -static DECLFR(M186Read) { - switch (A) { - case 0x4200: return 0x00; break; - case 0x4201: return 0x00; break; - case 0x4202: return 0x40; break; - case 0x4203: return 0x00; break; - } - return 0xFF; -} - -static DECLFR(ASWRAM) { - return(SWRAM[A - 0x4400]); -} -static DECLFW(BSWRAM) { - SWRAM[A - 0x4400] = V; -} - -static void M186Power(void) { - setchr8(0); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0xFFFF, CartBW); - SetReadHandler(0x4200, 0x43FF, M186Read); - SetWriteHandler(0x4200, 0x43FF, M186Write); - SetReadHandler(0x4400, 0x4FFF, ASWRAM); - SetWriteHandler(0x4400, 0x4FFF, BSWRAM); - FCEU_CheatAddRAM(32, 0x6000, WRAM); - regs[0] = regs[1] = regs[2] = regs[3]; - Sync(); -} - -static void M186Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void M186Restore(int version) { - Sync(); -} - -void Mapper186_Init(CartInfo *info) { - info->Power = M186Power; - info->Close = M186Close; - GameStateRestore = M186Restore; - WRAM = (uint8*)FCEU_gmalloc(32768); - SetupCartPRGMapping(0x10, WRAM, 32768, 1); - AddExState(WRAM, 32768, 0, "WRAM"); - AddExState(StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * Family Study Box by Fukutake Shoten + */ + +#include "mapinc.h" + +static uint8 SWRAM[3072]; +static uint8 *WRAM = NULL; +static uint8 regs[4]; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "DREG" }, + { SWRAM, 3072, "SWRM" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, regs[0] >> 6); + setprg16(0x8000, regs[1]); + setprg16(0xc000, 0); +} + +static DECLFW(M186Write) { + if (A & 0x4203) regs[A & 3] = V; + Sync(); +} + +static DECLFR(M186Read) { + switch (A) { + case 0x4200: return 0x00; break; + case 0x4201: return 0x00; break; + case 0x4202: return 0x40; break; + case 0x4203: return 0x00; break; + } + return 0xFF; +} + +static DECLFR(ASWRAM) { + return(SWRAM[A - 0x4400]); +} +static DECLFW(BSWRAM) { + SWRAM[A - 0x4400] = V; +} + +static void M186Power(void) { + setchr8(0); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, CartBW); + SetReadHandler(0x4200, 0x43FF, M186Read); + SetWriteHandler(0x4200, 0x43FF, M186Write); + SetReadHandler(0x4400, 0x4FFF, ASWRAM); + SetWriteHandler(0x4400, 0x4FFF, BSWRAM); + FCEU_CheatAddRAM(32, 0x6000, WRAM); + regs[0] = regs[1] = regs[2] = regs[3]; + Sync(); +} + +static void M186Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void M186Restore(int version) { + Sync(); +} + +void Mapper186_Init(CartInfo *info) { + info->Power = M186Power; + info->Close = M186Close; + GameStateRestore = M186Restore; + WRAM = (uint8*)FCEU_gmalloc(32768); + SetupCartPRGMapping(0x10, WRAM, 32768, 1); + AddExState(WRAM, 32768, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/src/boards/187.c b/src/boards/187.c index 6231dc4..701114b 100644 --- a/src/boards/187.c +++ b/src/boards/187.c @@ -1,88 +1,88 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * A98402 board, A9711, A9746 similar - * King of Fighters 96, The (Unl), Street Fighter Zero 2 (Unl) - * - */ - -#include "mapinc.h" -#include "mmc3.h" - -static void M187CW(uint32 A, uint8 V) { - if ((A & 0x1000) == ((MMC3_cmd & 0x80) << 5)) - setchr1(A, V | 0x100); - else - setchr1(A, V); -} - -static void M187PW(uint32 A, uint8 V) { - if (EXPREGS[0] & 0x80) { - uint8 bank = EXPREGS[0] & 0x1F; - if (EXPREGS[0] & 0x20) { - if (EXPREGS[0] & 0x40) - setprg32(0x8000, bank >> 2); - else - setprg32(0x8000, bank >> 1); /* hacky hacky! two mappers in one! need real hw carts to test */ - } else { - setprg16(0x8000, bank); - setprg16(0xC000, bank); - } - } else - setprg8(A, V & 0x3F); -} - -static DECLFW(M187Write8000) { - EXPREGS[1] = 1; - MMC3_CMDWrite(A, V); -} - -static DECLFW(M187Write8001) { - if (EXPREGS[1]) - MMC3_CMDWrite(A, V); -} - -static DECLFW(M187WriteLo) { - if ((A == 0x5000) || (A == 0x6000)) { - EXPREGS[0] = V; - FixMMC3PRG(MMC3_cmd); - } -} - -static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; -static DECLFR(M187Read) { - return prot_data[EXPREGS[1] & 3]; -} - -static void M187Power(void) { - EXPREGS[0] = EXPREGS[1] = 0; - GenMMC3Power(); - SetReadHandler(0x5000, 0x5FFF, M187Read); - SetWriteHandler(0x5000, 0x6FFF, M187WriteLo); - SetWriteHandler(0x8000, 0x8000, M187Write8000); - SetWriteHandler(0x8001, 0x8001, M187Write8001); -} - -void Mapper187_Init(CartInfo *info) { - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap = M187PW; - cwrap = M187CW; - info->Power = M187Power; - AddExState(EXPREGS, 3, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * A98402 board, A9711, A9746 similar + * King of Fighters 96, The (Unl), Street Fighter Zero 2 (Unl) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void M187CW(uint32 A, uint8 V) { + if ((A & 0x1000) == ((MMC3_cmd & 0x80) << 5)) + setchr1(A, V | 0x100); + else + setchr1(A, V); +} + +static void M187PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x80) { + uint8 bank = EXPREGS[0] & 0x1F; + if (EXPREGS[0] & 0x20) { + if (EXPREGS[0] & 0x40) + setprg32(0x8000, bank >> 2); + else + setprg32(0x8000, bank >> 1); /* hacky hacky! two mappers in one! need real hw carts to test */ + } else { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else + setprg8(A, V & 0x3F); +} + +static DECLFW(M187Write8000) { + EXPREGS[1] = 1; + MMC3_CMDWrite(A, V); +} + +static DECLFW(M187Write8001) { + if (EXPREGS[1]) + MMC3_CMDWrite(A, V); +} + +static DECLFW(M187WriteLo) { + if ((A == 0x5000) || (A == 0x6000)) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + } +} + +static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFR(M187Read) { + return prot_data[EXPREGS[1] & 3]; +} + +static void M187Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetReadHandler(0x5000, 0x5FFF, M187Read); + SetWriteHandler(0x5000, 0x6FFF, M187WriteLo); + SetWriteHandler(0x8000, 0x8000, M187Write8000); + SetWriteHandler(0x8001, 0x8001, M187Write8001); +} + +void Mapper187_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = M187PW; + cwrap = M187CW; + info->Power = M187Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/src/boards/189.c b/src/boards/189.c index 5b5026d..c3e1671 100644 --- a/src/boards/189.c +++ b/src/boards/189.c @@ -1,44 +1,44 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -static void M189PW(uint32 A, uint8 V) { - setprg32(0x8000, EXPREGS[0] & 7); -} - -static DECLFW(M189Write) { - EXPREGS[0] = V | (V >> 4); /* actually, there is a two versions of 189 mapper with hi or lo bits bankswitching. */ - FixMMC3PRG(MMC3_cmd); -} - -static void M189Power(void) { - EXPREGS[0] = EXPREGS[1] = 0; - GenMMC3Power(); - SetWriteHandler(0x4120, 0x7FFF, M189Write); -} - -void Mapper189_Init(CartInfo *info) { - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap = M189PW; - info->Power = M189Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void M189PW(uint32 A, uint8 V) { + setprg32(0x8000, EXPREGS[0] & 7); +} + +static DECLFW(M189Write) { + EXPREGS[0] = V | (V >> 4); /* actually, there is a two versions of 189 mapper with hi or lo bits bankswitching. */ + FixMMC3PRG(MMC3_cmd); +} + +static void M189Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetWriteHandler(0x4120, 0x7FFF, M189Write); +} + +void Mapper189_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = M189PW; + info->Power = M189Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/src/boards/190.c b/src/boards/190.c index 946f961..847d658 100644 --- a/src/boards/190.c +++ b/src/boards/190.c @@ -1,90 +1,90 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright (C) 2017 FCEUX 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 - * - * Magic Kid GooGoo - */ - -#include "mapinc.h" - -static uint8 preg, creg[4]; -static uint8 *WRAM = NULL; - -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { creg, 4, "CREG" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0x10, 0x6000, 0); - setprg16(0x8000, preg); - setprg16(0xC000, 0); - setchr2(0x0000, creg[0]); - setchr2(0x0800, creg[1]); - setchr2(0x1000, creg[2]); - setchr2(0x1800, creg[3]); -} - -static DECLFW(M190Write89) { - preg = V & 7; - Sync(); -} - -static DECLFW(M190WriteCD) { - preg = 8 | (V & 7); - Sync(); -} - -static DECLFW(M190WriteAB) { - creg[A & 3] = V; - Sync(); -} - -static void M190Power(void) { - creg[0] = creg[1] = creg[2] = creg[3] = 0; - preg = 0; - FCEU_CheatAddRAM(0x2000 >> 10, 0x6000, WRAM); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0x9FFF, M190Write89); - SetWriteHandler(0xA000, 0xBFFF, M190WriteAB); - SetWriteHandler(0xC000, 0xDFFF, M190WriteCD); - setmirror(MI_V); - Sync(); -} - -static void M190Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper190_Init(CartInfo *info) { - info->Power = M190Power; - info->Close = M190Close; - WRAM = (uint8*)FCEU_gmalloc(0x2000); - SetupCartPRGMapping(0x10, WRAM, 0x2000, 1); - AddExState(WRAM, 0x2000, 0, "WRAM"); - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright (C) 2017 FCEUX 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 + * + * Magic Kid GooGoo + */ + +#include "mapinc.h" + +static uint8 preg, creg[4]; +static uint8 *WRAM = NULL; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { creg, 4, "CREG" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, preg); + setprg16(0xC000, 0); + setchr2(0x0000, creg[0]); + setchr2(0x0800, creg[1]); + setchr2(0x1000, creg[2]); + setchr2(0x1800, creg[3]); +} + +static DECLFW(M190Write89) { + preg = V & 7; + Sync(); +} + +static DECLFW(M190WriteCD) { + preg = 8 | (V & 7); + Sync(); +} + +static DECLFW(M190WriteAB) { + creg[A & 3] = V; + Sync(); +} + +static void M190Power(void) { + creg[0] = creg[1] = creg[2] = creg[3] = 0; + preg = 0; + FCEU_CheatAddRAM(0x2000 >> 10, 0x6000, WRAM); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0x9FFF, M190Write89); + SetWriteHandler(0xA000, 0xBFFF, M190WriteAB); + SetWriteHandler(0xC000, 0xDFFF, M190WriteCD); + setmirror(MI_V); + Sync(); +} + +static void M190Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper190_Init(CartInfo *info) { + info->Power = M190Power; + info->Close = M190Close; + WRAM = (uint8*)FCEU_gmalloc(0x2000); + SetupCartPRGMapping(0x10, WRAM, 0x2000, 1); + AddExState(WRAM, 0x2000, 0, "WRAM"); + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/193.c b/src/boards/193.c index 32b9881..26f749a 100644 --- a/src/boards/193.c +++ b/src/boards/193.c @@ -1,74 +1,74 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * MEGA-SOFT WAR IN THE GULF - * - */ - -#include "mapinc.h" - -static uint8 reg[8]; -static uint8 mirror, cmd, bank; - -static SFORMAT StateRegs[] = -{ - { &cmd, 1, "CMD" }, - { &mirror, 1, "MIRR" }, - { &bank, 1, "BANK" }, - { reg, 8, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setmirror(mirror ^ 1); - setprg8(0x8000, reg[3]); - setprg8(0xA000, 0xD); - setprg8(0xC000, 0xE); - setprg8(0xE000, 0xF); - setchr4(0x0000, reg[0] >> 2); - setchr2(0x1000, reg[1] >> 1); - setchr2(0x1800, reg[2] >> 1); -} - -static DECLFW(M193Write) { - reg[A & 3] = V; - Sync(); -} - -static void M193Power(void) { - bank = 0; - Sync(); - SetWriteHandler(0x6000, 0x6003, M193Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, CartBW); -} - -static void M193Reset(void) { -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper193_Init(CartInfo *info) { - info->Reset = M193Reset; - info->Power = M193Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * MEGA-SOFT WAR IN THE GULF + * + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, bank; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { &mirror, 1, "MIRR" }, + { &bank, 1, "BANK" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirror ^ 1); + setprg8(0x8000, reg[3]); + setprg8(0xA000, 0xD); + setprg8(0xC000, 0xE); + setprg8(0xE000, 0xF); + setchr4(0x0000, reg[0] >> 2); + setchr2(0x1000, reg[1] >> 1); + setchr2(0x1800, reg[2] >> 1); +} + +static DECLFW(M193Write) { + reg[A & 3] = V; + Sync(); +} + +static void M193Power(void) { + bank = 0; + Sync(); + SetWriteHandler(0x6000, 0x6003, M193Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, CartBW); +} + +static void M193Reset(void) { +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper193_Init(CartInfo *info) { + info->Reset = M193Reset; + info->Power = M193Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/199.c b/src/boards/199.c index f8c9486..0c260af 100644 --- a/src/boards/199.c +++ b/src/boards/199.c @@ -1,97 +1,97 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - * Dragon Ball Z 2 - Gekishin Freeza! (C) - * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) - * San Guo Zhi 2 (C) - * - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; - -static void M199PW(uint32 A, uint8 V) { - setprg8(A, V); - setprg8(0xC000, EXPREGS[0]); - setprg8(0xE000, EXPREGS[1]); -} - -static void M199CW(uint32 A, uint8 V) { - setchr1r((V < 8) ? 0x10 : 0x00, A, V); - setchr1r((DRegBuf[0] < 8) ? 0x10 : 0x00, 0x0000, DRegBuf[0]); - setchr1r((EXPREGS[2] < 8) ? 0x10 : 0x00, 0x0400, EXPREGS[2]); - setchr1r((DRegBuf[1] < 8) ? 0x10 : 0x00, 0x0800, DRegBuf[1]); - setchr1r((EXPREGS[3] < 8) ? 0x10 : 0x00, 0x0c00, EXPREGS[3]); -} - -static void M199MW(uint8 V) { -/* FCEU_printf("%02x\n",V); */ - switch (V & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(M199Write) { - if ((A == 0x8001) && (MMC3_cmd & 8)) { - EXPREGS[MMC3_cmd & 3] = V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } else - if (A < 0xC000) - MMC3_CMDWrite(A, V); - else - MMC3_IRQWrite(A, V); -} - -static void M199Power(void) { - EXPREGS[0] = ~1; - EXPREGS[1] = ~0; - EXPREGS[2] = 1; - EXPREGS[3] = 3; - GenMMC3Power(); - SetWriteHandler(0x8000, 0xFFFF, M199Write); -} - -static void M199Close(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; -} - -void Mapper199_Init(CartInfo *info) { - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap = M199CW; - pwrap = M199PW; - mwrap = M199MW; - info->Power = M199Power; - info->Close = M199Close; - - CHRRAMSIZE = 8192; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); - - AddExState(EXPREGS, 4, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + * Dragon Ball Z 2 - Gekishin Freeza! (C) + * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) + * San Guo Zhi 2 (C) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static void M199PW(uint32 A, uint8 V) { + setprg8(A, V); + setprg8(0xC000, EXPREGS[0]); + setprg8(0xE000, EXPREGS[1]); +} + +static void M199CW(uint32 A, uint8 V) { + setchr1r((V < 8) ? 0x10 : 0x00, A, V); + setchr1r((DRegBuf[0] < 8) ? 0x10 : 0x00, 0x0000, DRegBuf[0]); + setchr1r((EXPREGS[2] < 8) ? 0x10 : 0x00, 0x0400, EXPREGS[2]); + setchr1r((DRegBuf[1] < 8) ? 0x10 : 0x00, 0x0800, DRegBuf[1]); + setchr1r((EXPREGS[3] < 8) ? 0x10 : 0x00, 0x0c00, EXPREGS[3]); +} + +static void M199MW(uint8 V) { +/* FCEU_printf("%02x\n",V); */ + switch (V & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M199Write) { + if ((A == 0x8001) && (MMC3_cmd & 8)) { + EXPREGS[MMC3_cmd & 3] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + if (A < 0xC000) + MMC3_CMDWrite(A, V); + else + MMC3_IRQWrite(A, V); +} + +static void M199Power(void) { + EXPREGS[0] = ~1; + EXPREGS[1] = ~0; + EXPREGS[2] = 1; + EXPREGS[3] = 3; + GenMMC3Power(); + SetWriteHandler(0x8000, 0xFFFF, M199Write); +} + +static void M199Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +void Mapper199_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap = M199CW; + pwrap = M199PW; + mwrap = M199MW; + info->Power = M199Power; + info->Close = M199Close; + + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/src/boards/208.c b/src/boards/208.c index d581b1e..151c135 100644 --- a/src/boards/208.c +++ b/src/boards/208.c @@ -1,78 +1,78 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 lut[256] = { - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, - 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, - 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -static void M208PW(uint32 A, uint8 V) { - setprg32(0x8000, EXPREGS[5]); -} - -static DECLFW(M208Write) { - EXPREGS[5] = (V & 0x1) | ((V >> 3) & 0x2); - FixMMC3PRG(MMC3_cmd); -} - -static DECLFW(M208ProtWrite) { - if (A <= 0x57FF) - EXPREGS[4] = V; - else - EXPREGS[(A & 0x03)] = V ^ lut[EXPREGS[4]]; -} - -static DECLFR(M208ProtRead) { - return(EXPREGS[(A & 0x3)]); -} - -static void M208Power(void) { - EXPREGS[5] = 3; - GenMMC3Power(); - SetWriteHandler(0x4800, 0x4fff, M208Write); - SetWriteHandler(0x6800, 0x6fff, M208Write); - SetWriteHandler(0x5000, 0x5fff, M208ProtWrite); - SetReadHandler(0x5800, 0x5fff, M208ProtRead); - SetReadHandler(0x8000, 0xffff, CartBR); -} - -void Mapper208_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 256, 0, 0); - pwrap = M208PW; - info->Power = M208Power; - AddExState(EXPREGS, 6, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 lut[256] = { + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static void M208PW(uint32 A, uint8 V) { + setprg32(0x8000, EXPREGS[5]); +} + +static DECLFW(M208Write) { + EXPREGS[5] = (V & 0x1) | ((V >> 3) & 0x2); + FixMMC3PRG(MMC3_cmd); +} + +static DECLFW(M208ProtWrite) { + if (A <= 0x57FF) + EXPREGS[4] = V; + else + EXPREGS[(A & 0x03)] = V ^ lut[EXPREGS[4]]; +} + +static DECLFR(M208ProtRead) { + return(EXPREGS[(A & 0x3)]); +} + +static void M208Power(void) { + EXPREGS[5] = 3; + GenMMC3Power(); + SetWriteHandler(0x4800, 0x4fff, M208Write); + SetWriteHandler(0x6800, 0x6fff, M208Write); + SetWriteHandler(0x5000, 0x5fff, M208ProtWrite); + SetReadHandler(0x5800, 0x5fff, M208ProtRead); + SetReadHandler(0x8000, 0xffff, CartBR); +} + +void Mapper208_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + pwrap = M208PW; + info->Power = M208Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} diff --git a/src/boards/222.c b/src/boards/222.c index da3cccb..3eee006 100644 --- a/src/boards/222.c +++ b/src/boards/222.c @@ -1,101 +1,101 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * (VRC4 mapper) - * - */ - -#include "mapinc.h" - -static uint8 IRQCount; /*, IRQPre; */ -static uint8 IRQa; -static uint8 prg_reg[2]; -static uint8 chr_reg[8]; -static uint8 mirr; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 1, "IRQC" }, - { &IRQa, 1, "IRQA" }, - { prg_reg, 2, "PRG" }, - { chr_reg, 8, "CHR" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void M222IRQ(void) { - if (IRQa) { - IRQCount++; - if (IRQCount >= 238) { - X6502_IRQBegin(FCEU_IQEXT); -/* IRQa=0; */ - } - } -} - -static void Sync(void) { - int i; - setprg8(0x8000, prg_reg[0]); - setprg8(0xA000, prg_reg[1]); - for (i = 0; i < 8; i++) - setchr1(i << 10, chr_reg[i]); - setmirror(mirr ^ 1); -} - -static DECLFW(M222Write) { - switch (A & 0xF003) { - case 0x8000: prg_reg[0] = V; break; - case 0x9000: mirr = V & 1; break; - case 0xA000: prg_reg[1] = V; break; - case 0xB000: chr_reg[0] = V; break; - case 0xB002: chr_reg[1] = V; break; - case 0xC000: chr_reg[2] = V; break; - case 0xC002: chr_reg[3] = V; break; - case 0xD000: chr_reg[4] = V; break; - case 0xD002: chr_reg[5] = V; break; - case 0xE000: chr_reg[6] = V; break; - case 0xE002: chr_reg[7] = V; break; -#if 0 - case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break; - case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; - case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; - case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; -#endif - case 0xF000: IRQa = IRQCount = V; if (scanline < 240) IRQCount -= 8; else IRQCount += 4; X6502_IRQEnd(FCEU_IQEXT); break; - } - Sync(); -} - -static void M222Power(void) { - setprg16(0xC000, ~0); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M222Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper222_Init(CartInfo *info) { - info->Power = M222Power; - GameHBIRQHook = M222IRQ; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * (VRC4 mapper) + * + */ + +#include "mapinc.h" + +static uint8 IRQCount; /*, IRQPre; */ +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { prg_reg, 2, "PRG" }, + { chr_reg, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void M222IRQ(void) { + if (IRQa) { + IRQCount++; + if (IRQCount >= 238) { + X6502_IRQBegin(FCEU_IQEXT); +/* IRQa=0; */ + } + } +} + +static void Sync(void) { + int i; + setprg8(0x8000, prg_reg[0]); + setprg8(0xA000, prg_reg[1]); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr_reg[i]); + setmirror(mirr ^ 1); +} + +static DECLFW(M222Write) { + switch (A & 0xF003) { + case 0x8000: prg_reg[0] = V; break; + case 0x9000: mirr = V & 1; break; + case 0xA000: prg_reg[1] = V; break; + case 0xB000: chr_reg[0] = V; break; + case 0xB002: chr_reg[1] = V; break; + case 0xC000: chr_reg[2] = V; break; + case 0xC002: chr_reg[3] = V; break; + case 0xD000: chr_reg[4] = V; break; + case 0xD002: chr_reg[5] = V; break; + case 0xE000: chr_reg[6] = V; break; + case 0xE002: chr_reg[7] = V; break; +#if 0 + case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break; + case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; + case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; + case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; +#endif + case 0xF000: IRQa = IRQCount = V; if (scanline < 240) IRQCount -= 8; else IRQCount += 4; X6502_IRQEnd(FCEU_IQEXT); break; + } + Sync(); +} + +static void M222Power(void) { + setprg16(0xC000, ~0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M222Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper222_Init(CartInfo *info) { + info->Power = M222Power; + GameHBIRQHook = M222IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/225.c b/src/boards/225.c index 15fdd60..2fb9768 100644 --- a/src/boards/225.c +++ b/src/boards/225.c @@ -1,89 +1,89 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * PCB-018 board, discrete multigame cart 110-in-1 - * - */ - -#include "mapinc.h" - -static uint8 prot[4], prg, mode, chr, mirr; - -static SFORMAT StateRegs[] = -{ - { prot, 4, "PROT" }, - { &prg, 1, "PRG" }, - { &chr, 1, "CHR" }, - { &mode, 1, "MODE" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - if (mode) { - setprg16(0x8000, prg); - setprg16(0xC000, prg); - } else - setprg32(0x8000, prg >> 1); - setchr8(chr); - setmirror(mirr ^ 1); -} - -static DECLFW(M225Write) { - uint32 bank = (A >> 14) & 1; - mirr = (A >> 13) & 1; - mode = (A >> 12) & 1; - chr = (A & 0x3f) | (bank << 6); - prg = ((A >> 6) & 0x3f) | (bank << 6); - Sync(); -} - -static DECLFW(M225LoWrite) { -} - -static DECLFR(M225LoRead) { - return 0; -} - -static void M225Power(void) { - prg = 0; - mode = 0; - Sync(); - SetReadHandler(0x5000, 0x5fff, M225LoRead); - SetWriteHandler(0x5000, 0x5fff, M225LoWrite); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M225Write); -} - -static void M225Reset(void) { - prg = 0; - mode = 0; - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper225_Init(CartInfo *info) { - info->Reset = M225Reset; - info->Power = M225Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * PCB-018 board, discrete multigame cart 110-in-1 + * + */ + +#include "mapinc.h" + +static uint8 prot[4], prg, mode, chr, mirr; + +static SFORMAT StateRegs[] = +{ + { prot, 4, "PROT" }, + { &prg, 1, "PRG" }, + { &chr, 1, "CHR" }, + { &mode, 1, "MODE" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + if (mode) { + setprg16(0x8000, prg); + setprg16(0xC000, prg); + } else + setprg32(0x8000, prg >> 1); + setchr8(chr); + setmirror(mirr ^ 1); +} + +static DECLFW(M225Write) { + uint32 bank = (A >> 14) & 1; + mirr = (A >> 13) & 1; + mode = (A >> 12) & 1; + chr = (A & 0x3f) | (bank << 6); + prg = ((A >> 6) & 0x3f) | (bank << 6); + Sync(); +} + +static DECLFW(M225LoWrite) { +} + +static DECLFR(M225LoRead) { + return 0; +} + +static void M225Power(void) { + prg = 0; + mode = 0; + Sync(); + SetReadHandler(0x5000, 0x5fff, M225LoRead); + SetWriteHandler(0x5000, 0x5fff, M225LoWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M225Write); +} + +static void M225Reset(void) { + prg = 0; + mode = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper225_Init(CartInfo *info) { + info->Reset = M225Reset; + info->Power = M225Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/228.c b/src/boards/228.c index 9b63da3..af23d24 100644 --- a/src/boards/228.c +++ b/src/boards/228.c @@ -1,85 +1,85 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 mram[4], vreg; -static uint16 areg; - -static SFORMAT StateRegs[] = -{ - { mram, 4, "MRAM" }, - { &areg, 2, "AREG" }, - { &vreg, 1, "VREG" }, - { 0 } -}; - -static void Sync(void) { - uint32 prgl, prgh, page = (areg >> 7) & 0x3F; - if ((page & 0x30) == 0x30) - page -= 0x10; - prgl = prgh = (page << 1) + (((areg >> 6) & 1) & ((areg >> 5) & 1)); - prgh += ((areg >> 5) & 1) ^ 1; - - setmirror(((areg >> 13) & 1) ^ 1); - setprg16(0x8000, prgl); - setprg16(0xc000, prgh); - setchr8(((vreg & 0x3) | ((areg & 0xF) << 2))); -} - -static DECLFW(M228RamWrite) { - mram[A & 3] = V & 0x0F; -} - -static DECLFR(M228RamRead) { - return mram[A & 3]; -} - -static DECLFW(M228Write) { - areg = A; - vreg = V; - Sync(); -} - -static void M228Reset(void) { - areg = 0x8000; - vreg = 0; - memset(mram, 0, sizeof(mram)); - Sync(); -} - -static void M228Power(void) { - M228Reset(); - SetReadHandler(0x5000, 0x5FFF, M228RamRead); - SetWriteHandler(0x5000, 0x5FFF, M228RamWrite); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M228Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper228_Init(CartInfo *info) { - info->Reset = M228Reset; - info->Power = M228Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 mram[4], vreg; +static uint16 areg; + +static SFORMAT StateRegs[] = +{ + { mram, 4, "MRAM" }, + { &areg, 2, "AREG" }, + { &vreg, 1, "VREG" }, + { 0 } +}; + +static void Sync(void) { + uint32 prgl, prgh, page = (areg >> 7) & 0x3F; + if ((page & 0x30) == 0x30) + page -= 0x10; + prgl = prgh = (page << 1) + (((areg >> 6) & 1) & ((areg >> 5) & 1)); + prgh += ((areg >> 5) & 1) ^ 1; + + setmirror(((areg >> 13) & 1) ^ 1); + setprg16(0x8000, prgl); + setprg16(0xc000, prgh); + setchr8(((vreg & 0x3) | ((areg & 0xF) << 2))); +} + +static DECLFW(M228RamWrite) { + mram[A & 3] = V & 0x0F; +} + +static DECLFR(M228RamRead) { + return mram[A & 3]; +} + +static DECLFW(M228Write) { + areg = A; + vreg = V; + Sync(); +} + +static void M228Reset(void) { + areg = 0x8000; + vreg = 0; + memset(mram, 0, sizeof(mram)); + Sync(); +} + +static void M228Power(void) { + M228Reset(); + SetReadHandler(0x5000, 0x5FFF, M228RamRead); + SetWriteHandler(0x5000, 0x5FFF, M228RamWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M228Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper228_Init(CartInfo *info) { + info->Reset = M228Reset; + info->Power = M228Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/230.c b/src/boards/230.c index 174a70c..89e235b 100644 --- a/src/boards/230.c +++ b/src/boards/230.c @@ -1,78 +1,78 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 CaH4e3 - * Copyright (C) 2009 qeed - * - * 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 - * - * 22 + Contra Reset based custom mapper... - * - */ - -#include "mapinc.h" - -static uint8 latche, reset; -static SFORMAT StateRegs[] = -{ - { &reset, 1, "RST" }, - { &latche, 1, "LATC" }, - { 0 } -}; - -static void Sync(void) { - if (reset) { - setprg16(0x8000, latche & 7); - setprg16(0xC000, 7); - setmirror(MI_V); - } else { - uint32 bank = (latche & 0x1F) + 8; - if (latche & 0x20) { - setprg16(0x8000, bank); - setprg16(0xC000, bank); - } else - setprg32(0x8000, bank >> 1); - setmirror((latche >> 6) & 1); - } - setchr8(0); -} - -static DECLFW(M230Write) { - latche = V; - Sync(); -} - -static void M230Reset(void) { - reset ^= 1; - Sync(); -} - -static void M230Power(void) { - latche = reset = 0; - Sync(); - SetWriteHandler(0x8000, 0xFFFF, M230Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper230_Init(CartInfo *info) { - info->Power = M230Power; - info->Reset = M230Reset; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2009 qeed + * + * 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 + * + * 22 + Contra Reset based custom mapper... + * + */ + +#include "mapinc.h" + +static uint8 latche, reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "RST" }, + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + if (reset) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, 7); + setmirror(MI_V); + } else { + uint32 bank = (latche & 0x1F) + 8; + if (latche & 0x20) { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } else + setprg32(0x8000, bank >> 1); + setmirror((latche >> 6) & 1); + } + setchr8(0); +} + +static DECLFW(M230Write) { + latche = V; + Sync(); +} + +static void M230Reset(void) { + reset ^= 1; + Sync(); +} + +static void M230Power(void) { + latche = reset = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M230Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper230_Init(CartInfo *info) { + info->Power = M230Power; + info->Reset = M230Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/232.c b/src/boards/232.c index a42a02f..ec1dbba 100644 --- a/src/boards/232.c +++ b/src/boards/232.c @@ -1,69 +1,69 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 bank, preg; -static SFORMAT StateRegs[] = -{ - { &bank, 1, "BANK" }, - { &preg, 1, "PREG" }, - { 0 } -}; - -static void Sync(void) { -/* uint32 bbank = (bank & 0x18) >> 1; */ - uint32 bbank = ((bank & 0x10) >> 2) | (bank & 8); /* some dumps have bbanks swapped, if swap commands, - * then all roms can be played, but with some swapped - * games in menu. if not, some dumps are unplayable - * make hard dump for both cart types to check - */ - setprg16(0x8000, bbank | (preg & 3)); - setprg16(0xC000, bbank | 3); - setchr8(0); -} - -static DECLFW(M232WriteBank) { - bank = V; - Sync(); -} - -static DECLFW(M232WritePreg) { - preg = V; - Sync(); -} - -static void M232Power(void) { - bank = preg = 0; - Sync(); - SetWriteHandler(0x8000, 0xBFFF, M232WriteBank); - SetWriteHandler(0xC000, 0xFFFF, M232WritePreg); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper232_Init(CartInfo *info) { - info->Power = M232Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 bank, preg; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { +/* uint32 bbank = (bank & 0x18) >> 1; */ + uint32 bbank = ((bank & 0x10) >> 2) | (bank & 8); /* some dumps have bbanks swapped, if swap commands, + * then all roms can be played, but with some swapped + * games in menu. if not, some dumps are unplayable + * make hard dump for both cart types to check + */ + setprg16(0x8000, bbank | (preg & 3)); + setprg16(0xC000, bbank | 3); + setchr8(0); +} + +static DECLFW(M232WriteBank) { + bank = V; + Sync(); +} + +static DECLFW(M232WritePreg) { + preg = V; + Sync(); +} + +static void M232Power(void) { + bank = preg = 0; + Sync(); + SetWriteHandler(0x8000, 0xBFFF, M232WriteBank); + SetWriteHandler(0xC000, 0xFFFF, M232WritePreg); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper232_Init(CartInfo *info) { + info->Power = M232Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/234.c b/src/boards/234.c index ef255bd..2037c53 100644 --- a/src/boards/234.c +++ b/src/boards/234.c @@ -1,79 +1,79 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 bank, preg; -static SFORMAT StateRegs[] = -{ - { &bank, 1, "BANK" }, - { &preg, 1, "PREG" }, - { 0 } -}; - -static void Sync(void) { - if (bank & 0x40) { - setprg32(0x8000, (bank & 0xE) | (preg & 1)); - setchr8(((bank & 0xE) << 2) | ((preg >> 4) & 7)); - } else { - setprg32(0x8000, bank & 0xF); - setchr8(((bank & 0xF) << 2) | ((preg >> 4) & 3)); - } - setmirror((bank >> 7) ^ 1); -} - -DECLFR(M234ReadBank) { - uint8 r = CartBR(A); - if (!bank) { - bank = r; - Sync(); - } - return r; -} - -DECLFR(M234ReadPreg) { - uint8 r = CartBR(A); - preg = r; - Sync(); - return r; -} - -static void M234Reset(void) { - bank = preg = 0; - Sync(); -} - -static void M234Power(void) { - M234Reset(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetReadHandler(0xFF80, 0xFF9F, M234ReadBank); - SetReadHandler(0xFFE8, 0xFFF7, M234ReadPreg); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper234_Init(CartInfo *info) { - info->Power = M234Power; - info->Reset = M234Reset; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 bank, preg; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { + if (bank & 0x40) { + setprg32(0x8000, (bank & 0xE) | (preg & 1)); + setchr8(((bank & 0xE) << 2) | ((preg >> 4) & 7)); + } else { + setprg32(0x8000, bank & 0xF); + setchr8(((bank & 0xF) << 2) | ((preg >> 4) & 3)); + } + setmirror((bank >> 7) ^ 1); +} + +DECLFR(M234ReadBank) { + uint8 r = CartBR(A); + if (!bank) { + bank = r; + Sync(); + } + return r; +} + +DECLFR(M234ReadPreg) { + uint8 r = CartBR(A); + preg = r; + Sync(); + return r; +} + +static void M234Reset(void) { + bank = preg = 0; + Sync(); +} + +static void M234Power(void) { + M234Reset(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0xFF80, 0xFF9F, M234ReadBank); + SetReadHandler(0xFFE8, 0xFFF7, M234ReadPreg); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper234_Init(CartInfo *info) { + info->Power = M234Power; + info->Reset = M234Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/235.c b/src/boards/235.c index 98ce11b..b2aca1d 100644 --- a/src/boards/235.c +++ b/src/boards/235.c @@ -1,63 +1,63 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" - -static uint16 cmdreg; -static SFORMAT StateRegs[] = -{ - { &cmdreg, 2, "CREG" }, - { 0 } -}; - -static void Sync(void) { - if (cmdreg & 0x400) - setmirror(MI_0); - else - setmirror(((cmdreg >> 13) & 1) ^ 1); - if (cmdreg & 0x800) { - setprg16(0x8000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); - setprg16(0xC000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); - } else - setprg32(0x8000, ((cmdreg & 0x300) >> 4) | (cmdreg & 0x1F)); -} - -static DECLFW(M235Write) { - cmdreg = A; - Sync(); -} - -static void M235Power(void) { - setchr8(0); - SetWriteHandler(0x8000, 0xFFFF, M235Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); - cmdreg = 0; - Sync(); -} - -static void M235Restore(int version) { - Sync(); -} - -void Mapper235_Init(CartInfo *info) { - info->Power = M235Power; - GameStateRestore = M235Restore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static SFORMAT StateRegs[] = +{ + { &cmdreg, 2, "CREG" }, + { 0 } +}; + +static void Sync(void) { + if (cmdreg & 0x400) + setmirror(MI_0); + else + setmirror(((cmdreg >> 13) & 1) ^ 1); + if (cmdreg & 0x800) { + setprg16(0x8000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); + setprg16(0xC000, ((cmdreg & 0x300) >> 3) | ((cmdreg & 0x1F) << 1) | ((cmdreg >> 12) & 1)); + } else + setprg32(0x8000, ((cmdreg & 0x300) >> 4) | (cmdreg & 0x1F)); +} + +static DECLFW(M235Write) { + cmdreg = A; + Sync(); +} + +static void M235Power(void) { + setchr8(0); + SetWriteHandler(0x8000, 0xFFFF, M235Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + cmdreg = 0; + Sync(); +} + +static void M235Restore(int version) { + Sync(); +} + +void Mapper235_Init(CartInfo *info) { + info->Power = M235Power; + GameStateRestore = M235Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/244.c b/src/boards/244.c index 67c3369..f5d696e 100644 --- a/src/boards/244.c +++ b/src/boards/244.c @@ -1,77 +1,77 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 preg, creg; -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { &creg, 1, "CREG" }, - { 0 } -}; - -static uint8 prg_perm[4][4] = { - { 0, 1, 2, 3, }, - { 3, 2, 1, 0, }, - { 0, 2, 1, 3, }, - { 3, 1, 2, 0, }, -}; - -static uint8 chr_perm[8][8] = { - { 0, 1, 2, 3, 4, 5, 6, 7, }, - { 0, 2, 1, 3, 4, 6, 5, 7, }, - { 0, 1, 4, 5, 2, 3, 6, 7, }, - { 0, 4, 1, 5, 2, 6, 3, 7, }, - { 0, 4, 2, 6, 1, 5, 3, 7, }, - { 0, 2, 4, 6, 1, 3, 5, 7, }, - { 7, 6, 5, 4, 3, 2, 1, 0, }, - { 7, 6, 5, 4, 3, 2, 1, 0, }, -}; - -static void Sync(void) { - setprg32(0x8000, preg); - setchr8(creg); -} - -static DECLFW(M244Write) { - if (V & 8) - creg = chr_perm[(V >> 4) & 7][V & 7]; - else - preg = prg_perm[(V >> 4) & 3][V & 3]; - Sync(); -} - -static void M244Power(void) { - preg = creg = 0; - Sync(); - SetWriteHandler(0x8000, 0xFFFF, M244Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper244_Init(CartInfo *info) { - info->Power = M244Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 preg, creg; +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { 0 } +}; + +static uint8 prg_perm[4][4] = { + { 0, 1, 2, 3, }, + { 3, 2, 1, 0, }, + { 0, 2, 1, 3, }, + { 3, 1, 2, 0, }, +}; + +static uint8 chr_perm[8][8] = { + { 0, 1, 2, 3, 4, 5, 6, 7, }, + { 0, 2, 1, 3, 4, 6, 5, 7, }, + { 0, 1, 4, 5, 2, 3, 6, 7, }, + { 0, 4, 1, 5, 2, 6, 3, 7, }, + { 0, 4, 2, 6, 1, 5, 3, 7, }, + { 0, 2, 4, 6, 1, 3, 5, 7, }, + { 7, 6, 5, 4, 3, 2, 1, 0, }, + { 7, 6, 5, 4, 3, 2, 1, 0, }, +}; + +static void Sync(void) { + setprg32(0x8000, preg); + setchr8(creg); +} + +static DECLFW(M244Write) { + if (V & 8) + creg = chr_perm[(V >> 4) & 7][V & 7]; + else + preg = prg_perm[(V >> 4) & 3][V & 3]; + Sync(); +} + +static void M244Power(void) { + preg = creg = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M244Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper244_Init(CartInfo *info) { + info->Power = M244Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/246.c b/src/boards/246.c index 3d673d8..8193f6c 100644 --- a/src/boards/246.c +++ b/src/boards/246.c @@ -1,86 +1,86 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 regs[8]; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { regs, 8, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg2r(0x10, 0x6800, 0); - setprg8(0x8000, regs[0]); - setprg8(0xA000, regs[1]); - setprg8(0xC000, regs[2]); - setprg8(0xE000, regs[3]); - setchr2(0x0000, regs[4]); - setchr2(0x0800, regs[5]); - setchr2(0x1000, regs[6]); - setchr2(0x1800, regs[7]); -} - -static DECLFW(M246Write) { - regs[A & 7] = V; - Sync(); -} - -static void M246Power(void) { - regs[0] = regs[1] = regs[2] = regs[3] = ~0; - Sync(); - SetWriteHandler(0x6000, 0x67FF, M246Write); - SetReadHandler(0x6800, 0x6FFF, CartBR); - SetWriteHandler(0x6800, 0x6FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M246Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper246_Init(CartInfo *info) { - info->Power = M246Power; - info->Close = M246Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 2048; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 regs[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0x10, 0x6800, 0); + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[1]); + setprg8(0xC000, regs[2]); + setprg8(0xE000, regs[3]); + setchr2(0x0000, regs[4]); + setchr2(0x0800, regs[5]); + setchr2(0x1000, regs[6]); + setchr2(0x1800, regs[7]); +} + +static DECLFW(M246Write) { + regs[A & 7] = V; + Sync(); +} + +static void M246Power(void) { + regs[0] = regs[1] = regs[2] = regs[3] = ~0; + Sync(); + SetWriteHandler(0x6000, 0x67FF, M246Write); + SetReadHandler(0x6800, 0x6FFF, CartBR); + SetWriteHandler(0x6800, 0x6FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M246Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper246_Init(CartInfo *info) { + info->Power = M246Power; + info->Close = M246Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 2048; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/252.c b/src/boards/252.c index 9962e08..fd6fca4 100644 --- a/src/boards/252.c +++ b/src/boards/252.c @@ -1,135 +1,135 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - */ - -#include "mapinc.h" - -static uint8 creg[8], preg[2]; -static int32 IRQa, IRQCount, IRQClock, IRQLatch; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { creg, 8, "CREG" }, - { preg, 2, "PREG" }, - { &IRQa, 4, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { &IRQLatch, 4, "IRQL" }, - { &IRQClock, 4, "IRQK" }, - { 0 } -}; - -static void Sync(void) { - uint8 i; - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, preg[0]); - setprg8(0xa000, preg[1]); - setprg8(0xc000, ~1); - setprg8(0xe000, ~0); - for (i = 0; i < 8; i++) - if ((creg[i] == 6) || (creg[i] == 7)) - setchr1r(0x10, i << 10, creg[i] & 1); - else - setchr1(i << 10, creg[i]); -} - -static DECLFW(M252Write) { - if ((A >= 0xB000) && (A <= 0xEFFF)) { - uint8 ind = ((((A & 8) | (A >> 8)) >> 3) + 2) & 7; - uint8 sar = A & 4; - creg[ind] = (creg[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); - Sync(); - } else - switch (A & 0xF00C) { - case 0x8000: - case 0x8004: - case 0x8008: - case 0x800C: preg[0] = V; Sync(); break; - case 0xA000: - case 0xA004: - case 0xA008: - case 0xA00C: preg[1] = V; Sync(); break; - case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; - case 0xF004: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; - case 0xF008: X6502_IRQEnd(FCEU_IQEXT); IRQClock = 0; IRQCount = IRQLatch; IRQa = V & 2; break; - } -} - -static void M252Power(void) { - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M252Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M252IRQ(int a) { - #define LCYCS 341 - if (IRQa) { - IRQClock += a * 3; - if (IRQClock >= LCYCS) { - while (IRQClock >= LCYCS) { - IRQClock -= LCYCS; - IRQCount++; - if (IRQCount & 0x100) { - X6502_IRQBegin(FCEU_IQEXT); - IRQCount = IRQLatch; - } - } - } - } -} - -static void M252Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - if (CHRRAM) - FCEU_gfree(CHRRAM); - WRAM = CHRRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper252_Init(CartInfo *info) { - info->Power = M252Power; - info->Close = M252Close; - MapIRQHook = M252IRQ; - - CHRRAMSIZE = 2048; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + */ + +#include "mapinc.h" + +static uint8 creg[8], preg[2]; +static int32 IRQa, IRQCount, IRQClock, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { creg, 8, "CREG" }, + { preg, 2, "PREG" }, + { &IRQa, 4, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { &IRQClock, 4, "IRQK" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, preg[0]); + setprg8(0xa000, preg[1]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) + if ((creg[i] == 6) || (creg[i] == 7)) + setchr1r(0x10, i << 10, creg[i] & 1); + else + setchr1(i << 10, creg[i]); +} + +static DECLFW(M252Write) { + if ((A >= 0xB000) && (A <= 0xEFFF)) { + uint8 ind = ((((A & 8) | (A >> 8)) >> 3) + 2) & 7; + uint8 sar = A & 4; + creg[ind] = (creg[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + Sync(); + } else + switch (A & 0xF00C) { + case 0x8000: + case 0x8004: + case 0x8008: + case 0x800C: preg[0] = V; Sync(); break; + case 0xA000: + case 0xA004: + case 0xA008: + case 0xA00C: preg[1] = V; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; + case 0xF004: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; + case 0xF008: X6502_IRQEnd(FCEU_IQEXT); IRQClock = 0; IRQCount = IRQLatch; IRQa = V & 2; break; + } +} + +static void M252Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M252Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M252IRQ(int a) { + #define LCYCS 341 + if (IRQa) { + IRQClock += a * 3; + if (IRQClock >= LCYCS) { + while (IRQClock >= LCYCS) { + IRQClock -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } + } +} + +static void M252Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper252_Init(CartInfo *info) { + info->Power = M252Power; + info->Close = M252Close; + MapIRQHook = M252IRQ; + + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/253.c b/src/boards/253.c index 3ed9bfe..476a187 100644 --- a/src/boards/253.c +++ b/src/boards/253.c @@ -1,152 +1,152 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - */ - -#include "mapinc.h" - -static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock; -static int32 IRQa, IRQCount, IRQLatch, IRQClock; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { chrlo, 8, "CHRL" }, - { chrhi, 8, "CHRH" }, - { prg, 2, "PRGR" }, - { &mirr, 1, "MIRR" }, - { &vlock, 1, "VLCK" }, - { &IRQa, 4, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { &IRQLatch, 4, "IRQL" }, - { &IRQClock, 4, "IRQK" }, - { 0 } -}; - -static void Sync(void) { - uint8 i; - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, prg[0]); - setprg8(0xa000, prg[1]); - setprg8(0xc000, ~1); - setprg8(0xe000, ~0); - for (i = 0; i < 8; i++) { - uint32 chr = chrlo[i] | (chrhi[i] << 8); - if (((chrlo[i] == 4) || (chrlo[i] == 5)) && !vlock) - setchr1r(0x10, i << 10, chr & 1); - else - setchr1(i << 10, chr); - } - switch (mirr) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(M253Write) { - if ((A >= 0xB000) && (A <= 0xE00C)) { - uint8 ind = ((((A & 8) | (A >> 8)) >> 3) + 2) & 7; - uint8 sar = A & 4; - uint8 clo = (chrlo[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); - chrlo[ind] = clo; - if (ind == 0) { - if (clo == 0xc8) - vlock = 0; - else if (clo == 0x88) - vlock = 1; - } - if (sar) - chrhi[ind] = V >> 4; - Sync(); - } else - switch (A) { - case 0x8010: prg[0] = V; Sync(); break; - case 0xA010: prg[1] = V; Sync(); break; - case 0x9400: mirr = V & 3; Sync(); break; - case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; - case 0xF004: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; - case 0xF008: X6502_IRQEnd(FCEU_IQEXT); IRQClock = 0; IRQCount = IRQLatch; IRQa = V & 2; break; - } -} - -static void M253Power(void) { - vlock = 0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M253Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M253Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - if (CHRRAM) - FCEU_gfree(CHRRAM); - WRAM = CHRRAM = NULL; -} - -static void M253IRQ(int a) { - #define LCYCS 341 - if (IRQa) { - IRQClock += a * 3; - if (IRQClock >= LCYCS) { - while (IRQClock >= LCYCS) { - IRQClock -= LCYCS; - IRQCount++; - if (IRQCount & 0x100) { - X6502_IRQBegin(FCEU_IQEXT); - IRQCount = IRQLatch; - } - } - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper253_Init(CartInfo *info) { - info->Power = M253Power; - info->Close = M253Close; - MapIRQHook = M253IRQ; - GameStateRestore = StateRestore; - - CHRRAMSIZE = 2048; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + */ + +#include "mapinc.h" + +static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock; +static int32 IRQa, IRQCount, IRQLatch, IRQClock; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { chrlo, 8, "CHRL" }, + { chrhi, 8, "CHRH" }, + { prg, 2, "PRGR" }, + { &mirr, 1, "MIRR" }, + { &vlock, 1, "VLCK" }, + { &IRQa, 4, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { &IRQClock, 4, "IRQK" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, prg[0]); + setprg8(0xa000, prg[1]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) { + uint32 chr = chrlo[i] | (chrhi[i] << 8); + if (((chrlo[i] == 4) || (chrlo[i] == 5)) && !vlock) + setchr1r(0x10, i << 10, chr & 1); + else + setchr1(i << 10, chr); + } + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M253Write) { + if ((A >= 0xB000) && (A <= 0xE00C)) { + uint8 ind = ((((A & 8) | (A >> 8)) >> 3) + 2) & 7; + uint8 sar = A & 4; + uint8 clo = (chrlo[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + chrlo[ind] = clo; + if (ind == 0) { + if (clo == 0xc8) + vlock = 0; + else if (clo == 0x88) + vlock = 1; + } + if (sar) + chrhi[ind] = V >> 4; + Sync(); + } else + switch (A) { + case 0x8010: prg[0] = V; Sync(); break; + case 0xA010: prg[1] = V; Sync(); break; + case 0x9400: mirr = V & 3; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; + case 0xF004: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; + case 0xF008: X6502_IRQEnd(FCEU_IQEXT); IRQClock = 0; IRQCount = IRQLatch; IRQa = V & 2; break; + } +} + +static void M253Power(void) { + vlock = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M253Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M253Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; +} + +static void M253IRQ(int a) { + #define LCYCS 341 + if (IRQa) { + IRQClock += a * 3; + if (IRQClock >= LCYCS) { + while (IRQClock >= LCYCS) { + IRQClock -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper253_Init(CartInfo *info) { + info->Power = M253Power; + info->Close = M253Close; + MapIRQHook = M253IRQ; + GameStateRestore = StateRestore; + + CHRRAMSIZE = 2048; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/32.c b/src/boards/32.c index 50b91da..165f645 100644 --- a/src/boards/32.c +++ b/src/boards/32.c @@ -1,102 +1,102 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 preg[2], creg[8], mirr; - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { preg, 4, "PREG" }, - { creg, 8, "CREG" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - uint8 i; - uint16 swap = ((mirr & 2) << 13); - setmirror((mirr & 1) ^ 1); - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000 ^ swap, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000 ^ swap, ~1); - setprg8(0xE000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, creg[i]); -} - -static DECLFW(M32Write0) { - preg[0] = V; - Sync(); -} - -static DECLFW(M32Write1) { - mirr = V; - Sync(); -} - -static DECLFW(M32Write2) { - preg[1] = V; - Sync(); -} - -static DECLFW(M32Write3) { - creg[A & 7] = V; - Sync(); -} - -static void M32Power(void) { - Sync(); - SetReadHandler(0x6000, 0x7fff, CartBR); - SetWriteHandler(0x6000, 0x7fff, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0x8FFF, M32Write0); - SetWriteHandler(0x9000, 0x9FFF, M32Write1); - SetWriteHandler(0xA000, 0xAFFF, M32Write2); - SetWriteHandler(0xB000, 0xBFFF, M32Write3); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M32Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper32_Init(CartInfo *info) { - info->Power = M32Power; - info->Close = M32Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 preg[2], creg[8], mirr; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + uint16 swap = ((mirr & 2) << 13); + setmirror((mirr & 1) ^ 1); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000 ^ swap, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000 ^ swap, ~1); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); +} + +static DECLFW(M32Write0) { + preg[0] = V; + Sync(); +} + +static DECLFW(M32Write1) { + mirr = V; + Sync(); +} + +static DECLFW(M32Write2) { + preg[1] = V; + Sync(); +} + +static DECLFW(M32Write3) { + creg[A & 7] = V; + Sync(); +} + +static void M32Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, M32Write0); + SetWriteHandler(0x9000, 0x9FFF, M32Write1); + SetWriteHandler(0xA000, 0xAFFF, M32Write2); + SetWriteHandler(0xB000, 0xBFFF, M32Write3); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M32Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper32_Init(CartInfo *info) { + info->Power = M32Power; + info->Close = M32Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/33.c b/src/boards/33.c index 2243dae..2838100 100644 --- a/src/boards/33.c +++ b/src/boards/33.c @@ -1,117 +1,117 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 is48; -static uint8 regs[8], mirr; -static uint8 IRQa; -static int16 IRQCount, IRQLatch; - -static SFORMAT StateRegs[] = -{ - { regs, 8, "PREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 2, "IRQC" }, - { &IRQLatch, 2, "IRQL" }, - { 0 } -}; - -static void Sync(void) { - setmirror(mirr); - setprg8(0x8000, regs[0]); - setprg8(0xA000, regs[1]); - setprg8(0xC000, ~1); - setprg8(0xE000, ~0); - setchr2(0x0000, regs[2]); - setchr2(0x0800, regs[3]); - setchr1(0x1000, regs[4]); - setchr1(0x1400, regs[5]); - setchr1(0x1800, regs[6]); - setchr1(0x1C00, regs[7]); -} - -static DECLFW(M33Write) { - A &= 0xF003; - switch (A) { - case 0x8000: regs[0] = V & 0x3F; if (!is48) mirr = ((V >> 6) & 1) ^ 1; Sync(); break; - case 0x8001: regs[1] = V & 0x3F; Sync(); break; - case 0x8002: regs[2] = V; Sync(); break; - case 0x8003: regs[3] = V; Sync(); break; - case 0xA000: regs[4] = V; Sync(); break; - case 0xA001: regs[5] = V; Sync(); break; - case 0xA002: regs[6] = V; Sync(); break; - case 0xA003: regs[7] = V; Sync(); break; - } -} - -static DECLFW(M48Write) { - switch (A & 0xF003) { - case 0xC000: IRQLatch = V; break; - case 0xC001: IRQCount = IRQLatch; break; - case 0xC003: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xC002: IRQa = 1; break; - case 0xE000: mirr = ((V >> 6) & 1) ^ 1; Sync(); break; - } -} - -static void M33Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M33Write); -} - -static void M48Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xBFFF, M33Write); - SetWriteHandler(0xC000, 0xFFFF, M48Write); -} - -static void M48IRQ(void) { - if (IRQa) { - IRQCount++; - if (IRQCount == 0x100) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper33_Init(CartInfo *info) { - is48 = 0; - info->Power = M33Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper48_Init(CartInfo *info) { - is48 = 1; - info->Power = M48Power; - GameHBIRQHook = M48IRQ; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 is48; +static uint8 regs[8], mirr; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "PREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + setchr2(0x0000, regs[2]); + setchr2(0x0800, regs[3]); + setchr1(0x1000, regs[4]); + setchr1(0x1400, regs[5]); + setchr1(0x1800, regs[6]); + setchr1(0x1C00, regs[7]); +} + +static DECLFW(M33Write) { + A &= 0xF003; + switch (A) { + case 0x8000: regs[0] = V & 0x3F; if (!is48) mirr = ((V >> 6) & 1) ^ 1; Sync(); break; + case 0x8001: regs[1] = V & 0x3F; Sync(); break; + case 0x8002: regs[2] = V; Sync(); break; + case 0x8003: regs[3] = V; Sync(); break; + case 0xA000: regs[4] = V; Sync(); break; + case 0xA001: regs[5] = V; Sync(); break; + case 0xA002: regs[6] = V; Sync(); break; + case 0xA003: regs[7] = V; Sync(); break; + } +} + +static DECLFW(M48Write) { + switch (A & 0xF003) { + case 0xC000: IRQLatch = V; break; + case 0xC001: IRQCount = IRQLatch; break; + case 0xC003: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xC002: IRQa = 1; break; + case 0xE000: mirr = ((V >> 6) & 1) ^ 1; Sync(); break; + } +} + +static void M33Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M33Write); +} + +static void M48Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, M33Write); + SetWriteHandler(0xC000, 0xFFFF, M48Write); +} + +static void M48IRQ(void) { + if (IRQa) { + IRQCount++; + if (IRQCount == 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper33_Init(CartInfo *info) { + is48 = 0; + info->Power = M33Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper48_Init(CartInfo *info) { + is48 = 1; + info->Power = M48Power; + GameHBIRQHook = M48IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/34.c b/src/boards/34.c index 5c27b00..a340697 100644 --- a/src/boards/34.c +++ b/src/boards/34.c @@ -1,93 +1,93 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * Many-in-one hacked mapper crap. - * - * Original BNROM is actually AxROM variations without mirroring control, - * and haven't SRAM on-board, so it must be removed from here - * - * Difficult banking is what NINA board doing, most hacks for 34 mapper are - * NINA hacks, so this is actually 34 mapper - * - */ - -#include "mapinc.h" - -static uint8 regs[3]; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { regs, 3, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0x10, 0x6000, 0); - setprg32(0x8000, regs[0]); - setchr4(0x0000, regs[1]); - setchr4(0x1000, regs[2]); -} - -static DECLFW(M34Write) { - if (A >= 0x8000) - regs[0] = V; - else - switch (A) { - case 0x7ffd: regs[0] = V; break; - case 0x7ffe: regs[1] = V; break; - case 0x7fff: regs[2] = V; break; - } - Sync(); -} - -static void M34Power(void) { - regs[0] = regs[1] = 0; - regs[2] = 1; - Sync(); - SetReadHandler(0x6000, 0x7ffc, CartBR); - SetWriteHandler(0x6000, 0x7ffc, CartBW); - SetReadHandler(0x8000, 0xffff, CartBR); - SetWriteHandler(0x7ffd, 0xffff, M34Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M34Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper34_Init(CartInfo *info) { - info->Power = M34Power; - info->Close = M34Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * Many-in-one hacked mapper crap. + * + * Original BNROM is actually AxROM variations without mirroring control, + * and haven't SRAM on-board, so it must be removed from here + * + * Difficult banking is what NINA board doing, most hacks for 34 mapper are + * NINA hacks, so this is actually 34 mapper + * + */ + +#include "mapinc.h" + +static uint8 regs[3]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 3, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, regs[0]); + setchr4(0x0000, regs[1]); + setchr4(0x1000, regs[2]); +} + +static DECLFW(M34Write) { + if (A >= 0x8000) + regs[0] = V; + else + switch (A) { + case 0x7ffd: regs[0] = V; break; + case 0x7ffe: regs[1] = V; break; + case 0x7fff: regs[2] = V; break; + } + Sync(); +} + +static void M34Power(void) { + regs[0] = regs[1] = 0; + regs[2] = 1; + Sync(); + SetReadHandler(0x6000, 0x7ffc, CartBR); + SetWriteHandler(0x6000, 0x7ffc, CartBW); + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x7ffd, 0xffff, M34Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M34Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper34_Init(CartInfo *info) { + info->Power = M34Power; + info->Close = M34Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/36.c b/src/boards/36.c index f342b00..9ffed93 100644 --- a/src/boards/36.c +++ b/src/boards/36.c @@ -1,63 +1,63 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * TXC/Micro Genius simplified mapper - */ - -#include "mapinc.h" - -static uint8 latche; - -static SFORMAT StateRegs[] = -{ - { &latche, 1, "LATC" }, - { 0 } -}; - -static void Sync(void) { - setprg32(0x8000, latche >> 4); - setchr8(latche & 0xf); -} - -static DECLFW(M36Write) { - latche = V; - Sync(); -} - -static DECLFR(M36Read) { - return latche; /* Need by Strike Wolf, being simplified mapper, this cart still uses some TCX mapper features andrely on it */ -} - -static void M36Power(void) { - latche = 0; - Sync(); - SetReadHandler(0x4100, 0x4100, M36Read); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFE, M36Write); /* Actually, BUS conflict there preventing from triggering the wrong banks */ -} - -static void M36Restore(int version) { - Sync(); -} - -void Mapper36_Init(CartInfo *info) { - info->Power = M36Power; - GameStateRestore = M36Restore; - AddExState(StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * TXC/Micro Genius simplified mapper + */ + +#include "mapinc.h" + +static uint8 latche; + +static SFORMAT StateRegs[] = +{ + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, latche >> 4); + setchr8(latche & 0xf); +} + +static DECLFW(M36Write) { + latche = V; + Sync(); +} + +static DECLFR(M36Read) { + return latche; /* Need by Strike Wolf, being simplified mapper, this cart still uses some TCX mapper features andrely on it */ +} + +static void M36Power(void) { + latche = 0; + Sync(); + SetReadHandler(0x4100, 0x4100, M36Read); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFE, M36Write); /* Actually, BUS conflict there preventing from triggering the wrong banks */ +} + +static void M36Restore(int version) { + Sync(); +} + +void Mapper36_Init(CartInfo *info) { + info->Power = M36Power; + GameStateRestore = M36Restore; + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/src/boards/3d-block.c b/src/boards/3d-block.c index f8513b4..c5ed2ea 100644 --- a/src/boards/3d-block.c +++ b/src/boards/3d-block.c @@ -1,95 +1,95 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg[4], IRQa; -static int16 IRQCount, IRQPause; - -static int16 Count = 0x0000; - -static SFORMAT StateRegs[] = -{ - { reg, 4, "REGS" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 2, "IRQC" }, - { 0 } -}; - -static void Sync(void) { - setprg32(0x8000, 0); - setchr8(0); -} - -/* #define Count 0x1800 */ -#define Pause 0x010 - -static DECLFW(UNL3DBlockWrite) { - switch (A) { -/* 4800 32 */ -/* 4900 37 */ -/* 4a00 01 */ -/* 4e00 18 */ - case 0x4800: reg[0] = V; break; - case 0x4900: reg[1] = V; break; - case 0x4a00: reg[2] = V; break; - case 0x4e00: reg[3] = V; IRQCount = Count; IRQPause = Pause; IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; - } -} - -static void UNL3DBlockPower(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x4800, 0x4E00, UNL3DBlockWrite); -} - -static void UNL3DBlockReset(void) { - Count += 0x10; - FCEU_printf("Count=%04x\n", Count); -} - -static void FP_FASTAPASS(1) UNL3DBlockIRQHook(int a) { - if (IRQa) { - if (IRQCount > 0) { - IRQCount -= a; - } else { - if (IRQPause > 0) { - IRQPause -= a; - X6502_IRQBegin(FCEU_IQEXT); - } else { - IRQCount = Count; - IRQPause = Pause; - X6502_IRQEnd(FCEU_IQEXT); - } - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void UNL3DBlock_Init(CartInfo *info) { - info->Power = UNL3DBlockPower; - info->Reset = UNL3DBlockReset; - MapIRQHook = UNL3DBlockIRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg[4], IRQa; +static int16 IRQCount, IRQPause; + +static int16 Count = 0x0000; + +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, 0); + setchr8(0); +} + +/* #define Count 0x1800 */ +#define Pause 0x010 + +static DECLFW(UNL3DBlockWrite) { + switch (A) { +/* 4800 32 */ +/* 4900 37 */ +/* 4a00 01 */ +/* 4e00 18 */ + case 0x4800: reg[0] = V; break; + case 0x4900: reg[1] = V; break; + case 0x4a00: reg[2] = V; break; + case 0x4e00: reg[3] = V; IRQCount = Count; IRQPause = Pause; IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void UNL3DBlockPower(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4800, 0x4E00, UNL3DBlockWrite); +} + +static void UNL3DBlockReset(void) { + Count += 0x10; + FCEU_printf("Count=%04x\n", Count); +} + +static void FP_FASTAPASS(1) UNL3DBlockIRQHook(int a) { + if (IRQa) { + if (IRQCount > 0) { + IRQCount -= a; + } else { + if (IRQPause > 0) { + IRQPause -= a; + X6502_IRQBegin(FCEU_IQEXT); + } else { + IRQCount = Count; + IRQPause = Pause; + X6502_IRQEnd(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void UNL3DBlock_Init(CartInfo *info) { + info->Power = UNL3DBlockPower; + info->Reset = UNL3DBlockReset; + MapIRQHook = UNL3DBlockIRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/40.c b/src/boards/40.c index 1525a42..80d1ad0 100644 --- a/src/boards/40.c +++ b/src/boards/40.c @@ -1,85 +1,85 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg; -static uint32 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 4, "IRQC" }, - { &IRQa, 4, "IRQA" }, - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, ~1); - setprg8(0x8000, ~3); - setprg8(0xa000, ~2); - setprg8(0xc000, reg); - setprg8(0xe000, ~0); - setchr8(0); -} - -static DECLFW(M40Write) { - switch (A & 0xe000) { - case 0x8000: IRQa = 0; IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xa000: IRQa = 1; break; - case 0xe000: reg = V & 7; Sync(); break; - } -} - -static void M40Power(void) { - reg = 0; - Sync(); - SetReadHandler(0x6000, 0xffff, CartBR); - SetWriteHandler(0x8000, 0xffff, M40Write); -} - -static void M40Reset(void) { -} - -static void FP_FASTAPASS(1) M40IRQHook(int a) { - if (IRQa) { - if (IRQCount < 4096) - IRQCount += a; - else { - IRQa = 0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper40_Init(CartInfo *info) { - info->Reset = M40Reset; - info->Power = M40Power; - MapIRQHook = M40IRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, ~1); + setprg8(0x8000, ~3); + setprg8(0xa000, ~2); + setprg8(0xc000, reg); + setprg8(0xe000, ~0); + setchr8(0); +} + +static DECLFW(M40Write) { + switch (A & 0xe000) { + case 0x8000: IRQa = 0; IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xa000: IRQa = 1; break; + case 0xe000: reg = V & 7; Sync(); break; + } +} + +static void M40Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x8000, 0xffff, M40Write); +} + +static void M40Reset(void) { +} + +static void FP_FASTAPASS(1) M40IRQHook(int a) { + if (IRQa) { + if (IRQCount < 4096) + IRQCount += a; + else { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper40_Init(CartInfo *info) { + info->Reset = M40Reset; + info->Power = M40Power; + MapIRQHook = M40IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/411120-c.c b/src/boards/411120-c.c index 6bc821f..a4c30e0 100644 --- a/src/boards/411120-c.c +++ b/src/boards/411120-c.c @@ -1,64 +1,64 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2008 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 - */ - -/* actually cart ID is 811120-C, sorry ;) K-3094 - another ID */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 reset_flag = 0; - -static void BMC411120CCW(uint32 A, uint8 V) { - setchr1(A, V | ((EXPREGS[0] & 3) << 7)); -} - -static void BMC411120CPW(uint32 A, uint8 V) { - if (EXPREGS[0] & (8 | reset_flag)) - setprg32(0x8000, ((EXPREGS[0] >> 4) & 3) | (0x0C)); - else - setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 3) << 4)); -} - -static DECLFW(BMC411120CLoWrite) { - EXPREGS[0] = A; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void BMC411120CReset(void) { - EXPREGS[0] = 0; - reset_flag ^= 4; - MMC3RegReset(); -} - -static void BMC411120CPower(void) { - EXPREGS[0] = 0; - GenMMC3Power(); - SetWriteHandler(0x6000, 0x7FFF, BMC411120CLoWrite); -} - -void BMC411120C_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 128, 8, 0); - pwrap = BMC411120CPW; - cwrap = BMC411120CCW; - info->Power = BMC411120CPower; - info->Reset = BMC411120CReset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 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 + */ + +/* actually cart ID is 811120-C, sorry ;) K-3094 - another ID */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0; + +static void BMC411120CCW(uint32 A, uint8 V) { + setchr1(A, V | ((EXPREGS[0] & 3) << 7)); +} + +static void BMC411120CPW(uint32 A, uint8 V) { + if (EXPREGS[0] & (8 | reset_flag)) + setprg32(0x8000, ((EXPREGS[0] >> 4) & 3) | (0x0C)); + else + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 3) << 4)); +} + +static DECLFW(BMC411120CLoWrite) { + EXPREGS[0] = A; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC411120CReset(void) { + EXPREGS[0] = 0; + reset_flag ^= 4; + MMC3RegReset(); +} + +static void BMC411120CPower(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, BMC411120CLoWrite); +} + +void BMC411120C_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = BMC411120CPW; + cwrap = BMC411120CCW; + info->Power = BMC411120CPower; + info->Reset = BMC411120CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/42.c b/src/boards/42.c index a4e1620..b1e6ea3 100644 --- a/src/boards/42.c +++ b/src/boards/42.c @@ -1,83 +1,83 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 preg, creg, mirr; -static uint32 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { &creg, 1, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQCount, 4, "IRQC" }, - { &IRQa, 4, "IRQA" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, preg); - setprg32(0x8000, ~0); - setchr8(creg); - setmirror(mirr); -} - -static DECLFW(M42Write) { - switch (A & 0xE003) { - case 0x8000: creg = V; Sync(); break; - case 0xE000: preg = V & 0x0F; Sync(); break; - case 0xE001: mirr = ((V >> 3) & 1) ^ 1; Sync(); break; - case 0xE002: IRQa = V & 2; if (!IRQa) IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; - } -} - -static void M42Power(void) { - preg = 0; - mirr = 1; /* Ai Senshi Nicol actually has fixed mirroring, but mapper forcing it's default value now */ - Sync(); - SetReadHandler(0x6000, 0xffff, CartBR); - SetWriteHandler(0x6000, 0xffff, M42Write); -} - -static void FP_FASTAPASS(1) M42IRQHook(int a) { - if (IRQa) { - IRQCount += a; - if (IRQCount >= 32768) IRQCount -= 32768; - if (IRQCount >= 24576) - X6502_IRQBegin(FCEU_IQEXT); - else - X6502_IRQEnd(FCEU_IQEXT); - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper42_Init(CartInfo *info) { - info->Power = M42Power; - MapIRQHook = M42IRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 preg, creg, mirr; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, preg); + setprg32(0x8000, ~0); + setchr8(creg); + setmirror(mirr); +} + +static DECLFW(M42Write) { + switch (A & 0xE003) { + case 0x8000: creg = V; Sync(); break; + case 0xE000: preg = V & 0x0F; Sync(); break; + case 0xE001: mirr = ((V >> 3) & 1) ^ 1; Sync(); break; + case 0xE002: IRQa = V & 2; if (!IRQa) IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void M42Power(void) { + preg = 0; + mirr = 1; /* Ai Senshi Nicol actually has fixed mirroring, but mapper forcing it's default value now */ + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x6000, 0xffff, M42Write); +} + +static void FP_FASTAPASS(1) M42IRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 32768) IRQCount -= 32768; + if (IRQCount >= 24576) + X6502_IRQBegin(FCEU_IQEXT); + else + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper42_Init(CartInfo *info) { + info->Power = M42Power; + MapIRQHook = M42IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/43.c b/src/boards/43.c index f45bb03..7a83108 100644 --- a/src/boards/43.c +++ b/src/boards/43.c @@ -1,92 +1,92 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg, swap; -static uint32 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 4, "IRQC" }, - { &IRQa, 4, "IRQA" }, - { ®, 1, "REG" }, - { &swap, 1, "SWAP" }, - { 0 } -}; - -static void Sync(void) { - setprg4(0x5000, 8 << 1); /* Only YS-612 advanced version */ - setprg8(0x6000, swap?0:2); - setprg8(0x8000, 1); - setprg8(0xa000, 0); - setprg8(0xc000, reg); - setprg8(0xe000, swap?8:9); /* hard dump for mr.Mary is 128K, - * bank 9 is the last 2K ok bank 8 repeated 4 times, then till the end of 128K - * instead used bank A, containing some CHR data, ines rom have unused banks removed, - * and bank A moved to the bank 9 place for compatibility with other crappy dumps - */ - setchr8(0); -} - -static DECLFW(M43Write) { -/* int transo[8]={4,3,4,4,4,7,5,6}; */ - int transo[8] = { 4, 3, 5, 3, 6, 3, 7, 3 }; /* According to hardware tests */ - switch (A & 0xf1ff) { - case 0x4022: reg = transo[V & 7]; Sync(); break; - case 0x4120: swap = V & 1; Sync(); break; - case 0x8122: /* hacked version */ - case 0x4122: IRQa = V & 1; X6502_IRQEnd(FCEU_IQEXT); IRQCount = 0; break; /* original version */ - } -} - -static void M43Power(void) { - reg = swap = 0; - Sync(); - SetReadHandler(0x5000, 0xffff, CartBR); - SetWriteHandler(0x4020, 0xffff, M43Write); -} - -static void M43Reset(void) { -} - -static void FP_FASTAPASS(1) M43IRQHook(int a) { - IRQCount += a; - if (IRQa) - if (IRQCount >= 4096) { - IRQa = 0; - X6502_IRQBegin(FCEU_IQEXT); - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper43_Init(CartInfo *info) { - info->Reset = M43Reset; - info->Power = M43Power; - MapIRQHook = M43IRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, swap; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { ®, 1, "REG" }, + { &swap, 1, "SWAP" }, + { 0 } +}; + +static void Sync(void) { + setprg4(0x5000, 8 << 1); /* Only YS-612 advanced version */ + setprg8(0x6000, swap?0:2); + setprg8(0x8000, 1); + setprg8(0xa000, 0); + setprg8(0xc000, reg); + setprg8(0xe000, swap?8:9); /* hard dump for mr.Mary is 128K, + * bank 9 is the last 2K ok bank 8 repeated 4 times, then till the end of 128K + * instead used bank A, containing some CHR data, ines rom have unused banks removed, + * and bank A moved to the bank 9 place for compatibility with other crappy dumps + */ + setchr8(0); +} + +static DECLFW(M43Write) { +/* int transo[8]={4,3,4,4,4,7,5,6}; */ + int transo[8] = { 4, 3, 5, 3, 6, 3, 7, 3 }; /* According to hardware tests */ + switch (A & 0xf1ff) { + case 0x4022: reg = transo[V & 7]; Sync(); break; + case 0x4120: swap = V & 1; Sync(); break; + case 0x8122: /* hacked version */ + case 0x4122: IRQa = V & 1; X6502_IRQEnd(FCEU_IQEXT); IRQCount = 0; break; /* original version */ + } +} + +static void M43Power(void) { + reg = swap = 0; + Sync(); + SetReadHandler(0x5000, 0xffff, CartBR); + SetWriteHandler(0x4020, 0xffff, M43Write); +} + +static void M43Reset(void) { +} + +static void FP_FASTAPASS(1) M43IRQHook(int a) { + IRQCount += a; + if (IRQa) + if (IRQCount >= 4096) { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper43_Init(CartInfo *info) { + info->Reset = M43Reset; + info->Power = M43Power; + MapIRQHook = M43IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/50.c b/src/boards/50.c index 150c95e..d13dfdc 100644 --- a/src/boards/50.c +++ b/src/boards/50.c @@ -1,84 +1,84 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg; -static uint32 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 4, "IRQC" }, - { &IRQa, 4, "IRQA" }, - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, 0xF); - setprg8(0x8000, 0x8); - setprg8(0xa000, 0x9); - setprg8(0xc000, reg); - setprg8(0xe000, 0xB); - setchr8(0); -} - -static DECLFW(M50Write) { - switch (A & 0xD160) { - case 0x4120: IRQa = V & 1; if (!IRQa) IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0x4020: reg = ((V & 1) << 2) | ((V & 2) >> 1) | ((V & 4) >> 1) | (V & 8); Sync(); break; - } -} - -static void M50Power(void) { - reg = 0; - Sync(); - SetReadHandler(0x6000, 0xffff, CartBR); - SetWriteHandler(0x4020, 0x5fff, M50Write); -} - -static void M50Reset(void) { -} - -static void FP_FASTAPASS(1) M50IRQHook(int a) { - if (IRQa) { - if (IRQCount < 4096) - IRQCount += a; - else { - IRQa = 0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper50_Init(CartInfo *info) { - info->Reset = M50Reset; - info->Power = M50Power; - MapIRQHook = M50IRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint32 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 4, "IRQA" }, + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, 0xF); + setprg8(0x8000, 0x8); + setprg8(0xa000, 0x9); + setprg8(0xc000, reg); + setprg8(0xe000, 0xB); + setchr8(0); +} + +static DECLFW(M50Write) { + switch (A & 0xD160) { + case 0x4120: IRQa = V & 1; if (!IRQa) IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4020: reg = ((V & 1) << 2) | ((V & 2) >> 1) | ((V & 4) >> 1) | (V & 8); Sync(); break; + } +} + +static void M50Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x4020, 0x5fff, M50Write); +} + +static void M50Reset(void) { +} + +static void FP_FASTAPASS(1) M50IRQHook(int a) { + if (IRQa) { + if (IRQCount < 4096) + IRQCount += a; + else { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper50_Init(CartInfo *info) { + info->Reset = M50Reset; + info->Power = M50Power; + MapIRQHook = M50IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/51.c b/src/boards/51.c index 02d693c..35b1fb1 100644 --- a/src/boards/51.c +++ b/src/boards/51.c @@ -1,84 +1,84 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 bank, mode; -static SFORMAT StateRegs[] = -{ - { &bank, 1, "BANK" }, - { &mode, 1, "MODE" }, - { 0 } -}; - -static void Sync(void) { - if (mode & 2) { - setprg8(0x6000, ((bank & 7) << 2) | 0x23); - setprg16(0x8000, (bank << 1) | 0); - setprg16(0xC000, (bank << 1) | 1); - } else { - setprg8(0x6000, ((bank & 4) << 2) | 0x2F); - setprg16(0x8000, (bank << 1) | (mode >> 4)); - setprg16(0xC000, ((bank & 0xC) << 1) | 7); - } - if (mode == 0x12) - setmirror(MI_H); - else - setmirror(MI_V); - setchr8(0); -} - -static DECLFW(M51WriteMode) { - mode = V & 0x12; - Sync(); -} - -static DECLFW(M51WriteBank) { - bank = V & 0x0F; - if (A & 0x4000) - mode = (mode & 2) | (V & 0x10); - Sync(); -} - -static void M51Power(void) { - bank = 0; - mode = 2; - Sync(); - SetWriteHandler(0x6000, 0x7FFF, M51WriteMode); - SetWriteHandler(0x8000, 0xFFFF, M51WriteBank); - SetReadHandler(0x6000, 0xFFFF, CartBR); -} - -static void M51Reset(void) { - bank = 0; - mode = 2; - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper51_Init(CartInfo *info) { - info->Power = M51Power; - info->Reset = M51Reset; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 bank, mode; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &mode, 1, "MODE" }, + { 0 } +}; + +static void Sync(void) { + if (mode & 2) { + setprg8(0x6000, ((bank & 7) << 2) | 0x23); + setprg16(0x8000, (bank << 1) | 0); + setprg16(0xC000, (bank << 1) | 1); + } else { + setprg8(0x6000, ((bank & 4) << 2) | 0x2F); + setprg16(0x8000, (bank << 1) | (mode >> 4)); + setprg16(0xC000, ((bank & 0xC) << 1) | 7); + } + if (mode == 0x12) + setmirror(MI_H); + else + setmirror(MI_V); + setchr8(0); +} + +static DECLFW(M51WriteMode) { + mode = V & 0x12; + Sync(); +} + +static DECLFW(M51WriteBank) { + bank = V & 0x0F; + if (A & 0x4000) + mode = (mode & 2) | (V & 0x10); + Sync(); +} + +static void M51Power(void) { + bank = 0; + mode = 2; + Sync(); + SetWriteHandler(0x6000, 0x7FFF, M51WriteMode); + SetWriteHandler(0x8000, 0xFFFF, M51WriteBank); + SetReadHandler(0x6000, 0xFFFF, CartBR); +} + +static void M51Reset(void) { + bank = 0; + mode = 2; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper51_Init(CartInfo *info) { + info->Power = M51Power; + info->Reset = M51Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/57.c b/src/boards/57.c index fb2a11f..2cd41c0 100644 --- a/src/boards/57.c +++ b/src/boards/57.c @@ -1,80 +1,80 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - */ - -#include "mapinc.h" - -static uint8 regs[2]; -static uint8 hrd_flag; - -static SFORMAT StateRegs[] = -{ - { &hrd_flag, 1, "DPSW" }, - { regs, 2, "REGS" }, - { 0 } -}; - -static void Sync(void) { - if (regs[1] & 0x10) - setprg32(0x8000, (regs[1] >> 6) & 3); - else { - setprg16(0x8000, (regs[1] >> 5) & 7); - setprg16(0xC000, (regs[1] >> 5) & 7); - } - setmirror((regs[1] & 8) >> 3 ^ 1); - setchr8((regs[0] & 7) | (regs[1] & 7) | ((regs[0] & 0x40) >> 3)); -} - -static DECLFR(M57Read) { - return hrd_flag; -} - -static DECLFW(M57Write) { - switch (A & 0x8800) { - case 0x8000: regs[0] = V; Sync(); break; - case 0x8800: regs[1] = V; Sync(); break; - } -} - -static void M57Power(void) { - regs[1] = regs[0] = 0; - hrd_flag = 0; - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M57Write); - SetReadHandler(0x6000, 0x6000, M57Read); - Sync(); -} - -static void M57Reset() { - hrd_flag++; - hrd_flag &= 3; - FCEU_printf("Select Register = %02x\n", hrd_flag); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper57_Init(CartInfo *info) { - info->Power = M57Power; - info->Reset = M57Reset; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + */ + +#include "mapinc.h" + +static uint8 regs[2]; +static uint8 hrd_flag; + +static SFORMAT StateRegs[] = +{ + { &hrd_flag, 1, "DPSW" }, + { regs, 2, "REGS" }, + { 0 } +}; + +static void Sync(void) { + if (regs[1] & 0x10) + setprg32(0x8000, (regs[1] >> 6) & 3); + else { + setprg16(0x8000, (regs[1] >> 5) & 7); + setprg16(0xC000, (regs[1] >> 5) & 7); + } + setmirror((regs[1] & 8) >> 3 ^ 1); + setchr8((regs[0] & 7) | (regs[1] & 7) | ((regs[0] & 0x40) >> 3)); +} + +static DECLFR(M57Read) { + return hrd_flag; +} + +static DECLFW(M57Write) { + switch (A & 0x8800) { + case 0x8000: regs[0] = V; Sync(); break; + case 0x8800: regs[1] = V; Sync(); break; + } +} + +static void M57Power(void) { + regs[1] = regs[0] = 0; + hrd_flag = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M57Write); + SetReadHandler(0x6000, 0x6000, M57Read); + Sync(); +} + +static void M57Reset() { + hrd_flag++; + hrd_flag &= 3; + FCEU_printf("Select Register = %02x\n", hrd_flag); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper57_Init(CartInfo *info) { + info->Power = M57Power; + info->Reset = M57Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/603-5052.c b/src/boards/603-5052.c index 2372603..1de82f8 100644 --- a/src/boards/603-5052.c +++ b/src/boards/603-5052.c @@ -1,49 +1,49 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) - * the same as 603-5052 board (TODO: add reading registers, merge) - * - * Contra Fighter prot board - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 }; - -static DECLFW(UNL6035052ProtWrite) { - EXPREGS[0] = lut[V & 3]; -} - -static DECLFR(UNL6035052ProtRead) { - return EXPREGS[0]; -} - -static void UNL6035052Power(void) { - GenMMC3Power(); - SetWriteHandler(0x4020, 0x7FFF, UNL6035052ProtWrite); - SetReadHandler(0x4020, 0x7FFF, UNL6035052ProtRead); -} - -void UNL6035052_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 256, 0, 0); - info->Power = UNL6035052Power; - AddExState(EXPREGS, 6, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) + * the same as 603-5052 board (TODO: add reading registers, merge) + * + * Contra Fighter prot board + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 }; + +static DECLFW(UNL6035052ProtWrite) { + EXPREGS[0] = lut[V & 3]; +} + +static DECLFR(UNL6035052ProtRead) { + return EXPREGS[0]; +} + +static void UNL6035052Power(void) { + GenMMC3Power(); + SetWriteHandler(0x4020, 0x7FFF, UNL6035052ProtWrite); + SetReadHandler(0x4020, 0x7FFF, UNL6035052ProtRead); +} + +void UNL6035052_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = UNL6035052Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} diff --git a/src/boards/62.c b/src/boards/62.c index 0dc2a63..15edc02 100644 --- a/src/boards/62.c +++ b/src/boards/62.c @@ -1,69 +1,69 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 bank; -static uint16 mode; -static SFORMAT StateRegs[] = -{ - { &bank, 1, "BANK" }, - { &mode, 2, "MODE" }, - { 0 } -}; - -static void Sync(void) { - setchr8(((mode & 0x1F) << 2) | (bank & 0x03)); - if (mode & 0x20) { - setprg16(0x8000, (mode & 0x40) | ((mode >> 8) & 0x3F)); - setprg16(0xc000, (mode & 0x40) | ((mode >> 8) & 0x3F)); - } else - setprg32(0x8000, ((mode & 0x40) | ((mode >> 8) & 0x3F)) >> 1); - setmirror(((mode >> 7) & 1) ^ 1); -} - -static DECLFW(M62Write) { - mode = A & 0x3FFF; - bank = V & 3; - Sync(); -} - -static void M62Power(void) { - bank = mode = 0; - Sync(); - SetWriteHandler(0x8000, 0xFFFF, M62Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void M62Reset(void) { - bank = mode = 0; - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper62_Init(CartInfo *info) { - info->Power = M62Power; - info->Reset = M62Reset; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 bank; +static uint16 mode; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &mode, 2, "MODE" }, + { 0 } +}; + +static void Sync(void) { + setchr8(((mode & 0x1F) << 2) | (bank & 0x03)); + if (mode & 0x20) { + setprg16(0x8000, (mode & 0x40) | ((mode >> 8) & 0x3F)); + setprg16(0xc000, (mode & 0x40) | ((mode >> 8) & 0x3F)); + } else + setprg32(0x8000, ((mode & 0x40) | ((mode >> 8) & 0x3F)) >> 1); + setmirror(((mode >> 7) & 1) ^ 1); +} + +static DECLFW(M62Write) { + mode = A & 0x3FFF; + bank = V & 3; + Sync(); +} + +static void M62Power(void) { + bank = mode = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M62Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M62Reset(void) { + bank = mode = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper62_Init(CartInfo *info) { + info->Power = M62Power; + info->Reset = M62Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/65.c b/src/boards/65.c index aca3f64..cfe8d6c 100644 --- a/src/boards/65.c +++ b/src/boards/65.c @@ -1,104 +1,104 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 preg[3], creg[8], mirr; -static uint8 IRQa; -static int16 IRQCount, IRQLatch; - -static SFORMAT StateRegs[] = -{ - { preg, 3, "PREG" }, - { creg, 8, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 2, "IRQC" }, - { &IRQLatch, 2, "IRQL" }, - { 0 } -}; - -static void Sync(void) { - setmirror(mirr); - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, ~0); - setchr1(0x0000, creg[0]); - setchr1(0x0400, creg[1]); - setchr1(0x0800, creg[2]); - setchr1(0x0C00, creg[3]); - setchr1(0x1000, creg[4]); - setchr1(0x1400, creg[5]); - setchr1(0x1800, creg[6]); - setchr1(0x1C00, creg[7]); - setmirror(mirr); -} - -static DECLFW(M65Write) { - switch (A) { - case 0x8000: preg[0] = V; Sync(); break; - case 0xA000: preg[1] = V; Sync(); break; - case 0xC000: preg[2] = V; Sync(); break; - case 0x9001: mirr = ((V >> 7) & 1) ^ 1; Sync(); break; - case 0x9003: IRQa = V & 0x80; X6502_IRQEnd(FCEU_IQEXT); break; - case 0x9004: IRQCount = IRQLatch; break; - case 0x9005: IRQLatch &= 0x00FF; IRQLatch |= V << 8; break; - case 0x9006: IRQLatch &= 0xFF00; IRQLatch |= V; break; - case 0xB000: creg[0] = V; Sync(); break; - case 0xB001: creg[1] = V; Sync(); break; - case 0xB002: creg[2] = V; Sync(); break; - case 0xB003: creg[3] = V; Sync(); break; - case 0xB004: creg[4] = V; Sync(); break; - case 0xB005: creg[5] = V; Sync(); break; - case 0xB006: creg[6] = V; Sync(); break; - case 0xB007: creg[7] = V; Sync(); break; - } -} - -static void M65Power(void) { - preg[2] = ~1; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M65Write); -} - -void FP_FASTAPASS(1) M65IRQ(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount < -4) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - IRQCount = 0xFFFF; - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper65_Init(CartInfo *info) { - info->Power = M65Power; - MapIRQHook = M65IRQ; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 preg[3], creg[8], mirr; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { preg, 3, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + setchr1(0x0000, creg[0]); + setchr1(0x0400, creg[1]); + setchr1(0x0800, creg[2]); + setchr1(0x0C00, creg[3]); + setchr1(0x1000, creg[4]); + setchr1(0x1400, creg[5]); + setchr1(0x1800, creg[6]); + setchr1(0x1C00, creg[7]); + setmirror(mirr); +} + +static DECLFW(M65Write) { + switch (A) { + case 0x8000: preg[0] = V; Sync(); break; + case 0xA000: preg[1] = V; Sync(); break; + case 0xC000: preg[2] = V; Sync(); break; + case 0x9001: mirr = ((V >> 7) & 1) ^ 1; Sync(); break; + case 0x9003: IRQa = V & 0x80; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x9004: IRQCount = IRQLatch; break; + case 0x9005: IRQLatch &= 0x00FF; IRQLatch |= V << 8; break; + case 0x9006: IRQLatch &= 0xFF00; IRQLatch |= V; break; + case 0xB000: creg[0] = V; Sync(); break; + case 0xB001: creg[1] = V; Sync(); break; + case 0xB002: creg[2] = V; Sync(); break; + case 0xB003: creg[3] = V; Sync(); break; + case 0xB004: creg[4] = V; Sync(); break; + case 0xB005: creg[5] = V; Sync(); break; + case 0xB006: creg[6] = V; Sync(); break; + case 0xB007: creg[7] = V; Sync(); break; + } +} + +static void M65Power(void) { + preg[2] = ~1; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M65Write); +} + +void FP_FASTAPASS(1) M65IRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount < -4) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0xFFFF; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper65_Init(CartInfo *info) { + info->Power = M65Power; + MapIRQHook = M65IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/67.c b/src/boards/67.c index 73b5333..6d8e5ab 100644 --- a/src/boards/67.c +++ b/src/boards/67.c @@ -1,105 +1,105 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 preg, creg[4], mirr, suntoggle = 0; -static uint8 IRQa; -static int16 IRQCount, IRQLatch; - -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { &suntoggle, 1, "STOG" }, - { creg, 4, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 2, "IRQC" }, - { &IRQLatch, 2, "IRQL" }, - { 0 } -}; - -static void Sync(void) { - setmirror(mirr); - setprg16(0x8000, preg); - setprg16(0xC000, ~0); - setchr2(0x0000, creg[0]); - setchr2(0x0800, creg[1]); - setchr2(0x1000, creg[2]); - setchr2(0x1800, creg[3]); - switch (mirr) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(M67Write) { - switch (A & 0xF800) { - case 0x8800: creg[0] = V; Sync(); break; - case 0x9800: creg[1] = V; Sync(); break; - case 0xA800: creg[2] = V; Sync(); break; - case 0xB800: creg[3] = V; Sync(); break; - case 0xC000: - case 0xC800: - IRQCount &= 0xFF << (suntoggle << 3); - IRQCount |= V << ((suntoggle ^ 1) << 3); - suntoggle ^= 1; - break; - case 0xD800: - suntoggle = 0; - IRQa = V & 0x10; - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xE800: mirr = V & 3; Sync(); break; - case 0xF800: preg = V; Sync(); break; - } -} - -static void M67Power(void) { - suntoggle = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M67Write); -} - -void FP_FASTAPASS(1) M67IRQ(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount <= 0) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - IRQCount = 0xFFFF; - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper67_Init(CartInfo *info) { - info->Power = M67Power; - MapIRQHook = M67IRQ; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 preg, creg[4], mirr, suntoggle = 0; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &suntoggle, 1, "STOG" }, + { creg, 4, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr2(0x0000, creg[0]); + setchr2(0x0800, creg[1]); + setchr2(0x1000, creg[2]); + setchr2(0x1800, creg[3]); + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M67Write) { + switch (A & 0xF800) { + case 0x8800: creg[0] = V; Sync(); break; + case 0x9800: creg[1] = V; Sync(); break; + case 0xA800: creg[2] = V; Sync(); break; + case 0xB800: creg[3] = V; Sync(); break; + case 0xC000: + case 0xC800: + IRQCount &= 0xFF << (suntoggle << 3); + IRQCount |= V << ((suntoggle ^ 1) << 3); + suntoggle ^= 1; + break; + case 0xD800: + suntoggle = 0; + IRQa = V & 0x10; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xE800: mirr = V & 3; Sync(); break; + case 0xF800: preg = V; Sync(); break; + } +} + +static void M67Power(void) { + suntoggle = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M67Write); +} + +void FP_FASTAPASS(1) M67IRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0xFFFF; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper67_Init(CartInfo *info) { + info->Power = M67Power; + MapIRQHook = M67IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/68.c b/src/boards/68.c index 710f443..19da627 100644 --- a/src/boards/68.c +++ b/src/boards/68.c @@ -1,164 +1,164 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - */ - -#include "mapinc.h" - -static uint8 chr_reg[4]; -static uint8 kogame, prg_reg, nt1, nt2, mirr; - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE, count; - -static SFORMAT StateRegs[] = -{ - { &nt1, 1, "NT1" }, - { &nt2, 1, "NT2" }, - { &mirr, 1, "MIRR" }, - { &prg_reg, 1, "PRG" }, - { &kogame, 1, "KGME" }, - { &count, 4, "CNT" }, - { chr_reg, 4, "CHR" }, - { 0 } -}; - -static void M68NTfix(void) { - if ((!UNIFchrrama) && (mirr & 0x10)) { - PPUNTARAM = 0; - switch (mirr & 3) { - case 0: - vnapage[0] = vnapage[2] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); - vnapage[1] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); - break; - case 1: - vnapage[0] = vnapage[1] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); - vnapage[2] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); - break; - case 2: - vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); - break; - case 3: - vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); - break; - } - } else - switch (mirr & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static void Sync(void) { - setchr2(0x0000, chr_reg[0]); - setchr2(0x0800, chr_reg[1]); - setchr2(0x1000, chr_reg[2]); - setchr2(0x1800, chr_reg[3]); - setprg8r(0x10, 0x6000, 0); - setprg16r((PRGptr[1]) ? kogame : 0, 0x8000, prg_reg); - setprg16(0xC000, ~0); -} - -static DECLFR(M68Read) { - if (!(kogame & 8)) { - count++; - if (count == 1784) - setprg16r(0, 0x8000, prg_reg); - } - return CartBR(A); -} - -static DECLFW(M68WriteLo) { - if (!V) { - count = 0; - setprg16r((PRGptr[1]) ? kogame : 0, 0x8000, prg_reg); - } - CartBW(A, V); -} - -static DECLFW(M68WriteCHR) { - chr_reg[(A >> 12) & 3] = V; - Sync(); -} - -static DECLFW(M68WriteNT1) { - nt1 = V; - M68NTfix(); -} - -static DECLFW(M68WriteNT2) { - nt2 = V; - M68NTfix(); -} - -static DECLFW(M68WriteMIR) { - mirr = V; - M68NTfix(); -} - -static DECLFW(M68WriteROM) { - prg_reg = V & 7; - kogame = ((V >> 3) & 1) ^ 1; - Sync(); -} - -static void M68Power(void) { - prg_reg = 0; - kogame = 0; - Sync(); - M68NTfix(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xBFFF, M68Read); - SetReadHandler(0xC000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xBFFF, M68WriteCHR); - SetWriteHandler(0xC000, 0xCFFF, M68WriteNT1); - SetWriteHandler(0xD000, 0xDFFF, M68WriteNT2); - SetWriteHandler(0xE000, 0xEFFF, M68WriteMIR); - SetWriteHandler(0xF000, 0xFFFF, M68WriteROM); - SetWriteHandler(0x6000, 0x6000, M68WriteLo); - SetWriteHandler(0x6001, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M68Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); - M68NTfix(); -} - -void Mapper68_Init(CartInfo *info) { - info->Power = M68Power; - info->Close = M68Close; - GameStateRestore = StateRestore; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + */ + +#include "mapinc.h" + +static uint8 chr_reg[4]; +static uint8 kogame, prg_reg, nt1, nt2, mirr; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE, count; + +static SFORMAT StateRegs[] = +{ + { &nt1, 1, "NT1" }, + { &nt2, 1, "NT2" }, + { &mirr, 1, "MIRR" }, + { &prg_reg, 1, "PRG" }, + { &kogame, 1, "KGME" }, + { &count, 4, "CNT" }, + { chr_reg, 4, "CHR" }, + { 0 } +}; + +static void M68NTfix(void) { + if ((!UNIFchrrama) && (mirr & 0x10)) { + PPUNTARAM = 0; + switch (mirr & 3) { + case 0: + vnapage[0] = vnapage[2] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); + vnapage[1] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); + break; + case 1: + vnapage[0] = vnapage[1] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); + vnapage[2] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); + break; + case 2: + vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = CHRptr[0] + (((nt1 | 128) & CHRmask1[0]) << 10); + break; + case 3: + vnapage[0] = vnapage[1] = vnapage[2] = vnapage[3] = CHRptr[0] + (((nt2 | 128) & CHRmask1[0]) << 10); + break; + } + } else + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static void Sync(void) { + setchr2(0x0000, chr_reg[0]); + setchr2(0x0800, chr_reg[1]); + setchr2(0x1000, chr_reg[2]); + setchr2(0x1800, chr_reg[3]); + setprg8r(0x10, 0x6000, 0); + setprg16r((PRGptr[1]) ? kogame : 0, 0x8000, prg_reg); + setprg16(0xC000, ~0); +} + +static DECLFR(M68Read) { + if (!(kogame & 8)) { + count++; + if (count == 1784) + setprg16r(0, 0x8000, prg_reg); + } + return CartBR(A); +} + +static DECLFW(M68WriteLo) { + if (!V) { + count = 0; + setprg16r((PRGptr[1]) ? kogame : 0, 0x8000, prg_reg); + } + CartBW(A, V); +} + +static DECLFW(M68WriteCHR) { + chr_reg[(A >> 12) & 3] = V; + Sync(); +} + +static DECLFW(M68WriteNT1) { + nt1 = V; + M68NTfix(); +} + +static DECLFW(M68WriteNT2) { + nt2 = V; + M68NTfix(); +} + +static DECLFW(M68WriteMIR) { + mirr = V; + M68NTfix(); +} + +static DECLFW(M68WriteROM) { + prg_reg = V & 7; + kogame = ((V >> 3) & 1) ^ 1; + Sync(); +} + +static void M68Power(void) { + prg_reg = 0; + kogame = 0; + Sync(); + M68NTfix(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xBFFF, M68Read); + SetReadHandler(0xC000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, M68WriteCHR); + SetWriteHandler(0xC000, 0xCFFF, M68WriteNT1); + SetWriteHandler(0xD000, 0xDFFF, M68WriteNT2); + SetWriteHandler(0xE000, 0xEFFF, M68WriteMIR); + SetWriteHandler(0xF000, 0xFFFF, M68WriteROM); + SetWriteHandler(0x6000, 0x6000, M68WriteLo); + SetWriteHandler(0x6001, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M68Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); + M68NTfix(); +} + +void Mapper68_Init(CartInfo *info) { + info->Power = M68Power; + info->Close = M68Close; + GameStateRestore = StateRestore; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/69.c b/src/boards/69.c index 0de0558..6ff54cb 100644 --- a/src/boards/69.c +++ b/src/boards/69.c @@ -1,282 +1,282 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 CaH4e3 - * Copyright (C) 2002 Xodnizel - * - * 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" - -static uint8 cmdreg, preg[4], creg[8], mirr; -static uint8 IRQa; -static int32 IRQCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &cmdreg, 1, "CMDR" }, - { preg, 4, "PREG" }, - { creg, 8, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { 0 } -}; - -static void Sync(void) { - uint8 i; - if ((preg[3] & 0xC0) == 0xC0) - setprg8r(0x10, 0x6000, 0); - else - setprg8(0x6000, preg[3] & 0x3F); - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, creg[i]); - switch (mirr & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(M69WRAMWrite) { - if ((preg[3] & 0xC0) == 0xC0) - CartBW(A, V); -} - -static DECLFR(M69WRAMRead) { - if ((preg[3] & 0xC0) == 0x40) - return X.DB; - else - return CartBR(A); -} - -static DECLFW(M69Write0) { - cmdreg = V & 0xF; -} - -static DECLFW(M69Write1) { - switch (cmdreg) { - case 0x0: creg[0] = V; Sync(); break; - case 0x1: creg[1] = V; Sync(); break; - case 0x2: creg[2] = V; Sync(); break; - case 0x3: creg[3] = V; Sync(); break; - case 0x4: creg[4] = V; Sync(); break; - case 0x5: creg[5] = V; Sync(); break; - case 0x6: creg[6] = V; Sync(); break; - case 0x7: creg[7] = V; Sync(); break; - case 0x8: preg[3] = V; Sync(); break; - case 0x9: preg[0] = V; Sync(); break; - case 0xA: preg[1] = V; Sync(); break; - case 0xB: preg[2] = V; Sync(); break; - case 0xC: mirr = V & 3; Sync();break; - /* 17/10/17- reg $0D should awknowledge IRQ and no other - * http://forums.nesdev.com/viewtopic.php?f=2&t=12436&start=15 - */ - case 0xD: IRQa = V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xE: IRQCount &= 0xFF00; IRQCount |= V; break; - case 0xF: IRQCount &= 0x00FF; IRQCount |= V << 8; break; - } -} - -/* SUNSOFT-5/FME-7 Sound */ - -static void AYSound(int Count); -static void AYSoundHQ(void); -static void DoAYSQ(int x); -static void DoAYSQHQ(int x); - -static uint8 sndcmd, sreg[14]; -static int32 vcount[3]; -static int32 dcount[3]; -static int CAYBC[3]; - -static SFORMAT SStateRegs[] = -{ - { &sndcmd, 1, "SCMD" }, - { sreg, 14, "SREG" }, - { 0 } -}; - -static DECLFW(M69SWrite0) { - sndcmd = V % 14; -} - -static DECLFW(M69SWrite1) { - int x; - GameExpSound.Fill = AYSound; - GameExpSound.HiFill = AYSoundHQ; - if (FSettings.SndRate) - switch (sndcmd) { - case 0: - case 1: - case 8: if (FSettings.soundq >= 1) DoAYSQHQ(0); else DoAYSQ(0); break; - case 2: - case 3: - case 9: if (FSettings.soundq >= 1) DoAYSQHQ(1); else DoAYSQ(1); break; - case 4: - case 5: - case 10: if (FSettings.soundq >= 1) DoAYSQHQ(2); else DoAYSQ(2); break; - case 7: - for (x = 0; x < 2; x++) - if (FSettings.soundq >= 1) DoAYSQHQ(x); else DoAYSQ(x); - break; - } - sreg[sndcmd] = V; -} - -static void DoAYSQ(int x) { - int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << (4 + 17); - int32 amp = (sreg[0x8 + x] & 15) << 2; - int32 start, end; - int V; - - amp += amp >> 1; - - start = CAYBC[x]; - end = (SOUNDTS << 16) / soundtsinc; - if (end <= start) return; - CAYBC[x] = end; - - if (amp && !(sreg[0x7] & (1 << x))) - for (V = start; V < end; V++) { - if (dcount[x]) - Wave[V >> 4] += amp; - vcount[x] -= nesincsize; - while (vcount[x] <= 0) { - dcount[x] ^= 1; - vcount[x] += freq; - } - } -} - -static void DoAYSQHQ(int x) { - uint32 V; - int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << 4; - int32 amp = (sreg[0x8 + x] & 15) << 6; - - amp += amp >> 1; - - if (!(sreg[0x7] & (1 << x))) { - for (V = CAYBC[x]; V < SOUNDTS; V++) { - if (dcount[x]) - WaveHi[V] += amp; - vcount[x]--; - if (vcount[x] <= 0) { - dcount[x] ^= 1; - vcount[x] = freq; - } - } - } - CAYBC[x] = SOUNDTS; -} - -static void AYSound(int Count) { - int x; - DoAYSQ(0); - DoAYSQ(1); - DoAYSQ(2); - for (x = 0; x < 3; x++) - CAYBC[x] = Count; -} - -static void AYSoundHQ(void) { - DoAYSQHQ(0); - DoAYSQHQ(1); - DoAYSQHQ(2); -} - -static void AYHiSync(int32 ts) { - int x; - - for (x = 0; x < 3; x++) - CAYBC[x] = ts; -} - -void Mapper69_ESI(void) { - GameExpSound.RChange = Mapper69_ESI; - GameExpSound.HiSync = AYHiSync; - memset(dcount, 0, sizeof(dcount)); - memset(vcount, 0, sizeof(vcount)); - memset(CAYBC, 0, sizeof(CAYBC)); - AddExState(&SStateRegs, ~0, 0, 0); -} - -/* SUNSOFT-5/FME-7 Sound */ - -static void M69Power(void) { - cmdreg = sndcmd = 0; - IRQCount = 0xFFFF; - IRQa = 0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, M69WRAMRead); - SetWriteHandler(0x6000, 0x7FFF, M69WRAMWrite); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0x9FFF, M69Write0); - SetWriteHandler(0xA000, 0xBFFF, M69Write1); - SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); - SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M69Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void M69IRQHook(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount <= 0) { - X6502_IRQBegin(FCEU_IQEXT); IRQa = 0; IRQCount = 0xFFFF; - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper69_Init(CartInfo *info) { - info->Power = M69Power; - info->Close = M69Close; - MapIRQHook = M69IRQHook; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - GameStateRestore = StateRestore; - Mapper69_ESI(); - AddExState(&StateRegs, ~0, 0, 0); -} - -void NSFAY_Init(void) { - sndcmd = 0; - SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); - SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); - Mapper69_ESI(); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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" + +static uint8 cmdreg, preg[4], creg[8], mirr; +static uint8 IRQa; +static int32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &cmdreg, 1, "CMDR" }, + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + if ((preg[3] & 0xC0) == 0xC0) + setprg8r(0x10, 0x6000, 0); + else + setprg8(0x6000, preg[3] & 0x3F); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M69WRAMWrite) { + if ((preg[3] & 0xC0) == 0xC0) + CartBW(A, V); +} + +static DECLFR(M69WRAMRead) { + if ((preg[3] & 0xC0) == 0x40) + return X.DB; + else + return CartBR(A); +} + +static DECLFW(M69Write0) { + cmdreg = V & 0xF; +} + +static DECLFW(M69Write1) { + switch (cmdreg) { + case 0x0: creg[0] = V; Sync(); break; + case 0x1: creg[1] = V; Sync(); break; + case 0x2: creg[2] = V; Sync(); break; + case 0x3: creg[3] = V; Sync(); break; + case 0x4: creg[4] = V; Sync(); break; + case 0x5: creg[5] = V; Sync(); break; + case 0x6: creg[6] = V; Sync(); break; + case 0x7: creg[7] = V; Sync(); break; + case 0x8: preg[3] = V; Sync(); break; + case 0x9: preg[0] = V; Sync(); break; + case 0xA: preg[1] = V; Sync(); break; + case 0xB: preg[2] = V; Sync(); break; + case 0xC: mirr = V & 3; Sync();break; + /* 17/10/17- reg $0D should awknowledge IRQ and no other + * http://forums.nesdev.com/viewtopic.php?f=2&t=12436&start=15 + */ + case 0xD: IRQa = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE: IRQCount &= 0xFF00; IRQCount |= V; break; + case 0xF: IRQCount &= 0x00FF; IRQCount |= V << 8; break; + } +} + +/* SUNSOFT-5/FME-7 Sound */ + +static void AYSound(int Count); +static void AYSoundHQ(void); +static void DoAYSQ(int x); +static void DoAYSQHQ(int x); + +static uint8 sndcmd, sreg[14]; +static int32 vcount[3]; +static int32 dcount[3]; +static int CAYBC[3]; + +static SFORMAT SStateRegs[] = +{ + { &sndcmd, 1, "SCMD" }, + { sreg, 14, "SREG" }, + { 0 } +}; + +static DECLFW(M69SWrite0) { + sndcmd = V % 14; +} + +static DECLFW(M69SWrite1) { + int x; + GameExpSound.Fill = AYSound; + GameExpSound.HiFill = AYSoundHQ; + if (FSettings.SndRate) + switch (sndcmd) { + case 0: + case 1: + case 8: if (FSettings.soundq >= 1) DoAYSQHQ(0); else DoAYSQ(0); break; + case 2: + case 3: + case 9: if (FSettings.soundq >= 1) DoAYSQHQ(1); else DoAYSQ(1); break; + case 4: + case 5: + case 10: if (FSettings.soundq >= 1) DoAYSQHQ(2); else DoAYSQ(2); break; + case 7: + for (x = 0; x < 2; x++) + if (FSettings.soundq >= 1) DoAYSQHQ(x); else DoAYSQ(x); + break; + } + sreg[sndcmd] = V; +} + +static void DoAYSQ(int x) { + int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << (4 + 17); + int32 amp = (sreg[0x8 + x] & 15) << 2; + int32 start, end; + int V; + + amp += amp >> 1; + + start = CAYBC[x]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + CAYBC[x] = end; + + if (amp && !(sreg[0x7] & (1 << x))) + for (V = start; V < end; V++) { + if (dcount[x]) + Wave[V >> 4] += amp; + vcount[x] -= nesincsize; + while (vcount[x] <= 0) { + dcount[x] ^= 1; + vcount[x] += freq; + } + } +} + +static void DoAYSQHQ(int x) { + uint32 V; + int32 freq = ((sreg[x << 1] | ((sreg[(x << 1) + 1] & 15) << 8)) + 1) << 4; + int32 amp = (sreg[0x8 + x] & 15) << 6; + + amp += amp >> 1; + + if (!(sreg[0x7] & (1 << x))) { + for (V = CAYBC[x]; V < SOUNDTS; V++) { + if (dcount[x]) + WaveHi[V] += amp; + vcount[x]--; + if (vcount[x] <= 0) { + dcount[x] ^= 1; + vcount[x] = freq; + } + } + } + CAYBC[x] = SOUNDTS; +} + +static void AYSound(int Count) { + int x; + DoAYSQ(0); + DoAYSQ(1); + DoAYSQ(2); + for (x = 0; x < 3; x++) + CAYBC[x] = Count; +} + +static void AYSoundHQ(void) { + DoAYSQHQ(0); + DoAYSQHQ(1); + DoAYSQHQ(2); +} + +static void AYHiSync(int32 ts) { + int x; + + for (x = 0; x < 3; x++) + CAYBC[x] = ts; +} + +void Mapper69_ESI(void) { + GameExpSound.RChange = Mapper69_ESI; + GameExpSound.HiSync = AYHiSync; + memset(dcount, 0, sizeof(dcount)); + memset(vcount, 0, sizeof(vcount)); + memset(CAYBC, 0, sizeof(CAYBC)); + AddExState(&SStateRegs, ~0, 0, 0); +} + +/* SUNSOFT-5/FME-7 Sound */ + +static void M69Power(void) { + cmdreg = sndcmd = 0; + IRQCount = 0xFFFF; + IRQa = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, M69WRAMRead); + SetWriteHandler(0x6000, 0x7FFF, M69WRAMWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x9FFF, M69Write0); + SetWriteHandler(0xA000, 0xBFFF, M69Write1); + SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); + SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M69Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void M69IRQHook(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); IRQa = 0; IRQCount = 0xFFFF; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper69_Init(CartInfo *info) { + info->Power = M69Power; + info->Close = M69Close; + MapIRQHook = M69IRQHook; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + Mapper69_ESI(); + AddExState(&StateRegs, ~0, 0, 0); +} + +void NSFAY_Init(void) { + sndcmd = 0; + SetWriteHandler(0xC000, 0xDFFF, M69SWrite0); + SetWriteHandler(0xE000, 0xFFFF, M69SWrite1); + Mapper69_ESI(); +} diff --git a/src/boards/71.c b/src/boards/71.c index a709a1f..12ce402 100644 --- a/src/boards/71.c +++ b/src/boards/71.c @@ -1,64 +1,64 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 preg, mirr; - -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setprg16(0x8000, preg); - setprg16(0xC000, ~0); - setchr8(0); - if (mirr) - setmirror(mirr); -} - -static DECLFW(M71Write) { - if ((A & 0xF000) == 0x9000) - mirr = MI_0 + ((V >> 4) & 1); /* 2-in-1, some carts are normal hardwire V/H mirror, some uses mapper selectable 0/1 mirror */ - else - preg = V; - Sync(); -} - -static void M71Power(void) { - mirr = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M71Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper71_Init(CartInfo *info) { - info->Power = M71Power; - GameStateRestore = StateRestore; - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 preg, mirr; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr8(0); + if (mirr) + setmirror(mirr); +} + +static DECLFW(M71Write) { + if ((A & 0xF000) == 0x9000) + mirr = MI_0 + ((V >> 4) & 1); /* 2-in-1, some carts are normal hardwire V/H mirror, some uses mapper selectable 0/1 mirror */ + else + preg = V; + Sync(); +} + +static void M71Power(void) { + mirr = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M71Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper71_Init(CartInfo *info) { + info->Power = M71Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/72.c b/src/boards/72.c index de5ec91..bd187f8 100644 --- a/src/boards/72.c +++ b/src/boards/72.c @@ -1,64 +1,64 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * Moero!! Pro Tennis have ADPCM codec on-board, PROM isn't dumped, emulation isn't - * possible just now. - */ - -#include "mapinc.h" - -static uint8 preg, creg; - -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { &creg, 1, "CREG" }, - { 0 } -}; - -static void Sync(void) { - setprg16(0x8000, preg); - setprg16(0xC000, ~0); - setchr8(creg); -} - -static DECLFW(M72Write) { - if (V & 0x80) - preg = V & 0xF; - if (V & 0x40) - creg = V & 0xF; - Sync(); -} - -static void M72Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0xFFFF, M72Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper72_Init(CartInfo *info) { - info->Power = M72Power; - GameStateRestore = StateRestore; - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * Moero!! Pro Tennis have ADPCM codec on-board, PROM isn't dumped, emulation isn't + * possible just now. + */ + +#include "mapinc.h" + +static uint8 preg, creg; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr8(creg); +} + +static DECLFW(M72Write) { + if (V & 0x80) + preg = V & 0xF; + if (V & 0x40) + creg = V & 0xF; + Sync(); +} + +static void M72Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, M72Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper72_Init(CartInfo *info) { + info->Power = M72Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/77.c b/src/boards/77.c index 577ab4d..7edbd3e 100644 --- a/src/boards/77.c +++ b/src/boards/77.c @@ -1,74 +1,74 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 latche; - -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &latche, 1, "LATC" }, - { 0 } -}; - -static void Sync(void) { - setprg32(0x8000, latche & 7); - setchr2(0x0000, latche >> 4); - setchr2r(0x10, 0x0800, 2); - setchr4r(0x10, 0x1000, 0); -} - -static DECLFW(M77Write) { - latche = V; - Sync(); -} - -static void M77Power(void) { - latche = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M77Write); -} - -static void M77Close(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper77_Init(CartInfo *info) { - info->Power = M77Power; - info->Close = M77Close; - GameStateRestore = StateRestore; - - CHRRAMSIZE = 6 * 1024; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 latche; + +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, latche & 7); + setchr2(0x0000, latche >> 4); + setchr2r(0x10, 0x0800, 2); + setchr4r(0x10, 0x1000, 0); +} + +static DECLFW(M77Write) { + latche = V; + Sync(); +} + +static void M77Power(void) { + latche = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M77Write); +} + +static void M77Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper77_Init(CartInfo *info) { + info->Power = M77Power; + info->Close = M77Close; + GameStateRestore = StateRestore; + + CHRRAMSIZE = 6 * 1024; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/79.c b/src/boards/79.c index 14d9ac7..c5b7f8e 100644 --- a/src/boards/79.c +++ b/src/boards/79.c @@ -1,61 +1,61 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 CaH4e3 - * Copyright (C) 2002 Xodnizel - * - * 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" - -static uint8 creg, preg; -static SFORMAT StateRegs[] = -{ - { &creg, 1, "CREG" }, - { &preg, 1, "PREG" }, - { 0 } -}; - -static void Sync(void) { - setprg32(0x8000, preg); - setchr8(creg); -} - -static DECLFW(M79Write) { - if ((A < 0x8000) && ((A ^ 0x4100) == 0)) { - preg = (V >> 3) & 1; - } - creg = V & 7; - Sync(); -} - -static void M79Power(void) { - preg = ~0; - Sync(); - SetWriteHandler(0x4100, 0x5FFF, M79Write); - SetWriteHandler(0x8000, 0xFFFF, M79Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper79_Init(CartInfo *info) { - info->Power = M79Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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" + +static uint8 creg, preg; +static SFORMAT StateRegs[] = +{ + { &creg, 1, "CREG" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, preg); + setchr8(creg); +} + +static DECLFW(M79Write) { + if ((A < 0x8000) && ((A ^ 0x4100) == 0)) { + preg = (V >> 3) & 1; + } + creg = V & 7; + Sync(); +} + +static void M79Power(void) { + preg = ~0; + Sync(); + SetWriteHandler(0x4100, 0x5FFF, M79Write); + SetWriteHandler(0x8000, 0xFFFF, M79Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper79_Init(CartInfo *info) { + info->Power = M79Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/80.c b/src/boards/80.c index a882f4b..3427d83 100644 --- a/src/boards/80.c +++ b/src/boards/80.c @@ -1,193 +1,193 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 CaH4e3 - * Copyright (C) 2002 Xodnizel - * - * 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" - -static uint8 preg[3], creg[6], isExMirr; -static uint8 mirr, cmd, wram_enable, wram[256]; -static uint8 mcache[8]; -static uint32 lastppu; - -static SFORMAT StateRegs80[] = -{ - { preg, 3, "PREG" }, - { creg, 6, "CREG" }, - { wram, 256, "WRAM" }, - { &mirr, 1, "MIRR" }, - { &wram_enable, 1, "WRME" }, - { 0 } -}; - -static SFORMAT StateRegs95[] = -{ - { &cmd, 1, "CMDR" }, - { preg, 3, "PREG" }, - { creg, 6, "CREG" }, - { mcache, 8, "MCCH" }, - { &lastppu, 4, "LPPU" }, - { 0 } -}; - -static SFORMAT StateRegs207[] = -{ - { preg, 3, "PREG" }, - { creg, 6, "CREG" }, - { mcache, 8, "MCCH" }, - { &lastppu, 4, "LPPU" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, ~0); - setchr2(0x0000, (creg[0] >> 1) & 0x3F); - setchr2(0x0800, (creg[1] >> 1) & 0x3F); - setchr1(0x1000, creg[2]); - setchr1(0x1400, creg[3]); - setchr1(0x1800, creg[4]); - setchr1(0x1C00, creg[5]); - if (isExMirr) { - setmirror(MI_0 + mcache[lastppu]); - } else - setmirror(mirr); -} - -static DECLFW(M80RamWrite) { - if (wram_enable == 0xA3) - wram[A & 0xFF] = V; -} - -static DECLFR(M80RamRead) { - if (wram_enable == 0xA3) - return wram[A & 0xFF]; - else - return 0xFF; -} - -static DECLFW(M80Write) { - switch (A) { - case 0x7EF0: creg[0] = V; mcache[0] = mcache[1] = V >> 7; Sync(); break; - case 0x7EF1: creg[1] = V; mcache[2] = mcache[3] = V >> 7; Sync(); break; - case 0x7EF2: creg[2] = V; mcache[4] = V >> 7; Sync(); break; - case 0x7EF3: creg[3] = V; mcache[5] = V >> 7; Sync(); break; - case 0x7EF4: creg[4] = V; mcache[6] = V >> 7; Sync(); break; - case 0x7EF5: creg[5] = V; mcache[7] = V >> 7; Sync(); break; - case 0x7EF6: mirr = V & 1; Sync(); break; - case 0x7EF8: wram_enable = V; break; - case 0x7EFA: - case 0x7EFB: preg[0] = V; Sync(); break; - case 0x7EFC: - case 0x7EFD: preg[1] = V; Sync(); break; - case 0x7EFE: - case 0x7EFF: preg[2] = V; Sync(); break; - } -} - -static DECLFW(M95Write) { - switch (A & 0xF001) { - case 0x8000: cmd = V; break; - case 0x8001: - switch (cmd & 0x07) { - case 0: creg[0] = V & 0x1F; mcache[0] = mcache[1] = (V >> 5) & 1; Sync(); break; - case 1: creg[1] = V & 0x1F; mcache[2] = mcache[3] = (V >> 5) & 1; Sync(); break; - case 2: creg[2] = V & 0x1F; mcache[4] = (V >> 5) & 1; Sync(); break; - case 3: creg[3] = V & 0x1F; mcache[5] = (V >> 5) & 1; Sync(); break; - case 4: creg[4] = V & 0x1F; mcache[6] = (V >> 5) & 1; Sync(); break; - case 5: creg[5] = V & 0x1F; mcache[7] = (V >> 5) & 1; Sync(); break; - case 6: preg[0] = V; Sync(); break; - case 7: preg[1] = V; Sync(); break; - } - Sync(); - } -} - -static void FP_FASTAPASS(1) MExMirrPPU(uint32 A) { - static int8 lastmirr = -1, curmirr; - if (A < 0x2000) { - lastppu = A >> 10; - curmirr = mcache[lastppu]; - if (curmirr != lastmirr) { - setmirror(MI_0 + curmirr); - lastmirr = curmirr; - } - } -} - -static void M80Power(void) { - wram_enable = 0xFF; - Sync(); - SetReadHandler(0x7F00, 0x7FFF, M80RamRead); - SetWriteHandler(0x7F00, 0x7FFF, M80RamWrite); - SetWriteHandler(0x7EF0, 0x7EFF, M80Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void M207Power(void) { - mcache[0] = mcache[1] = mcache[2] = mcache[3] = 0; - mcache[4] = mcache[5] = mcache[6] = mcache[7] = 0; - Sync(); - SetWriteHandler(0x7EF0, 0x7EFF, M80Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void M95Power(void) { - preg[2] = ~1; - mcache[0] = mcache[1] = mcache[2] = mcache[3] = 0; - mcache[4] = mcache[5] = mcache[6] = mcache[7] = 0; - Sync(); - SetWriteHandler(0x8000, 0xFFFF, M95Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper80_Init(CartInfo *info) { - isExMirr = 0; - info->Power = M80Power; - GameStateRestore = StateRestore; - - if (info->battery) { - info->SaveGame[0] = wram; - info->SaveGameLen[0] = 256; - } - - AddExState(&StateRegs80, ~0, 0, 0); -} - -void Mapper95_Init(CartInfo *info) { - isExMirr = 1; - info->Power = M95Power; - PPU_hook = MExMirrPPU; - GameStateRestore = StateRestore; - AddExState(&StateRegs95, ~0, 0, 0); -} - -void Mapper207_Init(CartInfo *info) { - isExMirr = 1; - info->Power = M207Power; - PPU_hook = MExMirrPPU; - GameStateRestore = StateRestore; - AddExState(&StateRegs207, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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" + +static uint8 preg[3], creg[6], isExMirr; +static uint8 mirr, cmd, wram_enable, wram[256]; +static uint8 mcache[8]; +static uint32 lastppu; + +static SFORMAT StateRegs80[] = +{ + { preg, 3, "PREG" }, + { creg, 6, "CREG" }, + { wram, 256, "WRAM" }, + { &mirr, 1, "MIRR" }, + { &wram_enable, 1, "WRME" }, + { 0 } +}; + +static SFORMAT StateRegs95[] = +{ + { &cmd, 1, "CMDR" }, + { preg, 3, "PREG" }, + { creg, 6, "CREG" }, + { mcache, 8, "MCCH" }, + { &lastppu, 4, "LPPU" }, + { 0 } +}; + +static SFORMAT StateRegs207[] = +{ + { preg, 3, "PREG" }, + { creg, 6, "CREG" }, + { mcache, 8, "MCCH" }, + { &lastppu, 4, "LPPU" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + setchr2(0x0000, (creg[0] >> 1) & 0x3F); + setchr2(0x0800, (creg[1] >> 1) & 0x3F); + setchr1(0x1000, creg[2]); + setchr1(0x1400, creg[3]); + setchr1(0x1800, creg[4]); + setchr1(0x1C00, creg[5]); + if (isExMirr) { + setmirror(MI_0 + mcache[lastppu]); + } else + setmirror(mirr); +} + +static DECLFW(M80RamWrite) { + if (wram_enable == 0xA3) + wram[A & 0xFF] = V; +} + +static DECLFR(M80RamRead) { + if (wram_enable == 0xA3) + return wram[A & 0xFF]; + else + return 0xFF; +} + +static DECLFW(M80Write) { + switch (A) { + case 0x7EF0: creg[0] = V; mcache[0] = mcache[1] = V >> 7; Sync(); break; + case 0x7EF1: creg[1] = V; mcache[2] = mcache[3] = V >> 7; Sync(); break; + case 0x7EF2: creg[2] = V; mcache[4] = V >> 7; Sync(); break; + case 0x7EF3: creg[3] = V; mcache[5] = V >> 7; Sync(); break; + case 0x7EF4: creg[4] = V; mcache[6] = V >> 7; Sync(); break; + case 0x7EF5: creg[5] = V; mcache[7] = V >> 7; Sync(); break; + case 0x7EF6: mirr = V & 1; Sync(); break; + case 0x7EF8: wram_enable = V; break; + case 0x7EFA: + case 0x7EFB: preg[0] = V; Sync(); break; + case 0x7EFC: + case 0x7EFD: preg[1] = V; Sync(); break; + case 0x7EFE: + case 0x7EFF: preg[2] = V; Sync(); break; + } +} + +static DECLFW(M95Write) { + switch (A & 0xF001) { + case 0x8000: cmd = V; break; + case 0x8001: + switch (cmd & 0x07) { + case 0: creg[0] = V & 0x1F; mcache[0] = mcache[1] = (V >> 5) & 1; Sync(); break; + case 1: creg[1] = V & 0x1F; mcache[2] = mcache[3] = (V >> 5) & 1; Sync(); break; + case 2: creg[2] = V & 0x1F; mcache[4] = (V >> 5) & 1; Sync(); break; + case 3: creg[3] = V & 0x1F; mcache[5] = (V >> 5) & 1; Sync(); break; + case 4: creg[4] = V & 0x1F; mcache[6] = (V >> 5) & 1; Sync(); break; + case 5: creg[5] = V & 0x1F; mcache[7] = (V >> 5) & 1; Sync(); break; + case 6: preg[0] = V; Sync(); break; + case 7: preg[1] = V; Sync(); break; + } + Sync(); + } +} + +static void FP_FASTAPASS(1) MExMirrPPU(uint32 A) { + static int8 lastmirr = -1, curmirr; + if (A < 0x2000) { + lastppu = A >> 10; + curmirr = mcache[lastppu]; + if (curmirr != lastmirr) { + setmirror(MI_0 + curmirr); + lastmirr = curmirr; + } + } +} + +static void M80Power(void) { + wram_enable = 0xFF; + Sync(); + SetReadHandler(0x7F00, 0x7FFF, M80RamRead); + SetWriteHandler(0x7F00, 0x7FFF, M80RamWrite); + SetWriteHandler(0x7EF0, 0x7EFF, M80Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M207Power(void) { + mcache[0] = mcache[1] = mcache[2] = mcache[3] = 0; + mcache[4] = mcache[5] = mcache[6] = mcache[7] = 0; + Sync(); + SetWriteHandler(0x7EF0, 0x7EFF, M80Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M95Power(void) { + preg[2] = ~1; + mcache[0] = mcache[1] = mcache[2] = mcache[3] = 0; + mcache[4] = mcache[5] = mcache[6] = mcache[7] = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M95Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper80_Init(CartInfo *info) { + isExMirr = 0; + info->Power = M80Power; + GameStateRestore = StateRestore; + + if (info->battery) { + info->SaveGame[0] = wram; + info->SaveGameLen[0] = 256; + } + + AddExState(&StateRegs80, ~0, 0, 0); +} + +void Mapper95_Init(CartInfo *info) { + isExMirr = 1; + info->Power = M95Power; + PPU_hook = MExMirrPPU; + GameStateRestore = StateRestore; + AddExState(&StateRegs95, ~0, 0, 0); +} + +void Mapper207_Init(CartInfo *info) { + isExMirr = 1; + info->Power = M207Power; + PPU_hook = MExMirrPPU; + GameStateRestore = StateRestore; + AddExState(&StateRegs207, ~0, 0, 0); +} diff --git a/src/boards/8157.c b/src/boards/8157.c index 0d46287..8a95353 100644 --- a/src/boards/8157.c +++ b/src/boards/8157.c @@ -1,85 +1,85 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * GG1 boards, similar to T-262, with no Data latch - * - */ - -#include "mapinc.h" - -static uint16 cmdreg; -static uint8 reset; -static SFORMAT StateRegs[] = -{ - { &reset, 1, "REST" }, - { &cmdreg, 2, "CREG" }, - { 0 } -}; - -static void Sync(void) { - uint32 base = ((cmdreg & 0x060) | ((cmdreg & 0x100) >> 1)) >> 2; - uint32 bank = (cmdreg & 0x01C) >> 2; - uint32 lbank = (cmdreg & 0x200) ? 7 : ((cmdreg & 0x80) ? bank : 0); - if (PRGptr[1]) { - setprg16r(base >> 3, 0x8000, bank); /* for versions with split ROMs */ - setprg16r(base >> 3, 0xC000, lbank); - } else { - setprg16(0x8000, base | bank); - setprg16(0xC000, base | lbank); - } - setmirror(((cmdreg & 2) >> 1) ^ 1); -} - -static DECLFR(UNL8157Read) { - if ((cmdreg & 0x100) && (PRGsize[0] < (1024 * 1024))) { - A = (A & 0xFFF0) + reset; - } - return CartBR(A); -} - -static DECLFW(UNL8157Write) { - cmdreg = A; - Sync(); -} - -static void UNL8157Power(void) { - setchr8(0); - SetWriteHandler(0x8000, 0xFFFF, UNL8157Write); - SetReadHandler(0x8000, 0xFFFF, UNL8157Read); - cmdreg = reset = 0; - Sync(); -} - -static void UNL8157Reset(void) { - cmdreg = reset = 0; - reset++; - reset &= 0x1F; - Sync(); -} - -static void UNL8157Restore(int version) { - Sync(); -} - -void UNL8157_Init(CartInfo *info) { - info->Power = UNL8157Power; - info->Reset = UNL8157Reset; - GameStateRestore = UNL8157Restore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * GG1 boards, similar to T-262, with no Data latch + * + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static uint8 reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "REST" }, + { &cmdreg, 2, "CREG" }, + { 0 } +}; + +static void Sync(void) { + uint32 base = ((cmdreg & 0x060) | ((cmdreg & 0x100) >> 1)) >> 2; + uint32 bank = (cmdreg & 0x01C) >> 2; + uint32 lbank = (cmdreg & 0x200) ? 7 : ((cmdreg & 0x80) ? bank : 0); + if (PRGptr[1]) { + setprg16r(base >> 3, 0x8000, bank); /* for versions with split ROMs */ + setprg16r(base >> 3, 0xC000, lbank); + } else { + setprg16(0x8000, base | bank); + setprg16(0xC000, base | lbank); + } + setmirror(((cmdreg & 2) >> 1) ^ 1); +} + +static DECLFR(UNL8157Read) { + if ((cmdreg & 0x100) && (PRGsize[0] < (1024 * 1024))) { + A = (A & 0xFFF0) + reset; + } + return CartBR(A); +} + +static DECLFW(UNL8157Write) { + cmdreg = A; + Sync(); +} + +static void UNL8157Power(void) { + setchr8(0); + SetWriteHandler(0x8000, 0xFFFF, UNL8157Write); + SetReadHandler(0x8000, 0xFFFF, UNL8157Read); + cmdreg = reset = 0; + Sync(); +} + +static void UNL8157Reset(void) { + cmdreg = reset = 0; + reset++; + reset &= 0x1F; + Sync(); +} + +static void UNL8157Restore(int version) { + Sync(); +} + +void UNL8157_Init(CartInfo *info) { + info->Power = UNL8157Power; + info->Reset = UNL8157Reset; + GameStateRestore = UNL8157Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/82.c b/src/boards/82.c index ff63e97..fd71c75 100644 --- a/src/boards/82.c +++ b/src/boards/82.c @@ -1,98 +1,98 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * Taito X1-017 board, battery backed - * - */ - -#include "mapinc.h" - -static uint8 regs[9], ctrl; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { regs, 9, "REGS" }, - { &ctrl, 1, "CTRL" }, - { 0 } -}; - -static void Sync(void) { - uint32 swap = ((ctrl & 2) << 11); - setchr2(0x0000 ^ swap, regs[0] >> 1); - setchr2(0x0800 ^ swap, regs[1] >> 1); - setchr1(0x1000 ^ swap, regs[2]); - setchr1(0x1400 ^ swap, regs[3]); - setchr1(0x1800 ^ swap, regs[4]); - setchr1(0x1c00 ^ swap, regs[5]); - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, regs[6]); - setprg8(0xA000, regs[7]); - setprg8(0xC000, regs[8]); - setprg8(0xE000, ~0); - setmirror(ctrl & 1); -} - -static DECLFW(M82Write) { - if (A <= 0x7ef5) - regs[A & 7] = V; - else - switch (A) { - case 0x7ef6: ctrl = V & 3; break; - case 0x7efa: regs[6] = V >> 2; break; - case 0x7efb: regs[7] = V >> 2; break; - case 0x7efc: regs[8] = V >> 2; break; - } - Sync(); -} - -static void M82Power(void) { - Sync(); - SetReadHandler(0x6000, 0xffff, CartBR); - SetWriteHandler(0x6000, 0x7fff, CartBW); - SetWriteHandler(0x7ef0, 0x7efc, M82Write); /* external WRAM might end at $73FF */ - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M82Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper82_Init(CartInfo *info) { - info->Power = M82Power; - info->Close = M82Close; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * Taito X1-017 board, battery backed + * + */ + +#include "mapinc.h" + +static uint8 regs[9], ctrl; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 9, "REGS" }, + { &ctrl, 1, "CTRL" }, + { 0 } +}; + +static void Sync(void) { + uint32 swap = ((ctrl & 2) << 11); + setchr2(0x0000 ^ swap, regs[0] >> 1); + setchr2(0x0800 ^ swap, regs[1] >> 1); + setchr1(0x1000 ^ swap, regs[2]); + setchr1(0x1400 ^ swap, regs[3]); + setchr1(0x1800 ^ swap, regs[4]); + setchr1(0x1c00 ^ swap, regs[5]); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, regs[6]); + setprg8(0xA000, regs[7]); + setprg8(0xC000, regs[8]); + setprg8(0xE000, ~0); + setmirror(ctrl & 1); +} + +static DECLFW(M82Write) { + if (A <= 0x7ef5) + regs[A & 7] = V; + else + switch (A) { + case 0x7ef6: ctrl = V & 3; break; + case 0x7efa: regs[6] = V >> 2; break; + case 0x7efb: regs[7] = V >> 2; break; + case 0x7efc: regs[8] = V >> 2; break; + } + Sync(); +} + +static void M82Power(void) { + Sync(); + SetReadHandler(0x6000, 0xffff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetWriteHandler(0x7ef0, 0x7efc, M82Write); /* external WRAM might end at $73FF */ + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M82Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper82_Init(CartInfo *info) { + info->Power = M82Power; + info->Close = M82Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/830118C.c b/src/boards/830118C.c index ba464d7..5196c8d 100644 --- a/src/boards/830118C.c +++ b/src/boards/830118C.c @@ -1,68 +1,68 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2008 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 - */ - -/* M-022 MMC3 based 830118C T-106 4M + 4M */ - -#include "mapinc.h" -#include "mmc3.h" - -static void BMC830118CCW(uint32 A, uint8 V) { - setchr1(A, (V & 0x7F) | ((EXPREGS[0] & 0x0c) << 5)); -} - -static void BMC830118CPW(uint32 A, uint8 V) { - if ((EXPREGS[0] & 0x0C) == 0x0C) { - if (A == 0x8000) { - setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); - setprg8(0xC000, (V & 0x0F) | 0x32); - } else if (A == 0xA000) { - setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); - setprg8(0xE000, (V & 0x0F) | 0x32); - } - } else { - setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); - } -} - -static DECLFW(BMC830118CLoWrite) { - EXPREGS[0] = V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void BMC830118CReset(void) { - EXPREGS[0] = 0; - MMC3RegReset(); -} - -static void BMC830118CPower(void) { - EXPREGS[0] = 0; - GenMMC3Power(); - SetWriteHandler(0x6800, 0x68FF, BMC830118CLoWrite); -} - -void BMC830118C_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 128, 8, 0); - pwrap = BMC830118CPW; - cwrap = BMC830118CCW; - info->Power = BMC830118CPower; - info->Reset = BMC830118CReset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 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 + */ + +/* M-022 MMC3 based 830118C T-106 4M + 4M */ + +#include "mapinc.h" +#include "mmc3.h" + +static void BMC830118CCW(uint32 A, uint8 V) { + setchr1(A, (V & 0x7F) | ((EXPREGS[0] & 0x0c) << 5)); +} + +static void BMC830118CPW(uint32 A, uint8 V) { + if ((EXPREGS[0] & 0x0C) == 0x0C) { + if (A == 0x8000) { + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); + setprg8(0xC000, (V & 0x0F) | 0x32); + } else if (A == 0xA000) { + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); + setprg8(0xE000, (V & 0x0F) | 0x32); + } + } else { + setprg8(A, (V & 0x0F) | ((EXPREGS[0] & 0x0c) << 2)); + } +} + +static DECLFW(BMC830118CLoWrite) { + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC830118CReset(void) { + EXPREGS[0] = 0; + MMC3RegReset(); +} + +static void BMC830118CPower(void) { + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6800, 0x68FF, BMC830118CLoWrite); +} + +void BMC830118C_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = BMC830118CPW; + cwrap = BMC830118CCW; + info->Power = BMC830118CPower; + info->Reset = BMC830118CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/91.c b/src/boards/91.c index d1ed61b..da9177f 100644 --- a/src/boards/91.c +++ b/src/boards/91.c @@ -1,85 +1,85 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 cregs[4], pregs[2]; -static uint8 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { cregs, 4, "CREG" }, - { pregs, 2, "PREG" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 1, "IRQC" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x8000, pregs[0]); - setprg8(0xa000, pregs[1]); - setprg8(0xc000, ~1); - setprg8(0xe000, ~0); - setchr2(0x0000, cregs[0]); - setchr2(0x0800, cregs[1]); - setchr2(0x1000, cregs[2]); - setchr2(0x1800, cregs[3]); -} - -static DECLFW(M91Write0) { - cregs[A & 3] = V; - Sync(); -} - -static DECLFW(M91Write1) { - switch (A & 3) { - case 0: - case 1: pregs[A & 1] = V; Sync(); break; - case 2: IRQa = IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 3: IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; - } -} - -static void M91Power(void) { - Sync(); - SetWriteHandler(0x6000, 0x6fff, M91Write0); - SetWriteHandler(0x7000, 0x7fff, M91Write1); - SetReadHandler(0x8000, 0xffff, CartBR); -} - -static void M91IRQHook(void) { - if (IRQCount < 8 && IRQa) { - IRQCount++; - if (IRQCount >= 8) { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper91_Init(CartInfo *info) { - info->Power = M91Power; - GameHBIRQHook = M91IRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 cregs[4], pregs[2]; +static uint8 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { cregs, 4, "CREG" }, + { pregs, 2, "PREG" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 1, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, pregs[0]); + setprg8(0xa000, pregs[1]); + setprg8(0xc000, ~1); + setprg8(0xe000, ~0); + setchr2(0x0000, cregs[0]); + setchr2(0x0800, cregs[1]); + setchr2(0x1000, cregs[2]); + setchr2(0x1800, cregs[3]); +} + +static DECLFW(M91Write0) { + cregs[A & 3] = V; + Sync(); +} + +static DECLFW(M91Write1) { + switch (A & 3) { + case 0: + case 1: pregs[A & 1] = V; Sync(); break; + case 2: IRQa = IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 3: IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void M91Power(void) { + Sync(); + SetWriteHandler(0x6000, 0x6fff, M91Write0); + SetWriteHandler(0x7000, 0x7fff, M91Write1); + SetReadHandler(0x8000, 0xffff, CartBR); +} + +static void M91IRQHook(void) { + if (IRQCount < 8 && IRQa) { + IRQCount++; + if (IRQCount >= 8) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper91_Init(CartInfo *info) { + info->Power = M91Power; + GameHBIRQHook = M91IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/96.c b/src/boards/96.c index d3f24e9..de59381 100644 --- a/src/boards/96.c +++ b/src/boards/96.c @@ -1,77 +1,77 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * Copyright (C) 2002 Xodnizel - * Copyright (C) 2012 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 - * - * Oeka-kids board - * - * I might want to add some code to the mapper 96 PPU hook function - * to not change CHR banks if the attribute table is being accessed, - * if I make emulation a little more accurate in the future. - * - */ - -#include "mapinc.h" - -static uint8 reg, ppulatch; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { &ppulatch, 1, "PPUL" }, - { 0 } -}; - -static void Sync(void) { - setmirror(MI_0); - setprg32(0x8000, reg & 3); - setchr4(0x0000, (reg & 4) | ppulatch); - setchr4(0x1000, (reg & 4) | 3); -} - -static DECLFW(M96Write) { - reg = V; - Sync(); -} - -static void FP_FASTAPASS(1) M96Hook(uint32 A) { - if ((A & 0x3000) == 0x2000) { - ppulatch = (A >> 8) & 3; - Sync(); - } -} - -static void M96Power(void) { - reg = ppulatch = 0; - Sync(); - SetReadHandler(0x8000, 0xffff, CartBR); - SetWriteHandler(0x8000, 0xffff, M96Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper96_Init(CartInfo *info) { - info->Power = M96Power; - PPU_hook = M96Hook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * Copyright (C) 2012 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 + * + * Oeka-kids board + * + * I might want to add some code to the mapper 96 PPU hook function + * to not change CHR banks if the attribute table is being accessed, + * if I make emulation a little more accurate in the future. + * + */ + +#include "mapinc.h" + +static uint8 reg, ppulatch; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &ppulatch, 1, "PPUL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(MI_0); + setprg32(0x8000, reg & 3); + setchr4(0x0000, (reg & 4) | ppulatch); + setchr4(0x1000, (reg & 4) | 3); +} + +static DECLFW(M96Write) { + reg = V; + Sync(); +} + +static void FP_FASTAPASS(1) M96Hook(uint32 A) { + if ((A & 0x3000) == 0x2000) { + ppulatch = (A >> 8) & 3; + Sync(); + } +} + +static void M96Power(void) { + reg = ppulatch = 0; + Sync(); + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x8000, 0xffff, M96Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper96_Init(CartInfo *info) { + info->Power = M96Power; + PPU_hook = M96Hook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/99.c b/src/boards/99.c index cf3bb14..c6a3eb3 100644 --- a/src/boards/99.c +++ b/src/boards/99.c @@ -1,78 +1,78 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" - -static uint8 latch; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static writefunc old4016; - -static SFORMAT StateRegs[] = -{ - { &latch, 1, "LATC" }, - { 0 } -}; - -static void Sync(void) { - setchr8((latch >> 2) & 1); - setprg8r(0x10, 0x6000, 0); - setprg32(0x8000, 0); - setprg8(0x8000, latch & 4); /* Special for VS Gumshoe */ -} - -static DECLFW(M99Write) { - latch = V; - Sync(); - old4016(A, V); -} - -static void M99Power(void) { - latch = 0; - Sync(); - old4016 = GetWriteHandler(0x4016); - SetWriteHandler(0x4016, 0x4016, M99Write); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M99Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper99_Init(CartInfo *info) { - info->Power = M99Power; - info->Close = M99Close; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +static uint8 latch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static writefunc old4016; + +static SFORMAT StateRegs[] = +{ + { &latch, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setchr8((latch >> 2) & 1); + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, 0); + setprg8(0x8000, latch & 4); /* Special for VS Gumshoe */ +} + +static DECLFW(M99Write) { + latch = V; + Sync(); + old4016(A, V); +} + +static void M99Power(void) { + latch = 0; + Sync(); + old4016 = GetWriteHandler(0x4016); + SetWriteHandler(0x4016, 0x4016, M99Write); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M99Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper99_Init(CartInfo *info) { + info->Power = M99Power; + info->Close = M99Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7012.c b/src/boards/KS7012.c index 326dc14..c4dbcb7 100644 --- a/src/boards/KS7012.c +++ b/src/boards/KS7012.c @@ -1,87 +1,87 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0x10, 0x6000, 0); - setprg32(0x8000, reg & 1); - setchr8(0); -} - -static DECLFW(UNLKS7012Write) { -/* FCEU_printf("bs %04x %02x\n",A,V); */ - switch (A) { - case 0xE0A0: reg = 0; Sync(); break; - case 0xEE36: reg = 1; Sync(); break; - } -} - -static void UNLKS7012Power(void) { - reg = ~0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLKS7012Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void UNLKS7012Reset(void) { - reg = ~0; - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -static void UNLKS7012Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void UNLKS7012_Init(CartInfo *info) { - info->Power = UNLKS7012Power; - info->Reset = UNLKS7012Reset; - info->Close = UNLKS7012Close; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, reg & 1); + setchr8(0); +} + +static DECLFW(UNLKS7012Write) { +/* FCEU_printf("bs %04x %02x\n",A,V); */ + switch (A) { + case 0xE0A0: reg = 0; Sync(); break; + case 0xEE36: reg = 1; Sync(); break; + } +} + +static void UNLKS7012Power(void) { + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLKS7012Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void UNLKS7012Reset(void) { + reg = ~0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +static void UNLKS7012Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void UNLKS7012_Init(CartInfo *info) { + info->Power = UNLKS7012Power; + info->Reset = UNLKS7012Reset; + info->Close = UNLKS7012Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7013.c b/src/boards/KS7013.c index fe8349e..1ec7b8b 100644 --- a/src/boards/KS7013.c +++ b/src/boards/KS7013.c @@ -1,77 +1,77 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * Just another pirate cart with pirate mapper, instead of original MMC1 - * Kaiser Highway Star - * - */ - -#include "mapinc.h" - -static uint8 reg, mirr; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REGS" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setprg16(0x8000, reg); - setprg16(0xc000, ~0); - setmirror(mirr); - setchr8(0); -} - -static DECLFW(UNLKS7013BLoWrite) { - reg = V; - Sync(); -} - -static DECLFW(UNLKS7013BHiWrite) { - mirr = (V & 1) ^ 1; - Sync(); -} - -static void UNLKS7013BPower(void) { - reg = 0; - mirr = 0; - Sync(); - SetWriteHandler(0x6000, 0x7FFF, UNLKS7013BLoWrite); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLKS7013BHiWrite); -} - -static void UNLKS7013BReset(void) { - reg = 0; - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLKS7013B_Init(CartInfo *info) { - info->Power = UNLKS7013BPower; - info->Reset = UNLKS7013BReset; - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * Just another pirate cart with pirate mapper, instead of original MMC1 + * Kaiser Highway Star + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, reg); + setprg16(0xc000, ~0); + setmirror(mirr); + setchr8(0); +} + +static DECLFW(UNLKS7013BLoWrite) { + reg = V; + Sync(); +} + +static DECLFW(UNLKS7013BHiWrite) { + mirr = (V & 1) ^ 1; + Sync(); +} + +static void UNLKS7013BPower(void) { + reg = 0; + mirr = 0; + Sync(); + SetWriteHandler(0x6000, 0x7FFF, UNLKS7013BLoWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLKS7013BHiWrite); +} + +static void UNLKS7013BReset(void) { + reg = 0; + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7013B_Init(CartInfo *info) { + info->Power = UNLKS7013BPower; + info->Reset = UNLKS7013BReset; + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7017.c b/src/boards/KS7017.c index 686f3cb..64812a4 100644 --- a/src/boards/KS7017.c +++ b/src/boards/KS7017.c @@ -1,115 +1,115 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg, mirr; -static int32 IRQa, IRQCount, IRQLatch; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &mirr, 1, "MIRR" }, - { ®, 1, "REGS" }, - { &IRQa, 4, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { &IRQLatch, 4, "IRQL" }, - { 0 } -}; - -static void Sync(void) { - setprg16(0x8000, reg); - setprg16(0xC000, 2); - setmirror(mirr); -} - -static DECLFW(UNLKS7017Write) { -/* FCEU_printf("bs %04x %02x\n",A,V); */ - if ((A & 0xFF00) == 0x4A00) { - reg = ((A >> 2) & 3) | ((A >> 4) & 4); - } else if ((A & 0xFF00) == 0x5100) { - Sync(); - } else if (A == 0x4020) { - X6502_IRQEnd(FCEU_IQEXT); - IRQCount &= 0xFF00; - IRQCount |= V; - } else if (A == 0x4021) { - X6502_IRQEnd(FCEU_IQEXT); - IRQCount &= 0xFF; - IRQCount |= V << 8; - IRQa = 1; - } else if (A == 0x4025) { - mirr = ((V & 8) >> 3) ^ 1; - } -} -static DECLFR(FDSRead4030) { - X6502_IRQEnd(FCEU_IQEXT); - return X.IRQlow & FCEU_IQEXT ? 1 : 0; -} - -static void FP_FASTAPASS(1) UNL7017IRQ(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount <= 0) { - IRQa = 0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void UNLKS7017Power(void) { - Sync(); - setchr8(0); - setprg8r(0x10, 0x6000, 0); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetReadHandler(0x4030, 0x4030, FDSRead4030); - SetWriteHandler(0x4020, 0x5FFF, UNLKS7017Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void UNLKS7017Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLKS7017_Init(CartInfo *info) { - info->Power = UNLKS7017Power; - info->Close = UNLKS7017Close; - MapIRQHook = UNL7017IRQ; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static int32 IRQa, IRQCount, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &mirr, 1, "MIRR" }, + { ®, 1, "REGS" }, + { &IRQa, 4, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setprg16(0x8000, reg); + setprg16(0xC000, 2); + setmirror(mirr); +} + +static DECLFW(UNLKS7017Write) { +/* FCEU_printf("bs %04x %02x\n",A,V); */ + if ((A & 0xFF00) == 0x4A00) { + reg = ((A >> 2) & 3) | ((A >> 4) & 4); + } else if ((A & 0xFF00) == 0x5100) { + Sync(); + } else if (A == 0x4020) { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount &= 0xFF00; + IRQCount |= V; + } else if (A == 0x4021) { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount &= 0xFF; + IRQCount |= V << 8; + IRQa = 1; + } else if (A == 0x4025) { + mirr = ((V & 8) >> 3) ^ 1; + } +} +static DECLFR(FDSRead4030) { + X6502_IRQEnd(FCEU_IQEXT); + return X.IRQlow & FCEU_IQEXT ? 1 : 0; +} + +static void FP_FASTAPASS(1) UNL7017IRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + IRQa = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7017Power(void) { + Sync(); + setchr8(0); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0x4030, 0x4030, FDSRead4030); + SetWriteHandler(0x4020, 0x5FFF, UNLKS7017Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void UNLKS7017Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7017_Init(CartInfo *info) { + info->Power = UNLKS7017Power; + info->Close = UNLKS7017Close; + MapIRQHook = UNL7017IRQ; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7030.c b/src/boards/KS7030.c index 5c661e5..f9ece1f 100644 --- a/src/boards/KS7030.c +++ b/src/boards/KS7030.c @@ -1,142 +1,142 @@ -/* 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 - * - * FDS Conversion - * - * Logical bank layot 32 K BANK 0, 64K BANK 1, 32K ~0 hardwired, 8K is missing - * need redump from MASKROM! - * probably need refix mapper after hard dump - * - */ - -#include "mapinc.h" - -static uint8 reg0, reg1; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®0, 1, "REG0" }, - { ®1, 1, "REG1" }, - { 0 } -}; - -static void Sync(void) { - setchr8(0); - setprg32(0x8000, ~0); - setprg4(0xb800, reg0); - setprg4(0xc800, 8 + reg1); -} - -/* 6000 - 6BFF - RAM - * 6C00 - 6FFF - BANK 1K REG1 - * 7000 - 7FFF - BANK 4K REG0 - */ - -static DECLFW(UNLKS7030RamWrite0) { - if ((A >= 0x6000) && A <= 0x6BFF) { - WRAM[A - 0x6000] = V; - } else if ((A >= 0x6C00) && A <= 0x6FFF) { - CartBW(0xC800 + (A - 0x6C00), V); - } else if ((A >= 0x7000) && A <= 0x7FFF) { - CartBW(0xB800 + (A - 0x7000), V); - } -} - -static DECLFR(UNLKS7030RamRead0) { - if ((A >= 0x6000) && A <= 0x6BFF) { - return WRAM[A - 0x6000]; - } else if ((A >= 0x6C00) && A <= 0x6FFF) { - return CartBR(0xC800 + (A - 0x6C00)); - } else if ((A >= 0x7000) && A <= 0x7FFF) { - return CartBR(0xB800 + (A - 0x7000)); - } - return 0; -} - -/* B800 - BFFF - RAM - * C000 - CBFF - BANK 3K - * CC00 - D7FF - RAM - */ - -static DECLFW(UNLKS7030RamWrite1) { - if ((A >= 0xB800) && A <= 0xBFFF) { - WRAM[0x0C00 + (A - 0xB800)] = V; - } else if ((A >= 0xC000) && A <= 0xCBFF) { - CartBW(0xCC00 + (A - 0xC000), V); - } else if ((A >= 0xCC00) && A <= 0xD7FF) { - WRAM[0x1400 + (A - 0xCC00)] = V; - } -} - -static DECLFR(UNLKS7030RamRead1) { - if ((A >= 0xB800) && A <= 0xBFFF) { - return WRAM[0x0C00 + (A - 0xB800)]; - } else if ((A >= 0xC000) && A <= 0xCBFF) { - return CartBR(0xCC00 + (A - 0xC000)); - } else if ((A >= 0xCC00) && A <= 0xD7FF) { - return WRAM[0x1400 + (A - 0xCC00)]; - } - return 0; -} - -static DECLFW(UNLKS7030Write0) { - reg0 = A & 7; - Sync(); -} - -static DECLFW(UNLKS7030Write1) { - reg1 = A & 15; - Sync(); -} - -static void UNLKS7030Power(void) { - reg0 = reg1 = ~0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, UNLKS7030RamRead0); - SetWriteHandler(0x6000, 0x7FFF, UNLKS7030RamWrite0); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0x8FFF, UNLKS7030Write0); - SetWriteHandler(0x9000, 0x9FFF, UNLKS7030Write1); - SetReadHandler(0xB800, 0xD7FF, UNLKS7030RamRead1); - SetWriteHandler(0xB800, 0xD7FF, UNLKS7030RamWrite1); -} - -static void UNLKS7030Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLKS7030_Init(CartInfo *info) { - info->Power = UNLKS7030Power; - info->Close = UNLKS7030Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + * Logical bank layot 32 K BANK 0, 64K BANK 1, 32K ~0 hardwired, 8K is missing + * need redump from MASKROM! + * probably need refix mapper after hard dump + * + */ + +#include "mapinc.h" + +static uint8 reg0, reg1; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®0, 1, "REG0" }, + { ®1, 1, "REG1" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg32(0x8000, ~0); + setprg4(0xb800, reg0); + setprg4(0xc800, 8 + reg1); +} + +/* 6000 - 6BFF - RAM + * 6C00 - 6FFF - BANK 1K REG1 + * 7000 - 7FFF - BANK 4K REG0 + */ + +static DECLFW(UNLKS7030RamWrite0) { + if ((A >= 0x6000) && A <= 0x6BFF) { + WRAM[A - 0x6000] = V; + } else if ((A >= 0x6C00) && A <= 0x6FFF) { + CartBW(0xC800 + (A - 0x6C00), V); + } else if ((A >= 0x7000) && A <= 0x7FFF) { + CartBW(0xB800 + (A - 0x7000), V); + } +} + +static DECLFR(UNLKS7030RamRead0) { + if ((A >= 0x6000) && A <= 0x6BFF) { + return WRAM[A - 0x6000]; + } else if ((A >= 0x6C00) && A <= 0x6FFF) { + return CartBR(0xC800 + (A - 0x6C00)); + } else if ((A >= 0x7000) && A <= 0x7FFF) { + return CartBR(0xB800 + (A - 0x7000)); + } + return 0; +} + +/* B800 - BFFF - RAM + * C000 - CBFF - BANK 3K + * CC00 - D7FF - RAM + */ + +static DECLFW(UNLKS7030RamWrite1) { + if ((A >= 0xB800) && A <= 0xBFFF) { + WRAM[0x0C00 + (A - 0xB800)] = V; + } else if ((A >= 0xC000) && A <= 0xCBFF) { + CartBW(0xCC00 + (A - 0xC000), V); + } else if ((A >= 0xCC00) && A <= 0xD7FF) { + WRAM[0x1400 + (A - 0xCC00)] = V; + } +} + +static DECLFR(UNLKS7030RamRead1) { + if ((A >= 0xB800) && A <= 0xBFFF) { + return WRAM[0x0C00 + (A - 0xB800)]; + } else if ((A >= 0xC000) && A <= 0xCBFF) { + return CartBR(0xCC00 + (A - 0xC000)); + } else if ((A >= 0xCC00) && A <= 0xD7FF) { + return WRAM[0x1400 + (A - 0xCC00)]; + } + return 0; +} + +static DECLFW(UNLKS7030Write0) { + reg0 = A & 7; + Sync(); +} + +static DECLFW(UNLKS7030Write1) { + reg1 = A & 15; + Sync(); +} + +static void UNLKS7030Power(void) { + reg0 = reg1 = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, UNLKS7030RamRead0); + SetWriteHandler(0x6000, 0x7FFF, UNLKS7030RamWrite0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, UNLKS7030Write0); + SetWriteHandler(0x9000, 0x9FFF, UNLKS7030Write1); + SetReadHandler(0xB800, 0xD7FF, UNLKS7030RamRead1); + SetWriteHandler(0xB800, 0xD7FF, UNLKS7030RamWrite1); +} + +static void UNLKS7030Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7030_Init(CartInfo *info) { + info->Power = UNLKS7030Power; + info->Close = UNLKS7030Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7031.c b/src/boards/KS7031.c index f994434..bbd1d84 100644 --- a/src/boards/KS7031.c +++ b/src/boards/KS7031.c @@ -1,80 +1,80 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg[4]; - -static SFORMAT StateRegs[] = -{ - { reg, 4, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg2(0x6000, reg[0]); - setprg2(0x6800, reg[1]); - setprg2(0x7000, reg[2]); - setprg2(0x7800, reg[3]); - - setprg2(0x8000, 15); - setprg2(0x8800, 14); - setprg2(0x9000, 13); - setprg2(0x9800, 12); - setprg2(0xa000, 11); - setprg2(0xa800, 10); - setprg2(0xb000, 9); - setprg2(0xb800, 8); - - setprg2(0xc000, 7); - setprg2(0xc800, 6); - setprg2(0xd000, 5); - setprg2(0xd800, 4); - setprg2(0xe000, 3); - setprg2(0xe800, 2); - setprg2(0xf000, 1); - setprg2(0xf800, 0); - - setchr8(0); -} - -static DECLFW(UNLKS7031Write) { - reg[(A >> 11) & 3] = V; - Sync(); -} - -static void UNLKS7031Power(void) { - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xffff, UNLKS7031Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLKS7031_Init(CartInfo *info) { - info->Power = UNLKS7031Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[4]; + +static SFORMAT StateRegs[] = +{ + { reg, 4, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2(0x6000, reg[0]); + setprg2(0x6800, reg[1]); + setprg2(0x7000, reg[2]); + setprg2(0x7800, reg[3]); + + setprg2(0x8000, 15); + setprg2(0x8800, 14); + setprg2(0x9000, 13); + setprg2(0x9800, 12); + setprg2(0xa000, 11); + setprg2(0xa800, 10); + setprg2(0xb000, 9); + setprg2(0xb800, 8); + + setprg2(0xc000, 7); + setprg2(0xc800, 6); + setprg2(0xd000, 5); + setprg2(0xd800, 4); + setprg2(0xe000, 3); + setprg2(0xe800, 2); + setprg2(0xf000, 1); + setprg2(0xf800, 0); + + setchr8(0); +} + +static DECLFW(UNLKS7031Write) { + reg[(A >> 11) & 3] = V; + Sync(); +} + +static void UNLKS7031Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xffff, UNLKS7031Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7031_Init(CartInfo *info) { + info->Power = UNLKS7031Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7032.c b/src/boards/KS7032.c index e732e3d..7958a0c 100644 --- a/src/boards/KS7032.c +++ b/src/boards/KS7032.c @@ -1,91 +1,91 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg[8], cmd, IRQa = 0, isirqused = 0; -static int32 IRQCount; - -static SFORMAT StateRegs[] = -{ - { &cmd, 1, "CMD" }, - { reg, 8, "REGS" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, reg[4]); - setprg8(0x8000, reg[1]); - setprg8(0xA000, reg[2]); - setprg8(0xC000, reg[3]); - setprg8(0xE000, ~0); - setchr8(0); -} - -static DECLFW(UNLKS7032Write) { -/* FCEU_printf("bs %04x %02x\n",A,V); */ - switch (A & 0xF000) { -/* case 0x8FFF: reg[4]=V; Sync(); break; */ - case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x000F) | (V & 0x0F); isirqused = 1; break; - case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x00F0) | ((V & 0x0F) << 4); isirqused = 1; break; - case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x0F00) | ((V & 0x0F) << 8); isirqused = 1; break; - case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0xF000) | (V << 12); isirqused = 1; break; - case 0xC000: if (isirqused) { - X6502_IRQEnd(FCEU_IQEXT); IRQa = 1; - } - break; - case 0xE000: cmd = V & 7; break; - case 0xF000: reg[cmd] = V; Sync(); break; - } -} - -static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a) { - if (IRQa) { - IRQCount += a; - if (IRQCount >= 0xFFFF) { - IRQa = 0; - IRQCount = 0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void UNLKS7032Power(void) { - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x4020, 0xFFFF, UNLKS7032Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLKS7032_Init(CartInfo *info) { - info->Power = UNLKS7032Power; - MapIRQHook = UNLSMB2JIRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd, IRQa = 0, isirqused = 0; +static int32 IRQCount; + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { reg, 8, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg[4]); + setprg8(0x8000, reg[1]); + setprg8(0xA000, reg[2]); + setprg8(0xC000, reg[3]); + setprg8(0xE000, ~0); + setchr8(0); +} + +static DECLFW(UNLKS7032Write) { +/* FCEU_printf("bs %04x %02x\n",A,V); */ + switch (A & 0xF000) { +/* case 0x8FFF: reg[4]=V; Sync(); break; */ + case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x000F) | (V & 0x0F); isirqused = 1; break; + case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x00F0) | ((V & 0x0F) << 4); isirqused = 1; break; + case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0x0F00) | ((V & 0x0F) << 8); isirqused = 1; break; + case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount = (IRQCount & 0xF000) | (V << 12); isirqused = 1; break; + case 0xC000: if (isirqused) { + X6502_IRQEnd(FCEU_IQEXT); IRQa = 1; + } + break; + case 0xE000: cmd = V & 7; break; + case 0xF000: reg[cmd] = V; Sync(); break; + } +} + +static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 0xFFFF) { + IRQa = 0; + IRQCount = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7032Power(void) { + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x4020, 0xFFFF, UNLKS7032Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLKS7032_Init(CartInfo *info) { + info->Power = UNLKS7032Power; + MapIRQHook = UNLSMB2JIRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7037.c b/src/boards/KS7037.c index 232e758..17c047d 100644 --- a/src/boards/KS7037.c +++ b/src/boards/KS7037.c @@ -1,126 +1,126 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg[8], cmd; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static void (*WSync)(void); - -static SFORMAT StateRegs[] = -{ - { &cmd, 1, "CMD" }, - { reg, 8, "REGS" }, - { 0 } -}; - -static void SyncKS7037(void) { - setprg4r(0x10, 0x6000, 0); - setprg4(0x7000, 15); - setprg8(0x8000, reg[6]); - setprg4(0xA000, ~3); - setprg4r(0x10, 0xB000, 1); - setprg8(0xC000, reg[7]); - setprg8(0xE000, ~0); - setchr8(0); - setmirrorw(reg[2] & 1, reg[4] & 1, reg[3] & 1, reg[5] & 1); -} - -static void SyncLH10(void) { - setprg8(0x6000, ~1); - setprg8(0x8000, reg[6]); - setprg8(0xA000, reg[7]); - setprg8r(0x10, 0xC000, 0); - setprg8(0xE000, ~0); - setchr8(0); - setmirror(0); -} - -static DECLFW(UNLKS7037Write) { - switch (A & 0xE001) { - case 0x8000: cmd = V & 7; break; - case 0x8001: reg[cmd] = V; WSync(); break; - } -} - -static void UNLKS7037Power(void) { - reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; - WSync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0x9FFF, UNLKS7037Write); - SetWriteHandler(0xA000, 0xBFFF, CartBW); - SetWriteHandler(0xC000, 0xFFFF, UNLKS7037Write); -} - -static void LH10Power(void) { - reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; - WSync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xBFFF, UNLKS7037Write); - SetWriteHandler(0xC000, 0xDFFF, CartBW); - SetWriteHandler(0xE000, 0xFFFF, UNLKS7037Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - WSync(); -} - -void UNLKS7037_Init(CartInfo *info) { - info->Power = UNLKS7037Power; - info->Close = Close; - - WSync = SyncKS7037; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void LH10_Init(CartInfo *info) { - info->Power = LH10Power; - info->Close = Close; - - WSync = SyncLH10; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static void (*WSync)(void); + +static SFORMAT StateRegs[] = +{ + { &cmd, 1, "CMD" }, + { reg, 8, "REGS" }, + { 0 } +}; + +static void SyncKS7037(void) { + setprg4r(0x10, 0x6000, 0); + setprg4(0x7000, 15); + setprg8(0x8000, reg[6]); + setprg4(0xA000, ~3); + setprg4r(0x10, 0xB000, 1); + setprg8(0xC000, reg[7]); + setprg8(0xE000, ~0); + setchr8(0); + setmirrorw(reg[2] & 1, reg[4] & 1, reg[3] & 1, reg[5] & 1); +} + +static void SyncLH10(void) { + setprg8(0x6000, ~1); + setprg8(0x8000, reg[6]); + setprg8(0xA000, reg[7]); + setprg8r(0x10, 0xC000, 0); + setprg8(0xE000, ~0); + setchr8(0); + setmirror(0); +} + +static DECLFW(UNLKS7037Write) { + switch (A & 0xE001) { + case 0x8000: cmd = V & 7; break; + case 0x8001: reg[cmd] = V; WSync(); break; + } +} + +static void UNLKS7037Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; + WSync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0x9FFF, UNLKS7037Write); + SetWriteHandler(0xA000, 0xBFFF, CartBW); + SetWriteHandler(0xC000, 0xFFFF, UNLKS7037Write); +} + +static void LH10Power(void) { + reg[0] = reg[1] = reg[2] = reg[3] = reg[4] = reg[5] = reg[6] = reg[7] = 0; + WSync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, UNLKS7037Write); + SetWriteHandler(0xC000, 0xDFFF, CartBW); + SetWriteHandler(0xE000, 0xFFFF, UNLKS7037Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + WSync(); +} + +void UNLKS7037_Init(CartInfo *info) { + info->Power = UNLKS7037Power; + info->Close = Close; + + WSync = SyncKS7037; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void LH10_Init(CartInfo *info) { + info->Power = LH10Power; + info->Close = Close; + + WSync = SyncLH10; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/KS7057.c b/src/boards/KS7057.c index a9c4796..3762138 100644 --- a/src/boards/KS7057.c +++ b/src/boards/KS7057.c @@ -1,92 +1,92 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg[8], mirror; -static SFORMAT StateRegs[] = -{ - { reg, 8, "PRG" }, - { &mirror, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setprg2(0x6000, reg[4]); - setprg2(0x6800, reg[5]); - setprg2(0x7000, reg[6]); - setprg2(0x7800, reg[7]); - setprg2(0x8000, reg[0]); - setprg2(0x8800, reg[1]); - setprg2(0x9000, reg[2]); - setprg2(0x9800, reg[3]); - setprg8(0xA000, 0xd); - setprg16(0xC000, 7); - setchr8(0); - setmirror(mirror); -} - -static DECLFW(UNLKS7057Write) { - switch (A & 0xF003) { - case 0x8000: - case 0x8001: - case 0x8002: - case 0x8003: - case 0x9000: - case 0x9001: - case 0x9002: - case 0x9003: mirror = V & 1; Sync(); break; - case 0xB000: reg[0] = (reg[0] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xB001: reg[0] = (reg[0] & 0x0F) | (V << 4); Sync(); break; - case 0xB002: reg[1] = (reg[1] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xB003: reg[1] = (reg[1] & 0x0F) | (V << 4); Sync(); break; - case 0xC000: reg[2] = (reg[2] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xC001: reg[2] = (reg[2] & 0x0F) | (V << 4); Sync(); break; - case 0xC002: reg[3] = (reg[3] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xC003: reg[3] = (reg[3] & 0x0F) | (V << 4); Sync(); break; - case 0xD000: reg[4] = (reg[4] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xD001: reg[4] = (reg[4] & 0x0F) | (V << 4); Sync(); break; - case 0xD002: reg[5] = (reg[5] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xD003: reg[5] = (reg[5] & 0x0F) | (V << 4); Sync(); break; - case 0xE000: reg[6] = (reg[6] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xE001: reg[6] = (reg[6] & 0x0F) | (V << 4); Sync(); break; - case 0xE002: reg[7] = (reg[7] & 0xF0) | (V & 0x0F); Sync(); break; - case 0xE003: reg[7] = (reg[7] & 0x0F) | (V << 4); Sync(); break; - } -} - -static void UNLKS7057Power(void) { - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLKS7057Write); -} - -static void UNLKS7057Reset(void) { - Sync(); -} - -void UNLKS7057_Init(CartInfo *info) { - info->Power = UNLKS7057Power; - info->Reset = UNLKS7057Reset; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], mirror; +static SFORMAT StateRegs[] = +{ + { reg, 8, "PRG" }, + { &mirror, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg2(0x6000, reg[4]); + setprg2(0x6800, reg[5]); + setprg2(0x7000, reg[6]); + setprg2(0x7800, reg[7]); + setprg2(0x8000, reg[0]); + setprg2(0x8800, reg[1]); + setprg2(0x9000, reg[2]); + setprg2(0x9800, reg[3]); + setprg8(0xA000, 0xd); + setprg16(0xC000, 7); + setchr8(0); + setmirror(mirror); +} + +static DECLFW(UNLKS7057Write) { + switch (A & 0xF003) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: + case 0x9000: + case 0x9001: + case 0x9002: + case 0x9003: mirror = V & 1; Sync(); break; + case 0xB000: reg[0] = (reg[0] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB001: reg[0] = (reg[0] & 0x0F) | (V << 4); Sync(); break; + case 0xB002: reg[1] = (reg[1] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB003: reg[1] = (reg[1] & 0x0F) | (V << 4); Sync(); break; + case 0xC000: reg[2] = (reg[2] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC001: reg[2] = (reg[2] & 0x0F) | (V << 4); Sync(); break; + case 0xC002: reg[3] = (reg[3] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC003: reg[3] = (reg[3] & 0x0F) | (V << 4); Sync(); break; + case 0xD000: reg[4] = (reg[4] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD001: reg[4] = (reg[4] & 0x0F) | (V << 4); Sync(); break; + case 0xD002: reg[5] = (reg[5] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD003: reg[5] = (reg[5] & 0x0F) | (V << 4); Sync(); break; + case 0xE000: reg[6] = (reg[6] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE001: reg[6] = (reg[6] & 0x0F) | (V << 4); Sync(); break; + case 0xE002: reg[7] = (reg[7] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE003: reg[7] = (reg[7] & 0x0F) | (V << 4); Sync(); break; + } +} + +static void UNLKS7057Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLKS7057Write); +} + +static void UNLKS7057Reset(void) { + Sync(); +} + +void UNLKS7057_Init(CartInfo *info) { + info->Power = UNLKS7057Power; + info->Reset = UNLKS7057Reset; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/SA-9602B.c b/src/boards/SA-9602B.c index a6a19bb..7acd049 100644 --- a/src/boards/SA-9602B.c +++ b/src/boards/SA-9602B.c @@ -1,61 +1,61 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -static void SA9602BPW(uint32 A, uint8 V) { - setprg8r(EXPREGS[1], A, V & 0x3F); - if (MMC3_cmd & 0x40) - setprg8r(0, 0x8000, ~(1)); - else - setprg8r(0, 0xc000, ~(1)); - setprg8r(0, 0xe000, ~(0)); -} - -static DECLFW(SA9602BWrite) { - switch (A & 0xe001) { - case 0x8000: EXPREGS[0] = V; break; - case 0x8001: - if ((EXPREGS[0] & 7) < 6) { - EXPREGS[1] = V >> 6; - FixMMC3PRG(MMC3_cmd); - } - break; - } - MMC3_CMDWrite(A, V); -} - -static void SA9602BPower(void) { - EXPREGS[0] = EXPREGS[1] = 0; - GenMMC3Power(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xBFFF, SA9602BWrite); -} - -void SA9602B_Init(CartInfo *info) { - GenMMC3_Init(info, 512, 0, 0, 0); - pwrap = SA9602BPW; - mmc3opts |= 2; - info->SaveGame[0] = UNIFchrrama; - info->SaveGameLen[0] = 32 * 1024; - info->Power = SA9602BPower; - AddExState(EXPREGS, 2, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void SA9602BPW(uint32 A, uint8 V) { + setprg8r(EXPREGS[1], A, V & 0x3F); + if (MMC3_cmd & 0x40) + setprg8r(0, 0x8000, ~(1)); + else + setprg8r(0, 0xc000, ~(1)); + setprg8r(0, 0xe000, ~(0)); +} + +static DECLFW(SA9602BWrite) { + switch (A & 0xe001) { + case 0x8000: EXPREGS[0] = V; break; + case 0x8001: + if ((EXPREGS[0] & 7) < 6) { + EXPREGS[1] = V >> 6; + FixMMC3PRG(MMC3_cmd); + } + break; + } + MMC3_CMDWrite(A, V); +} + +static void SA9602BPower(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, SA9602BWrite); +} + +void SA9602B_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 0, 0, 0); + pwrap = SA9602BPW; + mmc3opts |= 2; + info->SaveGame[0] = UNIFchrrama; + info->SaveGameLen[0] = 32 * 1024; + info->Power = SA9602BPower; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/src/boards/__dummy_mapper.c b/src/boards/__dummy_mapper.c index 2f4e7d9..3443486 100644 --- a/src/boards/__dummy_mapper.c +++ b/src/boards/__dummy_mapper.c @@ -1,98 +1,98 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2013 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 - */ - -#include "mapinc.h" - -static uint8 reg[8]; -static uint8 IRQa; -static int16 IRQCount, IRQLatch; -/* -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; -*/ - -static SFORMAT StateRegs[] = -{ - { reg, 8, "REGS" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 2, "IRQC" }, - { &IRQLatch, 2, "IRQL" }, - { 0 } -}; - -static void Sync(void) { -} - -static DECLFW(MNNNWrite) { -} - -static void MNNNPower(void) { -/* SetReadHandler(0x6000, 0x7fff, CartBR); */ -/* SetWriteHandler(0x6000, 0x7fff, CartBW); */ - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, MNNNWrite); -} - -static void MNNNReset(void) { -} - -/* -static void MNNNClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - if (CHRRAM) - FCEU_gfree(CHRRAM); - WRAM = CHRRAM = NULL; -} -*/ - -static void MNNNIRQHook() { - X6502_IRQBegin(FCEU_IQEXT); -} - -static void StateRestore(int version) { - Sync(); -} - -void MapperNNN_Init(CartInfo *info) { - info->Reset = MNNNReset; - info->Power = MNNNPower; -/* info->Close = MNNNClose; */ - GameHBIRQHook = MNNNIRQHook; - GameStateRestore = StateRestore; -#if 0 - CHRRAMSIZE = 8192; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } -#endif - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2013 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 + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; +/* +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; +*/ + +static SFORMAT StateRegs[] = +{ + { reg, 8, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { +} + +static DECLFW(MNNNWrite) { +} + +static void MNNNPower(void) { +/* SetReadHandler(0x6000, 0x7fff, CartBR); */ +/* SetWriteHandler(0x6000, 0x7fff, CartBW); */ + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, MNNNWrite); +} + +static void MNNNReset(void) { +} + +/* +static void MNNNClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; +} +*/ + +static void MNNNIRQHook() { + X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) { + Sync(); +} + +void MapperNNN_Init(CartInfo *info) { + info->Reset = MNNNReset; + info->Power = MNNNPower; +/* info->Close = MNNNClose; */ + GameHBIRQHook = MNNNIRQHook; + GameStateRestore = StateRestore; +#if 0 + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } +#endif + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/__serial.c b/src/boards/__serial.c index c773d68..b13c608 100644 --- a/src/boards/__serial.c +++ b/src/boards/__serial.c @@ -1,150 +1,150 @@ -#include "__serial.h" - -#if defined(_WIN32) && !defined(_XBOX) && !defined(__LIBRETRO__) - -HANDLE SerialPort = NULL; /* Handle of SerialPort itself. */ - -BOOL SerialOpen(int port, int baud) { - HANDLE Comport; - DCB myDCB; - COMMTIMEOUTS CTout; - char str[100]; - - if (port > 9) - sprintf(str, "\\\\.\\COM%d", port); - else - sprintf(str, "COM%d", port); - - /* Open the serial port */ - if ((Comport = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) - return FALSE; - - /* Configure Serial port (Setup Comm) */ - - /* Buffer sizes */ - if (!SetupComm(Comport, 128, 128)) - return FALSE; - - /* Setup DCB using current values */ - if (!GetCommState(Comport, &myDCB)) - return FALSE; - - myDCB.fInX = FALSE; /* Turn off xon/xoff handler */ - myDCB.fOutX = FALSE; - myDCB.fOutxDsrFlow = FALSE; - myDCB.fOutxCtsFlow = FALSE; /* no hardware flow control. */ - myDCB.BaudRate = baud; - myDCB.DCBlength = sizeof(DCB); - myDCB.fBinary = 1; - myDCB.fParity = 0; - myDCB.fDtrControl = DTR_CONTROL_DISABLE; - myDCB.fDsrSensitivity = 0; - myDCB.fTXContinueOnXoff = 1; - myDCB.fNull = 0; - myDCB.fRtsControl = RTS_CONTROL_DISABLE; - myDCB.fDummy2 = 0; - myDCB.wReserved = 0; - myDCB.Parity = NOPARITY; - myDCB.StopBits = ONESTOPBIT; - myDCB.wReserved1 = 0; - myDCB.ByteSize = 8; - - if (!SetCommState(Comport, &myDCB)) - return FALSE; - - /* Set timeouts */ - CTout.ReadIntervalTimeout = 0xffffffff; - CTout.ReadTotalTimeoutMultiplier = 0; - CTout.ReadTotalTimeoutConstant = 0; - CTout.WriteTotalTimeoutMultiplier = 0; - CTout.WriteTotalTimeoutConstant = 5000; /* don't hang if CTS is locked, for example */ - - SetCommTimeouts(Comport, &CTout); - EscapeCommFunction(Comport, SETDTR); - PurgeComm(Comport, PURGE_TXCLEAR | PURGE_RXCLEAR); - - SerialPort = Comport; - - return TRUE; -} - -void SerialClose(void) { - if (SerialPort == NULL) return; - - PurgeComm(SerialPort, PURGE_TXCLEAR | PURGE_RXCLEAR); - CloseHandle(SerialPort); - - SerialPort = NULL; -} - -BOOL SerialSendChar(int c) { - DWORD cr; - if (WriteFile(SerialPort, &c, 1, (LPDWORD)&cr, NULL) && cr) - return TRUE; - else - return FALSE; -} - -int SerialIsOpen(void) { - return(SerialPort != NULL); -} - -int SerialGetChar(void) { - uint8 ch; - DWORD cr; - if (SerialPort != NULL) { - if (ReadFile(SerialPort, &ch, 1, (LPDWORD)&cr, NULL) && cr) - return (int)ch; - } - return EOF; -} - -void SendCmd(uint8 *cmd, int size) { - int i; - for (i = 0; i < size; i++) { - SerialSendChar(cmd[i]); - } -} - -int ReadResp(uint8 *resp, int size) { - int i = 0, sum = 0, data; - while (i < size) { - while ((data = SerialGetChar()) == EOF) { - } - resp[i] = data & 0xff; - sum += (data & 0xff); - i++; - } - return sum; -} -#else - -/* code is not portable, so make stubs for now */ - -BOOL SerialOpen(int port, int baud) { - return FALSE; -} - -void SerialClose(void) { -} - -BOOL SerialSendChar(int c) { - return FALSE; -} - -int SerialIsOpen(void) { - return FALSE; -} - -int SerialGetChar(void) { - return EOF; -} - -void SendCmd(uint8 *cmd, int size) { -} - -int ReadResp(uint8 *resp, int size) { - return 0; -} - -#endif +#include "__serial.h" + +#if defined(_WIN32) && !defined(_XBOX) && !defined(__LIBRETRO__) + +HANDLE SerialPort = NULL; /* Handle of SerialPort itself. */ + +BOOL SerialOpen(int port, int baud) { + HANDLE Comport; + DCB myDCB; + COMMTIMEOUTS CTout; + char str[100]; + + if (port > 9) + sprintf(str, "\\\\.\\COM%d", port); + else + sprintf(str, "COM%d", port); + + /* Open the serial port */ + if ((Comport = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) + return FALSE; + + /* Configure Serial port (Setup Comm) */ + + /* Buffer sizes */ + if (!SetupComm(Comport, 128, 128)) + return FALSE; + + /* Setup DCB using current values */ + if (!GetCommState(Comport, &myDCB)) + return FALSE; + + myDCB.fInX = FALSE; /* Turn off xon/xoff handler */ + myDCB.fOutX = FALSE; + myDCB.fOutxDsrFlow = FALSE; + myDCB.fOutxCtsFlow = FALSE; /* no hardware flow control. */ + myDCB.BaudRate = baud; + myDCB.DCBlength = sizeof(DCB); + myDCB.fBinary = 1; + myDCB.fParity = 0; + myDCB.fDtrControl = DTR_CONTROL_DISABLE; + myDCB.fDsrSensitivity = 0; + myDCB.fTXContinueOnXoff = 1; + myDCB.fNull = 0; + myDCB.fRtsControl = RTS_CONTROL_DISABLE; + myDCB.fDummy2 = 0; + myDCB.wReserved = 0; + myDCB.Parity = NOPARITY; + myDCB.StopBits = ONESTOPBIT; + myDCB.wReserved1 = 0; + myDCB.ByteSize = 8; + + if (!SetCommState(Comport, &myDCB)) + return FALSE; + + /* Set timeouts */ + CTout.ReadIntervalTimeout = 0xffffffff; + CTout.ReadTotalTimeoutMultiplier = 0; + CTout.ReadTotalTimeoutConstant = 0; + CTout.WriteTotalTimeoutMultiplier = 0; + CTout.WriteTotalTimeoutConstant = 5000; /* don't hang if CTS is locked, for example */ + + SetCommTimeouts(Comport, &CTout); + EscapeCommFunction(Comport, SETDTR); + PurgeComm(Comport, PURGE_TXCLEAR | PURGE_RXCLEAR); + + SerialPort = Comport; + + return TRUE; +} + +void SerialClose(void) { + if (SerialPort == NULL) return; + + PurgeComm(SerialPort, PURGE_TXCLEAR | PURGE_RXCLEAR); + CloseHandle(SerialPort); + + SerialPort = NULL; +} + +BOOL SerialSendChar(int c) { + DWORD cr; + if (WriteFile(SerialPort, &c, 1, (LPDWORD)&cr, NULL) && cr) + return TRUE; + else + return FALSE; +} + +int SerialIsOpen(void) { + return(SerialPort != NULL); +} + +int SerialGetChar(void) { + uint8 ch; + DWORD cr; + if (SerialPort != NULL) { + if (ReadFile(SerialPort, &ch, 1, (LPDWORD)&cr, NULL) && cr) + return (int)ch; + } + return EOF; +} + +void SendCmd(uint8 *cmd, int size) { + int i; + for (i = 0; i < size; i++) { + SerialSendChar(cmd[i]); + } +} + +int ReadResp(uint8 *resp, int size) { + int i = 0, sum = 0, data; + while (i < size) { + while ((data = SerialGetChar()) == EOF) { + } + resp[i] = data & 0xff; + sum += (data & 0xff); + i++; + } + return sum; +} +#else + +/* code is not portable, so make stubs for now */ + +BOOL SerialOpen(int port, int baud) { + return FALSE; +} + +void SerialClose(void) { +} + +BOOL SerialSendChar(int c) { + return FALSE; +} + +int SerialIsOpen(void) { + return FALSE; +} + +int SerialGetChar(void) { + return EOF; +} + +void SendCmd(uint8 *cmd, int size) { +} + +int ReadResp(uint8 *resp, int size) { + return 0; +} + +#endif diff --git a/src/boards/__serial.h b/src/boards/__serial.h index f9d8488..c9f9af5 100644 --- a/src/boards/__serial.h +++ b/src/boards/__serial.h @@ -1,31 +1,31 @@ -#ifndef __SERIAL_H -#define __SERIAL_H - -#include - -typedef int BOOL; - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#include "../fceu-types.h" - -void SendCmd(uint8 *cmd, int size); -int ReadResp(uint8 *resp, int size); - -#define SEND(cmd) SendCmd((uint8*)&cmd[0], sizeof(cmd)) -#define GET(buf, size) ReadResp((uint8*)&buf, size) -#define SENDGET(cmd, buf, size) SEND(cmd); GET(buf, size) - -BOOL SerialOpen(int port, int baud); -void SerialClose(void); -BOOL SerialSendChar(int c); -int SerialIsOpen(void); -int SerialGetChar(void); - -#endif +#ifndef __SERIAL_H +#define __SERIAL_H + +#include + +typedef int BOOL; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#include "../fceu-types.h" + +void SendCmd(uint8 *cmd, int size); +int ReadResp(uint8 *resp, int size); + +#define SEND(cmd) SendCmd((uint8*)&cmd[0], sizeof(cmd)) +#define GET(buf, size) ReadResp((uint8*)&buf, size) +#define SENDGET(cmd, buf, size) SEND(cmd); GET(buf, size) + +BOOL SerialOpen(int port, int baud); +void SerialClose(void); +BOOL SerialSendChar(int c); +int SerialIsOpen(void); +int SerialGetChar(void); + +#endif diff --git a/src/boards/a9746.c b/src/boards/a9746.c index b7bea21..97e2755 100644 --- a/src/boards/a9746.c +++ b/src/boards/a9746.c @@ -1,75 +1,75 @@ -/* 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -static DECLFW(UNLA9746Write) { -/* FCEU_printf("write raw %04x:%02x\n",A,V); */ - switch (A & 0xE003) { - case 0x8000: EXPREGS[1] = V; EXPREGS[0] = 0; break; - case 0x8002: EXPREGS[0] = V; EXPREGS[1] = 0; break; - case 0x8001: - { - uint8 bits_rev = ((V & 0x20) >> 5) | ((V & 0x10) >> 3) | ((V & 0x08) >> 1) | ((V & 0x04) << 1); - switch (EXPREGS[0]) { - case 0x26: setprg8(0x8000, bits_rev); break; - case 0x25: setprg8(0xA000, bits_rev); break; - case 0x24: setprg8(0xC000, bits_rev); break; - case 0x23: setprg8(0xE000, bits_rev); break; - } - switch (EXPREGS[1]) { - case 0x0a: - case 0x08: EXPREGS[2] = (V << 4); break; - case 0x09: setchr1(0x0000, EXPREGS[2] | (V >> 1)); break; - case 0x0b: setchr1(0x0400, EXPREGS[2] | (V >> 1) | 1); break; - case 0x0c: - case 0x0e: EXPREGS[2] = (V << 4); break; - case 0x0d: setchr1(0x0800, EXPREGS[2] | (V >> 1)); break; - case 0x0f: setchr1(0x0c00, EXPREGS[2] | (V >> 1) | 1); break; - case 0x10: - case 0x12: EXPREGS[2] = (V << 4); break; - case 0x11: setchr1(0x1000, EXPREGS[2] | (V >> 1)); break; - case 0x14: - case 0x16: EXPREGS[2] = (V << 4); break; - case 0x15: setchr1(0x1400, EXPREGS[2] | (V >> 1)); break; - case 0x18: - case 0x1a: EXPREGS[2] = (V << 4); break; - case 0x19: setchr1(0x1800, EXPREGS[2] | (V >> 1)); break; - case 0x1c: - case 0x1e: EXPREGS[2] = (V << 4); break; - case 0x1d: setchr1(0x1c00, EXPREGS[2] | (V >> 1)); break; - } - } - break; - } -} - -static void UNLA9746Power(void) { - GenMMC3Power(); - SetWriteHandler(0x8000, 0xbfff, UNLA9746Write); -} - -void UNLA9746_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 256, 0, 0); - info->Power = UNLA9746Power; - AddExState(EXPREGS, 6, 0, "EXPR"); -} - +/* 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLA9746Write) { +/* FCEU_printf("write raw %04x:%02x\n",A,V); */ + switch (A & 0xE003) { + case 0x8000: EXPREGS[1] = V; EXPREGS[0] = 0; break; + case 0x8002: EXPREGS[0] = V; EXPREGS[1] = 0; break; + case 0x8001: + { + uint8 bits_rev = ((V & 0x20) >> 5) | ((V & 0x10) >> 3) | ((V & 0x08) >> 1) | ((V & 0x04) << 1); + switch (EXPREGS[0]) { + case 0x26: setprg8(0x8000, bits_rev); break; + case 0x25: setprg8(0xA000, bits_rev); break; + case 0x24: setprg8(0xC000, bits_rev); break; + case 0x23: setprg8(0xE000, bits_rev); break; + } + switch (EXPREGS[1]) { + case 0x0a: + case 0x08: EXPREGS[2] = (V << 4); break; + case 0x09: setchr1(0x0000, EXPREGS[2] | (V >> 1)); break; + case 0x0b: setchr1(0x0400, EXPREGS[2] | (V >> 1) | 1); break; + case 0x0c: + case 0x0e: EXPREGS[2] = (V << 4); break; + case 0x0d: setchr1(0x0800, EXPREGS[2] | (V >> 1)); break; + case 0x0f: setchr1(0x0c00, EXPREGS[2] | (V >> 1) | 1); break; + case 0x10: + case 0x12: EXPREGS[2] = (V << 4); break; + case 0x11: setchr1(0x1000, EXPREGS[2] | (V >> 1)); break; + case 0x14: + case 0x16: EXPREGS[2] = (V << 4); break; + case 0x15: setchr1(0x1400, EXPREGS[2] | (V >> 1)); break; + case 0x18: + case 0x1a: EXPREGS[2] = (V << 4); break; + case 0x19: setchr1(0x1800, EXPREGS[2] | (V >> 1)); break; + case 0x1c: + case 0x1e: EXPREGS[2] = (V << 4); break; + case 0x1d: setchr1(0x1c00, EXPREGS[2] | (V >> 1)); break; + } + } + break; + } +} + +static void UNLA9746Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xbfff, UNLA9746Write); +} + +void UNLA9746_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = UNLA9746Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} + diff --git a/src/boards/ac-08.c b/src/boards/ac-08.c index 1507c8b..8dd16eb 100644 --- a/src/boards/ac-08.c +++ b/src/boards/ac-08.c @@ -1,71 +1,71 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg, mirr; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, reg); - setprg32r(1, 0x8000, 0); - setchr8(0); - setmirror(mirr); -} - -static DECLFW(AC08Mirr) { - mirr = ((V & 8) >> 3) ^ 1; - Sync(); -} - -static DECLFW(AC08Write) { - if (A == 0x8001) /* Green Berret bank switching is only 100x xxxx xxxx xxx1 mask */ - reg = (V >> 1) & 0xf; - else - reg = V & 0xf; /* Sad But True, 2-in-1 mapper, Green Berret need value shifted left one byte, Castlevania doesn't */ - Sync(); -} - -static void AC08Power(void) { - reg = 0; - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x4025, 0x4025, AC08Mirr); - SetWriteHandler(0x8000, 0xFFFF, AC08Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void AC08_Init(CartInfo *info) { - info->Power = AC08Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg32r(1, 0x8000, 0); + setchr8(0); + setmirror(mirr); +} + +static DECLFW(AC08Mirr) { + mirr = ((V & 8) >> 3) ^ 1; + Sync(); +} + +static DECLFW(AC08Write) { + if (A == 0x8001) /* Green Berret bank switching is only 100x xxxx xxxx xxx1 mask */ + reg = (V >> 1) & 0xf; + else + reg = V & 0xf; /* Sad But True, 2-in-1 mapper, Green Berret need value shifted left one byte, Castlevania doesn't */ + Sync(); +} + +static void AC08Power(void) { + reg = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x4025, 0x4025, AC08Mirr); + SetWriteHandler(0x8000, 0xFFFF, AC08Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void AC08_Init(CartInfo *info) { + info->Power = AC08Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/addrlatch.c b/src/boards/addrlatch.c index 6c752f2..b9efe6d 100644 --- a/src/boards/addrlatch.c +++ b/src/boards/addrlatch.c @@ -1,508 +1,508 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - */ - -#include "mapinc.h" - -static uint16 latche, latcheinit; -static uint16 addrreg0, addrreg1; -static uint8 dipswitch; -static void (*WSync)(void); -static readfunc defread; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static DECLFW(LatchWrite) { - latche = A; - WSync(); -} - -static void LatchReset(void) { - latche = latcheinit; - WSync(); -} - -static void LatchPower(void) { - latche = latcheinit; - WSync(); - if (WRAM) { - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - } else - SetReadHandler(0x6000, 0xFFFF, defread); - SetWriteHandler(addrreg0, addrreg1, LatchWrite); -} - -static void LatchClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - WSync(); -} - -static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 linit, uint16 adr0, uint16 adr1, uint8 wram) { - latcheinit = linit; - addrreg0 = adr0; - addrreg1 = adr1; - WSync = proc; - if (func != NULL) - defread = func; - else - defread = CartBROB; - info->Power = LatchPower; - info->Reset = LatchReset; - info->Close = LatchClose; - if (wram) { - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - } - GameStateRestore = StateRestore; - AddExState(&latche, 2, 0, "LATC"); -} - -/*------------------ BMCD1038 ---------------------------*/ - -static void BMCD1038Sync(void) { - if (latche & 0x80) { - setprg16(0x8000, (latche & 0x70) >> 4); - setprg16(0xC000, (latche & 0x70) >> 4); - } else - setprg32(0x8000, (latche & 0x60) >> 5); - setchr8(latche & 7); - setmirror(((latche & 8) >> 3) ^ 1); -} - -static DECLFR(BMCD1038Read) { - if (latche & 0x100) - return dipswitch; - else - return CartBR(A); -} - -static void BMCD1038Reset(void) { - dipswitch++; - dipswitch &= 3; -} - -void BMCD1038_Init(CartInfo *info) { - Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0x0000, 0x8000, 0xFFFF, 0); - info->Reset = BMCD1038Reset; - AddExState(&dipswitch, 1, 0, "DIPSW"); -} - -/*------------------ UNL43272 ---------------------------*/ -/* mapper much complex, including 16K bankswitching */ -static void UNL43272Sync(void) { - if ((latche & 0x81) == 0x81) { - setprg32(0x8000, (latche & 0x38) >> 3); - } else - FCEU_printf("unrecognized command %04!\n", latche); - setchr8(0); - setmirror(0); -} - -static DECLFR(UNL43272Read) { - if (latche & 0x400) - return CartBR(A & 0xFE); - else - return CartBR(A); -} - -static void UNL43272Reset(void) { - latche = 0; - UNL43272Sync(); -} - -void UNL43272_Init(CartInfo *info) { - Latch_Init(info, UNL43272Sync, UNL43272Read, 0x0081, 0x8000, 0xFFFF, 0); - info->Reset = UNL43272Reset; - AddExState(&dipswitch, 1, 0, "DIPSW"); -} - -/*------------------ Map 058 ---------------------------*/ - -static void BMCGK192Sync(void) { - if (latche & 0x40) { - setprg16(0x8000, latche & 7); - setprg16(0xC000, latche & 7); - } else - setprg32(0x8000, (latche >> 1) & 3); - setchr8((latche >> 3) & 7); - setmirror(((latche & 0x80) >> 7) ^ 1); -} - -void BMCGK192_Init(CartInfo *info) { - Latch_Init(info, BMCGK192Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 059 ---------------------------*/ -/* One more forgotten mapper */ -static void M59Sync(void) { - setprg32(0x8000, (latche >> 4) & 7); - setchr8(latche & 0x7); - setmirror((latche >> 3) & 1); -} - -static DECLFR(M59Read) { - if (latche & 0x100) - return 0; - else - return CartBR(A); -} - -void Mapper59_Init(CartInfo *info) { - Latch_Init(info, M59Sync, M59Read, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 061 ---------------------------*/ -static void M61Sync(void) { - if (((latche & 0x10) << 1) ^ (latche & 0x20)) { - setprg16(0x8000, ((latche & 0xF) << 1) | (((latche & 0x20) >> 4))); - setprg16(0xC000, ((latche & 0xF) << 1) | (((latche & 0x20) >> 4))); - } else - setprg32(0x8000, latche & 0xF); - setchr8(0); - setmirror(((latche >> 7) & 1) ^ 1); -} - -void Mapper61_Init(CartInfo *info) { - Latch_Init(info, M61Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 092 ---------------------------*/ -/* Another two-in-one mapper, two Jaleco carts uses similar - * hardware, but with different wiring. - * Original code provided by LULU - * Additionally, PCB contains DSP extra sound chip, used for voice samples (unemulated) - */ - -static void M92Sync(void) { - uint8 reg = latche & 0xF0; - setprg16(0x8000, 0); - if (latche >= 0x9000) { - switch (reg) { - case 0xD0: setprg16(0xc000, latche & 15); break; - case 0xE0: setchr8(latche & 15); break; - } - } else { - switch (reg) { - case 0xB0: setprg16(0xc000, latche & 15); break; - case 0x70: setchr8(latche & 15); break; - } - } -} - -void Mapper92_Init(CartInfo *info) { - Latch_Init(info, M92Sync, NULL, 0x80B0, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 200 ---------------------------*/ - -static void M200Sync(void) { - setprg16(0x8000, latche & 7); - setprg16(0xC000, latche & 7); - setchr8(latche & 7); - setmirror((latche & 8) >> 3); -} - -void Mapper200_Init(CartInfo *info) { - Latch_Init(info, M200Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 201 ---------------------------*/ - -static void M201Sync(void) { - if (latche & 8) { - setprg32(0x8000, latche & 3); - setchr8(latche & 3); - } else { - setprg32(0x8000, 0); - setchr8(0); - } -} - -void Mapper201_Init(CartInfo *info) { - Latch_Init(info, M201Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 202 ---------------------------*/ - -static void M202Sync(void) { - /* According to more carefull hardware tests and PCB study */ - int32 mirror = latche & 1; - int32 bank = (latche >> 1) & 0x7; - int32 select = (mirror & (bank >> 2)); - setprg16(0x8000, select ? (bank & 6) | 0 : bank); - setprg16(0xc000, select ? (bank & 6) | 1 : bank); - setmirror(mirror ^ 1); - setchr8(bank); -} - -void Mapper202_Init(CartInfo *info) { - Latch_Init(info, M202Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 204 ---------------------------*/ - -static void M204Sync(void) { - int32 tmp2 = latche & 0x6; - int32 tmp1 = tmp2 + ((tmp2 == 0x6) ? 0 : (latche & 1)); - setprg16(0x8000, tmp1); - setprg16(0xc000, tmp2 + ((tmp2 == 0x6) ? 1 : (latche & 1))); - setchr8(tmp1); - setmirror(((latche >> 4) & 1) ^ 1); -} - -void Mapper204_Init(CartInfo *info) { - Latch_Init(info, M204Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 212 ---------------------------*/ - -static DECLFR(M212Read) { - uint8 ret = CartBROB(A); - if ((A & 0xE010) == 0x6000) - ret |= 0x80; - return ret; -} - -static void M212Sync(void) { - if (latche & 0x4000) { - setprg32(0x8000, (latche >> 1) & 3); - } else { - setprg16(0x8000, latche & 7); - setprg16(0xC000, latche & 7); - } - setchr8(latche & 7); - setmirror(((latche >> 3) & 1) ^ 1); -} - -void Mapper212_Init(CartInfo *info) { - Latch_Init(info, M212Sync, M212Read, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 213 ---------------------------*/ - -static void M213Sync(void) { - setprg32(0x8000, (latche >> 1) & 3); - setchr8((latche >> 3) & 7); -} - -void Mapper213_Init(CartInfo *info) { - Latch_Init(info, M213Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 214 ---------------------------*/ - -static void M214Sync(void) { - setprg16(0x8000, (latche >> 2) & 3); - setprg16(0xC000, (latche >> 2) & 3); - setchr8(latche & 3); -} - -void Mapper214_Init(CartInfo *info) { - Latch_Init(info, M214Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 217 ---------------------------*/ - -static void M217Sync(void) { - setprg32(0x8000, (latche >> 2) & 3); - setchr8(latche & 7); -} - -void Mapper217_Init(CartInfo *info) { - Latch_Init(info, M217Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 227 ---------------------------*/ - -static void M227Sync(void) { - uint32 S = latche & 1; - uint32 p = ((latche >> 2) & 0x1F) + ((latche & 0x100) >> 3); - uint32 L = (latche >> 9) & 1; - - if ((latche >> 7) & 1) { - if (S) { - setprg32(0x8000, p >> 1); - } else { - setprg16(0x8000, p); - setprg16(0xC000, p); - } - } else { - if (S) { - if (L) { - setprg16(0x8000, p & 0x3E); - setprg16(0xC000, p | 7); - } else { - setprg16(0x8000, p & 0x3E); - setprg16(0xC000, p & 0x38); - } - } else { - if (L) { - setprg16(0x8000, p); - setprg16(0xC000, p | 7); - } else { - setprg16(0x8000, p); - setprg16(0xC000, p & 0x38); - } - } - } - - setmirror(((latche >> 1) & 1) ^ 1); - setchr8(0); - setprg8r(0x10, 0x6000, 0); -} - -void Mapper227_Init(CartInfo *info) { - Latch_Init(info, M227Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); -} - -/*------------------ Map 229 ---------------------------*/ - -static void M229Sync(void) { - setchr8(latche); - if (!(latche & 0x1e)) - setprg32(0x8000, 0); - else { - setprg16(0x8000, latche & 0x1F); - setprg16(0xC000, latche & 0x1F); - } - setmirror(((latche >> 5) & 1) ^ 1); -} - -void Mapper229_Init(CartInfo *info) { - Latch_Init(info, M229Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 231 ---------------------------*/ - -static void M231Sync(void) { - setchr8(0); - if (latche & 0x20) - setprg32(0x8000, (latche >> 1) & 0x0F); - else { - setprg16(0x8000, latche & 0x1E); - setprg16(0xC000, latche & 0x1E); - } - setmirror(((latche >> 7) & 1) ^ 1); -} - -void Mapper231_Init(CartInfo *info) { - Latch_Init(info, M231Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*------------------ Map 242 ---------------------------*/ - -static void M242Sync(void) { - setchr8(0); - setprg8r(0x10, 0x6000, 0); - setprg32(0x8000, (latche >> 3) & 0xf); - setmirror(((latche >> 1) & 1) ^ 1); -} - -void Mapper242_Init(CartInfo *info) { - Latch_Init(info, M242Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); -} - -/*------------------ 190in1 ---------------------------*/ - -static void BMC190in1Sync(void) { - setprg16(0x8000, (latche >> 2) & 7); - setprg16(0xC000, (latche >> 2) & 7); - setchr8((latche >> 2) & 7); - setmirror((latche & 1) ^ 1); -} - -void BMC190in1_Init(CartInfo *info) { - Latch_Init(info, BMC190in1Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*-------------- BMC810544-C-A1 ------------------------*/ - -static void BMC810544CA1Sync(void) { - uint32 bank = latche >> 7; - if (latche & 0x40) - setprg32(0x8000, bank); - else { - setprg16(0x8000, (bank << 1) | ((latche >> 5) & 1)); - setprg16(0xC000, (bank << 1) | ((latche >> 5) & 1)); - } - setchr8(latche & 0x0f); - setmirror(((latche >> 4) & 1) ^ 1); -} - -void BMC810544CA1_Init(CartInfo *info) { - Latch_Init(info, BMC810544CA1Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*-------------- BMCNTD-03 ------------------------*/ - -static void BMCNTD03Sync(void) { - /* 1PPP Pmcc spxx xccc - * 1000 0000 0000 0000 v - * 1001 1100 0000 0100 h - * 1011 1010 1100 0100 - */ - uint32 prg = ((latche >> 10) & 0x1e); - uint32 chr = ((latche & 0x0300) >> 5) | (latche & 7); - if (latche & 0x80) { - setprg16(0x8000, prg | ((latche >> 6) & 1)); - setprg16(0xC000, prg | ((latche >> 6) & 1)); - } else - setprg32(0x8000, prg >> 1); - setchr8(chr); - setmirror(((latche >> 10) & 1) ^ 1); -} - -void BMCNTD03_Init(CartInfo *info) { - Latch_Init(info, BMCNTD03Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} - -/*-------------- BMCG-146 ------------------------*/ - -static void BMCG146Sync(void) { - setchr8(0); - if (latche & 0x800) { /* UNROM mode */ - setprg16(0x8000, (latche & 0x1F) | (latche & ((latche & 0x40) >> 6))); - setprg16(0xC000, (latche & 0x18) | 7); - } else { - if (latche & 0x40) { /* 16K mode */ - setprg16(0x8000, latche & 0x1F); - setprg16(0xC000, latche & 0x1F); - } else { - setprg32(0x8000, (latche >> 1) & 0x0F); - } - } - setmirror(((latche & 0x80) >> 7) ^ 1); -} - -void BMCG146_Init(CartInfo *info) { - Latch_Init(info, BMCG146Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + */ + +#include "mapinc.h" + +static uint16 latche, latcheinit; +static uint16 addrreg0, addrreg1; +static uint8 dipswitch; +static void (*WSync)(void); +static readfunc defread; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static DECLFW(LatchWrite) { + latche = A; + WSync(); +} + +static void LatchReset(void) { + latche = latcheinit; + WSync(); +} + +static void LatchPower(void) { + latche = latcheinit; + WSync(); + if (WRAM) { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + } else + SetReadHandler(0x6000, 0xFFFF, defread); + SetWriteHandler(addrreg0, addrreg1, LatchWrite); +} + +static void LatchClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 linit, uint16 adr0, uint16 adr1, uint8 wram) { + latcheinit = linit; + addrreg0 = adr0; + addrreg1 = adr1; + WSync = proc; + if (func != NULL) + defread = func; + else + defread = CartBROB; + info->Power = LatchPower; + info->Reset = LatchReset; + info->Close = LatchClose; + if (wram) { + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + GameStateRestore = StateRestore; + AddExState(&latche, 2, 0, "LATC"); +} + +/*------------------ BMCD1038 ---------------------------*/ + +static void BMCD1038Sync(void) { + if (latche & 0x80) { + setprg16(0x8000, (latche & 0x70) >> 4); + setprg16(0xC000, (latche & 0x70) >> 4); + } else + setprg32(0x8000, (latche & 0x60) >> 5); + setchr8(latche & 7); + setmirror(((latche & 8) >> 3) ^ 1); +} + +static DECLFR(BMCD1038Read) { + if (latche & 0x100) + return dipswitch; + else + return CartBR(A); +} + +static void BMCD1038Reset(void) { + dipswitch++; + dipswitch &= 3; +} + +void BMCD1038_Init(CartInfo *info) { + Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0x0000, 0x8000, 0xFFFF, 0); + info->Reset = BMCD1038Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + +/*------------------ UNL43272 ---------------------------*/ +/* mapper much complex, including 16K bankswitching */ +static void UNL43272Sync(void) { + if ((latche & 0x81) == 0x81) { + setprg32(0x8000, (latche & 0x38) >> 3); + } else + FCEU_printf("unrecognized command %04!\n", latche); + setchr8(0); + setmirror(0); +} + +static DECLFR(UNL43272Read) { + if (latche & 0x400) + return CartBR(A & 0xFE); + else + return CartBR(A); +} + +static void UNL43272Reset(void) { + latche = 0; + UNL43272Sync(); +} + +void UNL43272_Init(CartInfo *info) { + Latch_Init(info, UNL43272Sync, UNL43272Read, 0x0081, 0x8000, 0xFFFF, 0); + info->Reset = UNL43272Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + +/*------------------ Map 058 ---------------------------*/ + +static void BMCGK192Sync(void) { + if (latche & 0x40) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, latche & 7); + } else + setprg32(0x8000, (latche >> 1) & 3); + setchr8((latche >> 3) & 7); + setmirror(((latche & 0x80) >> 7) ^ 1); +} + +void BMCGK192_Init(CartInfo *info) { + Latch_Init(info, BMCGK192Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 059 ---------------------------*/ +/* One more forgotten mapper */ +static void M59Sync(void) { + setprg32(0x8000, (latche >> 4) & 7); + setchr8(latche & 0x7); + setmirror((latche >> 3) & 1); +} + +static DECLFR(M59Read) { + if (latche & 0x100) + return 0; + else + return CartBR(A); +} + +void Mapper59_Init(CartInfo *info) { + Latch_Init(info, M59Sync, M59Read, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 061 ---------------------------*/ +static void M61Sync(void) { + if (((latche & 0x10) << 1) ^ (latche & 0x20)) { + setprg16(0x8000, ((latche & 0xF) << 1) | (((latche & 0x20) >> 4))); + setprg16(0xC000, ((latche & 0xF) << 1) | (((latche & 0x20) >> 4))); + } else + setprg32(0x8000, latche & 0xF); + setchr8(0); + setmirror(((latche >> 7) & 1) ^ 1); +} + +void Mapper61_Init(CartInfo *info) { + Latch_Init(info, M61Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 092 ---------------------------*/ +/* Another two-in-one mapper, two Jaleco carts uses similar + * hardware, but with different wiring. + * Original code provided by LULU + * Additionally, PCB contains DSP extra sound chip, used for voice samples (unemulated) + */ + +static void M92Sync(void) { + uint8 reg = latche & 0xF0; + setprg16(0x8000, 0); + if (latche >= 0x9000) { + switch (reg) { + case 0xD0: setprg16(0xc000, latche & 15); break; + case 0xE0: setchr8(latche & 15); break; + } + } else { + switch (reg) { + case 0xB0: setprg16(0xc000, latche & 15); break; + case 0x70: setchr8(latche & 15); break; + } + } +} + +void Mapper92_Init(CartInfo *info) { + Latch_Init(info, M92Sync, NULL, 0x80B0, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 200 ---------------------------*/ + +static void M200Sync(void) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, latche & 7); + setchr8(latche & 7); + setmirror((latche & 8) >> 3); +} + +void Mapper200_Init(CartInfo *info) { + Latch_Init(info, M200Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 201 ---------------------------*/ + +static void M201Sync(void) { + if (latche & 8) { + setprg32(0x8000, latche & 3); + setchr8(latche & 3); + } else { + setprg32(0x8000, 0); + setchr8(0); + } +} + +void Mapper201_Init(CartInfo *info) { + Latch_Init(info, M201Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 202 ---------------------------*/ + +static void M202Sync(void) { + /* According to more carefull hardware tests and PCB study */ + int32 mirror = latche & 1; + int32 bank = (latche >> 1) & 0x7; + int32 select = (mirror & (bank >> 2)); + setprg16(0x8000, select ? (bank & 6) | 0 : bank); + setprg16(0xc000, select ? (bank & 6) | 1 : bank); + setmirror(mirror ^ 1); + setchr8(bank); +} + +void Mapper202_Init(CartInfo *info) { + Latch_Init(info, M202Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 204 ---------------------------*/ + +static void M204Sync(void) { + int32 tmp2 = latche & 0x6; + int32 tmp1 = tmp2 + ((tmp2 == 0x6) ? 0 : (latche & 1)); + setprg16(0x8000, tmp1); + setprg16(0xc000, tmp2 + ((tmp2 == 0x6) ? 1 : (latche & 1))); + setchr8(tmp1); + setmirror(((latche >> 4) & 1) ^ 1); +} + +void Mapper204_Init(CartInfo *info) { + Latch_Init(info, M204Sync, NULL, 0xFFFF, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 212 ---------------------------*/ + +static DECLFR(M212Read) { + uint8 ret = CartBROB(A); + if ((A & 0xE010) == 0x6000) + ret |= 0x80; + return ret; +} + +static void M212Sync(void) { + if (latche & 0x4000) { + setprg32(0x8000, (latche >> 1) & 3); + } else { + setprg16(0x8000, latche & 7); + setprg16(0xC000, latche & 7); + } + setchr8(latche & 7); + setmirror(((latche >> 3) & 1) ^ 1); +} + +void Mapper212_Init(CartInfo *info) { + Latch_Init(info, M212Sync, M212Read, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 213 ---------------------------*/ + +static void M213Sync(void) { + setprg32(0x8000, (latche >> 1) & 3); + setchr8((latche >> 3) & 7); +} + +void Mapper213_Init(CartInfo *info) { + Latch_Init(info, M213Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 214 ---------------------------*/ + +static void M214Sync(void) { + setprg16(0x8000, (latche >> 2) & 3); + setprg16(0xC000, (latche >> 2) & 3); + setchr8(latche & 3); +} + +void Mapper214_Init(CartInfo *info) { + Latch_Init(info, M214Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 217 ---------------------------*/ + +static void M217Sync(void) { + setprg32(0x8000, (latche >> 2) & 3); + setchr8(latche & 7); +} + +void Mapper217_Init(CartInfo *info) { + Latch_Init(info, M217Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 227 ---------------------------*/ + +static void M227Sync(void) { + uint32 S = latche & 1; + uint32 p = ((latche >> 2) & 0x1F) + ((latche & 0x100) >> 3); + uint32 L = (latche >> 9) & 1; + + if ((latche >> 7) & 1) { + if (S) { + setprg32(0x8000, p >> 1); + } else { + setprg16(0x8000, p); + setprg16(0xC000, p); + } + } else { + if (S) { + if (L) { + setprg16(0x8000, p & 0x3E); + setprg16(0xC000, p | 7); + } else { + setprg16(0x8000, p & 0x3E); + setprg16(0xC000, p & 0x38); + } + } else { + if (L) { + setprg16(0x8000, p); + setprg16(0xC000, p | 7); + } else { + setprg16(0x8000, p); + setprg16(0xC000, p & 0x38); + } + } + } + + setmirror(((latche >> 1) & 1) ^ 1); + setchr8(0); + setprg8r(0x10, 0x6000, 0); +} + +void Mapper227_Init(CartInfo *info) { + Latch_Init(info, M227Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); +} + +/*------------------ Map 229 ---------------------------*/ + +static void M229Sync(void) { + setchr8(latche); + if (!(latche & 0x1e)) + setprg32(0x8000, 0); + else { + setprg16(0x8000, latche & 0x1F); + setprg16(0xC000, latche & 0x1F); + } + setmirror(((latche >> 5) & 1) ^ 1); +} + +void Mapper229_Init(CartInfo *info) { + Latch_Init(info, M229Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 231 ---------------------------*/ + +static void M231Sync(void) { + setchr8(0); + if (latche & 0x20) + setprg32(0x8000, (latche >> 1) & 0x0F); + else { + setprg16(0x8000, latche & 0x1E); + setprg16(0xC000, latche & 0x1E); + } + setmirror(((latche >> 7) & 1) ^ 1); +} + +void Mapper231_Init(CartInfo *info) { + Latch_Init(info, M231Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*------------------ Map 242 ---------------------------*/ + +static void M242Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, (latche >> 3) & 0xf); + setmirror(((latche >> 1) & 1) ^ 1); +} + +void Mapper242_Init(CartInfo *info) { + Latch_Init(info, M242Sync, NULL, 0x0000, 0x8000, 0xFFFF, 1); +} + +/*------------------ 190in1 ---------------------------*/ + +static void BMC190in1Sync(void) { + setprg16(0x8000, (latche >> 2) & 7); + setprg16(0xC000, (latche >> 2) & 7); + setchr8((latche >> 2) & 7); + setmirror((latche & 1) ^ 1); +} + +void BMC190in1_Init(CartInfo *info) { + Latch_Init(info, BMC190in1Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*-------------- BMC810544-C-A1 ------------------------*/ + +static void BMC810544CA1Sync(void) { + uint32 bank = latche >> 7; + if (latche & 0x40) + setprg32(0x8000, bank); + else { + setprg16(0x8000, (bank << 1) | ((latche >> 5) & 1)); + setprg16(0xC000, (bank << 1) | ((latche >> 5) & 1)); + } + setchr8(latche & 0x0f); + setmirror(((latche >> 4) & 1) ^ 1); +} + +void BMC810544CA1_Init(CartInfo *info) { + Latch_Init(info, BMC810544CA1Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*-------------- BMCNTD-03 ------------------------*/ + +static void BMCNTD03Sync(void) { + /* 1PPP Pmcc spxx xccc + * 1000 0000 0000 0000 v + * 1001 1100 0000 0100 h + * 1011 1010 1100 0100 + */ + uint32 prg = ((latche >> 10) & 0x1e); + uint32 chr = ((latche & 0x0300) >> 5) | (latche & 7); + if (latche & 0x80) { + setprg16(0x8000, prg | ((latche >> 6) & 1)); + setprg16(0xC000, prg | ((latche >> 6) & 1)); + } else + setprg32(0x8000, prg >> 1); + setchr8(chr); + setmirror(((latche >> 10) & 1) ^ 1); +} + +void BMCNTD03_Init(CartInfo *info) { + Latch_Init(info, BMCNTD03Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} + +/*-------------- BMCG-146 ------------------------*/ + +static void BMCG146Sync(void) { + setchr8(0); + if (latche & 0x800) { /* UNROM mode */ + setprg16(0x8000, (latche & 0x1F) | (latche & ((latche & 0x40) >> 6))); + setprg16(0xC000, (latche & 0x18) | 7); + } else { + if (latche & 0x40) { /* 16K mode */ + setprg16(0x8000, latche & 0x1F); + setprg16(0xC000, latche & 0x1F); + } else { + setprg32(0x8000, (latche >> 1) & 0x0F); + } + } + setmirror(((latche & 0x80) >> 7) ^ 1); +} + +void BMCG146_Init(CartInfo *info) { + Latch_Init(info, BMCG146Sync, NULL, 0x0000, 0x8000, 0xFFFF, 0); +} diff --git a/src/boards/ax5705.c b/src/boards/ax5705.c index d208278..d2f98f6 100644 --- a/src/boards/ax5705.c +++ b/src/boards/ax5705.c @@ -1,116 +1,116 @@ -/* 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 - * - * Super Bros. Pocker Mali (VRC4 mapper) - */ - -#include "mapinc.h" - -static uint8 IRQCount; /*, IRQPre; */ -static uint8 IRQa; -static uint8 prg_reg[2]; -static uint8 chr_reg[8]; -static uint8 mirr; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 1, "IRQC" }, - { &IRQa, 1, "IRQA" }, - { prg_reg, 2, "PRG" }, - { chr_reg, 8, "CHR" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -#if 0 -static void UNLAX5705IRQ(void) { - if(IRQa) { - IRQCount++; - if(IRQCount>=238) { - X6502_IRQBegin(FCEU_IQEXT); -/* IRQa=0; */ - } - } -} -#endif - -static void Sync(void) { - int i; - setprg8(0x8000, prg_reg[0]); - setprg8(0xA000, prg_reg[1]); - setprg8(0xC000, ~1); - setprg8(0xE000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, chr_reg[i]); - setmirror(mirr ^ 1); -} - -static DECLFW(UNLAX5705Write) { -#if 0 - if((A>=0xA008)&&(A<=0xE003)) { - int ind=(((A>>11)-6)|(A&1))&7; - int sar=((A&2)<<1); - chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<> 2) | (V & 5); break; /* EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed */ - case 0x8008: mirr = V & 1; break; - case 0xA000: prg_reg[1] = ((V & 2) << 2) | ((V & 8) >> 2) | (V & 5); break; - case 0xA008: chr_reg[0] = (chr_reg[0] & 0xF0) | (V & 0x0F); break; - case 0xA009: chr_reg[0] = (chr_reg[0] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xA00A: chr_reg[1] = (chr_reg[1] & 0xF0) | (V & 0x0F); break; - case 0xA00B: chr_reg[1] = (chr_reg[1] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xC000: chr_reg[2] = (chr_reg[2] & 0xF0) | (V & 0x0F); break; - case 0xC001: chr_reg[2] = (chr_reg[2] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xC002: chr_reg[3] = (chr_reg[3] & 0xF0) | (V & 0x0F); break; - case 0xC003: chr_reg[3] = (chr_reg[3] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xC008: chr_reg[4] = (chr_reg[4] & 0xF0) | (V & 0x0F); break; - case 0xC009: chr_reg[4] = (chr_reg[4] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xC00A: chr_reg[5] = (chr_reg[5] & 0xF0) | (V & 0x0F); break; - case 0xC00B: chr_reg[5] = (chr_reg[5] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xE000: chr_reg[6] = (chr_reg[6] & 0xF0) | (V & 0x0F); break; - case 0xE001: chr_reg[6] = (chr_reg[6] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; - case 0xE002: chr_reg[7] = (chr_reg[7] & 0xF0) | (V & 0x0F); break; - case 0xE003: chr_reg[7] = (chr_reg[7] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; -#if 0 - case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; - case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/ break; -#endif - } - Sync(); -} - -static void UNLAX5705Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLAX5705Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLAX5705_Init(CartInfo *info) { - info->Power = UNLAX5705Power; -/* GameHBIRQHook=UNLAX5705IRQ; */ - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * Super Bros. Pocker Mali (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 IRQCount; /*, IRQPre; */ +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { prg_reg, 2, "PRG" }, + { chr_reg, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +#if 0 +static void UNLAX5705IRQ(void) { + if(IRQa) { + IRQCount++; + if(IRQCount>=238) { + X6502_IRQBegin(FCEU_IQEXT); +/* IRQa=0; */ + } + } +} +#endif + +static void Sync(void) { + int i; + setprg8(0x8000, prg_reg[0]); + setprg8(0xA000, prg_reg[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr_reg[i]); + setmirror(mirr ^ 1); +} + +static DECLFW(UNLAX5705Write) { +#if 0 + if((A>=0xA008)&&(A<=0xE003)) { + int ind=(((A>>11)-6)|(A&1))&7; + int sar=((A&2)<<1); + chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<> 2) | (V & 5); break; /* EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed */ + case 0x8008: mirr = V & 1; break; + case 0xA000: prg_reg[1] = ((V & 2) << 2) | ((V & 8) >> 2) | (V & 5); break; + case 0xA008: chr_reg[0] = (chr_reg[0] & 0xF0) | (V & 0x0F); break; + case 0xA009: chr_reg[0] = (chr_reg[0] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xA00A: chr_reg[1] = (chr_reg[1] & 0xF0) | (V & 0x0F); break; + case 0xA00B: chr_reg[1] = (chr_reg[1] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC000: chr_reg[2] = (chr_reg[2] & 0xF0) | (V & 0x0F); break; + case 0xC001: chr_reg[2] = (chr_reg[2] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC002: chr_reg[3] = (chr_reg[3] & 0xF0) | (V & 0x0F); break; + case 0xC003: chr_reg[3] = (chr_reg[3] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC008: chr_reg[4] = (chr_reg[4] & 0xF0) | (V & 0x0F); break; + case 0xC009: chr_reg[4] = (chr_reg[4] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xC00A: chr_reg[5] = (chr_reg[5] & 0xF0) | (V & 0x0F); break; + case 0xC00B: chr_reg[5] = (chr_reg[5] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xE000: chr_reg[6] = (chr_reg[6] & 0xF0) | (V & 0x0F); break; + case 0xE001: chr_reg[6] = (chr_reg[6] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; + case 0xE002: chr_reg[7] = (chr_reg[7] & 0xF0) | (V & 0x0F); break; + case 0xE003: chr_reg[7] = (chr_reg[7] & 0x0F) | ((((V & 4) >> 1) | ((V & 2) << 1) | (V & 0x09)) << 4); break; +#if 0 + case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; + case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/ break; +#endif + } + Sync(); +} + +static void UNLAX5705Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLAX5705Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLAX5705_Init(CartInfo *info) { + info->Power = UNLAX5705Power; +/* GameHBIRQHook=UNLAX5705IRQ; */ + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bandai.c b/src/boards/bandai.c index 79adbd7..9d3ca99 100644 --- a/src/boards/bandai.c +++ b/src/boards/bandai.c @@ -1,464 +1,464 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2007 CaH4e3 - * Copyright (C) 2011 FCEUX 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 - * - * Bandai mappers - * - */ - -#include "mapinc.h" - -static uint8 reg[16], is153, x24c02; -static uint8 IRQa; -static int16 IRQCount, IRQLatch; - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { reg, 16, "REGS" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 2, "IRQC" }, - { &IRQLatch, 2, "IRQL" }, /* need for Famicom Jump II - Saikyou no 7 Nin (J) [!] */ - { 0 } -}; - -/* x24C0x interface */ - -#define X24C0X_STANDBY 0 -#define X24C0X_ADDRESS 1 -#define X24C0X_WORD 2 -#define X24C0X_READ 3 -#define X24C0X_WRITE 4 - -static uint8 x24c0x_data[256], x24c0x_state; -static uint8 x24c0x_addr, x24c0x_word, x24c0x_latch, x24c0x_bitcount; -static uint8 x24c0x_sda, x24c0x_scl, x24c0x_out, x24c0x_oe; - -static SFORMAT x24c0xStateRegs[] = -{ - { &x24c0x_addr, 1, "ADDR" }, - { &x24c0x_word, 1, "WORD" }, - { &x24c0x_latch, 1, "LATC" }, - { &x24c0x_bitcount, 1, "BITC" }, - { &x24c0x_sda, 1, "SDA" }, - { &x24c0x_scl, 1, "SCL" }, - { &x24c0x_out, 1, "OUT" }, - { &x24c0x_oe, 1, "OE" }, - { &x24c0x_state, 1, "STAT" }, - { 0 } -}; - -static void x24c0x_init() { - x24c0x_addr = x24c0x_word = x24c0x_latch = x24c0x_bitcount = x24c0x_sda = x24c0x_scl = x24c0x_oe = 0; - x24c0x_state = X24C0X_STANDBY; -} - -static void x24c0x_write(uint8 data) { - uint8 sda = (data >> 6) & 1; - uint8 scl = (data >> 5) & 1; - x24c0x_oe = (data >> 7); - - if(x24c0x_scl && scl) { - if(x24c0x_sda && !sda) { /* START */ - x24c0x_state = X24C0X_ADDRESS; - x24c0x_bitcount = 0; - x24c0x_addr = 0; - } else if(!x24c0x_sda && sda) { /* STOP */ - x24c0x_state = X24C0X_STANDBY; - } - } else if(!x24c0x_scl && scl) { /* RISING EDGE */ - switch(x24c0x_state) { - case X24C0X_ADDRESS: - if(x24c0x_bitcount < 7) { - x24c0x_addr <<= 1; - x24c0x_addr |= sda; - } else { - if(!x24c02) /* X24C01 mode */ - x24c0x_word = x24c0x_addr; - if(sda) { /* READ COMMAND */ - x24c0x_state = X24C0X_READ; - } else { /* WRITE COMMAND */ - if(x24c02) /* X24C02 mode */ - x24c0x_state = X24C0X_WORD; - else - x24c0x_state = X24C0X_WRITE; - } - } - x24c0x_bitcount++; - break; - case X24C0X_WORD: - if(x24c0x_bitcount == 8) { /* ACK */ - x24c0x_word = 0; - x24c0x_out = 0; - } else { /* WORD ADDRESS INPUT */ - x24c0x_word <<= 1; - x24c0x_word |= sda; - if(x24c0x_bitcount == 16) { /* END OF ADDRESS INPUT */ - x24c0x_bitcount = 7; - x24c0x_state = X24C0X_WRITE; - } - } - x24c0x_bitcount++; - break; - case X24C0X_READ: - if (x24c0x_bitcount == 8) { /* ACK */ - x24c0x_out = 0; - x24c0x_latch = x24c0x_data[x24c0x_word]; - x24c0x_bitcount = 0; - } else { /* REAL OUTPUT */ - x24c0x_out = x24c0x_latch >> 7; - x24c0x_latch <<= 1; - x24c0x_bitcount++; - if(x24c0x_bitcount == 8) { - x24c0x_word++; - x24c0x_word &= 0xff; - } - } - break; - case X24C0X_WRITE: - if (x24c0x_bitcount == 8) { /* ACK */ - x24c0x_out = 0; - x24c0x_latch = 0; - x24c0x_bitcount = 0; - } else { /* REAL INPUT */ - x24c0x_latch <<= 1; - x24c0x_latch |= sda; - x24c0x_bitcount++; - if(x24c0x_bitcount == 8) { - x24c0x_data[x24c0x_word] = x24c0x_latch; - x24c0x_word++; - x24c0x_word &= 0xff; - } - } - break; - } - } - - x24c0x_sda = sda; - x24c0x_scl = scl; -} - -static uint8 x24c0x_read() { - return x24c0x_out << 4; -} - -static void Sync(void) { - if (is153) { - int base = (reg[0] & 1) << 4; - setchr8(0); - setprg16(0x8000, (reg[8] & 0x0F) | base); - setprg16(0xC000, 0x0F | base); - } else { - int i; - for (i = 0; i < 8; i++) setchr1(i << 10, reg[i]); - setprg16(0x8000, reg[8]); - setprg16(0xC000, ~0); - } - switch (reg[9] & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(BandaiWrite) { - A &= 0x0F; - if (A < 0x0A) { - reg[A & 0x0F] = V; - Sync(); - } else - switch (A) { - case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa = V & 1; IRQCount = IRQLatch; break; - case 0x0B: IRQLatch &= 0xFF00; IRQLatch |= V; break; - case 0x0C: IRQLatch &= 0xFF; IRQLatch |= V << 8; break; - case 0x0D: x24c0x_write(V); break; - } -} - -static DECLFR(BandaiRead) { - return (X.DB & 0xEF) | x24c0x_read(); -} - -static void FP_FASTAPASS(1) BandaiIRQHook(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount < 0) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - IRQCount = -1; - } - } -} - -static void BandaiPower(void) { - IRQa = 0; - x24c0x_init(); - Sync(); - SetReadHandler(0x6000, 0x7FFF, BandaiRead); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0xFFFF, BandaiWrite); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper16_Init(CartInfo *info) { - x24c02 = 1; - is153 = 0; - info->Power = BandaiPower; - MapIRQHook = BandaiIRQHook; - - info->battery = 1; - info->SaveGame[0] = x24c0x_data; - info->SaveGameLen[0] = 256; - AddExState(x24c0x_data, 256, 0, "DATA"); - - GameStateRestore = StateRestore; - AddExState(&x24c0xStateRegs, ~0, 0, 0); - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper159_Init(CartInfo *info) { - x24c02 = 0; - is153 = 0; - info->Power = BandaiPower; - MapIRQHook = BandaiIRQHook; - - info->battery = 1; - info->SaveGame[0] = x24c0x_data; - info->SaveGameLen[0] = 128; - AddExState(x24c0x_data, 128, 0, "DATA"); - - GameStateRestore = StateRestore; - AddExState(&x24c0xStateRegs, ~0, 0, 0); - AddExState(&StateRegs, ~0, 0, 0); -} - -/* Famicom jump 2: - * 0-7: Lower bit of data selects which 256KB PRG block is in use. - * This seems to be a hack on the developers' part, so I'll make emulation - * of it a hack(I think the current PRG block would depend on whatever the - * lowest bit of the CHR bank switching register that corresponds to the - * last CHR address read). - */ - -static void M153Power(void) { - Sync(); - setprg8r(0x10, 0x6000, 0); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, BandaiWrite); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - - -static void M153Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void Mapper153_Init(CartInfo *info) { - is153 = 1; - info->Power = M153Power; - info->Close = M153Close; - MapIRQHook = BandaiIRQHook; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -/* Datach Barcode Battler */ - -static uint8 BarcodeData[256]; -static int BarcodeReadPos; -static int BarcodeCycleCount; -static uint32 BarcodeOut; - -int FCEUI_DatachSet(const uint8 *rcode) { - int prefix_parity_type[10][6] = { - { 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 1, 1 }, { 0, 0, 1, 1, 0, 1 }, { 0, 0, 1, 1, 1, 0 }, - { 0, 1, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 1 }, { 0, 1, 1, 1, 0, 0 }, { 0, 1, 0, 1, 0, 1 }, - { 0, 1, 0, 1, 1, 0 }, { 0, 1, 1, 0, 1, 0 } - }; - int data_left_odd[10][7] = { - { 0, 0, 0, 1, 1, 0, 1 }, { 0, 0, 1, 1, 0, 0, 1 }, { 0, 0, 1, 0, 0, 1, 1 }, { 0, 1, 1, 1, 1, 0, 1 }, - { 0, 1, 0, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1 }, { 0, 1, 1, 1, 0, 1, 1 }, - { 0, 1, 1, 0, 1, 1, 1 }, { 0, 0, 0, 1, 0, 1, 1 } - }; - int data_left_even[10][7] = { - { 0, 1, 0, 0, 1, 1, 1 }, { 0, 1, 1, 0, 0, 1, 1 }, { 0, 0, 1, 1, 0, 1, 1 }, { 0, 1, 0, 0, 0, 0, 1 }, - { 0, 0, 1, 1, 1, 0, 1 }, { 0, 1, 1, 1, 0, 0, 1 }, { 0, 0, 0, 0, 1, 0, 1 }, { 0, 0, 1, 0, 0, 0, 1 }, - { 0, 0, 0, 1, 0, 0, 1 }, { 0, 0, 1, 0, 1, 1, 1 } - }; - int data_right[10][7] = { - { 1, 1, 1, 0, 0, 1, 0 }, { 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 0, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 1, 0 }, - { 1, 0, 1, 1, 1, 0, 0 }, { 1, 0, 0, 1, 1, 1, 0 }, { 1, 0, 1, 0, 0, 0, 0 }, { 1, 0, 0, 0, 1, 0, 0 }, - { 1, 0, 0, 1, 0, 0, 0 }, { 1, 1, 1, 0, 1, 0, 0 } - }; - uint8 code[13 + 1]; - uint32 tmp_p = 0; - int i, j; - int len; - - for (i = len = 0; i < 13; i++) { - if (!rcode[i]) break; - if ((code[i] = rcode[i] - '0') > 9) - return(0); - len++; - } - if (len != 13 && len != 12 && len != 8 && len != 7) return(0); - - #define BS(x) BarcodeData[tmp_p] = x; tmp_p++ - - for (j = 0; j < 32; j++) { - BS(0x00); - } - - /* Left guard bars */ - BS(1); BS(0); BS(1); - - if (len == 13 || len == 12) { - uint32 csum; - - for (i = 0; i < 6; i++) - if (prefix_parity_type[code[0]][i]) { - for (j = 0; j < 7; j++) { - BS(data_left_even[code[i + 1]][j]); - } - } else - for (j = 0; j < 7; j++) { - BS(data_left_odd[code[i + 1]][j]); - } - - /* Center guard bars */ - BS(0); BS(1); BS(0); BS(1); BS(0); - - for (i = 7; i < 12; i++) - for (j = 0; j < 7; j++) { - BS(data_right[code[i]][j]); - } - csum = 0; - for (i = 0; i < 12; i++) csum += code[i] * ((i & 1) ? 3 : 1); - csum = (10 - (csum % 10)) % 10; - for (j = 0; j < 7; j++) { - BS(data_right[csum][j]); - } - } else if (len == 8 || len == 7) { - uint32 csum = 0; - - for (i = 0; i < 7; i++) csum += (i & 1) ? code[i] : (code[i] * 3); - - csum = (10 - (csum % 10)) % 10; - - for (i = 0; i < 4; i++) - for (j = 0; j < 7; j++) { - BS(data_left_odd[code[i]][j]); - } - - - /* Center guard bars */ - BS(0); BS(1); BS(0); BS(1); BS(0); - - for (i = 4; i < 7; i++) - for (j = 0; j < 7; j++) { - BS(data_right[code[i]][j]); - } - - for (j = 0; j < 7; j++) { - BS(data_right[csum][j]); - } - } - - /* Right guard bars */ - BS(1); BS(0); BS(1); - - for (j = 0; j < 32; j++) { - BS(0x00); - } - - BS(0xFF); - - #undef BS - - BarcodeReadPos = 0; - BarcodeOut = 0x8; - BarcodeCycleCount = 0; - return(1); -} - -static void FP_FASTAPASS(1) BarcodeIRQHook(int a) { - BandaiIRQHook(a); - - BarcodeCycleCount += a; - - if (BarcodeCycleCount >= 1000) { - BarcodeCycleCount -= 1000; - if (BarcodeData[BarcodeReadPos] == 0xFF) { - BarcodeOut = 0; - } else { - BarcodeOut = (BarcodeData[BarcodeReadPos] ^ 1) << 3; - BarcodeReadPos++; - } - } -} - -static DECLFR(BarcodeRead) { - return BarcodeOut; -} - -static void M157Power(void) { - IRQa = 0; - BarcodeData[0] = 0xFF; - BarcodeReadPos = 0; - BarcodeOut = 0; - BarcodeCycleCount = 0; - - Sync(); - - SetWriteHandler(0x6000, 0xFFFF, BandaiWrite); - SetReadHandler(0x6000, 0x7FFF, BarcodeRead); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -void Mapper157_Init(CartInfo *info) { - is153 = 1; - info->Power = M157Power; - MapIRQHook = BarcodeIRQHook; - - GameInfo->cspecial = SIS_DATACH; - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * Copyright (C) 2011 FCEUX 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 + * + * Bandai mappers + * + */ + +#include "mapinc.h" + +static uint8 reg[16], is153, x24c02; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { reg, 16, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, /* need for Famicom Jump II - Saikyou no 7 Nin (J) [!] */ + { 0 } +}; + +/* x24C0x interface */ + +#define X24C0X_STANDBY 0 +#define X24C0X_ADDRESS 1 +#define X24C0X_WORD 2 +#define X24C0X_READ 3 +#define X24C0X_WRITE 4 + +static uint8 x24c0x_data[256], x24c0x_state; +static uint8 x24c0x_addr, x24c0x_word, x24c0x_latch, x24c0x_bitcount; +static uint8 x24c0x_sda, x24c0x_scl, x24c0x_out, x24c0x_oe; + +static SFORMAT x24c0xStateRegs[] = +{ + { &x24c0x_addr, 1, "ADDR" }, + { &x24c0x_word, 1, "WORD" }, + { &x24c0x_latch, 1, "LATC" }, + { &x24c0x_bitcount, 1, "BITC" }, + { &x24c0x_sda, 1, "SDA" }, + { &x24c0x_scl, 1, "SCL" }, + { &x24c0x_out, 1, "OUT" }, + { &x24c0x_oe, 1, "OE" }, + { &x24c0x_state, 1, "STAT" }, + { 0 } +}; + +static void x24c0x_init() { + x24c0x_addr = x24c0x_word = x24c0x_latch = x24c0x_bitcount = x24c0x_sda = x24c0x_scl = x24c0x_oe = 0; + x24c0x_state = X24C0X_STANDBY; +} + +static void x24c0x_write(uint8 data) { + uint8 sda = (data >> 6) & 1; + uint8 scl = (data >> 5) & 1; + x24c0x_oe = (data >> 7); + + if(x24c0x_scl && scl) { + if(x24c0x_sda && !sda) { /* START */ + x24c0x_state = X24C0X_ADDRESS; + x24c0x_bitcount = 0; + x24c0x_addr = 0; + } else if(!x24c0x_sda && sda) { /* STOP */ + x24c0x_state = X24C0X_STANDBY; + } + } else if(!x24c0x_scl && scl) { /* RISING EDGE */ + switch(x24c0x_state) { + case X24C0X_ADDRESS: + if(x24c0x_bitcount < 7) { + x24c0x_addr <<= 1; + x24c0x_addr |= sda; + } else { + if(!x24c02) /* X24C01 mode */ + x24c0x_word = x24c0x_addr; + if(sda) { /* READ COMMAND */ + x24c0x_state = X24C0X_READ; + } else { /* WRITE COMMAND */ + if(x24c02) /* X24C02 mode */ + x24c0x_state = X24C0X_WORD; + else + x24c0x_state = X24C0X_WRITE; + } + } + x24c0x_bitcount++; + break; + case X24C0X_WORD: + if(x24c0x_bitcount == 8) { /* ACK */ + x24c0x_word = 0; + x24c0x_out = 0; + } else { /* WORD ADDRESS INPUT */ + x24c0x_word <<= 1; + x24c0x_word |= sda; + if(x24c0x_bitcount == 16) { /* END OF ADDRESS INPUT */ + x24c0x_bitcount = 7; + x24c0x_state = X24C0X_WRITE; + } + } + x24c0x_bitcount++; + break; + case X24C0X_READ: + if (x24c0x_bitcount == 8) { /* ACK */ + x24c0x_out = 0; + x24c0x_latch = x24c0x_data[x24c0x_word]; + x24c0x_bitcount = 0; + } else { /* REAL OUTPUT */ + x24c0x_out = x24c0x_latch >> 7; + x24c0x_latch <<= 1; + x24c0x_bitcount++; + if(x24c0x_bitcount == 8) { + x24c0x_word++; + x24c0x_word &= 0xff; + } + } + break; + case X24C0X_WRITE: + if (x24c0x_bitcount == 8) { /* ACK */ + x24c0x_out = 0; + x24c0x_latch = 0; + x24c0x_bitcount = 0; + } else { /* REAL INPUT */ + x24c0x_latch <<= 1; + x24c0x_latch |= sda; + x24c0x_bitcount++; + if(x24c0x_bitcount == 8) { + x24c0x_data[x24c0x_word] = x24c0x_latch; + x24c0x_word++; + x24c0x_word &= 0xff; + } + } + break; + } + } + + x24c0x_sda = sda; + x24c0x_scl = scl; +} + +static uint8 x24c0x_read() { + return x24c0x_out << 4; +} + +static void Sync(void) { + if (is153) { + int base = (reg[0] & 1) << 4; + setchr8(0); + setprg16(0x8000, (reg[8] & 0x0F) | base); + setprg16(0xC000, 0x0F | base); + } else { + int i; + for (i = 0; i < 8; i++) setchr1(i << 10, reg[i]); + setprg16(0x8000, reg[8]); + setprg16(0xC000, ~0); + } + switch (reg[9] & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(BandaiWrite) { + A &= 0x0F; + if (A < 0x0A) { + reg[A & 0x0F] = V; + Sync(); + } else + switch (A) { + case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa = V & 1; IRQCount = IRQLatch; break; + case 0x0B: IRQLatch &= 0xFF00; IRQLatch |= V; break; + case 0x0C: IRQLatch &= 0xFF; IRQLatch |= V << 8; break; + case 0x0D: x24c0x_write(V); break; + } +} + +static DECLFR(BandaiRead) { + return (X.DB & 0xEF) | x24c0x_read(); +} + +static void FP_FASTAPASS(1) BandaiIRQHook(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount < 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = -1; + } + } +} + +static void BandaiPower(void) { + IRQa = 0; + x24c0x_init(); + Sync(); + SetReadHandler(0x6000, 0x7FFF, BandaiRead); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, BandaiWrite); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper16_Init(CartInfo *info) { + x24c02 = 1; + is153 = 0; + info->Power = BandaiPower; + MapIRQHook = BandaiIRQHook; + + info->battery = 1; + info->SaveGame[0] = x24c0x_data; + info->SaveGameLen[0] = 256; + AddExState(x24c0x_data, 256, 0, "DATA"); + + GameStateRestore = StateRestore; + AddExState(&x24c0xStateRegs, ~0, 0, 0); + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper159_Init(CartInfo *info) { + x24c02 = 0; + is153 = 0; + info->Power = BandaiPower; + MapIRQHook = BandaiIRQHook; + + info->battery = 1; + info->SaveGame[0] = x24c0x_data; + info->SaveGameLen[0] = 128; + AddExState(x24c0x_data, 128, 0, "DATA"); + + GameStateRestore = StateRestore; + AddExState(&x24c0xStateRegs, ~0, 0, 0); + AddExState(&StateRegs, ~0, 0, 0); +} + +/* Famicom jump 2: + * 0-7: Lower bit of data selects which 256KB PRG block is in use. + * This seems to be a hack on the developers' part, so I'll make emulation + * of it a hack(I think the current PRG block would depend on whatever the + * lowest bit of the CHR bank switching register that corresponds to the + * last CHR address read). + */ + +static void M153Power(void) { + Sync(); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BandaiWrite); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + + +static void M153Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper153_Init(CartInfo *info) { + is153 = 1; + info->Power = M153Power; + info->Close = M153Close; + MapIRQHook = BandaiIRQHook; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +/* Datach Barcode Battler */ + +static uint8 BarcodeData[256]; +static int BarcodeReadPos; +static int BarcodeCycleCount; +static uint32 BarcodeOut; + +int FCEUI_DatachSet(const uint8 *rcode) { + int prefix_parity_type[10][6] = { + { 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 1, 1 }, { 0, 0, 1, 1, 0, 1 }, { 0, 0, 1, 1, 1, 0 }, + { 0, 1, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 1 }, { 0, 1, 1, 1, 0, 0 }, { 0, 1, 0, 1, 0, 1 }, + { 0, 1, 0, 1, 1, 0 }, { 0, 1, 1, 0, 1, 0 } + }; + int data_left_odd[10][7] = { + { 0, 0, 0, 1, 1, 0, 1 }, { 0, 0, 1, 1, 0, 0, 1 }, { 0, 0, 1, 0, 0, 1, 1 }, { 0, 1, 1, 1, 1, 0, 1 }, + { 0, 1, 0, 0, 0, 1, 1 }, { 0, 1, 1, 0, 0, 0, 1 }, { 0, 1, 0, 1, 1, 1, 1 }, { 0, 1, 1, 1, 0, 1, 1 }, + { 0, 1, 1, 0, 1, 1, 1 }, { 0, 0, 0, 1, 0, 1, 1 } + }; + int data_left_even[10][7] = { + { 0, 1, 0, 0, 1, 1, 1 }, { 0, 1, 1, 0, 0, 1, 1 }, { 0, 0, 1, 1, 0, 1, 1 }, { 0, 1, 0, 0, 0, 0, 1 }, + { 0, 0, 1, 1, 1, 0, 1 }, { 0, 1, 1, 1, 0, 0, 1 }, { 0, 0, 0, 0, 1, 0, 1 }, { 0, 0, 1, 0, 0, 0, 1 }, + { 0, 0, 0, 1, 0, 0, 1 }, { 0, 0, 1, 0, 1, 1, 1 } + }; + int data_right[10][7] = { + { 1, 1, 1, 0, 0, 1, 0 }, { 1, 1, 0, 0, 1, 1, 0 }, { 1, 1, 0, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 1, 0 }, + { 1, 0, 1, 1, 1, 0, 0 }, { 1, 0, 0, 1, 1, 1, 0 }, { 1, 0, 1, 0, 0, 0, 0 }, { 1, 0, 0, 0, 1, 0, 0 }, + { 1, 0, 0, 1, 0, 0, 0 }, { 1, 1, 1, 0, 1, 0, 0 } + }; + uint8 code[13 + 1]; + uint32 tmp_p = 0; + int i, j; + int len; + + for (i = len = 0; i < 13; i++) { + if (!rcode[i]) break; + if ((code[i] = rcode[i] - '0') > 9) + return(0); + len++; + } + if (len != 13 && len != 12 && len != 8 && len != 7) return(0); + + #define BS(x) BarcodeData[tmp_p] = x; tmp_p++ + + for (j = 0; j < 32; j++) { + BS(0x00); + } + + /* Left guard bars */ + BS(1); BS(0); BS(1); + + if (len == 13 || len == 12) { + uint32 csum; + + for (i = 0; i < 6; i++) + if (prefix_parity_type[code[0]][i]) { + for (j = 0; j < 7; j++) { + BS(data_left_even[code[i + 1]][j]); + } + } else + for (j = 0; j < 7; j++) { + BS(data_left_odd[code[i + 1]][j]); + } + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for (i = 7; i < 12; i++) + for (j = 0; j < 7; j++) { + BS(data_right[code[i]][j]); + } + csum = 0; + for (i = 0; i < 12; i++) csum += code[i] * ((i & 1) ? 3 : 1); + csum = (10 - (csum % 10)) % 10; + for (j = 0; j < 7; j++) { + BS(data_right[csum][j]); + } + } else if (len == 8 || len == 7) { + uint32 csum = 0; + + for (i = 0; i < 7; i++) csum += (i & 1) ? code[i] : (code[i] * 3); + + csum = (10 - (csum % 10)) % 10; + + for (i = 0; i < 4; i++) + for (j = 0; j < 7; j++) { + BS(data_left_odd[code[i]][j]); + } + + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for (i = 4; i < 7; i++) + for (j = 0; j < 7; j++) { + BS(data_right[code[i]][j]); + } + + for (j = 0; j < 7; j++) { + BS(data_right[csum][j]); + } + } + + /* Right guard bars */ + BS(1); BS(0); BS(1); + + for (j = 0; j < 32; j++) { + BS(0x00); + } + + BS(0xFF); + + #undef BS + + BarcodeReadPos = 0; + BarcodeOut = 0x8; + BarcodeCycleCount = 0; + return(1); +} + +static void FP_FASTAPASS(1) BarcodeIRQHook(int a) { + BandaiIRQHook(a); + + BarcodeCycleCount += a; + + if (BarcodeCycleCount >= 1000) { + BarcodeCycleCount -= 1000; + if (BarcodeData[BarcodeReadPos] == 0xFF) { + BarcodeOut = 0; + } else { + BarcodeOut = (BarcodeData[BarcodeReadPos] ^ 1) << 3; + BarcodeReadPos++; + } + } +} + +static DECLFR(BarcodeRead) { + return BarcodeOut; +} + +static void M157Power(void) { + IRQa = 0; + BarcodeData[0] = 0xFF; + BarcodeReadPos = 0; + BarcodeOut = 0; + BarcodeCycleCount = 0; + + Sync(); + + SetWriteHandler(0x6000, 0xFFFF, BandaiWrite); + SetReadHandler(0x6000, 0x7FFF, BarcodeRead); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +void Mapper157_Init(CartInfo *info) { + is153 = 1; + info->Power = M157Power; + MapIRQHook = BarcodeIRQHook; + + GameInfo->cspecial = SIS_DATACH; + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bb.c b/src/boards/bb.c index 7f42455..1541f28 100644 --- a/src/boards/bb.c +++ b/src/boards/bb.c @@ -1,68 +1,68 @@ -/* 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 - * - * FDS Conversion - * - * Bubble Bobble CHR-ROM version - * - */ - -#include "mapinc.h" - -static uint8 reg, chr; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { &chr, 1, "CHR" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, reg & 3); - setprg32(0x8000, ~0); - setchr8(chr & 3); -} - -static DECLFW(UNLBBWrite) { - if ((A & 0x9000) == 0x8000) - reg = chr = V; - else - chr = V & 1; /* hacky hacky, ProWres simplified FDS conversion 2-in-1 mapper */ - Sync(); -} - -static void UNLBBPower(void) { - chr = 0; - reg = ~0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLBBWrite); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLBB_Init(CartInfo *info) { - info->Power = UNLBBPower; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + * Bubble Bobble CHR-ROM version + * + */ + +#include "mapinc.h" + +static uint8 reg, chr; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &chr, 1, "CHR" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg & 3); + setprg32(0x8000, ~0); + setchr8(chr & 3); +} + +static DECLFW(UNLBBWrite) { + if ((A & 0x9000) == 0x8000) + reg = chr = V; + else + chr = V & 1; /* hacky hacky, ProWres simplified FDS conversion 2-in-1 mapper */ + Sync(); +} + +static void UNLBBPower(void) { + chr = 0; + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLBBWrite); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLBB_Init(CartInfo *info) { + info->Power = UNLBBPower; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bmc13in1jy110.c b/src/boards/bmc13in1jy110.c index 36dea97..c7bd349 100644 --- a/src/boards/bmc13in1jy110.c +++ b/src/boards/bmc13in1jy110.c @@ -1,97 +1,97 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * BMC 42-in-1 "reset switch" type - */ - -#include "mapinc.h" - -static uint8 bank_mode; -static uint8 bank_value; -static uint8 prgb[4]; -static SFORMAT StateRegs[] = -{ - { &bank_mode, 1, "BNM" }, - { &bank_value, 1, "BMV" }, - { prgb, 4, "PRGB" }, - { 0 } -}; - -static void Sync(void) { -/* FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]); */ - switch (bank_mode & 7) { - case 0: - setprg32(0x8000, bank_value & 7); break; - case 1: - setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]); - setprg16(0xC000, (bank_value & 7) >> 1); - case 4: - setprg32(0x8000, 8 + (bank_value & 7)); break; - case 5: - setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]); - setprg16(0xC000, ((8 + (bank_value & 7)) >> 1) + prgb[3]); - case 2: - setprg8(0x8000, prgb[0] >> 2); - setprg8(0xa000, prgb[1]); - setprg8(0xc000, prgb[2]); - setprg8(0xe000, ~0); - break; - case 3: - setprg8(0x8000, prgb[0]); - setprg8(0xa000, prgb[1]); - setprg8(0xc000, prgb[2]); - setprg8(0xe000, prgb[3]); - break; - } -} - -static DECLFW(BMC13in1JY110Write) { -/* FCEU_printf("%04x:%04x\n",A,V); */ - switch (A) { - case 0x8000: - case 0x8001: - case 0x8002: - case 0x8003: prgb[A & 3] = V; break; - case 0xD000: bank_mode = V; break; - case 0xD001: setmirror(V & 3); - case 0xD002: break; - case 0xD003: bank_value = V; break; - } - Sync(); -} - -static void BMC13in1JY110Power(void) { - prgb[0] = prgb[1] = prgb[2] = prgb[3] = 0; - bank_mode = 0; - bank_value = 0; - setprg32(0x8000, 0); - setchr8(0); - SetWriteHandler(0x8000, 0xFFFF, BMC13in1JY110Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void BMC13in1JY110_Init(CartInfo *info) { - info->Power = BMC13in1JY110Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * BMC 42-in-1 "reset switch" type + */ + +#include "mapinc.h" + +static uint8 bank_mode; +static uint8 bank_value; +static uint8 prgb[4]; +static SFORMAT StateRegs[] = +{ + { &bank_mode, 1, "BNM" }, + { &bank_value, 1, "BMV" }, + { prgb, 4, "PRGB" }, + { 0 } +}; + +static void Sync(void) { +/* FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]); */ + switch (bank_mode & 7) { + case 0: + setprg32(0x8000, bank_value & 7); break; + case 1: + setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]); + setprg16(0xC000, (bank_value & 7) >> 1); + case 4: + setprg32(0x8000, 8 + (bank_value & 7)); break; + case 5: + setprg16(0x8000, ((8 + (bank_value & 7)) >> 1) + prgb[1]); + setprg16(0xC000, ((8 + (bank_value & 7)) >> 1) + prgb[3]); + case 2: + setprg8(0x8000, prgb[0] >> 2); + setprg8(0xa000, prgb[1]); + setprg8(0xc000, prgb[2]); + setprg8(0xe000, ~0); + break; + case 3: + setprg8(0x8000, prgb[0]); + setprg8(0xa000, prgb[1]); + setprg8(0xc000, prgb[2]); + setprg8(0xe000, prgb[3]); + break; + } +} + +static DECLFW(BMC13in1JY110Write) { +/* FCEU_printf("%04x:%04x\n",A,V); */ + switch (A) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: prgb[A & 3] = V; break; + case 0xD000: bank_mode = V; break; + case 0xD001: setmirror(V & 3); + case 0xD002: break; + case 0xD003: bank_value = V; break; + } + Sync(); +} + +static void BMC13in1JY110Power(void) { + prgb[0] = prgb[1] = prgb[2] = prgb[3] = 0; + bank_mode = 0; + bank_value = 0; + setprg32(0x8000, 0); + setchr8(0); + SetWriteHandler(0x8000, 0xFFFF, BMC13in1JY110Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC13in1JY110_Init(CartInfo *info) { + info->Power = BMC13in1JY110Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/bmc42in1r.c b/src/boards/bmc42in1r.c index 036997d..6f7a2b3 100644 --- a/src/boards/bmc42in1r.c +++ b/src/boards/bmc42in1r.c @@ -1,86 +1,86 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 CaH4e3 - * Copyright (C) 2009 qeed - * - * 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 - * - * BMC 42-in-1 "reset switch" + "select switch" - * - */ - -#include "mapinc.h" - -static uint8 isresetbased = 0; -static uint8 latche[2], reset; -static SFORMAT StateRegs[] = -{ - { &reset, 1, "RST" }, - { latche, 2, "LATC" }, - { 0 } -}; - -static void Sync(void) { - uint8 bank; - 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); - if (!(latche[0] & 0x20)) - setprg32(0x8000, bank >> 1); - else { - setprg16(0x8000, bank); - setprg16(0xC000, bank); - } - setmirror((latche[0] >> 6) & 1); - setchr8(0); -} - -static DECLFW(M226Write) { - latche[A & 1] = V; - Sync(); -} - -static void M226Power(void) { - latche[0] = latche[1] = reset = 0; - Sync(); - SetWriteHandler(0x8000, 0xFFFF, M226Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper226_Init(CartInfo *info) { - isresetbased = 0; - info->Power = M226Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} - -static void M233Reset(void) { - reset ^= 1; - Sync(); -} - -void Mapper233_Init(CartInfo *info) { - isresetbased = 1; - info->Power = M226Power; - info->Reset = M233Reset; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2009 qeed + * + * 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 + * + * BMC 42-in-1 "reset switch" + "select switch" + * + */ + +#include "mapinc.h" + +static uint8 isresetbased = 0; +static uint8 latche[2], reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "RST" }, + { latche, 2, "LATC" }, + { 0 } +}; + +static void Sync(void) { + uint8 bank; + 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); + if (!(latche[0] & 0x20)) + setprg32(0x8000, bank >> 1); + else { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + setmirror((latche[0] >> 6) & 1); + setchr8(0); +} + +static DECLFW(M226Write) { + latche[A & 1] = V; + Sync(); +} + +static void M226Power(void) { + latche[0] = latche[1] = reset = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M226Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper226_Init(CartInfo *info) { + isresetbased = 0; + info->Power = M226Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} + +static void M233Reset(void) { + reset ^= 1; + Sync(); +} + +void Mapper233_Init(CartInfo *info) { + isresetbased = 1; + info->Power = M226Power; + info->Reset = M233Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/bmc64in1nr.c b/src/boards/bmc64in1nr.c index 51f7c2b..88c46cf 100644 --- a/src/boards/bmc64in1nr.c +++ b/src/boards/bmc64in1nr.c @@ -1,83 +1,83 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * BMC 42-in-1 "reset switch" type - */ - -#include "mapinc.h" - -static uint8 regs[4]; - -static SFORMAT StateRegs[] = -{ - { regs, 4, "REGS" }, - { 0 } -}; - -static void Sync(void) { - if (regs[0] & 0x80) { - if (regs[1] & 0x80) - setprg32(0x8000, regs[1] & 0x1F); - else { - int bank = ((regs[1] & 0x1f) << 1) | ((regs[1] >> 6) & 1); - setprg16(0x8000, bank); - setprg16(0xC000, bank); - } - } else { - int bank = ((regs[1] & 0x1f) << 1) | ((regs[1] >> 6) & 1); - setprg16(0xC000, bank); - } - if (regs[0] & 0x20) - setmirror(MI_H); - else - setmirror(MI_V); - setchr8((regs[2] << 2) | ((regs[0] >> 1) & 3)); -} - -static DECLFW(BMC64in1nrWriteLo) { - regs[A & 3] = V; - Sync(); -} - -static DECLFW(BMC64in1nrWriteHi) { - regs[3] = V; - Sync(); -} - -static void BMC64in1nrPower(void) { - regs[0] = 0x80; - regs[1] = 0x43; - regs[2] = regs[3] = 0; - Sync(); - SetWriteHandler(0x5000, 0x5003, BMC64in1nrWriteLo); - SetWriteHandler(0x8000, 0xFFFF, BMC64in1nrWriteHi); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void BMC64in1nr_Init(CartInfo *info) { - info->Power = BMC64in1nrPower; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} - - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * BMC 42-in-1 "reset switch" type + */ + +#include "mapinc.h" + +static uint8 regs[4]; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "REGS" }, + { 0 } +}; + +static void Sync(void) { + if (regs[0] & 0x80) { + if (regs[1] & 0x80) + setprg32(0x8000, regs[1] & 0x1F); + else { + int bank = ((regs[1] & 0x1f) << 1) | ((regs[1] >> 6) & 1); + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else { + int bank = ((regs[1] & 0x1f) << 1) | ((regs[1] >> 6) & 1); + setprg16(0xC000, bank); + } + if (regs[0] & 0x20) + setmirror(MI_H); + else + setmirror(MI_V); + setchr8((regs[2] << 2) | ((regs[0] >> 1) & 3)); +} + +static DECLFW(BMC64in1nrWriteLo) { + regs[A & 3] = V; + Sync(); +} + +static DECLFW(BMC64in1nrWriteHi) { + regs[3] = V; + Sync(); +} + +static void BMC64in1nrPower(void) { + regs[0] = 0x80; + regs[1] = 0x43; + regs[2] = regs[3] = 0; + Sync(); + SetWriteHandler(0x5000, 0x5003, BMC64in1nrWriteLo); + SetWriteHandler(0x8000, 0xFFFF, BMC64in1nrWriteHi); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC64in1nr_Init(CartInfo *info) { + info->Power = BMC64in1nrPower; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} + + diff --git a/src/boards/bmc70in1.c b/src/boards/bmc70in1.c index 3a73568..97fb34f 100644 --- a/src/boards/bmc70in1.c +++ b/src/boards/bmc70in1.c @@ -1,123 +1,123 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" - -static uint8 is_large_banks, hw_switch; -static uint8 large_bank; -static uint8 prg_bank; -static uint8 chr_bank; -static uint8 bank_mode; -static uint8 mirroring; -static SFORMAT StateRegs[] = -{ - { &large_bank, 1, "LB" }, - { &hw_switch, 1, "DPSW" }, - { &prg_bank, 1, "PRG" }, - { &chr_bank, 1, "CHR" }, - { &bank_mode, 1, "BM" }, - { &mirroring, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - switch (bank_mode) { - case 0x00: - case 0x10: - setprg16(0x8000, large_bank | prg_bank); - setprg16(0xC000, large_bank | 7); - break; - case 0x20: - setprg32(0x8000, (large_bank | prg_bank) >> 1); - break; - case 0x30: - setprg16(0x8000, large_bank | prg_bank); - setprg16(0xC000, large_bank | prg_bank); - break; - } - setmirror(mirroring); - if (!is_large_banks) - setchr8(chr_bank); -} - -static DECLFR(BMC70in1Read) { - if (bank_mode == 0x10) -/* if(is_large_banks) */ - return CartBR((A & 0xFFF0) | hw_switch); -#if 0 - else - return CartBR((A&0xFFF0)|hw_switch); -#endif - else - return CartBR(A); -} - -static DECLFW(BMC70in1Write) { - if (A & 0x4000) { - bank_mode = A & 0x30; - prg_bank = A & 7; - } else { - mirroring = ((A & 0x20) >> 5) ^ 1; - if (is_large_banks) - large_bank = (A & 3) << 3; - else - chr_bank = A & 7; - } - Sync(); -} - -static void BMC70in1Reset(void) { - bank_mode = 0; - large_bank = 0; - Sync(); - hw_switch++; - hw_switch &= 0xf; -} - -static void BMC70in1Power(void) { - setchr8(0); - bank_mode = 0; - large_bank = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, BMC70in1Read); - SetWriteHandler(0x8000, 0xffff, BMC70in1Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void BMC70in1_Init(CartInfo *info) { - is_large_banks = 0; - hw_switch = 0xd; - info->Power = BMC70in1Power; - info->Reset = BMC70in1Reset; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void BMC70in1B_Init(CartInfo *info) { - is_large_banks = 1; - hw_switch = 0x6; - info->Power = BMC70in1Power; - info->Reset = BMC70in1Reset; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" + +static uint8 is_large_banks, hw_switch; +static uint8 large_bank; +static uint8 prg_bank; +static uint8 chr_bank; +static uint8 bank_mode; +static uint8 mirroring; +static SFORMAT StateRegs[] = +{ + { &large_bank, 1, "LB" }, + { &hw_switch, 1, "DPSW" }, + { &prg_bank, 1, "PRG" }, + { &chr_bank, 1, "CHR" }, + { &bank_mode, 1, "BM" }, + { &mirroring, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + switch (bank_mode) { + case 0x00: + case 0x10: + setprg16(0x8000, large_bank | prg_bank); + setprg16(0xC000, large_bank | 7); + break; + case 0x20: + setprg32(0x8000, (large_bank | prg_bank) >> 1); + break; + case 0x30: + setprg16(0x8000, large_bank | prg_bank); + setprg16(0xC000, large_bank | prg_bank); + break; + } + setmirror(mirroring); + if (!is_large_banks) + setchr8(chr_bank); +} + +static DECLFR(BMC70in1Read) { + if (bank_mode == 0x10) +/* if(is_large_banks) */ + return CartBR((A & 0xFFF0) | hw_switch); +#if 0 + else + return CartBR((A&0xFFF0)|hw_switch); +#endif + else + return CartBR(A); +} + +static DECLFW(BMC70in1Write) { + if (A & 0x4000) { + bank_mode = A & 0x30; + prg_bank = A & 7; + } else { + mirroring = ((A & 0x20) >> 5) ^ 1; + if (is_large_banks) + large_bank = (A & 3) << 3; + else + chr_bank = A & 7; + } + Sync(); +} + +static void BMC70in1Reset(void) { + bank_mode = 0; + large_bank = 0; + Sync(); + hw_switch++; + hw_switch &= 0xf; +} + +static void BMC70in1Power(void) { + setchr8(0); + bank_mode = 0; + large_bank = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, BMC70in1Read); + SetWriteHandler(0x8000, 0xffff, BMC70in1Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMC70in1_Init(CartInfo *info) { + is_large_banks = 0; + hw_switch = 0xd; + info->Power = BMC70in1Power; + info->Reset = BMC70in1Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void BMC70in1B_Init(CartInfo *info) { + is_large_banks = 1; + hw_switch = 0x6; + info->Power = BMC70in1Power; + info->Reset = BMC70in1Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bonza.c b/src/boards/bonza.c index c7cb458..b4b3754 100644 --- a/src/boards/bonza.c +++ b/src/boards/bonza.c @@ -1,136 +1,136 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 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 - */ - -#include "mapinc.h" - -#define CARD_EXTERNAL_INSERED 0x80 - -static uint8 prg_reg; -static uint8 chr_reg; -static SFORMAT StateRegs[] = -{ - { &prg_reg, 1, "PREG" }, - { &chr_reg, 1, "CREG" }, - { 0 } -}; - -#if 0 - -cmd[0] = response on/off - 0x00 - on - 0x80 - off -cmd[1] = cmd - - -_GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62 - -_SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0 -_SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1 -_SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3 -_SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4 -_SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5 -_SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4 -_SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0 - -_READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2 -_READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4 -_READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18 -_READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3 -_READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4 -_READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C -_READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10 - -_UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4 -_UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10 - -_GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8 -_GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2 -_GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6 -_GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8 -_GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C -_GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10 - -byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1 -byte_8C48: .BYTE $80,$32, 0, 1, 4 -byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0 -byte_8D01: .BYTE $80,$36, 0, 0, $C -byte_8CA7: .BYTE $80,$38, 0, 2, 4 -byte_8BEC: .BYTE $80,$3A, 0, 3, 0 - -byte_89A0: .BYTE 0,$48, 0, 0, 6 -byte_8808: .BYTE 0,$54, 0, 0,$1C -byte_89BF: .BYTE 0,$58, 0, 0,$1C - -_MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8 -byte_8CE5: .BYTE 0,$74, 0, 0,$12 -byte_8C29: .BYTE 0,$76, 0, 0, 8 -byte_8CC6: .BYTE 0,$78, 0, 0,$12 -#endif - -#if 0 /* Silenced since unused */ -static uint8 sim0reset[0x1F] = { - 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE, - 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53, - 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 -}; - -#endif - -static void Sync(void) { - setprg32(0x8000, prg_reg); - setchr8(chr_reg); -} - -static void StateRestore(int version) { - Sync(); -} - -static DECLFW(M216WriteHi) { - prg_reg = A & 1; - chr_reg = (A & 0x0E) >> 1; - Sync(); -} - -static DECLFW(M216Write5000) { -/* FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt); */ -} - -static DECLFR(M216Read5000) { -/* FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit); */ - return 0; -} - -static void Power(void) { - prg_reg = 0; - chr_reg = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M216WriteHi); - SetWriteHandler(0x5000, 0x5000, M216Write5000); - SetReadHandler(0x5000, 0x5000, M216Read5000); -} - - -void Mapper216_Init(CartInfo *info) { - info->Power = Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 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 + */ + +#include "mapinc.h" + +#define CARD_EXTERNAL_INSERED 0x80 + +static uint8 prg_reg; +static uint8 chr_reg; +static SFORMAT StateRegs[] = +{ + { &prg_reg, 1, "PREG" }, + { &chr_reg, 1, "CREG" }, + { 0 } +}; + +#if 0 + +cmd[0] = response on/off + 0x00 - on + 0x80 - off +cmd[1] = cmd + + +_GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62 + +_SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0 +_SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1 +_SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3 +_SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4 +_SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5 +_SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4 +_SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0 + +_READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2 +_READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4 +_READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18 +_READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3 +_READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4 +_READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C +_READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10 + +_UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4 +_UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10 + +_GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8 +_GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2 +_GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6 +_GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8 +_GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C +_GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10 + +byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1 +byte_8C48: .BYTE $80,$32, 0, 1, 4 +byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0 +byte_8D01: .BYTE $80,$36, 0, 0, $C +byte_8CA7: .BYTE $80,$38, 0, 2, 4 +byte_8BEC: .BYTE $80,$3A, 0, 3, 0 + +byte_89A0: .BYTE 0,$48, 0, 0, 6 +byte_8808: .BYTE 0,$54, 0, 0,$1C +byte_89BF: .BYTE 0,$58, 0, 0,$1C + +_MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8 +byte_8CE5: .BYTE 0,$74, 0, 0,$12 +byte_8C29: .BYTE 0,$76, 0, 0, 8 +byte_8CC6: .BYTE 0,$78, 0, 0,$12 +#endif + +#if 0 /* Silenced since unused */ +static uint8 sim0reset[0x1F] = { + 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE, + 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53, + 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 +}; + +#endif + +static void Sync(void) { + setprg32(0x8000, prg_reg); + setchr8(chr_reg); +} + +static void StateRestore(int version) { + Sync(); +} + +static DECLFW(M216WriteHi) { + prg_reg = A & 1; + chr_reg = (A & 0x0E) >> 1; + Sync(); +} + +static DECLFW(M216Write5000) { +/* FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt); */ +} + +static DECLFR(M216Read5000) { +/* FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit); */ + return 0; +} + +static void Power(void) { + prg_reg = 0; + chr_reg = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M216WriteHi); + SetWriteHandler(0x5000, 0x5000, M216Write5000); + SetReadHandler(0x5000, 0x5000, M216Read5000); +} + + +void Mapper216_Init(CartInfo *info) { + info->Power = Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bs-5.c b/src/boards/bs-5.c index 5e2ff1f..f00f4f9 100644 --- a/src/boards/bs-5.c +++ b/src/boards/bs-5.c @@ -1,84 +1,84 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg_prg[4]; -static uint8 reg_chr[4]; -static uint8 dip_switch; - -static SFORMAT StateRegs[] = -{ - { reg_prg, 4, "PREG" }, - { reg_chr, 4, "CREG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x8000, reg_prg[0]); - setprg8(0xa000, reg_prg[1]); - setprg8(0xc000, reg_prg[2]); - setprg8(0xe000, reg_prg[3]); - setchr2(0x0000, reg_chr[0]); - setchr2(0x0800, reg_chr[1]); - setchr2(0x1000, reg_chr[2]); - setchr2(0x1800, reg_chr[3]); - setmirror(MI_V); -} - -static DECLFW(MBS5Write) { - int bank_sel = (A & 0xC00) >> 10; - switch (A & 0xF000) { - case 0x8000: - reg_chr[bank_sel] = A & 0x1F; - break; - case 0xA000: - if (A & (1 << (dip_switch + 4))) - reg_prg[bank_sel] = A & 0x0F; - break; - } - Sync(); -} - -static void MBS5Reset(void) { - dip_switch++; - dip_switch &= 3; - reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0; - Sync(); -} - -static void MBS5Power(void) { - dip_switch = 0; - reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, MBS5Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void BMCBS5_Init(CartInfo *info) { - info->Power = MBS5Power; - info->Reset = MBS5Reset; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg_prg[4]; +static uint8 reg_chr[4]; +static uint8 dip_switch; + +static SFORMAT StateRegs[] = +{ + { reg_prg, 4, "PREG" }, + { reg_chr, 4, "CREG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, reg_prg[0]); + setprg8(0xa000, reg_prg[1]); + setprg8(0xc000, reg_prg[2]); + setprg8(0xe000, reg_prg[3]); + setchr2(0x0000, reg_chr[0]); + setchr2(0x0800, reg_chr[1]); + setchr2(0x1000, reg_chr[2]); + setchr2(0x1800, reg_chr[3]); + setmirror(MI_V); +} + +static DECLFW(MBS5Write) { + int bank_sel = (A & 0xC00) >> 10; + switch (A & 0xF000) { + case 0x8000: + reg_chr[bank_sel] = A & 0x1F; + break; + case 0xA000: + if (A & (1 << (dip_switch + 4))) + reg_prg[bank_sel] = A & 0x0F; + break; + } + Sync(); +} + +static void MBS5Reset(void) { + dip_switch++; + dip_switch &= 3; + reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0; + Sync(); +} + +static void MBS5Power(void) { + dip_switch = 0; + reg_prg[0] = reg_prg[1] = reg_prg[2] = reg_prg[3] = ~0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, MBS5Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void BMCBS5_Init(CartInfo *info) { + info->Power = MBS5Power; + info->Reset = MBS5Reset; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/cityfighter.c b/src/boards/cityfighter.c index 9064065..6558640 100644 --- a/src/boards/cityfighter.c +++ b/src/boards/cityfighter.c @@ -1,124 +1,124 @@ -/* 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 - * - * City Fighter IV sith Sound VRC4 hacked - */ - -#include "mapinc.h" - -static int32 IRQCount; -static uint8 IRQa; -static uint8 prg_reg, prg_mode, mirr; -static uint8 chr_reg[8]; -static writefunc pcmwrite; - -static SFORMAT StateRegs[] = -{ - { &IRQCount, 4, "IRQC" }, - { &IRQa, 1, "IRQA" }, - { &prg_reg, 1, "PREG" }, - { &prg_mode, 1, "PMOD" }, - { &mirr, 1, "MIRR" }, - { chr_reg, 8, "CREG" }, - { 0 } -}; - -static void Sync(void) { - int i; - setprg32(0x8000, prg_reg >> 2); - if (!prg_mode) - setprg8(0xC000, prg_reg); - for (i = 0; i < 8; i++) - setchr1(i << 10, chr_reg[i]); - switch (mirr) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(UNLCITYFIGHTWrite) { - /* FCEU_printf("%04x %02x",A,V); */ - switch (A & 0xF00C) { - case 0x9000: prg_reg = V & 0xC; mirr = V & 3; break; - case 0x9004: - case 0x9008: - case 0x900C: - if (A & 0x800) - pcmwrite(0x4011, (V & 0xf) << 3); - else - prg_reg = V & 0xC; - break; - case 0xC000: - case 0xC004: - case 0xC008: - case 0xC00C: prg_mode = V & 1; break; - case 0xD000: chr_reg[0] = (chr_reg[0] & 0xF0) | (V & 0x0F); break; - case 0xD004: chr_reg[0] = (chr_reg[0] & 0x0F) | (V << 4); break; - case 0xD008: chr_reg[1] = (chr_reg[1] & 0xF0) | (V & 0x0F); break; - case 0xD00C: chr_reg[1] = (chr_reg[1] & 0x0F) | (V << 4); break; - case 0xA000: chr_reg[2] = (chr_reg[2] & 0xF0) | (V & 0x0F); break; - case 0xA004: chr_reg[2] = (chr_reg[2] & 0x0F) | (V << 4); break; - case 0xA008: chr_reg[3] = (chr_reg[3] & 0xF0) | (V & 0x0F); break; - case 0xA00C: chr_reg[3] = (chr_reg[3] & 0x0F) | (V << 4); break; - case 0xB000: chr_reg[4] = (chr_reg[4] & 0xF0) | (V & 0x0F); break; - case 0xB004: chr_reg[4] = (chr_reg[4] & 0x0F) | (V << 4); break; - case 0xB008: chr_reg[5] = (chr_reg[5] & 0xF0) | (V & 0x0F); break; - case 0xB00C: chr_reg[5] = (chr_reg[5] & 0x0F) | (V << 4); break; - case 0xE000: chr_reg[6] = (chr_reg[6] & 0xF0) | (V & 0x0F); break; - case 0xE004: chr_reg[6] = (chr_reg[6] & 0x0F) | (V << 4); break; - case 0xE008: chr_reg[7] = (chr_reg[7] & 0xF0) | (V & 0x0F); break; - case 0xE00C: chr_reg[7] = (chr_reg[7] & 0x0F) | (V << 4); break; - case 0xF000: IRQCount = ((IRQCount & 0x1E0) | ((V & 0xF) << 1)); break; - case 0xF004: IRQCount = ((IRQCount & 0x1E) | ((V & 0xF) << 5)); break; - case 0xF008: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); break; - default: - break; - } - Sync(); -} - -static void UNLCITYFIGHTIRQ(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount <= 0) { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void UNLCITYFIGHTPower(void) { - prg_reg = 0; - Sync(); - pcmwrite = GetWriteHandler(0x4011); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLCITYFIGHTWrite); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLCITYFIGHT_Init(CartInfo *info) { - info->Power = UNLCITYFIGHTPower; - MapIRQHook = UNLCITYFIGHTIRQ; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * City Fighter IV sith Sound VRC4 hacked + */ + +#include "mapinc.h" + +static int32 IRQCount; +static uint8 IRQa; +static uint8 prg_reg, prg_mode, mirr; +static uint8 chr_reg[8]; +static writefunc pcmwrite; + +static SFORMAT StateRegs[] = +{ + { &IRQCount, 4, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { &prg_reg, 1, "PREG" }, + { &prg_mode, 1, "PMOD" }, + { &mirr, 1, "MIRR" }, + { chr_reg, 8, "CREG" }, + { 0 } +}; + +static void Sync(void) { + int i; + setprg32(0x8000, prg_reg >> 2); + if (!prg_mode) + setprg8(0xC000, prg_reg); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr_reg[i]); + switch (mirr) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(UNLCITYFIGHTWrite) { + /* FCEU_printf("%04x %02x",A,V); */ + switch (A & 0xF00C) { + case 0x9000: prg_reg = V & 0xC; mirr = V & 3; break; + case 0x9004: + case 0x9008: + case 0x900C: + if (A & 0x800) + pcmwrite(0x4011, (V & 0xf) << 3); + else + prg_reg = V & 0xC; + break; + case 0xC000: + case 0xC004: + case 0xC008: + case 0xC00C: prg_mode = V & 1; break; + case 0xD000: chr_reg[0] = (chr_reg[0] & 0xF0) | (V & 0x0F); break; + case 0xD004: chr_reg[0] = (chr_reg[0] & 0x0F) | (V << 4); break; + case 0xD008: chr_reg[1] = (chr_reg[1] & 0xF0) | (V & 0x0F); break; + case 0xD00C: chr_reg[1] = (chr_reg[1] & 0x0F) | (V << 4); break; + case 0xA000: chr_reg[2] = (chr_reg[2] & 0xF0) | (V & 0x0F); break; + case 0xA004: chr_reg[2] = (chr_reg[2] & 0x0F) | (V << 4); break; + case 0xA008: chr_reg[3] = (chr_reg[3] & 0xF0) | (V & 0x0F); break; + case 0xA00C: chr_reg[3] = (chr_reg[3] & 0x0F) | (V << 4); break; + case 0xB000: chr_reg[4] = (chr_reg[4] & 0xF0) | (V & 0x0F); break; + case 0xB004: chr_reg[4] = (chr_reg[4] & 0x0F) | (V << 4); break; + case 0xB008: chr_reg[5] = (chr_reg[5] & 0xF0) | (V & 0x0F); break; + case 0xB00C: chr_reg[5] = (chr_reg[5] & 0x0F) | (V << 4); break; + case 0xE000: chr_reg[6] = (chr_reg[6] & 0xF0) | (V & 0x0F); break; + case 0xE004: chr_reg[6] = (chr_reg[6] & 0x0F) | (V << 4); break; + case 0xE008: chr_reg[7] = (chr_reg[7] & 0xF0) | (V & 0x0F); break; + case 0xE00C: chr_reg[7] = (chr_reg[7] & 0x0F) | (V << 4); break; + case 0xF000: IRQCount = ((IRQCount & 0x1E0) | ((V & 0xF) << 1)); break; + case 0xF004: IRQCount = ((IRQCount & 0x1E) | ((V & 0xF) << 5)); break; + case 0xF008: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); break; + default: + break; + } + Sync(); +} + +static void UNLCITYFIGHTIRQ(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount <= 0) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLCITYFIGHTPower(void) { + prg_reg = 0; + Sync(); + pcmwrite = GetWriteHandler(0x4011); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLCITYFIGHTWrite); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLCITYFIGHT_Init(CartInfo *info) { + info->Power = UNLCITYFIGHTPower; + MapIRQHook = UNLCITYFIGHTIRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/coolboy.c b/src/boards/coolboy.c index 90413cf..b0f8649 100644 --- a/src/boards/coolboy.c +++ b/src/boards/coolboy.c @@ -1,152 +1,152 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2015 CaH4e3, ClusteR - * - * 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 - * - * CoolBoy 400-in-1 FK23C-mimic mapper 16Mb/32Mb PROM + 128K/256K CHR RAM, optional SRAM, optional NTRAM - * only MMC3 mode - * - * 6000 (xx76x210) | 0xC0 - * 6001 (xxx354x) - * 6002 = 0 - * 6003 = 0 - * - * hardware tested logic, don't try to understand lol - */ - -#include "mapinc.h" -#include "mmc3.h" - -static void COOLBOYCW(uint32 A, uint8 V) { - uint32 mask = 0xFF ^ (EXPREGS[0] & 0x80); - if (EXPREGS[3] & 0x10) { - if (EXPREGS[3] & 0x40) { /* Weird mode */ - int cbase = (MMC3_cmd & 0x80) << 5; - switch (cbase ^ A) { /* Don't even try to understand */ - case 0x0400: - case 0x0C00: V &= 0x7F; break; - } - } - /* Highest bit goes from MMC3 registers when EXPREGS[3]&0x80==0 or from EXPREGS[0]&0x08 otherwise */ - setchr1(A, - (V & 0x80 & mask) | ((((EXPREGS[0] & 0x08) << 4) & ~mask)) /* 7th bit */ - | ((EXPREGS[2] & 0x0F) << 3) /* 6-3 bits */ - | ((A >> 10) & 7) /* 2-0 bits */ - ); - } else { - if (EXPREGS[3] & 0x40) { /* Weird mode, again */ - int cbase = (MMC3_cmd & 0x80) << 5; - switch (cbase ^ A) { /* Don't even try to understand */ - case 0x0000: V = DRegBuf[0]; break; - case 0x0800: V = DRegBuf[1]; break; - case 0x0400: - case 0x0C00: V = 0; break; - } - } - /* Simple MMC3 mode - * Highest bit goes from MMC3 registers when EXPREGS[3]&0x80==0 or from EXPREGS[0]&0x08 otherwise - */ - setchr1(A, (V & mask) | (((EXPREGS[0] & 0x08) << 4) & ~mask)); - } -} - -static void COOLBOYPW(uint32 A, uint8 V) { - uint32 mask = ((0x3F | (EXPREGS[1] & 0x40) | ((EXPREGS[1] & 0x20) << 2)) ^ ((EXPREGS[0] & 0x40) >> 2)) ^ ((EXPREGS[1] & 0x80) >> 2); - uint32 base = ((EXPREGS[0] & 0x07) >> 0) | ((EXPREGS[1] & 0x10) >> 1) | ((EXPREGS[1] & 0x0C) << 2) | ((EXPREGS[0] & 0x30) << 2); - - /* Very weird mode - * Last banks are first in this mode, ignored when MMC3_cmd&0x40 - */ - if ((EXPREGS[3] & 0x40) && (V >= 0xFE) && !((MMC3_cmd & 0x40) != 0)) { - switch (A & 0xE000) { - case 0xA000: - if ((MMC3_cmd & 0x40)) V = 0; - break; - case 0xC000: - if (!(MMC3_cmd & 0x40)) V = 0; - break; - case 0xE000: - V = 0; - break; - } - } - - /* Regular MMC3 mode, internal ROM size can be up to 2048kb! */ - if (!(EXPREGS[3] & 0x10)) - setprg8(A, (((base << 4) & ~mask)) | (V & mask)); - else { /* NROM mode */ - uint8 emask; - mask &= 0xF0; - if ((((EXPREGS[1] & 2) != 0))) /* 32kb mode */ - emask = (EXPREGS[3] & 0x0C) | ((A & 0x4000) >> 13); - else /* 16kb mode */ - emask = EXPREGS[3] & 0x0E; - setprg8(A, ((base << 4) & ~mask) /* 7-4 bits are from base (see below) */ - | (V & mask) /* ... or from MM3 internal regs, depends on mask */ - | emask /* 3-1 (or 3-2 when (EXPREGS[3]&0x0C is set) from EXPREGS[3] */ - | ((A & 0x2000) >> 13)); /* 0th just as is */ - } -} - -static DECLFW(COOLBOYWrite) { - if(A001B & 0x80) - CartBW(A,V); - - /* Deny any further writes when 7th bit is 1 AND 4th is 0 */ - if ((EXPREGS[3] & 0x90) != 0x80) { - EXPREGS[A & 3] = V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } -} - -static void COOLBOYReset(void) { - MMC3RegReset(); - EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0; -#if 0 - EXPREGS[0] = 0; - EXPREGS[1] = 0x60; - EXPREGS[2] = 0; - EXPREGS[3] = 0; -#endif - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void COOLBOYPower(void) { - GenMMC3Power(); - EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0; -#if 0 - EXPREGS[0] = 0; - EXPREGS[1] = 0x60; - EXPREGS[2] = 0; - EXPREGS[3] = 0; -#endif - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - SetWriteHandler(0x5000, 0x5fff, CartBW); /* some games access random unmapped areas and crashes because of KT-008 PCB hack in MMC3 source lol */ - SetWriteHandler(0x6000, 0x7fff, COOLBOYWrite); -} - -void COOLBOY_Init(CartInfo *info) { - GenMMC3_Init(info, 512, 256, 8, 0); - pwrap = COOLBOYPW; - cwrap = COOLBOYCW; - info->Power = COOLBOYPower; - info->Reset = COOLBOYReset; - AddExState(EXPREGS, 4, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2015 CaH4e3, ClusteR + * + * 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 + * + * CoolBoy 400-in-1 FK23C-mimic mapper 16Mb/32Mb PROM + 128K/256K CHR RAM, optional SRAM, optional NTRAM + * only MMC3 mode + * + * 6000 (xx76x210) | 0xC0 + * 6001 (xxx354x) + * 6002 = 0 + * 6003 = 0 + * + * hardware tested logic, don't try to understand lol + */ + +#include "mapinc.h" +#include "mmc3.h" + +static void COOLBOYCW(uint32 A, uint8 V) { + uint32 mask = 0xFF ^ (EXPREGS[0] & 0x80); + if (EXPREGS[3] & 0x10) { + if (EXPREGS[3] & 0x40) { /* Weird mode */ + int cbase = (MMC3_cmd & 0x80) << 5; + switch (cbase ^ A) { /* Don't even try to understand */ + case 0x0400: + case 0x0C00: V &= 0x7F; break; + } + } + /* Highest bit goes from MMC3 registers when EXPREGS[3]&0x80==0 or from EXPREGS[0]&0x08 otherwise */ + setchr1(A, + (V & 0x80 & mask) | ((((EXPREGS[0] & 0x08) << 4) & ~mask)) /* 7th bit */ + | ((EXPREGS[2] & 0x0F) << 3) /* 6-3 bits */ + | ((A >> 10) & 7) /* 2-0 bits */ + ); + } else { + if (EXPREGS[3] & 0x40) { /* Weird mode, again */ + int cbase = (MMC3_cmd & 0x80) << 5; + switch (cbase ^ A) { /* Don't even try to understand */ + case 0x0000: V = DRegBuf[0]; break; + case 0x0800: V = DRegBuf[1]; break; + case 0x0400: + case 0x0C00: V = 0; break; + } + } + /* Simple MMC3 mode + * Highest bit goes from MMC3 registers when EXPREGS[3]&0x80==0 or from EXPREGS[0]&0x08 otherwise + */ + setchr1(A, (V & mask) | (((EXPREGS[0] & 0x08) << 4) & ~mask)); + } +} + +static void COOLBOYPW(uint32 A, uint8 V) { + uint32 mask = ((0x3F | (EXPREGS[1] & 0x40) | ((EXPREGS[1] & 0x20) << 2)) ^ ((EXPREGS[0] & 0x40) >> 2)) ^ ((EXPREGS[1] & 0x80) >> 2); + uint32 base = ((EXPREGS[0] & 0x07) >> 0) | ((EXPREGS[1] & 0x10) >> 1) | ((EXPREGS[1] & 0x0C) << 2) | ((EXPREGS[0] & 0x30) << 2); + + /* Very weird mode + * Last banks are first in this mode, ignored when MMC3_cmd&0x40 + */ + if ((EXPREGS[3] & 0x40) && (V >= 0xFE) && !((MMC3_cmd & 0x40) != 0)) { + switch (A & 0xE000) { + case 0xA000: + if ((MMC3_cmd & 0x40)) V = 0; + break; + case 0xC000: + if (!(MMC3_cmd & 0x40)) V = 0; + break; + case 0xE000: + V = 0; + break; + } + } + + /* Regular MMC3 mode, internal ROM size can be up to 2048kb! */ + if (!(EXPREGS[3] & 0x10)) + setprg8(A, (((base << 4) & ~mask)) | (V & mask)); + else { /* NROM mode */ + uint8 emask; + mask &= 0xF0; + if ((((EXPREGS[1] & 2) != 0))) /* 32kb mode */ + emask = (EXPREGS[3] & 0x0C) | ((A & 0x4000) >> 13); + else /* 16kb mode */ + emask = EXPREGS[3] & 0x0E; + setprg8(A, ((base << 4) & ~mask) /* 7-4 bits are from base (see below) */ + | (V & mask) /* ... or from MM3 internal regs, depends on mask */ + | emask /* 3-1 (or 3-2 when (EXPREGS[3]&0x0C is set) from EXPREGS[3] */ + | ((A & 0x2000) >> 13)); /* 0th just as is */ + } +} + +static DECLFW(COOLBOYWrite) { + if(A001B & 0x80) + CartBW(A,V); + + /* Deny any further writes when 7th bit is 1 AND 4th is 0 */ + if ((EXPREGS[3] & 0x90) != 0x80) { + EXPREGS[A & 3] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void COOLBOYReset(void) { + MMC3RegReset(); + EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0; +#if 0 + EXPREGS[0] = 0; + EXPREGS[1] = 0x60; + EXPREGS[2] = 0; + EXPREGS[3] = 0; +#endif + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void COOLBOYPower(void) { + GenMMC3Power(); + EXPREGS[0] = EXPREGS[1] = EXPREGS[2] = EXPREGS[3] = 0; +#if 0 + EXPREGS[0] = 0; + EXPREGS[1] = 0x60; + EXPREGS[2] = 0; + EXPREGS[3] = 0; +#endif + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + SetWriteHandler(0x5000, 0x5fff, CartBW); /* some games access random unmapped areas and crashes because of KT-008 PCB hack in MMC3 source lol */ + SetWriteHandler(0x6000, 0x7fff, COOLBOYWrite); +} + +void COOLBOY_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 256, 8, 0); + pwrap = COOLBOYPW; + cwrap = COOLBOYCW; + info->Power = COOLBOYPower; + info->Reset = COOLBOYReset; + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/src/boards/copyfami_emu.c b/src/boards/copyfami_emu.c index e565d98..96a22c3 100644 --- a/src/boards/copyfami_emu.c +++ b/src/boards/copyfami_emu.c @@ -1,355 +1,355 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - */ - -#ifdef COPYFAMI - -#include "__serial.h" -#include "mapinc.h" -#include "mmc3.h" - -/* #define DEBUG_SERIAL */ - -/* *** COPY FAMICOM EMULATION *** */ - -/* - * - * - * $0000-$1FFF - * $2000-$200F PPU - * $2010-$3FFB - * $3FFC-$3FFF - * $4000-$7FFF APU / - * $8000-$FFF9 CART/ROM - * $FFFA-$FFFB CART/ NMI - * $FFFE-$FFFF CART/ IRQ - * - * - * - * CTRL R/W $3FFC ---aenic ($00 at reset) - * - * c - - * 0 - - * 1 - - * i - IRQ - * 0 - - * 1 - - * n - NMI - * 0 - - * 1 - - * e - NMI - * 0 - - * 1 - - * a - AROM - * 0 - - * 1 - - * - * BANK R/W $3FFD ---mbbbb - * - * b - - * m - ROM - * - * USBDATA R/W $3FFE dddddddd - * - * d - / - * - * STATUS R $3FFF vmnicptr - * - * r - USB - * 0 - - * 1 - - * t - USB - * 0 - - * 1 - - * p - USB - * 0 - - * 1 - - * c - - * 0 - - * 1 - - * i - IRQ - * 0 - - * 1 - - * n - NMI - * 0 - - * 1 - - * m - 10 VRAM () - * v - VRAM - * 0 - - * 1 - - * - * AROM - * - * VRAM - * 8000-FFFF - */ - -#define CTRL 0x00 -#define CCART 0x01 -#define CVIRQ 0x02 -#define CVNMI 0x04 -#define CDNMI 0x08 -#define CAROM 0x10 -#define BANK 0x01 -#define BMIRR 0x10 -#define USB 0x02 -#define STATUS 0x03 -#define SRX 0x01 -#define STX 0x02 -#define SPEN 0x04 -#define SCART 0x08 -#define SIRQ 0x10 -#define SNMI 0x20 -#define SA10 0x40 -#define SVRAM 0x80 - -#ifdef DEBUG_SERIAL -static uint8 debug_serial_data[] = { - 0xDE, 0xAD, 0xBE, 0xEF, 0x00, - 0xDE, 0xAD, 0xBE, 0xEF, 0x01, - - 0x02, - - 0x14, 0x50, 0xB0, - - 0x02, - - 0x14, 0x50, 0xB0, - - 0x02, -}; -static uint32 debug_serial_data_size = sizeof(debug_serial_data); -static uint32 debug_serial_data_pos; -#endif - -static uint8 *CHRRAM = NULL; -static uint32 CHRRAMSIZE; - -static uint8 regs[4]; - -static readfunc def_read_ram, def_read_rom; -static writefunc def_write_ram; - -static SFORMAT StateRegs[] = -{ - { regs, 4, "CREGS" }, - { 0 } -}; - -static void Sync() { - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void MCopyFamiMMC3PW(uint32 A, uint8 V) { - if (regs[CTRL] & CCART) - setprg8(A, V); - else - setprg32r(1, 0x8000, (regs[BANK] & 0x0F) ^ 0x08); -} - -static void MCopyFamiMMC3CW(uint32 A, uint8 V) { - if ((regs[STATUS] & SCART) && (regs[CTRL] & CAROM)) - setchr8r(0x10, 0); - else - setchr1r(0, A, V); -} - -static void MCopyFamiMMC3MW(uint8 V) { - if (regs[CTRL] & CAROM) { - setmirror(MI_0 + ((regs[BANK] >> 4) & 1)); - } else { - A000B = V; - setmirror((V & 1) ^ 1); - } -} - -static uint32 direction = 0xffffffff; -static uint32 bytes_count = 0; - -static DECLFW(MCopyFamiWriteReg) { - if (((A & 3) == USB) && !fceuindbg) { - if (direction != 0) { - direction = 0; - bytes_count = 0; - FCEU_printf(" >"); - } -#ifndef DEBUG_SERIAL - while (!SerialSendChar(V)) { - } - ; -#endif - bytes_count++; -/* FCEU_printf(" %02X",V); */ - } else { - regs[A & 3] = V; - Sync(); - } -} - -static DECLFR(MCopyFamiReadReg) { -#ifdef DEBUG_SERIAL - if (debug_serial_data_pos == debug_serial_data_size) - regs[STATUS] |= SRX; - else - regs[STATUS] &= ~SRX; -#endif - if (!fceuindbg) { -#ifndef DEBUG_SERIAL - if ((A & 3) == STATUS) { - int data; - if ((data = SerialGetChar()) == EOF) - regs[STATUS] |= SRX; - else - regs[STATUS] &= ~SRX; - regs[USB] = data & 0xff; - } else -#endif - if ((A & 3) == USB) { -#ifdef DEBUG_SERIAL - regs[USB] = debug_serial_data[debug_serial_data_pos++]; -#endif - if (direction != 1) { - if (direction != 0xffffffff) FCEU_printf(" bytes sent: %08x", bytes_count); - direction = 1; - bytes_count = 0; - FCEU_printf("\n<"); - } - FCEU_printf(" %02X", regs[USB]); - } - } - return regs[A & 3]; -} - -static DECLFW(MCopyFamiMMC3Write) { - if (regs[CTRL] & CAROM) { - regs[BANK] = V & 0x1F; - Sync(); - } else { - if (A >= 0xC000) - MMC3_IRQWrite(A, V); - else - MMC3_CMDWrite(A, V); - } -} - -static DECLFW(MCopyFamiMMC3WriteNMI) { - if (regs[CTRL] & CVNMI) - def_write_ram(0x3FFC + (A & 1), V); - else - MCopyFamiMMC3Write(A, V); -} - -static DECLFW(MCopyFamiMMC3WriteIRQ) { - if (regs[CTRL] & CVIRQ) - def_write_ram(0x3FFE + (A & 1), V); - else - MCopyFamiMMC3Write(A, V); -} - -static DECLFR(MCopyFamiReadNMI) { - if (regs[CTRL] & CVNMI) - return def_read_ram(0x3FFC + (A & 1)); - else - return def_read_rom(A); -} - -static DECLFR(MCopyFamiReadIRQ) { - if (regs[CTRL] & CVIRQ) - return def_read_ram(0x3FFE + (A & 1)); - else - return def_read_rom(A); -} - -static void MCopyFamiMMC3Power(void) { - regs[CTRL] = regs[USB] = 0; - regs[STATUS] = SIRQ | SNMI | SVRAM; - regs[BANK] = 0x08; -#ifdef DEBUG_SERIAL - debug_serial_data_pos = 0; -#endif - GenMMC3Power(); - Sync(); - - def_write_ram = GetWriteHandler(0x3FFC); - SetWriteHandler(0x3FFC, 0x3FFF, MCopyFamiWriteReg); - def_read_ram = GetReadHandler(0x3FFC); - SetReadHandler(0x3FFC, 0x3FFF, MCopyFamiReadReg); - - SetWriteHandler(0x8000, 0xFFF9, MCopyFamiMMC3Write); - SetWriteHandler(0xFFFA, 0xFFFB, MCopyFamiMMC3WriteNMI); - SetWriteHandler(0xFFFE, 0xFFFF, MCopyFamiMMC3WriteIRQ); - - def_read_rom = GetReadHandler(0xFFFA); - SetReadHandler(0xFFFA, 0xFFFB, MCopyFamiReadNMI); - SetReadHandler(0xFFFE, 0xFFFF, MCopyFamiReadIRQ); -} - -static void MCopyFamiMMC3Reset(void) { - regs[CTRL] = regs[USB] = 0; - regs[STATUS] = SIRQ | SNMI | SVRAM; - regs[BANK] = 0x08; -#ifdef DEBUG_SERIAL - debug_serial_data_pos = 0; -#endif - MMC3RegReset(); - Sync(); -} - -static void MCopyFamiClose(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; - SerialClose(); -} - -static void StateRestore(int version) { - Sync(); -} - -void MapperCopyFamiMMC3_Init(CartInfo *info) { - GenMMC3_Init(info, 512, 512, 8, 0); - - cwrap = MCopyFamiMMC3CW; - pwrap = MCopyFamiMMC3PW; - mwrap = MCopyFamiMMC3MW; - - info->Reset = MCopyFamiMMC3Reset; - info->Power = MCopyFamiMMC3Power; - info->Close = MCopyFamiClose; - GameStateRestore = StateRestore; - - CHRRAMSIZE = 8192; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); - -#ifndef DEBUG_SERIAL - FCEU_printf("WAITING FOR PORT...\n"); - - while (!SerialOpen(20, 921600)) { - } - - FCEU_printf("PORT READY.\n"); -#endif - - AddExState(&StateRegs, ~0, 0, 0); -} - -#endif +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + */ + +#ifdef COPYFAMI + +#include "__serial.h" +#include "mapinc.h" +#include "mmc3.h" + +/* #define DEBUG_SERIAL */ + +/* *** COPY FAMICOM EMULATION *** */ + +/* + * + * + * $0000-$1FFF + * $2000-$200F PPU + * $2010-$3FFB + * $3FFC-$3FFF + * $4000-$7FFF APU / + * $8000-$FFF9 CART/ROM + * $FFFA-$FFFB CART/ NMI + * $FFFE-$FFFF CART/ IRQ + * + * + * + * CTRL R/W $3FFC ---aenic ($00 at reset) + * + * c - + * 0 - + * 1 - + * i - IRQ + * 0 - + * 1 - + * n - NMI + * 0 - + * 1 - + * e - NMI + * 0 - + * 1 - + * a - AROM + * 0 - + * 1 - + * + * BANK R/W $3FFD ---mbbbb + * + * b - + * m - ROM + * + * USBDATA R/W $3FFE dddddddd + * + * d - / + * + * STATUS R $3FFF vmnicptr + * + * r - USB + * 0 - + * 1 - + * t - USB + * 0 - + * 1 - + * p - USB + * 0 - + * 1 - + * c - + * 0 - + * 1 - + * i - IRQ + * 0 - + * 1 - + * n - NMI + * 0 - + * 1 - + * m - 10 VRAM () + * v - VRAM + * 0 - + * 1 - + * + * AROM + * + * VRAM + * 8000-FFFF + */ + +#define CTRL 0x00 +#define CCART 0x01 +#define CVIRQ 0x02 +#define CVNMI 0x04 +#define CDNMI 0x08 +#define CAROM 0x10 +#define BANK 0x01 +#define BMIRR 0x10 +#define USB 0x02 +#define STATUS 0x03 +#define SRX 0x01 +#define STX 0x02 +#define SPEN 0x04 +#define SCART 0x08 +#define SIRQ 0x10 +#define SNMI 0x20 +#define SA10 0x40 +#define SVRAM 0x80 + +#ifdef DEBUG_SERIAL +static uint8 debug_serial_data[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0x00, + 0xDE, 0xAD, 0xBE, 0xEF, 0x01, + + 0x02, + + 0x14, 0x50, 0xB0, + + 0x02, + + 0x14, 0x50, 0xB0, + + 0x02, +}; +static uint32 debug_serial_data_size = sizeof(debug_serial_data); +static uint32 debug_serial_data_pos; +#endif + +static uint8 *CHRRAM = NULL; +static uint32 CHRRAMSIZE; + +static uint8 regs[4]; + +static readfunc def_read_ram, def_read_rom; +static writefunc def_write_ram; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "CREGS" }, + { 0 } +}; + +static void Sync() { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void MCopyFamiMMC3PW(uint32 A, uint8 V) { + if (regs[CTRL] & CCART) + setprg8(A, V); + else + setprg32r(1, 0x8000, (regs[BANK] & 0x0F) ^ 0x08); +} + +static void MCopyFamiMMC3CW(uint32 A, uint8 V) { + if ((regs[STATUS] & SCART) && (regs[CTRL] & CAROM)) + setchr8r(0x10, 0); + else + setchr1r(0, A, V); +} + +static void MCopyFamiMMC3MW(uint8 V) { + if (regs[CTRL] & CAROM) { + setmirror(MI_0 + ((regs[BANK] >> 4) & 1)); + } else { + A000B = V; + setmirror((V & 1) ^ 1); + } +} + +static uint32 direction = 0xffffffff; +static uint32 bytes_count = 0; + +static DECLFW(MCopyFamiWriteReg) { + if (((A & 3) == USB) && !fceuindbg) { + if (direction != 0) { + direction = 0; + bytes_count = 0; + FCEU_printf(" >"); + } +#ifndef DEBUG_SERIAL + while (!SerialSendChar(V)) { + } + ; +#endif + bytes_count++; +/* FCEU_printf(" %02X",V); */ + } else { + regs[A & 3] = V; + Sync(); + } +} + +static DECLFR(MCopyFamiReadReg) { +#ifdef DEBUG_SERIAL + if (debug_serial_data_pos == debug_serial_data_size) + regs[STATUS] |= SRX; + else + regs[STATUS] &= ~SRX; +#endif + if (!fceuindbg) { +#ifndef DEBUG_SERIAL + if ((A & 3) == STATUS) { + int data; + if ((data = SerialGetChar()) == EOF) + regs[STATUS] |= SRX; + else + regs[STATUS] &= ~SRX; + regs[USB] = data & 0xff; + } else +#endif + if ((A & 3) == USB) { +#ifdef DEBUG_SERIAL + regs[USB] = debug_serial_data[debug_serial_data_pos++]; +#endif + if (direction != 1) { + if (direction != 0xffffffff) FCEU_printf(" bytes sent: %08x", bytes_count); + direction = 1; + bytes_count = 0; + FCEU_printf("\n<"); + } + FCEU_printf(" %02X", regs[USB]); + } + } + return regs[A & 3]; +} + +static DECLFW(MCopyFamiMMC3Write) { + if (regs[CTRL] & CAROM) { + regs[BANK] = V & 0x1F; + Sync(); + } else { + if (A >= 0xC000) + MMC3_IRQWrite(A, V); + else + MMC3_CMDWrite(A, V); + } +} + +static DECLFW(MCopyFamiMMC3WriteNMI) { + if (regs[CTRL] & CVNMI) + def_write_ram(0x3FFC + (A & 1), V); + else + MCopyFamiMMC3Write(A, V); +} + +static DECLFW(MCopyFamiMMC3WriteIRQ) { + if (regs[CTRL] & CVIRQ) + def_write_ram(0x3FFE + (A & 1), V); + else + MCopyFamiMMC3Write(A, V); +} + +static DECLFR(MCopyFamiReadNMI) { + if (regs[CTRL] & CVNMI) + return def_read_ram(0x3FFC + (A & 1)); + else + return def_read_rom(A); +} + +static DECLFR(MCopyFamiReadIRQ) { + if (regs[CTRL] & CVIRQ) + return def_read_ram(0x3FFE + (A & 1)); + else + return def_read_rom(A); +} + +static void MCopyFamiMMC3Power(void) { + regs[CTRL] = regs[USB] = 0; + regs[STATUS] = SIRQ | SNMI | SVRAM; + regs[BANK] = 0x08; +#ifdef DEBUG_SERIAL + debug_serial_data_pos = 0; +#endif + GenMMC3Power(); + Sync(); + + def_write_ram = GetWriteHandler(0x3FFC); + SetWriteHandler(0x3FFC, 0x3FFF, MCopyFamiWriteReg); + def_read_ram = GetReadHandler(0x3FFC); + SetReadHandler(0x3FFC, 0x3FFF, MCopyFamiReadReg); + + SetWriteHandler(0x8000, 0xFFF9, MCopyFamiMMC3Write); + SetWriteHandler(0xFFFA, 0xFFFB, MCopyFamiMMC3WriteNMI); + SetWriteHandler(0xFFFE, 0xFFFF, MCopyFamiMMC3WriteIRQ); + + def_read_rom = GetReadHandler(0xFFFA); + SetReadHandler(0xFFFA, 0xFFFB, MCopyFamiReadNMI); + SetReadHandler(0xFFFE, 0xFFFF, MCopyFamiReadIRQ); +} + +static void MCopyFamiMMC3Reset(void) { + regs[CTRL] = regs[USB] = 0; + regs[STATUS] = SIRQ | SNMI | SVRAM; + regs[BANK] = 0x08; +#ifdef DEBUG_SERIAL + debug_serial_data_pos = 0; +#endif + MMC3RegReset(); + Sync(); +} + +static void MCopyFamiClose(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; + SerialClose(); +} + +static void StateRestore(int version) { + Sync(); +} + +void MapperCopyFamiMMC3_Init(CartInfo *info) { + GenMMC3_Init(info, 512, 512, 8, 0); + + cwrap = MCopyFamiMMC3CW; + pwrap = MCopyFamiMMC3PW; + mwrap = MCopyFamiMMC3MW; + + info->Reset = MCopyFamiMMC3Reset; + info->Power = MCopyFamiMMC3Power; + info->Close = MCopyFamiClose; + GameStateRestore = StateRestore; + + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + +#ifndef DEBUG_SERIAL + FCEU_printf("WAITING FOR PORT...\n"); + + while (!SerialOpen(20, 921600)) { + } + + FCEU_printf("PORT READY.\n"); +#endif + + AddExState(&StateRegs, ~0, 0, 0); +} + +#endif diff --git a/src/boards/copyfami_hwi.c b/src/boards/copyfami_hwi.c index 40d6632..72a05af 100644 --- a/src/boards/copyfami_hwi.c +++ b/src/boards/copyfami_hwi.c @@ -1,590 +1,590 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - */ - -#ifdef COPYFAMI - -/* *** COPY FAMICOM HARDWARE INTERFACE *** */ - -#define MESSAGE_LOG -#define NO_CACHE -#define NO_RAM - -#include "__serial.h" -#include "mapinc.h" - -#define FNV_32_PRIME ((uint32)0x01000193) - -#define CHR_CACHE_SIZE (1024 * 4) -#define WRAM_CACHE_SIZE (1024 / 2) -#define PRG_CACHE_SIZE (1024 / 4) -#define CMD_CACHE_SIZE (1024 * 128) - -#define CMD_MAX_SIZE (5) -#define CMD_MAX_RETEST (16) -#define CMD_MAX_VERIFY (16) - -static uint8 *WRAM = NULL; - -uint8 InitVector[] = { 0xDE, 0xAD, 0xBE, 0xEF };/* args none, return DE AD BE EF */ -uint8 ResetCmd[] = { 0x00 }; /* args none, return none */ -uint8 StateCmd[] = { 0x01 }; /* args none, return 7 bytes status */ -uint8 StatusCmd[] = { 0x02 }; /* args none, return 32 bytes status */ -uint8 LoadPlugCmd[] = { 0x03, 0x00, 0x00 }; /* args 2b size, Nb data return none */ -uint8 RunPlugCmd[] = { 0x04 }; /* args none, return none */ -uint8 RunGameCmd[] = { 0x05 }; /* args none, return none */ -uint8 NROMSave[] = { 0x06 }; /* args none, return 16b + 32kb + 8kb */ - -uint8 PRGWBCmd[] = { 0x08, 0x00, 0x00, 0x00 }; /* args 2b addr, 1b data return none */ -uint8 PRGRBCmd[] = { 0x09, 0x00, 0x00 }; /* args 2b addr return 1b data */ -uint8 CHRWBCmd[] = { 0x0A, 0x00, 0x00, 0x00 }; /* args 2b addr, 1b data return none */ -uint8 CHRRBCmd[] = { 0x0B, 0x00, 0x00 }; /* args 2b addr, return 1b data */ - -uint8 PRGSUMCmd[] = { 0x10, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ -uint8 PRG32KSUMCmd[] = { 0x10, 0x80, 0x80 }; /* args 1b addr, 1b size return 32kb */ -uint8 PRG16KSUMCmd[] = { 0x10, 0x00, 0x40 }; /* args 1b addr, 1b size return 16kb */ -uint8 PRG8KSUMCmd[] = { 0x10, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ -uint8 PRG4KSUMCmd[] = { 0x10, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ - -uint8 CHRSUMCmd[] = { 0x11, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ -uint8 CHR8KSUMCmd[] = { 0x11, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ -uint8 CHR4KSUMCmd[] = { 0x11, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ -uint8 CHR2KSUMCmd[] = { 0x11, 0x00, 0x08 }; /* args 1b addr, 1b size return 2kb */ -uint8 CHR1KSUMCmd[] = { 0x11, 0x00, 0x04 }; /* args 1b addr, 1b size return 1kb */ - -uint8 PRGGetCmd[] = { 0x12, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ -uint8 PRG32KGetCmd[] = { 0x12, 0x80, 0x80 }; /* args 1b addr, 1b size return 32kb */ -uint8 PRG16KGetCmd[] = { 0x12, 0x00, 0x40 }; /* args 1b addr, 1b size return 16kb */ -uint8 PRG8KGetCmd[] = { 0x12, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ -uint8 PRG4KGetCmd[] = { 0x12, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ - -uint8 CHRGetCmd[] = { 0x13, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ -uint8 CHR8KGetCmd[] = { 0x13, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ -uint8 CHR4KGetCmd[] = { 0x13, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ -uint8 CHR2KGetCmd[] = { 0x13, 0x00, 0x08 }; /* args 1b addr, 1b size return 2kb */ -uint8 CHR1KGetCmd[] = { 0x13, 0x00, 0x04 }; /* args 1b addr, 1b size return 1kb */ - -uint8 CPUTestCmd[] = { 0x14, 0x00, 0x00 }; /* args 1b addr, 1b size return (2b + 1b) * N + 3b */ - -typedef struct { - int32 mirror; - int32 chrsum[8]; - int32 prgsum[4]; -} SYNC_STATE; - -static SYNC_STATE state_cur, state_new, state_def; - -typedef struct { - uint8 *buf; - int32 count; -} DATA_BANKS; - -static DATA_BANKS chr_data; -static int32 chr_bank[0x10000]; -static DATA_BANKS prg_data; -static int32 prg_bank[0x10000]; - -typedef struct { - SYNC_STATE states[CMD_CACHE_SIZE]; - int32 seqs[CMD_CACHE_SIZE][CMD_MAX_SIZE]; - int32 count; -} SYNC_CMDS; - -typedef struct { - int32 seq[CMD_MAX_SIZE]; - int32 size; - int32 found; - uint32 hash; - uint16 hashf; -} SYNC_CMD; - -static SYNC_CMD cmd; -static SYNC_CMDS cmds; - -typedef struct { - int32 index; - int32 size; - int32 retest; - int32 verify; -} CMD_CACHE; - -static CMD_CACHE cmd_cache[0x10000]; - -static SFORMAT StateRegs[] = -{ - { state_cur.chrsum, sizeof(state_cur.chrsum), "CHRREG" }, - { state_cur.prgsum, sizeof(state_cur.prgsum), "ROMREG" }, - { &state_cur.mirror, sizeof(state_cur.mirror), "MIRREG" }, - { 0 } -}; - -#define MI_U 4 - -static char *mirror_names[5] = { "Horizontal", "Vertical", "Mirror 0", "Mirror 1", "Unknown mirror" }; -static int32 mirror_modes[16] = { - MI_0, MI_U, MI_U, MI_H, MI_U, MI_V, MI_U, MI_U, - MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_1 -}; - -#define CHRDEF(slot) (chr_bank[state_def.chrsum[slot]]) -#define PRGDEF(slot) (prg_bank[state_def.prgsum[slot]]) -#define CHRCUR(slot) (chr_bank[state_cur.chrsum[slot]]) -#define PRGCUR(slot) (prg_bank[state_cur.prgsum[slot]]) -#define CHRNEW(slot) (chr_bank[state_new.chrsum[slot]]) -#define PRGNEW(slot) (prg_bank[state_new.prgsum[slot]]) - -static void GetStatus(SYNC_STATE *state) { - uint8 resp0; - uint16 resp1, i; - SEND(StatusCmd); - GET(resp0, 1); - state->mirror = resp0; - GET(resp0, 1); - for (i = 0; i < 8; i++) { - GET(resp1, 2); - state->chrsum[i] = resp1; - } - for (i = 0; i < 4; i++) { - GET(resp1, 2); - state->prgsum[i] = resp1; - } -} - -static int32 FetchNewCHRBank(int32 slot) { - FILE *ofile; - char name[256]; - int32 bank = chr_data.count++; - CHR1KGetCmd[1] = slot << 2; - SENDGET(CHR1KGetCmd, chr_data.buf[bank * 1024], 1024); - sprintf(name, "%04x.chr", bank); - ofile = fopen(name, "wb"); - fwrite((void*)&chr_data.buf[bank * 1024], 1, 1024, ofile); - fclose(ofile); - return bank; -} - -static int32 FetchNewPRGBank(int32 slot) { - FILE *ofile; - char name[256]; - int32 bank = prg_data.count++; - PRG8KGetCmd[1] = 0x80 + (slot << 5); - SENDGET(PRG8KGetCmd, prg_data.buf[bank * 8192], 8192); - sprintf(name, "%04x.prg", bank); - ofile = fopen(name, "wb"); - fwrite((void*)&prg_data.buf[bank * 8192], 1, 8192, ofile); - fclose(ofile); - return bank; -} - -static int CheckStatus(void) { - int32 i, ischanged = 0; - GetStatus(&state_new); - if (state_cur.mirror != state_new.mirror) { - state_cur.mirror = state_new.mirror; -#ifdef MESSAGE_LOG - FCEU_printf(">> mirror changed to %s (%02X)\n", mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); -#endif - ischanged = 1; - } else { - state_new.mirror = -1; - } - for (i = 0; i < 8; i++) { - if (state_cur.chrsum[i] != state_new.chrsum[i]) { - state_cur.chrsum[i] = state_new.chrsum[i]; - if (CHRCUR(i) == -1) { - CHRCUR(i) = FetchNewCHRBank(i); -#ifdef MESSAGE_LOG - FCEU_printf(">> chr[%d] bank %d loaded\n", i, CHRCUR(i)); -#endif - } -#ifdef MESSAGE_LOG - else - FCEU_printf(">> chr[%d] bank %d switched\n", i, CHRCUR(i)); -#endif - ischanged = 1; - } else { - state_new.chrsum[i] = -1; - } - } - for (i = 0; i < 4; i++) { - if (state_cur.prgsum[i] != state_new.prgsum[i]) { - state_cur.prgsum[i] = state_new.prgsum[i]; - if (PRGCUR(i) == -1) { - PRGCUR(i) = FetchNewPRGBank(i); -#ifdef MESSAGE_LOG - FCEU_printf(">> prg[%d] bank %d loaded\n", i, PRGCUR(i)); -#endif - } -#ifdef MESSAGE_LOG - else - FCEU_printf(">> prg[%d] bank %d switched\n", i, PRGCUR(i)); -#endif - ischanged = 1; - } else { - state_new.prgsum[i] = -1; - } - } - return ischanged; -} - -#ifndef NO_CACHE -static void ApplyStatus() { - int32 i; - if ((cmds.states[cmd.found].mirror != -1) && (cmds.states[cmd.found].mirror != state_cur.mirror)) { - state_cur.mirror = cmds.states[cmd.found].mirror; - setmirror(mirror_modes[state_cur.mirror]); -#ifdef MESSAGE_LOG - FCEU_printf(">> mirror changed to %s (%02X)\n", mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); -#endif - } - for (i = 0; i < 8; i++) { - int32 sum = cmds.states[cmd.found].chrsum[i]; - if (sum != -1) { - if (sum != state_cur.chrsum[i]) { - state_cur.chrsum[i] = sum; - setchr1r(1, i * 1024, CHRCUR(i)); -#ifdef MESSAGE_LOG - FCEU_printf(">> chr[%d] bank %d switched\n", i, chr_bank[sum]); -#endif - } else -#ifdef MESSAGE_LOG - FCEU_printf(">> chr[%d] bank %d switched the same\n", i, chr_bank[sum]); - } -#endif - } - for (i = 0; i < 4; i++) { - int32 sum = cmds.states[cmd.found].prgsum[i]; - if (sum != -1) { - if (sum != state_cur.prgsum[i]) { - state_cur.prgsum[i] = sum; - setprg8r(2, 0x8000 + (i * 8192), PRGCUR(i)); -#ifdef MESSAGE_LOG - FCEU_printf(">> prg[%d] bank %d switched\n", i, prg_bank[sum]); -#endif - } else -#ifdef MESSAGE_LOG - FCEU_printf(">> prg[%d] bank %d switched the same\n", i, prg_bank[sum]); - } -#endif - } - } - - static void LogCmd() { - int32 i; - FCEU_printf(">> new cmd size %d [", cmd_cache[cmd.hashf].size); - for (i = 0; i < cmd_cache[cmd.hashf].size; i++) - FCEU_printf(" %06X", cmds.seqs[cmd.found][i]); - FCEU_printf(" ], switched to ("); - if (cmds.states[cmd.found].mirror != -1) - FCEU_printf(" mirror=%s", mirror_names[mirror_modes[cmds.states[cmd.found].mirror]]); - for (i = 0; i < 8; i++) - if (cmds.states[cmd.found].chrsum[i] != -1) - FCEU_printf(" chr%d=%02X", i, chr_bank[cmds.states[cmd.found].chrsum[i]]); - for (i = 0; i < 4; i++) - if (cmds.states[cmd.found].prgsum[i] != -1) - FCEU_printf(" prg%d=%02X", i, prg_bank[cmds.states[cmd.found].prgsum[i]]); - FCEU_printf(" )\n"); - } -#endif -static void Sync() { - setchr1r(1, 0x0000, CHRCUR(0)); - setchr1r(1, 0x0400, CHRCUR(1)); - setchr1r(1, 0x0800, CHRCUR(2)); - setchr1r(1, 0x0C00, CHRCUR(3)); - setchr1r(1, 0x1000, CHRCUR(4)); - setchr1r(1, 0x1400, CHRCUR(5)); - setchr1r(1, 0x1800, CHRCUR(6)); - setchr1r(1, 0x1C00, CHRCUR(7)); -#ifndef NO_RAM - setprg8r(1, 0x6000, 0); -#endif - setprg8r(2, 0x8000, PRGCUR(0)); - setprg8r(2, 0xA000, PRGCUR(1)); - setprg8r(2, 0xC000, PRGCUR(2)); - setprg8r(2, 0xE000, PRGCUR(3)); - setmirror(mirror_modes[state_cur.mirror]); -} -#ifndef NO_CACHE -static void UpdateCmd(uint32 val) { - int32 index; - if (cmd.size < CMD_MAX_SIZE) { - index = cmd.size++; - } else { - /* åñëè äîñòèãíóò ìàêñèìóì äëÿ êîìàíäû, âûáðîñèòü ïîñëåäíóþþ, äîáàâèòü íîâóþ, - * ïðîäîëæàòü äî áàíêñâè÷èíãà - */ - cmd.hash = 0; - for (index = 0; index < (CMD_MAX_SIZE - 1); index++) { - cmd.seq[index] = cmd.seq[index + 1]; - cmd.hash *= FNV_32_PRIME; - cmd.hash ^= cmd.seq[index]; - } - } - cmd.seq[index] = val; - cmd.hash *= FNV_32_PRIME; - cmd.hash ^= val; - cmd.hashf = (cmd.hash >> 16) ^ (cmd.hash & 0xffff); - cmd.found = cmd_cache[cmd.hashf].index; -} -#endif - -static DECLFW(MCopyFamiWrite) { -#ifndef NO_CACHE - int32 i; -#endif - -#ifdef MESSAGE_LOG - FCEU_printf("> WRITE %04X:%02X\n", A, V); -#endif - - PRGWBCmd[1] = A & 0xFF; - PRGWBCmd[2] = A >> 8; - PRGWBCmd[3] = V & 0xFF; - SEND(PRGWBCmd); -#ifdef NO_CACHE - CheckStatus(); - Sync(); -#else - UpdateCmd((A << 8) | V); - /* èùåì êîìàíäó â êåøå */ - if (cmd.found == -1) { - /* íå íàéäåíà, ïðîâåðÿåì, èçìåíèëîñü ëè ñîñòîÿíèå áàíêîâ - * ëèáî íå ïðåäåëüíîé ëè îíà äëèíû äëÿ êîìàíäû - */ - cmd_cache[cmd.hashf].index = cmd.found = cmds.count++; - cmd_cache[cmd.hashf].retest = 0; - cmd_cache[cmd.hashf].verify = 0; - for (i = 0; i < cmd.size; i++) - cmds.seqs[cmd.found][i] = cmd.seq[i]; - cmd_cache[cmd.hashf].size = cmd.size; - if (CheckStatus()) { - cmds.states[cmd.found] = state_new; - LogCmd(); - cmd.size = 0; - cmd.hash = 0; - Sync(); - } else { - /* åñëè äîáàâëåíà ïîëíàÿ êîìàíäà áåç áàíêñâèò÷èíãà */ - cmd_cache[cmd.hashf].index = -2; - } - } else if (cmd.found == -2) { - /* ÷àñòè÷íîå ñîâïàäåíèå, åñëè ÷èñëî ïðîâåðîê íå ïðåâûñèëî ëèìèò */ - if (cmd_cache[cmd.hashf].retest < CMD_MAX_RETEST) { - /* òî ïðîâåðèì ñîñòîÿíèå áàíêîâ */ - if (CheckStatus()) { - /* èçìåíèëîñü, çàïèøåì íîâóþ êîìàíäó */ - cmd_cache[cmd.hashf].index = cmd.found = cmds.count++; - cmd_cache[cmd.hashf].retest = 0; - cmd_cache[cmd.hashf].verify = 0; - for (i = 0; i < cmd.size; i++) - cmds.seqs[cmd.found][i] = cmd.seq[i]; - cmd_cache[cmd.hashf].size = cmd.size; - cmds.states[cmd.found] = state_new; - LogCmd(); - cmd.size = 0; - cmd.hash = 0; - Sync(); - } else { - /* íå èçìåíèëîñü, îòìåòèì óâåëè÷èì ñ÷åò÷èê ïðîâåðîê */ - cmd_cache[cmd.hashf].retest++; - } - } - } else { - /* íàéäåíà, ïîñëåäíèé ðóáåæ îáîðîíû îò ãîâíà */ -#if 0 - if(cmd_cache[cmd.hashf].verify < CMD_MAX_VERIFY) { - if(CheckStatus()) { - int32 changed = 0; - if(cmds.states[cmd.found].mirror != state_new.mirror) - changed = 1; - for(i=0; i<8; i++) - if(cmds.states[cmd.found].chrsum[i] != state_new.chrsum[i]) - changed = 1; - for(i=0; i<4; i++) - if(cmds.states[cmd.found].prgsum[i] != state_new.prgsum[i]) - changed = 1; - if(changed) { - cmd_cache[cmd.hashf].index = -1; - cmd_cache[cmd.hashf].retest = 0; - cmd_cache[cmd.hashf].verify = 0; - Sync(); - } - } else - cmd_cache[cmd.hashf].verify++; - } else -#endif - { - /* ïðèìåíÿåì áåç ìàëåéøåãî çàçðåíèÿ ñîâåñòè */ - ApplyStatus(); - cmd.size = 0; - cmd.hash = 0; - } - } -#endif -} - -static DECLFR(MCopyFamiRead) { - uint8 result; - PRGRBCmd[1] = A & 0xFF; - PRGRBCmd[2] = A >> 8; - SENDGET(PRGRBCmd, result, 1); -#ifdef MESSAGE_LOG - FCEU_printf("> READ %04X:%02X\n", A, result); -#endif - return result; -} - -static void MCopyFamiReset(void) { - state_cur = state_def; - Sync(); -} - -static void MCopyFamiPower(void) { -/* uint32 resp, presp; */ - - FCEU_printf("NOW POWERING... "); - - Sync(); - - SetWriteHandler(0x4018, 0x7fff, MCopyFamiWrite); - SetReadHandler(0x4018, 0x7fff, MCopyFamiRead); -#ifndef NO_RAM - SetWriteHandler(0x6000, 0x7fff, CartBW); - SetReadHandler(0x6000, 0x7fff, CartBR); -#endif - -#if 0 - FCEU_printf("READING MEMORY MAP...\n"); - CPUTestCmd[1] = 0x50; - CPUTestCmd[2] = 0x30; - SEND(CPUTestCmd); - resp = 0; - presp = 0xffffffff; - while (presp != 0x00ff0000) { - GET(resp, 3); - if(presp != 0xffffffff) { - switch(presp & 0x00FF0000) { - case 0x00000000: /* BUS */ - FCEU_printf(" %04X-%04X OPEN BUS\n",presp & 0x7fff, (resp - 1) & 0x7fff); - break; - case 0x00010000: /* RAM */ - FCEU_printf(" %04X-%04X RAM\n",presp & 0x7fff, (resp - 1) & 0x7fff); - SetWriteHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBW); - SetReadHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBR); - break; - } - } - presp = resp; - } -#endif - SetWriteHandler(0x8000, 0xffff, MCopyFamiWrite); - SetReadHandler(0x8000, 0xffff, CartBR); - - FCEU_printf("DONE!\nNOW COLLECTING DATA...\n"); -} - -static void MCopyFamiClose(void) { - if (chr_data.buf) - FCEU_gfree(chr_data.buf); - chr_data.buf = NULL; - if (prg_data.buf) - FCEU_gfree(prg_data.buf); - prg_data.buf = NULL; - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; - - SerialClose(); -} - -static void StateRestore(int version) { - Sync(); -} - -void MapperCopyFami_Init(CartInfo *info) { - uint32 resp = 0, i, size; - - memset(chr_bank, -1, sizeof(chr_bank)); - memset(prg_bank, -1, sizeof(chr_bank)); - memset(cmd_cache, -1, sizeof(cmd_cache)); - memset(&cmds, 0, sizeof(cmds)); - memset(&cmd, 0, sizeof(cmd)); - - info->Reset = MCopyFamiReset; - info->Power = MCopyFamiPower; - info->Close = MCopyFamiClose; - GameStateRestore = StateRestore; - - size = 1024 * CHR_CACHE_SIZE; /* ðàçìåð ñòðàíèöû 1êá */ - chr_data.buf = (uint8*)FCEU_gmalloc(size); - SetupCartCHRMapping(1, chr_data.buf, size, 1); /* ïðîâåðÿòü ïïó ðàì, èíà÷å èãðà ìîæåò ïîðòèòü äàííûå */ - AddExState(chr_data.buf, size, 0, "CCHR"); - - size = 8192; /* ðàçìåð ñòðàíèöû 8êá */ - WRAM = (uint8*)FCEU_gmalloc(size); - SetupCartPRGMapping(1, WRAM, size, 1); - AddExState(WRAM, size, 0, "CPRM"); - - size = 8192 * PRG_CACHE_SIZE; /* ðàçìåð ñòðàíèöû 8êá */ - prg_data.buf = (uint8*)FCEU_gmalloc(size); - SetupCartPRGMapping(2, prg_data.buf, size, 0); - AddExState(prg_data.buf, size, 0, "CPPR"); - - - FCEU_printf("WAITING FOR SERIAL PORT... "); - while (!SerialOpen(19, 921600)) { - Sleep(500); - } - FCEU_printf("READY!\n"); - - FCEU_printf("WAITING FOR DEVICE... "); - - while (resp != *(uint32*)&InitVector[0]) { - SEND(ResetCmd); - SENDGET(InitVector, resp, 4); - Sleep(500); - } - - FCEU_printf("READY!\n"); - FCEU_printf("READING STATUS...\n"); - GetStatus(&state_cur); - FCEU_printf("MIRRORING IS %s (%02X)\n", mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); - FCEU_printf("READING CHR...\n INITIAL STATE:"); - - for (i = 0; i < 8; i++) { - if (CHRCUR(i) == -1) - CHRCUR(i) = FetchNewCHRBank(i); - FCEU_printf(" CHR%d=%02X", i, CHRCUR(i)); - } - FCEU_printf("\n"); - - FCEU_printf("READING PRG...\n INITIAL STATE:"); - for (i = 0; i < 4; i++) { - if (PRGCUR(i) == -1) - PRGCUR(i) = FetchNewPRGBank(i); - FCEU_printf(" PRG%d=%02X", i, PRGCUR(i)); - } - FCEU_printf("\nDONE!\n"); - - state_def = state_cur; - - AddExState(&StateRegs, ~0, 0, 0); -} - -#endif +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + */ + +#ifdef COPYFAMI + +/* *** COPY FAMICOM HARDWARE INTERFACE *** */ + +#define MESSAGE_LOG +#define NO_CACHE +#define NO_RAM + +#include "__serial.h" +#include "mapinc.h" + +#define FNV_32_PRIME ((uint32)0x01000193) + +#define CHR_CACHE_SIZE (1024 * 4) +#define WRAM_CACHE_SIZE (1024 / 2) +#define PRG_CACHE_SIZE (1024 / 4) +#define CMD_CACHE_SIZE (1024 * 128) + +#define CMD_MAX_SIZE (5) +#define CMD_MAX_RETEST (16) +#define CMD_MAX_VERIFY (16) + +static uint8 *WRAM = NULL; + +uint8 InitVector[] = { 0xDE, 0xAD, 0xBE, 0xEF };/* args none, return DE AD BE EF */ +uint8 ResetCmd[] = { 0x00 }; /* args none, return none */ +uint8 StateCmd[] = { 0x01 }; /* args none, return 7 bytes status */ +uint8 StatusCmd[] = { 0x02 }; /* args none, return 32 bytes status */ +uint8 LoadPlugCmd[] = { 0x03, 0x00, 0x00 }; /* args 2b size, Nb data return none */ +uint8 RunPlugCmd[] = { 0x04 }; /* args none, return none */ +uint8 RunGameCmd[] = { 0x05 }; /* args none, return none */ +uint8 NROMSave[] = { 0x06 }; /* args none, return 16b + 32kb + 8kb */ + +uint8 PRGWBCmd[] = { 0x08, 0x00, 0x00, 0x00 }; /* args 2b addr, 1b data return none */ +uint8 PRGRBCmd[] = { 0x09, 0x00, 0x00 }; /* args 2b addr return 1b data */ +uint8 CHRWBCmd[] = { 0x0A, 0x00, 0x00, 0x00 }; /* args 2b addr, 1b data return none */ +uint8 CHRRBCmd[] = { 0x0B, 0x00, 0x00 }; /* args 2b addr, return 1b data */ + +uint8 PRGSUMCmd[] = { 0x10, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ +uint8 PRG32KSUMCmd[] = { 0x10, 0x80, 0x80 }; /* args 1b addr, 1b size return 32kb */ +uint8 PRG16KSUMCmd[] = { 0x10, 0x00, 0x40 }; /* args 1b addr, 1b size return 16kb */ +uint8 PRG8KSUMCmd[] = { 0x10, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ +uint8 PRG4KSUMCmd[] = { 0x10, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ + +uint8 CHRSUMCmd[] = { 0x11, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ +uint8 CHR8KSUMCmd[] = { 0x11, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ +uint8 CHR4KSUMCmd[] = { 0x11, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ +uint8 CHR2KSUMCmd[] = { 0x11, 0x00, 0x08 }; /* args 1b addr, 1b size return 2kb */ +uint8 CHR1KSUMCmd[] = { 0x11, 0x00, 0x04 }; /* args 1b addr, 1b size return 1kb */ + +uint8 PRGGetCmd[] = { 0x12, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ +uint8 PRG32KGetCmd[] = { 0x12, 0x80, 0x80 }; /* args 1b addr, 1b size return 32kb */ +uint8 PRG16KGetCmd[] = { 0x12, 0x00, 0x40 }; /* args 1b addr, 1b size return 16kb */ +uint8 PRG8KGetCmd[] = { 0x12, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ +uint8 PRG4KGetCmd[] = { 0x12, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ + +uint8 CHRGetCmd[] = { 0x13, 0x00, 0x00 }; /* args 1b addr, 1b size return (256 * N)b */ +uint8 CHR8KGetCmd[] = { 0x13, 0x00, 0x20 }; /* args 1b addr, 1b size return 8kb */ +uint8 CHR4KGetCmd[] = { 0x13, 0x00, 0x10 }; /* args 1b addr, 1b size return 4kb */ +uint8 CHR2KGetCmd[] = { 0x13, 0x00, 0x08 }; /* args 1b addr, 1b size return 2kb */ +uint8 CHR1KGetCmd[] = { 0x13, 0x00, 0x04 }; /* args 1b addr, 1b size return 1kb */ + +uint8 CPUTestCmd[] = { 0x14, 0x00, 0x00 }; /* args 1b addr, 1b size return (2b + 1b) * N + 3b */ + +typedef struct { + int32 mirror; + int32 chrsum[8]; + int32 prgsum[4]; +} SYNC_STATE; + +static SYNC_STATE state_cur, state_new, state_def; + +typedef struct { + uint8 *buf; + int32 count; +} DATA_BANKS; + +static DATA_BANKS chr_data; +static int32 chr_bank[0x10000]; +static DATA_BANKS prg_data; +static int32 prg_bank[0x10000]; + +typedef struct { + SYNC_STATE states[CMD_CACHE_SIZE]; + int32 seqs[CMD_CACHE_SIZE][CMD_MAX_SIZE]; + int32 count; +} SYNC_CMDS; + +typedef struct { + int32 seq[CMD_MAX_SIZE]; + int32 size; + int32 found; + uint32 hash; + uint16 hashf; +} SYNC_CMD; + +static SYNC_CMD cmd; +static SYNC_CMDS cmds; + +typedef struct { + int32 index; + int32 size; + int32 retest; + int32 verify; +} CMD_CACHE; + +static CMD_CACHE cmd_cache[0x10000]; + +static SFORMAT StateRegs[] = +{ + { state_cur.chrsum, sizeof(state_cur.chrsum), "CHRREG" }, + { state_cur.prgsum, sizeof(state_cur.prgsum), "ROMREG" }, + { &state_cur.mirror, sizeof(state_cur.mirror), "MIRREG" }, + { 0 } +}; + +#define MI_U 4 + +static char *mirror_names[5] = { "Horizontal", "Vertical", "Mirror 0", "Mirror 1", "Unknown mirror" }; +static int32 mirror_modes[16] = { + MI_0, MI_U, MI_U, MI_H, MI_U, MI_V, MI_U, MI_U, + MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_1 +}; + +#define CHRDEF(slot) (chr_bank[state_def.chrsum[slot]]) +#define PRGDEF(slot) (prg_bank[state_def.prgsum[slot]]) +#define CHRCUR(slot) (chr_bank[state_cur.chrsum[slot]]) +#define PRGCUR(slot) (prg_bank[state_cur.prgsum[slot]]) +#define CHRNEW(slot) (chr_bank[state_new.chrsum[slot]]) +#define PRGNEW(slot) (prg_bank[state_new.prgsum[slot]]) + +static void GetStatus(SYNC_STATE *state) { + uint8 resp0; + uint16 resp1, i; + SEND(StatusCmd); + GET(resp0, 1); + state->mirror = resp0; + GET(resp0, 1); + for (i = 0; i < 8; i++) { + GET(resp1, 2); + state->chrsum[i] = resp1; + } + for (i = 0; i < 4; i++) { + GET(resp1, 2); + state->prgsum[i] = resp1; + } +} + +static int32 FetchNewCHRBank(int32 slot) { + FILE *ofile; + char name[256]; + int32 bank = chr_data.count++; + CHR1KGetCmd[1] = slot << 2; + SENDGET(CHR1KGetCmd, chr_data.buf[bank * 1024], 1024); + sprintf(name, "%04x.chr", bank); + ofile = fopen(name, "wb"); + fwrite((void*)&chr_data.buf[bank * 1024], 1, 1024, ofile); + fclose(ofile); + return bank; +} + +static int32 FetchNewPRGBank(int32 slot) { + FILE *ofile; + char name[256]; + int32 bank = prg_data.count++; + PRG8KGetCmd[1] = 0x80 + (slot << 5); + SENDGET(PRG8KGetCmd, prg_data.buf[bank * 8192], 8192); + sprintf(name, "%04x.prg", bank); + ofile = fopen(name, "wb"); + fwrite((void*)&prg_data.buf[bank * 8192], 1, 8192, ofile); + fclose(ofile); + return bank; +} + +static int CheckStatus(void) { + int32 i, ischanged = 0; + GetStatus(&state_new); + if (state_cur.mirror != state_new.mirror) { + state_cur.mirror = state_new.mirror; +#ifdef MESSAGE_LOG + FCEU_printf(">> mirror changed to %s (%02X)\n", mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); +#endif + ischanged = 1; + } else { + state_new.mirror = -1; + } + for (i = 0; i < 8; i++) { + if (state_cur.chrsum[i] != state_new.chrsum[i]) { + state_cur.chrsum[i] = state_new.chrsum[i]; + if (CHRCUR(i) == -1) { + CHRCUR(i) = FetchNewCHRBank(i); +#ifdef MESSAGE_LOG + FCEU_printf(">> chr[%d] bank %d loaded\n", i, CHRCUR(i)); +#endif + } +#ifdef MESSAGE_LOG + else + FCEU_printf(">> chr[%d] bank %d switched\n", i, CHRCUR(i)); +#endif + ischanged = 1; + } else { + state_new.chrsum[i] = -1; + } + } + for (i = 0; i < 4; i++) { + if (state_cur.prgsum[i] != state_new.prgsum[i]) { + state_cur.prgsum[i] = state_new.prgsum[i]; + if (PRGCUR(i) == -1) { + PRGCUR(i) = FetchNewPRGBank(i); +#ifdef MESSAGE_LOG + FCEU_printf(">> prg[%d] bank %d loaded\n", i, PRGCUR(i)); +#endif + } +#ifdef MESSAGE_LOG + else + FCEU_printf(">> prg[%d] bank %d switched\n", i, PRGCUR(i)); +#endif + ischanged = 1; + } else { + state_new.prgsum[i] = -1; + } + } + return ischanged; +} + +#ifndef NO_CACHE +static void ApplyStatus() { + int32 i; + if ((cmds.states[cmd.found].mirror != -1) && (cmds.states[cmd.found].mirror != state_cur.mirror)) { + state_cur.mirror = cmds.states[cmd.found].mirror; + setmirror(mirror_modes[state_cur.mirror]); +#ifdef MESSAGE_LOG + FCEU_printf(">> mirror changed to %s (%02X)\n", mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); +#endif + } + for (i = 0; i < 8; i++) { + int32 sum = cmds.states[cmd.found].chrsum[i]; + if (sum != -1) { + if (sum != state_cur.chrsum[i]) { + state_cur.chrsum[i] = sum; + setchr1r(1, i * 1024, CHRCUR(i)); +#ifdef MESSAGE_LOG + FCEU_printf(">> chr[%d] bank %d switched\n", i, chr_bank[sum]); +#endif + } else +#ifdef MESSAGE_LOG + FCEU_printf(">> chr[%d] bank %d switched the same\n", i, chr_bank[sum]); + } +#endif + } + for (i = 0; i < 4; i++) { + int32 sum = cmds.states[cmd.found].prgsum[i]; + if (sum != -1) { + if (sum != state_cur.prgsum[i]) { + state_cur.prgsum[i] = sum; + setprg8r(2, 0x8000 + (i * 8192), PRGCUR(i)); +#ifdef MESSAGE_LOG + FCEU_printf(">> prg[%d] bank %d switched\n", i, prg_bank[sum]); +#endif + } else +#ifdef MESSAGE_LOG + FCEU_printf(">> prg[%d] bank %d switched the same\n", i, prg_bank[sum]); + } +#endif + } + } + + static void LogCmd() { + int32 i; + FCEU_printf(">> new cmd size %d [", cmd_cache[cmd.hashf].size); + for (i = 0; i < cmd_cache[cmd.hashf].size; i++) + FCEU_printf(" %06X", cmds.seqs[cmd.found][i]); + FCEU_printf(" ], switched to ("); + if (cmds.states[cmd.found].mirror != -1) + FCEU_printf(" mirror=%s", mirror_names[mirror_modes[cmds.states[cmd.found].mirror]]); + for (i = 0; i < 8; i++) + if (cmds.states[cmd.found].chrsum[i] != -1) + FCEU_printf(" chr%d=%02X", i, chr_bank[cmds.states[cmd.found].chrsum[i]]); + for (i = 0; i < 4; i++) + if (cmds.states[cmd.found].prgsum[i] != -1) + FCEU_printf(" prg%d=%02X", i, prg_bank[cmds.states[cmd.found].prgsum[i]]); + FCEU_printf(" )\n"); + } +#endif +static void Sync() { + setchr1r(1, 0x0000, CHRCUR(0)); + setchr1r(1, 0x0400, CHRCUR(1)); + setchr1r(1, 0x0800, CHRCUR(2)); + setchr1r(1, 0x0C00, CHRCUR(3)); + setchr1r(1, 0x1000, CHRCUR(4)); + setchr1r(1, 0x1400, CHRCUR(5)); + setchr1r(1, 0x1800, CHRCUR(6)); + setchr1r(1, 0x1C00, CHRCUR(7)); +#ifndef NO_RAM + setprg8r(1, 0x6000, 0); +#endif + setprg8r(2, 0x8000, PRGCUR(0)); + setprg8r(2, 0xA000, PRGCUR(1)); + setprg8r(2, 0xC000, PRGCUR(2)); + setprg8r(2, 0xE000, PRGCUR(3)); + setmirror(mirror_modes[state_cur.mirror]); +} +#ifndef NO_CACHE +static void UpdateCmd(uint32 val) { + int32 index; + if (cmd.size < CMD_MAX_SIZE) { + index = cmd.size++; + } else { + /* åñëè äîñòèãíóò ìàêñèìóì äëÿ êîìàíäû, âûáðîñèòü ïîñëåäíóþþ, äîáàâèòü íîâóþ, + * ïðîäîëæàòü äî áàíêñâè÷èíãà + */ + cmd.hash = 0; + for (index = 0; index < (CMD_MAX_SIZE - 1); index++) { + cmd.seq[index] = cmd.seq[index + 1]; + cmd.hash *= FNV_32_PRIME; + cmd.hash ^= cmd.seq[index]; + } + } + cmd.seq[index] = val; + cmd.hash *= FNV_32_PRIME; + cmd.hash ^= val; + cmd.hashf = (cmd.hash >> 16) ^ (cmd.hash & 0xffff); + cmd.found = cmd_cache[cmd.hashf].index; +} +#endif + +static DECLFW(MCopyFamiWrite) { +#ifndef NO_CACHE + int32 i; +#endif + +#ifdef MESSAGE_LOG + FCEU_printf("> WRITE %04X:%02X\n", A, V); +#endif + + PRGWBCmd[1] = A & 0xFF; + PRGWBCmd[2] = A >> 8; + PRGWBCmd[3] = V & 0xFF; + SEND(PRGWBCmd); +#ifdef NO_CACHE + CheckStatus(); + Sync(); +#else + UpdateCmd((A << 8) | V); + /* èùåì êîìàíäó â êåøå */ + if (cmd.found == -1) { + /* íå íàéäåíà, ïðîâåðÿåì, èçìåíèëîñü ëè ñîñòîÿíèå áàíêîâ + * ëèáî íå ïðåäåëüíîé ëè îíà äëèíû äëÿ êîìàíäû + */ + cmd_cache[cmd.hashf].index = cmd.found = cmds.count++; + cmd_cache[cmd.hashf].retest = 0; + cmd_cache[cmd.hashf].verify = 0; + for (i = 0; i < cmd.size; i++) + cmds.seqs[cmd.found][i] = cmd.seq[i]; + cmd_cache[cmd.hashf].size = cmd.size; + if (CheckStatus()) { + cmds.states[cmd.found] = state_new; + LogCmd(); + cmd.size = 0; + cmd.hash = 0; + Sync(); + } else { + /* åñëè äîáàâëåíà ïîëíàÿ êîìàíäà áåç áàíêñâèò÷èíãà */ + cmd_cache[cmd.hashf].index = -2; + } + } else if (cmd.found == -2) { + /* ÷àñòè÷íîå ñîâïàäåíèå, åñëè ÷èñëî ïðîâåðîê íå ïðåâûñèëî ëèìèò */ + if (cmd_cache[cmd.hashf].retest < CMD_MAX_RETEST) { + /* òî ïðîâåðèì ñîñòîÿíèå áàíêîâ */ + if (CheckStatus()) { + /* èçìåíèëîñü, çàïèøåì íîâóþ êîìàíäó */ + cmd_cache[cmd.hashf].index = cmd.found = cmds.count++; + cmd_cache[cmd.hashf].retest = 0; + cmd_cache[cmd.hashf].verify = 0; + for (i = 0; i < cmd.size; i++) + cmds.seqs[cmd.found][i] = cmd.seq[i]; + cmd_cache[cmd.hashf].size = cmd.size; + cmds.states[cmd.found] = state_new; + LogCmd(); + cmd.size = 0; + cmd.hash = 0; + Sync(); + } else { + /* íå èçìåíèëîñü, îòìåòèì óâåëè÷èì ñ÷åò÷èê ïðîâåðîê */ + cmd_cache[cmd.hashf].retest++; + } + } + } else { + /* íàéäåíà, ïîñëåäíèé ðóáåæ îáîðîíû îò ãîâíà */ +#if 0 + if(cmd_cache[cmd.hashf].verify < CMD_MAX_VERIFY) { + if(CheckStatus()) { + int32 changed = 0; + if(cmds.states[cmd.found].mirror != state_new.mirror) + changed = 1; + for(i=0; i<8; i++) + if(cmds.states[cmd.found].chrsum[i] != state_new.chrsum[i]) + changed = 1; + for(i=0; i<4; i++) + if(cmds.states[cmd.found].prgsum[i] != state_new.prgsum[i]) + changed = 1; + if(changed) { + cmd_cache[cmd.hashf].index = -1; + cmd_cache[cmd.hashf].retest = 0; + cmd_cache[cmd.hashf].verify = 0; + Sync(); + } + } else + cmd_cache[cmd.hashf].verify++; + } else +#endif + { + /* ïðèìåíÿåì áåç ìàëåéøåãî çàçðåíèÿ ñîâåñòè */ + ApplyStatus(); + cmd.size = 0; + cmd.hash = 0; + } + } +#endif +} + +static DECLFR(MCopyFamiRead) { + uint8 result; + PRGRBCmd[1] = A & 0xFF; + PRGRBCmd[2] = A >> 8; + SENDGET(PRGRBCmd, result, 1); +#ifdef MESSAGE_LOG + FCEU_printf("> READ %04X:%02X\n", A, result); +#endif + return result; +} + +static void MCopyFamiReset(void) { + state_cur = state_def; + Sync(); +} + +static void MCopyFamiPower(void) { +/* uint32 resp, presp; */ + + FCEU_printf("NOW POWERING... "); + + Sync(); + + SetWriteHandler(0x4018, 0x7fff, MCopyFamiWrite); + SetReadHandler(0x4018, 0x7fff, MCopyFamiRead); +#ifndef NO_RAM + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x6000, 0x7fff, CartBR); +#endif + +#if 0 + FCEU_printf("READING MEMORY MAP...\n"); + CPUTestCmd[1] = 0x50; + CPUTestCmd[2] = 0x30; + SEND(CPUTestCmd); + resp = 0; + presp = 0xffffffff; + while (presp != 0x00ff0000) { + GET(resp, 3); + if(presp != 0xffffffff) { + switch(presp & 0x00FF0000) { + case 0x00000000: /* BUS */ + FCEU_printf(" %04X-%04X OPEN BUS\n",presp & 0x7fff, (resp - 1) & 0x7fff); + break; + case 0x00010000: /* RAM */ + FCEU_printf(" %04X-%04X RAM\n",presp & 0x7fff, (resp - 1) & 0x7fff); + SetWriteHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBW); + SetReadHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBR); + break; + } + } + presp = resp; + } +#endif + SetWriteHandler(0x8000, 0xffff, MCopyFamiWrite); + SetReadHandler(0x8000, 0xffff, CartBR); + + FCEU_printf("DONE!\nNOW COLLECTING DATA...\n"); +} + +static void MCopyFamiClose(void) { + if (chr_data.buf) + FCEU_gfree(chr_data.buf); + chr_data.buf = NULL; + if (prg_data.buf) + FCEU_gfree(prg_data.buf); + prg_data.buf = NULL; + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; + + SerialClose(); +} + +static void StateRestore(int version) { + Sync(); +} + +void MapperCopyFami_Init(CartInfo *info) { + uint32 resp = 0, i, size; + + memset(chr_bank, -1, sizeof(chr_bank)); + memset(prg_bank, -1, sizeof(chr_bank)); + memset(cmd_cache, -1, sizeof(cmd_cache)); + memset(&cmds, 0, sizeof(cmds)); + memset(&cmd, 0, sizeof(cmd)); + + info->Reset = MCopyFamiReset; + info->Power = MCopyFamiPower; + info->Close = MCopyFamiClose; + GameStateRestore = StateRestore; + + size = 1024 * CHR_CACHE_SIZE; /* ðàçìåð ñòðàíèöû 1êá */ + chr_data.buf = (uint8*)FCEU_gmalloc(size); + SetupCartCHRMapping(1, chr_data.buf, size, 1); /* ïðîâåðÿòü ïïó ðàì, èíà÷å èãðà ìîæåò ïîðòèòü äàííûå */ + AddExState(chr_data.buf, size, 0, "CCHR"); + + size = 8192; /* ðàçìåð ñòðàíèöû 8êá */ + WRAM = (uint8*)FCEU_gmalloc(size); + SetupCartPRGMapping(1, WRAM, size, 1); + AddExState(WRAM, size, 0, "CPRM"); + + size = 8192 * PRG_CACHE_SIZE; /* ðàçìåð ñòðàíèöû 8êá */ + prg_data.buf = (uint8*)FCEU_gmalloc(size); + SetupCartPRGMapping(2, prg_data.buf, size, 0); + AddExState(prg_data.buf, size, 0, "CPPR"); + + + FCEU_printf("WAITING FOR SERIAL PORT... "); + while (!SerialOpen(19, 921600)) { + Sleep(500); + } + FCEU_printf("READY!\n"); + + FCEU_printf("WAITING FOR DEVICE... "); + + while (resp != *(uint32*)&InitVector[0]) { + SEND(ResetCmd); + SENDGET(InitVector, resp, 4); + Sleep(500); + } + + FCEU_printf("READY!\n"); + FCEU_printf("READING STATUS...\n"); + GetStatus(&state_cur); + FCEU_printf("MIRRORING IS %s (%02X)\n", mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); + FCEU_printf("READING CHR...\n INITIAL STATE:"); + + for (i = 0; i < 8; i++) { + if (CHRCUR(i) == -1) + CHRCUR(i) = FetchNewCHRBank(i); + FCEU_printf(" CHR%d=%02X", i, CHRCUR(i)); + } + FCEU_printf("\n"); + + FCEU_printf("READING PRG...\n INITIAL STATE:"); + for (i = 0; i < 4; i++) { + if (PRGCUR(i) == -1) + PRGCUR(i) = FetchNewPRGBank(i); + FCEU_printf(" PRG%d=%02X", i, PRGCUR(i)); + } + FCEU_printf("\nDONE!\n"); + + state_def = state_cur; + + AddExState(&StateRegs, ~0, 0, 0); +} + +#endif diff --git a/src/boards/dance2000.c b/src/boards/dance2000.c index 78fc4b7..a8a90f6 100644 --- a/src/boards/dance2000.c +++ b/src/boards/dance2000.c @@ -1,113 +1,113 @@ -/* 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 - * - * Dance 2000 12-in-1 - * - */ - -#include "mapinc.h" - -static uint8 prg, mode; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static uint32 lastnt = 0; - -static SFORMAT StateRegs[] = -{ - { &prg, 1, "REGS" }, - { &mode, 1, "MODE" }, - { &lastnt, 4, "LSNT" }, - { 0 } -}; - -static void Sync(void) { - setmirror((mode ^ 1) & 1); - setprg8r(0x10, 0x6000, 0); - setchr4(0x0000, lastnt); - setchr4(0x1000, 1); - if (mode & 4) - setprg32(0x8000, prg & 7); - else { - setprg16(0x8000, prg & 0x0f); - setprg16(0xC000, 0); - } -} - -static DECLFW(UNLD2000Write) { - switch (A) { - case 0x5000: prg = V; Sync(); break; - case 0x5200: mode = V; if (mode & 4) Sync(); break; - } -} - -static DECLFR(UNLD2000Read) { - if (prg & 0x40) - return X.DB; - else - return CartBR(A); -} - -static void UNLD2000Power(void) { - prg = mode = 0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, UNLD2000Read); - SetWriteHandler(0x5000, 0x5FFF, UNLD2000Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void FP_FASTAPASS(1) UNL2000Hook(uint32 A) { - if (mode & 2) { - if ((A & 0x3000) == 0x2000) { - uint32 curnt = A & 0x800; - if (curnt != lastnt) { - setchr4(0x0000, curnt >> 11); - lastnt = curnt; - } - } - } else { - lastnt = 0; - setchr4(0x0000, 0); - } -} - -static void UNLD2000Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLD2000_Init(CartInfo *info) { - info->Power = UNLD2000Power; - info->Close = UNLD2000Close; - PPU_hook = UNL2000Hook; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 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 + * + * Dance 2000 12-in-1 + * + */ + +#include "mapinc.h" + +static uint8 prg, mode; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint32 lastnt = 0; + +static SFORMAT StateRegs[] = +{ + { &prg, 1, "REGS" }, + { &mode, 1, "MODE" }, + { &lastnt, 4, "LSNT" }, + { 0 } +}; + +static void Sync(void) { + setmirror((mode ^ 1) & 1); + setprg8r(0x10, 0x6000, 0); + setchr4(0x0000, lastnt); + setchr4(0x1000, 1); + if (mode & 4) + setprg32(0x8000, prg & 7); + else { + setprg16(0x8000, prg & 0x0f); + setprg16(0xC000, 0); + } +} + +static DECLFW(UNLD2000Write) { + switch (A) { + case 0x5000: prg = V; Sync(); break; + case 0x5200: mode = V; if (mode & 4) Sync(); break; + } +} + +static DECLFR(UNLD2000Read) { + if (prg & 0x40) + return X.DB; + else + return CartBR(A); +} + +static void UNLD2000Power(void) { + prg = mode = 0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, UNLD2000Read); + SetWriteHandler(0x5000, 0x5FFF, UNLD2000Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void FP_FASTAPASS(1) UNL2000Hook(uint32 A) { + if (mode & 2) { + if ((A & 0x3000) == 0x2000) { + uint32 curnt = A & 0x800; + if (curnt != lastnt) { + setchr4(0x0000, curnt >> 11); + lastnt = curnt; + } + } + } else { + lastnt = 0; + setchr4(0x0000, 0); + } +} + +static void UNLD2000Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLD2000_Init(CartInfo *info) { + info->Power = UNLD2000Power; + info->Close = UNLD2000Close; + PPU_hook = UNL2000Hook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/datalatch.c b/src/boards/datalatch.c index c57b624..6ad608e 100644 --- a/src/boards/datalatch.c +++ b/src/boards/datalatch.c @@ -1,510 +1,510 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel - * - * 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 "../ines.h" - -static uint8 latche, latcheinit, bus_conflict; -static uint16 addrreg0, addrreg1; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static void (*WSync)(void); - -static DECLFW(LatchWrite) { -/* FCEU_printf("bs %04x %02x\n",A,V); */ - if (bus_conflict) - latche = V & CartBR(A); - else - latche = V; - WSync(); -} - -static void LatchPower(void) { - latche = latcheinit; - WSync(); - if (WRAM) { - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - } else { - SetReadHandler(0x8000, 0xFFFF, CartBR); - } - SetWriteHandler(addrreg0, addrreg1, LatchWrite); -} - -static void LatchClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - WSync(); -} - -static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc) { - bus_conflict = busc; - latcheinit = init; - addrreg0 = adr0; - addrreg1 = adr1; - WSync = proc; - info->Power = LatchPower; - info->Close = LatchClose; - GameStateRestore = StateRestore; - if (wram) { - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - } - AddExState(&latche, 1, 0, "LATC"); - AddExState(&bus_conflict, 1, 0, "BUSC"); -} - -/*------------------ Map 0 ---------------------------*/ - -#ifdef DEBUG_MAPPER -static DECLFW(NROMWrite) { - FCEU_printf("bs %04x %02x\n", A, V); - CartBW(A, V); -} -#endif - -static void NROMPower(void) { - setprg8r(0x10, 0x6000, 0); /* Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB */ - setprg16(0x8000, 0); - setprg16(0xC000, ~0); - setchr8(0); - - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - - #ifdef DEBUG_MAPPER - SetWriteHandler(0x4020, 0xFFFF, NROMWrite); - #endif -} - -void NROM_Init(CartInfo *info) { - info->Power = NROMPower; - info->Close = LatchClose; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); -} - -/*------------------ Map 2 ---------------------------*/ - -static void UNROMSync(void) { -#if 0 - static uint32 mirror_in_use = 0; - if (PRGsize[0] <= 128 * 1024) { - setprg16(0x8000, latche & 0x7); - if ((latche & 0xF8) == 0x08) mirror_in_use = 1; - if (mirror_in_use) - setmirror(((latche >> 3) & 1) ^ 1); /* Higway Star Hacked mapper to be redefined to another mapper */ - } else -#endif - setprg8r(0x10, 0x6000, 0); - setprg16(0x8000, latche); - setprg16(0xc000, ~0); - setchr8(0); -} - -void UNROM_Init(CartInfo *info) { - Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 1, 0); -} - -/*------------------ Map 3 ---------------------------*/ - -static void CNROMSync(void) { - setchr8(latche); - setprg32(0x8000, 0); - setprg8r(0x10, 0x6000, 0); /* Hayauchy IGO uses 2Kb or RAM */ -} - -void CNROM_Init(CartInfo *info) { - /* TODO: move these to extended database when implemented. */ - int _busc, x; - uint64 partialmd5 = 0; - _busc = 1; - for (x = 0; x < 8; x++) - partialmd5 |= (uint64)info->MD5[15 - x] << (x * 8); - if (partialmd5 == 0x117181328eb1ad23LL) /* 75 Bingo (Sachen-English) [U].unf */ - _busc = 0; - else - switch (info->CRC32) { - case 0xf283cf58: /* Colorful Dragon (Asia) (PAL) (Unl).nes */ - case 0x2915faf0: /* Incantation (Asia) (Unl).nes */ - case 0xebd0644d: /* Dao Shuai (Asia) (Unl).nes */ - case 0x8f154a0d: /* Pu Ke Jing Ling (China) (Unl).nes */ - case 0xd04a40e6: /* Bingo 75 (Asia) (Unl).nes */ - _busc = 0; - break; - } - Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, _busc); -} - -/*------------------ Map 7 ---------------------------*/ - -static void ANROMSync() { - setprg32(0x8000, latche & 0xF); - setmirror(MI_0 + ((latche >> 4) & 1)); - setchr8(0); -} - -void ANROM_Init(CartInfo *info) { - Latch_Init(info, ANROMSync, 0, 0x4020, 0xFFFF, 0, 0); -} - -/*------------------ Map 8 ---------------------------*/ - -static void M8Sync() { - setprg16(0x8000, latche >> 3); - setprg16(0xc000, 1); - setchr8(latche & 3); -} - -void Mapper8_Init(CartInfo *info) { - Latch_Init(info, M8Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 11 ---------------------------*/ - -static void M11Sync(void) { - setprg32(0x8000, latche & 0xF); - setchr8(latche >> 4); -} - -void Mapper11_Init(CartInfo *info) { - Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -void Mapper144_Init(CartInfo *info) { - Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0); -} - -/*------------------ Map 13 ---------------------------*/ - -static void CPROMSync(void) { - setchr4(0x0000, 0); - setchr4(0x1000, latche & 3); - setprg32(0x8000, 0); -} - -void CPROM_Init(CartInfo *info) { - Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 38 ---------------------------*/ - -static void M38Sync(void) { - setprg32(0x8000, latche & 3); - setchr8(latche >> 2); -} - -void Mapper38_Init(CartInfo *info) { - Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF, 0, 0); -} - -/*------------------ Map 66 ---------------------------*/ - -static void MHROMSync(void) { - setprg32(0x8000, latche >> 4); - setchr8(latche & 0xF); -} - -void MHROM_Init(CartInfo *info) { - Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 70 ---------------------------*/ - -static void M70Sync() { - setprg16(0x8000, latche >> 4); - setprg16(0xc000, ~0); - setchr8(latche & 0xf); -} - -void Mapper70_Init(CartInfo *info) { - Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 78 ---------------------------*/ -/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ -static void M78Sync() { - setprg16(0x8000, (latche & 7)); - setprg16(0xc000, ~0); - setchr8(latche >> 4); - setmirror(MI_0 + ((latche >> 3) & 1)); -} - -void Mapper78_Init(CartInfo *info) { - Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 86 ---------------------------*/ - -static void M86Sync(void) { - setprg32(0x8000, (latche >> 4) & 3); - setchr8((latche & 3) | ((latche >> 4) & 4)); -} - -void Mapper86_Init(CartInfo *info) { - Latch_Init(info, M86Sync, ~0, 0x6000, 0x6FFF, 0, 0); -} - -/*------------------ Map 87 ---------------------------*/ - -static void M87Sync(void) { - setprg32(0x8000, 0); - setchr8(((latche >> 1) & 1) | ((latche << 1) & 2)); -} - -void Mapper87_Init(CartInfo *info) { - Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); -} - -/*------------------ Map 89 ---------------------------*/ - -static void M89Sync(void) { - setprg16(0x8000, (latche >> 4) & 7); - setprg16(0xc000, ~0); - setchr8((latche & 7) | ((latche >> 4) & 8)); - setmirror(MI_0 + ((latche >> 3) & 1)); -} - -void Mapper89_Init(CartInfo *info) { - Latch_Init(info, M89Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 93 ---------------------------*/ - -static void SSUNROMSync(void) { - setprg16(0x8000, latche >> 4); - setprg16(0xc000, ~0); - setchr8(0); -} - -void SUNSOFT_UNROM_Init(CartInfo *info) { - Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 94 ---------------------------*/ - -static void M94Sync(void) { - setprg16(0x8000, latche >> 2); - setprg16(0xc000, ~0); - setchr8(0); -} - -void Mapper94_Init(CartInfo *info) { - Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 97 ---------------------------*/ - -static void M97Sync(void) { - setchr8(0); - setprg16(0x8000, ~0); - setprg16(0xc000, latche & 15); - switch (latche >> 6) { - case 0: break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_V); break; - case 3: break; - } - setchr8(((latche >> 1) & 1) | ((latche << 1) & 2)); -} - -void Mapper97_Init(CartInfo *info) { - Latch_Init(info, M97Sync, ~0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 101 ---------------------------*/ - -static void M101Sync(void) { - setprg32(0x8000, 0); - setchr8(latche); -} - -void Mapper101_Init(CartInfo *info) { - Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0); -} - -/*------------------ Map 107 ---------------------------*/ - -static void M107Sync(void) { - setprg32(0x8000, (latche >> 1) & 3); - setchr8(latche & 7); -} - -void Mapper107_Init(CartInfo *info) { - Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 113 ---------------------------*/ - -static void M113Sync(void) { - setprg32(0x8000, (latche >> 3) & 7); - setchr8(((latche >> 3) & 8) | (latche & 7)); -/* setmirror(latche>>7);*/ /* only for HES 6in1 */ -} - -void Mapper113_Init(CartInfo *info) { - Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0); -} - -/*------------------ Map 140 ---------------------------*/ - -void Mapper140_Init(CartInfo *info) { - Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); -} - -/*------------------ Map 152 ---------------------------*/ - -static void M152Sync() { - setprg16(0x8000, (latche >> 4) & 7); - setprg16(0xc000, ~0); - setchr8(latche & 0xf); - setmirror(MI_0 + ((latche >> 7) & 1)); /* Saint Seiya...hmm. */ -} - -void Mapper152_Init(CartInfo *info) { - Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 180 ---------------------------*/ - -static void M180Sync(void) { - setprg16(0x8000, 0); - setprg16(0xc000, latche); - setchr8(0); -} - -void Mapper180_Init(CartInfo *info) { - Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 184 ---------------------------*/ - -static void M184Sync(void) { - setchr4(0x0000, latche); - setchr4(0x1000, latche >> 4); - setprg32(0x8000, 0); -} - -void Mapper184_Init(CartInfo *info) { - Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); -} - -/*------------------ Map 203 ---------------------------*/ - -static void M203Sync(void) { - setprg16(0x8000, (latche >> 2) & 3); - setprg16(0xC000, (latche >> 2) & 3); - setchr8(latche & 3); -} - -void Mapper203_Init(CartInfo *info) { - Latch_Init(info, M203Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ Map 240 ---------------------------*/ - -static void M240Sync(void) { - setprg8r(0x10, 0x6000, 0); - setprg32(0x8000, latche >> 4); - setchr8(latche & 0xF); -} - -void Mapper240_Init(CartInfo *info) { - Latch_Init(info, M240Sync, 0, 0x4020, 0x5FFF, 1, 0); -} - -/*------------------ Map 241 ---------------------------*/ -/* Mapper 7 mostly, but with SRAM or maybe prot circuit - * figure out, which games do need 5xxx area reading - */ - -static void M241Sync(void) { - setchr8(0); - setprg8r(0x10, 0x6000, 0); - if (latche & 0x80) - setprg32(0x8000, latche | 8); /* no 241 actually, but why not afterall? */ - else - setprg32(0x8000, latche); -} - -void Mapper241_Init(CartInfo *info) { - Latch_Init(info, M241Sync, 0, 0x8000, 0xFFFF, 1, 0); -} - -/* ------------------ A65AS --------------------------- */ - -/* actually, there is two cart in one... First have extra mirroring - * mode (one screen) and 32K bankswitching, second one have only - * 16 bankswitching mode and normal mirroring... But there is no any - * correlations between modes and they can be used in one mapper code. - */ - -static void BMCA65ASSync(void) { - if (latche & 0x40) - setprg32(0x8000, (latche >> 1) & 0x0F); - else { - setprg16(0x8000, ((latche & 0x30) >> 1) | (latche & 7)); - setprg16(0xC000, ((latche & 0x30) >> 1) | 7); - } - setchr8(0); - if (latche & 0x80) - setmirror(MI_0 + (((latche >> 5) & 1))); - else - setmirror(((latche >> 3) & 1) ^ 1); -} - -void BMCA65AS_Init(CartInfo *info) { - Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -/*------------------ BMC-11160 ---------------------------*/ -/* Simple BMC discrete mapper by TXC */ - -static void BMC11160Sync(void) { - uint32 bank = (latche >> 4) & 7; - setprg32(0x8000, bank); - setchr8((bank << 2) | (latche & 3)); - setmirror((latche >> 7) & 1); -} - -void BMC11160_Init(CartInfo *info) { - Latch_Init(info, BMC11160Sync, 0, 0x8000, 0xFFFF, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 "../ines.h" + +static uint8 latche, latcheinit, bus_conflict; +static uint16 addrreg0, addrreg1; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static void (*WSync)(void); + +static DECLFW(LatchWrite) { +/* FCEU_printf("bs %04x %02x\n",A,V); */ + if (bus_conflict) + latche = V & CartBR(A); + else + latche = V; + WSync(); +} + +static void LatchPower(void) { + latche = latcheinit; + WSync(); + if (WRAM) { + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + } else { + SetReadHandler(0x8000, 0xFFFF, CartBR); + } + SetWriteHandler(addrreg0, addrreg1, LatchWrite); +} + +static void LatchClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc) { + bus_conflict = busc; + latcheinit = init; + addrreg0 = adr0; + addrreg1 = adr1; + WSync = proc; + info->Power = LatchPower; + info->Close = LatchClose; + GameStateRestore = StateRestore; + if (wram) { + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + } + AddExState(&latche, 1, 0, "LATC"); + AddExState(&bus_conflict, 1, 0, "BUSC"); +} + +/*------------------ Map 0 ---------------------------*/ + +#ifdef DEBUG_MAPPER +static DECLFW(NROMWrite) { + FCEU_printf("bs %04x %02x\n", A, V); + CartBW(A, V); +} +#endif + +static void NROMPower(void) { + setprg8r(0x10, 0x6000, 0); /* Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB */ + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); + + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + + #ifdef DEBUG_MAPPER + SetWriteHandler(0x4020, 0xFFFF, NROMWrite); + #endif +} + +void NROM_Init(CartInfo *info) { + info->Power = NROMPower; + info->Close = LatchClose; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} + +/*------------------ Map 2 ---------------------------*/ + +static void UNROMSync(void) { +#if 0 + static uint32 mirror_in_use = 0; + if (PRGsize[0] <= 128 * 1024) { + setprg16(0x8000, latche & 0x7); + if ((latche & 0xF8) == 0x08) mirror_in_use = 1; + if (mirror_in_use) + setmirror(((latche >> 3) & 1) ^ 1); /* Higway Star Hacked mapper to be redefined to another mapper */ + } else +#endif + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, latche); + setprg16(0xc000, ~0); + setchr8(0); +} + +void UNROM_Init(CartInfo *info) { + Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 1, 0); +} + +/*------------------ Map 3 ---------------------------*/ + +static void CNROMSync(void) { + setchr8(latche); + setprg32(0x8000, 0); + setprg8r(0x10, 0x6000, 0); /* Hayauchy IGO uses 2Kb or RAM */ +} + +void CNROM_Init(CartInfo *info) { + /* TODO: move these to extended database when implemented. */ + int _busc, x; + uint64 partialmd5 = 0; + _busc = 1; + for (x = 0; x < 8; x++) + partialmd5 |= (uint64)info->MD5[15 - x] << (x * 8); + if (partialmd5 == 0x117181328eb1ad23LL) /* 75 Bingo (Sachen-English) [U].unf */ + _busc = 0; + else + switch (info->CRC32) { + case 0xf283cf58: /* Colorful Dragon (Asia) (PAL) (Unl).nes */ + case 0x2915faf0: /* Incantation (Asia) (Unl).nes */ + case 0xebd0644d: /* Dao Shuai (Asia) (Unl).nes */ + case 0x8f154a0d: /* Pu Ke Jing Ling (China) (Unl).nes */ + case 0xd04a40e6: /* Bingo 75 (Asia) (Unl).nes */ + _busc = 0; + break; + } + Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, _busc); +} + +/*------------------ Map 7 ---------------------------*/ + +static void ANROMSync() { + setprg32(0x8000, latche & 0xF); + setmirror(MI_0 + ((latche >> 4) & 1)); + setchr8(0); +} + +void ANROM_Init(CartInfo *info) { + Latch_Init(info, ANROMSync, 0, 0x4020, 0xFFFF, 0, 0); +} + +/*------------------ Map 8 ---------------------------*/ + +static void M8Sync() { + setprg16(0x8000, latche >> 3); + setprg16(0xc000, 1); + setchr8(latche & 3); +} + +void Mapper8_Init(CartInfo *info) { + Latch_Init(info, M8Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 11 ---------------------------*/ + +static void M11Sync(void) { + setprg32(0x8000, latche & 0xF); + setchr8(latche >> 4); +} + +void Mapper11_Init(CartInfo *info) { + Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +void Mapper144_Init(CartInfo *info) { + Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0); +} + +/*------------------ Map 13 ---------------------------*/ + +static void CPROMSync(void) { + setchr4(0x0000, 0); + setchr4(0x1000, latche & 3); + setprg32(0x8000, 0); +} + +void CPROM_Init(CartInfo *info) { + Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 38 ---------------------------*/ + +static void M38Sync(void) { + setprg32(0x8000, latche & 3); + setchr8(latche >> 2); +} + +void Mapper38_Init(CartInfo *info) { + Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF, 0, 0); +} + +/*------------------ Map 66 ---------------------------*/ + +static void MHROMSync(void) { + setprg32(0x8000, latche >> 4); + setchr8(latche & 0xF); +} + +void MHROM_Init(CartInfo *info) { + Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 70 ---------------------------*/ + +static void M70Sync() { + setprg16(0x8000, latche >> 4); + setprg16(0xc000, ~0); + setchr8(latche & 0xf); +} + +void Mapper70_Init(CartInfo *info) { + Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 78 ---------------------------*/ +/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ +static void M78Sync() { + setprg16(0x8000, (latche & 7)); + setprg16(0xc000, ~0); + setchr8(latche >> 4); + setmirror(MI_0 + ((latche >> 3) & 1)); +} + +void Mapper78_Init(CartInfo *info) { + Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 86 ---------------------------*/ + +static void M86Sync(void) { + setprg32(0x8000, (latche >> 4) & 3); + setchr8((latche & 3) | ((latche >> 4) & 4)); +} + +void Mapper86_Init(CartInfo *info) { + Latch_Init(info, M86Sync, ~0, 0x6000, 0x6FFF, 0, 0); +} + +/*------------------ Map 87 ---------------------------*/ + +static void M87Sync(void) { + setprg32(0x8000, 0); + setchr8(((latche >> 1) & 1) | ((latche << 1) & 2)); +} + +void Mapper87_Init(CartInfo *info) { + Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); +} + +/*------------------ Map 89 ---------------------------*/ + +static void M89Sync(void) { + setprg16(0x8000, (latche >> 4) & 7); + setprg16(0xc000, ~0); + setchr8((latche & 7) | ((latche >> 4) & 8)); + setmirror(MI_0 + ((latche >> 3) & 1)); +} + +void Mapper89_Init(CartInfo *info) { + Latch_Init(info, M89Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 93 ---------------------------*/ + +static void SSUNROMSync(void) { + setprg16(0x8000, latche >> 4); + setprg16(0xc000, ~0); + setchr8(0); +} + +void SUNSOFT_UNROM_Init(CartInfo *info) { + Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 94 ---------------------------*/ + +static void M94Sync(void) { + setprg16(0x8000, latche >> 2); + setprg16(0xc000, ~0); + setchr8(0); +} + +void Mapper94_Init(CartInfo *info) { + Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 97 ---------------------------*/ + +static void M97Sync(void) { + setchr8(0); + setprg16(0x8000, ~0); + setprg16(0xc000, latche & 15); + switch (latche >> 6) { + case 0: break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_V); break; + case 3: break; + } + setchr8(((latche >> 1) & 1) | ((latche << 1) & 2)); +} + +void Mapper97_Init(CartInfo *info) { + Latch_Init(info, M97Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 101 ---------------------------*/ + +static void M101Sync(void) { + setprg32(0x8000, 0); + setchr8(latche); +} + +void Mapper101_Init(CartInfo *info) { + Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0); +} + +/*------------------ Map 107 ---------------------------*/ + +static void M107Sync(void) { + setprg32(0x8000, (latche >> 1) & 3); + setchr8(latche & 7); +} + +void Mapper107_Init(CartInfo *info) { + Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 113 ---------------------------*/ + +static void M113Sync(void) { + setprg32(0x8000, (latche >> 3) & 7); + setchr8(((latche >> 3) & 8) | (latche & 7)); +/* setmirror(latche>>7);*/ /* only for HES 6in1 */ +} + +void Mapper113_Init(CartInfo *info) { + Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0); +} + +/*------------------ Map 140 ---------------------------*/ + +void Mapper140_Init(CartInfo *info) { + Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); +} + +/*------------------ Map 152 ---------------------------*/ + +static void M152Sync() { + setprg16(0x8000, (latche >> 4) & 7); + setprg16(0xc000, ~0); + setchr8(latche & 0xf); + setmirror(MI_0 + ((latche >> 7) & 1)); /* Saint Seiya...hmm. */ +} + +void Mapper152_Init(CartInfo *info) { + Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 180 ---------------------------*/ + +static void M180Sync(void) { + setprg16(0x8000, 0); + setprg16(0xc000, latche); + setchr8(0); +} + +void Mapper180_Init(CartInfo *info) { + Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 184 ---------------------------*/ + +static void M184Sync(void) { + setchr4(0x0000, latche); + setchr4(0x1000, latche >> 4); + setprg32(0x8000, 0); +} + +void Mapper184_Init(CartInfo *info) { + Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); +} + +/*------------------ Map 203 ---------------------------*/ + +static void M203Sync(void) { + setprg16(0x8000, (latche >> 2) & 3); + setprg16(0xC000, (latche >> 2) & 3); + setchr8(latche & 3); +} + +void Mapper203_Init(CartInfo *info) { + Latch_Init(info, M203Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ Map 240 ---------------------------*/ + +static void M240Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg32(0x8000, latche >> 4); + setchr8(latche & 0xF); +} + +void Mapper240_Init(CartInfo *info) { + Latch_Init(info, M240Sync, 0, 0x4020, 0x5FFF, 1, 0); +} + +/*------------------ Map 241 ---------------------------*/ +/* Mapper 7 mostly, but with SRAM or maybe prot circuit + * figure out, which games do need 5xxx area reading + */ + +static void M241Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + if (latche & 0x80) + setprg32(0x8000, latche | 8); /* no 241 actually, but why not afterall? */ + else + setprg32(0x8000, latche); +} + +void Mapper241_Init(CartInfo *info) { + Latch_Init(info, M241Sync, 0, 0x8000, 0xFFFF, 1, 0); +} + +/* ------------------ A65AS --------------------------- */ + +/* actually, there is two cart in one... First have extra mirroring + * mode (one screen) and 32K bankswitching, second one have only + * 16 bankswitching mode and normal mirroring... But there is no any + * correlations between modes and they can be used in one mapper code. + */ + +static void BMCA65ASSync(void) { + if (latche & 0x40) + setprg32(0x8000, (latche >> 1) & 0x0F); + else { + setprg16(0x8000, ((latche & 0x30) >> 1) | (latche & 7)); + setprg16(0xC000, ((latche & 0x30) >> 1) | 7); + } + setchr8(0); + if (latche & 0x80) + setmirror(MI_0 + (((latche >> 5) & 1))); + else + setmirror(((latche >> 3) & 1) ^ 1); +} + +void BMCA65AS_Init(CartInfo *info) { + Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +/*------------------ BMC-11160 ---------------------------*/ +/* Simple BMC discrete mapper by TXC */ + +static void BMC11160Sync(void) { + uint32 bank = (latche >> 4) & 7; + setprg32(0x8000, bank); + setchr8((bank << 2) | (latche & 3)); + setmirror((latche >> 7) & 1); +} + +void BMC11160_Init(CartInfo *info) { + Latch_Init(info, BMC11160Sync, 0, 0x8000, 0xFFFF, 0, 0); +} diff --git a/src/boards/dream.c b/src/boards/dream.c index c42fa0f..bdc4394 100644 --- a/src/boards/dream.c +++ b/src/boards/dream.c @@ -1,51 +1,51 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" - -static uint8 latche; - -static void Sync(void) { - setprg16(0x8000, latche); - setprg16(0xC000, 8); -} - -static DECLFW(DREAMWrite) { - latche = V & 7; - Sync(); -} - -static void DREAMPower(void) { - latche = 0; - Sync(); - setchr8(0); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x5020, 0x5020, DREAMWrite); -} - -static void Restore(int version) { - Sync(); -} - -void DreamTech01_Init(CartInfo *info) { - GameStateRestore = Restore; - info->Power = DREAMPower; - AddExState(&latche, 1, 0, "LATC"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" + +static uint8 latche; + +static void Sync(void) { + setprg16(0x8000, latche); + setprg16(0xC000, 8); +} + +static DECLFW(DREAMWrite) { + latche = V & 7; + Sync(); +} + +static void DREAMPower(void) { + latche = 0; + Sync(); + setchr8(0); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x5020, 0x5020, DREAMWrite); +} + +static void Restore(int version) { + Sync(); +} + +void DreamTech01_Init(CartInfo *info) { + GameStateRestore = Restore; + info->Power = DREAMPower; + AddExState(&latche, 1, 0, "LATC"); +} diff --git a/src/boards/edu2000.c b/src/boards/edu2000.c index 2a66a14..b8dd5bc 100644 --- a/src/boards/edu2000.c +++ b/src/boards/edu2000.c @@ -1,78 +1,78 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - */ - -#include "mapinc.h" - -static uint8 *WRAM = NULL; -static uint8 reg; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setchr8(0); - setprg8r(0x10, 0x6000, (reg & 0xC0) >> 6); - setprg32(0x8000, reg & 0x1F); -/* setmirror(((reg&0x20)>>5)); */ -} - -static DECLFW(UNLEDU2000HiWrite) { -/* FCEU_printf("%04x:%02x\n",A,V); */ - reg = V; - Sync(); -} - -static void UNLEDU2000Power(void) { - setmirror(MI_0); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0xFFFF, CartBW); - SetWriteHandler(0x8000, 0xFFFF, UNLEDU2000HiWrite); - FCEU_CheatAddRAM(32, 0x6000, WRAM); - reg = 0; - Sync(); -} - -static void UNLEDU2000Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void UNLEDU2000Restore(int version) { - Sync(); -} - -void UNLEDU2000_Init(CartInfo *info) { - info->Power = UNLEDU2000Power; - info->Close = UNLEDU2000Close; - GameStateRestore = UNLEDU2000Restore; - WRAM = (uint8*)FCEU_gmalloc(32768); - SetupCartPRGMapping(0x10, WRAM, 32768, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = 32768; - } - AddExState(WRAM, 32768, 0, "WRAM"); - AddExState(StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + */ + +#include "mapinc.h" + +static uint8 *WRAM = NULL; +static uint8 reg; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, (reg & 0xC0) >> 6); + setprg32(0x8000, reg & 0x1F); +/* setmirror(((reg&0x20)>>5)); */ +} + +static DECLFW(UNLEDU2000HiWrite) { +/* FCEU_printf("%04x:%02x\n",A,V); */ + reg = V; + Sync(); +} + +static void UNLEDU2000Power(void) { + setmirror(MI_0); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0xFFFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, UNLEDU2000HiWrite); + FCEU_CheatAddRAM(32, 0x6000, WRAM); + reg = 0; + Sync(); +} + +static void UNLEDU2000Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void UNLEDU2000Restore(int version) { + Sync(); +} + +void UNLEDU2000_Init(CartInfo *info) { + info->Power = UNLEDU2000Power; + info->Close = UNLEDU2000Close; + GameStateRestore = UNLEDU2000Restore; + WRAM = (uint8*)FCEU_gmalloc(32768); + SetupCartPRGMapping(0x10, WRAM, 32768, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = 32768; + } + AddExState(WRAM, 32768, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/src/boards/famicombox.c b/src/boards/famicombox.c index f72916b..67d9be1 100644 --- a/src/boards/famicombox.c +++ b/src/boards/famicombox.c @@ -1,120 +1,120 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - */ - -#include "mapinc.h" - -static uint8 regs[8]; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { regs, 8, "REGS" }, - { 0 } -}; - -static void Sync(void) { - setprg2r(0x10, 0x0800, 0); - setprg2r(0x10, 0x1000, 1); - setprg2r(0x10, 0x1800, 2); - setprg8r(0x10, 0x6000, 1); - setprg16(0x8000, 0); - setprg16(0xC000, ~0); - setchr8(0); -} - -#if 0 - static DECLFW(SSSNROMWrite) -{ - CartBW(A,V); -} -#endif - -static DECLFW(SSSNROMWrite) { -#if 0 - FCEU_printf("write %04x %02x\n",A,V); - regs[A&7] = V; -#endif -} - -static DECLFR(SSSNROMRead) { -/* FCEU_printf("read %04x\n",A); */ - switch (A & 7) { - case 0: return regs[0] = 0xff; /* clear all exceptions */ - case 2: return 0xc0; /* DIP selftest + freeplay */ - case 3: return 0x00; /* 0, 1 - attract - * 2 - * 4 - menu - * 8 - self check and game casette check - * 10 - lock? - * 20 - game title & count display - */ - case 7: return 0x22; /* TV type, key not turned, relay B */ - default: return 0; - } -} - -static void SSSNROMPower(void) { - regs[0] = regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = regs[6] = 0; - regs[7] = 0xff; - Sync(); - memset(WRAM, 0x00, WRAMSIZE); -/* SetWriteHandler(0x0000,0x1FFF,SSSNROMRamWrite); */ - SetReadHandler(0x0800, 0x1FFF, CartBR); - SetWriteHandler(0x0800, 0x1FFF, CartBW); - SetReadHandler(0x5000, 0x5FFF, SSSNROMRead); - SetWriteHandler(0x5000, 0x5FFF, SSSNROMWrite); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void SSSNROMReset(void) { - regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = regs[6] = 0; -} - -static void SSSNROMClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void SSSNROMIRQHook(void) { -/* X6502_IRQBegin(FCEU_IQEXT); */ -} - -static void StateRestore(int version) { - Sync(); -} - -void SSSNROM_Init(CartInfo *info) { - info->Reset = SSSNROMReset; - info->Power = SSSNROMPower; - info->Close = SSSNROMClose; - GameHBIRQHook = SSSNROMIRQHook; - GameStateRestore = StateRestore; - - WRAMSIZE = 16384; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + */ + +#include "mapinc.h" + +static uint8 regs[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0x10, 0x0800, 0); + setprg2r(0x10, 0x1000, 1); + setprg2r(0x10, 0x1800, 2); + setprg8r(0x10, 0x6000, 1); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); +} + +#if 0 + static DECLFW(SSSNROMWrite) +{ + CartBW(A,V); +} +#endif + +static DECLFW(SSSNROMWrite) { +#if 0 + FCEU_printf("write %04x %02x\n",A,V); + regs[A&7] = V; +#endif +} + +static DECLFR(SSSNROMRead) { +/* FCEU_printf("read %04x\n",A); */ + switch (A & 7) { + case 0: return regs[0] = 0xff; /* clear all exceptions */ + case 2: return 0xc0; /* DIP selftest + freeplay */ + case 3: return 0x00; /* 0, 1 - attract + * 2 + * 4 - menu + * 8 - self check and game casette check + * 10 - lock? + * 20 - game title & count display + */ + case 7: return 0x22; /* TV type, key not turned, relay B */ + default: return 0; + } +} + +static void SSSNROMPower(void) { + regs[0] = regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = regs[6] = 0; + regs[7] = 0xff; + Sync(); + memset(WRAM, 0x00, WRAMSIZE); +/* SetWriteHandler(0x0000,0x1FFF,SSSNROMRamWrite); */ + SetReadHandler(0x0800, 0x1FFF, CartBR); + SetWriteHandler(0x0800, 0x1FFF, CartBW); + SetReadHandler(0x5000, 0x5FFF, SSSNROMRead); + SetWriteHandler(0x5000, 0x5FFF, SSSNROMWrite); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void SSSNROMReset(void) { + regs[1] = regs[2] = regs[3] = regs[4] = regs[5] = regs[6] = 0; +} + +static void SSSNROMClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void SSSNROMIRQHook(void) { +/* X6502_IRQBegin(FCEU_IQEXT); */ +} + +static void StateRestore(int version) { + Sync(); +} + +void SSSNROM_Init(CartInfo *info) { + info->Reset = SSSNROMReset; + info->Power = SSSNROMPower; + info->Close = SSSNROMClose; + GameHBIRQHook = SSSNROMIRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 16384; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/ffe.c b/src/boards/ffe.c index ff68125..5b80e9c 100644 --- a/src/boards/ffe.c +++ b/src/boards/ffe.c @@ -1,153 +1,153 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * FFE Copier Mappers - * - */ - -#include "mapinc.h" - -static uint8 preg[4], creg[8], latch, ffemode; -static uint8 IRQa, mirr; -static int32 IRQCount, IRQLatch; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { preg, 4, "PREG" }, - { creg, 8, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { &IRQLatch, 4, "IRQL" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0x10, 0x6000, 0); - if (ffemode) { - int i; - for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, preg[3]); - } else { - setchr8(latch & 3); - setprg16(0x8000, (latch >> 2) & 0x3F); - setprg16(0xc000, 0x7); - } - switch (mirr) { - case 0: setmirror(MI_0); break; - case 1: setmirror(MI_1); break; - case 2: setmirror(MI_V); break; - case 3: setmirror(MI_H); break; - } -} - -static DECLFW(FFEWriteMirr) { - mirr = ((A << 1) & 2) | ((V >> 4) & 1); - Sync(); -} - -static DECLFW(FFEWriteIRQ) { - switch (A) { - case 0x4501: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0x4502: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0x4503: IRQCount &= 0x00FF; IRQCount |= V << 8; IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; - } -} - -static DECLFW(FFEWritePrg) { - preg[A & 3] = V; - Sync(); -} - -static DECLFW(FFEWriteChr) { - creg[A & 7] = V; - Sync(); -} - -static DECLFW(FFEWriteLatch) { - latch = V; - Sync(); -} - -static void FFEPower(void) { - preg[3] = ~0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x42FE, 0x42FF, FFEWriteMirr); - SetWriteHandler(0x4500, 0x4503, FFEWriteIRQ); - SetWriteHandler(0x4504, 0x4507, FFEWritePrg); - SetWriteHandler(0x4510, 0x4517, FFEWriteChr); - SetWriteHandler(0x4510, 0x4517, FFEWriteChr); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, FFEWriteLatch); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void FP_FASTAPASS(1) FFEIRQHook(int a) { - if (IRQa) { - IRQCount += a; - if (IRQCount >= 0x10000) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - IRQCount = 0; - } - } -} - -static void FFEClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper6_Init(CartInfo *info) { - ffemode = 0; - mirr = ((info->mirror & 1) ^ 1) | 2; - - info->Power = FFEPower; - info->Close = FFEClose; - MapIRQHook = FFEIRQHook; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper17_Init(CartInfo *info) { - ffemode = 1; - Mapper6_Init(info); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FFE Copier Mappers + * + */ + +#include "mapinc.h" + +static uint8 preg[4], creg[8], latch, ffemode; +static uint8 IRQa, mirr; +static int32 IRQCount, IRQLatch; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { &IRQLatch, 4, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + if (ffemode) { + int i; + for (i = 0; i < 8; i++) setchr1(i << 10, creg[i]); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, preg[3]); + } else { + setchr8(latch & 3); + setprg16(0x8000, (latch >> 2) & 0x3F); + setprg16(0xc000, 0x7); + } + switch (mirr) { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + } +} + +static DECLFW(FFEWriteMirr) { + mirr = ((A << 1) & 2) | ((V >> 4) & 1); + Sync(); +} + +static DECLFW(FFEWriteIRQ) { + switch (A) { + case 0x4501: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4502: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4503: IRQCount &= 0x00FF; IRQCount |= V << 8; IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static DECLFW(FFEWritePrg) { + preg[A & 3] = V; + Sync(); +} + +static DECLFW(FFEWriteChr) { + creg[A & 7] = V; + Sync(); +} + +static DECLFW(FFEWriteLatch) { + latch = V; + Sync(); +} + +static void FFEPower(void) { + preg[3] = ~0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x42FE, 0x42FF, FFEWriteMirr); + SetWriteHandler(0x4500, 0x4503, FFEWriteIRQ); + SetWriteHandler(0x4504, 0x4507, FFEWritePrg); + SetWriteHandler(0x4510, 0x4517, FFEWriteChr); + SetWriteHandler(0x4510, 0x4517, FFEWriteChr); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, FFEWriteLatch); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void FP_FASTAPASS(1) FFEIRQHook(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount >= 0x10000) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0; + } + } +} + +static void FFEClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper6_Init(CartInfo *info) { + ffemode = 0; + mirr = ((info->mirror & 1) ^ 1) | 2; + + info->Power = FFEPower; + info->Close = FFEClose; + MapIRQHook = FFEIRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper17_Init(CartInfo *info) { + ffemode = 1; + Mapper6_Init(info); +} diff --git a/src/boards/ghostbusters63in1.c b/src/boards/ghostbusters63in1.c index 82568a7..2ca6ee1 100644 --- a/src/boards/ghostbusters63in1.c +++ b/src/boards/ghostbusters63in1.c @@ -1,96 +1,96 @@ -/* 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) { - setprg16r(banks[bank], 0x8000, reg[0] & 0x1F); - setprg16r(banks[bank], 0xC000, reg[0] & 0x1F); - } else - setprg32r(banks[bank], 0x8000, (reg[0] >> 1) & 0x0F); - 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); -} +/* 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) { + setprg16r(banks[bank], 0x8000, reg[0] & 0x1F); + setprg16r(banks[bank], 0xC000, reg[0] & 0x1F); + } else + setprg32r(banks[bank], 0x8000, (reg[0] >> 1) & 0x0F); + 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/boards/gs-2004.c b/src/boards/gs-2004.c index 43f7068..b292d90 100644 --- a/src/boards/gs-2004.c +++ b/src/boards/gs-2004.c @@ -1,63 +1,63 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg, mirr; -static SFORMAT StateRegs[] = -{ - { ®, 1, "REGS" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(1, 0x6000, 0); - setprg32(0x8000, reg); - setchr8(0); -} - -static DECLFW(BMCGS2004Write) { - reg = V; - Sync(); -} - -static void BMCGS2004Power(void) { - reg = ~0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, BMCGS2004Write); -} - -static void BMCGS2004Reset(void) { - reg = ~0; -} - -static void StateRestore(int version) { - Sync(); -} - -void BMCGS2004_Init(CartInfo *info) { - info->Reset = BMCGS2004Reset; - info->Power = BMCGS2004Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(1, 0x6000, 0); + setprg32(0x8000, reg); + setchr8(0); +} + +static DECLFW(BMCGS2004Write) { + reg = V; + Sync(); +} + +static void BMCGS2004Power(void) { + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BMCGS2004Write); +} + +static void BMCGS2004Reset(void) { + reg = ~0; +} + +static void StateRestore(int version) { + Sync(); +} + +void BMCGS2004_Init(CartInfo *info) { + info->Reset = BMCGS2004Reset; + info->Power = BMCGS2004Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/gs-2013.c b/src/boards/gs-2013.c index 704a8cf..fe81a53 100644 --- a/src/boards/gs-2013.c +++ b/src/boards/gs-2013.c @@ -1,63 +1,63 @@ -/* 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 - */ - -#include "mapinc.h" - -static uint8 reg, mirr; -static SFORMAT StateRegs[] = -{ - { ®, 1, "REGS" }, - { &mirr, 1, "MIRR" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0, 0x6000, ~0); - setprg32r((reg & 8) >> 3, 0x8000, reg); - setchr8(0); -} - -static DECLFW(BMCGS2013Write) { - reg = V; - Sync(); -} - -static void BMCGS2013Power(void) { - reg = ~0; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, BMCGS2013Write); -} - -static void BMCGS2013Reset(void) { - reg = ~0; -} - -static void StateRestore(int version) { - Sync(); -} - -void BMCGS2013_Init(CartInfo *info) { - info->Reset = BMCGS2013Reset; - info->Power = BMCGS2013Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[] = +{ + { ®, 1, "REGS" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0, 0x6000, ~0); + setprg32r((reg & 8) >> 3, 0x8000, reg); + setchr8(0); +} + +static DECLFW(BMCGS2013Write) { + reg = V; + Sync(); +} + +static void BMCGS2013Power(void) { + reg = ~0; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, BMCGS2013Write); +} + +static void BMCGS2013Reset(void) { + reg = ~0; +} + +static void StateRestore(int version) { + Sync(); +} + +void BMCGS2013_Init(CartInfo *info) { + info->Reset = BMCGS2013Reset; + info->Power = BMCGS2013Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/h2288.c b/src/boards/h2288.c index 5ac8fa4..797c976 100644 --- a/src/boards/h2288.c +++ b/src/boards/h2288.c @@ -1,70 +1,70 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -extern uint8 m114_perm[8]; - -static void H2288PW(uint32 A, uint8 V) { - if (EXPREGS[0] & 0x40) { - uint8 bank = (EXPREGS[0] & 5) | ((EXPREGS[0] & 8) >> 2) | ((EXPREGS[0] & 0x20) >> 2); - if (EXPREGS[0] & 2) - setprg32(0x8000, bank >> 1); - else { - setprg16(0x8000, bank); - setprg16(0xC000, bank); - } - } else - setprg8(A, V & 0x3F); -} - -static DECLFW(H2288WriteHi) { - switch (A & 0x8001) { - case 0x8000: MMC3_CMDWrite(0x8000, (V & 0xC0) | (m114_perm[V & 7])); break; - case 0x8001: MMC3_CMDWrite(0x8001, V); break; - } -} - -static DECLFW(H2288WriteLo) { - if (A & 0x800) { - if (A & 1) - EXPREGS[1] = V; - else - EXPREGS[0] = V; - FixMMC3PRG(MMC3_cmd); - } -} - -static void H2288Power(void) { - EXPREGS[0] = EXPREGS[1] = 0; - GenMMC3Power(); -/* SetReadHandler(0x5000,0x5FFF,H2288Read); */ - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x5000, 0x5FFF, H2288WriteLo); - SetWriteHandler(0x8000, 0x9FFF, H2288WriteHi); -} - -void UNLH2288_Init(CartInfo *info) { - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap = H2288PW; - info->Power = H2288Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +extern uint8 m114_perm[8]; + +static void H2288PW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) { + uint8 bank = (EXPREGS[0] & 5) | ((EXPREGS[0] & 8) >> 2) | ((EXPREGS[0] & 0x20) >> 2); + if (EXPREGS[0] & 2) + setprg32(0x8000, bank >> 1); + else { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + } else + setprg8(A, V & 0x3F); +} + +static DECLFW(H2288WriteHi) { + switch (A & 0x8001) { + case 0x8000: MMC3_CMDWrite(0x8000, (V & 0xC0) | (m114_perm[V & 7])); break; + case 0x8001: MMC3_CMDWrite(0x8001, V); break; + } +} + +static DECLFW(H2288WriteLo) { + if (A & 0x800) { + if (A & 1) + EXPREGS[1] = V; + else + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void H2288Power(void) { + EXPREGS[0] = EXPREGS[1] = 0; + GenMMC3Power(); +/* SetReadHandler(0x5000,0x5FFF,H2288Read); */ + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x5000, 0x5FFF, H2288WriteLo); + SetWriteHandler(0x8000, 0x9FFF, H2288WriteHi); +} + +void UNLH2288_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap = H2288PW; + info->Power = H2288Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/src/boards/kof97.c b/src/boards/kof97.c index 1306b1a..e5766af 100644 --- a/src/boards/kof97.c +++ b/src/boards/kof97.c @@ -1,46 +1,46 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -static DECLFW(UNLKOF97CMDWrite) { - V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); /* 76143502 */ - if (A == 0x9000) A = 0x8001; - MMC3_CMDWrite(A, V); -} - -static DECLFW(UNLKOF97IRQWrite) { - V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); - if (A == 0xD000) A = 0xC001; - else if (A == 0xF000) A = 0xE001; - MMC3_IRQWrite(A, V); -} - -static void UNLKOF97Power(void) { - GenMMC3Power(); - SetWriteHandler(0x8000, 0xA000, UNLKOF97CMDWrite); - SetWriteHandler(0xC000, 0xF000, UNLKOF97IRQWrite); -} - -void UNLKOF97_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 256, 0, 0); - info->Power = UNLKOF97Power; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLKOF97CMDWrite) { + V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); /* 76143502 */ + if (A == 0x9000) A = 0x8001; + MMC3_CMDWrite(A, V); +} + +static DECLFW(UNLKOF97IRQWrite) { + V = (V & 0xD8) | ((V & 0x20) >> 4) | ((V & 4) << 3) | ((V & 2) >> 1) | ((V & 1) << 2); + if (A == 0xD000) A = 0xC001; + else if (A == 0xF000) A = 0xE001; + MMC3_IRQWrite(A, V); +} + +static void UNLKOF97Power(void) { + GenMMC3Power(); + SetWriteHandler(0x8000, 0xA000, UNLKOF97CMDWrite); + SetWriteHandler(0xC000, 0xF000, UNLKOF97IRQWrite); +} + +void UNLKOF97_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power = UNLKOF97Power; +} diff --git a/src/boards/le05.c b/src/boards/le05.c index efbe13f..59eab1a 100644 --- a/src/boards/le05.c +++ b/src/boards/le05.c @@ -1,62 +1,62 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 chr; -static SFORMAT StateRegs[] = -{ - { &chr, 1, "CHR" }, - { 0 } -}; - -static void Sync(void) { - setprg2r(0, 0xE000, 0); - setprg2r(0, 0xE800, 0); - setprg2r(0, 0xF000, 0); - setprg2r(0, 0xF800, 0); - - setprg8r(1, 0x6000, 3); - setprg8r(1, 0x8000, 0); - setprg8r(1, 0xA000, 1); - setprg8r(1, 0xC000, 2); - - setchr8(chr & 1); - setmirror(MI_V); -} - -static DECLFW(LE05Write) { - chr = V; - Sync(); -} - -static void LE05Power(void) { - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, LE05Write); -} - -void LE05_Init(CartInfo *info) { - info->Power = LE05Power; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 chr; +static SFORMAT StateRegs[] = +{ + { &chr, 1, "CHR" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0, 0xE000, 0); + setprg2r(0, 0xE800, 0); + setprg2r(0, 0xF000, 0); + setprg2r(0, 0xF800, 0); + + setprg8r(1, 0x6000, 3); + setprg8r(1, 0x8000, 0); + setprg8r(1, 0xA000, 1); + setprg8r(1, 0xC000, 2); + + setchr8(chr & 1); + setmirror(MI_V); +} + +static DECLFW(LE05Write) { + chr = V; + Sync(); +} + +static void LE05Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, LE05Write); +} + +void LE05_Init(CartInfo *info) { + info->Power = LE05Power; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/lh32.c b/src/boards/lh32.c index 3983327..74a0a83 100644 --- a/src/boards/lh32.c +++ b/src/boards/lh32.c @@ -1,79 +1,79 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x6000, reg); - setprg8(0x8000, ~3); - setprg8(0xa000, ~2); - setprg8r(0x10, 0xc000, 0); - setprg8(0xe000, ~0); - setchr8(0); -} - -static DECLFW(LH32Write) { - reg = V; - Sync(); -} - -static void LH32Power(void) { - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0xC000, 0xDFFF, CartBW); - SetWriteHandler(0x6000, 0x6000, LH32Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void LH32Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void LH32_Init(CartInfo *info) { - info->Power = LH32Power; - info->Close = LH32Close; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x6000, reg); + setprg8(0x8000, ~3); + setprg8(0xa000, ~2); + setprg8r(0x10, 0xc000, 0); + setprg8(0xe000, ~0); + setchr8(0); +} + +static DECLFW(LH32Write) { + reg = V; + Sync(); +} + +static void LH32Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0xC000, 0xDFFF, CartBW); + SetWriteHandler(0x6000, 0x6000, LH32Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void LH32Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void LH32_Init(CartInfo *info) { + info->Power = LH32Power; + info->Close = LH32Close; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/lh53.c b/src/boards/lh53.c index 7cfc5b3..10aae81 100644 --- a/src/boards/lh53.c +++ b/src/boards/lh53.c @@ -1,108 +1,108 @@ -/* 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 - * - * FDS Conversion - * - */ - -#include "mapinc.h" - -static uint8 reg, IRQa; -static int32 IRQCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { ®, 1, "REG" }, - { &IRQa, 1, "IRQA" }, - { &IRQCount, 4, "IRQC" }, - { 0 } -}; - -static void Sync(void) { - setchr8(0); - setprg8(0x6000, reg); - setprg8(0x8000, 0xc); - setprg4(0xa000, (0xd << 1)); - setprg2(0xb000, (0xd << 2) + 2); - setprg2r(0x10, 0xb800, 4); - setprg2r(0x10, 0xc000, 5); - setprg2r(0x10, 0xc800, 6); - setprg2r(0x10, 0xd000, 7); - setprg2(0xd800, (0xe << 2) + 3); - setprg8(0xe000, 0xf); -} - -static DECLFW(LH53RamWrite) { - WRAM[(A - 0xB800) & 0x1FFF] = V; -} - -static DECLFW(LH53Write) { - reg = V; - Sync(); -} - -static DECLFW(LH53IRQaWrite) { - IRQa = V & 2; - IRQCount = 0; - if (!IRQa) - X6502_IRQEnd(FCEU_IQEXT); -} - -static void FP_FASTAPASS(1) LH53IRQ(int a) { - if (IRQa) { - IRQCount += a; - if (IRQCount > 7560) - X6502_IRQBegin(FCEU_IQEXT); - } -} - -static void LH53Power(void) { - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0xB800, 0xD7FF, LH53RamWrite); - SetWriteHandler(0xE000, 0xEFFF, LH53IRQaWrite); - SetWriteHandler(0xF000, 0xFFFF, LH53Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void LH53Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void LH53_Init(CartInfo *info) { - info->Power = LH53Power; - info->Close = LH53Close; - MapIRQHook = LH53IRQ; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, IRQa; +static int32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { ®, 1, "REG" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 4, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg8(0x6000, reg); + setprg8(0x8000, 0xc); + setprg4(0xa000, (0xd << 1)); + setprg2(0xb000, (0xd << 2) + 2); + setprg2r(0x10, 0xb800, 4); + setprg2r(0x10, 0xc000, 5); + setprg2r(0x10, 0xc800, 6); + setprg2r(0x10, 0xd000, 7); + setprg2(0xd800, (0xe << 2) + 3); + setprg8(0xe000, 0xf); +} + +static DECLFW(LH53RamWrite) { + WRAM[(A - 0xB800) & 0x1FFF] = V; +} + +static DECLFW(LH53Write) { + reg = V; + Sync(); +} + +static DECLFW(LH53IRQaWrite) { + IRQa = V & 2; + IRQCount = 0; + if (!IRQa) + X6502_IRQEnd(FCEU_IQEXT); +} + +static void FP_FASTAPASS(1) LH53IRQ(int a) { + if (IRQa) { + IRQCount += a; + if (IRQCount > 7560) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void LH53Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0xB800, 0xD7FF, LH53RamWrite); + SetWriteHandler(0xE000, 0xEFFF, LH53IRQaWrite); + SetWriteHandler(0xF000, 0xFFFF, LH53Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void LH53Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void LH53_Init(CartInfo *info) { + info->Power = LH53Power; + info->Close = LH53Close; + MapIRQHook = LH53IRQ; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/mihunche.c b/src/boards/mihunche.c index 6eec579..e41ced4 100644 --- a/src/boards/mihunche.c +++ b/src/boards/mihunche.c @@ -1,68 +1,68 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2013 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 - */ - -#include "mapinc.h" - -static uint16 latche; - -static SFORMAT StateRegs[] = -{ - { &latche, 2, "LATC" }, - { 0 } -}; - -static void Sync(void) { - setprg32(0x8000, 0); - if(CHRsize[0] == 8192) { - setchr4(0x0000, latche & 1); - setchr4(0x1000, latche & 1); - } else { - setchr8(latche & 1); /* actually, my bad, overdumped roms, the real CHR size if 8K */ - } - setmirror(MI_0 + (latche & 1)); -} - -static DECLFW(UNLCC21Write1) { - latche = A; - Sync(); -} - -static DECLFW(UNLCC21Write2) { - latche = V; - Sync(); -} - -static void UNLCC21Power(void) { - latche = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8001, 0xFFFF, UNLCC21Write1); - SetWriteHandler(0x8000, 0x8000, UNLCC21Write2); /* another one many-in-1 mapper, there is a lot of similar carts with little different wirings */ -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLCC21_Init(CartInfo *info) { - info->Power = UNLCC21Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2013 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 + */ + +#include "mapinc.h" + +static uint16 latche; + +static SFORMAT StateRegs[] = +{ + { &latche, 2, "LATC" }, + { 0 } +}; + +static void Sync(void) { + setprg32(0x8000, 0); + if(CHRsize[0] == 8192) { + setchr4(0x0000, latche & 1); + setchr4(0x1000, latche & 1); + } else { + setchr8(latche & 1); /* actually, my bad, overdumped roms, the real CHR size if 8K */ + } + setmirror(MI_0 + (latche & 1)); +} + +static DECLFW(UNLCC21Write1) { + latche = A; + Sync(); +} + +static DECLFW(UNLCC21Write2) { + latche = V; + Sync(); +} + +static void UNLCC21Power(void) { + latche = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8001, 0xFFFF, UNLCC21Write1); + SetWriteHandler(0x8000, 0x8000, UNLCC21Write2); /* another one many-in-1 mapper, there is a lot of similar carts with little different wirings */ +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLCC21_Init(CartInfo *info) { + info->Power = UNLCC21Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/mmc1.c b/src/boards/mmc1.c index 0a294b0..d05b29a 100644 --- a/src/boards/mmc1.c +++ b/src/boards/mmc1.c @@ -1,392 +1,392 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * Copyright (C) 2002 Xodnizel - * - * 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" - -static void GenMMC1Power(void); -static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery); - -static uint8 DRegs[4]; -static uint8 Buffer, BufferShift; - -static int mmc1opts; - -static void (*MMC1CHRHook4)(uint32 A, uint8 V); -static void (*MMC1PRGHook16)(uint32 A, uint8 V); - -static uint8 *WRAM = NULL; -static uint8 *CHRRAM = NULL; -static int is155, is171; - -static DECLFW(MBWRAM) { - if (!(DRegs[3] & 0x10) || is155) - Page[A >> 11][A] = V; /* WRAM is enabled. */ -} - -static DECLFR(MAWRAM) { - if ((DRegs[3] & 0x10) && !is155) - return X.DB; /* WRAM is disabled */ - return(Page[A >> 11][A]); -} - -static void MMC1CHR(void) { - if (mmc1opts & 4) { - if (DRegs[0] & 0x10) - setprg8r(0x10, 0x6000, (DRegs[1] >> 4) & 1); - else - setprg8r(0x10, 0x6000, (DRegs[1] >> 3) & 1); - } - - if (MMC1CHRHook4) { - if (DRegs[0] & 0x10) { - MMC1CHRHook4(0x0000, DRegs[1]); - MMC1CHRHook4(0x1000, DRegs[2]); - } else { - MMC1CHRHook4(0x0000, (DRegs[1] & 0xFE)); - MMC1CHRHook4(0x1000, DRegs[1] | 1); - } - } else { - if (DRegs[0] & 0x10) { - setchr4(0x0000, DRegs[1]); - setchr4(0x1000, DRegs[2]); - } else - setchr8(DRegs[1] >> 1); - } -} - -static void MMC1PRG(void) { - uint8 offs = DRegs[1] & 0x10; - if (MMC1PRGHook16) { - switch (DRegs[0] & 0xC) { - case 0xC: - MMC1PRGHook16(0x8000, (DRegs[3] + offs)); - MMC1PRGHook16(0xC000, 0xF + offs); - break; - case 0x8: - MMC1PRGHook16(0xC000, (DRegs[3] + offs)); - MMC1PRGHook16(0x8000, offs); - break; - case 0x0: - case 0x4: - MMC1PRGHook16(0x8000, ((DRegs[3] & ~1) + offs)); - MMC1PRGHook16(0xc000, ((DRegs[3] & ~1) + offs + 1)); - break; - } - } else { - switch (DRegs[0] & 0xC) { - case 0xC: - setprg16(0x8000, (DRegs[3] + offs)); - setprg16(0xC000, 0xF + offs); - break; - case 0x8: - setprg16(0xC000, (DRegs[3] + offs)); - setprg16(0x8000, offs); - break; - case 0x0: - case 0x4: - setprg16(0x8000, ((DRegs[3] & ~1) + offs)); - setprg16(0xc000, ((DRegs[3] & ~1) + offs + 1)); - break; - } - } -} - -static void MMC1MIRROR(void) { - if (!is171) - switch (DRegs[0] & 3) { - case 2: setmirror(MI_V); break; - case 3: setmirror(MI_H); break; - case 0: setmirror(MI_0); break; - case 1: setmirror(MI_1); break; - } -} - -static uint64 lreset; -static DECLFW(MMC1_write) { - int n = (A >> 13) - 4; - - /* The MMC1 is busy so ignore the write. */ - /* As of version FCE Ultra 0.81, the timestamp is only - increased before each instruction is executed(in other words - precision isn't that great), but this should still work to - deal with 2 writes in a row from a single RMW instruction. - */ - if ((timestampbase + timestamp) < (lreset + 2)) - return; -/* FCEU_printf("Write %04x:%02x\n",A,V); */ - if (V & 0x80) { - DRegs[0] |= 0xC; - BufferShift = Buffer = 0; - MMC1PRG(); - lreset = timestampbase + timestamp; - return; - } - - Buffer |= (V & 1) << (BufferShift++); - - if (BufferShift == 5) { -/* FCEU_printf("REG[%d]=%02x\n",n,Buffer); */ - DRegs[n] = Buffer; - BufferShift = Buffer = 0; - switch (n) { - case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break; - case 1: MMC1CHR(); MMC1PRG(); break; - case 2: MMC1CHR(); break; - case 3: MMC1PRG(); break; - } - } -} - -static void MMC1_Restore(int version) { - MMC1MIRROR(); - MMC1CHR(); - MMC1PRG(); - lreset = 0; /* timestamp(base) is not stored in save states. */ -} - -static void MMC1CMReset(void) { - int i; - - for (i = 0; i < 4; i++) - DRegs[i] = 0; - Buffer = BufferShift = 0; - DRegs[0] = 0x1F; - - DRegs[1] = 0; - DRegs[2] = 0; /* Should this be something other than 0? */ - DRegs[3] = 0; - - MMC1MIRROR(); - MMC1CHR(); - MMC1PRG(); -} - -static int DetectMMC1WRAMSize(uint32 crc32) { - switch (crc32) { - case 0xc6182024: /* Romance of the 3 Kingdoms */ - case 0x2225c20f: /* Genghis Khan */ - case 0x4642dda6: /* Nobunaga's Ambition */ - case 0x29449ba9: /* "" "" (J) */ - case 0x2b11e0b0: /* "" "" (J) */ - case 0xb8747abf: /* Best Play Pro Yakyuu Special (J) */ - case 0xc9556b36: /* Final Fantasy I & II (J) [!] */ - FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); - return(16); - break; - case 0xd1e50064: /* Dezaemon */ - FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); - return(32); - break; - default: return(8); - } -} - -static uint32 NWCIRQCount; -static uint8 NWCRec; -#define NWCDIP 0xE - -static void NWCIRQHook(int a) { - if (!(NWCRec & 0x10)) { - NWCIRQCount += a; - if ((NWCIRQCount | (NWCDIP << 25)) >= 0x3e000000) { - NWCIRQCount = 0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void NWCCHRHook(uint32 A, uint8 V) { - if ((V & 0x10)) { /* && !(NWCRec&0x10)) */ - NWCIRQCount = 0; - X6502_IRQEnd(FCEU_IQEXT); - } - - NWCRec = V; - if (V & 0x08) - MMC1PRG(); - else - setprg32(0x8000, (V >> 1) & 3); -} - -static void NWCPRGHook(uint32 A, uint8 V) { - if (NWCRec & 0x8) - setprg16(A, 8 | (V & 0x7)); - else - setprg32(0x8000, (NWCRec >> 1) & 3); -} - -static void NWCPower(void) { - GenMMC1Power(); - setchr8r(0, 0); -} - -void Mapper105_Init(CartInfo *info) { - GenMMC1Init(info, 256, 256, 8, 0); - MMC1CHRHook4 = NWCCHRHook; - MMC1PRGHook16 = NWCPRGHook; - MapIRQHook = NWCIRQHook; - info->Power = NWCPower; -} - -static void GenMMC1Power(void) { - lreset = 0; - if (mmc1opts & 1) { - FCEU_CheatAddRAM(8, 0x6000, WRAM); - if (mmc1opts & 4) - FCEU_dwmemset(WRAM, 0, 8192) - else if (!(mmc1opts & 2)) - FCEU_dwmemset(WRAM, 0, 8192); - } - SetWriteHandler(0x8000, 0xFFFF, MMC1_write); - SetReadHandler(0x8000, 0xFFFF, CartBR); - - if (mmc1opts & 1) { - SetReadHandler(0x6000, 0x7FFF, MAWRAM); - SetWriteHandler(0x6000, 0x7FFF, MBWRAM); - setprg8r(0x10, 0x6000, 0); - } - - MMC1CMReset(); -} - -static void GenMMC1Close(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - if (WRAM) - FCEU_gfree(WRAM); - CHRRAM = WRAM = NULL; -} - -static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) { - is155 = 0; - - info->Close = GenMMC1Close; - MMC1PRGHook16 = MMC1CHRHook4 = 0; - mmc1opts = 0; - PRGmask16[0] &= (prg >> 14) - 1; - CHRmask4[0] &= (chr >> 12) - 1; - CHRmask8[0] &= (chr >> 13) - 1; - - if (wram) { - WRAM = (uint8*)FCEU_gmalloc(wram * 1024); - mmc1opts |= 1; - if (wram > 8) mmc1opts |= 4; - SetupCartPRGMapping(0x10, WRAM, wram * 1024, 1); - AddExState(WRAM, wram * 1024, 0, "WRAM"); - if (battery) { - mmc1opts |= 2; - info->SaveGame[0] = WRAM + ((mmc1opts & 4) ? 8192 : 0); - info->SaveGameLen[0] = 8192; - } - } - if (!chr) { - CHRRAM = (uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0, CHRRAM, 8192, 1); - AddExState(CHRRAM, 8192, 0, "CHRR"); - } - AddExState(DRegs, 4, 0, "DREG"); - - info->Power = GenMMC1Power; - GameStateRestore = MMC1_Restore; - AddExState(&lreset, 8, 1, "LRST"); - AddExState(&Buffer, 1, 1, "BFFR"); - AddExState(&BufferShift, 1, 1, "BFRS"); -} - -void Mapper1_Init(CartInfo *info) { - int ws = DetectMMC1WRAMSize(info->CRC32); - GenMMC1Init(info, 512, 256, ws, info->battery); -} - -/* Same as mapper 1, without respect for WRAM enable bit. */ -void Mapper155_Init(CartInfo *info) { - GenMMC1Init(info, 512, 256, 8, info->battery); - is155 = 1; -} - -/* Same as mapper 1, with different (or without) mirroring control. */ -/* Kaiser KS7058 board, KS203 custom chip */ -void Mapper171_Init(CartInfo *info) { - GenMMC1Init(info, 32, 32, 0, 0); - is171 = 1; -} - -void SAROM_Init(CartInfo *info) { - GenMMC1Init(info, 128, 64, 8, info->battery); -} - -void SBROM_Init(CartInfo *info) { - GenMMC1Init(info, 128, 64, 0, 0); -} - -void SCROM_Init(CartInfo *info) { - GenMMC1Init(info, 128, 128, 0, 0); -} - -void SEROM_Init(CartInfo *info) { - GenMMC1Init(info, 32, 64, 0, 0); -} - -void SGROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 0, 0, 0); -} - -void SKROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 64, 8, info->battery); -} - -void SLROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 128, 0, 0); -} - -void SL1ROM_Init(CartInfo *info) { - GenMMC1Init(info, 128, 128, 0, 0); -} - -/* Begin unknown - may be wrong - perhaps they use different MMC1s from the - similarly functioning boards? -*/ - -void SL2ROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 256, 0, 0); -} - -void SFROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 256, 0, 0); -} - -void SHROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 256, 0, 0); -} - -/* End unknown */ -/* */ -/* */ - -void SNROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 0, 8, info->battery); -} - -void SOROM_Init(CartInfo *info) { - GenMMC1Init(info, 256, 0, 16, info->battery); -} - - +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * + * 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" + +static void GenMMC1Power(void); +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery); + +static uint8 DRegs[4]; +static uint8 Buffer, BufferShift; + +static int mmc1opts; + +static void (*MMC1CHRHook4)(uint32 A, uint8 V); +static void (*MMC1PRGHook16)(uint32 A, uint8 V); + +static uint8 *WRAM = NULL; +static uint8 *CHRRAM = NULL; +static int is155, is171; + +static DECLFW(MBWRAM) { + if (!(DRegs[3] & 0x10) || is155) + Page[A >> 11][A] = V; /* WRAM is enabled. */ +} + +static DECLFR(MAWRAM) { + if ((DRegs[3] & 0x10) && !is155) + return X.DB; /* WRAM is disabled */ + return(Page[A >> 11][A]); +} + +static void MMC1CHR(void) { + if (mmc1opts & 4) { + if (DRegs[0] & 0x10) + setprg8r(0x10, 0x6000, (DRegs[1] >> 4) & 1); + else + setprg8r(0x10, 0x6000, (DRegs[1] >> 3) & 1); + } + + if (MMC1CHRHook4) { + if (DRegs[0] & 0x10) { + MMC1CHRHook4(0x0000, DRegs[1]); + MMC1CHRHook4(0x1000, DRegs[2]); + } else { + MMC1CHRHook4(0x0000, (DRegs[1] & 0xFE)); + MMC1CHRHook4(0x1000, DRegs[1] | 1); + } + } else { + if (DRegs[0] & 0x10) { + setchr4(0x0000, DRegs[1]); + setchr4(0x1000, DRegs[2]); + } else + setchr8(DRegs[1] >> 1); + } +} + +static void MMC1PRG(void) { + uint8 offs = DRegs[1] & 0x10; + if (MMC1PRGHook16) { + switch (DRegs[0] & 0xC) { + case 0xC: + MMC1PRGHook16(0x8000, (DRegs[3] + offs)); + MMC1PRGHook16(0xC000, 0xF + offs); + break; + case 0x8: + MMC1PRGHook16(0xC000, (DRegs[3] + offs)); + MMC1PRGHook16(0x8000, offs); + break; + case 0x0: + case 0x4: + MMC1PRGHook16(0x8000, ((DRegs[3] & ~1) + offs)); + MMC1PRGHook16(0xc000, ((DRegs[3] & ~1) + offs + 1)); + break; + } + } else { + switch (DRegs[0] & 0xC) { + case 0xC: + setprg16(0x8000, (DRegs[3] + offs)); + setprg16(0xC000, 0xF + offs); + break; + case 0x8: + setprg16(0xC000, (DRegs[3] + offs)); + setprg16(0x8000, offs); + break; + case 0x0: + case 0x4: + setprg16(0x8000, ((DRegs[3] & ~1) + offs)); + setprg16(0xc000, ((DRegs[3] & ~1) + offs + 1)); + break; + } + } +} + +static void MMC1MIRROR(void) { + if (!is171) + switch (DRegs[0] & 3) { + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + } +} + +static uint64 lreset; +static DECLFW(MMC1_write) { + int n = (A >> 13) - 4; + + /* The MMC1 is busy so ignore the write. */ + /* As of version FCE Ultra 0.81, the timestamp is only + increased before each instruction is executed(in other words + precision isn't that great), but this should still work to + deal with 2 writes in a row from a single RMW instruction. + */ + if ((timestampbase + timestamp) < (lreset + 2)) + return; +/* FCEU_printf("Write %04x:%02x\n",A,V); */ + if (V & 0x80) { + DRegs[0] |= 0xC; + BufferShift = Buffer = 0; + MMC1PRG(); + lreset = timestampbase + timestamp; + return; + } + + Buffer |= (V & 1) << (BufferShift++); + + if (BufferShift == 5) { +/* FCEU_printf("REG[%d]=%02x\n",n,Buffer); */ + DRegs[n] = Buffer; + BufferShift = Buffer = 0; + switch (n) { + case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break; + case 1: MMC1CHR(); MMC1PRG(); break; + case 2: MMC1CHR(); break; + case 3: MMC1PRG(); break; + } + } +} + +static void MMC1_Restore(int version) { + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); + lreset = 0; /* timestamp(base) is not stored in save states. */ +} + +static void MMC1CMReset(void) { + int i; + + for (i = 0; i < 4; i++) + DRegs[i] = 0; + Buffer = BufferShift = 0; + DRegs[0] = 0x1F; + + DRegs[1] = 0; + DRegs[2] = 0; /* Should this be something other than 0? */ + DRegs[3] = 0; + + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); +} + +static int DetectMMC1WRAMSize(uint32 crc32) { + switch (crc32) { + case 0xc6182024: /* Romance of the 3 Kingdoms */ + case 0x2225c20f: /* Genghis Khan */ + case 0x4642dda6: /* Nobunaga's Ambition */ + case 0x29449ba9: /* "" "" (J) */ + case 0x2b11e0b0: /* "" "" (J) */ + case 0xb8747abf: /* Best Play Pro Yakyuu Special (J) */ + case 0xc9556b36: /* Final Fantasy I & II (J) [!] */ + FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(16); + break; + case 0xd1e50064: /* Dezaemon */ + FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(32); + break; + default: return(8); + } +} + +static uint32 NWCIRQCount; +static uint8 NWCRec; +#define NWCDIP 0xE + +static void NWCIRQHook(int a) { + if (!(NWCRec & 0x10)) { + NWCIRQCount += a; + if ((NWCIRQCount | (NWCDIP << 25)) >= 0x3e000000) { + NWCIRQCount = 0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void NWCCHRHook(uint32 A, uint8 V) { + if ((V & 0x10)) { /* && !(NWCRec&0x10)) */ + NWCIRQCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + } + + NWCRec = V; + if (V & 0x08) + MMC1PRG(); + else + setprg32(0x8000, (V >> 1) & 3); +} + +static void NWCPRGHook(uint32 A, uint8 V) { + if (NWCRec & 0x8) + setprg16(A, 8 | (V & 0x7)); + else + setprg32(0x8000, (NWCRec >> 1) & 3); +} + +static void NWCPower(void) { + GenMMC1Power(); + setchr8r(0, 0); +} + +void Mapper105_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 8, 0); + MMC1CHRHook4 = NWCCHRHook; + MMC1PRGHook16 = NWCPRGHook; + MapIRQHook = NWCIRQHook; + info->Power = NWCPower; +} + +static void GenMMC1Power(void) { + lreset = 0; + if (mmc1opts & 1) { + FCEU_CheatAddRAM(8, 0x6000, WRAM); + if (mmc1opts & 4) + FCEU_dwmemset(WRAM, 0, 8192) + else if (!(mmc1opts & 2)) + FCEU_dwmemset(WRAM, 0, 8192); + } + SetWriteHandler(0x8000, 0xFFFF, MMC1_write); + SetReadHandler(0x8000, 0xFFFF, CartBR); + + if (mmc1opts & 1) { + SetReadHandler(0x6000, 0x7FFF, MAWRAM); + SetWriteHandler(0x6000, 0x7FFF, MBWRAM); + setprg8r(0x10, 0x6000, 0); + } + + MMC1CMReset(); +} + +static void GenMMC1Close(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + if (WRAM) + FCEU_gfree(WRAM); + CHRRAM = WRAM = NULL; +} + +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) { + is155 = 0; + + info->Close = GenMMC1Close; + MMC1PRGHook16 = MMC1CHRHook4 = 0; + mmc1opts = 0; + PRGmask16[0] &= (prg >> 14) - 1; + CHRmask4[0] &= (chr >> 12) - 1; + CHRmask8[0] &= (chr >> 13) - 1; + + if (wram) { + WRAM = (uint8*)FCEU_gmalloc(wram * 1024); + mmc1opts |= 1; + if (wram > 8) mmc1opts |= 4; + SetupCartPRGMapping(0x10, WRAM, wram * 1024, 1); + AddExState(WRAM, wram * 1024, 0, "WRAM"); + if (battery) { + mmc1opts |= 2; + info->SaveGame[0] = WRAM + ((mmc1opts & 4) ? 8192 : 0); + info->SaveGameLen[0] = 8192; + } + } + if (!chr) { + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + } + AddExState(DRegs, 4, 0, "DREG"); + + info->Power = GenMMC1Power; + GameStateRestore = MMC1_Restore; + AddExState(&lreset, 8, 1, "LRST"); + AddExState(&Buffer, 1, 1, "BFFR"); + AddExState(&BufferShift, 1, 1, "BFRS"); +} + +void Mapper1_Init(CartInfo *info) { + int ws = DetectMMC1WRAMSize(info->CRC32); + GenMMC1Init(info, 512, 256, ws, info->battery); +} + +/* Same as mapper 1, without respect for WRAM enable bit. */ +void Mapper155_Init(CartInfo *info) { + GenMMC1Init(info, 512, 256, 8, info->battery); + is155 = 1; +} + +/* Same as mapper 1, with different (or without) mirroring control. */ +/* Kaiser KS7058 board, KS203 custom chip */ +void Mapper171_Init(CartInfo *info) { + GenMMC1Init(info, 32, 32, 0, 0); + is171 = 1; +} + +void SAROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 64, 8, info->battery); +} + +void SBROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 64, 0, 0); +} + +void SCROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 128, 0, 0); +} + +void SEROM_Init(CartInfo *info) { + GenMMC1Init(info, 32, 64, 0, 0); +} + +void SGROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 0, 0, 0); +} + +void SKROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 64, 8, info->battery); +} + +void SLROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 128, 0, 0); +} + +void SL1ROM_Init(CartInfo *info) { + GenMMC1Init(info, 128, 128, 0, 0); +} + +/* Begin unknown - may be wrong - perhaps they use different MMC1s from the + similarly functioning boards? +*/ + +void SL2ROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SFROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SHROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 256, 0, 0); +} + +/* End unknown */ +/* */ +/* */ + +void SNROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 0, 8, info->battery); +} + +void SOROM_Init(CartInfo *info) { + GenMMC1Init(info, 256, 0, 16, info->battery); +} + + diff --git a/src/boards/mmc2and4.c b/src/boards/mmc2and4.c index c2e7f04..cc94b0a 100644 --- a/src/boards/mmc2and4.c +++ b/src/boards/mmc2and4.c @@ -1,152 +1,152 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 CaH4e3 - * Copyright (C) 2002 Xodnizel - * - * 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" - -static uint8 is10, isPC10; -static uint8 creg[4], latch0, latch1, preg, mirr; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { creg, 4, "CREG" }, - { &preg, 1, "PREG" }, - { &mirr, 1, "MIRR" }, - { &latch0, 1, "LAT0" }, - { &latch1, 1, "LAT1" }, - { 0 } -}; - -static void Sync(void) { - if (is10) { - setprg16(0x8000, preg); - setprg16(0xC000, ~0); - } else { - setprg8(0x8000, preg); - setprg8(0xA000, ~2); - setprg8(0xC000, ~1); - setprg8(0xE000, ~0); - } - if (is10 || isPC10) - setprg8r(0x10, 0x6000, 0); - setchr4(0x0000, creg[latch0]); - setchr4(0x1000, creg[latch1 + 2]); - setmirror(mirr); -} - -DECLFW(MMC2and4Write) { - switch (A & 0xF000) { - case 0xA000: preg = V & 0xF; Sync(); break; - case 0xB000: creg[0] = V & 0x1F; Sync(); break; - case 0xC000: creg[1] = V & 0x1F; Sync(); break; - case 0xD000: creg[2] = V & 0x1F; Sync(); break; - case 0xE000: creg[3] = V & 0x1F; Sync(); break; - case 0xF000: mirr = (V & 1) ^ 1; Sync(); break; - } -} - -static void FP_FASTAPASS(1) MMC2and4PPUHook(uint32 A) { - uint8 l, h = A >> 8; - if (h >= 0x20 || ((h & 0xF) != 0xF)) - return; - l = A & 0xF0; - if (h < 0x10) { - if (l == 0xD0) { - latch0 = 0; - setchr4(0x0000, creg[0]); - } else if (l == 0xE0) { - latch0 = 1; - setchr4(0x0000, creg[1]); - } - } else { - if (l == 0xD0) { - latch1 = 0; - setchr4(0x1000, creg[2]); - } else if (l == 0xE0) { - latch1 = 1; - setchr4(0x1000, creg[3]); - } - } -} - -static void MMC2and4Power(void) { - preg = 0; - latch0 = latch1 = 1; - Sync(); - if (is10 || isPC10) { - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - } - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0xA000, 0xFFFF, MMC2and4Write); -} - -static void StateRestore(int version) { - Sync(); -} - -static void MMC2and4Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void Mapper9_Init(CartInfo *info) { - is10 = 0; - isPC10 = 0; - info->Power = MMC2and4Power; - info->Close = MMC2and4Close; - PPU_hook = MMC2and4PPUHook; - if (info->CRC32 == 0x7b837fde) { /* Mike Tyson's Punch-Out!! (PC10) supports save ram */ - isPC10 = 1; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - } - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper10_Init(CartInfo *info) { - is10 = 1; - isPC10 = 0; - info->Power = MMC2and4Power; - info->Close = MMC2and4Close; - PPU_hook = MMC2and4PPUHook; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 CaH4e3 + * Copyright (C) 2002 Xodnizel + * + * 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" + +static uint8 is10, isPC10; +static uint8 creg[4], latch0, latch1, preg, mirr; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { creg, 4, "CREG" }, + { &preg, 1, "PREG" }, + { &mirr, 1, "MIRR" }, + { &latch0, 1, "LAT0" }, + { &latch1, 1, "LAT1" }, + { 0 } +}; + +static void Sync(void) { + if (is10) { + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + } else { + setprg8(0x8000, preg); + setprg8(0xA000, ~2); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + } + if (is10 || isPC10) + setprg8r(0x10, 0x6000, 0); + setchr4(0x0000, creg[latch0]); + setchr4(0x1000, creg[latch1 + 2]); + setmirror(mirr); +} + +DECLFW(MMC2and4Write) { + switch (A & 0xF000) { + case 0xA000: preg = V & 0xF; Sync(); break; + case 0xB000: creg[0] = V & 0x1F; Sync(); break; + case 0xC000: creg[1] = V & 0x1F; Sync(); break; + case 0xD000: creg[2] = V & 0x1F; Sync(); break; + case 0xE000: creg[3] = V & 0x1F; Sync(); break; + case 0xF000: mirr = (V & 1) ^ 1; Sync(); break; + } +} + +static void FP_FASTAPASS(1) MMC2and4PPUHook(uint32 A) { + uint8 l, h = A >> 8; + if (h >= 0x20 || ((h & 0xF) != 0xF)) + return; + l = A & 0xF0; + if (h < 0x10) { + if (l == 0xD0) { + latch0 = 0; + setchr4(0x0000, creg[0]); + } else if (l == 0xE0) { + latch0 = 1; + setchr4(0x0000, creg[1]); + } + } else { + if (l == 0xD0) { + latch1 = 0; + setchr4(0x1000, creg[2]); + } else if (l == 0xE0) { + latch1 = 1; + setchr4(0x1000, creg[3]); + } + } +} + +static void MMC2and4Power(void) { + preg = 0; + latch0 = latch1 = 1; + Sync(); + if (is10 || isPC10) { + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + } + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0xA000, 0xFFFF, MMC2and4Write); +} + +static void StateRestore(int version) { + Sync(); +} + +static void MMC2and4Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper9_Init(CartInfo *info) { + is10 = 0; + isPC10 = 0; + info->Power = MMC2and4Power; + info->Close = MMC2and4Close; + PPU_hook = MMC2and4PPUHook; + if (info->CRC32 == 0x7b837fde) { /* Mike Tyson's Punch-Out!! (PC10) supports save ram */ + isPC10 = 1; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper10_Init(CartInfo *info) { + is10 = 1; + isPC10 = 0; + info->Power = MMC2and4Power; + info->Close = MMC2and4Close; + PPU_hook = MMC2and4PPUHook; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/mmc3.h b/src/boards/mmc3.h index d8b4b01..3dc1e47 100644 --- a/src/boards/mmc3.h +++ b/src/boards/mmc3.h @@ -1,26 +1,26 @@ -extern uint8 MMC3_cmd; -extern uint8 mmc3opts; -extern uint8 A000B; -extern uint8 A001B; -extern uint8 EXPREGS[8]; -extern uint8 DRegBuf[8]; - -#undef IRQCount -#undef IRQLatch -#undef IRQa -extern uint8 IRQCount, IRQLatch, IRQa; -extern uint8 IRQReload; - -extern void (*pwrap)(uint32 A, uint8 V); -extern void (*cwrap)(uint32 A, uint8 V); -extern void (*mwrap)(uint8 V); - -void GenMMC3Power(void); -void GenMMC3Restore(int version); -void MMC3RegReset(void); -void FixMMC3PRG(int V); -void FixMMC3CHR(int V); -DECLFW(MMC3_CMDWrite); -DECLFW(MMC3_IRQWrite); - -void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); +extern uint8 MMC3_cmd; +extern uint8 mmc3opts; +extern uint8 A000B; +extern uint8 A001B; +extern uint8 EXPREGS[8]; +extern uint8 DRegBuf[8]; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +extern uint8 IRQCount, IRQLatch, IRQa; +extern uint8 IRQReload; + +extern void (*pwrap)(uint32 A, uint8 V); +extern void (*cwrap)(uint32 A, uint8 V); +extern void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void GenMMC3Restore(int version); +void MMC3RegReset(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); +DECLFW(MMC3_CMDWrite); +DECLFW(MMC3_IRQWrite); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); diff --git a/src/boards/n625092.c b/src/boards/n625092.c index 058cd3d..1f134c0 100644 --- a/src/boards/n625092.c +++ b/src/boards/n625092.c @@ -1,95 +1,95 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - * 700in1 and 400in1 carts - * - */ - - -#include "mapinc.h" - -static uint16 cmd, bank; - -static SFORMAT StateRegs[] = -{ - { &cmd, 2, "CMD" }, - { &bank, 2, "BANK" }, - { 0 } -}; - -static void Sync(void) { - setmirror((cmd & 1) ^ 1); - setchr8(0); - if (cmd & 2) { - if (cmd & 0x100) { - setprg16(0x8000, ((cmd & 0xfc) >> 2) | bank); - setprg16(0xC000, ((cmd & 0xfc) >> 2) | 7); - } else { - setprg16(0x8000, ((cmd & 0xfc) >> 2) | (bank & 6)); - setprg16(0xC000, ((cmd & 0xfc) >> 2) | ((bank & 6) | 1)); - } - } else { - setprg16(0x8000, ((cmd & 0xfc) >> 2) | bank); - setprg16(0xC000, ((cmd & 0xfc) >> 2) | bank); - } -} - -static uint16 ass = 0; - -static DECLFW(UNLN625092WriteCommand) { - cmd = A; - if (A == 0x80F8) { - setprg16(0x8000, ass); - setprg16(0xC000, ass); - } else { - Sync(); - } -} - -static DECLFW(UNLN625092WriteBank) { - bank = A & 7; - Sync(); -} - -static void UNLN625092Power(void) { - cmd = 0; - bank = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xBFFF, UNLN625092WriteCommand); - SetWriteHandler(0xC000, 0xFFFF, UNLN625092WriteBank); -} - -static void UNLN625092Reset(void) { - cmd = 0; - bank = 0; - ass++; - FCEU_printf("%04x\n", ass); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLN625092_Init(CartInfo *info) { - info->Reset = UNLN625092Reset; - info->Power = UNLN625092Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + * 700in1 and 400in1 carts + * + */ + + +#include "mapinc.h" + +static uint16 cmd, bank; + +static SFORMAT StateRegs[] = +{ + { &cmd, 2, "CMD" }, + { &bank, 2, "BANK" }, + { 0 } +}; + +static void Sync(void) { + setmirror((cmd & 1) ^ 1); + setchr8(0); + if (cmd & 2) { + if (cmd & 0x100) { + setprg16(0x8000, ((cmd & 0xfc) >> 2) | bank); + setprg16(0xC000, ((cmd & 0xfc) >> 2) | 7); + } else { + setprg16(0x8000, ((cmd & 0xfc) >> 2) | (bank & 6)); + setprg16(0xC000, ((cmd & 0xfc) >> 2) | ((bank & 6) | 1)); + } + } else { + setprg16(0x8000, ((cmd & 0xfc) >> 2) | bank); + setprg16(0xC000, ((cmd & 0xfc) >> 2) | bank); + } +} + +static uint16 ass = 0; + +static DECLFW(UNLN625092WriteCommand) { + cmd = A; + if (A == 0x80F8) { + setprg16(0x8000, ass); + setprg16(0xC000, ass); + } else { + Sync(); + } +} + +static DECLFW(UNLN625092WriteBank) { + bank = A & 7; + Sync(); +} + +static void UNLN625092Power(void) { + cmd = 0; + bank = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, UNLN625092WriteCommand); + SetWriteHandler(0xC000, 0xFFFF, UNLN625092WriteBank); +} + +static void UNLN625092Reset(void) { + cmd = 0; + bank = 0; + ass++; + FCEU_printf("%04x\n", ass); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLN625092_Init(CartInfo *info) { + info->Reset = UNLN625092Reset; + info->Power = UNLN625092Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/onebus.c b/src/boards/onebus.c index 5f14d6f..d970456 100644 --- a/src/boards/onebus.c +++ b/src/boards/onebus.c @@ -1,300 +1,300 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2007-2010 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 - * - * VR02/VT03 Console and OneBus System - * - * Street Dance (Dance pad) (Unl) - * 101-in-1 Arcade Action II - * DreamGEAR 75-in-1, etc. - * - */ - -#include "mapinc.h" - -/* General Purpose Registers */ -static uint8 cpu410x[16], ppu201x[16], apu40xx[64]; - -/* IRQ Registers */ -static uint8 IRQCount, IRQa, IRQReload; -#define IRQLatch cpu410x[0x1] /* accc cccc, a = 0, AD12 switching, a = 1, HSYNC switching */ - -/* MMC3 Registers */ -static uint8 inv_hack = 0; /* some OneBus Systems have swapped PRG reg commans in MMC3 inplementation, - * trying to autodetect unusual behavior, due not to add a new mapper. - */ -#define mmc3cmd cpu410x[0x5] /* pcv- ----, p - program swap, c - video swap, v - internal VRAM enable */ -#define mirror cpu410x[0x6] /* ---- ---m, m = 0 - H, m = 1 - V */ - -/* APU Registers */ -static uint8 pcm_enable = 0, pcm_irq = 0; -static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xE1; - -static writefunc defapuwrite[64]; -static readfunc defapuread[64]; - -static SFORMAT StateRegs[] = -{ - { cpu410x, 16, "REGC" }, - { ppu201x, 16, "REGS" }, - { apu40xx, 64, "REGA" }, - { &IRQReload, 1, "IRQR" }, - { &IRQCount, 1, "IRQC" }, - { &IRQa, 1, "IRQA" }, - { &pcm_enable, 1, "PCME" }, - { &pcm_irq, 1, "PCMI" }, - { &pcm_addr, 2, "PCMA" }, - { &pcm_size, 2, "PCMS" }, - { &pcm_latch, 2, "PCML" }, - { &pcm_clock, 2, "PCMC" }, - { 0 } -}; - -static void PSync(void) { - uint8 bankmode = cpu410x[0xb] & 7; - uint8 mask = (bankmode == 0x7) ? (0xff) : (0x3f >> bankmode); - uint32 block = ((cpu410x[0x0] & 0xf0) << 4) + (cpu410x[0xa] & (~mask)); - uint32 pswap = (mmc3cmd & 0x40) << 8; - -#if 0 - uint8 bank0 = (cpu410x[0xb] & 0x40)?(~1):(cpu410x[0x7]); - uint8 bank1 = cpu410x[0x8]; - uint8 bank2 = (cpu410x[0xb] & 0x40)?(cpu410x[0x9]):(~1); - uint8 bank3 = ~0; -#endif - uint8 bank0 = cpu410x[0x7 ^ inv_hack]; - uint8 bank1 = cpu410x[0x8 ^ inv_hack]; - uint8 bank2 = (cpu410x[0xb] & 0x40) ? (cpu410x[0x9]) : (~1); - uint8 bank3 = ~0; - -/* FCEU_printf(" PRG: %04x [%02x]",0x8000^pswap,block | (bank0 & mask)); */ - setprg8(0x8000 ^ pswap, block | (bank0 & mask)); -/* FCEU_printf(" %04x [%02x]",0xa000^pswap,block | (bank1 & mask)); */ - setprg8(0xa000, block | (bank1 & mask)); -/* FCEU_printf(" %04x [%02x]",0xc000^pswap,block | (bank2 & mask)); */ - setprg8(0xc000 ^ pswap, block | (bank2 & mask)); -/* FCEU_printf(" %04x [%02x]\n",0xe000^pswap,block | (bank3 & mask)); */ - setprg8(0xe000, block | (bank3 & mask)); -} - -static void CSync(void) { - static const uint8 midx[8] = { 0, 1, 2, 0, 3, 4, 5, 0 }; - uint8 mask = 0xff >> midx[ppu201x[0xa] & 7]; - uint32 block = ((cpu410x[0x0] & 0x0f) << 11) + ((ppu201x[0x8] & 0x70) << 4) + (ppu201x[0xa] & (~mask)); - uint32 cswap = (mmc3cmd & 0x80) << 5; - - uint8 bank0 = ppu201x[0x6] & (~1); - uint8 bank1 = ppu201x[0x6] | 1; - uint8 bank2 = ppu201x[0x7] & (~1); - uint8 bank3 = ppu201x[0x7] | 1; - uint8 bank4 = ppu201x[0x2]; - uint8 bank5 = ppu201x[0x3]; - uint8 bank6 = ppu201x[0x4]; - uint8 bank7 = ppu201x[0x5]; - - setchr1(0x0000 ^ cswap, block | (bank0 & mask)); - setchr1(0x0400 ^ cswap, block | (bank1 & mask)); - setchr1(0x0800 ^ cswap, block | (bank2 & mask)); - setchr1(0x0c00 ^ cswap, block | (bank3 & mask)); - setchr1(0x1000 ^ cswap, block | (bank4 & mask)); - setchr1(0x1400 ^ cswap, block | (bank5 & mask)); - setchr1(0x1800 ^ cswap, block | (bank6 & mask)); - setchr1(0x1c00 ^ cswap, block | (bank7 & mask)); - - setmirror((mirror ^ 1) & 1); -} - -static void Sync(void) { - PSync(); - CSync(); -} - -static DECLFW(UNLOneBusWriteCPU410X) { -/* FCEU_printf("CPU %04x:%04x\n",A,V); */ - switch (A & 0xf) { - case 0x1: IRQLatch = V & 0xfe; break; /* íå ïî äàòàøèòó */ - case 0x2: IRQReload = 1; break; - case 0x3: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; - case 0x4: IRQa = 1; break; - default: - cpu410x[A & 0xf] = V; - Sync(); - } -} - -static DECLFW(UNLOneBusWritePPU201X) { -/* FCEU_printf("PPU %04x:%04x\n",A,V); */ - ppu201x[A & 0x0f] = V; - Sync(); -} - -static DECLFW(UNLOneBusWriteMMC3) { -/* FCEU_printf("MMC %04x:%04x\n",A,V); */ - switch (A & 0xe001) { - case 0x8000: mmc3cmd = (mmc3cmd & 0x38) | (V & 0xc7); Sync(); break; - case 0x8001: - { - switch (mmc3cmd & 7) { - case 0: ppu201x[0x6] = V; CSync(); break; - case 1: ppu201x[0x7] = V; CSync(); break; - case 2: ppu201x[0x2] = V; CSync(); break; - case 3: ppu201x[0x3] = V; CSync(); break; - case 4: ppu201x[0x4] = V; CSync(); break; - case 5: ppu201x[0x5] = V; CSync(); break; - case 6: cpu410x[0x7] = V; PSync(); break; - case 7: cpu410x[0x8] = V; PSync(); break; - } - break; - } - case 0xa000: mirror = V; CSync(); break; - case 0xc000: IRQLatch = V & 0xfe; break; - case 0xc001: IRQReload = 1; break; - case 0xe000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; - case 0xe001: IRQa = 1; break; - } -} - -static void UNLOneBusIRQHook(void) { - uint32 count = IRQCount; - if (!count || IRQReload) { - IRQCount = IRQLatch; - IRQReload = 0; - } else - IRQCount--; - if (count && !IRQCount) { - if (IRQa) - X6502_IRQBegin(FCEU_IQEXT); - } -} - -static DECLFW(UNLOneBusWriteAPU40XX) { -/* if(((A & 0x3f)!=0x16) && ((apu40xx[0x30] & 0x10) || ((A & 0x3f)>0x17)))FCEU_printf("APU %04x:%04x\n",A,V); */ - apu40xx[A & 0x3f] = V; - switch (A & 0x3f) { - case 0x12: - if (apu40xx[0x30] & 0x10) { - pcm_addr = V << 6; - } - break; - case 0x13: - if (apu40xx[0x30] & 0x10) { - pcm_size = (V << 4) + 1; - } - break; - case 0x15: - if (apu40xx[0x30] & 0x10) { - pcm_enable = V & 0x10; - if (pcm_irq) { - X6502_IRQEnd(FCEU_IQEXT); - pcm_irq = 0; - } - if (pcm_enable) - pcm_latch = pcm_clock; - V &= 0xef; - } - break; - } - defapuwrite[A & 0x3f](A, V); -} - -static DECLFR(UNLOneBusReadAPU40XX) { - uint8 result = defapuread[A & 0x3f](A); -/* FCEU_printf("read %04x, %02x\n",A,result); */ - switch (A & 0x3f) { - case 0x15: - if (apu40xx[0x30] & 0x10) { - result = (result & 0x7f) | pcm_irq; - } - break; - } - return result; -} - -static void UNLOneBusCpuHook(int a) { - if (pcm_enable) { - pcm_latch -= a; - if (pcm_latch <= 0) { - pcm_latch += pcm_clock; - pcm_size--; - if (pcm_size < 0) { - pcm_irq = 0x80; - pcm_enable = 0; - X6502_IRQBegin(FCEU_IQEXT); - } else { - uint16 addr = pcm_addr | ((apu40xx[0x30]^3) << 14); - uint8 raw_pcm = ARead[addr](addr) >> 1; - defapuwrite[0x11](0x4011, raw_pcm); - pcm_addr++; - pcm_addr &= 0x7FFF; - } - } - } -} - -static void UNLOneBusPower(void) { - uint32 i; - IRQReload = IRQCount = IRQa = 0; - - memset(cpu410x, 0x00, sizeof(cpu410x)); - memset(ppu201x, 0x00, sizeof(ppu201x)); - memset(apu40xx, 0x00, sizeof(apu40xx)); - - SetupCartCHRMapping(0, PRGptr[0], PRGsize[0], 0); - - for (i = 0; i < 64; i++) { - defapuread[i] = GetReadHandler(0x4000 | i); - defapuwrite[i] = GetWriteHandler(0x4000 | i); - } - SetReadHandler(0x4000, 0x403f, UNLOneBusReadAPU40XX); - SetWriteHandler(0x4000, 0x403f, UNLOneBusWriteAPU40XX); - - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x2010, 0x201f, UNLOneBusWritePPU201X); - SetWriteHandler(0x4100, 0x410f, UNLOneBusWriteCPU410X); - SetWriteHandler(0x8000, 0xffff, UNLOneBusWriteMMC3); - - Sync(); -} - -static void UNLOneBusReset(void) { - IRQReload = IRQCount = IRQa = 0; - - memset(cpu410x, 0x00, sizeof(cpu410x)); - memset(ppu201x, 0x00, sizeof(ppu201x)); - memset(apu40xx, 0x00, sizeof(apu40xx)); - - Sync(); -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLOneBus_Init(CartInfo *info) { - info->Power = UNLOneBusPower; - info->Reset = UNLOneBusReset; - - if (((*(uint32*)&(info->MD5)) == 0x305fcdc3) || /* PowerJoy Supermax Carts */ - ((*(uint32*)&(info->MD5)) == 0x6abfce8e)) - inv_hack = 0xf; - - GameHBIRQHook = UNLOneBusIRQHook; - MapIRQHook = UNLOneBusCpuHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2010 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 + * + * VR02/VT03 Console and OneBus System + * + * Street Dance (Dance pad) (Unl) + * 101-in-1 Arcade Action II + * DreamGEAR 75-in-1, etc. + * + */ + +#include "mapinc.h" + +/* General Purpose Registers */ +static uint8 cpu410x[16], ppu201x[16], apu40xx[64]; + +/* IRQ Registers */ +static uint8 IRQCount, IRQa, IRQReload; +#define IRQLatch cpu410x[0x1] /* accc cccc, a = 0, AD12 switching, a = 1, HSYNC switching */ + +/* MMC3 Registers */ +static uint8 inv_hack = 0; /* some OneBus Systems have swapped PRG reg commans in MMC3 inplementation, + * trying to autodetect unusual behavior, due not to add a new mapper. + */ +#define mmc3cmd cpu410x[0x5] /* pcv- ----, p - program swap, c - video swap, v - internal VRAM enable */ +#define mirror cpu410x[0x6] /* ---- ---m, m = 0 - H, m = 1 - V */ + +/* APU Registers */ +static uint8 pcm_enable = 0, pcm_irq = 0; +static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xE1; + +static writefunc defapuwrite[64]; +static readfunc defapuread[64]; + +static SFORMAT StateRegs[] = +{ + { cpu410x, 16, "REGC" }, + { ppu201x, 16, "REGS" }, + { apu40xx, 64, "REGA" }, + { &IRQReload, 1, "IRQR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { &pcm_enable, 1, "PCME" }, + { &pcm_irq, 1, "PCMI" }, + { &pcm_addr, 2, "PCMA" }, + { &pcm_size, 2, "PCMS" }, + { &pcm_latch, 2, "PCML" }, + { &pcm_clock, 2, "PCMC" }, + { 0 } +}; + +static void PSync(void) { + uint8 bankmode = cpu410x[0xb] & 7; + uint8 mask = (bankmode == 0x7) ? (0xff) : (0x3f >> bankmode); + uint32 block = ((cpu410x[0x0] & 0xf0) << 4) + (cpu410x[0xa] & (~mask)); + uint32 pswap = (mmc3cmd & 0x40) << 8; + +#if 0 + uint8 bank0 = (cpu410x[0xb] & 0x40)?(~1):(cpu410x[0x7]); + uint8 bank1 = cpu410x[0x8]; + uint8 bank2 = (cpu410x[0xb] & 0x40)?(cpu410x[0x9]):(~1); + uint8 bank3 = ~0; +#endif + uint8 bank0 = cpu410x[0x7 ^ inv_hack]; + uint8 bank1 = cpu410x[0x8 ^ inv_hack]; + uint8 bank2 = (cpu410x[0xb] & 0x40) ? (cpu410x[0x9]) : (~1); + uint8 bank3 = ~0; + +/* FCEU_printf(" PRG: %04x [%02x]",0x8000^pswap,block | (bank0 & mask)); */ + setprg8(0x8000 ^ pswap, block | (bank0 & mask)); +/* FCEU_printf(" %04x [%02x]",0xa000^pswap,block | (bank1 & mask)); */ + setprg8(0xa000, block | (bank1 & mask)); +/* FCEU_printf(" %04x [%02x]",0xc000^pswap,block | (bank2 & mask)); */ + setprg8(0xc000 ^ pswap, block | (bank2 & mask)); +/* FCEU_printf(" %04x [%02x]\n",0xe000^pswap,block | (bank3 & mask)); */ + setprg8(0xe000, block | (bank3 & mask)); +} + +static void CSync(void) { + static const uint8 midx[8] = { 0, 1, 2, 0, 3, 4, 5, 0 }; + uint8 mask = 0xff >> midx[ppu201x[0xa] & 7]; + uint32 block = ((cpu410x[0x0] & 0x0f) << 11) + ((ppu201x[0x8] & 0x70) << 4) + (ppu201x[0xa] & (~mask)); + uint32 cswap = (mmc3cmd & 0x80) << 5; + + uint8 bank0 = ppu201x[0x6] & (~1); + uint8 bank1 = ppu201x[0x6] | 1; + uint8 bank2 = ppu201x[0x7] & (~1); + uint8 bank3 = ppu201x[0x7] | 1; + uint8 bank4 = ppu201x[0x2]; + uint8 bank5 = ppu201x[0x3]; + uint8 bank6 = ppu201x[0x4]; + uint8 bank7 = ppu201x[0x5]; + + setchr1(0x0000 ^ cswap, block | (bank0 & mask)); + setchr1(0x0400 ^ cswap, block | (bank1 & mask)); + setchr1(0x0800 ^ cswap, block | (bank2 & mask)); + setchr1(0x0c00 ^ cswap, block | (bank3 & mask)); + setchr1(0x1000 ^ cswap, block | (bank4 & mask)); + setchr1(0x1400 ^ cswap, block | (bank5 & mask)); + setchr1(0x1800 ^ cswap, block | (bank6 & mask)); + setchr1(0x1c00 ^ cswap, block | (bank7 & mask)); + + setmirror((mirror ^ 1) & 1); +} + +static void Sync(void) { + PSync(); + CSync(); +} + +static DECLFW(UNLOneBusWriteCPU410X) { +/* FCEU_printf("CPU %04x:%04x\n",A,V); */ + switch (A & 0xf) { + case 0x1: IRQLatch = V & 0xfe; break; /* íå ïî äàòàøèòó */ + case 0x2: IRQReload = 1; break; + case 0x3: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0x4: IRQa = 1; break; + default: + cpu410x[A & 0xf] = V; + Sync(); + } +} + +static DECLFW(UNLOneBusWritePPU201X) { +/* FCEU_printf("PPU %04x:%04x\n",A,V); */ + ppu201x[A & 0x0f] = V; + Sync(); +} + +static DECLFW(UNLOneBusWriteMMC3) { +/* FCEU_printf("MMC %04x:%04x\n",A,V); */ + switch (A & 0xe001) { + case 0x8000: mmc3cmd = (mmc3cmd & 0x38) | (V & 0xc7); Sync(); break; + case 0x8001: + { + switch (mmc3cmd & 7) { + case 0: ppu201x[0x6] = V; CSync(); break; + case 1: ppu201x[0x7] = V; CSync(); break; + case 2: ppu201x[0x2] = V; CSync(); break; + case 3: ppu201x[0x3] = V; CSync(); break; + case 4: ppu201x[0x4] = V; CSync(); break; + case 5: ppu201x[0x5] = V; CSync(); break; + case 6: cpu410x[0x7] = V; PSync(); break; + case 7: cpu410x[0x8] = V; PSync(); break; + } + break; + } + case 0xa000: mirror = V; CSync(); break; + case 0xc000: IRQLatch = V & 0xfe; break; + case 0xc001: IRQReload = 1; break; + case 0xe000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0xe001: IRQa = 1; break; + } +} + +static void UNLOneBusIRQHook(void) { + uint32 count = IRQCount; + if (!count || IRQReload) { + IRQCount = IRQLatch; + IRQReload = 0; + } else + IRQCount--; + if (count && !IRQCount) { + if (IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static DECLFW(UNLOneBusWriteAPU40XX) { +/* if(((A & 0x3f)!=0x16) && ((apu40xx[0x30] & 0x10) || ((A & 0x3f)>0x17)))FCEU_printf("APU %04x:%04x\n",A,V); */ + apu40xx[A & 0x3f] = V; + switch (A & 0x3f) { + case 0x12: + if (apu40xx[0x30] & 0x10) { + pcm_addr = V << 6; + } + break; + case 0x13: + if (apu40xx[0x30] & 0x10) { + pcm_size = (V << 4) + 1; + } + break; + case 0x15: + if (apu40xx[0x30] & 0x10) { + pcm_enable = V & 0x10; + if (pcm_irq) { + X6502_IRQEnd(FCEU_IQEXT); + pcm_irq = 0; + } + if (pcm_enable) + pcm_latch = pcm_clock; + V &= 0xef; + } + break; + } + defapuwrite[A & 0x3f](A, V); +} + +static DECLFR(UNLOneBusReadAPU40XX) { + uint8 result = defapuread[A & 0x3f](A); +/* FCEU_printf("read %04x, %02x\n",A,result); */ + switch (A & 0x3f) { + case 0x15: + if (apu40xx[0x30] & 0x10) { + result = (result & 0x7f) | pcm_irq; + } + break; + } + return result; +} + +static void UNLOneBusCpuHook(int a) { + if (pcm_enable) { + pcm_latch -= a; + if (pcm_latch <= 0) { + pcm_latch += pcm_clock; + pcm_size--; + if (pcm_size < 0) { + pcm_irq = 0x80; + pcm_enable = 0; + X6502_IRQBegin(FCEU_IQEXT); + } else { + uint16 addr = pcm_addr | ((apu40xx[0x30]^3) << 14); + uint8 raw_pcm = ARead[addr](addr) >> 1; + defapuwrite[0x11](0x4011, raw_pcm); + pcm_addr++; + pcm_addr &= 0x7FFF; + } + } + } +} + +static void UNLOneBusPower(void) { + uint32 i; + IRQReload = IRQCount = IRQa = 0; + + memset(cpu410x, 0x00, sizeof(cpu410x)); + memset(ppu201x, 0x00, sizeof(ppu201x)); + memset(apu40xx, 0x00, sizeof(apu40xx)); + + SetupCartCHRMapping(0, PRGptr[0], PRGsize[0], 0); + + for (i = 0; i < 64; i++) { + defapuread[i] = GetReadHandler(0x4000 | i); + defapuwrite[i] = GetWriteHandler(0x4000 | i); + } + SetReadHandler(0x4000, 0x403f, UNLOneBusReadAPU40XX); + SetWriteHandler(0x4000, 0x403f, UNLOneBusWriteAPU40XX); + + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x2010, 0x201f, UNLOneBusWritePPU201X); + SetWriteHandler(0x4100, 0x410f, UNLOneBusWriteCPU410X); + SetWriteHandler(0x8000, 0xffff, UNLOneBusWriteMMC3); + + Sync(); +} + +static void UNLOneBusReset(void) { + IRQReload = IRQCount = IRQa = 0; + + memset(cpu410x, 0x00, sizeof(cpu410x)); + memset(ppu201x, 0x00, sizeof(ppu201x)); + memset(apu40xx, 0x00, sizeof(apu40xx)); + + Sync(); +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLOneBus_Init(CartInfo *info) { + info->Power = UNLOneBusPower; + info->Reset = UNLOneBusReset; + + if (((*(uint32*)&(info->MD5)) == 0x305fcdc3) || /* PowerJoy Supermax Carts */ + ((*(uint32*)&(info->MD5)) == 0x6abfce8e)) + inv_hack = 0xf; + + GameHBIRQHook = UNLOneBusIRQHook; + MapIRQHook = UNLOneBusCpuHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/pec-586.c b/src/boards/pec-586.c index fce3883..536905d 100644 --- a/src/boards/pec-586.c +++ b/src/boards/pec-586.c @@ -1,128 +1,128 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - */ - -#include "mapinc.h" - -static uint8 reg[8]; -static uint32 lastnt = 0; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { reg, 2, "REG" }, - { &lastnt, 4, "LNT" }, - { 0 } -}; - -static uint8 bs_tbl[128] = { - 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, /* 00 */ - 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, /* 10 */ - 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, /* 20 */ - 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, /* 30 */ - 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, /* 40 */ - 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, /* 50 */ - 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30, /* 60 */ - 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, /* 70 */ -}; - -static uint8 br_tbl[16] = { - 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, -}; - -static void Sync(void) { - setchr8(0); - setprg8r(0x10, 0x6000, 0); - if(PRGsize[0] == 512 * 1024) { - if(reg[0] & 0x010) { - setprg32(0x8000, reg[0] & 7); - } else { - if(reg[0] & 0x40) - setprg8(0x8000, (reg[0] & 0x0F) | 0x20 | ((reg[0] & 0x20) >> 1)); - } - if((reg[0] & 0x18) == 0x18) - setmirror(MI_H); - else - setmirror(MI_V); - } else { - setprg16(0x8000, bs_tbl[reg[0] & 0x7f] >> 4); - setprg16(0xc000, bs_tbl[reg[0] & 0x7f] & 0xf); - setmirror(MI_V); - } -} - -static DECLFW(UNLPEC586Write) { - reg[(A & 0x700) >> 8] = V; - PEC586Hack = (reg[0] & 0x80) >> 7; -/* FCEU_printf("bs %04x %02x\n", A, V); */ - Sync(); -} - -static DECLFR(UNLPEC586Read) { -/* FCEU_printf("read %04x\n", A); */ - return (X.DB & 0xD8) | br_tbl[reg[4] >> 4]; -} - -static DECLFR(UNLPEC586ReadHi) { - if((reg[0] & 0x10) || ((reg[0] & 0x40) && (A < 0xA000))) - return CartBR(A); - else - return PRGptr[0][((0x0107 | ((A >> 7) & 0x0F8)) << 10) | (A & 0x3FF)]; -} - -static void UNLPEC586Power(void) { - if(PRGsize[0] == 512 * 1024) - reg[0] = 0x00; - else - reg[0] = 0x0E; - Sync(); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - if(PRGsize[0] == 512 * 1024) - SetReadHandler(0x8000, 0xFFFF, UNLPEC586ReadHi); - else - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x5000, 0x5fff, UNLPEC586Write); - SetReadHandler(0x5000, 0x5fff, UNLPEC586Read); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void UNLPEC586Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLPEC586Init(CartInfo *info) { - info->Power = UNLPEC586Power; - info->Close = UNLPEC586Close; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint32 lastnt = 0; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { reg, 2, "REG" }, + { &lastnt, 4, "LNT" }, + { 0 } +}; + +static uint8 bs_tbl[128] = { + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, /* 00 */ + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, /* 10 */ + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, /* 20 */ + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, /* 30 */ + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, /* 40 */ + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, /* 50 */ + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30, /* 60 */ + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, /* 70 */ +}; + +static uint8 br_tbl[16] = { + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, +}; + +static void Sync(void) { + setchr8(0); + setprg8r(0x10, 0x6000, 0); + if(PRGsize[0] == 512 * 1024) { + if(reg[0] & 0x010) { + setprg32(0x8000, reg[0] & 7); + } else { + if(reg[0] & 0x40) + setprg8(0x8000, (reg[0] & 0x0F) | 0x20 | ((reg[0] & 0x20) >> 1)); + } + if((reg[0] & 0x18) == 0x18) + setmirror(MI_H); + else + setmirror(MI_V); + } else { + setprg16(0x8000, bs_tbl[reg[0] & 0x7f] >> 4); + setprg16(0xc000, bs_tbl[reg[0] & 0x7f] & 0xf); + setmirror(MI_V); + } +} + +static DECLFW(UNLPEC586Write) { + reg[(A & 0x700) >> 8] = V; + PEC586Hack = (reg[0] & 0x80) >> 7; +/* FCEU_printf("bs %04x %02x\n", A, V); */ + Sync(); +} + +static DECLFR(UNLPEC586Read) { +/* FCEU_printf("read %04x\n", A); */ + return (X.DB & 0xD8) | br_tbl[reg[4] >> 4]; +} + +static DECLFR(UNLPEC586ReadHi) { + if((reg[0] & 0x10) || ((reg[0] & 0x40) && (A < 0xA000))) + return CartBR(A); + else + return PRGptr[0][((0x0107 | ((A >> 7) & 0x0F8)) << 10) | (A & 0x3FF)]; +} + +static void UNLPEC586Power(void) { + if(PRGsize[0] == 512 * 1024) + reg[0] = 0x00; + else + reg[0] = 0x0E; + Sync(); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + if(PRGsize[0] == 512 * 1024) + SetReadHandler(0x8000, 0xFFFF, UNLPEC586ReadHi); + else + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x5000, 0x5fff, UNLPEC586Write); + SetReadHandler(0x5000, 0x5fff, UNLPEC586Read); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void UNLPEC586Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLPEC586Init(CartInfo *info) { + info->Power = UNLPEC586Power; + info->Close = UNLPEC586Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/sc-127.c b/src/boards/sc-127.c index 2d2d968..127fcb8 100644 --- a/src/boards/sc-127.c +++ b/src/boards/sc-127.c @@ -1,123 +1,123 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * Wario Land II (Kirby hack) - */ - -#include "mapinc.h" - -static uint8 reg[8], chr[8]; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; -static uint16 IRQCount, IRQa; - -static SFORMAT StateRegs[] = -{ - { reg, 8, "REGS" }, - { chr, 8, "CHRS" }, - { &IRQCount, 2, "IRQc" }, - { &IRQa, 2, "IRQa" }, - { 0 } -}; - -static void Sync(void) { - int i; - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, reg[0]); - setprg8(0xA000, reg[1]); - setprg8(0xC000, reg[2]); - setprg8(0xE000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, chr[i]); - setmirror(reg[3] ^ 1); -} - -static DECLFW(UNLSC127Write) { - switch (A) { - case 0x8000: reg[0] = V; break; - case 0x8001: reg[1] = V; break; - case 0x8002: reg[2] = V; break; - case 0x9000: chr[0] = V; break; - case 0x9001: chr[1] = V; break; - case 0x9002: chr[2] = V; break; - case 0x9003: chr[3] = V; break; - case 0x9004: chr[4] = V; break; - case 0x9005: chr[5] = V; break; - case 0x9006: chr[6] = V; break; - case 0x9007: chr[7] = V; break; - case 0xC002: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xC005: IRQCount = V; break; - case 0xC003: IRQa = 1; break; - case 0xD001: reg[3] = V; break; - } - Sync(); -} - -static DECLFR(UNLSC127ProtRead) { - return 0x20; -} - -static void UNLSC127Power(void) { - IRQCount = IRQa = 0; - Sync(); - SetReadHandler(0x5800, 0x5800, UNLSC127ProtRead); - SetReadHandler(0x6000, 0x7fff, CartBR); - SetWriteHandler(0x6000, 0x7fff, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLSC127Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void UNLSC127IRQ(void) { - if (IRQa) { - if(IRQCount > 0) - IRQCount--; - if (!IRQCount) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - } - } -} - -static void UNLSC127Reset(void) { - IRQCount = IRQa = 0; -} - -static void UNLSC127Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLSC127_Init(CartInfo *info) { - info->Reset = UNLSC127Reset; - info->Power = UNLSC127Power; - info->Close = UNLSC127Close; - GameHBIRQHook = UNLSC127IRQ; - GameStateRestore = StateRestore; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * Wario Land II (Kirby hack) + */ + +#include "mapinc.h" + +static uint8 reg[8], chr[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; +static uint16 IRQCount, IRQa; + +static SFORMAT StateRegs[] = +{ + { reg, 8, "REGS" }, + { chr, 8, "CHRS" }, + { &IRQCount, 2, "IRQc" }, + { &IRQa, 2, "IRQa" }, + { 0 } +}; + +static void Sync(void) { + int i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, reg[0]); + setprg8(0xA000, reg[1]); + setprg8(0xC000, reg[2]); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + setmirror(reg[3] ^ 1); +} + +static DECLFW(UNLSC127Write) { + switch (A) { + case 0x8000: reg[0] = V; break; + case 0x8001: reg[1] = V; break; + case 0x8002: reg[2] = V; break; + case 0x9000: chr[0] = V; break; + case 0x9001: chr[1] = V; break; + case 0x9002: chr[2] = V; break; + case 0x9003: chr[3] = V; break; + case 0x9004: chr[4] = V; break; + case 0x9005: chr[5] = V; break; + case 0x9006: chr[6] = V; break; + case 0x9007: chr[7] = V; break; + case 0xC002: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xC005: IRQCount = V; break; + case 0xC003: IRQa = 1; break; + case 0xD001: reg[3] = V; break; + } + Sync(); +} + +static DECLFR(UNLSC127ProtRead) { + return 0x20; +} + +static void UNLSC127Power(void) { + IRQCount = IRQa = 0; + Sync(); + SetReadHandler(0x5800, 0x5800, UNLSC127ProtRead); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLSC127Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void UNLSC127IRQ(void) { + if (IRQa) { + if(IRQCount > 0) + IRQCount--; + if (!IRQCount) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void UNLSC127Reset(void) { + IRQCount = IRQa = 0; +} + +static void UNLSC127Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLSC127_Init(CartInfo *info) { + info->Reset = UNLSC127Reset; + info->Power = UNLSC127Power; + info->Close = UNLSC127Close; + GameHBIRQHook = UNLSC127IRQ; + GameStateRestore = StateRestore; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/sheroes.c b/src/boards/sheroes.c index 651671b..6fe8a6e 100644 --- a/src/boards/sheroes.c +++ b/src/boards/sheroes.c @@ -1,79 +1,79 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 *CHRRAM; -static uint8 tekker; - -static void MSHCW(uint32 A, uint8 V) { - if (EXPREGS[0] & 0x40) - setchr8r(0x10, 0); - else { - if (A < 0x800) - setchr1(A, V | ((EXPREGS[0] & 8) << 5)); - else if (A < 0x1000) - setchr1(A, V | ((EXPREGS[0] & 4) << 6)); - else if (A < 0x1800) - setchr1(A, V | ((EXPREGS[0] & 1) << 8)); - else - setchr1(A, V | ((EXPREGS[0] & 2) << 7)); - } -} - -static DECLFW(MSHWrite) { - EXPREGS[0] = V; - FixMMC3CHR(MMC3_cmd); -} - -static DECLFR(MSHRead) { - return(tekker); -} - -static void MSHReset(void) { - MMC3RegReset(); - tekker ^= 0xFF; -} - -static void MSHPower(void) { - tekker = 0x00; - GenMMC3Power(); - SetWriteHandler(0x4100, 0x4100, MSHWrite); - SetReadHandler(0x4100, 0x4100, MSHRead); -} - -static void MSHClose(void) { - if (CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; -} - -void UNLSHeroes_Init(CartInfo *info) { - GenMMC3_Init(info, 256, 512, 0, 0); - cwrap = MSHCW; - info->Power = MSHPower; - info->Reset = MSHReset; - info->Close = MSHClose; - CHRRAM = (uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); - AddExState(EXPREGS, 4, 0, "EXPR"); - AddExState(&tekker, 1, 0, "DIPSW"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 *CHRRAM; +static uint8 tekker; + +static void MSHCW(uint32 A, uint8 V) { + if (EXPREGS[0] & 0x40) + setchr8r(0x10, 0); + else { + if (A < 0x800) + setchr1(A, V | ((EXPREGS[0] & 8) << 5)); + else if (A < 0x1000) + setchr1(A, V | ((EXPREGS[0] & 4) << 6)); + else if (A < 0x1800) + setchr1(A, V | ((EXPREGS[0] & 1) << 8)); + else + setchr1(A, V | ((EXPREGS[0] & 2) << 7)); + } +} + +static DECLFW(MSHWrite) { + EXPREGS[0] = V; + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(MSHRead) { + return(tekker); +} + +static void MSHReset(void) { + MMC3RegReset(); + tekker ^= 0xFF; +} + +static void MSHPower(void) { + tekker = 0x00; + GenMMC3Power(); + SetWriteHandler(0x4100, 0x4100, MSHWrite); + SetReadHandler(0x4100, 0x4100, MSHRead); +} + +static void MSHClose(void) { + if (CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +void UNLSHeroes_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 512, 0, 0); + cwrap = MSHCW; + info->Power = MSHPower; + info->Reset = MSHReset; + info->Close = MSHClose; + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(EXPREGS, 4, 0, "EXPR"); + AddExState(&tekker, 1, 0, "DIPSW"); +} diff --git a/src/boards/sl1632.c b/src/boards/sl1632.c index 43b8abb..33c38ee 100644 --- a/src/boards/sl1632.c +++ b/src/boards/sl1632.c @@ -1,111 +1,111 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * SL1632 2-in-1 protected board, similar to SL12 - * Samurai Spirits Rex (Full) - * - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; -static SFORMAT StateRegs[] = -{ - { chrcmd, 8, "CHRC" }, - { &prg0, 1, "PRG0" }, - { &prg1, 1, "PRG1" }, - { &bbrk, 1, "BRK" }, - { &mirr, 1, "MIRR" }, - { &swap, 1, "SWAP" }, - { 0 } -}; - -static void Sync(void) { - int i; - setprg8(0x8000, prg0); - setprg8(0xA000, prg1); - setprg8(0xC000, ~1); - setprg8(0xE000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, chrcmd[i]); - setmirror(mirr ^ 1); -} - -static void UNLSL1632CW(uint32 A, uint8 V) { - int cbase = (MMC3_cmd & 0x80) << 5; - int page0 = (bbrk & 0x08) << 5; - int page1 = (bbrk & 0x20) << 3; - int page2 = (bbrk & 0x80) << 1; - setchr1(cbase ^ 0x0000, page0 | (DRegBuf[0] & (~1))); - setchr1(cbase ^ 0x0400, page0 | DRegBuf[0] | 1); - setchr1(cbase ^ 0x0800, page0 | (DRegBuf[1] & (~1))); - setchr1(cbase ^ 0x0C00, page0 | DRegBuf[1] | 1); - setchr1(cbase ^ 0x1000, page1 | DRegBuf[2]); - setchr1(cbase ^ 0x1400, page1 | DRegBuf[3]); - setchr1(cbase ^ 0x1800, page2 | DRegBuf[4]); - setchr1(cbase ^ 0x1c00, page2 | DRegBuf[5]); -} - -static DECLFW(UNLSL1632CMDWrite) { - if (A == 0xA131) { - bbrk = V; - } - if (bbrk & 2) { - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - if (A < 0xC000) - MMC3_CMDWrite(A, V); - else - MMC3_IRQWrite(A, V); - } else { - if ((A >= 0xB000) && (A <= 0xE003)) { - int ind = ((((A & 2) | (A >> 10)) >> 1) + 2) & 7; - int sar = ((A & 1) << 2); - chrcmd[ind] = (chrcmd[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); - } else - switch (A & 0xF003) { - case 0x8000: prg0 = V; break; - case 0xA000: prg1 = V; break; - case 0x9000: mirr = V & 1; break; - } - Sync(); - } -} - -static void StateRestore(int version) { - if (bbrk & 2) { - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } else - Sync(); -} - -static void UNLSL1632Power(void) { - GenMMC3Power(); - SetWriteHandler(0x4100, 0xFFFF, UNLSL1632CMDWrite); -} - -void UNLSL1632_Init(CartInfo *info) { - GenMMC3_Init(info, 256, 512, 0, 0); - cwrap = UNLSL1632CW; - info->Power = UNLSL1632Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * SL1632 2-in-1 protected board, similar to SL12 + * Samurai Spirits Rex (Full) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; +static SFORMAT StateRegs[] = +{ + { chrcmd, 8, "CHRC" }, + { &prg0, 1, "PRG0" }, + { &prg1, 1, "PRG1" }, + { &bbrk, 1, "BRK" }, + { &mirr, 1, "MIRR" }, + { &swap, 1, "SWAP" }, + { 0 } +}; + +static void Sync(void) { + int i; + setprg8(0x8000, prg0); + setprg8(0xA000, prg1); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chrcmd[i]); + setmirror(mirr ^ 1); +} + +static void UNLSL1632CW(uint32 A, uint8 V) { + int cbase = (MMC3_cmd & 0x80) << 5; + int page0 = (bbrk & 0x08) << 5; + int page1 = (bbrk & 0x20) << 3; + int page2 = (bbrk & 0x80) << 1; + setchr1(cbase ^ 0x0000, page0 | (DRegBuf[0] & (~1))); + setchr1(cbase ^ 0x0400, page0 | DRegBuf[0] | 1); + setchr1(cbase ^ 0x0800, page0 | (DRegBuf[1] & (~1))); + setchr1(cbase ^ 0x0C00, page0 | DRegBuf[1] | 1); + setchr1(cbase ^ 0x1000, page1 | DRegBuf[2]); + setchr1(cbase ^ 0x1400, page1 | DRegBuf[3]); + setchr1(cbase ^ 0x1800, page2 | DRegBuf[4]); + setchr1(cbase ^ 0x1c00, page2 | DRegBuf[5]); +} + +static DECLFW(UNLSL1632CMDWrite) { + if (A == 0xA131) { + bbrk = V; + } + if (bbrk & 2) { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + if (A < 0xC000) + MMC3_CMDWrite(A, V); + else + MMC3_IRQWrite(A, V); + } else { + if ((A >= 0xB000) && (A <= 0xE003)) { + int ind = ((((A & 2) | (A >> 10)) >> 1) + 2) & 7; + int sar = ((A & 1) << 2); + chrcmd[ind] = (chrcmd[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + } else + switch (A & 0xF003) { + case 0x8000: prg0 = V; break; + case 0xA000: prg1 = V; break; + case 0x9000: mirr = V & 1; break; + } + Sync(); + } +} + +static void StateRestore(int version) { + if (bbrk & 2) { + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else + Sync(); +} + +static void UNLSL1632Power(void) { + GenMMC3Power(); + SetWriteHandler(0x4100, 0xFFFF, UNLSL1632CMDWrite); +} + +void UNLSL1632_Init(CartInfo *info) { + GenMMC3_Init(info, 256, 512, 0, 0); + cwrap = UNLSL1632CW; + info->Power = UNLSL1632Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/subor.c b/src/boards/subor.c index 00d9a99..4f9a9bb 100644 --- a/src/boards/subor.c +++ b/src/boards/subor.c @@ -1,88 +1,88 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - */ - -#include "mapinc.h" - -static uint8 is167, regs[4]; - -static SFORMAT StateRegs[] = -{ - { regs, 4, "DREG" }, - { 0 } -}; - -static void Sync(void) { - int base, bank; - base = ((regs[0] ^ regs[1]) & 0x10) << 1; - bank = (regs[2] ^ regs[3]) & 0x1f; - - if (regs[1] & 0x08) { - bank &= 0xFE; - if (is167) { - setprg16(0x8000, base + bank + 1); - setprg16(0xC000, base + bank + 0); - } else { - setprg16(0x8000, base + bank + 0); - setprg16(0xC000, base + bank + 1); - } - } else { - if (regs[1] & 0x04) { - setprg16(0x8000, 0x1F); - setprg16(0xC000, base + bank); - } else { - setprg16(0x8000, base + bank); - if (is167) - setprg16(0xC000, 0x20); - else - setprg16(0xC000, 0x07); - } - } - setchr8(0); -} - -static DECLFW(M166Write) { - regs[(A >> 13) & 0x03] = V; - Sync(); -} - -static void M166Power(void) { - regs[0] = regs[1] = regs[2] = regs[3] = 0; - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M166Write); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper166_Init(CartInfo *info) { - is167 = 0; - info->Power = M166Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper167_Init(CartInfo *info) { - is167 = 1; - info->Power = M166Power; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + */ + +#include "mapinc.h" + +static uint8 is167, regs[4]; + +static SFORMAT StateRegs[] = +{ + { regs, 4, "DREG" }, + { 0 } +}; + +static void Sync(void) { + int base, bank; + base = ((regs[0] ^ regs[1]) & 0x10) << 1; + bank = (regs[2] ^ regs[3]) & 0x1f; + + if (regs[1] & 0x08) { + bank &= 0xFE; + if (is167) { + setprg16(0x8000, base + bank + 1); + setprg16(0xC000, base + bank + 0); + } else { + setprg16(0x8000, base + bank + 0); + setprg16(0xC000, base + bank + 1); + } + } else { + if (regs[1] & 0x04) { + setprg16(0x8000, 0x1F); + setprg16(0xC000, base + bank); + } else { + setprg16(0x8000, base + bank); + if (is167) + setprg16(0xC000, 0x20); + else + setprg16(0xC000, 0x07); + } + } + setchr8(0); +} + +static DECLFW(M166Write) { + regs[(A >> 13) & 0x03] = V; + Sync(); +} + +static void M166Power(void) { + regs[0] = regs[1] = regs[2] = regs[3] = 0; + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M166Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper166_Init(CartInfo *info) { + is167 = 0; + info->Power = M166Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper167_Init(CartInfo *info) { + is167 = 1; + info->Power = M166Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/t-227-1.c b/src/boards/t-227-1.c index cc13960..847c9c0 100644 --- a/src/boards/t-227-1.c +++ b/src/boards/t-227-1.c @@ -1,100 +1,100 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2008 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 - */ - -/* T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 reset_flag = 0x07; - -static void BMCT2271CW(uint32 A, uint8 V) { - uint32 va = V; - if (EXPREGS[0] & 0x20) { - va |= 0x200; - va |= (EXPREGS[0] & 0x10) << 4; - } else { - va &= 0x7F; - va |= (EXPREGS[0] & 0x18) << 4; - } - setchr1(A, va); -} - -static void BMCT2271PW(uint32 A, uint8 V) { - uint32 va = V & 0x3F; - if (EXPREGS[0] & 0x20) { - va &= 0x1F; - va |= 0x40; - va |= (EXPREGS[0] & 0x10) << 1; - } else { - va &= 0x0F; - va |= (EXPREGS[0] & 0x18) << 1; - } - switch (EXPREGS[0] & 3) { - case 0x00: setprg8(A, va); break; - case 0x02: - { - va = (va & 0xFD) | ((EXPREGS[0] & 4) >> 1); - if (A < 0xC000) { - setprg16(0x8000, va >> 1); - setprg16(0xC000, va >> 1); - } - break; - } - case 0x01: - case 0x03: if (A < 0xC000) setprg32(0x8000, va >> 2); break; - } -} - -static DECLFW(BMCT2271LoWrite) { - if (!(EXPREGS[0] & 0x80)) - EXPREGS[0] = A & 0xFF; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static DECLFR(BMCT2271HiRead) { - uint32 av = A; - if (EXPREGS[0] & 0x40) av = (av & 0xFFF0) | reset_flag; - return CartBR(av); -} - -static void BMCT2271Reset(void) { - EXPREGS[0] = 0x00; - reset_flag++; - reset_flag &= 0x0F; - MMC3RegReset(); -} - -static void BMCT2271Power(void) { - EXPREGS[0] = 0x00; - GenMMC3Power(); - SetWriteHandler(0x6000, 0x7FFF, BMCT2271LoWrite); - SetReadHandler(0x8000, 0xFFFF, BMCT2271HiRead); -} - -void BMCT2271_Init(CartInfo *info) { - GenMMC3_Init(info, 128, 128, 8, 0); - pwrap = BMCT2271PW; - cwrap = BMCT2271CW; - info->Power = BMCT2271Power; - info->Reset = BMCT2271Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 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 + */ + +/* T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0x07; + +static void BMCT2271CW(uint32 A, uint8 V) { + uint32 va = V; + if (EXPREGS[0] & 0x20) { + va |= 0x200; + va |= (EXPREGS[0] & 0x10) << 4; + } else { + va &= 0x7F; + va |= (EXPREGS[0] & 0x18) << 4; + } + setchr1(A, va); +} + +static void BMCT2271PW(uint32 A, uint8 V) { + uint32 va = V & 0x3F; + if (EXPREGS[0] & 0x20) { + va &= 0x1F; + va |= 0x40; + va |= (EXPREGS[0] & 0x10) << 1; + } else { + va &= 0x0F; + va |= (EXPREGS[0] & 0x18) << 1; + } + switch (EXPREGS[0] & 3) { + case 0x00: setprg8(A, va); break; + case 0x02: + { + va = (va & 0xFD) | ((EXPREGS[0] & 4) >> 1); + if (A < 0xC000) { + setprg16(0x8000, va >> 1); + setprg16(0xC000, va >> 1); + } + break; + } + case 0x01: + case 0x03: if (A < 0xC000) setprg32(0x8000, va >> 2); break; + } +} + +static DECLFW(BMCT2271LoWrite) { + if (!(EXPREGS[0] & 0x80)) + EXPREGS[0] = A & 0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(BMCT2271HiRead) { + uint32 av = A; + if (EXPREGS[0] & 0x40) av = (av & 0xFFF0) | reset_flag; + return CartBR(av); +} + +static void BMCT2271Reset(void) { + EXPREGS[0] = 0x00; + reset_flag++; + reset_flag &= 0x0F; + MMC3RegReset(); +} + +static void BMCT2271Power(void) { + EXPREGS[0] = 0x00; + GenMMC3Power(); + SetWriteHandler(0x6000, 0x7FFF, BMCT2271LoWrite); + SetReadHandler(0x8000, 0xFFFF, BMCT2271HiRead); +} + +void BMCT2271_Init(CartInfo *info) { + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap = BMCT2271PW; + cwrap = BMCT2271CW; + info->Power = BMCT2271Power; + info->Reset = BMCT2271Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/t-262.c b/src/boards/t-262.c index 01b873b..ae8c818 100644 --- a/src/boards/t-262.c +++ b/src/boards/t-262.c @@ -1,73 +1,73 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - */ - -#include "mapinc.h" - -static uint8 bank, base, lock, mirr, mode; -static SFORMAT StateRegs[] = -{ - { &bank, 1, "BANK" }, - { &base, 1, "BASE" }, - { &lock, 1, "LOCK" }, - { &mirr, 1, "MIRR" }, - { &mode, 1, "MODE" }, - { 0 } -}; - -static void Sync(void) { - setchr8(0); - setprg16(0x8000, base | bank); - setprg16(0xC000, base | (mode ? bank : 7)); - setmirror(mirr); -} - -static DECLFW(BMCT262Write) { - if (!lock) { - base = ((A & 0x60) >> 2) | ((A & 0x100) >> 3); - mode = A & 0x80; - mirr = ((A & 2) >> 1) ^ 1; - lock = (A & 0x2000) >> 13; - } - bank = V & 7; - Sync(); -} - -static void BMCT262Power(void) { - lock = bank = base = mode = 0; - Sync(); - SetWriteHandler(0x8000, 0xFFFF, BMCT262Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void BMCT262Reset(void) { - lock = bank = base = mode = 0; - Sync(); -} - -static void BMCT262Restore(int version) { - Sync(); -} - -void BMCT262_Init(CartInfo *info) { - info->Power = BMCT262Power; - info->Reset = BMCT262Reset; - GameStateRestore = BMCT262Restore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + */ + +#include "mapinc.h" + +static uint8 bank, base, lock, mirr, mode; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &base, 1, "BASE" }, + { &lock, 1, "LOCK" }, + { &mirr, 1, "MIRR" }, + { &mode, 1, "MODE" }, + { 0 } +}; + +static void Sync(void) { + setchr8(0); + setprg16(0x8000, base | bank); + setprg16(0xC000, base | (mode ? bank : 7)); + setmirror(mirr); +} + +static DECLFW(BMCT262Write) { + if (!lock) { + base = ((A & 0x60) >> 2) | ((A & 0x100) >> 3); + mode = A & 0x80; + mirr = ((A & 2) >> 1) ^ 1; + lock = (A & 0x2000) >> 13; + } + bank = V & 7; + Sync(); +} + +static void BMCT262Power(void) { + lock = bank = base = mode = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, BMCT262Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void BMCT262Reset(void) { + lock = bank = base = mode = 0; + Sync(); +} + +static void BMCT262Restore(int version) { + Sync(); +} + +void BMCT262_Init(CartInfo *info) { + info->Power = BMCT262Power; + info->Reset = BMCT262Reset; + GameStateRestore = BMCT262Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/tf-1201.c b/src/boards/tf-1201.c index 24e8a77..6470e0f 100644 --- a/src/boards/tf-1201.c +++ b/src/boards/tf-1201.c @@ -1,109 +1,109 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005 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 - * - * Lethal Weapon (VRC4 mapper) - */ - -#include "mapinc.h" - -static uint8 prg0, prg1, mirr, swap; -static uint8 chr[8]; -static uint8 IRQCount; -static uint8 IRQPre; -static uint8 IRQa; - -static SFORMAT StateRegs[] = -{ - { &prg0, 1, "PRG0" }, - { &prg0, 1, "PRG1" }, - { &mirr, 1, "MIRR" }, - { &swap, 1, "SWAP" }, - { chr, 8, "CHR" }, - { &IRQCount, 1, "IRQC" }, - { &IRQPre, 1, "IRQP" }, - { &IRQa, 1, "IRQA" }, - { 0 } -}; - -static void SyncPrg(void) { - if (swap & 3) { - setprg8(0x8000, ~1); - setprg8(0xC000, prg0); - } else { - setprg8(0x8000, prg0); - setprg8(0xC000, ~1); - } - setprg8(0xA000, prg1); - setprg8(0xE000, ~0); -} - -static void SyncChr(void) { - int i; - for (i = 0; i < 8; i++) - setchr1(i << 10, chr[i]); - setmirror(mirr ^ 1); -} - -static void StateRestore(int version) { - SyncPrg(); - SyncChr(); -} - -static DECLFW(UNLTF1201Write) { - A = (A & 0xF003) | ((A & 0xC) >> 2); - if ((A >= 0xB000) && (A <= 0xE003)) { - int ind = (((A >> 11) - 6) | (A & 1)) & 7; - int sar = ((A & 2) << 1); - chr[ind] = (chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); - SyncChr(); - } else switch (A & 0xF003) { - case 0x8000: prg0 = V; SyncPrg(); break; - case 0xA000: prg1 = V; SyncPrg(); break; - case 0x9000: mirr = V & 1; SyncChr(); break; - case 0x9001: swap = V & 3; SyncPrg(); break; - case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; - case 0xF002: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; - case 0xF001: - case 0xF003: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); if (scanline < 240) IRQCount -= 8; break; - } -} - -static void UNLTF1201IRQCounter(void) { - if (IRQa) { - IRQCount++; - if (IRQCount == 237) { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void UNLTF1201Power(void) { - IRQPre = IRQCount = IRQa = 0; - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLTF1201Write); - SyncPrg(); - SyncChr(); -} - -void UNLTF1201_Init(CartInfo *info) { - info->Power = UNLTF1201Power; - GameHBIRQHook = UNLTF1201IRQCounter; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 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 + * + * Lethal Weapon (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg0, prg1, mirr, swap; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[] = +{ + { &prg0, 1, "PRG0" }, + { &prg0, 1, "PRG1" }, + { &mirr, 1, "MIRR" }, + { &swap, 1, "SWAP" }, + { chr, 8, "CHR" }, + { &IRQCount, 1, "IRQC" }, + { &IRQPre, 1, "IRQP" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static void SyncPrg(void) { + if (swap & 3) { + setprg8(0x8000, ~1); + setprg8(0xC000, prg0); + } else { + setprg8(0x8000, prg0); + setprg8(0xC000, ~1); + } + setprg8(0xA000, prg1); + setprg8(0xE000, ~0); +} + +static void SyncChr(void) { + int i; + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + setmirror(mirr ^ 1); +} + +static void StateRestore(int version) { + SyncPrg(); + SyncChr(); +} + +static DECLFW(UNLTF1201Write) { + A = (A & 0xF003) | ((A & 0xC) >> 2); + if ((A >= 0xB000) && (A <= 0xE003)) { + int ind = (((A >> 11) - 6) | (A & 1)) & 7; + int sar = ((A & 2) << 1); + chr[ind] = (chr[ind] & (0xF0 >> sar)) | ((V & 0x0F) << sar); + SyncChr(); + } else switch (A & 0xF003) { + case 0x8000: prg0 = V; SyncPrg(); break; + case 0xA000: prg1 = V; SyncPrg(); break; + case 0x9000: mirr = V & 1; SyncChr(); break; + case 0x9001: swap = V & 3; SyncPrg(); break; + case 0xF000: IRQCount = ((IRQCount & 0xF0) | (V & 0xF)); break; + case 0xF002: IRQCount = ((IRQCount & 0x0F) | ((V & 0xF) << 4)); break; + case 0xF001: + case 0xF003: IRQa = V & 2; X6502_IRQEnd(FCEU_IQEXT); if (scanline < 240) IRQCount -= 8; break; + } +} + +static void UNLTF1201IRQCounter(void) { + if (IRQa) { + IRQCount++; + if (IRQCount == 237) { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLTF1201Power(void) { + IRQPre = IRQCount = IRQa = 0; + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLTF1201Write); + SyncPrg(); + SyncChr(); +} + +void UNLTF1201_Init(CartInfo *info) { + info->Power = UNLTF1201Power; + GameHBIRQHook = UNLTF1201IRQCounter; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/transformer.c b/src/boards/transformer.c index 1a887d9..cef9514 100644 --- a/src/boards/transformer.c +++ b/src/boards/transformer.c @@ -1,109 +1,109 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * All regs access only by READ - * - * 5000 - I/O - when read, 0 goes to tape output - * ---m3210 - * 3210 - lower scancode nibble - * m - tape input bit - * 5001 - I - * ----7654 - * 7654 - higher scancode nibble - * 5002 - I - reset scancode buffer, ready to new input - * 5004 - O - when read, 1 goes to tape output - * - */ - -#include "mapinc.h" - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -char *GetKeyboard(void); - -static char *TransformerKeys, oldkeys[256]; -static int TransformerCycleCount, TransformerChar = 0; - -static void FP_FASTAPASS(1) TransformerIRQHook(int a) { - TransformerCycleCount += a; - if (TransformerCycleCount >= 1000) { - uint32 i; - TransformerCycleCount -= 1000; - TransformerKeys = GetKeyboard(); - - for (i = 0; i < 256; i++) { - if (oldkeys[i] != TransformerKeys[i]) { - if (oldkeys[i] == 0) - TransformerChar = i; - else - TransformerChar = i | 0x80; - X6502_IRQBegin(FCEU_IQEXT); - memcpy((void*)&oldkeys[0], (void*)TransformerKeys, sizeof(oldkeys)); - break; - } - } - } -} - -static DECLFR(TransformerRead) { - uint8 ret = 0; - switch (A & 3) { - case 0: ret = TransformerChar & 15; break; - case 1: ret = (TransformerChar >> 4); break; - case 2: X6502_IRQEnd(FCEU_IQEXT); break; - case 4: break; - } - return ret; -} - -static void TransformerPower(void) { - setprg8r(0x10, 0x6000, 0); - setprg16(0x8000, 0); - setprg16(0xC000, ~0); - setchr8(0); - - SetReadHandler(0x5000, 0x5004, TransformerRead); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - - MapIRQHook = TransformerIRQHook; -} - -static void TransformerClose(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void Transformer_Init(CartInfo *info) { - info->Power = TransformerPower; - info->Close = TransformerClose; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * All regs access only by READ + * + * 5000 - I/O - when read, 0 goes to tape output + * ---m3210 + * 3210 - lower scancode nibble + * m - tape input bit + * 5001 - I + * ----7654 + * 7654 - higher scancode nibble + * 5002 - I - reset scancode buffer, ready to new input + * 5004 - O - when read, 1 goes to tape output + * + */ + +#include "mapinc.h" + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +char *GetKeyboard(void); + +static char *TransformerKeys, oldkeys[256]; +static int TransformerCycleCount, TransformerChar = 0; + +static void FP_FASTAPASS(1) TransformerIRQHook(int a) { + TransformerCycleCount += a; + if (TransformerCycleCount >= 1000) { + uint32 i; + TransformerCycleCount -= 1000; + TransformerKeys = GetKeyboard(); + + for (i = 0; i < 256; i++) { + if (oldkeys[i] != TransformerKeys[i]) { + if (oldkeys[i] == 0) + TransformerChar = i; + else + TransformerChar = i | 0x80; + X6502_IRQBegin(FCEU_IQEXT); + memcpy((void*)&oldkeys[0], (void*)TransformerKeys, sizeof(oldkeys)); + break; + } + } + } +} + +static DECLFR(TransformerRead) { + uint8 ret = 0; + switch (A & 3) { + case 0: ret = TransformerChar & 15; break; + case 1: ret = (TransformerChar >> 4); break; + case 2: X6502_IRQEnd(FCEU_IQEXT); break; + case 4: break; + } + return ret; +} + +static void TransformerPower(void) { + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); + + SetReadHandler(0x5000, 0x5004, TransformerRead); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + + MapIRQHook = TransformerIRQHook; +} + +static void TransformerClose(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Transformer_Init(CartInfo *info) { + info->Power = TransformerPower; + info->Close = TransformerClose; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); +} diff --git a/src/boards/unrom512.c b/src/boards/unrom512.c index 3b5e9f2..a303ac5 100644 --- a/src/boards/unrom512.c +++ b/src/boards/unrom512.c @@ -1,249 +1,249 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2014 CaitSith2 - * - * 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 - */ - -/* - * Roms still using NES 1.0 format should be loaded as 32K CHR RAM. - * Roms defined under NES 2.0 should use the VRAM size field, defining 7, 8 or 9, based on how much VRAM should be present. - * UNIF doesn't have this problem, because unique board names can define this information. - * The UNIF names are UNROM-512-8K, UNROM-512-16K and UNROM-512-32K - * - * The battery flag in the NES header enables flash, Mirrror mode 2 Enables MI_0 and MI_1 mode. - * Known games to use this board are: - * Battle Kid 2: Mountain of Torment (512K PRG, 8K CHR RAM, Horizontal Mirroring, Flash disabled) - * Study Hall (128K PRG (in 512K flash chip), 8K CHR RAM, Horizontal Mirroring, Flash enabled) - * Although Xmas 2013 uses a different board, where LEDs can be controlled (with writes to the $8000-BFFF space), - * it otherwise functions identically. - * - * 17-10-20 - Works with Mystic Origins (Demo) -*/ - -#include "mapinc.h" -#include "../ines.h" - -static uint8 latche, latcheinit, bus_conflict, chrram_mask, software_id=0; -static uint16 latcha; -static uint8 *flashdata; -static uint32 *flash_write_count; -static uint8 *FlashPage[32]; -/* static uint32 *FlashWriteCountPage[32]; */ -/* static uint8 flashloaded = 0; */ - -static uint8 flash_save = 0, flash_state = 0, flash_mode = 0, flash_bank; -static void (*WLSync)(void); -static void (*WHSync)(void); - -static INLINE void setfpageptr(int s, uint32 A, uint8 *p) { - uint32 AB = A >> 11; - int x; - - if (p) - for (x = (s >> 1) - 1; x >= 0; x--) { - FlashPage[AB + x] = p - A; - } - else - for (x = (s >> 1) - 1; x >= 0; x--) { - FlashPage[AB + x] = 0; - } -} - -void setfprg16(uint32 A, uint32 V) { - if (PRGsize[0] >= 16384) { - V &= PRGmask16[0]; - setfpageptr(16, A, flashdata ? (&flashdata[V << 14]) : 0); - } else { - int x; - uint32 VA = V << 3; - - for (x = 0; x < 8; x++) - setfpageptr(2, A + (x << 11), flashdata ? (&flashdata[((VA + x) & PRGmask2[0]) << 11]) : 0); - } -} - -void inc_flash_write_count(uint8 bank, uint32 A) { - flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]++; - if (!flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]) - flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]++; -} - -uint32 GetFlashWriteCount(uint8 bank, uint32 A) { - return flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]; -} - -static void StateRestore(int version) { - WHSync(); -} - -static DECLFW(UNROM512LLatchWrite) { - latche = V; - latcha = A; - WLSync(); -} - -static DECLFW(UNROM512HLatchWrite) { - if (bus_conflict) - latche = (V == CartBR(A)) ? V : 0; - else - latche = V; - latcha = A; - WHSync(); -} - -static DECLFR(UNROM512LatchRead) { - uint8 flash_id[3] = { 0xB5, 0xB6, 0xB7 }; - if (software_id) { - if (A & 1) - return flash_id[ROM_size >> 4]; - else - return 0xBF; - } - if (flash_save) { - if (A < 0xC000) { - if (GetFlashWriteCount(flash_bank, A)) - return FlashPage[A >> 11][A]; - } else { - if (GetFlashWriteCount(ROM_size - 1, A)) - return FlashPage[A >> 11][A]; - } - } - return Page[A >> 11][A]; -} - -static void UNROM512LatchPower(void) { - latche = latcheinit; - WHSync(); - SetReadHandler(0x8000, 0xFFFF, UNROM512LatchRead); - if (!flash_save) - SetWriteHandler(0x8000, 0xFFFF, UNROM512HLatchWrite); - else - { - SetWriteHandler(0x8000, 0xBFFF, UNROM512LLatchWrite); - SetWriteHandler(0xC000, 0xFFFF, UNROM512HLatchWrite); - } -} - -static void UNROM512LatchClose(void) { - if (flash_write_count) - FCEU_gfree(flash_write_count); - if (flashdata) - FCEU_gfree(flashdata); - flash_write_count = NULL; - flashdata = NULL; -} - - -static void UNROM512LSync() { - int erase_a[5] = { 0x9555, 0xAAAA, 0x9555, 0x9555, 0xAAAA }; - int erase_d[5] = { 0xAA, 0x55, 0x80, 0xAA, 0x55 }; - int erase_b[5] = { 1, 0, 1, 1, 0 }; - - if (flash_mode==0) { - if ((latcha == erase_a[flash_state]) && (latche == erase_d[flash_state]) && (flash_bank == erase_b[flash_state])) { - flash_state++; - if (flash_state == 5) { - flash_mode = 1; - } - } - else if ((flash_state == 2) && (latcha == 0x9555) && (latche == 0xA0) && (flash_bank == 1)) { - flash_state++; - flash_mode = 2; - } - else if ((flash_state == 2) && (latcha == 0x9555) && (latche == 0x90) && (flash_bank == 1)) { - flash_state = 0; - software_id = 1; - } else { - if (latche == 0xF0) - software_id = 0; - flash_state = 0; - } - } - else if (flash_mode == 1) { /* Chip Erase or Sector Erase */ - if (latche == 0x30) { - inc_flash_write_count(flash_bank,latcha); - memset(&FlashPage[(latcha & 0xF000) >> 11][latcha & 0xF000], 0xFF, 0x1000); - } - else if (latche == 0x10) { - uint32 i; - for(i = 0; i < (ROM_size * 4); i++) - inc_flash_write_count(i >> 2,i << 12); - memset(flashdata, 0xFF, ROM_size * 0x4000); /* Erasing the rom chip as instructed. Crash rate calulated to be 99.9% :) */ - } - flash_state = 0; - flash_mode = 0; - } - else if (flash_mode == 2) { /* Byte Program */ - if (!GetFlashWriteCount(flash_bank, latcha)) { - inc_flash_write_count(flash_bank, latcha); - memcpy(&FlashPage[(latcha & 0xF000) >> 11][latcha & 0xF000], &Page[(latcha & 0xF000) >> 11][latcha & 0xF000], 0x1000); - } - FlashPage[latcha >> 11][latcha] &= latche; - flash_state = 0; - flash_mode = 0; - } -} - -static void UNROM512HSync() { - flash_bank=latche&(ROM_size - 1); - - setprg16(0x8000, flash_bank); - setprg16(0xc000, ~0); - setfprg16(0x8000, flash_bank); - setfprg16(0xC000, ~0); - setchr8r(0, (latche & chrram_mask) >> 5); - setmirror(MI_0 + (latche >> 7)); -} - -void UNROM512_Init(CartInfo *info) { - flash_state = 0; - flash_bank = 0; - flash_save = info->battery; - - if (info->vram_size == 8192) - chrram_mask = 0; - else if (info->vram_size == 16384) - chrram_mask = 0x20; - else - chrram_mask = 0x60; - - SetupCartMirroring(info->mirror, (info->mirror >= MI_0) ? 0 : 1, 0); - bus_conflict = !info->battery; - latcheinit = 0; - WLSync = UNROM512LSync; - WHSync = UNROM512HSync; - info->Power = UNROM512LatchPower; - info->Close = UNROM512LatchClose; - GameStateRestore = StateRestore; - if (flash_save) - { - flashdata = (uint8*)FCEU_gmalloc(ROM_size * 0x4000); - flash_write_count = (uint32*)FCEU_gmalloc(ROM_size * 4 * sizeof(uint32)); - info->SaveGame[0] = (uint8*)flash_write_count; - info->SaveGame[1] = flashdata; - info->SaveGameLen[0] = ROM_size * 4 * sizeof(uint32); - info->SaveGameLen[1] = ROM_size * 0x4000; - AddExState(flash_write_count,ROM_size * 4 * sizeof(uint32), 0, "FLASH_WRITE_COUNT"); - AddExState(flashdata,ROM_size * 0x4000, 0, "FLASH_DATA"); - AddExState(&flash_state, 1, 0, "FLASH_STATE"); - AddExState(&flash_mode, 1, 0, "FLASH_MODE"); - AddExState(&flash_bank, 1, 0, "FLASH_BANK"); - AddExState(&latcha, 2, 0, "LATA"); - } - AddExState(&latche, 1, 0, "LATC"); - AddExState(&bus_conflict, 1, 0, "BUSC"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2014 CaitSith2 + * + * 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 + */ + +/* + * Roms still using NES 1.0 format should be loaded as 32K CHR RAM. + * Roms defined under NES 2.0 should use the VRAM size field, defining 7, 8 or 9, based on how much VRAM should be present. + * UNIF doesn't have this problem, because unique board names can define this information. + * The UNIF names are UNROM-512-8K, UNROM-512-16K and UNROM-512-32K + * + * The battery flag in the NES header enables flash, Mirrror mode 2 Enables MI_0 and MI_1 mode. + * Known games to use this board are: + * Battle Kid 2: Mountain of Torment (512K PRG, 8K CHR RAM, Horizontal Mirroring, Flash disabled) + * Study Hall (128K PRG (in 512K flash chip), 8K CHR RAM, Horizontal Mirroring, Flash enabled) + * Although Xmas 2013 uses a different board, where LEDs can be controlled (with writes to the $8000-BFFF space), + * it otherwise functions identically. + * + * 17-10-20 - Works with Mystic Origins (Demo) +*/ + +#include "mapinc.h" +#include "../ines.h" + +static uint8 latche, latcheinit, bus_conflict, chrram_mask, software_id=0; +static uint16 latcha; +static uint8 *flashdata; +static uint32 *flash_write_count; +static uint8 *FlashPage[32]; +/* static uint32 *FlashWriteCountPage[32]; */ +/* static uint8 flashloaded = 0; */ + +static uint8 flash_save = 0, flash_state = 0, flash_mode = 0, flash_bank; +static void (*WLSync)(void); +static void (*WHSync)(void); + +static INLINE void setfpageptr(int s, uint32 A, uint8 *p) { + uint32 AB = A >> 11; + int x; + + if (p) + for (x = (s >> 1) - 1; x >= 0; x--) { + FlashPage[AB + x] = p - A; + } + else + for (x = (s >> 1) - 1; x >= 0; x--) { + FlashPage[AB + x] = 0; + } +} + +void setfprg16(uint32 A, uint32 V) { + if (PRGsize[0] >= 16384) { + V &= PRGmask16[0]; + setfpageptr(16, A, flashdata ? (&flashdata[V << 14]) : 0); + } else { + int x; + uint32 VA = V << 3; + + for (x = 0; x < 8; x++) + setfpageptr(2, A + (x << 11), flashdata ? (&flashdata[((VA + x) & PRGmask2[0]) << 11]) : 0); + } +} + +void inc_flash_write_count(uint8 bank, uint32 A) { + flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]++; + if (!flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]) + flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]++; +} + +uint32 GetFlashWriteCount(uint8 bank, uint32 A) { + return flash_write_count[(bank * 4) + ((A & 0x3000) >> 12)]; +} + +static void StateRestore(int version) { + WHSync(); +} + +static DECLFW(UNROM512LLatchWrite) { + latche = V; + latcha = A; + WLSync(); +} + +static DECLFW(UNROM512HLatchWrite) { + if (bus_conflict) + latche = (V == CartBR(A)) ? V : 0; + else + latche = V; + latcha = A; + WHSync(); +} + +static DECLFR(UNROM512LatchRead) { + uint8 flash_id[3] = { 0xB5, 0xB6, 0xB7 }; + if (software_id) { + if (A & 1) + return flash_id[ROM_size >> 4]; + else + return 0xBF; + } + if (flash_save) { + if (A < 0xC000) { + if (GetFlashWriteCount(flash_bank, A)) + return FlashPage[A >> 11][A]; + } else { + if (GetFlashWriteCount(ROM_size - 1, A)) + return FlashPage[A >> 11][A]; + } + } + return Page[A >> 11][A]; +} + +static void UNROM512LatchPower(void) { + latche = latcheinit; + WHSync(); + SetReadHandler(0x8000, 0xFFFF, UNROM512LatchRead); + if (!flash_save) + SetWriteHandler(0x8000, 0xFFFF, UNROM512HLatchWrite); + else + { + SetWriteHandler(0x8000, 0xBFFF, UNROM512LLatchWrite); + SetWriteHandler(0xC000, 0xFFFF, UNROM512HLatchWrite); + } +} + +static void UNROM512LatchClose(void) { + if (flash_write_count) + FCEU_gfree(flash_write_count); + if (flashdata) + FCEU_gfree(flashdata); + flash_write_count = NULL; + flashdata = NULL; +} + + +static void UNROM512LSync() { + int erase_a[5] = { 0x9555, 0xAAAA, 0x9555, 0x9555, 0xAAAA }; + int erase_d[5] = { 0xAA, 0x55, 0x80, 0xAA, 0x55 }; + int erase_b[5] = { 1, 0, 1, 1, 0 }; + + if (flash_mode==0) { + if ((latcha == erase_a[flash_state]) && (latche == erase_d[flash_state]) && (flash_bank == erase_b[flash_state])) { + flash_state++; + if (flash_state == 5) { + flash_mode = 1; + } + } + else if ((flash_state == 2) && (latcha == 0x9555) && (latche == 0xA0) && (flash_bank == 1)) { + flash_state++; + flash_mode = 2; + } + else if ((flash_state == 2) && (latcha == 0x9555) && (latche == 0x90) && (flash_bank == 1)) { + flash_state = 0; + software_id = 1; + } else { + if (latche == 0xF0) + software_id = 0; + flash_state = 0; + } + } + else if (flash_mode == 1) { /* Chip Erase or Sector Erase */ + if (latche == 0x30) { + inc_flash_write_count(flash_bank,latcha); + memset(&FlashPage[(latcha & 0xF000) >> 11][latcha & 0xF000], 0xFF, 0x1000); + } + else if (latche == 0x10) { + uint32 i; + for(i = 0; i < (ROM_size * 4); i++) + inc_flash_write_count(i >> 2,i << 12); + memset(flashdata, 0xFF, ROM_size * 0x4000); /* Erasing the rom chip as instructed. Crash rate calulated to be 99.9% :) */ + } + flash_state = 0; + flash_mode = 0; + } + else if (flash_mode == 2) { /* Byte Program */ + if (!GetFlashWriteCount(flash_bank, latcha)) { + inc_flash_write_count(flash_bank, latcha); + memcpy(&FlashPage[(latcha & 0xF000) >> 11][latcha & 0xF000], &Page[(latcha & 0xF000) >> 11][latcha & 0xF000], 0x1000); + } + FlashPage[latcha >> 11][latcha] &= latche; + flash_state = 0; + flash_mode = 0; + } +} + +static void UNROM512HSync() { + flash_bank=latche&(ROM_size - 1); + + setprg16(0x8000, flash_bank); + setprg16(0xc000, ~0); + setfprg16(0x8000, flash_bank); + setfprg16(0xC000, ~0); + setchr8r(0, (latche & chrram_mask) >> 5); + setmirror(MI_0 + (latche >> 7)); +} + +void UNROM512_Init(CartInfo *info) { + flash_state = 0; + flash_bank = 0; + flash_save = info->battery; + + if (info->vram_size == 8192) + chrram_mask = 0; + else if (info->vram_size == 16384) + chrram_mask = 0x20; + else + chrram_mask = 0x60; + + SetupCartMirroring(info->mirror, (info->mirror >= MI_0) ? 0 : 1, 0); + bus_conflict = !info->battery; + latcheinit = 0; + WLSync = UNROM512LSync; + WHSync = UNROM512HSync; + info->Power = UNROM512LatchPower; + info->Close = UNROM512LatchClose; + GameStateRestore = StateRestore; + if (flash_save) + { + flashdata = (uint8*)FCEU_gmalloc(ROM_size * 0x4000); + flash_write_count = (uint32*)FCEU_gmalloc(ROM_size * 4 * sizeof(uint32)); + info->SaveGame[0] = (uint8*)flash_write_count; + info->SaveGame[1] = flashdata; + info->SaveGameLen[0] = ROM_size * 4 * sizeof(uint32); + info->SaveGameLen[1] = ROM_size * 0x4000; + AddExState(flash_write_count,ROM_size * 4 * sizeof(uint32), 0, "FLASH_WRITE_COUNT"); + AddExState(flashdata,ROM_size * 0x4000, 0, "FLASH_DATA"); + AddExState(&flash_state, 1, 0, "FLASH_STATE"); + AddExState(&flash_mode, 1, 0, "FLASH_MODE"); + AddExState(&flash_bank, 1, 0, "FLASH_BANK"); + AddExState(&latcha, 2, 0, "LATA"); + } + AddExState(&latche, 1, 0, "LATC"); + AddExState(&bus_conflict, 1, 0, "BUSC"); +} diff --git a/src/boards/vrc1.c b/src/boards/vrc1.c index 899bcfb..eec2d9d 100644 --- a/src/boards/vrc1.c +++ b/src/boards/vrc1.c @@ -1,70 +1,70 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * VRC-1 - * - */ - -#include "mapinc.h" - -static uint8 preg[3], creg[2], mode; -static SFORMAT StateRegs[] = -{ - { &mode, 1, "MODE" }, - { creg, 2, "CREG" }, - { preg, 3, "PREG" }, - { 0 } -}; - -static void Sync(void) { - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, ~0); - setchr4(0x0000, creg[0] | ((mode & 2) << 3)); - setchr4(0x1000, creg[1] | ((mode & 4) << 2)); - setmirror((mode & 1) ^ 1); -} - -static DECLFW(M75Write) { - switch (A & 0xF000) { - case 0x8000: preg[0] = V; Sync(); break; - case 0x9000: mode = V; Sync(); break; - case 0xA000: preg[1] = V; Sync(); break; - case 0xC000: preg[2] = V; Sync(); break; - case 0xE000: creg[0] = V & 0xF; Sync(); break; - case 0xF000: creg[1] = V & 0xF; Sync(); break; - } -} - -static void M75Power(void) { - Sync(); - SetWriteHandler(0x8000, 0xFFFF, M75Write); - SetReadHandler(0x8000, 0xFFFF, CartBR); -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper75_Init(CartInfo *info) { - info->Power = M75Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * VRC-1 + * + */ + +#include "mapinc.h" + +static uint8 preg[3], creg[2], mode; +static SFORMAT StateRegs[] = +{ + { &mode, 1, "MODE" }, + { creg, 2, "CREG" }, + { preg, 3, "PREG" }, + { 0 } +}; + +static void Sync(void) { + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + setchr4(0x0000, creg[0] | ((mode & 2) << 3)); + setchr4(0x1000, creg[1] | ((mode & 4) << 2)); + setmirror((mode & 1) ^ 1); +} + +static DECLFW(M75Write) { + switch (A & 0xF000) { + case 0x8000: preg[0] = V; Sync(); break; + case 0x9000: mode = V; Sync(); break; + case 0xA000: preg[1] = V; Sync(); break; + case 0xC000: preg[2] = V; Sync(); break; + case 0xE000: creg[0] = V & 0xF; Sync(); break; + case 0xF000: creg[1] = V & 0xF; Sync(); break; + } +} + +static void M75Power(void) { + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M75Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper75_Init(CartInfo *info) { + info->Power = M75Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/vrc2and4.c b/src/boards/vrc2and4.c index 59942bf..7ff7ce7 100644 --- a/src/boards/vrc2and4.c +++ b/src/boards/vrc2and4.c @@ -1,281 +1,281 @@ -/* 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 - * - * VRC-2/VRC-4 Konami - * VRC-4 Pirate - * - */ - -#include "mapinc.h" - -static uint8 isPirate, is22; -static uint16 IRQCount; -static uint8 IRQLatch, IRQa; -static uint8 prgreg[2], chrreg[8]; -static uint16 chrhi[8]; -static uint8 regcmd, irqcmd, mirr, big_bank; -static uint16 acount = 0; -static uint16 weirdo = 0; - -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { prgreg, 2, "PREG" }, - { chrreg, 8, "CREG" }, - { chrhi, 16, "CRGH" }, - { ®cmd, 1, "CMDR" }, - { &irqcmd, 1, "CMDI" }, - { &mirr, 1, "MIRR" }, - { &big_bank, 1, "BIGB" }, - { &IRQCount, 2, "IRQC" }, - { &IRQLatch, 1, "IRQL" }, - { &IRQa, 1, "IRQA" }, - { 0 } -}; - -static void Sync(void) { - if (regcmd & 2) { - setprg8(0xC000, prgreg[0] | big_bank); - setprg8(0x8000, ((~1) & 0x1F) | big_bank); - } else { - setprg8(0x8000, prgreg[0] | big_bank); - setprg8(0xC000, ((~1) & 0x1F) | big_bank); - } - setprg8(0xA000, prgreg[1] | big_bank); - setprg8(0xE000, ((~0) & 0x1F) | big_bank); - if (UNIFchrrama) - setchr8(0); - else { - uint8 i; - /* if (!weirdo) */ - for (i = 0; i < 8; i++) - setchr1(i << 10, (chrhi[i] | chrreg[i]) >> is22); - /* else { - setchr1(0x0000, 0xFC); - setchr1(0x0400, 0xFD); - setchr1(0x0800, 0xFF); - weirdo--; - } */ - } - switch (mirr & 0x3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(VRC24Write) { - A &= 0xF003; - if ((A >= 0xB000) && (A <= 0xE003)) { - if (UNIFchrrama) - big_bank = (V & 8) << 2; /* my personally many-in-one feature ;) just for support pirate cart 2-in-1 */ - else { - uint16 i = ((A >> 1) & 1) | ((A - 0xB000) >> 11); - uint16 nibble = ((A & 1) << 2); - chrreg[i] = (chrreg[i] & (0xF0 >> nibble)) | ((V & 0xF) << nibble); - if (nibble) - chrhi[i] = (V & 0x10) << 4; /* another one many in one feature from pirate carts */ - } - Sync(); - } else - switch (A & 0xF003) { - case 0x8000: - case 0x8001: - case 0x8002: - case 0x8003: - if (!isPirate) { - prgreg[0] = V & 0x1F; - Sync(); - } - break; - case 0xA000: - case 0xA001: - case 0xA002: - case 0xA003: - if (!isPirate) - prgreg[1] = V & 0x1F; - else { - prgreg[0] = (V & 0x1F) << 1; - prgreg[1] = ((V & 0x1F) << 1) | 1; - } - Sync(); - break; - case 0x9000: - case 0x9001: if (V != 0xFF) mirr = V; Sync(); break; - case 0x9002: - case 0x9003: regcmd = V; Sync(); break; - case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; - case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; - case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount = 0; IRQCount = IRQLatch; IRQa = V & 2; irqcmd = V & 1; break; - case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa = irqcmd; break; - } -} - -static DECLFW(M21Write) { - A = (A & 0xF000) | ((A >> 1) & 0x3) | ((A >> 6) & 0x3); /* Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] is Mapper 21*/ - VRC24Write(A, V); -} - -static DECLFW(M22Write) { -#if 0 - /* Removed this hack, which was a bug in actual game cart. - * http://forums.nesdev.com/viewtopic.php?f=3&t=6584 - */ - if ((A >= 0xC004) && (A <= 0xC007)) { /* Ganbare Goemon Gaiden does strange things!!! at the end credits - weirdo = 1; * quick dirty hack, seems there is no other games with such PCB, so - * we never know if it will not work for something else lol - */ - } -#endif - A |= ((A >> 2) & 0x3); /* It's just swapped lines from 21 mapper - */ - VRC24Write((A & 0xF000) | ((A >> 1) & 1) | ((A << 1) & 2), V); -} - -static DECLFW(M23Write) { - A |= ((A >> 2) & 0x3) | ((A >> 4) & 0x3); /* actually there is many-in-one mapper source, some pirate or - * licensed games use various address bits for registers - */ - VRC24Write(A, V); -} - -static void M21Power(void) { - Sync(); - setprg8r(0x10, 0x6000, 0); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M21Write); -} - -static void M22Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M22Write); -} - -static void M23Power(void) { - big_bank = 0x20; - Sync(); - setprg8r(0x10, 0x6000, 0); /* Only two Goemon games are have battery backed RAM, three more shooters - * (Parodius Da!, Gradius 2 and Crisis Force uses 2k or SRAM at 6000-67FF only - */ - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M23Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M25Power(void) { - big_bank = 0x20; - Sync(); - setprg8r(0x10, 0x6000, 0); - SetReadHandler(0x6000, 0x7FFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, M22Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -void FP_FASTAPASS(1) VRC24IRQHook(int a) { - #define LCYCS 341 - if (IRQa) { - acount += a * 3; - if (acount >= LCYCS) { - while (acount >= LCYCS) { - acount -= LCYCS; - IRQCount++; - if (IRQCount & 0x100) { - X6502_IRQBegin(FCEU_IQEXT); - IRQCount = IRQLatch; - } - } - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -static void VRC24Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -void Mapper22_Init(CartInfo *info) { - isPirate = 0; - is22 = 1; - info->Power = M22Power; - GameStateRestore = StateRestore; - - AddExState(&StateRegs, ~0, 0, 0); -} - -void VRC24_Init(CartInfo *info) { - info->Close = VRC24Close; - MapIRQHook = VRC24IRQHook; - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper21_Init(CartInfo *info) { - isPirate = 0; - is22 = 0; - info->Power = M21Power; - VRC24_Init(info); -} - -void Mapper23_Init(CartInfo *info) { - isPirate = 0; - is22 = 0; - info->Power = M23Power; - VRC24_Init(info); -} - -void Mapper25_Init(CartInfo *info) { - isPirate = 0; - is22 = 0; - info->Power = M25Power; - VRC24_Init(info); -} - -void UNLT230_Init(CartInfo *info) { - isPirate = 1; - is22 = 0; - info->Power = M23Power; - VRC24_Init(info); -} +/* 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 + * + * VRC-2/VRC-4 Konami + * VRC-4 Pirate + * + */ + +#include "mapinc.h" + +static uint8 isPirate, is22; +static uint16 IRQCount; +static uint8 IRQLatch, IRQa; +static uint8 prgreg[2], chrreg[8]; +static uint16 chrhi[8]; +static uint8 regcmd, irqcmd, mirr, big_bank; +static uint16 acount = 0; +static uint16 weirdo = 0; + +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { prgreg, 2, "PREG" }, + { chrreg, 8, "CREG" }, + { chrhi, 16, "CRGH" }, + { ®cmd, 1, "CMDR" }, + { &irqcmd, 1, "CMDI" }, + { &mirr, 1, "MIRR" }, + { &big_bank, 1, "BIGB" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQa, 1, "IRQA" }, + { 0 } +}; + +static void Sync(void) { + if (regcmd & 2) { + setprg8(0xC000, prgreg[0] | big_bank); + setprg8(0x8000, ((~1) & 0x1F) | big_bank); + } else { + setprg8(0x8000, prgreg[0] | big_bank); + setprg8(0xC000, ((~1) & 0x1F) | big_bank); + } + setprg8(0xA000, prgreg[1] | big_bank); + setprg8(0xE000, ((~0) & 0x1F) | big_bank); + if (UNIFchrrama) + setchr8(0); + else { + uint8 i; + /* if (!weirdo) */ + for (i = 0; i < 8; i++) + setchr1(i << 10, (chrhi[i] | chrreg[i]) >> is22); + /* else { + setchr1(0x0000, 0xFC); + setchr1(0x0400, 0xFD); + setchr1(0x0800, 0xFF); + weirdo--; + } */ + } + switch (mirr & 0x3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(VRC24Write) { + A &= 0xF003; + if ((A >= 0xB000) && (A <= 0xE003)) { + if (UNIFchrrama) + big_bank = (V & 8) << 2; /* my personally many-in-one feature ;) just for support pirate cart 2-in-1 */ + else { + uint16 i = ((A >> 1) & 1) | ((A - 0xB000) >> 11); + uint16 nibble = ((A & 1) << 2); + chrreg[i] = (chrreg[i] & (0xF0 >> nibble)) | ((V & 0xF) << nibble); + if (nibble) + chrhi[i] = (V & 0x10) << 4; /* another one many in one feature from pirate carts */ + } + Sync(); + } else + switch (A & 0xF003) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: + if (!isPirate) { + prgreg[0] = V & 0x1F; + Sync(); + } + break; + case 0xA000: + case 0xA001: + case 0xA002: + case 0xA003: + if (!isPirate) + prgreg[1] = V & 0x1F; + else { + prgreg[0] = (V & 0x1F) << 1; + prgreg[1] = ((V & 0x1F) << 1) | 1; + } + Sync(); + break; + case 0x9000: + case 0x9001: if (V != 0xFF) mirr = V; Sync(); break; + case 0x9002: + case 0x9003: regcmd = V; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0xF0; IRQLatch |= V & 0xF; break; + case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch &= 0x0F; IRQLatch |= V << 4; break; + case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount = 0; IRQCount = IRQLatch; IRQa = V & 2; irqcmd = V & 1; break; + case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa = irqcmd; break; + } +} + +static DECLFW(M21Write) { + A = (A & 0xF000) | ((A >> 1) & 0x3) | ((A >> 6) & 0x3); /* Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] is Mapper 21*/ + VRC24Write(A, V); +} + +static DECLFW(M22Write) { +#if 0 + /* Removed this hack, which was a bug in actual game cart. + * http://forums.nesdev.com/viewtopic.php?f=3&t=6584 + */ + if ((A >= 0xC004) && (A <= 0xC007)) { /* Ganbare Goemon Gaiden does strange things!!! at the end credits + weirdo = 1; * quick dirty hack, seems there is no other games with such PCB, so + * we never know if it will not work for something else lol + */ + } +#endif + A |= ((A >> 2) & 0x3); /* It's just swapped lines from 21 mapper + */ + VRC24Write((A & 0xF000) | ((A >> 1) & 1) | ((A << 1) & 2), V); +} + +static DECLFW(M23Write) { + A |= ((A >> 2) & 0x3) | ((A >> 4) & 0x3); /* actually there is many-in-one mapper source, some pirate or + * licensed games use various address bits for registers + */ + VRC24Write(A, V); +} + +static void M21Power(void) { + Sync(); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M21Write); +} + +static void M22Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M22Write); +} + +static void M23Power(void) { + big_bank = 0x20; + Sync(); + setprg8r(0x10, 0x6000, 0); /* Only two Goemon games are have battery backed RAM, three more shooters + * (Parodius Da!, Gradius 2 and Crisis Force uses 2k or SRAM at 6000-67FF only + */ + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M23Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M25Power(void) { + big_bank = 0x20; + Sync(); + setprg8r(0x10, 0x6000, 0); + SetReadHandler(0x6000, 0x7FFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M22Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +void FP_FASTAPASS(1) VRC24IRQHook(int a) { + #define LCYCS 341 + if (IRQa) { + acount += a * 3; + if (acount >= LCYCS) { + while (acount >= LCYCS) { + acount -= LCYCS; + IRQCount++; + if (IRQCount & 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount = IRQLatch; + } + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +static void VRC24Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +void Mapper22_Init(CartInfo *info) { + isPirate = 0; + is22 = 1; + info->Power = M22Power; + GameStateRestore = StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} + +void VRC24_Init(CartInfo *info) { + info->Close = VRC24Close; + MapIRQHook = VRC24IRQHook; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper21_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M21Power; + VRC24_Init(info); +} + +void Mapper23_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M23Power; + VRC24_Init(info); +} + +void Mapper25_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M25Power; + VRC24_Init(info); +} + +void UNLT230_Init(CartInfo *info) { + isPirate = 1; + is22 = 0; + info->Power = M23Power; + VRC24_Init(info); +} diff --git a/src/boards/vrc3.c b/src/boards/vrc3.c index 3dae047..6e32d49 100644 --- a/src/boards/vrc3.c +++ b/src/boards/vrc3.c @@ -1,134 +1,134 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - * - * VRC-3 - * - */ - -#include "mapinc.h" - -static uint8 preg; -static uint8 IRQx; /* autoenable */ -static uint8 IRQm; /* mode */ -static uint8 IRQa; -static uint16 IRQReload, IRQCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &preg, 1, "PREG" }, - { &IRQa, 1, "IRQA" }, - { &IRQx, 1, "IRQX" }, - { &IRQm, 1, "IRQM" }, - { &IRQReload, 2, "IRQR" }, - { &IRQCount, 2, "IRQC" }, - { 0 } -}; - -static void Sync(void) { - setprg8r(0x10, 0x6000, 0); - setprg16(0x8000, preg); - setprg16(0xC000, ~0); - setchr8(0); -} - -static DECLFW(M73Write) { - switch (A & 0xF000) { - case 0x8000: IRQReload &= 0xFFF0; IRQReload |= (V & 0xF) << 0; break; - case 0x9000: IRQReload &= 0xFF0F; IRQReload |= (V & 0xF) << 4; break; - case 0xA000: IRQReload &= 0xF0FF; IRQReload |= (V & 0xF) << 8; break; - case 0xB000: IRQReload &= 0x0FFF; IRQReload |= (V & 0xF) << 12; break; - case 0xC000: - IRQm = V & 4; - IRQx = V & 1; - IRQa = V & 2; - if (IRQa) { - if (IRQm) { - IRQCount &= 0xFFFF; - IRQCount |= (IRQReload & 0xFF); - } else - IRQCount = IRQReload; - } - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xD000: X6502_IRQEnd(FCEU_IQEXT); IRQa = IRQx; break; - case 0xF000: preg = V; Sync(); break; - } -} - -static void M73IRQHook(int a) { - int32 i; - if (!IRQa) return; - for (i = 0; i < a; i++) { - if (IRQm) { - uint16 temp = IRQCount; - temp &= 0xFF; - IRQCount &= 0xFF00; - if (temp == 0xFF) { - IRQCount = IRQReload; - IRQCount |= (uint16)(IRQReload & 0xFF); - X6502_IRQBegin(FCEU_IQEXT); - } else { - temp++; - IRQCount |= temp; - } - } else { - /* 16 bit mode */ - if (IRQCount == 0xFFFF) { - IRQCount = IRQReload; - X6502_IRQBegin(FCEU_IQEXT); - } else - IRQCount++; - } - } -} - -static void M73Power(void) { - IRQReload = IRQm = IRQx = 0; - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0xFFFF, M73Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void M73Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper73_Init(CartInfo *info) { - info->Power = M73Power; - info->Close = M73Close; - MapIRQHook = M73IRQHook; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore = StateRestore; -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * VRC-3 + * + */ + +#include "mapinc.h" + +static uint8 preg; +static uint8 IRQx; /* autoenable */ +static uint8 IRQm; /* mode */ +static uint8 IRQa; +static uint16 IRQReload, IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &IRQa, 1, "IRQA" }, + { &IRQx, 1, "IRQX" }, + { &IRQm, 1, "IRQM" }, + { &IRQReload, 2, "IRQR" }, + { &IRQCount, 2, "IRQC" }, + { 0 } +}; + +static void Sync(void) { + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, preg); + setprg16(0xC000, ~0); + setchr8(0); +} + +static DECLFW(M73Write) { + switch (A & 0xF000) { + case 0x8000: IRQReload &= 0xFFF0; IRQReload |= (V & 0xF) << 0; break; + case 0x9000: IRQReload &= 0xFF0F; IRQReload |= (V & 0xF) << 4; break; + case 0xA000: IRQReload &= 0xF0FF; IRQReload |= (V & 0xF) << 8; break; + case 0xB000: IRQReload &= 0x0FFF; IRQReload |= (V & 0xF) << 12; break; + case 0xC000: + IRQm = V & 4; + IRQx = V & 1; + IRQa = V & 2; + if (IRQa) { + if (IRQm) { + IRQCount &= 0xFFFF; + IRQCount |= (IRQReload & 0xFF); + } else + IRQCount = IRQReload; + } + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xD000: X6502_IRQEnd(FCEU_IQEXT); IRQa = IRQx; break; + case 0xF000: preg = V; Sync(); break; + } +} + +static void M73IRQHook(int a) { + int32 i; + if (!IRQa) return; + for (i = 0; i < a; i++) { + if (IRQm) { + uint16 temp = IRQCount; + temp &= 0xFF; + IRQCount &= 0xFF00; + if (temp == 0xFF) { + IRQCount = IRQReload; + IRQCount |= (uint16)(IRQReload & 0xFF); + X6502_IRQBegin(FCEU_IQEXT); + } else { + temp++; + IRQCount |= temp; + } + } else { + /* 16 bit mode */ + if (IRQCount == 0xFFFF) { + IRQCount = IRQReload; + X6502_IRQBegin(FCEU_IQEXT); + } else + IRQCount++; + } + } +} + +static void M73Power(void) { + IRQReload = IRQm = IRQx = 0; + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, M73Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void M73Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper73_Init(CartInfo *info) { + info->Power = M73Power; + info->Close = M73Close; + MapIRQHook = M73IRQHook; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/vrc6.c b/src/boards/vrc6.c index ee7660a..3c59846 100644 --- a/src/boards/vrc6.c +++ b/src/boards/vrc6.c @@ -1,377 +1,377 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * VRC-6 - * - */ - -#include "mapinc.h" - -static uint8 is26; -static uint8 prg[2], chr[8], mirr; -static uint8 IRQLatch, IRQa, IRQd; -static int32 IRQCount, CycleCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { prg, 2, "PRG" }, - { chr, 8, "CHR" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQd, 1, "IRQD" }, - { &IRQLatch, 1, "IRQL" }, - { &IRQCount, 4, "IRQC" }, - { &CycleCount, 4, "CYCC" }, - { 0 } -}; - -static void(*sfun[3]) (void); -static uint8 vpsg1[8]; -static uint8 vpsg2[4]; -static int32 cvbc[3]; -static int32 vcount[3]; -static int32 dcount[2]; - -static SFORMAT SStateRegs[] = -{ - { vpsg1, 8, "PSG1" }, - { vpsg2, 4, "PSG2" }, - { 0 } -}; - -static void Sync(void) { - uint8 i; - if (is26) - setprg8r(0x10, 0x6000, 0); - setprg16(0x8000, prg[0]); - setprg8(0xc000, prg[1]); - setprg8(0xe000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, chr[i]); - switch (mirr & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(VRC6SW) { - A &= 0xF003; - if (A >= 0x9000 && A <= 0x9002) { - vpsg1[A & 3] = V; - if (sfun[0]) sfun[0](); - } else if (A >= 0xA000 && A <= 0xA002) { - vpsg1[4 | (A & 3)] = V; - if (sfun[1]) sfun[1](); - } else if (A >= 0xB000 && A <= 0xB002) { - vpsg2[A & 3] = V; - if (sfun[2]) sfun[2](); - } -} - -static DECLFW(VRC6Write) { - if (is26) - A = (A & 0xFFFC) | ((A >> 1) & 1) | ((A << 1) & 2); - if (A >= 0x9000 && A <= 0xB002) { - VRC6SW(A, V); - return; - } - switch (A & 0xF003) { - case 0x8000: prg[0] = V; Sync(); break; - case 0xB003: mirr = (V >> 2) & 3; Sync(); break; - case 0xC000: prg[1] = V; Sync(); break; - case 0xD000: chr[0] = V; Sync(); break; - case 0xD001: chr[1] = V; Sync(); break; - case 0xD002: chr[2] = V; Sync(); break; - case 0xD003: chr[3] = V; Sync(); break; - case 0xE000: chr[4] = V; Sync(); break; - case 0xE001: chr[5] = V; Sync(); break; - case 0xE002: chr[6] = V; Sync(); break; - case 0xE003: chr[7] = V; Sync(); break; - case 0xF000: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xF001: - IRQa = V & 2; - IRQd = V & 1; - if (V & 2) - IRQCount = IRQLatch; - CycleCount = 0; - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xF002: - IRQa = IRQd; - X6502_IRQEnd(FCEU_IQEXT); - } -} - -static void VRC6Power(void) { - Sync(); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetWriteHandler(0x8000, 0xFFFF, VRC6Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void VRC6IRQHook(int a) { - if (IRQa) { - CycleCount += a * 3; - while (CycleCount >= 341) { - CycleCount -= 341; - IRQCount++; - if (IRQCount == 0x100) { - IRQCount = IRQLatch; - X6502_IRQBegin(FCEU_IQEXT); - } - } - } -} - -static void VRC6Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void StateRestore(int version) { - Sync(); -} - -/* VRC6 Sound */ - -static void DoSQV1(void); -static void DoSQV2(void); -static void DoSawV(void); - -static INLINE void DoSQV(int x) { - int32 V; - int32 amp = (((vpsg1[x << 2] & 15) << 8) * 6 / 8) >> 4; - int32 start, end; - - start = cvbc[x]; - end = (SOUNDTS << 16) / soundtsinc; - if (end <= start) return; - cvbc[x] = end; - - if (vpsg1[(x << 2) | 0x2] & 0x80) { - if (vpsg1[x << 2] & 0x80) { - for (V = start; V < end; V++) - Wave[V >> 4] += amp; - } else { - int32 thresh = (vpsg1[x << 2] >> 4) & 7; - int32 freq = ((vpsg1[(x << 2) | 0x1] | ((vpsg1[(x << 2) | 0x2] & 15) << 8)) + 1) << 17; - for (V = start; V < end; V++) { - if (dcount[x] > thresh) - Wave[V >> 4] += amp; - vcount[x] -= nesincsize; - while (vcount[x] <= 0) { - vcount[x] += freq; - dcount[x] = (dcount[x] + 1) & 15; - } - } - } - } -} - -static void DoSQV1(void) { - DoSQV(0); -} - -static void DoSQV2(void) { - DoSQV(1); -} - -static void DoSawV(void) { - int V; - int32 start, end; - - start = cvbc[2]; - end = (SOUNDTS << 16) / soundtsinc; - if (end <= start) return; - cvbc[2] = end; - - if (vpsg2[2] & 0x80) { - static int32 saw1phaseacc = 0; - uint32 freq3; - static uint8 b3 = 0; - static int32 phaseacc = 0; - static uint32 duff = 0; - - freq3 = (vpsg2[1] + ((vpsg2[2] & 15) << 8) + 1); - - for (V = start; V < end; V++) { - saw1phaseacc -= nesincsize; - if (saw1phaseacc <= 0) { - int32 t; - rea: - t = freq3; - t <<= 18; - saw1phaseacc += t; - phaseacc += vpsg2[0] & 0x3f; - b3++; - if (b3 == 7) { - b3 = 0; - phaseacc = 0; - } - if (saw1phaseacc <= 0) - goto rea; - duff = (((phaseacc >> 3) & 0x1f) << 4) * 6 / 8; - } - Wave[V >> 4] += duff; - } - } -} - -static INLINE void DoSQVHQ(int x) { - int32 V; - int32 amp = ((vpsg1[x << 2] & 15) << 8) * 6 / 8; - - if (vpsg1[(x << 2) | 0x2] & 0x80) { - if (vpsg1[x << 2] & 0x80) { - for (V = cvbc[x]; V < (int)SOUNDTS; V++) - WaveHi[V] += amp; - } else { - int32 thresh = (vpsg1[x << 2] >> 4) & 7; - for (V = cvbc[x]; V < (int)SOUNDTS; V++) { - if (dcount[x] > thresh) - WaveHi[V] += amp; - vcount[x]--; - if (vcount[x] <= 0) { - vcount[x] = (vpsg1[(x << 2) | 0x1] | ((vpsg1[(x << 2) | 0x2] & 15) << 8)) + 1; - dcount[x] = (dcount[x] + 1) & 15; - } - } - } - } - cvbc[x] = SOUNDTS; -} - -static void DoSQV1HQ(void) { - DoSQVHQ(0); -} - -static void DoSQV2HQ(void) { - DoSQVHQ(1); -} - -static void DoSawVHQ(void) { - static uint8 b3 = 0; - static int32 phaseacc = 0; - int32 V; - - if (vpsg2[2] & 0x80) { - for (V = cvbc[2]; V < (int)SOUNDTS; V++) { - WaveHi[V] += (((phaseacc >> 3) & 0x1f) << 8) * 6 / 8; - vcount[2]--; - if (vcount[2] <= 0) { - vcount[2] = (vpsg2[1] + ((vpsg2[2] & 15) << 8) + 1) << 1; - phaseacc += vpsg2[0] & 0x3f; - b3++; - if (b3 == 7) { - b3 = 0; - phaseacc = 0; - } - } - } - } - cvbc[2] = SOUNDTS; -} - - -void VRC6Sound(int Count) { - int x; - - DoSQV1(); - DoSQV2(); - DoSawV(); - for (x = 0; x < 3; x++) - cvbc[x] = Count; -} - -void VRC6SoundHQ(void) { - DoSQV1HQ(); - DoSQV2HQ(); - DoSawVHQ(); -} - -void VRC6SyncHQ(int32 ts) { - int x; - for (x = 0; x < 3; x++) cvbc[x] = ts; -} - -static void VRC6_ESI(void) { - GameExpSound.RChange = VRC6_ESI; - GameExpSound.Fill = VRC6Sound; - GameExpSound.HiFill = VRC6SoundHQ; - GameExpSound.HiSync = VRC6SyncHQ; - - memset(cvbc, 0, sizeof(cvbc)); - memset(vcount, 0, sizeof(vcount)); - memset(dcount, 0, sizeof(dcount)); - if (FSettings.SndRate) { - if (FSettings.soundq >= 1) { - sfun[0] = DoSQV1HQ; - sfun[1] = DoSQV2HQ; - sfun[2] = DoSawVHQ; - } else { - sfun[0] = DoSQV1; - sfun[1] = DoSQV2; - sfun[2] = DoSawV; - } - } else - memset(sfun, 0, sizeof(sfun)); - AddExState(&SStateRegs, ~0, 0, 0); -} - -/* VRC6 Sound */ - -void Mapper24_Init(CartInfo *info) { - is26 = 0; - info->Power = VRC6Power; - MapIRQHook = VRC6IRQHook; - VRC6_ESI(); - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper26_Init(CartInfo *info) { - is26 = 1; - info->Power = VRC6Power; - info->Close = VRC6Close; - MapIRQHook = VRC6IRQHook; - VRC6_ESI(); - GameStateRestore = StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - - AddExState(&StateRegs, ~0, 0, 0); -} - -void NSFVRC6_Init(void) { - VRC6_ESI(); - SetWriteHandler(0x8000, 0xbfff, VRC6SW); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * VRC-6 + * + */ + +#include "mapinc.h" + +static uint8 is26; +static uint8 prg[2], chr[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static int32 IRQCount, CycleCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { prg, 2, "PRG" }, + { chr, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQd, 1, "IRQD" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQCount, 4, "IRQC" }, + { &CycleCount, 4, "CYCC" }, + { 0 } +}; + +static void(*sfun[3]) (void); +static uint8 vpsg1[8]; +static uint8 vpsg2[4]; +static int32 cvbc[3]; +static int32 vcount[3]; +static int32 dcount[2]; + +static SFORMAT SStateRegs[] = +{ + { vpsg1, 8, "PSG1" }, + { vpsg2, 4, "PSG2" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + if (is26) + setprg8r(0x10, 0x6000, 0); + setprg16(0x8000, prg[0]); + setprg8(0xc000, prg[1]); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(VRC6SW) { + A &= 0xF003; + if (A >= 0x9000 && A <= 0x9002) { + vpsg1[A & 3] = V; + if (sfun[0]) sfun[0](); + } else if (A >= 0xA000 && A <= 0xA002) { + vpsg1[4 | (A & 3)] = V; + if (sfun[1]) sfun[1](); + } else if (A >= 0xB000 && A <= 0xB002) { + vpsg2[A & 3] = V; + if (sfun[2]) sfun[2](); + } +} + +static DECLFW(VRC6Write) { + if (is26) + A = (A & 0xFFFC) | ((A >> 1) & 1) | ((A << 1) & 2); + if (A >= 0x9000 && A <= 0xB002) { + VRC6SW(A, V); + return; + } + switch (A & 0xF003) { + case 0x8000: prg[0] = V; Sync(); break; + case 0xB003: mirr = (V >> 2) & 3; Sync(); break; + case 0xC000: prg[1] = V; Sync(); break; + case 0xD000: chr[0] = V; Sync(); break; + case 0xD001: chr[1] = V; Sync(); break; + case 0xD002: chr[2] = V; Sync(); break; + case 0xD003: chr[3] = V; Sync(); break; + case 0xE000: chr[4] = V; Sync(); break; + case 0xE001: chr[5] = V; Sync(); break; + case 0xE002: chr[6] = V; Sync(); break; + case 0xE003: chr[7] = V; Sync(); break; + case 0xF000: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF001: + IRQa = V & 2; + IRQd = V & 1; + if (V & 2) + IRQCount = IRQLatch; + CycleCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF002: + IRQa = IRQd; + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void VRC6Power(void) { + Sync(); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetWriteHandler(0x8000, 0xFFFF, VRC6Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void VRC6IRQHook(int a) { + if (IRQa) { + CycleCount += a * 3; + while (CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 0x100) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void VRC6Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +/* VRC6 Sound */ + +static void DoSQV1(void); +static void DoSQV2(void); +static void DoSawV(void); + +static INLINE void DoSQV(int x) { + int32 V; + int32 amp = (((vpsg1[x << 2] & 15) << 8) * 6 / 8) >> 4; + int32 start, end; + + start = cvbc[x]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + cvbc[x] = end; + + if (vpsg1[(x << 2) | 0x2] & 0x80) { + if (vpsg1[x << 2] & 0x80) { + for (V = start; V < end; V++) + Wave[V >> 4] += amp; + } else { + int32 thresh = (vpsg1[x << 2] >> 4) & 7; + int32 freq = ((vpsg1[(x << 2) | 0x1] | ((vpsg1[(x << 2) | 0x2] & 15) << 8)) + 1) << 17; + for (V = start; V < end; V++) { + if (dcount[x] > thresh) + Wave[V >> 4] += amp; + vcount[x] -= nesincsize; + while (vcount[x] <= 0) { + vcount[x] += freq; + dcount[x] = (dcount[x] + 1) & 15; + } + } + } + } +} + +static void DoSQV1(void) { + DoSQV(0); +} + +static void DoSQV2(void) { + DoSQV(1); +} + +static void DoSawV(void) { + int V; + int32 start, end; + + start = cvbc[2]; + end = (SOUNDTS << 16) / soundtsinc; + if (end <= start) return; + cvbc[2] = end; + + if (vpsg2[2] & 0x80) { + static int32 saw1phaseacc = 0; + uint32 freq3; + static uint8 b3 = 0; + static int32 phaseacc = 0; + static uint32 duff = 0; + + freq3 = (vpsg2[1] + ((vpsg2[2] & 15) << 8) + 1); + + for (V = start; V < end; V++) { + saw1phaseacc -= nesincsize; + if (saw1phaseacc <= 0) { + int32 t; + rea: + t = freq3; + t <<= 18; + saw1phaseacc += t; + phaseacc += vpsg2[0] & 0x3f; + b3++; + if (b3 == 7) { + b3 = 0; + phaseacc = 0; + } + if (saw1phaseacc <= 0) + goto rea; + duff = (((phaseacc >> 3) & 0x1f) << 4) * 6 / 8; + } + Wave[V >> 4] += duff; + } + } +} + +static INLINE void DoSQVHQ(int x) { + int32 V; + int32 amp = ((vpsg1[x << 2] & 15) << 8) * 6 / 8; + + if (vpsg1[(x << 2) | 0x2] & 0x80) { + if (vpsg1[x << 2] & 0x80) { + for (V = cvbc[x]; V < (int)SOUNDTS; V++) + WaveHi[V] += amp; + } else { + int32 thresh = (vpsg1[x << 2] >> 4) & 7; + for (V = cvbc[x]; V < (int)SOUNDTS; V++) { + if (dcount[x] > thresh) + WaveHi[V] += amp; + vcount[x]--; + if (vcount[x] <= 0) { + vcount[x] = (vpsg1[(x << 2) | 0x1] | ((vpsg1[(x << 2) | 0x2] & 15) << 8)) + 1; + dcount[x] = (dcount[x] + 1) & 15; + } + } + } + } + cvbc[x] = SOUNDTS; +} + +static void DoSQV1HQ(void) { + DoSQVHQ(0); +} + +static void DoSQV2HQ(void) { + DoSQVHQ(1); +} + +static void DoSawVHQ(void) { + static uint8 b3 = 0; + static int32 phaseacc = 0; + int32 V; + + if (vpsg2[2] & 0x80) { + for (V = cvbc[2]; V < (int)SOUNDTS; V++) { + WaveHi[V] += (((phaseacc >> 3) & 0x1f) << 8) * 6 / 8; + vcount[2]--; + if (vcount[2] <= 0) { + vcount[2] = (vpsg2[1] + ((vpsg2[2] & 15) << 8) + 1) << 1; + phaseacc += vpsg2[0] & 0x3f; + b3++; + if (b3 == 7) { + b3 = 0; + phaseacc = 0; + } + } + } + } + cvbc[2] = SOUNDTS; +} + + +void VRC6Sound(int Count) { + int x; + + DoSQV1(); + DoSQV2(); + DoSawV(); + for (x = 0; x < 3; x++) + cvbc[x] = Count; +} + +void VRC6SoundHQ(void) { + DoSQV1HQ(); + DoSQV2HQ(); + DoSawVHQ(); +} + +void VRC6SyncHQ(int32 ts) { + int x; + for (x = 0; x < 3; x++) cvbc[x] = ts; +} + +static void VRC6_ESI(void) { + GameExpSound.RChange = VRC6_ESI; + GameExpSound.Fill = VRC6Sound; + GameExpSound.HiFill = VRC6SoundHQ; + GameExpSound.HiSync = VRC6SyncHQ; + + memset(cvbc, 0, sizeof(cvbc)); + memset(vcount, 0, sizeof(vcount)); + memset(dcount, 0, sizeof(dcount)); + if (FSettings.SndRate) { + if (FSettings.soundq >= 1) { + sfun[0] = DoSQV1HQ; + sfun[1] = DoSQV2HQ; + sfun[2] = DoSawVHQ; + } else { + sfun[0] = DoSQV1; + sfun[1] = DoSQV2; + sfun[2] = DoSawV; + } + } else + memset(sfun, 0, sizeof(sfun)); + AddExState(&SStateRegs, ~0, 0, 0); +} + +/* VRC6 Sound */ + +void Mapper24_Init(CartInfo *info) { + is26 = 0; + info->Power = VRC6Power; + MapIRQHook = VRC6IRQHook; + VRC6_ESI(); + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper26_Init(CartInfo *info) { + is26 = 1; + info->Power = VRC6Power; + info->Close = VRC6Close; + MapIRQHook = VRC6IRQHook; + VRC6_ESI(); + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} + +void NSFVRC6_Init(void) { + VRC6_ESI(); + SetWriteHandler(0x8000, 0xbfff, VRC6SW); +} diff --git a/src/boards/vrc7.c b/src/boards/vrc7.c index fbf21c9..7166f8c 100644 --- a/src/boards/vrc7.c +++ b/src/boards/vrc7.c @@ -1,200 +1,200 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2012 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 - */ - -#include "mapinc.h" -#include "emu2413.h" - -static int32 dwave = 0; -static OPLL *VRC7Sound = NULL; -static uint8 vrc7idx, preg[3], creg[8], mirr; -static uint8 IRQLatch, IRQa, IRQd; -static int32 IRQCount, CycleCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[] = -{ - { &vrc7idx, 1, "VRCI" }, - { preg, 3, "PREG" }, - { creg, 8, "CREG" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQd, 1, "IRQD" }, - { &IRQLatch, 1, "IRQL" }, - { &IRQCount, 4, "IRQC" }, - { &CycleCount, 4, "CYCC" }, - { 0 } -}; - -/* VRC7 Sound */ - -void DoVRC7Sound(void) { - int32 z, a; - if (FSettings.soundq >= 1) - return; - z = ((SOUNDTS << 16) / soundtsinc) >> 4; - a = z - dwave; - OPLL_fillbuf(VRC7Sound, &Wave[dwave], a, 1); - dwave += a; -} - -void UpdateOPLNEO(int32 *Wave, int Count) { - OPLL_fillbuf(VRC7Sound, Wave, Count, 4); -} - -void UpdateOPL(int Count) { - int32 z, a; - z = ((SOUNDTS << 16) / soundtsinc) >> 4; - a = z - dwave; - if (VRC7Sound && a) - OPLL_fillbuf(VRC7Sound, &Wave[dwave], a, 1); - dwave = 0; -} - -static void VRC7SC(void) { - if (VRC7Sound) - OPLL_set_rate(VRC7Sound, FSettings.SndRate); -} - -static void VRC7SKill(void) { - if (VRC7Sound) - OPLL_delete(VRC7Sound); - VRC7Sound = NULL; -} - -static void VRC7_ESI(void) { - GameExpSound.RChange = VRC7SC; - GameExpSound.Kill = VRC7SKill; - VRC7Sound = OPLL_new(3579545, FSettings.SndRate ? FSettings.SndRate : 44100); - OPLL_reset(VRC7Sound); - OPLL_reset(VRC7Sound); -} - -/* VRC7 Sound */ - -static void Sync(void) { - uint8 i; - setprg8r(0x10, 0x6000, 0); - setprg8(0x8000, preg[0]); - setprg8(0xA000, preg[1]); - setprg8(0xC000, preg[2]); - setprg8(0xE000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, creg[i]); - switch (mirr & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(VRC7SW) { - if (FSettings.SndRate) { - OPLL_writeReg(VRC7Sound, vrc7idx, V); - GameExpSound.Fill = UpdateOPL; - GameExpSound.NeoFill = UpdateOPLNEO; - } -} - -static DECLFW(VRC7Write) { - A |= (A & 8) << 1; /* another two-in-oooone */ - if (A >= 0xA000 && A <= 0xDFFF) { - A &= 0xF010; - creg[((A >> 4) & 1) | ((A - 0xA000) >> 11)] = V; - Sync(); - } else if (A == 0x9030) { - VRC7SW(A, V); - } else switch (A & 0xF010) { - case 0x8000: preg[0] = V; Sync(); break; - case 0x8010: preg[1] = V; Sync(); break; - case 0x9000: preg[2] = V; Sync(); break; - case 0x9010: vrc7idx = V; break; - case 0xE000: mirr = V & 3; Sync(); break; - case 0xE010: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xF000: - IRQa = V & 2; - IRQd = V & 1; - if (V & 2) - IRQCount = IRQLatch; - CycleCount = 0; - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xF010: - IRQa = IRQd; - X6502_IRQEnd(FCEU_IQEXT); - break; - } -} - -static void VRC7Power(void) { - Sync(); - SetWriteHandler(0x6000, 0x7FFF, CartBW); - SetReadHandler(0x6000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, VRC7Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void VRC7Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void VRC7IRQHook(int a) { - if (IRQa) { - CycleCount += a * 3; - while (CycleCount >= 341) { - CycleCount -= 341; - IRQCount++; - if (IRQCount == 0x100) { - IRQCount = IRQLatch; - X6502_IRQBegin(FCEU_IQEXT); - } - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void Mapper85_Init(CartInfo *info) { - info->Power = VRC7Power; - info->Close = VRC7Close; - MapIRQHook = VRC7IRQHook; - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - if (info->battery) { - info->SaveGame[0] = WRAM; - info->SaveGameLen[0] = WRAMSIZE; - } - GameStateRestore = StateRestore; - VRC7_ESI(); - AddExState(&StateRegs, ~0, 0, 0); -} - -void NSFVRC7_Init(void) { - SetWriteHandler(0x9010, 0x901F, VRC7Write); - SetWriteHandler(0x9030, 0x903F, VRC7Write); - VRC7_ESI(); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" +#include "emu2413.h" + +static int32 dwave = 0; +static OPLL *VRC7Sound = NULL; +static uint8 vrc7idx, preg[3], creg[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static int32 IRQCount, CycleCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { &vrc7idx, 1, "VRCI" }, + { preg, 3, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQd, 1, "IRQD" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQCount, 4, "IRQC" }, + { &CycleCount, 4, "CYCC" }, + { 0 } +}; + +/* VRC7 Sound */ + +void DoVRC7Sound(void) { + int32 z, a; + if (FSettings.soundq >= 1) + return; + z = ((SOUNDTS << 16) / soundtsinc) >> 4; + a = z - dwave; + OPLL_fillbuf(VRC7Sound, &Wave[dwave], a, 1); + dwave += a; +} + +void UpdateOPLNEO(int32 *Wave, int Count) { + OPLL_fillbuf(VRC7Sound, Wave, Count, 4); +} + +void UpdateOPL(int Count) { + int32 z, a; + z = ((SOUNDTS << 16) / soundtsinc) >> 4; + a = z - dwave; + if (VRC7Sound && a) + OPLL_fillbuf(VRC7Sound, &Wave[dwave], a, 1); + dwave = 0; +} + +static void VRC7SC(void) { + if (VRC7Sound) + OPLL_set_rate(VRC7Sound, FSettings.SndRate); +} + +static void VRC7SKill(void) { + if (VRC7Sound) + OPLL_delete(VRC7Sound); + VRC7Sound = NULL; +} + +static void VRC7_ESI(void) { + GameExpSound.RChange = VRC7SC; + GameExpSound.Kill = VRC7SKill; + VRC7Sound = OPLL_new(3579545, FSettings.SndRate ? FSettings.SndRate : 44100); + OPLL_reset(VRC7Sound); + OPLL_reset(VRC7Sound); +} + +/* VRC7 Sound */ + +static void Sync(void) { + uint8 i; + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000, preg[2]); + setprg8(0xE000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(VRC7SW) { + if (FSettings.SndRate) { + OPLL_writeReg(VRC7Sound, vrc7idx, V); + GameExpSound.Fill = UpdateOPL; + GameExpSound.NeoFill = UpdateOPLNEO; + } +} + +static DECLFW(VRC7Write) { + A |= (A & 8) << 1; /* another two-in-oooone */ + if (A >= 0xA000 && A <= 0xDFFF) { + A &= 0xF010; + creg[((A >> 4) & 1) | ((A - 0xA000) >> 11)] = V; + Sync(); + } else if (A == 0x9030) { + VRC7SW(A, V); + } else switch (A & 0xF010) { + case 0x8000: preg[0] = V; Sync(); break; + case 0x8010: preg[1] = V; Sync(); break; + case 0x9000: preg[2] = V; Sync(); break; + case 0x9010: vrc7idx = V; break; + case 0xE000: mirr = V & 3; Sync(); break; + case 0xE010: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF000: + IRQa = V & 2; + IRQd = V & 1; + if (V & 2) + IRQCount = IRQLatch; + CycleCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF010: + IRQa = IRQd; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void VRC7Power(void) { + Sync(); + SetWriteHandler(0x6000, 0x7FFF, CartBW); + SetReadHandler(0x6000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, VRC7Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void VRC7Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void VRC7IRQHook(int a) { + if (IRQa) { + CycleCount += a * 3; + while (CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 0x100) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper85_Init(CartInfo *info) { + info->Power = VRC7Power; + info->Close = VRC7Close; + MapIRQHook = VRC7IRQHook; + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if (info->battery) { + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE; + } + GameStateRestore = StateRestore; + VRC7_ESI(); + AddExState(&StateRegs, ~0, 0, 0); +} + +void NSFVRC7_Init(void) { + SetWriteHandler(0x9010, 0x901F, VRC7Write); + SetWriteHandler(0x9030, 0x903F, VRC7Write); + VRC7_ESI(); +} diff --git a/src/boards/vrc7p.c b/src/boards/vrc7p.c index 5a886cb..f1d28ca 100644 --- a/src/boards/vrc7p.c +++ b/src/boards/vrc7p.c @@ -1,120 +1,120 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2009 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 - * - * YOKO Mortal Kombat V Pro, VRC7 pirate clone - */ - -#include "mapinc.h" - -static uint8 prg[3], chr[8], mirr; -static uint8 IRQLatch, IRQa, IRQd; -static int32 IRQCount, CycleCount; - -static SFORMAT StateRegs[] = -{ - { prg, 3, "PRG" }, - { chr, 8, "CHR" }, - { &mirr, 1, "MIRR" }, - { &IRQa, 1, "IRQA" }, - { &IRQd, 1, "IRQD" }, - { &IRQLatch, 1, "IRQL" }, - { &IRQCount, 4, "IRQC" }, - { &CycleCount, 4, "CYCC" }, - { 0 } -}; - -static void Sync(void) { - uint8 i; - setprg8(0x8000, prg[0]); - setprg8(0xa000, prg[1]); - setprg8(0xc000, prg[2]); - setprg8(0xe000, ~0); - for (i = 0; i < 8; i++) - setchr1(i << 10, chr[i]); - switch (mirr & 3) { - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(UNLVRC7Write) { - switch (A & 0xF008) { - case 0x8000: prg[0] = V; Sync(); break; - case 0x8008: prg[1] = V; Sync(); break; - case 0x9000: prg[2] = V; Sync(); break; - case 0xa000: chr[0] = V; Sync(); break; - case 0xa008: chr[1] = V; Sync(); break; - case 0xb000: chr[2] = V; Sync(); break; - case 0xb008: chr[3] = V; Sync(); break; - case 0xc000: chr[4] = V; Sync(); break; - case 0xc008: chr[5] = V; Sync(); break; - case 0xd000: chr[6] = V; Sync(); break; - case 0xd008: chr[7] = V; Sync(); break; - case 0xe000: mirr = V; Sync(); break; - case 0xe008: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xf000: - IRQa = V & 2; - IRQd = V & 1; - if (V & 2) - IRQCount = IRQLatch; - CycleCount = 0; - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xf008: - if (IRQd) - IRQa = 1; - else - IRQa = 0; - X6502_IRQEnd(FCEU_IQEXT); - break; - } -} - -static void UNLVRC7Power(void) { - Sync(); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLVRC7Write); -} - -static void UNLVRC7IRQHook(int a) { - if (IRQa) { - CycleCount += a * 3; - while (CycleCount >= 341) { - CycleCount -= 341; - IRQCount++; - if (IRQCount == 248) { - IRQCount = IRQLatch; - X6502_IRQBegin(FCEU_IQEXT); - } - } - } -} - -static void StateRestore(int version) { - Sync(); -} - -void UNLVRC7_Init(CartInfo *info) { - info->Power = UNLVRC7Power; - MapIRQHook = UNLVRC7IRQHook; - GameStateRestore = StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * YOKO Mortal Kombat V Pro, VRC7 pirate clone + */ + +#include "mapinc.h" + +static uint8 prg[3], chr[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static int32 IRQCount, CycleCount; + +static SFORMAT StateRegs[] = +{ + { prg, 3, "PRG" }, + { chr, 8, "CHR" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQd, 1, "IRQD" }, + { &IRQLatch, 1, "IRQL" }, + { &IRQCount, 4, "IRQC" }, + { &CycleCount, 4, "CYCC" }, + { 0 } +}; + +static void Sync(void) { + uint8 i; + setprg8(0x8000, prg[0]); + setprg8(0xa000, prg[1]); + setprg8(0xc000, prg[2]); + setprg8(0xe000, ~0); + for (i = 0; i < 8; i++) + setchr1(i << 10, chr[i]); + switch (mirr & 3) { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(UNLVRC7Write) { + switch (A & 0xF008) { + case 0x8000: prg[0] = V; Sync(); break; + case 0x8008: prg[1] = V; Sync(); break; + case 0x9000: prg[2] = V; Sync(); break; + case 0xa000: chr[0] = V; Sync(); break; + case 0xa008: chr[1] = V; Sync(); break; + case 0xb000: chr[2] = V; Sync(); break; + case 0xb008: chr[3] = V; Sync(); break; + case 0xc000: chr[4] = V; Sync(); break; + case 0xc008: chr[5] = V; Sync(); break; + case 0xd000: chr[6] = V; Sync(); break; + case 0xd008: chr[7] = V; Sync(); break; + case 0xe000: mirr = V; Sync(); break; + case 0xe008: IRQLatch = V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xf000: + IRQa = V & 2; + IRQd = V & 1; + if (V & 2) + IRQCount = IRQLatch; + CycleCount = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf008: + if (IRQd) + IRQa = 1; + else + IRQa = 0; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void UNLVRC7Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLVRC7Write); +} + +static void UNLVRC7IRQHook(int a) { + if (IRQa) { + CycleCount += a * 3; + while (CycleCount >= 341) { + CycleCount -= 341; + IRQCount++; + if (IRQCount == 248) { + IRQCount = IRQLatch; + X6502_IRQBegin(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void UNLVRC7_Init(CartInfo *info) { + info->Power = UNLVRC7Power; + MapIRQHook = UNLVRC7IRQHook; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/yoko.c b/src/boards/yoko.c index 9601864..e91974a 100644 --- a/src/boards/yoko.c +++ b/src/boards/yoko.c @@ -1,237 +1,237 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - * - * YOKO mapper, almost the same as 83, TODO: figure out difference - * Mapper 83 - 30-in-1 mapper, two modes for single game carts, one mode for - * multigame Dragon Ball Z Party - * - * Mortal Kombat 2 YOKO - * N-CXX(M), XX - PRG+CHR, 12 - 128+256, 22 - 256+256, 14 - 128+512 - * - */ - -#include "mapinc.h" - -static uint8 mode, bank, reg[11], low[4], dip, IRQa; -static int32 IRQCount; -static uint8 *WRAM = NULL; -static uint32 WRAMSIZE; - -static uint8 is2kbank, isnot2kbank; - -static SFORMAT StateRegs[] = -{ - { &mode, 1, "MODE" }, - { &bank, 1, "BANK" }, - { &IRQCount, 4, "IRQC" }, - { &IRQa, 1, "IRQA" }, - { reg, 11, "REGS" }, - { low, 4, "LOWR" }, - { &is2kbank, 1, "IS2K" }, - { &isnot2kbank, 1, "NT2K" }, - { 0 } -}; - -static void UNLYOKOSync(void) { - setmirror((mode & 1) ^ 1); - setchr2(0x0000, reg[3]); - setchr2(0x0800, reg[4]); - setchr2(0x1000, reg[5]); - setchr2(0x1800, reg[6]); - if (mode & 0x10) { - uint32 base = (bank & 8) << 1; - setprg8(0x8000, (reg[0] & 0x0f) | base); - setprg8(0xA000, (reg[1] & 0x0f) | base); - setprg8(0xC000, (reg[2] & 0x0f) | base); - setprg8(0xE000, 0x0f | base); - } else { - if (mode & 8) - setprg32(0x8000, bank >> 1); - else { - setprg16(0x8000, bank); - setprg16(0xC000, ~0); - } - } -} - -static void M83Sync(void) { - switch (mode & 3) { /* check if it is true */ - case 0: setmirror(MI_V); break; - case 1: setmirror(MI_H); break; - case 2: setmirror(MI_0); break; - case 3: setmirror(MI_1); break; - } - if (is2kbank && !isnot2kbank) { - setchr2(0x0000, reg[0]); - setchr2(0x0800, reg[1]); - setchr2(0x1000, reg[6]); - setchr2(0x1800, reg[7]); - } else { - int x; - for (x = 0; x < 8; x++) - setchr1(x << 10, reg[x] | ((bank & 0x30) << 4)); - } - setprg8r(0x10, 0x6000, 0); - if (mode & 0x40) { - setprg16(0x8000, (bank & 0x3F)); /* DBZ Party [p1] */ - setprg16(0xC000, (bank & 0x30) | 0xF); - } else { - setprg8(0x8000, reg[8]); - setprg8(0xA000, reg[9]); - setprg8(0xC000, reg[10]); - setprg8(0xE000, ~0); - } -} - -static DECLFW(UNLYOKOWrite) { - switch (A & 0x8C17) { - case 0x8000: bank = V; UNLYOKOSync(); break; - case 0x8400: mode = V; UNLYOKOSync(); break; - case 0x8800: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0x8801: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break; - case 0x8c00: reg[0] = V; UNLYOKOSync(); break; - case 0x8c01: reg[1] = V; UNLYOKOSync(); break; - case 0x8c02: reg[2] = V; UNLYOKOSync(); break; - case 0x8c10: reg[3] = V; UNLYOKOSync(); break; - case 0x8c11: reg[4] = V; UNLYOKOSync(); break; - case 0x8c16: reg[5] = V; UNLYOKOSync(); break; - case 0x8c17: reg[6] = V; UNLYOKOSync(); break; - } -} - -static DECLFW(M83Write) { - switch (A) { - case 0x8000: is2kbank = 1; - case 0xB000: /* Dragon Ball Z Party [p1] BMC */ - case 0xB0FF: /* Dragon Ball Z Party [p1] BMC */ - case 0xB1FF: bank = V; mode |= 0x40; M83Sync(); break; /* Dragon Ball Z Party [p1] BMC */ - case 0x8100: mode = V | (mode & 0x40); M83Sync(); break; - case 0x8200: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; - case 0x8201: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break; - case 0x8300: reg[8] = V; mode &= 0xBF; M83Sync(); break; - case 0x8301: reg[9] = V; mode &= 0xBF; M83Sync(); break; - case 0x8302: reg[10] = V; mode &= 0xBF; M83Sync(); break; - case 0x8310: reg[0] = V; M83Sync(); break; - case 0x8311: reg[1] = V; M83Sync(); break; - case 0x8312: reg[2] = V; isnot2kbank = 1; M83Sync(); break; - case 0x8313: reg[3] = V; isnot2kbank = 1; M83Sync(); break; - case 0x8314: reg[4] = V; isnot2kbank = 1; M83Sync(); break; - case 0x8315: reg[5] = V; isnot2kbank = 1; M83Sync(); break; - case 0x8316: reg[6] = V; M83Sync(); break; - case 0x8317: reg[7] = V; M83Sync(); break; - } -} - -static DECLFR(UNLYOKOReadDip) { - return (X.DB & 0xFC) | dip; -} - -static DECLFR(UNLYOKOReadLow) { - return low[A & 3]; -} - -static DECLFW(UNLYOKOWriteLow) { - low[A & 3] = V; -} - -static void UNLYOKOPower(void) { - mode = bank = 0; - dip = 3; - UNLYOKOSync(); - SetReadHandler(0x5000, 0x53FF, UNLYOKOReadDip); - SetReadHandler(0x5400, 0x5FFF, UNLYOKOReadLow); - SetWriteHandler(0x5400, 0x5FFF, UNLYOKOWriteLow); - SetReadHandler(0x8000, 0xFFFF, CartBR); - SetWriteHandler(0x8000, 0xFFFF, UNLYOKOWrite); -} - -static void M83Power(void) { - is2kbank = 0; - isnot2kbank = 0; - mode = bank = 0; - dip = 0; - M83Sync(); - SetReadHandler(0x5000, 0x5000, UNLYOKOReadDip); - SetReadHandler(0x5100, 0x5103, UNLYOKOReadLow); - SetWriteHandler(0x5100, 0x5103, UNLYOKOWriteLow); - SetReadHandler(0x6000, 0x7fff, CartBR); - SetWriteHandler(0x6000, 0x7fff, CartBW);/* Pirate Dragon Ball Z Party [p1] used if for saves instead of seraial EEPROM */ - SetReadHandler(0x8000, 0xffff, CartBR); - SetWriteHandler(0x8000, 0xffff, M83Write); - FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); -} - -static void UNLYOKOReset(void) { - dip = (dip + 1) & 3; - mode = bank = 0; - UNLYOKOSync(); -} - -static void M83Reset(void) { - dip ^= 1; - M83Sync(); -} - -static void M83Close(void) { - if (WRAM) - FCEU_gfree(WRAM); - WRAM = NULL; -} - -static void FP_FASTAPASS(1) UNLYOKOIRQHook(int a) { - if (IRQa) { - IRQCount -= a; - if (IRQCount < 0) { - X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - IRQCount = 0xFFFF; - } - } -} - -static void UNLYOKOStateRestore(int version) { - UNLYOKOSync(); -} - -static void M83StateRestore(int version) { - M83Sync(); -} - -void UNLYOKO_Init(CartInfo *info) { - info->Power = UNLYOKOPower; - info->Reset = UNLYOKOReset; - MapIRQHook = UNLYOKOIRQHook; - GameStateRestore = UNLYOKOStateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper83_Init(CartInfo *info) { - info->Power = M83Power; - info->Reset = M83Reset; - info->Close = M83Close; - MapIRQHook = UNLYOKOIRQHook; - GameStateRestore = M83StateRestore; - - WRAMSIZE = 8192; - WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); - SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); - AddExState(WRAM, WRAMSIZE, 0, "WRAM"); - - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + * + * YOKO mapper, almost the same as 83, TODO: figure out difference + * Mapper 83 - 30-in-1 mapper, two modes for single game carts, one mode for + * multigame Dragon Ball Z Party + * + * Mortal Kombat 2 YOKO + * N-CXX(M), XX - PRG+CHR, 12 - 128+256, 22 - 256+256, 14 - 128+512 + * + */ + +#include "mapinc.h" + +static uint8 mode, bank, reg[11], low[4], dip, IRQa; +static int32 IRQCount; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static uint8 is2kbank, isnot2kbank; + +static SFORMAT StateRegs[] = +{ + { &mode, 1, "MODE" }, + { &bank, 1, "BANK" }, + { &IRQCount, 4, "IRQC" }, + { &IRQa, 1, "IRQA" }, + { reg, 11, "REGS" }, + { low, 4, "LOWR" }, + { &is2kbank, 1, "IS2K" }, + { &isnot2kbank, 1, "NT2K" }, + { 0 } +}; + +static void UNLYOKOSync(void) { + setmirror((mode & 1) ^ 1); + setchr2(0x0000, reg[3]); + setchr2(0x0800, reg[4]); + setchr2(0x1000, reg[5]); + setchr2(0x1800, reg[6]); + if (mode & 0x10) { + uint32 base = (bank & 8) << 1; + setprg8(0x8000, (reg[0] & 0x0f) | base); + setprg8(0xA000, (reg[1] & 0x0f) | base); + setprg8(0xC000, (reg[2] & 0x0f) | base); + setprg8(0xE000, 0x0f | base); + } else { + if (mode & 8) + setprg32(0x8000, bank >> 1); + else { + setprg16(0x8000, bank); + setprg16(0xC000, ~0); + } + } +} + +static void M83Sync(void) { + switch (mode & 3) { /* check if it is true */ + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } + if (is2kbank && !isnot2kbank) { + setchr2(0x0000, reg[0]); + setchr2(0x0800, reg[1]); + setchr2(0x1000, reg[6]); + setchr2(0x1800, reg[7]); + } else { + int x; + for (x = 0; x < 8; x++) + setchr1(x << 10, reg[x] | ((bank & 0x30) << 4)); + } + setprg8r(0x10, 0x6000, 0); + if (mode & 0x40) { + setprg16(0x8000, (bank & 0x3F)); /* DBZ Party [p1] */ + setprg16(0xC000, (bank & 0x30) | 0xF); + } else { + setprg8(0x8000, reg[8]); + setprg8(0xA000, reg[9]); + setprg8(0xC000, reg[10]); + setprg8(0xE000, ~0); + } +} + +static DECLFW(UNLYOKOWrite) { + switch (A & 0x8C17) { + case 0x8000: bank = V; UNLYOKOSync(); break; + case 0x8400: mode = V; UNLYOKOSync(); break; + case 0x8800: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8801: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break; + case 0x8c00: reg[0] = V; UNLYOKOSync(); break; + case 0x8c01: reg[1] = V; UNLYOKOSync(); break; + case 0x8c02: reg[2] = V; UNLYOKOSync(); break; + case 0x8c10: reg[3] = V; UNLYOKOSync(); break; + case 0x8c11: reg[4] = V; UNLYOKOSync(); break; + case 0x8c16: reg[5] = V; UNLYOKOSync(); break; + case 0x8c17: reg[6] = V; UNLYOKOSync(); break; + } +} + +static DECLFW(M83Write) { + switch (A) { + case 0x8000: is2kbank = 1; + case 0xB000: /* Dragon Ball Z Party [p1] BMC */ + case 0xB0FF: /* Dragon Ball Z Party [p1] BMC */ + case 0xB1FF: bank = V; mode |= 0x40; M83Sync(); break; /* Dragon Ball Z Party [p1] BMC */ + case 0x8100: mode = V | (mode & 0x40); M83Sync(); break; + case 0x8200: IRQCount &= 0xFF00; IRQCount |= V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8201: IRQa = mode & 0x80; IRQCount &= 0xFF; IRQCount |= V << 8; break; + case 0x8300: reg[8] = V; mode &= 0xBF; M83Sync(); break; + case 0x8301: reg[9] = V; mode &= 0xBF; M83Sync(); break; + case 0x8302: reg[10] = V; mode &= 0xBF; M83Sync(); break; + case 0x8310: reg[0] = V; M83Sync(); break; + case 0x8311: reg[1] = V; M83Sync(); break; + case 0x8312: reg[2] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8313: reg[3] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8314: reg[4] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8315: reg[5] = V; isnot2kbank = 1; M83Sync(); break; + case 0x8316: reg[6] = V; M83Sync(); break; + case 0x8317: reg[7] = V; M83Sync(); break; + } +} + +static DECLFR(UNLYOKOReadDip) { + return (X.DB & 0xFC) | dip; +} + +static DECLFR(UNLYOKOReadLow) { + return low[A & 3]; +} + +static DECLFW(UNLYOKOWriteLow) { + low[A & 3] = V; +} + +static void UNLYOKOPower(void) { + mode = bank = 0; + dip = 3; + UNLYOKOSync(); + SetReadHandler(0x5000, 0x53FF, UNLYOKOReadDip); + SetReadHandler(0x5400, 0x5FFF, UNLYOKOReadLow); + SetWriteHandler(0x5400, 0x5FFF, UNLYOKOWriteLow); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, UNLYOKOWrite); +} + +static void M83Power(void) { + is2kbank = 0; + isnot2kbank = 0; + mode = bank = 0; + dip = 0; + M83Sync(); + SetReadHandler(0x5000, 0x5000, UNLYOKOReadDip); + SetReadHandler(0x5100, 0x5103, UNLYOKOReadLow); + SetWriteHandler(0x5100, 0x5103, UNLYOKOWriteLow); + SetReadHandler(0x6000, 0x7fff, CartBR); + SetWriteHandler(0x6000, 0x7fff, CartBW);/* Pirate Dragon Ball Z Party [p1] used if for saves instead of seraial EEPROM */ + SetReadHandler(0x8000, 0xffff, CartBR); + SetWriteHandler(0x8000, 0xffff, M83Write); + FCEU_CheatAddRAM(WRAMSIZE >> 10, 0x6000, WRAM); +} + +static void UNLYOKOReset(void) { + dip = (dip + 1) & 3; + mode = bank = 0; + UNLYOKOSync(); +} + +static void M83Reset(void) { + dip ^= 1; + M83Sync(); +} + +static void M83Close(void) { + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void FP_FASTAPASS(1) UNLYOKOIRQHook(int a) { + if (IRQa) { + IRQCount -= a; + if (IRQCount < 0) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0xFFFF; + } + } +} + +static void UNLYOKOStateRestore(int version) { + UNLYOKOSync(); +} + +static void M83StateRestore(int version) { + M83Sync(); +} + +void UNLYOKO_Init(CartInfo *info) { + info->Power = UNLYOKOPower; + info->Reset = UNLYOKOReset; + MapIRQHook = UNLYOKOIRQHook; + GameStateRestore = UNLYOKOStateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper83_Init(CartInfo *info) { + info->Power = M83Power; + info->Reset = M83Reset; + info->Close = M83Close; + MapIRQHook = UNLYOKOIRQHook; + GameStateRestore = M83StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/debug.c b/src/debug.c index cd5b616..53449d6 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,497 +1,497 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2003 Xodnizel - * - * 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 -#include -#include - -#include "fceu-types.h" -#include "x6502.h" -#include "fceu.h" -#include "debug.h" -#include "cart.h" - - -void FCEUI_DumpVid(const char *fname, uint32 start, uint32 end) { - FILE *fp = FCEUD_UTF8fopen(fname, "wb"); - fceuindbg = 1; - start &= 0x3FFF; - end &= 0x3FFF; - for (; start <= end; start++) - fputc(VPage[start >> 10][start], fp); - fclose(fp); - fceuindbg = 0; -} - -void FCEUI_DumpMem(const char *fname, uint32 start, uint32 end) { - FILE *fp = FCEUD_UTF8fopen(fname, "wb"); - fceuindbg = 1; - for (; start <= end; start++) - fputc(ARead[start](start), fp); - fclose(fp); - fceuindbg = 0; -} - -void FCEUI_LoadMem(const char *fname, uint32 start, int hl) { - int t; - - FILE *fp = FCEUD_UTF8fopen(fname, "rb"); - while ((t = fgetc(fp)) >= 0) { - if (start > 0xFFFF) break; - if (hl) { - extern uint8 *Page[32]; - if (Page[start / 2048]) - Page[start / 2048][start] = t; - } else - BWrite[start](start, t); - start++; - } - fclose(fp); -} - -#ifdef FCEUDEF_DEBUGGER - -static char *fstrings[12] = -{ - "#$%02X", /* immediate */ - "$%04X", /* RELATIVE(jump) */ - "$%02X", /* Z */ - "$%02X,X", /* Z,x */ - "$%02X,Y", /* Z,y */ - "$%04X", /*ABS */ - "$%04X,X", /* ABS,x */ - "$%04X,Y", /* ABS,y */ - "($%04X)", /* IND */ - "($%02X,X)", /* INX */ - "($%02X),Y", /* INY */ - "" -}; -static int flengths[12] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 0 }; - -#define IMD(x) ((0 << 16) | x) -#define REL(x) ((1 << 16) | x) -#define ZP(x) ((2 << 16) | x) -#define ZPX(x) ((3 << 16) | x) -#define ZPY(x) ((4 << 16) | x) -#define ABS(x) ((5 << 16) | x) -#define ABX(x) ((6 << 16) | x) -#define ABY(x) ((7 << 16) | x) -#define IND(x) ((8 << 16) | x) -#define INX(x) ((9 << 16) | x) -#define INY(x) ((10 << 16) | x) -#define IMP(x) ((11 << 16) | x) - -typedef struct { - char *name; - int type; /* 1 for read, 2 for write, 3 for r then write. */ - int32 modes[10]; -} OPS; -#define NUMOPS 56 -static OPS optable[NUMOPS] = -{ - { "BRK", 0, { IMP(0x00), -1 } }, - { "RTI", 0, { IMP(0x40), -1 } }, - { "RTS", 0, { IMP(0x60), -1 } }, - { "PHA", 2, { IMP(0x48), -1 } }, - { "PHP", 2, { IMP(0x08), -1 } }, - { "PLA", 1, { IMP(0x68), -1 } }, - { "PLP", 1, { IMP(0x28), -1 } }, - { "JMP", 0, { ABS(0x4C), IND(0x6C), -1 } }, - { "JSR", 0, { ABS(0x20), -1 } }, - { "TAX", 0, { IMP(0xAA), -1 } }, - { "TXA", 0, { IMP(0x8A), -1 } }, - { "TAY", 0, { IMP(0xA8), -1 } }, - { "TYA", 0, { IMP(0x98), -1 } }, - { "TSX", 0, { IMP(0xBA), -1 } }, - { "TXS", 0, { IMP(0x9A), -1 } }, - { "DEX", 0, { IMP(0xCA), -1 } }, - { "DEY", 0, { IMP(0x88), -1 } }, - { "INX", 0, { IMP(0xE8), -1 } }, - { "INY", 0, { IMP(0xC8), -1 } }, - { "CLC", 0, { IMP(0x18), -1 } }, - { "CLD", 0, { IMP(0xD8), -1 } }, - { "CLI", 0, { IMP(0x58), -1 } }, - { "CLV", 0, { IMP(0xB8), -1 } }, - { "SEC", 0, { IMP(0x38), -1 } }, - { "SED", 0, { IMP(0xF8), -1 } }, - { "SEI", 0, { IMP(0x78), -1 } }, - { "NOP", 0, { IMP(0xEA), -1 } }, - { "ASL", 1, { IMP(0x0a), ZP(0x06), ZPX(0x16), ABS(0x0E), ABX(0x1E), -1 } }, - { "DEC", 3, { ZP(0xc6), ZPX(0xd6), ABS(0xcE), ABX(0xdE), -1 } }, - { "INC", 3, { ZP(0xe6), ZPX(0xf6), ABS(0xeE), ABX(0xfE), -1 } }, - { "LSR", 3, { IMP(0x4a), ZP(0x46), ZPX(0x56), ABS(0x4E), ABX(0x5E), -1 } }, - { "ROL", 3, { IMP(0x2a), ZP(0x26), ZPX(0x36), ABS(0x2E), ABX(0x3E), -1 } }, - { "ROR", 3, { IMP(0x6a), ZP(0x66), ZPX(0x76), ABS(0x6E), ABX(0x7E), -1 } }, - { "ADC", 1, { IMD(0x69), ZP(0x65), ZPX(0x75), ABS(0x6D), ABX(0x7d), ABY(0x79), - INX(0x61), INY(0x71), -1 } }, - { "AND", 1, { IMD(0x29), ZP(0x25), ZPX(0x35), ABS(0x2D), ABX(0x3d), ABY(0x39), - INX(0x21), INY(0x31), -1 } }, - { "BIT", 1, { ZP(0x24), ABS(0x2c), -1 } }, - { "CMP", 1, { IMD(0xc9), ZP(0xc5), ZPX(0xd5), ABS(0xcD), ABX(0xdd), ABY(0xd9), - INX(0xc1), INY(0xd1), -1 } }, - { "CPX", 1, { IMD(0xe0), ZP(0xe4), ABS(0xec), -1 } }, - { "CPY", 1, { IMD(0xc0), ZP(0xc4), ABS(0xcc), -1 } }, - { "EOR", 1, { IMD(0x49), ZP(0x45), ZPX(0x55), ABS(0x4D), ABX(0x5d), ABY(0x59), - INX(0x41), INY(0x51), -1 } }, - { "LDA", 1, { IMD(0xa9), ZP(0xa5), ZPX(0xb5), ABS(0xaD), ABX(0xbd), ABY(0xb9), - INX(0xa1), INY(0xb1), -1 } }, - { "LDX", 1, { IMD(0xa2), ZP(0xa6), ZPY(0xB6), ABS(0xae), ABY(0xbe), -1 } }, - { "LDY", 1, { IMD(0xa0), ZP(0xa4), ZPX(0xB4), ABS(0xac), ABX(0xbc), -1 } }, - { "ORA", 1, { IMD(0x09), ZP(0x05), ZPX(0x15), ABS(0x0D), ABX(0x1d), ABY(0x19), - INX(0x01), INY(0x11), -1 } }, - { "SBC", 1, { IMD(0xEB), IMD(0xe9), ZP(0xe5), ZPX(0xf5), ABS(0xeD), ABX(0xfd), ABY(0xf9), - INX(0xe1), INY(0xf1), -1 } }, - { "STA", 2, { ZP(0x85), ZPX(0x95), ABS(0x8D), ABX(0x9d), ABY(0x99), - INX(0x81), INY(0x91), -1 } }, - { "STX", 2, { ZP(0x86), ZPY(0x96), ABS(0x8E), -1 } }, - { "STY", 2, { ZP(0x84), ZPX(0x94), ABS(0x8C), -1 } }, - { "BCC", 1, { REL(0x90), -1 } }, - { "BCS", 1, { REL(0xb0), -1 } }, - { "BEQ", 1, { REL(0xf0), -1 } }, - { "BNE", 1, { REL(0xd0), -1 } }, - { "BMI", 1, { REL(0x30), -1 } }, - { "BPL", 1, { REL(0x10), -1 } }, - { "BVC", 1, { REL(0x50), -1 } }, - { "BVS", 1, { REL(0x70), -1 } }, -}; - -uint16 FCEUI_Disassemble(void *XA, uint16 a, char *stringo) { - X6502 *X = XA; - uint8 buf; - uint32 arg; - int32 info; - int x; - int y; - - info = -1; - fceuindbg = 1; - - buf = ARead[a](a); - a++; - - for (x = 0; x < NUMOPS; x++) { - y = 0; - while (optable[x].modes[y] >= 0) { - if ((optable[x].modes[y] & 0xFF) == buf) { - info = optable[x].modes[y]; - goto endy; - } - y++; - } - } - - endy: - sprintf(stringo, "%02X ", buf); - if (info >= 0) { - int z = flengths[(info >> 16)]; - - if (z) { - arg = ARead[a](a); - sprintf(stringo + strlen(stringo), "%02X ", arg); - a++; - if (z == 2) { - arg |= ARead[a](a) << 8; sprintf(stringo + strlen(stringo), "%02X ", arg >> 8); a++; - } else - strcat(stringo, " "); - - if ((info >> 16) == 1) /* Relative branch */ - arg = a + (char)arg; - sprintf(stringo + strlen(stringo), "%s ", optable[x].name); - sprintf(stringo + strlen(stringo), fstrings[info >> 16], arg); -/* - 0 "#$%02X", // immediate - 1 "$%04X", // RELATIVE(jump) - 2 "$%02X", // Z - 3 "$%02X,X", // Z,x - 4 "$%02X,Y", // Z,y - 5 "$%04X", //ABS - 6 "$%04X,X", // ABS,x - 7 "$%04X,Y", // ABS,y - 8 "($%04X)", // IND - 9 "($%02X,X)", // INX - 10 "($%02X),Y", // INY - 11 #define IMP(x) ((11<<16)|x) -*/ - { - uint32 tmp; - switch (info >> 16) { - case 2: tmp = arg; - if (optable[x].type & 1) { - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - } - break; - case 3: tmp = (arg + X->X) & 0xff; - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - if (optable[x].type & 1) - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - break; - case 4: tmp = (arg + X->Y) & 0xff; - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - if (optable[x].type & 1) - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - break; - case 5: tmp = arg; - if (optable[x].type & 1) { - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - } - break; - case 6: tmp = (arg + X->X) & 0xffff; - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - if (optable[x].type & 1) - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - break; - case 7: tmp = (arg + X->Y) & 0xffff; - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - if (optable[x].type & 1) - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - break; - case 8: tmp = ARead[arg](arg) | (ARead[(arg + 1) & 0xffff]((arg + 1) & 0xffff) << 8); - sprintf(stringo + strlen(stringo), " $%04X", tmp); - break; - case 9: tmp = (arg + X->X) & 0xFF; - tmp = ARead[tmp](tmp) | (ARead[(tmp + 1) & 0xFF]((tmp + 1) & 0xFF) << 8); - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - if (optable[x].type & 1) - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - break; - case 10: tmp = ARead[arg](arg) | (ARead[(arg + 1) & 0xFF]((arg + 1) & 0xFF) << 8); - tmp = (tmp + X->Y) & 0xFFFF; - sprintf(stringo + strlen(stringo), " @ $%04X", tmp); - if (optable[x].type & 1) - sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); - break; - } - } - } else { - strcat(stringo, " "); - strcat(stringo, optable[x].name); - } - } else - sprintf(stringo + strlen(stringo), " .db $%02X", buf); - fceuindbg = 0; - return(a); -} - -void FCEUI_MemDump(uint16 a, int32 len, void (*callb)(uint16 a, uint8 v)) { - fceuindbg = 1; - while (len) { - callb(a, ARead[a](a)); - a++; - len--; - } - fceuindbg = 0; -} - -uint8 FCEUI_MemSafePeek(uint16 A) { - uint8 ret; - - fceuindbg = 1; - ret = ARead[A](A); - fceuindbg = 0; - return(ret); -} - -void FCEUI_MemPoke(uint16 a, uint8 v, int hl) { - extern uint8 *Page[32]; - if (hl) { - if (Page[a / 2048]) - Page[a / 2048][a] = v; - } else - BWrite[a](a, v); -} - -typedef struct __BPOINT { - struct __BPOINT *next; - void (*Handler)(X6502 *X, int type, uint32 A); - uint32 A[2]; - int type; -} BPOINT; - -static BPOINT *BreakPoints = NULL; -static BPOINT *LastBP = NULL; - -static void (*CPUHook)(X6502 *) = NULL; - -static int FindBPoint(X6502 *X, int who, uint32 A) { - BPOINT *tmp; - - tmp = BreakPoints; - while (tmp) { - if (who & BPOINT_EXCLUDE) { - if ((tmp->type & who) == who) { - if ((X->PC >= tmp->A[0]) && (X->PC <= tmp->A[1])) { - return(1); - } - } - } else { - if (tmp->type & who) { - if (tmp->type & BPOINT_PC) - if (X->PC != A) goto don; - if (tmp->type & BPOINT_EXCLUDE) goto don; - - if ((A >= tmp->A[0]) && (A <= tmp->A[1])) { - if (!FindBPoint(X, who | BPOINT_EXCLUDE, A)) { - tmp->Handler(X, tmp->type, A); - return(1); - } - } - } - } - don: - tmp = tmp->next; - } - return(0); -} - -static uint8 ReadHandler(X6502 *X, uint32 A) { - extern X6502 XSave; - - if (X->preexec) - FindBPoint(&XSave, BPOINT_READ, A); - return(ARead[A](A)); -} - -static void WriteHandler(X6502 *X, uint32 A, uint8 V) { - extern X6502 XSave; - - if (X->preexec) - FindBPoint(&XSave, BPOINT_WRITE, A); - else - BWrite[A](A, V); -} - -int FCEUI_AddBreakPoint(int type, uint32 A1, uint32 A2, - void (*Handler)(X6502 *, int type, uint32 A)) { - BPOINT *tmp; - - tmp = (BPOINT*)malloc(sizeof(BPOINT)); - - tmp->A[0] = A1; - tmp->A[1] = A2; - tmp->Handler = Handler; - tmp->type = type; - tmp->next = 0; - - if (BreakPoints == NULL) - BreakPoints = tmp; - else - LastBP->next = tmp; - - LastBP = tmp; - - X6502_Debug(CPUHook, ReadHandler, WriteHandler); - return(1); -} - -int FCEUI_SetBreakPoint(uint32 w, int type, uint32 A1, uint32 A2, - void (*Handler)(X6502 *, int type, uint32 A)) { - uint32 x = 0; - BPOINT *tmp; - - tmp = BreakPoints; - - while (tmp) { - if (w == x) { - tmp->type = type; - tmp->A[0] = A1; - tmp->A[1] = A2; - tmp->Handler = Handler; - return(1); - } - x++; - tmp = tmp->next; - } - return(0); -} - -int FCEUI_GetBreakPoint(uint32 w, int *type, uint32 *A1, uint32 *A2, - void(**Handler) (X6502 *, int type, uint32 A)) { - uint32 x = 0; - BPOINT *tmp; - - tmp = BreakPoints; - - while (tmp) { - if (w == x) { - *type = tmp->type; - *A1 = tmp->A[0]; - *A2 = tmp->A[1]; - *Handler = tmp->Handler; - return(1); - } - x++; - tmp = tmp->next; - } - return(0); -} - -int FCEUI_ListBreakPoints(int (*callb)(int type, uint32 A1, uint32 A2, - void (*Handler)(X6502 *, int type, uint32 A))) { - BPOINT *tmp; - tmp = BreakPoints; - while (tmp) { - callb(tmp->type, tmp->A[0], tmp->A[1], tmp->Handler); - tmp = tmp->next; - } - return(1); -} - -int FCEUI_DeleteBreakPoint(uint32 w) { - BPOINT *tmp, *prev = NULL; - uint32 x = 0; - - tmp = BreakPoints; - - while (tmp) { - if (w == x) { - if (prev) { /* Not the first breakpoint. */ - if (tmp->next) /* More breakpoints. */ - prev->next = tmp->next; - else { /* This is the last breakpoint. */ - prev->next = 0; - LastBP = prev; - } - } else {/* The first breakpoint. */ - if (tmp->next) /* More breakpoints. */ - BreakPoints = tmp->next; - else { - BreakPoints = LastBP = 0; /* No more breakpoints. */ - /* Update the CPU hooks. */ - X6502_Debug(CPUHook, BreakPoints ? ReadHandler : 0, BreakPoints ? WriteHandler : 0); - } - } - free(tmp); - tmp = 0; - return(1); - } - prev = tmp; - tmp = tmp->next; - x++; - } - return(0); -} - -void FCEUI_SetCPUCallback(void (*callb)(X6502 *X)) { - CPUHook = callb; - X6502_Debug(CPUHook, BreakPoints ? ReadHandler : 0, BreakPoints ? WriteHandler : 0); -} -#endif +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 Xodnizel + * + * 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 +#include +#include + +#include "fceu-types.h" +#include "x6502.h" +#include "fceu.h" +#include "debug.h" +#include "cart.h" + + +void FCEUI_DumpVid(const char *fname, uint32 start, uint32 end) { + FILE *fp = FCEUD_UTF8fopen(fname, "wb"); + fceuindbg = 1; + start &= 0x3FFF; + end &= 0x3FFF; + for (; start <= end; start++) + fputc(VPage[start >> 10][start], fp); + fclose(fp); + fceuindbg = 0; +} + +void FCEUI_DumpMem(const char *fname, uint32 start, uint32 end) { + FILE *fp = FCEUD_UTF8fopen(fname, "wb"); + fceuindbg = 1; + for (; start <= end; start++) + fputc(ARead[start](start), fp); + fclose(fp); + fceuindbg = 0; +} + +void FCEUI_LoadMem(const char *fname, uint32 start, int hl) { + int t; + + FILE *fp = FCEUD_UTF8fopen(fname, "rb"); + while ((t = fgetc(fp)) >= 0) { + if (start > 0xFFFF) break; + if (hl) { + extern uint8 *Page[32]; + if (Page[start / 2048]) + Page[start / 2048][start] = t; + } else + BWrite[start](start, t); + start++; + } + fclose(fp); +} + +#ifdef FCEUDEF_DEBUGGER + +static char *fstrings[12] = +{ + "#$%02X", /* immediate */ + "$%04X", /* RELATIVE(jump) */ + "$%02X", /* Z */ + "$%02X,X", /* Z,x */ + "$%02X,Y", /* Z,y */ + "$%04X", /*ABS */ + "$%04X,X", /* ABS,x */ + "$%04X,Y", /* ABS,y */ + "($%04X)", /* IND */ + "($%02X,X)", /* INX */ + "($%02X),Y", /* INY */ + "" +}; +static int flengths[12] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 0 }; + +#define IMD(x) ((0 << 16) | x) +#define REL(x) ((1 << 16) | x) +#define ZP(x) ((2 << 16) | x) +#define ZPX(x) ((3 << 16) | x) +#define ZPY(x) ((4 << 16) | x) +#define ABS(x) ((5 << 16) | x) +#define ABX(x) ((6 << 16) | x) +#define ABY(x) ((7 << 16) | x) +#define IND(x) ((8 << 16) | x) +#define INX(x) ((9 << 16) | x) +#define INY(x) ((10 << 16) | x) +#define IMP(x) ((11 << 16) | x) + +typedef struct { + char *name; + int type; /* 1 for read, 2 for write, 3 for r then write. */ + int32 modes[10]; +} OPS; +#define NUMOPS 56 +static OPS optable[NUMOPS] = +{ + { "BRK", 0, { IMP(0x00), -1 } }, + { "RTI", 0, { IMP(0x40), -1 } }, + { "RTS", 0, { IMP(0x60), -1 } }, + { "PHA", 2, { IMP(0x48), -1 } }, + { "PHP", 2, { IMP(0x08), -1 } }, + { "PLA", 1, { IMP(0x68), -1 } }, + { "PLP", 1, { IMP(0x28), -1 } }, + { "JMP", 0, { ABS(0x4C), IND(0x6C), -1 } }, + { "JSR", 0, { ABS(0x20), -1 } }, + { "TAX", 0, { IMP(0xAA), -1 } }, + { "TXA", 0, { IMP(0x8A), -1 } }, + { "TAY", 0, { IMP(0xA8), -1 } }, + { "TYA", 0, { IMP(0x98), -1 } }, + { "TSX", 0, { IMP(0xBA), -1 } }, + { "TXS", 0, { IMP(0x9A), -1 } }, + { "DEX", 0, { IMP(0xCA), -1 } }, + { "DEY", 0, { IMP(0x88), -1 } }, + { "INX", 0, { IMP(0xE8), -1 } }, + { "INY", 0, { IMP(0xC8), -1 } }, + { "CLC", 0, { IMP(0x18), -1 } }, + { "CLD", 0, { IMP(0xD8), -1 } }, + { "CLI", 0, { IMP(0x58), -1 } }, + { "CLV", 0, { IMP(0xB8), -1 } }, + { "SEC", 0, { IMP(0x38), -1 } }, + { "SED", 0, { IMP(0xF8), -1 } }, + { "SEI", 0, { IMP(0x78), -1 } }, + { "NOP", 0, { IMP(0xEA), -1 } }, + { "ASL", 1, { IMP(0x0a), ZP(0x06), ZPX(0x16), ABS(0x0E), ABX(0x1E), -1 } }, + { "DEC", 3, { ZP(0xc6), ZPX(0xd6), ABS(0xcE), ABX(0xdE), -1 } }, + { "INC", 3, { ZP(0xe6), ZPX(0xf6), ABS(0xeE), ABX(0xfE), -1 } }, + { "LSR", 3, { IMP(0x4a), ZP(0x46), ZPX(0x56), ABS(0x4E), ABX(0x5E), -1 } }, + { "ROL", 3, { IMP(0x2a), ZP(0x26), ZPX(0x36), ABS(0x2E), ABX(0x3E), -1 } }, + { "ROR", 3, { IMP(0x6a), ZP(0x66), ZPX(0x76), ABS(0x6E), ABX(0x7E), -1 } }, + { "ADC", 1, { IMD(0x69), ZP(0x65), ZPX(0x75), ABS(0x6D), ABX(0x7d), ABY(0x79), + INX(0x61), INY(0x71), -1 } }, + { "AND", 1, { IMD(0x29), ZP(0x25), ZPX(0x35), ABS(0x2D), ABX(0x3d), ABY(0x39), + INX(0x21), INY(0x31), -1 } }, + { "BIT", 1, { ZP(0x24), ABS(0x2c), -1 } }, + { "CMP", 1, { IMD(0xc9), ZP(0xc5), ZPX(0xd5), ABS(0xcD), ABX(0xdd), ABY(0xd9), + INX(0xc1), INY(0xd1), -1 } }, + { "CPX", 1, { IMD(0xe0), ZP(0xe4), ABS(0xec), -1 } }, + { "CPY", 1, { IMD(0xc0), ZP(0xc4), ABS(0xcc), -1 } }, + { "EOR", 1, { IMD(0x49), ZP(0x45), ZPX(0x55), ABS(0x4D), ABX(0x5d), ABY(0x59), + INX(0x41), INY(0x51), -1 } }, + { "LDA", 1, { IMD(0xa9), ZP(0xa5), ZPX(0xb5), ABS(0xaD), ABX(0xbd), ABY(0xb9), + INX(0xa1), INY(0xb1), -1 } }, + { "LDX", 1, { IMD(0xa2), ZP(0xa6), ZPY(0xB6), ABS(0xae), ABY(0xbe), -1 } }, + { "LDY", 1, { IMD(0xa0), ZP(0xa4), ZPX(0xB4), ABS(0xac), ABX(0xbc), -1 } }, + { "ORA", 1, { IMD(0x09), ZP(0x05), ZPX(0x15), ABS(0x0D), ABX(0x1d), ABY(0x19), + INX(0x01), INY(0x11), -1 } }, + { "SBC", 1, { IMD(0xEB), IMD(0xe9), ZP(0xe5), ZPX(0xf5), ABS(0xeD), ABX(0xfd), ABY(0xf9), + INX(0xe1), INY(0xf1), -1 } }, + { "STA", 2, { ZP(0x85), ZPX(0x95), ABS(0x8D), ABX(0x9d), ABY(0x99), + INX(0x81), INY(0x91), -1 } }, + { "STX", 2, { ZP(0x86), ZPY(0x96), ABS(0x8E), -1 } }, + { "STY", 2, { ZP(0x84), ZPX(0x94), ABS(0x8C), -1 } }, + { "BCC", 1, { REL(0x90), -1 } }, + { "BCS", 1, { REL(0xb0), -1 } }, + { "BEQ", 1, { REL(0xf0), -1 } }, + { "BNE", 1, { REL(0xd0), -1 } }, + { "BMI", 1, { REL(0x30), -1 } }, + { "BPL", 1, { REL(0x10), -1 } }, + { "BVC", 1, { REL(0x50), -1 } }, + { "BVS", 1, { REL(0x70), -1 } }, +}; + +uint16 FCEUI_Disassemble(void *XA, uint16 a, char *stringo) { + X6502 *X = XA; + uint8 buf; + uint32 arg; + int32 info; + int x; + int y; + + info = -1; + fceuindbg = 1; + + buf = ARead[a](a); + a++; + + for (x = 0; x < NUMOPS; x++) { + y = 0; + while (optable[x].modes[y] >= 0) { + if ((optable[x].modes[y] & 0xFF) == buf) { + info = optable[x].modes[y]; + goto endy; + } + y++; + } + } + + endy: + sprintf(stringo, "%02X ", buf); + if (info >= 0) { + int z = flengths[(info >> 16)]; + + if (z) { + arg = ARead[a](a); + sprintf(stringo + strlen(stringo), "%02X ", arg); + a++; + if (z == 2) { + arg |= ARead[a](a) << 8; sprintf(stringo + strlen(stringo), "%02X ", arg >> 8); a++; + } else + strcat(stringo, " "); + + if ((info >> 16) == 1) /* Relative branch */ + arg = a + (char)arg; + sprintf(stringo + strlen(stringo), "%s ", optable[x].name); + sprintf(stringo + strlen(stringo), fstrings[info >> 16], arg); +/* + 0 "#$%02X", // immediate + 1 "$%04X", // RELATIVE(jump) + 2 "$%02X", // Z + 3 "$%02X,X", // Z,x + 4 "$%02X,Y", // Z,y + 5 "$%04X", //ABS + 6 "$%04X,X", // ABS,x + 7 "$%04X,Y", // ABS,y + 8 "($%04X)", // IND + 9 "($%02X,X)", // INX + 10 "($%02X),Y", // INY + 11 #define IMP(x) ((11<<16)|x) +*/ + { + uint32 tmp; + switch (info >> 16) { + case 2: tmp = arg; + if (optable[x].type & 1) { + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + } + break; + case 3: tmp = (arg + X->X) & 0xff; + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + if (optable[x].type & 1) + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + break; + case 4: tmp = (arg + X->Y) & 0xff; + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + if (optable[x].type & 1) + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + break; + case 5: tmp = arg; + if (optable[x].type & 1) { + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + } + break; + case 6: tmp = (arg + X->X) & 0xffff; + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + if (optable[x].type & 1) + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + break; + case 7: tmp = (arg + X->Y) & 0xffff; + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + if (optable[x].type & 1) + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + break; + case 8: tmp = ARead[arg](arg) | (ARead[(arg + 1) & 0xffff]((arg + 1) & 0xffff) << 8); + sprintf(stringo + strlen(stringo), " $%04X", tmp); + break; + case 9: tmp = (arg + X->X) & 0xFF; + tmp = ARead[tmp](tmp) | (ARead[(tmp + 1) & 0xFF]((tmp + 1) & 0xFF) << 8); + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + if (optable[x].type & 1) + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + break; + case 10: tmp = ARead[arg](arg) | (ARead[(arg + 1) & 0xFF]((arg + 1) & 0xFF) << 8); + tmp = (tmp + X->Y) & 0xFFFF; + sprintf(stringo + strlen(stringo), " @ $%04X", tmp); + if (optable[x].type & 1) + sprintf(stringo + strlen(stringo), " = $%02X", ARead[tmp](tmp)); + break; + } + } + } else { + strcat(stringo, " "); + strcat(stringo, optable[x].name); + } + } else + sprintf(stringo + strlen(stringo), " .db $%02X", buf); + fceuindbg = 0; + return(a); +} + +void FCEUI_MemDump(uint16 a, int32 len, void (*callb)(uint16 a, uint8 v)) { + fceuindbg = 1; + while (len) { + callb(a, ARead[a](a)); + a++; + len--; + } + fceuindbg = 0; +} + +uint8 FCEUI_MemSafePeek(uint16 A) { + uint8 ret; + + fceuindbg = 1; + ret = ARead[A](A); + fceuindbg = 0; + return(ret); +} + +void FCEUI_MemPoke(uint16 a, uint8 v, int hl) { + extern uint8 *Page[32]; + if (hl) { + if (Page[a / 2048]) + Page[a / 2048][a] = v; + } else + BWrite[a](a, v); +} + +typedef struct __BPOINT { + struct __BPOINT *next; + void (*Handler)(X6502 *X, int type, uint32 A); + uint32 A[2]; + int type; +} BPOINT; + +static BPOINT *BreakPoints = NULL; +static BPOINT *LastBP = NULL; + +static void (*CPUHook)(X6502 *) = NULL; + +static int FindBPoint(X6502 *X, int who, uint32 A) { + BPOINT *tmp; + + tmp = BreakPoints; + while (tmp) { + if (who & BPOINT_EXCLUDE) { + if ((tmp->type & who) == who) { + if ((X->PC >= tmp->A[0]) && (X->PC <= tmp->A[1])) { + return(1); + } + } + } else { + if (tmp->type & who) { + if (tmp->type & BPOINT_PC) + if (X->PC != A) goto don; + if (tmp->type & BPOINT_EXCLUDE) goto don; + + if ((A >= tmp->A[0]) && (A <= tmp->A[1])) { + if (!FindBPoint(X, who | BPOINT_EXCLUDE, A)) { + tmp->Handler(X, tmp->type, A); + return(1); + } + } + } + } + don: + tmp = tmp->next; + } + return(0); +} + +static uint8 ReadHandler(X6502 *X, uint32 A) { + extern X6502 XSave; + + if (X->preexec) + FindBPoint(&XSave, BPOINT_READ, A); + return(ARead[A](A)); +} + +static void WriteHandler(X6502 *X, uint32 A, uint8 V) { + extern X6502 XSave; + + if (X->preexec) + FindBPoint(&XSave, BPOINT_WRITE, A); + else + BWrite[A](A, V); +} + +int FCEUI_AddBreakPoint(int type, uint32 A1, uint32 A2, + void (*Handler)(X6502 *, int type, uint32 A)) { + BPOINT *tmp; + + tmp = (BPOINT*)malloc(sizeof(BPOINT)); + + tmp->A[0] = A1; + tmp->A[1] = A2; + tmp->Handler = Handler; + tmp->type = type; + tmp->next = 0; + + if (BreakPoints == NULL) + BreakPoints = tmp; + else + LastBP->next = tmp; + + LastBP = tmp; + + X6502_Debug(CPUHook, ReadHandler, WriteHandler); + return(1); +} + +int FCEUI_SetBreakPoint(uint32 w, int type, uint32 A1, uint32 A2, + void (*Handler)(X6502 *, int type, uint32 A)) { + uint32 x = 0; + BPOINT *tmp; + + tmp = BreakPoints; + + while (tmp) { + if (w == x) { + tmp->type = type; + tmp->A[0] = A1; + tmp->A[1] = A2; + tmp->Handler = Handler; + return(1); + } + x++; + tmp = tmp->next; + } + return(0); +} + +int FCEUI_GetBreakPoint(uint32 w, int *type, uint32 *A1, uint32 *A2, + void(**Handler) (X6502 *, int type, uint32 A)) { + uint32 x = 0; + BPOINT *tmp; + + tmp = BreakPoints; + + while (tmp) { + if (w == x) { + *type = tmp->type; + *A1 = tmp->A[0]; + *A2 = tmp->A[1]; + *Handler = tmp->Handler; + return(1); + } + x++; + tmp = tmp->next; + } + return(0); +} + +int FCEUI_ListBreakPoints(int (*callb)(int type, uint32 A1, uint32 A2, + void (*Handler)(X6502 *, int type, uint32 A))) { + BPOINT *tmp; + tmp = BreakPoints; + while (tmp) { + callb(tmp->type, tmp->A[0], tmp->A[1], tmp->Handler); + tmp = tmp->next; + } + return(1); +} + +int FCEUI_DeleteBreakPoint(uint32 w) { + BPOINT *tmp, *prev = NULL; + uint32 x = 0; + + tmp = BreakPoints; + + while (tmp) { + if (w == x) { + if (prev) { /* Not the first breakpoint. */ + if (tmp->next) /* More breakpoints. */ + prev->next = tmp->next; + else { /* This is the last breakpoint. */ + prev->next = 0; + LastBP = prev; + } + } else {/* The first breakpoint. */ + if (tmp->next) /* More breakpoints. */ + BreakPoints = tmp->next; + else { + BreakPoints = LastBP = 0; /* No more breakpoints. */ + /* Update the CPU hooks. */ + X6502_Debug(CPUHook, BreakPoints ? ReadHandler : 0, BreakPoints ? WriteHandler : 0); + } + } + free(tmp); + tmp = 0; + return(1); + } + prev = tmp; + tmp = tmp->next; + x++; + } + return(0); +} + +void FCEUI_SetCPUCallback(void (*callb)(X6502 *X)) { + CPUHook = callb; + X6502_Debug(CPUHook, BreakPoints ? ReadHandler : 0, BreakPoints ? WriteHandler : 0); +} +#endif diff --git a/src/input/bbox.c b/src/input/bbox.c index c236b55..5622455 100644 --- a/src/input/bbox.c +++ b/src/input/bbox.c @@ -1,194 +1,194 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2006 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 - */ -/* -#include -#include -#include "share.h" - -#define DI 01 -#define CLK 02 -#define CS 04 -#define OUT0 01 -#define D3 01 -#define D4 02 - -typedef struct -{ - uint8 state; - uint8 cmd; - uint8 addr; - uint8 iswritable; - uint16 acc; - uint16 data[128]; -} EEPROM; - -EEPROM serialROM[2]; -uint8 oldCLK, bankFlip, DIFlip, OUT0state; - -uint8 serialROMautomat(uint8 chip, uint16 data) -{ - uint8 resp = 1; - chip &= 1; - if(!(data & CS)) - { - if(!(data & CLK)) - { - uint8 state = serialROM[chip].state; - uint8 mask, i; - switch (serialROM[chip].cmd) - { - case 0x00: - mask = ~(1<<(state&7)); - if(state<8) - { - serialROM[chip].addr &= mask; - serialROM[chip].addr |= ((data&1)<<(state&7)); - } - else if(state<15) - { - serialROM[chip].acc &= mask; - serialROM[chip].acc |= ((data&1)<<(state&7)); - } - else - { - serialROM[chip].acc &= mask; - serialROM[chip].acc |= ((data&1)<<(state&7)); - serialROM[chip].cmd = serialROM[chip].acc; - } - break; - case 0x01: - if(state<30) - resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; - else - { - resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; - serialROM[chip].cmd = 0; - } - break; - case 0x06: - mask = ~(1<<(state&15)); - if(state<30) - { - serialROM[chip].acc &= mask; - serialROM[chip].acc |= ((data&1)<<(state&15)); - } - else - { - serialROM[chip].acc &= mask; - serialROM[chip].acc |= ((data&1)<<(state&15)); - if(serialROM[chip].iswritable) - serialROM[chip].data[serialROM[chip].addr] = serialROM[chip].acc; - serialROM[chip].cmd = 0; - } - break; - case 0x0C: - for(i=0;i<128;i++) - serialROM[chip].data[i] = 0xFFFF; - serialROM[chip].cmd = 0; - resp = 1; - break; - case 0x0D: - serialROM[chip].cmd = 0; - resp = 1; - break; - case 0x09: - serialROM[chip].cmd = 0; - serialROM[chip].iswritable = 1; - break; - case 0x0B: - serialROM[chip].cmd = 0; - serialROM[chip].iswritable = 0; - break; - default: - serialROM[chip].cmd = 0; - serialROM[chip].state = 0; - break; - } - } - else - { - if(serialROM[chip].cmd == 0) - { - if(serialROM[chip].state>15) - serialROM[chip].state = 0; - } - else - serialROM[chip].cmd++; - } - } - else - { - serialROM[chip].cmd = 0; - serialROM[chip].state = 0; - } - return resp; -} - -uint8 serialROMstate(uint8 linestate) -{ - uint8 answ = 0, newCLK = linestate & CLK; - if((!oldCLK)&&newCLK) - { - DIFlip^=1; - if(linestate&&OUT0) - { - serialROMautomat(bankFlip, 04+DIFlip); - bankFlip^=1; - serialROMautomat(bankFlip, 02+DIFlip); - } - } - answ = DIFlip^1; - answ |= (serialROMautomat(bankFlip, newCLK+DIFlip)<<1); - oldCLK = newCLK; - return answ; -} - -static uint8 FP_FASTAPASS(2) BBRead(int w, uint8 ret) -{ - if(w) - { - serialROMstate(OUT0); - ret |= serialROMstate(OUT0|CLK); - } - return(ret); -} - -static void FP_FASTAPASS(1) BBWrite(uint8 V) -{ - OUT0state = V; - serialROMstate(OUT0state?OUT0:0); -} - -static INPUTCFC BattleBox={BBRead,BBWrite,0,0,0,0}; - -INPUTCFC *FCEU_InitBattleBox(void) -{ - oldCLK = 1; - bankFlip = 0; - DIFlip = 0; - serialROM[0].iswritable = 1; - serialROMautomat(0, 4); - serialROM[1].iswritable = 1; - serialROMautomat(1, 4); - serialROMautomat(bankFlip, 02+DIFlip); - return(&BattleBox); -} - -*/ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 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 + */ +/* +#include +#include +#include "share.h" + +#define DI 01 +#define CLK 02 +#define CS 04 +#define OUT0 01 +#define D3 01 +#define D4 02 + +typedef struct +{ + uint8 state; + uint8 cmd; + uint8 addr; + uint8 iswritable; + uint16 acc; + uint16 data[128]; +} EEPROM; + +EEPROM serialROM[2]; +uint8 oldCLK, bankFlip, DIFlip, OUT0state; + +uint8 serialROMautomat(uint8 chip, uint16 data) +{ + uint8 resp = 1; + chip &= 1; + if(!(data & CS)) + { + if(!(data & CLK)) + { + uint8 state = serialROM[chip].state; + uint8 mask, i; + switch (serialROM[chip].cmd) + { + case 0x00: + mask = ~(1<<(state&7)); + if(state<8) + { + serialROM[chip].addr &= mask; + serialROM[chip].addr |= ((data&1)<<(state&7)); + } + else if(state<15) + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&7)); + } + else + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&7)); + serialROM[chip].cmd = serialROM[chip].acc; + } + break; + case 0x01: + if(state<30) + resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; + else + { + resp = (serialROM[chip].data[serialROM[chip].addr]>>(state&15))&1; + serialROM[chip].cmd = 0; + } + break; + case 0x06: + mask = ~(1<<(state&15)); + if(state<30) + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&15)); + } + else + { + serialROM[chip].acc &= mask; + serialROM[chip].acc |= ((data&1)<<(state&15)); + if(serialROM[chip].iswritable) + serialROM[chip].data[serialROM[chip].addr] = serialROM[chip].acc; + serialROM[chip].cmd = 0; + } + break; + case 0x0C: + for(i=0;i<128;i++) + serialROM[chip].data[i] = 0xFFFF; + serialROM[chip].cmd = 0; + resp = 1; + break; + case 0x0D: + serialROM[chip].cmd = 0; + resp = 1; + break; + case 0x09: + serialROM[chip].cmd = 0; + serialROM[chip].iswritable = 1; + break; + case 0x0B: + serialROM[chip].cmd = 0; + serialROM[chip].iswritable = 0; + break; + default: + serialROM[chip].cmd = 0; + serialROM[chip].state = 0; + break; + } + } + else + { + if(serialROM[chip].cmd == 0) + { + if(serialROM[chip].state>15) + serialROM[chip].state = 0; + } + else + serialROM[chip].cmd++; + } + } + else + { + serialROM[chip].cmd = 0; + serialROM[chip].state = 0; + } + return resp; +} + +uint8 serialROMstate(uint8 linestate) +{ + uint8 answ = 0, newCLK = linestate & CLK; + if((!oldCLK)&&newCLK) + { + DIFlip^=1; + if(linestate&&OUT0) + { + serialROMautomat(bankFlip, 04+DIFlip); + bankFlip^=1; + serialROMautomat(bankFlip, 02+DIFlip); + } + } + answ = DIFlip^1; + answ |= (serialROMautomat(bankFlip, newCLK+DIFlip)<<1); + oldCLK = newCLK; + return answ; +} + +static uint8 FP_FASTAPASS(2) BBRead(int w, uint8 ret) +{ + if(w) + { + serialROMstate(OUT0); + ret |= serialROMstate(OUT0|CLK); + } + return(ret); +} + +static void FP_FASTAPASS(1) BBWrite(uint8 V) +{ + OUT0state = V; + serialROMstate(OUT0state?OUT0:0); +} + +static INPUTCFC BattleBox={BBRead,BBWrite,0,0,0,0}; + +INPUTCFC *FCEU_InitBattleBox(void) +{ + oldCLK = 1; + bankFlip = 0; + DIFlip = 0; + serialROM[0].iswritable = 1; + serialROMautomat(0, 4); + serialROM[1].iswritable = 1; + serialROMautomat(1, 4); + serialROMautomat(bankFlip, 02+DIFlip); + return(&BattleBox); +} + +*/ diff --git a/src/input/fkb.h b/src/input/fkb.h index d635d9d..d290c79 100644 --- a/src/input/fkb.h +++ b/src/input/fkb.h @@ -1,72 +1,72 @@ -#define FKB_F1 0x01 -#define FKB_F2 0x02 -#define FKB_F3 0x03 -#define FKB_F4 0x04 -#define FKB_F5 0x05 -#define FKB_F6 0x06 -#define FKB_F7 0x07 -#define FKB_F8 0x08 -#define FKB_1 0x09 -#define FKB_2 0x0A -#define FKB_3 0x0B -#define FKB_4 0x0C -#define FKB_5 0x0D -#define FKB_6 0x0E -#define FKB_7 0x0F -#define FKB_8 0x10 -#define FKB_9 0x11 -#define FKB_0 0x12 -#define FKB_MINUS 0x13 -#define FKB_CARET 0x14 -#define FKB_BACKSLASH 0x15 -#define FKB_STOP 0x16 -#define FKB_ESCAPE 0x17 -#define FKB_Q 0x18 -#define FKB_W 0x19 -#define FKB_E 0x1A -#define FKB_R 0x1B -#define FKB_T 0x1C -#define FKB_Y 0x1D -#define FKB_U 0x1E -#define FKB_I 0x1F -#define FKB_O 0x20 -#define FKB_P 0x21 -#define FKB_AT 0x22 -#define FKB_BRACKETLEFT 0x23 -#define FKB_RETURN 0x24 -#define FKB_CONTROL 0x25 -#define FKB_A 0x26 -#define FKB_S 0x27 -#define FKB_D 0x28 -#define FKB_F 0x29 -#define FKB_G 0x2A -#define FKB_H 0x2B -#define FKB_J 0x2C -#define FKB_K 0x2D -#define FKB_L 0x2E -#define FKB_SEMICOLON 0x2F -#define FKB_COLON 0x30 -#define FKB_BRACKETRIGHT 0x31 -#define FKB_KANA 0x32 -#define FKB_LEFTSHIFT 0x33 -#define FKB_Z 0x34 -#define FKB_X 0x35 -#define FKB_C 0x36 -#define FKB_V 0x37 -#define FKB_B 0x38 -#define FKB_N 0x39 -#define FKB_M 0x3A -#define FKB_COMMA 0x3B -#define FKB_PERIOD 0x3C -#define FKB_SLASH 0x3D -#define FKB_UNDERSCORE 0x3E -#define FKB_RIGHTSHIFT 0x3F -#define FKB_GRAPH 0x40 -#define FKB_SPACE 0x41 -#define FKB_CLEAR 0x42 -#define FKB_INSERT 0x43 -#define FKB_DELETE 0x44 -#define FKB_UP 0x45 -#define FKB_LEFT 0x46 -#define FKB_RIGHT 0x47 -#define FKB_DOWN 0x48 +#define FKB_F1 0x01 +#define FKB_F2 0x02 +#define FKB_F3 0x03 +#define FKB_F4 0x04 +#define FKB_F5 0x05 +#define FKB_F6 0x06 +#define FKB_F7 0x07 +#define FKB_F8 0x08 +#define FKB_1 0x09 +#define FKB_2 0x0A +#define FKB_3 0x0B +#define FKB_4 0x0C +#define FKB_5 0x0D +#define FKB_6 0x0E +#define FKB_7 0x0F +#define FKB_8 0x10 +#define FKB_9 0x11 +#define FKB_0 0x12 +#define FKB_MINUS 0x13 +#define FKB_CARET 0x14 +#define FKB_BACKSLASH 0x15 +#define FKB_STOP 0x16 +#define FKB_ESCAPE 0x17 +#define FKB_Q 0x18 +#define FKB_W 0x19 +#define FKB_E 0x1A +#define FKB_R 0x1B +#define FKB_T 0x1C +#define FKB_Y 0x1D +#define FKB_U 0x1E +#define FKB_I 0x1F +#define FKB_O 0x20 +#define FKB_P 0x21 +#define FKB_AT 0x22 +#define FKB_BRACKETLEFT 0x23 +#define FKB_RETURN 0x24 +#define FKB_CONTROL 0x25 +#define FKB_A 0x26 +#define FKB_S 0x27 +#define FKB_D 0x28 +#define FKB_F 0x29 +#define FKB_G 0x2A +#define FKB_H 0x2B +#define FKB_J 0x2C +#define FKB_K 0x2D +#define FKB_L 0x2E +#define FKB_SEMICOLON 0x2F +#define FKB_COLON 0x30 +#define FKB_BRACKETRIGHT 0x31 +#define FKB_KANA 0x32 +#define FKB_LEFTSHIFT 0x33 +#define FKB_Z 0x34 +#define FKB_X 0x35 +#define FKB_C 0x36 +#define FKB_V 0x37 +#define FKB_B 0x38 +#define FKB_N 0x39 +#define FKB_M 0x3A +#define FKB_COMMA 0x3B +#define FKB_PERIOD 0x3C +#define FKB_SLASH 0x3D +#define FKB_UNDERSCORE 0x3E +#define FKB_RIGHTSHIFT 0x3F +#define FKB_GRAPH 0x40 +#define FKB_SPACE 0x41 +#define FKB_CLEAR 0x42 +#define FKB_INSERT 0x43 +#define FKB_DELETE 0x44 +#define FKB_UP 0x45 +#define FKB_LEFT 0x46 +#define FKB_RIGHT 0x47 +#define FKB_DOWN 0x48 diff --git a/src/input/mouse.c b/src/input/mouse.c index 6f7cd83..28f2e64 100644 --- a/src/input/mouse.c +++ b/src/input/mouse.c @@ -1,86 +1,86 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel - * - * 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 -#include -#include "share.h" - -typedef struct { - int32 mzx, mzy, mzxold, mzyold; - uint32 readbit; - uint32 data; -} MOUSE; - -static MOUSE Mouse; - -static void FP_FASTAPASS(1) StrobeMOUSE(int w) { - Mouse.readbit = 0; - if ((Mouse.mzxold - Mouse.mzx) > 0) - Mouse.data |= 0x0C; - else if ((Mouse.mzxold - Mouse.mzx) < 0) - Mouse.data |= 0x04; - if ((Mouse.mzyold - Mouse.mzy) > 0) - Mouse.data |= 0x30; - else if ((Mouse.mzyold - Mouse.mzy) < 0) - Mouse.data |= 0x10; -} - -static uint8 FP_FASTAPASS(1) ReadMOUSE(int w) { - uint8 ret = 0; - if (Mouse.readbit >= 8) - ret |= 1; - else { - ret |= (Mouse.data >> Mouse.readbit) & 1; - #ifdef FCEUDEF_DEBUGGER - if (!fceuindbg) - #endif - Mouse.readbit++; - } - return(ret); -} - -static void FP_FASTAPASS(3) UpdateMOUSE(int w, void *data, int arg) { - uint32 *ptr = (uint32*)data; - Mouse.data = 0; - Mouse.mzxold = Mouse.mzx; - Mouse.mzyold = Mouse.mzy; - Mouse.mzx = ptr[0]; - Mouse.mzy = ptr[1]; - Mouse.data |= ptr[2]; - if ((Mouse.mzxold - Mouse.mzx) > 0) - Mouse.data |= 0x0C; - else if ((Mouse.mzxold - Mouse.mzx) < 0) - Mouse.data |= 0x04; - if ((Mouse.mzyold - Mouse.mzy) > 0) - Mouse.data |= 0x30; - else if ((Mouse.mzyold - Mouse.mzy) < 0) - Mouse.data |= 0x10; -} - -static INPUTC MOUSEC = { ReadMOUSE, 0, StrobeMOUSE, UpdateMOUSE, 0, 0 }; - -INPUTC *FCEU_InitMouse(int w) { - Mouse.mzx = 0; - Mouse.mzy = 0; - Mouse.mzxold = 0; - Mouse.mzyold = 0; - Mouse.data = 0; - return(&MOUSEC); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 +#include +#include "share.h" + +typedef struct { + int32 mzx, mzy, mzxold, mzyold; + uint32 readbit; + uint32 data; +} MOUSE; + +static MOUSE Mouse; + +static void FP_FASTAPASS(1) StrobeMOUSE(int w) { + Mouse.readbit = 0; + if ((Mouse.mzxold - Mouse.mzx) > 0) + Mouse.data |= 0x0C; + else if ((Mouse.mzxold - Mouse.mzx) < 0) + Mouse.data |= 0x04; + if ((Mouse.mzyold - Mouse.mzy) > 0) + Mouse.data |= 0x30; + else if ((Mouse.mzyold - Mouse.mzy) < 0) + Mouse.data |= 0x10; +} + +static uint8 FP_FASTAPASS(1) ReadMOUSE(int w) { + uint8 ret = 0; + if (Mouse.readbit >= 8) + ret |= 1; + else { + ret |= (Mouse.data >> Mouse.readbit) & 1; + #ifdef FCEUDEF_DEBUGGER + if (!fceuindbg) + #endif + Mouse.readbit++; + } + return(ret); +} + +static void FP_FASTAPASS(3) UpdateMOUSE(int w, void *data, int arg) { + uint32 *ptr = (uint32*)data; + Mouse.data = 0; + Mouse.mzxold = Mouse.mzx; + Mouse.mzyold = Mouse.mzy; + Mouse.mzx = ptr[0]; + Mouse.mzy = ptr[1]; + Mouse.data |= ptr[2]; + if ((Mouse.mzxold - Mouse.mzx) > 0) + Mouse.data |= 0x0C; + else if ((Mouse.mzxold - Mouse.mzx) < 0) + Mouse.data |= 0x04; + if ((Mouse.mzyold - Mouse.mzy) > 0) + Mouse.data |= 0x30; + else if ((Mouse.mzyold - Mouse.mzy) < 0) + Mouse.data |= 0x10; +} + +static INPUTC MOUSEC = { ReadMOUSE, 0, StrobeMOUSE, UpdateMOUSE, 0, 0 }; + +INPUTC *FCEU_InitMouse(int w) { + Mouse.mzx = 0; + Mouse.mzy = 0; + Mouse.mzxold = 0; + Mouse.mzyold = 0; + Mouse.data = 0; + return(&MOUSEC); +} diff --git a/src/input/pec586kb.c b/src/input/pec586kb.c index 938bc3e..3ab947e 100644 --- a/src/input/pec586kb.c +++ b/src/input/pec586kb.c @@ -1,97 +1,97 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel - * - * 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 -#include "share.h" -#include "suborkb.h" - -#define AK(x) FKB_ ## x - -static uint8 bufit[0x66]; -static uint8 kspos, kstrobe; -static uint8 ksindex; - -/* TODO: check all keys, some of the are wrong */ - -static uint16 matrix[13][8] = -{ - { AK(ESCAPE),AK(SPACE),AK(LMENU),AK(LCONTROL),AK(LSHIFT),AK(GRAVE),AK(TAB),AK(CAPITAL) }, - { AK(F6),AK(F7),AK(F5),AK(F4),AK(F8),AK(F2),AK(F1),AK(F3) }, - { AK(EQUALS), AK(NUMPAD0),AK(PERIOD),AK(A),AK(RETURN),AK(1),AK(Q),AK(Z) }, - { 0, AK(NUMPAD3),AK(NUMPAD6),AK(S),AK(NUMPAD9),AK(2),AK(W),AK(X) }, - { AK(SLASH), AK(NUMPAD2),AK(NUMPAD5),AK(D),AK(NUMPAD8),AK(3),AK(E),AK(C) }, - { AK(BREAK), AK(NUMPAD1),AK(NUMPAD4),AK(F),AK(NUMPAD7),AK(4),AK(R),AK(V) }, - { AK(BACK),AK(BACKSLASH),AK(GRETURN),AK(G),AK(RBRACKET),AK(5),AK(T),AK(B) }, - { AK(9),AK(PERIOD),AK(L),AK(K),AK(O),AK(8),AK(I),AK(COMMA) }, - { AK(0),AK(SLASH),AK(SEMICOLON),AK(J),AK(P),AK(7),AK(U),AK(M) }, - { AK(MINUS),AK(MINUS),AK(APOSTROPHE),AK(H),AK(LBRACKET),AK(6),AK(Y),AK(N) }, - { AK(F11),AK(F12),AK(F10),0,AK(MINUS),AK(F9),0,0 }, - { AK(UP),AK(RIGHT),AK(DOWN),AK(DIVIDE),AK(LEFT),AK(MULTIPLY),AK(SUBTRACT),AK(ADD) }, - { AK(INSERT),AK(NUMPAD1),AK(HOME),AK(PRIOR),AK(DELETE),AK(END),AK(NEXT),AK(NUMLOCK) }, -}; - -static void FP_FASTAPASS(1) PEC586KB_Write(uint8 v) { - if (!(kstrobe & 2) && (v & 2)) { - kspos = 0; - } - if ((kstrobe & 1) && !(v & 1)) { - ksindex = 0; - } - if ((kstrobe & 4) && !(v & 4)) { - kspos++; - kspos %= 13; - } - kstrobe = v; -} - -static uint8 FP_FASTAPASS(2) PEC586KB_Read(int w, uint8 ret) { -#ifdef FCEUDEF_DEBUGGER - if (!fceuindbg) { -#endif - if (w) { - ret &= ~2; - if(bufit[matrix[kspos][7-ksindex]]) - ret |= 2; - ksindex++; - ksindex&=7; - } -#ifdef FCEUDEF_DEBUGGER - } -#endif - return(ret); -} - -static void PEC586KB_Strobe(void) { -/* kstrobe = 0; - ksindex = 0; -*/ -} - -static void FP_FASTAPASS(2) PEC586KB_Update(void *data, int arg) { - memcpy(bufit + 1, data, sizeof(bufit) - 1); -} - -static INPUTCFC PEC586KB = { PEC586KB_Read, PEC586KB_Write, PEC586KB_Strobe, PEC586KB_Update, 0, 0 }; - -INPUTCFC *FCEU_InitPEC586KB(void) { - memset(bufit, 0, sizeof(bufit)); - kspos = ksindex = kstrobe = 0; - return(&PEC586KB); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * 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 +#include "share.h" +#include "suborkb.h" + +#define AK(x) FKB_ ## x + +static uint8 bufit[0x66]; +static uint8 kspos, kstrobe; +static uint8 ksindex; + +/* TODO: check all keys, some of the are wrong */ + +static uint16 matrix[13][8] = +{ + { AK(ESCAPE),AK(SPACE),AK(LMENU),AK(LCONTROL),AK(LSHIFT),AK(GRAVE),AK(TAB),AK(CAPITAL) }, + { AK(F6),AK(F7),AK(F5),AK(F4),AK(F8),AK(F2),AK(F1),AK(F3) }, + { AK(EQUALS), AK(NUMPAD0),AK(PERIOD),AK(A),AK(RETURN),AK(1),AK(Q),AK(Z) }, + { 0, AK(NUMPAD3),AK(NUMPAD6),AK(S),AK(NUMPAD9),AK(2),AK(W),AK(X) }, + { AK(SLASH), AK(NUMPAD2),AK(NUMPAD5),AK(D),AK(NUMPAD8),AK(3),AK(E),AK(C) }, + { AK(BREAK), AK(NUMPAD1),AK(NUMPAD4),AK(F),AK(NUMPAD7),AK(4),AK(R),AK(V) }, + { AK(BACK),AK(BACKSLASH),AK(GRETURN),AK(G),AK(RBRACKET),AK(5),AK(T),AK(B) }, + { AK(9),AK(PERIOD),AK(L),AK(K),AK(O),AK(8),AK(I),AK(COMMA) }, + { AK(0),AK(SLASH),AK(SEMICOLON),AK(J),AK(P),AK(7),AK(U),AK(M) }, + { AK(MINUS),AK(MINUS),AK(APOSTROPHE),AK(H),AK(LBRACKET),AK(6),AK(Y),AK(N) }, + { AK(F11),AK(F12),AK(F10),0,AK(MINUS),AK(F9),0,0 }, + { AK(UP),AK(RIGHT),AK(DOWN),AK(DIVIDE),AK(LEFT),AK(MULTIPLY),AK(SUBTRACT),AK(ADD) }, + { AK(INSERT),AK(NUMPAD1),AK(HOME),AK(PRIOR),AK(DELETE),AK(END),AK(NEXT),AK(NUMLOCK) }, +}; + +static void FP_FASTAPASS(1) PEC586KB_Write(uint8 v) { + if (!(kstrobe & 2) && (v & 2)) { + kspos = 0; + } + if ((kstrobe & 1) && !(v & 1)) { + ksindex = 0; + } + if ((kstrobe & 4) && !(v & 4)) { + kspos++; + kspos %= 13; + } + kstrobe = v; +} + +static uint8 FP_FASTAPASS(2) PEC586KB_Read(int w, uint8 ret) { +#ifdef FCEUDEF_DEBUGGER + if (!fceuindbg) { +#endif + if (w) { + ret &= ~2; + if(bufit[matrix[kspos][7-ksindex]]) + ret |= 2; + ksindex++; + ksindex&=7; + } +#ifdef FCEUDEF_DEBUGGER + } +#endif + return(ret); +} + +static void PEC586KB_Strobe(void) { +/* kstrobe = 0; + ksindex = 0; +*/ +} + +static void FP_FASTAPASS(2) PEC586KB_Update(void *data, int arg) { + memcpy(bufit + 1, data, sizeof(bufit) - 1); +} + +static INPUTCFC PEC586KB = { PEC586KB_Read, PEC586KB_Write, PEC586KB_Strobe, PEC586KB_Update, 0, 0 }; + +INPUTCFC *FCEU_InitPEC586KB(void) { + memset(bufit, 0, sizeof(bufit)); + kspos = ksindex = kstrobe = 0; + return(&PEC586KB); +} diff --git a/src/misc.c b/src/misc.c index 4888983..d6f06e2 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1,20 +1,20 @@ -#include - -#include "fceu-types.h" -#include "fceu.h" - -#include "driver.h" - -/* wave.c */ - -void FCEU_WriteWaveData(int32 *Buffer, int Count) { } -int FCEUI_EndWaveRecord(void) { return 0; } -int FCEUI_BeginWaveRecord(char *fn) { return 0; } - -/* netplay.c */ -int FCEUNET_SendFile(uint8 cmd, char *fn) { return 0; } - -/* movie.c */ -void FCEUMOV_AddJoy(uint8 *js) { } -void FCEUMOV_Stop(void) {} -void FCEUI_SelectMovie(int w) { } +#include + +#include "fceu-types.h" +#include "fceu.h" + +#include "driver.h" + +/* wave.c */ + +void FCEU_WriteWaveData(int32 *Buffer, int Count) { } +int FCEUI_EndWaveRecord(void) { return 0; } +int FCEUI_BeginWaveRecord(char *fn) { return 0; } + +/* netplay.c */ +int FCEUNET_SendFile(uint8 cmd, char *fn) { return 0; } + +/* movie.c */ +void FCEUMOV_AddJoy(uint8 *js) { } +void FCEUMOV_Stop(void) {} +void FCEUI_SelectMovie(int w) { } diff --git a/src/ppuview.h b/src/ppuview.h index e905060..740a183 100644 --- a/src/ppuview.h +++ b/src/ppuview.h @@ -1,13 +1,13 @@ -#ifndef _FCEU_PPUVIEW_H -#define _FCEU_PPUVIEW_H - -extern int PPUViewScanline; -extern int PPUViewer; -extern int scanline; - -void PPUViewDoBlit(); -void DoPPUView(); -void UpdatePPUView(int refreshchr); - - -#endif +#ifndef _FCEU_PPUVIEW_H +#define _FCEU_PPUVIEW_H + +extern int PPUViewScanline; +extern int PPUViewer; +extern int scanline; + +void PPUViewDoBlit(); +void DoPPUView(); +void UpdatePPUView(int refreshchr); + + +#endif