From 386f5371eb984fb9c2860c83e740890a75cd45c1 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 30 Sep 2012 02:11:57 +0300 Subject: [PATCH] merge mapper code from FCEUX seems to be work by CaH4e3 and others --- boards/01-222.c | 103 ++ boards/103.c | 125 ++ boards/106.c | 119 ++ boards/{bmcgk192.c => 108.c} | 129 +- boards/112.c | 22 +- boards/116.c | 359 ++++ boards/117.c | 9 +- boards/120.c | 66 + boards/121.c | 91 + boards/15.c | 120 ++ boards/164.c | 64 +- boards/175.c | 88 + boards/176.c | 158 ++ boards/177.c | 87 + boards/178.c | 101 ++ boards/179.c | 94 + boards/183.c | 234 +-- boards/185.c | 231 ++- boards/186.c | 208 +-- boards/187.c | 207 ++- boards/189.c | 96 +- boards/199.c | 97 ++ boards/208.c | 166 +- boards/222.c | 205 +-- boards/23.c | 208 +++ boards/235.c | 140 +- boards/253.c | 175 ++ boards/3d-block.c | 110 ++ boards/411120-c.c | 70 + boards/43.c | 94 + boards/57.c | 185 +- boards/{cc21.c => 603-5052.c} | 104 +- boards/68.c | 178 ++ boards/8157.c | 161 +- boards/8237.c | 288 +++- boards/830118C.c | 82 + boards/88.c | 2 +- boards/90.c | 133 +- boards/95.c | 5 +- boards/Makefile | 45 +- boards/__dummy_mapper.c | 200 +-- boards/{sonic5.c => a9711.c} | 151 +- boards/a9746.c | 186 ++ boards/addrlatch.c | 172 ++ boards/ax5705.c | 122 ++ boards/bandai.c | 176 ++ boards/bmc13in1jy110.c | 206 +-- boards/bmc42in1r.c | 163 +- boards/bmc64in1nr.c | 186 +- boards/bmc70in1.c | 246 +-- boards/bonza.c | 271 ++- boards/bs-5.c | 91 + boards/datalatch.c | 232 ++- boards/deirom.c | 4 +- boards/dream.c | 112 +- boards/edu2000.c | 84 + boards/fk23c.c | 402 +++-- boards/ghostbusters63in1.c | 106 ++ boards/gs-2004.c | 69 + boards/gs-2013.c | 69 + boards/h2288.c | 178 +- boards/karaoke.c | 2 +- boards/kof97.c | 100 +- boards/konami-qtai.c | 374 ++-- boards/ks7032.c | 94 + boards/malee.c | 7 +- boards/mapinc.h | 7 +- boards/mmc1.c | 874 +++++----- boards/mmc3.c | 3030 +++++++++++++++------------------ boards/mmc3.h | 48 +- boards/mmc5.c | 1747 ++++++++++--------- boards/n-c22m.c | 103 ++ boards/n106.c | 33 +- boards/n625092.c | 97 ++ boards/novel.c | 2 +- boards/onebus.c | 308 ++++ boards/sachen.c | 92 +- boards/sc-127.c | 125 ++ boards/sheroes.c | 174 +- boards/sl1632.c | 283 ++- boards/smb2j.c | 96 ++ boards/subor.c | 158 +- boards/super24.c | 5 +- boards/supervision.c | 2 +- boards/t-227-1.c | 116 ++ boards/t-262.c | 167 +- boards/tengen.c | 26 +- boards/tf-1201.c | 124 ++ driver.h | 3 + fce.c | 14 +- fce.h | 7 +- file.h | 1 + git.h | 1 + ines-correct.h | 90 +- ines.c | 2000 +++++++++++++--------- ines.h | 174 +- mappers/113.c | 64 - mappers/15.c | 73 - mappers/151.c | 2 +- mappers/156.c | 126 ++ mappers/16.c | 36 +- mappers/17.c | 4 +- mappers/18.c | 4 +- mappers/180.c | 14 - mappers/183.c | 0 mappers/184.c | 15 - mappers/200.c | 36 - mappers/201.c | 6 +- mappers/202.c | 2 +- mappers/203.c | 2 +- mappers/204.c | 76 +- mappers/21.c | 4 +- mappers/212.c | 46 +- mappers/213.c | 28 +- mappers/214.c | 34 +- mappers/217.c | 1 - mappers/22.c | 3 +- mappers/225.c | 4 +- mappers/226.c | 105 -- mappers/227.c | 67 +- mappers/228.c | 57 +- mappers/229.c | 2 +- mappers/23.c | 103 -- mappers/230.c | 2 +- mappers/231.c | 2 +- mappers/232.c | 2 +- mappers/234.c | 2 +- mappers/240.c | 39 - mappers/242.c | 6 +- mappers/244.c | 2 +- mappers/246.c | 2 +- mappers/24and26.c | 18 +- mappers/25.c | 24 +- mappers/255.c | 2 +- mappers/27.c | 143 +- mappers/32.c | 2 +- mappers/33.c | 5 +- mappers/40.c | 4 +- mappers/41.c | 2 +- mappers/42.c | 4 +- mappers/43.c | 76 - mappers/46.c | 2 +- mappers/50.c | 4 +- mappers/51.c | 2 +- mappers/59.c | 2 +- mappers/6.c | 4 +- mappers/60.c | 6 +- mappers/61.c | 2 +- mappers/62.c | 2 +- mappers/65.c | 4 +- mappers/67.c | 4 +- mappers/68.c | 105 -- mappers/69.c | 29 +- mappers/71.c | 2 +- mappers/72.c | 2 +- mappers/73.c | 4 +- mappers/75.c | 2 +- mappers/76.c | 2 +- mappers/77.c | 2 +- mappers/79.c | 3 +- mappers/8.c | 2 +- mappers/80.c | 7 +- mappers/82.c | 2 +- mappers/83.c | 50 +- mappers/85.c | 10 +- mappers/86.c | 2 +- mappers/89.c | 2 +- mappers/91.c | 2 +- mappers/92.c | 2 +- mappers/97.c | 2 +- mappers/99.c | 2 +- mappers/Makefile | 22 +- mappers/mmc2and4.c | 4 +- mappers/simple.c | 22 +- svga.h | 1 + types.h | 4 + unif.c | 903 +++++----- unif.h | 37 +- 178 files changed, 13494 insertions(+), 8085 deletions(-) create mode 100644 boards/01-222.c create mode 100644 boards/103.c create mode 100644 boards/106.c rename boards/{bmcgk192.c => 108.c} (57%) create mode 100644 boards/116.c create mode 100644 boards/120.c create mode 100644 boards/121.c create mode 100644 boards/15.c create mode 100644 boards/175.c create mode 100644 boards/176.c create mode 100644 boards/177.c create mode 100644 boards/178.c create mode 100644 boards/179.c create mode 100644 boards/199.c create mode 100644 boards/23.c create mode 100644 boards/253.c create mode 100644 boards/3d-block.c create mode 100644 boards/411120-c.c create mode 100644 boards/43.c rename boards/{cc21.c => 603-5052.c} (54%) create mode 100644 boards/68.c create mode 100644 boards/830118C.c rename boards/{sonic5.c => a9711.c} (51%) create mode 100644 boards/a9746.c create mode 100644 boards/addrlatch.c create mode 100644 boards/ax5705.c create mode 100644 boards/bandai.c create mode 100644 boards/bs-5.c create mode 100644 boards/edu2000.c create mode 100644 boards/ghostbusters63in1.c create mode 100644 boards/gs-2004.c create mode 100644 boards/gs-2013.c create mode 100644 boards/ks7032.c create mode 100644 boards/n-c22m.c create mode 100644 boards/n625092.c create mode 100644 boards/onebus.c create mode 100644 boards/sc-127.c create mode 100644 boards/smb2j.c create mode 100644 boards/t-227-1.c create mode 100644 boards/tf-1201.c delete mode 100644 mappers/113.c delete mode 100644 mappers/15.c create mode 100644 mappers/156.c delete mode 100644 mappers/180.c delete mode 100644 mappers/183.c delete mode 100644 mappers/184.c delete mode 100644 mappers/200.c delete mode 100644 mappers/226.c delete mode 100644 mappers/23.c delete mode 100644 mappers/240.c delete mode 100644 mappers/43.c delete mode 100644 mappers/68.c diff --git a/boards/01-222.c b/boards/01-222.c new file mode 100644 index 0000000..c0e7320 --- /dev/null +++ b/boards/01-222.c @@ -0,0 +1,103 @@ +/* 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 + */ + +#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(reg[3]) +// return reg[2]; +// else +// return X.DB; +} + +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/boards/103.c b/boards/103.c new file mode 100644 index 0000000..e25f5fc --- /dev/null +++ b/boards/103.c @@ -0,0 +1,125 @@ +/* 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 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/boards/106.c b/boards/106.c new file mode 100644 index 0000000..638dda9 --- /dev/null +++ b/boards/106.c @@ -0,0 +1,119 @@ +/* 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, "IRQCOUNT"}, + {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 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/boards/bmcgk192.c b/boards/108.c similarity index 57% rename from boards/bmcgk192.c rename to boards/108.c index b66d831..fc3aebd 100644 --- a/boards/bmcgk192.c +++ b/boards/108.c @@ -1,67 +1,62 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint16 addrlatche; - -static void Sync(void) -{ - if(addrlatche&0x40) - { - setprg16(0x8000,addrlatche&7); - setprg16(0xC000,addrlatche&7); - } - else - setprg32(0x8000,(addrlatche>>1)&3); - setchr8((addrlatche>>3)&7); - setmirror(((addrlatche&0x80)>>7)^1); -} - -static DECLFW(BMCGK192Write) -{ - addrlatche=A; - Sync(); -} - -static void BMCGK192Reset(void) -{ - setprg32(0x8000,0); -} - -static void BMCGK192Power(void) -{ - setprg32(0x8000,0); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xffff,BMCGK192Write); -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper58_Init(CartInfo *info) -{ - info->Power=BMCGK192Power; - info->Reset=BMCGK192Reset; - GameStateRestore=StateRestore; - AddExState(&addrlatche, 2, 0, "ALATC"); -} +/* 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 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(0x8FFF,0x8FFF,M108Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper108_Init(CartInfo *info) +{ + info->Power=M108Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/112.c b/boards/112.c index 2bb1e4b..ccfd4f4 100644 --- a/boards/112.c +++ b/boards/112.c @@ -15,19 +15,21 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * NTDEC, ASDER games */ #include "mapinc.h" static uint8 reg[8]; -static uint8 mirror, cmd; +static uint8 mirror, cmd, bank; static uint8 *WRAM=NULL; static SFORMAT StateRegs[]= { {&cmd, 1, "CMD"}, {&mirror, 1, "MIRR"}, + {&bank, 1, "BANK"}, {reg, 8, "REGS"}, {0} }; @@ -37,12 +39,12 @@ static void Sync(void) setmirror(mirror^1); setprg8(0x8000,reg[0]); setprg8(0xA000,reg[1]); - setchr2(0x0000,reg[2]>>1); - setchr2(0x0800,reg[3]>>1); - setchr1(0x1000,reg[4]); - setchr1(0x1400,reg[5]); - setchr1(0x1800,reg[6]); - setchr1(0x1C00,reg[7]); + setchr2(0x0000,(reg[2]>>1)); + setchr2(0x0800,(reg[3]>>1)); + setchr1(0x1000,((bank&0x10)<<4)|reg[4]); + setchr1(0x1400,((bank&0x20)<<3)|reg[5]); + setchr1(0x1800,((bank&0x40)<<2)|reg[6]); + setchr1(0x1C00,((bank&0x80)<<1)|reg[7]); } static DECLFW(M112Write) @@ -52,8 +54,8 @@ static DECLFW(M112Write) case 0xe000: mirror=V&1; Sync(); ;break; case 0x8000: cmd=V&7; break; case 0xa000: reg[cmd]=V; Sync(); break; + case 0xc000: bank=V; Sync(); break; } -FCEU_printf("%04x:%04x %d\n",A,V,scanline); } static void M112Close(void) @@ -65,10 +67,12 @@ static void M112Close(void) static void M112Power(void) { + bank=0; setprg16(0xC000,~0); setprg8r(0x10,0x6000,0); SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x8000,0xFFFF,M112Write); + SetWriteHandler(0x4020,0x5FFF,M112Write); SetReadHandler(0x6000,0x7FFF,CartBR); SetWriteHandler(0x6000,0x7FFF,CartBW); } diff --git a/boards/116.c b/boards/116.c new file mode 100644 index 0000000..3a21668 --- /dev/null +++ b/boards/116.c @@ -0,0 +1,359 @@ +/* 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 () + * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms) + * Contra Fighter (603-5052 board, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) + * + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 mode; +static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr; +static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr; +extern uint8 IRQCount,IRQLatch,IRQa; +extern uint8 IRQReload; +static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift; + +static SFORMAT StateRegs[]= +{ + {&mode, 1, "MODE"}, + {vrc2_chr, 8, "vrch"}, + {vrc2_prg, 2, "vrpr"}, + {&vrc2_mirr, 1, "vrmi"}, + {mmc3_regs, 10, "m3re"}, + {&mmc3_ctrl, 1, "m3ct"}, + {&mmc3_mirr, 1, "m3mi"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {mmc1_regs, 4, "m1r"}, + {&mmc1_buffer, 1, "m1bf"}, + {&mmc1_shift, 1, "m1mi"}, + {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) +{ + 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) +{ + printf("%04X:%02X\n",A,V); + if(A==0xA123) + { + int zzz=9; + } + 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)<> 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); +} + +void Mapper116_Init(CartInfo *info) +{ + UNLSL12_Init(info); +} diff --git a/boards/117.c b/boards/117.c index 6746015..b2348f0 100644 --- a/boards/117.c +++ b/boards/117.c @@ -15,12 +15,12 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -static uint8 prgreg[4], chrreg[8]; +static uint8 prgreg[4], chrreg[8], mirror; static uint8 IRQa, IRQCount, IRQLatch; static SFORMAT StateRegs[]= @@ -30,18 +30,20 @@ static SFORMAT StateRegs[]= {&IRQLatch, 1, "IRQL"}, {prgreg, 4, "PREGS"}, {chrreg, 8, "CREGS"}, + {&mirror, 1, "MREG"}, {0} }; static void Sync(void) { + int i; setprg8(0x8000,prgreg[0]); setprg8(0xa000,prgreg[1]); setprg8(0xc000,prgreg[2]); setprg8(0xe000,prgreg[3]); - int i; for(i=0; i<8; i++) setchr1(i<<10,chrreg[i]); + setmirror(mirror^1); } static DECLFW(M117Write) @@ -62,6 +64,7 @@ static DECLFW(M117Write) case 0xc003: IRQCount=IRQLatch; IRQa|=2; break; case 0xe000: IRQa&=~1; IRQa|=V&1; X6502_IRQEnd(FCEU_IQEXT); break; case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break; + case 0xd000: mirror=V&1; } } diff --git a/boards/120.c b/boards/120.c new file mode 100644 index 0000000..ed681b9 --- /dev/null +++ b/boards/120.c @@ -0,0 +1,66 @@ +/* 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 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,0x7FFF,CartBR); + SetReadHandler(0x8000,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/boards/121.c b/boards/121.c new file mode 100644 index 0000000..63784f9 --- /dev/null +++ b/boards/121.c @@ -0,0 +1,91 @@ +/* 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 board, MAPPER 187 the same! + * UNL6035052_Init seems to be the same too, but with prot array in reverse + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 readbyte = 0; + +static DECLFW(M121Write) +{ +// FCEU_printf("write: %04x:%04x\n",A&0xE003,V); + if((A&0xF003)==0x8003) + { +// FCEU_printf(" prot write"); +// FCEU_printf("write: %04x:%04x\n",A,V); + if (V==0xAB) setprg8(0xE000,7); + else if(V==0x26) setprg8(0xE000,8); +// else if(V==0x26) setprg8(0xE000,1); // MK3 +// else if(V==0x26) setprg8(0xE000,0x15); // sonic 3D blast, 8003 - command (0x26), 8001 - data 0x2A (<<1 = 0x15) + else if(V==0xFF) setprg8(0xE000,9); + else if(V==0x28) setprg8(0xC000,0xC); + else if(V==0xEC) setprg8(0xE000,0xD); +// else if(V==0xEC) setprg8(0xE000,0xC);//MK3 + else if(V==0xEF) setprg8(0xE000,0xD); // damn mess, need real hardware to figure out bankswitching + else if(V==0x2A) setprg8(0xA000,0x0E); +// else if(V==0x2A) setprg8(0xE000,0x0C); // MK3 + else if(V==0x20) setprg8(0xE000,0x13); + else if(V==0x29) setprg8(0xE000,0x1B); + else + { +// FCEU_printf(" unknown"); + FixMMC3PRG(MMC3_cmd); + MMC3_CMDWrite(A,V); + } +// FCEU_printf("\n"); + } + else + { +// FixMMC3PRG(MMC3_cmd); + MMC3_CMDWrite(A,V); + } +} + +static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFW(M121LoWrite) +{ + EXPREGS[0] = prot_array[V&3]; // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter) +// FCEU_printf("write: %04x:%04x\n",A,V); +} + +static DECLFR(M121Read) +{ +// FCEU_printf("read: %04x\n",A); + return EXPREGS[0]; +} + +static void M121Power(void) +{ + GenMMC3Power(); +// Write_IRQFM(0x4017,0x40); + SetReadHandler(0x5000,0x5FFF,M121Read); + SetWriteHandler(0x5000,0x5FFF,M121LoWrite); + SetWriteHandler(0x8000,0x9FFF,M121Write); +} + +void Mapper121_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 8, 0); + info->Power=M121Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/boards/15.c b/boards/15.c new file mode 100644 index 0000000..6405afa --- /dev/null +++ b/boards/15.c @@ -0,0 +1,120 @@ +/* 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)) + i=0x7F; + setprg8(0x8000+(i<<13),(i&1)+((b<<1)^(latched>>7))); + } + break; + } +} + +static DECLFW(M15Write) +{ + latchea=A; + latched=V; + printf("%04X = %02X\n",A,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); + 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/boards/164.c b/boards/164.c index 0bb85b3..22589ec 100644 --- a/boards/164.c +++ b/boards/164.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel + * Copyright (C) 2002 Xodnizel 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 @@ -15,16 +15,18 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -static uint8 cmd; +static uint8 cmd, laststrobe, trigger; static uint8 DRegs[8]; static SFORMAT StateRegs[]= { {&cmd, 1, "CMD"}, + {&laststrobe, 1, "STB"}, + {&trigger, 1, "TRG"}, {DRegs, 8, "DREG"}, {0} }; @@ -32,7 +34,6 @@ static SFORMAT StateRegs[]= static void Sync(void) { setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF)); - setchr8(0); } static void StateRestore(int version) @@ -40,21 +41,46 @@ static void StateRestore(int version) Sync(); } +static DECLFR(ReadLow) +{ + switch (A&0x7700) + { + case 0x5100: return DRegs[2]; break; + case 0x5500: if(trigger) + return DRegs[2]; + else + return 0; + } + return 4; +} + static DECLFW(Write) { switch (A&0x7300) { case 0x5100: DRegs[0]=V; Sync(); break; case 0x5000: DRegs[1]=V; Sync(); break; + case 0x5300: DRegs[2]=V; break; } } static DECLFW(Write2) { + if(A==0x5101) + { + if(laststrobe&&!V) + { + trigger^=1; + } + laststrobe=V; + }else if(A==0x5100&&V==6) //damn thoose protected games + setprg32(0x8000,3); + else switch (A&0x7300) { case 0x5200: DRegs[0]=V; Sync(); break; - case 0x5000: DRegs[1]=V; Sync(); break; + case 0x5000: DRegs[1]=V; Sync(); if(!(DRegs[1]&0x80)&&(scanline<128)) setchr8(0); break; + case 0x5300: DRegs[2]=V; break; } } @@ -75,28 +101,42 @@ static void Power(void) DRegs[1]=0xFF; cmd=0; SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x4020,0xFFFF,Write); + SetWriteHandler(0x4020,0x5FFF,Write); SetReadHandler(0x6000,0x7FFF,AWRAM); SetWriteHandler(0x6000,0x7FFF,BWRAM); + setchr8(0); Sync(); } static void M163HB(void) { - if(scanline==127&&DRegs[1]&0x80) - setchr4(0x0000,1); + if(DRegs[1]&0x80) + { + if(scanline==239) + { + setchr4(0x0000,0); + setchr4(0x1000,0); + } + else if(scanline==127) + { + setchr4(0x0000,1); + setchr4(0x1000,1); + } + } } - static void Power2(void) { memset(DRegs,0,8); DRegs[1]=0xFF; + laststrobe=1; cmd=0; SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x4020,0xFFFF,Write2); + SetWriteHandler(0x4020,0x5FFF,Write2); SetReadHandler(0x6000,0x7FFF,AWRAM); SetWriteHandler(0x6000,0x7FFF,BWRAM); + SetReadHandler(0x5000,0x5FFF,ReadLow); + setchr8(0); Sync(); } @@ -105,6 +145,9 @@ void Mapper164_Init(CartInfo *info) info->Power=Power; GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); + AddExState(WRAM, 8192, 0, "WRAM"); + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=8192; } void Mapper163_Init(CartInfo *info) @@ -113,4 +156,5 @@ void Mapper163_Init(CartInfo *info) GameHBIRQHook=M163HB; GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); + AddExState(WRAM, 8192, 0, "WRAM"); } diff --git a/boards/175.c b/boards/175.c new file mode 100644 index 0000000..2830584 --- /dev/null +++ b/boards/175.c @@ -0,0 +1,88 @@ +/* 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/boards/176.c b/boards/176.c new file mode 100644 index 0000000..0830df8 --- /dev/null +++ b/boards/176.c @@ -0,0 +1,158 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * Copyright (C) 2012 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 + */ + +#include "mapinc.h" + +extern uint32 ROM_size; + +static uint8 prg[4], chr, sbw, we_sram; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {prg, 4, "PRG"}, + {&chr, 1, "CHR"}, + {&sbw, 1, "SBW"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,0); + setprg8(0x8000,prg[0]); + setprg8(0xA000,prg[1]); + setprg8(0xC000,prg[2]); + setprg8(0xE000,prg[3]); + + setchr8(chr); +} + +static DECLFW(M176Write_5001) +{ + printf("%04X = $%02X\n",A,V); + if(sbw) + { + prg[0] = V*4; + prg[1] = V*4+1; + prg[2] = V*4+2; + prg[3] = V*4+3; + } + Sync(); +} + +static DECLFW(M176Write_5010) +{ + printf("%04X = $%02X\n",A,V); + if(V == 0x24) sbw = 1; + Sync(); +} + +static DECLFW(M176Write_5011) +{ + printf("%04X = $%02X\n",A,V); + V >>= 1; + if(sbw) + { + prg[0] = V*4; + prg[1] = V*4+1; + prg[2] = V*4+2; + prg[3] = V*4+3; + } + Sync(); +} + +static DECLFW(M176Write_5FF1) +{ + printf("%04X = $%02X\n",A,V); + V >>= 1; + prg[0] = V*4; + prg[1] = V*4+1; + prg[2] = V*4+2; + prg[3] = V*4+3; + Sync(); +} + +static DECLFW(M176Write_5FF2) +{ + printf("%04X = $%02X\n",A,V); + chr = V; + Sync(); +} + +static DECLFW(M176Write_A001) +{ + we_sram = V & 0x03; +} + +static DECLFW(M176Write_WriteSRAM) +{ +// if(we_sram) + CartBW(A,V); +} + +static void M176Power(void) +{ + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,M176Write_WriteSRAM); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0xA001,0xA001,M176Write_A001); + SetWriteHandler(0x5001,0x5001,M176Write_5001); + SetWriteHandler(0x5010,0x5010,M176Write_5010); + SetWriteHandler(0x5011,0x5011,M176Write_5011); + SetWriteHandler(0x5ff1,0x5ff1,M176Write_5FF1); + SetWriteHandler(0x5ff2,0x5ff2,M176Write_5FF2); + + we_sram = 0; + sbw = 0; + prg[0] = 0; + prg[1] = 1; + prg[2] = (ROM_size-2)&63; + prg[3] = (ROM_size-1)&63; + Sync(); +} + + +static void M176Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper176_Init(CartInfo *info) +{ + info->Power=M176Power; + info->Close=M176Close; + + 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/boards/177.c b/boards/177.c new file mode 100644 index 0000000..6bc81b9 --- /dev/null +++ b/boards/177.c @@ -0,0 +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 + */ + +#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); +} + +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/boards/178.c b/boards/178.c new file mode 100644 index 0000000..19e1b8d --- /dev/null +++ b/boards/178.c @@ -0,0 +1,101 @@ +/* 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[3]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 3, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setmirror(reg[0]); + setprg8r(0x10,0x6000,0); + setchr8(0); + setprg32(0x8000,(reg[1]+reg[2])); +} + +static DECLFW(M178Write0) +{ + reg[0]=(V&1)^1; + Sync(); +} + +static DECLFW(M178Write1) +{ + reg[1]=(V>>1)&0xf; + Sync(); +} + +static DECLFW(M178Write2) +{ + reg[2]=(V<<2); + Sync(); +} + +static void M178Power(void) +{ + reg[0]=1; reg[1]=0; reg[2]=0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4800,0x4800,M178Write0); + SetWriteHandler(0x4801,0x4801,M178Write1); + SetWriteHandler(0x4802,0x4802,M178Write2); +} + +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; + + 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/boards/179.c b/boards/179.c new file mode 100644 index 0000000..91a530f --- /dev/null +++ b/boards/179.c @@ -0,0 +1,94 @@ +/* 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[2]; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 2, "REG"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8r(0x10,0x6000,0); + setprg32(0x8000,reg[1]>>1); + setmirror((reg[0]&1)^1); +} + +static DECLFW(M179Write) +{ + if(A==0xa000) reg[0]=V; + Sync(); +} + +static DECLFW(M179WriteLo) +{ + if(A==0x5ff1) reg[1]=V; + Sync(); +} + +static void M179Power(void) +{ + reg[0]=reg[1]=0; + Sync(); + SetWriteHandler(0x4020,0x5fff,M179WriteLo); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M179Write); +} + +static void M179Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper179_Init(CartInfo *info) +{ + info->Power=M179Power; + info->Close=M179Close; + 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/boards/183.c b/boards/183.c index 5e80a6b..bf0b7c0 100644 --- a/boards/183.c +++ b/boards/183.c @@ -1,117 +1,117 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Gimmick Bootleg - */ - -#include "mapinc.h" - -static uint8 prg[4]; -static uint8 chr[8]; -static uint8 IRQCount; -static uint8 IRQPre; -static uint8 IRQa; - -static SFORMAT StateRegs[]= -{ - {prg, 4, "PRG"}, - {chr, 8, "CHR"}, - {&IRQCount, 1, "IRQCOUNT"}, - {&IRQPre, 1, "IRQPRE"}, - {&IRQa, 1, "IRQA"}, - {0} -}; - -static void SyncPrg(void) -{ - setprg8(0x6000,0); - setprg8(0x8000,prg[0]); - setprg8(0xA000,prg[1]); - setprg8(0xC000,prg[2]); - setprg8(0xE000,~0); -} - -static void SyncChr(void) -{ - int i; - for(i=0; i<8; i++) - setchr1(i<<10,chr[i]); -} - -static void StateRestore(int version) -{ - SyncPrg(); - SyncChr(); -} - -static DECLFW(M183Write) -{ - if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C)) - { - uint8 index=(((A&0x7000)>>11)-6)|((A&8)>>3); - 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: 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; - } - 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(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,M183Write); - SetReadHandler(0x6000,0x7FFF,CartBR); - 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]; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[]= +{ + {prg, 4, "PRG"}, + {chr, 8, "CHR"}, + {&IRQCount, 1, "IRQCOUNT"}, + {&IRQPre, 1, "IRQPRE"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void SyncPrg(void) +{ + setprg8(0x6000,0); + setprg8(0x8000,prg[0]); + setprg8(0xA000,prg[1]); + setprg8(0xC000,prg[2]); + setprg8(0xE000,~0); +} + +static void SyncChr(void) +{ + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); +} + +static void StateRestore(int version) +{ + SyncPrg(); + SyncChr(); +} + +static DECLFW(M183Write) +{ + if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C)) + { + uint8 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: 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; + } + 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(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M183Write); + SetReadHandler(0x6000,0x7FFF,CartBR); + SyncPrg(); + SyncChr(); +} + +void Mapper183_Init(CartInfo *info) +{ + info->Power=M183Power; + GameHBIRQHook=M183IRQCounter; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/185.c b/boards/185.c index 49b63dc..b865a8f 100644 --- a/boards/185.c +++ b/boards/185.c @@ -1,116 +1,115 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Family Study Box by Fukutake Shoten - */ - -#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) -{ - Sync=Sync185; - info->Power=MPower; - info->Close=MClose; - GameStateRestore=MRestore; - DummyCHR=(uint8*)FCEU_gmalloc(8192); - int x; - for(x=0;x<8192;x++) - DummyCHR[x]=0xff; - SetupCartCHRMapping(0x10,DummyCHR,8192,0); - AddExState(StateRegs, ~0, 0, 0); -} - -void Mapper181_Init(CartInfo *info) -{ - Sync=Sync181; - info->Power=MPower; - info->Close=MClose; - GameStateRestore=MRestore; - DummyCHR=(uint8*)FCEU_gmalloc(8192); - int x; - 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/boards/186.c b/boards/186.c index 80b39d8..4976265 100644 --- a/boards/186.c +++ b/boards/186.c @@ -1,104 +1,104 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Family Study Box by Fukutake Shoten - */ - -#include "mapinc.h" - -static uint8 SWRAM[2816]; -static uint8 *WRAM=NULL; -static uint8 regs[4]; - -static SFORMAT StateRegs[]= -{ - {regs, 4, "DREG"}, - {SWRAM, 2816, "SWRAM"}, - {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,0x4EFF,ASWRAM); - SetWriteHandler(0x4400,0x4EFF,BSWRAM); - 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(32384); - SetupCartPRGMapping(0x10,WRAM,32384,1); - AddExState(WRAM, 32384, 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[2816]; +static uint8 *WRAM=NULL; +static uint8 regs[4]; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "DREG"}, + {SWRAM, 2816, "SWRAM"}, + {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,0x4EFF,ASWRAM); + SetWriteHandler(0x4400,0x4EFF,BSWRAM); + 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/boards/187.c b/boards/187.c index 0fa4a15..0f49748 100644 --- a/boards/187.c +++ b/boards/187.c @@ -1,104 +1,103 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#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) - setprg32(0x8000,bank>>2); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,V&0x3F); -} - -static DECLFW(M187Write8000) -{ - EXPREGS[2]=1; - MMC3_CMDWrite(A,V); -} - -static DECLFW(M187Write8001) -{ - if(EXPREGS[2]) - MMC3_CMDWrite(A,V); -} - -static DECLFW(M187Write8003) -{ - EXPREGS[2]=0; - if(V==0x28)setprg8(0xC000,0x17); - else if(V==0x2A)setprg8(0xA000,0x0F); -} - - -static DECLFW(M187WriteLo) -{ - EXPREGS[1]=V; - if(A==0x5000) - { - 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]=EXPREGS[2]=0; - GenMMC3Power(); - Write_IRQFM(0x4017,0x40); - SetReadHandler(0x5000,0x5FFF,M187Read); - SetWriteHandler(0x5000,0x5FFF,M187WriteLo); - SetWriteHandler(0x8000,0x8000,M187Write8000); - SetWriteHandler(0x8001,0x8001,M187Write8001); - SetWriteHandler(0x8003,0x8003,M187Write8003); -} - -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 + */ + +#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) + setprg32(0x8000,bank>>2); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,V&0x3F); +} + +static DECLFW(M187Write8000) +{ + EXPREGS[2]=1; + MMC3_CMDWrite(A,V); +} + +static DECLFW(M187Write8001) +{ + if(EXPREGS[2]) + MMC3_CMDWrite(A,V); +} + +static DECLFW(M187Write8003) +{ + EXPREGS[2]=0; + if(V==0x28)setprg8(0xC000,0x17); + else if(V==0x2A)setprg8(0xA000,0x0F); +} + + +static DECLFW(M187WriteLo) +{ + EXPREGS[1]=V; + if(A==0x5000) + { + 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]=EXPREGS[2]=0; + GenMMC3Power(); + SetReadHandler(0x5000,0x5FFF,M187Read); + SetWriteHandler(0x5000,0x5FFF,M187WriteLo); + SetWriteHandler(0x8000,0x8000,M187Write8000); + SetWriteHandler(0x8001,0x8001,M187Write8001); + SetWriteHandler(0x8003,0x8003,M187Write8003); +} + +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/boards/189.c b/boards/189.c index 23be63a..ff045a5 100644 --- a/boards/189.c +++ b/boards/189.c @@ -1,48 +1,48 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" -#include "mmc3.h" - -static void M189PW(uint32 A, uint8 V) -{ - setprg32(0x8000,EXPREGS[0]&3); -} - -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]&3); +} + +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/boards/199.c b/boards/199.c new file mode 100644 index 0000000..ed21278 --- /dev/null +++ b/boards/199.c @@ -0,0 +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; // and here too + +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)) + { +// FCEU_printf("%02x=>%02x\n",MMC3_cmd,V); + 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); +} + +void Mapper199_Init(CartInfo *info) +{ + int CHRRAMSize=1024*8; + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M199CW; + pwrap=M199PW; + mwrap=M199MW; + info->Power=M199Power; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/boards/208.c b/boards/208.c index 9ccf8e7..3bbb34d 100644 --- a/boards/208.c +++ b/boards/208.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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(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(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/boards/222.c b/boards/222.c index fd3cc8a..e230751 100644 --- a/boards/222.c +++ b/boards/222.c @@ -1,99 +1,106 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "mapinc.h" - -static uint16 IRQCount; -static uint8 IRQa; -static uint8 prg_reg[2]; -static uint8 chr_reg[8]; - -static SFORMAT StateRegs[]= -{ - {&IRQCount, 2, "IRQC"}, - {&IRQa, 2, "IRQA"}, - {prg_reg, 2, "PRG"}, - {chr_reg, 8, "CHR"}, - {0} -}; - -static void M222IRQ(void) -{ - if(IRQa) - { - IRQCount++; - if(IRQCount>=240) - { - X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; - } - } -} - -static void Sync(void) -{ - setprg8(0x8000,prg_reg[0]); - setprg8(0xA000,prg_reg[1]); - int i; - for(i=0; i<8; i++) - setchr1(i<<10,chr_reg[i]); -} - -static DECLFW(M222Write) -{ - switch(A&0xF003) - { - case 0x8000: prg_reg[0]=V; 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; - case 0xF000: IRQCount=IRQa=V; - 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; +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; +// 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; + 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/boards/23.c b/boards/23.c new file mode 100644 index 0000000..8760d50 --- /dev/null +++ b/boards/23.c @@ -0,0 +1,208 @@ +/* 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 is23; +static uint16 IRQCount; +static uint8 IRQLatch,IRQa; +static uint8 prgreg[2]; +static uint8 chrreg[8]; +static uint8 regcmd, irqcmd, mirr, big_bank; +static uint16 acount=0; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {prgreg, 2, "PRGREGS"}, + {chrreg, 8, "CHRREGS"}, + {®cmd, 1, "REGCMD"}, + {&irqcmd, 1, "IRQCMD"}, + {&mirr, 1, "MIRR"}, + {&big_bank, 1, "BIGB"}, + {&IRQCount, 2, "IRCN"}, + {&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; + for(i=0; i<8; i++) + setchr1(i<<10, chrreg[i]); + } + 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(M23Write) +{ +// FCEU_printf("%04x:%04x\n",A,V); + A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); // actually there is many-in-one mapper source, some pirate or + // licensed games use various address bits for registers + 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); + chrreg[i]&=(0xF0)>>((A&1)<<2); + chrreg[i]|=(V&0xF)<<((A&1)<<2); + } + Sync(); + } + else + switch(A&0xF003) + { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: if(is23) + prgreg[0]=V&0x1F; + Sync(); + break; + case 0xA000: + case 0xA001: + case 0xA002: + case 0xA003: if(is23) + prgreg[1]=V&0x1F; + else + { + prgreg[0]=(V<<1)&0x1F; + prgreg[1]=((V<<1)&0x1F)|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 void M23Power(void) +{ + big_bank=0x20; + Sync(); + setprg8r(0x10,0x6000,0); // another many-in-one code, WRAM actually contain only WaiWaiWorld game + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M23Write); +} + +static void M23Reset(void) +{ +} + +void M23IRQHook(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 M23Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); +} + +void Mapper23_Init(CartInfo *info) +{ + is23=1; + info->Power=M23Power; + info->Close=M23Close; + MapIRQHook=M23IRQHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} + +void UNLT230_Init(CartInfo *info) +{ + is23=0; + info->Power=M23Power; + info->Close=M23Close; + MapIRQHook=M23IRQHook; + 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/boards/235.c b/boards/235.c index 34bbc0f..4cae946 100644 --- a/boards/235.c +++ b/boards/235.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint16 cmdreg; -static SFORMAT StateRegs[]= -{ - {&cmdreg, 2, "CMDREG"}, - {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, "CMDREG"}, + {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/boards/253.c b/boards/253.c new file mode 100644 index 0000000..6e3b569 --- /dev/null +++ b/boards/253.c @@ -0,0 +1,175 @@ +/* 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, "CHRLO"}, + {chrhi, 8, "CHRHI"}, + {prg, 2, "PRGR"}, + {&mirr, 1, "MIRR"}, + {&vlock, 1, "VLOCK"}, + {&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]==0xc8) + { + vlock = 0; + continue; + } + else if(chrlo[i]==0x88) + { + vlock = 1; + continue; + } + 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; + chrlo[ind]=(chrlo[ind]&(0xF0>>sar))|((V&0x0F)<>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: IRQLatch = (IRQLatch & 0xF0) | (V & 0x0F); break; + case 0xF004: IRQLatch = (IRQLatch & 0x0F) | (V << 4); break; + case 0xF008: + IRQa = V&3; + if(IRQa&2) + { + IRQCount = IRQLatch; + IRQClock = 0; + } + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void M253Power(void) +{ + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M253Write); +} + +static void M253Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + if(CHRRAM) + FCEU_gfree(CHRRAM); + WRAM=CHRRAM=NULL; +} + +static void M253IRQ(int cycles) +{ + if(IRQa&2) + { + if((IRQClock+=cycles)>=0x72) + { + IRQClock -= 0x72; + if(IRQCount==0xFF) + { + IRQCount = IRQLatch; + IRQa = IRQa|((IRQa&1)<<1); + X6502_IRQBegin(FCEU_IQEXT); + } + else + IRQCount++; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper253_Init(CartInfo *info) +{ + info->Power=M253Power; + info->Close=M253Close; + MapIRQHook=M253IRQ; + GameStateRestore=StateRestore; + + CHRRAMSIZE=4096; + 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/boards/3d-block.c b/boards/3d-block.c new file mode 100644 index 0000000..24572a4 --- /dev/null +++ b/boards/3d-block.c @@ -0,0 +1,110 @@ +/* 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 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/boards/411120-c.c b/boards/411120-c.c new file mode 100644 index 0000000..479a9bf --- /dev/null +++ b/boards/411120-c.c @@ -0,0 +1,70 @@ +/* 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/boards/43.c b/boards/43.c new file mode 100644 index 0000000..ee12dec --- /dev/null +++ b/boards/43.c @@ -0,0 +1,94 @@ +/* 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 + */ + +//ccording to nestopia, BTL_SMB2_C, otherwise known as UNL-SMB2J + +#include "mapinc.h" + +static uint8 reg; +static uint8 IRQa; +static uint32 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 4, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg4(0x5000,16); + setprg8(0x6000,2); + setprg8(0x8000,1); + setprg8(0xa000,0); + setprg8(0xc000,reg); + setprg8(0xe000,9); + setchr8(0); +} + +static DECLFW(M43Write) +{ + int transo[8]={4,3,4,4,4,7,5,6}; + switch(A&0xf1ff) + { + case 0x4022: reg=transo[V&7]; Sync(); break; + case 0x8122: IRQa=V&1; IRQCount=0; break; + } +} + +static void M43Power(void) +{ + reg=0; + Sync(); +// SetReadHandler(0x5000,0x5fff,CartBR); + SetReadHandler(0x5000,0xffff,CartBR); + SetWriteHandler(0x4020,0xffff,M43Write); +} + +static void M43Reset(void) +{ +} + +static void 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/boards/57.c b/boards/57.c index 693677d..ba5de0b 100644 --- a/boards/57.c +++ b/boards/57.c @@ -1,93 +1,92 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "mapinc.h" - -static uint8 prg_reg; -static uint8 chr_reg; -static uint8 hrd_flag; - -static SFORMAT StateRegs[]= -{ - {&prg_reg, 1, "PRG"}, - {&chr_reg, 1, "CHR"}, - {0} -}; - -static void Sync(void) -{ - if(prg_reg&0x80) - setprg32(0x8000,prg_reg>>6); - else - { - setprg16(0x8000,(prg_reg>>5)&3); - setprg16(0xC000,(prg_reg>>5)&3); - } - setmirror((prg_reg&8)>>3); - setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1)); -} - -static DECLFR(M57Read) -{ - return hrd_flag; -} - -static DECLFW(M57Write) -{ - if((A&0x8800)==0x8800) - prg_reg=V; - else - chr_reg=V; - Sync(); -} - -static void M57Power(void) -{ - prg_reg=0; - chr_reg=0; - hrd_flag=0; - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,M57Write); - SetReadHandler(0x6000,0x6000,M57Read); - Sync(); -} - -static void M57Reset() -{ - if(hrd_flag==3) - hrd_flag=0; - else - hrd_flag++; - 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 prg_reg; +static uint8 chr_reg; +static uint8 hrd_flag; + +static SFORMAT StateRegs[]= +{ + {&hrd_flag, 1, "DIPSW"}, + {&prg_reg, 1, "PRG"}, + {&chr_reg, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + if(prg_reg&0x80) + setprg32(0x8000,prg_reg>>6); + else + { + setprg16(0x8000,(prg_reg>>5)&3); + setprg16(0xC000,(prg_reg>>5)&3); + } + setmirror((prg_reg&8)>>3); + setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1)); +} + +static DECLFR(M57Read) +{ + return hrd_flag; +} + +static DECLFW(M57Write) +{ + if((A&0x8800)==0x8800) + prg_reg=V; + else + chr_reg=V; + Sync(); +} + +static void M57Power(void) +{ + prg_reg=0; + chr_reg=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/boards/cc21.c b/boards/603-5052.c similarity index 54% rename from boards/cc21.c rename to boards/603-5052.c index 0e2cbe6..43b4e0a 100644 --- a/boards/cc21.c +++ b/boards/603-5052.c @@ -1,56 +1,48 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint16 addrlatche; - -//------------------ UNLCC21 --------------------------- - -static void UNLCC21Sync(void) -{ - setchr8(addrlatche&1); - setmirror(MI_0+((addrlatche&2)>>1)); -} - -static DECLFW(UNLCC21Write) -{ - addrlatche=A; - UNLCC21Sync(); -} - -static void UNLCC21Power(void) -{ - setprg32(0x8000,0); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xffff,UNLCC21Write); -} - -static void UNLCC21Restore(int version) -{ - UNLCC21Sync(); -} - -void UNLCC21_Init(CartInfo *info) -{ - info->Power=UNLCC21Power; - GameStateRestore=UNLCC21Restore; - AddExState(&addrlatche, 2, 0, "ALATC"); -} +/* 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[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/boards/68.c b/boards/68.c new file mode 100644 index 0000000..6a9420c --- /dev/null +++ b/boards/68.c @@ -0,0 +1,178 @@ +/* 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, "KOGAME"}, + {&count, 4, "COUNT"}, + {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); + } +} + +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); +} + +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/boards/8157.c b/boards/8157.c index 2aa3f4e..1b23023 100644 --- a/boards/8157.c +++ b/boards/8157.c @@ -1,80 +1,81 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint16 cmdreg; -static uint8 invalid_data; -static SFORMAT StateRegs[]= -{ - {&cmdreg, 2, "CMDREG"}, - {0} -}; - -static void Sync(void) -{ - setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2); - setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0); - setmirror(((cmdreg&2)>>1)^1); -} - -static DECLFR(UNL8157Read) -{ - if(invalid_data&&cmdreg&0x100) - return 0xFF; - else - return CartBR(A); -} - -static DECLFW(UNL8157Write) -{ - cmdreg=A; - Sync(); -} - -static void UNL8157Power(void) -{ - setchr8(0); - SetWriteHandler(0x8000,0xFFFF,UNL8157Write); - SetReadHandler(0x8000,0xFFFF,UNL8157Read); - cmdreg=0x200; - invalid_data=1; - Sync(); -} - -static void UNL8157Reset(void) -{ - cmdreg=0; - invalid_data^=1; - 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 + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static uint8 invalid_data; +static SFORMAT StateRegs[]= +{ + {&invalid_data, 1, "INVD"}, + {&cmdreg, 2, "CMDREG"}, + {0} +}; + +static void Sync(void) +{ + setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2); + setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0); + setmirror(((cmdreg&2)>>1)^1); +} + +static DECLFR(UNL8157Read) +{ + if(invalid_data&&cmdreg&0x100) + return 0xFF; + else + return CartBR(A); +} + +static DECLFW(UNL8157Write) +{ + cmdreg=A; + Sync(); +} + +static void UNL8157Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,UNL8157Write); + SetReadHandler(0x8000,0xFFFF,UNL8157Read); + cmdreg=0x200; + invalid_data=1; + Sync(); +} + +static void UNL8157Reset(void) +{ + cmdreg=0; + invalid_data^=1; + 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/boards/8237.c b/boards/8237.c index 5b4e2df..0415338 100644 --- a/boards/8237.c +++ b/boards/8237.c @@ -1,93 +1,195 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 cmdin; -static uint8 UNL8237_perm[8] = {0, 2, 6, 1, 7, 3, 4, 5}; - -static void UNL8237CW(uint32 A, uint8 V) -{ - setchr1(A,((EXPREGS[1]&4)<<6)|V); -} - -static void UNL8237PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - { - if(EXPREGS[0]&0x20) - setprg32(0x8000,(EXPREGS[0]&0xF)>>1); - else - { - setprg16(0x8000,(EXPREGS[0]&0x1F)); - setprg16(0xC000,(EXPREGS[0]&0x1F)); - } - } - else - setprg8(A,V&0x3F); -} - -static DECLFW(UNL8237Write) -{ - if((A&0xF000)==0xF000) - IRQCount=V; - else if((A&0xF000)==0xE000) - X6502_IRQEnd(FCEU_IQEXT); - else switch(A&0xE001) - { - case 0x8000: setmirror(((V|(V>>7))&1)^1); break; - case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(UNL8237_perm[V&7])); cmdin=1; break; - case 0xC000: if(cmdin) - { - MMC3_CMDWrite(0x8001,V); - cmdin=0; - } - break; - } -} - -static DECLFW(UNL8237ExWrite) -{ - switch(A) - { - case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break; - case 0x5001: EXPREGS[1]=V; FixMMC3CHR(MMC3_cmd); break; - } -} - -static void UNL8237Power(void) -{ - IRQa=1; - EXPREGS[0]=EXPREGS[1]=0; - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,UNL8237Write); - SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite); -} - -void UNL8237_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - cwrap=UNL8237CW; - pwrap=UNL8237PW; - info->Power=UNL8237Power; - AddExState(EXPREGS, 3, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005-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 + * + * Super Game (Sugar Softec) protected mapper + * Pocahontas 2 (Unl) [U][!], etc. + * TODO: 9in1 LION KING HANGS! + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 cmdin; + +static uint8 regperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {0, 2, 6, 1, 7, 3, 4, 5}, + {0, 5, 4, 1, 7, 2, 6, 3}, // unused + {0, 6, 3, 7, 5, 2, 4, 1}, + {0, 2, 5, 3, 6, 1, 7, 4}, + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + }; + +static uint8 adrperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {3, 2, 0, 4, 1, 5, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, // unused + {5, 0, 1, 2, 3, 7, 6, 4}, + {3, 1, 0, 5, 2, 4, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + }; + +static void UNL8237CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xc)<<6)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xc)<<6)|V); +} + +static void UNL8237PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x0F)|sbank); + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x1F)); + } +} + +static void UNL8237ACW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xE)<<7)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xE)<<7)|V); +} + +static void UNL8237APW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F)); + } +} +static DECLFW(UNL8237Write) +{ + uint8 dat = V; + uint8 adr = adrperm[EXPREGS[2]][((A>>12)&6)|(A&1)]; + uint16 addr = (adr & 1)|((adr & 6)<<12)|0x8000; + if(adr < 4) + { + if(!adr) + dat = (dat & 0xC0)|(regperm[EXPREGS[2]][dat & 7]); + MMC3_CMDWrite(addr,dat); + } + else + MMC3_IRQWrite(addr,dat); +} + +static DECLFW(UNL8237ExWrite) +{ + switch(A) + { + case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break; + case 0x5001: EXPREGS[1]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break; + case 0x5007: EXPREGS[2]=V; break; + } +} + +static void UNL8237Power(void) +{ + EXPREGS[0]=EXPREGS[2]=0; + EXPREGS[1]=3; + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,UNL8237Write); + SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite); +} + +void UNL8237_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237CW; + pwrap=UNL8237PW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDIN"); +} + +void UNL8237A_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237ACW; + pwrap=UNL8237APW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDIN"); +} diff --git a/boards/830118C.c b/boards/830118C.c new file mode 100644 index 0000000..8b6ce60 --- /dev/null +++ b/boards/830118C.c @@ -0,0 +1,82 @@ +/* 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 uint8 reset_flag = 0; + +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/boards/88.c b/boards/88.c index 03fbf5b..88d45ce 100644 --- a/boards/88.c +++ b/boards/88.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/boards/90.c b/boards/90.c index 994910d..caccc09 100644 --- a/boards/90.c +++ b/boards/90.c @@ -16,13 +16,17 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" //#define DEBUG90 -static int is209; +// Mapper 090 is simpliest mapper hardware and have not extended nametable control and latched chr banks in 4k mode +// Mapper 209 much compicated hardware with decribed above features disabled by default and switchable by command +// Mapper 211 the same mapper 209 but with forced nametable control + +static int is209; static int is211; static uint8 IRQMode; // from $c001 @@ -40,20 +44,23 @@ static uint8 prgb[4]; static uint8 chrlow[8]; static uint8 chrhigh[8]; +static uint8 chr[2]; + static uint16 names[4]; static uint8 tekker; static SFORMAT Tek_StateRegs[]={ - {&IRQMode, 1, "IRQMODE"}, - {&IRQPre, 1, "IRQPRE"}, - {&IRQPreSize, 1, "IRQPRESIZE"}, + {&IRQMode, 1, "IRQM"}, + {&IRQPre, 1, "IRQP"}, + {&IRQPreSize, 1, "IRQS"}, {&IRQCount, 1, "IRQC"}, - {&IRQXOR, 1, "IRQXOR"}, + {&IRQXOR, 1, "IRQX"}, {&IRQa, 1, "IRQa"}, {mul, 2, "MUL"}, {®ie, 1, "REGI"}, {tkcom, 4, "TKCO"}, {prgb, 4, "PRGB"}, + {chr, 2, "CHRA"}, {chrlow, 4, "CHRL"}, {chrhigh, 8, "CHRH"}, {&names[0], 2|FCEUSTATE_RLSB, "NMS0"}, @@ -159,8 +166,10 @@ static void tekvrom(void) setchr8(((chrlow[0]|(chrhigh[0]<<8))&mask)|bank); break; case 0x08: // 4KB - for(x=0;x<8;x+=4) - setchr4(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); +// for(x=0;x<8;x+=4) +// setchr4(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank); + setchr4(0x0000,((chrlow[chr[0]]|(chrhigh[chr[0]]<<8))&mask)|bank); + setchr4(0x1000,((chrlow[chr[1]]|(chrhigh[chr[1]]<<8))&mask)|bank); break; case 0x10: // 2KB for(x=0;x<8;x+=2) @@ -175,7 +184,7 @@ static void tekvrom(void) static DECLFW(M90TekWrite) { - switch(A) + switch(A&0x5C03) { case 0x5800: mul[0]=V; break; case 0x5801: mul[1]=V; break; @@ -185,35 +194,40 @@ static DECLFW(M90TekWrite) static DECLFR(M90TekRead) { - switch(A) + switch(A&0x5C03) { case 0x5800: return (mul[0]*mul[1]); case 0x5801: return((mul[0]*mul[1])>>8); case 0x5803: return (regie); + default: return tekker; } - return(tekker); + return(0xff); } static DECLFW(M90PRGWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); prgb[A&3]=V; tekprom(); } static DECLFW(M90CHRlowWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); chrlow[A&7]=V; tekvrom(); } static DECLFW(M90CHRhiWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); chrhigh[A&7]=V; tekvrom(); } static DECLFW(M90NTWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); if(A&4) { names[A&3]&=0x00FF; @@ -229,6 +243,7 @@ static DECLFW(M90NTWrite) static DECLFW(M90IRQWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); switch(A&7) { case 00: //FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable"); @@ -238,20 +253,20 @@ static DECLFW(M90IRQWrite) case 03: //FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline); IRQa=1;break; case 01: IRQMode=V; -/* FCEU_printf("IRQ Count method: "); - switch (IRQMode&3) - { - case 00: FCEU_printf("M2 cycles\n");break; - case 01: FCEU_printf("PPU A12 toggles\n");break; - case 02: FCEU_printf("PPU reads\n");break; - case 03: FCEU_printf("Writes to CPU space\n");break; - } - FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits"); - FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation"); - if((IRQMode>>6)==2) FCEU_printf("Counter Down\n"); - else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n"); - else FCEU_printf("Counter Stopped\n"); -*/ break; + // FCEU_printf("IRQ Count method: "); + // switch (IRQMode&3) + // { + // case 00: FCEU_printf("M2 cycles\n");break; + // case 01: FCEU_printf("PPU A12 toggles\n");break; + // case 02: FCEU_printf("PPU reads\n");break; + // case 03: FCEU_printf("Writes to CPU space\n");break; + // } + // FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits"); + // FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation"); + // if((IRQMode>>6)==2) FCEU_printf("Counter Down\n"); + // else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n"); + // else FCEU_printf("Counter Stopped\n"); + break; case 04: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); IRQPre=V^IRQXOR;break; case 05: //FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); @@ -259,14 +274,15 @@ static DECLFW(M90IRQWrite) case 06: //FCEU_printf("Xor Value: %d\n",V); IRQXOR=V;break; case 07: //if(!(IRQMode&8)) FCEU_printf("C001 is clear, no effect applied\n"); - // else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n"); - // else FCEU_printf("Counter Stopped\n"); + // else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n"); + // else FCEU_printf("Counter Stopped\n"); IRQPreSize=V;break; } } static DECLFW(M90ModeWrite) { +// FCEU_printf("bs %04x %02x\n",A,V); tkcom[A&3]=V; tekprom(); tekvrom(); @@ -305,6 +321,11 @@ static DECLFW(M90ModeWrite) #endif } +static DECLFW(M90DummyWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); +} + static void CCL(void) { if((IRQMode>>6) == 1) // Count Up @@ -345,7 +366,7 @@ static void ClockCounter(void) } } -void FP_FASTAPASS(1) CPUWrap(int a) +void CPUWrap(int a) { int x; if((IRQMode&3)==0) for(x=0;x>8; + if(h<0x20&&((h&0x0F)==0xF)) + { + l=A&0xF0; + if(l==0xD0) + { + chr[(h&0x10)>>4]=((h&0x10)>>2); + tekvrom(); + } + else if(l==0xE0) + { + chr[(h&0x10)>>4]=((h&0x10)>>2)|2; + tekvrom(); + } + } + } + else + { + chr[0]=0; + chr[1]=4; + } } static void togglie() { - tekker>>=6; - if(tekker>3) - tekker=0; - else - tekker++; - tekker<<=6; - FCEU_printf("tekker=%04x\n",tekker); + tekker+=0x40; + tekker&=0xC0; + FCEU_printf("tekker=%02x\n",tekker); memset(tkcom,0x00,sizeof(tkcom)); memset(prgb,0xff,sizeof(prgb)); tekprom(); @@ -403,12 +438,14 @@ static void M90Restore(int version) static void M90Power(void) { SetWriteHandler(0x5000,0x5fff,M90TekWrite); - SetWriteHandler(0x8000,0x8fff,M90PRGWrite); + SetWriteHandler(0x8000,0x8ff0,M90PRGWrite); SetWriteHandler(0x9000,0x9fff,M90CHRlowWrite); SetWriteHandler(0xA000,0xAfff,M90CHRhiWrite); SetWriteHandler(0xB000,0xBfff,M90NTWrite); SetWriteHandler(0xC000,0xCfff,M90IRQWrite); - SetWriteHandler(0xD000,0xDfff,M90ModeWrite); + SetWriteHandler(0xD000,0xD5ff,M90ModeWrite); + SetWriteHandler(0xE000,0xFfff,M90DummyWrite); + SetReadHandler(0x5000,0x5fff,M90TekRead); SetReadHandler(0x6000,0xffff,CartBR); @@ -438,8 +475,8 @@ void Mapper90_Init(CartInfo *info) info->Reset=togglie; info->Power=M90Power; PPU_hook=M90PPU; - GameHBIRQHook2=SLWrap; MapIRQHook=CPUWrap; + GameHBIRQHook2=SLWrap; GameStateRestore=M90Restore; AddExState(Tek_StateRegs, ~0, 0, 0); } @@ -450,6 +487,8 @@ void Mapper209_Init(CartInfo *info) is209=1; info->Reset=togglie; info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; GameHBIRQHook2=SLWrap; GameStateRestore=M90Restore; AddExState(Tek_StateRegs, ~0, 0, 0); @@ -460,6 +499,8 @@ void Mapper211_Init(CartInfo *info) is211=1; info->Reset=togglie; info->Power=M90Power; + PPU_hook=M90PPU; + MapIRQHook=CPUWrap; GameHBIRQHook2=SLWrap; GameStateRestore=M90Restore; AddExState(Tek_StateRegs, ~0, 0, 0); diff --git a/boards/95.c b/boards/95.c index 7b69435..0a5d9dd 100644 --- a/boards/95.c +++ b/boards/95.c @@ -15,10 +15,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" +#include "../ines.h" static uint8 lastA; static uint8 DRegs[8]; @@ -78,7 +79,7 @@ static DECLFW(Mapper95_write) } } -static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A) +static void dragonbust_ppu(uint32 A) { static int last=-1; static uint8 z; diff --git a/boards/Makefile b/boards/Makefile index 7af1889..b14ee56 100644 --- a/boards/Makefile +++ b/boards/Makefile @@ -1,51 +1,88 @@ +B_C += boards/01-222.c +B_C += boards/103.c +B_C += boards/106.c +B_C += boards/108.c B_C += boards/112.c +B_C += boards/116.c B_C += boards/117.c +B_C += boards/120.c +B_C += boards/121.c +B_C += boards/15.c B_C += boards/164.c +B_C += boards/175.c +B_C += boards/176.c +B_C += boards/177.c +B_C += boards/178.c +B_C += boards/179.c B_C += boards/183.c B_C += boards/185.c B_C += boards/186.c B_C += boards/187.c B_C += boards/189.c +B_C += boards/199.c B_C += boards/208.c B_C += boards/222.c +B_C += boards/23.c B_C += boards/235.c +B_C += boards/253.c +B_C += boards/3d-block.c +B_C += boards/411120-c.c +B_C += boards/43.c B_C += boards/57.c +B_C += boards/603-5052.c +B_C += boards/68.c B_C += boards/8157.c B_C += boards/8237.c +B_C += boards/830118C.c B_C += boards/88.c B_C += boards/90.c B_C += boards/95.c +B_C += boards/a9711.c +B_C += boards/a9746.c +B_C += boards/addrlatch.c +B_C += boards/ax5705.c +B_C += boards/bandai.c B_C += boards/bmc13in1jy110.c B_C += boards/bmc42in1r.c B_C += boards/bmc64in1nr.c B_C += boards/bmc70in1.c -B_C += boards/bmcgk192.c B_C += boards/bonza.c -B_C += boards/cc21.c +B_C += boards/bs-5.c B_C += boards/datalatch.c B_C += boards/deirom.c B_C += boards/dream.c +B_C += boards/__dummy_mapper.c +B_C += boards/edu2000.c B_C += boards/fk23c.c +B_C += boards/ghostbusters63in1.c +B_C += boards/gs-2004.c +B_C += boards/gs-2013.c B_C += boards/h2288.c B_C += boards/karaoke.c B_C += boards/kof97.c B_C += boards/konami-qtai.c +B_C += boards/ks7032.c B_C += boards/malee.c B_C += boards/mmc1.c B_C += boards/mmc3.c B_C += boards/mmc5.c +B_C += boards/n-c22m.c B_C += boards/n106.c +B_C += boards/n625092.c B_C += boards/novel.c +B_C += boards/onebus.c B_C += boards/sachen.c +B_C += boards/sc-127.c B_C += boards/sheroes.c B_C += boards/sl1632.c -B_C += boards/sonic5.c +B_C += boards/smb2j.c B_C += boards/subor.c B_C += boards/super24.c B_C += boards/supervision.c +B_C += boards/t-227-1.c B_C += boards/t-262.c B_C += boards/tengen.c -B_C += boards/__dummy_mapper.c +B_C += boards/tf-1201.c MUOBJS += $(patsubst %.c,%.o,$(B_C)) diff --git a/boards/__dummy_mapper.c b/boards/__dummy_mapper.c index 6bb703c..f56736d 100644 --- a/boards/__dummy_mapper.c +++ b/boards/__dummy_mapper.c @@ -1,97 +1,103 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint8 reg[8]; -/* -static uint8 *WRAM=NULL; -static uint32 WRAMSIZE; -static uint8 *CHRRAM=NULL; -static uint32 CHRRAMSIZE; -*/ - -static SFORMAT StateRegs[]= -{ - {reg, 8, "REGS"}, - {0} -}; - -static void Sync(void) -{ -} - -static DECLFW(MNNNWrite) -{ -} - -static void MNNNPower(void) -{ - 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(void) -{ - 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; -/* - CHRRAMSIZE=8192; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); - SetupCartPRGMapping(0x10,CHRRAM,CHRRAMSIZE,1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "WRAM"); -*/ -/* - 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 uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; +*/ + +static SFORMAT StateRegs[]= +{ + {reg, 8, "REGS"}, + {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(void) +{ + 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; +/* + 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; + } +*/ + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/sonic5.c b/boards/a9711.c similarity index 51% rename from boards/sonic5.c rename to boards/a9711.c index 4a55d0d..3fb5460 100644 --- a/boards/sonic5.c +++ b/boards/a9711.c @@ -1,73 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" -#include "mmc3.h" - -//static uint8 m_perm[8] = {0, 1, 0, 3, 0, 5, 6, 7}; - -static void UNLSonicPW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - { - uint8 bank=EXPREGS[0]&0x1F; - if(EXPREGS[0]&0x20) - setprg32(0x8000,bank>>2); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,V&0x3F); -} - -/* -static DECLFW(UNLSonicWrite8000) -{ - if(V&0x80) - MMC3_CMDWrite(A,V); - else - MMC3_CMDWrite(A,m_perm[V&7]); -} -*/ - -static DECLFW(UNLSonicWriteLo) -{ - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); -} - -static void UNLSonicPower(void) -{ - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; - GenMMC3Power(); - SetWriteHandler(0x5000,0x5FFF,UNLSonicWriteLo); -// SetWriteHandler(0x8000,0x8000,UNLSonicWrite8000); -} - -void UNLSonic_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap=UNLSonicPW; - info->Power=UNLSonicPower; - 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 + */ + +#include "mapinc.h" +#include "mmc3.h" + +//static uint8 m_perm[8] = {0, 1, 0, 3, 0, 5, 6, 7}; + +static void UNLA9711PW(uint32 A, uint8 V) +{ + if((EXPREGS[0]&0xFF) == 0x37) + { + setprg8(0x8000, 0x13); + setprg8(0xA000, 0x13); + setprg8(0xC000, 0x13); + setprg8(0xE000, 0x0); +// uint8 bank=EXPREGS[0]&0x1F; +// if(EXPREGS[0]&0x20) +// setprg32(0x8000,bank>>2); +// else +// { +// setprg16(0x8000,bank); +// setprg16(0xC000,bank); +// } + } + else + setprg8(A,V&0x3F); +} + +//static DECLFW(UNLA9711Write8000) +//{ +// FCEU_printf("bs %04x %02x\n",A,V); +// if(V&0x80) +// MMC3_CMDWrite(A,V); +// else +// MMC3_CMDWrite(A,m_perm[V&7]); +// if(V!=0x86) MMC3_CMDWrite(A,V); +//} + +static DECLFW(UNLA9711WriteLo) +{ + FCEU_printf("bs %04x %02x\n",A,V); + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); +} + +static void UNLA9711Power(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x5FFF,UNLA9711WriteLo); +// SetWriteHandler(0x8000,0xbfff,UNLA9711Write8000); +} + +void UNLA9711_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=UNLA9711PW; + info->Power=UNLA9711Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/boards/a9746.c b/boards/a9746.c new file mode 100644 index 0000000..3522336 --- /dev/null +++ b/boards/a9746.c @@ -0,0 +1,186 @@ + +/* 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 chr_cmd, prg_cmd, mirror; +static uint8 chr_reg[6], prg_reg[4]; + +static SFORMAT StateRegs[]= +{ + {&chr_cmd, 1, "CHRCMD"}, + {&prg_cmd, 1, "PRGCMD"}, + {&mirror, 1, "MIRR"}, + {chr_reg, 6, "CREGS"}, + {prg_reg, 4, "PREGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x8000, prg_reg[0]); + setprg8(0xA000, prg_reg[1]); + setprg8(0xC000, prg_reg[2]); + setprg8(0xE000, prg_reg[3]); + + setchr2(0x0000, chr_reg[0]); + setchr2(0x0800, chr_reg[1]); + setchr1(0x1000, chr_reg[2]); + setchr1(0x1400, chr_reg[3]); + setchr1(0x1800, chr_reg[4]); + setchr1(0x1c00, chr_reg[5]); + + setmirror(mirror); +} + +static DECLFW(UNLA9746Write) +{ + uint8 bits_rev; +// FCEU_printf("write raw %04x:%02x\n",A,V); + switch (A&0xE003) + { +// case 0xA000: mirror = V; break; + case 0x8000: chr_cmd = V; prg_cmd = 0; break; + case 0x8002: prg_cmd = V; chr_cmd = 0; break; + case 0x8001: bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1); +// if(prg_cmd>0x23) +// prg_reg[(0x26-prg_cmd)&3] = bits_rev; + switch(chr_cmd) + { + case 0x08: chr_reg[0] = (V << 3); break; + case 0x09: chr_reg[0] = chr_reg[0]|(V >> 2); break; + case 0x0e: chr_reg[1] = (V << 3); break; + case 0x0d: chr_reg[1] = chr_reg[1]|(V >> 2); break; + case 0x12: chr_reg[2] = (V << 4); break; + case 0x11: chr_reg[2] = chr_reg[2]|(V >> 1); FCEU_printf("Sync CHR 0x1000:%02x\n",chr_reg[2]); break; + case 0x16: chr_reg[3] = (V << 4); break; + case 0x15: chr_reg[3] = chr_reg[3]|(V >> 1); break; + case 0x1a: chr_reg[4] = (V << 4); break; + case 0x19: chr_reg[4] = chr_reg[4]|(V >> 1); break; + case 0x1e: chr_reg[5] = (V << 4); break; + case 0x1d: chr_reg[5] = chr_reg[5]|(V >> 1); break; + } + Sync(); + break; + } +} + +static void UNLA9746Power(void) +{ + prg_reg[2]=~1; + prg_reg[3]=~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xbfff,UNLA9746Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLA9746_Init(CartInfo *info) +{ + info->Power=UNLA9746Power; + 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" +#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/boards/addrlatch.c b/boards/addrlatch.c new file mode 100644 index 0000000..4b70d6e --- /dev/null +++ b/boards/addrlatch.c @@ -0,0 +1,172 @@ +/* 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 void(*WSync)(void); +static readfunc defread; + +static DECLFW(LatchWrite) +{ + FCEU_printf("%04x:%02x\n",A,V); + latche=A; + WSync(); +} + +static void LatchReset(void) +{ + latche=latcheinit; + WSync(); +} + +static void LatchPower(void) +{ + latche=latcheinit; + WSync(); + SetReadHandler(0x8000,0xFFFF,defread); + SetWriteHandler(addrreg0,addrreg1,LatchWrite); +} + +static void StateRestore(int version) +{ + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 init, uint16 adr0, uint16 adr1) +{ + latcheinit=init; + addrreg0=adr0; + addrreg1=adr1; + WSync=proc; + if(func) + defread=func; + else + defread=CartBR; + info->Power=LatchPower; + info->Reset=LatchReset; + GameStateRestore=StateRestore; + AddExState(&latche, 2, 0, "LATC"); +} + +//------------------ UNLCC21 --------------------------- + +static void UNLCC21Sync(void) +{ + setprg32(0x8000,0); + setchr8(latche&1); + setmirror(MI_0+((latche&2)>>1)); +} + +void UNLCC21_Init(CartInfo *info) +{ + Latch_Init(info, UNLCC21Sync, 0, 0, 0x8000, 0xFFFF); +} + +//------------------ BMCD1038 --------------------------- + +static uint8 dipswitch; +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, 0, 0x8000, 0xFFFF); + info->Reset=BMCD1038Reset; + 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, 0, 0, 0x8000, 0xFFFF); +} + +//------------------ Map 200 --------------------------- + +static void M200Sync(void) +{ +// FCEU_printf("A\n"); + setprg16(0x8000,latche&7); + setprg16(0xC000,latche&7); + setchr8(latche&7); + setmirror((latche&8)>>3); +} + +void Mapper200_Init(CartInfo *info) +{ + Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF); +} + +//------------------ 190in1 --------------------------- + +static void BMC190in1Sync(void) +{ + setprg16(0x8000,(latche>>2)&0x07); + setprg16(0xC000,(latche>>2)&0x07); + setchr8((latche>>2)&0x07); + setmirror((latche&1)^1); +} + +void BMC190in1_Init(CartInfo *info) +{ + Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF); +} + diff --git a/boards/ax5705.c b/boards/ax5705.c new file mode 100644 index 0000000..66f1498 --- /dev/null +++ b/boards/ax5705.c @@ -0,0 +1,122 @@ +/* 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} +}; + +/* +static void UNLAX5705IRQ(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]); + 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((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; +// 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; + } + 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/boards/bandai.c b/boards/bandai.c new file mode 100644 index 0000000..8468aad --- /dev/null +++ b/boards/bandai.c @@ -0,0 +1,176 @@ +/* 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 + * + */ + +//Famicom Jump 2 should get transformed to m153 +//All other games are not supporting EEPROM saving right now. +//We may need to distinguish between 16 and 159 in order to know the EEPROM configuration. +//Until then, we just return 0x00 from the EEPROM read + +#include "mapinc.h" + +static uint8 reg[16], is153; +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} +}; + +static void BandaiIRQHook(int a) +{ + if(IRQa) + { + IRQCount -= a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = -1; + } + } +} + +static void BandaiSync(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; + BandaiSync(); + } + 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: break;// Serial EEPROM control port + } +} + +DECLFR(BandaiRead) +{ + return 0; +} + +static void BandaiPower(void) +{ + BandaiSync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0xFFFF,BandaiWrite); + SetReadHandler(0x6000,0x7FFF,BandaiRead); +} + +static void M153Power(void) +{ + BandaiSync(); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BandaiWrite); +} + + +static void M153Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + BandaiSync(); +} + +void Mapper16_Init(CartInfo *info) +{ + is153=0; + info->Power=BandaiPower; + MapIRQHook=BandaiIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper159_Init(CartInfo *info) +{ + Mapper16_Init(info); +} + + +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); +} diff --git a/boards/bmc13in1jy110.c b/boards/bmc13in1jy110.c index 6f11f8a..89aa4fb 100644 --- a/boards/bmc13in1jy110.c +++ b/boards/bmc13in1jy110.c @@ -1,103 +1,103 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * BMC 42-in-1 reset switch - */ - -#include "mapinc.h" - -static uint8 bank_mode; -static uint8 bank_value; -static uint8 prgb[4]; -static SFORMAT StateRegs[]= -{ - {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 + */ + +#include "mapinc.h" + +static uint8 bank_mode; +static uint8 bank_value; +static uint8 prgb[4]; +static SFORMAT StateRegs[]= +{ + {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/boards/bmc42in1r.c b/boards/bmc42in1r.c index 8084847..bcbdfc1 100644 --- a/boards/bmc42in1r.c +++ b/boards/bmc42in1r.c @@ -1,87 +1,76 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * BMC 42-in-1 reset switch - */ - -#include "mapinc.h" - -static uint8 hrd_sw; -static uint8 latche; -static SFORMAT StateRegs[]= -{ - {&latche, 1, "LATCHE"}, - {&hrd_sw, 1, "HRDSW"}, - {0} -}; - -static void Sync(void) -{ - if(!(latche&0x20)) - setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f); - else - { - setprg16r(hrd_sw,0x8000,latche&0x1f); - setprg16r(hrd_sw,0xC000,latche&0x1f); - } - switch((latche>>6)&3) - { - case 0: setmirrorw(0,0,0,1); break; - case 1: setmirror(MI_V); break; - case 2: setmirror(MI_H); break; - case 3: setmirror(MI_1); break; - } -} - -static DECLFW(BMC42in1rWrite) -{ - latche=V; - Sync(); -} - -static void BMC42in1rReset(void) -{ - hrd_sw^=1; - Sync(); -} - -static void BMC42in1rPower(void) -{ - latche=0x00; - hrd_sw=0; - setchr8(0); - Sync(); - SetWriteHandler(0x8000,0xFFFF,BMC42in1rWrite); - SetReadHandler(0x8000,0xFFFF,CartBR); -} - -static void StateRestore(int version) -{ - Sync(); -} - -void BMC42in1r_Init(CartInfo *info) -{ - info->Power=BMC42in1rPower; - info->Reset=BMC42in1rReset; - 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 + * it seems now, mapper not reset-based, + * tested on real hardware and it does menus switch by pressing just Select, not Reset + * new registers behaviour proven this too + * + */ + +#include "mapinc.h" + +static uint8 latche[2]; +static SFORMAT StateRegs[]= +{ + {&latche, sizeof(latche), "LATCHE"}, + {0} +}; + +static void Sync(void) +{ + uint8 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] = 0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,M226Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper226_Init(CartInfo *info) +{ + info->Power=M226Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + diff --git a/boards/bmc64in1nr.c b/boards/bmc64in1nr.c index af663ba..4f90c9f 100644 --- a/boards/bmc64in1nr.c +++ b/boards/bmc64in1nr.c @@ -1,93 +1,93 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * BMC 42-in-1 reset switch - */ - -#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 + */ + +#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/boards/bmc70in1.c b/boards/bmc70in1.c index 9d4eb28..75baaa5 100644 --- a/boards/bmc70in1.c +++ b/boards/bmc70in1.c @@ -1,116 +1,130 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint8 is_large_banks; -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"}, - {&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)|0x06); - else - return CartBR((A&0xFFF0)|0x0d); - 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 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; - info->Power=BMC70in1Power; - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void BMC70in1B_Init(CartInfo *info) -{ - is_large_banks=1; - info->Power=BMC70in1Power; - 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, "DIPSW"}, + {&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); +// else +// return CartBR((A&0xFFF0)|hw_switch); + 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/boards/bonza.c b/boards/bonza.c index ba390e6..a618f90 100644 --- a/boards/bonza.c +++ b/boards/bonza.c @@ -1,139 +1,132 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint8 prg_reg; -static uint8 chr_reg; - -static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt; -static uint16 sim0data; -static uint8 sim0array[128] = -{ - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA, -}; - -static SFORMAT StateRegs[]= -{ - {&prg_reg, 1, "PREG"}, - {&chr_reg, 1, "CREG"}, - {0} -}; - -static void Sync(void) -{ - setprg32(0x8000, prg_reg); - setchr8(chr_reg); -} - -static void StateRestore(int version) -{ - Sync(); -} - -static DECLFW(M216WriteHi) -{ -// FCEU_printf("%04x:%04x\n",A,V); - prg_reg=A&1; - chr_reg=(A&0x0E)>>1; - Sync(); -} - -static DECLFW(M216Write5000) -{ -// FCEU_printf("WRITE: %04x:%04x\n",A,V); - sim0reg=V; - if(!sim0reg) - { - sim0bit=sim0byte=sim0parity=0; - sim0data=sim0array[0]; - sim0bcnt=0x80; - } - else if(sim0reg&0x20) - { - sim0bcnt=0x20; - } -} - -static DECLFR(M216Read5000) -{ - if(sim0reg&0x60) - { - sim0reg=(sim0reg^(sim0reg<<1))&0x40; - return sim0reg; - } - else - { - uint8 sim0out=0; - if(sim0bit<8) - { -// sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1; - sim0out=(sim0data&1)<<6; - sim0data>>=1; - sim0bit++; - sim0parity+=sim0data; - } - else if(sim0bit==8) - { - sim0bit++; - sim0out=sim0parity&1; - } - else if(sim0bit==9) - { - if(sim0byte==sim0bcnt) - sim0out=0x60; - else - { - sim0bit=0; - sim0byte++; - sim0data=sim0array[sim0byte]; - sim0out=0; - } - } -// FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte); - return sim0out; - } -} - -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} +}; + +/* + +_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 +*/ + +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 }; + +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/boards/bs-5.c b/boards/bs-5.c new file mode 100644 index 0000000..ad7a82a --- /dev/null +++ b/boards/bs-5.c @@ -0,0 +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 + */ + +#include "mapinc.h" + +static uint8 reg_prg[4]; +static uint8 reg_chr[4]; +static uint8 dip_switch; + +static SFORMAT StateRegs[]= +{ + {reg_prg, 4, "PREGS"}, + {reg_chr, 4, "CREGS"}, + {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/boards/datalatch.c b/boards/datalatch.c index b3452fe..4a61f04 100644 --- a/boards/datalatch.c +++ b/boards/datalatch.c @@ -15,17 +15,24 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" +#include "../ines.h" -static uint8 latche, latcheinit; +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(); } @@ -34,23 +41,52 @@ static void LatchPower(void) { latche=latcheinit; WSync(); - SetReadHandler(0x8000,0xFFFF,CartBR); + if(WRAM) + { + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + } + 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(); } -void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1) +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"); } @@ -66,21 +102,40 @@ static void CPROMSync(void) void CPROM_Init(CartInfo *info) { - Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF); + Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); } -//------------------ CNROM --------------------------- +//------------------ Map 184 --------------------------- -static void CNROMSync(void) +static void M184Sync(void) { - setchr8(latche&3); + setchr4(0x0000,latche); + setchr4(0x1000,latche>>4); setprg16(0x8000,0); setprg16(0xC000,1); } +void Mapper184_Init(CartInfo *info) +{ + Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ CNROM --------------------------- + +static void CNROMSync(void) +{ + //mbg 8/10/08 - fixed this so that large homebrew roms would work. + //setchr8(latche&3); + setchr8(latche); + setprg16(0x8000,0); + setprg16(0xC000,1); + setprg8r(0x10,0x6000,0); // Hayauchy IGO uses 2Kb or RAM +} + void CNROM_Init(CartInfo *info) { - Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF); + bool busc = MasterRomInfoParams.ContainsKey("busc"); + Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, busc?1:0); } //------------------ ANROM --------------------------- @@ -94,7 +149,7 @@ static void ANROMSync() void ANROM_Init(CartInfo *info) { - Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF); + Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF, 0, 0); } //------------------ Map 70 --------------------------- @@ -108,7 +163,7 @@ static void M70Sync() void Mapper70_Init(CartInfo *info) { - Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF); + Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); } //------------------ Map 152 --------------------------- @@ -123,7 +178,7 @@ static void M152Sync() void Mapper152_Init(CartInfo *info) { - Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF); + Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); } //------------------ Map 78 --------------------------- @@ -138,7 +193,7 @@ static void M78Sync() void Mapper78_Init(CartInfo *info) { - Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF); + Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); } //------------------ MHROM --------------------------- @@ -150,13 +205,19 @@ static void MHROMSync(void) } void MHROM_Init(CartInfo *info) -{ - Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF); +{ + Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); } void Mapper140_Init(CartInfo *info) -{ - Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF); +{ + Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); +} + +void Mapper240_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x4020, 0x5FFF, 0, 0); + // need SRAM. } //------------------ Map 87 --------------------------- @@ -165,12 +226,27 @@ static void M87Sync(void) { setprg16(0x8000,0); setprg16(0xC000,1); - setchr8(latche>>1); + setchr8(((latche>>1)&1)|((latche<<1)&2)); +// setchr8(latche); } void Mapper87_Init(CartInfo *info) -{ - Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF); +{ + Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); +} + +//------------------ Map 101 --------------------------- + +static void M101Sync(void) +{ + setprg16(0x8000,0); + setprg16(0xC000,1); + setchr8(latche); +} + +void Mapper101_Init(CartInfo *info) +{ + Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0); } //------------------ Map 11 --------------------------- @@ -182,15 +258,40 @@ static void M11Sync(void) } void Mapper11_Init(CartInfo *info) -{ - Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF); +{ + Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); } void Mapper144_Init(CartInfo *info) -{ - Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF); +{ + Latch_Init(info, M11Sync, 0, 0x8001, 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 36 --------------------------- + +static void M36Sync(void) +{ + setprg32(0x8000,latche>>4); + setchr8((latche)&0xF); +} + +void Mapper36_Init(CartInfo *info) +{ + Latch_Init(info, M36Sync, 0, 0x8400, 0xfffe, 0, 0); +} //------------------ UNROM --------------------------- static void UNROMSync(void) @@ -202,7 +303,7 @@ static void UNROMSync(void) void UNROM_Init(CartInfo *info) { - Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF); + Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1); } //------------------ Map 93 --------------------------- @@ -216,7 +317,7 @@ static void SSUNROMSync(void) void SUNSOFT_UNROM_Init(CartInfo *info) { - Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF); + Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); } //------------------ Map 94 --------------------------- @@ -230,7 +331,21 @@ static void M94Sync(void) void Mapper94_Init(CartInfo *info) { - Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF); + Latch_Init(info, M94Sync, 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 107 --------------------------- @@ -243,7 +358,49 @@ static void M107Sync(void) void Mapper107_Init(CartInfo *info) { - Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF); + 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); +} + +//------------------ 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); } //------------------ NROM --------------------------- @@ -251,16 +408,22 @@ void Mapper107_Init(CartInfo *info) #ifdef DEBUG_MAPPER static DECLFW(WriteHandler) { - FCEU_printf("$%04x:$%02x\n",A,V); + 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); + #ifdef DEBUG_MAPPER SetWriteHandler(0x4020,0xFFFF,WriteHandler); #endif @@ -269,4 +432,15 @@ static void NROMPower(void) 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"); } diff --git a/boards/deirom.c b/boards/deirom.c index 7a1ed43..2d28bd0 100644 --- a/boards/deirom.c +++ b/boards/deirom.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -32,9 +32,9 @@ static SFORMAT DEI_StateRegs[]= static void Sync(void) { + int x; setchr2(0x0000,DRegs[0]); setchr2(0x0800,DRegs[1]); - int x; for(x=0;x<4;x++) setchr1(0x1000+(x<<10),DRegs[2+x]); setprg8(0x8000,DRegs[6]); diff --git a/boards/dream.c b/boards/dream.c index 7e1d563..d2a9cb8 100644 --- a/boards/dream.c +++ b/boards/dream.c @@ -1,56 +1,56 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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, "LATCH"); -} +/* 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, "LATCH"); +} diff --git a/boards/edu2000.c b/boards/edu2000.c new file mode 100644 index 0000000..36dcb5d --- /dev/null +++ b/boards/edu2000.c @@ -0,0 +1,84 @@ +/* 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); + 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/boards/fk23c.c b/boards/fk23c.c index abf0859..c869680 100644 --- a/boards/fk23c.c +++ b/boards/fk23c.c @@ -1,112 +1,290 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 unromchr; - -static void BMCFK23CCW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x40) - setchr8((EXPREGS[2]&0xFC)|unromchr); - else - { - uint16 base=(EXPREGS[2]&0x7F)<<3; - setchr1(A,V|base); - if(EXPREGS[3]&2) - { - setchr1(0x0400,EXPREGS[6]|base); - setchr1(0x0C00,EXPREGS[7]|base); - } - } -} - -static void BMCFK23CPW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&4) - setprg32(0x8000,EXPREGS[1]>>1); - else - { - if(EXPREGS[0]&2) - setprg8(A,(V&(0x3F>>(EXPREGS[0]&3)))|(EXPREGS[1]<<1)); - else - setprg8(A,V); - if(EXPREGS[3]&2) - { - setprg8(0xC000,EXPREGS[4]); - setprg8(0xE000,EXPREGS[5]); - } - } -} - -static DECLFW(BMCFK23C8003Write) -{ - if(EXPREGS[0]&0x40) - { - unromchr=V&3; - FixMMC3CHR(MMC3_cmd); - } - else - { - if((A==0x8001)&&(EXPREGS[3]&2&&MMC3_cmd&8)) - { - EXPREGS[4|(MMC3_cmd&3)]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } - else - MMC3_CMDWrite(A,V); - } -} - -static DECLFW(BMCFK23CWrite) -{ - EXPREGS[A&3]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void BMCFK23CReset(void) -{ - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; - EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; - MMC3RegReset(); -} - -static void BMCFK23CPower(void) -{ - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; - EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; - GenMMC3Power(); - SetWriteHandler(0x5ff0,0x5fff,BMCFK23CWrite); - SetWriteHandler(0x8000,0x8003,BMCFK23C8003Write); -} - -void BMCFK23C_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); - cwrap=BMCFK23CCW; - pwrap=BMCFK23CPW; - info->Power=BMCFK23CPower; - info->Reset=BMCFK23CReset; - AddExState(EXPREGS, 8, 0, "EXPR"); - AddExState(&unromchr, 1, 0, "UNCHR"); -} +/* 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" +#include "../ines.h" + +static bool is_BMCFK23CA; +static uint8 unromchr; +static uint32 dipswitch; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSize; + +static void BMCFK23CCW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr8(EXPREGS[2]|unromchr); + else if(EXPREGS[0]&0x20) { + setchr1r(0x10, A, V); + } + else + { + uint16 base=(EXPREGS[2]&0x7F)<<3; + if(EXPREGS[3]&2) + { + int cbase=(MMC3_cmd&0x80)<<5; + setchr1(A,V|base); + setchr1(0x0000^cbase,DRegBuf[0]|base); + setchr1(0x0400^cbase,EXPREGS[6]|base); + setchr1(0x0800^cbase,DRegBuf[1]|base); + setchr1(0x0c00^cbase,EXPREGS[7]|base); + } + else + setchr1(A,V|base); + } +} + +//some games are wired differently, and this will need to be changed. +//all the WXN games require prg_bonus = 1, and cah4e3's multicarts require prg_bonus = 0 +//we'll populate this from a game database +static int prg_bonus; +static int prg_mask; + +//prg_bonus = 0 +//4-in-1 (FK23C8021)[p1][!].nes +//4-in-1 (FK23C8033)[p1][!].nes +//4-in-1 (FK23C8043)[p1][!].nes +//4-in-1 (FK23Cxxxx, S-0210A PCB)[p1][!].nes + +//prg_bonus = 1 +//[m176]大富翁2-上海大亨.wxn.nes +//[m176]宠物翡翠.fix.nes +//[m176]格兰帝亚.wxn.nes +//[m176]梦幻之星.wxn.nes +//[m176]水浒神兽.fix.nes +//[m176]西楚霸王.fix.nes +//[m176]超级大富翁.wxn.nes +//[m176]雄霸天下.wxn.nes + +//works as-is under virtuanes m176 +//[m176]三侠五义.wxn.nes +//[m176]口袋金.fix.nes +//[m176]爆笑三国.fix.nes + +//needs other tweaks +//[m176]三国忠烈传.wxn.nes +//[m176]破釜沉舟.fix.nes + +//PRG wrapper +static void BMCFK23CPW(uint32 A, uint8 V) +{ + uint32 bank = (EXPREGS[1] & 0x1F); + uint32 hiblock = ((EXPREGS[0] & 8) << 4)|((EXPREGS[0] & 0x80) << 1)|(UNIFchrrama?((EXPREGS[2] & 0x40)<<3):0); + uint32 block = (EXPREGS[1] & 0x60) | hiblock; + uint32 extra = (EXPREGS[3] & 2); + + if((EXPREGS[0]&7)==4) + setprg32(0x8000,EXPREGS[1]>>1); + else if ((EXPREGS[0]&7)==3) + { + setprg16(0x8000,EXPREGS[1]); + setprg16(0xC000,EXPREGS[1]); + } + else + { + if(EXPREGS[0]&3) + { + uint32 blocksize = (6)-(EXPREGS[0]&3); + uint32 mask = (1<Power=BMCFK23CPower; + info->Reset=BMCFK23CReset; + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UNCHR"); + AddExState(&dipswitch, 1, 0, "DIPSW"); + + prg_bonus = 1; + if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end()) + prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str()); + + prg_mask = 0x7F>>(prg_bonus); +} + +void BMCFK23CA_Init(CartInfo *info) +{ + is_BMCFK23CA = true; + + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap=BMCFK23CCW; + pwrap=BMCFK23CPW; + info->Power=BMCFK23CAPower; + info->Reset=BMCFK23CReset; + info->Close=BMCFK23CAClose; + + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CRAM"); + + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UNCHR"); + AddExState(&dipswitch, 1, 0, "DIPSW"); + + prg_bonus = 1; + if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end()) + prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str()); + prg_mask = 0x7F>>(prg_bonus); +} diff --git a/boards/ghostbusters63in1.c b/boards/ghostbusters63in1.c new file mode 100644 index 0000000..627f16d --- /dev/null +++ b/boards/ghostbusters63in1.c @@ -0,0 +1,106 @@ +/* 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, "CHRROM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/gs-2004.c b/boards/gs-2004.c new file mode 100644 index 0000000..574ed97 --- /dev/null +++ b/boards/gs-2004.c @@ -0,0 +1,69 @@ +/* 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/boards/gs-2013.c b/boards/gs-2013.c new file mode 100644 index 0000000..1b4d37b --- /dev/null +++ b/boards/gs-2013.c @@ -0,0 +1,69 @@ +/* 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/boards/h2288.c b/boards/h2288.c index 22bc7c2..7786daf 100644 --- a/boards/h2288.c +++ b/boards/h2288.c @@ -1,89 +1,89 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 DECLFR(H2288Read) -{ - int bit; - bit=(A&1)^1; - bit&=((A>>8)&1); - bit^=1; - return((X.DB&0xFE)|bit); -} - -static void H2288Power(void) -{ - EXPREGS[0]=EXPREGS[1]=0; - GenMMC3Power(); - SetReadHandler(0x5000,0x5FFF,H2288Read); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x5000,0x5FFF,H2288WriteLo); - SetWriteHandler(0x8000,0x8FFF,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 DECLFR(H2288Read) +{ + int bit; + bit=(A&1)^1; + bit&=((A>>8)&1); + bit^=1; + return((X.DB&0xFE)|bit); +} + +static void H2288Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetReadHandler(0x5000,0x5FFF,H2288Read); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0x5FFF,H2288WriteLo); + SetWriteHandler(0x8000,0x8FFF,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/boards/karaoke.c b/boards/karaoke.c index e089cda..dfb4cc8 100644 --- a/boards/karaoke.c +++ b/boards/karaoke.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/boards/kof97.c b/boards/kof97.c index 4e477d3..7bb63ee 100644 --- a/boards/kof97.c +++ b/boards/kof97.c @@ -1,50 +1,50 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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/boards/konami-qtai.c b/boards/konami-qtai.c index b78d8e3..83630a6 100644 --- a/boards/konami-qtai.c +++ b/boards/konami-qtai.c @@ -1,132 +1,242 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * CAI Shogakko no Sansu - */ - -#include "mapinc.h" - -static uint8 *CHRRAM=NULL; -static uint8 SWRAM[4096]; - -static uint8 regs[16]; -static uint8 WRAM[4096]; -static SFORMAT StateRegs[]= -{ - {®s, 16, "REGS"}, - {WRAM, 4096, "WRAM"}, - {0} -}; - -static void Sync(void) -{ - if(regs[5]&0x40) - { - setchr4r(0,0x1000,regs[5]&0x3F); - } - else - { - setchr4r(0x10,0x0000,regs[5]); - setchr4r(0x10,0x1000,regs[5]^1); - } - setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F)); - setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F)); - setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F)); - setprg8r(1,0xE000,~0); - setmirror((regs[0xA]&3)); -} - -static DECLFW(M190Write) -{ -// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp); - regs[(A&0x0F00)>>8]=V; - Sync(); -} - -static DECLFR(M190Read) -{ -// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); - return regs[(A&0x0F00)>>8]; -} - -static DECLFR(AWRAM) -{ - return(WRAM[A-0x7000]); -} -static DECLFW(BWRAM) -{ - WRAM[A-0x7000]=V; -} - -static DECLFR(ASWRAM) -{ - return(SWRAM[A-0x6000]); -} -static DECLFW(BSWRAM) -{ - SWRAM[A-0x6000]=V; -} - -static void M190Power(void) -{ - setvram8(CHRRAM); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,M190Write); -// SetReadHandler(0xDA00,0xDA00,M190Read); -// SetReadHandler(0xDB00,0xDB00,M190Read); - SetReadHandler(0xDC00,0xDC00,M190Read); - SetReadHandler(0xDD00,0xDD00,M190Read); - SetReadHandler(0x7000,0x7FFF,AWRAM); - SetWriteHandler(0x7000,0x7FFF,BWRAM); - SetReadHandler(0x6000,0x6FFF,ASWRAM); - SetWriteHandler(0x6000,0x6FFF,BSWRAM); -#ifdef ASM_6502 - Page[14]=Page[15]=WRAM-0x7000; - Page[12]=Page[13]=SWRAM-0x6000; -#endif - Sync(); -} - -static void M190Close(void) -{ - if(CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM=NULL; -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper190_Init(CartInfo *info) -{ - info->Power=M190Power; - info->Close=M190Close; - if(info->battery) - { - info->SaveGame[0]=SWRAM; - info->SaveGameLen[0]=4096; - } - GameStateRestore=StateRestore; - CHRRAM=(uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0x10,CHRRAM,8192,1); - AddExState(CHRRAM, 8192, 0, "CHRRAM"); - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005-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 + * + * CAI Shogakko no Sansu + */ + +#include "mapinc.h" + +static uint8 QTAINTRAM[2048]; +static writefunc old2007wrap; + +static uint16 CHRSIZE = 8192; +static uint16 WRAMSIZE = 8192 + 4096; +static uint8 *CHRRAM=NULL; +static uint8 *WRAM = NULL; + +static uint8 IRQa, K4IRQ; +static uint32 IRQLatch, IRQCount; + +static uint8 regs[16]; +//static uint8 test[8]; +static SFORMAT StateRegs[]= +{ + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {&K4IRQ, 1, "K4IRQ"}, + {regs, 16, "REGS"}, + {0} +}; + +static void chrSync(void) +{ + setchr4r(0x10,0x0000,regs[5]&1); + setchr4r(0x10,0x1000,0); +} + +static void Sync(void) +{ + chrSync(); +// if(regs[0xA]&0x10) +// { +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,0); + setchr1r(0x10,0x1400,1); + setchr1r(0x10,0x1800,2); + setchr1r(0x10,0x1c00,3);*/ +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7); +*/ +// } +// else +// { +/* + setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7); +// } +//*/ +/* setchr1r(1,0x0000,test[0]); + setchr1r(1,0x0400,test[1]); + setchr1r(1,0x0800,test[2]); + setchr1r(1,0x0c00,test[3]); + setchr1r(1,0x1000,test[4]); + setchr1r(1,0x1400,test[5]); + setchr1r(1,0x1800,test[6]); + setchr1r(1,0x1c00,test[7]); +*/ + setprg4r(0x10,0x6000,regs[0]&1); + if(regs[2]>=0x40) + setprg8r(1,0x8000,(regs[2]-0x40)); + else + setprg8r(0,0x8000,(regs[2]&0x3F)); + if(regs[3]>=0x40) + setprg8r(1,0xA000,(regs[3]-0x40)); + else + setprg8r(0,0xA000,(regs[3]&0x3F)); + if(regs[4]>=0x40) + setprg8r(1,0xC000,(regs[4]-0x40)); + else + setprg8r(0,0xC000,(regs[4]&0x3F)); + + setprg8r(1,0xE000,~0); + setmirror(MI_V); +} + +/*static DECLFW(TestWrite) +{ + test[A&7] = V; + Sync(); +}*/ + +static DECLFW(M190Write) +{ +// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp); + regs[(A&0x0F00)>>8]=V; + switch(A) + { + case 0xd600:IRQLatch&=0xFF00;IRQLatch|=V;break; + case 0xd700:IRQLatch&=0x00FF;IRQLatch|=V<<8;break; + case 0xd900:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xd800:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; + } + Sync(); +} + +static DECLFR(M190Read) +{ +// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); + return regs[(A&0x0F00)>>8]+regs[0x0B]; +} +static void VRC5IRQ(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount&0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); +// IRQCount=IRQLatch; + } + } +} + +static void Mapper190_PPU(uint32 A) +{ + if(A>=0x2000) + { + setchr4r(0x10,0x0000,QTAINTRAM[A&0x1FFF]&1); + setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1); + } +// else +// chrSync(); +} + +static DECLFW(M1902007Wrap) +{ + if(A>=0x2000) + { + if(regs[0xA]&1) + QTAINTRAM[A&0x1FFF]=V; + else + old2007wrap(A,V); + } +} + + +static void M190Power(void) +{ +/* test[0]=0; + test[1]=1; + test[2]=2; + test[3]=3; + test[4]=4; + test[5]=5; + test[6]=6; + test[7]=7; +*/ + setprg4r(0x10,0x7000,2); + + old2007wrap=GetWriteHandler(0x2007); + SetWriteHandler(0x2007,0x2007,M1902007Wrap); + + SetReadHandler(0x6000,0xFFFF,CartBR); +// SetWriteHandler(0x5000,0x5007,TestWrite); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,M190Write); + SetReadHandler(0xDC00,0xDC00,M190Read); + SetReadHandler(0xDD00,0xDD00,M190Read); + Sync(); +} + +static void M190Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper190_Init(CartInfo *info) +{ + info->Power=M190Power; + info->Close=M190Close; + GameStateRestore=StateRestore; + + MapIRQHook=VRC5IRQ; + //PPU_hook=Mapper190_PPU; + + CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1); + AddExState(CHRRAM, CHRSIZE, 0, "CHRRAM"); + + 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 - 4096; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/ks7032.c b/boards/ks7032.c new file mode 100644 index 0000000..fcb0eb5 --- /dev/null +++ b/boards/ks7032.c @@ -0,0 +1,94 @@ +/* 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[8], cmd, IRQa; +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) + { +// case 0x8FFF: reg[4]=V; Sync(); break; + case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); break; + case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); break; + case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); break; + case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); break; + case 0xC000: X6502_IRQEnd(FCEU_IQEXT); IRQa=1; break; + case 0xE000: cmd=V&7; break; + case 0xF000: reg[cmd]=V; Sync(); break; + } +} + +static void 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/boards/malee.c b/boards/malee.c index 7feb95e..8c30182 100644 --- a/boards/malee.c +++ b/boards/malee.c @@ -15,19 +15,20 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" static uint8 WRAM[2048]; -static void MALEEReset(void) +static void MALEEPower(void) { setprg2r(0x10,0x7000,0); SetReadHandler(0x8000,0xFFFF,CartBR); SetReadHandler(0x6000,0x67FF,CartBR); SetReadHandler(0x7000,0x77FF,CartBR); + SetWriteHandler(0x7000,0x77FF,CartBW); setprg2r(1,0x6000,0); setprg32(0x8000,0); setchr8(0); @@ -35,7 +36,7 @@ static void MALEEReset(void) void MALEE_Init(CartInfo *info) { - info->Power=MALEEReset; + info->Power=MALEEPower; SetupCartPRGMapping(0x10, WRAM, 2048, 1); AddExState(WRAM, 2048, 0,"RAM"); } diff --git a/boards/mapinc.h b/boards/mapinc.h index 81d4edb..8fa46f4 100644 --- a/boards/mapinc.h +++ b/boards/mapinc.h @@ -1,13 +1,12 @@ #include "../types.h" +#include "../utils/memory.h" #include "../x6502.h" -#include "../fce.h" +#include "../fceu.h" #include "../ppu.h" -#include "../memory.h" #include "../sound.h" #include "../state.h" #include "../cart.h" -#include "../ines.h" #include "../cheat.h" #include "../unif.h" -#include "../svga.h" +#include #include diff --git a/boards/mmc1.c b/boards/mmc1.c index 816a1ed..24a07bc 100644 --- a/boards/mmc1.c +++ b/boards/mmc1.c @@ -1,423 +1,451 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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; - -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) -{ - 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; - //FCEU_DispMessage("%016x",timestampbase+timestamp); - //printf("$%04x:$%02x, $%04x\n",A,V,X.PC); - //DumpMem("out",0xe000,0xffff); - - /* 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; - if(V&0x80) - { - DRegs[0]|=0xC; - BufferShift=Buffer=0; - MMC1PRG(); - lreset=timestampbase+timestamp; - return; - } - Buffer|=(V&1)<<(BufferShift++); - if(BufferShift==5) - { - 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; - default:return(8); - } -} - -static uint32 NWCIRQCount; -static uint8 NWCRec; -#define NWCDIP 0xE - -static void FP_FASTAPASS(1) 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"); -} - -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; -} - -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; + //FCEU_DispMessage("%016x",0,timestampbase+timestamp); +// FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC); + //DumpMem("out",0xe000,0xffff); + + /* 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) + { + 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; + 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); + //mbg 17-jun-08 - this shouldve been cleared to re-initialize save ram + //ch4 10-dec-08 - nope, this souldn't + //mbg 29-mar-09 - no time to debate this, we need to keep from breaking some old stuff. + //we really need to make up a policy for how compatibility and accuracy can be resolved. + memset(WRAM,0,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/boards/mmc3.c b/boards/mmc3.c index bfee5cd..2618db4 100644 --- a/boards/mmc3.c +++ b/boards/mmc3.c @@ -1,1619 +1,1411 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * Copyright (C) 2003 Xodnizel - * Mapper 12 code Copyright (C) 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, - 119,148,165,205,214,215,245,249,250,254 -*/ - -#include "mapinc.h" -#include "mmc3.h" - -uint8 MMC3_cmd; -uint8 *WRAM; -uint8 *CHRRAM; -uint32 CHRRAMSize; -uint8 EXPREGS[8]; /* For bootleg games, mostly. */ - -static uint8 A000B,A001B; -static uint8 DRegBuf[8]; - -#undef IRQCount -#undef IRQLatch -#undef IRQa -uint8 IRQCount,IRQLatch,IRQa; -uint8 IRQReload; - -static SFORMAT MMC3_StateRegs[]= -{ - {DRegBuf, 8, "REGS"}, - {&MMC3_cmd, 1, "CMD"}, - {&A000B, 1, "A000"}, - {&A001B, 1, "A001"}, - {&IRQReload, 1, "IRQR"}, - {&IRQCount, 1, "IRQC"}, - {&IRQLatch, 1, "IRQL"}, - {&IRQa, 1, "IRQA"}, - {0} -}; - -static int mmc3opts=0; -static int wrams; -static int isRevB=1; - -void (*pwrap)(uint32 A, uint8 V); -void (*cwrap)(uint32 A, uint8 V); -void (*mwrap)(uint8 V); - -void GenMMC3Power(void); -void FixMMC3PRG(int V); -void FixMMC3CHR(int V); - -void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); - -// ---------------------------------------------------------------------- -// ------------------------- Generic MM3 Code --------------------------- -// ---------------------------------------------------------------------- - -void FixMMC3PRG(int V) -{ - if(V&0x40) - { - pwrap(0xC000,DRegBuf[6]); - pwrap(0x8000,~1); - } - else - { - pwrap(0x8000,DRegBuf[6]); - pwrap(0xC000,~1); - } - pwrap(0xA000,DRegBuf[7]); - pwrap(0xE000,~0); -} - -void FixMMC3CHR(int V) -{ - int cbase=(V&0x80)<<5; - - cwrap((cbase^0x000),DRegBuf[0]&(~1)); - cwrap((cbase^0x400),DRegBuf[0]|1); - cwrap((cbase^0x800),DRegBuf[1]&(~1)); - cwrap((cbase^0xC00),DRegBuf[1]|1); - - cwrap(cbase^0x1000,DRegBuf[2]); - cwrap(cbase^0x1400,DRegBuf[3]); - cwrap(cbase^0x1800,DRegBuf[4]); - cwrap(cbase^0x1c00,DRegBuf[5]); -} - -void MMC3RegReset(void) -{ - IRQCount=IRQLatch=IRQa=MMC3_cmd=0; - - DRegBuf[0]=0; - DRegBuf[1]=2; - DRegBuf[2]=4; - DRegBuf[3]=5; - DRegBuf[4]=6; - DRegBuf[5]=7; - DRegBuf[6]=0; - DRegBuf[7]=1; - - FixMMC3PRG(0); - FixMMC3CHR(0); -} - -DECLFW(MMC3_CMDWrite) -{ -// FCEU_printf("%04x:%04x\n",A,V); - switch(A&0xE001) - { - case 0x8000: - if((V&0x40) != (MMC3_cmd&0x40)) - FixMMC3PRG(V); - if((V&0x80) != (MMC3_cmd&0x80)) - FixMMC3CHR(V); - MMC3_cmd = V; - break; - case 0x8001: - { - int cbase=(MMC3_cmd&0x80)<<5; - DRegBuf[MMC3_cmd&0x7]=V; - switch(MMC3_cmd&0x07) - { - case 0: cwrap((cbase^0x000),V&(~1)); - cwrap((cbase^0x400),V|1); - break; - case 1: cwrap((cbase^0x800),V&(~1)); - cwrap((cbase^0xC00),V|1); - break; - case 2: cwrap(cbase^0x1000,V); - break; - case 3: cwrap(cbase^0x1400,V); - break; - case 4: cwrap(cbase^0x1800,V); - break; - case 5: cwrap(cbase^0x1C00,V); - break; - case 6: - if(MMC3_cmd&0x40) - pwrap(0xC000,V); - else - pwrap(0x8000,V); - break; - case 7: - pwrap(0xA000,V); - break; - } - } - break; - case 0xA000: - if(mwrap) mwrap(V&1); - break; - case 0xA001: - A001B=V; - Write_IRQFM(0x4017,0x40); - break; - } -} - -DECLFW(MMC3_IRQWrite) -{ -// FCEU_printf("%04x:%04x\n",A,V); - switch(A&0xE001) - { - case 0xC000:IRQLatch=V;break; - case 0xC001:IRQReload=1;break; - case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break; - case 0xE001:IRQa=1;break; - } -} - -static void ClockMMC3Counter(void) -{ - int count = IRQCount; - if(!count || IRQReload) - { - IRQCount = IRQLatch; - IRQReload = 0; - } - else - IRQCount--; - if((count|isRevB) && !IRQCount) - { - if(IRQa) - { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void MMC3_hb(void) -{ - ClockMMC3Counter(); -} - -static void MMC3_hb_KickMasterHack(void) -{ - if(scanline==238) ClockMMC3Counter(); - ClockMMC3Counter(); -} - -static void MMC3_hb_PALStarWarsHack(void) -{ - if(scanline==240) ClockMMC3Counter(); - ClockMMC3Counter(); -} - -void GenMMC3Restore(int version) -{ - if(mwrap) mwrap(A000B&1); - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void GENCWRAP(uint32 A, uint8 V) -{ - if(!UNIFchrrama) setchr1(A,V); -} - -static void GENPWRAP(uint32 A, uint8 V) -{ - setprg8(A,V&0x3F); -} - -static void GENMWRAP(uint8 V) -{ - A000B=V; - setmirror(V^1); -} - -static void GENNOMWRAP(uint8 V) -{ - A000B=V; -} - -static DECLFW(MBWRAM) -{ - WRAM[A-0x6000]=V; -} - -static DECLFR(MAWRAM) -{ - return(WRAM[A-0x6000]); -} - -static DECLFW(MBWRAMMMC6) -{ - WRAM[A&0x3ff]=V; -} - -static DECLFR(MAWRAMMMC6) -{ - return(WRAM[A&0x3ff]); -} - -void GenMMC3Power(void) -{ - if(UNIFchrrama) setchr8(0); - - SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite); - SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite); - SetReadHandler(0x8000,0xFFFF,CartBR); - A001B=A000B=0; - setmirror(1); - if(mmc3opts&1) - { - if(wrams==1024) - { - FCEU_CheatAddRAM(1,0x7000,WRAM); - SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6); - SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6); -#ifdef ASM_6502 - // asm code needs pages to be set again.. - Page[14]=Page[15]=WRAM-0x7000; -#endif - } - else - { - FCEU_CheatAddRAM(wrams>>10,0x6000,WRAM); - SetReadHandler(0x6000,0x6000+wrams-1,MAWRAM); - SetWriteHandler(0x6000,0x6000+wrams-1,MBWRAM); -#ifdef ASM_6502 - { - int addr; - for (addr=0x6000; addr < 0x6000+wrams-0x7ff; addr += 0x800) - { - Page[addr>>11]=WRAM - 0x6000; - } - } -#endif - } - if(!(mmc3opts&2)) - FCEU_dwmemset(WRAM,0,wrams); - } - MMC3RegReset(); - if(CHRRAM) - FCEU_dwmemset(CHRRAM,0,CHRRAMSize); -} - -static void GenMMC3Close(void) -{ - if(CHRRAM) - FCEU_gfree(CHRRAM); - if(WRAM) - FCEU_gfree(WRAM); - CHRRAM=WRAM=NULL; -} - -//static uint16 _a12; -//static void FP_FASTAPASS(1) MMC3_PPU(uint32 A) -//{ -// if(A&0x2000)return; -// if((!_a12)&&(A&0x1000)) -// ClockMMC3Counter(); -// _a12=A&0x1000; -//} - -void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) -{ - pwrap=GENPWRAP; - cwrap=GENCWRAP; - mwrap=GENMWRAP; - - wrams=wram<<10; - - PRGmask8[0]&=(prg>>13)-1; - CHRmask1[0]&=(chr>>10)-1; - CHRmask2[0]&=(chr>>11)-1; - - if(wram) - { - mmc3opts|=1; - WRAM=(uint8*)FCEU_gmalloc(wrams); - AddExState(WRAM, wrams, 0, "WRAM"); - } - - if(battery) - { - mmc3opts|=2; - info->SaveGame[0]=WRAM; - info->SaveGameLen[0]=wrams; - } - -// if(!chr) // duplicated CHR RAM set up -// { -// CHRRAM=(uint8*)FCEU_gmalloc(8192); -// CHRRAMSize=8192; -// SetupCartCHRMapping(0, CHRRAM, 8192, 1); -// AddExState(CHRRAM, 8192, 0, "CHRR"); -// } - - AddExState(MMC3_StateRegs, ~0, 0, 0); - - info->Power=GenMMC3Power; - info->Reset=MMC3RegReset; - info->Close=GenMMC3Close; - - if(info->CRC32 == 0x5104833e) // Kick Master - GameHBIRQHook = MMC3_hb_KickMasterHack; - else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93 - GameHBIRQHook = MMC3_hb_KickMasterHack; - else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master. - GameHBIRQHook = MMC3_hb_PALStarWarsHack; - else - GameHBIRQHook=MMC3_hb; -// PPU_hook=MMC3_PPU; - GameStateRestore=GenMMC3Restore; -} - -// ---------------------------------------------------------------------- -// -------------------------- MMC3 Based Code --------------------------- -// ---------------------------------------------------------------------- - -// ---------------------------- Mapper 4 -------------------------------- - -static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/ - -static void M4Power(void) -{ - GenMMC3Power(); - A000B=(hackm4^1)&1; - setmirror(hackm4); -} - -void Mapper4_Init(CartInfo *info) -{ - int ws=8; - - if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84)) - { - FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); - ws=0; - } - GenMMC3_Init(info,512,256,ws,info->battery); - info->Power=M4Power; - hackm4=info->mirror; -} - -// ---------------------------- Mapper 12 ------------------------------- - -static void M12CW(uint32 A, uint8 V) -{ - setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V); -} - -static DECLFW(M12Write) -{ - EXPREGS[0]=V&0x01; - EXPREGS[1]=(V&0x10)>>4; -} - -static void M12Power(void) -{ - EXPREGS[0]=EXPREGS[1]=0; - GenMMC3Power(); - SetWriteHandler(0x4100,0x5FFF,M12Write); -} - -void Mapper12_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M12CW; - info->Power=M12Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- Mapper 37 ------------------------------- - -static void M37PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]!=2) - V&=0x7; - else - V&=0xF; - V|=EXPREGS[0]<<3; - setprg8(A,V); -} - -static void M37CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x7F; - NV|=EXPREGS[0]<<6; - setchr1(A,NV); -} - -static DECLFW(M37Write) -{ - EXPREGS[0]=(V&6)>>1; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M37Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -static void M37Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M37Write); -} - -void Mapper37_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - pwrap=M37PW; - cwrap=M37CW; - info->Power=M37Power; - info->Reset=M37Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 44 ------------------------------- - -static void M44PW(uint32 A, uint8 V) -{ - uint32 NV=V; - if(EXPREGS[0]>=6) NV&=0x1F; - else NV&=0x0F; - NV|=EXPREGS[0]<<4; - setprg8(A,NV); -} - -static void M44CW(uint32 A, uint8 V) -{ - uint32 NV=V; - if(EXPREGS[0]<6) NV&=0x7F; - NV|=EXPREGS[0]<<7; - setchr1(A,NV); -} - -static DECLFW(M44Write) -{ - if(A&1) - { - EXPREGS[0]=V&7; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } - else - MMC3_CMDWrite(A,V); -} - -static void M44Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0xA000,0xBFFF,M44Write); -} - -void Mapper44_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M44CW; - pwrap=M44PW; - info->Power=M44Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 45 ------------------------------- - -static void M45CW(uint32 A, uint8 V) -{ - if(!UNIFchrrama) - { - uint32 NV=V; - if(EXPREGS[2]&8) - NV&=(1<<((EXPREGS[2]&7)+1))-1; -// else -// NV&=0; - NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4); - setchr1(A,NV); - } -} - -static void M45PW(uint32 A, uint8 V) -{ - V&=(EXPREGS[3]&0x3F)^0x3F; - V|=EXPREGS[1]; - setprg8(A,V); -} - -static DECLFW(M45Write) -{ - if(EXPREGS[3]&0x40) - { - WRAM[A-0x6000]=V; - return; - } - EXPREGS[EXPREGS[4]]=V; - EXPREGS[4]=(EXPREGS[4]+1)&3; - if(!EXPREGS[4]) - { - FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]); - FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n", - (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), - (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), - (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]), - (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1])); - } - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M45Reset(void) -{ - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0; - MMC3RegReset(); -} - -static void M45Power(void) -{ - setchr8(0); - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M45Write); -} - -void Mapper45_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M45CW; - pwrap=M45PW; - info->Reset=M45Reset; - info->Power=M45Power; - AddExState(EXPREGS, 5, 0, "EXPR"); -} - -// ---------------------------- Mapper 47 ------------------------------- - -static void M47PW(uint32 A, uint8 V) -{ - V&=0xF; - V|=EXPREGS[0]<<4; - setprg8(A,V); -} - -static void M47CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x7F; - NV|=EXPREGS[0]<<7; - setchr1(A,NV); -} - -static DECLFW(M47Write) -{ - EXPREGS[0]=V&1; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M47Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M47Write); -// SetReadHandler(0x6000,0x7FFF,0); -} - -void Mapper47_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - pwrap=M47PW; - cwrap=M47CW; - info->Power=M47Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 49 ------------------------------- - -static void M49PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&1) - { - V&=0xF; - V|=(EXPREGS[0]&0xC0)>>2; - setprg8(A,V); - } - else - setprg32(0x8000,(EXPREGS[0]>>4)&3); -} - -static void M49CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x7F; - NV|=(EXPREGS[0]&0xC0)<<1; - setchr1(A,NV); -} - -static DECLFW(M49Write) -{ - if(A001B&0x80) - { - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } -} - -static void M49Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -static void M49Power(void) -{ - M49Reset(); - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M49Write); - SetReadHandler(0x6000,0x7FFF,0); -} - -void Mapper49_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 0, 0); - cwrap=M49CW; - pwrap=M49PW; - info->Reset=M49Reset; - info->Power=M49Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 52 ------------------------------- - -static void M52PW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x1F^((EXPREGS[0]&8)<<1); - NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4; - setprg8(A,NV); -} - -static void M52CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0xFF^((EXPREGS[0]&0x40)<<1); - NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; - setchr1(A,NV); -} - -static DECLFW(M52Write) -{ - if(EXPREGS[1]) - { - WRAM[A-0x6000]=V; - return; - } - EXPREGS[1]=1; - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M52Reset(void) -{ - EXPREGS[0]=EXPREGS[1]=0; - MMC3RegReset(); -} - -static void M52Power(void) -{ - M52Reset(); - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M52Write); -} - -void Mapper52_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M52CW; - pwrap=M52PW; - info->Reset=M52Reset; - info->Power=M52Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- Mapper 74 ------------------------------- - -static void M74CW(uint32 A, uint8 V) -{ - if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -void Mapper74_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M74CW; - CHRRAMSize=2048; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 114 ------------------------------ - -static uint8 cmdin; -uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4}; - -static void M114PWRAP(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - { - setprg16(0x8000,EXPREGS[0]&0xF); - setprg16(0xC000,EXPREGS[0]&0xF); - } - else - setprg8(A,V&0x3F); -} - -static DECLFW(M114Write) -{ - if(A==0xE003) - { - IRQa=1; - IRQLatch=V; - IRQReload=1; - } - else if(A==0xE002) - { - IRQa=0; - X6502_IRQEnd(FCEU_IQEXT); - } - else switch(A&0xE000) - { - case 0x8000: setmirror((V&1)^1); break; - case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break; - case 0xC000: if(!cmdin) break; - MMC3_CMDWrite(0x8001,V); - cmdin=0; - break; - } -} - -static DECLFW(M114ExWrite) -{ - if(A<=0x7FFF) - { - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - } -} - -static void M114Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,M114Write); - SetWriteHandler(0x5000,0x7FFF,M114ExWrite); -} - -static void M114Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -void Mapper114_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap=M114PWRAP; - info->Power=M114Power; - info->Reset=M114Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} - -// ---------------------------- Mapper 115 ------------------------------ - -static void M115PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - setprg32(0x8000,(EXPREGS[0]&7)>>1); - else - setprg8(A,V); -} - -static void M115CW(uint32 A, uint8 V) -{ - setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8)); -} - -static DECLFW(M115Write) -{ - if(A==0x6000) - EXPREGS[0]=V; - else if(A==0x6001) - EXPREGS[1]=V; - FixMMC3PRG(MMC3_cmd); -} - -static void M115Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x4100,0x7FFF,M115Write); - SetReadHandler(0x4100,0x7FFF,0); -} - -void Mapper115_Init(CartInfo *info) -{ - GenMMC3_Init(info, 128, 512, 0, 0); - cwrap=M115CW; - pwrap=M115PW; - info->Power=M115Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- Mapper 116 ------------------------------ - -static void M116CW(uint32 A, uint8 V) -{ -// setchr1(A,V|((EXPREGS[0]&0x4)<<6)); - if(EXPREGS[0]&2) - setchr8r(0x10,0); - else - setchr1(A,V); -} - -static DECLFW(M116Write) -{ - EXPREGS[0]=V; - FixMMC3CHR(MMC3_cmd); -} - -static void M116Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x4100,0x4100,M116Write); -} - -void Mapper116_Init(CartInfo *info) -{ - GenMMC3_Init(info, 128, 512, 0, 0); - cwrap=M116CW; - info->Power=M116Power; - CHRRAM = (uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); - AddExState(EXPREGS, 4, 0, "EXPR"); -} - -// ---------------------------- Mapper 118 ------------------------------ - -static uint8 PPUCHRBus; -static uint8 TKSMIR[8]; - -static void FP_FASTAPASS(1) TKSPPU(uint32 A) -{ - A&=0x1FFF; - A>>=10; - PPUCHRBus=A; - setmirror(MI_0+TKSMIR[A]); -} - -static void TKSWRAP(uint32 A, uint8 V) -{ - TKSMIR[A>>10]=V>>7; - setchr1(A,V&0x7F); - if(PPUCHRBus==(A>>10)) - setmirror(MI_0+(V>>7)); -} - -void Mapper118_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=TKSWRAP; - mwrap=GENNOMWRAP; - PPU_hook=TKSPPU; - AddExState(&PPUCHRBus, 1, 0, "PPUC"); -} - -// ---------------------------- Mapper 119 ------------------------------ - -static void TQWRAP(uint32 A, uint8 V) -{ - setchr1r((V&0x40)>>2,A,V&0x3F); -} - -void Mapper119_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 64, 0, 0); - cwrap=TQWRAP; - CHRRAMSize=8192; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); -} - -// ---------------------------- Mapper 165 ------------------------------ - -static void M165CW(uint32 A, uint8 V) -{ - if(V==0) - setchr4r(0x10,A,0); - else - setchr4(A,V>>2); -} - -static void M165PPUFD(void) -{ - if(EXPREGS[0]==0xFD) - { - M165CW(0x0000,DRegBuf[0]); - M165CW(0x1000,DRegBuf[2]); - } -} - -static void M165PPUFE(void) -{ - if(EXPREGS[0]==0xFE) - { - M165CW(0x0000,DRegBuf[1]); - M165CW(0x1000,DRegBuf[4]); - } -} - -static void M165CWM(uint32 A, uint8 V) -{ - if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2)) - M165PPUFD(); - if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4)) - M165PPUFE(); -} - -static void FP_FASTAPASS(1) M165PPU(uint32 A) -{ - if((A&0x1FF0)==0x1FD0) - { - EXPREGS[0]=0xFD; - M165PPUFD(); - } else if((A&0x1FF0)==0x1FE0) - { - EXPREGS[0]=0xFE; - M165PPUFE(); - } -} - -static void M165Power(void) -{ - EXPREGS[0]=0xFD; - GenMMC3Power(); -} - -void Mapper165_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 128, 8, info->battery); - cwrap=M165CWM; - PPU_hook=M165PPU; - info->Power=M165Power; - CHRRAMSize = 4096; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); - AddExState(EXPREGS, 4, 0, "EXPR"); -} - -// ---------------------------- Mapper 182 ------------------------------ -// òàáëèöà ïåðìóòàöè àíàëîãè÷íà 114 ìàïïåðó, ðåãèñòðû ìàïïåðà ãîðàçäî ñëîæíåå, -// ÷åì èñïîëüçóþòñÿ çäåñü, õîòÿ âñå ïðåêðàñíî ðàáîòàåò. - -//static uint8 m182_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4}; -static DECLFW(M182Write) -{ - switch(A&0xF003) - { - case 0x8001: setmirror((V&1)^1); break; - case 0xA000: MMC3_CMDWrite(0x8000,m114_perm[V&7]); break; - case 0xC000: MMC3_CMDWrite(0x8001,V); break; - case 0xE003: if(V) - { - IRQLatch=V; - IRQReload=1; - IRQa=1; - } - X6502_IRQEnd(FCEU_IQEXT); - break; - } -} - -static void M182Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,M182Write); -} - -void Mapper182_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - info->Power=M182Power; -} - -// ---------------------------- Mapper 191 ------------------------------ - -static void M191CW(uint32 A, uint8 V) -{ - setchr1r((V&0x80)>>3,A,V); -} - -void Mapper191_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 8, info->battery); - cwrap=M191CW; - CHRRAMSize=2048; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 192 ------------------------------- - -static void M192CW(uint32 A, uint8 V) -{ - if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese), - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -void Mapper192_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M192CW; - CHRRAMSize=4096; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 194 ------------------------------- - -static void M194CW(uint32 A, uint8 V) -{ - if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -void Mapper194_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M194CW; - CHRRAMSize=2048; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 198 ------------------------------- - -static uint8 *wramtw; -static uint16 wramsize; -static void M198CW(uint32 A, uint8 V) -{ - if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C) - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -static void M198Power(void) -{ - GenMMC3Power(); - setprg4r(0x10,0x5000,0); - SetWriteHandler(0x5000,0x5fff,CartBW); - SetReadHandler(0x5000,0x5fff,CartBR); -} - -static void M198Close(void) -{ - if(wramtw) - FCEU_gfree(wramtw); - wramtw=NULL; -} - -void Mapper198_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M198CW; - info->Power=M198Power; - info->Close=M198Close; - CHRRAMSize=4096; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - wramsize=4096; - wramtw=(uint8*)FCEU_gmalloc(wramsize); - SetupCartPRGMapping(0x10, wramtw, wramsize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); - AddExState(wramtw, wramsize, 0, "WRAMTW"); -} - -// ---------------------------- Mapper 199 ------------------------------- - -static uint8 *wramtw; -static uint16 wramsize; -static void M199PW(uint32 A, uint8 V) -{ - if(V>=0x50) - setprg8(A,V&0x4F); - else - setprg8(A,V); -} - -void Mapper199_Init(CartInfo *info) -{ - GenMMC3_Init(info, 1024, 256, 8, info->battery); - pwrap=M199PW; - info->Power=M198Power; - info->Close=M198Close; - wramsize=4096; - wramtw=(uint8*)FCEU_gmalloc(wramsize); - SetupCartPRGMapping(0x10, wramtw, wramsize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); - AddExState(wramtw, wramsize, 0, "WRAMTW"); -} - -// ---------------------------- Mapper 205 ------------------------------ - -static void M205PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&2) - setprg8(A,(V&0x0f)|((EXPREGS[0]&3)<<4)); - else - setprg8(A,(V&0x1f)|((EXPREGS[0]&3)<<4)); -} - -static void M205CW(uint32 A, uint8 V) -{ - setchr1(A,V|((EXPREGS[0]&3)<<7)); -} - -static DECLFW(M205Write) -{ - if((A&0x6800)==0x6800) EXPREGS[0]= V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M205Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -static void M205Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x4020,0x7FFF,M205Write); -} - -void Mapper205_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); - pwrap=M205PW; - cwrap=M205CW; - info->Power=M205Power; - info->Reset=M205Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 215 ------------------------------ - -static uint8 m215_perm[8] = {0, 2, 5, 3, 6, 1, 7, 4}; - -static void M215CW(uint32 A, uint8 V) -{ - if(EXPREGS[1]&0x04) - setchr1(A,V|0x100); - else - setchr1(A,(V&0x7F)|((EXPREGS[1]&0x10)<<3)); -} - -static void M215PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - { - setprg16(0x8000,(EXPREGS[0]&0x0F)|(EXPREGS[1]&0x10)); - setprg16(0xC000,(EXPREGS[0]&0x0F)|(EXPREGS[1]&0x10)); - } - else if(EXPREGS[1]&0x08) - setprg8(A,(V&0x1F)|0x20); - else - setprg8(A,(V&0x0F)|(EXPREGS[1]&0x10)); -} - -static DECLFW(M215Write) -{ - if(!(EXPREGS[2])) - { - if(A >= 0xc000) - MMC3_IRQWrite(A,V); - else - MMC3_CMDWrite(A,V); - } - else switch(A&0xE001) - { - case 0xC001: IRQLatch=V; break; - case 0xA001: IRQReload=1; break; - case 0xE001: IRQa=1; break; - case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; - case 0xC000: setmirror(((V|(V>>7))&1)^1); break; - case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m215_perm[V&7])); cmdin=1; break; - case 0x8001: if(!cmdin) break; - MMC3_CMDWrite(0x8001,V); - cmdin=0; - break; - } -} - -static DECLFW(M215ExWrite) -{ - switch(A) - { - case 0x5000: - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - break; - case 0x5001: - EXPREGS[1]=V; - FixMMC3CHR(MMC3_cmd); - break; - case 0x5007: - EXPREGS[2]=V; - MMC3RegReset(); - break; - } -} - -static void M215Power(void) -{ - EXPREGS[0]=0; - EXPREGS[1]=0xFF; - EXPREGS[2]=4; - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,M215Write); - SetWriteHandler(0x5000,0x7FFF,M215ExWrite); -} - -void Mapper215_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - cwrap=M215CW; - pwrap=M215PW; - info->Power=M215Power; - AddExState(EXPREGS, 3, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} - -// ---------------------------- Mapper 217 ------------------------------ - -static uint8 m217_perm[8] = {0, 6, 3, 7, 5, 2, 4, 1}; - -static void M217CW(uint32 A, uint8 V) -{ - if(EXPREGS[1]&0x08) - setchr1(A,V|((EXPREGS[1]&3)<<8)); - else - setchr1(A,(V&0x7F)|((EXPREGS[1]&3)<<8)|((EXPREGS[1]&0x10)<<3)); -} - -static void M217PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - { - setprg16(0x8000,(EXPREGS[0]&0x0F)|((EXPREGS[1]&3)<<4)); - setprg16(0xC000,(EXPREGS[0]&0x0F)|((EXPREGS[1]&3)<<4)); - } - else if(EXPREGS[1]&0x08) - setprg8(A,(V&0x1F)|((EXPREGS[1]&3)<<5)); - else - setprg8(A,(V&0x0F)|((EXPREGS[1]&3)<<5)|(EXPREGS[1]&0x10)); -} - -static DECLFW(M217Write) -{ - if(!EXPREGS[2]) - { - if(A >= 0xc000) - MMC3_IRQWrite(A, V); - else - MMC3_CMDWrite(A,V); - } - else switch(A&0xE001) - { - case 0x8000: IRQCount=V; break; - case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; - case 0xC001: IRQa=1; break; - case 0xA001: setmirror((V&1)^1); break; - case 0x8001: MMC3_CMDWrite(0x8000,(V&0xC0)|(m217_perm[V&7])); cmdin=1; break; - case 0xA000: if(!cmdin) break; - MMC3_CMDWrite(0x8001,V); - cmdin=0; - break; - } -} - -static DECLFW(M217ExWrite) -{ - switch(A) - { - case 0x5000: - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - break; - case 0x5001: - EXPREGS[1]=V; - FixMMC3PRG(MMC3_cmd); - break; - case 0x5007: - EXPREGS[2]=V; - break; - } -} - -static void M217Power(void) -{ - EXPREGS[0]=0; - EXPREGS[1]=0xFF; - EXPREGS[2]=3; - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,M217Write); - SetWriteHandler(0x5000,0x7FFF,M217ExWrite); -} - -void Mapper217_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - cwrap=M217CW; - pwrap=M217PW; - info->Power=M217Power; - AddExState(EXPREGS, 3, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} - -// ---------------------------- Mapper 245 ------------------------------ - -static void M245CW(uint32 A, uint8 V) -{ - setchr1(A,V&7); - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); -} - -static void M245PW(uint32 A, uint8 V) -{ - setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5)); -} - -static void M245Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); -} - -void Mapper245_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M245CW; - pwrap=M245PW; - info->Power=M245Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 249 ------------------------------ - -static void M249PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x2) - { - if(V<0x20) - V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10); - else - { - V-=0x20; - V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); - } - } - setprg8(A,V); -} - -static void M249CW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x2) - V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); - setchr1(A,V); -} - -static DECLFW(M249Write) -{ - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M249Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0x5000,0x5000,M249Write); -} - -void Mapper249_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M249CW; - pwrap=M249PW; - info->Power=M249Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 250 ------------------------------ - -static DECLFW(M250Write) -{ - MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); -} - -static DECLFW(M250IRQWrite) -{ - MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); -} - -static void M250_Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xBFFF,M250Write); - SetWriteHandler(0xC000,0xFFFF,M250IRQWrite); -} - -void Mapper250_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - info->Power=M250_Power; -} - -// ---------------------------- Mapper 254 ------------------------------ - -static DECLFR(MR254WRAM) -{ - if(EXPREGS[0]) - return WRAM[A-0x6000]; - else - return WRAM[A-0x6000]^EXPREGS[1]; -} - -static DECLFW(M254Write) -{ - switch (A) { - case 0x8000: EXPREGS[0]=0xff; - break; - case 0xA001: EXPREGS[1]=V; - } - MMC3_CMDWrite(A,V); -} - -static void M254_Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xBFFF,M254Write); - SetReadHandler(0x6000,0x7FFF,MR254WRAM); -#ifdef ASM_6502 - // hrrr.. can't handle those evil xors here.. - Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000; -#endif -} - -void Mapper254_Init(CartInfo *info) -{ - GenMMC3_Init(info, 128, 128, 8, info->battery); - info->Power=M254_Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- UNIF Boards ----------------------------- - -void TEROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 32, 32, 0, 0); -} - -void TFROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 64, 0, 0); -} - -void TGROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 0, 0, 0); -} - -void TKROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); -} - -void TLROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 0, 0); -} - -void TSROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); -} - -void TLSROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); - cwrap=TKSWRAP; - mwrap=GENNOMWRAP; - PPU_hook=TKSPPU; - AddExState(&PPUCHRBus, 1, 0, "PPUC"); -} - -void TKSROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=TKSWRAP; - mwrap=GENNOMWRAP; - PPU_hook=TKSPPU; - AddExState(&PPUCHRBus, 1, 0, "PPUC"); -} - -void TQROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 64, 0, 0); - cwrap=TQWRAP; - CHRRAMSize=8192; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); -} - -void HKROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 512, 1, info->battery); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2003 Xodnizel + * Mapper 12 code Copyright (C) 2003 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 + */ + +/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, + 119,165,205,214,215,245,249,250,254 +*/ + +#include "mapinc.h" +#include "mmc3.h" + +uint8 MMC3_cmd; +uint8 *WRAM; +uint8 *CHRRAM; +uint32 CHRRAMSize; +uint8 DRegBuf[8]; +uint8 EXPREGS[8]; /* For bootleg games, mostly. */ +uint8 A000B,A001B; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +uint8 IRQCount,IRQLatch,IRQa; +uint8 IRQReload; + +static SFORMAT MMC3_StateRegs[]= +{ + {DRegBuf, 8, "REGS"}, + {&MMC3_cmd, 1, "CMD"}, + {&A000B, 1, "A000"}, + {&A001B, 1, "A001"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static int mmc3opts=0; +static int wrams; +static int isRevB=1; + +void (*pwrap)(uint32 A, uint8 V); +void (*cwrap)(uint32 A, uint8 V); +void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); + +// ---------------------------------------------------------------------- +// ------------------------- Generic MM3 Code --------------------------- +// ---------------------------------------------------------------------- + +void FixMMC3PRG(int V) +{ + if(V&0x40) + { + pwrap(0xC000,DRegBuf[6]); + pwrap(0x8000,~1); + } + else + { + pwrap(0x8000,DRegBuf[6]); + pwrap(0xC000,~1); + } + pwrap(0xA000,DRegBuf[7]); + pwrap(0xE000,~0); +} + +void FixMMC3CHR(int V) +{ + int cbase=(V&0x80)<<5; + + cwrap((cbase^0x000),DRegBuf[0]&(~1)); + cwrap((cbase^0x400),DRegBuf[0]|1); + cwrap((cbase^0x800),DRegBuf[1]&(~1)); + cwrap((cbase^0xC00),DRegBuf[1]|1); + + cwrap(cbase^0x1000,DRegBuf[2]); + cwrap(cbase^0x1400,DRegBuf[3]); + cwrap(cbase^0x1800,DRegBuf[4]); + cwrap(cbase^0x1c00,DRegBuf[5]); + + if(mwrap) mwrap(A000B); +} + +void MMC3RegReset(void) +{ + IRQCount=IRQLatch=IRQa=MMC3_cmd=0; + + DRegBuf[0]=0; + DRegBuf[1]=2; + DRegBuf[2]=4; + DRegBuf[3]=5; + DRegBuf[4]=6; + DRegBuf[5]=7; + DRegBuf[6]=0; + DRegBuf[7]=1; + + FixMMC3PRG(0); + FixMMC3CHR(0); +} + +DECLFW(MMC3_CMDWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + switch(A&0xE001) + { + case 0x8000: + if((V&0x40) != (MMC3_cmd&0x40)) + FixMMC3PRG(V); + if((V&0x80) != (MMC3_cmd&0x80)) + FixMMC3CHR(V); + MMC3_cmd = V; + break; + case 0x8001: + { + int cbase=(MMC3_cmd&0x80)<<5; + DRegBuf[MMC3_cmd&0x7]=V; + switch(MMC3_cmd&0x07) + { + case 0: cwrap((cbase^0x000),V&(~1)); + cwrap((cbase^0x400),V|1); + break; + case 1: cwrap((cbase^0x800),V&(~1)); + cwrap((cbase^0xC00),V|1); + break; + case 2: cwrap(cbase^0x1000,V); + break; + case 3: cwrap(cbase^0x1400,V); + break; + case 4: cwrap(cbase^0x1800,V); + break; + case 5: cwrap(cbase^0x1C00,V); + break; + case 6: + if(MMC3_cmd&0x40) + pwrap(0xC000,V); + else + pwrap(0x8000,V); + break; + case 7: + pwrap(0xA000,V); + break; + } + } + break; + case 0xA000: + if(mwrap) mwrap(V); + break; + case 0xA001: + A001B=V; + break; + } +} + +DECLFW(MMC3_IRQWrite) +{ +// FCEU_printf("%04x:%04x\n",A,V); + switch(A&0xE001) + { + case 0xC000:IRQLatch=V;break; + case 0xC001:IRQReload=1;break; + case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break; + case 0xE001:IRQa=1;break; + } +} + +static void ClockMMC3Counter(void) +{ + int count = IRQCount; + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if((count|isRevB) && !IRQCount) + { + if(IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void MMC3_hb(void) +{ + ClockMMC3Counter(); +} + +static void MMC3_hb_KickMasterHack(void) +{ + if(scanline==238) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +static void MMC3_hb_PALStarWarsHack(void) +{ + if(scanline==240) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +void GenMMC3Restore(int version) +{ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void GENCWRAP(uint32 A, uint8 V) +{ + setchr1(A,V); // Business Wars NEEDS THIS for 8K CHR-RAM +} + +static void GENPWRAP(uint32 A, uint8 V) +{ + setprg8(A,V&0x7F); // [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken +} + +static void GENMWRAP(uint8 V) +{ + A000B=V; + setmirror((V&1)^1); +} + +static void GENNOMWRAP(uint8 V) +{ + A000B=V; +} + +static DECLFW(MBWRAMMMC6) +{ + WRAM[A&0x3ff]=V; +} + +static DECLFR(MAWRAMMMC6) +{ + return(WRAM[A&0x3ff]); +} + +void GenMMC3Power(void) +{ + if(UNIFchrrama) setchr8(0); + + SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite); + SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + A001B=A000B=0; + setmirror(1); + if(mmc3opts&1) + { + if(wrams==1024) + { + FCEU_CheatAddRAM(1,0x7000,WRAM); + SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6); + SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6); + } + else + { + FCEU_CheatAddRAM((wrams&0x1fff)>>10,0x6000,WRAM); + SetWriteHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBW); + SetReadHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBR); + setprg8r(0x10,0x6000,0); + } + if(!(mmc3opts&2)) + FCEU_dwmemset(WRAM,0,wrams); + } + MMC3RegReset(); + if(CHRRAM) + FCEU_dwmemset(CHRRAM,0,CHRRAMSize); +} + +static void GenMMC3Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + if(WRAM) + FCEU_gfree(WRAM); + CHRRAM=WRAM=NULL; +} + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) +{ + pwrap=GENPWRAP; + cwrap=GENCWRAP; + mwrap=GENMWRAP; + + wrams=wram<<10; + + PRGmask8[0]&=(prg>>13)-1; + CHRmask1[0]&=(chr>>10)-1; + CHRmask2[0]&=(chr>>11)-1; + + if(wram) + { + mmc3opts|=1; + WRAM=(uint8*)FCEU_gmalloc(wrams); + SetupCartPRGMapping(0x10,WRAM,wrams,1); + AddExState(WRAM, wrams, 0, "MMC3WRAM"); + } + + if(battery) + { + mmc3opts|=2; + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=wrams; + } + + AddExState(MMC3_StateRegs, ~0, 0, 0); + + info->Power=GenMMC3Power; + info->Reset=MMC3RegReset; + info->Close=GenMMC3Close; + + if(info->CRC32 == 0x5104833e) // Kick Master + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93 + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master. + GameHBIRQHook = MMC3_hb_PALStarWarsHack; + else + GameHBIRQHook=MMC3_hb; + GameStateRestore=GenMMC3Restore; +} + +// ---------------------------------------------------------------------- +// -------------------------- MMC3 Based Code --------------------------- +// ---------------------------------------------------------------------- + +// ---------------------------- Mapper 4 -------------------------------- + +static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/ + +static void M4Power(void) +{ + GenMMC3Power(); + A000B=(hackm4^1)&1; + setmirror(hackm4); +} + +void Mapper4_Init(CartInfo *info) +{ + int ws=8; + + if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84)) + { + FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); + ws=0; + } + GenMMC3_Init(info,512,256,ws,info->battery); + info->Power=M4Power; + hackm4=info->mirror; +} + +// ---------------------------- Mapper 12 ------------------------------- + +static void M12CW(uint32 A, uint8 V) +{ + setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V); +} + +static DECLFW(M12Write) +{ + EXPREGS[0]=V&0x01; + EXPREGS[1]=(V&0x10)>>4; +} + +static void M12Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetWriteHandler(0x4100,0x5FFF,M12Write); +} + +void Mapper12_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M12CW; + isRevB=0; + + info->Power=M12Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 37 ------------------------------- + +static void M37PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]!=2) + V&=0x7; + else + V&=0xF; + V|=EXPREGS[0]<<3; + setprg8(A,V); +} + +static void M37CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=EXPREGS[0]<<6; + setchr1(A,NV); +} + +static DECLFW(M37Write) +{ + EXPREGS[0]=(V&6)>>1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M37Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M37Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M37Write); +} + +void Mapper37_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + pwrap=M37PW; + cwrap=M37CW; + info->Power=M37Power; + info->Reset=M37Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 44 ------------------------------- + +static void M44PW(uint32 A, uint8 V) +{ + uint32 NV=V; + if(EXPREGS[0]>=6) NV&=0x1F; + else NV&=0x0F; + NV|=EXPREGS[0]<<4; + setprg8(A,NV); +} + +static void M44CW(uint32 A, uint8 V) +{ + uint32 NV=V; + if(EXPREGS[0]<6) NV&=0x7F; + NV|=EXPREGS[0]<<7; + setchr1(A,NV); +} + +static DECLFW(M44Write) +{ + if(A&1) + { + EXPREGS[0]=V&7; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + MMC3_CMDWrite(A,V); +} + +static void M44Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0xA000,0xBFFF,M44Write); +} + +void Mapper44_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M44CW; + pwrap=M44PW; + info->Power=M44Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 45 ------------------------------- + +static void M45CW(uint32 A, uint8 V) +{ + if(!UNIFchrrama) + { + uint32 NV=V; + if(EXPREGS[2]&8) + NV&=(1<<((EXPREGS[2]&7)+1))-1; + else + if(EXPREGS[2]) + NV&=0; // hack ;( don't know exactly how it should be + NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4); + setchr1(A,NV); + } +} + +static void M45PW(uint32 A, uint8 V) +{ + V&=(EXPREGS[3]&0x3F)^0x3F; + V|=EXPREGS[1]; + setprg8(A,V); +} + +static DECLFW(M45Write) +{ + if(EXPREGS[3]&0x40) + { + WRAM[A-0x6000]=V; + return; + } + EXPREGS[EXPREGS[4]]=V; + EXPREGS[4]=(EXPREGS[4]+1)&3; +// if(!EXPREGS[4]) +// { +// FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]); +// FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n", +// (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), +// (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), +// (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]), +// (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1])); +// } + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M45Reset(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0; + MMC3RegReset(); +} + +static void M45Power(void) +{ + setchr8(0); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M45Write); +} + +void Mapper45_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M45CW; + pwrap=M45PW; + info->Reset=M45Reset; + info->Power=M45Power; + AddExState(EXPREGS, 5, 0, "EXPR"); +} + +// ---------------------------- Mapper 47 ------------------------------- + +static void M47PW(uint32 A, uint8 V) +{ + V&=0xF; + V|=EXPREGS[0]<<4; + setprg8(A,V); +} + +static void M47CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=EXPREGS[0]<<7; + setchr1(A,NV); +} + +static DECLFW(M47Write) +{ + EXPREGS[0]=V&1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M47Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M47Write); +// SetReadHandler(0x6000,0x7FFF,0); +} + +void Mapper47_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + pwrap=M47PW; + cwrap=M47CW; + info->Power=M47Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 49 ------------------------------- + +static void M49PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&1) + { + V&=0xF; + V|=(EXPREGS[0]&0xC0)>>2; + setprg8(A,V); + } + else + setprg32(0x8000,(EXPREGS[0]>>4)&3); +} + +static void M49CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=(EXPREGS[0]&0xC0)<<1; + setchr1(A,NV); +} + +static DECLFW(M49Write) +{ + if(A001B&0x80) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void M49Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M49Power(void) +{ + M49Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M49Write); + SetReadHandler(0x6000,0x7FFF,0); +} + +void Mapper49_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 0, 0); + cwrap=M49CW; + pwrap=M49PW; + info->Reset=M49Reset; + info->Power=M49Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 52 ------------------------------- + +static void M52PW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x1F^((EXPREGS[0]&8)<<1); + NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4; + setprg8(A,NV); +} + +static void M52CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0xFF^((EXPREGS[0]&0x40)<<1); + NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; + setchr1(A,NV); +} + +static DECLFW(M52Write) +{ + if(EXPREGS[1]) + { + WRAM[A-0x6000]=V; + return; + } + EXPREGS[1]=1; + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M52Reset(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + MMC3RegReset(); +} + +static void M52Power(void) +{ + M52Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M52Write); +} + +void Mapper52_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M52CW; + pwrap=M52PW; + info->Reset=M52Reset; + info->Power=M52Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 74 ------------------------------- + +static void M74CW(uint32 A, uint8 V) +{ + if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper74_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M74CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 114 ------------------------------ + +static uint8 cmdin; +uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4}; + +static void M114PWRAP(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + { + setprg16(0x8000,EXPREGS[0]&0xF); + setprg16(0xC000,EXPREGS[0]&0xF); + } + else + setprg8(A,V&0x3F); +} + +static DECLFW(M114Write) +{ + switch(A&0xE001) + { + case 0x8001: MMC3_CMDWrite(0xA000,V); break; + case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break; + case 0xC000: if(!cmdin) break; MMC3_CMDWrite(0x8001,V); cmdin=0; break; + case 0xA001: IRQLatch=V; break; + case 0xC001: IRQReload=1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; + case 0xE001: IRQa=1; break; + } +} + +static DECLFW(M114ExWrite) +{ + if(A<=0x7FFF) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void M114Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,M114Write); + SetWriteHandler(0x5000,0x7FFF,M114ExWrite); +} + +static void M114Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +void Mapper114_Init(CartInfo *info) +{ + isRevB=0; + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M114PWRAP; + info->Power=M114Power; + info->Reset=M114Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDIN"); +} + +// ---------------------------- Mapper 115 ------------------------------ + +static void M115PW(uint32 A, uint8 V) +{ + //zero 09-apr-2012 - #3515357 - changed to support Bao Qing Tian (mapper 248) which was missing BG gfx. 115 game(s?) seem still to work OK. + GENPWRAP(A,V); + if(A==0x8000 && EXPREGS[0]&0x80) + setprg16(0x8000,(EXPREGS[0]&0xF)); +} + +static void M115CW(uint32 A, uint8 V) +{ + setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8)); +} + +static DECLFW(M115Write) +{ +// FCEU_printf("%04x:%04x\n",A,V); + if(A==0x5080) EXPREGS[2]=V; + if(A==0x6000) + EXPREGS[0]=V; + else if(A==0x6001) + EXPREGS[1]=V; + FixMMC3PRG(MMC3_cmd); +} + +static DECLFR(M115Read) +{ + return EXPREGS[2]; +} + +static void M115Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x4100,0x7FFF,M115Write); + SetReadHandler(0x5000,0x5FFF,M115Read); +} + +void Mapper115_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 512, 0, 0); + cwrap=M115CW; + pwrap=M115PW; + info->Power=M115Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 118 ------------------------------ + +static uint8 PPUCHRBus; +static uint8 TKSMIR[8]; + +static void TKSPPU(uint32 A) +{ + A&=0x1FFF; + A>>=10; + PPUCHRBus=A; + setmirror(MI_0+TKSMIR[A]); +} + +static void TKSWRAP(uint32 A, uint8 V) +{ + TKSMIR[A>>10]=V>>7; + setchr1(A,V&0x7F); + if(PPUCHRBus==(A>>10)) + setmirror(MI_0+(V>>7)); +} + +// ---------------------------- Mapper 119 ------------------------------ + +static void TQWRAP(uint32 A, uint8 V) +{ + setchr1r((V&0x40)>>2,A,V&0x3F); +} + +void Mapper119_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap=TQWRAP; + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); +} + +// ---------------------------- Mapper 134 ------------------------------ + +static void M134PW(uint32 A, uint8 V) +{ + setprg8(A,(V&0x1F)|((EXPREGS[0]&2)<<4)); +} + +static void M134CW(uint32 A, uint8 V) +{ + setchr1(A,(V&0xFF)|((EXPREGS[0]&0x20)<<3)); +} + +static DECLFW(M134Write) +{ + EXPREGS[0]=V; + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); +} + +static void M134Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6001,0x6001,M134Write); +} + +static void M134Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +void Mapper134_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M134PW; + cwrap=M134CW; + info->Power=M134Power; + info->Reset=M134Reset; + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +// ---------------------------- Mapper 165 ------------------------------ + +static void M165CW(uint32 A, uint8 V) +{ + if(V==0) + setchr4r(0x10,A,0); + else + setchr4(A,V>>2); +} + +static void M165PPUFD(void) +{ + if(EXPREGS[0]==0xFD) + { + M165CW(0x0000,DRegBuf[0]); + M165CW(0x1000,DRegBuf[2]); + } +} + +static void M165PPUFE(void) +{ + if(EXPREGS[0]==0xFE) + { + M165CW(0x0000,DRegBuf[1]); + M165CW(0x1000,DRegBuf[4]); + } +} + +static void M165CWM(uint32 A, uint8 V) +{ + if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2)) + M165PPUFD(); + if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4)) + M165PPUFE(); +} + +static void M165PPU(uint32 A) +{ + if((A&0x1FF0)==0x1FD0) + { + EXPREGS[0]=0xFD; + M165PPUFD(); + } else if((A&0x1FF0)==0x1FE0) + { + EXPREGS[0]=0xFE; + M165PPUFE(); + } +} + +static void M165Power(void) +{ + EXPREGS[0]=0xFD; + GenMMC3Power(); +} + +void Mapper165_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 128, 8, info->battery); + cwrap=M165CWM; + PPU_hook=M165PPU; + info->Power=M165Power; + CHRRAMSize = 4096; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +// ---------------------------- Mapper 191 ------------------------------ + +static void M191CW(uint32 A, uint8 V) +{ + setchr1r((V&0x80)>>3,A,V); +} + +void Mapper191_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 8, info->battery); + cwrap=M191CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 192 ------------------------------- + +static void M192CW(uint32 A, uint8 V) +{ + if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese), + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper192_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M192CW; + CHRRAMSize=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 194 ------------------------------- + +static void M194CW(uint32 A, uint8 V) +{ + if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper194_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M194CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 195 ------------------------------- +static uint8 *wramtw; +static uint16 wramsize; + +static void M195CW(uint32 A, uint8 V) +{ + if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C) + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +static void M195Power(void) +{ + GenMMC3Power(); + setprg4r(0x10,0x5000,0); + SetWriteHandler(0x5000,0x5fff,CartBW); + SetReadHandler(0x5000,0x5fff,CartBR); +} + +static void M195Close(void) +{ + if(wramtw) + FCEU_gfree(wramtw); + wramtw=NULL; +} + +void Mapper195_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M195CW; + info->Power=M195Power; + info->Close=M195Close; + CHRRAMSize=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(wramtw, wramsize, 0, "WRAMTW"); +} + +// ---------------------------- Mapper 196 ------------------------------- + +static DECLFW(Mapper196Write) +{ + A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1); + if(A >= 0xC000) + MMC3_IRQWrite(A,V); + else + MMC3_CMDWrite(A,V); +} + +static void Mapper196Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,Mapper196Write); +} + +void Mapper196_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 0, 0); + info->Power=Mapper196Power; +} + +// ---------------------------- Mapper 197 ------------------------------- + +static void M197CW(uint32 A, uint8 V) +{ + if(A==0x0000) + setchr4(0x0000,V>>1); + else if(A==0x1000) + setchr2(0x1000,V); + else if(A==0x1400) + setchr2(0x1800,V); +} + +void Mapper197_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 512, 8, 0); + cwrap=M197CW; +} + +// ---------------------------- Mapper 198 ------------------------------- + +static void M198PW(uint32 A, uint8 V) +{ + if(V>=0x50) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes + setprg8(A,V&0x4F); + else + setprg8(A,V); +} + +void Mapper198_Init(CartInfo *info) +{ + GenMMC3_Init(info, 1024, 256, 8, info->battery); + pwrap=M198PW; + info->Power=M195Power; + info->Close=M195Close; + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(wramtw, wramsize, 0, "WRAMTW"); +} + +// ---------------------------- Mapper 205 ------------------------------ + +static void M205PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&2) + setprg8(A,(V&0x0f)|((EXPREGS[0]&3)<<4)); + else + setprg8(A,(V&0x1f)|((EXPREGS[0]&3)<<4)); +} + +static void M205CW(uint32 A, uint8 V) +{ + setchr1(A,V|((EXPREGS[0]&3)<<7)); +} + +static DECLFW(M205Write) +{ + if((A&0x6800)==0x6800) EXPREGS[0]= V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M205Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M205Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x4020,0x7FFF,M205Write); +} + +void Mapper205_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + pwrap=M205PW; + cwrap=M205CW; + info->Power=M205Power; + info->Reset=M205Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 245 ------------------------------ + +static void M245CW(uint32 A, uint8 V) +{ + if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart + setchr1(A,V&7); + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); +} + +static void M245PW(uint32 A, uint8 V) +{ + setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5)); +} + +static void M245Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); +} + +void Mapper245_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M245CW; + pwrap=M245PW; + info->Power=M245Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 249 ------------------------------ + +static void M249PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x2) + { + if(V<0x20) + V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10); + else + { + V-=0x20; + V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); + } + } + setprg8(A,V); +} + +static void M249CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x2) + V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); + setchr1(A,V); +} + +static DECLFW(M249Write) +{ + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M249Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x5000,M249Write); +} + +void Mapper249_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M249CW; + pwrap=M249PW; + info->Power=M249Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 250 ------------------------------ + +static DECLFW(M250Write) +{ + MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); +} + +static DECLFW(M250IRQWrite) +{ + MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); +} + +static void M250_Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xBFFF,M250Write); + SetWriteHandler(0xC000,0xFFFF,M250IRQWrite); +} + +void Mapper250_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + info->Power=M250_Power; +} + +// ---------------------------- Mapper 254 ------------------------------ + +static DECLFR(MR254WRAM) +{ + if(EXPREGS[0]) + return WRAM[A-0x6000]; + else + return WRAM[A-0x6000]^EXPREGS[1]; +} + +static DECLFW(M254Write) +{ + switch (A) { + case 0x8000: EXPREGS[0]=0xff; + break; + case 0xA001: EXPREGS[1]=V; + } + MMC3_CMDWrite(A,V); +} + +static void M254_Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xBFFF,M254Write); + SetReadHandler(0x6000,0x7FFF,MR254WRAM); +} + +void Mapper254_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, info->battery); + info->Power=M254_Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- UNIF Boards ----------------------------- + +void TBROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 64, 64, 0, 0); +} + +void TEROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 32, 32, 0, 0); +} + +void TFROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); +} + +void TGROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 0, 0, 0); +} + +void TKROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); +} + +void TLROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 0, 0); +} + +void TSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); +} + +void TLSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap=TKSWRAP; + mwrap=GENNOMWRAP; + PPU_hook=TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TKSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=TKSWRAP; + mwrap=GENNOMWRAP; + PPU_hook=TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TQROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap=TQWRAP; + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); +} + +void HKROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 512, 1, info->battery); +} diff --git a/boards/mmc3.h b/boards/mmc3.h index 6692dd4..a5e03cd 100644 --- a/boards/mmc3.h +++ b/boards/mmc3.h @@ -1,23 +1,25 @@ -extern uint8 MMC3_cmd; -extern uint8 *WRAM; -extern uint8 *CHRRAM; -extern uint8 EXPREGS[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 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/boards/mmc5.c b/boards/mmc5.c index d14ca0e..1916df9 100644 --- a/boards/mmc5.c +++ b/boards/mmc5.c @@ -1,839 +1,908 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* None of this code should use any of the iNES bank switching wrappers. */ - -#include "mapinc.h" - -static void (*sfun)(int P); -static void (*psfun)(void); - -void MMC5RunSound(int Count); -//void MMC5RunSoundHQ(void); - -static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) -{ - if(CHRptr[0]) - { - V&=CHRmask1[0]; - MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A); - } -} - -static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}} - -static INLINE void MMC5SPRVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} -static INLINE void MMC5BGVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} - -static INLINE void MMC5SPRVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]= MMC5SPRVPage[((A)>>10)+2]=MMC5SPRVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} -static INLINE void MMC5BGVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=MMC5BGVPage[((A)>>10)+2]=MMC5BGVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} - -static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5SPRVPage[0]=MMC5SPRVPage[1]=MMC5SPRVPage[2]=MMC5SPRVPage[3]=MMC5SPRVPage[4]=MMC5SPRVPage[5]=MMC5SPRVPage[6]=MMC5SPRVPage[7]=&CHRptr[0][(V)<<13];}} -static INLINE void MMC5BGVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5BGVPage[0]=MMC5BGVPage[1]=MMC5BGVPage[2]=MMC5BGVPage[3]=MMC5BGVPage[4]=MMC5BGVPage[5]=MMC5BGVPage[6]=MMC5BGVPage[7]=&CHRptr[0][(V)<<13];}} - -static uint8 PRGBanks[4]; -static uint8 WRAMPage; -static uint8 CHRBanksA[8], CHRBanksB[4]; -static uint8 WRAMMaskEnable[2]; -static uint8 ABMode; /* A=0, B=1 */ - -static uint8 IRQScanline,IRQEnable; -static uint8 CHRMode, NTAMirroring, NTFill, ATFill; - -static uint8 MMC5IRQR; -static uint8 MMC5LineCounter; -static uint8 mmc5psize, mmc5vsize; -static uint8 mul[2]; - -static uint8 *WRAM=NULL; -static uint8 *MMC5fill=NULL; -static uint8 *ExRAM=NULL; - -static uint8 MMC5WRAMsize; -static uint8 MMC5WRAMIndex[8]; - -static uint8 MMC5ROMWrProtect[4]; -static uint8 MMC5MemIn[5]; - -static void MMC5CHRA(void); -static void MMC5CHRB(void); - -typedef struct __cartdata { - uint32 crc32; - uint8 size; -} cartdata; - - -// ETROM seems to have 16KB of WRAM, ELROM seems to have 8KB -// EWROM seems to have 32KB of WRAM - -#define MMC5_NOCARTS 14 -cartdata MMC5CartList[MMC5_NOCARTS]= -{ - {0x9c18762b,2}, /* L'Empereur */ - {0x26533405,2}, - {0x6396b988,2}, - - {0xaca15643,2}, /* Uncharted Waters */ - {0xfe3488d1,2}, /* Dai Koukai Jidai */ - - {0x15fe6d0f,2}, /* BKAC */ - {0x39f2ce4b,2}, /* Suikoden */ - - {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ - {0xeee9a682,2}, - - {0x1ced086f,2}, /* Ishin no Arashi */ - - {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ - - {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ - - {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ - {0x184c2124,4}, /* Sangokushi 2 */ -}; - - -int DetectMMC5WRAMSize(uint32 crc32) -{ - int x; - for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); - return(MMC5CartList[x].size*8); - } - return(8); -} - -static void BuildWRAMSizeTable(void) -{ - int x; - for(x=0;x<8;x++) - { - switch(MMC5WRAMsize) - { - case 0: MMC5WRAMIndex[x]=255; break; - case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; - case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; - case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; - } - } -} - -static void MMC5CHRA(void) -{ - int x; - switch(mmc5vsize&3) - { - case 0: setchr8(CHRBanksA[7]); - MMC5SPRVROM_BANK8(CHRBanksA[7]); - break; - case 1: setchr4(0x0000,CHRBanksA[3]); - setchr4(0x1000,CHRBanksA[7]); - MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); - MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); - break; - case 2: setchr2(0x0000,CHRBanksA[1]); - setchr2(0x0800,CHRBanksA[3]); - setchr2(0x1000,CHRBanksA[5]); - setchr2(0x1800,CHRBanksA[7]); - MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); - MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); - MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); - MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); - break; - case 3: for(x=0;x<8;x++) - { - setchr1(x<<10,CHRBanksA[x]); - MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); - } - break; - } -} - -static void MMC5CHRB(void) -{ - int x; - switch(mmc5vsize&3) - { - case 0: setchr8(CHRBanksB[3]); - MMC5BGVROM_BANK8(CHRBanksB[3]); - break; - case 1: setchr4(0x0000,CHRBanksB[3]); - setchr4(0x1000,CHRBanksB[3]); - MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); - MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); - break; - case 2: setchr2(0x0000,CHRBanksB[1]); - setchr2(0x0800,CHRBanksB[3]); - setchr2(0x1000,CHRBanksB[1]); - setchr2(0x1800,CHRBanksB[3]); - MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); - MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); - MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); - MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); - break; - case 3: for(x=0;x<8;x++) - { - setchr1(x<<10,CHRBanksB[x&3]); - MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); - } - break; - } -} - -static void FASTAPASS(2) MMC5WRAM(uint32 A, uint32 V) -{ - //printf("%02x\n",V); - V=MMC5WRAMIndex[V&7]; - if(V!=255) - { - setprg8r(0x10,A,V); - MMC5MemIn[(A-0x6000)>>13]=1; - } - else - MMC5MemIn[(A-0x6000)>>13]=0; -} - -static void MMC5PRG(void) -{ - int x; - switch(mmc5psize&3) - { - case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]= - MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; - setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); - for(x=0;x<4;x++) - MMC5MemIn[1+x]=1; - break; - case 1: if(PRGBanks[1]&0x80) - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; - setprg16(0x8000,(PRGBanks[1]>>1)); - MMC5MemIn[1]=MMC5MemIn[2]=1; - } - else - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; - MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); - MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); - } - MMC5MemIn[3]=MMC5MemIn[4]=1; - MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; - setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); - break; - case 2: if(PRGBanks[1]&0x80) - { - MMC5MemIn[1]=MMC5MemIn[2]=1; - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; - setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); - } - else - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; - MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); - MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); - } - if(PRGBanks[2]&0x80) - { - MMC5ROMWrProtect[2]=1; - MMC5MemIn[3]=1; - setprg8(0xC000,PRGBanks[2]&0x7F); - } - else - { - MMC5ROMWrProtect[2]=0; - MMC5WRAM(0xC000,PRGBanks[2]&7); - } - MMC5MemIn[4]=1; - MMC5ROMWrProtect[3]=1; - setprg8(0xE000,PRGBanks[3]&0x7F); - break; - case 3: for(x=0;x<3;x++) - if(PRGBanks[x]&0x80) - { - MMC5ROMWrProtect[x]=1; - setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); - MMC5MemIn[1+x]=1; - } - else - { - MMC5ROMWrProtect[x]=0; - MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); - } - MMC5MemIn[4]=1; - MMC5ROMWrProtect[3]=1; - setprg8(0xE000,PRGBanks[3]&0x7F); - break; - } -} - -static DECLFW(Mapper5_write) -{ - if(A>=0x5120&&A<=0x5127) - { - ABMode = 0; - CHRBanksA[A&7]=V; - MMC5CHRA(); - } - else switch(A) - { - case 0x5105: { - int x; - for(x=0;x<4;x++) - { - switch((V>>(x<<1))&3) - { - case 0:PPUNTARAM|=1<>3)&0x1F;break; - case 0x5202: MMC5HackSPPage=V&0x3F;break; - case 0x5203: X6502_IRQEnd(FCEU_IQEXT);IRQScanline=V;break; - case 0x5204: X6502_IRQEnd(FCEU_IQEXT);IRQEnable=V&0x80;break; - case 0x5205: mul[0]=V;break; - case 0x5206: mul[1]=V;break; - } -} - -static DECLFR(MMC5_ReadROMRAM) -{ - if(MMC5MemIn[(A-0x6000)>>13]) - return Page[A>>11][A]; - else - return X.DB; -} - -static DECLFW(MMC5_WriteROMRAM) -{ - if(A>=0x8000) - if(MMC5ROMWrProtect[(A-0x8000)>>13]) return; - if(MMC5MemIn[(A-0x6000)>>13]) - if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) Page[A>>11][A]=V; -} - -static DECLFW(MMC5_ExRAMWr) -{ - if(MMC5HackCHRMode!=3) - ExRAM[A&0x3ff]=V; -} - -static DECLFR(MMC5_ExRAMRd) -{ - /* Not sure if this is correct, so I'll comment it out for now. */ - //if(MMC5HackCHRMode>=2) - return ExRAM[A&0x3ff]; - //else - // return(X.DB); -} - -static DECLFR(MMC5_read) -{ - switch(A) - { - case 0x5204: X6502_IRQEnd(FCEU_IQEXT); - { - uint8 x; - x=MMC5IRQR; - if(!fceuindbg) - MMC5IRQR&=0x40; - return x; - } - case 0x5205: return (mul[0]*mul[1]); - case 0x5206: return ((mul[0]*mul[1])>>8); - } - return(X.DB); -} - -void MMC5Synco(void) -{ - int x; - - MMC5PRG(); - for(x=0;x<4;x++) - { - switch((NTAMirroring>>(x<<1))&3) - { - case 0:PPUNTARAM|=1<>4]+=MMC5Sound.raw<<1; -} - -#if 0 -static void Do5PCMHQ() -{ - int32 V; - if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) - for(V=MMC5Sound.BC[2];V>2); - MMC5Sound.env[A>>2]=V; - break; - case 0x2: - case 0x6: if(sfun) sfun(A>>2); - MMC5Sound.wl[A>>2]&=~0x00FF; - MMC5Sound.wl[A>>2]|=V&0xFF; - break; - case 0x3: - case 0x7://printf("%04x:$%02x\n",A,V>>3); - MMC5Sound.wl[A>>2]&=~0x0700; - MMC5Sound.wl[A>>2]|=(V&0x07)<<8; - MMC5Sound.running|=1<<(A>>2); - break; - case 0x15:if(sfun) - { - sfun(0); - sfun(1); - } - MMC5Sound.running&=V; - MMC5Sound.enable=V; - //printf("%02x\n",V); - break; - } -} - -static void Do5SQ(int P) -{ - static int tal[4]={1,2,4,6}; - int32 V,amp,rthresh,wl; - int32 start,end; - - start=MMC5Sound.BC[P]; - end=(SOUNDTS<<16)/soundtsinc; - if(end<=start) return; - MMC5Sound.BC[P]=end; - - wl=MMC5Sound.wl[P]+1; - amp=(MMC5Sound.env[P]&0xF)<<4; - rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; - - if(wl>=8 && (MMC5Sound.running&(P+1))) - { - int dc,vc; - - wl<<=18; - dc=MMC5Sound.dcount[P]; - vc=MMC5Sound.vcount[P]; - - for(V=start;V>4]+=amp; - vc-=nesincsize; - while(vc<=0) - { - vc+=wl; - dc=(dc+1)&7; - } - } - MMC5Sound.dcount[P]=dc; - MMC5Sound.vcount[P]=vc; - } -} - -#if 0 -static void Do5SQHQ(int P) -{ - static int tal[4]={1,2,4,6}; - int32 V,amp,rthresh,wl; - - wl=MMC5Sound.wl[P]+1; - amp=((MMC5Sound.env[P]&0xF)<<8); - rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; - - if(wl>=8 && (MMC5Sound.running&(P+1))) - { - int dc,vc; - - wl<<=1; - - dc=MMC5Sound.dcount[P]; - vc=MMC5Sound.vcount[P]; - for(V=MMC5Sound.BC[P];V=1) - { - sfun=Do5SQHQ; - psfun=Do5PCMHQ; - } - else -#endif - { - sfun=Do5SQ; - psfun=Do5PCM; - } - } - else - { - sfun=0; - psfun=0; - } - memset(MMC5Sound.BC,0,sizeof(MMC5Sound.BC)); - memset(MMC5Sound.vcount,0,sizeof(MMC5Sound.vcount)); - GameExpSound.HiSync=0;//MMC5HiSync; -} - -void NSFMMC5_Init(void) -{ - memset(&MMC5Sound,0,sizeof(MMC5Sound)); - mul[0]=mul[1]=0; - ExRAM=(uint8*)FCEU_gmalloc(1024); - Mapper5_ESI(); - SetWriteHandler(0x5c00,0x5fef,MMC5_ExRAMWr); - SetReadHandler(0x5c00,0x5fef,MMC5_ExRAMRd); - MMC5HackCHRMode=2; - SetWriteHandler(0x5000,0x5015,Mapper5_SW); - SetWriteHandler(0x5205,0x5206,Mapper5_write); - SetReadHandler(0x5205,0x5206,MMC5_read); -} - -void NSFMMC5_Close(void) -{ - FCEU_gfree(ExRAM); - ExRAM=0; -} - -static void GenMMC5Reset(void) -{ - int x; - - for(x=0;x<4;x++) PRGBanks[x]=~0; - for(x=0;x<8;x++) CHRBanksA[x]=~0; - for(x=0;x<4;x++) CHRBanksB[x]=~0; - WRAMMaskEnable[0]=WRAMMaskEnable[1]=~0; - - mmc5psize=mmc5vsize=3; - CHRMode=0; - - NTAMirroring=NTFill=ATFill=0xFF; - - MMC5Synco(); - - SetWriteHandler(0x4020,0x5bff,Mapper5_write); - SetReadHandler(0x4020,0x5bff,MMC5_read); - - SetWriteHandler(0x5c00,0x5fff,MMC5_ExRAMWr); - SetReadHandler(0x5c00,0x5fff,MMC5_ExRAMRd); - - SetWriteHandler(0x6000,0xFFFF,MMC5_WriteROMRAM); - SetReadHandler(0x6000,0xFFFF,MMC5_ReadROMRAM); - - SetWriteHandler(0x5000,0x5015,Mapper5_SW); - SetWriteHandler(0x5205,0x5206,Mapper5_write); - SetReadHandler(0x5205,0x5206,MMC5_read); - - //GameHBIRQHook=MMC5_hb; - FCEU_CheatAddRAM(8,0x6000,WRAM); - FCEU_CheatAddRAM(1,0x5c00,ExRAM); -} - -static SFORMAT MMC5_StateRegs[]={ - { PRGBanks, 4, "PRGB"}, - { CHRBanksA, 8, "CHRA"}, - { CHRBanksB, 4, "CHRB"}, - { &WRAMPage, 1, "WRMP"}, - { WRAMMaskEnable, 2, "WRME"}, - { &ABMode, 1, "ABMD"}, - { &IRQScanline, 1, "IRQS"}, - { &IRQEnable, 1, "IRQE"}, - { &CHRMode, 1, "CHRM"}, - { &NTAMirroring, 1, "NTAM"}, - { &NTFill, 1, "NTFL"}, - { &ATFill, 1, "ATFL"}, - - { &MMC5Sound.wl[0], 2|FCEUSTATE_RLSB, "SDW0"}, - { &MMC5Sound.wl[1], 2|FCEUSTATE_RLSB, "SDW1"}, - { MMC5Sound.env, 2, "SDEV"}, - { &MMC5Sound.enable, 1, "SDEN"}, - { &MMC5Sound.running, 1, "SDRU"}, - { &MMC5Sound.raw, 1, "SDRW"}, - { &MMC5Sound.rawcontrol, 1, "SDRC"}, - {0} -}; - -static void GenMMC5_Init(CartInfo *info, int wsize, int battery) -{ - if(wsize) - { - WRAM=(uint8*)FCEU_gmalloc(wsize*1024); - SetupCartPRGMapping(0x10,WRAM,wsize*1024,1); - AddExState(WRAM, wsize*1024, 0, "WRAM"); - } - - MMC5fill=(uint8*)FCEU_gmalloc(1024); - ExRAM=(uint8*)FCEU_gmalloc(1024); - - AddExState(MMC5_StateRegs, ~0, 0, 0); - AddExState(WRAM, wsize*1024, 0, "WRAM"); - AddExState(ExRAM, 1024, 0, "ERAM"); - AddExState(&MMC5HackSPMode, 1, 0, "SPLM"); - AddExState(&MMC5HackSPScroll, 1, 0, "SPLS"); - AddExState(&MMC5HackSPPage, 1, 0, "SPLP"); - - MMC5WRAMsize=wsize/8; - BuildWRAMSizeTable(); - GameStateRestore=MMC5_StateRestore; - info->Power=GenMMC5Reset; - - if(battery) - { - info->SaveGame[0]=WRAM; - if(wsize<=16) - info->SaveGameLen[0]=8192; - else - info->SaveGameLen[0]=32768; - } - - MMC5HackVROMMask=CHRmask4[0]; - MMC5HackExNTARAMPtr=ExRAM; - MMC5Hack=1; - MMC5HackVROMPTR=CHRptr[0]; - MMC5HackCHRMode=0; - MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0; - Mapper5_ESI(); -} - -void Mapper5_Init(CartInfo *info) -{ - GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); -} - -// ELROM seems to have 0KB of WRAM -// EKROM seems to have 8KB of WRAM -// ETROM seems to have 16KB of WRAM -// EWROM seems to have 32KB of WRAM - -// ETROM and EWROM are battery-backed, EKROM isn't. - -void ETROM_Init(CartInfo *info) -{ - GenMMC5_Init(info, 16,info->battery); -} - -void ELROM_Init(CartInfo *info) -{ - GenMMC5_Init(info,0,0); -} - -void EWROM_Init(CartInfo *info) -{ - GenMMC5_Init(info,32,info->battery); -} - -void EKROM_Init(CartInfo *info) -{ - GenMMC5_Init(info,8,info->battery); -} +/* 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 + */ + +/* None of this code should use any of the iNES bank switching wrappers. */ + +#include "mapinc.h" + +static void (*sfun)(int P); +static void (*psfun)(void); + +void MMC5RunSound(int Count); +void MMC5RunSoundHQ(void); + +static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) +{ + if(CHRptr[0]) + { + V&=CHRmask1[0]; + MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A); + } +} + +static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}} + +static INLINE void MMC5SPRVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} +static INLINE void MMC5BGVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} + +static INLINE void MMC5SPRVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]= MMC5SPRVPage[((A)>>10)+2]=MMC5SPRVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} +static INLINE void MMC5BGVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=MMC5BGVPage[((A)>>10)+2]=MMC5BGVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} + +static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5SPRVPage[0]=MMC5SPRVPage[1]=MMC5SPRVPage[2]=MMC5SPRVPage[3]=MMC5SPRVPage[4]=MMC5SPRVPage[5]=MMC5SPRVPage[6]=MMC5SPRVPage[7]=&CHRptr[0][(V)<<13];}} +static INLINE void MMC5BGVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5BGVPage[0]=MMC5BGVPage[1]=MMC5BGVPage[2]=MMC5BGVPage[3]=MMC5BGVPage[4]=MMC5BGVPage[5]=MMC5BGVPage[6]=MMC5BGVPage[7]=&CHRptr[0][(V)<<13];}} + +static uint8 PRGBanks[4]; +static uint8 WRAMPage; +static uint16 CHRBanksA[8], CHRBanksB[4]; +static uint8 WRAMMaskEnable[2]; +uint8 mmc5ABMode; /* A=0, B=1 */ + +static uint8 IRQScanline,IRQEnable; +static uint8 CHRMode, NTAMirroring, NTFill, ATFill; + +static uint8 MMC5IRQR; +static uint8 MMC5LineCounter; +static uint8 mmc5psize, mmc5vsize; +static uint8 mul[2]; + +static uint8 *WRAM=NULL; +static uint8 *MMC5fill=NULL; +static uint8 *ExRAM=NULL; + +static uint8 MMC5WRAMsize; +static uint8 MMC5WRAMIndex[8]; + +static uint8 MMC5ROMWrProtect[4]; +static uint8 MMC5MemIn[5]; + +static void MMC5CHRA(void); +static void MMC5CHRB(void); + +typedef struct __cartdata { + uint32 crc32; + uint8 size; +} cartdata; + +#define Sprite16 (PPU[0]&0x20) //Sprites 8x16/8x8 +//#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] +static inline uint8 * MMC5BGVRAMADR(uint32 A) +{ + if(!Sprite16) { + if(mmc5ABMode==0) + return &MMC5SPRVPage[(A)>>10][(A)]; + else + return &MMC5BGVPage[(A)>>10][(A)]; + } else return &MMC5BGVPage[(A)>>10][(A)]; +} + +static void mmc5_PPUWrite(uint32 A, uint8 V) { + uint32 tmp = A; + extern uint8 PALRAM[0x20]; + + if(tmp>=0x3F00) + { + // hmmm.... + if(!(tmp&0xf)) + PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3F; + else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; + } + else if(tmp<0x2000) + { + if(PPUCHRRAM&(1<<(tmp>>10))) + VPage[tmp>>10][tmp]=V; + } + else + { + if(PPUNTARAM&(1<<((tmp&0xF00)>>10))) + vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V; + } +} + +uint8 FASTCALL mmc5_PPURead(uint32 A) { + if(A<0x2000) + { + if(ppuphase == PPUPHASE_BG) + return *MMC5BGVRAMADR(A); + else return MMC5SPRVPage[(A)>>10][(A)]; + } + else + { + return vnapage[(A>>10)&0x3][A&0x3FF]; + } +} + + + +// ELROM seems to have 8KB of RAM +// ETROM seems to have 16KB of WRAM +// EWROM seems to have 32KB of WRAM + +cartdata MMC5CartList[]= +{ + {0x9c18762b,2}, /* L'Empereur */ + {0x26533405,2}, + {0x6396b988,2}, + {0xaca15643,2}, /* Uncharted Waters */ + {0xfe3488d1,2}, /* Dai Koukai Jidai */ + {0x15fe6d0f,2}, /* BKAC */ + {0x39f2ce4b,2}, /* Suikoden */ + {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ + {0xeee9a682,2}, + {0xf9b4240f,2}, + {0x1ced086f,2}, /* Ishin no Arashi */ + {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ + {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ + {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ + {0x184c2124,4}, /* Sangokushi 2 */ + {0xee8e6553,4}, +}; + +#define MMC5_NOCARTS (sizeof(MMC5CartList)/sizeof(MMC5CartList[0])) +int DetectMMC5WRAMSize(uint32 crc32) +{ + int x; + for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(MMC5CartList[x].size*8); + } + } + + //mbg 04-aug-08 - previously, this was returning 8KB + //but I changed it to return 64 because unlisted carts are probably homebrews, and they should probably use 64 (why not use it all?) + //ch4 10-dec-08 - then f***ng for what all this shit above? let's give em all this 64k shit! Damn + // homebrew must use it's own emulators or standart features. + //adelikat 20-dec-08 - reverting back to return 64, sounds like it was changed back to 8 simply on principle. FCEUX is all encompassing, and that include + //rom-hacking. We want it to be the best emulator for such purposes. So unless return 64 harms compatibility with anything else, I see now reason not to have it + //mbg 29-mar-09 - I should note that mmc5 is in principle capable of 64KB, even if no real carts ever supported it. + //This does not in principle break any games which share this mapper, and it should be OK for homebrew. + //if there are games which need 8KB instead of 64KB default then lets add them to the list + return 64; +} + +static void BuildWRAMSizeTable(void) +{ + int x; + for(x=0;x<8;x++) + { + switch(MMC5WRAMsize) + { + case 0: MMC5WRAMIndex[x]=255; break; //X,X,X,X,X,X,X,X + case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; //0,0,0,0,X,X,X,X + case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; //0,0,0,0,1,1,1,1 + case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; //0,1,2,3,X,X,X,X + case 8: MMC5WRAMIndex[x]=x; break; //0,1,2,3,4,5,6,7,8 + //mbg 8/6/08 - i added this to support 64KB of wram + //now, I have at least one example (laser invasion) which actually uses size 1 but isnt in the crc list + //so, whereas before my change on 8/4/08 we would have selected size 1, now we select size 8 + //this means that we could have just introduced an emulation bug, in case those games happened to + //address, say, page 3. with size 1 that would resolve to [0] but in size 8 it resolves to [3]. + //so, you know what to do if there are problems. + } + } +} + +static void MMC5CHRA(void) +{ + int x; + switch(mmc5vsize&3) + { + case 0: setchr8(CHRBanksA[7]); + MMC5SPRVROM_BANK8(CHRBanksA[7]); + break; + case 1: setchr4(0x0000,CHRBanksA[3]); + setchr4(0x1000,CHRBanksA[7]); + MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); + MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); + break; + case 2: setchr2(0x0000,CHRBanksA[1]); + setchr2(0x0800,CHRBanksA[3]); + setchr2(0x1000,CHRBanksA[5]); + setchr2(0x1800,CHRBanksA[7]); + MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); + MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); + MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); + MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); + break; + case 3: for(x=0;x<8;x++) + { + setchr1(x<<10,CHRBanksA[x]); + MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); + } + break; + } +} + +static void MMC5CHRB(void) +{ + int x; + switch(mmc5vsize&3) + { + case 0: setchr8(CHRBanksB[3]); + MMC5BGVROM_BANK8(CHRBanksB[3]); + break; + case 1: setchr4(0x0000,CHRBanksB[3]); + setchr4(0x1000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); + break; + case 2: setchr2(0x0000,CHRBanksB[1]); + setchr2(0x0800,CHRBanksB[3]); + setchr2(0x1000,CHRBanksB[1]); + setchr2(0x1800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); + break; + case 3: for(x=0;x<8;x++) + { + setchr1(x<<10,CHRBanksB[x&3]); + MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); + } + break; + } +} + +static void MMC5WRAM(uint32 A, uint32 V) +{ + //printf("%02x\n",V); + V=MMC5WRAMIndex[V&7]; + if(V!=255) + { + setprg8r(0x10,A,V); + MMC5MemIn[(A-0x6000)>>13]=1; + } + else + MMC5MemIn[(A-0x6000)>>13]=0; +} + +static void MMC5PRG(void) +{ + int x; + switch(mmc5psize&3) + { + case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]= + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); + for(x=0;x<4;x++) + MMC5MemIn[1+x]=1; + break; + case 1: if(PRGBanks[1]&0x80) + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]>>1)); + MMC5MemIn[1]=MMC5MemIn[2]=1; + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + MMC5MemIn[3]=MMC5MemIn[4]=1; + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); + break; + case 2: if(PRGBanks[1]&0x80) + { + MMC5MemIn[1]=MMC5MemIn[2]=1; + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + if(PRGBanks[2]&0x80) + { + MMC5ROMWrProtect[2]=1; + MMC5MemIn[3]=1; + setprg8(0xC000,PRGBanks[2]&0x7F); + } + else + { + MMC5ROMWrProtect[2]=0; + MMC5WRAM(0xC000,PRGBanks[2]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; + case 3: for(x=0;x<3;x++) + if(PRGBanks[x]&0x80) + { + MMC5ROMWrProtect[x]=1; + setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); + MMC5MemIn[1+x]=1; + } + else + { + MMC5ROMWrProtect[x]=0; + MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; + } +} + +static DECLFW(Mapper5_write) +{ + if(A>=0x5120&&A<=0x5127) + { + mmc5ABMode = 0; + CHRBanksA[A&7]=V | ((MMC50x5130&0x3)<<8); //if we had a test case for this then we could test this, but it hasnt been verified + //CHRBanksA[A&7]=V; + MMC5CHRA(); + } + else switch(A) + { + case 0x5105: { + int x; + for(x=0;x<4;x++) + { + switch((V>>(x<<1))&3) + { + case 0: + PPUNTARAM|=1<>3)&0x1F;break; + case 0x5202: MMC5HackSPPage=V&0x3F;break; + case 0x5203: X6502_IRQEnd(FCEU_IQEXT);IRQScanline=V;break; + case 0x5204: X6502_IRQEnd(FCEU_IQEXT);IRQEnable=V&0x80;break; + case 0x5205: mul[0]=V;break; + case 0x5206: mul[1]=V;break; + } +} + +static DECLFR(MMC5_ReadROMRAM) +{ + if(MMC5MemIn[(A-0x6000)>>13]) + return Page[A>>11][A]; + else + return X.DB; +} + +static DECLFW(MMC5_WriteROMRAM) +{ + if(A>=0x8000) + if(MMC5ROMWrProtect[(A-0x8000)>>13]) return; + if(MMC5MemIn[(A-0x6000)>>13]) + if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) + Page[A>>11][A]=V; +} + +static DECLFW(MMC5_ExRAMWr) +{ + if(MMC5HackCHRMode!=3) + ExRAM[A&0x3ff]=V; +} + +static DECLFR(MMC5_ExRAMRd) +{ + /* Not sure if this is correct, so I'll comment it out for now. */ + //if(MMC5HackCHRMode>=2) + return ExRAM[A&0x3ff]; + //else + // return(X.DB); +} + +static DECLFR(MMC5_read) +{ + switch(A) + { + case 0x5204: X6502_IRQEnd(FCEU_IQEXT); + { + uint8 x; + x=MMC5IRQR; + if(!fceuindbg) + MMC5IRQR&=0x40; + return x; + } + case 0x5205: return (mul[0]*mul[1]); + case 0x5206: return ((mul[0]*mul[1])>>8); + } + return(X.DB); +} + +void MMC5Synco(void) +{ + int x; + + MMC5PRG(); + for(x=0;x<4;x++) + { + switch((NTAMirroring>>(x<<1))&3) + { + case 0:PPUNTARAM|=1<>4]+=MMC5Sound.raw<<1; +} + +static void Do5PCMHQ() +{ + uint32 V; //mbg merge 7/17/06 made uint32 + if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) + for(V=MMC5Sound.BC[2];V>2); + MMC5Sound.env[A>>2]=V; + break; + case 0x2: + case 0x6: if(sfun) sfun(A>>2); + MMC5Sound.wl[A>>2]&=~0x00FF; + MMC5Sound.wl[A>>2]|=V&0xFF; + break; + case 0x3: + case 0x7://printf("%04x:$%02x\n",A,V>>3); + MMC5Sound.wl[A>>2]&=~0x0700; + MMC5Sound.wl[A>>2]|=(V&0x07)<<8; + MMC5Sound.running|=1<<(A>>2); + break; + case 0x15:if(sfun) + { + sfun(0); + sfun(1); + } + MMC5Sound.running&=V; + MMC5Sound.enable=V; + //printf("%02x\n",V); + break; + } +} + +static void Do5SQ(int P) +{ + static int tal[4]={1,2,4,6}; + int32 V,amp,rthresh,wl; + int32 start,end; + + start=MMC5Sound.BC[P]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + MMC5Sound.BC[P]=end; + + wl=MMC5Sound.wl[P]+1; + amp=(MMC5Sound.env[P]&0xF)<<4; + rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; + + if(wl>=8 && (MMC5Sound.running&(P+1))) + { + int dc,vc; + + wl<<=18; + dc=MMC5Sound.dcount[P]; + vc=MMC5Sound.vcount[P]; + + for(V=start;V>4]+=amp; + vc-=nesincsize; + while(vc<=0) + { + vc+=wl; + dc=(dc+1)&7; + } + } + MMC5Sound.dcount[P]=dc; + MMC5Sound.vcount[P]=vc; + } +} + +static void Do5SQHQ(int P) +{ + static int tal[4]={1,2,4,6}; + uint32 V; //mbg merge 7/17/06 made uint32 + int32 amp,rthresh,wl; + + wl=MMC5Sound.wl[P]+1; + amp=((MMC5Sound.env[P]&0xF)<<8); + rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; + + if(wl>=8 && (MMC5Sound.running&(P+1))) + { + int dc,vc; + + wl<<=1; + + dc=MMC5Sound.dcount[P]; + vc=MMC5Sound.vcount[P]; + for(V=MMC5Sound.BC[P];V=1) + { + sfun=Do5SQHQ; + psfun=Do5PCMHQ; + } + else + { + sfun=Do5SQ; + psfun=Do5PCM; + } + } + else + { + sfun=0; + psfun=0; + } + memset(MMC5Sound.BC,0,sizeof(MMC5Sound.BC)); + memset(MMC5Sound.vcount,0,sizeof(MMC5Sound.vcount)); + GameExpSound.HiSync=MMC5HiSync; +} + +void NSFMMC5_Init(void) +{ + memset(&MMC5Sound,0,sizeof(MMC5Sound)); + mul[0]=mul[1]=0; + ExRAM=(uint8*)FCEU_gmalloc(1024); + Mapper5_ESI(); + SetWriteHandler(0x5c00,0x5fef,MMC5_ExRAMWr); + SetReadHandler(0x5c00,0x5fef,MMC5_ExRAMRd); + MMC5HackCHRMode=2; + SetWriteHandler(0x5000,0x5015,Mapper5_SW); + SetWriteHandler(0x5205,0x5206,Mapper5_write); + SetReadHandler(0x5205,0x5206,MMC5_read); +} + +void NSFMMC5_Close(void) +{ + FCEU_gfree(ExRAM); + ExRAM=0; +} + +static void GenMMC5Reset(void) +{ + int x; + + for(x=0;x<4;x++) PRGBanks[x]=~0; + for(x=0;x<8;x++) CHRBanksA[x]=~0; + for(x=0;x<4;x++) CHRBanksB[x]=~0; + WRAMMaskEnable[0]=WRAMMaskEnable[1]=~0; + + mmc5psize=mmc5vsize=3; + CHRMode=0; + + NTAMirroring=NTFill=ATFill=0xFF; + + MMC5Synco(); + + SetWriteHandler(0x4020,0x5bff,Mapper5_write); + SetReadHandler(0x4020,0x5bff,MMC5_read); + + SetWriteHandler(0x5c00,0x5fff,MMC5_ExRAMWr); + SetReadHandler(0x5c00,0x5fff,MMC5_ExRAMRd); + + SetWriteHandler(0x6000,0xFFFF,MMC5_WriteROMRAM); + SetReadHandler(0x6000,0xFFFF,MMC5_ReadROMRAM); + + SetWriteHandler(0x5000,0x5015,Mapper5_SW); + SetWriteHandler(0x5205,0x5206,Mapper5_write); + SetReadHandler(0x5205,0x5206,MMC5_read); + + //GameHBIRQHook=MMC5_hb; + FCEU_CheatAddRAM(8,0x6000,WRAM); + FCEU_CheatAddRAM(1,0x5c00,ExRAM); +} + +static SFORMAT MMC5_StateRegs[]={ + { PRGBanks, 4, "PRGB"}, + { CHRBanksA, 16, "CHRA"}, + { CHRBanksB, 8, "CHRB"}, + { &WRAMPage, 1, "WRMP"}, + { WRAMMaskEnable, 2, "WRME"}, + { &mmc5ABMode, 1, "ABMD"}, + { &IRQScanline, 1, "IRQS"}, + { &IRQEnable, 1, "IRQE"}, + { &CHRMode, 1, "CHRM"}, + { &NTAMirroring, 1, "NTAM"}, + { &NTFill, 1, "NTFL"}, + { &ATFill, 1, "ATFL"}, + + { &MMC5Sound.wl[0], 2|FCEUSTATE_RLSB, "SDW0"}, + { &MMC5Sound.wl[1], 2|FCEUSTATE_RLSB, "SDW1"}, + { MMC5Sound.env, 2, "SDEV"}, + { &MMC5Sound.enable, 1, "SDEN"}, + { &MMC5Sound.running, 1, "SDRU"}, + { &MMC5Sound.raw, 1, "SDRW"}, + { &MMC5Sound.rawcontrol, 1, "SDRC"}, + {0} +}; + +static void GenMMC5_Init(CartInfo *info, int wsize, int battery) +{ + if(wsize) + { + WRAM=(uint8*)FCEU_gmalloc(wsize*1024); + SetupCartPRGMapping(0x10,WRAM,wsize*1024,1); + AddExState(WRAM, wsize*1024, 0, "WRAM"); + } + + MMC5fill=(uint8*)FCEU_gmalloc(1024); + ExRAM=(uint8*)FCEU_gmalloc(1024); + + AddExState(MMC5_StateRegs, ~0, 0, 0); + AddExState(WRAM, wsize*1024, 0, "WRAM"); + AddExState(ExRAM, 1024, 0, "ERAM"); + AddExState(&MMC5HackSPMode, 1, 0, "SPLM"); + AddExState(&MMC5HackSPScroll, 1, 0, "SPLS"); + AddExState(&MMC5HackSPPage, 1, 0, "SPLP"); + AddExState(&MMC50x5130, 1, 0, "5130"); + + MMC5WRAMsize=wsize/8; + BuildWRAMSizeTable(); + GameStateRestore=MMC5_StateRestore; + info->Power=GenMMC5Reset; + + if(battery) + { + info->SaveGame[0]=WRAM; + if(wsize<=16) + info->SaveGameLen[0]=8192; + else + info->SaveGameLen[0]=32768; + } + + MMC5HackVROMMask=CHRmask4[0]; + MMC5HackExNTARAMPtr=ExRAM; + MMC5Hack=1; + MMC5HackVROMPTR=CHRptr[0]; + MMC5HackCHRMode=0; + MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0; + Mapper5_ESI(); + + FFCEUX_PPURead = mmc5_PPURead; + FFCEUX_PPUWrite = mmc5_PPUWrite; +} + +void Mapper5_Init(CartInfo *info) +{ + GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); +} + +// ELROM seems to have 0KB of WRAM +// EKROM seems to have 8KB of WRAM +// ETROM seems to have 16KB of WRAM +// EWROM seems to have 32KB of WRAM + +// ETROM and EWROM are battery-backed, EKROM isn't. + +void ETROM_Init(CartInfo *info) +{ + GenMMC5_Init(info, 16,info->battery); +} + +void ELROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,0,0); +} + +void EWROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,32,info->battery); +} + +void EKROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,8,info->battery); +} diff --git a/boards/n-c22m.c b/boards/n-c22m.c new file mode 100644 index 0000000..49f965f --- /dev/null +++ b/boards/n-c22m.c @@ -0,0 +1,103 @@ +/* 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 + * Mortal Kombat 2 YOKO */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reg[8]; + +static SFORMAT StateRegs[]= +{ + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ +// FCEU_printf("(%02x, %02x)\n",reg[3],reg[4]); + setprg8(0x8000,reg[0]); + setprg8(0xA000,reg[1]); + setprg8(0xC000,reg[2]); + setprg8(0xE000,~0); +// setchr2(0x0000,reg[3]); +// setchr2(0x0800,reg[4]); +// setchr2(0x1000,reg[5]); +// setchr2(0x1800,reg[6]); + setchr2(0x0000,reg[3]); + setchr2(0x0800,reg[4]); + setchr2(0x1000,reg[5]); + setchr2(0x1800,reg[6]); +} + +static DECLFW(MCN22MWrite) +{ +//FCEU_printf("bs %04x %02x\n",A,V); + switch(A) + { + case 0x8c00: + case 0x8c01: + case 0x8c02: reg[A&3]=V; break; + case 0x8d10: reg[3]=V; break; + case 0x8d11: reg[4]=V; break; + case 0x8d16: reg[5]=V; break; + case 0x8d17: reg[6]=V; break; + } + Sync(); +} + +static void MCN22MPower(void) +{ + reg[0]=reg[1]=reg[2]=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,MCN22MWrite); +} +/* +static void MCN22MIRQHook(void) +{ + int 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(); +} + +void UNLCN22M_Init(CartInfo *info) +{ + info->Power=MCN22MPower; +// GameHBIRQHook=MCN22MIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/n106.c b/boards/n106.c index d54af02..880a296 100644 --- a/boards/n106.c +++ b/boards/n106.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -23,8 +23,8 @@ static uint16 IRQCount; static uint8 IRQa; -static uint8 WRAM[8192] __attribute__ ((aligned (4))); -static uint8 IRAM[128] __attribute__ ((aligned (4))); +static uint8 WRAM[8192]; +static uint8 IRAM[128]; static DECLFR(AWRAM) { @@ -47,7 +47,7 @@ static uint8 gorko; static void NamcoSound(int Count); static void NamcoSoundHack(void); static void DoNamcoSound(int32 *Wave, int Count); -//static void DoNamcoSoundHQ(void); +static void DoNamcoSoundHQ(void); static void SyncHQ(int32 ts); static int is210; /* Lesser mapper. */ @@ -70,7 +70,7 @@ static void SyncPRG(void) setprg8(0xe000,0x3F); } -static void FP_FASTAPASS(1) NamcoIRQHook(int a) +static void NamcoIRQHook(int a) { if(IRQa) { @@ -104,7 +104,7 @@ static DECLFR(Namco_Read5800) return(IRQCount>>8); } -static void FASTAPASS(2) DoNTARAMROM(int w, uint8 V) +static void DoNTARAMROM(int w, uint8 V) { NTAPage[w]=V; if(V>=0xE0) @@ -123,7 +123,7 @@ static void FixNTAR(void) DoNTARAMROM(x,NTAPage[x]); } -static void FASTAPASS(2) DoCHRRAMROM(int x, uint8 V) +static void DoCHRRAMROM(int x, uint8 V) { CHR[x]=V; if(!is210 && !((gorfus>>((x>>2)+6))&1) && (V>=0xE0)) @@ -179,7 +179,7 @@ static DECLFW(Mapper19_write) { NamcoSoundHack(); GameExpSound.Fill=NamcoSound; - GameExpSound.HiFill=0;//DoNamcoSoundHQ; + GameExpSound.HiFill=DoNamcoSoundHQ; GameExpSound.HiSync=SyncHQ; } FixCache(dopol,V); @@ -220,16 +220,14 @@ static int dwave=0; static void NamcoSoundHack(void) { int32 z,a; -#if 0 if(FSettings.soundq>=1) { DoNamcoSoundHQ(); return; } -#endif z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; - if(a) DoNamcoSound((int32 *)&Wave[dwave], a); + if(a) DoNamcoSound(&Wave[dwave], a); dwave+=a; } @@ -238,7 +236,7 @@ static void NamcoSound(int Count) int32 z,a; z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; - if(a) DoNamcoSound((int32 *)&Wave[dwave], a); + if(a) DoNamcoSound(&Wave[dwave], a); dwave=0; } @@ -274,10 +272,10 @@ static INLINE uint32 FetchDuff(uint32 P, uint32 envelope) return(duff); } -#if 0 static void DoNamcoSoundHQ(void) { - int32 P,V; + uint32 V; //mbg merge 7/17/06 made uint32 + int32 P; int32 cyclesuck=(((IRAM[0x7F]>>4)&7)+1)*15; for(P=7;P>=(7-((IRAM[0x7F]>>4)&7));P--) @@ -311,7 +309,7 @@ static void DoNamcoSoundHQ(void) } CVBC=SOUNDTS; } -#endif + static void DoNamcoSound(int32 *Wave, int Count) { @@ -366,10 +364,10 @@ static void DoNamcoSound(int32 *Wave, int Count) static void Mapper19_StateRestore(int version) { + int x; SyncPRG(); FixNTAR(); FixCRR(); - int x; for(x=0x40;x<0x80;x++) FixCache(x,IRAM[x]); } @@ -445,7 +443,7 @@ void Mapper19_Init(CartInfo *info) Mapper19_ESI(); AddExState(WRAM, 8192, 0, "WRAM"); - AddExState(IRAM, 128, 0, "WRAM"); + AddExState(IRAM, 128, 0, "IRAM"); AddExState(N106_StateRegs, ~0, 0, 0); if(info->battery) @@ -469,4 +467,5 @@ void Mapper210_Init(CartInfo *info) GameStateRestore=Mapper210_StateRestore; info->Power=N106_Power; AddExState(WRAM, 8192, 0, "WRAM"); + AddExState(N106_StateRegs, ~0, 0, 0); } diff --git a/boards/n625092.c b/boards/n625092.c new file mode 100644 index 0000000..30d8298 --- /dev/null +++ b/boards/n625092.c @@ -0,0 +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 + * 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&0xe0)>>2)|bank); + setprg16(0xC000,((cmd&0xe0)>>2)|7); + } + else + { + setprg16(0x8000,((cmd&0xe0)>>2)|(bank&6)); + setprg16(0xC000,((cmd&0xe0)>>2)|((bank&6)|1)); + } + } + else + { + setprg16(0x8000,((cmd&0xe0)>>2)|bank); + setprg16(0xC000,((cmd&0xe0)>>2)|bank); + } +} + +static DECLFW(UNLN625092WriteCommand) +{ + cmd=A; + 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; +} + +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/boards/novel.c b/boards/novel.c index 26e70ec..1918abf 100644 --- a/boards/novel.c +++ b/boards/novel.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/boards/onebus.c b/boards/onebus.c new file mode 100644 index 0000000..a09b488 --- /dev/null +++ b/boards/onebus.c @@ -0,0 +1,308 @@ +/* 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 + * + * OneBus system + * Street Dance (Dance pad) (Unl) + * 101-in-1 Arcade Action II + * DreamGEAR 75-in-1 + */ + +#include "mapinc.h" + +static uint8 isDance; +static uint8 regs[16],regc[6]; +static uint8 IRQCount,IRQLatch,IRQa, IRQReload, pcm_enable = 0, pcm_irq = 0; +static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xF6; +static writefunc old4011write, old4012write, old4013write, old4015write; +static readfunc old4015read; + +static SFORMAT StateRegs[]= +{ + {regc, 6, "REGC"}, + {regs, 16, "REGS"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {&pcm_enable, 1, "PCME"}, + {&pcm_irq, 1, "PCMIRQ"}, + {&pcm_addr, 2, "PCMADDR"}, + {&pcm_size, 2, "PCMSIZE"}, + {&pcm_latch, 2, "PCMLATCH"}, + {&pcm_clock, 2, "PCMCLOCK"}, + {0} +}; + +static void Sync(void) +{ + uint16 cswap = (regs[0xf] & 0x80) << 5; + uint16 pswap = (regs[0xd]&1)?((regs[0xf] & 0x40) << 8):0; + uint16 pbase = (regs[0]&0xf0)<<4; + uint16 cbase = (((regs[0]&0x0f)<<8)|(regs[0xc]<<1)|((regs[0xd]&0xf8)>>3))<<3; + uint16 pmask = 0x3f>>(regs[0xb]&0xf); + + setchr1(cswap^0x0000,cbase|(regc[0]&(~1))); + setchr1(cswap^0x0400,cbase|(regc[0]|1)); + setchr1(cswap^0x0800,cbase|(regc[1]&(-1))); + setchr1(cswap^0x0c00,cbase|(regc[1]|1)); + setchr1(cswap^0x1000,cbase|(regc[2])); + setchr1(cswap^0x1400,cbase|(regc[3])); + setchr1(cswap^0x1800,cbase|(regc[4])); + setchr1(cswap^0x1c00,cbase|(regc[5])); + + if(regs[0xd]&2) + { + setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask))); + setprg8(pswap^0xC000, pbase|(regs[0x9]&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xE000, pbase|regs[0xa]); + } + else + { + setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask))); + setprg8(pswap^0xC000, pbase|((~1)&pmask)|(regs[0xa]&(~pmask))); + setprg8( 0xE000, pbase|((~0)&pmask)|(regs[0xa]&(~pmask))); + } + + setmirror(regs[0xe]); +} + +static DECLFW(UNLOneBusWrite20XX) +{ +// FCEU_printf("PPU %04x:%04x\n",A,V); + if(A == 0x201A) + regs[0xd] = V; + else if(A == 0x2018) + regs[0xc] = V; + Sync(); +} + +static DECLFW(UNLOneBusWriteExp) +{ +// FCEU_printf("EXP %04x:%04x\n",A,V); +// switch(A & 0x0F) +// { +// case 2: pcm_latch = pcm_clock; FCEU_printf("write %04x:%04x\n",A,V); break; +// case 3: pcm_irqa = 0; X6502_IRQEnd(FCEU_IQEXT); pcm_irq = 0; FCEU_printf("write %04x:%04x\n",A,V); break; +// case 4: pcm_irqa = 1; FCEU_printf("write %04x:%04x\n",A,V); break; +// default: + regs[A & 0x0F] = V; + Sync(); +// } +} + +static DECLFW(UNLOneBusWriteDebug) +{ +// FCEU_printf("write %04x:%04x\n",A,V); +} + +static DECLFW(UNLOneBusWriteMMC) +{ +// FCEU_printf("MMC %04x:%04x\n",A,V); + switch(A&0xE001) + { + case 0x8000: regs[0xf] = V; Sync(); break; + case 0x8001: + { + uint8 mask = 0xff, mmc3cmd = regs[0xf]&7; + switch(mmc3cmd) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + if(regs[0xd]&4) + mask = 0x0f; + else + mask >>= ((regs[0xb]&0xf0)>>4); + regc[mmc3cmd] = V&mask; + break; + case 6: + case 7: + mask = (mask&0x3f)>>(regs[0xb]&0xf); + regs[mmc3cmd+1] = (regs[mmc3cmd+1]&(~mask))|(V&mask); + break; + } + + Sync(); + break; + } + case 0xA000: regs[0xe] = (V & 1)^1; Sync(); 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) +{ + int count = IRQCount; + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if(count && !IRQCount) + { + if(IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static DECLFW(UNLOneBusWriteAPU2) +{ +// FCEU_printf("APU2 %04x:%04x\n",A,V); + CartBW(A&0xffdf,V); +} + +static DECLFW(UNLOneBusWrite4012) +{ +// FCEU_printf("write %04x:%04x\n",A,V); + pcm_addr = V << 6; + old4012write(A,V); +} + +static DECLFW(UNLOneBusWrite4013) +{ +// FCEU_printf("write %04x:%04x\n",A,V); + pcm_size = (V << 4) + 1; + old4013write(A,V); +} + +static DECLFW(UNLOneBusWrite4015) +{ +// FCEU_printf("write %04x:%04x\n",A,V); + pcm_enable = V&0x10; + if(pcm_irq) + { + X6502_IRQEnd(FCEU_IQEXT); + pcm_irq = 0; + } + if(pcm_enable) + pcm_latch = pcm_clock; + old4015write(A,V&0xEF); +} + +static DECLFR(UNLOneBusRead4015) +{ + uint8 result = (old4015read(A) & 0x7F)|pcm_irq; +// FCEU_printf("read %04x, %02x\n",A,result); + 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 + { + uint8 raw_pcm = ARead[pcm_addr](pcm_addr) >> 1; + old4011write(0x4011,raw_pcm); + pcm_addr++; + pcm_addr&=0x7FFF; + } + } + } +} + +static void UNLOneBusPower(void) +{ + IRQCount=IRQLatch=IRQa==0; + regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; + regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0; + regs[0x09]=0x3E; + regs[0x0A]=0x3F; + + SetupCartCHRMapping(0,PRGptr[0],4096 * 1024,0); + + if(isDance) // quick workaround, TODO: figure out how it works together + { + old4015read=GetReadHandler(0x4015); + SetReadHandler(0x4015,0x4015,UNLOneBusRead4015); + old4011write=GetWriteHandler(0x4011); + old4012write=GetWriteHandler(0x4012); + SetWriteHandler(0x4012,0x4012,UNLOneBusWrite4012); + old4013write=GetWriteHandler(0x4013); + SetWriteHandler(0x4013,0x4013,UNLOneBusWrite4013); + old4015write=GetWriteHandler(0x4015); + SetWriteHandler(0x4015,0x4015,UNLOneBusWrite4015); + } + + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x2009,0x2fff,UNLOneBusWrite20XX); +// SetWriteHandler(0x4020,0xffff,UNLOneBusWriteDebug); +// SetWriteHandler(0x4020,0x4040,UNLOneBusWriteAPU2); + SetWriteHandler(0x4100,0x410f,UNLOneBusWriteExp); + SetWriteHandler(0x8000,0xefff,UNLOneBusWriteMMC); + Sync(); +} + +static void UNLOneBusReset(void) +{ + IRQCount=IRQLatch=IRQa=0; + regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; + regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0; + regs[0x09]=0x3E; + regs[0x0A]=0x3F; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLOneBus_Init(CartInfo *info) +{ + isDance = 0; + info->Power=UNLOneBusPower; + info->Reset=UNLOneBusReset; + GameHBIRQHook=UNLOneBusIRQHook; +// MapIRQHook=UNLOneBusCpuHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void UNLDANCE_Init(CartInfo *info) +{ + isDance = 1; + info->Power=UNLOneBusPower; + info->Reset=UNLOneBusReset; + GameHBIRQHook=UNLOneBusIRQHook; + MapIRQHook=UNLOneBusCpuHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/sachen.c b/boards/sachen.c index 64ad5f6..ab57f3c 100644 --- a/boards/sachen.c +++ b/boards/sachen.c @@ -15,12 +15,12 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -static uint8 cmd; +static uint8 cmd, dip; static uint8 latch[8]; static void S74LS374MSync(uint8 mirr) @@ -64,7 +64,8 @@ static DECLFR(S74LS374NRead) { uint8 ret; if((A&0x4100)==0x4100) - ret=(X.DB&0xC0)|((~cmd)&0x3F); +// ret=(X.DB&0xC0)|((~cmd)&0x3F); + ret=((~cmd)&0x3F)^dip; else ret=X.DB; return ret; @@ -72,6 +73,7 @@ static DECLFR(S74LS374NRead) static void S74LS374NPower(void) { + dip=0; latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; S74LS374NSynco(); SetReadHandler(0x8000,0xFFFF,CartBR); @@ -79,6 +81,13 @@ static void S74LS374NPower(void) SetReadHandler(0x4100,0x5fff,S74LS374NRead); } +static void S74LS374NReset(void) +{ + dip^=1; + latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; + S74LS374NSynco(); +} + static void S74LS374NRestore(int version) { S74LS374NSynco(); @@ -87,9 +96,11 @@ static void S74LS374NRestore(int version) void S74LS374N_Init(CartInfo *info) { info->Power=S74LS374NPower; + info->Reset=S74LS374NReset; GameStateRestore=S74LS374NRestore; AddExState(latch, 5, 0, "LATC"); AddExState(&cmd, 1, 0, "CMD"); + AddExState(&dip, 1, 0, "DIP"); } static void S74LS374NASynco(void) @@ -291,6 +302,12 @@ static void SA72007Synco() setchr8(latch[0]>>7); } +static void SA009Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]&1); +} + static void SA72008Synco() { setprg32(0x8000,(latch[0]>>2)&1); @@ -321,6 +338,14 @@ void SA72008_Init(CartInfo *info) AddExState(&latch[0], 1, 0, "LATC"); } +void SA009_Init(CartInfo *info) +{ + WSync=SA009Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + void SA0036_Init(CartInfo *info) { WSync=SA72007Synco; @@ -337,13 +362,15 @@ void SA0037_Init(CartInfo *info) AddExState(&latch[0], 1, 0, "LATC"); } +// ----------------------------------------------- + static void TCU01Synco() { - setprg32(0x8000,(latch[0]>>2)&1); + setprg32(0x8000,((latch[0]&0x80)>>6)|((latch[0]>>2)&1)); setchr8((latch[0]>>3)&0xF); } -static DECLFW(TCWrite) +static DECLFW(TCU01Write) { if((A&0x103)==0x102) { @@ -352,11 +379,11 @@ static DECLFW(TCWrite) } } -static void TCU01Reset(void) +static void TCU01Power(void) { latch[0]=0; SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x4100,0xFFFF,TCWrite); + SetWriteHandler(0x4100,0xFFFF,TCU01Write); TCU01Synco(); } @@ -368,10 +395,55 @@ static void TCU01Restore(int version) void TCU01_Init(CartInfo *info) { GameStateRestore=TCU01Restore; - info->Power=TCU01Reset; + info->Power=TCU01Power; AddExState(&latch[0], 1, 0, "LATC"); } +//----------------------------------------------- + +static void TCU02Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]&3); +} + +static DECLFW(TCU02Write) +{ + if((A&0x103)==0x102) + { + latch[0]=V+3; + TCU02Synco(); + } +} + +static DECLFR(TCU02Read) +{ + return (latch[0]&0x3F)|(X.DB&0xC0); +} + +static void TCU02Power(void) +{ + latch[0]=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4100,0x4100,TCU02Read); + SetWriteHandler(0x4100,0xFFFF,TCU02Write); + TCU02Synco(); +} + +static void TCU02Restore(int version) +{ + TCU02Synco(); +} + +void TCU02_Init(CartInfo *info) +{ + GameStateRestore=TCU02Restore; + info->Power=TCU02Power; + AddExState(&latch[0], 1, 0, "LATC"); +} + +// --------------------------------------------- + static DECLFR(TCA01Read) { uint8 ret; @@ -382,7 +454,7 @@ static DECLFR(TCA01Read) return ret; } -static void TCA01Reset(void) +static void TCA01Power(void) { setprg16(0x8000,0); setprg16(0xC000,1); @@ -393,6 +465,6 @@ static void TCA01Reset(void) void TCA01_Init(CartInfo *info) { - info->Power=TCA01Reset; + info->Power=TCA01Power; } diff --git a/boards/sc-127.c b/boards/sc-127.c new file mode 100644 index 0000000..a2c29ff --- /dev/null +++ b/boards/sc-127.c @@ -0,0 +1,125 @@ +/* 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, 16, "IRQc"}, + {&IRQa, 16, "IRQa"}, + {0} +}; + +static void Sync(void) +{ + int i; + setprg8(0x8000,reg[0]); + setprg8(0xA000,reg[1]); + setprg8(0xC000,reg[2]); + 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 void UNLSC127Power(void) +{ + Sync(); + setprg8r(0x10,0x6000,0); + setprg8(0xE000,~0); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLSC127Write); +} + +static void UNLSC127IRQ(void) +{ + if(IRQa) + { + IRQCount--; + if(IRQCount==0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + } + } +} + +static void UNLSC127Reset(void) +{ +} + +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/boards/sheroes.c b/boards/sheroes.c index d228a26..8bea1f7 100644 --- a/boards/sheroes.c +++ b/boards/sheroes.c @@ -1,86 +1,88 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"); -} +/* 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; // there is no more extern CHRRAM in mmc3.h + // I need chrram here and local static == local +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/boards/sl1632.c b/boards/sl1632.c index 9e99722..18895fb 100644 --- a/boards/sl1632.c +++ b/boards/sl1632.c @@ -1,159 +1,124 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint8 chrcmd[8], prg0, prg1, brk, mirr; -static uint8 reg[8], cmd; -static uint8 IRQCount,IRQLatch,IRQa; -static uint8 IRQReload; -static SFORMAT StateRegs[]= -{ - {reg, 8, "MMCREG"}, - {&cmd, 1, "MMCCMD"}, - {chrcmd, 8, "CHRCMD"}, - {&prg0, 1, "PRG0"}, - {&prg1, 1, "PRG1"}, - {&brk, 1, "BRK"}, - {&mirr, 1, "MIRR"}, - {&IRQReload, 1, "IRQR"}, - {&IRQCount, 1, "IRQC"}, - {&IRQLatch, 1, "IRQL"}, - {&IRQa, 1, "IRQA"}, - {0} -}; - -static void Sync(void) -{ -// if(brk&2) -// { -// setprg16(0x8000,~0); -// setprg16(0xC000,~0); -// } -// else - { - setprg8(0x8000,prg0); - setprg8(0xA000,prg1); - } - int i; - for(i=0; i<8; i++) - setchr1(i<<10,chrcmd[i]); - setmirror(mirr^1); -} - -static void Sync2(void) -{ - setprg8(0x8000,reg[6]&0x3F); - setprg8(0xA000,reg[7]&0x3F); - setchr2(0x0000,reg[0]>>1); - setchr2(0x8000,reg[1]>>1); - setchr1(0x1000,reg[2]); - setchr1(0x1400,reg[3]); - setchr1(0x1800,reg[4]); - setchr1(0x1C00,reg[5]); - setmirror(mirr^1); -} - -static DECLFW(UNLSL1632CMDWrite) -{ - FCEU_printf("bs %04x %02x\n",A,V); -// if((A&0xA131)==0xA131) brk=V; - if((A&0xA131)==0xA131) brk=V; - if(brk==2) - { - switch(A&0xE001) - { - case 0x8000: cmd=V&7; break; - case 0x8001: reg[cmd]=V; Sync(); break; - case 0xA000: mirr=V&1; 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; - } - Sync2(); - } - else - { - switch(A&0xF003) - { - case 0x8000: prg0=V; break; - case 0xA000: prg1=V; break; - case 0x9000: mirr=V&1; break; - case 0xB000: chrcmd[0]=(chrcmd[0]&0xF0)|(V&0x0F); break; - case 0xB001: chrcmd[0]=(chrcmd[0]&0x0F)|(V<<4); break; - case 0xB002: chrcmd[1]=(chrcmd[1]&0xF0)|(V&0x0F); break; - case 0xB003: chrcmd[1]=(chrcmd[1]&0x0F)|(V<<4); break; - case 0xC000: chrcmd[2]=(chrcmd[2]&0xF0)|(V&0x0F); break; - case 0xC001: chrcmd[2]=(chrcmd[2]&0x0F)|(V<<4); break; - case 0xC002: chrcmd[3]=(chrcmd[3]&0xF0)|(V&0x0F); break; - case 0xC003: chrcmd[3]=(chrcmd[3]&0x0F)|(V<<4); break; - case 0xD000: chrcmd[4]=(chrcmd[4]&0xF0)|(V&0x0F); break; - case 0xD001: chrcmd[4]=(chrcmd[4]&0x0F)|(V<<4); break; - case 0xD002: chrcmd[5]=(chrcmd[5]&0xF0)|(V&0x0F); break; - case 0xD003: chrcmd[5]=(chrcmd[5]&0x0F)|(V<<4); break; - case 0xE000: chrcmd[6]=(chrcmd[6]&0xF0)|(V&0x0F); break; - case 0xE001: chrcmd[6]=(chrcmd[6]&0x0F)|(V<<4); break; - case 0xE002: chrcmd[7]=(chrcmd[7]&0xF0)|(V&0x0F); break; - case 0xE003: chrcmd[7]=(chrcmd[7]&0x0F)|(V<<4); break; - } - Sync(); - } -} - -static void UNLSL1632IRQHook(void) -{ - int count = IRQCount; - if((scanline==128)&&IRQa)X6502_IRQBegin(FCEU_IQEXT); - 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 UNLSL1632Power(void) -{ - setprg16(0xC000,~0); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,UNLSL1632CMDWrite); -} - -void UNLSL1632_Init(CartInfo *info) -{ - info->Power=UNLSL1632Power; - GameHBIRQHook2=UNLSL1632IRQHook; - 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" +#include "mmc3.h" + +// brk is a system call in *nix, and is an illegal variable name - soules +static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; +static SFORMAT StateRegs[]= +{ + {chrcmd, 8, "CHRCMD"}, + {&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)<Power=UNLSL1632Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/smb2j.c b/boards/smb2j.c new file mode 100644 index 0000000..15655a7 --- /dev/null +++ b/boards/smb2j.c @@ -0,0 +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 + * Super Mario Bros 2 J alt version + * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present + */ + +#include "mapinc.h" + +static uint8 prg, IRQa; +static uint16 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "PRG"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg4r(1,0x5000,1); + setprg8r(1,0x6000,1); + setprg32(0x8000,prg); + setchr8(0); +} + +static DECLFW(UNLSMB2JWrite) +{ + if(A==0x4022) + { + prg=V&1; + Sync(); + } + if(A==0x4122) + { + IRQa=V; + IRQCount=0; + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void UNLSMB2JPower(void) +{ + prg=~0; + Sync(); + SetReadHandler(0x5000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite); +} + +static void UNLSMB2JReset(void) +{ + prg=~0; + Sync(); +} + +static void UNLSMB2JIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a*3; + if((IRQCount>>12)==IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLSMB2J_Init(CartInfo *info) +{ + info->Reset=UNLSMB2JReset; + info->Power=UNLSMB2JPower; + MapIRQHook=UNLSMB2JIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/subor.c b/boards/subor.c index f96cc12..9f0386d 100644 --- a/boards/subor.c +++ b/boards/subor.c @@ -1,79 +1,79 @@ -#include "mapinc.h" - -static uint8 mode; -static uint8 DRegs[4]; - -static SFORMAT StateRegs[]= -{ - {DRegs, 4, "DREG"}, - {0} -}; - -static void Sync(void) -{ - int base, bank; - base = ((DRegs[0]^DRegs[1])&0x10)<<1; - bank = (DRegs[2]^DRegs[3])&0x1f; - - if(DRegs[1]&0x08) - { - bank &= 0xfe; - if(mode==0) - { - setprg16(0x8000,base+bank+1); - setprg16(0xC000,base+bank+0); - } - else - { - setprg16(0x8000,base+bank+0); - setprg16(0xC000,base+bank+1); - } - } - else - { - if(DRegs[1]&0x04) - { - setprg16(0x8000,0x1f); - setprg16(0xC000,base+bank); - } - else - { - setprg16(0x8000,base+bank); - if(mode==0) - setprg16(0xC000,0x20); - else - setprg16(0xC000,0x07); - } - } -} - -static DECLFW(Mapper167_write) -{ - DRegs[(A>>13)&0x03]=V; - Sync(); -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper166_init(void) -{ - mode=1; - DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; - Sync(); - SetWriteHandler(0x8000,0xFFFF,Mapper167_write); - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper167_init(void) -{ - mode=0; - DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; - Sync(); - SetWriteHandler(0x8000,0xFFFF,Mapper167_write); - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +#include "mapinc.h" + +static uint8 mode; +static uint8 DRegs[4]; + +static SFORMAT StateRegs[]= +{ + {DRegs, 4, "DREG"}, + {0} +}; + +static void Sync(void) +{ + int base, bank; + base = ((DRegs[0]^DRegs[1])&0x10)<<1; + bank = (DRegs[2]^DRegs[3])&0x1f; + + if(DRegs[1]&0x08) + { + bank &= 0xfe; + if(mode==0) + { + setprg16(0x8000,base+bank+1); + setprg16(0xC000,base+bank+0); + } + else + { + setprg16(0x8000,base+bank+0); + setprg16(0xC000,base+bank+1); + } + } + else + { + if(DRegs[1]&0x04) + { + setprg16(0x8000,0x1f); + setprg16(0xC000,base+bank); + } + else + { + setprg16(0x8000,base+bank); + if(mode==0) + setprg16(0xC000,0x20); + else + setprg16(0xC000,0x07); + } + } +} + +static DECLFW(Mapper167_write) +{ + DRegs[(A>>13)&0x03]=V; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper166_init(void) +{ + mode=1; + DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,Mapper167_write); + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper167_init(void) +{ + mode=0; + DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,Mapper167_write); + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/super24.c b/boards/super24.c index 205c8d2..4ccc766 100644 --- a/boards/super24.c +++ b/boards/super24.c @@ -15,13 +15,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" #include "mmc3.h" -//static uint8 *CHRRAM = NULL; +static uint8 *CHRRAM = NULL; // there is no more extern CHRRAM in mmc3.h + // I need chrram here and local static == local static int masko8[8]={63,31,15,1,3,0,0,0}; static void Super24PW(uint32 A, uint8 V) diff --git a/boards/supervision.c b/boards/supervision.c index 61a373d..e405c75 100644 --- a/boards/supervision.c +++ b/boards/supervision.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/boards/t-227-1.c b/boards/t-227-1.c new file mode 100644 index 0000000..25d64af --- /dev/null +++ b/boards/t-227-1.c @@ -0,0 +1,116 @@ +/* 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/boards/t-262.c b/boards/t-262.c index fe9b446..15e94ea 100644 --- a/boards/t-262.c +++ b/boards/t-262.c @@ -1,83 +1,84 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint16 addrreg; -static uint8 datareg; -static uint8 busy; -static SFORMAT StateRegs[]= -{ - {&addrreg, 2, "ADDRREG"}, - {&datareg, 1, "DATAREG"}, - {&busy, 1, "BUSY"}, - {0} -}; - -static void Sync(void) -{ - setprg16(0x8000,(datareg&7)|((addrreg&0x60)>>2)|((addrreg&0x100)>>3)); - setprg16(0xC000,7|((addrreg&0x60)>>2)|((addrreg&0x100)>>3)); - setmirror(((addrreg&2)>>1)^1); -} - -static DECLFW(BMCT262Write) -{ - if(busy||(A==0x8000)) - datareg=V; - else - { - addrreg=A; - busy=1; - } - Sync(); -} - -static void BMCT262Power(void) -{ - setchr8(0); - SetWriteHandler(0x8000,0xFFFF,BMCT262Write); - SetReadHandler(0x8000,0xFFFF,CartBR); - busy=0; - addrreg=0; - datareg=0; - Sync(); -} - -static void BMCT262Reset(void) -{ - busy=0; - addrreg=0; - datareg=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 uint16 addrreg; +static uint8 datareg; +static uint8 busy; +static SFORMAT StateRegs[]= +{ + {&addrreg, 2, "ADDRREG"}, + {&datareg, 1, "DATAREG"}, + {&busy, 1, "BUSY"}, + {0} +}; + +static void Sync(void) +{ + uint16 base=((addrreg&0x60)>>2)|((addrreg&0x100)>>3); + setprg16(0x8000,(datareg&7)|base); + setprg16(0xC000,7|base); + setmirror(((addrreg&2)>>1)^1); +} + +static DECLFW(BMCT262Write) +{ + if(busy||(A==0x8000)) + datareg=V; + else + { + addrreg=A; + busy=1; + } + Sync(); +} + +static void BMCT262Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,BMCT262Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + busy=0; + addrreg=0; + datareg=0xff; + Sync(); +} + +static void BMCT262Reset(void) +{ + busy=0; + addrreg=0; + datareg=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/boards/tengen.c b/boards/tengen.c index a4f33f5..3881622 100644 --- a/boards/tengen.c +++ b/boards/tengen.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -36,10 +36,10 @@ static SFORMAT Rambo_StateRegs[]={ {0} }; -static void FP_FASTAPASS(2) (*setchr1wrap)(unsigned int A, unsigned int V); -static int nomirror; +static void (*setchr1wrap)(unsigned int A, unsigned int V); +//static int nomirror; -static void FP_FASTAPASS(1) RAMBO1_IRQHook(int a) +static void RAMBO1_IRQHook(int a) { static int smallcount; if(!IRQmode) return; @@ -104,7 +104,7 @@ static DECLFW(RAMBO1_write) switch(A&0xF001) { case 0xa000: mir=V&1; - if(!nomirror) +// if(!nomirror) setmirror(mir^1); break; case 0x8000: cmd = V; @@ -138,7 +138,7 @@ static DECLFW(RAMBO1_write) static void RAMBO1_Restore(int version) { Synco(); - if(!nomirror) +// if(!nomirror) setmirror(mir^1); } @@ -148,7 +148,7 @@ static void RAMBO1_init(void) for(x=0;x<11;x++) DRegs[x]=~0; cmd=mir=0; - if(!nomirror) +// if(!nomirror) setmirror(1); Synco(); GameHBIRQHook=RAMBO1_hb; @@ -158,7 +158,7 @@ static void RAMBO1_init(void) AddExState(Rambo_StateRegs, ~0, 0, 0); } -static void FP_FASTAPASS(2) CHRWrap(unsigned int A, unsigned int V) +static void CHRWrap(unsigned int A, unsigned int V) { setchr1(A,V); } @@ -166,14 +166,14 @@ static void FP_FASTAPASS(2) CHRWrap(unsigned int A, unsigned int V) void Mapper64_init(void) { setchr1wrap=CHRWrap; - nomirror=0; +// nomirror=0; RAMBO1_init(); } - +/* static int MirCache[8]; static unsigned int PPUCHRBus; -static void FP_FASTAPASS(2) MirWrap(unsigned int A, unsigned int V) +static void MirWrap(unsigned int A, unsigned int V) { MirCache[A>>10]=(V>>7)&1; if(PPUCHRBus==(A>>10)) @@ -181,7 +181,7 @@ static void FP_FASTAPASS(2) MirWrap(unsigned int A, unsigned int V) setchr1(A,V); } -static void FP_FASTAPASS(1) MirrorFear(uint32 A) +static void MirrorFear(uint32 A) { A&=0x1FFF; A>>=10; @@ -196,3 +196,5 @@ void Mapper158_init(void) nomirror=1; RAMBO1_init(); } +*/ + diff --git a/boards/tf-1201.c b/boards/tf-1201.c new file mode 100644 index 0000000..d40cb5f --- /dev/null +++ b/boards/tf-1201.c @@ -0,0 +1,124 @@ +/* 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, "IRQCOUNT"}, + {&IRQPre, 1, "IRQPRE"}, + {&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)<Power=UNLTF1201Power; + GameHBIRQHook=UNLTF1201IRQCounter; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/driver.h b/driver.h index ed321fd..1e7345e 100644 --- a/driver.h +++ b/driver.h @@ -62,13 +62,16 @@ void FCEUI_SetNTSCTH(int n, int tint, int hue); #include "version.h" +#define SI_UNSET -1 #define SI_NONE 0 #define SI_GAMEPAD 1 #define SI_ZAPPER 2 #define SI_POWERPADA 3 #define SI_POWERPADB 4 #define SI_ARKANOID 5 +#define SI_MOUSE 6 +#define SIFC_UNSET -1 #define SIFC_NONE 0 #define SIFC_ARKANOID 1 #define SIFC_SHADOW 2 diff --git a/fce.c b/fce.c index 78a75b6..282a264 100644 --- a/fce.c +++ b/fce.c @@ -98,6 +98,7 @@ static uint8 deemp=0; static int deempcnt[8]; FCEUGI FCEUGameInfo; +FCEUGI *GameInfo = &FCEUGameInfo; void (*GameInterface)(int h, void *param); void FP_FASTAPASS(1) (*PPU_hook)(uint32 A); @@ -1114,7 +1115,7 @@ void ResetGameLoaded(void) char lastLoadedGameName [2048]; int LoadGameLastError = 0; int UNIFLoad(const char *name, int fp); -int iNESLoad(const char *name, int fp); +int iNESLoad(const char *name, int fp, int OverwriteVidMode); int FDSLoad(const char *name, int fp); int NSFLoad(int fp); @@ -1175,7 +1176,7 @@ FCEUGI *FCEUI_LoadGame(char *name) } GetFileBase(name2); - if(iNESLoad(name2,fp)) + if(iNESLoad(name2,fp,1)) goto endlseq; if(NSFLoad(fp)) goto endlseq; @@ -1518,9 +1519,9 @@ void ResetNES081(void) X6502_Reset(); } -#ifndef DEBUG_ASM_6502 -static void FCEU_MemoryRand(uint8 *ptr, uint32 size) +void FCEU_MemoryRand(uint8 *ptr, uint32 size) { +#ifndef DEBUG_ASM_6502 int x=0; while(size) { @@ -1529,8 +1530,8 @@ static void FCEU_MemoryRand(uint8 *ptr, uint32 size) size--; ptr++; } -} #endif +} void PowerNES(void) { @@ -1541,9 +1542,8 @@ void PowerNES(void) GeniePower(); -#ifndef DEBUG_ASM_6502 FCEU_MemoryRand(RAM,0x800); -#else +#ifdef DEBUG_ASM_6502 memset(RAM,0x00,0x800); memset(nes_internal_ram,0x00,0x800); #endif diff --git a/fce.h b/fce.h index 593d858..dde07c0 100644 --- a/fce.h +++ b/fce.h @@ -15,6 +15,7 @@ void ResetGameLoaded(void); #define DECLFR(x) uint8 FP_FASTAPASS(1) x (uint32 A) #define DECLFW(x) void FP_FASTAPASS(2) x (uint32 A, uint8 V) +void FCEU_MemoryRand(uint8 *ptr, uint32 size); void FASTAPASS(3) SetReadHandler(int32 start, int32 end, readfunc func); void FASTAPASS(3) SetWriteHandler(int32 start, int32 end, writefunc func); writefunc FASTAPASS(1) GetWriteHandler(int32 a); @@ -43,7 +44,9 @@ extern uint8 MMC5HackSPMode; extern uint8 MMC5HackSPScroll; extern uint8 MMC5HackSPPage; -extern uint8 GameMemBlock[131072]; +#define GAME_MEM_BLOCK_SIZE 131072 + +extern uint8 GameMemBlock[GAME_MEM_BLOCK_SIZE]; extern uint8 NTARAM[0x800],PALRAM[0x20]; extern uint8 RAM[0x800]; @@ -85,10 +88,12 @@ extern void (*GameStateRestore)(int version); #define GI_RESETM2 1 #define GI_POWER 2 #define GI_CLOSE 3 +#define GI_RESETSAVE 4 #define GI_INFOSTRING 11 #include "git.h" extern FCEUGI FCEUGameInfo; +extern FCEUGI *GameInfo; // FCEUX compatibility HACK extern int GameAttributes; extern uint8 pale; diff --git a/file.h b/file.h index 233be1a..0230c57 100644 --- a/file.h +++ b/file.h @@ -6,6 +6,7 @@ int FASTAPASS(3) FCEU_fseek(int stream, long offset, int whence); long FASTAPASS(1) FCEU_ftell(int stream); void FASTAPASS(1) FCEU_rewind(int stream); int FASTAPASS(2) FCEU_read32(void *Bufo, int fp); +#define FCEU_read32le FCEU_read32 // HACK int FASTAPASS(1) FCEU_fgetc(int stream); long FASTAPASS(1) FCEU_fgetsize(int stream); int FASTAPASS(1) FCEU_fisarchive(int stream); diff --git a/git.h b/git.h index bbe6405..ff9290d 100644 --- a/git.h +++ b/git.h @@ -12,6 +12,7 @@ typedef struct { uint8 *name; /* Game name, UTF8 encoding */ + int mappernum; int type; /* GIT_* */ int vidsys; /* Current emulated video system; GIV_* */ diff --git a/ines-correct.h b/ines-correct.h index 054b0ec..d7705e8 100644 --- a/ines-correct.h +++ b/ines-correct.h @@ -1,7 +1,10 @@ {0x9cbadc25,5,8}, /* JustBreed */ {0x6e68e31a,16,8}, /* Dragon Ball 3*/ + {0xbfc7a2e9,16,8}, + {0x33b899c9,16,-1}, /* Dragon Ball - Dai Maou Fukkatsu (J) [!] */ {0x3f15d20d,153,8}, /* Famicom Jump 2 */ + {0x983d8175,157,8}, /* Datach Battle Rush */ {0x894efdbc,157,8}, /* Datach Crayon Shin Chan */ {0x19e81461,157,8}, /* Datach DBZ */ @@ -17,16 +20,17 @@ {0x063b1151,209,-1}, /* Power Rangers 4 */ {0xdd8ced31,209,-1}, /* Power Rangers 3 */ - {0x0c47946d,210,-1}, /* Chibi Maruko Chan */ - {0xbd523011,210,-1}, /* Dream Master */ - {0xc247cc80,210,-1}, /* Family Circuit '91 */ - {0x6ec51de5,210,-1}, /* Famista '92 */ - {0xadffd64f,210,-1}, /* Famista '93 */ - {0x429103c9,210,-1}, /* Famista '94 */ - {0x81b7f1a8,210,-1}, /* Heisei Tensai Bakabon */ - {0x2447e03b,210,-1}, /* Top Striker */ - {0x1dc0f740,210,-1}, /* Wagyan Land 2 */ - {0xd323b806,210,-1}, /* Wagyan Land 3 */ + {0x0c47946d,210,1}, /* Chibi Maruko Chan */ + {0xbd523011,210,2}, /* Dream Master */ // may be wrong, but seems it solve most problems + {0xc247cc80,210,1}, /* Family Circuit '91 */ + {0x6ec51de5,210,1}, /* Famista '92 */ + {0xadffd64f,210,1}, /* Famista '93 */ + {0x429103c9,210,1}, /* Famista '94 */ + {0x81b7f1a8,210,1}, /* Heisei Tensai Bakabon */ + {0x2447e03b,210,1}, /* Top Striker */ + {0x1dc0f740,210,1}, /* Wagyan Land 2 */ + {0xd323b806,210,1}, /* Wagyan Land 3 */ + {0x07eb2c12,208,-1}, /* Street Fighter IV */ {0x96ce586e,189,8}, /* Street Fighter 2 YOKO */ {0x7678f1d5,207,8}, /* Fudou Myouou Den */ @@ -43,7 +47,7 @@ {0x1500e835,48,8}, /* Jetsons (J) */ {0x637134e8,193,1}, /* Fighting Hero */ - {0xcbf4366f,158,8}, /* Alien Syndrome (U.S. unlicensed) */ + {0xcbf4366f,118,8}, /* Alien Syndrome (U.S. unlicensed) */ {0xb19a55dd,64,8}, /* Road Runner */ //{0x3eafd012,116,-1}, /* AV Girl Fighting */ {0x1d0f4d6b,2,1}, /* Black Bass thinging */ @@ -90,9 +94,9 @@ {0xbb7c5f7a,89,8}, /* Mito Koumon or something similar */ /* Probably a Namco MMC3-workalike */ -{0xa5e6baf9,4,1|4}, /* Dragon Slayer 4 */ -{0xe40b4973,4,1|4}, /* Metro Cross */ -{0xd97c31b0,4,1|4}, /* Rasaaru Ishii no Childs Quest */ +//{0xa5e6baf9,4,1|4}, /* Dragon Slayer 4 */ +//{0xe40b4973,4,1|4}, /* Metro Cross */ +//{0xd97c31b0,4,1|4}, /* Rasaaru Ishii no Childs Quest */ {0x84382231,9,0}, /* Punch Out (J) */ @@ -163,6 +167,7 @@ {0xd26efd78,66,1}, /* SMB Duck Hunt */ {0x811f06d9,66,1}, /* Dragon Power */ {0x3293afea,140,1}, /* Mississippi Satsujin Jiken */ +{0xe46b1c5d,140,1}, /* Mississippi Satsujin Jiken */ {0xe84274c5,66,1}, /* "" "" */ {0x9552e8df,66,1}, /* Dragon Ball */ @@ -199,15 +204,54 @@ {0x555a555e,191,-1}, {0x98c1cd4b,192,-1},/* Ying Lie Qun Xia Zhuan (Chinese) */ {0x442f1a29,192,-1},/* Young chivalry */ + {0xa9115bc1,192,-1}, + {0x4c7bbb0e,192,-1}, + {0xa145fae6,192,-1}, {0xa925226c,194,-1},/* Dai-2-Ji - Super Robot Taisen (As) */ - {0xd5224fde,198,-1},/* [074]Crystalis (c) */ - {0x1bc0be6c,198,-1},/* Captain Tsubasa Vol 2 - Super Striker (C) */ - {0xdd431ba7,199,-1},/* Tenchi wo kurau 2 (c) */ - {0x28192599,199,-1}, - {0x700705f4,199,-1}, - {0x9a2cf02c,199,-1}, - {0xd8b401a7,199,-1}, - - {0x1f1326d4,218,-1}, + {0xd5224fde,195,-1},/* Crystalis (c) */ + {0x1bc0be6c,195,-1},/* Captain Tsubasa Vol 2 - Super Striker (C) */ + {0x33c5df92,195,-1}, + {0xb616885c,195,0}, /* CHaos WOrld (Ch)*/ + {0x7f3dbf1b,195,0}, + {0xdd431ba7,198,-1},/* Tenchi wo kurau 2 (c) */ + {0x28192599,198,-1}, + {0x700705f4,198,-1}, + {0x9a2cf02c,198,-1}, + {0xd8b401a7,198,-1}, + {0x19b9e732,198,-1}, + {0xd871d3e6,199,-1},/* Dragon Ball Z 2 - Gekishin Freeza! (C) */ + {0xed481b7c,199,-1},/* Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) */ + {0x44c20420,199,-1},/* San Guo Zhi 2 (C) */ + {0xa1dc16c0,116,-1}, + + {0xcc868d4e,149,-1}, /* 16 Mahjong [p1][!] */ + {0x48239b42,146,-1}, /* Mahjong Companion (Sachen) [!] */ + {0xb6a727fa,146,-1}, /* Papillion (As) [!] */ + {0xa62b79e1,146,-1}, /* Side Winder (HES) [!] */ + {0x73fb55ac,150,-1}, /* 2-in-1 Cosmo Cop + Cyber Monster (Sachen) [!] */ + {0xddcbda16,150,-1}, /* 2-in-1 Tough Cop + Super Tough Cop (Sachen) [!] */ + {0x47918d84,150,-1}, /* auto-upturn */ + {0x29582ca1,150,-1}, + {0x40dbf7a2,150,-1}, + {0x5aefbc94,133,-1}, /* Jovial Race (Sachen) [a1][!] */ + {0x58152b42,160,1}, /* Pipe 5 (Sachen) */ + + {0x22d6d5bd,4,1}, + {0x6a03d3f3,114,-1}, + {0x0d98db53,114,-1}, /* Pocahontas */ + {0x4e7729ff,114,-1}, /* Super Donkey Kong */ + + {0x02c41438,176,-1}, /* Xing He Zhan Shi (C) */ + {0xfb2b6b10,241,-1}, /* Fan Kong Jing Ying (Ch) */ + {0xb5e83c9a,241,-1}, /* Xing Ji Zheng Ba (Ch) */ + {0x081caaff,163,-1}, /* Commandos (Ch) */ + + {0x0da5e32e,101,-1}, /* new Uruusey Yatsura */ + {0x4f2f1846,-1,1}, /* Famista '89 - Kaimaku Han!! (J) */ + {0x6c71feae,45,-1}, /* Kunio 8-in-1 */ +// {0xbdbe3c96,238,-1}, /* Contra Fighter iNES version */ + + {0xd97c31b0,4,1}, //Rasaaru Ishii no Childs Quest (J) + {0,-1,-1} diff --git a/ines.c b/ines.c index 2f5fbeb..042dad2 100644 --- a/ines.c +++ b/ines.c @@ -1,23 +1,23 @@ /* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +* +* 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 #include @@ -32,24 +32,26 @@ #define INESPRIV #include "ines.h" #include "unif.h" -#include "general.h" #include "state.h" #include "file.h" +#include "general.h" #include "memory.h" #include "crc32.h" #include "md5.h" #include "cheat.h" #include "vsuni.h" - #include "driver.h" #include "svga.h" extern SFORMAT FCEUVSUNI_STATEINFO[]; -static uint8 *trainerpoo=0; -static uint8 *ROM=NULL; -//static -uint8 *VROM=NULL; +//mbg merge 6/29/06 - these need to be global +uint8 *trainerpoo=0; +uint8 *ROM = NULL; +uint8 *VROM = NULL; +struct iNES_HEADER head; + + static CartInfo iNESCart; @@ -60,7 +62,9 @@ uint8 iNESIRQa=0; uint32 ROM_size=0; uint32 VROM_size=0; +//char LoadedRomFName[2048]; //mbg merge 7/17/06 added +static int CHRRAMSize = -1; static void iNESPower(void); static int NewiNES_Init(int num); @@ -69,60 +73,72 @@ void (*MapperReset)(void); static int MapperNo=0; -static iNES_HEADER head; - /* MapperReset() is called when the NES is reset(with the reset button). - Mapperxxx_init is called when the NES has been powered on. +Mapperxxx_init is called when the NES has been powered on. */ + static DECLFR(TrainerRead) { - return(trainerpoo[A&0x1FF]); + return(trainerpoo[A&0x1FF]); +} + +static void iNES_ExecPower() +{ + if(CHRRAMSize != -1) + FCEU_MemoryRand(VROM,CHRRAMSize); + + if(iNESCart.Power) + iNESCart.Power(); + + if(trainerpoo) + { + int x; + for(x=0;x<512;x++) + { + //X6502_DMW(0x7000+x,trainerpoo[x]); + //if(X6502_DMR(0x7000+x)!=trainerpoo[x]) + unsigned int A=0x7000+x; + BWrite[A](A,trainerpoo[x]); + if(ARead[A](A)!=trainerpoo[x]) + { + SetReadHandler(0x7000,0x71FF,TrainerRead); + break; + } + } + } } static void iNESGI(int h, void *param) { - switch(h) - { - case GI_RESETM2: + switch(h) + { + case GI_RESETSAVE: + //FCEU_ClearGameSave(&iNESCart); + break; + + case GI_RESETM2: if(MapperReset) - MapperReset(); + MapperReset(); if(iNESCart.Reset) - iNESCart.Reset(); + iNESCart.Reset(); + break; + case GI_POWER: + iNES_ExecPower(); + break; - case GI_POWER: - if(iNESCart.Power) - iNESCart.Power(); - if(trainerpoo) + case GI_CLOSE: { - int x; - for(x=0;x<512;x++) - { - //X6502_DMW(0x7000+x,trainerpoo[x]); - //if(X6502_DMR(0x7000+x)!=trainerpoo[x]) - unsigned int A=0x7000+x; - BWrite[A](A,trainerpoo[x]); - if(ARead[A](A)!=trainerpoo[x]) - { - SetReadHandler(0x7000,0x71FF,TrainerRead); - break; - } - } + FCEU_SaveGameSave(&iNESCart); + + if(iNESCart.Close) iNESCart.Close(); + if(ROM) {free(ROM); ROM = NULL;} + if(VROM) {free(VROM); VROM = NULL;} + if(MapClose) MapClose(); + if(trainerpoo) {FCEU_gfree(trainerpoo);trainerpoo=0;} } break; - case GI_CLOSE: - { - FCEU_SaveGameSave(&iNESCart); - - if(iNESCart.Close) iNESCart.Close(); - if(ROM) {free(ROM);ROM=0;} - if(VROM) {free(VROM);VROM=0;} - if(MapClose) MapClose(); - if(trainerpoo) {FCEU_gfree(trainerpoo);trainerpoo=0;} - ResetExState(0,0); - } - break; - case GI_INFOSTRING: + case GI_INFOSTRING: { int MapperNo; MapperNo = (head.ROM_type>>4); @@ -131,7 +147,7 @@ static void iNESGI(int h, void *param) MapperNo, (head.ROM_type&2)?", BB":"", (head.ROM_type&4)?", T":""); } break; - } + } } uint32 iNESGameCRC32=0; @@ -148,102 +164,99 @@ struct INPSEL { int inputfc; }; -/* This is mostly for my personal use. So HA. */ static void SetInput(void) { - static struct INPSEL moo[]= + static struct INPSEL moo[]= { - {0x3a1694f9,SI_GAMEPAD,SI_GAMEPAD,SIFC_4PLAYER}, /* Nekketsu Kakutou Densetsu */ - -#if 0 - {0xc3c0811d,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS}, /* The two "Oeka Kids" games */ - {0x9d048ea4,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS}, /* */ - - {0xaf4010ea,SI_GAMEPAD,SI_POWERPADB,-1}, /* World Class Track Meet */ - {0xd74b2719,SI_GAMEPAD,SI_POWERPADB,-1}, /* Super Team Games */ - {0x61d86167,SI_GAMEPAD,SI_POWERPADB,-1}, /* Street Cop */ - {0x6435c095,SI_GAMEPAD,SI_POWERPADB,-1}, /* Short Order/Eggsplode */ - - - {0x47232739,SI_GAMEPAD,SI_GAMEPAD,SIFC_TOPRIDER}, /* Top Rider */ - - {0x48ca0ee1,SI_GAMEPAD,SI_GAMEPAD,SIFC_BWORLD}, /* Barcode World */ - {0x9f8f200a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Super Mogura Tataki!! - Pokkun Moguraa */ - {0x9044550e,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Rairai Kyonshizu */ - {0x2f128512,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Jogging Race */ - {0x60ad090a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Athletic World */ - - {0x8a12a7d9,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Totsugeki Fuuun Takeshi Jou */ - {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Running Stadium */ - {0x370ceb65,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Meiro Dai Sakusen */ - // Bad dump? {0x69ffb014,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Fuun Takeshi Jou 2 */ - {0x6cca1c1f,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Dai Undoukai */ - {0x29de87af,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Aerobics Studio */ - {0xbba58be5,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Family Trainer: Manhattan Police */ - {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Family Trainer: Running Stadium */ - - {0xd9f45be9,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING}, /* Gimme a Break ... */ - {0x1545bd13,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING}, /* Gimme a Break ... 2 */ - - {0x7b44fb2a,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG}, /* Ide Yousuke Meijin no Jissen Mahjong 2 */ - {0x9fae4d46,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG}, /* Ide Yousuke Meijin no Jissen Mahjong */ - - {0x980be936,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Olympic */ - {0x21f85681,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Olympic (Gentei Ban) */ - {0x915a53a7,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Sports */ -#endif - {0xad9c63e2,SI_GAMEPAD,-1,SIFC_SHADOW}, /* Space Shadow */ - - {0x24598791,-1,SI_ZAPPER,0}, /* Duck Hunt */ - {0xff24d794,-1,SI_ZAPPER,0}, /* Hogan's Alley */ - {0xbeb8ab01,-1,SI_ZAPPER,0}, /* Gumshoe */ - {0xde8fd935,-1,SI_ZAPPER,0}, /* To the Earth */ - {0xedc3662b,-1,SI_ZAPPER,0}, /* Operation Wolf */ - {0x2a6559a1,-1,SI_ZAPPER,0}, /* Operation Wolf (J) */ - - {0x23d17f5e,SI_GAMEPAD,SI_ZAPPER,0}, /* The Lone Ranger */ - {0xb8b9aca3,-1,SI_ZAPPER,0}, /* Wild Gunman */ - {0x5112dc21,-1,SI_ZAPPER,0}, /* Wild Gunman */ - {0x4318a2f8,-1,SI_ZAPPER,0}, /* Barker Bill's Trick Shooting */ - {0x5ee6008e,-1,SI_ZAPPER,0}, /* Mechanized Attack */ - {0x3e58a87e,-1,SI_ZAPPER,0}, /* Freedom Force */ - {0x851eb9be,SI_GAMEPAD,SI_ZAPPER,0}, /* Shooting Range */ - {0x74bea652,SI_GAMEPAD,SI_ZAPPER,0}, /* Supergun 3-in-1 */ - {0x32fb0583,-1,SI_ARKANOID,0}, /* Arkanoid(NES) */ - {0xd89e5a67,-1,-1,SIFC_ARKANOID}, /* Arkanoid (J) */ - {0x0f141525,-1,-1,SIFC_ARKANOID}, /* Arkanoid 2(J) */ - - {0x912989dc,-1,-1,SIFC_FKB}, /* Playbox BASIC */ - {0xf7606810,-1,-1,SIFC_FKB}, /* Family BASIC 2.0A */ - {0x895037bc,-1,-1,SIFC_FKB}, /* Family BASIC 2.1a */ - {0xb2530afc,-1,-1,SIFC_FKB}, /* Family BASIC 3.0 */ -#if 0 - {0x82f1fb96,-1,-1,SIFC_SUBORKB}, /* Subor 1.0 Russian */ - {0xabb2f974,-1,-1,SIFC_SUBORKB}, /* Study and Game 32-in-1 */ - {0xd5d6eac4,-1,-1,SIFC_SUBORKB}, /* Edu (As) */ - {0x589b6b0d,-1,-1,SIFC_SUBORKB}, /* SuporV20 */ - {0x5e073a1b,-1,-1,SIFC_SUBORKB}, /* Supor English (Chinese) */ - {0x8b265862,-1,-1,SIFC_SUBORKB}, - {0x41401c6d,-1,-1,SIFC_SUBORKB}, /* SuporV40 */ - {0x41ef9ac4,-1,-1,SIFC_SUBORKB}, - {0x368c19a8,-1,-1,SIFC_SUBORKB}, /* LIKO Study Cartridge */ - {0x543ab532,-1,-1,SIFC_SUBORKB}, /* LIKO Color Lines */ -#endif - {0,-1,-1,-1} + {0x3a1694f9,SI_GAMEPAD,SI_GAMEPAD,SIFC_4PLAYER}, // Nekketsu Kakutou Densetsu + + {0xc3c0811d,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS}, // The two "Oeka Kids" games + {0x9d048ea4,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS}, // + + {0xaf4010ea,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET}, // World Class Track Meet + {0xd74b2719,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET}, // Super Team Games + {0x61d86167,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET}, // Street Cop + {0x6435c095,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET}, // Short Order/Eggsplode + + + {0x47232739,SI_GAMEPAD,SI_GAMEPAD,SIFC_TOPRIDER}, // Top Rider + + {0x48ca0ee1,SI_GAMEPAD,SI_GAMEPAD,SIFC_BWORLD}, // Barcode World + {0x9f8f200a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Super Mogura Tataki!! - Pokkun Moguraa + {0x9044550e,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Rairai Kyonshizu + {0x2f128512,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Jogging Race + {0x60ad090a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Athletic World + + {0x8a12a7d9,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Totsugeki Fuuun Takeshi Jou + {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Running Stadium + {0x370ceb65,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Meiro Dai Sakusen + // Bad dump? {0x69ffb014,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Fuun Takeshi Jou 2 + {0x6cca1c1f,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Dai Undoukai + {0x29de87af,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Aerobics Studio + {0xbba58be5,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Family Trainer: Manhattan Police + {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Family Trainer: Running Stadium + + {0xd9f45be9,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING}, // Gimme a Break ... + {0x1545bd13,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING}, // Gimme a Break ... 2 + + {0x7b44fb2a,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG}, // Ide Yousuke Meijin no Jissen Mahjong 2 + {0x9fae4d46,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG}, // Ide Yousuke Meijin no Jissen Mahjong + + {0x980be936,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, // Hyper Olympic + {0x21f85681,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, // Hyper Olympic (Gentei Ban) + {0x915a53a7,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, // Hyper Sports + {0xad9c63e2,SI_GAMEPAD,SI_UNSET,SIFC_SHADOW}, // Space Shadow + + {0x24598791,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Duck Hunt + {0xff24d794,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Hogan's Alley + {0xbeb8ab01,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Gumshoe + {0xde8fd935,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // To the Earth + {0xedc3662b,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Operation Wolf + {0x2a6559a1,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Operation Wolf (J) + {0x4e959173,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Gotcha! - The Sport! + + {0x23d17f5e,SI_GAMEPAD,SI_ZAPPER,SIFC_NONE}, // The Lone Ranger + {0xb8b9aca3,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Wild Gunman + {0x5112dc21,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Wild Gunman + {0x4318a2f8,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Barker Bill's Trick Shooting + {0x5ee6008e,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Mechanized Attack + {0x3e58a87e,SI_UNSET,SI_ZAPPER,SIFC_NONE}, // Freedom Force + {0xe9a7fe9e,SI_UNSET,SI_MOUSE,SIFC_NONE}, // Educational Computer 2000 //mbg merge 7/17/06 added -- appears to be from newer MM build + {0x851eb9be,SI_GAMEPAD,SI_ZAPPER,SIFC_NONE}, // Shooting Range + {0x74bea652,SI_GAMEPAD,SI_ZAPPER,SIFC_NONE}, // Supergun 3-in-1 + {0x32fb0583,SI_UNSET,SI_ARKANOID,SIFC_NONE}, // Arkanoid(NES) + {0xd89e5a67,SI_UNSET,SI_UNSET,SIFC_ARKANOID}, // Arkanoid (J) + {0x0f141525,SI_UNSET,SI_UNSET,SIFC_ARKANOID}, // Arkanoid 2(J) + + {0x912989dc,SI_UNSET,SI_UNSET,SIFC_FKB}, // Playbox BASIC + {0xf7606810,SI_UNSET,SI_UNSET,SIFC_FKB}, // Family BASIC 2.0A + {0x895037bc,SI_UNSET,SI_UNSET,SIFC_FKB}, // Family BASIC 2.1a + {0xb2530afc,SI_UNSET,SI_UNSET,SIFC_FKB}, // Family BASIC 3.0 + {0x82f1fb96,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // Subor 1.0 Russian + {0xabb2f974,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // Study and Game 32-in-1 + {0xd5d6eac4,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // Edu (As) + {0x589b6b0d,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // SuporV20 + {0x5e073a1b,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // Supor English (Chinese) + {0x8b265862,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, + {0x41401c6d,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // SuporV40 + {0x41ef9ac4,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, + {0x368c19a8,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // LIKO Study Cartridge + {0x543ab532,SI_UNSET,SI_UNSET,SIFC_SUBORKB}, // LIKO Color Lines + {0,SI_UNSET,SI_UNSET,SIFC_UNSET} }; - int x=0; - - while(moo[x].input1>=0 || moo[x].input2>=0 || moo[x].inputfc>=0) - { - if(moo[x].crc32==iNESGameCRC32) - { - FCEUGameInfo.input[0]=moo[x].input1; - FCEUGameInfo.input[1]=moo[x].input2; - FCEUGameInfo.inputfc=moo[x].inputfc; - break; - } - x++; - } + int x=0; + + while(moo[x].input1>=0 || moo[x].input2>=0 || moo[x].inputfc>=0) + { + if(moo[x].crc32==iNESGameCRC32) + { + GameInfo->input[0]=moo[x].input1; + GameInfo->input[1]=moo[x].input2; + GameInfo->inputfc=moo[x].inputfc; + break; + } + x++; + } } #define INESB_INCOMPLETE 1 @@ -259,24 +272,24 @@ struct BADINF { static struct BADINF BadROMImages[]= { - #include "ines-bad.h" +#include "ines-bad.h" }; void CheckBad(uint64 md5partial) { - int x; - - x=0; - //printf("0x%llx\n",md5partial); - while(BadROMImages[x].name) - { - if(BadROMImages[x].md5partial == md5partial) - { - FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly on FCE Ultra.", BadROMImages[x].name); - return; - } - x++; - } + int x; + + x=0; + //printf("0x%llx\n",md5partial); + while(BadROMImages[x].name) + { + if(BadROMImages[x].md5partial == md5partial) + { + FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly in FCEUX.", BadROMImages[x].name); + return; + } + x++; + } } @@ -285,175 +298,233 @@ struct CHINF { uint32 crc32; int32 mapper; int32 mirror; + const char* params; }; +void MapperInit() +{ + if(NewiNES_Init(MapperNo)) + { + + } + else + { + iNESCart.Power=iNESPower; + if(head.ROM_type&2) + { + iNESCart.SaveGame[0]=WRAM; + iNESCart.SaveGameLen[0]=8192; + } + } +} + +#if 0 +static const TMasterRomInfo sMasterRomInfo[] = { + { 0x62b51b108a01d2beLL, "bonus=0" }, //4-in-1 (FK23C8021)[p1][!].nes + { 0x8bb48490d8d22711LL, "bonus=0" }, //4-in-1 (FK23C8033)[p1][!].nes + { 0xc75888d7b48cd378LL, "bonus=0" }, //4-in-1 (FK23C8043)[p1][!].nes + { 0xf81a376fa54fdd69LL, "bonus=0" }, //4-in-1 (FK23Cxxxx, S-0210A PCB)[p1][!].nes + { 0xa37eb9163e001a46LL, "bonus=0" }, //4-in-1 (FK23C8026) [p1][!].nes + { 0xde5ce25860233f7eLL, "bonus=0" }, //4-in-1 (FK23C8045) [p1][!].nes + { 0x5b3aa4cdc484a088LL, "bonus=0" }, //4-in-1 (FK23C8056) [p1][!].nes + { 0x9342bf9bae1c798aLL, "bonus=0" }, //4-in-1 (FK23C8079) [p1][!].nes + { 0x164eea6097a1e313LL, "busc=1" }, //Cybernoid - The Fighting Machine (U)[!].nes -- needs bus conflict emulation +}; +const TMasterRomInfo* MasterRomInfo; +TMasterRomInfoParams MasterRomInfoParams; +#endif + static void CheckHInfo(void) { - /* ROM images that have the battery-backed bit set in the header that really - don't have battery-backed RAM is not that big of a problem, so I'll - treat this differently by only listing games that should have battery-backed RAM. + /* ROM images that have the battery-backed bit set in the header that really + don't have battery-backed RAM is not that big of a problem, so I'll + treat this differently by only listing games that should have battery-backed RAM. - Lower 64 bits of the MD5 hash. - */ + Lower 64 bits of the MD5 hash. + */ - static uint64 savie[]= + static uint64 savie[]= { - 0x498c10dc463cfe95LL, /* Battle Fleet */ - 0x6917ffcaca2d8466LL, /* Famista '90 */ + 0x498c10dc463cfe95LL, /* Battle Fleet */ + 0x6917ffcaca2d8466LL, /* Famista '90 */ - 0xd63dcc68c2b20adcLL, /* Final Fantasy J */ - 0x012df596e2b31174LL, /* Final Fantasy 1+2 */ - 0xf6b359a720549ecdLL, /* Final Fantasy 2 */ - 0x5a30da1d9b4af35dLL, /* Final Fantasy 3 */ + 0xd63dcc68c2b20adcLL, /* Final Fantasy J */ + 0x012df596e2b31174LL, /* Final Fantasy 1+2 */ + 0xf6b359a720549ecdLL, /* Final Fantasy 2 */ + 0x5a30da1d9b4af35dLL, /* Final Fantasy 3 */ - 0x2ee3417ba8b69706LL, /* Hydlide 3*/ + 0x2ee3417ba8b69706LL, /* Hydlide 3*/ - 0xebbce5a54cf3ecc0LL, /* Justbreed */ + 0xebbce5a54cf3ecc0LL, /* Justbreed */ - 0x6a858da551ba239eLL, /* Kaijuu Monogatari */ - 0xa40666740b7d22feLL, /* Mindseeker */ + 0x6a858da551ba239eLL, /* Kaijuu Monogatari */ + 0xa40666740b7d22feLL, /* Mindseeker */ - 0x77b811b2760104b9LL, /* Mouryou Senki Madara */ + 0x77b811b2760104b9LL, /* Mouryou Senki Madara */ - 0x11b69122efe86e8cLL, /* RPG Jinsei Game */ + 0x11b69122efe86e8cLL, /* RPG Jinsei Game */ - 0xa70b495314f4d075LL, /* Ys 3 */ + 0xa70b495314f4d075LL, /* Ys 3 */ - 0xc04361e499748382LL, /* AD&D Heroes of the Lance */ - 0xb72ee2337ced5792LL, /* AD&D Hillsfar */ - 0x2b7103b7a27bd72fLL, /* AD&D Pool of Radiance */ + 0xc04361e499748382LL, /* AD&D Heroes of the Lance */ + 0xb72ee2337ced5792LL, /* AD&D Hillsfar */ + 0x2b7103b7a27bd72fLL, /* AD&D Pool of Radiance */ - 0x854d7947a3177f57LL, /* Crystalis */ + 0x854d7947a3177f57LL, /* Crystalis */ - 0xb0bcc02c843c1b79LL, /* DW */ - 0x4a1f5336b86851b6LL, /* DW */ + 0xb0bcc02c843c1b79LL, /* DW */ + 0x4a1f5336b86851b6LL, /* DW */ - 0x2dcf3a98c7937c22LL, /* DW 2 */ - 0x733026b6b72f2470LL, /* Dw 3 */ - 0x98e55e09dfcc7533LL, /* DW 4*/ - 0x8da46db592a1fcf4LL, /* Faria */ - 0x91a6846d3202e3d6LL, /* Final Fantasy */ - 0xedba17a2c4608d20LL, /* "" */ + 0x2dcf3a98c7937c22LL, /* DW 2 */ + 0x733026b6b72f2470LL, /* Dw 3 */ + 0x98e55e09dfcc7533LL, /* DW 4*/ + 0x8da46db592a1fcf4LL, /* Faria */ + 0x91a6846d3202e3d6LL, /* Final Fantasy */ + 0xedba17a2c4608d20LL, /* "" */ - 0x94b9484862a26cbaLL, /* Legend of Zelda */ - 0x04a31647de80fdabLL, /* "" */ + 0x94b9484862a26cbaLL, /* Legend of Zelda */ + 0x04a31647de80fdabLL, /* "" */ - 0x9aa1dc16c05e7de5LL, /* Startropics */ - 0x1b084107d0878bd0LL, /* Startropics 2*/ + 0x9aa1dc16c05e7de5LL, /* Startropics */ + 0x1b084107d0878bd0LL, /* Startropics 2*/ - 0x836c0ff4f3e06e45LL, /* Zelda 2 */ + 0x836c0ff4f3e06e45LL, /* Zelda 2 */ - 0 /* Abandon all hope if the game has 0 in the lower 64-bits of its MD5 hash */ + 0x82000965f04a71bbLL, /* Mirai Shinwa Jarvas */ + + 0 /* Abandon all hope if the game has 0 in the lower 64-bits of its MD5 hash */ }; - static struct CHINF moo[]= + static struct CHINF moo[]= { - #include "ines-correct.h" +#include "ines-correct.h" }; - int tofix=0; - int x; - uint64 partialmd5=0; - - for(x=0;x<8;x++) - { - partialmd5 |= (uint64)iNESCart.MD5[15-x] << (x*8); - //printf("%16llx\n",partialmd5); - } - CheckBad(partialmd5); - - x=0; - - do - { - if(moo[x].crc32==iNESGameCRC32) - { - if(moo[x].mapper>=0) - { - if(moo[x].mapper&0x800 && VROM_size) - { - VROM_size=0; - free(VROM); - VROM=0; - tofix|=8; - } - if(MapperNo!=(moo[x].mapper&0xFF)) - { - tofix|=1; - MapperNo=moo[x].mapper&0xFF; - } - } - if(moo[x].mirror>=0) - { - if(moo[x].mirror==8) - { - if(Mirroring==2) /* Anything but hard-wired(four screen). */ - { - tofix|=2; - Mirroring=0; - } - } - else if(Mirroring!=moo[x].mirror) - { - if(Mirroring!=(moo[x].mirror&~4)) - if((moo[x].mirror&~4)<=2) /* Don't complain if one-screen mirroring - needs to be set(the iNES header can't - hold this information). - */ - tofix|=2; - Mirroring=moo[x].mirror; - } - } - break; - } - x++; - } while(moo[x].mirror>=0 || moo[x].mapper>=0); - - x=0; - while(savie[x] != 0) - { - if(savie[x] == partialmd5) - { - if(!(head.ROM_type&2)) - { - tofix|=4; - head.ROM_type|=2; - } - } - x++; - } - - /* Games that use these iNES mappers tend to have the four-screen bit set - when it should not be. - */ - if((MapperNo==118 || MapperNo==24 || MapperNo==26) && (Mirroring==2)) - { - Mirroring=0; - tofix|=2; - } - - /* Four-screen mirroring implicitly set. */ - if(MapperNo==99) - Mirroring=2; - - if(tofix) - { - char gigastr[768]; - strcpy(gigastr,"The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); - if(tofix&1) - sprintf(gigastr+strlen(gigastr),"The mapper number should be set to %d. ",MapperNo); - if(tofix&2) - { - char *mstr[3]={"Horizontal","Vertical","Four-screen"}; - sprintf(gigastr+strlen(gigastr),"Mirroring should be set to \"%s\". ",mstr[Mirroring&3]); - } - if(tofix&4) - strcat(gigastr,"The battery-backed bit should be set. "); - if(tofix&8) - strcat(gigastr,"This game should not have any CHR ROM. "); - strcat(gigastr,"\n"); - FCEU_printf("%s",gigastr); - } + int tofix=0; + int x; + uint64 partialmd5=0; + + for(x=0;x<8;x++) + { + partialmd5 |= (uint64)iNESCart.MD5[15-x] << (x*8); + //printf("%16llx\n",partialmd5); + } + CheckBad(partialmd5); + +#if 0 + MasterRomInfo = NULL; + MasterRomInfoParams = TMasterRomInfoParams(); + for(int i=0;i toks = tokenize_str(info.params,","); + for(int j=0;j<(int)toks.size();j++) + { + std::vector parts = tokenize_str(toks[j],"="); + MasterRomInfoParams[parts[0]] = parts[1]; + } + break; + } +#endif + + x=0; + + do + { + if(moo[x].crc32==iNESGameCRC32) + { + if(moo[x].mapper>=0) + { + if(moo[x].mapper&0x800 && VROM_size) + { + VROM_size=0; + free(VROM); + VROM = NULL; + tofix|=8; + } + if(MapperNo!=(moo[x].mapper&0xFF)) + { + tofix|=1; + MapperNo=moo[x].mapper&0xFF; + } + } + if(moo[x].mirror>=0) + { + if(moo[x].mirror==8) + { + if(Mirroring==2) /* Anything but hard-wired(four screen). */ + { + tofix|=2; + Mirroring=0; + } + } + else if(Mirroring!=moo[x].mirror) + { + if(Mirroring!=(moo[x].mirror&~4)) + if((moo[x].mirror&~4)<=2) /* Don't complain if one-screen mirroring + needs to be set(the iNES header can't + hold this information). + */ + tofix|=2; + Mirroring=moo[x].mirror; + } + } + break; + } + x++; + } while(moo[x].mirror>=0 || moo[x].mapper>=0); + + x=0; + while(savie[x] != 0) + { + if(savie[x] == partialmd5) + { + if(!(head.ROM_type&2)) + { + tofix|=4; + head.ROM_type|=2; + } + } + x++; + } + + /* Games that use these iNES mappers tend to have the four-screen bit set + when it should not be. + */ + if((MapperNo==118 || MapperNo==24 || MapperNo==26) && (Mirroring==2)) + { + Mirroring=0; + tofix|=2; + } + + /* Four-screen mirroring implicitly set. */ + if(MapperNo==99) + Mirroring=2; + + if(tofix) + { + char gigastr[768]; + strcpy(gigastr,"The iNES header contains incorrect information. For now, the information will be corrected in RAM. "); + if(tofix&1) + sprintf(gigastr+strlen(gigastr),"The mapper number should be set to %d. ",MapperNo); + if(tofix&2) + { + char *mstr[3]={"Horizontal","Vertical","Four-screen"}; + sprintf(gigastr+strlen(gigastr),"Mirroring should be set to \"%s\". ",mstr[Mirroring&3]); + } + if(tofix&4) + strcat(gigastr,"The battery-backed bit should be set. "); + if(tofix&8) + strcat(gigastr,"This game should not have any CHR ROM. "); + strcat(gigastr,"\n"); + FCEU_printf("%s",gigastr); + } } typedef struct { @@ -461,282 +532,562 @@ typedef struct { void (*init)(CartInfo *); } NewMI; -int iNESLoad(const char *name, int fp) +//this is for games that is not the a power of 2 +//mapper based for now... +//not really accurate but this works since games +//that are not in the power of 2 tends to come +//in obscure mappers themselves which supports such +//size +static int not_power2[] = +{ + 228 +}; +typedef struct { + char* name; + int number; + void (*init)(CartInfo *); +} BMAPPINGLocal; + +static BMAPPINGLocal bmap[] = { + {"NROM", 0, NROM_Init}, + {"MMC1", 1, Mapper1_Init}, + {"UNROM", 2, UNROM_Init}, + {"CNROM", 3, CNROM_Init}, + {"MMC3", 4, Mapper4_Init}, + {"MMC5", 5, Mapper5_Init}, + {"ANROM", 7, ANROM_Init}, + {"Color Dreams", 11, Mapper11_Init}, + {"", 12, Mapper12_Init}, + {"CPROM", 13, CPROM_Init}, + {"100-in1", 15, Mapper15_Init}, + {"Bandai", 16, Mapper16_Init}, + {"Namcot 106", 19, Mapper19_Init}, + {"Konami VRC2 type B", 23, Mapper23_Init}, + {"Wario Land 2", 35, UNLSC127_Init}, // Wario Land 2 + {"TXC Policeman", 36, Mapper36_Init}, // TXC Policeman + {"", 37, Mapper37_Init}, + {"Bit Corp. Crime Busters", 38, Mapper38_Init}, // Bit Corp. Crime Busters + {"", 43, Mapper43_Init}, + {"", 44, Mapper44_Init}, + {"", 45, Mapper45_Init}, + {"", 47, Mapper47_Init}, + {"", 49, Mapper49_Init}, + {"", 52, Mapper52_Init}, + {"", 57, Mapper57_Init}, + {"", 58, BMCGK192_Init}, + {"", 60, BMCD1038_Init}, + {"MHROM", 66, MHROM_Init}, + {"Sunsoft Mapper #4", 68, Mapper68_Init}, + {"", 70, Mapper70_Init}, + {"", 74, Mapper74_Init}, + {"Irem 74HC161/32", 78, Mapper78_Init}, + {"", 87, Mapper87_Init}, + {"", 88, Mapper88_Init}, + {"", 90, Mapper90_Init}, + {"Sunsoft UNROM", 93, SUNSOFT_UNROM_Init}, + {"", 94, Mapper94_Init}, + {"", 95, Mapper95_Init}, + {"", 101, Mapper101_Init}, + {"", 103, Mapper103_Init}, + {"", 105, Mapper105_Init}, + {"", 106, Mapper106_Init}, + {"", 107, Mapper107_Init}, + {"", 108, Mapper108_Init}, + {"", 112, Mapper112_Init}, + {"", 113, Mapper113_Init}, + {"", 114, Mapper114_Init}, + {"", 115, Mapper115_Init}, + {"", 116, Mapper116_Init}, +// {116, UNLSL1632_Init}, + {"", 117, Mapper117_Init}, + {"TSKROM", 118, TKSROM_Init}, + {"", 119, Mapper119_Init}, + {"", 120, Mapper120_Init}, + {"", 121, Mapper121_Init}, + {"UNLH2288", 123, UNLH2288_Init}, + {"UNL22211", 132, UNL22211_Init}, + {"SA72008", 133, SA72008_Init}, + {"", 134, Mapper134_Init}, + {"TCU02", 136, TCU02_Init}, + {"S8259D", 137, S8259D_Init}, + {"S8259B", 138, S8259B_Init}, + {"S8259C", 139, S8259C_Init}, + {"", 140, Mapper140_Init}, + {"S8259A", 141, S8259A_Init}, + {"UNLKS7032", 142, UNLKS7032_Init}, + {"TCA01", 143, TCA01_Init}, + {"", 144, Mapper144_Init}, + {"SA72007", 145, SA72007_Init}, + {"SA0161M", 146, SA0161M_Init}, + {"TCU01", 147, TCU01_Init}, + {"SA0037", 148, SA0037_Init}, + {"SA0036", 149, SA0036_Init}, + {"S74LS374N", 150, S74LS374N_Init}, + {"", 152, Mapper152_Init}, + {"", 153, Mapper153_Init}, + {"", 154, Mapper154_Init}, + {"", 155, Mapper155_Init}, + {"", 156, Mapper156_Init}, + {"", 159, Mapper159_Init}, + {"SA009", 160, SA009_Init}, + {"", 163, Mapper163_Init}, + {"", 164, Mapper164_Init}, + {"", 165, Mapper165_Init}, +// {169, Mapper169_Init}, + {"", 171, Mapper171_Init}, + {"", 172, Mapper172_Init}, + {"", 173, Mapper173_Init}, + {"", 175, Mapper175_Init}, + {"BMCFK23C", 176, BMCFK23C_Init}, //zero 26-may-2012 - well, i have some WXN junk games that use 176 for instance 水浒神兽. i dont know what game uses this BMCFK23C as mapper 176. we'll have to make a note when we find it. + //{"BMCFK23C", 176, Mapper176_Init}, + {"", 177, Mapper177_Init}, + {"", 178, Mapper178_Init}, + {"", 180, Mapper180_Init}, + {"", 181, Mapper181_Init}, +// {"", 182, Mapper182_Init}, // identical to 114 + {"", 183, Mapper183_Init}, + {"", 184, Mapper184_Init}, + {"", 185, Mapper185_Init}, + {"", 186, Mapper186_Init}, + {"", 187, Mapper187_Init}, + {"", 188, Mapper188_Init}, + {"", 189, Mapper189_Init}, + {"", 191, Mapper191_Init}, + {"", 192, Mapper192_Init}, + {"", 194, Mapper194_Init}, + {"", 195, Mapper195_Init}, + {"", 196, Mapper196_Init}, + {"", 197, Mapper197_Init}, + {"", 198, Mapper198_Init}, + {"", 199, Mapper199_Init}, + {"", 200, Mapper200_Init}, + {"", 205, Mapper205_Init}, + {"DEIROM", 206, DEIROM_Init}, + {"", 208, Mapper208_Init}, + {"", 209, Mapper209_Init}, + {"", 210, Mapper210_Init}, + {"", 211, Mapper211_Init}, + {"", 215, UNL8237_Init}, + {"", 216, Mapper216_Init}, +// {"", 217, Mapper217_Init}, + {"UNLA9746", 219, UNLA9746_Init}, + {"OneBus", 220, UNLOneBus_Init}, + +// {220, BMCFK23C_Init}, +// {220, UNL3DBlock_Init}, +// {220, UNLTF1201_Init}, +// {220, TCU02_Init}, +// {220, UNLCN22M_Init}, +// {220, BMCT2271_Init}, +// {220, UNLDANCE_Init}, + + {"UNLN625092", 221, UNLN625092_Init}, + {"", 222, Mapper222_Init}, + {"", 226, Mapper226_Init}, + {"", 235, Mapper235_Init}, + {"UNL6035052", 238, UNL6035052_Init}, + {"", 240, Mapper240_Init}, + {"S74LS374NA", 243, S74LS374NA_Init}, + {"", 245, Mapper245_Init}, + {"", 249, Mapper249_Init}, + {"", 250, Mapper250_Init}, + {"", 253, Mapper253_Init}, + {"", 254, Mapper254_Init}, + {"", 0, 0} +}; + +void cleanup(struct iNES_HEADER *this) +{ + if(!memcmp((char *)(this)+0x7,"DiskDude",8)) + { + memset((char *)(this)+0x7,0,0x9); + } + + if(!memcmp((char *)(this)+0x7,"demiforce",9)) + { + memset((char *)(this)+0x7,0,0x9); + } + + if(!memcmp((char *)(this)+0xA,"Ni03",4)) + { + if(!memcmp((char *)(this)+0x7,"Dis",3)) + memset((char *)(this)+0x7,0,0x9); + else + memset((char *)(this)+0xA,0,0x6); + } +} + +int iNESLoad(const char *name, int fp, int OverwriteVidMode) { - struct md5_context md5; + struct md5_context md5; if(FCEU_fread(&head,1,16,fp)!=16) - return 0; + return 0; - if(memcmp(&head,"NES\x1a",4)) - return 0; + if(memcmp(&head,"NES\x1a",4)) + return 0; + + cleanup(&head); memset(&iNESCart,0,sizeof(iNESCart)); - if(!memcmp((char *)(&head)+0x7,"DiskDude",8)) - { - memset((char *)(&head)+0x7,0,0x9); - } + MapperNo = (head.ROM_type>>4); + MapperNo|=(head.ROM_type2&0xF0); + Mirroring = (head.ROM_type&1); - if(!memcmp((char *)(&head)+0x7,"demiforce",9)) - { - memset((char *)(&head)+0x7,0,0x9); - } - if(!memcmp((char *)(&head)+0xA,"Ni03",4)) - { - if(!memcmp((char *)(&head)+0x7,"Dis",3)) - memset((char *)(&head)+0x7,0,0x9); - else - memset((char *)(&head)+0xA,0,0x6); - } - -// int ROM_size=0; - if(!head.ROM_size) + // int ROM_size=0; + if(!head.ROM_size) { -// FCEU_PrintError("No PRG ROM!"); -// return(0); - ROM_size=256; - //head.ROM_size++; + // FCEU_PrintError("No PRG ROM!"); + // return(0); + ROM_size=256; + //head.ROM_size++; } - else - ROM_size=head.ROM_size; + else + ROM_size=uppow2(head.ROM_size); + + // ROM_size = head.ROM_size; + VROM_size = head.VROM_size; -// ROM_size = head.ROM_size; - VROM_size = head.VROM_size; - ROM_size=uppow2(ROM_size); + int round = 1; + int i; + for (i = 0; i != sizeof(not_power2)/sizeof(not_power2[0]); ++i) + { + //for games not to the power of 2, so we just read enough + //prg rom from it, but we have to keep ROM_size to the power of 2 + //since PRGCartMapping wants ROM_size to be to the power of 2 + //so instead if not to power of 2, we just use head.ROM_size when + //we use FCEU_read + if (not_power2[i] == MapperNo) + { + round = 0; + break; + } + } - if(VROM_size) - VROM_size=uppow2(VROM_size); + if(VROM_size) + VROM_size=uppow2(VROM_size); - MapperNo = (head.ROM_type>>4); - MapperNo|=(head.ROM_type2&0xF0); - Mirroring = (head.ROM_type&1); if(head.ROM_type&8) Mirroring=2; - if(!(ROM=(uint8 *)FCEU_malloc(ROM_size<<14))) - return 0; - - if(VROM_size) - if(!(VROM=(uint8 *)FCEU_malloc(VROM_size<<13))) - { - free(ROM); - return 0; - } + if((ROM = (uint8 *)FCEU_malloc(ROM_size<<14)) == NULL) return 0; - memset(ROM,0xFF,ROM_size<<14); - if(VROM_size) memset(VROM,0xFF,VROM_size<<13); - if(head.ROM_type&4) /* Trainer */ + if(VROM_size) + { + if((VROM = (uint8 *)FCEU_malloc(VROM_size<<13)) == NULL) + { + free(ROM); + ROM = NULL; + return 0; + } + } + memset(ROM,0xFF,ROM_size<<14); + if(VROM_size) memset(VROM,0xFF,VROM_size<<13); + if(head.ROM_type&4) /* Trainer */ { - trainerpoo=(uint8 *)FCEU_gmalloc(512); - FCEU_fread(trainerpoo,512,1,fp); + trainerpoo=(uint8 *)FCEU_gmalloc(512); + FCEU_fread(trainerpoo,512,1,fp); } ResetCartMapping(); ResetExState(0,0); SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0); - SetupCartPRGMapping(1,WRAM,8192,1); + // SetupCartPRGMapping(1,WRAM,8192,1); // ? - FCEU_fread(ROM,0x4000,head.ROM_size,fp); + FCEU_fread(ROM,0x4000,(round) ? ROM_size : head.ROM_size,fp); if(VROM_size) - FCEU_fread(VROM,0x2000,head.VROM_size,fp); + FCEU_fread(VROM,0x2000,head.VROM_size,fp); - md5_starts(&md5); - md5_update(&md5,ROM,ROM_size<<14); + md5_starts(&md5); + md5_update(&md5,ROM,ROM_size<<14); iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14); if(VROM_size) { - iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13); - md5_update(&md5,VROM,VROM_size<<13); + iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13); + md5_update(&md5,VROM,VROM_size<<13); } md5_finish(&md5,iNESCart.MD5); - memcpy(FCEUGameInfo.MD5,iNESCart.MD5,sizeof(iNESCart.MD5)); + memcpy(&GameInfo->MD5,&iNESCart.MD5,sizeof(iNESCart.MD5)); iNESCart.CRC32=iNESGameCRC32; - FCEU_printf(" PRG ROM: %3d x 16KiB\n CHR ROM: %3d x 8KiB\n ROM CRC32: 0x%08x\n", - head.ROM_size,head.VROM_size,iNESGameCRC32); + FCEU_printf(" PRG ROM: %3d x 16KiB\n CHR ROM: %3d x 8KiB\n ROM CRC32: 0x%08lx\n", + (round) ? ROM_size : head.ROM_size, head.VROM_size, + (unsigned long)iNESGameCRC32); - { - int x; - FCEU_printf(" ROM MD5: 0x"); - for(x=0;x<16;x++) - FCEU_printf("%02x",iNESCart.MD5[x]); - FCEU_printf("\n"); - } - FCEU_printf(" Mapper: %d\n Mirroring: %s\n", MapperNo,Mirroring==2?"None(Four-screen)":Mirroring?"Vertical":"Horizontal"); - if(head.ROM_type&2) FCEU_printf(" Battery-backed.\n"); - if(head.ROM_type&4) FCEU_printf(" Trained.\n"); + { + int x; + FCEU_printf(" ROM MD5: 0x"); + for(x=0;x<16;x++) + FCEU_printf("%02x",iNESCart.MD5[x]); + FCEU_printf("\n"); + } + + char* mappername = "Not Listed"; + int mappertest; + + for(mappertest=0;mappertest< (sizeof bmap / sizeof bmap[0]) - 1;mappertest++) + { + if (bmap[mappertest].number == MapperNo) { + mappername = bmap[mappertest].name; + break; + } + } + + FCEU_printf(" Mapper #: %d\n Mapper name: %s\n Mirroring: %s\n", + MapperNo, mappername, Mirroring==2?"None (Four-screen)":Mirroring?"Vertical":"Horizontal"); + + FCEU_printf(" Battery-backed: %s\n", (head.ROM_type&2)?"Yes":"No"); + FCEU_printf(" Trained: %s\n", (head.ROM_type&4)?"Yes":"No"); + // (head.ROM_type&8) = Mirroring: None(Four-screen) SetInput(); CheckHInfo(); { - int x; - uint64 partialmd5=0; + int x; + uint64 partialmd5=0; - for(x=0;x<8;x++) - { - partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8); - } + for(x=0;x<8;x++) + { + partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8); + } - FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring); + FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring); } /* Must remain here because above functions might change value of - VROM_size and free(VROM). + VROM_size and free(VROM). */ if(VROM_size) - SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0); + SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0); - if(Mirroring==2) - SetupCartMirroring(4,1,ExtraNTARAM); - else if(Mirroring>=0x10) - SetupCartMirroring(2+(Mirroring&1),1,0); + if(Mirroring==2) + SetupCartMirroring(4,1,ExtraNTARAM); + else if(Mirroring>=0x10) + SetupCartMirroring(2+(Mirroring&1),1,0); else - SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0); + SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0); iNESCart.battery=(head.ROM_type&2)?1:0; iNESCart.mirror=Mirroring; //if(MapperNo != 18) { - // if(ROM) free(ROM); - // if(VROM) free(VROM); - // ROM=VROM=0; - // return(0); + // if(ROM) free(ROM); + // if(VROM) free(VROM); + // ROM=VROM=0; + // return(0); // } - if(NewiNES_Init(MapperNo)) - { - } - else - { - iNESCart.Power=iNESPower; - if(head.ROM_type&2) - { - iNESCart.SaveGame[0]=WRAM; - iNESCart.SaveGameLen[0]=8192; - } - } + GameInfo->mappernum = MapperNo; + MapperInit(); FCEU_LoadGameSave(&iNESCart); + //strcpy(LoadedRomFName,name); //bbit edited: line added + + // Extract Filename only. Should account for Windows/Unix this way. + if (strrchr(name, '/')) { + name = strrchr(name, '/') + 1; + } else if(strrchr(name, '\\')) { + name = strrchr(name, '\\') + 1; + } + GameInterface=iNESGI; FCEU_printf("\n"); // since apparently the iNES format doesn't store this information, // guess if the settings should be PAL or NTSC from the ROM name // TODO: MD5 check against a list of all known PAL games instead? - if(strstr(name,"(E)") || strstr(name,"(e)") - || strstr(name,"(F)") || strstr(name,"(f)") - || strstr(name,"(G)") || strstr(name,"(g)") - || strstr(name,"(I)") || strstr(name,"(i)")) - FCEUI_SetVidSystem(1); - else - FCEUI_SetVidSystem(0); + if(OverwriteVidMode) + { + if(strstr(name,"(E)") || strstr(name,"(e)") + || strstr(name,"(F)") || strstr(name,"(f)") + || strstr(name,"(G)") || strstr(name,"(g)") + || strstr(name,"(I)") || strstr(name,"(i)")) + FCEUI_SetVidSystem(1); + else + FCEUI_SetVidSystem(0); + } + return 1; +} + + +//bbit edited: the whole function below was added +int iNesSave(){ + FILE *fp; + char name[2048]; + + if(GameInfo->type != GIT_CART)return 0; + if(GameInterface!=iNESGI)return 0; + + //strcpy(name,LoadedRomFName); + if (strcmp(name+strlen(name)-4,".nes") != 0) { //para edit + strcat(name,".nes"); + } + + fp = fopen(name,"wb"); + + if(fwrite(&head,1,16,fp)!=16) + { + fclose(fp); + return 0; + } + + if(head.ROM_type&4) /* Trainer */ + { + fwrite(trainerpoo,512,1,fp); + } + + fwrite(ROM,0x4000,ROM_size,fp); + + if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp); + fclose(fp); + + return 1; +} + +int iNesSaveAs(char* name) +{ + //adelikat: TODO: iNesSave() and this have pretty much the same code, outsource the common code to a single function + FILE *fp; + + if(GameInfo->type != GIT_CART)return 0; + if(GameInterface != iNESGI)return 0; + + fp = fopen(name,"wb"); + + if(fwrite(&head,1,16,fp)!=16) + { + fclose(fp); + return 0; + } + + if(head.ROM_type&4) /* Trainer */ + { + fwrite(trainerpoo,512,1,fp); + } + + fwrite(ROM,0x4000,ROM_size,fp); + + if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp); + fclose(fp); return 1; } -void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V) +//para edit: added function below +#if 0 +char *iNesShortFName() { + char *ret; + + if (!(ret = strrchr(LoadedRomFName,'\\'))) { + if (!(ret = strrchr(LoadedRomFName,'/'))) return 0; + } + return ret+1; +} +#endif + +void VRAM_BANK1(uint32 A, uint8 V) { - V&=7; - PPUCHRRAM|=(1<<(A>>10)); - CHRBankList[(A)>>10]=V; - VPage[(A)>>10]=&CHRRAM[V<<10]-(A); + V&=7; + PPUCHRRAM|=(1<<(A>>10)); + CHRBankList[(A)>>10]=V; + VPage[(A)>>10]=&CHRRAM[V<<10]-(A); } -void FASTAPASS(2) VRAM_BANK4(uint32 A, uint32 V) +void VRAM_BANK4(uint32 A, uint32 V) { - V&=1; - PPUCHRRAM|=(0xF<<(A>>10)); - CHRBankList[(A)>>10]=(V<<2); - CHRBankList[((A)>>10)+1]=(V<<2)+1; - CHRBankList[((A)>>10)+2]=(V<<2)+2; - CHRBankList[((A)>>10)+3]=(V<<2)+3; - VPage[(A)>>10]=&CHRRAM[V<<10]-(A); + V&=1; + PPUCHRRAM|=(0xF<<(A>>10)); + CHRBankList[(A)>>10]=(V<<2); + CHRBankList[((A)>>10)+1]=(V<<2)+1; + CHRBankList[((A)>>10)+2]=(V<<2)+2; + CHRBankList[((A)>>10)+3]=(V<<2)+3; + VPage[(A)>>10]=&CHRRAM[V<<10]-(A); } -void FASTAPASS(2) VROM_BANK1(uint32 A,uint32 V) +void VROM_BANK1(uint32 A,uint32 V) { - setchr1(A,V); - CHRBankList[(A)>>10]=V; + setchr1(A,V); + CHRBankList[(A)>>10]=V; } -void FASTAPASS(2) VROM_BANK2(uint32 A,uint32 V) +void VROM_BANK2(uint32 A,uint32 V) { - setchr2(A,V); - CHRBankList[(A)>>10]=(V<<1); - CHRBankList[((A)>>10)+1]=(V<<1)+1; + setchr2(A,V); + CHRBankList[(A)>>10]=(V<<1); + CHRBankList[((A)>>10)+1]=(V<<1)+1; } -void FASTAPASS(2) VROM_BANK4(uint32 A, uint32 V) +void VROM_BANK4(uint32 A, uint32 V) { - setchr4(A,V); - CHRBankList[(A)>>10]=(V<<2); - CHRBankList[((A)>>10)+1]=(V<<2)+1; - CHRBankList[((A)>>10)+2]=(V<<2)+2; - CHRBankList[((A)>>10)+3]=(V<<2)+3; + setchr4(A,V); + CHRBankList[(A)>>10]=(V<<2); + CHRBankList[((A)>>10)+1]=(V<<2)+1; + CHRBankList[((A)>>10)+2]=(V<<2)+2; + CHRBankList[((A)>>10)+3]=(V<<2)+3; } -void FASTAPASS(1) VROM_BANK8(uint32 V) +void VROM_BANK8(uint32 V) { - setchr8(V); - CHRBankList[0]=(V<<3); - CHRBankList[1]=(V<<3)+1; - CHRBankList[2]=(V<<3)+2; - CHRBankList[3]=(V<<3)+3; - CHRBankList[4]=(V<<3)+4; - CHRBankList[5]=(V<<3)+5; - CHRBankList[6]=(V<<3)+6; - CHRBankList[7]=(V<<3)+7; + setchr8(V); + CHRBankList[0]=(V<<3); + CHRBankList[1]=(V<<3)+1; + CHRBankList[2]=(V<<3)+2; + CHRBankList[3]=(V<<3)+3; + CHRBankList[4]=(V<<3)+4; + CHRBankList[5]=(V<<3)+5; + CHRBankList[6]=(V<<3)+6; + CHRBankList[7]=(V<<3)+7; } -void FASTAPASS(2) ROM_BANK8(uint32 A, uint32 V) +void ROM_BANK8(uint32 A, uint32 V) { - setprg8(A,V); - if(A>=0x8000) - PRGBankList[((A-0x8000)>>13)]=V; + setprg8(A,V); + if(A>=0x8000) + PRGBankList[((A-0x8000)>>13)]=V; } -void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V) +void ROM_BANK16(uint32 A, uint32 V) { - setprg16(A,V); - if(A>=0x8000) - { - PRGBankList[((A-0x8000)>>13)]=V<<1; - PRGBankList[((A-0x8000)>>13)+1]=(V<<1)+1; - } + setprg16(A,V); + if(A>=0x8000) + { + PRGBankList[((A-0x8000)>>13)]=V<<1; + PRGBankList[((A-0x8000)>>13)+1]=(V<<1)+1; + } } -void FASTAPASS(1) ROM_BANK32(uint32 V) +void ROM_BANK32(uint32 V) { - setprg32(0x8000,V); - PRGBankList[0]=V<<2; - PRGBankList[1]=(V<<2)+1; - PRGBankList[2]=(V<<2)+2; - PRGBankList[3]=(V<<2)+3; + setprg32(0x8000,V); + PRGBankList[0]=V<<2; + PRGBankList[1]=(V<<2)+1; + PRGBankList[2]=(V<<2)+2; + PRGBankList[3]=(V<<2)+3; } -void FASTAPASS(1) onemir(uint8 V) +void onemir(uint8 V) { if(Mirroring==2) return; - if(V>1) - V=1; + if(V>1) + V=1; Mirroring=0x10|V; setmirror(MI_0+V); } -void FASTAPASS(1) MIRROR_SET2(uint8 V) +void MIRROR_SET2(uint8 V) { if(Mirroring==2) return; Mirroring=V; setmirror(V); } -void FASTAPASS(1) MIRROR_SET(uint8 V) +void MIRROR_SET(uint8 V) { if(Mirroring==2) return; V^=1; @@ -746,377 +1097,418 @@ void FASTAPASS(1) MIRROR_SET(uint8 V) static void NONE_init(void) { - ROM_BANK16(0x8000,0); - ROM_BANK16(0xC000,~0); + ROM_BANK16(0x8000,0); + ROM_BANK16(0xC000,~0); - if(VROM_size) - VROM_BANK8(0); - else - setvram8(CHRRAM); + if(VROM_size) + VROM_BANK8(0); + else + setvram8(CHRRAM); } - void (*MapInitTab[256])(void)= { - 0,0, //Mapper2_init,Mapper3_init, - 0,0, - 0,0, - Mapper6_init, - 0,//Mapper7_init, - Mapper8_init,Mapper9_init, - Mapper10_init, - 0, //Mapper11_init, - 0, //Mapper13_init, - 0, - 0, - Mapper15_init,Mapper16_init,Mapper17_init,Mapper18_init, - 0,0, - Mapper21_init,Mapper22_init,Mapper23_init,Mapper24_init, - Mapper25_init,Mapper26_init,Mapper27_init, - 0,0,0,0, - Mapper32_init,Mapper33_init,Mapper34_init, - 0,0,0,0,0, - Mapper40_init,Mapper41_init,Mapper42_init,Mapper43_init, - 0,0, - Mapper46_init, - 0, - Mapper48_init, - 0, - Mapper50_init,Mapper51_init, - 0,0,0,0,0, - 0,// Mapper57_init, - 0,// Mapper58_init, - Mapper59_init,Mapper60_init, - Mapper61_init,Mapper62_init, - 0, - Mapper64_init,Mapper65_init, - 0,//Mapper66_init, - Mapper67_init, - Mapper68_init,Mapper69_init, - 0,//Mapper70_init, - Mapper71_init, - Mapper72_init,Mapper73_init, - 0, - Mapper75_init,Mapper76_init,Mapper77_init, - 0, //Mapper78_init, - Mapper79_init,Mapper80_init, - 0, - Mapper82_init,Mapper83_init, - 0, - Mapper85_init,Mapper86_init, - 0, //Mapper87_init, - 0, //Mapper88_init, - Mapper89_init, - 0, - Mapper91_init,Mapper92_init, - 0, //Mapper93_init, - 0, //Mapper94_init, - 0, - Mapper96_init,Mapper97_init, - 0, - Mapper99_init, - 0,0,0,0,0,0,0, - 0, //Mapper107_init, - 0,0,0,0, - 0,Mapper113_init, - 0,0,0, - 0, //Mapper117_init, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0, //Mapper140_init, - 0,0,0, - 0, //Mapper144_init, - 0,0,0,0,0,0, - Mapper151_init, - 0, //Mapper152_init, - Mapper153_init, - 0, //Mapper154_init, - 0, - Mapper156_init,Mapper157_init,Mapper158_init,0, - 0,0,0,0,0,0, - Mapper166_init,Mapper167_init, - 0,0,0,0,0,0,0,0,0,0,0,0, - Mapper180_init, - 0,0,0, - Mapper184_init, - 0, //Mapper185_init, - 0,0,0, - 0, //Mapper189_init, - 0, - 0, //Mapper191_init, - 0, - Mapper193_init, - 0,0,0,0,0,0, - Mapper200_init,Mapper201_init,Mapper202_init,Mapper203_init, - Mapper204_init, - 0,0, - Mapper207_init, - 0,0,0, - 0, //Mapper211_init, - Mapper212_init,Mapper213_init,Mapper214_init, - 0,0,0,0,0,0,0,0,0,0, - Mapper225_init,Mapper226_init,Mapper227_init,Mapper228_init, - Mapper229_init,Mapper230_init,Mapper231_init,Mapper232_init, - 0, - Mapper234_init, - 0, //Mapper235_init, - 0,0,0,0, - Mapper240_init,Mapper241_init,Mapper242_init,0, - Mapper244_init, - 0, - Mapper246_init, - 0,0,0,0,0,0,0,0, - Mapper255_init + 0, + 0, + 0, //Mapper2_init, + 0, //Mapper3_init, + 0, + 0, + Mapper6_init, + 0,//Mapper7_init, + Mapper8_init, + Mapper9_init, + Mapper10_init, + 0, //Mapper11_init, + 0, + 0, //Mapper13_init, + 0, + 0, //Mapper15_init, + 0, //Mapper16_init, + Mapper17_init, + Mapper18_init, + 0, + 0, + Mapper21_init, + Mapper22_init, + 0, //Mapper23_init, + Mapper24_init, + Mapper25_init, + Mapper26_init, + Mapper27_init, + 0, + 0, + 0, + 0, + Mapper32_init, + Mapper33_init, + Mapper34_init, + 0, + 0, + 0, + 0, + 0, + Mapper40_init, + Mapper41_init, + Mapper42_init, + 0, //Mapper43_init, + 0, + 0, + Mapper46_init, + 0, + Mapper48_init, + 0, + Mapper50_init, + Mapper51_init, + 0, + 0, + 0, + 0, + 0, + 0,// Mapper57_init, + 0,// Mapper58_init, + Mapper59_init, + 0,// Mapper60_init, + Mapper61_init, + Mapper62_init, + 0, + Mapper64_init, + Mapper65_init, + 0,//Mapper66_init, + Mapper67_init, + 0,//Mapper68_init, + Mapper69_init, + 0,//Mapper70_init, + Mapper71_init, + Mapper72_init, + Mapper73_init, + 0, + Mapper75_init, + Mapper76_init, + Mapper77_init, + 0, //Mapper78_init, + Mapper79_init, + Mapper80_init, + 0, + Mapper82_init, + Mapper83_init, + 0, + Mapper85_init, + Mapper86_init, + 0, //Mapper87_init, + 0, //Mapper88_init, + Mapper89_init, + 0, + Mapper91_init, + Mapper92_init, + 0, //Mapper93_init, + 0, //Mapper94_init, + 0, + Mapper96_init, + Mapper97_init, + 0, + Mapper99_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper107_init, + 0, + 0, + 0, + 0, + 0, + 0, // Mapper113_init, + 0, + 0, + 0, //Mapper116_init, + 0, //Mapper117_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper140_init, + 0, + 0, + 0, + 0, //Mapper144_init, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper151_init, + 0, //Mapper152_init, + 0, //Mapper153_init, + 0, //Mapper154_init, + 0, + 0, + Mapper157_init, + 0, //Mapper158_init, removed + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper166_init, + Mapper167_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper180_init, + 0, + 0, + 0, + 0, //Mapper184_init, + 0, //Mapper185_init, + 0, + 0, + 0, + 0, //Mapper189_init, + 0, + 0, //Mapper191_init, + 0, + Mapper193_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper200_init, + Mapper201_init, + Mapper202_init, + Mapper203_init, + Mapper204_init, + 0, + 0, + Mapper207_init, + 0, + 0, + 0, + 0, //Mapper211_init, + Mapper212_init, + Mapper213_init, + Mapper214_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper225_init, + 0, //Mapper226_init, + Mapper227_init, + Mapper228_init, + Mapper229_init, + Mapper230_init, + Mapper231_init, + Mapper232_init, + 0, + Mapper234_init, + 0, //Mapper235_init, + 0, + 0, + 0, + 0, + 0, //Mapper240_init, + Mapper241_init, + Mapper242_init, + 0, + Mapper244_init, + 0, + Mapper246_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper255_init }; - - static DECLFW(BWRAM) { - WRAM[A-0x6000]=V; + WRAM[A-0x6000]=V; } static DECLFR(AWRAM) { - return WRAM[A-0x6000]; + return WRAM[A-0x6000]; } -#ifdef DEBUG_MAPPER -static DECLFW(WriteHandler) -{ - FCEU_printf("$%04x:$%02x\n",A,V); -} -#endif void (*MapStateRestore)(int version); void iNESStateRestore(int version) { - int x; - - if(!MapperNo) return; - - for(x=0;x<4;x++) - setprg8(0x8000+x*8192,PRGBankList[x]); - - if(VROM_size) - for(x=0;x<8;x++) - setchr1(0x400*x,CHRBankList[x]); - -if(0) switch(Mirroring) - { - case 0:setmirror(MI_H);break; - case 1:setmirror(MI_V);break; - case 0x12: - case 0x10:setmirror(MI_0);break; - case 0x13: - case 0x11:setmirror(MI_1);break; - } - if(MapStateRestore) MapStateRestore(version); + int x; + + if(!MapperNo) return; + + for(x=0;x<4;x++) + setprg8(0x8000+x*8192,PRGBankList[x]); + + if(VROM_size) + for(x=0;x<8;x++) + setchr1(0x400*x,CHRBankList[x]); + + if(0) switch(Mirroring) + { + case 0:setmirror(MI_H);break; + case 1:setmirror(MI_V);break; + case 0x12: + case 0x10:setmirror(MI_0);break; + case 0x13: + case 0x11:setmirror(MI_1);break; + } + if(MapStateRestore) MapStateRestore(version); } static void iNESPower(void) { - int x; + int x; int type=MapperNo; - SetReadHandler(0x8000,0xFFFF,CartBR); - GameStateRestore=iNESStateRestore; - MapClose=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + GameStateRestore=iNESStateRestore; + MapClose=0; MapperReset=0; - MapStateRestore=0; + MapStateRestore=0; - setprg8r(1,0x6000,0); + setprg8r(1,0x6000,0); - SetReadHandler(0x6000,0x7FFF,AWRAM); + SetReadHandler(0x6000,0x7FFF,AWRAM); #ifdef ASM_6502 - // asm code needs pages to be set again.. - Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000; + // asm code needs pages to be set again.. + Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000; #endif - SetWriteHandler(0x6000,0x7FFF,BWRAM); - FCEU_CheatAddRAM(8,0x6000,WRAM); - - #ifdef DEBUG_MAPPER - if(type==0) SetWriteHandler(0x4020,0xFFFF,WriteHandler); - #endif + SetWriteHandler(0x6000,0x7FFF,BWRAM); + FCEU_CheatAddRAM(8,0x6000,WRAM); /* This statement represents atrocious code. I need to rewrite - all of the iNES mapper code... */ + all of the iNES mapper code... */ IRQCount=IRQLatch=IRQa=0; - if(head.ROM_type&2) - memset(GameMemBlock+8192,0,sizeof(GameMemBlock)-8192); + if(head.ROM_type&2) + memset(GameMemBlock+8192,0,GAME_MEM_BLOCK_SIZE-8192); else - memset(GameMemBlock,0,sizeof(GameMemBlock)); + memset(GameMemBlock,0,GAME_MEM_BLOCK_SIZE); - NONE_init(); + NONE_init(); + ResetExState(0,0); - ResetExState(0,0); - if(FCEUGameInfo.type == GIT_VSUNI) - AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); + if(GameInfo->type == GIT_VSUNI) + AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); - AddExState(WRAM, 8192, 0, "WRAM"); - if(type==19 || type==6 || type==69 || type==85 || type==96) - AddExState(MapperExRAM, 32768, 0, "MEXR"); - if((!VROM_size || type==6 || type==19) && (type!=13 && type!=96)) - AddExState(CHRRAM, 8192, 0, "CHRR"); - if(head.ROM_type&8) - AddExState(ExtraNTARAM, 2048, 0, "EXNR"); + AddExState(WRAM, 8192, 0, "WRAM"); + if(type==19 || type==6 || type==69 || type==85 || type==96) + AddExState(MapperExRAM, 32768, 0, "MEXR"); + if((!VROM_size || type==6 || type==19) && (type!=13 && type!=96)) + AddExState(CHRRAM, 8192, 0, "CHRR"); + if(head.ROM_type&8) + AddExState(ExtraNTARAM, 2048, 0, "EXNR"); /* Exclude some mappers whose emulation code handle save state stuff - themselves. */ + themselves. */ if(type && type!=13 && type!=96) { - AddExState(mapbyte1, 32, 0, "MPBY"); - AddExState(&Mirroring, 1, 0, "MIRR"); - AddExState(&IRQCount, 4, 1, "IRQC"); - AddExState(&IRQLatch, 4, 1, "IQL1"); - AddExState(&IRQa, 1, 0, "IRQA"); - AddExState(PRGBankList, 4, 0, "PBL"); - for(x=0;x<8;x++) - { - char tak[8]; - sprintf(tak,"CBL%d",x); - AddExState(&CHRBankList[x], 2, 1,tak); - } + AddExState(mapbyte1, 32, 0, "MPBY"); + AddExState(&Mirroring, 1, 0, "MIRR"); + AddExState(&IRQCount, 4, 1, "IRQC"); + AddExState(&IRQLatch, 4, 1, "IQL1"); + AddExState(&IRQa, 1, 0, "IRQA"); + AddExState(PRGBankList, 4, 0, "PBL"); + for(x=0;x<8;x++) + { + char tak[8]; + sprintf(tak,"CBL%d",x); + AddExState(&CHRBankList[x], 2, 1,tak); + } } - if(MapInitTab[type]) MapInitTab[type](); - else if(type) - { - FCEU_PrintError("iNES mapper #%d is not supported at all.",type); - } + if(MapInitTab[type]) MapInitTab[type](); + else if(type) + { + FCEU_PrintError("iNES mapper #%d is not supported at all.",type); + } } +static int NewiNES_Init(int num) +{ + BMAPPINGLocal *tmp=bmap; -typedef struct { - int number; - void (*init)(CartInfo *); -} BMAPPING; - -static BMAPPING bmap[] = { - {0, NROM_Init}, - {1, Mapper1_Init}, - {2, UNROM_Init}, - {3, CNROM_Init}, - {4, Mapper4_Init}, - {5, Mapper5_Init}, - {7, ANROM_Init}, - {11, Mapper11_Init}, - {12, Mapper12_Init}, - {13, CPROM_Init}, - {19, Mapper19_Init}, - {37, Mapper37_Init}, - {44, Mapper44_Init}, - {45, Mapper45_Init}, - {47, Mapper47_Init}, - {49, Mapper49_Init}, - {52, Mapper52_Init}, - {57, Mapper57_Init}, - {58, Mapper58_Init}, - {66, MHROM_Init}, - {70, Mapper70_Init}, - {74, Mapper74_Init}, - {78, Mapper78_Init}, - {87, Mapper87_Init}, - {88, Mapper88_Init}, - {90, Mapper90_Init}, - {93, SUNSOFT_UNROM_Init}, - {94, Mapper94_Init}, - {95, Mapper95_Init}, - {105, Mapper105_Init}, - {107, Mapper107_Init}, - {112, Mapper112_Init}, - {114, Mapper114_Init}, - {115, Mapper115_Init}, - {116, Mapper116_Init}, - {117, Mapper117_Init}, - {118, Mapper118_Init}, - {119, Mapper119_Init}, - {133, SA72008_Init}, - {137, S8259D_Init}, - {138, S8259B_Init}, - {139, S8259C_Init}, - {140, Mapper140_Init}, - {141, S8259A_Init}, - {143, TCA01_Init}, - {144, Mapper144_Init}, - {145, SA72007_Init}, - {146, SA0161M_Init}, - {147, TCU01_Init}, - {148, SA0037_Init}, - {149, SA0036_Init}, - {150, S74LS374N_Init}, - {152, Mapper152_Init}, - {154, Mapper154_Init}, - {155, Mapper155_Init}, - {160, Mapper90_Init}, - {163, Mapper163_Init}, - {164, Mapper164_Init}, - {165, Mapper165_Init}, - {181, Mapper181_Init}, - {182, Mapper182_Init}, - {183, Mapper183_Init}, - {185, Mapper185_Init}, - {186, Mapper186_Init}, - {187, Mapper187_Init}, - {188, Mapper188_Init}, - {189, Mapper189_Init}, - {191, Mapper191_Init}, - {192, Mapper192_Init}, - {194, Mapper194_Init}, - {198, Mapper198_Init}, - {199, Mapper199_Init}, - {205, Mapper205_Init}, - {206, DEIROM_Init}, - {208, Mapper208_Init}, - {209, Mapper209_Init}, - {210, Mapper210_Init}, - {211, Mapper211_Init}, - {215, Mapper215_Init}, - {216, Mapper216_Init}, - {217, Mapper217_Init}, - {218, UNLSonic_Init}, - {219, UNLSL1632_Init}, -// {220, Mapper220_Init}, - {222, Mapper222_Init}, - {235, Mapper235_Init}, - {243, S74LS374NA_Init}, - {245, Mapper245_Init}, - {249, Mapper249_Init}, - {250, Mapper250_Init}, - {254, Mapper254_Init}, - { 0, 0} -}; + CHRRAMSize = -1; + if(GameInfo->type == GIT_VSUNI) + AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); -static int NewiNES_Init(int num) -{ - BMAPPING *tmp=bmap; - - if(FCEUGameInfo.type == GIT_VSUNI) - AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); - - while(tmp->init) - { - if(num==tmp->number) - { - UNIFchrrama=0; // need here for compatibility with UNIF mapper code - if(!VROM_size) - { - int CHRRAMSize; - if(num==13) - CHRRAMSize=16384; - else - CHRRAMSize=8192; - VROM=(uint8 *)malloc(CHRRAMSize); - UNIFchrrama=VROM; - SetupCartCHRMapping(0,VROM,CHRRAMSize,1); - AddExState(VROM,CHRRAMSize, 0, "CHRR"); - } - if(head.ROM_type&8) - AddExState(ExtraNTARAM, 2048, 0, "EXNR"); - tmp->init(&iNESCart); - return(1); - } - tmp++; - } - return(0); + while(tmp->init) + { + if(num==tmp->number) + { + UNIFchrrama=0; // need here for compatibility with UNIF mapper code + if(!VROM_size) + { + if(num==13) + { + CHRRAMSize=16384; + } + else + { + CHRRAMSize=8192; + } + if((VROM = (uint8 *)FCEU_malloc(CHRRAMSize)) == NULL) return 0; + FCEU_MemoryRand(VROM,CHRRAMSize); + + UNIFchrrama=VROM; + SetupCartCHRMapping(0,VROM,CHRRAMSize,1); + AddExState(VROM,CHRRAMSize, 0, "CHRR"); + } + if(head.ROM_type&8) + AddExState(ExtraNTARAM, 2048, 0, "EXNR"); + tmp->init(&iNESCart); + return 1; + } + tmp++; + } + return 0; } +// vim:ts=4 diff --git a/ines.h b/ines.h index 5a49aed..d18002c 100644 --- a/ines.h +++ b/ines.h @@ -16,9 +16,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef _INES_H_ +#define _INES_H_ +#include +#include #include "cart.h" #ifdef INESPRIV @@ -65,25 +69,53 @@ extern uint8 iNESIRQa; #else #endif - typedef struct { +#if 0 +struct TMasterRomInfo +{ + uint64 md5lower; + const char* params; +}; + +class TMasterRomInfoParams : public std::map +{ +public: + bool ContainsKey(const std::string& key) { return find(key) != end(); } +}; +#endif + +//mbg merge 6/29/06 +extern uint8 *ROM; +extern uint8 *VROM; +extern uint32 VROM_size; +extern uint32 ROM_size; +extern int iNesSave(); //bbit Edited: line added +extern int iNesSaveAs(char* name); +extern char LoadedRomFName[2048]; //bbit Edited: line added +//extern const TMasterRomInfo* MasterRomInfo; +//extern TMasterRomInfoParams MasterRomInfoParams; + +//mbg merge 7/19/06 changed to c++ decl format +struct iNES_HEADER { char ID[4]; /*NES^Z*/ uint8 ROM_size; uint8 VROM_size; uint8 ROM_type; uint8 ROM_type2; uint8 reserve[8]; - } iNES_HEADER; +}; + +extern struct iNES_HEADER head; //for mappers usage -void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V); -void FASTAPASS(2) VRAM_BANK4(uint32 A,uint32 V); +void VRAM_BANK1(uint32 A, uint8 V); +void VRAM_BANK4(uint32 A,uint32 V); -void FASTAPASS(2) VROM_BANK1(uint32 A,uint32 V); -void FASTAPASS(2) VROM_BANK2(uint32 A,uint32 V); -void FASTAPASS(2) VROM_BANK4(uint32 A, uint32 V); -void FASTAPASS(1) VROM_BANK8(uint32 V); -void FASTAPASS(2) ROM_BANK8(uint32 A, uint32 V); -void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V); -void FASTAPASS(1) ROM_BANK32(uint32 V); +void VROM_BANK1(uint32 A,uint32 V); +void VROM_BANK2(uint32 A,uint32 V); +void VROM_BANK4(uint32 A, uint32 V); +void VROM_BANK8(uint32 V); +void ROM_BANK8(uint32 A, uint32 V); +void ROM_BANK16(uint32 A, uint32 V); +void ROM_BANK32(uint32 V); extern uint8 vmask; extern uint32 vmask1; @@ -93,9 +125,9 @@ extern uint32 pmask8; extern uint8 pmask16; extern uint8 pmask32; -void FASTAPASS(1) onemir(uint8 V); -void FASTAPASS(1) MIRROR_SET2(uint8 V); -void FASTAPASS(1) MIRROR_SET(uint8 V); +void onemir(uint8 V); +void MIRROR_SET2(uint8 V); +void MIRROR_SET(uint8 V); void Mapper0_init(void); void Mapper1_init(void); @@ -110,15 +142,15 @@ void Mapper10_init(void); void Mapper12_init(void); //void Mapper13_init(void); void Mapper14_init(void); -void Mapper15_init(void); -void Mapper16_init(void); +//void Mapper15_init(void); +//void Mapper16_init(void); void Mapper17_init(void); void Mapper18_init(void); void Mapper19_init(void); void Mapper20_init(void); void Mapper21_init(void); void Mapper22_init(void); -void Mapper23_init(void); +//void Mapper23_init(void); void Mapper24_init(void); void Mapper25_init(void); void Mapper26_init(void); @@ -133,12 +165,12 @@ void Mapper34_init(void); void Mapper35_init(void); void Mapper36_init(void); //void Mapper37_init(void); -void Mapper38_init(void); -void Mapper39_init(void); +//void Mapper38_init(void); +//void Mapper39_init(void); void Mapper40_init(void); void Mapper41_init(void); void Mapper42_init(void); -void Mapper43_init(void); +//void Mapper43_init(void); void Mapper44_init(void); void Mapper45_init(void); void Mapper46_init(void); @@ -160,7 +192,7 @@ void Mapper64_init(void); void Mapper65_init(void); //void Mapper66_init(void); void Mapper67_init(void); -void Mapper68_init(void); +//void Mapper68_init(void); void Mapper69_init(void); //void Mapper70_init(void); void Mapper71_init(void); @@ -191,21 +223,21 @@ void Mapper97_init(void); void Mapper98_init(void); void Mapper99_init(void); void Mapper100_init(void); -void Mapper101_init(void); -void Mapper103_init(void); +//void Mapper101_init(void); +//void Mapper103_init(void); void Mapper104_init(void); -void Mapper106_init(void); +//void Mapper106_init(void); //void Mapper107_init(void); -void Mapper108_init(void); +//void Mapper108_init(void); void Mapper109_init(void); void Mapper110_init(void); void Mapper111_init(void); -void Mapper113_init(void); +//void Mapper113_init(void); void Mapper115_init(void); void Mapper116_init(void); //void Mapper117_init(void); -void Mapper120_init(void); -void Mapper121_init(void); +//void Mapper120_init(void); +//void Mapper121_init(void); void Mapper122_init(void); void Mapper123_init(void); void Mapper124_init(void); @@ -216,24 +248,23 @@ void Mapper129_init(void); void Mapper130_init(void); void Mapper131_init(void); void Mapper132_init(void); -void Mapper134_init(void); +//void Mapper134_init(void); void Mapper135_init(void); void Mapper136_init(void); void Mapper137_init(void); void Mapper139_init(void); //void Mapper140_init(void); void Mapper141_init(void); -void Mapper142_init(void); +//void Mapper142_init(void); void Mapper143_init(void); //void Mapper144_init(void); void Mapper150_init(void); void Mapper151_init(void); //void Mapper152_init(void); -void Mapper153_init(void); +//void Mapper153_init(void); void Mapper154_init(void); -void Mapper156_init(void); void Mapper157_init(void); -void Mapper158_init(void); +//void Mapper158_init(void); void Mapper159_init(void); void Mapper160_init(void); void Mapper161_init(void); @@ -241,31 +272,31 @@ void Mapper162_init(void); void Mapper166_init(void); void Mapper167_init(void); void Mapper168_init(void); -void Mapper169_init(void); +//void Mapper169_init(void); void Mapper170_init(void); -void Mapper171_init(void); -void Mapper172_init(void); -void Mapper173_init(void); +//void Mapper171_init(void); +//void Mapper172_init(void); +//void Mapper173_init(void); void Mapper174_init(void); void Mapper175_init(void); void Mapper176_init(void); -void Mapper177_init(void); -void Mapper178_init(void); -void Mapper179_init(void); -void Mapper180_init(void); +//void Mapper177_init(void); +//void Mapper178_init(void); +//void Mapper179_init(void); +//void Mapper180_init(void); //void Mapper181_init(void); -void Mapper184_init(void); +//void Mapper184_init(void); //void Mapper185_init(void); //void Mapper189_init(void); //void Mapper192_init(void); void Mapper193_init(void); //void Mapper194_init(void); -void Mapper195_init(void); -void Mapper196_init(void); -void Mapper197_init(void); +//void Mapper195_init(void); +//void Mapper196_init(void); +//void Mapper197_init(void); //void Mapper198_init(void); void Mapper199_init(void); -void Mapper200_init(void); +//void Mapper200_init(void); void Mapper201_init(void); void Mapper202_init(void); void Mapper203_init(void); @@ -283,7 +314,7 @@ void Mapper221_init(void); void Mapper223_init(void); void Mapper224_init(void); void Mapper225_init(void); -void Mapper226_init(void); +//void Mapper226_init(void); void Mapper227_init(void); void Mapper228_init(void); void Mapper229_init(void); @@ -307,7 +338,7 @@ void Mapper247_init(void); void Mapper249_init(void); void Mapper251_init(void); void Mapper252_init(void); -void Mapper253_init(void); +//void Mapper253_init(void); void Mapper255_init(void); void NSFVRC6_Init(void); @@ -322,15 +353,22 @@ void Mapper4_Init(CartInfo *); void Mapper5_Init(CartInfo *); void Mapper11_Init(CartInfo *); void Mapper12_Init(CartInfo *); +void Mapper15_Init(CartInfo *); +void Mapper16_Init(CartInfo *); void Mapper19_Init(CartInfo *); +void Mapper23_Init(CartInfo *); +void Mapper36_Init(CartInfo *); void Mapper37_Init(CartInfo *); +void Mapper38_Init(CartInfo *); +void Mapper43_Init(CartInfo *); void Mapper44_Init(CartInfo *); void Mapper45_Init(CartInfo *); void Mapper47_Init(CartInfo *); void Mapper49_Init(CartInfo *); void Mapper52_Init(CartInfo *); void Mapper57_Init(CartInfo *); -void Mapper58_Init(CartInfo *); +//void Mapper58_Init(CartInfo *); +void Mapper68_Init(CartInfo *); void Mapper70_Init(CartInfo *); void Mapper74_Init(CartInfo *); void Mapper78_Init(CartInfo *); @@ -340,27 +378,48 @@ void Mapper90_Init(CartInfo *); void Mapper93_Init(CartInfo *); void Mapper94_Init(CartInfo *); void Mapper95_Init(CartInfo *); +void Mapper101_Init(CartInfo *); +void Mapper103_Init(CartInfo *); void Mapper105_Init(CartInfo *); +void Mapper106_Init(CartInfo *); void Mapper107_Init(CartInfo *); +void Mapper108_Init(CartInfo *); void Mapper112_Init(CartInfo *); +void Mapper113_Init(CartInfo *); void Mapper114_Init(CartInfo *); void Mapper115_Init(CartInfo *); void Mapper116_Init(CartInfo *); void Mapper117_Init(CartInfo *); void Mapper118_Init(CartInfo *); void Mapper119_Init(CartInfo *); +void Mapper120_Init(CartInfo *); +void Mapper121_Init(CartInfo *); void Mapper125_Init(CartInfo *); +void Mapper134_Init(CartInfo *); void Mapper140_Init(CartInfo *); void Mapper144_Init(CartInfo *); void Mapper152_Init(CartInfo *); +void Mapper153_Init(CartInfo *); void Mapper154_Init(CartInfo *); void Mapper155_Init(CartInfo *); +void Mapper156_Init(CartInfo *); +void Mapper159_Init(CartInfo *); void Mapper163_Init(CartInfo *); void Mapper164_Init(CartInfo *); void Mapper165_Init(CartInfo *); +//void Mapper169_Init(CartInfo *); +void Mapper171_Init(CartInfo *); +void Mapper172_Init(CartInfo *); +void Mapper173_Init(CartInfo *); +void Mapper175_Init(CartInfo *); +void Mapper176_Init(CartInfo *); +void Mapper177_Init(CartInfo *); +void Mapper178_Init(CartInfo *); +void Mapper180_Init(CartInfo *); void Mapper181_Init(CartInfo *); -void Mapper182_Init(CartInfo *); +//void Mapper182_Init(CartInfo *); void Mapper183_Init(CartInfo *); +void Mapper184_Init(CartInfo *); void Mapper185_Init(CartInfo *); void Mapper186_Init(CartInfo *); void Mapper187_Init(CartInfo *); @@ -369,22 +428,31 @@ void Mapper189_Init(CartInfo *); void Mapper191_Init(CartInfo *); void Mapper192_Init(CartInfo *); void Mapper194_Init(CartInfo *); +void Mapper195_Init(CartInfo *); +void Mapper196_Init(CartInfo *); +void Mapper197_Init(CartInfo *); void Mapper198_Init(CartInfo *); void Mapper199_Init(CartInfo *); +void Mapper200_Init(CartInfo *); void Mapper205_Init(CartInfo *); void Mapper208_Init(CartInfo *); void Mapper209_Init(CartInfo *); void Mapper210_Init(CartInfo *); void Mapper211_Init(CartInfo *); -void Mapper215_Init(CartInfo *); +//void Mapper215_Init(CartInfo *); void Mapper216_Init(CartInfo *); -void Mapper217_Init(CartInfo *); +//void Mapper217_Init(CartInfo *); void Mapper220_Init(CartInfo *); void Mapper222_Init(CartInfo *); +void Mapper226_Init(CartInfo *); void Mapper235_Init(CartInfo *); void Mapper236_Init(CartInfo *); void Mapper237_Init(CartInfo *); +void Mapper240_Init(CartInfo *); void Mapper245_Init(CartInfo *); void Mapper249_Init(CartInfo *); void Mapper250_Init(CartInfo *); +void Mapper253_Init(CartInfo *); void Mapper254_Init(CartInfo *); + +#endif diff --git a/mappers/113.c b/mappers/113.c deleted file mode 100644 index 525f131..0000000 --- a/mappers/113.c +++ /dev/null @@ -1,64 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -/* I'm getting the feeling this is another "jam two different bank - switching hardwares into one mapper". -*/ - -/* HES 4-in-1 */ -DECLFW(Mapper113_write) -{ - ROM_BANK32((V>>3)&7); - VROM_BANK8(((V>>3)&8)|(V&7)); - //printf("$%04x:$%02x\n",A,V); -} - - -/* Deathbots */ -DECLFW(Mapper113_writeh) -{ - //printf("$%04x:$%02x\n",A,V); - // ROM_BANK32(V&0x7); - //VROM_BANK8((V>>4)&0x7); - switch(A) { - case 0x8008: - case 0x8009: - ROM_BANK32(V>>3); - VROM_BANK8(((V>>3)&0x08)+(V&0x07) ); - break; - case 0x8E66: - case 0x8E67: - VROM_BANK8( (V&0x07)?0:1 ); - break; - case 0xE00A: - MIRROR_SET2( 2 ); - break; - } -} - - -void Mapper113_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x4020,0x7fff,Mapper113_write); - SetWriteHandler(0x8000,0xffff,Mapper113_writeh); -} diff --git a/mappers/15.c b/mappers/15.c deleted file mode 100644 index e649af6..0000000 --- a/mappers/15.c +++ /dev/null @@ -1,73 +0,0 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static void Sync(void) -{ - int x; - - setmirror(((mapbyte1[0]>>6)&1)^1); - switch(mapbyte1[1]&0x3) - { - case 0x0: - for(x=0;x<4;x++) - setprg8(0x8000+x*8192,(((mapbyte1[0]&0x7F)<<1)+x)^(mapbyte1[0]>>7)); - break; - case 0x2: - for(x=0;x<4;x++) - setprg8(0x8000+x*8192,((mapbyte1[0]&0x7F)<<1)+(mapbyte1[0]>>7)); - break; - case 0x1: - case 0x3: - for(x=0;x<4;x++) - { - unsigned int b; - - b=mapbyte1[0]&0x7F; - if(x>=2 && !(mapbyte1[1]&0x2)) - b=0x7F; - setprg8(0x8000+x*8192,(x&1)+((b<<1)^(mapbyte1[0]>>7))); - } - break; - } -} - - -static DECLFW(Mapper15_write) -{ - mapbyte1[0]=V; - mapbyte1[1]=A&3; - Sync(); -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper15_init(void) -{ - mapbyte1[0]=mapbyte1[1]=0; - Sync(); - GameStateRestore=StateRestore; - SetWriteHandler(0x8000,0xFFFF,Mapper15_write); -} - diff --git a/mappers/151.c b/mappers/151.c index 5d2cb28..91938d5 100644 --- a/mappers/151.c +++ b/mappers/151.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/156.c b/mappers/156.c new file mode 100644 index 0000000..8e40a19 --- /dev/null +++ b/mappers/156.c @@ -0,0 +1,126 @@ +/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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; +// uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "PREG"}, + {chrlo, 8, "CRLO"}, + {chrhi, 8, "CRHI"}, + {&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 M1566Reset() +{ + for(int i=0;i<8;i++) + { + chrlo[i]=0; + chrhi[i]=0; + } + prg=0; + mirr=0; + mirrisused = 0; +} + +static void M156Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0xC000,0xCFFF,M156Write); + + M1566Reset(); +} + +static void M156Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper156_Init(CartInfo *info) +{ + 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/mappers/16.c b/mappers/16.c index 2e8d013..002d3cb 100644 --- a/mappers/16.c +++ b/mappers/16.c @@ -16,12 +16,12 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -static void FP_FASTAPASS(1) BandaiIRQHook(int a) +static void BandaiIRQHook(int a) { if(IRQa) { @@ -70,7 +70,7 @@ static DECLFW(Mapper16_write) // 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 PRGO(void) { uint32 base=(mapbyte1[0]&1)<<4; @@ -110,21 +110,21 @@ static DECLFW(Mapper153_write) IRQLatch|=V<<8; break; } -} - -void Mapper16_init(void) -{ - MapIRQHook=BandaiIRQHook; - SetWriteHandler(0x6000,0xFFFF,Mapper16_write); -} - -void Mapper153_init(void) -{ - MapIRQHook=BandaiIRQHook; - SetWriteHandler(0x8000,0xFFFF,Mapper153_write); +}*/ + +//void Mapper16_init(void) +//{ +// MapIRQHook=BandaiIRQHook; +//SetWriteHandler(0x6000,0xFFFF,Mapper16_write); +//} + +//void Mapper153_init(void) +//{ +// MapIRQHook=BandaiIRQHook; +// SetWriteHandler(0x8000,0xFFFF,Mapper153_write); /* This mapper/board seems to have WRAM at $6000-$7FFF, so I'll let the main ines code take care of that memory region. */ -} +//} static uint8 BarcodeData[256]; @@ -260,7 +260,7 @@ int FCEUI_DatachSet(const uint8 *rcode) return(1); } -static void FP_FASTAPASS(1) BarcodeIRQHook(int a) +static void BarcodeIRQHook(int a) { BandaiIRQHook(a); @@ -291,7 +291,7 @@ static DECLFR(Mapper157_read) void Mapper157_init(void) { - FCEUGameInfo.cspecial = SIS_DATACH; + GameInfo->cspecial = SIS_DATACH; MapIRQHook=BarcodeIRQHook; SetWriteHandler(0x6000,0xFFFF,Mapper16_write); SetReadHandler(0x6000,0x7FFF,Mapper157_read); diff --git a/mappers/17.c b/mappers/17.c index 7fae1a8..c20bc28 100644 --- a/mappers/17.c +++ b/mappers/17.c @@ -15,14 +15,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -static void FP_FASTAPASS(1) FFEIRQHook(int a) +static void FFEIRQHook(int a) { if(IRQa) { diff --git a/mappers/18.c b/mappers/18.c index b682b26..030c055 100644 --- a/mappers/18.c +++ b/mappers/18.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -23,7 +23,7 @@ #define K4buf mapbyte2 #define K4buf2 mapbyte3 -void FP_FASTAPASS(1) JalecoIRQHook(int a) +void JalecoIRQHook(int a) { if(IRQa && IRQCount) { diff --git a/mappers/180.c b/mappers/180.c deleted file mode 100644 index bd877c8..0000000 --- a/mappers/180.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "mapinc.h" - - - -DECLFW(Mapper180_write) -{ -ROM_BANK16(0xC000,V); -} - -void Mapper180_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper180_write); -} - diff --git a/mappers/183.c b/mappers/183.c deleted file mode 100644 index e69de29..0000000 diff --git a/mappers/184.c b/mappers/184.c deleted file mode 100644 index 70fd6b1..0000000 --- a/mappers/184.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "mapinc.h" - - - -DECLFW(Mapper184_write) -{ -VROM_BANK4(0x0000,V); -VROM_BANK4(0x1000,(V>>4)); -} - -void Mapper184_init(void) -{ - SetWriteHandler(0x6000,0xffff,Mapper184_write); -} - diff --git a/mappers/200.c b/mappers/200.c deleted file mode 100644 index ec13308..0000000 --- a/mappers/200.c +++ /dev/null @@ -1,36 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static DECLFW(Mapper200_write) -{ -// FCEU_printf("%04x, %02x\n",A,V); - ROM_BANK16(0x8000,A&0x07); - ROM_BANK16(0xC000,A&0x07); - VROM_BANK8(A&0x07); - MIRROR_SET((A&0x08)>>3); -} - -void Mapper200_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper200_write); -} - diff --git a/mappers/201.c b/mappers/201.c index 03e77e6..d566470 100644 --- a/mappers/201.c +++ b/mappers/201.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -37,8 +37,8 @@ static DECLFW(Mapper201_write) void Mapper201_init(void) { - ROM_BANK32(0); - VROM_BANK8(0); + ROM_BANK32(~0); + VROM_BANK8(~0); SetWriteHandler(0x8000,0xffff,Mapper201_write); } diff --git a/mappers/202.c b/mappers/202.c index cac2a88..7c02f97 100644 --- a/mappers/202.c +++ b/mappers/202.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/203.c b/mappers/203.c index 6ab5d52..0187b8a 100644 --- a/mappers/203.c +++ b/mappers/203.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/204.c b/mappers/204.c index edca423..543364b 100644 --- a/mappers/204.c +++ b/mappers/204.c @@ -1,38 +1,38 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2003 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static DECLFW(Mapper204_write) -{ - int tmp2=A&0x6; - int tmp1=tmp2+((tmp2==0x6)?0:(A&1)); - MIRROR_SET((A>>4)&1); - ROM_BANK16(0x8000,tmp1); - ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1))); - VROM_BANK8(tmp1); -} - -void Mapper204_init(void) -{ - ROM_BANK32(~0); - VROM_BANK8(~0); - SetWriteHandler(0x8000,0xFFFF,Mapper204_write); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2003 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 DECLFW(Mapper204_write) +{ + int tmp2=A&0x6; + int tmp1=tmp2+((tmp2==0x6)?0:(A&1)); + MIRROR_SET((A>>4)&1); + ROM_BANK16(0x8000,tmp1); + ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1))); + VROM_BANK8(tmp1); +} + +void Mapper204_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xFFFF,Mapper204_write); +} diff --git a/mappers/21.c b/mappers/21.c index 8d60d4c..c8b8cd9 100644 --- a/mappers/21.c +++ b/mappers/21.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -82,7 +82,7 @@ DECLFW(Mapper21_write) case 0xf006:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; } } -static void FP_FASTAPASS(1) KonamiIRQHook(int a) +static void KonamiIRQHook(int a) { #define LCYCS ((227*2)+1) //#define LCYCS 341 diff --git a/mappers/212.c b/mappers/212.c index e5677b6..b069fc3 100644 --- a/mappers/212.c +++ b/mappers/212.c @@ -1,23 +1,23 @@ -#include "mapinc.h" - -static DECLFW(Mapper212_write) -{ - if((A&0x4000)==0x4000) - { - ROM_BANK32((A&6)>>1); - } - else - { - ROM_BANK16(0x8000,A&7); - ROM_BANK16(0xc000,A&7); - } - VROM_BANK8(A&7); - MIRROR_SET((A>>3)&1); -} - -void Mapper212_init(void) -{ - ROM_BANK32(~0); - VROM_BANK8(~0); - SetWriteHandler(0x8000,0xFFFF,Mapper212_write); -} +#include "mapinc.h" + +static DECLFW(Mapper212_write) +{ + if((A&0x4000)==0x4000) + { + ROM_BANK32((A&6)>>1); + } + else + { + ROM_BANK16(0x8000,A&7); + ROM_BANK16(0xc000,A&7); + } + VROM_BANK8(A&7); + MIRROR_SET((A>>3)&1); +} + +void Mapper212_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xFFFF,Mapper212_write); +} diff --git a/mappers/213.c b/mappers/213.c index c537f6c..e0b8d82 100644 --- a/mappers/213.c +++ b/mappers/213.c @@ -1,14 +1,14 @@ -#include "mapinc.h" - -static DECLFW(Mapper213_write) -{ - ROM_BANK32((A>>1)&3); - VROM_BANK8((A>>3)&7); -} - -void Mapper213_init(void) -{ - ROM_BANK32(0); - VROM_BANK8(0); - SetWriteHandler(0x8000,0xFFFF,Mapper213_write); -} +#include "mapinc.h" + +static DECLFW(Mapper213_write) +{ + ROM_BANK32((A>>1)&3); + VROM_BANK8((A>>3)&7); +} + +void Mapper213_init(void) +{ + ROM_BANK32(0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper213_write); +} diff --git a/mappers/214.c b/mappers/214.c index deaf47d..03a73ce 100644 --- a/mappers/214.c +++ b/mappers/214.c @@ -1,17 +1,17 @@ -#include "mapinc.h" - -static DECLFW(Mapper214_write) -{ -// FCEU_printf("%02x:%02x\n",A,V); - ROM_BANK16(0x8000,(A>>2)&3); - ROM_BANK16(0xC000,(A>>2)&3); - VROM_BANK8(A&3); -} - -void Mapper214_init(void) -{ - ROM_BANK16(0x8000,0); - ROM_BANK16(0xC000,0); - VROM_BANK8(0); - SetWriteHandler(0x8000,0xFFFF,Mapper214_write); -} +#include "mapinc.h" + +static DECLFW(Mapper214_write) +{ +// FCEU_printf("%02x:%02x\n",A,V); + ROM_BANK16(0x8000,(A>>2)&3); + ROM_BANK16(0xC000,(A>>2)&3); + VROM_BANK8(A&3); +} + +void Mapper214_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xC000,0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper214_write); +} diff --git a/mappers/217.c b/mappers/217.c index c9c3297..1bf4cbd 100644 --- a/mappers/217.c +++ b/mappers/217.c @@ -94,4 +94,3 @@ void Mapper217_init(void) DoCHR217(); } */ - diff --git a/mappers/22.c b/mappers/22.c index 4a08094..eee5365 100644 --- a/mappers/22.c +++ b/mappers/22.c @@ -15,7 +15,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * (VRC4 mapper) */ #include "mapinc.h" diff --git a/mappers/225.c b/mappers/225.c index 14e38f2..60c97c8 100644 --- a/mappers/225.c +++ b/mappers/225.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -58,7 +58,7 @@ DECLFW(Mapper225_write) else banks=0; - VROM_BANK8(((A&0x003f)+(banks<<6))); + VROM_BANK8(((A&0x003f)+(banks<<6))); if(A&0x1000) { if(A&0x40) diff --git a/mappers/226.c b/mappers/226.c deleted file mode 100644 index bde4f52..0000000 --- a/mappers/226.c +++ /dev/null @@ -1,105 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -#define rg mapbyte1 -static void DoPRG(void) -{ - int32 b=((rg[0]>>1)&0xF) | ((rg[0]>>3)&0x10) | ((rg[1]&1)<<5); - if(rg[0]&0x20) // 16 KB - { - ROM_BANK16(0x8000,(b<<1)|(rg[0]&1)); - ROM_BANK16(0xC000,(b<<1)|(rg[0]&1)); - } - else - ROM_BANK32(b); -} - -static DECLFW(Mapper226_write) -{ - rg[A&1]=V; - DoPRG(); - if(A&1) - { - if(rg[1]&2) - PPUCHRRAM=0; // Write protected. - else - PPUCHRRAM=0xFF; // Not write protected. - } - else - MIRROR_SET2((rg[0]>>6)&1); -} - -static void M26Reset(void) -{ - rg[0]=rg[1]=0; - DoPRG(); - PPUCHRRAM=0xFF; - MIRROR_SET2(0); -} - -static void M26Restore(int version) -{ - DoPRG(); - if(rg[1]&2) - PPUCHRRAM=0; // Write protected. - else - PPUCHRRAM=0xFF; // Not write protected. - MIRROR_SET2((rg[0]>>6)&1); -} - -void Mapper226_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper226_write); - MapperReset=M26Reset; - GameStateRestore=M26Restore; - M26Reset(); -} - -#ifdef OLD // What the heck is this?? -DECLFW(Mapper226_write) -{ - MIRROR_SET((A>>13)&1); - VROM_BANK8(A&0x7F); - if(A&0x1000) - { - if(A&0x40) - { - ROM_BANK16(0x8000,(((A>>7))<<1)+1); - ROM_BANK16(0xC000,(((A>>7))<<1)+1); - } - else - { - ROM_BANK16(0x8000,(((A>>7))<<1)); - ROM_BANK16(0xC000,(((A>>7))<<1)); - } - } - else - { - ROM_BANK32(A>>7); - } -} - -void Mapper226_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper226_write); -} -#endif diff --git a/mappers/227.c b/mappers/227.c index 457e79e..8b5cff9 100644 --- a/mappers/227.c +++ b/mappers/227.c @@ -15,53 +15,68 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" +//zero 14-apr-2012 - redid this entirely to match bizhawk + #define rg mapbyte1 static void DoSync(uint32 A) { - int32 p=((A>>3)&0xF) | ((A>>4)&0x10); + int S = A & 1; + int M_horz = (A>>1)&1; + int p = (A >> 2) & 0x1F; + p += (A&0x100) ? 0x20 : 0; + bool o = (A>>7)&1; + bool L = (A>>9)&1; + + if (o && !S ) + { + ROM_BANK16(0x8000,p); + ROM_BANK16(0xC000,p); + } + if (o && S ) + { + ROM_BANK16(0x8000,p); + ROM_BANK16(0xC000,p+1); + } + if (!o && !S && !L ) + { + ROM_BANK16(0x8000,p); + ROM_BANK16(0xC000,p&0x38); + } + if (!o && S && !L ) + { + ROM_BANK16(0x8000,p&0x3E); + ROM_BANK16(0xC000,p&0x38); + } + if (!o && !S && L) + { + ROM_BANK16(0x8000,p); + ROM_BANK16(0xC000,p|7); + } + if (!o && S && L ) + { + ROM_BANK16(0x8000,p&0x3E); + ROM_BANK16(0xC000,p|7); + } rg[0]=A; rg[1]=A>>8; MIRROR_SET((A>>1)&1); - if(A&1) //32 KB - { - ROM_BANK32(p); - } - else //16 KB - { - ROM_BANK16(0x8000,(p<<1)|((A&4)>>2)); - ROM_BANK16(0xc000,(p<<1)|((A&4)>>2)); - } - if(A&0x80) - { - PPUCHRRAM=0; - } - else - { - PPUCHRRAM=0xFF; - if(A&0x200) - ROM_BANK16(0xC000,(p<<1)|7); - else - ROM_BANK16(0xC000,(p<<1)&(~7)); - } } static DECLFW(Mapper227_write) { - rg[A&1]=V; DoSync(A); } static void M227Reset(void) { - rg[0]=rg[1]=0; DoSync(0); } @@ -72,7 +87,7 @@ static void M227Restore(int version) void Mapper227_init(void) { - SetWriteHandler(0x6000,0xffff,Mapper227_write); + SetWriteHandler(0x8000,0xffff,Mapper227_write); MapperReset=M227Reset; GameStateRestore=M227Restore; M227Reset(); diff --git a/mappers/228.c b/mappers/228.c index bfae3a6..a63218e 100644 --- a/mappers/228.c +++ b/mappers/228.c @@ -15,39 +15,62 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" +//16 bits of ram in total +//only use bottom 4 bits as ram though +static uint8 mapper228_ram[4]; + +static SFORMAT StateRegs[]= +{ + { mapper228_ram, 4, "MAPPER_RAM" }, + { 0 } +}; + +static DECLFR(Mapper228_read) +{ + return mapper228_ram[A & 3] & 0xF; +} + static DECLFW(Mapper228_write) { - uint32 page,pagel,pageh; + uint32 page, pagel, pageh; - MIRROR_SET((A>>13)&1); + //write to ram + if (A < 0x6000) + { + mapper228_ram[A & 3] = V; + return; + } + MIRROR_SET((A >> 13) & 1); + page = (A >> 7) & 0x3F; - page=(A>>7)&0x3F; - //printf("%04x\n",A); - if((page&0x30)==0x30) - page-=0x10; - - pagel=pageh=(page<<1) + (((A>>6)&1)&((A>>5)&1)); - pageh+=((A>>5)&1)^1; + if( (page & 0x30) == 0x30) + page -= 0x10; - ROM_BANK16(0x8000,pagel); - ROM_BANK16(0xC000,pageh); - VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); + pagel = pageh = (page << 1) + (((A >> 6) & 1) & ((A >> 5) & 1)); + pageh += ((A >> 5) & 1) ^ 1; + + ROM_BANK16(0x8000,pagel); + ROM_BANK16(0xC000,pageh); + VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); } static void A52Reset(void) { - Mapper228_write(0,0); + Mapper228_write(0x8000, 0); } void Mapper228_init(void) { - MapperReset=A52Reset; - A52Reset(); - SetWriteHandler(0x8000,0xffff,Mapper228_write); + MapperReset=A52Reset; + A52Reset(); + SetWriteHandler(0x8000, 0xFFFF, Mapper228_write); + SetWriteHandler(0x4020, 0x5FFF, Mapper228_write); + SetReadHandler (0x4020, 0x5FFF, Mapper228_read); + AddExState(StateRegs, ~0, 0, 0); } diff --git a/mappers/229.c b/mappers/229.c index a78dd73..acc31a3 100644 --- a/mappers/229.c +++ b/mappers/229.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/23.c b/mappers/23.c deleted file mode 100644 index d61a555..0000000 --- a/mappers/23.c +++ /dev/null @@ -1,103 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -#define K4buf mapbyte2 -#define K4IRQ mapbyte1[1] -#define K4sel mapbyte1[0] -static int acount=0; -static DECLFW(Mapper23_write) -{ - if((A&0xF000)==0x8000) - { - if(K4sel&2) - ROM_BANK8(0xC000,V); - else - ROM_BANK8(0x8000,V); - } - else if((A&0xF000)==0xA000) - ROM_BANK8(0xA000,V); - else - { - A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); - A&=0xF003; - if(A>=0xb000 && A<=0xe003) - { - int x=((A>>1)&1)|((A-0xB000)>>11); - - K4buf[x]&=(0xF0)>>((A&1)<<2); - K4buf[x]|=(V&0xF)<<((A&1)<<2); - VROM_BANK1(x<<10,K4buf[x]); - } - else - switch(A) - { - 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;K4IRQ=V&1;break; - case 0xf003:X6502_IRQEnd(FCEU_IQEXT);IRQa=K4IRQ;break; - case 0x9001: - case 0x9002: - case 0x9003: - if((K4sel&2)!=(V&2)) - { - uint8 swa; - swa=PRGBankList[0]; - ROM_BANK8(0x8000,PRGBankList[2]); - ROM_BANK8(0xc000,swa); - } - K4sel=V; - break; - case 0x9000: - if(V!=0xFF) - switch(V&0x3) - { - case 0:MIRROR_SET(0);break; - case 1:MIRROR_SET(1);break; - case 2:onemir(0);break; - case 3:onemir(1);break; - } - break; - } - } -} - -void FP_FASTAPASS(1) KonamiIRQHook2(int a) -{ - #define LCYCS 341 - if(IRQa) - { - acount+=a*3; - if(acount>=LCYCS) - { - doagainbub:acount-=LCYCS;IRQCount++; - if(IRQCount&0x100) {X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;} - if(acount>=LCYCS) goto doagainbub; - } - } -} - -void Mapper23_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper23_write); - MapIRQHook=KonamiIRQHook2; -} - diff --git a/mappers/230.c b/mappers/230.c index cbf1fbe..32550e5 100644 --- a/mappers/230.c +++ b/mappers/230.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/231.c b/mappers/231.c index 9b8d1fc..0f467ec 100644 --- a/mappers/231.c +++ b/mappers/231.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/232.c b/mappers/232.c index 548db8c..6beafb2 100644 --- a/mappers/232.c +++ b/mappers/232.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/234.c b/mappers/234.c index d8ca53f..1835d57 100644 --- a/mappers/234.c +++ b/mappers/234.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/240.c b/mappers/240.c deleted file mode 100644 index dbbfe19..0000000 --- a/mappers/240.c +++ /dev/null @@ -1,39 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - - - -DECLFW(Mapper240_write) -{ - if(A<0x8000) - { - ROM_BANK32(V>>4); - VROM_BANK8(V&0xF); - } -} - -void Mapper240_init(void) -{ - SetWriteHandler(0x4020,0x5fff,Mapper240_write); - SetWriteHandler(0x8000,0xffff,Mapper240_write); -} - diff --git a/mappers/242.c b/mappers/242.c index 2fa4171..72c0be5 100644 --- a/mappers/242.c +++ b/mappers/242.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -24,12 +24,10 @@ DECLFW(Mapper242_write) { ROM_BANK32((A>>3)&0xF); - switch(V&3) + switch((A>>1)&1) { case 0:MIRROR_SET(0);break; case 1:MIRROR_SET(1);break; - case 2:onemir(0);break; - case 3:onemir(1);break; } } diff --git a/mappers/244.c b/mappers/244.c index 13ea2c1..68a7563 100644 --- a/mappers/244.c +++ b/mappers/244.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/246.c b/mappers/246.c index 8623233..4ae017e 100644 --- a/mappers/246.c +++ b/mappers/246.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/24and26.c b/mappers/24and26.c index 3368856..115ead0 100644 --- a/mappers/24and26.c +++ b/mappers/24and26.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -34,7 +34,7 @@ static int swaparoo; static int acount=0; -static void FP_FASTAPASS(1) KonamiIRQHook(int a) +static void KonamiIRQHook(int a) { #define LCYCS 341 // #define LCYCS ((227*2)+1) @@ -222,10 +222,9 @@ static void DoSawV(void) } } -#if 0 static INLINE void DoSQVHQ(int x) { - int32 V; + uint32 V; //mbg merge 7/17/06 made uint int32 amp=((VPSG[x<<2]&15)<<8)*6/8; if(VPSG[(x<<2)|0x2]&0x80) @@ -268,7 +267,7 @@ static void DoSawVHQ(void) { static uint8 b3=0; static int32 phaseacc=0; - int32 V; + uint32 V; //mbg merge 7/17/06 made uint32 if(VPSG2[2]&0x80) { @@ -292,7 +291,6 @@ static void DoSawVHQ(void) } CVBC[2]=SOUNDTS; } -#endif void VRC6Sound(int Count) @@ -306,7 +304,6 @@ void VRC6Sound(int Count) CVBC[x]=Count; } -#if 0 void VRC6SoundHQ(void) { DoSQV1HQ(); @@ -319,21 +316,19 @@ void VRC6SyncHQ(int32 ts) int x; for(x=0;x<3;x++) CVBC[x]=ts; } -#endif static void VRC6_ESI(void) { GameExpSound.RChange=VRC6_ESI; GameExpSound.Fill=VRC6Sound; - GameExpSound.HiFill=0;//VRC6SoundHQ; - GameExpSound.HiSync=0;//VRC6SyncHQ; + 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 0 if(FSettings.soundq>=1) { sfun[0]=DoSQV1HQ; @@ -341,7 +336,6 @@ static void VRC6_ESI(void) sfun[2]=DoSawVHQ; } else -#endif { sfun[0]=DoSQV1; sfun[1]=DoSQV2; diff --git a/mappers/25.c b/mappers/25.c index f8c1d73..e099cc9 100644 --- a/mappers/25.c +++ b/mappers/25.c @@ -15,7 +15,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * (VRCII mapper) */ #include "mapinc.h" @@ -25,9 +26,21 @@ #define K4sel mapbyte1[0] static int acount=0; +static int weirdo=0; static DECLFW(Mapper25_write) { - A=(A&0xF003)|((A&0xC)>>2); + if(A==0xC007) + { + weirdo=8; // Ganbare Goemon Gaiden does strange things!!! at the end credits + // 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 + VROM_BANK1(0x0000,0xFC); + VROM_BANK1(0x0400,0xFD); + VROM_BANK1(0x0800,0xFF); + VROM_BANK1(0x0c00,0xCF); + } + + A=(A&0xF003)|((A&0xC)>>2); if((A&0xF000)==0xA000) ROM_BANK8(0xA000,V); @@ -37,7 +50,10 @@ static DECLFW(Mapper25_write) K4buf[x]&=(0xF0)>>((A&2)<<1); K4buf[x]|=(V&0xF)<<((A&2)<<1); - VROM_BANK1(x<<10,K4buf[x]); + if(weirdo) + weirdo--; + else + VROM_BANK1(x<<10,K4buf[x]); } else if((A&0xF000)==0x8000) { @@ -72,7 +88,7 @@ static DECLFW(Mapper25_write) } } -static void FP_FASTAPASS(1) KonamiIRQHook(int a) +static void KonamiIRQHook(int a) { // #define LCYCS ((227*2)) #define LCYCS 341 diff --git a/mappers/255.c b/mappers/255.c index d65f18d..405340e 100644 --- a/mappers/255.c +++ b/mappers/255.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/27.c b/mappers/27.c index 4b5cd73..e1afc22 100644 --- a/mappers/27.c +++ b/mappers/27.c @@ -1,74 +1,69 @@ -#include "mapinc.h" - -static uint32 regchr[9]; - -static DECLFW(Mapper27_write) -{ - A&=0xF00F; - int regnum; - if((A>=0xB000) && (A<=0xE003)) { - regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); - if(A&1) - regchr[regnum]=(regchr[regnum]&0x0F)|(V<<4); - else - regchr[regnum]=(regchr[regnum]&0xFF0)|(V&0xF); - VROM_BANK1(regnum<<10,regchr[regnum]); - } - switch(A) - { - case 0x8000: if(regchr[8]&2) - ROM_BANK8(0xc000,V); - else - ROM_BANK8(0x8000,V); - break; - case 0xA000: ROM_BANK8(0xa000,V); break; - case 0x9000: - 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; - } - case 0x9002: regchr[8]=V; break; - case 0xF000: //X6502_IRQEnd(FCEU_IQEXT); - IRQLatch=(IRQLatch&0xF0)|(V&0x0F); - break; - case 0xF001: //X6502_IRQEnd(FCEU_IQEXT); - IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4); - break; - case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1); - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xF002: IRQa=V&3; - if(IRQa&0x02) IRQCount=IRQLatch; - X6502_IRQEnd(FCEU_IQEXT); - break; - } -// if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline); -} - -static void Mapper27_hb(void) -{ -// FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch); - if(IRQa&0x2){ - if(IRQCount==0xFF){ - X6502_IRQBegin(FCEU_IQEXT); - IRQCount=IRQLatch+1; - } else { - IRQCount++; - } - } -} - -void Mapper27_init(void) -{ - int i; - for (i=0; i<9; i++) { - regchr[i]=0; - } - IRQa=0; - IRQCount=IRQLatch=0; - SetWriteHandler(0x8000,0xffff,Mapper27_write); - GameHBIRQHook=Mapper27_hb; -} - +#include "mapinc.h" + +static uint32 regchr[9]; + +static DECLFW(Mapper27_write) +{ + int regnum; + A&=0xF00F; + if((A>=0xB000) && (A<=0xE003)) { + regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); + if(A&1) + regchr[regnum]=(regchr[regnum]&0x00F)|(V<<4); + else + regchr[regnum]=(regchr[regnum]&0x1F0)|(V&0xF); + VROM_BANK1(regnum<<10,regchr[regnum]); + } + switch(A) + { + case 0x8000: ROM_BANK8(0x8000|((regchr[8]&2)<<13),V); break; + case 0xA000: ROM_BANK8(0xa000,V); break; + case 0x9000: 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; + } + case 0x9002: regchr[8]=V; break; + case 0xF000: //X6502_IRQEnd(FCEU_IQEXT); + IRQLatch=(IRQLatch&0xF0)|(V&0x0F); + break; + case 0xF001: //X6502_IRQEnd(FCEU_IQEXT); + IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4); + break; + case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1); + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF002: IRQa=V&3; + if(IRQa&0x02) IRQCount=IRQLatch-1; +// X6502_IRQEnd(FCEU_IQEXT); + break; + } +// if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline); +} + +static void Mapper27_hb(void) +{ +// FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch); + if(IRQa&0x2){ + if(IRQCount==0xFF){ + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch+1; + } else { + IRQCount++; + } + } +} + +void Mapper27_init(void) +{ + int i; + for (i=0; i<9; i++) { + regchr[i]=0; + } + IRQa=0; + IRQCount=IRQLatch=0; + SetWriteHandler(0x8000,0xffff,Mapper27_write); + GameHBIRQHook=Mapper27_hb; +} + diff --git a/mappers/32.c b/mappers/32.c index 13e4bba..b538947 100644 --- a/mappers/32.c +++ b/mappers/32.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/33.c b/mappers/33.c index f3362c0..1324663 100644 --- a/mappers/33.c +++ b/mappers/33.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -37,6 +37,7 @@ static DECLFW(Mapper33_write) case 0x8001:ROM_BANK8(0xA000,V); break; case 0x8002:VROM_BANK2(0x0000,V);break; case 0x8003:VROM_BANK2(0x0800,V);break; + case 0xe000:MIRROR_SET((V>>6)&1);break; } } @@ -73,7 +74,7 @@ void Mapper33_init(void) void Mapper48_init(void) { - SetWriteHandler(0x8000,0xffff,Mapper33_write); + SetWriteHandler(0x8000,0xbfff,Mapper33_write); SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite); GameHBIRQHook=heho; is48=1; diff --git a/mappers/40.c b/mappers/40.c index 471a7cc..9cdc24c 100644 --- a/mappers/40.c +++ b/mappers/40.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -31,7 +31,7 @@ static DECLFW(Mapper40_write) } } -static void FP_FASTAPASS(1) Mapper40IRQ(int a) +static void Mapper40IRQ(int a) { if(IRQa) { diff --git a/mappers/41.c b/mappers/41.c index dfb6908..84aed5d 100644 --- a/mappers/41.c +++ b/mappers/41.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/42.c b/mappers/42.c index bf31ac2..10774bd 100644 --- a/mappers/42.c +++ b/mappers/42.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -33,7 +33,7 @@ static DECLFW(Mapper42_write) } } -static void FP_FASTAPASS(1) Mapper42IRQ(int a) +static void Mapper42IRQ(int a) { if(IRQa) { diff --git a/mappers/43.c b/mappers/43.c deleted file mode 100644 index ef7d40d..0000000 --- a/mappers/43.c +++ /dev/null @@ -1,76 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - - - -static DECLFW(Mapper43_write) -{ - //printf("$%04x:$%02x\n",A,V); - if((A&0x8122)==0x8122) - { - X6502_IRQEnd(FCEU_IQEXT); - if(V&2) IRQa=1; - else - IRQCount=IRQa=0; - } -} - -static DECLFW(M43Low) -{ -// int transo[8]={4,3,4,4,4,7,5,6}; - int transo[8]={4,3,2,3,4,7,5,6}; - A&=0xF0FF; - if(A==0x4022) - setprg8(0x6000,transo[V&7]); - //printf("$%04x:$%02x\n",A,V); -} - -static void FP_FASTAPASS(1) M43Ho(int a) -{ - IRQCount+=a; - if(IRQa) - if(IRQCount>=4096) - { - X6502_IRQBegin(FCEU_IQEXT); - } -} - -//static DECLFR(boo) -//{ -// printf("$%04x\n",A); -// return( ROM[0x2000*8 +0x1000 +(A-0x5000)]); -//} - -void Mapper43_init(void) -{ - setprg4(0x5000,16); - setprg8(0x6000,2); - setprg8(0x8000,1); - setprg8(0xa000,0); - setprg8(0xc000,4); - setprg8(0xe000,9); - SetWriteHandler(0x8000,0xffff,Mapper43_write); - SetWriteHandler(0x4020,0x7fff,M43Low); - //SetReadHandler(0x5000,0x5fff,boo); - SetReadHandler(0x6000,0xffff,CartBR); - MapIRQHook=M43Ho; -} diff --git a/mappers/46.c b/mappers/46.c index 8c4ef6d..7e1a907 100644 --- a/mappers/46.c +++ b/mappers/46.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/50.c b/mappers/50.c index 8d7f515..629d86d 100644 --- a/mappers/50.c +++ b/mappers/50.c @@ -15,13 +15,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -static void FP_FASTAPASS(1) Mapper50IRQ(int a) +static void Mapper50IRQ(int a) { if(IRQa) { diff --git a/mappers/51.c b/mappers/51.c index cc1fbbd..c2c723e 100644 --- a/mappers/51.c +++ b/mappers/51.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/59.c b/mappers/59.c index 30ddb8b..4dd9e95 100644 --- a/mappers/59.c +++ b/mappers/59.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/6.c b/mappers/6.c index c6c5bf5..35fd900 100644 --- a/mappers/6.c +++ b/mappers/6.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -24,7 +24,7 @@ static uint8 FFEmode; #define FVRAM_BANK8(A,V) {VPage[0]=VPage[1]=VPage[2]=VPage[3]=VPage[4]=VPage[5]=VPage[6]=VPage[7]=V?&MapperExRAM[(V)<<13]-(A):&CHRRAM[(V)<<13]-(A);CHRBankList[0]=((V)<<3);CHRBankList[1]=((V)<<3)+1;CHRBankList[2]=((V)<<3)+2;CHRBankList[3]=((V)<<3)+3;CHRBankList[4]=((V)<<3)+4;CHRBankList[5]=((V)<<3)+5;CHRBankList[6]=((V)<<3)+6;CHRBankList[7]=((V)<<3)+7;PPUCHRRAM=0xFF;} -static void FP_FASTAPASS(1) FFEIRQHook(int a) +static void FFEIRQHook(int a) { if(IRQa) { diff --git a/mappers/60.c b/mappers/60.c index b48087c..a2b2ee1 100644 --- a/mappers/60.c +++ b/mappers/60.c @@ -15,9 +15,9 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ - +/* #include "mapinc.h" static DECLFW(Mapper60_write) @@ -37,5 +37,5 @@ void Mapper60_init(void) ROM_BANK32(0); SetWriteHandler(0x8000,0xffff, Mapper60_write); } - +*/ diff --git a/mappers/61.c b/mappers/61.c index 4303932..10b9e6d 100644 --- a/mappers/61.c +++ b/mappers/61.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/62.c b/mappers/62.c index 4d03c88..6da991c 100644 --- a/mappers/62.c +++ b/mappers/62.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/65.c b/mappers/65.c index d817694..1a8cb8b 100644 --- a/mappers/65.c +++ b/mappers/65.c @@ -15,13 +15,13 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" -void FP_FASTAPASS(1) IREMIRQHook(int a) +void IREMIRQHook(int a) { if(IRQa) { diff --git a/mappers/67.c b/mappers/67.c index 9d560f9..ee2390a 100644 --- a/mappers/67.c +++ b/mappers/67.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -58,7 +58,7 @@ static DECLFW(Mapper67_write) case 0xf800:ROM_BANK16(0x8000,V);break; } } -static void FP_FASTAPASS(1) SunIRQHook(int a) +static void SunIRQHook(int a) { if(IRQa) { diff --git a/mappers/68.c b/mappers/68.c deleted file mode 100644 index 69eaefc..0000000 --- a/mappers/68.c +++ /dev/null @@ -1,105 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static void Fixerit(void) -{ - switch(mapbyte2[0]&3) - { - case 0:vnapage[0]=vnapage[2]=CHRptr[0]+(((mapbyte1[0]|128)&CHRmask1[0])<<10); - vnapage[1]=vnapage[3]=CHRptr[0]+(((mapbyte1[1]|128)&CHRmask1[0])<<10); - break; - case 1:vnapage[0]=vnapage[1]=CHRptr[0]+(((mapbyte1[0]|128)&CHRmask1[0])<<10); - vnapage[2]=vnapage[3]=CHRptr[0]+(((mapbyte1[1]|128)&CHRmask1[0])<<10); - break; - case 2:vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((mapbyte1[0]|128)&CHRmask1[0])<<10); - break; - case 3:vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((mapbyte1[1]|128)&CHRmask1[0])<<10); - break; - } -} - -DECLFW(Mapper68_write) -{ -// FCEU_printf("%04x,%04x\n",A,V); - A&=0xF000; - - if(A>=0x8000 && A<=0xB000) - { - VROM_BANK2((A-0x8000)>>1,V); - } - else switch(A) - { - case 0xc000:mapbyte1[0]=V; - if(VROM_size && mapbyte2[0]&0x10) - Fixerit(); - break; - - case 0xd000:mapbyte1[1]=V; - if(VROM_size && mapbyte2[0]&0x10) - Fixerit(); - break; - - case 0xe000: mapbyte2[0]=V; - if(!(V&0x10)) - { - switch(V&3) - { - case 0:MIRROR_SET2(1);break; - case 1:MIRROR_SET2(0);break; - case 2:onemir(0);break; - case 3:onemir(1);break; - } - } - else if(VROM_size) - { - Fixerit(); - PPUNTARAM=0; - } - break; - case 0xf000: ROM_BANK16(0x8000,V);break; - } -} - -static void Mapper68_StateRestore(int version) -{ - if(!(mapbyte2[0]&0x10)) - { - switch(mapbyte2[0]&3) - { - case 0:MIRROR_SET(0);break; - case 1:MIRROR_SET(1);break; - case 2:onemir(0);break; - case 3:onemir(1);break; - } - } - else if(VROM_size) - { - Fixerit(); - PPUNTARAM=0; - } -} - -void Mapper68_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper68_write); - MapStateRestore=Mapper68_StateRestore; -} diff --git a/mappers/69.c b/mappers/69.c index 948c304..5d15243 100644 --- a/mappers/69.c +++ b/mappers/69.c @@ -15,15 +15,15 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" static void AYSound(int Count); -//static void AYSoundHQ(void); +static void AYSoundHQ(void); static void DoAYSQ(int x); -//static void DoAYSQHQ(int x); +static void DoAYSQHQ(int x); #define sunselect mapbyte1[0] #define sungah mapbyte1[1] @@ -39,7 +39,7 @@ static DECLFR(SUN5AWRAM) { if((sungah&0xC0)==0x40) return X.DB; - return CartBR(A); + return CartBROB(A); } static DECLFW(Mapper69_SWL) @@ -51,22 +51,22 @@ static DECLFW(Mapper69_SWH) { int x; GameExpSound.Fill=AYSound; - GameExpSound.HiFill=0;//AYSoundHQ; - if(FSettings.SndRate); + GameExpSound.HiFill=AYSoundHQ; + if(FSettings.SndRate) switch(sunindex) { case 0: case 1: - case 8:/*if(FSettings.soundq>=1) DoAYSQHQ(0); else*/ DoAYSQ(0);break; + 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 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 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); + if(FSettings.soundq>=1) DoAYSQHQ(x); else DoAYSQ(x); break; } MapperExRAM[sunindex]=V; @@ -133,7 +133,6 @@ static void DoAYSQ(int x) CAYBC[x]=end; if(amp) - if(!(MapperExRAM[0x7]&(1<=1) return; + if(FSettings.soundq>=1) return; z=((SOUNDTS<<16)/soundtsinc)>>4; a=z-dwave; - moocow(VRC7Sound, (int32 *)&Wave[dwave], a, 1); + moocow(VRC7Sound, &Wave[dwave], a, 1); dwave+=a; } @@ -56,7 +56,7 @@ void UpdateOPL(int Count) a=z-dwave; if(VRC7Sound && a) - moocow(VRC7Sound, (int32 *)&Wave[dwave], a, 1); + moocow(VRC7Sound, &Wave[dwave], a, 1); dwave=0; } @@ -113,7 +113,7 @@ DECLFW(Mapper85_write) } } -static void FP_FASTAPASS(1) KonamiIRQHook(int a) +static void KonamiIRQHook(int a) { #define ACBOO 341 // #define ACBOO ((227*2)+1) diff --git a/mappers/86.c b/mappers/86.c index 8404985..f95b639 100644 --- a/mappers/86.c +++ b/mappers/86.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/89.c b/mappers/89.c index a3a6f09..e742735 100644 --- a/mappers/89.c +++ b/mappers/89.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/91.c b/mappers/91.c index 8858103..6dc7fc9 100644 --- a/mappers/91.c +++ b/mappers/91.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/92.c b/mappers/92.c index e2ad374..1230836 100644 --- a/mappers/92.c +++ b/mappers/92.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/97.c b/mappers/97.c index 2990c0e..f0e7beb 100644 --- a/mappers/97.c +++ b/mappers/97.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/99.c b/mappers/99.c index 7a55536..6f3081f 100644 --- a/mappers/99.c +++ b/mappers/99.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" diff --git a/mappers/Makefile b/mappers/Makefile index 4bee951..242915a 100644 --- a/mappers/Makefile +++ b/mappers/Makefile @@ -1,62 +1,51 @@ -MM_C += mappers/113.c -MM_C += mappers/15.c MM_C += mappers/151.c MM_C += mappers/16.c MM_C += mappers/17.c MM_C += mappers/18.c -MM_C += mappers/180.c -MM_C += mappers/183.c -MM_C += mappers/184.c MM_C += mappers/193.c -MM_C += mappers/200.c MM_C += mappers/201.c MM_C += mappers/202.c MM_C += mappers/203.c MM_C += mappers/204.c -MM_C += mappers/21.c MM_C += mappers/212.c MM_C += mappers/213.c MM_C += mappers/214.c MM_C += mappers/215.c MM_C += mappers/217.c -MM_C += mappers/22.c +MM_C += mappers/21.c MM_C += mappers/225.c -MM_C += mappers/226.c MM_C += mappers/227.c MM_C += mappers/228.c MM_C += mappers/229.c -MM_C += mappers/23.c +MM_C += mappers/22.c MM_C += mappers/230.c MM_C += mappers/231.c MM_C += mappers/232.c MM_C += mappers/234.c -MM_C += mappers/240.c MM_C += mappers/241.c MM_C += mappers/242.c MM_C += mappers/244.c MM_C += mappers/246.c MM_C += mappers/24and26.c -MM_C += mappers/25.c MM_C += mappers/255.c +MM_C += mappers/25.c MM_C += mappers/27.c MM_C += mappers/32.c MM_C += mappers/33.c MM_C += mappers/40.c MM_C += mappers/41.c MM_C += mappers/42.c -MM_C += mappers/43.c MM_C += mappers/46.c MM_C += mappers/50.c MM_C += mappers/51.c MM_C += mappers/59.c -MM_C += mappers/6.c MM_C += mappers/60.c MM_C += mappers/61.c MM_C += mappers/62.c MM_C += mappers/65.c MM_C += mappers/67.c -MM_C += mappers/68.c MM_C += mappers/69.c +MM_C += mappers/6.c MM_C += mappers/71.c MM_C += mappers/72.c MM_C += mappers/73.c @@ -64,13 +53,13 @@ MM_C += mappers/75.c MM_C += mappers/76.c MM_C += mappers/77.c MM_C += mappers/79.c -MM_C += mappers/8.c MM_C += mappers/80.c MM_C += mappers/82.c MM_C += mappers/83.c MM_C += mappers/85.c MM_C += mappers/86.c MM_C += mappers/89.c +MM_C += mappers/8.c MM_C += mappers/91.c MM_C += mappers/92.c MM_C += mappers/97.c @@ -78,6 +67,7 @@ MM_C += mappers/99.c MM_C += mappers/emu2413.c MM_C += mappers/mmc2and4.c MM_C += mappers/simple.c +MM_C += mappers/156.c MOBJS += $(patsubst %.c,%.o,$(MM_C)) diff --git a/mappers/mmc2and4.c b/mappers/mmc2and4.c index 022d736..d34cc6b 100644 --- a/mappers/mmc2and4.c +++ b/mappers/mmc2and4.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -25,7 +25,7 @@ #define latcha2 mapbyte2[1] -static void FP_FASTAPASS(1) latchcheck(uint32 VAddr) +static void latchcheck(uint32 VAddr) { uint8 l,h; diff --git a/mappers/simple.c b/mappers/simple.c index c393d09..8310fbb 100644 --- a/mappers/simple.c +++ b/mappers/simple.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mapinc.h" @@ -55,7 +55,7 @@ static DECLFW(Mapper96_write) setchr4r(0x10,0x1000,(latche&4)|3); } -static void FP_FASTAPASS(1) M96Hook(uint32 A) +static void M96Hook(uint32 A) { if((A&0x3000)!=0x2000) return; //if((A&0x3ff)>=0x3c0) return; @@ -83,18 +83,6 @@ void Mapper96_init(void) GameStateRestore=M96Sync; } -static DECLFW(M156Write) -{ - if(A>=0xc000 && A<=0xC003) - VROM_BANK1((A&3)*1024,V); - else if(A>=0xc008 && A<=0xc00b) - VROM_BANK1(0x1000+(A&3)*1024,V); - if(A==0xc010) ROM_BANK16(0x8000,V); -// printf("$%04x:$%02x\n",A,V); -} - -void Mapper156_init(void) -{ - onemir(0); - SetWriteHandler(0xc000,0xc010,M156Write); -} +// DIS23C01 Open Soft, Korea +// Metal Force (K) +// Buzz and Waldog (K) diff --git a/svga.h b/svga.h index b18787d..6f78d69 100644 --- a/svga.h +++ b/svga.h @@ -41,6 +41,7 @@ typedef struct { int UsrLastSLine[2]; int SnapName; unsigned int SndRate; + int soundq; } FCEUS; extern FCEUS FSettings; diff --git a/types.h b/types.h index 485b019..76eb7ed 100644 --- a/types.h +++ b/types.h @@ -35,6 +35,10 @@ typedef uint32_t uint32; //typedef unsigned short uint16; //typedef unsigned long uint32; +#ifndef __cplusplus +#define bool int +#endif + #ifdef __GNUC__ typedef unsigned long long uint64; typedef long long int64; diff --git a/unif.c b/unif.c index 03430f5..6354131 100644 --- a/unif.c +++ b/unif.c @@ -1,22 +1,22 @@ /* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +* +* 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 +*/ /* TODO: Battery backup file saving, mirror force */ /* **INCOMPLETE** */ @@ -27,43 +27,42 @@ #include -#include "types.h" -#include "fce.h" -#include "cart.h" -#include "unif.h" -#include "ines.h" -#include "general.h" -#include "state.h" -#include "endian.h" -#include "file.h" -#include "memory.h" -#include "input.h" -#include "md5.h" - -#include "svga.h" +#include "types.h" +#include "fce.h" +#include "cart.h" +#include "unif.h" +#include "ines.h" +#include "endian.h" +#include "memory.h" +#include "md5.h" +#include "state.h" +#include "file.h" +#include "input.h" +#include "driver.h" +#include "svga.h" typedef struct { - char ID[4]; - uint32 info; + char ID[4]; + uint32 info; } UNIF_HEADER; typedef struct { - char *name; - void (*init)(CartInfo *); - int flags; + char *name; + void (*init)(CartInfo *); + int flags; } BMAPPING; typedef struct { - char *name; - int (*init)(int fp); + char *name; + int (*init)(int fp); } BFMAPPING; static CartInfo UNIFCart; static int vramo; static int mirrortodo; -static char *boardname; -static char *sboardname; +static uint8 *boardname; +static uint8 *sboardname; static uint32 CHRRAMSize; uint8 *UNIFchrrama=0; @@ -77,502 +76,544 @@ static uint32 mallocedsizes[32]; static int FixRomSize(uint32 size, uint32 minimum) { - int x=1; + uint32 x=1; //mbg merge 7/17/06 made uint - if(size0) - if(index<99) - namebuf[index++]=t; - - namebuf[index]=0; - FCEU_printf("%s\n",namebuf); - - if(!FCEUGameInfo.name) - { - FCEUGameInfo.name=malloc(strlen(namebuf)+1); - strcpy((char *)FCEUGameInfo.name,namebuf); - } - return(1); + char namebuf[100]; + int index; + int t; + + FCEU_printf(" Name: "); + index=0; + + while((t=FCEU_fgetc(fp))>0) + if(index<99) + namebuf[index++]=t; + + namebuf[index]=0; + FCEU_printf("%s\n",namebuf); + + if(!GameInfo->name) + { + GameInfo->name=(uint8*)malloc(strlen(namebuf)+1); //mbg merge 7/17/06 added cast + strcpy((char*)GameInfo->name,namebuf); //mbg merge 7/17/06 added cast + } + return(1); } static int DINF(int fp) { - char name[100], method[100]; - uint8 d, m; - uint16 y; - int t; - - if(FCEU_fread(name,1,100,fp)!=100) - return(0); - if((t=FCEU_fgetc(fp))==EOF) return(0); - d=t; - if((t=FCEU_fgetc(fp))==EOF) return(0); - m=t; - if((t=FCEU_fgetc(fp))==EOF) return(0); - y=t; - if((t=FCEU_fgetc(fp))==EOF) return(0); - y|=t<<8; - if(FCEU_fread(method,1,100,fp)!=100) - return(0); - name[99]=method[99]=0; - FCEU_printf(" Dumped by: %s\n",name); - FCEU_printf(" Dumped with: %s\n",method); - { - char *months[12]={"January","February","March","April","May","June","July", - "August","September","October","November","December"}; - FCEU_printf(" Dumped on: %s %d, %d\n",months[(m-1)%12],d,y); - } - return(1); + char name[100], method[100]; + uint8 d, m; + uint16 y; + int t; + + if(FCEU_fread(name,1,100,fp)!=100) + return(0); + if((t=FCEU_fgetc(fp))==EOF) return(0); + d=t; + if((t=FCEU_fgetc(fp))==EOF) return(0); + m=t; + if((t=FCEU_fgetc(fp))==EOF) return(0); + y=t; + if((t=FCEU_fgetc(fp))==EOF) return(0); + y|=t<<8; + if(FCEU_fread(method,1,100,fp)!=100) + return(0); + name[99]=method[99]=0; + FCEU_printf(" Dumped by: %s\n",name); + FCEU_printf(" Dumped with: %s\n",method); + { + char *months[12]={"January","February","March","April","May","June","July", + "August","September","October","November","December"}; + FCEU_printf(" Dumped on: %s %d, %d\n",months[(m-1)%12],d,y); + } + return(1); } static int CTRL(int fp) { - int t; + int t; - if((t=FCEU_fgetc(fp))==EOF) - return(0); - /* The information stored in this byte isn't very helpful, but it's - better than nothing...maybe. - */ + if((t=FCEU_fgetc(fp))==EOF) + return(0); + /* The information stored in this byte isn't very helpful, but it's + better than nothing...maybe. + */ - if(t&1) FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD; - else FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_NONE; + if(t&1) GameInfo->input[0]=GameInfo->input[1]=SI_GAMEPAD; + else GameInfo->input[0]=GameInfo->input[1]=SI_NONE; - if(t&2) FCEUGameInfo.input[1]=SI_ZAPPER; - //else if(t&0x10) FCEUGameInfo->input[1]=SI_POWERPAD; + if(t&2) GameInfo->input[1]=SI_ZAPPER; + //else if(t&0x10) GameInfo->input[1]=SI_POWERPAD; - return(1); + return(1); } static int TVCI(int fp) { - int t; - if( (t=FCEU_fgetc(fp)) ==EOF) - return(0); - if(t<=2) - { - char *stuffo[3]={"NTSC","PAL","NTSC and PAL"}; - if(t==0) - { - FCEUGameInfo.vidsys=GIV_NTSC; - FCEUI_SetVidSystem(0); - } - else if(t==1) - { - FCEUGameInfo.vidsys=GIV_PAL; - FCEUI_SetVidSystem(1); - } - FCEU_printf(" TV Standard Compatibility: %s\n",stuffo[t]); - } - return(1); + int t; + if( (t=FCEU_fgetc(fp)) ==EOF) + return(0); + if(t<=2) + { + char *stuffo[3]={"NTSC","PAL","NTSC and PAL"}; + if(t==0) + { + GameInfo->vidsys=GIV_NTSC; + FCEUI_SetVidSystem(0); + } + else if(t==1) + { + GameInfo->vidsys=GIV_PAL; + FCEUI_SetVidSystem(1); + } + FCEU_printf(" TV Standard Compatibility: %s\n",stuffo[t]); + } + return(1); } static int EnableBattery(int fp) { - FCEU_printf(" Battery-backed.\n"); - if(FCEU_fgetc(fp)==EOF) - return(0); - UNIFCart.battery=1; - return(1); + FCEU_printf(" Battery-backed.\n"); + if(FCEU_fgetc(fp)==EOF) + return(0); + UNIFCart.battery=1; + return(1); } static int LoadPRG(int fp) { - int z,t; - z=uchead.ID[3]-'0'; - - if(z<0 || z>15) - return(0); - FCEU_printf(" PRG ROM %d size: %d",z,(int) uchead.info); - if(malloced[z]) - free(malloced[z]); - t=FixRomSize(uchead.info,2048); - if(!(malloced[z]=(uint8 *)FCEU_malloc(t))) - return(0); - mallocedsizes[z]=t; - memset(malloced[z]+uchead.info,0xFF,t-uchead.info); - if(FCEU_fread(malloced[z],1,uchead.info,fp)!=uchead.info) - { - FCEU_printf("Read Error!\n"); - return(0); - } - else - FCEU_printf("\n"); - - SetupCartPRGMapping(z,malloced[z],t,0); - return(1); + int z,t; + z=uchead.ID[3]-'0'; + + if(z<0 || z>15) + return(0); + FCEU_printf(" PRG ROM %d size: %d",z,(int) uchead.info); + if(malloced[z]) + free(malloced[z]); + t=FixRomSize(uchead.info,2048); + if(!(malloced[z]=(uint8 *)FCEU_malloc(t))) + return(0); + mallocedsizes[z]=t; + memset(malloced[z]+uchead.info,0xFF,t-uchead.info); + if(FCEU_fread(malloced[z],1,uchead.info,fp)!=uchead.info) + { + FCEU_printf("Read Error!\n"); + return(0); + } + else + FCEU_printf("\n"); + + SetupCartPRGMapping(z,malloced[z],t,0); + return(1); } static int SetBoardName(int fp) { - if(!(boardname=FCEU_malloc(uchead.info+1))) - return(0); - FCEU_fread(boardname,1,uchead.info,fp); - boardname[uchead.info]=0; - FCEU_printf(" Board name: %s\n",boardname); - sboardname=boardname; - if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4)) - sboardname+=4; - return(1); + if(!(boardname=(uint8 *)FCEU_malloc(uchead.info+1))) + return(0); + FCEU_fread(boardname,1,uchead.info,fp); + boardname[uchead.info]=0; + FCEU_printf(" Board name: %s\n",boardname); + sboardname=boardname; + if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4)) + sboardname+=4; + return(1); } static int LoadCHR(int fp) { - int z,t; - z=uchead.ID[3]-'0'; - if(z<0 || z>15) - return(0); - FCEU_printf(" CHR ROM %d size: %d",z,(int) uchead.info); - if(malloced[16+z]) - free(malloced[16+z]); - t=FixRomSize(uchead.info,8192); - if(!(malloced[16+z]=(uint8 *)FCEU_malloc(t))) - return(0); - mallocedsizes[16+z]=t; - memset(malloced[16+z]+uchead.info,0xFF,t-uchead.info); - if(FCEU_fread(malloced[16+z],1,uchead.info,fp)!=uchead.info) - { - FCEU_printf("Read Error!\n"); - return(0); - } - else - FCEU_printf("\n"); - - SetupCartCHRMapping(z,malloced[16+z],t,0); - return(1); + int z,t; + z=uchead.ID[3]-'0'; + if(z<0 || z>15) + return(0); + FCEU_printf(" CHR ROM %d size: %d",z,(int) uchead.info); + if(malloced[16+z]) + free(malloced[16+z]); + t=FixRomSize(uchead.info,8192); + if(!(malloced[16+z]=(uint8 *)FCEU_malloc(t))) + return(0); + mallocedsizes[16+z]=t; + memset(malloced[16+z]+uchead.info,0xFF,t-uchead.info); + if(FCEU_fread(malloced[16+z],1,uchead.info,fp)!=uchead.info) + { + FCEU_printf("Read Error!\n"); + return(0); + } + else + FCEU_printf("\n"); + + SetupCartCHRMapping(z,malloced[16+z],t,0); + return(1); } #define BMCFLAG_FORCE4 1 #define BMCFLAG_16KCHRR 2 #define BMCFLAG_32KCHRR 4 +#define BMCFLAG_EXPCHRR 8 static BMAPPING bmap[] = { -/* Sachen Carts */ - { "TC-U01-1.5M", TCU01_Init,0}, - { "Sachen-8259A", S8259A_Init,0}, - { "Sachen-8259B", S8259B_Init,0}, - { "Sachen-8259C", S8259C_Init,0}, - { "Sachen-8259D", S8259D_Init,0}, - { "Sachen-74LS374N", S74LS374N_Init,0}, - { "Sachen-74LS374NA", S74LS374NA_Init,0}, //seems to be custom mapper - { "SA-016-1M", SA0161M_Init,0}, - { "SA-72007", SA72007_Init,0}, - { "SA-72008", SA72008_Init,0}, - { "SA-0036", SA0036_Init,0}, - { "SA-0037", SA0037_Init,0}, - { "SA-NROM", TCA01_Init,0}, - -// /* AVE carts. */ -// { "MB-91", MB91_Init,0}, // DeathBots -// { "NINA-06", NINA06_Init,0}, // F-15 City War -// { "NINA-03", NINA03_Init,0}, // Tiles of Fate -// { "NINA-001", NINA001_Init,0}, // Impossible Mission 2 - - { "ANROM", ANROM_Init,0}, - - { "HKROM", HKROM_Init,0}, - - { "EWROM", EWROM_Init,0}, - { "EKROM", EKROM_Init,0}, - { "ELROM", ELROM_Init,0}, - { "ETROM", ETROM_Init,0}, - - { "SAROM", SAROM_Init,0}, - { "SBROM", SBROM_Init,0}, - { "SCROM", SCROM_Init,0}, - { "SEROM", SEROM_Init,0}, - { "SGROM", SGROM_Init,0}, - { "SKROM", SKROM_Init,0}, - { "SLROM", SLROM_Init,0}, - { "SL1ROM", SL1ROM_Init,0}, - { "SNROM", SNROM_Init,0}, - { "SOROM", SOROM_Init,0}, - - { "TGROM", TGROM_Init,0}, - { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4}, - - { "TEROM", TEROM_Init,0}, - { "TFROM", TFROM_Init,0}, - { "TLROM", TLROM_Init,0}, - { "TKROM", TKROM_Init,0}, - { "TSROM", TSROM_Init,0}, - - { "TLSROM", TLSROM_Init,0}, - { "TKSROM", TKSROM_Init,0}, - { "TQROM", TQROM_Init,0}, - { "TVROM", TLROM_Init,BMCFLAG_FORCE4}, - - { "CPROM", CPROM_Init,BMCFLAG_16KCHRR}, - { "CNROM", CNROM_Init,0}, - { "NROM", NROM_Init,0 }, //NROM256_Init,0 }, - { "NROM-128", NROM_Init,0 }, //NROM128_Init,0 }, - { "NROM-256", NROM_Init,0 }, //NROM256_Init,0 }, - { "RROM", NROM_Init,0 }, //NROM128_Init,0 }, - { "RROM-128", NROM_Init,0 }, //NROM128_Init,0 }, - { "MHROM", MHROM_Init,0}, - { "UNROM", UNROM_Init,0}, - { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0}, - { "MARIO1-MALEE2", MALEE_Init,0}, - - { "CC-21", UNLCC21_Init,0}, - - { "H2288", UNLH2288_Init,0}, - { "KOF97", UNLKOF97_Init,0}, - { "SL1632", UNLSL1632_Init,0}, - { "SHERO", UNLSHeroes_Init,0}, - { "8237", UNL8237_Init,0}, - { "8157", UNL8157_Init,0}, - { "T-262", BMCT262_Init,0}, - { "FK23C", BMCFK23C_Init,0}, - { "Supervision16in1", Supervision16_Init,0}, - { "NovelDiamond9999999in1", Novel_Init,0}, - { "Super24in1SC03", Super24_Init,0}, - { "42in1ResetSwitch", BMC42in1r_Init, 0}, - { "64in1NoRepeat", BMC64in1nr_Init, 0}, - { "13in1JY110", BMC13in1JY110_Init, 0}, - { "70in1", BMC70in1_Init, 0}, - { "70in1B", BMC70in1B_Init, 0}, - { "GK-192", Mapper58_Init, 0}, - { "SuperHIK8in1", Mapper45_Init,0}, - - { "DREAMTECH01", DreamTech01_Init,0}, - { "KONAMI-QTAI", Mapper190_Init,0}, - - { "TEK90", Mapper90_Init,0}, - - {0,0,0} + /* Sachen Carts */ + { "TC-U01-1.5M", TCU01_Init,0}, + { "Sachen-8259A", S8259A_Init,0}, + { "Sachen-8259B", S8259B_Init,0}, + { "Sachen-8259C", S8259C_Init,0}, + { "Sachen-8259D", S8259D_Init,0}, + { "Sachen-74LS374N", S74LS374N_Init,0}, + { "Sachen-74LS374NA", S74LS374NA_Init,0}, //seems to be custom mapper + { "SA-002", TCU02_Init, 0}, + { "SA-016-1M", SA0161M_Init,0}, + { "SA-72007", SA72007_Init,0}, + { "SA-72008", SA72008_Init,0}, + { "SA-009", SA009_Init,0}, + { "SA-0036", SA0036_Init,0}, + { "SA-0037", SA0037_Init,0}, + { "SA-NROM", TCA01_Init,0}, + + // /* AVE carts. */ + // { "MB-91", MB91_Init,0}, // DeathBots + // { "NINA-06", NINA06_Init,0}, // F-15 City War + // { "NINA-03", NINA03_Init,0}, // Tiles of Fate + // { "NINA-001", NINA001_Init,0}, // Impossible Mission 2 + + { "ANROM", ANROM_Init,0}, + + { "HKROM", HKROM_Init,0}, + + { "EWROM", EWROM_Init,0}, + { "EKROM", EKROM_Init,0}, + { "ELROM", ELROM_Init,0}, + { "ETROM", ETROM_Init,0}, + + { "SAROM", SAROM_Init,0}, + { "SBROM", SBROM_Init,0}, + { "SCROM", SCROM_Init,0}, + { "SEROM", SEROM_Init,0}, + { "SGROM", SGROM_Init,0}, + { "SKROM", SKROM_Init,0}, + { "SLROM", SLROM_Init,0}, + { "SL1ROM", SL1ROM_Init,0}, + { "SNROM", SNROM_Init,0}, + { "SOROM", SOROM_Init,0}, + + { "TGROM", TGROM_Init,0}, + { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4}, + + { "TBROM", TBROM_Init,0}, + { "TEROM", TEROM_Init,0}, + { "TFROM", TFROM_Init,0}, + { "TLROM", TLROM_Init,0}, + { "TKROM", TKROM_Init,0}, + { "TSROM", TSROM_Init,0}, + + { "TLSROM", TLSROM_Init,0}, + { "TKSROM", TKSROM_Init,0}, + { "TQROM", TQROM_Init,0}, + { "TVROM", TLROM_Init,BMCFLAG_FORCE4}, + + { "NTBROM", Mapper68_Init,0}, + + { "CPROM", CPROM_Init,BMCFLAG_16KCHRR}, + { "CNROM", CNROM_Init,0}, + { "NROM", NROM_Init,0 }, //NROM256_Init,0 }, + { "NROM-128", NROM_Init,0 }, //NROM128_Init,0 }, + { "NROM-256", NROM_Init,0 }, //NROM256_Init,0 }, + { "RROM", NROM_Init,0 }, //NROM128_Init,0 }, + { "RROM-128", NROM_Init,0 }, //NROM128_Init,0 }, + { "MHROM", MHROM_Init,0}, + { "UNROM", UNROM_Init,0}, + { "UOROM", UNROM_Init,0}, + { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0}, + { "MARIO1-MALEE2", MALEE_Init,0}, + { "3D-BLOCK", UNL3DBlock_Init, 0}, + { "SMB2J", UNLSMB2J_Init, 0}, + { "AX5705", UNLAX5705_Init, 0}, + { "CC-21", UNLCC21_Init,0}, + { "H2288", UNLH2288_Init,0}, + { "KOF97", UNLKOF97_Init,0}, + { "SL1632", UNLSL1632_Init,0}, + { "SHERO", UNLSHeroes_Init,0}, + { "8237", UNL8237_Init,0}, + { "8237A", UNL8237A_Init,0}, + { "8157", UNL8157_Init,0}, + { "T-262", BMCT262_Init,0}, + { "FK23C", BMCFK23C_Init,0}, + { "A65AS", BMCA65AS_Init,0}, + { "C-N22M", UNLCN22M_Init,0}, + { "EDU2000", UNLEDU2000_Init,0}, + { "603-5052", UNL6035052_Init,0}, + { "N625092", UNLN625092_Init,0}, + { "Supervision16in1", Supervision16_Init,0}, + { "NovelDiamond9999999in1", Novel_Init,0}, + { "Super24in1SC03", Super24_Init,0}, + { "64in1NoRepeat", BMC64in1nr_Init, 0}, + { "13in1JY110", BMC13in1JY110_Init, 0}, + { "70in1", BMC70in1_Init, 0}, + { "70in1B", BMC70in1B_Init, 0}, + { "D1038", BMCD1038_Init, 0}, + { "GK-192", BMCGK192_Init, 0}, + { "SuperHIK8in1", Mapper45_Init,0}, + { "22211", UNL22211_Init,0}, + { "TF1201", UNLTF1201_Init, 0}, + { "GS-2004", BMCGS2004_Init, 0}, + { "GS-2013", BMCGS2013_Init, 0}, + { "KS7032", UNLKS7032_Init, 0}, + { "T-230", UNLT230_Init, 0}, + { "190in1", BMC190in1_Init, 0}, + { "Ghostbusters63in1", BMCGhostbusters63in1_Init, 0}, + { "BS-5",BMCBS5_Init, 0}, + { "411120-C",BMC411120C_Init, 0}, + { "830118C",BMC830118C_Init, 0}, + { "T-227-1",BMCT2271_Init,0}, + + { "DREAMTECH01", DreamTech01_Init,0}, + { "KONAMI-QTAI", Mapper190_Init,0}, + + { "DANCE", UNLDANCE_Init,0}, + { "OneBus", UNLOneBus_Init,0}, + { "SC-127", UNLSC127_Init,0}, + + { "TEK90", Mapper90_Init,0}, + + { "FK23C", BMCFK23C_Init,BMCFLAG_EXPCHRR}, + { "FK23CA", BMCFK23CA_Init,BMCFLAG_EXPCHRR}, + + {0,0,0} }; static BFMAPPING bfunc[] = { - { "CTRL", CTRL }, - { "TVCI", TVCI }, - { "BATR", EnableBattery }, - { "MIRR", DoMirroring }, - { "PRG", LoadPRG }, - { "CHR", LoadCHR }, - { "NAME", NAME }, - { "MAPR", SetBoardName }, - { "DINF", DINF }, - { 0, 0 } + { "CTRL", CTRL }, + { "TVCI", TVCI }, + { "BATR", EnableBattery }, + { "MIRR", DoMirroring }, + { "PRG", LoadPRG }, + { "CHR", LoadCHR }, + { "NAME", NAME }, + { "MAPR", SetBoardName }, + { "DINF", DINF }, + { 0, 0 } }; int LoadUNIFChunks(int fp) { - int x; - int t; - for(;;) - { - t=FCEU_fread(&uchead,1,4,fp); - if(t<4) - { - if(t>0) - return 0; - return 1; - } - if(!(FCEU_read32(&uchead.info,fp))) - return 0; - t=0; - x=0; - //printf("Funky: %s\n",((uint8 *)&uchead)); - while(bfunc[x].name) - { - if(!memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name))) - { - if(!bfunc[x].init(fp)) - return 0; - t=1; - break; - } - x++; - } - if(!t) - if(FCEU_fseek(fp,uchead.info,SEEK_CUR)) - return(0); - } + int x; + int t; + for(;;) + { + t=FCEU_fread(&uchead,1,4,fp); + if(t<4) + { + if(t>0) + return 0; + return 1; + } + if(!(FCEU_read32le(&uchead.info,fp))) + return 0; + t=0; + x=0; + //printf("Funky: %s\n",((uint8 *)&uchead)); + while(bfunc[x].name) + { + if(!memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name))) + { + if(!bfunc[x].init(fp)) + return 0; + t=1; + break; + } + x++; + } + if(!t) + if(FCEU_fseek(fp,uchead.info,SEEK_CUR)<0) + return(0); + } } static int InitializeBoard(void) { - int x=0; + int x=0; - if(!sboardname) return(0); + if(!sboardname) return(0); - while(bmap[x].name) - { - if(!strcmp(sboardname,(char *)bmap[x].name)) - { - if(!malloced[16]) - { + while(bmap[x].name) + { + if(!strcmp((char *)sboardname,(char *)bmap[x].name)) + { + if(!malloced[16]) + { if(bmap[x].flags & BMCFLAG_16KCHRR) CHRRAMSize = 16384; + else if(bmap[x].flags & BMCFLAG_32KCHRR) + CHRRAMSize = 32768; + else if(bmap[x].flags & BMCFLAG_EXPCHRR) + CHRRAMSize = 128 * 1024; else - CHRRAMSize = 8192; - if((UNIFchrrama=(uint8 *)FCEU_malloc(CHRRAMSize))) - { - SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1); - AddExState(UNIFchrrama, CHRRAMSize, 0,"CHRR"); - } - else - return(-1); - } - if(bmap[x].flags&BMCFLAG_FORCE4) - mirrortodo=4; - MooMirroring(); - bmap[x].init(&UNIFCart); - return(1); - } - x++; - } - FCEU_PrintError("Board type not supported."); - return(0); + CHRRAMSize = 8192; + if((UNIFchrrama=(uint8 *)FCEU_malloc(CHRRAMSize))) + { + SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1); + AddExState(UNIFchrrama, CHRRAMSize, 0,"CHRR"); + } + else + return(-1); + } + if(bmap[x].flags&BMCFLAG_FORCE4) + mirrortodo=4; + MooMirroring(); + bmap[x].init(&UNIFCart); + return(1); + } + x++; + } + FCEU_PrintError("Board type not supported."); + return(0); } static void UNIFGI(int h, void *param) { - switch(h) - { - case GI_RESETM2: - if(UNIFCart.Reset) - UNIFCart.Reset(); + switch(h) + { + case GI_RESETSAVE: + //FCEU_ClearGameSave(&UNIFCart); break; - case GI_POWER: - if(UNIFCart.Power) - UNIFCart.Power(); + + case GI_RESETM2: + if(UNIFCart.Reset) + UNIFCart.Reset(); + break; + case GI_POWER: + if(UNIFCart.Power) + UNIFCart.Power(); if(UNIFchrrama) memset(UNIFchrrama,0,8192); break; - case GI_CLOSE: - FCEU_SaveGameSave(&UNIFCart); + case GI_CLOSE: + FCEU_SaveGameSave(&UNIFCart); if(UNIFCart.Close) - UNIFCart.Close(); - FreeUNIF(); - ResetExState(0,0); - break; - case GI_INFOSTRING: + UNIFCart.Close(); + FreeUNIF(); + break; + case GI_INFOSTRING: { char board[24]; - strncpy(board, sboardname, 20); + strncpy(board, (char *)sboardname, 20); board[20] = 0; sprintf(param, "UNIF, %s, %s%s", board, PAL?"PAL":"NTSC", UNIFCart.battery?", BB":""); } break; - } + } } int UNIFLoad(const char *name, int fp) { - FCEU_fseek(fp,0,SEEK_SET); - FCEU_fread(&unhead,1,4,fp); - if(memcmp(&unhead,"UNIF",4)) - return 0; + FCEU_fseek(fp,0,SEEK_SET); + FCEU_fread(&unhead,1,4,fp); + if(memcmp(&unhead,"UNIF",4)) + return 0; ResetCartMapping(); - ResetExState(0,0); - ResetUNIF(); - if(!FCEU_read32(&unhead.info,fp)) - goto aborto; - if(FCEU_fseek(fp,0x20,SEEK_SET)<0) - goto aborto; - if(!LoadUNIFChunks(fp)) - goto aborto; + ResetExState(0,0); + ResetUNIF(); + if(!FCEU_read32le(&unhead.info,fp)) + goto aborto; + if(FCEU_fseek(fp,0x20,SEEK_SET)<0) + goto aborto; + if(!LoadUNIFChunks(fp)) + goto aborto; { - int x; - struct md5_context md5; - - md5_starts(&md5); - - for(x=0;x<32;x++) - if(malloced[x]) - { - md5_update(&md5,malloced[x],mallocedsizes[x]); - } - md5_finish(&md5,UNIFCart.MD5); - FCEU_printf(" ROM MD5: 0x"); - for(x=0;x<16;x++) - FCEU_printf("%02x",UNIFCart.MD5[x]); - FCEU_printf("\n"); - memcpy(FCEUGameInfo.MD5,UNIFCart.MD5,sizeof(UNIFCart.MD5)); + int x; + struct md5_context md5; + + md5_starts(&md5); + + for(x=0;x<32;x++) + if(malloced[x]) + { + md5_update(&md5,malloced[x],mallocedsizes[x]); + } + md5_finish(&md5,UNIFCart.MD5); + FCEU_printf(" ROM MD5: 0x"); + for(x=0;x<16;x++) + FCEU_printf("%02x",UNIFCart.MD5[x]); + FCEU_printf("\n"); + memcpy(&GameInfo->MD5,&UNIFCart.MD5,sizeof(UNIFCart.MD5)); } - if(!InitializeBoard()) - goto aborto; + if(!InitializeBoard()) + goto aborto; FCEU_LoadGameSave(&UNIFCart); - GameInterface=UNIFGI; - return 1; - aborto: + //strcpy(LoadedRomFName,name); //For the debugger list + GameInterface=UNIFGI; + return 1; + +aborto: FreeUNIF(); ResetUNIF(); diff --git a/unif.h b/unif.h index c8b0ef1..2a179ea 100644 --- a/unif.h +++ b/unif.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ void ANROM_Init(CartInfo *info); @@ -46,7 +46,9 @@ void MALEE_Init(CartInfo *info); void CNROM_Init(CartInfo *info); void CPROM_Init(CartInfo *info); void GNROM_Init(CartInfo *info); +void UNL3DBlock_Init(CartInfo *info); +void TBROM_Init(CartInfo *info); void TEROM_Init(CartInfo *info); void TFROM_Init(CartInfo *info); void TGROM_Init(CartInfo *info); @@ -62,6 +64,7 @@ void DEIROM_Init(CartInfo *info); void TCA01_Init(CartInfo *info); void TCU01_Init(CartInfo *info); +void TCU02_Init(CartInfo *info); void S8259A_Init(CartInfo *info); void S8259B_Init(CartInfo *info); void S8259C_Init(CartInfo *info); @@ -72,6 +75,7 @@ void SA0161M_Init(CartInfo *info); void SA72007_Init(CartInfo *info); void SA72008_Init(CartInfo *info); +void SA009_Init(CartInfo *info); void SA0036_Init(CartInfo *info); void SA0037_Init(CartInfo *info); @@ -79,24 +83,51 @@ void Supervision16_Init(CartInfo *info); void Super24_Init(CartInfo *info); void Novel_Init(CartInfo *info); -void BMC42in1r_Init(CartInfo *info); void BMC64in1nr_Init(CartInfo *info); void BMC70in1_Init(CartInfo *info); void BMC70in1B_Init(CartInfo *info); void BMC13in1JY110_Init(CartInfo *info); void BMCT262_Init(CartInfo *info); void BMCFK23C_Init(CartInfo *info); +void BMCFK23CA_Init(CartInfo *info); +void BMCD1038_Init(CartInfo *info); +void BMCA65AS_Init(CartInfo *info); +void BMCGK192_Init(CartInfo *info); +void BMCGS2004_Init(CartInfo *info); +void BMCGS2013_Init(CartInfo *info); +void BMC190in1_Init(CartInfo *info); +void BMCGhostbusters63in1_Init(CartInfo *info); +void BMCBS5_Init(CartInfo *info); void DreamTech01_Init(CartInfo *info); void Mapper190_Init(CartInfo *info); void UNLCC21_Init(CartInfo *info); +void UNLCN22M_Init(CartInfo *info); void UNLSL1632_Init(CartInfo *info); void UNLKOF97_Init(CartInfo *info); -void UNLSonic_Init(CartInfo *info); +void UNLA9746_Init(CartInfo *info); void UNLSHeroes_Init(CartInfo *info); void UNLH2288_Init(CartInfo *info); void UNL8237_Init(CartInfo *info); +void UNL8237A_Init(CartInfo *info); void UNL8157_Init(CartInfo *info); +void UNL22211_Init(CartInfo *info); +void UNLTF1201_Init(CartInfo *info); +void UNLKS7032_Init(CartInfo *info); +void UNLT230_Init(CartInfo *info); +void UNLAX5705_Init(CartInfo *info); +void UNLDANCE_Init(CartInfo *info); +void UNLOneBus_Init(CartInfo *info); +void UNLSC127_Init(CartInfo *info); + +void UNLEDU2000_Init(CartInfo *info); +void UNL6035052_Init(CartInfo *info); +void UNLN625092_Init(CartInfo *info); +void UNLSMB2J_Init(CartInfo *info); +//void UNL09034A_Init(CartInfo *info); +void BMC411120C_Init(CartInfo *info); +void BMC830118C_Init(CartInfo *info); +void BMCT2271_Init(CartInfo *info); extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM // bank switcherooing with certain boards... -- 2.39.5