merge mapper code from FCEUX
authornotaz <notasas@gmail.com>
Sat, 29 Sep 2012 23:11:57 +0000 (02:11 +0300)
committernotaz <notasas@gmail.com>
Sun, 30 Sep 2012 15:09:26 +0000 (18:09 +0300)
seems to be work by CaH4e3 and others

178 files changed:
boards/01-222.c [new file with mode: 0644]
boards/103.c [new file with mode: 0644]
boards/106.c [new file with mode: 0644]
boards/108.c [moved from boards/bmcgk192.c with 57% similarity]
boards/112.c
boards/116.c [new file with mode: 0644]
boards/117.c
boards/120.c [new file with mode: 0644]
boards/121.c [new file with mode: 0644]
boards/15.c [new file with mode: 0644]
boards/164.c
boards/175.c [new file with mode: 0644]
boards/176.c [new file with mode: 0644]
boards/177.c [new file with mode: 0644]
boards/178.c [new file with mode: 0644]
boards/179.c [new file with mode: 0644]
boards/183.c
boards/185.c
boards/186.c
boards/187.c
boards/189.c
boards/199.c [new file with mode: 0644]
boards/208.c
boards/222.c
boards/23.c [new file with mode: 0644]
boards/235.c
boards/253.c [new file with mode: 0644]
boards/3d-block.c [new file with mode: 0644]
boards/411120-c.c [new file with mode: 0644]
boards/43.c [new file with mode: 0644]
boards/57.c
boards/603-5052.c [moved from boards/cc21.c with 54% similarity]
boards/68.c [new file with mode: 0644]
boards/8157.c
boards/8237.c
boards/830118C.c [new file with mode: 0644]
boards/88.c
boards/90.c
boards/95.c
boards/Makefile
boards/__dummy_mapper.c
boards/a9711.c [moved from boards/sonic5.c with 51% similarity]
boards/a9746.c [new file with mode: 0644]
boards/addrlatch.c [new file with mode: 0644]
boards/ax5705.c [new file with mode: 0644]
boards/bandai.c [new file with mode: 0644]
boards/bmc13in1jy110.c
boards/bmc42in1r.c
boards/bmc64in1nr.c
boards/bmc70in1.c
boards/bonza.c
boards/bs-5.c [new file with mode: 0644]
boards/datalatch.c
boards/deirom.c
boards/dream.c
boards/edu2000.c [new file with mode: 0644]
boards/fk23c.c
boards/ghostbusters63in1.c [new file with mode: 0644]
boards/gs-2004.c [new file with mode: 0644]
boards/gs-2013.c [new file with mode: 0644]
boards/h2288.c
boards/karaoke.c
boards/kof97.c
boards/konami-qtai.c
boards/ks7032.c [new file with mode: 0644]
boards/malee.c
boards/mapinc.h
boards/mmc1.c
boards/mmc3.c
boards/mmc3.h
boards/mmc5.c
boards/n-c22m.c [new file with mode: 0644]
boards/n106.c
boards/n625092.c [new file with mode: 0644]
boards/novel.c
boards/onebus.c [new file with mode: 0644]
boards/sachen.c
boards/sc-127.c [new file with mode: 0644]
boards/sheroes.c
boards/sl1632.c
boards/smb2j.c [new file with mode: 0644]
boards/subor.c
boards/super24.c
boards/supervision.c
boards/t-227-1.c [new file with mode: 0644]
boards/t-262.c
boards/tengen.c
boards/tf-1201.c [new file with mode: 0644]
driver.h
fce.c
fce.h
file.h
git.h
ines-correct.h
ines.c
ines.h
mappers/113.c [deleted file]
mappers/15.c [deleted file]
mappers/151.c
mappers/156.c [new file with mode: 0644]
mappers/16.c
mappers/17.c
mappers/18.c
mappers/180.c [deleted file]
mappers/183.c [deleted file]
mappers/184.c [deleted file]
mappers/200.c [deleted file]
mappers/201.c
mappers/202.c
mappers/203.c
mappers/204.c
mappers/21.c
mappers/212.c
mappers/213.c
mappers/214.c
mappers/217.c
mappers/22.c
mappers/225.c
mappers/226.c [deleted file]
mappers/227.c
mappers/228.c
mappers/229.c
mappers/23.c [deleted file]
mappers/230.c
mappers/231.c
mappers/232.c
mappers/234.c
mappers/240.c [deleted file]
mappers/242.c
mappers/244.c
mappers/246.c
mappers/24and26.c
mappers/25.c
mappers/255.c
mappers/27.c
mappers/32.c
mappers/33.c
mappers/40.c
mappers/41.c
mappers/42.c
mappers/43.c [deleted file]
mappers/46.c
mappers/50.c
mappers/51.c
mappers/59.c
mappers/6.c
mappers/60.c
mappers/61.c
mappers/62.c
mappers/65.c
mappers/67.c
mappers/68.c [deleted file]
mappers/69.c
mappers/71.c
mappers/72.c
mappers/73.c
mappers/75.c
mappers/76.c
mappers/77.c
mappers/79.c
mappers/8.c
mappers/80.c
mappers/82.c
mappers/83.c
mappers/85.c
mappers/86.c
mappers/89.c
mappers/91.c
mappers/92.c
mappers/97.c
mappers/99.c
mappers/Makefile
mappers/mmc2and4.c
mappers/simple.c
svga.h
types.h
unif.c
unif.h

diff --git a/boards/01-222.c b/boards/01-222.c
new file mode 100644 (file)
index 0000000..c0e7320
--- /dev/null
@@ -0,0 +1,103 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * TXC mappers\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[4], cmd, is172, is173;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 4, "REGS"},\r
+  {&cmd, 1, "CMD"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg32(0x8000,(reg[2]>>2)&1);\r
+  if(is172)\r
+    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\r
+                                                          // rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary\r
+  else\r
+    setchr8(reg[2]&3);\r
+}\r
+\r
+static DECLFW(UNL22211WriteLo)\r
+{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+  reg[A&3]=V;\r
+}\r
+\r
+static DECLFW(UNL22211WriteHi)\r
+{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+  cmd=V;\r
+  Sync();\r
+}\r
+\r
+static DECLFR(UNL22211ReadLo)\r
+{\r
+    return (reg[1]^reg[2])|(is173?0x01:0x40);\r
+//  if(reg[3])\r
+//    return reg[2];\r
+//  else\r
+//    return X.DB;\r
+}\r
+\r
+static void UNL22211Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetReadHandler(0x4100,0x4100,UNL22211ReadLo);\r
+  SetWriteHandler(0x4100,0x4103,UNL22211WriteLo);\r
+  SetWriteHandler(0x8000,0xFFFF,UNL22211WriteHi);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNL22211_Init(CartInfo *info)\r
+{\r
+  is172=0;\r
+  is173=0;\r
+  info->Power=UNL22211Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper172_Init(CartInfo *info)\r
+{\r
+  is172=1;  \r
+  is173=0;\r
+  info->Power=UNL22211Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper173_Init(CartInfo *info)\r
+{\r
+  is172=0;  \r
+  is173=1;\r
+  info->Power=UNL22211Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/103.c b/boards/103.c
new file mode 100644 (file)
index 0000000..e25f5fc
--- /dev/null
@@ -0,0 +1,125 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg0, reg1, reg2;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg0, 1, "REG0"},\r
+  {&reg1, 1, "REG1"},\r
+  {&reg2, 1, "REG2"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr8(0);\r
+  setprg8(0x8000,0xc);\r
+  setprg8(0xe000,0xf);\r
+  if(reg2&0x10)\r
+  {\r
+    setprg8(0x6000,reg0);\r
+    setprg8(0xa000,0xd);\r
+    setprg8(0xc000,0xe);\r
+  }\r
+  else\r
+  {\r
+    setprg8r(0x10,0x6000,0);\r
+    setprg4(0xa000,(0xd<<1));\r
+    setprg2(0xb000,(0xd<<2)+2);\r
+    setprg2r(0x10,0xb800,4);\r
+    setprg2r(0x10,0xc000,5);\r
+    setprg2r(0x10,0xc800,6);\r
+    setprg2r(0x10,0xd000,7);\r
+    setprg2(0xd800,(0xe<<2)+3);\r
+  }\r
+  setmirror(reg1^1);\r
+}\r
+\r
+static DECLFW(M103RamWrite0)\r
+{\r
+  WRAM[A&0x1FFF]=V;\r
+}\r
+\r
+static DECLFW(M103RamWrite1)\r
+{\r
+  WRAM[0x2000+((A-0xB800)&0x1FFF)]=V;\r
+}\r
+\r
+static DECLFW(M103Write0)\r
+{\r
+  reg0=V&0xf;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M103Write1)\r
+{\r
+  reg1=(V>>3)&1;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M103Write2)\r
+{\r
+  reg2=V;\r
+  Sync();\r
+}\r
+\r
+static void M103Power(void)\r
+{\r
+  reg0=reg1=0; reg2=0;\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,M103RamWrite0);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0xB800,0xD7FF,M103RamWrite1);\r
+  SetWriteHandler(0x8000,0x8FFF,M103Write0);\r
+  SetWriteHandler(0xE000,0xEFFF,M103Write1);\r
+  SetWriteHandler(0xF000,0xFFFF,M103Write2);\r
+}\r
+\r
+static void M103Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper103_Init(CartInfo *info)\r
+{\r
+  info->Power=M103Power;\r
+  info->Close=M103Close;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=16384;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/106.c b/boards/106.c
new file mode 100644 (file)
index 0000000..638dda9
--- /dev/null
@@ -0,0 +1,119 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[16], IRQa;\r
+static uint32 IRQCount;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 4, "IRQCOUNT"},\r
+  {reg, 16, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr1(0x0000,reg[0]&0xfe);\r
+  setchr1(0x0400,reg[1]|1);\r
+  setchr1(0x0800,reg[2]&0xfe);\r
+  setchr1(0x0c00,reg[3]|1);\r
+  setchr1(0x1000,reg[4]);\r
+  setchr1(0x1400,reg[5]);\r
+  setchr1(0x1800,reg[6]);\r
+  setchr1(0x1c00,reg[7]);\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg8(0x8000,(reg[0x8]&0xf)|0x10);\r
+  setprg8(0xA000,(reg[0x9]&0x1f));\r
+  setprg8(0xC000,(reg[0xa]&0x1f));\r
+  setprg8(0xE000,(reg[0xb]&0xf)|0x10);\r
+  setmirror((reg[0xc]&1)^1);\r
+}\r
+\r
+static DECLFW(M106Write)\r
+{\r
+  A&=0xF;\r
+  switch(A)\r
+  {\r
+    case 0xD: IRQa=0; IRQCount=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+    case 0xE: IRQCount=(IRQCount&0xFF00)|V; break;\r
+    case 0xF: IRQCount=(IRQCount&0x00FF)|(V<<8); IRQa=1; break;\r
+    default: reg[A]=V; Sync(); break;\r
+  }\r
+}\r
+\r
+static void M106Power(void)\r
+{\r
+  reg[8]=reg[9]=reg[0xa]=reg[0xb]=-1;\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetWriteHandler(0x8000,0xFFFF,M106Write);\r
+}\r
+\r
+static void M106Reset(void)\r
+{\r
+}\r
+\r
+static void M106Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+void M106CpuHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount+=a;\r
+    if(IRQCount>0x10000)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+      IRQa=0;\r
+    }\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper106_Init(CartInfo *info)\r
+{\r
+  info->Reset=M106Reset;\r
+  info->Power=M106Power;\r
+  info->Close=M106Close;\r
+  MapIRQHook=M106CpuHook;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
similarity index 57%
rename from boards/bmcgk192.c
rename to boards/108.c
index b66d831..fc3aebd 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x6000,reg);\r
+  setprg32(0x8000,~0);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(M108Write)\r
+{\r
+   reg=V;\r
+   Sync();\r
+}\r
+\r
+static void M108Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8FFF,0x8FFF,M108Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper108_Init(CartInfo *info)\r
+{\r
+  info->Power=M108Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 2bb1e4b..ccfd4f4 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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];
  */
 
 #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"},
 static uint8 *WRAM=NULL;
 
 static SFORMAT StateRegs[]=
 {
   {&cmd, 1, "CMD"},
   {&mirror, 1, "MIRR"},
+  {&bank, 1, "BANK"},
   {reg, 8, "REGS"},
   {0}
 };
   {reg, 8, "REGS"},
   {0}
 };
@@ -37,12 +39,12 @@ static void Sync(void)
   setmirror(mirror^1);
   setprg8(0x8000,reg[0]);
   setprg8(0xA000,reg[1]);
   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)
 }
 
 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 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)
 }
 
 static void M112Close(void)
@@ -65,10 +67,12 @@ static void M112Close(void)
 
 static void M112Power(void)
 {
 
 static void M112Power(void)
 {
+  bank=0;
   setprg16(0xC000,~0);
   setprg8r(0x10,0x6000,0);
   SetReadHandler(0x8000,0xFFFF,CartBR);
   SetWriteHandler(0x8000,0xFFFF,M112Write);
   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);
 }
   SetReadHandler(0x6000,0x7FFF,CartBR);
   SetWriteHandler(0x6000,0x7FFF,CartBW);
 }
diff --git a/boards/116.c b/boards/116.c
new file mode 100644 (file)
index 0000000..3a21668
--- /dev/null
@@ -0,0 +1,359 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2011 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * \r
+ * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1)\r
+ * the same as 603-5052 board (TODO: add reading registers, merge)\r
+ * SL1632 2-in-1 protected board, similar to SL12 (TODO: find difference)\r
+ *\r
+ * Known PCB:\r
+ *\r
+ * Garou Densetsu Special (G0904.PCB, Huang-1, GAL dip: W conf.)\r
+ * Kart Fighter (008, Huang-1, GAL dip: W conf.)\r
+ * Somari (008, C5052-13, GAL dip: P conf., GK2-P/GK2-V maskroms)\r
+ * Somari (008, Huang-1, GAL dip: W conf., GK1-P/GK1-V maskroms)\r
+ * AV Mei Shao Nv Zhan Shi ()\r
+ * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms)\r
+ * Contra Fighter (603-5052 board, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms)\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 mode;\r
+static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr;\r
+static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr;\r
+extern uint8 IRQCount,IRQLatch,IRQa;\r
+extern uint8 IRQReload;\r
+static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&mode, 1, "MODE"},\r
+  {vrc2_chr, 8, "vrch"},\r
+  {vrc2_prg, 2, "vrpr"},\r
+  {&vrc2_mirr, 1, "vrmi"},\r
+  {mmc3_regs, 10, "m3re"},\r
+  {&mmc3_ctrl, 1, "m3ct"},\r
+  {&mmc3_mirr, 1, "m3mi"},\r
+  {&IRQReload, 1, "IRQR"},\r
+  {&IRQCount, 1, "IRQC"},\r
+  {&IRQLatch, 1, "IRQL"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {mmc1_regs, 4, "m1r"},\r
+  {&mmc1_buffer, 1, "m1bf"},\r
+  {&mmc1_shift, 1, "m1mi"},\r
+  {0}\r
+};\r
+\r
+static void SyncPRG(void)\r
+{\r
+  switch(mode & 3) {\r
+   case 0:\r
+     setprg8(0x8000, vrc2_prg[0]);\r
+     setprg8(0xA000, vrc2_prg[1]);\r
+     setprg8(0xC000, ~1);\r
+     setprg8(0xE000, ~0);\r
+     break;\r
+   case 1: {\r
+     uint32 swap = (mmc3_ctrl >> 5) & 2;\r
+     setprg8(0x8000, mmc3_regs[6 + swap]);\r
+     setprg8(0xA000, mmc3_regs[7]);\r
+     setprg8(0xC000, mmc3_regs[6 + (swap ^ 2)]);\r
+     setprg8(0xE000, mmc3_regs[9]);\r
+     break;\r
+   }\r
+   case 2:\r
+   case 3: {\r
+     uint8 bank = mmc1_regs[3] & 0xF;\r
+        if(mmc1_regs[0] & 8)\r
+     {\r
+       if(mmc1_regs[0] & 4)\r
+       {\r
+         setprg16(0x8000, bank);\r
+         setprg16(0xC000, 0x0F);\r
+       }\r
+       else\r
+       {\r
+         setprg16(0x8000, 0);\r
+         setprg16(0xC000, bank);\r
+       }\r
+     }\r
+        else\r
+          setprg32(0x8000, bank >> 1);\r
+     break;\r
+   }\r
+  }\r
+}\r
+\r
+static void SyncCHR(void)\r
+{\r
+  uint32 base = (mode & 4) << 6;\r
+  switch(mode & 3) {\r
+   case 0:\r
+     setchr1(0x0000, base|vrc2_chr[0]);\r
+     setchr1(0x0400, base|vrc2_chr[1]);\r
+     setchr1(0x0800, base|vrc2_chr[2]);\r
+     setchr1(0x0c00, base|vrc2_chr[3]);\r
+     setchr1(0x1000, base|vrc2_chr[4]);\r
+     setchr1(0x1400, base|vrc2_chr[5]);\r
+     setchr1(0x1800, base|vrc2_chr[6]);\r
+     setchr1(0x1c00, base|vrc2_chr[7]);\r
+     break;\r
+   case 1: {\r
+     uint32 swap = (mmc3_ctrl & 0x80) << 5;\r
+     setchr1(0x0000 ^ swap, base|((mmc3_regs[0])&0xFE));\r
+     setchr1(0x0400 ^ swap, base|(mmc3_regs[0]|1));\r
+     setchr1(0x0800 ^ swap, base|((mmc3_regs[1])&0xFE));\r
+     setchr1(0x0c00 ^ swap, base|(mmc3_regs[1]|1));\r
+     setchr1(0x1000 ^ swap, base|mmc3_regs[2]);\r
+     setchr1(0x1400 ^ swap, base|mmc3_regs[3]);\r
+     setchr1(0x1800 ^ swap, base|mmc3_regs[4]);\r
+     setchr1(0x1c00 ^ swap, base|mmc3_regs[5]);\r
+     break;\r
+   }\r
+   case 2:\r
+   case 3:\r
+     if(mmc1_regs[0]&0x10)\r
+     {\r
+       setchr4(0x0000, mmc1_regs[1]);\r
+       setchr4(0x1000, mmc1_regs[2]);\r
+     }\r
+     else\r
+       setchr8(mmc1_regs[1] >> 1);\r
+     break;\r
+  }\r
+}\r
+\r
+static void SyncMIR(void)\r
+{\r
+  switch(mode & 3) {\r
+   case 0: {\r
+     setmirror((vrc2_mirr&1)^1);\r
+     break;\r
+   }\r
+   case 1: {\r
+     setmirror((mmc3_mirr&1)^1);\r
+     break;\r
+   }\r
+   case 2:\r
+   case 3: {\r
+     switch(mmc1_regs[0]&3) {\r
+       case 0: setmirror(MI_0); break;\r
+       case 1: setmirror(MI_1); break;\r
+       case 2: setmirror(MI_V); break;\r
+       case 3: setmirror(MI_H); break;\r
+     }\r
+     break;\r
+   }\r
+  }\r
+}\r
+\r
+static void Sync(void)\r
+{\r
+  SyncPRG();\r
+  SyncCHR();\r
+  SyncMIR();\r
+}\r
+\r
+static DECLFW(UNLSL12ModeWrite)\r
+{\r
+  printf("%04X:%02X\n",A,V);\r
+  if((A & 0x4100) == 0x4100) {\r
+    mode = V;\r
+    if(A&1) { // hacky hacky, there are two configuration modes on SOMARI HUANG-1 PCBs\r
+              // Solder pads with P1/P2 shorted called SOMARI P,\r
+              // Solder pads with W1/W2 shorted called SOMARI W\r
+              // Both identical 3-in-1 but W wanted MMC1 registers\r
+              // to be reset when switch to MMC1 mode P one - doesn't\r
+              // There is issue with W version of Somari at starting copyrights\r
+      mmc1_regs[0] = 0xc;\r
+      mmc1_regs[3] = 0;\r
+      mmc1_buffer = 0;\r
+      mmc1_shift = 0;\r
+    }\r
+    Sync();\r
+  }\r
+}\r
+\r
+static DECLFW(UNLSL12Write)\r
+{\r
+  printf("%04X:%02X\n",A,V);\r
+       if(A==0xA123)\r
+       {\r
+               int zzz=9;\r
+       }\r
+  switch(mode & 3) {\r
+   case 0: {\r
+     if((A>=0xB000)&&(A<=0xE003))\r
+     {\r
+       int32 ind=((((A&2)|(A>>10))>>1)+2)&7;\r
+       int32 sar=((A&1)<<2);\r
+       vrc2_chr[ind]=(vrc2_chr[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r
+       SyncCHR();\r
+     }\r
+     else\r
+       switch(A&0xF000) {\r
+        case 0x8000: vrc2_prg[0] = V; SyncPRG(); break;\r
+        case 0xA000: vrc2_prg[1] = V; SyncPRG(); break;\r
+        case 0x9000: vrc2_mirr = V; SyncMIR(); break;\r
+       }\r
+     break;\r
+   }\r
+   case 1: {\r
+     switch(A & 0xE001) {\r
+      case 0x8000: {\r
+        uint8 old_ctrl = mmc3_ctrl;\r
+        mmc3_ctrl = V;\r
+        if((old_ctrl&0x40) != (mmc3_ctrl&0x40))\r
+          SyncPRG();\r
+        if((old_ctrl&0x80) != (mmc3_ctrl&0x80))\r
+          SyncCHR();\r
+        break;\r
+      }\r
+      case 0x8001:\r
+        mmc3_regs[mmc3_ctrl & 7] = V;\r
+        if((mmc3_ctrl & 7) < 6)\r
+          SyncCHR();\r
+        else\r
+          SyncPRG();\r
+        break;\r
+      case 0xA000:\r
+        mmc3_mirr = V;\r
+        SyncMIR();\r
+        break;\r
+      case 0xC000:\r
+        IRQLatch = V;\r
+        break;\r
+      case 0xC001:\r
+        IRQReload = 1;\r
+        break;\r
+      case 0xE000:\r
+        X6502_IRQEnd(FCEU_IQEXT);\r
+        IRQa=0;\r
+        break;\r
+      case 0xE001:\r
+        IRQa=1;\r
+        break;\r
+     }\r
+     break;\r
+   }\r
+   case 2:\r
+   case 3: {\r
+     if(V & 0x80)\r
+     {\r
+       mmc1_regs[0] |= 0xc;\r
+       mmc1_buffer = mmc1_shift = 0;\r
+       SyncPRG();\r
+     }\r
+     else\r
+     {\r
+       uint8 n = (A >> 13) - 4;\r
+       mmc1_buffer |=  (V & 1) << (mmc1_shift++);\r
+       if(mmc1_shift == 5)\r
+       {\r
+         mmc1_regs[n] = mmc1_buffer;\r
+         mmc1_buffer = mmc1_shift = 0;\r
+         switch(n) {\r
+          case 0: SyncMIR();\r
+          case 2: SyncCHR(); \r
+          case 3:\r
+          case 1: SyncPRG();\r
+         }\r
+       }\r
+     }\r
+     break;\r
+   }\r
+  }\r
+}\r
+\r
+static void UNLSL12HBIRQ(void)\r
+{\r
+  if((mode & 3) == 1)\r
+  {\r
+    int32 count = IRQCount;\r
+    if(!count || IRQReload)\r
+    {\r
+      IRQCount = IRQLatch;\r
+      IRQReload = 0;\r
+    }\r
+    else\r
+      IRQCount--;\r
+    if(!IRQCount)\r
+    {\r
+      if(IRQa)\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+static void UNLSL12Power(void)\r
+{\r
+  mode = 0;\r
+  vrc2_chr[0] = ~0;\r
+  vrc2_chr[1] = ~0;\r
+  vrc2_chr[2] = ~0;\r
+  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\r
+  vrc2_chr[4] = 4;\r
+  vrc2_chr[5] = 5;\r
+  vrc2_chr[6] = 6;\r
+  vrc2_chr[7] = 7;\r
+  vrc2_prg[0] = 0;\r
+  vrc2_prg[1] = 1;\r
+  vrc2_mirr = 0;\r
+  mmc3_regs[0] = 0;\r
+  mmc3_regs[1] = 2;\r
+  mmc3_regs[2] = 4;\r
+  mmc3_regs[3] = 5;\r
+  mmc3_regs[4] = 6;\r
+  mmc3_regs[5] = 7;\r
+  mmc3_regs[6] = ~3;\r
+  mmc3_regs[7] = ~2;\r
+  mmc3_regs[8] = ~1;\r
+  mmc3_regs[9] = ~0;\r
+  mmc3_ctrl = mmc3_mirr = IRQCount = IRQLatch = IRQa = 0;\r
+  mmc1_regs[0] = 0xc;\r
+  mmc1_regs[1] = 0;\r
+  mmc1_regs[2] = 0;\r
+  mmc1_regs[3] = 0;\r
+  mmc1_buffer = 0;\r
+  mmc1_shift = 0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4100,0x7FFF,UNLSL12ModeWrite);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLSL12Write);\r
+}\r
+\r
+void UNLSL12_Init(CartInfo *info)\r
+{\r
+  info->Power = UNLSL12Power;\r
+  GameHBIRQHook = UNLSL12HBIRQ;\r
+  GameStateRestore = StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper116_Init(CartInfo *info)\r
+{\r
+       UNLSL12_Init(info);\r
+}\r
index 6746015..b2348f0 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
-static uint8 prgreg[4], chrreg[8];
+static uint8 prgreg[4], chrreg[8], mirror;
 static uint8 IRQa, IRQCount, IRQLatch;
 
 static SFORMAT StateRegs[]=
 static uint8 IRQa, IRQCount, IRQLatch;
 
 static SFORMAT StateRegs[]=
@@ -30,18 +30,20 @@ static SFORMAT StateRegs[]=
   {&IRQLatch, 1, "IRQL"},
   {prgreg, 4, "PREGS"},
   {chrreg, 8, "CREGS"},
   {&IRQLatch, 1, "IRQL"},
   {prgreg, 4, "PREGS"},
   {chrreg, 8, "CREGS"},
+  {&mirror, 1, "MREG"},
   {0}
 };
 
 static void Sync(void)
 {
   {0}
 };
 
 static void Sync(void)
 {
+  int i;
   setprg8(0x8000,prgreg[0]);     
   setprg8(0xa000,prgreg[1]);     
   setprg8(0xc000,prgreg[2]);     
   setprg8(0xe000,prgreg[3]);
   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]);     
   for(i=0; i<8; i++)
      setchr1(i<<10,chrreg[i]);     
+  setmirror(mirror^1);   
 }
 
 static DECLFW(M117Write)
 }
 
 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 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 (file)
index 0000000..ed681b9
--- /dev/null
@@ -0,0 +1,66 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x6000,reg);\r
+  setprg32(0x8000,2);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(M120Write)\r
+{\r
+   if(A==0x41FF)\r
+   {\r
+     reg=V&7;\r
+     Sync();\r
+   }\r
+}\r
+\r
+static void M120Power(void)\r
+{\r
+  reg=0;\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4100,0x5FFF,M120Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper120_Init(CartInfo *info)\r
+{\r
+  info->Power=M120Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/121.c b/boards/121.c
new file mode 100644 (file)
index 0000000..63784f9
--- /dev/null
@@ -0,0 +1,91 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007-2008 Mad Dumper, CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * Panda prince pirate.\r
+ * MK4, MK6, A9711 board, MAPPER 187 the same!\r
+ * UNL6035052_Init seems to be the same too, but with prot array in reverse\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 readbyte = 0;\r
+\r
+static DECLFW(M121Write)\r
+{\r
+//  FCEU_printf("write: %04x:%04x\n",A&0xE003,V);\r
+  if((A&0xF003)==0x8003)\r
+  {\r
+//    FCEU_printf("       prot write");\r
+//    FCEU_printf("write: %04x:%04x\n",A,V);\r
+    if     (V==0xAB) setprg8(0xE000,7);\r
+    else if(V==0x26) setprg8(0xE000,8);\r
+//    else if(V==0x26) setprg8(0xE000,1); // MK3\r
+//    else if(V==0x26) setprg8(0xE000,0x15); // sonic 3D blast, 8003 - command (0x26), 8001 - data 0x2A (<<1 = 0x15)\r
+    else if(V==0xFF) setprg8(0xE000,9);\r
+    else if(V==0x28) setprg8(0xC000,0xC);\r
+    else if(V==0xEC) setprg8(0xE000,0xD); \r
+//    else if(V==0xEC) setprg8(0xE000,0xC);//MK3\r
+    else if(V==0xEF) setprg8(0xE000,0xD); // damn mess, need real hardware to figure out bankswitching\r
+    else if(V==0x2A) setprg8(0xA000,0x0E);\r
+//    else if(V==0x2A) setprg8(0xE000,0x0C); // MK3\r
+    else if(V==0x20) setprg8(0xE000,0x13);\r
+    else if(V==0x29) setprg8(0xE000,0x1B);\r
+    else \r
+    {\r
+//      FCEU_printf(" unknown");\r
+      FixMMC3PRG(MMC3_cmd);\r
+      MMC3_CMDWrite(A,V);\r
+    }\r
+//      FCEU_printf("\n");\r
+  }\r
+  else\r
+  {\r
+//    FixMMC3PRG(MMC3_cmd);\r
+    MMC3_CMDWrite(A,V);\r
+  }\r
+}\r
+\r
+static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 };\r
+static DECLFW(M121LoWrite)\r
+{\r
+  EXPREGS[0] = prot_array[V&3];  // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter)\r
+//  FCEU_printf("write: %04x:%04x\n",A,V);\r
+}\r
+\r
+static DECLFR(M121Read)\r
+{ \r
+//  FCEU_printf("read:  %04x\n",A);\r
+  return EXPREGS[0];\r
+}\r
+\r
+static void M121Power(void)\r
+{\r
+  GenMMC3Power();\r
+//  Write_IRQFM(0x4017,0x40);\r
+  SetReadHandler(0x5000,0x5FFF,M121Read);\r
+  SetWriteHandler(0x5000,0x5FFF,M121LoWrite);\r
+  SetWriteHandler(0x8000,0x9FFF,M121Write);\r
+}\r
+\r
+void Mapper121_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 256, 8, 0);\r
+  info->Power=M121Power;\r
+  AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
diff --git a/boards/15.c b/boards/15.c
new file mode 100644 (file)
index 0000000..6405afa
--- /dev/null
@@ -0,0 +1,120 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 latchea;\r
+static uint8 latched;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&latchea, 2, "AREG"},\r
+  {&latched, 1, "DREG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  int i;\r
+  setmirror(((latched>>6)&1)^1);\r
+  switch(latchea)\r
+  {\r
+    case 0x8000:\r
+      for(i=0;i<4;i++)\r
+        setprg8(0x8000+(i<<13),(((latched&0x7F)<<1)+i)^(latched>>7));\r
+      break;\r
+    case 0x8002:\r
+      for(i=0;i<4;i++)\r
+        setprg8(0x8000+(i<<13),((latched&0x7F)<<1)+(latched>>7));\r
+      break;\r
+    case 0x8001:\r
+    case 0x8003:\r
+      for(i=0;i<4;i++)\r
+      {\r
+        unsigned int b;\r
+        b=latched&0x7F;\r
+        if(i>=2 && !(latchea&0x2))\r
+          i=0x7F;\r
+        setprg8(0x8000+(i<<13),(i&1)+((b<<1)^(latched>>7)));\r
+      }\r
+      break;\r
+  }\r
+}\r
+\r
+static DECLFW(M15Write)\r
+{\r
+  latchea=A;\r
+  latched=V;\r
+       printf("%04X = %02X\n",A,V);\r
+  Sync();\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+static void M15Power(void)\r
+{\r
+  latchea=0x8000;\r
+  latched=0;\r
+  setchr8(0);\r
+  setprg8r(0x10,0x6000,0);\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetWriteHandler(0x8000,0xFFFF,M15Write);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  Sync();\r
+}\r
+\r
+static void M15Reset(void)\r
+{\r
+  latchea=0x8000;\r
+  latched=0;\r
+  Sync();\r
+}\r
+\r
+static void M15Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+void Mapper15_Init(CartInfo *info)\r
+{\r
+  info->Power=M15Power;\r
+  info->Reset=M15Reset;\r
+  info->Close=M15Close;\r
+  GameStateRestore=StateRestore;\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
index 0bb85b3..22589ec 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
 /* 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
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
-static uint8 cmd;
+static uint8 cmd, laststrobe, trigger;
 static uint8 DRegs[8];
 static SFORMAT StateRegs[]=
 {
   {&cmd, 1, "CMD"},
 static uint8 DRegs[8];
 static SFORMAT StateRegs[]=
 {
   {&cmd, 1, "CMD"},
+  {&laststrobe, 1, "STB"},
+  {&trigger, 1, "TRG"},
   {DRegs, 8, "DREG"},
   {0}
 };
   {DRegs, 8, "DREG"},
   {0}
 };
@@ -32,7 +34,6 @@ static SFORMAT StateRegs[]=
 static void Sync(void)
 {
   setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF));
 static void Sync(void)
 {
   setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF));
-  setchr8(0);
 }
 
 static void StateRestore(int version)
 }
 
 static void StateRestore(int version)
@@ -40,21 +41,46 @@ static void StateRestore(int version)
   Sync();
 }
 
   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;
 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)
 {
   }
 }
 
 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;
   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);
   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);
   SetReadHandler(0x6000,0x7FFF,AWRAM);
   SetWriteHandler(0x6000,0x7FFF,BWRAM);
+  setchr8(0);
   Sync();
 }
 
 static void M163HB(void)
 {
   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;
 static void Power2(void)
 {
   memset(DRegs,0,8);
   DRegs[1]=0xFF;
+  laststrobe=1;
   cmd=0;
   SetReadHandler(0x8000,0xFFFF,CartBR);
   cmd=0;
   SetReadHandler(0x8000,0xFFFF,CartBR);
-  SetWriteHandler(0x4020,0xFFFF,Write2);
+  SetWriteHandler(0x4020,0x5FFF,Write2);
   SetReadHandler(0x6000,0x7FFF,AWRAM);
   SetWriteHandler(0x6000,0x7FFF,BWRAM);
   SetReadHandler(0x6000,0x7FFF,AWRAM);
   SetWriteHandler(0x6000,0x7FFF,BWRAM);
+  SetReadHandler(0x5000,0x5FFF,ReadLow);
+  setchr8(0);
   Sync();
 }
 
   Sync();
 }
 
@@ -105,6 +145,9 @@ void Mapper164_Init(CartInfo *info)
   info->Power=Power;
   GameStateRestore=StateRestore;
   AddExState(&StateRegs, ~0, 0, 0);
   info->Power=Power;
   GameStateRestore=StateRestore;
   AddExState(&StateRegs, ~0, 0, 0);
+  AddExState(WRAM, 8192, 0, "WRAM");
+  info->SaveGame[0]=WRAM;\r
+  info->SaveGameLen[0]=8192;
 }
 
 void Mapper163_Init(CartInfo *info)
 }
 
 void Mapper163_Init(CartInfo *info)
@@ -113,4 +156,5 @@ void Mapper163_Init(CartInfo *info)
   GameHBIRQHook=M163HB;
   GameStateRestore=StateRestore;
   AddExState(&StateRegs, ~0, 0, 0);
   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 (file)
index 0000000..2830584
--- /dev/null
@@ -0,0 +1,88 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg, delay, mirr;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REG"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr8(reg);\r
+  if(!delay)\r
+  {\r
+  setprg16(0x8000,reg);\r
+  setprg8(0xC000,reg << 1);\r
+  }\r
+  setprg8(0xE000,(reg << 1) + 1);\r
+  setmirror(((mirr&4)>>2)^1);\r
+}\r
+\r
+static DECLFW(M175Write1)\r
+{\r
+  mirr = V;\r
+  delay = 1;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M175Write2)\r
+{\r
+  reg = V & 0x0F;\r
+  delay = 1;\r
+  Sync();\r
+}\r
+\r
+static DECLFR(M175Read)\r
+{\r
+  if(A==0xFFFC)\r
+  {\r
+    delay = 0;\r
+    Sync();\r
+  }\r
+  return CartBR(A);\r
+}\r
+\r
+static void M175Power(void)\r
+{\r
+  reg = mirr = delay = 0;\r
+  SetReadHandler(0x8000,0xFFFF,M175Read);\r
+  SetWriteHandler(0x8000,0x8000,M175Write1);\r
+  SetWriteHandler(0xA000,0xA000,M175Write2);\r
+  Sync();     \r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper175_Init(CartInfo *info)\r
+{\r
+  info->Power=M175Power;\r
+  GameStateRestore=StateRestore;\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/176.c b/boards/176.c
new file mode 100644 (file)
index 0000000..0830df8
--- /dev/null
@@ -0,0 +1,158 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *  Copyright (C) 2012 FCEUX team\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+extern uint32 ROM_size;\r
+\r
+static uint8 prg[4], chr, sbw, we_sram;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {prg, 4, "PRG"},\r
+  {&chr, 1, "CHR"},\r
+       {&sbw, 1, "SBW"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8r(0x10,0x6000,0);\r
+       setprg8(0x8000,prg[0]);\r
+       setprg8(0xA000,prg[1]);\r
+       setprg8(0xC000,prg[2]);\r
+       setprg8(0xE000,prg[3]);\r
+\r
+  setchr8(chr);\r
+}\r
+\r
+static DECLFW(M176Write_5001)\r
+{ \r
+       printf("%04X = $%02X\n",A,V);\r
+       if(sbw)\r
+       {\r
+               prg[0] = V*4;\r
+               prg[1] = V*4+1;\r
+               prg[2] = V*4+2;\r
+               prg[3] = V*4+3;\r
+       }\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M176Write_5010)\r
+{ \r
+       printf("%04X = $%02X\n",A,V);\r
+       if(V == 0x24) sbw = 1;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M176Write_5011)\r
+{ \r
+       printf("%04X = $%02X\n",A,V);\r
+       V >>= 1;\r
+       if(sbw)\r
+       {\r
+               prg[0] = V*4;\r
+               prg[1] = V*4+1;\r
+               prg[2] = V*4+2;\r
+               prg[3] = V*4+3;\r
+       }\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M176Write_5FF1)\r
+{ \r
+       printf("%04X = $%02X\n",A,V);\r
+  V >>= 1;\r
+       prg[0] = V*4;\r
+       prg[1] = V*4+1;\r
+       prg[2] = V*4+2;\r
+       prg[3] = V*4+3;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M176Write_5FF2)\r
+{ \r
+       printf("%04X = $%02X\n",A,V);\r
+  chr = V;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M176Write_A001)\r
+{\r
+       we_sram = V & 0x03;\r
+}\r
+\r
+static DECLFW(M176Write_WriteSRAM)\r
+{\r
+//     if(we_sram)\r
+               CartBW(A,V);\r
+}\r
+\r
+static void M176Power(void)\r
+{\r
+  SetReadHandler(0x6000,0x7fff,CartBR);\r
+  SetWriteHandler(0x6000,0x7fff,M176Write_WriteSRAM);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+       SetWriteHandler(0xA001,0xA001,M176Write_A001);\r
+       SetWriteHandler(0x5001,0x5001,M176Write_5001);\r
+       SetWriteHandler(0x5010,0x5010,M176Write_5010);\r
+       SetWriteHandler(0x5011,0x5011,M176Write_5011);\r
+  SetWriteHandler(0x5ff1,0x5ff1,M176Write_5FF1);\r
+  SetWriteHandler(0x5ff2,0x5ff2,M176Write_5FF2);\r
+       \r
+       we_sram = 0;\r
+       sbw = 0;\r
+       prg[0] = 0;\r
+       prg[1] = 1;\r
+       prg[2] = (ROM_size-2)&63;\r
+       prg[3] = (ROM_size-1)&63;\r
+  Sync();\r
+}\r
+\r
+\r
+static void M176Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper176_Init(CartInfo *info)\r
+{\r
+  info->Power=M176Power;\r
+  info->Close=M176Close;\r
+\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/177.c b/boards/177.c
new file mode 100644 (file)
index 0000000..6bc81b9
--- /dev/null
@@ -0,0 +1,87 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg;\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr8(0);\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg32(0x8000,reg&0x1f);\r
+  setmirror(((reg&0x20)>>5)^1);\r
+}\r
+\r
+static DECLFW(M177Write)\r
+{\r
+  reg=V;\r
+  Sync();\r
+}\r
+\r
+static void M177Power(void)\r
+{\r
+  reg=0;\r
+  Sync();     \r
+  SetReadHandler(0x6000,0x7fff,CartBR);\r
+  SetWriteHandler(0x6000,0x7fff,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M177Write);\r
+}\r
+\r
+static void M177Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper177_Init(CartInfo *info)\r
+{\r
+  info->Power=M177Power;\r
+  info->Close=M177Close;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/178.c b/boards/178.c
new file mode 100644 (file)
index 0000000..19e1b8d
--- /dev/null
@@ -0,0 +1,101 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[3];\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 3, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setmirror(reg[0]);\r
+  setprg8r(0x10,0x6000,0);\r
+  setchr8(0);\r
+  setprg32(0x8000,(reg[1]+reg[2]));\r
+}\r
+\r
+static DECLFW(M178Write0)\r
+{\r
+  reg[0]=(V&1)^1;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M178Write1)\r
+{\r
+  reg[1]=(V>>1)&0xf;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M178Write2)\r
+{\r
+  reg[2]=(V<<2);\r
+  Sync();\r
+}\r
+\r
+static void M178Power(void)\r
+{\r
+  reg[0]=1; reg[1]=0; reg[2]=0;\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4800,0x4800,M178Write0);\r
+  SetWriteHandler(0x4801,0x4801,M178Write1);\r
+  SetWriteHandler(0x4802,0x4802,M178Write2);\r
+}\r
+\r
+static void M178Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper178_Init(CartInfo *info)\r
+{\r
+  info->Power=M178Power;\r
+  info->Close=M178Close;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/179.c b/boards/179.c
new file mode 100644 (file)
index 0000000..91a530f
--- /dev/null
@@ -0,0 +1,94 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[2];\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 2, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr8(0);\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg32(0x8000,reg[1]>>1);\r
+  setmirror((reg[0]&1)^1);\r
+}\r
+\r
+static DECLFW(M179Write)\r
+{\r
+  if(A==0xa000) reg[0]=V;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M179WriteLo)\r
+{\r
+  if(A==0x5ff1) reg[1]=V;\r
+  Sync();\r
+}\r
+\r
+static void M179Power(void)\r
+{\r
+  reg[0]=reg[1]=0;\r
+  Sync();     \r
+  SetWriteHandler(0x4020,0x5fff,M179WriteLo);\r
+  SetReadHandler(0x6000,0x7fff,CartBR);\r
+  SetWriteHandler(0x6000,0x7fff,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M179Write);\r
+}\r
+\r
+static void M179Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper179_Init(CartInfo *info)\r
+{\r
+  info->Power=M179Power;\r
+  info->Close=M179Close;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 5e80a6b..bf0b7c0 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Gimmick Bootleg (VRC4 mapper)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg[4];\r
+static uint8 chr[8];\r
+static uint8 IRQCount;\r
+static uint8 IRQPre;\r
+static uint8 IRQa;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {prg, 4, "PRG"},\r
+  {chr, 8, "CHR"},\r
+  {&IRQCount, 1, "IRQCOUNT"},\r
+  {&IRQPre, 1, "IRQPRE"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {0}\r
+};\r
+\r
+static void SyncPrg(void)\r
+{\r
+  setprg8(0x6000,0);\r
+  setprg8(0x8000,prg[0]);\r
+  setprg8(0xA000,prg[1]);\r
+  setprg8(0xC000,prg[2]);\r
+  setprg8(0xE000,~0);\r
+}\r
+\r
+static void SyncChr(void)\r
+{\r
+  int i;\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr[i]);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  SyncPrg();\r
+  SyncChr();\r
+}\r
+\r
+static DECLFW(M183Write)\r
+{\r
+  if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C))\r
+  {\r
+    uint8 index=(((A>>11)-6)|(A>>3))&7;\r
+    chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4));\r
+    SyncChr();\r
+  }\r
+  else switch (A&0xF80C)\r
+  {\r
+    case 0x8800: prg[0]=V; SyncPrg(); break;\r
+    case 0xA800: prg[1]=V; SyncPrg(); break;\r
+    case 0xA000: prg[2]=V; SyncPrg(); break;\r
+    case 0x9800: switch (V&3)\r
+                 {\r
+                   case 0: setmirror(MI_V); break;\r
+                   case 1: setmirror(MI_H); break;\r
+                   case 2: setmirror(MI_0); break;\r
+                   case 3: setmirror(MI_1); break;\r
+                 }\r
+                 break;\r
+    case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r
+    case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r
+    case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+    case 0xF00C: IRQPre=16; break;\r
+  }\r
+}\r
+\r
+static void M183IRQCounter(void)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount++;\r
+    if((IRQCount-IRQPre)==238)\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+  }\r
+}\r
+\r
+static void M183Power(void)\r
+{\r
+  IRQPre=IRQCount=IRQa=0;\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M183Write);\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SyncPrg();\r
+  SyncChr();\r
+}\r
+\r
+void Mapper183_Init(CartInfo *info)\r
+{\r
+  info->Power=M183Power;\r
+  GameHBIRQHook=M183IRQCounter;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 49b63dc..b865a8f 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 *DummyCHR=NULL;\r
+static uint8 datareg;\r
+static void(*Sync)(void);\r
+\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&datareg, 1, "DREG"},\r
+  {0}\r
+};\r
+\r
+//   on    off\r
+//1  0x0F, 0xF0 - Bird Week\r
+//2  0x33, 0x00 - B-Wings\r
+//3  0x11, 0x00 - Mighty Bomb Jack\r
+//4  0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen\r
+//5  0xFF, 0x00 - Sansuu 3 Nen\r
+//6  0x21, 0x13 - Spy vs Spy\r
+//7  0x20, 0x21 - Seicross\r
+\r
+static void Sync185(void)\r
+{\r
+  // little dirty eh? ;_)\r
+  if((datareg&3)&&(datareg!=0x13)) // 1, 2, 3, 4, 5, 6\r
+   setchr8(0);\r
+  else\r
+   setchr8r(0x10,0);\r
+}\r
+\r
+static void Sync181(void)\r
+{\r
+  if(!(datareg&1))                      // 7\r
+   setchr8(0);\r
+  else\r
+   setchr8r(0x10,0);\r
+}\r
+\r
+static DECLFW(MWrite)\r
+{\r
+  datareg=V;\r
+  Sync();\r
+}\r
+\r
+static void MPower(void)\r
+{\r
+  datareg=0;\r
+  Sync();\r
+  setprg16(0x8000,0);\r
+  setprg16(0xC000,~0);\r
+  SetWriteHandler(0x8000,0xFFFF,MWrite);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+}\r
+\r
+static void MClose(void)\r
+{\r
+  if(DummyCHR)\r
+    FCEU_gfree(DummyCHR);\r
+  DummyCHR=NULL;\r
+}\r
+\r
+static void MRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper185_Init(CartInfo *info)\r
+{\r
+  int x;\r
+  Sync=Sync185;\r
+  info->Power=MPower;\r
+  info->Close=MClose;\r
+  GameStateRestore=MRestore;\r
+  DummyCHR=(uint8*)FCEU_gmalloc(8192);\r
+  for(x=0;x<8192;x++)\r
+     DummyCHR[x]=0xff;\r
+  SetupCartCHRMapping(0x10,DummyCHR,8192,0);\r
+  AddExState(StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper181_Init(CartInfo *info)\r
+{\r
+  int x;\r
+  Sync=Sync181;\r
+  info->Power=MPower;\r
+  info->Close=MClose;\r
+  GameStateRestore=MRestore;\r
+  DummyCHR=(uint8*)FCEU_gmalloc(8192);\r
+  for(x=0;x<8192;x++)\r
+     DummyCHR[x]=0xff;\r
+  SetupCartCHRMapping(0x10,DummyCHR,8192,0);\r
+  AddExState(StateRegs, ~0, 0, 0);\r
+}\r
index 80b39d8..4976265 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Family Study Box by Fukutake Shoten\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 SWRAM[2816];\r
+static uint8 *WRAM=NULL;\r
+static uint8 regs[4];\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {regs, 4, "DREG"},\r
+  {SWRAM, 2816, "SWRAM"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8r(0x10,0x6000,regs[0]>>6);\r
+  setprg16(0x8000,regs[1]);\r
+  setprg16(0xc000,0);\r
+}\r
+\r
+static DECLFW(M186Write)\r
+{\r
+  if(A&0x4203) regs[A&3]=V;\r
+  Sync();\r
+}\r
+\r
+static DECLFR(M186Read)\r
+{\r
+  switch(A)\r
+  {\r
+    case 0x4200: return 0x00; break;\r
+    case 0x4201: return 0x00; break;\r
+    case 0x4202: return 0x40; break;\r
+    case 0x4203: return 0x00; break;\r
+  }\r
+  return 0xFF;\r
+}\r
+\r
+static DECLFR(ASWRAM)\r
+{\r
+  return(SWRAM[A-0x4400]);\r
+}\r
+static DECLFW(BSWRAM)\r
+{\r
+  SWRAM[A-0x4400]=V;\r
+}\r
+\r
+static void M186Power(void)\r
+{\r
+  setchr8(0);\r
+  SetReadHandler(0x6000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x6000,0xFFFF,CartBW);\r
+  SetReadHandler(0x4200,0x43FF,M186Read);\r
+  SetWriteHandler(0x4200,0x43FF,M186Write);\r
+  SetReadHandler(0x4400,0x4EFF,ASWRAM);\r
+  SetWriteHandler(0x4400,0x4EFF,BSWRAM);\r
+  regs[0]=regs[1]=regs[2]=regs[3];\r
+  Sync();\r
+}\r
+\r
+static void M186Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void M186Restore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper186_Init(CartInfo *info)\r
+{\r
+  info->Power=M186Power;\r
+  info->Close=M186Close;\r
+  GameStateRestore=M186Restore;\r
+  WRAM=(uint8*)FCEU_gmalloc(32768);\r
+  SetupCartPRGMapping(0x10,WRAM,32768,1);\r
+  AddExState(WRAM, 32768, 0, "WRAM");\r
+  AddExState(StateRegs, ~0, 0, 0);\r
+}\r
index 0fa4a15..0f49748 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static void M187CW(uint32 A, uint8 V)\r
+{\r
+  if((A&0x1000)==((MMC3_cmd&0x80)<<5))\r
+    setchr1(A,V|0x100);\r
+  else\r
+    setchr1(A,V);\r
+}\r
+\r
+static void M187PW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x80)\r
+  {\r
+    uint8 bank=EXPREGS[0]&0x1F;\r
+    if(EXPREGS[0]&0x20)\r
+      setprg32(0x8000,bank>>2);\r
+    else\r
+    {\r
+      setprg16(0x8000,bank);\r
+      setprg16(0xC000,bank);\r
+    }\r
+  }\r
+  else\r
+    setprg8(A,V&0x3F);\r
+}\r
+\r
+static DECLFW(M187Write8000)\r
+{\r
+  EXPREGS[2]=1;\r
+  MMC3_CMDWrite(A,V);\r
+}\r
+\r
+static DECLFW(M187Write8001)\r
+{\r
+  if(EXPREGS[2])\r
+    MMC3_CMDWrite(A,V);\r
+}\r
+\r
+static DECLFW(M187Write8003)\r
+{\r
+  EXPREGS[2]=0;\r
+  if(V==0x28)setprg8(0xC000,0x17);\r
+  else if(V==0x2A)setprg8(0xA000,0x0F);\r
+}\r
+\r
+\r
+static DECLFW(M187WriteLo)\r
+{\r
+  EXPREGS[1]=V;\r
+  if(A==0x5000)\r
+  {\r
+    EXPREGS[0]=V;\r
+    FixMMC3PRG(MMC3_cmd);\r
+  }\r
+}\r
+\r
+static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 };\r
+static DECLFR(M187Read)\r
+{\r
+  return prot_data[EXPREGS[1]&3];\r
+}\r
+\r
+static void M187Power(void)\r
+{\r
+  EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0;\r
+  GenMMC3Power();\r
+  SetReadHandler(0x5000,0x5FFF,M187Read);\r
+  SetWriteHandler(0x5000,0x5FFF,M187WriteLo);\r
+  SetWriteHandler(0x8000,0x8000,M187Write8000);\r
+  SetWriteHandler(0x8001,0x8001,M187Write8001);\r
+  SetWriteHandler(0x8003,0x8003,M187Write8003);\r
+}\r
+\r
+void Mapper187_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 256, 0, 0);\r
+  pwrap=M187PW;\r
+  cwrap=M187CW;\r
+  info->Power=M187Power;\r
+  AddExState(EXPREGS, 3, 0, "EXPR");\r
+}\r
index 23be63a..ff045a5 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static void M189PW(uint32 A, uint8 V)\r
+{\r
+  setprg32(0x8000,EXPREGS[0]&3);\r
+}\r
+\r
+static DECLFW(M189Write)\r
+{\r
+  EXPREGS[0]=V|(V>>4); //actually, there is a two versions of 189 mapper with hi or lo bits bankswitching.\r
+  FixMMC3PRG(MMC3_cmd);\r
+}\r
+\r
+static void M189Power(void)\r
+{\r
+  EXPREGS[0]=EXPREGS[1]=0;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x4120,0x7FFF,M189Write);\r
+}\r
+\r
+void Mapper189_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 256, 0, 0);\r
+  pwrap=M189PW;\r
+  info->Power=M189Power;\r
+  AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
diff --git a/boards/199.c b/boards/199.c
new file mode 100644 (file)
index 0000000..ed21278
--- /dev/null
@@ -0,0 +1,97 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Dragon Ball Z 2 - Gekishin Freeza! (C)\r
+ * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C)\r
+ * San Guo Zhi 2 (C)\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 *CHRRAM=NULL; // and here too\r
+\r
+static void M199PW(uint32 A, uint8 V)\r
+{\r
+  setprg8(A,V);\r
+  setprg8(0xC000,EXPREGS[0]);\r
+  setprg8(0xE000,EXPREGS[1]);\r
+}\r
+\r
+static void M199CW(uint32 A, uint8 V)\r
+{\r
+  setchr1r((V<8)?0x10:0x00,A,V);\r
+  setchr1r((DRegBuf[0]<8)?0x10:0x00,0x0000,DRegBuf[0]);\r
+  setchr1r((EXPREGS[2]<8)?0x10:0x00,0x0400,EXPREGS[2]);\r
+  setchr1r((DRegBuf[1]<8)?0x10:0x00,0x0800,DRegBuf[1]);\r
+  setchr1r((EXPREGS[3]<8)?0x10:0x00,0x0c00,EXPREGS[3]);\r
+}\r
+\r
+static void M199MW(uint8 V)\r
+{\r
+//    FCEU_printf("%02x\n",V);\r
+  switch(V&3)\r
+  {\r
+    case 0: setmirror(MI_V); break;\r
+    case 1: setmirror(MI_H); break;\r
+    case 2: setmirror(MI_0); break;\r
+    case 3: setmirror(MI_1); break;\r
+  }\r
+}\r
+\r
+static DECLFW(M199Write)\r
+{\r
+  if((A==0x8001)&&(MMC3_cmd&8))\r
+  {\r
+//    FCEU_printf("%02x=>%02x\n",MMC3_cmd,V);\r
+    EXPREGS[MMC3_cmd&3]=V;\r
+    FixMMC3PRG(MMC3_cmd);\r
+    FixMMC3CHR(MMC3_cmd);\r
+  }\r
+  else    \r
+    if(A<0xC000)\r
+      MMC3_CMDWrite(A,V);\r
+    else\r
+      MMC3_IRQWrite(A,V);\r
+}\r
+\r
+static void M199Power(void)\r
+{\r
+  EXPREGS[0]=~1;\r
+  EXPREGS[1]=~0;\r
+  EXPREGS[2]=1;\r
+  EXPREGS[3]=3;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x8000,0xFFFF,M199Write);\r
+}\r
+\r
+void Mapper199_Init(CartInfo *info)\r
+{\r
+  int CHRRAMSize=1024*8;\r
+  GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+  cwrap=M199CW;\r
+  pwrap=M199PW;\r
+  mwrap=M199MW;\r
+  info->Power=M199Power;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+  SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+  AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+  AddExState(EXPREGS, 4, 0, "EXPR");\r
+}\r
index 9ccf8e7..3bbb34d 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 lut[256]={\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,\r
+  0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,\r
+  0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,\r
+  0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+};\r
+\r
+static void M208PW(uint32 A, uint8 V)\r
+{\r
+  setprg32(0x8000,EXPREGS[5]);\r
+}\r
+\r
+static DECLFW(M208Write)\r
+{\r
+  EXPREGS[5]=(V&0x1)|((V>>3)&0x2);\r
+  FixMMC3PRG(MMC3_cmd);\r
+}\r
+\r
+static DECLFW(M208ProtWrite)\r
+{\r
+  if(A<=0x57FF)\r
+    EXPREGS[4]=V;\r
+  else\r
+    EXPREGS[(A&0x03)]=V^lut[EXPREGS[4]];\r
+}\r
+\r
+static DECLFR(M208ProtRead)\r
+{\r
+  return(EXPREGS[(A&0x3)]);\r
+}\r
+\r
+static void M208Power(void)\r
+{\r
+  EXPREGS[5]=3;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x4800,0x4FFF,M208Write);\r
+  SetWriteHandler(0x5000,0x5fff,M208ProtWrite);\r
+  SetReadHandler(0x5800,0x5FFF,M208ProtRead);\r
+  SetReadHandler(0x8000,0xffff,CartBR);\r
+}\r
+\r
+void Mapper208_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 256, 0, 0);\r
+  pwrap=M208PW;\r
+  info->Power=M208Power;\r
+  AddExState(EXPREGS, 6, 0, "EXPR");\r
+}\r
index fd3cc8a..e230751 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * (VRC4 mapper)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 IRQCount;\r
+static uint8 IRQa;\r
+static uint8 prg_reg[2];\r
+static uint8 chr_reg[8];\r
+static uint8 mirr;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQCount, 1, "IRQC"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {prg_reg, 2, "PRG"},\r
+  {chr_reg, 8, "CHR"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void M222IRQ(void)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount++;\r
+    if(IRQCount>=238)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+//      IRQa=0;\r
+    }\r
+  }\r
+}\r
+\r
+static void Sync(void)\r
+{\r
+  int i;\r
+  setprg8(0x8000,prg_reg[0]);\r
+  setprg8(0xA000,prg_reg[1]);\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr_reg[i]);\r
+  setmirror(mirr^1);\r
+}\r
+\r
+static DECLFW(M222Write)\r
+{\r
+  switch(A&0xF003)\r
+  {\r
+    case 0x8000: prg_reg[0]=V; break;\r
+    case 0x9000: mirr=V&1;     break;\r
+    case 0xA000: prg_reg[1]=V; break;\r
+    case 0xB000: chr_reg[0]=V; break;\r
+    case 0xB002: chr_reg[1]=V; break;\r
+    case 0xC000: chr_reg[2]=V; break;\r
+    case 0xC002: chr_reg[3]=V; break;\r
+    case 0xD000: chr_reg[4]=V; break;\r
+    case 0xD002: chr_reg[5]=V; break;\r
+    case 0xE000: chr_reg[6]=V; break;\r
+    case 0xE002: chr_reg[7]=V; break;\r
+//    case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+//  /  case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break;\r
+//    case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;\r
+//    case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;\r
+//    case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;\r
+    case 0xF000: IRQa=IRQCount=V; if(scanline<240) IRQCount-=8; else IRQCount+=4; X6502_IRQEnd(FCEU_IQEXT); break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void M222Power(void)\r
+{\r
+  setprg16(0xC000,~0);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M222Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper222_Init(CartInfo *info)\r
+{\r
+  info->Power=M222Power;\r
+  GameHBIRQHook=M222IRQ;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/23.c b/boards/23.c
new file mode 100644 (file)
index 0000000..8760d50
--- /dev/null
@@ -0,0 +1,208 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 is23;\r
+static uint16 IRQCount;\r
+static uint8 IRQLatch,IRQa;\r
+static uint8 prgreg[2];\r
+static uint8 chrreg[8];\r
+static uint8 regcmd, irqcmd, mirr, big_bank;\r
+static uint16 acount=0;\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {prgreg, 2, "PRGREGS"},\r
+  {chrreg, 8, "CHRREGS"},\r
+  {&regcmd, 1, "REGCMD"},\r
+  {&irqcmd, 1, "IRQCMD"},\r
+  {&mirr, 1, "MIRR"},\r
+  {&big_bank, 1, "BIGB"},\r
+  {&IRQCount, 2, "IRCN"},\r
+  {&IRQLatch, 1, "IRQL"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  if(regcmd&2)\r
+  {\r
+    setprg8(0xC000,prgreg[0]|big_bank);\r
+    setprg8(0x8000,((~1)&0x1F)|big_bank);\r
+  }\r
+  else\r
+  {\r
+    setprg8(0x8000,prgreg[0]|big_bank);\r
+    setprg8(0xC000,((~1)&0x1F)|big_bank);\r
+  }\r
+  setprg8(0xA000,prgreg[1]|big_bank);\r
+  setprg8(0xE000,((~0)&0x1F)|big_bank);\r
+  if(UNIFchrrama)\r
+    setchr8(0);\r
+  else\r
+  {\r
+    uint8 i;\r
+    for(i=0; i<8; i++)\r
+       setchr1(i<<10, chrreg[i]);\r
+  }\r
+  switch(mirr&0x3)\r
+  {\r
+    case 0: setmirror(MI_V); break;\r
+    case 1: setmirror(MI_H); break;\r
+    case 2: setmirror(MI_0); break;\r
+    case 3: setmirror(MI_1); break;\r
+  }\r
+}\r
+\r
+static DECLFW(M23Write)\r
+{\r
+//  FCEU_printf("%04x:%04x\n",A,V);\r
+  A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); // actually there is many-in-one mapper source, some pirate or\r
+                                             // licensed games use various address bits for registers\r
+  A&=0xF003;\r
+  if((A>=0xB000)&&(A<=0xE003))\r
+  {\r
+    if(UNIFchrrama)\r
+      big_bank=(V&8)<<2;                    // my personally many-in-one feature ;) just for support pirate cart 2-in-1\r
+    else\r
+    {    \r
+      uint16 i=((A>>1)&1)|((A-0xB000)>>11);\r
+      chrreg[i]&=(0xF0)>>((A&1)<<2);\r
+      chrreg[i]|=(V&0xF)<<((A&1)<<2);\r
+    }\r
+    Sync();\r
+  }\r
+  else\r
+    switch(A&0xF003)\r
+    {\r
+      case 0x8000: \r
+      case 0x8001: \r
+      case 0x8002: \r
+      case 0x8003: if(is23) \r
+                     prgreg[0]=V&0x1F; \r
+                   Sync(); \r
+                   break;\r
+      case 0xA000: \r
+      case 0xA001: \r
+      case 0xA002: \r
+      case 0xA003: if(is23) \r
+                     prgreg[1]=V&0x1F; \r
+                   else\r
+                   {\r
+                     prgreg[0]=(V<<1)&0x1F;\r
+                     prgreg[1]=((V<<1)&0x1F)|1;\r
+                   }\r
+                   Sync();\r
+                   break;\r
+      case 0x9000:\r
+      case 0x9001: if(V!=0xFF) mirr=V; Sync(); break;\r
+      case 0x9002: \r
+      case 0x9003: regcmd=V; Sync(); break;\r
+      case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0xF0; IRQLatch|=V&0xF; break;\r
+      case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0x0F; IRQLatch|=V<<4; break;\r
+      case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount=0; IRQCount=IRQLatch; IRQa=V&2; irqcmd=V&1; break;\r
+      case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa=irqcmd; break;\r
+    }\r
+}\r
+\r
+static void M23Power(void)\r
+{\r
+  big_bank=0x20;  \r
+  Sync();\r
+  setprg8r(0x10,0x6000,0);              // another many-in-one code, WRAM actually contain only WaiWaiWorld game\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M23Write);\r
+}\r
+\r
+static void M23Reset(void)\r
+{\r
+}\r
+\r
+void M23IRQHook(int a)\r
+{\r
+  #define LCYCS 341\r
+  if(IRQa)\r
+  {\r
+    acount+=a*3;\r
+    if(acount>=LCYCS)\r
+    {\r
+      while(acount>=LCYCS)\r
+      {\r
+        acount-=LCYCS;\r
+        IRQCount++;\r
+        if(IRQCount&0x100) \r
+        {\r
+          X6502_IRQBegin(FCEU_IQEXT);\r
+          IRQCount=IRQLatch;\r
+        }\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+static void M23Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+}\r
+\r
+void Mapper23_Init(CartInfo *info)\r
+{\r
+  is23=1;\r
+  info->Power=M23Power;\r
+  info->Close=M23Close;\r
+  MapIRQHook=M23IRQHook;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void UNLT230_Init(CartInfo *info)\r
+{\r
+  is23=0;\r
+  info->Power=M23Power;\r
+  info->Close=M23Close;\r
+  MapIRQHook=M23IRQHook;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 34bbc0f..4cae946 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 cmdreg;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&cmdreg, 2, "CMDREG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  if(cmdreg&0x400)\r
+    setmirror(MI_0);\r
+  else\r
+    setmirror(((cmdreg>>13)&1)^1);\r
+  if(cmdreg&0x800)\r
+  {\r
+    setprg16(0x8000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1));\r
+    setprg16(0xC000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1));\r
+  }\r
+  else\r
+    setprg32(0x8000,((cmdreg&0x300)>>4)|(cmdreg&0x1F));\r
+}\r
+\r
+static DECLFW(M235Write)\r
+{\r
+  cmdreg=A;\r
+  Sync();\r
+}\r
+\r
+static void M235Power(void)\r
+{\r
+  setchr8(0);\r
+  SetWriteHandler(0x8000,0xFFFF,M235Write);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  cmdreg=0;\r
+  Sync();\r
+}\r
+\r
+static void M235Restore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper235_Init(CartInfo *info)\r
+{\r
+  info->Power=M235Power;\r
+  GameStateRestore=M235Restore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/253.c b/boards/253.c
new file mode 100644 (file)
index 0000000..6e3b569
--- /dev/null
@@ -0,0 +1,175 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2009 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock;\r
+static int32 IRQa, IRQCount, IRQLatch, IRQClock; \r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+static uint8 *CHRRAM=NULL;\r
+static uint32 CHRRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {chrlo, 8, "CHRLO"},\r
+  {chrhi, 8, "CHRHI"},\r
+  {prg, 2, "PRGR"},\r
+  {&mirr, 1, "MIRR"},\r
+  {&vlock, 1, "VLOCK"},\r
+  {&IRQa, 4, "IRQA"},\r
+  {&IRQCount, 4, "IRQC"},\r
+  {&IRQLatch, 4, "IRQL"},\r
+  {&IRQClock, 4, "IRQK"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint8 i;\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg8(0x8000,prg[0]);\r
+  setprg8(0xa000,prg[1]);\r
+  setprg8(0xc000,~1);\r
+  setprg8(0xe000,~0);\r
+  for(i=0; i<8; i++)\r
+  {\r
+    uint32 chr = chrlo[i]|(chrhi[i]<<8);\r
+    if(chrlo[i]==0xc8)\r
+    {\r
+      vlock = 0;\r
+      continue;\r
+    }\r
+    else if(chrlo[i]==0x88)\r
+    {\r
+      vlock = 1;\r
+      continue;\r
+    }\r
+    if(((chrlo[i]==4)||(chrlo[i]==5))&&!vlock)\r
+      setchr1r(0x10,i<<10,chr&1);\r
+    else\r
+      setchr1(i<<10,chr);\r
+  }\r
+  switch(mirr)\r
+  {\r
+    case 0: setmirror(MI_V); break;\r
+    case 1: setmirror(MI_H); break;\r
+    case 2: setmirror(MI_0); break;\r
+    case 3: setmirror(MI_1); break;\r
+  }\r
+}\r
+\r
+static DECLFW(M253Write)\r
+{\r
+  if((A>=0xB000)&&(A<=0xE00C))\r
+  {\r
+    uint8 ind=((((A&8)|(A>>8))>>3)+2)&7;\r
+    uint8 sar=A&4;\r
+    chrlo[ind]=(chrlo[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r
+    if(A&4)\r
+      chrhi[ind]=V>>4;\r
+    Sync();\r
+  }\r
+  else\r
+   switch(A)\r
+    {\r
+      case 0x8010: prg[0]=V; Sync(); break;\r
+      case 0xA010: prg[1]=V; Sync(); break;\r
+      case 0x9400: mirr=V&3; Sync(); break;\r
+      case 0xF000: IRQLatch = (IRQLatch & 0xF0) | (V & 0x0F); break;\r
+      case 0xF004: IRQLatch = (IRQLatch & 0x0F) | (V << 4); break;\r
+      case 0xF008:\r
+        IRQa = V&3;\r
+        if(IRQa&2)\r
+        {\r
+          IRQCount = IRQLatch;\r
+          IRQClock = 0;\r
+        }\r
+        X6502_IRQEnd(FCEU_IQEXT);\r
+        break;\r
+    }\r
+}\r
+\r
+static void M253Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M253Write);\r
+}\r
+\r
+static void M253Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  WRAM=CHRRAM=NULL;\r
+}\r
+\r
+static void M253IRQ(int cycles)\r
+{\r
+  if(IRQa&2) \r
+  {\r
+    if((IRQClock+=cycles)>=0x72) \r
+    {\r
+      IRQClock -= 0x72;\r
+      if(IRQCount==0xFF)  \r
+      {\r
+        IRQCount = IRQLatch;\r
+        IRQa = IRQa|((IRQa&1)<<1);\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+      }\r
+      else \r
+        IRQCount++;\r
+    }\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper253_Init(CartInfo *info)\r
+{\r
+  info->Power=M253Power;\r
+  info->Close=M253Close;\r
+  MapIRQHook=M253IRQ;\r
+  GameStateRestore=StateRestore;\r
+\r
+  CHRRAMSIZE=4096;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE);\r
+  SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1);\r
+  AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM");\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/3d-block.c b/boards/3d-block.c
new file mode 100644 (file)
index 0000000..24572a4
--- /dev/null
@@ -0,0 +1,110 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[4], IRQa;\r
+static int16 IRQCount, IRQPause;\r
+\r
+static int16 Count = 0x0000;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 4, "REGS"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 2, "IRQC"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg32(0x8000,0);\r
+  setchr8(0);\r
+}\r
+\r
+//#define Count 0x1800\r
+#define Pause 0x010\r
+\r
+static DECLFW(UNL3DBlockWrite)\r
+{\r
+  switch(A)\r
+  {\r
+//4800 32\r
+//4900 37\r
+//4a00 01\r
+//4e00 18\r
+    case 0x4800: reg[0]=V; break;\r
+    case 0x4900: reg[1]=V; break;\r
+    case 0x4a00: reg[2]=V; break;\r
+    case 0x4e00: reg[3]=V; IRQCount=Count; IRQPause=Pause; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break;\r
+  } \r
+}\r
+\r
+static void UNL3DBlockPower(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4800,0x4E00,UNL3DBlockWrite);\r
+}\r
+\r
+static void UNL3DBlockReset(void)\r
+{\r
+  Count+=0x10;\r
+  FCEU_printf("Count=%04x\n",Count);\r
+}\r
+\r
+static void UNL3DBlockIRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    if(IRQCount>0)\r
+    {\r
+      IRQCount-=a;\r
+    }\r
+    else\r
+    {\r
+      if(IRQPause>0)\r
+      {\r
+        IRQPause-=a;\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+      }\r
+      else\r
+      {\r
+        IRQCount=Count; \r
+        IRQPause=Pause;\r
+        X6502_IRQEnd(FCEU_IQEXT);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNL3DBlock_Init(CartInfo *info)\r
+{\r
+  info->Power=UNL3DBlockPower;\r
+  info->Reset=UNL3DBlockReset;\r
+  MapIRQHook=UNL3DBlockIRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/411120-c.c b/boards/411120-c.c
new file mode 100644 (file)
index 0000000..479a9bf
--- /dev/null
@@ -0,0 +1,70 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2008 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+// actually cart ID is 811120-C, sorry ;) K-3094 - another ID\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 reset_flag = 0;\r
+\r
+static void BMC411120CCW(uint32 A, uint8 V)\r
+{\r
+    setchr1(A,V|((EXPREGS[0]&3)<<7));\r
+}\r
+\r
+static void BMC411120CPW(uint32 A, uint8 V)\r
+{\r
+    if(EXPREGS[0]&(8|reset_flag))\r
+      setprg32(0x8000,((EXPREGS[0]>>4)&3)|(0x0C));\r
+    else\r
+      setprg8(A,(V&0x0F)|((EXPREGS[0]&3)<<4));\r
+}\r
+\r
+static DECLFW(BMC411120CLoWrite)\r
+{\r
+  EXPREGS[0] = A;\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void BMC411120CReset(void)\r
+{\r
+  EXPREGS[0]=0;\r
+  reset_flag ^=4;\r
+  MMC3RegReset();\r
+}\r
+\r
+static void BMC411120CPower(void)\r
+{\r
+  EXPREGS[0] = 0;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x6000,0x7FFF,BMC411120CLoWrite);\r
+}\r
+\r
+void BMC411120C_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 128, 8, 0);\r
+  pwrap=BMC411120CPW;\r
+  cwrap=BMC411120CCW;\r
+  info->Power=BMC411120CPower;\r
+  info->Reset=BMC411120CReset;\r
+  AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
diff --git a/boards/43.c b/boards/43.c
new file mode 100644 (file)
index 0000000..ee12dec
--- /dev/null
@@ -0,0 +1,94 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+//ccording to nestopia, BTL_SMB2_C, otherwise known as UNL-SMB2J\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg;\r
+static uint8 IRQa;\r
+static uint32 IRQCount;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQCount, 4, "IRQC"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&reg, 1, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg4(0x5000,16);  \r
+  setprg8(0x6000,2);\r
+  setprg8(0x8000,1);\r
+  setprg8(0xa000,0);\r
+  setprg8(0xc000,reg);\r
+  setprg8(0xe000,9);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(M43Write)\r
+{\r
+  int transo[8]={4,3,4,4,4,7,5,6};\r
+  switch(A&0xf1ff)\r
+  {\r
+    case 0x4022: reg=transo[V&7]; Sync(); break;\r
+    case 0x8122: IRQa=V&1; IRQCount=0; break;\r
+  }\r
+}\r
+\r
+static void M43Power(void)\r
+{\r
+  reg=0;\r
+  Sync();\r
+//  SetReadHandler(0x5000,0x5fff,CartBR);\r
+  SetReadHandler(0x5000,0xffff,CartBR);\r
+  SetWriteHandler(0x4020,0xffff,M43Write);\r
+}\r
+\r
+static void M43Reset(void)\r
+{\r
+}\r
+\r
+static void M43IRQHook(int a)\r
+{\r
+ IRQCount+=a;\r
+ if(IRQa)\r
+  if(IRQCount>=4096)\r
+  {\r
+   IRQa=0;\r
+   X6502_IRQBegin(FCEU_IQEXT);\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper43_Init(CartInfo *info)\r
+{\r
+  info->Reset=M43Reset;\r
+  info->Power=M43Power;\r
+  MapIRQHook=M43IRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 693677d..ba5de0b 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg_reg;\r
+static uint8 chr_reg;\r
+static uint8 hrd_flag;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&hrd_flag, 1, "DIPSW"},\r
+  {&prg_reg, 1, "PRG"},\r
+  {&chr_reg, 1, "CHR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  if(prg_reg&0x80)\r
+    setprg32(0x8000,prg_reg>>6);\r
+  else\r
+  {\r
+    setprg16(0x8000,(prg_reg>>5)&3);\r
+    setprg16(0xC000,(prg_reg>>5)&3);\r
+  }\r
+  setmirror((prg_reg&8)>>3);\r
+  setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1));\r
+}\r
+\r
+static DECLFR(M57Read)\r
+{\r
+  return hrd_flag;\r
+}\r
+\r
+static DECLFW(M57Write)\r
+{\r
+  if((A&0x8800)==0x8800)\r
+    prg_reg=V;\r
+  else\r
+    chr_reg=V;\r
+  Sync();\r
+}\r
+\r
+static void M57Power(void)\r
+{\r
+  prg_reg=0;\r
+  chr_reg=0;\r
+  hrd_flag=0;\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M57Write);\r
+  SetReadHandler(0x6000,0x6000,M57Read);\r
+  Sync();\r
+}\r
+\r
+static void M57Reset()\r
+{\r
+  hrd_flag++;\r
+  hrd_flag&=3;\r
+  FCEU_printf("Select Register = %02x\n",hrd_flag);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper57_Init(CartInfo *info)\r
+{\r
+  info->Power=M57Power;\r
+  info->Reset=M57Reset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
similarity index 54%
rename from boards/cc21.c
rename to boards/603-5052.c
index 0e2cbe6..43b4e0a 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 };\r
+\r
+static DECLFW(UNL6035052ProtWrite)\r
+{\r
+  EXPREGS[0]=lut[V&3];  \r
+}\r
+\r
+static DECLFR(UNL6035052ProtRead)\r
+{\r
+  return EXPREGS[0];\r
+}\r
+\r
+static void UNL6035052Power(void)\r
+{\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x4020,0x7FFF,UNL6035052ProtWrite);\r
+  SetReadHandler(0x4020,0x7FFF,UNL6035052ProtRead);\r
+}\r
+\r
+void UNL6035052_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 256, 0, 0);\r
+  info->Power=UNL6035052Power;\r
+  AddExState(EXPREGS, 6, 0, "EXPR");\r
+}\r
diff --git a/boards/68.c b/boards/68.c
new file mode 100644 (file)
index 0000000..6a9420c
--- /dev/null
@@ -0,0 +1,178 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 chr_reg[4];\r
+static uint8 kogame, prg_reg, nt1, nt2, mirr;\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE, count;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&nt1, 1, "NT1"},\r
+  {&nt2, 1, "NT2"},\r
+  {&mirr, 1, "MIRR"},\r
+  {&prg_reg, 1, "PRG"},\r
+  {&kogame, 1, "KOGAME"},\r
+  {&count, 4, "COUNT"},\r
+  {chr_reg, 4, "CHR"},\r
+  {0}\r
+};\r
+\r
+static void M68NTfix(void)\r
+{\r
+  if((!UNIFchrrama)&&(mirr&0x10))\r
+  {\r
+    PPUNTARAM = 0;\r
+    switch(mirr&3)\r
+    {\r
+     case 0: vnapage[0]=vnapage[2]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10);\r
+             vnapage[1]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10);\r
+             break;\r
+     case 1: vnapage[0]=vnapage[1]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10);\r
+             vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10);\r
+             break;\r
+     case 2: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10);\r
+             break;\r
+     case 3: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10);\r
+             break;\r
+    }\r
+  }\r
+  else\r
+    switch(mirr&3)\r
+    {\r
+      case 0: setmirror(MI_V); break;\r
+      case 1: setmirror(MI_H); break;\r
+      case 2: setmirror(MI_0); break;\r
+      case 3: setmirror(MI_1); break;\r
+    }\r
+}\r
+\r
+static void Sync(void)\r
+{\r
+  setchr2(0x0000,chr_reg[0]);\r
+  setchr2(0x0800,chr_reg[1]);\r
+  setchr2(0x1000,chr_reg[2]);\r
+  setchr2(0x1800,chr_reg[3]);\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg);\r
+  setprg16(0xC000,~0);\r
+}\r
+\r
+static DECLFR(M68Read)\r
+{\r
+  if(!(kogame&8))\r
+  {\r
+    count++;\r
+    if(count==1784)\r
+      setprg16r(0,0x8000,prg_reg);\r
+  }\r
+  return CartBR(A);\r
+}\r
+\r
+static DECLFW(M68WriteLo)\r
+{\r
+  if(!V)\r
+  { \r
+    count = 0;\r
+    setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg);\r
+  }\r
+}\r
+\r
+static DECLFW(M68WriteCHR)\r
+{\r
+  chr_reg[(A>>12)&3]=V;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M68WriteNT1)\r
+{\r
+  nt1 = V;            \r
+  M68NTfix();\r
+}\r
+\r
+static DECLFW(M68WriteNT2)\r
+{\r
+  nt2 = V;            \r
+  M68NTfix();\r
+}\r
+\r
+static DECLFW(M68WriteMIR)\r
+{\r
+  mirr = V;\r
+  M68NTfix();\r
+}\r
+\r
+static DECLFW(M68WriteROM)\r
+{\r
+  prg_reg = V&7;\r
+  kogame = ((V>>3)&1)^1;\r
+  Sync();\r
+}\r
+\r
+static void M68Power(void)\r
+{\r
+  prg_reg = 0;\r
+  kogame = 0;\r
+  Sync();\r
+  M68NTfix();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xBFFF,M68Read);\r
+  SetReadHandler(0xC000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xBFFF,M68WriteCHR);\r
+  SetWriteHandler(0xC000,0xCFFF,M68WriteNT1);\r
+  SetWriteHandler(0xD000,0xDFFF,M68WriteNT2);\r
+  SetWriteHandler(0xE000,0xEFFF,M68WriteMIR);\r
+  SetWriteHandler(0xF000,0xFFFF,M68WriteROM);\r
+  SetWriteHandler(0x6000,0x6000,M68WriteLo);\r
+  SetWriteHandler(0x6001,0x7FFF,CartBW);\r
+}\r
+\r
+static void M68Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+  M68NTfix();\r
+}\r
+\r
+void Mapper68_Init(CartInfo *info)\r
+{\r
+  info->Power=M68Power;\r
+  info->Close=M68Close;\r
+  GameStateRestore=StateRestore;\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 2aa3f4e..1b23023 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 cmdreg;\r
+static uint8 invalid_data;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&invalid_data, 1, "INVD"},  \r
+  {&cmdreg, 2, "CMDREG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2);\r
+  setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0);\r
+  setmirror(((cmdreg&2)>>1)^1);\r
+}\r
+\r
+static DECLFR(UNL8157Read)\r
+{\r
+  if(invalid_data&&cmdreg&0x100)\r
+    return 0xFF;\r
+  else\r
+    return CartBR(A);\r
+}\r
+\r
+static DECLFW(UNL8157Write)\r
+{\r
+  cmdreg=A;\r
+  Sync();\r
+}\r
+\r
+static void UNL8157Power(void)\r
+{\r
+  setchr8(0);\r
+  SetWriteHandler(0x8000,0xFFFF,UNL8157Write);\r
+  SetReadHandler(0x8000,0xFFFF,UNL8157Read);\r
+  cmdreg=0x200;\r
+  invalid_data=1;\r
+  Sync();\r
+}\r
+\r
+static void UNL8157Reset(void)\r
+{\r
+  cmdreg=0;\r
+  invalid_data^=1;\r
+  Sync();\r
+}\r
+\r
+static void UNL8157Restore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNL8157_Init(CartInfo *info)\r
+{\r
+  info->Power=UNL8157Power;\r
+  info->Reset=UNL8157Reset;\r
+  GameStateRestore=UNL8157Restore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 5b4e2df..0415338 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005-2011 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Super Game (Sugar Softec) protected mapper\r
+ * Pocahontas 2 (Unl) [U][!], etc.\r
+ * TODO: 9in1 LION KING HANGS!\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 cmdin;\r
+\r
+static uint8 regperm[8][8] = \r
+  {\r
+    {0, 1, 2, 3, 4, 5, 6, 7},\r
+    {0, 2, 6, 1, 7, 3, 4, 5},\r
+    {0, 5, 4, 1, 7, 2, 6, 3}, // unused\r
+    {0, 6, 3, 7, 5, 2, 4, 1},\r
+    {0, 2, 5, 3, 6, 1, 7, 4},\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // empty\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // empty\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // empty\r
+  };\r
+\r
+static uint8 adrperm[8][8] = \r
+  {\r
+    {0, 1, 2, 3, 4, 5, 6, 7},\r
+    {3, 2, 0, 4, 1, 5, 6, 7},\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // unused\r
+    {5, 0, 1, 2, 3, 7, 6, 4},\r
+    {3, 1, 0, 5, 2, 4, 6, 7},\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // empty\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // empty\r
+    {0, 1, 2, 3, 4, 5, 6, 7}, // empty\r
+  };\r
+\r
+static void UNL8237CW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+    setchr1(A,((EXPREGS[1]&0xc)<<6)|(V&0x7F)|((EXPREGS[1]&0x20)<<2));\r
+  else\r
+    setchr1(A,((EXPREGS[1]&0xc)<<6)|V);\r
+}\r
+\r
+static void UNL8237PW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+  {\r
+    uint8 sbank = (EXPREGS[1]&0x10);\r
+    if(EXPREGS[0]&0x80)\r
+    {\r
+      uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0x7)|(sbank>>1);\r
+      if(EXPREGS[0]&0x20)\r
+        setprg32(0x8000,bank>>1);\r
+      else\r
+      {\r
+        setprg16(0x8000,bank);\r
+        setprg16(0xC000,bank);\r
+      }\r
+    }\r
+    else\r
+      setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x0F)|sbank);\r
+  }\r
+  else\r
+  {\r
+    if(EXPREGS[0]&0x80)\r
+    {\r
+      uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0xF);\r
+      if(EXPREGS[0]&0x20)\r
+        setprg32(0x8000,bank>>1);\r
+      else\r
+      {\r
+        setprg16(0x8000,bank);\r
+        setprg16(0xC000,bank);\r
+      }\r
+    }\r
+    else\r
+      setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x1F));\r
+  }\r
+}\r
+\r
+static void UNL8237ACW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+    setchr1(A,((EXPREGS[1]&0xE)<<7)|(V&0x7F)|((EXPREGS[1]&0x20)<<2));\r
+  else\r
+    setchr1(A,((EXPREGS[1]&0xE)<<7)|V);\r
+}\r
+\r
+static void UNL8237APW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+  {\r
+    uint8 sbank = (EXPREGS[1]&0x10);\r
+    if(EXPREGS[0]&0x80)\r
+    {\r
+      uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0x7)|(sbank>>1);\r
+      if(EXPREGS[0]&0x20)\r
+        setprg32(0x8000,bank>>1);\r
+      else\r
+      {\r
+        setprg16(0x8000,bank);\r
+        setprg16(0xC000,bank);\r
+      }\r
+    }\r
+    else\r
+      setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank);\r
+  }\r
+  else\r
+  {\r
+    if(EXPREGS[0]&0x80)\r
+    {\r
+      uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0xF);\r
+      if(EXPREGS[0]&0x20)\r
+        setprg32(0x8000,bank>>1);\r
+      else\r
+      {\r
+        setprg16(0x8000,bank);\r
+        setprg16(0xC000,bank);\r
+      }\r
+    }\r
+    else\r
+      setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F));\r
+  }\r
+}\r
+static DECLFW(UNL8237Write)\r
+{\r
+  uint8 dat = V;\r
+  uint8 adr = adrperm[EXPREGS[2]][((A>>12)&6)|(A&1)];\r
+  uint16 addr = (adr & 1)|((adr & 6)<<12)|0x8000;\r
+  if(adr < 4)\r
+  {\r
+    if(!adr)\r
+      dat = (dat & 0xC0)|(regperm[EXPREGS[2]][dat & 7]);\r
+    MMC3_CMDWrite(addr,dat);\r
+  }\r
+  else \r
+    MMC3_IRQWrite(addr,dat);\r
+}\r
+\r
+static DECLFW(UNL8237ExWrite)\r
+{\r
+  switch(A)\r
+  {\r
+    case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break;\r
+    case 0x5001: EXPREGS[1]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break;\r
+    case 0x5007: EXPREGS[2]=V; break;\r
+  }\r
+}\r
+\r
+static void UNL8237Power(void)\r
+{\r
+  EXPREGS[0]=EXPREGS[2]=0;\r
+  EXPREGS[1]=3;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x8000,0xFFFF,UNL8237Write);\r
+  SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite);\r
+}\r
+\r
+void UNL8237_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 256, 0, 0);\r
+  cwrap=UNL8237CW;\r
+  pwrap=UNL8237PW;\r
+  info->Power=UNL8237Power;\r
+  AddExState(EXPREGS, 3, 0, "EXPR");\r
+  AddExState(&cmdin, 1, 0, "CMDIN");\r
+}\r
+\r
+void UNL8237A_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 256, 0, 0);\r
+  cwrap=UNL8237ACW;\r
+  pwrap=UNL8237APW;\r
+  info->Power=UNL8237Power;\r
+  AddExState(EXPREGS, 3, 0, "EXPR");\r
+  AddExState(&cmdin, 1, 0, "CMDIN");\r
+}\r
diff --git a/boards/830118C.c b/boards/830118C.c
new file mode 100644 (file)
index 0000000..8b6ce60
--- /dev/null
@@ -0,0 +1,82 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2008 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+// M-022 MMC3 based 830118C T-106 4M + 4M\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 reset_flag = 0;\r
+\r
+static void BMC830118CCW(uint32 A, uint8 V)\r
+{\r
+    setchr1(A,(V&0x7F)|((EXPREGS[0]&0x0c)<<5));\r
+}\r
+\r
+static void BMC830118CPW(uint32 A, uint8 V)\r
+{\r
+      if((EXPREGS[0]&0x0C)==0x0C) \r
+      {  \r
+         if(A==0x8000)\r
+         {\r
+           setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));\r
+           setprg8(0xC000,(V&0x0F)|0x32);\r
+         }\r
+         else if(A==0xA000)\r
+         {\r
+           setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));\r
+           setprg8(0xE000,(V&0x0F)|0x32);\r
+         }\r
+      }\r
+      else\r
+      {\r
+         setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));\r
+      }\r
+}\r
+\r
+static DECLFW(BMC830118CLoWrite)\r
+{\r
+  EXPREGS[0] = V;\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void BMC830118CReset(void)\r
+{\r
+  EXPREGS[0]=0;\r
+  MMC3RegReset();\r
+}\r
+\r
+static void BMC830118CPower(void)\r
+{\r
+  EXPREGS[0] = 0;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x6800,0x68FF,BMC830118CLoWrite);\r
+}\r
+\r
+void BMC830118C_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 128, 8, 0);\r
+  pwrap=BMC830118CPW;\r
+  cwrap=BMC830118CCW;\r
+  info->Power=BMC830118CPower;\r
+  info->Reset=BMC830118CReset;\r
+  AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
index 03fbf5b..88d45ce 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 994910d..caccc09 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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
 
  */
 
 #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
 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 chrlow[8];
 static uint8 chrhigh[8];
 
+static uint8 chr[2];
+
 static uint16 names[4];
 static uint8 tekker;
 
 static SFORMAT Tek_StateRegs[]={
 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"},
   {&IRQCount, 1, "IRQC"},
-  {&IRQXOR, 1, "IRQXOR"},
+  {&IRQXOR, 1, "IRQX"},
   {&IRQa, 1, "IRQa"},
   {mul, 2, "MUL"},
   {&regie, 1, "REGI"},
   {tkcom, 4, "TKCO"},
   {prgb, 4, "PRGB"},
   {&IRQa, 1, "IRQa"},
   {mul, 2, "MUL"},
   {&regie, 1, "REGI"},
   {tkcom, 4, "TKCO"},
   {prgb, 4, "PRGB"},
+  {chr, 2, "CHRA"},
   {chrlow, 4, "CHRL"},
   {chrhigh, 8, "CHRH"},
   {&names[0], 2|FCEUSTATE_RLSB, "NMS0"},
   {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
          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)
          break;
     case 0x10:      // 2KB
          for(x=0;x<8;x+=2)
@@ -175,7 +184,7 @@ static void tekvrom(void)
 
 static DECLFW(M90TekWrite)
 {
 
 static DECLFW(M90TekWrite)
 {
-  switch(A)
+  switch(A&0x5C03)
   {
     case 0x5800: mul[0]=V; break;
     case 0x5801: mul[1]=V; break;
   {
     case 0x5800: mul[0]=V; break;
     case 0x5801: mul[1]=V; break;
@@ -185,35 +194,40 @@ static DECLFW(M90TekWrite)
 
 static DECLFR(M90TekRead)
 {
 
 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);
   {
     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)
 {
 }
 
 static DECLFW(M90PRGWrite)
 {
+//  FCEU_printf("bs %04x %02x\n",A,V);
   prgb[A&3]=V;
   tekprom();
 }
 
 static DECLFW(M90CHRlowWrite)
 {
   prgb[A&3]=V;
   tekprom();
 }
 
 static DECLFW(M90CHRlowWrite)
 {
+//  FCEU_printf("bs %04x %02x\n",A,V);
   chrlow[A&7]=V;
   tekvrom();
 }
 
 static DECLFW(M90CHRhiWrite)
 {
   chrlow[A&7]=V;
   tekvrom();
 }
 
 static DECLFW(M90CHRhiWrite)
 {
+//  FCEU_printf("bs %04x %02x\n",A,V);
   chrhigh[A&7]=V;
   tekvrom();
 }
 
 static DECLFW(M90NTWrite)
 {
   chrhigh[A&7]=V;
   tekvrom();
 }
 
 static DECLFW(M90NTWrite)
 {
+//  FCEU_printf("bs %04x %02x\n",A,V);
   if(A&4)
   {
     names[A&3]&=0x00FF;
   if(A&4)
   {
     names[A&3]&=0x00FF;
@@ -229,6 +243,7 @@ static DECLFW(M90NTWrite)
 
 static DECLFW(M90IRQWrite)
 {
 
 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");
   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;
     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);
     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");
     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)
 {
              IRQPreSize=V;break;
   }
 }
 
 static DECLFW(M90ModeWrite)
 {
+//    FCEU_printf("bs %04x %02x\n",A,V);
     tkcom[A&3]=V;
     tekprom();
     tekvrom();
     tkcom[A&3]=V;
     tekprom();
     tekvrom();
@@ -305,6 +321,11 @@ static DECLFW(M90ModeWrite)
 #endif
 }
 
 #endif
 }
 
+static DECLFW(M90DummyWrite)
+{
+//    FCEU_printf("bs %04x %02x\n",A,V);
+}
+
 static void CCL(void)
 {
   if((IRQMode>>6) == 1) // Count Up
 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<a;x++) ClockCounter();
 {
   int x;
   if((IRQMode&3)==0) for(x=0;x<a;x++) ClockCounter();
@@ -358,7 +379,7 @@ static void SLWrap(void)
 }
 
 static uint32 lastread;
 }
 
 static uint32 lastread;
-static void FP_FASTAPASS(1) M90PPU(uint32 A)
+static void M90PPU(uint32 A)
 {
   if((IRQMode&3)==2)
   {
 {
   if((IRQMode&3)==2)
   {
@@ -369,24 +390,38 @@ static void FP_FASTAPASS(1) M90PPU(uint32 A)
     }
     lastread=A;
   }
     }
     lastread=A;
   }
-//  else
-//  {
-//    if((!lastread)&&(A&0x1000))
-//      ClockCounter();
-//    lastread=A&0x1000;
-//  }
-
+  
+  if(is209)
+  {
+    uint8 l,h;
+    h=A>>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()
 {
 }
 
 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();
   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);
 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(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);
 
   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;
   info->Reset=togglie;
   info->Power=M90Power;
   PPU_hook=M90PPU;
-  GameHBIRQHook2=SLWrap;
   MapIRQHook=CPUWrap;
   MapIRQHook=CPUWrap;
+  GameHBIRQHook2=SLWrap;
   GameStateRestore=M90Restore;
   AddExState(Tek_StateRegs, ~0, 0, 0);
 }
   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;
   is209=1;
   info->Reset=togglie;
   info->Power=M90Power;
+  PPU_hook=M90PPU;
+  MapIRQHook=CPUWrap;
   GameHBIRQHook2=SLWrap;
   GameStateRestore=M90Restore;
   AddExState(Tek_StateRegs, ~0, 0, 0);
   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;
   is211=1;
   info->Reset=togglie;
   info->Power=M90Power;
+  PPU_hook=M90PPU;
+  MapIRQHook=CPUWrap;
   GameHBIRQHook2=SLWrap;
   GameStateRestore=M90Restore;
   AddExState(Tek_StateRegs, ~0, 0, 0);
   GameHBIRQHook2=SLWrap;
   GameStateRestore=M90Restore;
   AddExState(Tek_StateRegs, ~0, 0, 0);
index 7b69435..0a5d9dd 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
+#include "../ines.h"
 
 static uint8 lastA;
 static uint8 DRegs[8];
 
 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;
 {
   static int last=-1;
   static uint8 z;
index 7af1889..b14ee56 100644 (file)
@@ -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/112.c
+B_C += boards/116.c
 B_C += boards/117.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/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/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/208.c
 B_C += boards/222.c
+B_C += boards/23.c
 B_C += boards/235.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/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/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/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/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/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/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/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/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/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/n106.c
+B_C += boards/n625092.c
 B_C += boards/novel.c
 B_C += boards/novel.c
+B_C += boards/onebus.c
 B_C += boards/sachen.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/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/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/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))
 
 
 MUOBJS += $(patsubst %.c,%.o,$(B_C))
 
index 6bb703c..f56736d 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2009 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[8];\r
+/*\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+static uint8 *CHRRAM=NULL;\r
+static uint32 CHRRAMSIZE;\r
+*/\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 8, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+}\r
+\r
+static DECLFW(MNNNWrite)\r
+{\r
+}\r
+\r
+static void MNNNPower(void)\r
+{\r
+//  SetReadHandler(0x6000,0x7fff,CartBR);\r
+// SetWriteHandler(0x6000,0x7fff,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,MNNNWrite);\r
+}\r
+\r
+static void MNNNReset(void)\r
+{\r
+}\r
+\r
+/*\r
+static void MNNNClose(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  WRAM=CHRRAM=NULL;\r
+}\r
+*/\r
+\r
+static void MNNNIRQHook(void)\r
+{\r
+  X6502_IRQBegin(FCEU_IQEXT);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void MapperNNN_Init(CartInfo *info)\r
+{\r
+  info->Reset=MNNNReset;\r
+  info->Power=MNNNPower;\r
+//  info->Close=MNNNClose;\r
+  GameHBIRQHook=MNNNIRQHook;\r
+  GameStateRestore=StateRestore;\r
+/*\r
+  CHRRAMSIZE=8192;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE);\r
+  SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1);\r
+  AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM");\r
+*/\r
+/*\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+*/\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
similarity index 51%
rename from boards/sonic5.c
rename to boards/a9711.c
index 4a55d0d..3fb5460 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+//static uint8 m_perm[8] = {0, 1, 0, 3, 0, 5, 6, 7};\r
+\r
+static void UNLA9711PW(uint32 A, uint8 V)\r
+{\r
+  if((EXPREGS[0]&0xFF) == 0x37)\r
+  {\r
+    setprg8(0x8000, 0x13);\r
+    setprg8(0xA000, 0x13);\r
+    setprg8(0xC000, 0x13);\r
+    setprg8(0xE000, 0x0);\r
+//    uint8 bank=EXPREGS[0]&0x1F;\r
+//   if(EXPREGS[0]&0x20)\r
+//      setprg32(0x8000,bank>>2);\r
+//    else\r
+//    {\r
+//      setprg16(0x8000,bank);\r
+//      setprg16(0xC000,bank);\r
+//    }\r
+  }\r
+  else\r
+    setprg8(A,V&0x3F);\r
+}\r
+\r
+//static DECLFW(UNLA9711Write8000)\r
+//{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+//  if(V&0x80)\r
+//    MMC3_CMDWrite(A,V);\r
+//  else\r
+//    MMC3_CMDWrite(A,m_perm[V&7]);\r
+//  if(V!=0x86) MMC3_CMDWrite(A,V);\r
+//}\r
+\r
+static DECLFW(UNLA9711WriteLo)\r
+{\r
+  FCEU_printf("bs %04x %02x\n",A,V);\r
+  EXPREGS[0]=V;\r
+  FixMMC3PRG(MMC3_cmd);\r
+}\r
+\r
+static void UNLA9711Power(void)\r
+{\r
+  EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x5000,0x5FFF,UNLA9711WriteLo);\r
+//  SetWriteHandler(0x8000,0xbfff,UNLA9711Write8000);\r
+}\r
+\r
+void UNLA9711_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 256, 0, 0);\r
+  pwrap=UNLA9711PW;\r
+  info->Power=UNLA9711Power;\r
+  AddExState(EXPREGS, 3, 0, "EXPR");\r
+}\r
diff --git a/boards/a9746.c b/boards/a9746.c
new file mode 100644 (file)
index 0000000..3522336
--- /dev/null
@@ -0,0 +1,186 @@
+\r
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+/*\r
+#include "mapinc.h"\r
+\r
+static uint8 chr_cmd, prg_cmd, mirror;\r
+static uint8 chr_reg[6], prg_reg[4];\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&chr_cmd, 1, "CHRCMD"},\r
+  {&prg_cmd, 1, "PRGCMD"},\r
+  {&mirror, 1, "MIRR"},\r
+  {chr_reg, 6, "CREGS"},\r
+  {prg_reg, 4, "PREGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x8000, prg_reg[0]);\r
+  setprg8(0xA000, prg_reg[1]); \r
+  setprg8(0xC000, prg_reg[2]); \r
+  setprg8(0xE000, prg_reg[3]);\r
+    \r
+  setchr2(0x0000, chr_reg[0]);\r
+  setchr2(0x0800, chr_reg[1]); \r
+  setchr1(0x1000, chr_reg[2]); \r
+  setchr1(0x1400, chr_reg[3]);\r
+  setchr1(0x1800, chr_reg[4]);\r
+  setchr1(0x1c00, chr_reg[5]); \r
+  \r
+  setmirror(mirror);\r
+}\r
+\r
+static DECLFW(UNLA9746Write)\r
+{\r
+   uint8 bits_rev;    \r
+//   FCEU_printf("write raw %04x:%02x\n",A,V);\r
+   switch (A&0xE003)\r
+   {\r
+//     case 0xA000: mirror = V; break;\r
+     case 0x8000: chr_cmd = V; prg_cmd = 0; break;\r
+     case 0x8002: prg_cmd = V; chr_cmd = 0; break;\r
+     case 0x8001: bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1);\r
+//                  if(prg_cmd>0x23)\r
+//                     prg_reg[(0x26-prg_cmd)&3] = bits_rev;\r
+                  switch(chr_cmd)\r
+                  {\r
+                    case 0x08: chr_reg[0] = (V << 3); break;\r
+                    case 0x09: chr_reg[0] = chr_reg[0]|(V >> 2); break;\r
+                    case 0x0e: chr_reg[1] = (V << 3); break;\r
+                    case 0x0d: chr_reg[1] = chr_reg[1]|(V >> 2); break;\r
+                    case 0x12: chr_reg[2] = (V << 4); break;\r
+                    case 0x11: chr_reg[2] = chr_reg[2]|(V >> 1); FCEU_printf("Sync CHR 0x1000:%02x\n",chr_reg[2]); break;\r
+                    case 0x16: chr_reg[3] = (V << 4); break;\r
+                    case 0x15: chr_reg[3] = chr_reg[3]|(V >> 1); break;\r
+                    case 0x1a: chr_reg[4] = (V << 4); break;\r
+                    case 0x19: chr_reg[4] = chr_reg[4]|(V >> 1); break;\r
+                    case 0x1e: chr_reg[5] = (V << 4); break;\r
+                    case 0x1d: chr_reg[5] = chr_reg[5]|(V >> 1); break;\r
+                  }\r
+                  Sync();\r
+                  break;\r
+   }\r
+}\r
+\r
+static void UNLA9746Power(void)\r
+{\r
+  prg_reg[2]=~1;\r
+  prg_reg[3]=~0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xbfff,UNLA9746Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLA9746_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLA9746Power;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+/**/\r
+\r
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static DECLFW(UNLA9746Write)\r
+{\r
+//   FCEU_printf("write raw %04x:%02x\n",A,V);\r
+   switch (A&0xE003)\r
+   {\r
+     case 0x8000: EXPREGS[1]=V; EXPREGS[0]=0; break;\r
+     case 0x8002: EXPREGS[0]=V; EXPREGS[1]=0; break;\r
+     case 0x8001: {\r
+                    uint8 bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1);\r
+                    switch(EXPREGS[0])\r
+                    {\r
+                      case 0x26: setprg8(0x8000, bits_rev); break;\r
+                      case 0x25: setprg8(0xA000, bits_rev); break; \r
+                      case 0x24: setprg8(0xC000, bits_rev); break; \r
+                      case 0x23: setprg8(0xE000, bits_rev); break;\r
+                    }\r
+                    switch(EXPREGS[1])\r
+                    {\r
+                      case 0x0a:\r
+                      case 0x08: EXPREGS[2] = (V << 4); break;\r
+                      case 0x09: setchr1(0x0000, EXPREGS[2]|(V >> 1)); break;\r
+                      case 0x0b: setchr1(0x0400, EXPREGS[2]|(V >> 1)|1);  break;\r
+                      case 0x0c:\r
+                      case 0x0e: EXPREGS[2] = (V << 4);  break;\r
+                      case 0x0d: setchr1(0x0800, EXPREGS[2]|(V >> 1));  break;\r
+                      case 0x0f: setchr1(0x0c00, EXPREGS[2]|(V >> 1)|1);  break;\r
+                      case 0x10:\r
+                      case 0x12: EXPREGS[2] = (V << 4);  break;\r
+                      case 0x11: setchr1(0x1000, EXPREGS[2]|(V >> 1)); break;\r
+                      case 0x14:\r
+                      case 0x16: EXPREGS[2] = (V << 4);  break;\r
+                      case 0x15: setchr1(0x1400, EXPREGS[2]|(V >> 1));  break;\r
+                      case 0x18:\r
+                      case 0x1a: EXPREGS[2] = (V << 4);  break;\r
+                      case 0x19: setchr1(0x1800, EXPREGS[2]|(V >> 1));  break;\r
+                      case 0x1c:\r
+                      case 0x1e: EXPREGS[2] = (V << 4);  break;\r
+                      case 0x1d: setchr1(0x1c00, EXPREGS[2]|(V >> 1));  break;\r
+                    }\r
+                  }\r
+                  break;\r
+   }\r
+}\r
+\r
+static void UNLA9746Power(void)\r
+{\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x8000,0xbfff,UNLA9746Write);\r
+}\r
+\r
+void UNLA9746_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 256, 0, 0);\r
+  info->Power=UNLA9746Power;\r
+  AddExState(EXPREGS, 6, 0, "EXPR");\r
+}\r
+/**/\r
diff --git a/boards/addrlatch.c b/boards/addrlatch.c
new file mode 100644 (file)
index 0000000..4b70d6e
--- /dev/null
@@ -0,0 +1,172 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 latche, latcheinit;\r
+static uint16 addrreg0, addrreg1;\r
+static void(*WSync)(void);\r
+static readfunc defread;\r
+\r
+static DECLFW(LatchWrite)\r
+{\r
+  FCEU_printf("%04x:%02x\n",A,V);\r
+  latche=A;\r
+  WSync();\r
+}\r
+\r
+static void LatchReset(void)\r
+{\r
+  latche=latcheinit;\r
+  WSync();\r
+}\r
+\r
+static void LatchPower(void)\r
+{\r
+  latche=latcheinit;\r
+  WSync();\r
+  SetReadHandler(0x8000,0xFFFF,defread);\r
+  SetWriteHandler(addrreg0,addrreg1,LatchWrite);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  WSync();\r
+}\r
+\r
+static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 init, uint16 adr0, uint16 adr1)\r
+{\r
+  latcheinit=init;\r
+  addrreg0=adr0;\r
+  addrreg1=adr1;\r
+  WSync=proc;\r
+  if(func)\r
+    defread=func;\r
+  else\r
+    defread=CartBR;\r
+  info->Power=LatchPower;\r
+  info->Reset=LatchReset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&latche, 2, 0, "LATC");\r
+}\r
+\r
+//------------------ UNLCC21 ---------------------------\r
+\r
+static void UNLCC21Sync(void)\r
+{\r
+  setprg32(0x8000,0);\r
+  setchr8(latche&1);\r
+  setmirror(MI_0+((latche&2)>>1));\r
+}\r
+\r
+void UNLCC21_Init(CartInfo *info)\r
+{ \r
+  Latch_Init(info, UNLCC21Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ BMCD1038 ---------------------------\r
+\r
+static uint8 dipswitch;\r
+static void BMCD1038Sync(void)\r
+{\r
+  if(latche&0x80)\r
+  {\r
+    setprg16(0x8000,(latche&0x70)>>4);\r
+    setprg16(0xC000,(latche&0x70)>>4);\r
+  }\r
+  else\r
+    setprg32(0x8000,(latche&0x60)>>5);\r
+  setchr8(latche&7);\r
+  setmirror(((latche&8)>>3)^1);\r
+}\r
+\r
+static DECLFR(BMCD1038Read)\r
+{\r
+  if(latche&0x100)\r
+    return dipswitch;\r
+  else\r
+    return CartBR(A);\r
+}\r
+\r
+static void BMCD1038Reset(void)\r
+{\r
+  dipswitch++;\r
+  dipswitch&=3; \r
+}\r
+\r
+void BMCD1038_Init(CartInfo *info)\r
+{ \r
+  Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0, 0x8000, 0xFFFF);\r
+  info->Reset=BMCD1038Reset;\r
+  AddExState(&dipswitch, 1, 0, "DIPSW");\r
+}\r
+\r
+\r
+//------------------ Map 058 ---------------------------\r
+\r
+static void BMCGK192Sync(void)\r
+{\r
+  if(latche&0x40)\r
+  {\r
+    setprg16(0x8000,latche&7);\r
+    setprg16(0xC000,latche&7);\r
+  }\r
+  else\r
+    setprg32(0x8000,(latche>>1)&3);\r
+  setchr8((latche>>3)&7);\r
+  setmirror(((latche&0x80)>>7)^1);\r
+}\r
+\r
+void BMCGK192_Init(CartInfo *info)\r
+{\r
+  Latch_Init(info, BMCGK192Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ Map 200 ---------------------------\r
+\r
+static void M200Sync(void)\r
+{\r
+//  FCEU_printf("A\n");\r
+  setprg16(0x8000,latche&7);\r
+  setprg16(0xC000,latche&7);\r
+  setchr8(latche&7);\r
+  setmirror((latche&8)>>3);\r
+}\r
+\r
+void Mapper200_Init(CartInfo *info)\r
+{ \r
+  Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ 190in1 ---------------------------\r
+\r
+static void BMC190in1Sync(void)\r
+{\r
+  setprg16(0x8000,(latche>>2)&0x07);\r
+  setprg16(0xC000,(latche>>2)&0x07);\r
+  setchr8((latche>>2)&0x07);\r
+  setmirror((latche&1)^1);\r
+}\r
+\r
+void BMC190in1_Init(CartInfo *info)\r
+{ \r
+  Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
diff --git a/boards/ax5705.c b/boards/ax5705.c
new file mode 100644 (file)
index 0000000..66f1498
--- /dev/null
@@ -0,0 +1,122 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Super Bros. Pocker Mali (VRC4 mapper)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 IRQCount;//, IRQPre;\r
+static uint8 IRQa;\r
+static uint8 prg_reg[2];\r
+static uint8 chr_reg[8];\r
+static uint8 mirr;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQCount, 1, "IRQC"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {prg_reg, 2, "PRG"},\r
+  {chr_reg, 8, "CHR"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+/*\r
+static void UNLAX5705IRQ(void)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount++;\r
+    if(IRQCount>=238)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+//      IRQa=0;\r
+    }\r
+  }\r
+}*/\r
+\r
+static void Sync(void)\r
+{\r
+  int i;\r
+  setprg8(0x8000,prg_reg[0]);\r
+  setprg8(0xA000,prg_reg[1]);\r
+  setprg8(0xC000,~1);\r
+  setprg8(0xE000,~0);\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr_reg[i]);     \r
+  setmirror(mirr^1);   \r
+}\r
+\r
+static DECLFW(UNLAX5705Write)\r
+{\r
+//  if((A>=0xA008)&&(A<=0xE003))\r
+//  {\r
+//    int ind=(((A>>11)-6)|(A&1))&7;\r
+//    int sar=((A&2)<<1);\r
+//    chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r
+//    SyncChr();\r
+//  }\r
+//  else \r
+  switch(A&0xF00F)\r
+  {\r
+    case 0x8000: prg_reg[0]=((V&2)<<2)|((V&8)>>2)|(V&5); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed\r
+    case 0x8008: mirr=V&1; break;\r
+    case 0xA000: prg_reg[1]=((V&2)<<2)|((V&8)>>2)|(V&5); break;\r
+    case 0xA008: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break;\r
+    case 0xA009: chr_reg[0]=(chr_reg[0]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xA00A: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break;\r
+    case 0xA00B: chr_reg[1]=(chr_reg[1]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break;\r
+    case 0xC001: chr_reg[2]=(chr_reg[2]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC002: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break;\r
+    case 0xC003: chr_reg[3]=(chr_reg[3]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC008: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break;\r
+    case 0xC009: chr_reg[4]=(chr_reg[4]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC00A: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break;\r
+    case 0xC00B: chr_reg[5]=(chr_reg[5]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break;\r
+    case 0xE001: chr_reg[6]=(chr_reg[6]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xE002: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break;\r
+    case 0xE003: chr_reg[7]=(chr_reg[7]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+//    case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;\r
+//    case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/  break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void UNLAX5705Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLAX5705Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLAX5705_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLAX5705Power;\r
+//  GameHBIRQHook=UNLAX5705IRQ;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/bandai.c b/boards/bandai.c
new file mode 100644 (file)
index 0000000..8468aad
--- /dev/null
@@ -0,0 +1,176 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *  Copyright (C) 2011 FCEUX team\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Bandai mappers\r
+ *\r
+ */\r
+\r
+//Famicom Jump 2 should get transformed to m153\r
+//All other games are not supporting EEPROM saving right now. \r
+//We may need to distinguish between 16 and 159 in order to know the EEPROM configuration.\r
+//Until then, we just return 0x00 from the EEPROM read\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[16], is153;\r
+static uint8 IRQa;\r
+static int16 IRQCount, IRQLatch;\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 16, "REGS"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 2, "IRQC"},\r
+  {&IRQLatch, 2, "IRQL"}, // need for Famicom Jump II - Saikyou no 7 Nin (J) [!]\r
+  {0}\r
+};\r
+\r
+static void BandaiIRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount -= a;\r
+    if(IRQCount<0)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+      IRQa = 0;\r
+      IRQCount = -1;\r
+    }\r
+  }\r
+}\r
+\r
+static void BandaiSync(void)\r
+{\r
+  if(is153)\r
+  {\r
+    int base=(reg[0]&1)<<4;\r
+    setchr8(0);\r
+    setprg16(0x8000,(reg[8]&0x0F)|base);\r
+    setprg16(0xC000,0x0F|base);\r
+  }\r
+  else\r
+  {\r
+    int i;\r
+    for(i=0; i<8; i++) setchr1(i<<10,reg[i]);\r
+    setprg16(0x8000,reg[8]);\r
+    setprg16(0xC000,~0);\r
+  }\r
+  switch(reg[9]&3)\r
+  {\r
+    case 0: setmirror(MI_V); break;\r
+    case 1: setmirror(MI_H); break;\r
+    case 2: setmirror(MI_0); break;\r
+    case 3: setmirror(MI_1); break;\r
+  }\r
+}\r
+\r
+static DECLFW(BandaiWrite)\r
+{\r
+  A&=0x0F;\r
+  if(A<0x0A)\r
+  {\r
+    reg[A&0x0F]=V;\r
+    BandaiSync();\r
+  }\r
+  else\r
+    switch(A)\r
+    {\r
+      case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break;\r
+      case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V;  break;\r
+      case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break;\r
+      case 0x0D: break;// Serial EEPROM control port\r
+    }\r
+}\r
+\r
+DECLFR(BandaiRead)
+{
+       return 0;
+}\r
+\r
+static void BandaiPower(void)\r
+{\r
+  BandaiSync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x6000,0xFFFF,BandaiWrite);\r
+  SetReadHandler(0x6000,0x7FFF,BandaiRead);\r
+}\r
+\r
+static void M153Power(void)\r
+{\r
+  BandaiSync();\r
+  setprg8r(0x10,0x6000,0);\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,BandaiWrite);\r
+}\r
+\r
+\r
+static void M153Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  BandaiSync();\r
+}\r
+\r
+void Mapper16_Init(CartInfo *info)\r
+{\r
+  is153=0;\r
+  info->Power=BandaiPower;\r
+  MapIRQHook=BandaiIRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper159_Init(CartInfo *info)\r
+{\r
+  Mapper16_Init(info);\r
+}\r
+\r
+\r
+void Mapper153_Init(CartInfo *info)\r
+{\r
+  is153=1;\r
+  info->Power=M153Power;\r
+  info->Close=M153Close;\r
+  MapIRQHook=BandaiIRQHook;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 6f11f8a..89aa4fb 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * BMC 42-in-1 reset switch\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 bank_mode;\r
+static uint8 bank_value;\r
+static uint8 prgb[4];\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]);  \r
+  switch(bank_mode&7)\r
+  {\r
+    case 0:\r
+         setprg32(0x8000,bank_value&7); break;\r
+    case 1:\r
+         setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]);\r
+         setprg16(0xC000,(bank_value&7)>>1);\r
+    case 4:\r
+         setprg32(0x8000,8+(bank_value&7)); break;\r
+    case 5:\r
+         setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]);\r
+         setprg16(0xC000,((8+(bank_value&7))>>1)+prgb[3]);\r
+    case 2:\r
+         setprg8(0x8000,prgb[0]>>2);\r
+         setprg8(0xa000,prgb[1]);\r
+         setprg8(0xc000,prgb[2]);\r
+         setprg8(0xe000,~0);\r
+         break;\r
+    case 3:\r
+         setprg8(0x8000,prgb[0]);\r
+         setprg8(0xa000,prgb[1]);\r
+         setprg8(0xc000,prgb[2]);\r
+         setprg8(0xe000,prgb[3]);\r
+         break;\r
+  }\r
+}\r
+\r
+static DECLFW(BMC13in1JY110Write)\r
+{\r
+  FCEU_printf("%04x:%04x\n",A,V);\r
+  switch(A)\r
+  {\r
+    case 0x8000:\r
+    case 0x8001:\r
+    case 0x8002:\r
+    case 0x8003: prgb[A&3]=V; break;\r
+    case 0xD000: bank_mode=V; break;\r
+    case 0xD001: setmirror(V&3);\r
+    case 0xD002: break;\r
+    case 0xD003: bank_value=V; break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void BMC13in1JY110Power(void)\r
+{\r
+  prgb[0]=prgb[1]=prgb[2]=prgb[3]=0;\r
+  bank_mode=0;\r
+  bank_value=0;\r
+  setprg32(0x8000,0);\r
+  setchr8(0);\r
+  SetWriteHandler(0x8000,0xFFFF,BMC13in1JY110Write);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMC13in1JY110_Init(CartInfo *info)\r
+{\r
+  info->Power=BMC13in1JY110Power;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+  GameStateRestore=StateRestore;\r
+}\r
+\r
+\r
index 8084847..bcbdfc1 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *  Copyright (C) 2009 qeed\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * BMC 42-in-1\r
+ * it seems now, mapper not reset-based,\r
+ * tested on real hardware and it does menus switch by pressing just Select, not Reset\r
+ * new registers behaviour proven this too\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 latche[2];\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&latche, sizeof(latche), "LATCHE"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint8 bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1))<<6;\r
+  if(!(latche[0] & 0x20))\r
+      setprg32(0x8000,bank >> 1);\r
+  else\r
+  {\r
+      setprg16(0x8000,bank);\r
+      setprg16(0xC000,bank);\r
+  }\r
+  setmirror((latche[0]>>6)&1);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(M226Write)\r
+{\r
+    latche[A & 1] = V;\r
+    Sync();\r
+}\r
+\r
+static void M226Power(void)\r
+{\r
+  latche[0] = latche[1] = 0;\r
+  Sync();\r
+  SetWriteHandler(0x8000,0xFFFF,M226Write);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper226_Init(CartInfo *info)\r
+{\r
+  info->Power=M226Power;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+  GameStateRestore=StateRestore;\r
+}\r
+\r
index af663ba..4f90c9f 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * BMC 42-in-1 reset switch\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 regs[4];\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {regs, 4, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  if(regs[0]&0x80)\r
+  {\r
+    if(regs[1]&0x80)\r
+      setprg32(0x8000,regs[1]&0x1F);\r
+    else\r
+    {\r
+      int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);\r
+      setprg16(0x8000,bank);\r
+      setprg16(0xC000,bank);\r
+    }\r
+  }\r
+  else\r
+  {\r
+    int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);\r
+    setprg16(0xC000,bank);\r
+  }\r
+  if(regs[0]&0x20)\r
+    setmirror(MI_H);\r
+  else\r
+    setmirror(MI_V);\r
+  setchr8((regs[2]<<2)|((regs[0]>>1)&3));\r
+}\r
+\r
+static DECLFW(BMC64in1nrWriteLo)\r
+{\r
+  regs[A&3]=V;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(BMC64in1nrWriteHi)\r
+{\r
+  regs[3]=V;\r
+  Sync();\r
+}\r
+\r
+static void BMC64in1nrPower(void)\r
+{\r
+  regs[0]=0x80;\r
+  regs[1]=0x43;\r
+  regs[2]=regs[3]=0;\r
+  Sync();\r
+  SetWriteHandler(0x5000,0x5003,BMC64in1nrWriteLo);\r
+  SetWriteHandler(0x8000,0xFFFF,BMC64in1nrWriteHi);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMC64in1nr_Init(CartInfo *info)\r
+{\r
+  info->Power=BMC64in1nrPower;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+  GameStateRestore=StateRestore;\r
+}\r
+\r
+\r
index 9d4eb28..75baaa5 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 is_large_banks, hw_switch;\r
+static uint8 large_bank;\r
+static uint8 prg_bank;\r
+static uint8 chr_bank;\r
+static uint8 bank_mode;\r
+static uint8 mirroring;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&large_bank, 1, "LB"},\r
+  {&hw_switch, 1, "DIPSW"},\r
+  {&prg_bank, 1, "PRG"},\r
+  {&chr_bank, 1, "CHR"},\r
+  {&bank_mode, 1, "BM"},\r
+  {&mirroring, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  switch (bank_mode)\r
+  {\r
+    case 0x00:\r
+    case 0x10: setprg16(0x8000,large_bank|prg_bank);\r
+               setprg16(0xC000,large_bank|7);\r
+               break;\r
+    case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1);\r
+               break;\r
+    case 0x30: setprg16(0x8000,large_bank|prg_bank);\r
+               setprg16(0xC000,large_bank|prg_bank);\r
+               break;\r
+  }\r
+  setmirror(mirroring);\r
+  if(!is_large_banks)\r
+    setchr8(chr_bank);\r
+}\r
+\r
+static DECLFR(BMC70in1Read)\r
+{\r
+  if(bank_mode==0x10)\r
+//    if(is_large_banks)\r
+      return CartBR((A&0xFFF0)|hw_switch);\r
+//    else\r
+//      return CartBR((A&0xFFF0)|hw_switch);\r
+  else\r
+    return CartBR(A);\r
+}\r
+\r
+static DECLFW(BMC70in1Write)\r
+{\r
+  if(A&0x4000)\r
+  {\r
+    bank_mode=A&0x30;\r
+    prg_bank=A&7;\r
+  }\r
+  else\r
+  {\r
+    mirroring=((A&0x20)>>5)^1;\r
+    if(is_large_banks)\r
+      large_bank=(A&3)<<3;\r
+    else\r
+      chr_bank=A&7;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void BMC70in1Reset(void)\r
+{\r
+  bank_mode=0;\r
+  large_bank=0;\r
+  Sync();\r
+  hw_switch++;\r
+  hw_switch&=0xf;\r
+}\r
+\r
+static void BMC70in1Power(void)\r
+{\r
+  setchr8(0);\r
+  bank_mode=0;\r
+  large_bank=0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,BMC70in1Read);\r
+  SetWriteHandler(0x8000,0xffff,BMC70in1Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMC70in1_Init(CartInfo *info)\r
+{\r
+  is_large_banks=0;\r
+  hw_switch=0xd;\r
+  info->Power=BMC70in1Power;\r
+  info->Reset=BMC70in1Reset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void BMC70in1B_Init(CartInfo *info)\r
+{\r
+  is_large_banks=1;\r
+  hw_switch=0x6;\r
+  info->Power=BMC70in1Power;\r
+  info->Reset=BMC70in1Reset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index ba390e6..a618f90 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2002 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+#define CARD_EXTERNAL_INSERED 0x80\r
+\r
+static uint8 prg_reg;\r
+static uint8 chr_reg;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&prg_reg, 1, "PREG"},\r
+  {&chr_reg, 1, "CREG"},\r
+  {0}\r
+};\r
+\r
+/*\r
+\r
+_GET_CHALLENGE:      .BYTE   0,$B4,  0,  0,$62\r
+\r
+_SELECT_FILE_1_0200: .BYTE   0,$A4,  1,  0,  2,  2,  0\r
+_SELECT_FILE_2_0201: .BYTE   0,$A4,  2,  0,  2,  2,  1\r
+_SELECT_FILE_2_0203: .BYTE   0,$A4,  2,  0,  2,  2,  3\r
+_SELECT_FILE_2_0204: .BYTE   0,$A4,  2,  0,  2,  2,  4\r
+_SELECT_FILE_2_0205: .BYTE   0,$A4,  2,  0,  2,  2,  5\r
+_SELECT_FILE_2_3F04: .BYTE   0,$A4,  2,  0,  2,$3F,  4\r
+_SELECT_FILE_2_4F00: .BYTE   0,$A4,  2,  0,  2,$4F,  0\r
+\r
+_READ_BINARY_5:      .BYTE   0,$B0,$85,  0,  2\r
+_READ_BINARY_6:      .BYTE   0,$B0,$86,  0,  4\r
+_READ_BINARY_6_0:    .BYTE   0,$B0,$86,  0,$18\r
+_READ_BINARY_0:      .BYTE   0,$B0,  0,  2,  3\r
+_READ_BINARY_0_0:    .BYTE   0,$B0,  0,  0,  4\r
+_READ_BINARY_0_1:    .BYTE   0,$B0,  0,  0, $C\r
+_READ_BINARY_0_2:    .BYTE   0,$B0,  0,  0,$10\r
+\r
+_UPDATE_BINARY:      .BYTE   0,$D6,  0,  0,  4\r
+_UPDATE_BINARY_0:    .BYTE   0,$D6,  0,  0,$10\r
+\r
+_GET_RESPONSE:       .BYTE $80,$C0,  2,$A1,  8\r
+_GET_RESPONSE_0:     .BYTE   0,$C0,  0,  0,  2\r
+_GET_RESPONSE_1:     .BYTE   0,$C0,  0,  0,  6\r
+_GET_RESPONSE_2:     .BYTE   0,$C0,  0,  0,  8\r
+_GET_RESPONSE_3:     .BYTE   0,$C0,  0,  0, $C\r
+_GET_RESPONSE_4:     .BYTE   0,$C0,  0,  0,$10\r
+\r
+byte_8C0B:           .BYTE $80,$30,  0,  2, $A,  0,  1\r
+byte_8C48:           .BYTE $80,$32,  0,  1,  4\r
+byte_8C89:           .BYTE $80,$34,  0,  0,  8,  0,  0\r
+byte_8D01:           .BYTE $80,$36,  0,  0, $C\r
+byte_8CA7:           .BYTE $80,$38,  0,  2,  4\r
+byte_8BEC:           .BYTE $80,$3A,  0,  3,  0\r
+\r
+byte_89A0:           .BYTE   0,$48,  0,  0,  6\r
+byte_8808:           .BYTE   0,$54,  0,  0,$1C\r
+byte_89BF:           .BYTE   0,$58,  0,  0,$1C\r
+\r
+_MANAGE_CHANNEL:     .BYTE   0,$70,  0,  0,  8\r
+byte_8CE5:           .BYTE   0,$74,  0,  0,$12\r
+byte_8C29:           .BYTE   0,$76,  0,  0,  8\r
+byte_8CC6:           .BYTE   0,$78,  0,  0,$12\r
+*/\r
+\r
+static uint8 sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE,\r
+                                 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53,\r
+                                 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10,\r
+                                 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; \r
+\r
+static void Sync(void)\r
+{\r
+  setprg32(0x8000, prg_reg);\r
+  setchr8(chr_reg);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M216WriteHi)\r
+{\r
+  prg_reg=A&1;\r
+  chr_reg=(A&0x0E)>>1;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M216Write5000)\r
+{\r
+//  FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt);\r
+}\r
+\r
+static DECLFR(M216Read5000)\r
+{\r
+//    FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit);\r
+    return 0;\r
+}\r
+\r
+static void Power(void)\r
+{\r
+  prg_reg = 0;\r
+  chr_reg = 0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M216WriteHi);\r
+  SetWriteHandler(0x5000,0x5000,M216Write5000);\r
+  SetReadHandler(0x5000,0x5000,M216Read5000);\r
+}\r
+\r
+\r
+void Mapper216_Init(CartInfo *info)\r
+{\r
+  info->Power=Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/bs-5.c b/boards/bs-5.c
new file mode 100644 (file)
index 0000000..ad7a82a
--- /dev/null
@@ -0,0 +1,91 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg_prg[4];\r
+static uint8 reg_chr[4];\r
+static uint8 dip_switch;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg_prg, 4, "PREGS"},\r
+  {reg_chr, 4, "CREGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x8000,reg_prg[0]);\r
+  setprg8(0xa000,reg_prg[1]);\r
+  setprg8(0xc000,reg_prg[2]);\r
+  setprg8(0xe000,reg_prg[3]);\r
+  setchr2(0x0000,reg_chr[0]);\r
+  setchr2(0x0800,reg_chr[1]);\r
+  setchr2(0x1000,reg_chr[2]);\r
+  setchr2(0x1800,reg_chr[3]);\r
+  setmirror(MI_V);\r
+}\r
+\r
+static DECLFW(MBS5Write)\r
+{\r
+  int bank_sel = (A&0xC00)>>10;\r
+  switch (A&0xF000)\r
+  {\r
+    case 0x8000:\r
+         reg_chr[bank_sel]=A&0x1F;\r
+         break;\r
+    case 0xA000:\r
+         if(A&(1<<(dip_switch+4)))\r
+          reg_prg[bank_sel]=A&0x0F;\r
+         break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void MBS5Reset(void)\r
+{\r
+  dip_switch++;\r
+  dip_switch&=3;\r
+  reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0;     \r
+  Sync();\r
+}\r
+\r
+static void MBS5Power(void)\r
+{\r
+  dip_switch=0;\r
+  reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0;     \r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,MBS5Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMCBS5_Init(CartInfo *info)\r
+{\r
+  info->Power=MBS5Power;\r
+  info->Reset=MBS5Reset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index b3452fe..4a61f04 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
+#include "../ines.h"
 
 
-static uint8 latche, latcheinit;
+static uint8 latche, latcheinit, bus_conflict;
 static uint16 addrreg0, addrreg1;
 static uint16 addrreg0, addrreg1;
+static uint8 *WRAM=NULL;
+static uint32 WRAMSIZE;
 static void(*WSync)(void);
 
 static DECLFW(LatchWrite)
 {
 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();
 }
   latche=V;
   WSync();
 }
@@ -34,23 +41,52 @@ static void LatchPower(void)
 {
   latche=latcheinit;
   WSync();
 {
   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);
 }
 
   SetWriteHandler(addrreg0,addrreg1,LatchWrite);
 }
 
+static void LatchClose(void)
+{
+  if(WRAM)
+    FCEU_gfree(WRAM);
+  WRAM=NULL;
+}
+
 static void StateRestore(int version)
 {
   WSync();
 }
 
 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;
   latcheinit=init;
   addrreg0=adr0;
   addrreg1=adr1;
   WSync=proc;
   info->Power=LatchPower;
+  info->Close=LatchClose;
   GameStateRestore=StateRestore;
   GameStateRestore=StateRestore;
+  if(wram)
+  {
+    WRAMSIZE=8192;
+    WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
+    SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
+    if(info->battery)
+    {
+      info->SaveGame[0]=WRAM;
+      info->SaveGameLen[0]=WRAMSIZE;
+    }
+    AddExState(WRAM, WRAMSIZE, 0, "WRAM");
+  }
   AddExState(&latche, 1, 0, "LATC");
 }
 
   AddExState(&latche, 1, 0, "LATC");
 }
 
@@ -66,21 +102,40 @@ static void CPROMSync(void)
 
 void CPROM_Init(CartInfo *info)
 {
 
 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);
 }
 
   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)
 {
 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 ---------------------------
 }
 
 //------------------ ANROM ---------------------------
@@ -94,7 +149,7 @@ static void ANROMSync()
 
 void ANROM_Init(CartInfo *info)
 {
 
 void ANROM_Init(CartInfo *info)
 {
-  Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF);
+  Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF, 0, 0);
 }
 
 //------------------ Map 70 ---------------------------
 }
 
 //------------------ Map 70 ---------------------------
@@ -108,7 +163,7 @@ static void M70Sync()
 
 void Mapper70_Init(CartInfo *info)
 {
 
 void Mapper70_Init(CartInfo *info)
 {
-  Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF);
+  Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0);
 }
 
 //------------------ Map 152 ---------------------------
 }
 
 //------------------ Map 152 ---------------------------
@@ -123,7 +178,7 @@ static void M152Sync()
 
 void Mapper152_Init(CartInfo *info)
 {
 
 void Mapper152_Init(CartInfo *info)
 {
-  Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF);
+  Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0);
 }
 
 //------------------ Map 78 ---------------------------
 }
 
 //------------------ Map 78 ---------------------------
@@ -138,7 +193,7 @@ static void M78Sync()
 
 void Mapper78_Init(CartInfo *info)
 {
 
 void Mapper78_Init(CartInfo *info)
 {
-  Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF);
+  Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0);
 }
 
 //------------------ MHROM ---------------------------
 }
 
 //------------------ MHROM ---------------------------
@@ -150,13 +205,19 @@ static void MHROMSync(void)
 }
 
 void MHROM_Init(CartInfo *info)
 }
 
 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)
 }
 
 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 ---------------------------
 }
 
 //------------------ Map 87 ---------------------------
@@ -165,12 +226,27 @@ static void M87Sync(void)
 {
   setprg16(0x8000,0);
   setprg16(0xC000,1);
 {
   setprg16(0x8000,0);
   setprg16(0xC000,1);
-  setchr8(latche>>1);
+  setchr8(((latche>>1)&1)|((latche<<1)&2));
+//  setchr8(latche);
 }
 
 void Mapper87_Init(CartInfo *info)
 }
 
 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 ---------------------------
 }
 
 //------------------ Map 11 ---------------------------
@@ -182,15 +258,40 @@ static void M11Sync(void)
 }
 
 void Mapper11_Init(CartInfo *info)
 }
 
 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)
 }
 
 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)
 //------------------ UNROM ---------------------------
 
 static void UNROMSync(void)
@@ -202,7 +303,7 @@ static void UNROMSync(void)
 
 void UNROM_Init(CartInfo *info)
 {
 
 void UNROM_Init(CartInfo *info)
 {
-  Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF);
+  Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1);
 }
 
 //------------------ Map 93 ---------------------------
 }
 
 //------------------ Map 93 ---------------------------
@@ -216,7 +317,7 @@ static void SSUNROMSync(void)
 
 void SUNSOFT_UNROM_Init(CartInfo *info)
 {
 
 void SUNSOFT_UNROM_Init(CartInfo *info)
 {
-  Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF);
+  Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0);
 }
 
 //------------------ Map 94 ---------------------------
 }
 
 //------------------ Map 94 ---------------------------
@@ -230,7 +331,21 @@ static void M94Sync(void)
 
 void Mapper94_Init(CartInfo *info)
 {
 
 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 ---------------------------
 }
 
 //------------------ Map 107 ---------------------------
@@ -243,7 +358,49 @@ static void M107Sync(void)
 
 void Mapper107_Init(CartInfo *info)
 {
 
 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 ---------------------------
 }
 
 //------------------ NROM ---------------------------
@@ -251,16 +408,22 @@ void Mapper107_Init(CartInfo *info)
 #ifdef DEBUG_MAPPER
 static DECLFW(WriteHandler)
 {
 #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)
 {
 }
 #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);
   setprg16(0x8000,0);
   setprg16(0xC000,~0);
   setchr8(0);
+
+  SetReadHandler(0x6000,0x7FFF,CartBR);
+  SetWriteHandler(0x6000,0x7FFF,CartBW);
   SetReadHandler(0x8000,0xFFFF,CartBR);
   SetReadHandler(0x8000,0xFFFF,CartBR);
+
   #ifdef DEBUG_MAPPER
   SetWriteHandler(0x4020,0xFFFF,WriteHandler);
   #endif
   #ifdef DEBUG_MAPPER
   SetWriteHandler(0x4020,0xFFFF,WriteHandler);
   #endif
@@ -269,4 +432,15 @@ static void NROMPower(void)
 void NROM_Init(CartInfo *info)
 {
   info->Power=NROMPower;
 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");
 }
 }
index 7a1ed43..2d28bd0 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -32,9 +32,9 @@ static SFORMAT DEI_StateRegs[]=
 
 static void Sync(void)
 {
 
 static void Sync(void)
 {
+  int x;
   setchr2(0x0000,DRegs[0]);
   setchr2(0x0800,DRegs[1]);
   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]);
   for(x=0;x<4;x++)
      setchr1(0x1000+(x<<10),DRegs[2+x]);
   setprg8(0x8000,DRegs[6]);
index 7e1d563..d2a9cb8 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 latche;\r
+\r
+static void Sync(void)\r
+{\r
+  setprg16(0x8000,latche);\r
+  setprg16(0xC000,8);\r
+}\r
+\r
+static DECLFW(DREAMWrite)\r
+{\r
+  latche=V&7;\r
+  Sync();\r
+}\r
+\r
+static void DREAMPower(void)\r
+{\r
+  latche=0;\r
+  Sync();\r
+  setchr8(0);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x5020,0x5020,DREAMWrite);\r
+}\r
+\r
+static void Restore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void DreamTech01_Init(CartInfo *info)\r
+{\r
+  GameStateRestore=Restore;\r
+  info->Power=DREAMPower;\r
+  AddExState(&latche, 1, 0, "LATCH");\r
+}\r
diff --git a/boards/edu2000.c b/boards/edu2000.c
new file mode 100644 (file)
index 0000000..36dcb5d
--- /dev/null
@@ -0,0 +1,84 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint8 reg;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr8(0);\r
+  setprg8r(0x10,0x6000,(reg&0xC0)>>6);\r
+  setprg32(0x8000,reg&0x1F);\r
+//  setmirror(((reg&0x20)>>5));\r
+}\r
+\r
+static DECLFW(UNLEDU2000HiWrite)\r
+{\r
+//  FCEU_printf("%04x:%02x\n",A,V);\r
+  reg=V;\r
+  Sync();\r
+}\r
+\r
+static void UNLEDU2000Power(void)\r
+{\r
+  setmirror(MI_0);\r
+  SetReadHandler(0x6000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x6000,0xFFFF,CartBW);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLEDU2000HiWrite);\r
+  reg=0;\r
+  Sync();\r
+}\r
+\r
+static void UNLEDU2000Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void UNLEDU2000Restore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLEDU2000_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLEDU2000Power;\r
+  info->Close=UNLEDU2000Close;\r
+  GameStateRestore=UNLEDU2000Restore;\r
+  WRAM=(uint8*)FCEU_gmalloc(32768);\r
+  SetupCartPRGMapping(0x10,WRAM,32768,1);\r
+  if(info->battery)\r
+  {\r
+  info->SaveGame[0]=WRAM;\r
+  info->SaveGameLen[0]=32768;\r
+  }\r
+  AddExState(WRAM, 32768, 0, "WRAM");\r
+  AddExState(StateRegs, ~0, 0, 0);\r
+}\r
index abf0859..c869680 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+#include "../ines.h"\r
+\r
+static bool is_BMCFK23CA;\r
+static uint8 unromchr;\r
+static uint32 dipswitch;\r
+static uint8 *CHRRAM=NULL;\r
+static uint32 CHRRAMSize;\r
+\r
+static void BMCFK23CCW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+    setchr8(EXPREGS[2]|unromchr);\r
+  else if(EXPREGS[0]&0x20) {\r
+    setchr1r(0x10, A, V);\r
+  }\r
+  else\r
+  {\r
+    uint16 base=(EXPREGS[2]&0x7F)<<3;\r
+    if(EXPREGS[3]&2)\r
+    {\r
+      int cbase=(MMC3_cmd&0x80)<<5;\r
+      setchr1(A,V|base);\r
+      setchr1(0x0000^cbase,DRegBuf[0]|base);\r
+      setchr1(0x0400^cbase,EXPREGS[6]|base);\r
+      setchr1(0x0800^cbase,DRegBuf[1]|base);\r
+      setchr1(0x0c00^cbase,EXPREGS[7]|base);\r
+    }\r
+    else\r
+      setchr1(A,V|base);\r
+  }\r
+}\r
+\r
+//some games are wired differently, and this will need to be changed.\r
+//all the WXN games require prg_bonus = 1, and cah4e3's multicarts require prg_bonus = 0\r
+//we'll populate this from a game database\r
+static int prg_bonus;\r
+static int prg_mask;\r
+\r
+//prg_bonus = 0\r
+//4-in-1 (FK23C8021)[p1][!].nes\r
+//4-in-1 (FK23C8033)[p1][!].nes\r
+//4-in-1 (FK23C8043)[p1][!].nes\r
+//4-in-1 (FK23Cxxxx, S-0210A PCB)[p1][!].nes\r
+\r
+//prg_bonus = 1\r
+//[m176]大富翁2-上海大亨.wxn.nes\r
+//[m176]宠物翡翠.fix.nes\r
+//[m176]格兰帝亚.wxn.nes\r
+//[m176]梦幻之星.wxn.nes\r
+//[m176]水浒神兽.fix.nes\r
+//[m176]西楚霸王.fix.nes\r
+//[m176]超级大富翁.wxn.nes\r
+//[m176]雄霸天下.wxn.nes\r
+\r
+//works as-is under virtuanes m176\r
+//[m176]三侠五义.wxn.nes\r
+//[m176]口袋金.fix.nes\r
+//[m176]爆笑三国.fix.nes\r
+\r
+//needs other tweaks\r
+//[m176]三国忠烈传.wxn.nes\r
+//[m176]破釜沉舟.fix.nes\r
+\r
+//PRG wrapper\r
+static void BMCFK23CPW(uint32 A, uint8 V)\r
+{\r
+  uint32 bank = (EXPREGS[1] & 0x1F);\r
+  uint32 hiblock = ((EXPREGS[0] & 8) << 4)|((EXPREGS[0] & 0x80) << 1)|(UNIFchrrama?((EXPREGS[2] & 0x40)<<3):0);\r
+  uint32 block = (EXPREGS[1] & 0x60) | hiblock;\r
+  uint32 extra = (EXPREGS[3] & 2);\r
+\r
+  if((EXPREGS[0]&7)==4)\r
+    setprg32(0x8000,EXPREGS[1]>>1);\r
+  else if ((EXPREGS[0]&7)==3)\r
+  {\r
+    setprg16(0x8000,EXPREGS[1]);\r
+    setprg16(0xC000,EXPREGS[1]);\r
+  }  \r
+  else\r
+  { \r
+    if(EXPREGS[0]&3)\r
+               {\r
+                       uint32 blocksize = (6)-(EXPREGS[0]&3);\r
+                       uint32 mask = (1<<blocksize)-1;\r
+                       V &= mask;\r
+                       //V &= 63; //? is this a good idea?\r
+                       V |= (EXPREGS[1]<<1);\r
+      setprg8(A,V);\r
+               }\r
+    else\r
+      setprg8(A,V & prg_mask);\r
+\r
+    if(EXPREGS[3]&2)\r
+    {\r
+      setprg8(0xC000,EXPREGS[4]);\r
+      setprg8(0xE000,EXPREGS[5]);\r
+    }\r
+  }\r
+       setprg8r(0x10,0x6000,A001B&3);\r
+}\r
+\r
+//PRG handler ($8000-$FFFF)\r
+static DECLFW(BMCFK23CHiWrite)\r
+{\r
+       if(EXPREGS[0]&0x40)\r
+       {\r
+               if(EXPREGS[0]&0x30)\r
+                       unromchr=0;\r
+               else\r
+               {\r
+                       unromchr=V&3;\r
+                       FixMMC3CHR(MMC3_cmd);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if((A==0x8001)&&(EXPREGS[3]&2&&MMC3_cmd&8))\r
+               {\r
+                       EXPREGS[4|(MMC3_cmd&3)]=V;\r
+                       FixMMC3PRG(MMC3_cmd);\r
+                       FixMMC3CHR(MMC3_cmd);\r
+               }\r
+    else\r
+      if(A<0xC000) {\r
+        if(UNIFchrrama) { // hacky... strange behaviour, must be bit scramble due to pcb layot restrictions\r
+                          // check if it not interfer with other dumps\r
+          if((A==0x8000)&&(V==0x46))\r
+            V=0x47;\r
+          else if((A==0x8000)&&(V==0x47))\r
+            V=0x46;\r
+        }\r
+        MMC3_CMDWrite(A,V);\r
+        FixMMC3PRG(MMC3_cmd);\r
+      }\r
+      else\r
+        MMC3_IRQWrite(A,V);\r
+  }\r
+}\r
+\r
+//EXP handler ($5000-$5FFF)\r
+static DECLFW(BMCFK23CWrite)\r
+{\r
+  if(A&(1<<(dipswitch+4)))\r
+  {\r
+               //printf("+ ");\r
+    EXPREGS[A&3]=V;\r
+\r
+               bool remap = false;\r
+\r
+               //sometimes writing to reg0 causes remappings to occur. we think the 2 signifies this. \r
+               //if not, 0x24 is a value that is known to work\r
+               //however, the low 4 bits are known to control the mapping mode, so 0x20 is more likely to be the immediate remap flag\r
+               remap |= ((EXPREGS[0]&0xF0)==0x20); \r
+\r
+               //this is an actual mapping reg. i think reg0 controls what happens when reg1 is written. anyway, we have to immediately remap these\r
+               remap |= (A&3)==1; \r
+               //this too.\r
+               remap |= (A&3)==2; \r
+\r
+               if(remap)\r
+               {\r
+                       FixMMC3PRG(MMC3_cmd);\r
+                       FixMMC3CHR(MMC3_cmd);\r
+               }\r
+  }\r
+\r
+       if(is_BMCFK23CA)\r
+       {\r
+               if(EXPREGS[3]&2)\r
+                       EXPREGS[0] &= ~7;   // hacky hacky! if someone wants extra banking, then for sure doesn't want mode 4 for it! (allow to run A version boards on normal mapper)\r
+       }\r
+\r
+       //printf("%04X = $%02X\n",A,V);\r
+       //printf("%02X %02X %02X %02X\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]);\r
+}\r
+\r
+static void BMCFK23CReset(void)\r
+{\r
+       //NOT NECESSARY ANYMORE\r
+       //this little hack makes sure that we try all the dip switch settings eventually, if we reset enough\r
+       // dipswitch++;\r
+       // dipswitch&=7;\r
+       //printf("BMCFK23C dipswitch set to %d\n",dipswitch);\r
+\r
+  EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0;\r
+  EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF;\r
+  MMC3RegReset();\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void BMCFK23CPower(void)\r
+{\r
+       dipswitch = 0;\r
+  GenMMC3Power();\r
+  EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0;\r
+  EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite);\r
+  SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite);\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void BMCFK23CAPower(void)\r
+{\r
+  GenMMC3Power();\r
+  dipswitch = 0;\r
+  EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0;\r
+  EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF;\r
+  SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite);\r
+  SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite);\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void BMCFK23CAClose(void)\r
+{\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  CHRRAM=NULL;\r
+}\r
+\r
+void BMCFK23C_Init(CartInfo *info)\r
+{\r
+       is_BMCFK23CA = false;\r
+\r
+  GenMMC3_Init(info, 512, 256, 8, 0);\r
+  cwrap=BMCFK23CCW;\r
+  pwrap=BMCFK23CPW;\r
+  info->Power=BMCFK23CPower;\r
+  info->Reset=BMCFK23CReset;\r
+  AddExState(EXPREGS, 8, 0, "EXPR");\r
+  AddExState(&unromchr, 1, 0, "UNCHR");\r
+  AddExState(&dipswitch, 1, 0, "DIPSW");\r
+\r
+       prg_bonus = 1;\r
+       if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end())\r
+               prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str());\r
+\r
+       prg_mask = 0x7F>>(prg_bonus);\r
+}\r
+\r
+void BMCFK23CA_Init(CartInfo *info)\r
+{\r
+       is_BMCFK23CA = true;\r
+\r
+  GenMMC3_Init(info, 512, 256, 8, 0);\r
+  cwrap=BMCFK23CCW;\r
+  pwrap=BMCFK23CPW;\r
+  info->Power=BMCFK23CAPower;\r
+  info->Reset=BMCFK23CReset;\r
+  info->Close=BMCFK23CAClose;\r
+\r
+       CHRRAMSize=8192;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+  SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+  AddExState(CHRRAM, CHRRAMSize, 0, "CRAM");\r
+\r
+  AddExState(EXPREGS, 8, 0, "EXPR");\r
+  AddExState(&unromchr, 1, 0, "UNCHR");\r
+  AddExState(&dipswitch, 1, 0, "DIPSW");\r
+\r
+       prg_bonus = 1;\r
+       if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end())\r
+               prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str());\r
+       prg_mask = 0x7F>>(prg_bonus);\r
+}\r
diff --git a/boards/ghostbusters63in1.c b/boards/ghostbusters63in1.c
new file mode 100644 (file)
index 0000000..627f16d
--- /dev/null
@@ -0,0 +1,106 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * 63in1 ghostbusters\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[2], bank;\r
+static uint8 banks[4] = {0, 0, 1, 2};\r
+static uint8 *CHRROM=NULL;\r
+static uint32 CHRROMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 2, "REGS"},\r
+  {&bank, 1, "BANK"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  if(reg[0]&0x20)\r
+  {\r
+    setprg16r(banks[bank],0x8000,reg[0]&0x1F);\r
+    setprg16r(banks[bank],0xC000,reg[0]&0x1F);\r
+  }\r
+  else\r
+    setprg32r(banks[bank],0x8000,(reg[0]>>1)&0x0F);\r
+  if(reg[1]&2)\r
+    setchr8r(0x10,0);\r
+  else\r
+    setchr8(0);\r
+  setmirror((reg[0]&0x40)>>6);\r
+}\r
+\r
+static DECLFW(BMCGhostbusters63in1Write)\r
+{\r
+  reg[A&1]=V;\r
+  bank=((reg[0]&0x80)>>7)|((reg[1]&1)<<1);\r
+//  FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank);\r
+  Sync();\r
+}\r
+\r
+static DECLFR(BMCGhostbusters63in1Read)\r
+{\r
+  if(bank==1)\r
+    return X.DB;\r
+  else\r
+    return CartBR(A);\r
+}\r
+\r
+static void BMCGhostbusters63in1Power(void)\r
+{\r
+  reg[0]=reg[1]=0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,BMCGhostbusters63in1Read);\r
+  SetWriteHandler(0x8000,0xFFFF,BMCGhostbusters63in1Write);\r
+}\r
+\r
+static void BMCGhostbusters63in1Reset(void)\r
+{\r
+  reg[0]=reg[1]=0;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+static void BMCGhostbusters63in1Close(void)\r
+{\r
+  if(CHRROM)\r
+    FCEU_gfree(CHRROM);\r
+  CHRROM=NULL;\r
+}\r
+\r
+void BMCGhostbusters63in1_Init(CartInfo *info)\r
+{\r
+  info->Reset=BMCGhostbusters63in1Reset;\r
+  info->Power=BMCGhostbusters63in1Power;\r
+  info->Close=BMCGhostbusters63in1Close;\r
+\r
+  CHRROMSIZE=8192; // dummy CHRROM, VRAM disable\r
+  CHRROM=(uint8*)FCEU_gmalloc(CHRROMSIZE);\r
+  SetupCartPRGMapping(0x10,CHRROM,CHRROMSIZE,0);\r
+  AddExState(CHRROM, CHRROMSIZE, 0, "CHRROM");\r
+\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/gs-2004.c b/boards/gs-2004.c
new file mode 100644 (file)
index 0000000..574ed97
--- /dev/null
@@ -0,0 +1,69 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg, mirr;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REGS"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8r(1,0x6000,0);\r
+  setprg32(0x8000,reg);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(BMCGS2004Write)\r
+{\r
+  reg=V;\r
+  Sync();\r
+}\r
+\r
+static void BMCGS2004Power(void)\r
+{\r
+  reg=~0;\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,BMCGS2004Write);\r
+}\r
+\r
+static void BMCGS2004Reset(void)\r
+{\r
+  reg=~0;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMCGS2004_Init(CartInfo *info)\r
+{\r
+  info->Reset=BMCGS2004Reset;\r
+  info->Power=BMCGS2004Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/gs-2013.c b/boards/gs-2013.c
new file mode 100644 (file)
index 0000000..1b4d37b
--- /dev/null
@@ -0,0 +1,69 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg, mirr;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REGS"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8r(0,0x6000,~0);\r
+  setprg32r((reg&8)>>3,0x8000,reg);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(BMCGS2013Write)\r
+{\r
+  reg=V;\r
+  Sync();\r
+}\r
+\r
+static void BMCGS2013Power(void)\r
+{\r
+  reg=~0;\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,BMCGS2013Write);\r
+}\r
+\r
+static void BMCGS2013Reset(void)\r
+{\r
+  reg=~0;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMCGS2013_Init(CartInfo *info)\r
+{\r
+  info->Reset=BMCGS2013Reset;\r
+  info->Power=BMCGS2013Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 22bc7c2..7786daf 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+extern uint8 m114_perm[8];\r
+\r
+static void H2288PW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+  {\r
+    uint8 bank=(EXPREGS[0]&5)|((EXPREGS[0]&8)>>2)|((EXPREGS[0]&0x20)>>2);\r
+    if(EXPREGS[0]&2)\r
+      setprg32(0x8000,bank>>1);\r
+    else\r
+    {\r
+      setprg16(0x8000,bank);\r
+      setprg16(0xC000,bank);\r
+    }\r
+  }\r
+  else\r
+    setprg8(A,V&0x3F);\r
+}\r
+\r
+static DECLFW(H2288WriteHi)\r
+{\r
+  switch (A&0x8001)\r
+  {\r
+    case 0x8000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); break;\r
+    case 0x8001: MMC3_CMDWrite(0x8001,V); break;\r
+  }\r
+}\r
+\r
+static DECLFW(H2288WriteLo)\r
+{\r
+  if(A&0x800)\r
+  {\r
+    if(A&1)\r
+      EXPREGS[1]=V;\r
+    else\r
+      EXPREGS[0]=V;\r
+    FixMMC3PRG(MMC3_cmd);\r
+  }\r
+}\r
+\r
+static DECLFR(H2288Read)\r
+{\r
+  int bit;\r
+  bit=(A&1)^1;\r
+  bit&=((A>>8)&1);\r
+  bit^=1;\r
+  return((X.DB&0xFE)|bit);\r
+}\r
+\r
+static void H2288Power(void)\r
+{\r
+  EXPREGS[0]=EXPREGS[1]=0;\r
+  GenMMC3Power();\r
+  SetReadHandler(0x5000,0x5FFF,H2288Read);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x5000,0x5FFF,H2288WriteLo);\r
+  SetWriteHandler(0x8000,0x8FFF,H2288WriteHi);\r
+}\r
+\r
+void UNLH2288_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 256, 0, 0);\r
+  pwrap=H2288PW;\r
+  info->Power=H2288Power;\r
+  AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
index e089cda..dfb4cc8 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 4e477d3..7bb63ee 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static DECLFW(UNLKOF97CMDWrite)\r
+{\r
+  V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2);  //76143502\r
+  if(A==0x9000) A=0x8001;  \r
+  MMC3_CMDWrite(A,V);\r
+}\r
+\r
+static DECLFW(UNLKOF97IRQWrite)\r
+{\r
+  V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2);\r
+  if(A==0xD000) A=0xC001;\r
+  else if(A==0xF000) A=0xE001;\r
+  MMC3_IRQWrite(A,V);\r
+}\r
+\r
+static void UNLKOF97Power(void)\r
+{\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x8000,0xA000,UNLKOF97CMDWrite);\r
+  SetWriteHandler(0xC000,0xF000,UNLKOF97IRQWrite);\r
+}\r
+\r
+void UNLKOF97_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 256, 0, 0);\r
+  info->Power=UNLKOF97Power;\r
+}\r
index b78d8e3..83630a6 100644 (file)
-/* 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[]=
-{
-  {&regs, 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005-2008 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * CAI Shogakko no Sansu\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 QTAINTRAM[2048];\r
+static writefunc old2007wrap;\r
+\r
+static uint16 CHRSIZE = 8192;\r
+static uint16 WRAMSIZE = 8192 + 4096;\r
+static uint8 *CHRRAM=NULL;\r
+static uint8 *WRAM = NULL;\r
+\r
+static uint8 IRQa, K4IRQ;\r
+static uint32 IRQLatch, IRQCount;\r
+\r
+static uint8 regs[16];\r
+//static uint8 test[8];\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQCount, 1, "IRQC"},\r
+  {&IRQLatch, 1, "IRQL"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&K4IRQ, 1, "K4IRQ"},\r
+  {regs, 16, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void chrSync(void)\r
+{\r
+    setchr4r(0x10,0x0000,regs[5]&1);\r
+    setchr4r(0x10,0x1000,0);\r
+}\r
+\r
+static void Sync(void)\r
+{\r
+    chrSync();\r
+//  if(regs[0xA]&0x10)\r
+//  {\r
+/*    setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0);\r
+    setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1);\r
+    setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2);\r
+    setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3);\r
+    setchr1r(0x10,0x1000,0);\r
+    setchr1r(0x10,0x1400,1);\r
+    setchr1r(0x10,0x1800,2);\r
+    setchr1r(0x10,0x1c00,3);*/\r
+/*    setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0);\r
+    setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1);\r
+    setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2);\r
+    setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3);\r
+    setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4);\r
+    setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5);\r
+    setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6);\r
+    setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7);\r
+*/\r
+//  }\r
+//  else\r
+//  {\r
+/*\r
+    setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0);\r
+    setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1);\r
+    setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2);\r
+    setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3);\r
+    setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4);\r
+    setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5);\r
+    setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6);\r
+    setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7);\r
+//  }\r
+//*/\r
+/*    setchr1r(1,0x0000,test[0]);\r
+    setchr1r(1,0x0400,test[1]);\r
+    setchr1r(1,0x0800,test[2]);\r
+    setchr1r(1,0x0c00,test[3]);\r
+    setchr1r(1,0x1000,test[4]);\r
+    setchr1r(1,0x1400,test[5]);\r
+    setchr1r(1,0x1800,test[6]);\r
+    setchr1r(1,0x1c00,test[7]);\r
+*/\r
+  setprg4r(0x10,0x6000,regs[0]&1);\r
+  if(regs[2]>=0x40)\r
+    setprg8r(1,0x8000,(regs[2]-0x40));\r
+  else\r
+    setprg8r(0,0x8000,(regs[2]&0x3F));\r
+  if(regs[3]>=0x40)\r
+    setprg8r(1,0xA000,(regs[3]-0x40));\r
+  else\r
+    setprg8r(0,0xA000,(regs[3]&0x3F));\r
+  if(regs[4]>=0x40)\r
+    setprg8r(1,0xC000,(regs[4]-0x40));\r
+  else\r
+    setprg8r(0,0xC000,(regs[4]&0x3F));\r
+\r
+  setprg8r(1,0xE000,~0);\r
+  setmirror(MI_V);\r
+}\r
+\r
+/*static DECLFW(TestWrite)\r
+{\r
+  test[A&7] = V;\r
+  Sync();\r
+}*/\r
+\r
+static DECLFW(M190Write)\r
+{\r
+// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);\r
+  regs[(A&0x0F00)>>8]=V;\r
+  switch(A)\r
+  {  \r
+    case 0xd600:IRQLatch&=0xFF00;IRQLatch|=V;break;\r
+    case 0xd700:IRQLatch&=0x00FF;IRQLatch|=V<<8;break;\r
+    case 0xd900:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;X6502_IRQEnd(FCEU_IQEXT);break;\r
+    case 0xd800:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static DECLFR(M190Read)\r
+{\r
+// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);\r
+  return regs[(A&0x0F00)>>8]+regs[0x0B];\r
+}\r
+static void VRC5IRQ(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount+=a;\r
+    if(IRQCount&0x10000)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+//      IRQCount=IRQLatch;\r
+    }\r
+  }\r
+}\r
+\r
+static void Mapper190_PPU(uint32 A)\r
+{\r
+  if(A>=0x2000)\r
+  {\r
+     setchr4r(0x10,0x0000,QTAINTRAM[A&0x1FFF]&1);\r
+     setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1);\r
+  }\r
+//  else\r
+//     chrSync();\r
+}\r
+\r
+static DECLFW(M1902007Wrap)\r
+{\r
+  if(A>=0x2000)\r
+  {\r
+    if(regs[0xA]&1)\r
+      QTAINTRAM[A&0x1FFF]=V;\r
+    else\r
+      old2007wrap(A,V);\r
+  }\r
+}\r
+\r
+\r
+static void M190Power(void)\r
+{\r
+/*  test[0]=0;\r
+  test[1]=1;\r
+  test[2]=2;\r
+  test[3]=3;\r
+  test[4]=4;\r
+  test[5]=5;\r
+  test[6]=6;\r
+  test[7]=7;\r
+*/  \r
+  setprg4r(0x10,0x7000,2);\r
+\r
+  old2007wrap=GetWriteHandler(0x2007);\r
+  SetWriteHandler(0x2007,0x2007,M1902007Wrap);\r
+\r
+  SetReadHandler(0x6000,0xFFFF,CartBR);\r
+//  SetWriteHandler(0x5000,0x5007,TestWrite);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetWriteHandler(0x8000,0xFFFF,M190Write);\r
+  SetReadHandler(0xDC00,0xDC00,M190Read);\r
+  SetReadHandler(0xDD00,0xDD00,M190Read);\r
+  Sync();\r
+}\r
+\r
+static void M190Close(void)\r
+{\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  CHRRAM=NULL;\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper190_Init(CartInfo *info)\r
+{\r
+  info->Power=M190Power;\r
+  info->Close=M190Close;\r
+  GameStateRestore=StateRestore;\r
+\r
+  MapIRQHook=VRC5IRQ;\r
+  //PPU_hook=Mapper190_PPU;\r
+\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE);\r
+  SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1);\r
+  AddExState(CHRRAM, CHRSIZE, 0, "CHRRAM");\r
+\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0] = WRAM;\r
+    info->SaveGameLen[0] = WRAMSIZE - 4096;\r
+  }\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/ks7032.c b/boards/ks7032.c
new file mode 100644 (file)
index 0000000..fcb0eb5
--- /dev/null
@@ -0,0 +1,94 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[8], cmd, IRQa;\r
+static int32 IRQCount;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&cmd, 1, "CMD"},\r
+  {reg, 8, "REGS"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 4, "IRQC"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x6000,reg[4]);\r
+  setprg8(0x8000,reg[1]);\r
+  setprg8(0xA000,reg[2]);\r
+  setprg8(0xC000,reg[3]);\r
+  setprg8(0xE000,~0);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(UNLKS7032Write)\r
+{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+  switch(A)\r
+  {\r
+//    case 0x8FFF: reg[4]=V; Sync(); break;\r
+    case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); break;\r
+    case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); break;\r
+    case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); break;\r
+    case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); break;\r
+    case 0xC000: X6502_IRQEnd(FCEU_IQEXT); IRQa=1; break;\r
+    case 0xE000: cmd=V&7; break;\r
+    case 0xF000: reg[cmd]=V; Sync(); break;\r
+  }\r
+}\r
+\r
+static void UNLSMB2JIRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount+=a;\r
+    if(IRQCount>=0xFFFF)\r
+    {\r
+      IRQa=0;\r
+      IRQCount=0;\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+  }\r
+}\r
+\r
+static void UNLKS7032Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLKS7032_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLKS7032Power;\r
+  MapIRQHook=UNLSMB2JIRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 7feb95e..8c30182 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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];
 
  */
 
 #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);
 {
   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);
   setprg2r(1,0x6000,0);
   setprg32(0x8000,0);
   setchr8(0);
@@ -35,7 +36,7 @@ static void MALEEReset(void)
 
 void MALEE_Init(CartInfo *info)
 {
 
 void MALEE_Init(CartInfo *info)
 {
-  info->Power=MALEEReset;
+  info->Power=MALEEPower;
   SetupCartPRGMapping(0x10, WRAM, 2048, 1);
   AddExState(WRAM, 2048, 0,"RAM");
 }
   SetupCartPRGMapping(0x10, WRAM, 2048, 1);
   AddExState(WRAM, 2048, 0,"RAM");
 }
index 81d4edb..8fa46f4 100644 (file)
@@ -1,13 +1,12 @@
 #include "../types.h"
 #include "../types.h"
+#include "../utils/memory.h"
 #include "../x6502.h"
 #include "../x6502.h"
-#include "../fce.h"
+#include "../fceu.h"
 #include "../ppu.h"
 #include "../ppu.h"
-#include "../memory.h"
 #include "../sound.h"
 #include "../state.h"
 #include "../cart.h"
 #include "../sound.h"
 #include "../state.h"
 #include "../cart.h"
-#include "../ines.h"
 #include "../cheat.h"
 #include "../unif.h"
 #include "../cheat.h"
 #include "../unif.h"
-#include "../svga.h"
+#include <stdio.h>
 #include <string.h>
 #include <string.h>
index 816a1ed..24a07bc 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 1998 BERO\r
+ *  Copyright (C) 2002 Xodnizel\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static void GenMMC1Power(void);\r
+static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery);\r
+\r
+static uint8 DRegs[4];\r
+static uint8 Buffer,BufferShift;\r
+\r
+static int mmc1opts;\r
+\r
+static void (*MMC1CHRHook4)(uint32 A, uint8 V);\r
+static void (*MMC1PRGHook16)(uint32 A, uint8 V);\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint8 *CHRRAM=NULL;\r
+static int is155, is171;\r
+\r
+static DECLFW(MBWRAM)\r
+{\r
+  if(!(DRegs[3]&0x10)||is155)\r
+    Page[A>>11][A]=V;     // WRAM is enabled.\r
+}\r
+\r
+static DECLFR(MAWRAM)\r
+{\r
+  if((DRegs[3]&0x10)&&!is155)\r
+    return X.DB;          // WRAM is disabled\r
+  return(Page[A>>11][A]);\r
+}\r
+\r
+static void MMC1CHR(void)\r
+{\r
+  if(mmc1opts&4)\r
+  {\r
+    if(DRegs[0]&0x10)\r
+      setprg8r(0x10,0x6000,(DRegs[1]>>4)&1);\r
+    else\r
+      setprg8r(0x10,0x6000,(DRegs[1]>>3)&1);\r
+  }\r
+\r
+  if(MMC1CHRHook4)\r
+  {\r
+    if(DRegs[0]&0x10)\r
+    {\r
+      MMC1CHRHook4(0x0000,DRegs[1]);\r
+      MMC1CHRHook4(0x1000,DRegs[2]);\r
+    }\r
+    else\r
+    {\r
+      MMC1CHRHook4(0x0000,(DRegs[1]&0xFE));\r
+      MMC1CHRHook4(0x1000,DRegs[1]|1);\r
+    }\r
+  }\r
+  else\r
+  {\r
+    if(DRegs[0]&0x10)\r
+    {\r
+      setchr4(0x0000,DRegs[1]);\r
+      setchr4(0x1000,DRegs[2]);\r
+    }\r
+    else\r
+      setchr8(DRegs[1]>>1);\r
+  }\r
+}\r
+\r
+static void MMC1PRG(void)\r
+{\r
+  uint8 offs=DRegs[1]&0x10;\r
+  if(MMC1PRGHook16)\r
+  {\r
+    switch(DRegs[0]&0xC)\r
+    {\r
+      case 0xC: MMC1PRGHook16(0x8000,(DRegs[3]+offs));\r
+                MMC1PRGHook16(0xC000,0xF+offs);\r
+                break;\r
+      case 0x8: MMC1PRGHook16(0xC000,(DRegs[3]+offs));\r
+                MMC1PRGHook16(0x8000,offs);\r
+                break;\r
+      case 0x0:\r
+      case 0x4:\r
+                MMC1PRGHook16(0x8000,((DRegs[3]&~1)+offs));\r
+                MMC1PRGHook16(0xc000,((DRegs[3]&~1)+offs+1));\r
+                break;\r
+    }\r
+  }\r
+  else\r
+  {\r
+    switch(DRegs[0]&0xC)\r
+  {\r
+    case 0xC: setprg16(0x8000,(DRegs[3]+offs));\r
+              setprg16(0xC000,0xF+offs);\r
+              break;\r
+    case 0x8: setprg16(0xC000,(DRegs[3]+offs));\r
+              setprg16(0x8000,offs);\r
+              break;\r
+    case 0x0:\r
+    case 0x4:\r
+              setprg16(0x8000,((DRegs[3]&~1)+offs));\r
+              setprg16(0xc000,((DRegs[3]&~1)+offs+1));\r
+              break;\r
+  }\r
+}\r
+}\r
+\r
+static void MMC1MIRROR(void)\r
+{\r
+  if(!is171) \r
+  switch(DRegs[0]&3)\r
+  {\r
+    case 2: setmirror(MI_V); break;\r
+    case 3: setmirror(MI_H); break;\r
+    case 0: setmirror(MI_0); break;\r
+    case 1: setmirror(MI_1); break;\r
+  }\r
+}\r
+\r
+static uint64 lreset;\r
+static DECLFW(MMC1_write)\r
+{\r
+  int n=(A>>13)-4;\r
+  //FCEU_DispMessage("%016x",0,timestampbase+timestamp);\r
+//  FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC);\r
+  //DumpMem("out",0xe000,0xffff);\r
+\r
+  /* The MMC1 is busy so ignore the write. */\r
+  /* As of version FCE Ultra 0.81, the timestamp is only\r
+     increased before each instruction is executed(in other words\r
+     precision isn't that great), but this should still work to\r
+          deal with 2 writes in a row from a single RMW instruction.\r
+       */\r
+  if((timestampbase+timestamp)<(lreset+2))\r
+    return;\r
+//  FCEU_printf("Write %04x:%02x\n",A,V);\r
+  if(V&0x80)\r
+  {\r
+    DRegs[0]|=0xC;\r
+    BufferShift=Buffer=0;\r
+    MMC1PRG();\r
+    lreset=timestampbase+timestamp;\r
+    return;\r
+  }\r
+\r
+  Buffer|=(V&1)<<(BufferShift++);\r
+\r
+  if(BufferShift==5)\r
+  {\r
+    DRegs[n] = Buffer;\r
+    BufferShift = Buffer = 0;\r
+    switch(n)\r
+    {\r
+      case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break;\r
+      case 1: MMC1CHR(); MMC1PRG(); break;\r
+      case 2: MMC1CHR(); break;\r
+      case 3: MMC1PRG(); break;\r
+    }\r
+  }\r
+}\r
+\r
+static void MMC1_Restore(int version)\r
+{\r
+  MMC1MIRROR();\r
+  MMC1CHR();\r
+  MMC1PRG();\r
+  lreset=0;        /* timestamp(base) is not stored in save states. */\r
+}\r
+\r
+static void MMC1CMReset(void)\r
+{\r
+  int i;\r
+\r
+  for(i=0;i<4;i++)\r
+     DRegs[i]=0;\r
+  Buffer = BufferShift = 0;\r
+  DRegs[0]=0x1F;\r
+\r
+  DRegs[1]=0;\r
+  DRegs[2]=0;                  // Should this be something other than 0?\r
+  DRegs[3]=0;\r
+\r
+  MMC1MIRROR();\r
+  MMC1CHR();\r
+  MMC1PRG();\r
+}\r
+\r
+static int DetectMMC1WRAMSize(uint32 crc32)\r
+{\r
+  switch(crc32)\r
+  {\r
+    case 0xc6182024:       /* Romance of the 3 Kingdoms */\r
+    case 0x2225c20f:       /* Genghis Khan */\r
+    case 0x4642dda6:       /* Nobunaga's Ambition */\r
+    case 0x29449ba9:       /* ""        "" (J) */\r
+    case 0x2b11e0b0:       /* ""        "" (J) */\r
+    case 0xb8747abf:       /* Best Play Pro Yakyuu Special (J) */\r
+    case 0xc9556b36:       /* Final Fantasy I & II (J) [!] */\r
+         FCEU_printf(" >8KB external WRAM present.  Use UNIF if you hack the ROM image.\n");\r
+         return(16);\r
+         break;\r
+    default:return(8);\r
+  }\r
+}\r
+\r
+static uint32 NWCIRQCount;\r
+static uint8 NWCRec;\r
+#define NWCDIP 0xE\r
+\r
+static void NWCIRQHook(int a)\r
+{\r
+  if(!(NWCRec&0x10))\r
+  {\r
+    NWCIRQCount+=a;\r
+    if((NWCIRQCount|(NWCDIP<<25))>=0x3e000000)\r
+    {\r
+      NWCIRQCount=0;\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+  }\r
+}\r
+\r
+static void NWCCHRHook(uint32 A, uint8 V)\r
+{\r
+  if((V&0x10)) // && !(NWCRec&0x10))\r
+  {\r
+    NWCIRQCount=0;\r
+    X6502_IRQEnd(FCEU_IQEXT);\r
+  }\r
+\r
+  NWCRec=V;\r
+  if(V&0x08)\r
+    MMC1PRG();\r
+  else\r
+    setprg32(0x8000,(V>>1)&3);\r
+}\r
+\r
+static void NWCPRGHook(uint32 A, uint8 V)\r
+{\r
+  if(NWCRec&0x8)\r
+    setprg16(A,8|(V&0x7));\r
+  else\r
+    setprg32(0x8000,(NWCRec>>1)&3);\r
+}\r
+\r
+static void NWCPower(void)\r
+{\r
+  GenMMC1Power();\r
+  setchr8r(0,0);\r
+}\r
+\r
+void Mapper105_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 256, 8, 0);\r
+  MMC1CHRHook4=NWCCHRHook;\r
+  MMC1PRGHook16=NWCPRGHook;\r
+  MapIRQHook=NWCIRQHook;\r
+  info->Power=NWCPower;\r
+}\r
+\r
+static void GenMMC1Power(void)\r
+{\r
+  lreset=0;\r
+  if(mmc1opts&1)\r
+  {\r
+    FCEU_CheatAddRAM(8,0x6000,WRAM);\r
+    if(mmc1opts&4)\r
+      FCEU_dwmemset(WRAM,0,8192)\r
+    else if(!(mmc1opts&2))\r
+      FCEU_dwmemset(WRAM,0,8192);\r
+  }\r
+  SetWriteHandler(0x8000,0xFFFF,MMC1_write);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+\r
+  if(mmc1opts&1)\r
+  {\r
+    SetReadHandler(0x6000,0x7FFF,MAWRAM);\r
+    SetWriteHandler(0x6000,0x7FFF,MBWRAM);\r
+    setprg8r(0x10,0x6000,0);\r
+  }\r
+\r
+  MMC1CMReset();\r
+}\r
+\r
+static void GenMMC1Close(void)\r
+{\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  CHRRAM=WRAM=NULL;\r
+}\r
+\r
+static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery)\r
+{\r
+  is155=0;\r
+\r
+  info->Close=GenMMC1Close;\r
+  MMC1PRGHook16=MMC1CHRHook4=0;\r
+  mmc1opts=0;\r
+  PRGmask16[0]&=(prg>>14)-1;\r
+  CHRmask4[0]&=(chr>>12)-1;\r
+  CHRmask8[0]&=(chr>>13)-1;\r
+\r
+  if(wram)\r
+  {\r
+    WRAM=(uint8*)FCEU_gmalloc(wram*1024);\r
+       //mbg 17-jun-08 - this shouldve been cleared to re-initialize save ram\r
+       //ch4 10-dec-08 - nope, this souldn't\r
+       //mbg 29-mar-09 - no time to debate this, we need to keep from breaking some old stuff.\r
+       //we really need to make up a policy for how compatibility and accuracy can be resolved.\r
+       memset(WRAM,0,wram*1024);\r
+    mmc1opts|=1;\r
+    if(wram>8) mmc1opts|=4;\r
+    SetupCartPRGMapping(0x10,WRAM,wram*1024,1);\r
+    AddExState(WRAM, wram*1024, 0, "WRAM");\r
+    if(battery)\r
+    {\r
+      mmc1opts|=2;\r
+      info->SaveGame[0]=WRAM+((mmc1opts&4)?8192:0);\r
+      info->SaveGameLen[0]=8192;\r
+    }\r
+  }\r
+  if(!chr)\r
+  {\r
+    CHRRAM=(uint8*)FCEU_gmalloc(8192);\r
+    SetupCartCHRMapping(0, CHRRAM, 8192, 1);\r
+    AddExState(CHRRAM, 8192, 0, "CHRR");\r
+  }\r
+  AddExState(DRegs, 4, 0, "DREG");\r
+\r
+  info->Power=GenMMC1Power;\r
+  GameStateRestore=MMC1_Restore;\r
+  AddExState(&lreset, 8, 1, "LRST");\r
+  AddExState(&Buffer, 1, 1, "BFFR");\r
+  AddExState(&BufferShift, 1, 1, "BFRS");\r
+}\r
+\r
+void Mapper1_Init(CartInfo *info)\r
+{\r
+  int ws=DetectMMC1WRAMSize(info->CRC32);\r
+  GenMMC1Init(info, 512, 256, ws, info->battery);\r
+}\r
+\r
+/* Same as mapper 1, without respect for WRAM enable bit. */\r
+void Mapper155_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info,512,256,8,info->battery);\r
+  is155=1;\r
+}\r
+\r
+/* Same as mapper 1, with different (or without) mirroring control. */\r
+/* Kaiser KS7058 board, KS203 custom chip */\r
+void Mapper171_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info,32,32,0,0);\r
+  is171=1;\r
+}\r
+\r
+void SAROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 128, 64, 8, info->battery);\r
+}\r
+\r
+void SBROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 128, 64, 0, 0);\r
+}\r
+\r
+void SCROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 128, 128, 0, 0);\r
+}\r
+\r
+void SEROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 32, 64, 0, 0);\r
+}\r
+\r
+void SGROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 0, 0, 0);\r
+}\r
+\r
+void SKROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 64, 8, info->battery);\r
+}\r
+\r
+void SLROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 128, 0, 0);\r
+}\r
+\r
+void SL1ROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 128, 128, 0, 0);\r
+}\r
+\r
+/* Begin unknown - may be wrong - perhaps they use different MMC1s from the\r
+   similarly functioning boards?\r
+*/\r
+\r
+void SL2ROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 256, 0, 0);\r
+}\r
+\r
+void SFROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 256, 0, 0);\r
+}\r
+\r
+void SHROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 256, 0, 0);\r
+}\r
+\r
+/* End unknown  */\r
+/*              */\r
+/*              */\r
+\r
+void SNROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 0, 8, info->battery);\r
+}\r
+\r
+void SOROM_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info, 256, 0, 16, info->battery);\r
+}\r
+\r
+\r
index bfee5cd..2618db4 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 1998 BERO\r
+ *  Copyright (C) 2003 Xodnizel\r
+ *  Mapper 12 code Copyright (C) 2003 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+/*  Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118,\r
+    119,165,205,214,215,245,249,250,254\r
+*/\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+uint8 MMC3_cmd;\r
+uint8 *WRAM;\r
+uint8 *CHRRAM;\r
+uint32 CHRRAMSize;\r
+uint8 DRegBuf[8];\r
+uint8 EXPREGS[8];    /* For bootleg games, mostly. */\r
+uint8 A000B,A001B;\r
+\r
+#undef IRQCount\r
+#undef IRQLatch\r
+#undef IRQa\r
+uint8 IRQCount,IRQLatch,IRQa;\r
+uint8 IRQReload;\r
+\r
+static SFORMAT MMC3_StateRegs[]=\r
+{\r
+ {DRegBuf, 8, "REGS"},\r
+ {&MMC3_cmd, 1, "CMD"},\r
+ {&A000B, 1, "A000"},\r
+ {&A001B, 1, "A001"},\r
+ {&IRQReload, 1, "IRQR"},\r
+ {&IRQCount, 1, "IRQC"},\r
+ {&IRQLatch, 1, "IRQL"},\r
+ {&IRQa, 1, "IRQA"},\r
+ {0}\r
+};\r
+\r
+static int mmc3opts=0;\r
+static int wrams;\r
+static int isRevB=1;\r
+\r
+void (*pwrap)(uint32 A, uint8 V);\r
+void (*cwrap)(uint32 A, uint8 V);\r
+void (*mwrap)(uint8 V);\r
+\r
+void GenMMC3Power(void);\r
+void FixMMC3PRG(int V);\r
+void FixMMC3CHR(int V);\r
+\r
+void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery);\r
+\r
+// ----------------------------------------------------------------------\r
+// ------------------------- Generic MM3 Code ---------------------------\r
+// ----------------------------------------------------------------------\r
+\r
+void FixMMC3PRG(int V)\r
+{\r
+ if(V&0x40)\r
+ {\r
+  pwrap(0xC000,DRegBuf[6]);\r
+  pwrap(0x8000,~1);\r
+ }\r
+ else\r
+ {\r
+  pwrap(0x8000,DRegBuf[6]);\r
+  pwrap(0xC000,~1);\r
+ }\r
+ pwrap(0xA000,DRegBuf[7]);\r
+ pwrap(0xE000,~0);\r
+}\r
+\r
+void FixMMC3CHR(int V)\r
+{\r
+ int cbase=(V&0x80)<<5;\r
+\r
+ cwrap((cbase^0x000),DRegBuf[0]&(~1));\r
+ cwrap((cbase^0x400),DRegBuf[0]|1);\r
+ cwrap((cbase^0x800),DRegBuf[1]&(~1));\r
+ cwrap((cbase^0xC00),DRegBuf[1]|1);\r
+\r
+ cwrap(cbase^0x1000,DRegBuf[2]);\r
+ cwrap(cbase^0x1400,DRegBuf[3]);\r
+ cwrap(cbase^0x1800,DRegBuf[4]);\r
+ cwrap(cbase^0x1c00,DRegBuf[5]);\r
+\r
+ if(mwrap) mwrap(A000B);\r
+}\r
+\r
+void MMC3RegReset(void)\r
+{\r
+ IRQCount=IRQLatch=IRQa=MMC3_cmd=0;\r
+\r
+ DRegBuf[0]=0;\r
+ DRegBuf[1]=2;\r
+ DRegBuf[2]=4;\r
+ DRegBuf[3]=5;\r
+ DRegBuf[4]=6;\r
+ DRegBuf[5]=7;\r
+ DRegBuf[6]=0;\r
+ DRegBuf[7]=1;\r
+\r
+ FixMMC3PRG(0);\r
+ FixMMC3CHR(0);\r
+}\r
+\r
+DECLFW(MMC3_CMDWrite)\r
+{\r
+// FCEU_printf("bs %04x %02x\n",A,V);\r
+ switch(A&0xE001)\r
+ {\r
+  case 0x8000:\r
+       if((V&0x40) != (MMC3_cmd&0x40))\r
+          FixMMC3PRG(V);\r
+       if((V&0x80) != (MMC3_cmd&0x80))\r
+          FixMMC3CHR(V);\r
+       MMC3_cmd = V;\r
+       break;\r
+  case 0x8001:\r
+       {\r
+        int cbase=(MMC3_cmd&0x80)<<5;\r
+        DRegBuf[MMC3_cmd&0x7]=V;\r
+        switch(MMC3_cmd&0x07)\r
+        {\r
+         case 0: cwrap((cbase^0x000),V&(~1));\r
+                 cwrap((cbase^0x400),V|1);\r
+                 break;\r
+         case 1: cwrap((cbase^0x800),V&(~1));\r
+                 cwrap((cbase^0xC00),V|1);\r
+                 break;\r
+         case 2: cwrap(cbase^0x1000,V);\r
+                 break;\r
+         case 3: cwrap(cbase^0x1400,V);\r
+                 break;\r
+         case 4: cwrap(cbase^0x1800,V);\r
+                 break;\r
+         case 5: cwrap(cbase^0x1C00,V);\r
+                 break;\r
+         case 6:\r
+                 if(MMC3_cmd&0x40)\r
+                    pwrap(0xC000,V);\r
+                 else\r
+                    pwrap(0x8000,V);\r
+                 break;\r
+         case 7:\r
+                 pwrap(0xA000,V);\r
+                 break;\r
+        }\r
+       }\r
+       break;\r
+  case 0xA000:\r
+       if(mwrap) mwrap(V);\r
+       break;\r
+  case 0xA001:\r
+       A001B=V;\r
+       break;\r
+ }\r
+}\r
+\r
+DECLFW(MMC3_IRQWrite)\r
+{\r
+// FCEU_printf("%04x:%04x\n",A,V);\r
+ switch(A&0xE001)\r
+ {\r
+  case 0xC000:IRQLatch=V;break;\r
+  case 0xC001:IRQReload=1;break;\r
+  case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break;\r
+  case 0xE001:IRQa=1;break;\r
+ }\r
+}\r
+\r
+static void ClockMMC3Counter(void)\r
+{\r
+ int count = IRQCount;\r
+ if(!count || IRQReload)\r
+ {\r
+    IRQCount = IRQLatch;\r
+    IRQReload = 0;\r
+ }\r
+ else\r
+    IRQCount--;\r
+ if((count|isRevB) && !IRQCount)\r
+ {\r
+    if(IRQa)\r
+    {\r
+       X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+ }\r
+}\r
+\r
+static void MMC3_hb(void)\r
+{\r
+ ClockMMC3Counter();\r
+}\r
+\r
+static void MMC3_hb_KickMasterHack(void)\r
+{\r
+ if(scanline==238) ClockMMC3Counter();\r
+ ClockMMC3Counter();\r
+}\r
+\r
+static void MMC3_hb_PALStarWarsHack(void)\r
+{\r
+ if(scanline==240) ClockMMC3Counter();\r
+ ClockMMC3Counter();\r
+}\r
+\r
+void GenMMC3Restore(int version)\r
+{\r
+ FixMMC3PRG(MMC3_cmd);\r
+ FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void GENCWRAP(uint32 A, uint8 V)\r
+{\r
+   setchr1(A,V);    // Business Wars NEEDS THIS for 8K CHR-RAM\r
+}\r
+\r
+static void GENPWRAP(uint32 A, uint8 V)\r
+{\r
+ setprg8(A,V&0x7F); // [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken\r
+}\r
+\r
+static void GENMWRAP(uint8 V)\r
+{\r
+ A000B=V;\r
+ setmirror((V&1)^1);\r
+}\r
+\r
+static void GENNOMWRAP(uint8 V)\r
+{\r
+ A000B=V;\r
+}\r
+\r
+static DECLFW(MBWRAMMMC6)\r
+{\r
+ WRAM[A&0x3ff]=V;\r
+}\r
+\r
+static DECLFR(MAWRAMMMC6)\r
+{\r
+ return(WRAM[A&0x3ff]);\r
+}\r
+\r
+void GenMMC3Power(void)\r
+{\r
+ if(UNIFchrrama) setchr8(0);\r
+\r
+ SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite);\r
+ SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ A001B=A000B=0;\r
+ setmirror(1);\r
+ if(mmc3opts&1)\r
+ {\r
+  if(wrams==1024)\r
+  {\r
+   FCEU_CheatAddRAM(1,0x7000,WRAM);\r
+   SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6);\r
+   SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6);\r
+  }\r
+  else\r
+  {\r
+   FCEU_CheatAddRAM((wrams&0x1fff)>>10,0x6000,WRAM);\r
+   SetWriteHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBW);\r
+   SetReadHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBR);\r
+   setprg8r(0x10,0x6000,0);\r
+  }\r
+  if(!(mmc3opts&2))\r
+     FCEU_dwmemset(WRAM,0,wrams);\r
+ }\r
+ MMC3RegReset();\r
+ if(CHRRAM)\r
+  FCEU_dwmemset(CHRRAM,0,CHRRAMSize);\r
+}\r
+\r
+static void GenMMC3Close(void)\r
+{\r
+ if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+ if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+ CHRRAM=WRAM=NULL;\r
+}\r
+\r
+void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery)\r
+{\r
+ pwrap=GENPWRAP;\r
+ cwrap=GENCWRAP;\r
+ mwrap=GENMWRAP;\r
+\r
+ wrams=wram<<10;\r
+\r
+ PRGmask8[0]&=(prg>>13)-1;\r
+ CHRmask1[0]&=(chr>>10)-1;\r
+ CHRmask2[0]&=(chr>>11)-1;\r
+\r
+ if(wram)\r
+ {\r
+  mmc3opts|=1;\r
+  WRAM=(uint8*)FCEU_gmalloc(wrams);\r
+  SetupCartPRGMapping(0x10,WRAM,wrams,1);\r
+  AddExState(WRAM, wrams, 0, "MMC3WRAM");\r
+ }\r
+\r
+ if(battery)\r
+ {\r
+  mmc3opts|=2;\r
+  info->SaveGame[0]=WRAM;\r
+  info->SaveGameLen[0]=wrams;\r
+ }\r
+\r
+ AddExState(MMC3_StateRegs, ~0, 0, 0);\r
+\r
+ info->Power=GenMMC3Power;\r
+ info->Reset=MMC3RegReset;\r
+ info->Close=GenMMC3Close;\r
+\r
+ if(info->CRC32 == 0x5104833e)        // Kick Master\r
+  GameHBIRQHook = MMC3_hb_KickMasterHack;\r
+ else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93\r
+  GameHBIRQHook = MMC3_hb_KickMasterHack;\r
+ else if(info->CRC32 == 0xfcd772eb)    // PAL Star Wars, similar problem as Kick Master.\r
+  GameHBIRQHook = MMC3_hb_PALStarWarsHack;\r
+ else\r
+  GameHBIRQHook=MMC3_hb;\r
+ GameStateRestore=GenMMC3Restore;\r
+}\r
+\r
+// ----------------------------------------------------------------------\r
+// -------------------------- MMC3 Based Code ---------------------------\r
+// ----------------------------------------------------------------------\r
+\r
+// ---------------------------- Mapper 4 --------------------------------\r
+\r
+static int hackm4=0;/* For Karnov, maybe others.  BLAH.  Stupid iNES format.*/\r
+\r
+static void M4Power(void)\r
+{\r
+ GenMMC3Power();\r
+ A000B=(hackm4^1)&1;\r
+ setmirror(hackm4);\r
+}\r
+\r
+void Mapper4_Init(CartInfo *info)\r
+{\r
+ int ws=8;\r
+\r
+ if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84))\r
+ {\r
+  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");\r
+  ws=0;\r
+ }\r
+ GenMMC3_Init(info,512,256,ws,info->battery);\r
+ info->Power=M4Power;\r
+ hackm4=info->mirror;\r
+}\r
+\r
+// ---------------------------- Mapper 12 -------------------------------\r
+\r
+static void M12CW(uint32 A, uint8 V)\r
+{\r
+ setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V);\r
+}\r
+\r
+static DECLFW(M12Write)\r
+{\r
+ EXPREGS[0]=V&0x01;\r
+ EXPREGS[1]=(V&0x10)>>4;\r
+}\r
+\r
+static void M12Power(void)\r
+{\r
+ EXPREGS[0]=EXPREGS[1]=0;\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x4100,0x5FFF,M12Write);\r
+}\r
+\r
+void Mapper12_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M12CW;\r
+ isRevB=0;\r
+\r
+ info->Power=M12Power;\r
+ AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 37 -------------------------------\r
+\r
+static void M37PW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]!=2)\r
+    V&=0x7;\r
+  else\r
+    V&=0xF;\r
+  V|=EXPREGS[0]<<3;\r
+  setprg8(A,V);\r
+}\r
+\r
+static void M37CW(uint32 A, uint8 V)\r
+{\r
+  uint32 NV=V;\r
+  NV&=0x7F;\r
+  NV|=EXPREGS[0]<<6;\r
+  setchr1(A,NV);\r
+}\r
+\r
+static DECLFW(M37Write)\r
+{\r
+  EXPREGS[0]=(V&6)>>1;\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void M37Reset(void)\r
+{\r
+  EXPREGS[0]=0;\r
+  MMC3RegReset();\r
+}\r
+\r
+static void M37Power(void)\r
+{\r
+  EXPREGS[0]=0;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x6000,0x7FFF,M37Write);\r
+}\r
+\r
+void Mapper37_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+  pwrap=M37PW;\r
+  cwrap=M37CW;\r
+  info->Power=M37Power;\r
+  info->Reset=M37Reset;\r
+  AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 44 -------------------------------\r
+\r
+static void M44PW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V;\r
+ if(EXPREGS[0]>=6) NV&=0x1F;\r
+ else NV&=0x0F;\r
+ NV|=EXPREGS[0]<<4;\r
+ setprg8(A,NV);\r
+}\r
+\r
+static void M44CW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V;\r
+ if(EXPREGS[0]<6) NV&=0x7F;\r
+ NV|=EXPREGS[0]<<7;\r
+ setchr1(A,NV);\r
+}\r
+\r
+static DECLFW(M44Write)\r
+{\r
+ if(A&1)\r
+ {\r
+  EXPREGS[0]=V&7;\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+ }\r
+ else\r
+  MMC3_CMDWrite(A,V);\r
+}\r
+\r
+static void M44Power(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ GenMMC3Power();\r
+ SetWriteHandler(0xA000,0xBFFF,M44Write);\r
+}\r
+\r
+void Mapper44_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M44CW;\r
+ pwrap=M44PW;\r
+ info->Power=M44Power;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 45 -------------------------------\r
+\r
+static void M45CW(uint32 A, uint8 V)\r
+{\r
+ if(!UNIFchrrama)\r
+ {\r
+   uint32 NV=V;\r
+   if(EXPREGS[2]&8)\r
+      NV&=(1<<((EXPREGS[2]&7)+1))-1;\r
+   else\r
+      if(EXPREGS[2])\r
+         NV&=0; // hack ;( don't know exactly how it should be\r
+   NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4);\r
+   setchr1(A,NV);\r
+ }\r
+}\r
+\r
+static void M45PW(uint32 A, uint8 V)\r
+{\r
+ V&=(EXPREGS[3]&0x3F)^0x3F;\r
+ V|=EXPREGS[1];\r
+ setprg8(A,V);\r
+}\r
+\r
+static DECLFW(M45Write)\r
+{\r
+ if(EXPREGS[3]&0x40)\r
+ {\r
+  WRAM[A-0x6000]=V;\r
+  return;\r
+ }\r
+ EXPREGS[EXPREGS[4]]=V;\r
+ EXPREGS[4]=(EXPREGS[4]+1)&3;\r
+// if(!EXPREGS[4]) \r
+// {\r
+//   FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]);\r
+//   FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n",\r
+//               (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),\r
+//               (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),\r
+//               (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]),\r
+//               (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]));\r
+// }\r
+ FixMMC3PRG(MMC3_cmd);\r
+ FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void M45Reset(void)\r
+{\r
+ EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+static void M45Power(void)\r
+{\r
+ setchr8(0);\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x6000,0x7FFF,M45Write);\r
+}\r
+\r
+void Mapper45_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M45CW;\r
+ pwrap=M45PW;\r
+ info->Reset=M45Reset;\r
+ info->Power=M45Power;\r
+ AddExState(EXPREGS, 5, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 47 -------------------------------\r
+\r
+static void M47PW(uint32 A, uint8 V)\r
+{\r
+ V&=0xF;\r
+ V|=EXPREGS[0]<<4;\r
+ setprg8(A,V);\r
+}\r
+\r
+static void M47CW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V;\r
+ NV&=0x7F;\r
+ NV|=EXPREGS[0]<<7;\r
+ setchr1(A,NV);\r
+}\r
+\r
+static DECLFW(M47Write)\r
+{\r
+ EXPREGS[0]=V&1;\r
+ FixMMC3PRG(MMC3_cmd);\r
+ FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void M47Power(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x6000,0x7FFF,M47Write);\r
+// SetReadHandler(0x6000,0x7FFF,0);\r
+}\r
+\r
+void Mapper47_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, 0);\r
+ pwrap=M47PW;\r
+ cwrap=M47CW;\r
+ info->Power=M47Power;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 49 -------------------------------\r
+\r
+static void M49PW(uint32 A, uint8 V)\r
+{\r
+ if(EXPREGS[0]&1)\r
+ {\r
+  V&=0xF;\r
+  V|=(EXPREGS[0]&0xC0)>>2;\r
+  setprg8(A,V);\r
+ }\r
+ else\r
+  setprg32(0x8000,(EXPREGS[0]>>4)&3);\r
+}\r
+\r
+static void M49CW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V;\r
+ NV&=0x7F;\r
+ NV|=(EXPREGS[0]&0xC0)<<1;\r
+ setchr1(A,NV);\r
+}\r
+\r
+static DECLFW(M49Write)\r
+{\r
+ if(A001B&0x80)\r
+ {\r
+  EXPREGS[0]=V;\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+ }\r
+}\r
+\r
+static void M49Reset(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+static void M49Power(void)\r
+{\r
+ M49Reset();\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x6000,0x7FFF,M49Write);\r
+ SetReadHandler(0x6000,0x7FFF,0);\r
+}\r
+\r
+void Mapper49_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 0, 0);\r
+ cwrap=M49CW;\r
+ pwrap=M49PW;\r
+ info->Reset=M49Reset;\r
+ info->Power=M49Power;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 52 -------------------------------\r
+\r
+static void M52PW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V;\r
+ NV&=0x1F^((EXPREGS[0]&8)<<1);\r
+ NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4;\r
+ setprg8(A,NV);\r
+}\r
+\r
+static void M52CW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V;\r
+ NV&=0xFF^((EXPREGS[0]&0x40)<<1);\r
+ NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7;\r
+ setchr1(A,NV);\r
+}\r
+\r
+static DECLFW(M52Write)\r
+{\r
+ if(EXPREGS[1])\r
+ {\r
+  WRAM[A-0x6000]=V;\r
+  return;\r
+ }\r
+ EXPREGS[1]=1;\r
+ EXPREGS[0]=V;\r
+ FixMMC3PRG(MMC3_cmd);\r
+ FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void M52Reset(void)\r
+{\r
+ EXPREGS[0]=EXPREGS[1]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+static void M52Power(void)\r
+{\r
+ M52Reset();\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x6000,0x7FFF,M52Write);\r
+}\r
+\r
+void Mapper52_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M52CW;\r
+ pwrap=M52PW;\r
+ info->Reset=M52Reset;\r
+ info->Power=M52Power;\r
+ AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 74 -------------------------------\r
+\r
+static void M74CW(uint32 A, uint8 V)\r
+{\r
+  if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes\r
+    setchr1r(0x10,A,V);\r
+  else\r
+    setchr1r(0,A,V);\r
+}\r
+\r
+void Mapper74_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M74CW;\r
+ CHRRAMSize=2048;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+ AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+}\r
+\r
+// ---------------------------- Mapper 114 ------------------------------\r
+\r
+static uint8 cmdin;\r
+uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4};\r
+\r
+static void M114PWRAP(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x80)\r
+  {\r
+    setprg16(0x8000,EXPREGS[0]&0xF);\r
+    setprg16(0xC000,EXPREGS[0]&0xF);\r
+  }\r
+  else\r
+    setprg8(A,V&0x3F);\r
+}\r
+\r
+static DECLFW(M114Write)\r
+{\r
+ switch(A&0xE001)\r
+ {\r
+  case 0x8001: MMC3_CMDWrite(0xA000,V); break;\r
+  case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break;\r
+  case 0xC000: if(!cmdin) break; MMC3_CMDWrite(0x8001,V); cmdin=0; break;\r
+  case 0xA001: IRQLatch=V; break;\r
+  case 0xC001: IRQReload=1; break;\r
+  case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break;\r
+  case 0xE001: IRQa=1; break;\r
+ }\r
+}\r
+\r
+static DECLFW(M114ExWrite)\r
+{\r
+  if(A<=0x7FFF)\r
+  {\r
+   EXPREGS[0]=V;\r
+   FixMMC3PRG(MMC3_cmd);\r
+  }\r
+}\r
+\r
+static void M114Power(void)\r
+{\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x8000,0xFFFF,M114Write);\r
+ SetWriteHandler(0x5000,0x7FFF,M114ExWrite);\r
+}\r
+\r
+static void M114Reset(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+void Mapper114_Init(CartInfo *info)\r
+{\r
+ isRevB=0;\r
+ GenMMC3_Init(info, 256, 256, 0, 0);\r
+ pwrap=M114PWRAP;\r
+ info->Power=M114Power;\r
+ info->Reset=M114Reset;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+ AddExState(&cmdin, 1, 0, "CMDIN");\r
+}\r
+\r
+// ---------------------------- Mapper 115 ------------------------------\r
+\r
+static void M115PW(uint32 A, uint8 V)\r
+{\r
+       //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.\r
+       GENPWRAP(A,V);\r
+       if(A==0x8000 && EXPREGS[0]&0x80)\r
+               setprg16(0x8000,(EXPREGS[0]&0xF));\r
+}\r
+\r
+static void M115CW(uint32 A, uint8 V)\r
+{\r
+  setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8));\r
+}\r
+\r
+static DECLFW(M115Write)\r
+{\r
+// FCEU_printf("%04x:%04x\n",A,V);\r
+ if(A==0x5080) EXPREGS[2]=V;\r
+ if(A==0x6000)\r
+    EXPREGS[0]=V;\r
+ else if(A==0x6001)\r
+    EXPREGS[1]=V;\r
+ FixMMC3PRG(MMC3_cmd);\r
+}\r
+\r
+static DECLFR(M115Read)\r
+{\r
+ return EXPREGS[2];\r
+}\r
+\r
+static void M115Power(void)\r
+{\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x4100,0x7FFF,M115Write);\r
+ SetReadHandler(0x5000,0x5FFF,M115Read);\r
+}\r
+\r
+void Mapper115_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 128, 512, 0, 0);\r
+ cwrap=M115CW;\r
+ pwrap=M115PW;\r
+ info->Power=M115Power;\r
+ AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 118 ------------------------------\r
+\r
+static uint8 PPUCHRBus;\r
+static uint8 TKSMIR[8];\r
+\r
+static void TKSPPU(uint32 A)\r
+{\r
+ A&=0x1FFF;\r
+ A>>=10;\r
+ PPUCHRBus=A;\r
+ setmirror(MI_0+TKSMIR[A]);\r
+}\r
+\r
+static void TKSWRAP(uint32 A, uint8 V)\r
+{\r
+ TKSMIR[A>>10]=V>>7;\r
+ setchr1(A,V&0x7F);\r
+ if(PPUCHRBus==(A>>10))\r
+    setmirror(MI_0+(V>>7));\r
+}\r
+\r
+// ---------------------------- Mapper 119 ------------------------------\r
+\r
+static void TQWRAP(uint32 A, uint8 V)\r
+{\r
+ setchr1r((V&0x40)>>2,A,V&0x3F);\r
+}\r
+\r
+void Mapper119_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 64, 0, 0);\r
+ cwrap=TQWRAP;\r
+ CHRRAMSize=8192;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+}\r
+\r
+// ---------------------------- Mapper 134 ------------------------------\r
+\r
+static void M134PW(uint32 A, uint8 V)\r
+{\r
+  setprg8(A,(V&0x1F)|((EXPREGS[0]&2)<<4));\r
+}\r
+\r
+static void M134CW(uint32 A, uint8 V)\r
+{\r
+  setchr1(A,(V&0xFF)|((EXPREGS[0]&0x20)<<3));\r
+}\r
+\r
+static DECLFW(M134Write)\r
+{\r
+  EXPREGS[0]=V;\r
+  FixMMC3CHR(MMC3_cmd);\r
+  FixMMC3PRG(MMC3_cmd);\r
+}\r
+\r
+static void M134Power(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x6001,0x6001,M134Write);\r
+}\r
+\r
+static void M134Reset(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+void Mapper134_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 256, 256, 0, 0);\r
+ pwrap=M134PW;\r
+ cwrap=M134CW;\r
+ info->Power=M134Power;\r
+ info->Reset=M134Reset;\r
+ AddExState(EXPREGS, 4, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 165 ------------------------------\r
+\r
+static void M165CW(uint32 A, uint8 V)\r
+{\r
+ if(V==0)\r
+    setchr4r(0x10,A,0);\r
+ else\r
+    setchr4(A,V>>2);\r
+}\r
+\r
+static void M165PPUFD(void)\r
+{\r
+ if(EXPREGS[0]==0xFD)\r
+ {\r
+  M165CW(0x0000,DRegBuf[0]);\r
+  M165CW(0x1000,DRegBuf[2]);\r
+ }\r
+}\r
+\r
+static void M165PPUFE(void)\r
+{\r
+ if(EXPREGS[0]==0xFE)\r
+ {\r
+  M165CW(0x0000,DRegBuf[1]);\r
+  M165CW(0x1000,DRegBuf[4]);\r
+ }\r
+}\r
+\r
+static void M165CWM(uint32 A, uint8 V)\r
+{\r
+ if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2))\r
+   M165PPUFD();\r
+ if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4))\r
+   M165PPUFE();\r
+}\r
+\r
+static void M165PPU(uint32 A)\r
+{\r
+ if((A&0x1FF0)==0x1FD0)\r
+ {\r
+  EXPREGS[0]=0xFD;\r
+  M165PPUFD();\r
+ } else if((A&0x1FF0)==0x1FE0)\r
+ {\r
+  EXPREGS[0]=0xFE;\r
+  M165PPUFE();\r
+ }\r
+}\r
+\r
+static void M165Power(void)\r
+{\r
+ EXPREGS[0]=0xFD;\r
+ GenMMC3Power();\r
+}\r
+\r
+void Mapper165_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 128, 8, info->battery);\r
+ cwrap=M165CWM;\r
+ PPU_hook=M165PPU;\r
+ info->Power=M165Power;\r
+ CHRRAMSize = 4096;\r
+ CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+ AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+ AddExState(EXPREGS, 4, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 191 ------------------------------\r
+\r
+static void M191CW(uint32 A, uint8 V)\r
+{\r
+  setchr1r((V&0x80)>>3,A,V);\r
+}\r
+\r
+void Mapper191_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 256, 256, 8, info->battery);\r
+ cwrap=M191CW;\r
+ CHRRAMSize=2048;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+ AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+}\r
+\r
+// ---------------------------- Mapper 192 -------------------------------\r
+\r
+static void M192CW(uint32 A, uint8 V)\r
+{\r
+  if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese),\r
+    setchr1r(0x10,A,V);\r
+  else\r
+    setchr1r(0,A,V);\r
+}\r
+\r
+void Mapper192_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M192CW;\r
+ CHRRAMSize=4096;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+ AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+}\r
+\r
+// ---------------------------- Mapper 194 -------------------------------\r
+\r
+static void M194CW(uint32 A, uint8 V)\r
+{\r
+  if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes\r
+    setchr1r(0x10,A,V);\r
+  else\r
+    setchr1r(0,A,V);\r
+}\r
+\r
+void Mapper194_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M194CW;\r
+ CHRRAMSize=2048;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+ AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+}\r
+\r
+// ---------------------------- Mapper 195 -------------------------------\r
+static uint8 *wramtw;\r
+static uint16 wramsize;\r
+\r
+static void M195CW(uint32 A, uint8 V)\r
+{\r
+  if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C)\r
+    setchr1r(0x10,A,V);\r
+  else\r
+    setchr1r(0,A,V);\r
+}\r
+\r
+static void M195Power(void)\r
+{\r
+ GenMMC3Power();\r
+ setprg4r(0x10,0x5000,0);\r
+ SetWriteHandler(0x5000,0x5fff,CartBW);\r
+ SetReadHandler(0x5000,0x5fff,CartBR);\r
+}\r
+\r
+static void M195Close(void)\r
+{\r
+  if(wramtw)\r
+    FCEU_gfree(wramtw);\r
+  wramtw=NULL;\r
+}\r
+\r
+void Mapper195_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M195CW;\r
+ info->Power=M195Power;\r
+ info->Close=M195Close;\r
+ CHRRAMSize=4096;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+ wramsize=4096;\r
+ wramtw=(uint8*)FCEU_gmalloc(wramsize);\r
+ SetupCartPRGMapping(0x10, wramtw, wramsize, 1);\r
+ AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+ AddExState(wramtw, wramsize, 0, "WRAMTW");\r
+}\r
+\r
+// ---------------------------- Mapper 196 -------------------------------\r
+\r
+static DECLFW(Mapper196Write)\r
+{\r
+  A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1);\r
+  if(A >= 0xC000)\r
+   MMC3_IRQWrite(A,V);\r
+  else\r
+   MMC3_CMDWrite(A,V);\r
+}\r
+\r
+static void Mapper196Power(void)\r
+{\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x8000,0xFFFF,Mapper196Write);\r
+}\r
+\r
+void Mapper196_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 128, 0, 0);\r
+  info->Power=Mapper196Power;\r
+}\r
+\r
+// ---------------------------- Mapper 197 -------------------------------\r
+\r
+static void M197CW(uint32 A, uint8 V)\r
+{\r
+  if(A==0x0000)\r
+    setchr4(0x0000,V>>1);\r
+  else if(A==0x1000)\r
+    setchr2(0x1000,V);\r
+  else if(A==0x1400)\r
+    setchr2(0x1800,V);\r
+}\r
+\r
+void Mapper197_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 128, 512, 8, 0);\r
+ cwrap=M197CW;\r
+}\r
+\r
+// ---------------------------- Mapper 198 -------------------------------\r
+\r
+static void M198PW(uint32 A, uint8 V)\r
+{\r
+  if(V>=0x50) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes\r
+    setprg8(A,V&0x4F);\r
+  else\r
+    setprg8(A,V);\r
+}\r
+\r
+void Mapper198_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 1024, 256, 8, info->battery);\r
+ pwrap=M198PW;\r
+ info->Power=M195Power;\r
+ info->Close=M195Close;\r
+ wramsize=4096;\r
+ wramtw=(uint8*)FCEU_gmalloc(wramsize);\r
+ SetupCartPRGMapping(0x10, wramtw, wramsize, 1);\r
+ AddExState(wramtw, wramsize, 0, "WRAMTW");\r
+}\r
+\r
+// ---------------------------- Mapper 205 ------------------------------\r
+\r
+static void M205PW(uint32 A, uint8 V)\r
+{\r
+ if(EXPREGS[0]&2)\r
+    setprg8(A,(V&0x0f)|((EXPREGS[0]&3)<<4));\r
+ else\r
+    setprg8(A,(V&0x1f)|((EXPREGS[0]&3)<<4));\r
+}\r
+\r
+static void M205CW(uint32 A, uint8 V)\r
+{\r
+ setchr1(A,V|((EXPREGS[0]&3)<<7));\r
+}\r
+\r
+static DECLFW(M205Write)\r
+{\r
+ if((A&0x6800)==0x6800) EXPREGS[0]= V;\r
+ FixMMC3PRG(MMC3_cmd);\r
+ FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void M205Reset(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+static void M205Power(void)\r
+{\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x4020,0x7FFF,M205Write);\r
+}\r
+\r
+void Mapper205_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, 0);\r
+ pwrap=M205PW;\r
+ cwrap=M205CW;\r
+ info->Power=M205Power;\r
+ info->Reset=M205Reset;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 245 ------------------------------\r
+\r
+static void M245CW(uint32 A, uint8 V)\r
+{\r
+ if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart\r
+  setchr1(A,V&7);\r
+ EXPREGS[0]=V;\r
+ FixMMC3PRG(MMC3_cmd);\r
+}\r
+\r
+static void M245PW(uint32 A, uint8 V)\r
+{\r
+ setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5));\r
+}\r
+\r
+static void M245Power(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ GenMMC3Power();\r
+}\r
+\r
+void Mapper245_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M245CW;\r
+ pwrap=M245PW;\r
+ info->Power=M245Power;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 249 ------------------------------\r
+\r
+static void M249PW(uint32 A, uint8 V)\r
+{\r
+ if(EXPREGS[0]&0x2)\r
+ {\r
+  if(V<0x20)\r
+   V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10);\r
+  else\r
+  {\r
+   V-=0x20;\r
+   V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);\r
+  }\r
+ }\r
+ setprg8(A,V);\r
+}\r
+\r
+static void M249CW(uint32 A, uint8 V)\r
+{\r
+ if(EXPREGS[0]&0x2)\r
+    V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);\r
+ setchr1(A,V);\r
+}\r
+\r
+static DECLFW(M249Write)\r
+{\r
+ EXPREGS[0]=V;\r
+ FixMMC3PRG(MMC3_cmd);\r
+ FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static void M249Power(void)\r
+{\r
+ EXPREGS[0]=0;\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x5000,0x5000,M249Write);\r
+}\r
+\r
+void Mapper249_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=M249CW;\r
+ pwrap=M249PW;\r
+ info->Power=M249Power;\r
+ AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- Mapper 250 ------------------------------\r
+\r
+static DECLFW(M250Write)\r
+{\r
+ MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);\r
+}\r
+\r
+static DECLFW(M250IRQWrite)\r
+{\r
+ MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);\r
+}\r
+\r
+static void M250_Power(void)\r
+{\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x8000,0xBFFF,M250Write);\r
+ SetWriteHandler(0xC000,0xFFFF,M250IRQWrite);\r
+}\r
+\r
+void Mapper250_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ info->Power=M250_Power;\r
+}\r
+\r
+// ---------------------------- Mapper 254 ------------------------------\r
+\r
+static DECLFR(MR254WRAM)\r
+{\r
+  if(EXPREGS[0])\r
+    return WRAM[A-0x6000];\r
+  else\r
+    return WRAM[A-0x6000]^EXPREGS[1];\r
+}\r
+\r
+static DECLFW(M254Write)\r
+{\r
+ switch (A) {\r
+  case 0x8000: EXPREGS[0]=0xff;\r
+               break;\r
+  case 0xA001: EXPREGS[1]=V;\r
+ }\r
+ MMC3_CMDWrite(A,V);\r
+}\r
+\r
+static void M254_Power(void)\r
+{\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x8000,0xBFFF,M254Write);\r
+ SetReadHandler(0x6000,0x7FFF,MR254WRAM);\r
+}\r
+\r
+void Mapper254_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 128, 128, 8, info->battery);\r
+ info->Power=M254_Power;\r
+ AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r
+\r
+// ---------------------------- UNIF Boards -----------------------------\r
+\r
+void TBROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 64, 64, 0, 0);\r
+}\r
+\r
+void TEROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 32, 32, 0, 0);\r
+}\r
+\r
+void TFROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 64, 0, 0);\r
+}\r
+\r
+void TGROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 0, 0, 0);\r
+}\r
+\r
+void TKROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+}\r
+\r
+void TLROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 0, 0);\r
+}\r
+\r
+void TSROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, 0);\r
+}\r
+\r
+void TLSROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, 0);\r
+ cwrap=TKSWRAP;\r
+ mwrap=GENNOMWRAP;\r
+ PPU_hook=TKSPPU;\r
+ AddExState(&PPUCHRBus, 1, 0, "PPUC");\r
+}\r
+\r
+void TKSROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+ cwrap=TKSWRAP;\r
+ mwrap=GENNOMWRAP;\r
+ PPU_hook=TKSPPU;\r
+ AddExState(&PPUCHRBus, 1, 0, "PPUC");\r
+}\r
+\r
+void TQROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 64, 0, 0);\r
+ cwrap=TQWRAP;\r
+ CHRRAMSize=8192;\r
+ CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+ SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+}\r
+\r
+void HKROM_Init(CartInfo *info)\r
+{\r
+ GenMMC3_Init(info, 512, 512, 1, info->battery);\r
+}\r
index 6692dd4..a5e03cd 100644 (file)
@@ -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;\r
+extern uint8 A000B;\r
+extern uint8 A001B;\r
+extern uint8 EXPREGS[8];\r
+extern uint8 DRegBuf[8];\r
+\r
+#undef IRQCount\r
+#undef IRQLatch\r
+#undef IRQa\r
+extern uint8 IRQCount,IRQLatch,IRQa;\r
+extern uint8 IRQReload;\r
+\r
+extern void (*pwrap)(uint32 A, uint8 V);\r
+extern void (*cwrap)(uint32 A, uint8 V);\r
+extern void (*mwrap)(uint8 V);\r
+\r
+void GenMMC3Power(void);\r
+void GenMMC3Restore(int version);\r
+void MMC3RegReset(void);\r
+void FixMMC3PRG(int V);\r
+void FixMMC3CHR(int V);\r
+DECLFW(MMC3_CMDWrite);\r
+DECLFW(MMC3_IRQWrite);\r
+\r
+void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery);\r
index d14ca0e..1916df9 100644 (file)
-/* 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;x<MMC5_NOCARTS;x++)
-  if(crc32==MMC5CartList[x].crc32)
-  {
-    FCEU_printf(" >8KB 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<<x;vnapage[x]=NTARAM;break;
-                  case 1:PPUNTARAM|=1<<x;vnapage[x]=NTARAM+0x400;break;
-                  case 2:PPUNTARAM|=1<<x;vnapage[x]=ExRAM;break;
-                  case 3:PPUNTARAM&=~(1<<x);vnapage[x]=MMC5fill;break;
-                 }
-                }
-               }
-               NTAMirroring=V;
-               break;
-    case 0x5113: WRAMPage=V;MMC5WRAM(0x6000,V&7);break;
-    case 0x5100: mmc5psize=V;MMC5PRG();break;
-    case 0x5101: mmc5vsize=V;
-                 if(!ABMode)
-                 { MMC5CHRB();MMC5CHRA();}
-                 else
-                 { MMC5CHRA();MMC5CHRB();}
-                 break;
-   case 0x5114:
-   case 0x5115:
-   case 0x5116:
-    case 0x5117: PRGBanks[A&3]=V;MMC5PRG();break;
-   case 0x5128:
-   case 0x5129:
-   case 0x512a:
-    case 0x512b: ABMode=1;
-               CHRBanksB[A&3]=V;
-               MMC5CHRB();
-               break;
-    case 0x5102: WRAMMaskEnable[0]=V;break;
-    case 0x5103: WRAMMaskEnable[1]=V;break;
-    case 0x5104: CHRMode=V;MMC5HackCHRMode=V&3;break;
-    case 0x5106: if(V!=NTFill)
-               {
-                uint32 t;
-                t=V|(V<<8)|(V<<16)|(V<<24);
-                FCEU_dwmemset(MMC5fill,t,0x3c0);
-               }
-               NTFill=V;
-               break;
-    case 0x5107: if(V!=ATFill)
-               {
-                unsigned char moop;
-                uint32 t;
-                moop=V|(V<<2)|(V<<4)|(V<<6);
-                t=moop|(moop<<8)|(moop<<16)|(moop<<24);
-                FCEU_dwmemset(MMC5fill+0x3c0,t,0x40);
-               }
-               ATFill=V;
-               break;
-    case 0x5200: MMC5HackSPMode=V;break;
-    case 0x5201: MMC5HackSPScroll=(V>>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<<x;vnapage[x]=NTARAM;break;
-    case 1:PPUNTARAM|=1<<x;vnapage[x]=NTARAM+0x400;break;
-    case 2:PPUNTARAM|=1<<x;vnapage[x]=ExRAM;break;
-    case 3:PPUNTARAM&=~(1<<x);vnapage[x]=MMC5fill;break;
-   }
- }
- MMC5WRAM(0x6000,WRAMPage&7);
- if(!ABMode)
- {
-  MMC5CHRB();
-  MMC5CHRA();
- }
- else
- {
-   MMC5CHRA();
-   MMC5CHRB();
- }
-  {
-    uint32 t;
-    t=NTFill|(NTFill<<8)|(NTFill<<16)|(NTFill<<24);
-    FCEU_dwmemset(MMC5fill,t,0x3c0);
-  }
-  {
-   unsigned char moop;
-   uint32 t;
-   moop=ATFill|(ATFill<<2)|(ATFill<<4)|(ATFill<<6);
-   t=moop|(moop<<8)|(moop<<16)|(moop<<24);
-   FCEU_dwmemset(MMC5fill+0x3c0,t,0x40);
-  }
-  X6502_IRQEnd(FCEU_IQEXT);
-  MMC5HackCHRMode=CHRMode&3;
-}
-
-void MMC5_hb(int scanline)
-{
-  if(scanline==240)
-  {
-   MMC5LineCounter=0;
-   MMC5IRQR=0x40;
-   return;
-  }
-  if(MMC5LineCounter<240)
-  {
-   if(MMC5LineCounter==IRQScanline)
-   {
-    MMC5IRQR|=0x80;
-    if(IRQEnable&0x80)
-     X6502_IRQBegin(FCEU_IQEXT);
-   }
-   MMC5LineCounter++;
-  }
- if(MMC5LineCounter==240)
-   MMC5IRQR=0;
-}
-
-void MMC5_StateRestore(int version)
-{
- MMC5Synco();
-}
-
-typedef struct {
-        uint16 wl[2];
-        uint8 env[2];
-        uint8 enable;
-        uint8 running;
-        uint8 raw;
-        uint8 rawcontrol;
-        int32 dcount[2];
-        int32 BC[3];
-        int32 vcount[2];
-} MMC5APU;
-
-static MMC5APU MMC5Sound;
-
-
-static void Do5PCM()
-{
-   int32 V;
-   int32 start,end;
-
-   start=MMC5Sound.BC[2];
-   end=(SOUNDTS<<16)/soundtsinc;
-   if(end<=start) return;
-   MMC5Sound.BC[2]=end;
-
-   if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw)
-    for(V=start;V<end;V++)
-     Wave[V>>4]+=MMC5Sound.raw<<1;
-}
-
-#if 0
-static void Do5PCMHQ()
-{
-   int32 V;
-   if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw)
-    for(V=MMC5Sound.BC[2];V<SOUNDTS;V++)
-     WaveHi[V]+=MMC5Sound.raw<<5;
-   MMC5Sound.BC[2]=SOUNDTS;
-}
-#endif
-
-static DECLFW(Mapper5_SW)
-{
- A&=0x1F;
-
- GameExpSound.Fill=MMC5RunSound;
- GameExpSound.HiFill=0;//MMC5RunSoundHQ;
-
- switch(A)
- {
-  case 0x10:if(psfun) psfun();MMC5Sound.rawcontrol=V;break;
-  case 0x11:if(psfun) psfun();MMC5Sound.raw=V;break;
-
-  case 0x0:
-  case 0x4://printf("%04x:$%02x\n",A,V&0x30);
-           if(sfun) sfun(A>>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<end;V++)
-  {
-    if(dc<rthresh)
-     Wave[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<SOUNDTS;V++)
-  {
-    if(dc<rthresh)
-     WaveHi[V]+=amp;
-    vc--;
-    if(vc<=0)   /* Less than zero when first started. */
-    {
-     vc=wl;
-     dc=(dc+1)&7;
-    }
-  }
-  MMC5Sound.dcount[P]=dc;
-  MMC5Sound.vcount[P]=vc;
- }
- MMC5Sound.BC[P]=SOUNDTS;
-}
-
-void MMC5RunSoundHQ(void)
-{
-  Do5SQHQ(0);
-  Do5SQHQ(1);
-  Do5PCMHQ();
-}
-
-void MMC5HiSync(int32 ts)
-{
- int x;
- for(x=0;x<3;x++) MMC5Sound.BC[x]=ts;
-}
-#endif
-
-void MMC5RunSound(int Count)
-{
-  int x;
-  Do5SQ(0);
-  Do5SQ(1);
-  Do5PCM();
-  for(x=0;x<3;x++)
-   MMC5Sound.BC[x]=Count;
-}
-
-void Mapper5_ESI(void)
-{
- GameExpSound.RChange=Mapper5_ESI;
- if(FSettings.SndRate)
- {
-#if 0
-  if(FSettings.soundq>=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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2002 Xodnizel\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+/* None of this code should use any of the iNES bank switching wrappers. */\r
+\r
+#include "mapinc.h"\r
+\r
+static void (*sfun)(int P);\r
+static void (*psfun)(void);\r
+\r
+void MMC5RunSound(int Count);\r
+void MMC5RunSoundHQ(void);\r
+\r
+static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V)\r
+{\r
+  if(CHRptr[0])\r
+  {\r
+    V&=CHRmask1[0];\r
+    MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);\r
+  }\r
+}\r
+\r
+static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}}\r
+\r
+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);}}\r
+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);}}\r
+\r
+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);}}\r
+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);}}\r
+\r
+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];}}\r
+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];}}\r
+\r
+static uint8 PRGBanks[4];\r
+static uint8 WRAMPage;\r
+static uint16 CHRBanksA[8], CHRBanksB[4];\r
+static uint8 WRAMMaskEnable[2];\r
+uint8 mmc5ABMode;                /* A=0, B=1 */\r
+\r
+static uint8 IRQScanline,IRQEnable;\r
+static uint8 CHRMode, NTAMirroring, NTFill, ATFill;\r
+\r
+static uint8 MMC5IRQR;\r
+static uint8 MMC5LineCounter;\r
+static uint8 mmc5psize, mmc5vsize;\r
+static uint8 mul[2];\r
+\r
+static uint8 *WRAM=NULL;\r
+static uint8 *MMC5fill=NULL;\r
+static uint8 *ExRAM=NULL;\r
+\r
+static uint8 MMC5WRAMsize;\r
+static uint8 MMC5WRAMIndex[8];\r
+\r
+static uint8 MMC5ROMWrProtect[4];\r
+static uint8 MMC5MemIn[5];\r
+\r
+static void MMC5CHRA(void);\r
+static void MMC5CHRB(void);\r
+\r
+typedef struct __cartdata {\r
+  uint32 crc32;\r
+  uint8 size;\r
+} cartdata;\r
+\r
+#define Sprite16  (PPU[0]&0x20)   //Sprites 8x16/8x8 \r
+//#define MMC5SPRVRAMADR(V)      &MMC5SPRVPage[(V)>>10][(V)]\r
+static inline uint8 *  MMC5BGVRAMADR(uint32 A)\r
+{\r
+       if(!Sprite16) {\r
+               if(mmc5ABMode==0)\r
+                       return &MMC5SPRVPage[(A)>>10][(A)];\r
+               else \r
+                       return &MMC5BGVPage[(A)>>10][(A)];\r
+       } else return &MMC5BGVPage[(A)>>10][(A)];\r
+}\r
+\r
+static void mmc5_PPUWrite(uint32 A, uint8 V) {\r
+       uint32 tmp = A;\r
+       extern uint8 PALRAM[0x20];\r
+\r
+       if(tmp>=0x3F00)\r
+               {\r
+                       // hmmm....\r
+                       if(!(tmp&0xf))\r
+                               PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3F;\r
+                       else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f;\r
+               }\r
+               else if(tmp<0x2000)\r
+               {\r
+                       if(PPUCHRRAM&(1<<(tmp>>10)))\r
+                               VPage[tmp>>10][tmp]=V;\r
+               }   \r
+               else\r
+               {\r
+                       if(PPUNTARAM&(1<<((tmp&0xF00)>>10)))\r
+                               vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V;\r
+               }\r
+}\r
+\r
+uint8 FASTCALL mmc5_PPURead(uint32 A) {\r
+       if(A<0x2000)\r
+       {\r
+               if(ppuphase == PPUPHASE_BG)\r
+                       return *MMC5BGVRAMADR(A);\r
+               else return MMC5SPRVPage[(A)>>10][(A)];\r
+       }\r
+       else\r
+       {   \r
+               return vnapage[(A>>10)&0x3][A&0x3FF];\r
+       }\r
+}\r
+\r
+\r
+\r
+// ELROM seems to have 8KB of RAM\r
+// ETROM seems to have 16KB of WRAM\r
+// EWROM seems to have 32KB of WRAM\r
+\r
+cartdata MMC5CartList[]=\r
+{\r
+  {0x9c18762b,2},         /* L'Empereur */\r
+  {0x26533405,2},\r
+  {0x6396b988,2},\r
+  {0xaca15643,2},        /* Uncharted Waters */\r
+  {0xfe3488d1,2},        /* Dai Koukai Jidai */\r
+  {0x15fe6d0f,2},        /* BKAC             */\r
+  {0x39f2ce4b,2},        /* Suikoden              */\r
+  {0x8ce478db,2},        /* Nobunaga's Ambition 2 */\r
+  {0xeee9a682,2},\r
+  {0xf9b4240f,2},\r
+  {0x1ced086f,2},        /* Ishin no Arashi */\r
+  {0xf540677b,4},        /* Nobunaga...Bushou Fuuun Roku */\r
+  {0x6f4e4312,4},        /* Aoki Ookami..Genchou */\r
+  {0xf011e490,4},        /* Romance of the 3 Kingdoms 2 */\r
+  {0x184c2124,4},        /* Sangokushi 2 */\r
+  {0xee8e6553,4},\r
+};\r
+\r
+#define MMC5_NOCARTS           (sizeof(MMC5CartList)/sizeof(MMC5CartList[0]))\r
+int DetectMMC5WRAMSize(uint32 crc32)\r
+{\r
+       int x;\r
+       for(x=0;x<MMC5_NOCARTS;x++) {\r
+               if(crc32==MMC5CartList[x].crc32) {\r
+                       FCEU_printf(" >8KB external WRAM present.  Use UNIF if you hack the ROM image.\n");\r
+                       return(MMC5CartList[x].size*8);\r
+               }\r
+       }\r
+\r
+       //mbg 04-aug-08 - previously, this was returning 8KB\r
+       //but I changed it to return 64 because unlisted carts are probably homebrews, and they should probably use 64 (why not use it all?)\r
+       //ch4 10-dec-08 - then f***ng for what all this shit above? let's give em all this 64k shit! Damn\r
+       //               homebrew must use it's own emulators or standart features.\r
+       //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\r
+       //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\r
+       //mbg 29-mar-09 - I should note that mmc5 is in principle capable of 64KB, even if no real carts ever supported it.\r
+       //This does not in principle break any games which share this mapper, and it should be OK for homebrew.\r
+       //if there are games which need 8KB instead of 64KB default then lets add them to the list\r
+       return 64;\r
+}\r
+\r
+static void BuildWRAMSizeTable(void)\r
+{\r
+       int x;\r
+       for(x=0;x<8;x++)\r
+       {\r
+               switch(MMC5WRAMsize)\r
+               {\r
+               case 0: MMC5WRAMIndex[x]=255; break; //X,X,X,X,X,X,X,X\r
+               case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; //0,0,0,0,X,X,X,X\r
+               case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; //0,0,0,0,1,1,1,1\r
+               case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; //0,1,2,3,X,X,X,X\r
+               case 8: MMC5WRAMIndex[x]=x; break; //0,1,2,3,4,5,6,7,8  \r
+                       //mbg 8/6/08 - i added this to support 64KB of wram\r
+                       //now, I have at least one example (laser invasion) which actually uses size 1 but isnt in the crc list\r
+                       //so, whereas before my change on 8/4/08 we would have selected size 1, now we select size 8\r
+                       //this means that we could have just introduced an emulation bug, in case those games happened to \r
+                       //address, say, page 3. with size 1 that would resolve to [0] but in size 8 it resolves to [3].\r
+                       //so, you know what to do if there are problems.\r
+               }\r
+       }\r
+}\r
+\r
+static void MMC5CHRA(void)\r
+{\r
+  int x;\r
+  switch(mmc5vsize&3)\r
+  {\r
+    case 0: setchr8(CHRBanksA[7]);\r
+            MMC5SPRVROM_BANK8(CHRBanksA[7]);\r
+            break;\r
+    case 1: setchr4(0x0000,CHRBanksA[3]);\r
+            setchr4(0x1000,CHRBanksA[7]);\r
+            MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]);\r
+            MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]);\r
+            break;\r
+    case 2: setchr2(0x0000,CHRBanksA[1]);\r
+            setchr2(0x0800,CHRBanksA[3]);\r
+            setchr2(0x1000,CHRBanksA[5]);\r
+            setchr2(0x1800,CHRBanksA[7]);\r
+            MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]);\r
+            MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]);\r
+            MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]);\r
+            MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]);\r
+            break;\r
+    case 3: for(x=0;x<8;x++)\r
+            {\r
+              setchr1(x<<10,CHRBanksA[x]);\r
+              MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]);\r
+            }\r
+            break;\r
+  }\r
+}\r
+\r
+static void MMC5CHRB(void)\r
+{\r
+  int x;\r
+  switch(mmc5vsize&3)\r
+  {\r
+    case 0: setchr8(CHRBanksB[3]);\r
+            MMC5BGVROM_BANK8(CHRBanksB[3]);\r
+            break;\r
+    case 1: setchr4(0x0000,CHRBanksB[3]);\r
+            setchr4(0x1000,CHRBanksB[3]);\r
+            MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]);\r
+            MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]);\r
+            break;\r
+    case 2: setchr2(0x0000,CHRBanksB[1]);\r
+            setchr2(0x0800,CHRBanksB[3]);\r
+            setchr2(0x1000,CHRBanksB[1]);\r
+            setchr2(0x1800,CHRBanksB[3]);\r
+            MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]);\r
+            MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]);\r
+            MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]);\r
+            MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]);\r
+            break;\r
+    case 3: for(x=0;x<8;x++)\r
+            {\r
+              setchr1(x<<10,CHRBanksB[x&3]);\r
+              MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]);\r
+            }\r
+            break;\r
+  }\r
+}\r
+\r
+static void MMC5WRAM(uint32 A, uint32 V)\r
+{\r
+  //printf("%02x\n",V);\r
+  V=MMC5WRAMIndex[V&7];\r
+  if(V!=255)\r
+  {\r
+    setprg8r(0x10,A,V);\r
+    MMC5MemIn[(A-0x6000)>>13]=1;\r
+  }\r
+  else\r
+    MMC5MemIn[(A-0x6000)>>13]=0;\r
+}\r
+\r
+static void MMC5PRG(void)\r
+{\r
+  int x;\r
+  switch(mmc5psize&3)\r
+  {\r
+    case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=\r
+            MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1;\r
+            setprg32(0x8000,((PRGBanks[1]&0x7F)>>2));\r
+            for(x=0;x<4;x++)\r
+               MMC5MemIn[1+x]=1;\r
+            break;\r
+    case 1: if(PRGBanks[1]&0x80)\r
+            {\r
+              MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1;\r
+              setprg16(0x8000,(PRGBanks[1]>>1));\r
+              MMC5MemIn[1]=MMC5MemIn[2]=1;\r
+            }\r
+            else\r
+            {\r
+              MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0;\r
+              MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE);\r
+              MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1);\r
+            }\r
+            MMC5MemIn[3]=MMC5MemIn[4]=1;\r
+            MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1;\r
+            setprg16(0xC000,(PRGBanks[3]&0x7F)>>1);\r
+            break;\r
+    case 2: if(PRGBanks[1]&0x80)\r
+            {\r
+              MMC5MemIn[1]=MMC5MemIn[2]=1;\r
+              MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1;\r
+              setprg16(0x8000,(PRGBanks[1]&0x7F)>>1);\r
+            }\r
+            else\r
+            {\r
+              MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0;\r
+              MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE);\r
+              MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1);\r
+            }\r
+            if(PRGBanks[2]&0x80)\r
+            {\r
+              MMC5ROMWrProtect[2]=1;\r
+              MMC5MemIn[3]=1;\r
+              setprg8(0xC000,PRGBanks[2]&0x7F);\r
+            }\r
+            else\r
+            {\r
+              MMC5ROMWrProtect[2]=0;\r
+              MMC5WRAM(0xC000,PRGBanks[2]&7);\r
+            }\r
+            MMC5MemIn[4]=1;\r
+            MMC5ROMWrProtect[3]=1;\r
+            setprg8(0xE000,PRGBanks[3]&0x7F);\r
+            break;\r
+    case 3: for(x=0;x<3;x++)\r
+            if(PRGBanks[x]&0x80)\r
+            {\r
+              MMC5ROMWrProtect[x]=1;\r
+              setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F);\r
+              MMC5MemIn[1+x]=1;\r
+            }\r
+            else\r
+            {\r
+              MMC5ROMWrProtect[x]=0;\r
+              MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7);\r
+            }\r
+            MMC5MemIn[4]=1;\r
+            MMC5ROMWrProtect[3]=1;\r
+            setprg8(0xE000,PRGBanks[3]&0x7F);\r
+            break;\r
+  }\r
+}\r
+\r
+static DECLFW(Mapper5_write)\r
+{\r
+  if(A>=0x5120&&A<=0x5127)\r
+  {\r
+    mmc5ABMode = 0;\r
+    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\r
+       //CHRBanksA[A&7]=V;\r
+    MMC5CHRA();\r
+  }\r
+  else switch(A)\r
+  {\r
+    case 0x5105: {\r
+                   int x;\r
+                   for(x=0;x<4;x++)\r
+                   {\r
+                     switch((V>>(x<<1))&3)\r
+                     {\r
+                       case 0:\r
+                                                  PPUNTARAM|=1<<x;vnapage[x]=NTARAM;break;\r
+                       case 1:\r
+                                                  PPUNTARAM|=1<<x;vnapage[x]=NTARAM+0x400;break;\r
+                       case 2:\r
+                                                  PPUNTARAM|=1<<x;vnapage[x]=ExRAM;break;\r
+                       case 3:\r
+                                                  PPUNTARAM&=~(1<<x);vnapage[x]=MMC5fill;break;\r
+                     }\r
+                   }\r
+                 }\r
+                 NTAMirroring=V;\r
+                 break;\r
+    case 0x5113: WRAMPage=V;MMC5WRAM(0x6000,V&7);break;\r
+    case 0x5100: mmc5psize=V;MMC5PRG();break;\r
+    case 0x5101: mmc5vsize=V;\r
+                 if(!mmc5ABMode)\r
+                 { MMC5CHRB();MMC5CHRA();}\r
+                 else\r
+                 { MMC5CHRA();MMC5CHRB();}\r
+                 break;\r
+    case 0x5114:\r
+    case 0x5115:\r
+    case 0x5116:\r
+    case 0x5117: PRGBanks[A&3]=V;MMC5PRG();break;\r
+    case 0x5128:\r
+    case 0x5129:\r
+    case 0x512a:\r
+    case 0x512b: mmc5ABMode=1;\r
+                 CHRBanksB[A&3]=V;\r
+                 MMC5CHRB();\r
+                 break;\r
+    case 0x5102: WRAMMaskEnable[0]=V;break;\r
+    case 0x5103: WRAMMaskEnable[1]=V;break;\r
+    case 0x5104: CHRMode=V;MMC5HackCHRMode=V&3;break;\r
+    case 0x5106: if(V!=NTFill)\r
+                 {\r
+                   uint32 t;\r
+                   t=V|(V<<8)|(V<<16)|(V<<24);\r
+                   FCEU_dwmemset(MMC5fill,t,0x3c0);\r
+                 }\r
+                 NTFill=V;\r
+                 break;\r
+    case 0x5107: if(V!=ATFill)\r
+                 {\r
+                   unsigned char moop;\r
+                   uint32 t;\r
+                   moop=V|(V<<2)|(V<<4)|(V<<6);\r
+                   t=moop|(moop<<8)|(moop<<16)|(moop<<24);\r
+                   FCEU_dwmemset(MMC5fill+0x3c0,t,0x40);\r
+                 }\r
+                 ATFill=V;\r
+                 break;\r
+    case 0x5130: MMC50x5130=V;break;\r
+\r
+    case 0x5200: MMC5HackSPMode=V;break;\r
+    case 0x5201: MMC5HackSPScroll=(V>>3)&0x1F;break;\r
+    case 0x5202: MMC5HackSPPage=V&0x3F;break;\r
+    case 0x5203: X6502_IRQEnd(FCEU_IQEXT);IRQScanline=V;break;\r
+    case 0x5204: X6502_IRQEnd(FCEU_IQEXT);IRQEnable=V&0x80;break;\r
+    case 0x5205: mul[0]=V;break;\r
+    case 0x5206: mul[1]=V;break;\r
+  }\r
+}\r
+\r
+static DECLFR(MMC5_ReadROMRAM)\r
+{\r
+  if(MMC5MemIn[(A-0x6000)>>13])\r
+    return Page[A>>11][A];\r
+  else\r
+    return X.DB;\r
+}\r
+\r
+static DECLFW(MMC5_WriteROMRAM)\r
+{\r
+  if(A>=0x8000)\r
+    if(MMC5ROMWrProtect[(A-0x8000)>>13]) return;\r
+  if(MMC5MemIn[(A-0x6000)>>13])\r
+    if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) \r
+               Page[A>>11][A]=V;\r
+}\r
+\r
+static DECLFW(MMC5_ExRAMWr)\r
+{\r
+  if(MMC5HackCHRMode!=3)\r
+    ExRAM[A&0x3ff]=V;\r
+}\r
+\r
+static DECLFR(MMC5_ExRAMRd)\r
+{\r
+ /* Not sure if this is correct, so I'll comment it out for now. */\r
+ //if(MMC5HackCHRMode>=2)\r
+  return ExRAM[A&0x3ff];\r
+ //else\r
+ // return(X.DB);\r
+}\r
+\r
+static DECLFR(MMC5_read)\r
+{\r
+  switch(A)\r
+  {\r
+    case 0x5204: X6502_IRQEnd(FCEU_IQEXT);\r
+                 {\r
+                   uint8 x;\r
+                   x=MMC5IRQR;\r
+                   if(!fceuindbg)\r
+                     MMC5IRQR&=0x40;\r
+                   return x;\r
+                 }\r
+    case 0x5205: return (mul[0]*mul[1]);\r
+    case 0x5206: return ((mul[0]*mul[1])>>8);\r
+  }\r
+  return(X.DB);\r
+}\r
+\r
+void MMC5Synco(void)\r
+{\r
+  int x;\r
+\r
+  MMC5PRG();\r
+  for(x=0;x<4;x++)\r
+  {\r
+    switch((NTAMirroring>>(x<<1))&3)\r
+    {\r
+      case 0:PPUNTARAM|=1<<x;vnapage[x]=NTARAM;break;\r
+      case 1:PPUNTARAM|=1<<x;vnapage[x]=NTARAM+0x400;break;\r
+      case 2:PPUNTARAM|=1<<x;vnapage[x]=ExRAM;break;\r
+      case 3:PPUNTARAM&=~(1<<x);vnapage[x]=MMC5fill;break;\r
+    }\r
+  }\r
+  MMC5WRAM(0x6000,WRAMPage&7);\r
+  if(!mmc5ABMode)\r
+  {\r
+    MMC5CHRB();\r
+    MMC5CHRA();\r
+  }\r
+  else\r
+  {\r
+    MMC5CHRA();\r
+    MMC5CHRB();\r
+  }\r
+  {\r
+    uint32 t;\r
+    t=NTFill|(NTFill<<8)|(NTFill<<16)|(NTFill<<24);\r
+    FCEU_dwmemset(MMC5fill,t,0x3c0);\r
+  }\r
+  {\r
+    unsigned char moop;\r
+    uint32 t;\r
+    moop=ATFill|(ATFill<<2)|(ATFill<<4)|(ATFill<<6);\r
+    t=moop|(moop<<8)|(moop<<16)|(moop<<24);\r
+    FCEU_dwmemset(MMC5fill+0x3c0,t,0x40);\r
+  }\r
+  X6502_IRQEnd(FCEU_IQEXT);\r
+  MMC5HackCHRMode=CHRMode&3;\r
+}\r
+\r
+void MMC5_hb(int scanline)\r
+{\r
+  if(scanline==240)\r
+  {\r
+    MMC5LineCounter=0;\r
+    MMC5IRQR=0x40;\r
+    return;\r
+  }\r
+  if(MMC5LineCounter<240)\r
+  {\r
+    if(MMC5LineCounter==IRQScanline)\r
+    {\r
+      MMC5IRQR|=0x80;\r
+      if(IRQEnable&0x80)\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+    MMC5LineCounter++;\r
+  }\r
+  if(MMC5LineCounter==240)\r
+    MMC5IRQR=0;\r
+}\r
+\r
+void MMC5_StateRestore(int version)\r
+{\r
+  MMC5Synco();\r
+}\r
+\r
+typedef struct {\r
+  uint16 wl[2];\r
+  uint8 env[2];\r
+  uint8 enable;\r
+  uint8 running;\r
+  uint8 raw;\r
+  uint8 rawcontrol;\r
+  int32 dcount[2];\r
+  int32 BC[3];\r
+  int32 vcount[2];\r
+} MMC5APU;\r
+\r
+static MMC5APU MMC5Sound;\r
+\r
+\r
+static void Do5PCM()\r
+{\r
+  int32 V;\r
+  int32 start,end;\r
+\r
+  start=MMC5Sound.BC[2];\r
+  end=(SOUNDTS<<16)/soundtsinc;\r
+  if(end<=start) return;\r
+  MMC5Sound.BC[2]=end;\r
+\r
+  if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw)\r
+    for(V=start;V<end;V++)\r
+       Wave[V>>4]+=MMC5Sound.raw<<1;\r
+}\r
+\r
+static void Do5PCMHQ()\r
+{\r
+  uint32 V; //mbg merge 7/17/06 made uint32\r
+  if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw)\r
+    for(V=MMC5Sound.BC[2];V<SOUNDTS;V++)\r
+       WaveHi[V]+=MMC5Sound.raw<<5;\r
+  MMC5Sound.BC[2]=SOUNDTS;\r
+}\r
+\r
+\r
+static DECLFW(Mapper5_SW)\r
+{\r
+  A&=0x1F;\r
+\r
+  GameExpSound.Fill=MMC5RunSound;\r
+  GameExpSound.HiFill=MMC5RunSoundHQ;\r
+\r
+  switch(A)\r
+  {\r
+    case 0x10:if(psfun) psfun();MMC5Sound.rawcontrol=V;break;\r
+    case 0x11:if(psfun) psfun();MMC5Sound.raw=V;break;\r
+\r
+    case 0x0:\r
+    case 0x4://printf("%04x:$%02x\n",A,V&0x30);\r
+              if(sfun) sfun(A>>2);\r
+              MMC5Sound.env[A>>2]=V;\r
+              break;\r
+    case 0x2:\r
+    case 0x6: if(sfun) sfun(A>>2);\r
+              MMC5Sound.wl[A>>2]&=~0x00FF;\r
+              MMC5Sound.wl[A>>2]|=V&0xFF;\r
+              break;\r
+    case 0x3:\r
+    case 0x7://printf("%04x:$%02x\n",A,V>>3);\r
+           MMC5Sound.wl[A>>2]&=~0x0700;\r
+           MMC5Sound.wl[A>>2]|=(V&0x07)<<8;\r
+           MMC5Sound.running|=1<<(A>>2);\r
+           break;\r
+  case 0x15:if(sfun)\r
+            {\r
+             sfun(0);\r
+             sfun(1);\r
+            }\r
+            MMC5Sound.running&=V;\r
+            MMC5Sound.enable=V;\r
+                //printf("%02x\n",V);\r
+            break;\r
+ }\r
+}\r
+\r
+static void Do5SQ(int P)\r
+{\r
+ static int tal[4]={1,2,4,6};\r
+ int32 V,amp,rthresh,wl;\r
+ int32 start,end;\r
+\r
+ start=MMC5Sound.BC[P];\r
+ end=(SOUNDTS<<16)/soundtsinc;\r
+ if(end<=start) return;\r
+ MMC5Sound.BC[P]=end;\r
+\r
+ wl=MMC5Sound.wl[P]+1;\r
+ amp=(MMC5Sound.env[P]&0xF)<<4;\r
+ rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6];\r
+\r
+ if(wl>=8 && (MMC5Sound.running&(P+1)))\r
+ {\r
+  int dc,vc;\r
+\r
+  wl<<=18;\r
+  dc=MMC5Sound.dcount[P];\r
+  vc=MMC5Sound.vcount[P];\r
+\r
+  for(V=start;V<end;V++)\r
+  {\r
+    if(dc<rthresh)\r
+     Wave[V>>4]+=amp;\r
+    vc-=nesincsize;\r
+    while(vc<=0)\r
+    {\r
+     vc+=wl;\r
+     dc=(dc+1)&7;\r
+    }\r
+  }\r
+  MMC5Sound.dcount[P]=dc;\r
+  MMC5Sound.vcount[P]=vc;\r
+ }\r
+}\r
+\r
+static void Do5SQHQ(int P)\r
+{\r
+ static int tal[4]={1,2,4,6};\r
+ uint32 V; //mbg merge 7/17/06 made uint32\r
+ int32 amp,rthresh,wl;\r
+\r
+ wl=MMC5Sound.wl[P]+1;\r
+ amp=((MMC5Sound.env[P]&0xF)<<8);\r
+ rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6];\r
+\r
+ if(wl>=8 && (MMC5Sound.running&(P+1)))\r
+ {\r
+  int dc,vc;\r
+\r
+  wl<<=1;\r
+\r
+  dc=MMC5Sound.dcount[P];\r
+  vc=MMC5Sound.vcount[P];\r
+  for(V=MMC5Sound.BC[P];V<SOUNDTS;V++)\r
+  {\r
+    if(dc<rthresh)\r
+     WaveHi[V]+=amp;\r
+    vc--;\r
+    if(vc<=0)   /* Less than zero when first started. */\r
+    {\r
+     vc=wl;\r
+     dc=(dc+1)&7;\r
+    }\r
+  }\r
+  MMC5Sound.dcount[P]=dc;\r
+  MMC5Sound.vcount[P]=vc;\r
+ }\r
+ MMC5Sound.BC[P]=SOUNDTS;\r
+}\r
+\r
+void MMC5RunSoundHQ(void)\r
+{\r
+  Do5SQHQ(0);\r
+  Do5SQHQ(1);\r
+  Do5PCMHQ();\r
+}\r
+\r
+void MMC5HiSync(int32 ts)\r
+{\r
+ int x;\r
+ for(x=0;x<3;x++) MMC5Sound.BC[x]=ts;\r
+}\r
+\r
+void MMC5RunSound(int Count)\r
+{\r
+  int x;\r
+  Do5SQ(0);\r
+  Do5SQ(1);\r
+  Do5PCM();\r
+  for(x=0;x<3;x++)\r
+   MMC5Sound.BC[x]=Count;\r
+}\r
+\r
+void Mapper5_ESI(void)\r
+{\r
+ GameExpSound.RChange=Mapper5_ESI;\r
+ if(FSettings.SndRate)\r
+ {\r
+  if(FSettings.soundq>=1)\r
+  {\r
+   sfun=Do5SQHQ;\r
+   psfun=Do5PCMHQ;\r
+  }\r
+  else\r
+  {\r
+   sfun=Do5SQ;\r
+   psfun=Do5PCM;\r
+  }\r
+ }\r
+ else\r
+ {\r
+  sfun=0;\r
+  psfun=0;\r
+ }\r
+ memset(MMC5Sound.BC,0,sizeof(MMC5Sound.BC));\r
+ memset(MMC5Sound.vcount,0,sizeof(MMC5Sound.vcount));\r
+ GameExpSound.HiSync=MMC5HiSync;\r
+}\r
+\r
+void NSFMMC5_Init(void)\r
+{\r
+  memset(&MMC5Sound,0,sizeof(MMC5Sound));\r
+  mul[0]=mul[1]=0;\r
+  ExRAM=(uint8*)FCEU_gmalloc(1024);\r
+  Mapper5_ESI();\r
+  SetWriteHandler(0x5c00,0x5fef,MMC5_ExRAMWr);\r
+  SetReadHandler(0x5c00,0x5fef,MMC5_ExRAMRd);\r
+  MMC5HackCHRMode=2;\r
+  SetWriteHandler(0x5000,0x5015,Mapper5_SW);\r
+  SetWriteHandler(0x5205,0x5206,Mapper5_write);\r
+  SetReadHandler(0x5205,0x5206,MMC5_read);\r
+}\r
+\r
+void NSFMMC5_Close(void)\r
+{\r
+ FCEU_gfree(ExRAM);\r
+ ExRAM=0;\r
+}\r
+\r
+static void GenMMC5Reset(void)\r
+{\r
+ int x;\r
+\r
+ for(x=0;x<4;x++) PRGBanks[x]=~0;\r
+ for(x=0;x<8;x++) CHRBanksA[x]=~0;\r
+ for(x=0;x<4;x++) CHRBanksB[x]=~0;\r
+ WRAMMaskEnable[0]=WRAMMaskEnable[1]=~0;\r
+\r
+ mmc5psize=mmc5vsize=3;\r
+ CHRMode=0;\r
+\r
+ NTAMirroring=NTFill=ATFill=0xFF;\r
+\r
+ MMC5Synco();\r
+\r
+ SetWriteHandler(0x4020,0x5bff,Mapper5_write);\r
+ SetReadHandler(0x4020,0x5bff,MMC5_read);\r
+\r
+ SetWriteHandler(0x5c00,0x5fff,MMC5_ExRAMWr);\r
+ SetReadHandler(0x5c00,0x5fff,MMC5_ExRAMRd);\r
+\r
+ SetWriteHandler(0x6000,0xFFFF,MMC5_WriteROMRAM);\r
+ SetReadHandler(0x6000,0xFFFF,MMC5_ReadROMRAM);\r
+\r
+ SetWriteHandler(0x5000,0x5015,Mapper5_SW);\r
+ SetWriteHandler(0x5205,0x5206,Mapper5_write);\r
+ SetReadHandler(0x5205,0x5206,MMC5_read);\r
+\r
+ //GameHBIRQHook=MMC5_hb;\r
+ FCEU_CheatAddRAM(8,0x6000,WRAM);\r
+ FCEU_CheatAddRAM(1,0x5c00,ExRAM);\r
+}\r
+\r
+static SFORMAT MMC5_StateRegs[]={\r
+        { PRGBanks, 4, "PRGB"},\r
+        { CHRBanksA, 16, "CHRA"},\r
+        { CHRBanksB, 8, "CHRB"},\r
+        { &WRAMPage, 1, "WRMP"},\r
+        { WRAMMaskEnable, 2, "WRME"},\r
+        { &mmc5ABMode, 1, "ABMD"},\r
+        { &IRQScanline, 1, "IRQS"},\r
+        { &IRQEnable, 1, "IRQE"},\r
+        { &CHRMode, 1, "CHRM"},\r
+        { &NTAMirroring, 1, "NTAM"},\r
+        { &NTFill, 1, "NTFL"},\r
+        { &ATFill, 1, "ATFL"},\r
+\r
+        { &MMC5Sound.wl[0], 2|FCEUSTATE_RLSB, "SDW0"},\r
+        { &MMC5Sound.wl[1], 2|FCEUSTATE_RLSB, "SDW1"},\r
+        { MMC5Sound.env, 2, "SDEV"},\r
+        { &MMC5Sound.enable, 1, "SDEN"},\r
+        { &MMC5Sound.running, 1, "SDRU"},\r
+        { &MMC5Sound.raw, 1, "SDRW"},\r
+        { &MMC5Sound.rawcontrol, 1, "SDRC"},\r
+        {0}\r
+};\r
+\r
+static void GenMMC5_Init(CartInfo *info, int wsize, int battery)\r
+{\r
+ if(wsize)\r
+ {\r
+  WRAM=(uint8*)FCEU_gmalloc(wsize*1024);\r
+  SetupCartPRGMapping(0x10,WRAM,wsize*1024,1);\r
+  AddExState(WRAM, wsize*1024, 0, "WRAM");\r
+ }\r
+\r
+ MMC5fill=(uint8*)FCEU_gmalloc(1024);\r
+ ExRAM=(uint8*)FCEU_gmalloc(1024);\r
+\r
+ AddExState(MMC5_StateRegs, ~0, 0, 0);\r
+ AddExState(WRAM, wsize*1024, 0, "WRAM");\r
+ AddExState(ExRAM, 1024, 0, "ERAM");\r
+ AddExState(&MMC5HackSPMode, 1, 0, "SPLM");\r
+ AddExState(&MMC5HackSPScroll, 1, 0, "SPLS");\r
+ AddExState(&MMC5HackSPPage, 1, 0, "SPLP");\r
+ AddExState(&MMC50x5130, 1, 0, "5130");\r
+\r
+ MMC5WRAMsize=wsize/8;\r
+ BuildWRAMSizeTable();\r
+ GameStateRestore=MMC5_StateRestore;\r
+ info->Power=GenMMC5Reset;\r
+\r
+ if(battery)\r
+ {\r
+  info->SaveGame[0]=WRAM;\r
+  if(wsize<=16)\r
+   info->SaveGameLen[0]=8192;\r
+  else\r
+   info->SaveGameLen[0]=32768;\r
+ }\r
+\r
+ MMC5HackVROMMask=CHRmask4[0];\r
+ MMC5HackExNTARAMPtr=ExRAM;\r
+ MMC5Hack=1;\r
+ MMC5HackVROMPTR=CHRptr[0];\r
+ MMC5HackCHRMode=0;\r
+ MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0;\r
+ Mapper5_ESI();\r
+\r
+ FFCEUX_PPURead = mmc5_PPURead;\r
+ FFCEUX_PPUWrite = mmc5_PPUWrite;\r
+}\r
+\r
+void Mapper5_Init(CartInfo *info)\r
+{\r
+ GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery);\r
+}\r
+\r
+// ELROM seems to have 0KB of WRAM\r
+// EKROM seems to have 8KB of WRAM\r
+// ETROM seems to have 16KB of WRAM\r
+// EWROM seems to have 32KB of WRAM\r
+\r
+// ETROM and EWROM are battery-backed, EKROM isn't.\r
+\r
+void ETROM_Init(CartInfo *info)\r
+{\r
+ GenMMC5_Init(info, 16,info->battery);\r
+}\r
+\r
+void ELROM_Init(CartInfo *info)\r
+{\r
+ GenMMC5_Init(info,0,0);\r
+}\r
+\r
+void EWROM_Init(CartInfo *info)\r
+{\r
+ GenMMC5_Init(info,32,info->battery);\r
+}\r
+\r
+void EKROM_Init(CartInfo *info)\r
+{\r
+ GenMMC5_Init(info,8,info->battery);\r
+}\r
diff --git a/boards/n-c22m.c b/boards/n-c22m.c
new file mode 100644 (file)
index 0000000..49f965f
--- /dev/null
@@ -0,0 +1,103 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * Mortal Kombat 2 YOKO */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 reg[8];\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 8, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+//  FCEU_printf("(%02x, %02x)\n",reg[3],reg[4]);\r
+  setprg8(0x8000,reg[0]);\r
+  setprg8(0xA000,reg[1]);\r
+  setprg8(0xC000,reg[2]);\r
+  setprg8(0xE000,~0);\r
+//  setchr2(0x0000,reg[3]);\r
+//  setchr2(0x0800,reg[4]);\r
+//  setchr2(0x1000,reg[5]);\r
+//  setchr2(0x1800,reg[6]);\r
+  setchr2(0x0000,reg[3]);\r
+  setchr2(0x0800,reg[4]);\r
+  setchr2(0x1000,reg[5]);\r
+  setchr2(0x1800,reg[6]);\r
+}\r
+\r
+static DECLFW(MCN22MWrite)\r
+{\r
+//FCEU_printf("bs %04x %02x\n",A,V);\r
+  switch(A)\r
+  {\r
+    case 0x8c00:\r
+    case 0x8c01:\r
+    case 0x8c02: reg[A&3]=V; break;\r
+    case 0x8d10: reg[3]=V; break;\r
+    case 0x8d11: reg[4]=V; break;\r
+    case 0x8d16: reg[5]=V; break;\r
+    case 0x8d17: reg[6]=V; break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void MCN22MPower(void)\r
+{\r
+  reg[0]=reg[1]=reg[2]=0;\r
+  Sync();  \r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,MCN22MWrite);\r
+}\r
+/*\r
+static void MCN22MIRQHook(void)\r
+{\r
+  int count = IRQCount;\r
+  if(!count || IRQReload)\r
+  {\r
+     IRQCount = IRQLatch;\r
+     IRQReload = 0;\r
+  }\r
+  else\r
+     IRQCount--;\r
+  if(!IRQCount)\r
+  {\r
+     if(IRQa)\r
+     {\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+     }\r
+  }\r
+}\r
+*/\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLCN22M_Init(CartInfo *info)\r
+{\r
+  info->Power=MCN22MPower;\r
+//  GameHBIRQHook=MCN22MIRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index d54af02..880a296 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -23,8 +23,8 @@
 static uint16 IRQCount;
 static uint8 IRQa;
 
 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)
 {
 
 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 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. */
 static void SyncHQ(int32 ts);
 
 static int is210;        /* Lesser mapper. */
@@ -70,7 +70,7 @@ static void SyncPRG(void)
   setprg8(0xe000,0x3F);
 }
 
   setprg8(0xe000,0x3F);
 }
 
-static void FP_FASTAPASS(1) NamcoIRQHook(int a)
+static void NamcoIRQHook(int a)
 {
   if(IRQa)
   {
 {
   if(IRQa)
   {
@@ -104,7 +104,7 @@ static DECLFR(Namco_Read5800)
   return(IRQCount>>8);
 }
 
   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)
 {
   NTAPage[w]=V;
   if(V>=0xE0)
@@ -123,7 +123,7 @@ static void FixNTAR(void)
      DoNTARAMROM(x,NTAPage[x]);
 }
 
      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))
 {
   CHR[x]=V;
   if(!is210 && !((gorfus>>((x>>2)+6))&1) && (V>=0xE0))
@@ -179,7 +179,7 @@ static DECLFW(Mapper19_write)
            {
              NamcoSoundHack();
              GameExpSound.Fill=NamcoSound;
            {
              NamcoSoundHack();
              GameExpSound.Fill=NamcoSound;
-             GameExpSound.HiFill=0;//DoNamcoSoundHQ;
+             GameExpSound.HiFill=DoNamcoSoundHQ;
              GameExpSound.HiSync=SyncHQ;
            }
            FixCache(dopol,V);
              GameExpSound.HiSync=SyncHQ;
            }
            FixCache(dopol,V);
@@ -220,16 +220,14 @@ static int dwave=0;
 static void NamcoSoundHack(void)
 {
   int32 z,a;
 static void NamcoSoundHack(void)
 {
   int32 z,a;
-#if 0
   if(FSettings.soundq>=1)
   {
     DoNamcoSoundHQ();
     return;
   }
   if(FSettings.soundq>=1)
   {
     DoNamcoSoundHQ();
     return;
   }
-#endif
   z=((SOUNDTS<<16)/soundtsinc)>>4;
   a=z-dwave;
   z=((SOUNDTS<<16)/soundtsinc)>>4;
   a=z-dwave;
-  if(a) DoNamcoSound((int32 *)&Wave[dwave], a);
+  if(a) DoNamcoSound(&Wave[dwave], a);
   dwave+=a;
 }
 
   dwave+=a;
 }
 
@@ -238,7 +236,7 @@ static void NamcoSound(int Count)
   int32 z,a;
   z=((SOUNDTS<<16)/soundtsinc)>>4;
   a=z-dwave;
   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;
 }
 
   dwave=0;
 }
 
@@ -274,10 +272,10 @@ static INLINE uint32 FetchDuff(uint32 P, uint32 envelope)
   return(duff);
 }
 
   return(duff);
 }
 
-#if 0
 static void DoNamcoSoundHQ(void)
 {
 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--)
   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;
 }
   }
   CVBC=SOUNDTS;
 }
-#endif
+
 
 static void DoNamcoSound(int32 *Wave, int Count)
 {
 
 static void DoNamcoSound(int32 *Wave, int Count)
 {
@@ -366,10 +364,10 @@ static void DoNamcoSound(int32 *Wave, int Count)
 
 static void Mapper19_StateRestore(int version)
 {
 
 static void Mapper19_StateRestore(int version)
 {
+  int x;
   SyncPRG();
   FixNTAR();
   FixCRR();
   SyncPRG();
   FixNTAR();
   FixCRR();
-  int x;
   for(x=0x40;x<0x80;x++)
      FixCache(x,IRAM[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");
     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)
   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");
   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 (file)
index 0000000..30d8298
--- /dev/null
@@ -0,0 +1,97 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * 700in1 and 400in1 carts\r
+ */\r
\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 cmd, bank;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&cmd, 2, "CMD"},\r
+  {&bank, 2, "BANK"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setmirror((cmd&1)^1);\r
+  setchr8(0);\r
+  if(cmd&2)\r
+  {\r
+    if(cmd&0x100)\r
+    {\r
+      setprg16(0x8000,((cmd&0xe0)>>2)|bank);\r
+      setprg16(0xC000,((cmd&0xe0)>>2)|7);  \r
+    }\r
+    else\r
+    {\r
+      setprg16(0x8000,((cmd&0xe0)>>2)|(bank&6));\r
+      setprg16(0xC000,((cmd&0xe0)>>2)|((bank&6)|1));  \r
+    }\r
+  }\r
+  else\r
+  {\r
+    setprg16(0x8000,((cmd&0xe0)>>2)|bank);\r
+    setprg16(0xC000,((cmd&0xe0)>>2)|bank);\r
+  }  \r
+}\r
+\r
+static DECLFW(UNLN625092WriteCommand)\r
+{\r
+  cmd=A;  \r
+  Sync();\r
+}\r
+\r
+static DECLFW(UNLN625092WriteBank)\r
+{ \r
+  bank=A&7;\r
+  Sync();\r
+}\r
+\r
+static void UNLN625092Power(void)\r
+{\r
+  cmd=0;\r
+  bank=0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xBFFF,UNLN625092WriteCommand);\r
+  SetWriteHandler(0xC000,0xFFFF,UNLN625092WriteBank);\r
+}\r
+\r
+static void UNLN625092Reset(void)\r
+{\r
+  cmd=0;\r
+  bank=0;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLN625092_Init(CartInfo *info)\r
+{\r
+  info->Reset=UNLN625092Reset;\r
+  info->Power=UNLN625092Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 26e70ec..1918abf 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
diff --git a/boards/onebus.c b/boards/onebus.c
new file mode 100644 (file)
index 0000000..a09b488
--- /dev/null
@@ -0,0 +1,308 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007-2010 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * OneBus system\r
+ * Street Dance (Dance pad) (Unl)\r
+ * 101-in-1 Arcade Action II\r
+ * DreamGEAR 75-in-1\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 isDance;\r
+static uint8 regs[16],regc[6];\r
+static uint8 IRQCount,IRQLatch,IRQa, IRQReload, pcm_enable = 0, pcm_irq = 0;\r
+static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xF6;\r
+static writefunc old4011write, old4012write, old4013write, old4015write;\r
+static readfunc old4015read;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {regc, 6, "REGC"},\r
+  {regs, 16, "REGS"},\r
+  {&IRQReload, 1, "IRQR"},\r
+  {&IRQCount, 1, "IRQC"},\r
+  {&IRQLatch, 1, "IRQL"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&pcm_enable, 1, "PCME"},\r
+  {&pcm_irq, 1, "PCMIRQ"},\r
+  {&pcm_addr, 2, "PCMADDR"},\r
+  {&pcm_size, 2, "PCMSIZE"},\r
+  {&pcm_latch, 2, "PCMLATCH"},\r
+  {&pcm_clock, 2, "PCMCLOCK"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint16 cswap = (regs[0xf] & 0x80) << 5;\r
+  uint16 pswap = (regs[0xd]&1)?((regs[0xf] & 0x40) << 8):0;\r
+  uint16 pbase = (regs[0]&0xf0)<<4;\r
+  uint16 cbase = (((regs[0]&0x0f)<<8)|(regs[0xc]<<1)|((regs[0xd]&0xf8)>>3))<<3;\r
+  uint16 pmask = 0x3f>>(regs[0xb]&0xf);\r
+\r
+  setchr1(cswap^0x0000,cbase|(regc[0]&(~1)));\r
+  setchr1(cswap^0x0400,cbase|(regc[0]|1));\r
+  setchr1(cswap^0x0800,cbase|(regc[1]&(-1)));\r
+  setchr1(cswap^0x0c00,cbase|(regc[1]|1));\r
+  setchr1(cswap^0x1000,cbase|(regc[2]));\r
+  setchr1(cswap^0x1400,cbase|(regc[3]));\r
+  setchr1(cswap^0x1800,cbase|(regc[4]));\r
+  setchr1(cswap^0x1c00,cbase|(regc[5]));\r
+\r
+  if(regs[0xd]&2)\r
+  {\r
+    setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask)));\r
+    setprg8(      0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask)));\r
+    setprg8(pswap^0xC000, pbase|(regs[0x9]&pmask)|(regs[0xa]&(~pmask)));\r
+    setprg8(      0xE000, pbase|regs[0xa]);\r
+  }\r
+  else\r
+  {\r
+    setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask)));\r
+    setprg8(      0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask)));\r
+    setprg8(pswap^0xC000, pbase|((~1)&pmask)|(regs[0xa]&(~pmask)));\r
+    setprg8(      0xE000, pbase|((~0)&pmask)|(regs[0xa]&(~pmask)));\r
+  }\r
+\r
+  setmirror(regs[0xe]);\r
+}\r
+\r
+static DECLFW(UNLOneBusWrite20XX)\r
+{\r
+//  FCEU_printf("PPU %04x:%04x\n",A,V);\r
+  if(A == 0x201A)\r
+    regs[0xd] = V;\r
+  else if(A == 0x2018)\r
+    regs[0xc] = V;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(UNLOneBusWriteExp)\r
+{\r
+//  FCEU_printf("EXP %04x:%04x\n",A,V);\r
+//  switch(A & 0x0F)\r
+//  {\r
+//  case 2: pcm_latch = pcm_clock; FCEU_printf("write %04x:%04x\n",A,V); break;\r
+//  case 3: pcm_irqa = 0; X6502_IRQEnd(FCEU_IQEXT); pcm_irq = 0; FCEU_printf("write %04x:%04x\n",A,V); break;\r
+//  case 4: pcm_irqa = 1; FCEU_printf("write %04x:%04x\n",A,V); break;\r
+//  default:\r
+   regs[A & 0x0F] = V;\r
+   Sync();\r
+//  }\r
+}\r
+\r
+static DECLFW(UNLOneBusWriteDebug)\r
+{\r
+//  FCEU_printf("write %04x:%04x\n",A,V);\r
+}\r
+\r
+static DECLFW(UNLOneBusWriteMMC)\r
+{\r
+//  FCEU_printf("MMC %04x:%04x\n",A,V);\r
+  switch(A&0xE001)\r
+  {\r
+  case 0x8000: regs[0xf] = V; Sync(); break;\r
+  case 0x8001:\r
+  {\r
+    uint8 mask = 0xff, mmc3cmd = regs[0xf]&7;\r
+    switch(mmc3cmd)\r
+    {\r
+    case 0:\r
+    case 1:\r
+    case 2:\r
+    case 3:\r
+    case 4:\r
+    case 5:\r
+      if(regs[0xd]&4)\r
+        mask = 0x0f;\r
+      else\r
+        mask >>= ((regs[0xb]&0xf0)>>4);\r
+      regc[mmc3cmd] = V&mask;\r
+      break;\r
+    case 6:\r
+    case 7:\r
+      mask = (mask&0x3f)>>(regs[0xb]&0xf);\r
+      regs[mmc3cmd+1] = (regs[mmc3cmd+1]&(~mask))|(V&mask);\r
+      break;\r
+    }\r
+\r
+    Sync();\r
+    break;\r
+  }\r
+  case 0xA000: regs[0xe] = (V & 1)^1; Sync(); break;\r
+  case 0xC000: IRQLatch = V&0xfe; break;\r
+  case 0xC001: IRQReload = 1; break;\r
+  case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break;\r
+  case 0xE001: IRQa = 1; break;\r
+  }\r
+}\r
+\r
+static void UNLOneBusIRQHook(void)\r
+{\r
+ int count = IRQCount;\r
+ if(!count || IRQReload)\r
+ {\r
+    IRQCount = IRQLatch;\r
+    IRQReload = 0;\r
+ }\r
+ else\r
+    IRQCount--;\r
+ if(count && !IRQCount)\r
+ {\r
+    if(IRQa)\r
+       X6502_IRQBegin(FCEU_IQEXT);\r
+ }\r
+}\r
+\r
+static DECLFW(UNLOneBusWriteAPU2)\r
+{\r
+//  FCEU_printf("APU2 %04x:%04x\n",A,V);\r
+   CartBW(A&0xffdf,V);\r
+}\r
+\r
+static DECLFW(UNLOneBusWrite4012)\r
+{\r
+//  FCEU_printf("write %04x:%04x\n",A,V);\r
+  pcm_addr = V << 6;\r
+  old4012write(A,V);\r
+}\r
+\r
+static DECLFW(UNLOneBusWrite4013)\r
+{\r
+//  FCEU_printf("write %04x:%04x\n",A,V);\r
+  pcm_size = (V << 4) + 1;\r
+  old4013write(A,V);\r
+}\r
+\r
+static DECLFW(UNLOneBusWrite4015)\r
+{\r
+//  FCEU_printf("write %04x:%04x\n",A,V);\r
+  pcm_enable = V&0x10;\r
+  if(pcm_irq)\r
+  {\r
+    X6502_IRQEnd(FCEU_IQEXT);\r
+    pcm_irq = 0;\r
+  }\r
+  if(pcm_enable)\r
+    pcm_latch = pcm_clock;\r
+  old4015write(A,V&0xEF);\r
+}\r
+\r
+static DECLFR(UNLOneBusRead4015)\r
+{\r
+  uint8 result = (old4015read(A) & 0x7F)|pcm_irq;\r
+//  FCEU_printf("read %04x, %02x\n",A,result);\r
+  return result;\r
+}\r
+\r
+static void UNLOneBusCpuHook(int a)\r
+{\r
+  if(pcm_enable)\r
+  {\r
+    pcm_latch-=a;\r
+    if(pcm_latch<=0)\r
+    {\r
+         pcm_latch+=pcm_clock;\r
+         pcm_size--;\r
+         if(pcm_size<0)\r
+         {\r
+           pcm_irq = 0x80;\r
+               pcm_enable = 0;\r
+           X6502_IRQBegin(FCEU_IQEXT);\r
+         }\r
+         else\r
+         {\r
+           uint8 raw_pcm = ARead[pcm_addr](pcm_addr) >> 1;\r
+           old4011write(0x4011,raw_pcm);\r
+               pcm_addr++;\r
+               pcm_addr&=0x7FFF;\r
+         }\r
+    }\r
+  }\r
+}\r
+\r
+static void UNLOneBusPower(void)\r
+{\r
+  IRQCount=IRQLatch=IRQa==0;\r
+  regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0;\r
+  regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0;\r
+  regs[0x09]=0x3E;\r
+  regs[0x0A]=0x3F;\r
+\r
+  SetupCartCHRMapping(0,PRGptr[0],4096 * 1024,0);\r
+\r
+  if(isDance) // quick workaround, TODO: figure out how it works together\r
+  {\r
+    old4015read=GetReadHandler(0x4015);\r
+    SetReadHandler(0x4015,0x4015,UNLOneBusRead4015);\r
+    old4011write=GetWriteHandler(0x4011);\r
+    old4012write=GetWriteHandler(0x4012);\r
+    SetWriteHandler(0x4012,0x4012,UNLOneBusWrite4012);\r
+    old4013write=GetWriteHandler(0x4013);\r
+    SetWriteHandler(0x4013,0x4013,UNLOneBusWrite4013);\r
+    old4015write=GetWriteHandler(0x4015);\r
+    SetWriteHandler(0x4015,0x4015,UNLOneBusWrite4015);\r
+  }\r
+\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x2009,0x2fff,UNLOneBusWrite20XX);\r
+//  SetWriteHandler(0x4020,0xffff,UNLOneBusWriteDebug);\r
+//  SetWriteHandler(0x4020,0x4040,UNLOneBusWriteAPU2);\r
+  SetWriteHandler(0x4100,0x410f,UNLOneBusWriteExp);\r
+  SetWriteHandler(0x8000,0xefff,UNLOneBusWriteMMC);\r
+  Sync();\r
+}\r
+\r
+static void UNLOneBusReset(void)\r
+{\r
+  IRQCount=IRQLatch=IRQa=0;\r
+  regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0;\r
+  regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0;\r
+  regs[0x09]=0x3E;\r
+  regs[0x0A]=0x3F;\r
+  Sync();\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLOneBus_Init(CartInfo *info)\r
+{\r
+  isDance = 0;\r
+  info->Power=UNLOneBusPower;\r
+  info->Reset=UNLOneBusReset;\r
+  GameHBIRQHook=UNLOneBusIRQHook;\r
+//  MapIRQHook=UNLOneBusCpuHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void UNLDANCE_Init(CartInfo *info)\r
+{\r
+  isDance = 1;\r
+  info->Power=UNLOneBusPower;\r
+  info->Reset=UNLOneBusReset;\r
+  GameHBIRQHook=UNLOneBusIRQHook;\r
+  MapIRQHook=UNLOneBusCpuHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 64ad5f6..ab57f3c 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
-static uint8 cmd;
+static uint8 cmd, dip;
 static uint8 latch[8];
 
 static void S74LS374MSync(uint8 mirr)
 static uint8 latch[8];
 
 static void S74LS374MSync(uint8 mirr)
@@ -64,7 +64,8 @@ static DECLFR(S74LS374NRead)
 {
   uint8 ret;
   if((A&0x4100)==0x4100)
 {
   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;
   else
     ret=X.DB;
   return ret;
@@ -72,6 +73,7 @@ static DECLFR(S74LS374NRead)
 
 static void S74LS374NPower(void)
 {
 
 static void S74LS374NPower(void)
 {
+   dip=0;
    latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
    S74LS374NSynco();
    SetReadHandler(0x8000,0xFFFF,CartBR);
    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);
 }
 
    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();
 static void S74LS374NRestore(int version)
 {
    S74LS374NSynco();
@@ -87,9 +96,11 @@ static void S74LS374NRestore(int version)
 void S74LS374N_Init(CartInfo *info)
 {
   info->Power=S74LS374NPower;
 void S74LS374N_Init(CartInfo *info)
 {
   info->Power=S74LS374NPower;
+  info->Reset=S74LS374NReset;
   GameStateRestore=S74LS374NRestore;
   AddExState(latch, 5, 0, "LATC");
   AddExState(&cmd, 1, 0, "CMD");
   GameStateRestore=S74LS374NRestore;
   AddExState(latch, 5, 0, "LATC");
   AddExState(&cmd, 1, 0, "CMD");
+  AddExState(&dip, 1, 0, "DIP");
 }
 
 static void S74LS374NASynco(void)
 }
 
 static void S74LS374NASynco(void)
@@ -291,6 +302,12 @@ static void SA72007Synco()
   setchr8(latch[0]>>7);
 }
 
   setchr8(latch[0]>>7);
 }
 
+static void SA009Synco()
+{
+  setprg32(0x8000,0);
+  setchr8(latch[0]&1);
+}
+
 static void SA72008Synco()
 {
   setprg32(0x8000,(latch[0]>>2)&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");
 }
 
   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;
 void SA0036_Init(CartInfo *info)
 {
   WSync=SA72007Synco;
@@ -337,13 +362,15 @@ void SA0037_Init(CartInfo *info)
   AddExState(&latch[0], 1, 0, "LATC");
 }
 
   AddExState(&latch[0], 1, 0, "LATC");
 }
 
+// -----------------------------------------------
+
 static void TCU01Synco()
 {
 static void TCU01Synco()
 {
-  setprg32(0x8000,(latch[0]>>2)&1);
+  setprg32(0x8000,((latch[0]&0x80)>>6)|((latch[0]>>2)&1));
   setchr8((latch[0]>>3)&0xF);
 }
 
   setchr8((latch[0]>>3)&0xF);
 }
 
-static DECLFW(TCWrite)
+static DECLFW(TCU01Write)
 {
   if((A&0x103)==0x102)
   {
 {
   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);
 {
   latch[0]=0;
   SetReadHandler(0x8000,0xFFFF,CartBR);
-  SetWriteHandler(0x4100,0xFFFF,TCWrite);
+  SetWriteHandler(0x4100,0xFFFF,TCU01Write);
   TCU01Synco();
 }
 
   TCU01Synco();
 }
 
@@ -368,10 +395,55 @@ static void TCU01Restore(int version)
 void TCU01_Init(CartInfo *info)
 {
   GameStateRestore=TCU01Restore;
 void TCU01_Init(CartInfo *info)
 {
   GameStateRestore=TCU01Restore;
-  info->Power=TCU01Reset;
+  info->Power=TCU01Power;
   AddExState(&latch[0], 1, 0, "LATC");
 }
 
   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;
 static DECLFR(TCA01Read)
 {
   uint8 ret;
@@ -382,7 +454,7 @@ static DECLFR(TCA01Read)
   return ret;
 }
 
   return ret;
 }
 
-static void TCA01Reset(void)
+static void TCA01Power(void)
 {
   setprg16(0x8000,0);
   setprg16(0xC000,1);
 {
   setprg16(0x8000,0);
   setprg16(0xC000,1);
@@ -393,6 +465,6 @@ static void TCA01Reset(void)
 
 void TCA01_Init(CartInfo *info)
 {
 
 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 (file)
index 0000000..a2c29ff
--- /dev/null
@@ -0,0 +1,125 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2009 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * \r
+ * Wario Land II (Kirby hack)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[8], chr[8];\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+static uint16 IRQCount, IRQa;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 8, "REGS"},\r
+  {chr, 8, "CHRS"},\r
+  {&IRQCount, 16, "IRQc"},\r
+  {&IRQa, 16, "IRQa"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  int i;\r
+  setprg8(0x8000,reg[0]);\r
+  setprg8(0xA000,reg[1]);\r
+  setprg8(0xC000,reg[2]);\r
+  for(i=0; i<8; i++)\r
+    setchr1(i << 10,chr[i]);\r
+  setmirror(reg[3]^1);\r
+}\r
+\r
+static DECLFW(UNLSC127Write)\r
+{\r
+  switch(A)\r
+  {\r
+    case 0x8000: reg[0] = V; break; \r
+    case 0x8001: reg[1] = V; break;\r
+    case 0x8002: reg[2] = V; break;\r
+    case 0x9000: chr[0] = V; break;\r
+    case 0x9001: chr[1] = V; break;\r
+    case 0x9002: chr[2] = V; break;\r
+    case 0x9003: chr[3] = V; break;\r
+    case 0x9004: chr[4] = V; break;\r
+    case 0x9005: chr[5] = V; break;\r
+    case 0x9006: chr[6] = V; break;\r
+    case 0x9007: chr[7] = V; break;\r
+    case 0xC002: IRQa=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+    case 0xC005: IRQCount=V; break;\r
+    case 0xC003: IRQa=1; break;\r
+    case 0xD001: reg[3] = V; break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void UNLSC127Power(void)\r
+{\r
+  Sync();\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg8(0xE000,~0);\r
+  SetReadHandler(0x6000,0x7fff,CartBR);\r
+  SetWriteHandler(0x6000,0x7fff,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLSC127Write);\r
+}\r
+\r
+static void UNLSC127IRQ(void)\r
+{\r
+ if(IRQa)\r
+ {\r
+   IRQCount--;\r
+   if(IRQCount==0)\r
+   {\r
+    X6502_IRQBegin(FCEU_IQEXT);\r
+    IRQa=0;\r
+   }\r
+ }\r
+}\r
+\r
+static void UNLSC127Reset(void)\r
+{\r
+}\r
+\r
+static void UNLSC127Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLSC127_Init(CartInfo *info)\r
+{\r
+  info->Reset=UNLSC127Reset;\r
+  info->Power=UNLSC127Power;\r
+  info->Close=UNLSC127Close;\r
+  GameHBIRQHook=UNLSC127IRQ;\r
+  GameStateRestore=StateRestore;\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index d228a26..8bea1f7 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 *CHRRAM;           // there is no more extern CHRRAM in mmc3.h
+                                                        // I need chrram here and local   static == local\r
+static uint8 tekker;\r
+\r
+static void MSHCW(uint32 A, uint8 V)\r
+{\r
+  if(EXPREGS[0]&0x40)\r
+    setchr8r(0x10,0);\r
+  else\r
+  {\r
+    if(A<0x800)\r
+      setchr1(A,V|((EXPREGS[0]&8)<<5));\r
+    else if(A<0x1000)\r
+      setchr1(A,V|((EXPREGS[0]&4)<<6));\r
+    else if(A<0x1800)\r
+      setchr1(A,V|((EXPREGS[0]&1)<<8));\r
+    else\r
+      setchr1(A,V|((EXPREGS[0]&2)<<7));\r
+  }\r
+}\r
+\r
+static DECLFW(MSHWrite)\r
+{\r
+  EXPREGS[0]=V;\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static DECLFR(MSHRead)\r
+{\r
+  return(tekker);\r
+}\r
+\r
+static void MSHReset(void)\r
+{\r
+  MMC3RegReset();\r
+  tekker^=0xFF; \r
+}\r
+\r
+static void MSHPower(void)\r
+{\r
+  tekker=0x00;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x4100,0x4100,MSHWrite);\r
+  SetReadHandler(0x4100,0x4100,MSHRead);\r
+}\r
+\r
+static void MSHClose(void)\r
+{\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  CHRRAM=NULL;\r
+}\r
+\r
+void UNLSHeroes_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 512, 0, 0);\r
+  cwrap=MSHCW;\r
+  info->Power=MSHPower;\r
+  info->Reset=MSHReset;\r
+  info->Close=MSHClose;\r
+  CHRRAM = (uint8*)FCEU_gmalloc(8192);\r
+  SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);\r
+  AddExState(EXPREGS, 4, 0, "EXPR");\r
+  AddExState(&tekker, 1, 0, "DIPSW");\r
+}\r
index 9e99722..18895fb 100644 (file)
-/* 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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+// brk is a system call in *nix, and is an illegal variable name - soules\r
+static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {chrcmd, 8, "CHRCMD"},\r
+  {&prg0, 1, "PRG0"},\r
+  {&prg1, 1, "PRG1"},\r
+  {&bbrk, 1, "BRK"},\r
+  {&mirr, 1, "MIRR"},\r
+  {&swap, 1, "SWAP"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  int i;\r
+  setprg8(0x8000,prg0);\r
+  setprg8(0xA000,prg1);\r
+  setprg8(0xC000,~1);\r
+  setprg8(0xE000,~0);\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chrcmd[i]);\r
+  setmirror(mirr^1);\r
+}\r
+\r
+static void UNLSL1632CW(uint32 A, uint8 V)\r
+{\r
+  int cbase=(MMC3_cmd&0x80)<<5;\r
+  int page0=(bbrk&0x08)<<5;\r
+  int page1=(bbrk&0x20)<<3;\r
+  int page2=(bbrk&0x80)<<1;\r
+  setchr1(cbase^0x0000,page0|(DRegBuf[0]&(~1)));\r
+  setchr1(cbase^0x0400,page0|DRegBuf[0]|1);\r
+  setchr1(cbase^0x0800,page0|(DRegBuf[1]&(~1)));\r
+  setchr1(cbase^0x0C00,page0|DRegBuf[1]|1);\r
+  setchr1(cbase^0x1000,page1|DRegBuf[2]);\r
+  setchr1(cbase^0x1400,page1|DRegBuf[3]);\r
+  setchr1(cbase^0x1800,page2|DRegBuf[4]);\r
+  setchr1(cbase^0x1c00,page2|DRegBuf[5]);\r
+}\r
+\r
+static DECLFW(UNLSL1632CMDWrite)\r
+{\r
+  if(A==0xA131)\r
+  {\r
+    bbrk=V;\r
+  }\r
+  if(bbrk&2)\r
+  {\r
+    FixMMC3PRG(MMC3_cmd);\r
+    FixMMC3CHR(MMC3_cmd);\r
+    if(A<0xC000)\r
+      MMC3_CMDWrite(A,V);\r
+    else\r
+      MMC3_IRQWrite(A,V);\r
+  }\r
+  else\r
+  {\r
+    if((A>=0xB000)&&(A<=0xE003))\r
+    {\r
+      int ind=((((A&2)|(A>>10))>>1)+2)&7;\r
+      int sar=((A&1)<<2);\r
+      chrcmd[ind]=(chrcmd[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r
+    }\r
+    else\r
+      switch(A&0xF003)\r
+      {\r
+        case 0x8000: prg0=V; break;\r
+        case 0xA000: prg1=V; break;\r
+        case 0x9000: mirr=V&1; break;\r
+      }\r
+    Sync();\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  if(bbrk&2)\r
+  {\r
+    FixMMC3PRG(MMC3_cmd);\r
+    FixMMC3CHR(MMC3_cmd);\r
+  }\r
+  else\r
+    Sync();\r
+}\r
+\r
+static void UNLSL1632Power(void)\r
+{\r
+  GenMMC3Power();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4100,0xFFFF,UNLSL1632CMDWrite);\r
+}\r
+\r
+void UNLSL1632_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 256, 512, 0, 0);\r
+  cwrap=UNLSL1632CW;\r
+  info->Power=UNLSL1632Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/smb2j.c b/boards/smb2j.c
new file mode 100644 (file)
index 0000000..15655a7
--- /dev/null
@@ -0,0 +1,96 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * Super Mario Bros 2 J alt version\r
+ * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg, IRQa;\r
+static uint16 IRQCount;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&prg, 1, "PRG"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 2, "IRQC"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg4r(1,0x5000,1);\r
+  setprg8r(1,0x6000,1);\r
+  setprg32(0x8000,prg);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(UNLSMB2JWrite)\r
+{\r
+  if(A==0x4022)\r
+  {\r
+    prg=V&1;\r
+    Sync();\r
+  }\r
+  if(A==0x4122)\r
+  {\r
+    IRQa=V;\r
+    IRQCount=0;\r
+    X6502_IRQEnd(FCEU_IQEXT);\r
+  }\r
+}\r
+\r
+static void UNLSMB2JPower(void)\r
+{\r
+  prg=~0;\r
+  Sync();\r
+  SetReadHandler(0x5000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite);\r
+}\r
+\r
+static void UNLSMB2JReset(void)\r
+{ \r
+  prg=~0;\r
+  Sync();\r
+}\r
+\r
+static void UNLSMB2JIRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount+=a*3;\r
+    if((IRQCount>>12)==IRQa)\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLSMB2J_Init(CartInfo *info)\r
+{\r
+  info->Reset=UNLSMB2JReset;\r
+  info->Power=UNLSMB2JPower;\r
+  MapIRQHook=UNLSMB2JIRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index f96cc12..9f0386d 100644 (file)
@@ -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"\r
+\r
+static uint8 mode;\r
+static uint8 DRegs[4];\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {DRegs, 4, "DREG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  int base, bank;\r
+  base = ((DRegs[0]^DRegs[1])&0x10)<<1;\r
+  bank = (DRegs[2]^DRegs[3])&0x1f;\r
+\r
+  if(DRegs[1]&0x08)\r
+  {\r
+    bank &= 0xfe;\r
+    if(mode==0)\r
+    {\r
+      setprg16(0x8000,base+bank+1);\r
+      setprg16(0xC000,base+bank+0);\r
+    }\r
+    else\r
+    {\r
+      setprg16(0x8000,base+bank+0);\r
+      setprg16(0xC000,base+bank+1);\r
+    }\r
+  }\r
+  else\r
+  {\r
+    if(DRegs[1]&0x04)\r
+    {\r
+      setprg16(0x8000,0x1f);\r
+      setprg16(0xC000,base+bank);\r
+    }\r
+    else\r
+    {\r
+      setprg16(0x8000,base+bank);\r
+      if(mode==0)\r
+         setprg16(0xC000,0x20);\r
+      else\r
+         setprg16(0xC000,0x07);\r
+    }\r
+  }\r
+}\r
+\r
+static DECLFW(Mapper167_write)\r
+{\r
+  DRegs[(A>>13)&0x03]=V;\r
+  Sync();\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper166_init(void)\r
+{\r
+  mode=1;\r
+  DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0;\r
+  Sync();\r
+  SetWriteHandler(0x8000,0xFFFF,Mapper167_write);\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper167_init(void)\r
+{\r
+  mode=0;\r
+  DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0;\r
+  Sync();\r
+  SetWriteHandler(0x8000,0xFFFF,Mapper167_write);\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 205c8d2..4ccc766 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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"
 
  */
 
 #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)
 static int masko8[8]={63,31,15,1,3,0,0,0};
 
 static void Super24PW(uint32 A, uint8 V)
index 61a373d..e405c75 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
diff --git a/boards/t-227-1.c b/boards/t-227-1.c
new file mode 100644 (file)
index 0000000..25d64af
--- /dev/null
@@ -0,0 +1,116 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2008 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+// T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 reset_flag = 0x07;\r
+\r
+static void BMCT2271CW(uint32 A, uint8 V)\r
+{\r
+    uint32 va = V; \r
+    if(EXPREGS[0]&0x20)\r
+    {\r
+      va|=0x200;\r
+      va|=(EXPREGS[0]&0x10)<<4;\r
+    }\r
+    else\r
+    {\r
+      va&=0x7F;\r
+      va|=(EXPREGS[0]&0x18)<<4;\r
+    }\r
+    setchr1(A,va);\r
+}\r
+\r
+static void BMCT2271PW(uint32 A, uint8 V)\r
+{\r
+    uint32 va = V & 0x3F; \r
+    if(EXPREGS[0]&0x20)\r
+    {\r
+       va&=0x1F;\r
+       va|=0x40;\r
+       va|=(EXPREGS[0]&0x10)<<1;\r
+    }\r
+    else\r
+    {\r
+       va&=0x0F;\r
+       va|=(EXPREGS[0]&0x18)<<1;\r
+    }\r
+    switch(EXPREGS[0]&3)\r
+    {\r
+      case 0x00: setprg8(A,va); break;\r
+      case 0x02: \r
+           {\r
+             va=(va&0xFD)|((EXPREGS[0]&4)>>1);\r
+             if(A<0xC000)\r
+             {\r
+               setprg16(0x8000,va >> 1); \r
+               setprg16(0xC000,va >> 1); \r
+             }\r
+             break;\r
+           }\r
+      case 0x01: \r
+      case 0x03: if(A<0xC000) setprg32(0x8000,va >> 2); break;\r
+    }\r
+\r
+}\r
+       \r
+static DECLFW(BMCT2271LoWrite)\r
+{\r
+  if(!(EXPREGS[0]&0x80))\r
+    EXPREGS[0] = A & 0xFF;\r
+  FixMMC3PRG(MMC3_cmd);\r
+  FixMMC3CHR(MMC3_cmd);\r
+}\r
+\r
+static DECLFR(BMCT2271HiRead)\r
+{\r
+  uint32 av = A;\r
+  if(EXPREGS[0]&0x40) av = (av & 0xFFF0)|reset_flag;\r
+  return CartBR(av);\r
+}\r
+\r
+static void BMCT2271Reset(void)\r
+{\r
+  EXPREGS[0] = 0x00;\r
+  reset_flag++;\r
+  reset_flag&=0x0F;\r
+  MMC3RegReset();\r
+}\r
+\r
+static void BMCT2271Power(void)\r
+{\r
+  EXPREGS[0] = 0x00;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x6000,0x7FFF,BMCT2271LoWrite);\r
+  SetReadHandler(0x8000,0xFFFF,BMCT2271HiRead);\r
+}\r
+\r
+void BMCT2271_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 128, 8, 0);\r
+  pwrap=BMCT2271PW;\r
+  cwrap=BMCT2271CW;\r
+  info->Power=BMCT2271Power;\r
+  info->Reset=BMCT2271Reset;\r
+  AddExState(EXPREGS, 1, 0, "EXPR");\r
+}\r
index fe9b446..15e94ea 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 addrreg;\r
+static uint8 datareg;\r
+static uint8 busy;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&addrreg, 2, "ADDRREG"},\r
+  {&datareg, 1, "DATAREG"},\r
+  {&busy, 1, "BUSY"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint16 base=((addrreg&0x60)>>2)|((addrreg&0x100)>>3);  \r
+  setprg16(0x8000,(datareg&7)|base);\r
+  setprg16(0xC000,7|base);\r
+  setmirror(((addrreg&2)>>1)^1);\r
+}\r
+\r
+static DECLFW(BMCT262Write)\r
+{\r
+  if(busy||(A==0x8000))\r
+    datareg=V;\r
+  else\r
+  {\r
+    addrreg=A;\r
+    busy=1;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void BMCT262Power(void)\r
+{\r
+  setchr8(0);\r
+  SetWriteHandler(0x8000,0xFFFF,BMCT262Write);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  busy=0;\r
+  addrreg=0;\r
+  datareg=0xff;\r
+  Sync();\r
+}\r
+\r
+static void BMCT262Reset(void)\r
+{\r
+  busy=0;\r
+  addrreg=0;\r
+  datareg=0;\r
+  Sync();\r
+}\r
+\r
+static void BMCT262Restore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMCT262_Init(CartInfo *info)\r
+{\r
+  info->Power=BMCT262Power;\r
+  info->Reset=BMCT262Reset;\r
+  GameStateRestore=BMCT262Restore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index a4f33f5..3881622 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -36,10 +36,10 @@ static SFORMAT Rambo_StateRegs[]={
   {0}
 };
 
   {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;
 {
   static int smallcount;
   if(!IRQmode) return;
@@ -104,7 +104,7 @@ static DECLFW(RAMBO1_write)
   switch(A&0xF001)
   {
     case 0xa000: mir=V&1;
   switch(A&0xF001)
   {
     case 0xa000: mir=V&1;
-                 if(!nomirror)
+//                 if(!nomirror)
                    setmirror(mir^1);
                  break;
     case 0x8000: cmd = V;
                    setmirror(mir^1);
                  break;
     case 0x8000: cmd = V;
@@ -138,7 +138,7 @@ static DECLFW(RAMBO1_write)
 static void RAMBO1_Restore(int version)
 {
   Synco();
 static void RAMBO1_Restore(int version)
 {
   Synco();
-  if(!nomirror)
+//  if(!nomirror)
     setmirror(mir^1);
 }
 
     setmirror(mir^1);
 }
 
@@ -148,7 +148,7 @@ static void RAMBO1_init(void)
   for(x=0;x<11;x++)
      DRegs[x]=~0;
   cmd=mir=0;
   for(x=0;x<11;x++)
      DRegs[x]=~0;
   cmd=mir=0;
-  if(!nomirror)
+//  if(!nomirror)
     setmirror(1);
   Synco();
   GameHBIRQHook=RAMBO1_hb;
     setmirror(1);
   Synco();
   GameHBIRQHook=RAMBO1_hb;
@@ -158,7 +158,7 @@ static void RAMBO1_init(void)
   AddExState(Rambo_StateRegs, ~0, 0, 0);
 }
 
   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);
 }
 {
   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;
 void Mapper64_init(void)
 {
   setchr1wrap=CHRWrap;
-  nomirror=0;
+//  nomirror=0;
   RAMBO1_init();
 }
   RAMBO1_init();
 }
-
+/*
 static int MirCache[8];
 static unsigned int PPUCHRBus;
 
 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))
 {
   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);
 }
 
   setchr1(A,V);
 }
 
-static void FP_FASTAPASS(1) MirrorFear(uint32 A)
+static void MirrorFear(uint32 A)
 {
   A&=0x1FFF;
   A>>=10;
 {
   A&=0x1FFF;
   A>>=10;
@@ -196,3 +196,5 @@ void Mapper158_init(void)
   nomirror=1;
   RAMBO1_init();
 }
   nomirror=1;
   RAMBO1_init();
 }
+*/
+
diff --git a/boards/tf-1201.c b/boards/tf-1201.c
new file mode 100644 (file)
index 0000000..d40cb5f
--- /dev/null
@@ -0,0 +1,124 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ *\r
+ * Lethal Weapon (VRC4 mapper)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg0, prg1, mirr, swap;\r
+static uint8 chr[8];\r
+static uint8 IRQCount;           \r
+static uint8 IRQPre;\r
+static uint8 IRQa;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&prg0, 1, "PRG0"},\r
+  {&prg0, 1, "PRG1"},\r
+  {&mirr, 1, "MIRR"},\r
+  {&swap, 1, "SWAP"},\r
+  {chr, 8, "CHR"},\r
+  {&IRQCount, 1, "IRQCOUNT"},\r
+  {&IRQPre, 1, "IRQPRE"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {0}\r
+};\r
+\r
+static void SyncPrg(void)\r
+{\r
+  if(swap&3)\r
+  {\r
+    setprg8(0x8000,~1);\r
+    setprg8(0xC000,prg0);\r
+  }  \r
+  else\r
+  {\r
+    setprg8(0x8000,prg0);\r
+    setprg8(0xC000,~1);\r
+  }\r
+  setprg8(0xA000,prg1);\r
+  setprg8(0xE000,~0);\r
+}\r
+\r
+static void SyncChr(void)\r
+{\r
+  int i;\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr[i]);\r
+  setmirror(mirr^1);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  SyncPrg();\r
+  SyncChr();\r
+}\r
+\r
+static DECLFW(UNLTF1201Write)\r
+{\r
+  A=(A&0xF003)|((A&0xC)>>2);\r
+  if((A>=0xB000)&&(A<=0xE003))\r
+  {\r
+    int ind=(((A>>11)-6)|(A&1))&7;\r
+    int sar=((A&2)<<1);\r
+    chr[ind]=(chr[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r
+    SyncChr();\r
+  }\r
+  else switch (A&0xF003)\r
+  {\r
+    case 0x8000: prg0=V; SyncPrg(); break;\r
+    case 0xA000: prg1=V; SyncPrg(); break;\r
+    case 0x9000: mirr=V&1; SyncChr(); break;\r
+    case 0x9001: swap=V&3; SyncPrg(); break;\r
+    case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r
+    case 0xF002: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r
+    case 0xF001: \r
+    case 0xF003: IRQa=V&2; X6502_IRQEnd(FCEU_IQEXT); if(scanline<240) IRQCount-=8; break;\r
+  }\r
+}\r
+  \r
+static void UNLTF1201IRQCounter(void)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount++;\r
+    if(IRQCount==237)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+  }\r
+}\r
+  \r
+static void UNLTF1201Power(void)\r
+{\r
+  IRQPre=IRQCount=IRQa=0;\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLTF1201Write);\r
+  SyncPrg();\r
+  SyncChr();\r
+}\r
+\r
+void UNLTF1201_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLTF1201Power;\r
+  GameHBIRQHook=UNLTF1201IRQCounter;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index ed321fd..1e7345e 100644 (file)
--- a/driver.h
+++ b/driver.h
@@ -62,13 +62,16 @@ void FCEUI_SetNTSCTH(int n, int tint, int hue);
 
 #include "version.h"
 
 
 #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_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
 #define SIFC_NONE      0
 #define SIFC_ARKANOID  1
 #define SIFC_SHADOW      2
diff --git a/fce.c b/fce.c
index 78a75b6..282a264 100644 (file)
--- a/fce.c
+++ b/fce.c
@@ -98,6 +98,7 @@ static uint8 deemp=0;
 static int deempcnt[8];
 
 FCEUGI FCEUGameInfo;
 static int deempcnt[8];
 
 FCEUGI FCEUGameInfo;
+FCEUGI *GameInfo = &FCEUGameInfo;
 void (*GameInterface)(int h, void *param);
 
 void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
 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);
 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);
 
 int FDSLoad(const char *name, int fp);
 int NSFLoad(int fp);
 
@@ -1175,7 +1176,7 @@ FCEUGI *FCEUI_LoadGame(char *name)
        }
 
         GetFileBase(name2);
        }
 
         GetFileBase(name2);
-        if(iNESLoad(name2,fp))
+        if(iNESLoad(name2,fp,1))
          goto endlseq;
         if(NSFLoad(fp))
          goto endlseq;
          goto endlseq;
         if(NSFLoad(fp))
          goto endlseq;
@@ -1518,9 +1519,9 @@ void ResetNES081(void)
         X6502_Reset();
 }
 
         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)
  {
  int x=0;
  while(size)
  {
@@ -1529,8 +1530,8 @@ static void FCEU_MemoryRand(uint8 *ptr, uint32 size)
   size--;
   ptr++;
  }
   size--;
   ptr++;
  }
-}
 #endif
 #endif
+}
 
 void PowerNES(void)
 {
 
 void PowerNES(void)
 {
@@ -1541,9 +1542,8 @@ void PowerNES(void)
 
         GeniePower();
 
 
         GeniePower();
 
-#ifndef DEBUG_ASM_6502
         FCEU_MemoryRand(RAM,0x800);
         FCEU_MemoryRand(RAM,0x800);
-#else
+#ifdef DEBUG_ASM_6502
         memset(RAM,0x00,0x800);
        memset(nes_internal_ram,0x00,0x800);
 #endif
         memset(RAM,0x00,0x800);
        memset(nes_internal_ram,0x00,0x800);
 #endif
diff --git a/fce.h b/fce.h
index 593d858..dde07c0 100644 (file)
--- 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)
 
 #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);
 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 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];
 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_RESETM2     1
 #define GI_POWER       2
 #define GI_CLOSE       3
+#define GI_RESETSAVE   4
 #define GI_INFOSTRING  11
 
 #include "git.h"
 extern FCEUGI FCEUGameInfo;
 #define GI_INFOSTRING  11
 
 #include "git.h"
 extern FCEUGI FCEUGameInfo;
+extern FCEUGI *GameInfo; // FCEUX compatibility HACK
 extern int GameAttributes;
 
 extern uint8 pale;
 extern int GameAttributes;
 
 extern uint8 pale;
diff --git a/file.h b/file.h
index 233be1a..0230c57 100644 (file)
--- 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);
 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);
 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 (file)
--- a/git.h
+++ b/git.h
@@ -12,6 +12,7 @@
        \r
 typedef struct {\r
   uint8 *name;  /* Game name, UTF8 encoding */\r
        \r
 typedef struct {\r
   uint8 *name;  /* Game name, UTF8 encoding */\r
+  int mappernum;\r
 \r
         int type;       /* GIT_* */\r
         int vidsys;     /* Current emulated video system; GIV_* */\r
 \r
         int type;       /* GIT_* */\r
         int vidsys;     /* Current emulated video system; GIV_* */\r
index 054b0ec..d7705e8 100644 (file)
@@ -1,7 +1,10 @@
     {0x9cbadc25,5,8},  /* JustBreed */
 
     {0x6e68e31a,16,8},     /* Dragon Ball 3*/
     {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 */
     {0x3f15d20d,153,8},    /* Famicom Jump 2 */
+
     {0x983d8175,157,8},  /* Datach Battle Rush */
     {0x894efdbc,157,8},  /* Datach Crayon Shin Chan */
     {0x19e81461,157,8},  /* Datach DBZ */
     {0x983d8175,157,8},  /* Datach Battle Rush */
     {0x894efdbc,157,8},  /* Datach Crayon Shin Chan */
     {0x19e81461,157,8},  /* Datach DBZ */
     {0x063b1151,209,-1},  /* Power Rangers 4 */
     {0xdd8ced31,209,-1},  /* Power Rangers 3 */
 
     {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 */
     {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 */
     {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 */
   {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 */
 {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) */
 
 
 {0x84382231,9,0},  /* Punch Out (J) */
 
 {0xd26efd78,66,1},  /* SMB Duck Hunt */
 {0x811f06d9,66,1},  /* Dragon Power */
 {0x3293afea,140,1},  /* Mississippi Satsujin Jiken */
 {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 */
 
 {0xe84274c5,66,1},  /* "" "" */
 {0x9552e8df,66,1},  /* Dragon Ball */
 
    {0x555a555e,191,-1},
    {0x98c1cd4b,192,-1},/* Ying Lie Qun Xia Zhuan (Chinese) */
    {0x442f1a29,192,-1},/* Young chivalry */
    {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) */
    {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},
    {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}
    {0,-1,-1}
diff --git a/ines.c b/ines.c
index 2f5fbeb..042dad2 100644 (file)
--- a/ines.c
+++ b/ines.c
@@ -1,23 +1,23 @@
 /* FCE Ultra - NES/Famicom Emulator\r
 /* FCE Ultra - NES/Famicom Emulator\r
- *\r
- * Copyright notice for this file:\r
- *  Copyright (C) 1998 BERO\r
- *  Copyright (C) 2002 Xodnizel\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
+*\r
+* Copyright notice for this file:\r
+*  Copyright (C) 1998 BERO\r
+*  Copyright (C) 2002 Xodnizel\r
+*\r
+* This program is free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+*/\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #define INESPRIV\r
 #include "ines.h"\r
 #include "unif.h"\r
 #define INESPRIV\r
 #include "ines.h"\r
 #include "unif.h"\r
-#include "general.h"\r
 #include "state.h"\r
 #include "file.h"\r
 #include "state.h"\r
 #include "file.h"\r
+#include "general.h"\r
 #include "memory.h"\r
 #include "crc32.h"\r
 #include "md5.h"\r
 #include "cheat.h"\r
 #include "vsuni.h"\r
 #include "memory.h"\r
 #include "crc32.h"\r
 #include "md5.h"\r
 #include "cheat.h"\r
 #include "vsuni.h"\r
-\r
 #include "driver.h"\r
 #include "svga.h"\r
 \r
 extern SFORMAT FCEUVSUNI_STATEINFO[];\r
 \r
 #include "driver.h"\r
 #include "svga.h"\r
 \r
 extern SFORMAT FCEUVSUNI_STATEINFO[];\r
 \r
-static uint8 *trainerpoo=0;\r
-static uint8 *ROM=NULL;\r
-//static\r
-uint8 *VROM=NULL;\r
+//mbg merge 6/29/06 - these need to be global\r
+uint8 *trainerpoo=0;\r
+uint8 *ROM = NULL;\r
+uint8 *VROM = NULL;\r
+struct iNES_HEADER head;\r
+\r
+\r
 \r
 static CartInfo iNESCart;\r
 \r
 \r
 static CartInfo iNESCart;\r
 \r
@@ -60,7 +62,9 @@ uint8 iNESIRQa=0;
 \r
 uint32 ROM_size=0;\r
 uint32 VROM_size=0;\r
 \r
 uint32 ROM_size=0;\r
 uint32 VROM_size=0;\r
+//char LoadedRomFName[2048]; //mbg merge 7/17/06 added\r
 \r
 \r
+static int CHRRAMSize = -1;\r
 static void iNESPower(void);\r
 static int NewiNES_Init(int num);\r
 \r
 static void iNESPower(void);\r
 static int NewiNES_Init(int num);\r
 \r
@@ -69,60 +73,72 @@ void (*MapperReset)(void);
 \r
 static int MapperNo=0;\r
 \r
 \r
 static int MapperNo=0;\r
 \r
-static iNES_HEADER head;\r
-\r
 /*  MapperReset() is called when the NES is reset(with the reset button).\r
 /*  MapperReset() is called when the NES is reset(with the reset button).\r
-    Mapperxxx_init is called when the NES has been powered on.\r
+Mapperxxx_init is called when the NES has been powered on.\r
 */\r
 \r
 */\r
 \r
+\r
 static DECLFR(TrainerRead)\r
 {\r
 static DECLFR(TrainerRead)\r
 {\r
- return(trainerpoo[A&0x1FF]);\r
+       return(trainerpoo[A&0x1FF]);\r
+}\r
+\r
+static void iNES_ExecPower()\r
+{\r
+       if(CHRRAMSize != -1)\r
+               FCEU_MemoryRand(VROM,CHRRAMSize);\r
+\r
+       if(iNESCart.Power)\r
+               iNESCart.Power();\r
+\r
+       if(trainerpoo)\r
+       {\r
+               int x;\r
+               for(x=0;x<512;x++)\r
+               {\r
+                       //X6502_DMW(0x7000+x,trainerpoo[x]);\r
+                       //if(X6502_DMR(0x7000+x)!=trainerpoo[x])\r
+                       unsigned int A=0x7000+x;\r
+                       BWrite[A](A,trainerpoo[x]);\r
+                       if(ARead[A](A)!=trainerpoo[x])\r
+                       {\r
+                               SetReadHandler(0x7000,0x71FF,TrainerRead);\r
+                               break;\r
+                       }\r
+               }\r
+       }\r
 }\r
 \r
 static void iNESGI(int h, void *param)\r
 {\r
 }\r
 \r
 static void iNESGI(int h, void *param)\r
 {\r
- switch(h)\r
- {\r
-  case GI_RESETM2:\r
+       switch(h)\r
+       {\r
+       case GI_RESETSAVE:\r
+               //FCEU_ClearGameSave(&iNESCart);\r
+               break;\r
+\r
+       case GI_RESETM2:\r
                if(MapperReset)\r
                if(MapperReset)\r
-                MapperReset();\r
+                       MapperReset();\r
                if(iNESCart.Reset)\r
                if(iNESCart.Reset)\r
-                iNESCart.Reset();\r
+                       iNESCart.Reset();\r
+               break;\r
+       case GI_POWER:\r
+               iNES_ExecPower();\r
+       \r
                break;\r
                break;\r
-  case GI_POWER:\r
-                if(iNESCart.Power)\r
-                 iNESCart.Power();\r
-               if(trainerpoo)\r
+       case GI_CLOSE:\r
                {\r
                {\r
-                int x;\r
-                for(x=0;x<512;x++)\r
-                {\r
-                 //X6502_DMW(0x7000+x,trainerpoo[x]);\r
-                 //if(X6502_DMR(0x7000+x)!=trainerpoo[x])\r
-                 unsigned int A=0x7000+x;\r
-                 BWrite[A](A,trainerpoo[x]);\r
-                 if(ARead[A](A)!=trainerpoo[x])\r
-                 {\r
-                    SetReadHandler(0x7000,0x71FF,TrainerRead);\r
-                   break;\r
-                 }\r
-                }\r
+                       FCEU_SaveGameSave(&iNESCart);\r
+\r
+                       if(iNESCart.Close) iNESCart.Close();\r
+                       if(ROM) {free(ROM); ROM = NULL;}\r
+                       if(VROM) {free(VROM); VROM = NULL;}\r
+                       if(MapClose) MapClose();\r
+                       if(trainerpoo) {FCEU_gfree(trainerpoo);trainerpoo=0;}\r
                }\r
                break;\r
                }\r
                break;\r
-  case GI_CLOSE:\r
-               {\r
-                 FCEU_SaveGameSave(&iNESCart);\r
-\r
-                if(iNESCart.Close) iNESCart.Close();\r
-                if(ROM) {free(ROM);ROM=0;}\r
-                if(VROM) {free(VROM);VROM=0;}\r
-                if(MapClose) MapClose();\r
-                if(trainerpoo) {FCEU_gfree(trainerpoo);trainerpoo=0;}\r
-                ResetExState(0,0);\r
-               }\r
-               break;\r
-  case GI_INFOSTRING:\r
+       case GI_INFOSTRING:\r
                {\r
                 int MapperNo;\r
                 MapperNo = (head.ROM_type>>4);\r
                {\r
                 int MapperNo;\r
                 MapperNo = (head.ROM_type>>4);\r
@@ -131,7 +147,7 @@ static void iNESGI(int h, void *param)
                        MapperNo, (head.ROM_type&2)?", BB":"", (head.ROM_type&4)?", T":"");\r
                }\r
                break;\r
                        MapperNo, (head.ROM_type&2)?", BB":"", (head.ROM_type&4)?", T":"");\r
                }\r
                break;\r
- }\r
      }\r
 }\r
 \r
 uint32 iNESGameCRC32=0;\r
 }\r
 \r
 uint32 iNESGameCRC32=0;\r
@@ -148,102 +164,99 @@ struct INPSEL {
        int inputfc;\r
 };\r
 \r
        int inputfc;\r
 };\r
 \r
-/* This is mostly for my personal use.  So HA. */\r
 static void SetInput(void)\r
 {\r
 static void SetInput(void)\r
 {\r
- static struct INPSEL moo[]=\r
      static struct INPSEL moo[]=\r
        {\r
        {\r
-         {0x3a1694f9,SI_GAMEPAD,SI_GAMEPAD,SIFC_4PLAYER},       /* Nekketsu Kakutou Densetsu */\r
-\r
-#if 0\r
-   {0xc3c0811d,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS},  /* The two "Oeka Kids" games */\r
-   {0x9d048ea4,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS},  /*           */\r
-\r
-   {0xaf4010ea,SI_GAMEPAD,SI_POWERPADB,-1},  /* World Class Track Meet */\r
-   {0xd74b2719,SI_GAMEPAD,SI_POWERPADB,-1},  /* Super Team Games */\r
-   {0x61d86167,SI_GAMEPAD,SI_POWERPADB,-1},  /* Street Cop */\r
-   {0x6435c095,SI_GAMEPAD,SI_POWERPADB,-1},      /* Short Order/Eggsplode */\r
-\r
-\r
-   {0x47232739,SI_GAMEPAD,SI_GAMEPAD,SIFC_TOPRIDER},  /* Top Rider */\r
-\r
-        {0x48ca0ee1,SI_GAMEPAD,SI_GAMEPAD,SIFC_BWORLD},    /* Barcode World */\r
-        {0x9f8f200a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Super Mogura Tataki!! - Pokkun Moguraa */\r
-        {0x9044550e,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Rairai Kyonshizu */\r
-        {0x2f128512,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Jogging Race */\r
-        {0x60ad090a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, /* Athletic World */\r
-\r
-        {0x8a12a7d9,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Totsugeki Fuuun Takeshi Jou */\r
-        {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Running Stadium */\r
-        {0x370ceb65,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Meiro Dai Sakusen */\r
-        // Bad dump? {0x69ffb014,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Fuun Takeshi Jou 2 */\r
-        {0x6cca1c1f,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, /* Dai Undoukai */\r
-        {0x29de87af,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB},  /* Aerobics Studio */\r
-         {0xbba58be5,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB},  /* Family Trainer: Manhattan Police */\r
-        {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB},  /* Family Trainer:  Running Stadium */\r
-\r
-        {0xd9f45be9,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING},  /* Gimme a Break ... */\r
-        {0x1545bd13,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING},  /* Gimme a Break ... 2 */\r
-\r
-        {0x7b44fb2a,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG},  /* Ide Yousuke Meijin no Jissen Mahjong 2 */\r
-        {0x9fae4d46,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG},  /* Ide Yousuke Meijin no Jissen Mahjong */\r
-\r
-        {0x980be936,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Olympic */\r
-        {0x21f85681,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Olympic (Gentei Ban) */\r
-        {0x915a53a7,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, /* Hyper Sports */\r
-#endif\r
-   {0xad9c63e2,SI_GAMEPAD,-1,SIFC_SHADOW},  /* Space Shadow */\r
-\r
-   {0x24598791,-1,SI_ZAPPER,0},  /* Duck Hunt */\r
-        {0xff24d794,-1,SI_ZAPPER,0},   /* Hogan's Alley */\r
-   {0xbeb8ab01,-1,SI_ZAPPER,0},  /* Gumshoe */\r
-   {0xde8fd935,-1,SI_ZAPPER,0},  /* To the Earth */\r
-   {0xedc3662b,-1,SI_ZAPPER,0},  /* Operation Wolf */\r
-   {0x2a6559a1,-1,SI_ZAPPER,0},  /* Operation Wolf (J) */\r
-\r
-   {0x23d17f5e,SI_GAMEPAD,SI_ZAPPER,0},  /* The Lone Ranger */\r
-        {0xb8b9aca3,-1,SI_ZAPPER,0},  /* Wild Gunman */\r
-        {0x5112dc21,-1,SI_ZAPPER,0},  /* Wild Gunman */\r
-        {0x4318a2f8,-1,SI_ZAPPER,0},  /* Barker Bill's Trick Shooting */\r
-        {0x5ee6008e,-1,SI_ZAPPER,0},  /* Mechanized Attack */\r
-        {0x3e58a87e,-1,SI_ZAPPER,0},  /* Freedom Force */\r
-   {0x851eb9be,SI_GAMEPAD,SI_ZAPPER,0},  /* Shooting Range */\r
-   {0x74bea652,SI_GAMEPAD,SI_ZAPPER,0},  /* Supergun 3-in-1 */\r
-        {0x32fb0583,-1,SI_ARKANOID,0}, /* Arkanoid(NES) */\r
-        {0xd89e5a67,-1,-1,SIFC_ARKANOID}, /* Arkanoid (J) */\r
-        {0x0f141525,-1,-1,SIFC_ARKANOID}, /* Arkanoid 2(J) */\r
-\r
-   {0x912989dc,-1,-1,SIFC_FKB},  /* Playbox BASIC */\r
-   {0xf7606810,-1,-1,SIFC_FKB},  /* Family BASIC 2.0A */\r
-   {0x895037bc,-1,-1,SIFC_FKB},  /* Family BASIC 2.1a */\r
-   {0xb2530afc,-1,-1,SIFC_FKB},  /* Family BASIC 3.0 */\r
-#if 0\r
-   {0x82f1fb96,-1,-1,SIFC_SUBORKB},  /* Subor 1.0 Russian */\r
-   {0xabb2f974,-1,-1,SIFC_SUBORKB},  /* Study and Game 32-in-1 */\r
-   {0xd5d6eac4,-1,-1,SIFC_SUBORKB},  /* Edu (As) */\r
-   {0x589b6b0d,-1,-1,SIFC_SUBORKB},  /* SuporV20 */\r
-     {0x5e073a1b,-1,-1,SIFC_SUBORKB},  /* Supor English (Chinese) */\r
-    {0x8b265862,-1,-1,SIFC_SUBORKB},\r
-   {0x41401c6d,-1,-1,SIFC_SUBORKB},  /* SuporV40 */\r
-     {0x41ef9ac4,-1,-1,SIFC_SUBORKB},\r
-     {0x368c19a8,-1,-1,SIFC_SUBORKB},   /* LIKO Study Cartridge */\r
-   {0x543ab532,-1,-1,SIFC_SUBORKB},   /* LIKO Color Lines */\r
-#endif\r
-        {0,-1,-1,-1}\r
+               {0x3a1694f9,SI_GAMEPAD,SI_GAMEPAD,SIFC_4PLAYER},       // Nekketsu Kakutou Densetsu\r
+\r
+               {0xc3c0811d,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS},  // The two "Oeka Kids" games\r
+               {0x9d048ea4,SI_GAMEPAD,SI_GAMEPAD,SIFC_OEKAKIDS},  //\r
+\r
+               {0xaf4010ea,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET},  // World Class Track Meet\r
+               {0xd74b2719,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET},  // Super Team Games\r
+               {0x61d86167,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET},  // Street Cop\r
+               {0x6435c095,SI_GAMEPAD,SI_POWERPADB,SIFC_UNSET},  // Short Order/Eggsplode\r
+\r
+\r
+               {0x47232739,SI_GAMEPAD,SI_GAMEPAD,SIFC_TOPRIDER},  // Top Rider\r
+\r
+               {0x48ca0ee1,SI_GAMEPAD,SI_GAMEPAD,SIFC_BWORLD},    // Barcode World\r
+               {0x9f8f200a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Super Mogura Tataki!! - Pokkun Moguraa\r
+               {0x9044550e,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Rairai Kyonshizu\r
+               {0x2f128512,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Jogging Race\r
+               {0x60ad090a,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERA}, // Athletic World\r
+\r
+               {0x8a12a7d9,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Totsugeki Fuuun Takeshi Jou\r
+               {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Running Stadium\r
+               {0x370ceb65,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Meiro Dai Sakusen\r
+               // Bad dump? {0x69ffb014,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Fuun Takeshi Jou 2\r
+               {0x6cca1c1f,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB}, // Dai Undoukai\r
+               {0x29de87af,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB},  // Aerobics Studio\r
+               {0xbba58be5,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB},  // Family Trainer: Manhattan Police\r
+               {0xea90f3e2,SI_GAMEPAD,SI_GAMEPAD,SIFC_FTRAINERB},  // Family Trainer:  Running Stadium\r
+\r
+               {0xd9f45be9,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING},  // Gimme a Break ...\r
+               {0x1545bd13,SI_GAMEPAD,SI_GAMEPAD,SIFC_QUIZKING},  // Gimme a Break ... 2\r
+\r
+               {0x7b44fb2a,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG},  // Ide Yousuke Meijin no Jissen Mahjong 2\r
+               {0x9fae4d46,SI_GAMEPAD,SI_GAMEPAD,SIFC_MAHJONG},  // Ide Yousuke Meijin no Jissen Mahjong\r
+\r
+               {0x980be936,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, // Hyper Olympic\r
+               {0x21f85681,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, // Hyper Olympic (Gentei Ban)\r
+               {0x915a53a7,SI_GAMEPAD,SI_GAMEPAD,SIFC_HYPERSHOT}, // Hyper Sports\r
+               {0xad9c63e2,SI_GAMEPAD,SI_UNSET,SIFC_SHADOW},  // Space Shadow\r
+\r
+               {0x24598791,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Duck Hunt\r
+               {0xff24d794,SI_UNSET,SI_ZAPPER,SIFC_NONE},   // Hogan's Alley\r
+               {0xbeb8ab01,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Gumshoe\r
+               {0xde8fd935,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // To the Earth\r
+               {0xedc3662b,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Operation Wolf\r
+               {0x2a6559a1,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Operation Wolf (J)\r
+           {0x4e959173,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Gotcha! - The Sport!\r
+\r
+               {0x23d17f5e,SI_GAMEPAD,SI_ZAPPER,SIFC_NONE},  // The Lone Ranger\r
+               {0xb8b9aca3,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Wild Gunman\r
+               {0x5112dc21,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Wild Gunman\r
+               {0x4318a2f8,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Barker Bill's Trick Shooting\r
+               {0x5ee6008e,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Mechanized Attack\r
+               {0x3e58a87e,SI_UNSET,SI_ZAPPER,SIFC_NONE},  // Freedom Force\r
+               {0xe9a7fe9e,SI_UNSET,SI_MOUSE,SIFC_NONE}, // Educational Computer 2000  //mbg merge 7/17/06 added -- appears to be from newer MM build\r
+               {0x851eb9be,SI_GAMEPAD,SI_ZAPPER,SIFC_NONE},  // Shooting Range\r
+               {0x74bea652,SI_GAMEPAD,SI_ZAPPER,SIFC_NONE},  // Supergun 3-in-1\r
+               {0x32fb0583,SI_UNSET,SI_ARKANOID,SIFC_NONE}, // Arkanoid(NES)\r
+               {0xd89e5a67,SI_UNSET,SI_UNSET,SIFC_ARKANOID}, // Arkanoid (J)\r
+               {0x0f141525,SI_UNSET,SI_UNSET,SIFC_ARKANOID}, // Arkanoid 2(J)\r
+\r
+               {0x912989dc,SI_UNSET,SI_UNSET,SIFC_FKB},  // Playbox BASIC\r
+               {0xf7606810,SI_UNSET,SI_UNSET,SIFC_FKB},  // Family BASIC 2.0A\r
+               {0x895037bc,SI_UNSET,SI_UNSET,SIFC_FKB},  // Family BASIC 2.1a\r
+               {0xb2530afc,SI_UNSET,SI_UNSET,SIFC_FKB},  // Family BASIC 3.0\r
+               {0x82f1fb96,SI_UNSET,SI_UNSET,SIFC_SUBORKB},  // Subor 1.0 Russian\r
+               {0xabb2f974,SI_UNSET,SI_UNSET,SIFC_SUBORKB},  // Study and Game 32-in-1\r
+               {0xd5d6eac4,SI_UNSET,SI_UNSET,SIFC_SUBORKB},  // Edu (As)\r
+               {0x589b6b0d,SI_UNSET,SI_UNSET,SIFC_SUBORKB},  // SuporV20\r
+               {0x5e073a1b,SI_UNSET,SI_UNSET,SIFC_SUBORKB},  // Supor English (Chinese)\r
+               {0x8b265862,SI_UNSET,SI_UNSET,SIFC_SUBORKB},\r
+               {0x41401c6d,SI_UNSET,SI_UNSET,SIFC_SUBORKB},  // SuporV40\r
+               {0x41ef9ac4,SI_UNSET,SI_UNSET,SIFC_SUBORKB},\r
+               {0x368c19a8,SI_UNSET,SI_UNSET,SIFC_SUBORKB},   // LIKO Study Cartridge\r
+               {0x543ab532,SI_UNSET,SI_UNSET,SIFC_SUBORKB},   // LIKO Color Lines\r
+               {0,SI_UNSET,SI_UNSET,SIFC_UNSET}\r
        };\r
        };\r
- int x=0;\r
-\r
- while(moo[x].input1>=0 || moo[x].input2>=0 || moo[x].inputfc>=0)\r
- {\r
-  if(moo[x].crc32==iNESGameCRC32)\r
-  {\r
-   FCEUGameInfo.input[0]=moo[x].input1;\r
-   FCEUGameInfo.input[1]=moo[x].input2;\r
-   FCEUGameInfo.inputfc=moo[x].inputfc;\r
-   break;\r
-  }\r
-  x++;\r
- }\r
      int x=0;\r
+\r
      while(moo[x].input1>=0 || moo[x].input2>=0 || moo[x].inputfc>=0)\r
      {\r
+               if(moo[x].crc32==iNESGameCRC32)\r
+               {\r
+                       GameInfo->input[0]=moo[x].input1;\r
+                       GameInfo->input[1]=moo[x].input2;\r
+                       GameInfo->inputfc=moo[x].inputfc;\r
+                       break;\r
+               }\r
+               x++;\r
      }\r
 }\r
 \r
 #define INESB_INCOMPLETE  1\r
 }\r
 \r
 #define INESB_INCOMPLETE  1\r
@@ -259,24 +272,24 @@ struct BADINF {
 \r
 static struct BADINF BadROMImages[]=\r
 {\r
 \r
 static struct BADINF BadROMImages[]=\r
 {\r
- #include "ines-bad.h"\r
+#include "ines-bad.h"\r
 };\r
 \r
 void CheckBad(uint64 md5partial)\r
 {\r
 };\r
 \r
 void CheckBad(uint64 md5partial)\r
 {\r
- int x;\r
-\r
- x=0;\r
- //printf("0x%llx\n",md5partial);\r
- while(BadROMImages[x].name)\r
- {\r
-  if(BadROMImages[x].md5partial == md5partial)\r
-  {\r
-   FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly on FCE Ultra.", BadROMImages[x].name);\r
-   return;\r
-  }\r
-  x++;\r
- }\r
      int x;\r
+\r
      x=0;\r
      //printf("0x%llx\n",md5partial);\r
      while(BadROMImages[x].name)\r
      {\r
+               if(BadROMImages[x].md5partial == md5partial)\r
+               {\r
+                       FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly in FCEUX.", BadROMImages[x].name);\r
+                       return;\r
+               }\r
+               x++;\r
      }\r
 \r
 }\r
 \r
 \r
 }\r
 \r
@@ -285,175 +298,233 @@ struct CHINF {
        uint32 crc32;\r
        int32 mapper;\r
        int32 mirror;\r
        uint32 crc32;\r
        int32 mapper;\r
        int32 mirror;\r
+       const char* params;\r
 };\r
 \r
 };\r
 \r
+void MapperInit()\r
+{\r
+       if(NewiNES_Init(MapperNo))\r
+       {\r
+\r
+       }\r
+       else\r
+       {\r
+               iNESCart.Power=iNESPower;\r
+               if(head.ROM_type&2)\r
+               {\r
+                       iNESCart.SaveGame[0]=WRAM;\r
+                       iNESCart.SaveGameLen[0]=8192;\r
+               }\r
+       }\r
+}\r
+\r
+#if 0\r
+static const TMasterRomInfo sMasterRomInfo[] = {\r
+       { 0x62b51b108a01d2beLL, "bonus=0" }, //4-in-1 (FK23C8021)[p1][!].nes\r
+       { 0x8bb48490d8d22711LL, "bonus=0" }, //4-in-1 (FK23C8033)[p1][!].nes\r
+       { 0xc75888d7b48cd378LL, "bonus=0" }, //4-in-1 (FK23C8043)[p1][!].nes\r
+       { 0xf81a376fa54fdd69LL, "bonus=0" }, //4-in-1 (FK23Cxxxx, S-0210A PCB)[p1][!].nes\r
+       { 0xa37eb9163e001a46LL, "bonus=0" }, //4-in-1 (FK23C8026) [p1][!].nes\r
+       { 0xde5ce25860233f7eLL, "bonus=0" }, //4-in-1 (FK23C8045) [p1][!].nes\r
+       { 0x5b3aa4cdc484a088LL, "bonus=0" }, //4-in-1 (FK23C8056) [p1][!].nes\r
+       { 0x9342bf9bae1c798aLL, "bonus=0" }, //4-in-1 (FK23C8079) [p1][!].nes\r
+       { 0x164eea6097a1e313LL, "busc=1" }, //Cybernoid - The Fighting Machine (U)[!].nes -- needs bus conflict emulation\r
+};\r
+const TMasterRomInfo* MasterRomInfo;\r
+TMasterRomInfoParams MasterRomInfoParams;\r
+#endif\r
+\r
 static void CheckHInfo(void)\r
 {\r
 static void CheckHInfo(void)\r
 {\r
- /* ROM images that have the battery-backed bit set in the header that really\r
-    don't have battery-backed RAM is not that big of a problem, so I'll\r
-    treat this differently by only listing games that should have battery-backed RAM.\r
      /* ROM images that have the battery-backed bit set in the header that really\r
+       don't have battery-backed RAM is not that big of a problem, so I'll\r
+       treat this differently by only listing games that should have battery-backed RAM.\r
 \r
 \r
-    Lower 64 bits of the MD5 hash.\r
- */\r
+       Lower 64 bits of the MD5 hash.\r
      */\r
 \r
 \r
- static uint64 savie[]=\r
      static uint64 savie[]=\r
        {\r
        {\r
-   0x498c10dc463cfe95LL,  /* Battle Fleet */\r
-   0x6917ffcaca2d8466LL,  /* Famista '90 */\r
+               0x498c10dc463cfe95LL,  /* Battle Fleet */\r
+               0x6917ffcaca2d8466LL,  /* Famista '90 */\r
 \r
 \r
-         0xd63dcc68c2b20adcLL,    /* Final Fantasy J */\r
-         0x012df596e2b31174LL,    /* Final Fantasy 1+2 */\r
-         0xf6b359a720549ecdLL,    /* Final Fantasy 2 */\r
-         0x5a30da1d9b4af35dLL,    /* Final Fantasy 3 */\r
+               0xd63dcc68c2b20adcLL,    /* Final Fantasy J */\r
+               0x012df596e2b31174LL,    /* Final Fantasy 1+2 */\r
+               0xf6b359a720549ecdLL,    /* Final Fantasy 2 */\r
+               0x5a30da1d9b4af35dLL,    /* Final Fantasy 3 */\r
 \r
 \r
-   0x2ee3417ba8b69706LL,  /* Hydlide 3*/\r
+               0x2ee3417ba8b69706LL,  /* Hydlide 3*/\r
 \r
 \r
-   0xebbce5a54cf3ecc0LL,  /* Justbreed */\r
+               0xebbce5a54cf3ecc0LL,  /* Justbreed */\r
 \r
 \r
-   0x6a858da551ba239eLL,  /* Kaijuu Monogatari */\r
-   0xa40666740b7d22feLL,  /* Mindseeker */\r
+               0x6a858da551ba239eLL,  /* Kaijuu Monogatari */\r
+               0xa40666740b7d22feLL,  /* Mindseeker */\r
 \r
 \r
-         0x77b811b2760104b9LL,    /* Mouryou Senki Madara */\r
+               0x77b811b2760104b9LL,    /* Mouryou Senki Madara */\r
 \r
 \r
-   0x11b69122efe86e8cLL,  /* RPG Jinsei Game */\r
+               0x11b69122efe86e8cLL,  /* RPG Jinsei Game */\r
 \r
 \r
-   0xa70b495314f4d075LL,  /* Ys 3 */\r
+               0xa70b495314f4d075LL,  /* Ys 3 */\r
 \r
 \r
 \r
 \r
-   0xc04361e499748382LL,  /* AD&D Heroes of the Lance */\r
-   0xb72ee2337ced5792LL,  /* AD&D Hillsfar */\r
-   0x2b7103b7a27bd72fLL,  /* AD&D Pool of Radiance */\r
+               0xc04361e499748382LL,  /* AD&D Heroes of the Lance */\r
+               0xb72ee2337ced5792LL,  /* AD&D Hillsfar */\r
+               0x2b7103b7a27bd72fLL,  /* AD&D Pool of Radiance */\r
 \r
 \r
-        0x854d7947a3177f57LL,    /* Crystalis */\r
+               0x854d7947a3177f57LL,    /* Crystalis */\r
 \r
 \r
-   0xb0bcc02c843c1b79LL,  /* DW */\r
-   0x4a1f5336b86851b6LL,  /* DW */\r
+               0xb0bcc02c843c1b79LL,  /* DW */\r
+               0x4a1f5336b86851b6LL,  /* DW */\r
 \r
 \r
-   0x2dcf3a98c7937c22LL,  /* DW 2 */\r
-   0x733026b6b72f2470LL,  /* Dw 3 */\r
-   0x98e55e09dfcc7533LL,  /* DW 4*/\r
-   0x8da46db592a1fcf4LL,  /* Faria */\r
-   0x91a6846d3202e3d6LL,  /* Final Fantasy */\r
-   0xedba17a2c4608d20LL,  /* ""    */\r
+               0x2dcf3a98c7937c22LL,  /* DW 2 */\r
+               0x733026b6b72f2470LL,  /* Dw 3 */\r
+               0x98e55e09dfcc7533LL,  /* DW 4*/\r
+               0x8da46db592a1fcf4LL,  /* Faria */\r
+               0x91a6846d3202e3d6LL,  /* Final Fantasy */\r
+               0xedba17a2c4608d20LL,  /* ""    */\r
 \r
 \r
-         0x94b9484862a26cbaLL,    /* Legend of Zelda */\r
-         0x04a31647de80fdabLL,    /*      ""      */\r
+               0x94b9484862a26cbaLL,    /* Legend of Zelda */\r
+               0x04a31647de80fdabLL,    /*      ""      */\r
 \r
 \r
-         0x9aa1dc16c05e7de5LL,    /* Startropics */\r
-         0x1b084107d0878bd0LL,    /* Startropics 2*/\r
+               0x9aa1dc16c05e7de5LL,    /* Startropics */\r
+               0x1b084107d0878bd0LL,    /* Startropics 2*/\r
 \r
 \r
-         0x836c0ff4f3e06e45LL,    /* Zelda 2 */\r
+               0x836c0ff4f3e06e45LL,    /* Zelda 2 */\r
 \r
 \r
-   0      /* Abandon all hope if the game has 0 in the lower 64-bits of its MD5 hash */\r
+               0x82000965f04a71bbLL,    /* Mirai Shinwa Jarvas */\r
+\r
+               0      /* Abandon all hope if the game has 0 in the lower 64-bits of its MD5 hash */\r
        };\r
 \r
        };\r
 \r
- static struct CHINF moo[]=\r
      static struct CHINF moo[]=\r
        {\r
        {\r
-  #include "ines-correct.h"\r
+#include "ines-correct.h"\r
        };\r
        };\r
- int tofix=0;\r
- int x;\r
- uint64 partialmd5=0;\r
-\r
- for(x=0;x<8;x++)\r
- {\r
-  partialmd5 |= (uint64)iNESCart.MD5[15-x] << (x*8);\r
-  //printf("%16llx\n",partialmd5);\r
- }\r
- CheckBad(partialmd5);\r
-\r
- x=0;\r
-\r
- do\r
- {\r
-  if(moo[x].crc32==iNESGameCRC32)\r
-  {\r
-   if(moo[x].mapper>=0)\r
-   {\r
-    if(moo[x].mapper&0x800 && VROM_size)\r
-    {\r
-     VROM_size=0;\r
-     free(VROM);\r
-     VROM=0;\r
-     tofix|=8;\r
-    }\r
-    if(MapperNo!=(moo[x].mapper&0xFF))\r
-    {\r
-     tofix|=1;\r
-     MapperNo=moo[x].mapper&0xFF;\r
-    }\r
-   }\r
-   if(moo[x].mirror>=0)\r
-   {\r
-    if(moo[x].mirror==8)\r
-    {\r
-     if(Mirroring==2)  /* Anything but hard-wired(four screen). */\r
-     {\r
-      tofix|=2;\r
-      Mirroring=0;\r
-     }\r
-    }\r
-    else if(Mirroring!=moo[x].mirror)\r
-    {\r
-     if(Mirroring!=(moo[x].mirror&~4))\r
-      if((moo[x].mirror&~4)<=2)  /* Don't complain if one-screen mirroring\r
-                                  needs to be set(the iNES header can't\r
-                                  hold this information).\r
-                               */\r
-       tofix|=2;\r
-     Mirroring=moo[x].mirror;\r
-    }\r
-   }\r
-   break;\r
-  }\r
-  x++;\r
- } while(moo[x].mirror>=0 || moo[x].mapper>=0);\r
-\r
- x=0;\r
- while(savie[x] != 0)\r
- {\r
-  if(savie[x] == partialmd5)\r
-  {\r
-   if(!(head.ROM_type&2))\r
-   {\r
-    tofix|=4;\r
-    head.ROM_type|=2;\r
-   }\r
-  }\r
-  x++;\r
- }\r
-\r
- /* Games that use these iNES mappers tend to have the four-screen bit set\r
-    when it should not be.\r
- */\r
- if((MapperNo==118 || MapperNo==24 || MapperNo==26) && (Mirroring==2))\r
- {\r
-  Mirroring=0;\r
-  tofix|=2;\r
- }\r
-\r
- /* Four-screen mirroring implicitly set. */\r
- if(MapperNo==99)\r
-  Mirroring=2;\r
-\r
- if(tofix)\r
- {\r
-  char gigastr[768];\r
-  strcpy(gigastr,"The iNES header contains incorrect information.  For now, the information will be corrected in RAM.  ");\r
-  if(tofix&1)\r
-   sprintf(gigastr+strlen(gigastr),"The mapper number should be set to %d.  ",MapperNo);\r
-  if(tofix&2)\r
-  {\r
-   char *mstr[3]={"Horizontal","Vertical","Four-screen"};\r
-   sprintf(gigastr+strlen(gigastr),"Mirroring should be set to \"%s\".  ",mstr[Mirroring&3]);\r
-  }\r
-  if(tofix&4)\r
-   strcat(gigastr,"The battery-backed bit should be set.  ");\r
-  if(tofix&8)\r
-   strcat(gigastr,"This game should not have any CHR ROM.  ");\r
-  strcat(gigastr,"\n");\r
-  FCEU_printf("%s",gigastr);\r
- }\r
+       int tofix=0;\r
+       int x;\r
+       uint64 partialmd5=0;\r
+\r
+       for(x=0;x<8;x++)\r
+       {\r
+               partialmd5 |= (uint64)iNESCart.MD5[15-x] << (x*8);\r
+               //printf("%16llx\n",partialmd5);\r
+       }\r
+       CheckBad(partialmd5);\r
+\r
+#if 0\r
+       MasterRomInfo = NULL;\r
+       MasterRomInfoParams = TMasterRomInfoParams();\r
+       for(int i=0;i<ARRAY_SIZE(sMasterRomInfo);i++)\r
+       {\r
+               const TMasterRomInfo& info = sMasterRomInfo[i];\r
+               if(info.md5lower != partialmd5)\r
+                       continue;\r
+               \r
+               MasterRomInfo = &info;\r
+               if(!info.params) break;\r
+               \r
+               std::vector<std::string> toks = tokenize_str(info.params,",");\r
+               for(int j=0;j<(int)toks.size();j++)\r
+               {\r
+                       std::vector<std::string> parts = tokenize_str(toks[j],"=");\r
+                       MasterRomInfoParams[parts[0]] = parts[1];\r
+               }\r
+               break;\r
+       }\r
+#endif\r
+\r
+       x=0;\r
+\r
+       do\r
+       {\r
+               if(moo[x].crc32==iNESGameCRC32)\r
+               {\r
+                       if(moo[x].mapper>=0)\r
+                       {\r
+                               if(moo[x].mapper&0x800 && VROM_size)\r
+                               {\r
+                                       VROM_size=0;\r
+                                       free(VROM);\r
+                                       VROM = NULL;\r
+                                       tofix|=8;\r
+                               }\r
+                               if(MapperNo!=(moo[x].mapper&0xFF))\r
+                               {\r
+                                       tofix|=1;\r
+                                       MapperNo=moo[x].mapper&0xFF;\r
+                               }\r
+                       }\r
+                       if(moo[x].mirror>=0)\r
+                       {\r
+                               if(moo[x].mirror==8)\r
+                               {\r
+                                       if(Mirroring==2)  /* Anything but hard-wired(four screen). */\r
+                                       {\r
+                                               tofix|=2;\r
+                                               Mirroring=0;\r
+                                       }\r
+                               }\r
+                               else if(Mirroring!=moo[x].mirror)\r
+                               {\r
+                                       if(Mirroring!=(moo[x].mirror&~4))\r
+                                               if((moo[x].mirror&~4)<=2)  /* Don't complain if one-screen mirroring\r
+                                                                                                  needs to be set(the iNES header can't\r
+                                                                                                  hold this information).\r
+                                                                                                  */\r
+                                                                                                  tofix|=2;\r
+                                       Mirroring=moo[x].mirror;\r
+                               }\r
+                       }\r
+                       break;\r
+               }\r
+               x++;\r
+       } while(moo[x].mirror>=0 || moo[x].mapper>=0);\r
+\r
+       x=0;\r
+       while(savie[x] != 0)\r
+       {\r
+               if(savie[x] == partialmd5)\r
+               {\r
+                       if(!(head.ROM_type&2))\r
+                       {\r
+                               tofix|=4;\r
+                               head.ROM_type|=2;\r
+                       }\r
+               }\r
+               x++;\r
+       }\r
+\r
+       /* Games that use these iNES mappers tend to have the four-screen bit set\r
+       when it should not be.\r
+       */\r
+       if((MapperNo==118 || MapperNo==24 || MapperNo==26) && (Mirroring==2))\r
+       {\r
+               Mirroring=0;\r
+               tofix|=2;\r
+       }\r
+\r
+       /* Four-screen mirroring implicitly set. */\r
+       if(MapperNo==99)\r
+               Mirroring=2;\r
+\r
+       if(tofix)\r
+       {\r
+               char gigastr[768];\r
+               strcpy(gigastr,"The iNES header contains incorrect information.  For now, the information will be corrected in RAM.  ");\r
+               if(tofix&1)\r
+                       sprintf(gigastr+strlen(gigastr),"The mapper number should be set to %d.  ",MapperNo);\r
+               if(tofix&2)\r
+               {\r
+                       char *mstr[3]={"Horizontal","Vertical","Four-screen"};\r
+                       sprintf(gigastr+strlen(gigastr),"Mirroring should be set to \"%s\".  ",mstr[Mirroring&3]);\r
+               }\r
+               if(tofix&4)\r
+                       strcat(gigastr,"The battery-backed bit should be set.  ");\r
+               if(tofix&8)\r
+                       strcat(gigastr,"This game should not have any CHR ROM.  ");\r
+               strcat(gigastr,"\n");\r
+               FCEU_printf("%s",gigastr);\r
+       }\r
 }\r
 \r
 typedef struct {\r
 }\r
 \r
 typedef struct {\r
@@ -461,282 +532,562 @@ typedef struct {
        void (*init)(CartInfo *);\r
 } NewMI;\r
 \r
        void (*init)(CartInfo *);\r
 } NewMI;\r
 \r
-int iNESLoad(const char *name, int fp)\r
+//this is for games that is not the a power of 2\r
+//mapper based for now...\r
+//not really accurate but this works since games\r
+//that are not in the power of 2 tends to come\r
+//in obscure mappers themselves which supports such\r
+//size\r
+static int not_power2[] =\r
+{\r
+    228\r
+};\r
+typedef struct {\r
+       char* name;\r
+       int number;\r
+       void (*init)(CartInfo *);\r
+} BMAPPINGLocal;\r
+\r
+static BMAPPINGLocal bmap[] = {\r
+       {"NROM",                                0,   NROM_Init},\r
+       {"MMC1",                        1,       Mapper1_Init},\r
+       {"UNROM",                               2,   UNROM_Init},\r
+       {"CNROM",                               3,   CNROM_Init},\r
+       {"MMC3",                                4,   Mapper4_Init},\r
+       {"MMC5",                                5,   Mapper5_Init},\r
+       {"ANROM",                               7,   ANROM_Init},\r
+       {"Color Dreams",                11,  Mapper11_Init},\r
+       {"",                                    12,  Mapper12_Init},\r
+       {"CPROM",                               13,  CPROM_Init},\r
+    {"100-in1",                                15,  Mapper15_Init},\r
+    {"Bandai",                         16,  Mapper16_Init},\r
+       {"Namcot 106",                  19,  Mapper19_Init},\r
+    {"Konami VRC2 type B",     23,  Mapper23_Init},\r
+    {"Wario Land 2",           35,  UNLSC127_Init}, // Wario Land 2\r
+    {"TXC Policeman",          36,  Mapper36_Init}, // TXC Policeman\r
+       {"",                                    37,  Mapper37_Init},\r
+    {"Bit Corp. Crime Busters",        38,  Mapper38_Init}, // Bit Corp. Crime Busters\r
+       {"",                                    43,  Mapper43_Init},\r
+       {"",                                    44,  Mapper44_Init},\r
+       {"",                                    45,  Mapper45_Init},\r
+       {"",                                    47,  Mapper47_Init},\r
+       {"",                                    49,  Mapper49_Init},\r
+       {"",                                    52,  Mapper52_Init},\r
+       {"",                                    57,  Mapper57_Init},\r
+       {"",                                    58,  BMCGK192_Init},\r
+       {"",                                    60,  BMCD1038_Init},\r
+       {"MHROM",                               66,  MHROM_Init},\r
+    {"Sunsoft Mapper #4",      68,  Mapper68_Init},\r
+       {"",                                    70,  Mapper70_Init},\r
+       {"",                                    74,  Mapper74_Init},\r
+       {"Irem 74HC161/32",             78,  Mapper78_Init},\r
+       {"",                                    87,  Mapper87_Init},\r
+       {"",                                    88,  Mapper88_Init},\r
+       {"",                                    90,  Mapper90_Init},\r
+       {"Sunsoft UNROM",               93,  SUNSOFT_UNROM_Init},\r
+       {"",                                    94,  Mapper94_Init},\r
+       {"",                                    95,  Mapper95_Init},\r
+    {"",                                       101, Mapper101_Init},\r
+    {"",                                       103, Mapper103_Init},\r
+       {"",                                    105, Mapper105_Init},\r
+    {"",                                       106, Mapper106_Init},\r
+       {"",                                    107, Mapper107_Init},\r
+    {"",                                       108, Mapper108_Init},\r
+       {"",                                    112, Mapper112_Init},\r
+       {"",                                    113, Mapper113_Init},\r
+       {"",                                    114, Mapper114_Init},\r
+       {"",                                    115, Mapper115_Init},\r
+       {"",                                    116, Mapper116_Init},\r
+//    {116, UNLSL1632_Init},\r
+       {"",                                    117, Mapper117_Init},\r
+       {"TSKROM",                              118, TKSROM_Init},\r
+       {"",                                    119, Mapper119_Init},\r
+    {"",                                       120, Mapper120_Init},\r
+    {"",                                       121, Mapper121_Init},\r
+    {"UNLH2288",                       123, UNLH2288_Init},\r
+       {"UNL22211",                    132, UNL22211_Init},\r
+       {"SA72008",                             133, SA72008_Init},\r
+    {"",                                       134, Mapper134_Init},\r
+    {"TCU02",                          136, TCU02_Init},\r
+       {"S8259D",                              137, S8259D_Init},\r
+       {"S8259B",                              138, S8259B_Init},\r
+       {"S8259C",                              139, S8259C_Init},\r
+       {"",                                    140, Mapper140_Init},\r
+       {"S8259A",                              141, S8259A_Init},\r
+    {"UNLKS7032",                      142, UNLKS7032_Init},\r
+       {"TCA01",                               143, TCA01_Init},\r
+       {"",                                    144, Mapper144_Init},\r
+       {"SA72007",                             145, SA72007_Init},\r
+       {"SA0161M",                             146, SA0161M_Init},\r
+       {"TCU01",                               147, TCU01_Init},\r
+       {"SA0037",                              148, SA0037_Init},\r
+       {"SA0036",                              149, SA0036_Init},\r
+       {"S74LS374N",                   150, S74LS374N_Init},\r
+       {"",                                    152, Mapper152_Init},\r
+    {"",                                       153, Mapper153_Init},\r
+       {"",                                    154, Mapper154_Init},\r
+       {"",                                    155, Mapper155_Init},\r
+       {"",                                    156, Mapper156_Init},\r
+  {"",                                 159, Mapper159_Init},\r
+    {"SA009",                          160, SA009_Init},\r
+       {"",                                    163, Mapper163_Init},\r
+       {"",                                    164, Mapper164_Init},\r
+       {"",                                    165, Mapper165_Init},\r
+//    {169, Mapper169_Init},\r
+    {"",                                       171, Mapper171_Init},\r
+    {"",                                       172, Mapper172_Init},\r
+    {"",                                       173, Mapper173_Init},\r
+    {"",                                       175, Mapper175_Init},\r
+    {"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.\r
+               //{"BMCFK23C",                  176, Mapper176_Init}, \r
+    {"",                                       177, Mapper177_Init},\r
+    {"",                                       178, Mapper178_Init},\r
+       {"",                                    180, Mapper180_Init},\r
+       {"",                                    181, Mapper181_Init},\r
+//     {"",                                    182, Mapper182_Init},   // identical to 114\r
+       {"",                                    183, Mapper183_Init},\r
+       {"",                                    184, Mapper184_Init},\r
+       {"",                                    185, Mapper185_Init},\r
+       {"",                                    186, Mapper186_Init},\r
+       {"",                                    187, Mapper187_Init},\r
+       {"",                                    188, Mapper188_Init},\r
+       {"",                                    189, Mapper189_Init},\r
+       {"",                                    191, Mapper191_Init},\r
+       {"",                                    192, Mapper192_Init},\r
+       {"",                                    194, Mapper194_Init},\r
+       {"",                                    195, Mapper195_Init},\r
+    {"",                                       196, Mapper196_Init},\r
+    {"",                                       197, Mapper197_Init},\r
+       {"",                                    198, Mapper198_Init},\r
+       {"",                                    199, Mapper199_Init},\r
+       {"",                                    200, Mapper200_Init},\r
+       {"",                                    205, Mapper205_Init},\r
+       {"DEIROM",                              206, DEIROM_Init},\r
+       {"",                                    208, Mapper208_Init},\r
+       {"",                                    209, Mapper209_Init},\r
+       {"",                                    210, Mapper210_Init},\r
+       {"",                                    211, Mapper211_Init},\r
+       {"",                                    215, UNL8237_Init},\r
+       {"",                                    216, Mapper216_Init},\r
+//     {"",                                    217, Mapper217_Init},\r
+       {"UNLA9746",                    219, UNLA9746_Init},\r
+       {"OneBus",                          220, UNLOneBus_Init},\r
+\r
+//    {220, BMCFK23C_Init},\r
+//    {220, UNL3DBlock_Init},\r
+//    {220, UNLTF1201_Init},\r
+//    {220, TCU02_Init},\r
+//    {220, UNLCN22M_Init},\r
+//    {220, BMCT2271_Init},\r
+//       {220, UNLDANCE_Init},\r
+\r
+    {"UNLN625092",                     221, UNLN625092_Init},\r
+       {"",                                    222, Mapper222_Init},\r
+       {"",                                    226, Mapper226_Init},\r
+       {"",                                    235, Mapper235_Init},\r
+    {"UNL6035052",                     238, UNL6035052_Init},\r
+       {"",                                    240, Mapper240_Init},\r
+       {"S74LS374NA",                  243, S74LS374NA_Init},\r
+       {"",                                    245, Mapper245_Init},\r
+       {"",                                    249, Mapper249_Init},\r
+       {"",                                    250, Mapper250_Init},\r
+    {"",                                       253, Mapper253_Init},\r
+       {"",                                    254, Mapper254_Init},\r
+       {"",  0,        0}\r
+};\r
+\r
+void cleanup(struct iNES_HEADER *this)\r
+{\r
+       if(!memcmp((char *)(this)+0x7,"DiskDude",8))\r
+       {\r
+               memset((char *)(this)+0x7,0,0x9);\r
+       }\r
+\r
+       if(!memcmp((char *)(this)+0x7,"demiforce",9))\r
+       {\r
+               memset((char *)(this)+0x7,0,0x9);\r
+       }\r
+\r
+       if(!memcmp((char *)(this)+0xA,"Ni03",4))\r
+       {\r
+               if(!memcmp((char *)(this)+0x7,"Dis",3))\r
+                       memset((char *)(this)+0x7,0,0x9);\r
+               else\r
+                       memset((char *)(this)+0xA,0,0x6);\r
+       }\r
+}\r
+\r
+int iNESLoad(const char *name, int fp, int OverwriteVidMode)\r
 {\r
 {\r
-        struct md5_context md5;\r
+       struct md5_context md5;\r
 \r
        if(FCEU_fread(&head,1,16,fp)!=16)\r
 \r
        if(FCEU_fread(&head,1,16,fp)!=16)\r
-        return 0;\r
+               return 0;\r
 \r
 \r
-        if(memcmp(&head,"NES\x1a",4))\r
-         return 0;\r
+       if(memcmp(&head,"NES\x1a",4))\r
+               return 0;\r
+\r
+       cleanup(&head);\r
 \r
        memset(&iNESCart,0,sizeof(iNESCart));\r
 \r
 \r
        memset(&iNESCart,0,sizeof(iNESCart));\r
 \r
-        if(!memcmp((char *)(&head)+0x7,"DiskDude",8))\r
-        {\r
-         memset((char *)(&head)+0x7,0,0x9);\r
-        }\r
+       MapperNo = (head.ROM_type>>4);\r
+       MapperNo|=(head.ROM_type2&0xF0);\r
+       Mirroring = (head.ROM_type&1);\r
 \r
 \r
-        if(!memcmp((char *)(&head)+0x7,"demiforce",9))\r
-        {\r
-         memset((char *)(&head)+0x7,0,0x9);\r
-        }\r
 \r
 \r
-        if(!memcmp((char *)(&head)+0xA,"Ni03",4))\r
-        {\r
-         if(!memcmp((char *)(&head)+0x7,"Dis",3))\r
-          memset((char *)(&head)+0x7,0,0x9);\r
-         else\r
-          memset((char *)(&head)+0xA,0,0x6);\r
-        }\r
-\r
-//  int ROM_size=0;\r
-        if(!head.ROM_size)\r
+       //  int ROM_size=0;\r
+       if(!head.ROM_size)\r
        {\r
        {\r
-//   FCEU_PrintError("No PRG ROM!");\r
-//   return(0);\r
-   ROM_size=256;\r
-         //head.ROM_size++;\r
+               //   FCEU_PrintError("No PRG ROM!");\r
+               //   return(0);\r
+               ROM_size=256;\r
+               //head.ROM_size++;\r
        }\r
        }\r
-  else\r
-   ROM_size=head.ROM_size;\r
+       else\r
+               ROM_size=uppow2(head.ROM_size);\r
+\r
+       //    ROM_size = head.ROM_size;\r
+       VROM_size = head.VROM_size;\r
 \r
 \r
-//    ROM_size = head.ROM_size;\r
-        VROM_size = head.VROM_size;\r
-       ROM_size=uppow2(ROM_size);\r
+    int round = 1;\r
+       int i;\r
+    for (i = 0; i != sizeof(not_power2)/sizeof(not_power2[0]); ++i)\r
+    {\r
+        //for games not to the power of 2, so we just read enough\r
+        //prg rom from it, but we have to keep ROM_size to the power of 2\r
+        //since PRGCartMapping wants ROM_size to be to the power of 2\r
+        //so instead if not to power of 2, we just use head.ROM_size when\r
+        //we use FCEU_read\r
+        if (not_power2[i] == MapperNo)\r
+        {\r
+            round = 0;\r
+            break;\r
+        }\r
+    }\r
 \r
 \r
-        if(VROM_size)\r
-        VROM_size=uppow2(VROM_size);\r
+    if(VROM_size)\r
+               VROM_size=uppow2(VROM_size);\r
 \r
 \r
-        MapperNo = (head.ROM_type>>4);\r
-        MapperNo|=(head.ROM_type2&0xF0);\r
-        Mirroring = (head.ROM_type&1);\r
 \r
        if(head.ROM_type&8) Mirroring=2;\r
 \r
 \r
        if(head.ROM_type&8) Mirroring=2;\r
 \r
-        if(!(ROM=(uint8 *)FCEU_malloc(ROM_size<<14)))\r
-        return 0;\r
-\r
-  if(VROM_size)\r
-         if(!(VROM=(uint8 *)FCEU_malloc(VROM_size<<13)))\r
-        {\r
-         free(ROM);\r
-         return 0;\r
-        }\r
+       if((ROM = (uint8 *)FCEU_malloc(ROM_size<<14)) == NULL) return 0;\r
 \r
 \r
-        memset(ROM,0xFF,ROM_size<<14);\r
-        if(VROM_size) memset(VROM,0xFF,VROM_size<<13);\r
-  if(head.ROM_type&4)   /* Trainer */\r
+       if(VROM_size)\r
+       {\r
+               if((VROM = (uint8 *)FCEU_malloc(VROM_size<<13)) == NULL)\r
+               {\r
+                       free(ROM);\r
+                       ROM = NULL;\r
+                       return 0;\r
+               }\r
+       }\r
+       memset(ROM,0xFF,ROM_size<<14);\r
+       if(VROM_size) memset(VROM,0xFF,VROM_size<<13);\r
+       if(head.ROM_type&4)   /* Trainer */\r
        {\r
        {\r
-        trainerpoo=(uint8 *)FCEU_gmalloc(512);\r
-        FCEU_fread(trainerpoo,512,1,fp);\r
+               trainerpoo=(uint8 *)FCEU_gmalloc(512);\r
+               FCEU_fread(trainerpoo,512,1,fp);\r
        }\r
 \r
        ResetCartMapping();\r
        ResetExState(0,0);\r
 \r
        SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0);\r
        }\r
 \r
        ResetCartMapping();\r
        ResetExState(0,0);\r
 \r
        SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0);\r
-        SetupCartPRGMapping(1,WRAM,8192,1);\r
+   // SetupCartPRGMapping(1,WRAM,8192,1); // ?\r
 \r
 \r
-        FCEU_fread(ROM,0x4000,head.ROM_size,fp);\r
+    FCEU_fread(ROM,0x4000,(round) ? ROM_size : head.ROM_size,fp);\r
 \r
        if(VROM_size)\r
 \r
        if(VROM_size)\r
-        FCEU_fread(VROM,0x2000,head.VROM_size,fp);\r
+               FCEU_fread(VROM,0x2000,head.VROM_size,fp);\r
 \r
 \r
-        md5_starts(&md5);\r
-        md5_update(&md5,ROM,ROM_size<<14);\r
+       md5_starts(&md5);\r
+       md5_update(&md5,ROM,ROM_size<<14);\r
 \r
        iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14);\r
 \r
        if(VROM_size)\r
        {\r
 \r
        iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14);\r
 \r
        if(VROM_size)\r
        {\r
-        iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13);\r
-         md5_update(&md5,VROM,VROM_size<<13);\r
+               iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13);\r
+               md5_update(&md5,VROM,VROM_size<<13);\r
        }\r
        md5_finish(&md5,iNESCart.MD5);\r
        }\r
        md5_finish(&md5,iNESCart.MD5);\r
-       memcpy(FCEUGameInfo.MD5,iNESCart.MD5,sizeof(iNESCart.MD5));\r
+       memcpy(&GameInfo->MD5,&iNESCart.MD5,sizeof(iNESCart.MD5));\r
 \r
        iNESCart.CRC32=iNESGameCRC32;\r
 \r
 \r
        iNESCart.CRC32=iNESGameCRC32;\r
 \r
-        FCEU_printf(" PRG ROM:  %3d x 16KiB\n CHR ROM:  %3d x  8KiB\n ROM CRC32:  0x%08x\n",\r
-               head.ROM_size,head.VROM_size,iNESGameCRC32);\r
+       FCEU_printf(" PRG ROM:  %3d x 16KiB\n CHR ROM:  %3d x  8KiB\n ROM CRC32:  0x%08lx\n",\r
+                (round) ? ROM_size : head.ROM_size, head.VROM_size,\r
+                               (unsigned long)iNESGameCRC32);\r
 \r
 \r
-        {\r
-         int x;\r
-         FCEU_printf(" ROM MD5:  0x");\r
-         for(x=0;x<16;x++)\r
-          FCEU_printf("%02x",iNESCart.MD5[x]);\r
-         FCEU_printf("\n");\r
-        }\r
-       FCEU_printf(" Mapper:  %d\n Mirroring: %s\n", MapperNo,Mirroring==2?"None(Four-screen)":Mirroring?"Vertical":"Horizontal");\r
-        if(head.ROM_type&2) FCEU_printf(" Battery-backed.\n");\r
-        if(head.ROM_type&4) FCEU_printf(" Trained.\n");\r
+       {\r
+               int x;\r
+               FCEU_printf(" ROM MD5:  0x");\r
+               for(x=0;x<16;x++)\r
+                       FCEU_printf("%02x",iNESCart.MD5[x]);\r
+               FCEU_printf("\n");\r
+       }\r
+\r
+       char* mappername = "Not Listed";\r
+       int mappertest;\r
+\r
+       for(mappertest=0;mappertest< (sizeof bmap / sizeof bmap[0]) - 1;mappertest++)\r
+       {\r
+               if (bmap[mappertest].number == MapperNo) {\r
+                       mappername = bmap[mappertest].name;\r
+                       break;\r
+               }\r
+       }\r
+\r
+       FCEU_printf(" Mapper #:  %d\n Mapper name: %s\n Mirroring: %s\n",\r
+               MapperNo, mappername, Mirroring==2?"None (Four-screen)":Mirroring?"Vertical":"Horizontal");\r
+\r
+       FCEU_printf(" Battery-backed: %s\n", (head.ROM_type&2)?"Yes":"No");\r
+       FCEU_printf(" Trained: %s\n", (head.ROM_type&4)?"Yes":"No");\r
+       // (head.ROM_type&8) = Mirroring: None(Four-screen)\r
 \r
        SetInput();\r
        CheckHInfo();\r
        {\r
 \r
        SetInput();\r
        CheckHInfo();\r
        {\r
-        int x;\r
-        uint64 partialmd5=0;\r
+               int x;\r
+               uint64 partialmd5=0;\r
 \r
 \r
-        for(x=0;x<8;x++)\r
-        {\r
-         partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8);\r
-        }\r
+               for(x=0;x<8;x++)\r
+               {\r
+                       partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8);\r
+               }\r
 \r
 \r
-        FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring);\r
+               FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring);\r
        }\r
        /* Must remain here because above functions might change value of\r
        }\r
        /* Must remain here because above functions might change value of\r
-          VROM_size and free(VROM).\r
+       VROM_size and free(VROM).\r
        */\r
        if(VROM_size)\r
        */\r
        if(VROM_size)\r
-         SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0);\r
+               SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0);\r
 \r
 \r
-        if(Mirroring==2)\r
-         SetupCartMirroring(4,1,ExtraNTARAM);\r
-        else if(Mirroring>=0x10)\r
-        SetupCartMirroring(2+(Mirroring&1),1,0);\r
+       if(Mirroring==2)\r
+               SetupCartMirroring(4,1,ExtraNTARAM);\r
+       else if(Mirroring>=0x10)\r
+               SetupCartMirroring(2+(Mirroring&1),1,0);\r
        else\r
        else\r
-         SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0);\r
+               SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0);\r
 \r
        iNESCart.battery=(head.ROM_type&2)?1:0;\r
        iNESCart.mirror=Mirroring;\r
 \r
        //if(MapperNo != 18) {\r
 \r
        iNESCart.battery=(head.ROM_type&2)?1:0;\r
        iNESCart.mirror=Mirroring;\r
 \r
        //if(MapperNo != 18) {\r
-  //  if(ROM) free(ROM);\r
-  //  if(VROM) free(VROM);\r
-  //  ROM=VROM=0;\r
-  //  return(0);\r
+       //  if(ROM) free(ROM);\r
+       //  if(VROM) free(VROM);\r
+       //  ROM=VROM=0;\r
+       //  return(0);\r
        // }\r
 \r
        // }\r
 \r
-       if(NewiNES_Init(MapperNo))\r
-       {\r
 \r
 \r
-       }\r
-       else\r
-       {\r
-        iNESCart.Power=iNESPower;\r
-         if(head.ROM_type&2)\r
-        {\r
-         iNESCart.SaveGame[0]=WRAM;\r
-         iNESCart.SaveGameLen[0]=8192;\r
-        }\r
-       }\r
+       GameInfo->mappernum = MapperNo;\r
+       MapperInit();\r
        FCEU_LoadGameSave(&iNESCart);\r
 \r
        FCEU_LoadGameSave(&iNESCart);\r
 \r
+       //strcpy(LoadedRomFName,name); //bbit edited: line added\r
+\r
+       // Extract Filename only. Should account for Windows/Unix this way.\r
+       if (strrchr(name, '/')) {\r
+       name = strrchr(name, '/') + 1;\r
+       } else if(strrchr(name, '\\')) {\r
+       name = strrchr(name, '\\') + 1;\r
+       }\r
+\r
        GameInterface=iNESGI;\r
        FCEU_printf("\n");\r
 \r
        // since apparently the iNES format doesn't store this information,\r
        // guess if the settings should be PAL or NTSC from the ROM name\r
        // TODO: MD5 check against a list of all known PAL games instead?\r
        GameInterface=iNESGI;\r
        FCEU_printf("\n");\r
 \r
        // since apparently the iNES format doesn't store this information,\r
        // guess if the settings should be PAL or NTSC from the ROM name\r
        // TODO: MD5 check against a list of all known PAL games instead?\r
-       if(strstr(name,"(E)") || strstr(name,"(e)")\r
-       || strstr(name,"(F)") || strstr(name,"(f)")\r
-       || strstr(name,"(G)") || strstr(name,"(g)")\r
-       || strstr(name,"(I)") || strstr(name,"(i)"))\r
-               FCEUI_SetVidSystem(1);\r
-       else\r
-               FCEUI_SetVidSystem(0);\r
+       if(OverwriteVidMode)\r
+       {\r
+               if(strstr(name,"(E)") || strstr(name,"(e)")\r
+                       || strstr(name,"(F)") || strstr(name,"(f)")\r
+                       || strstr(name,"(G)") || strstr(name,"(g)")\r
+                       || strstr(name,"(I)") || strstr(name,"(i)"))\r
+                       FCEUI_SetVidSystem(1);\r
+               else\r
+                       FCEUI_SetVidSystem(0);\r
+       }\r
+       return 1;\r
+}\r
+\r
+\r
+//bbit edited: the whole function below was added\r
+int iNesSave(){\r
+       FILE *fp;\r
+       char name[2048];\r
+\r
+       if(GameInfo->type != GIT_CART)return 0;\r
+       if(GameInterface!=iNESGI)return 0;\r
+\r
+       //strcpy(name,LoadedRomFName);\r
+       if (strcmp(name+strlen(name)-4,".nes") != 0) { //para edit\r
+               strcat(name,".nes");\r
+       }\r
+\r
+       fp = fopen(name,"wb");\r
+\r
+       if(fwrite(&head,1,16,fp)!=16)\r
+       {\r
+               fclose(fp);\r
+               return 0;\r
+       }\r
+\r
+       if(head.ROM_type&4)     /* Trainer */\r
+       {\r
+               fwrite(trainerpoo,512,1,fp);\r
+       }\r
+\r
+       fwrite(ROM,0x4000,ROM_size,fp);\r
+\r
+       if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp);\r
+       fclose(fp);\r
+\r
+       return 1;\r
+}\r
+\r
+int iNesSaveAs(char* name)\r
+{\r
+       //adelikat: TODO: iNesSave() and this have pretty much the same code, outsource the common code to a single function\r
+       FILE *fp;\r
+\r
+       if(GameInfo->type != GIT_CART)return 0;\r
+       if(GameInterface != iNESGI)return 0;\r
+\r
+       fp = fopen(name,"wb");\r
+\r
+       if(fwrite(&head,1,16,fp)!=16)\r
+       {\r
+               fclose(fp);\r
+               return 0;\r
+       }\r
+\r
+       if(head.ROM_type&4)     /* Trainer */\r
+       {\r
+               fwrite(trainerpoo,512,1,fp);\r
+       }\r
+\r
+       fwrite(ROM,0x4000,ROM_size,fp);\r
+\r
+       if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp);\r
+       fclose(fp);\r
 \r
        return 1;\r
 }\r
 \r
 \r
        return 1;\r
 }\r
 \r
-void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V)\r
+//para edit: added function below\r
+#if 0\r
+char *iNesShortFName() {\r
+       char *ret;\r
+\r
+       if (!(ret = strrchr(LoadedRomFName,'\\'))) {\r
+               if (!(ret = strrchr(LoadedRomFName,'/'))) return 0;\r
+       }\r
+       return ret+1;\r
+}\r
+#endif\r
+\r
+void VRAM_BANK1(uint32 A, uint8 V)\r
 {\r
 {\r
- V&=7;\r
- PPUCHRRAM|=(1<<(A>>10));\r
- CHRBankList[(A)>>10]=V;\r
- VPage[(A)>>10]=&CHRRAM[V<<10]-(A);\r
      V&=7;\r
      PPUCHRRAM|=(1<<(A>>10));\r
      CHRBankList[(A)>>10]=V;\r
      VPage[(A)>>10]=&CHRRAM[V<<10]-(A);\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(2) VRAM_BANK4(uint32 A, uint32 V)\r
+void VRAM_BANK4(uint32 A, uint32 V)\r
 {\r
 {\r
- V&=1;\r
- PPUCHRRAM|=(0xF<<(A>>10));\r
- CHRBankList[(A)>>10]=(V<<2);\r
- CHRBankList[((A)>>10)+1]=(V<<2)+1;\r
- CHRBankList[((A)>>10)+2]=(V<<2)+2;\r
- CHRBankList[((A)>>10)+3]=(V<<2)+3;\r
- VPage[(A)>>10]=&CHRRAM[V<<10]-(A);\r
      V&=1;\r
      PPUCHRRAM|=(0xF<<(A>>10));\r
      CHRBankList[(A)>>10]=(V<<2);\r
      CHRBankList[((A)>>10)+1]=(V<<2)+1;\r
      CHRBankList[((A)>>10)+2]=(V<<2)+2;\r
      CHRBankList[((A)>>10)+3]=(V<<2)+3;\r
      VPage[(A)>>10]=&CHRRAM[V<<10]-(A);\r
 }\r
 }\r
-void FASTAPASS(2) VROM_BANK1(uint32 A,uint32 V)\r
+void VROM_BANK1(uint32 A,uint32 V)\r
 {\r
 {\r
- setchr1(A,V);\r
- CHRBankList[(A)>>10]=V;\r
      setchr1(A,V);\r
      CHRBankList[(A)>>10]=V;\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(2) VROM_BANK2(uint32 A,uint32 V)\r
+void VROM_BANK2(uint32 A,uint32 V)\r
 {\r
 {\r
- setchr2(A,V);\r
- CHRBankList[(A)>>10]=(V<<1);\r
- CHRBankList[((A)>>10)+1]=(V<<1)+1;\r
      setchr2(A,V);\r
      CHRBankList[(A)>>10]=(V<<1);\r
      CHRBankList[((A)>>10)+1]=(V<<1)+1;\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(2) VROM_BANK4(uint32 A, uint32 V)\r
+void VROM_BANK4(uint32 A, uint32 V)\r
 {\r
 {\r
- setchr4(A,V);\r
- CHRBankList[(A)>>10]=(V<<2);\r
- CHRBankList[((A)>>10)+1]=(V<<2)+1;\r
- CHRBankList[((A)>>10)+2]=(V<<2)+2;\r
- CHRBankList[((A)>>10)+3]=(V<<2)+3;\r
      setchr4(A,V);\r
      CHRBankList[(A)>>10]=(V<<2);\r
      CHRBankList[((A)>>10)+1]=(V<<2)+1;\r
      CHRBankList[((A)>>10)+2]=(V<<2)+2;\r
      CHRBankList[((A)>>10)+3]=(V<<2)+3;\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(1) VROM_BANK8(uint32 V)\r
+void VROM_BANK8(uint32 V)\r
 {\r
 {\r
- setchr8(V);\r
- CHRBankList[0]=(V<<3);\r
- CHRBankList[1]=(V<<3)+1;\r
- CHRBankList[2]=(V<<3)+2;\r
- CHRBankList[3]=(V<<3)+3;\r
- CHRBankList[4]=(V<<3)+4;\r
- CHRBankList[5]=(V<<3)+5;\r
- CHRBankList[6]=(V<<3)+6;\r
- CHRBankList[7]=(V<<3)+7;\r
      setchr8(V);\r
      CHRBankList[0]=(V<<3);\r
      CHRBankList[1]=(V<<3)+1;\r
      CHRBankList[2]=(V<<3)+2;\r
      CHRBankList[3]=(V<<3)+3;\r
      CHRBankList[4]=(V<<3)+4;\r
      CHRBankList[5]=(V<<3)+5;\r
      CHRBankList[6]=(V<<3)+6;\r
      CHRBankList[7]=(V<<3)+7;\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(2) ROM_BANK8(uint32 A, uint32 V)\r
+void ROM_BANK8(uint32 A, uint32 V)\r
 {\r
 {\r
- setprg8(A,V);\r
- if(A>=0x8000)\r
-  PRGBankList[((A-0x8000)>>13)]=V;\r
      setprg8(A,V);\r
      if(A>=0x8000)\r
+               PRGBankList[((A-0x8000)>>13)]=V;\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V)\r
+void ROM_BANK16(uint32 A, uint32 V)\r
 {\r
 {\r
- setprg16(A,V);\r
- if(A>=0x8000)\r
- {\r
-  PRGBankList[((A-0x8000)>>13)]=V<<1;\r
-  PRGBankList[((A-0x8000)>>13)+1]=(V<<1)+1;\r
- }\r
      setprg16(A,V);\r
      if(A>=0x8000)\r
      {\r
+               PRGBankList[((A-0x8000)>>13)]=V<<1;\r
+               PRGBankList[((A-0x8000)>>13)+1]=(V<<1)+1;\r
      }\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(1) ROM_BANK32(uint32 V)\r
+void ROM_BANK32(uint32 V)\r
 {\r
 {\r
- setprg32(0x8000,V);\r
- PRGBankList[0]=V<<2;\r
- PRGBankList[1]=(V<<2)+1;\r
- PRGBankList[2]=(V<<2)+2;\r
- PRGBankList[3]=(V<<2)+3;\r
      setprg32(0x8000,V);\r
      PRGBankList[0]=V<<2;\r
      PRGBankList[1]=(V<<2)+1;\r
      PRGBankList[2]=(V<<2)+2;\r
      PRGBankList[3]=(V<<2)+3;\r
 }\r
 \r
 }\r
 \r
-void FASTAPASS(1) onemir(uint8 V)\r
+void onemir(uint8 V)\r
 {\r
        if(Mirroring==2) return;\r
 {\r
        if(Mirroring==2) return;\r
-        if(V>1)\r
-         V=1;\r
+       if(V>1)\r
+               V=1;\r
        Mirroring=0x10|V;\r
        setmirror(MI_0+V);\r
 }\r
 \r
        Mirroring=0x10|V;\r
        setmirror(MI_0+V);\r
 }\r
 \r
-void FASTAPASS(1) MIRROR_SET2(uint8 V)\r
+void MIRROR_SET2(uint8 V)\r
 {\r
        if(Mirroring==2) return;\r
        Mirroring=V;\r
        setmirror(V);\r
 }\r
 \r
 {\r
        if(Mirroring==2) return;\r
        Mirroring=V;\r
        setmirror(V);\r
 }\r
 \r
-void FASTAPASS(1) MIRROR_SET(uint8 V)\r
+void MIRROR_SET(uint8 V)\r
 {\r
        if(Mirroring==2) return;\r
        V^=1;\r
 {\r
        if(Mirroring==2) return;\r
        V^=1;\r
@@ -746,377 +1097,418 @@ void FASTAPASS(1) MIRROR_SET(uint8 V)
 \r
 static void NONE_init(void)\r
 {\r
 \r
 static void NONE_init(void)\r
 {\r
-        ROM_BANK16(0x8000,0);\r
-        ROM_BANK16(0xC000,~0);\r
+       ROM_BANK16(0x8000,0);\r
+       ROM_BANK16(0xC000,~0);\r
 \r
 \r
-        if(VROM_size)\r
-        VROM_BANK8(0);\r
-        else\r
-        setvram8(CHRRAM);\r
+       if(VROM_size)\r
+               VROM_BANK8(0);\r
+       else\r
+               setvram8(CHRRAM);\r
 }\r
 }\r
-\r
 void (*MapInitTab[256])(void)=\r
 {\r
 void (*MapInitTab[256])(void)=\r
 {\r
-    0,0, //Mapper2_init,Mapper3_init,\r
-    0,0,\r
-    0,0,\r
-    Mapper6_init,\r
-    0,//Mapper7_init,\r
-    Mapper8_init,Mapper9_init,\r
-    Mapper10_init,\r
-    0, //Mapper11_init,\r
-    0, //Mapper13_init,\r
-    0,\r
-    0,\r
-    Mapper15_init,Mapper16_init,Mapper17_init,Mapper18_init,\r
-    0,0,\r
-    Mapper21_init,Mapper22_init,Mapper23_init,Mapper24_init,\r
-    Mapper25_init,Mapper26_init,Mapper27_init,\r
-    0,0,0,0,\r
-    Mapper32_init,Mapper33_init,Mapper34_init,\r
-    0,0,0,0,0,\r
-    Mapper40_init,Mapper41_init,Mapper42_init,Mapper43_init,\r
-    0,0,\r
-    Mapper46_init,\r
-    0,\r
-    Mapper48_init,\r
-    0,\r
-    Mapper50_init,Mapper51_init,\r
-    0,0,0,0,0,\r
-    0,//    Mapper57_init,\r
-    0,//    Mapper58_init,\r
-    Mapper59_init,Mapper60_init,\r
-    Mapper61_init,Mapper62_init,\r
-    0,\r
-    Mapper64_init,Mapper65_init,\r
-    0,//Mapper66_init,\r
-    Mapper67_init,\r
-    Mapper68_init,Mapper69_init,\r
-    0,//Mapper70_init,\r
-    Mapper71_init,\r
-    Mapper72_init,Mapper73_init,\r
-    0,\r
-    Mapper75_init,Mapper76_init,Mapper77_init,\r
-    0, //Mapper78_init,\r
-    Mapper79_init,Mapper80_init,\r
-    0,\r
-    Mapper82_init,Mapper83_init,\r
-    0,\r
-    Mapper85_init,Mapper86_init,\r
-    0, //Mapper87_init,\r
-    0, //Mapper88_init,\r
-    Mapper89_init,\r
-    0,\r
-    Mapper91_init,Mapper92_init,\r
-    0, //Mapper93_init,\r
-    0, //Mapper94_init,\r
-    0,\r
-    Mapper96_init,Mapper97_init,\r
-    0,\r
-    Mapper99_init,\r
-    0,0,0,0,0,0,0,\r
-    0, //Mapper107_init,\r
-    0,0,0,0,\r
-    0,Mapper113_init,\r
-    0,0,0,\r
-    0, //Mapper117_init,\r
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\r
-    0, //Mapper140_init,\r
-    0,0,0,\r
-    0, //Mapper144_init,\r
-    0,0,0,0,0,0,\r
-    Mapper151_init,\r
-    0, //Mapper152_init,\r
-    Mapper153_init,\r
-    0, //Mapper154_init,\r
-    0,\r
-    Mapper156_init,Mapper157_init,Mapper158_init,0,\r
-    0,0,0,0,0,0,\r
-    Mapper166_init,Mapper167_init,\r
-    0,0,0,0,0,0,0,0,0,0,0,0,\r
-    Mapper180_init,\r
-    0,0,0,\r
-    Mapper184_init,\r
-    0, //Mapper185_init,\r
-    0,0,0,\r
-    0, //Mapper189_init,\r
-    0,\r
-    0, //Mapper191_init,\r
-    0,\r
-    Mapper193_init,\r
-    0,0,0,0,0,0,\r
-    Mapper200_init,Mapper201_init,Mapper202_init,Mapper203_init,\r
-    Mapper204_init,\r
-    0,0,\r
-    Mapper207_init,\r
-    0,0,0,\r
-    0, //Mapper211_init,\r
-    Mapper212_init,Mapper213_init,Mapper214_init,\r
-    0,0,0,0,0,0,0,0,0,0,\r
-    Mapper225_init,Mapper226_init,Mapper227_init,Mapper228_init,\r
-    Mapper229_init,Mapper230_init,Mapper231_init,Mapper232_init,\r
-    0,\r
-    Mapper234_init,\r
-    0, //Mapper235_init,\r
-    0,0,0,0,\r
-    Mapper240_init,Mapper241_init,Mapper242_init,0,\r
-    Mapper244_init,\r
-    0,\r
-    Mapper246_init,\r
-    0,0,0,0,0,0,0,0,\r
-    Mapper255_init\r
+       0,\r
+       0,\r
+       0, //Mapper2_init,\r
+       0, //Mapper3_init,\r
+       0,\r
+       0,\r
+       Mapper6_init,\r
+       0,//Mapper7_init,\r
+       Mapper8_init,\r
+       Mapper9_init,\r
+       Mapper10_init,\r
+       0, //Mapper11_init,\r
+       0,\r
+       0, //Mapper13_init,\r
+       0,\r
+    0, //Mapper15_init,\r
+    0, //Mapper16_init,\r
+       Mapper17_init,\r
+       Mapper18_init,\r
+       0,\r
+       0,\r
+       Mapper21_init,\r
+       Mapper22_init,\r
+    0, //Mapper23_init,\r
+       Mapper24_init,\r
+       Mapper25_init,\r
+       Mapper26_init,\r
+       Mapper27_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       Mapper32_init,\r
+       Mapper33_init,\r
+       Mapper34_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       Mapper40_init,\r
+       Mapper41_init,\r
+       Mapper42_init,\r
+       0, //Mapper43_init,\r
+       0,\r
+       0,\r
+       Mapper46_init,\r
+       0,\r
+       Mapper48_init,\r
+       0,\r
+       Mapper50_init,\r
+       Mapper51_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,//    Mapper57_init,\r
+       0,//    Mapper58_init,\r
+       Mapper59_init,\r
+       0,// Mapper60_init,\r
+       Mapper61_init,\r
+       Mapper62_init,\r
+       0,\r
+       Mapper64_init,\r
+       Mapper65_init,\r
+       0,//Mapper66_init,\r
+       Mapper67_init,\r
+    0,//Mapper68_init,\r
+       Mapper69_init,\r
+       0,//Mapper70_init,\r
+       Mapper71_init,\r
+       Mapper72_init,\r
+       Mapper73_init,\r
+       0,\r
+       Mapper75_init,\r
+       Mapper76_init,\r
+       Mapper77_init,\r
+       0, //Mapper78_init,\r
+       Mapper79_init,\r
+       Mapper80_init,\r
+       0,\r
+       Mapper82_init,\r
+       Mapper83_init,\r
+       0,\r
+       Mapper85_init,\r
+       Mapper86_init,\r
+       0, //Mapper87_init,\r
+       0, //Mapper88_init,\r
+       Mapper89_init,\r
+       0,\r
+       Mapper91_init,\r
+       Mapper92_init,\r
+       0, //Mapper93_init,\r
+       0, //Mapper94_init,\r
+       0,\r
+       Mapper96_init,\r
+       Mapper97_init,\r
+       0,\r
+       Mapper99_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper107_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0, // Mapper113_init,\r
+       0,\r
+       0,\r
+       0, //Mapper116_init,\r
+       0, //Mapper117_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper140_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper144_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       Mapper151_init,\r
+       0, //Mapper152_init,\r
+    0, //Mapper153_init,\r
+       0, //Mapper154_init,\r
+       0,\r
+       0,\r
+       Mapper157_init,\r
+       0, //Mapper158_init, removed\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       Mapper166_init,\r
+       Mapper167_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper180_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper184_init,\r
+       0, //Mapper185_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper189_init,\r
+       0,\r
+       0, //Mapper191_init,\r
+       0,\r
+       Mapper193_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper200_init,\r
+       Mapper201_init,\r
+       Mapper202_init,\r
+       Mapper203_init,\r
+       Mapper204_init,\r
+       0,\r
+       0,\r
+       Mapper207_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper211_init,\r
+       Mapper212_init,\r
+       Mapper213_init,\r
+       Mapper214_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       Mapper225_init,\r
+       0, //Mapper226_init,\r
+       Mapper227_init,\r
+       Mapper228_init,\r
+       Mapper229_init,\r
+       Mapper230_init,\r
+       Mapper231_init,\r
+       Mapper232_init,\r
+       0,\r
+       Mapper234_init,\r
+       0, //Mapper235_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0, //Mapper240_init,\r
+       Mapper241_init,\r
+       Mapper242_init,\r
+       0,\r
+       Mapper244_init,\r
+       0,\r
+       Mapper246_init,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       0,\r
+       Mapper255_init\r
 };\r
 \r
 };\r
 \r
-\r
-\r
 static DECLFW(BWRAM)\r
 {\r
 static DECLFW(BWRAM)\r
 {\r
-                WRAM[A-0x6000]=V;\r
+       WRAM[A-0x6000]=V;\r
 }\r
 \r
 static DECLFR(AWRAM)\r
 {\r
 }\r
 \r
 static DECLFR(AWRAM)\r
 {\r
-                return WRAM[A-0x6000];\r
+       return WRAM[A-0x6000];\r
 }\r
 \r
 }\r
 \r
-#ifdef DEBUG_MAPPER\r
-static DECLFW(WriteHandler)\r
-{\r
- FCEU_printf("$%04x:$%02x\n",A,V);\r
-}\r
-#endif\r
 \r
 void (*MapStateRestore)(int version);\r
 void iNESStateRestore(int version)\r
 {\r
 \r
 void (*MapStateRestore)(int version);\r
 void iNESStateRestore(int version)\r
 {\r
- int x;\r
-\r
- if(!MapperNo) return;\r
-\r
- for(x=0;x<4;x++)\r
-  setprg8(0x8000+x*8192,PRGBankList[x]);\r
-\r
- if(VROM_size)\r
-  for(x=0;x<8;x++)\r
-    setchr1(0x400*x,CHRBankList[x]);\r
-\r
-if(0) switch(Mirroring)\r
- {\r
-   case 0:setmirror(MI_H);break;\r
-   case 1:setmirror(MI_V);break;\r
-   case 0x12:\r
-   case 0x10:setmirror(MI_0);break;\r
-   case 0x13:\r
-   case 0x11:setmirror(MI_1);break;\r
- }\r
- if(MapStateRestore) MapStateRestore(version);\r
      int x;\r
+\r
      if(!MapperNo) return;\r
+\r
      for(x=0;x<4;x++)\r
+               setprg8(0x8000+x*8192,PRGBankList[x]);\r
+\r
      if(VROM_size)\r
+               for(x=0;x<8;x++)\r
+                       setchr1(0x400*x,CHRBankList[x]);\r
+\r
+       if(0) switch(Mirroring)\r
      {\r
+               case 0:setmirror(MI_H);break;\r
+               case 1:setmirror(MI_V);break;\r
+               case 0x12:\r
+               case 0x10:setmirror(MI_0);break;\r
+               case 0x13:\r
+               case 0x11:setmirror(MI_1);break;\r
      }\r
      if(MapStateRestore) MapStateRestore(version);\r
 }\r
 \r
 static void iNESPower(void)\r
 {\r
 }\r
 \r
 static void iNESPower(void)\r
 {\r
-        int x;\r
+       int x;\r
        int type=MapperNo;\r
 \r
        int type=MapperNo;\r
 \r
-        SetReadHandler(0x8000,0xFFFF,CartBR);\r
-        GameStateRestore=iNESStateRestore;\r
-        MapClose=0;\r
+       SetReadHandler(0x8000,0xFFFF,CartBR);\r
+       GameStateRestore=iNESStateRestore;\r
+       MapClose=0;\r
        MapperReset=0;\r
        MapperReset=0;\r
-        MapStateRestore=0;\r
+       MapStateRestore=0;\r
 \r
 \r
-        setprg8r(1,0x6000,0);\r
+       setprg8r(1,0x6000,0);\r
 \r
 \r
-        SetReadHandler(0x6000,0x7FFF,AWRAM);\r
+       SetReadHandler(0x6000,0x7FFF,AWRAM);\r
 #ifdef ASM_6502\r
 #ifdef ASM_6502\r
-        // asm code needs pages to be set again..\r
-        Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000;\r
+       // asm code needs pages to be set again..\r
+       Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000;\r
 #endif\r
 #endif\r
-        SetWriteHandler(0x6000,0x7FFF,BWRAM);\r
-        FCEU_CheatAddRAM(8,0x6000,WRAM);\r
-\r
-    #ifdef DEBUG_MAPPER\r
-    if(type==0) SetWriteHandler(0x4020,0xFFFF,WriteHandler);\r
-    #endif\r
+       SetWriteHandler(0x6000,0x7FFF,BWRAM);\r
+       FCEU_CheatAddRAM(8,0x6000,WRAM);\r
 \r
        /* This statement represents atrocious code.  I need to rewrite\r
 \r
        /* This statement represents atrocious code.  I need to rewrite\r
-          all of the iNES mapper code... */\r
+       all of the iNES mapper code... */\r
        IRQCount=IRQLatch=IRQa=0;\r
        IRQCount=IRQLatch=IRQa=0;\r
-        if(head.ROM_type&2)\r
-         memset(GameMemBlock+8192,0,sizeof(GameMemBlock)-8192);\r
+       if(head.ROM_type&2)\r
+               memset(GameMemBlock+8192,0,GAME_MEM_BLOCK_SIZE-8192);\r
        else\r
        else\r
-         memset(GameMemBlock,0,sizeof(GameMemBlock));\r
+               memset(GameMemBlock,0,GAME_MEM_BLOCK_SIZE);\r
 \r
 \r
-        NONE_init();\r
+       NONE_init();\r
+       ResetExState(0,0);\r
 \r
 \r
-        ResetExState(0,0);\r
-       if(FCEUGameInfo.type == GIT_VSUNI)\r
-        AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0);\r
+       if(GameInfo->type == GIT_VSUNI)\r
+               AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0);\r
 \r
 \r
-        AddExState(WRAM, 8192, 0, "WRAM");\r
-        if(type==19 || type==6 || type==69 || type==85 || type==96)\r
-         AddExState(MapperExRAM, 32768, 0, "MEXR");\r
-    if((!VROM_size || type==6 || type==19) && (type!=13 && type!=96))\r
-         AddExState(CHRRAM, 8192, 0, "CHRR");\r
-        if(head.ROM_type&8)\r
-         AddExState(ExtraNTARAM, 2048, 0, "EXNR");\r
+       AddExState(WRAM, 8192, 0, "WRAM");\r
+       if(type==19 || type==6 || type==69 || type==85 || type==96)\r
+               AddExState(MapperExRAM, 32768, 0, "MEXR");\r
+       if((!VROM_size || type==6 || type==19) && (type!=13 && type!=96))\r
+               AddExState(CHRRAM, 8192, 0, "CHRR");\r
+       if(head.ROM_type&8)\r
+               AddExState(ExtraNTARAM, 2048, 0, "EXNR");\r
 \r
        /* Exclude some mappers whose emulation code handle save state stuff\r
 \r
        /* Exclude some mappers whose emulation code handle save state stuff\r
-          themselves. */\r
+       themselves. */\r
        if(type && type!=13 && type!=96)\r
        {\r
        if(type && type!=13 && type!=96)\r
        {\r
-         AddExState(mapbyte1, 32, 0, "MPBY");\r
-         AddExState(&Mirroring, 1, 0, "MIRR");\r
-         AddExState(&IRQCount, 4, 1, "IRQC");\r
-         AddExState(&IRQLatch, 4, 1, "IQL1");\r
-         AddExState(&IRQa, 1, 0, "IRQA");\r
-         AddExState(PRGBankList, 4, 0, "PBL");\r
-         for(x=0;x<8;x++)\r
-         {\r
-          char tak[8];\r
-          sprintf(tak,"CBL%d",x);\r
-          AddExState(&CHRBankList[x], 2, 1,tak);\r
-         }\r
+               AddExState(mapbyte1, 32, 0, "MPBY");\r
+               AddExState(&Mirroring, 1, 0, "MIRR");\r
+               AddExState(&IRQCount, 4, 1, "IRQC");\r
+               AddExState(&IRQLatch, 4, 1, "IQL1");\r
+               AddExState(&IRQa, 1, 0, "IRQA");\r
+               AddExState(PRGBankList, 4, 0, "PBL");\r
+               for(x=0;x<8;x++)\r
+               {\r
+                       char tak[8];\r
+                       sprintf(tak,"CBL%d",x);\r
+                       AddExState(&CHRBankList[x], 2, 1,tak);\r
+               }\r
        }\r
 \r
        }\r
 \r
-        if(MapInitTab[type]) MapInitTab[type]();\r
-        else if(type)\r
-        {\r
-         FCEU_PrintError("iNES mapper #%d is not supported at all.",type);\r
-        }\r
+       if(MapInitTab[type]) MapInitTab[type]();\r
+       else if(type)\r
+       {\r
+               FCEU_PrintError("iNES mapper #%d is not supported at all.",type);\r
+       }\r
 }\r
 \r
 }\r
 \r
+static int NewiNES_Init(int num)\r
+{\r
+       BMAPPINGLocal *tmp=bmap;\r
 \r
 \r
-typedef struct {\r
-           int number;\r
-           void (*init)(CartInfo *);\r
-} BMAPPING;\r
-\r
-static BMAPPING bmap[] = {\r
-    {0,   NROM_Init},\r
-    {1,   Mapper1_Init},\r
-    {2,   UNROM_Init},\r
-    {3,   CNROM_Init},\r
-    {4,   Mapper4_Init},\r
-    {5,   Mapper5_Init},\r
-    {7,   ANROM_Init},\r
-    {11,  Mapper11_Init},\r
-    {12,  Mapper12_Init},\r
-    {13,  CPROM_Init},\r
-    {19,  Mapper19_Init},\r
-    {37,  Mapper37_Init},\r
-    {44,  Mapper44_Init},\r
-    {45,  Mapper45_Init},\r
-    {47,  Mapper47_Init},\r
-    {49,  Mapper49_Init},\r
-    {52,  Mapper52_Init},\r
-    {57,  Mapper57_Init},\r
-    {58,  Mapper58_Init},\r
-    {66,  MHROM_Init},\r
-    {70,  Mapper70_Init},\r
-    {74,  Mapper74_Init},\r
-    {78,  Mapper78_Init},\r
-    {87,  Mapper87_Init},\r
-    {88,  Mapper88_Init},\r
-    {90,  Mapper90_Init},\r
-    {93,  SUNSOFT_UNROM_Init},\r
-    {94,  Mapper94_Init},\r
-    {95,  Mapper95_Init},\r
-    {105, Mapper105_Init},\r
-    {107, Mapper107_Init},\r
-    {112, Mapper112_Init},\r
-    {114, Mapper114_Init},\r
-    {115, Mapper115_Init},\r
-    {116, Mapper116_Init},\r
-    {117, Mapper117_Init},\r
-    {118, Mapper118_Init},\r
-    {119, Mapper119_Init},\r
-    {133, SA72008_Init},\r
-    {137, S8259D_Init},\r
-    {138, S8259B_Init},\r
-    {139, S8259C_Init},\r
-    {140, Mapper140_Init},\r
-    {141, S8259A_Init},\r
-    {143, TCA01_Init},\r
-    {144, Mapper144_Init},\r
-    {145, SA72007_Init},\r
-    {146, SA0161M_Init},\r
-    {147, TCU01_Init},\r
-    {148, SA0037_Init},\r
-    {149, SA0036_Init},\r
-    {150, S74LS374N_Init},\r
-    {152, Mapper152_Init},\r
-    {154, Mapper154_Init},\r
-    {155, Mapper155_Init},\r
-    {160, Mapper90_Init},\r
-    {163, Mapper163_Init},\r
-    {164, Mapper164_Init},\r
-    {165, Mapper165_Init},\r
-    {181, Mapper181_Init},\r
-    {182, Mapper182_Init},\r
-    {183, Mapper183_Init},\r
-    {185, Mapper185_Init},\r
-    {186, Mapper186_Init},\r
-    {187, Mapper187_Init},\r
-    {188, Mapper188_Init},\r
-    {189, Mapper189_Init},\r
-    {191, Mapper191_Init},\r
-    {192, Mapper192_Init},\r
-    {194, Mapper194_Init},\r
-    {198, Mapper198_Init},\r
-    {199, Mapper199_Init},\r
-    {205, Mapper205_Init},\r
-    {206, DEIROM_Init},\r
-    {208, Mapper208_Init},\r
-    {209, Mapper209_Init},\r
-    {210, Mapper210_Init},\r
-    {211, Mapper211_Init},\r
-    {215, Mapper215_Init},\r
-    {216, Mapper216_Init},\r
-    {217, Mapper217_Init},\r
-    {218, UNLSonic_Init},\r
-    {219, UNLSL1632_Init},\r
-//    {220, Mapper220_Init},\r
-    {222, Mapper222_Init},\r
-    {235, Mapper235_Init},\r
-    {243, S74LS374NA_Init},\r
-    {245, Mapper245_Init},\r
-    {249, Mapper249_Init},\r
-    {250, Mapper250_Init},\r
-    {254, Mapper254_Init},\r
-    {  0,        0}\r
-};\r
+       CHRRAMSize = -1;\r
 \r
 \r
+       if(GameInfo->type == GIT_VSUNI)\r
+               AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0);\r
 \r
 \r
-static int NewiNES_Init(int num)\r
-{\r
- BMAPPING *tmp=bmap;\r
-\r
- if(FCEUGameInfo.type == GIT_VSUNI)\r
-  AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0);\r
-\r
- while(tmp->init)\r
- {\r
-  if(num==tmp->number)\r
-  {\r
-   UNIFchrrama=0; // need here for compatibility with UNIF mapper code\r
-   if(!VROM_size)\r
-   {\r
-    int CHRRAMSize;\r
-    if(num==13)\r
-      CHRRAMSize=16384;\r
-    else\r
-      CHRRAMSize=8192;\r
-    VROM=(uint8 *)malloc(CHRRAMSize);\r
-    UNIFchrrama=VROM;\r
-    SetupCartCHRMapping(0,VROM,CHRRAMSize,1);\r
-    AddExState(VROM,CHRRAMSize, 0, "CHRR");\r
-   }\r
-   if(head.ROM_type&8)\r
-    AddExState(ExtraNTARAM, 2048, 0, "EXNR");\r
-   tmp->init(&iNESCart);\r
-   return(1);\r
-  }\r
-  tmp++;\r
- }\r
- return(0);\r
+       while(tmp->init)\r
+       {\r
+               if(num==tmp->number)\r
+               {\r
+                       UNIFchrrama=0; // need here for compatibility with UNIF mapper code\r
+                       if(!VROM_size)\r
+                       {\r
+                               if(num==13)\r
+                               {\r
+                                       CHRRAMSize=16384;\r
+                               }\r
+                               else\r
+                               {\r
+                                       CHRRAMSize=8192;\r
+                               }\r
+                               if((VROM = (uint8 *)FCEU_malloc(CHRRAMSize)) == NULL) return 0;\r
+                               FCEU_MemoryRand(VROM,CHRRAMSize);\r
+\r
+                               UNIFchrrama=VROM;\r
+                               SetupCartCHRMapping(0,VROM,CHRRAMSize,1);\r
+                               AddExState(VROM,CHRRAMSize, 0, "CHRR");\r
+                       }\r
+                       if(head.ROM_type&8)\r
+                               AddExState(ExtraNTARAM, 2048, 0, "EXNR");\r
+                       tmp->init(&iNESCart);\r
+                       return 1;\r
+               }\r
+               tmp++;\r
+       }\r
+       return 0;\r
 }\r
 \r
 }\r
 \r
+// vim:ts=4\r
diff --git a/ines.h b/ines.h
index 5a49aed..d18002c 100644 (file)
--- a/ines.h
+++ b/ines.h
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
  */\r
 \r
  */\r
 \r
+#ifndef _INES_H_\r
+#define _INES_H_\r
+#include <stdlib.h>\r
+#include <string.h>\r
 #include "cart.h"\r
 #ifdef INESPRIV\r
 \r
 #include "cart.h"\r
 #ifdef INESPRIV\r
 \r
@@ -65,25 +69,53 @@ extern uint8 iNESIRQa;
 #else\r
 #endif\r
 \r
 #else\r
 #endif\r
 \r
-  typedef struct {\r
+#if 0\r
+struct TMasterRomInfo\r
+{\r
+       uint64 md5lower;\r
+       const char* params;\r
+};\r
+\r
+class TMasterRomInfoParams : public std::map<std::string,std::string> \r
+{\r
+public:\r
+       bool ContainsKey(const std::string& key) { return find(key) != end(); }\r
+};\r
+#endif\r
+\r
+//mbg merge 6/29/06\r
+extern uint8 *ROM;\r
+extern uint8 *VROM;\r
+extern uint32 VROM_size;\r
+extern uint32 ROM_size;\r
+extern int iNesSave(); //bbit Edited: line added\r
+extern int iNesSaveAs(char* name);\r
+extern char LoadedRomFName[2048]; //bbit Edited: line added\r
+//extern const TMasterRomInfo* MasterRomInfo;\r
+//extern TMasterRomInfoParams MasterRomInfoParams;\r
+\r
+//mbg merge 7/19/06 changed to c++ decl format\r
+struct iNES_HEADER {\r
     char ID[4]; /*NES^Z*/\r
     uint8 ROM_size;\r
     uint8 VROM_size;\r
     uint8 ROM_type;\r
     uint8 ROM_type2;\r
     uint8 reserve[8];\r
     char ID[4]; /*NES^Z*/\r
     uint8 ROM_size;\r
     uint8 VROM_size;\r
     uint8 ROM_type;\r
     uint8 ROM_type2;\r
     uint8 reserve[8];\r
-  } iNES_HEADER;\r
+};\r
+\r
+extern struct iNES_HEADER head; //for mappers usage\r
 \r
 \r
-void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V);\r
-void FASTAPASS(2) VRAM_BANK4(uint32 A,uint32 V);\r
+void VRAM_BANK1(uint32 A, uint8 V);\r
+void VRAM_BANK4(uint32 A,uint32 V);\r
 \r
 \r
-void FASTAPASS(2) VROM_BANK1(uint32 A,uint32 V);\r
-void FASTAPASS(2) VROM_BANK2(uint32 A,uint32 V);\r
-void FASTAPASS(2) VROM_BANK4(uint32 A, uint32 V);\r
-void FASTAPASS(1) VROM_BANK8(uint32 V);\r
-void FASTAPASS(2) ROM_BANK8(uint32 A, uint32 V);\r
-void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V);\r
-void FASTAPASS(1) ROM_BANK32(uint32 V);\r
+void VROM_BANK1(uint32 A,uint32 V);\r
+void VROM_BANK2(uint32 A,uint32 V);\r
+void VROM_BANK4(uint32 A, uint32 V);\r
+void VROM_BANK8(uint32 V);\r
+void ROM_BANK8(uint32 A, uint32 V);\r
+void ROM_BANK16(uint32 A, uint32 V);\r
+void ROM_BANK32(uint32 V);\r
 \r
 extern uint8 vmask;\r
 extern uint32 vmask1;\r
 \r
 extern uint8 vmask;\r
 extern uint32 vmask1;\r
@@ -93,9 +125,9 @@ extern uint32 pmask8;
 extern uint8 pmask16;\r
 extern uint8 pmask32;\r
 \r
 extern uint8 pmask16;\r
 extern uint8 pmask32;\r
 \r
-void FASTAPASS(1) onemir(uint8 V);\r
-void FASTAPASS(1) MIRROR_SET2(uint8 V);\r
-void FASTAPASS(1) MIRROR_SET(uint8 V);\r
+void onemir(uint8 V);\r
+void MIRROR_SET2(uint8 V);\r
+void MIRROR_SET(uint8 V);\r
 \r
 void Mapper0_init(void);\r
 void Mapper1_init(void);\r
 \r
 void Mapper0_init(void);\r
 void Mapper1_init(void);\r
@@ -110,15 +142,15 @@ void Mapper10_init(void);
 void Mapper12_init(void);\r
 //void Mapper13_init(void);\r
 void Mapper14_init(void);\r
 void Mapper12_init(void);\r
 //void Mapper13_init(void);\r
 void Mapper14_init(void);\r
-void Mapper15_init(void);\r
-void Mapper16_init(void);\r
+//void Mapper15_init(void);\r
+//void Mapper16_init(void);\r
 void Mapper17_init(void);\r
 void Mapper18_init(void);\r
 void Mapper19_init(void);\r
 void Mapper20_init(void);\r
 void Mapper21_init(void);\r
 void Mapper22_init(void);\r
 void Mapper17_init(void);\r
 void Mapper18_init(void);\r
 void Mapper19_init(void);\r
 void Mapper20_init(void);\r
 void Mapper21_init(void);\r
 void Mapper22_init(void);\r
-void Mapper23_init(void);\r
+//void Mapper23_init(void);\r
 void Mapper24_init(void);\r
 void Mapper25_init(void);\r
 void Mapper26_init(void);\r
 void Mapper24_init(void);\r
 void Mapper25_init(void);\r
 void Mapper26_init(void);\r
@@ -133,12 +165,12 @@ void Mapper34_init(void);
 void Mapper35_init(void);\r
 void Mapper36_init(void);\r
 //void Mapper37_init(void);\r
 void Mapper35_init(void);\r
 void Mapper36_init(void);\r
 //void Mapper37_init(void);\r
-void Mapper38_init(void);\r
-void Mapper39_init(void);\r
+//void Mapper38_init(void);\r
+//void Mapper39_init(void);\r
 void Mapper40_init(void);\r
 void Mapper41_init(void);\r
 void Mapper42_init(void);\r
 void Mapper40_init(void);\r
 void Mapper41_init(void);\r
 void Mapper42_init(void);\r
-void Mapper43_init(void);\r
+//void Mapper43_init(void);\r
 void Mapper44_init(void);\r
 void Mapper45_init(void);\r
 void Mapper46_init(void);\r
 void Mapper44_init(void);\r
 void Mapper45_init(void);\r
 void Mapper46_init(void);\r
@@ -160,7 +192,7 @@ void Mapper64_init(void);
 void Mapper65_init(void);\r
 //void Mapper66_init(void);\r
 void Mapper67_init(void);\r
 void Mapper65_init(void);\r
 //void Mapper66_init(void);\r
 void Mapper67_init(void);\r
-void Mapper68_init(void);\r
+//void Mapper68_init(void);\r
 void Mapper69_init(void);\r
 //void Mapper70_init(void);\r
 void Mapper71_init(void);\r
 void Mapper69_init(void);\r
 //void Mapper70_init(void);\r
 void Mapper71_init(void);\r
@@ -191,21 +223,21 @@ void Mapper97_init(void);
 void Mapper98_init(void);\r
 void Mapper99_init(void);\r
 void Mapper100_init(void);\r
 void Mapper98_init(void);\r
 void Mapper99_init(void);\r
 void Mapper100_init(void);\r
-void Mapper101_init(void);\r
-void Mapper103_init(void);\r
+//void Mapper101_init(void);\r
+//void Mapper103_init(void);\r
 void Mapper104_init(void);\r
 void Mapper104_init(void);\r
-void Mapper106_init(void);\r
+//void Mapper106_init(void);\r
 //void Mapper107_init(void);\r
 //void Mapper107_init(void);\r
-void Mapper108_init(void);\r
+//void Mapper108_init(void);\r
 void Mapper109_init(void);\r
 void Mapper110_init(void);\r
 void Mapper111_init(void);\r
 void Mapper109_init(void);\r
 void Mapper110_init(void);\r
 void Mapper111_init(void);\r
-void Mapper113_init(void);\r
+//void Mapper113_init(void);\r
 void Mapper115_init(void);\r
 void Mapper116_init(void);\r
 //void Mapper117_init(void);\r
 void Mapper115_init(void);\r
 void Mapper116_init(void);\r
 //void Mapper117_init(void);\r
-void Mapper120_init(void);\r
-void Mapper121_init(void);\r
+//void Mapper120_init(void);\r
+//void Mapper121_init(void);\r
 void Mapper122_init(void);\r
 void Mapper123_init(void);\r
 void Mapper124_init(void);\r
 void Mapper122_init(void);\r
 void Mapper123_init(void);\r
 void Mapper124_init(void);\r
@@ -216,24 +248,23 @@ void Mapper129_init(void);
 void Mapper130_init(void);\r
 void Mapper131_init(void);\r
 void Mapper132_init(void);\r
 void Mapper130_init(void);\r
 void Mapper131_init(void);\r
 void Mapper132_init(void);\r
-void Mapper134_init(void);\r
+//void Mapper134_init(void);\r
 void Mapper135_init(void);\r
 void Mapper136_init(void);\r
 void Mapper137_init(void);\r
 void Mapper139_init(void);\r
 //void Mapper140_init(void);\r
 void Mapper141_init(void);\r
 void Mapper135_init(void);\r
 void Mapper136_init(void);\r
 void Mapper137_init(void);\r
 void Mapper139_init(void);\r
 //void Mapper140_init(void);\r
 void Mapper141_init(void);\r
-void Mapper142_init(void);\r
+//void Mapper142_init(void);\r
 void Mapper143_init(void);\r
 //void Mapper144_init(void);\r
 void Mapper150_init(void);\r
 void Mapper151_init(void);\r
 //void Mapper152_init(void);\r
 void Mapper143_init(void);\r
 //void Mapper144_init(void);\r
 void Mapper150_init(void);\r
 void Mapper151_init(void);\r
 //void Mapper152_init(void);\r
-void Mapper153_init(void);\r
+//void Mapper153_init(void);\r
 void Mapper154_init(void);\r
 void Mapper154_init(void);\r
-void Mapper156_init(void);\r
 void Mapper157_init(void);\r
 void Mapper157_init(void);\r
-void Mapper158_init(void);\r
+//void Mapper158_init(void);\r
 void Mapper159_init(void);\r
 void Mapper160_init(void);\r
 void Mapper161_init(void);\r
 void Mapper159_init(void);\r
 void Mapper160_init(void);\r
 void Mapper161_init(void);\r
@@ -241,31 +272,31 @@ void Mapper162_init(void);
 void Mapper166_init(void);\r
 void Mapper167_init(void);\r
 void Mapper168_init(void);\r
 void Mapper166_init(void);\r
 void Mapper167_init(void);\r
 void Mapper168_init(void);\r
-void Mapper169_init(void);\r
+//void Mapper169_init(void);\r
 void Mapper170_init(void);\r
 void Mapper170_init(void);\r
-void Mapper171_init(void);\r
-void Mapper172_init(void);\r
-void Mapper173_init(void);\r
+//void Mapper171_init(void);\r
+//void Mapper172_init(void);\r
+//void Mapper173_init(void);\r
 void Mapper174_init(void);\r
 void Mapper175_init(void);\r
 void Mapper176_init(void);\r
 void Mapper174_init(void);\r
 void Mapper175_init(void);\r
 void Mapper176_init(void);\r
-void Mapper177_init(void);\r
-void Mapper178_init(void);\r
-void Mapper179_init(void);\r
-void Mapper180_init(void);\r
+//void Mapper177_init(void);\r
+//void Mapper178_init(void);\r
+//void Mapper179_init(void);\r
+//void Mapper180_init(void);\r
 //void Mapper181_init(void);\r
 //void Mapper181_init(void);\r
-void Mapper184_init(void);\r
+//void Mapper184_init(void);\r
 //void Mapper185_init(void);\r
 //void Mapper189_init(void);\r
 //void Mapper192_init(void);\r
 void Mapper193_init(void);\r
 //void Mapper194_init(void);\r
 //void Mapper185_init(void);\r
 //void Mapper189_init(void);\r
 //void Mapper192_init(void);\r
 void Mapper193_init(void);\r
 //void Mapper194_init(void);\r
-void Mapper195_init(void);\r
-void Mapper196_init(void);\r
-void Mapper197_init(void);\r
+//void Mapper195_init(void);\r
+//void Mapper196_init(void);\r
+//void Mapper197_init(void);\r
 //void Mapper198_init(void);\r
 void Mapper199_init(void);\r
 //void Mapper198_init(void);\r
 void Mapper199_init(void);\r
-void Mapper200_init(void);\r
+//void Mapper200_init(void);\r
 void Mapper201_init(void);\r
 void Mapper202_init(void);\r
 void Mapper203_init(void);\r
 void Mapper201_init(void);\r
 void Mapper202_init(void);\r
 void Mapper203_init(void);\r
@@ -283,7 +314,7 @@ void Mapper221_init(void);
 void Mapper223_init(void);\r
 void Mapper224_init(void);\r
 void Mapper225_init(void);\r
 void Mapper223_init(void);\r
 void Mapper224_init(void);\r
 void Mapper225_init(void);\r
-void Mapper226_init(void);\r
+//void Mapper226_init(void);\r
 void Mapper227_init(void);\r
 void Mapper228_init(void);\r
 void Mapper229_init(void);\r
 void Mapper227_init(void);\r
 void Mapper228_init(void);\r
 void Mapper229_init(void);\r
@@ -307,7 +338,7 @@ void Mapper247_init(void);
 void Mapper249_init(void);\r
 void Mapper251_init(void);\r
 void Mapper252_init(void);\r
 void Mapper249_init(void);\r
 void Mapper251_init(void);\r
 void Mapper252_init(void);\r
-void Mapper253_init(void);\r
+//void Mapper253_init(void);\r
 void Mapper255_init(void);\r
 \r
 void NSFVRC6_Init(void);\r
 void Mapper255_init(void);\r
 \r
 void NSFVRC6_Init(void);\r
@@ -322,15 +353,22 @@ void Mapper4_Init(CartInfo *);
 void Mapper5_Init(CartInfo *);\r
 void Mapper11_Init(CartInfo *);\r
 void Mapper12_Init(CartInfo *);\r
 void Mapper5_Init(CartInfo *);\r
 void Mapper11_Init(CartInfo *);\r
 void Mapper12_Init(CartInfo *);\r
+void Mapper15_Init(CartInfo *);\r
+void Mapper16_Init(CartInfo *);\r
 void Mapper19_Init(CartInfo *);\r
 void Mapper19_Init(CartInfo *);\r
+void Mapper23_Init(CartInfo *);\r
+void Mapper36_Init(CartInfo *);\r
 void Mapper37_Init(CartInfo *);\r
 void Mapper37_Init(CartInfo *);\r
+void Mapper38_Init(CartInfo *);\r
+void Mapper43_Init(CartInfo *);\r
 void Mapper44_Init(CartInfo *);\r
 void Mapper45_Init(CartInfo *);\r
 void Mapper47_Init(CartInfo *);\r
 void Mapper49_Init(CartInfo *);\r
 void Mapper52_Init(CartInfo *);\r
 void Mapper57_Init(CartInfo *);\r
 void Mapper44_Init(CartInfo *);\r
 void Mapper45_Init(CartInfo *);\r
 void Mapper47_Init(CartInfo *);\r
 void Mapper49_Init(CartInfo *);\r
 void Mapper52_Init(CartInfo *);\r
 void Mapper57_Init(CartInfo *);\r
-void Mapper58_Init(CartInfo *);\r
+//void Mapper58_Init(CartInfo *);\r
+void Mapper68_Init(CartInfo *);\r
 void Mapper70_Init(CartInfo *);\r
 void Mapper74_Init(CartInfo *);\r
 void Mapper78_Init(CartInfo *);\r
 void Mapper70_Init(CartInfo *);\r
 void Mapper74_Init(CartInfo *);\r
 void Mapper78_Init(CartInfo *);\r
@@ -340,27 +378,48 @@ void Mapper90_Init(CartInfo *);
 void Mapper93_Init(CartInfo *);\r
 void Mapper94_Init(CartInfo *);\r
 void Mapper95_Init(CartInfo *);\r
 void Mapper93_Init(CartInfo *);\r
 void Mapper94_Init(CartInfo *);\r
 void Mapper95_Init(CartInfo *);\r
+void Mapper101_Init(CartInfo *);\r
+void Mapper103_Init(CartInfo *);\r
 void Mapper105_Init(CartInfo *);\r
 void Mapper105_Init(CartInfo *);\r
+void Mapper106_Init(CartInfo *);\r
 void Mapper107_Init(CartInfo *);\r
 void Mapper107_Init(CartInfo *);\r
+void Mapper108_Init(CartInfo *);\r
 void Mapper112_Init(CartInfo *);\r
 void Mapper112_Init(CartInfo *);\r
+void Mapper113_Init(CartInfo *);\r
 void Mapper114_Init(CartInfo *);\r
 void Mapper115_Init(CartInfo *);\r
 void Mapper116_Init(CartInfo *);\r
 void Mapper117_Init(CartInfo *);\r
 void Mapper118_Init(CartInfo *);\r
 void Mapper119_Init(CartInfo *);\r
 void Mapper114_Init(CartInfo *);\r
 void Mapper115_Init(CartInfo *);\r
 void Mapper116_Init(CartInfo *);\r
 void Mapper117_Init(CartInfo *);\r
 void Mapper118_Init(CartInfo *);\r
 void Mapper119_Init(CartInfo *);\r
+void Mapper120_Init(CartInfo *);\r
+void Mapper121_Init(CartInfo *);\r
 void Mapper125_Init(CartInfo *);\r
 void Mapper125_Init(CartInfo *);\r
+void Mapper134_Init(CartInfo *);\r
 void Mapper140_Init(CartInfo *);\r
 void Mapper144_Init(CartInfo *);\r
 void Mapper152_Init(CartInfo *);\r
 void Mapper140_Init(CartInfo *);\r
 void Mapper144_Init(CartInfo *);\r
 void Mapper152_Init(CartInfo *);\r
+void Mapper153_Init(CartInfo *);\r
 void Mapper154_Init(CartInfo *);\r
 void Mapper155_Init(CartInfo *);\r
 void Mapper154_Init(CartInfo *);\r
 void Mapper155_Init(CartInfo *);\r
+void Mapper156_Init(CartInfo *);\r
+void Mapper159_Init(CartInfo *);\r
 void Mapper163_Init(CartInfo *);\r
 void Mapper164_Init(CartInfo *);\r
 void Mapper165_Init(CartInfo *);\r
 void Mapper163_Init(CartInfo *);\r
 void Mapper164_Init(CartInfo *);\r
 void Mapper165_Init(CartInfo *);\r
+//void Mapper169_Init(CartInfo *);\r
+void Mapper171_Init(CartInfo *);\r
+void Mapper172_Init(CartInfo *);\r
+void Mapper173_Init(CartInfo *);\r
+void Mapper175_Init(CartInfo *);\r
+void Mapper176_Init(CartInfo *);\r
+void Mapper177_Init(CartInfo *);\r
+void Mapper178_Init(CartInfo *);\r
+void Mapper180_Init(CartInfo *);\r
 void Mapper181_Init(CartInfo *);\r
 void Mapper181_Init(CartInfo *);\r
-void Mapper182_Init(CartInfo *);\r
+//void Mapper182_Init(CartInfo *);\r
 void Mapper183_Init(CartInfo *);\r
 void Mapper183_Init(CartInfo *);\r
+void Mapper184_Init(CartInfo *);\r
 void Mapper185_Init(CartInfo *);\r
 void Mapper186_Init(CartInfo *);\r
 void Mapper187_Init(CartInfo *);\r
 void Mapper185_Init(CartInfo *);\r
 void Mapper186_Init(CartInfo *);\r
 void Mapper187_Init(CartInfo *);\r
@@ -369,22 +428,31 @@ void Mapper189_Init(CartInfo *);
 void Mapper191_Init(CartInfo *);\r
 void Mapper192_Init(CartInfo *);\r
 void Mapper194_Init(CartInfo *);\r
 void Mapper191_Init(CartInfo *);\r
 void Mapper192_Init(CartInfo *);\r
 void Mapper194_Init(CartInfo *);\r
+void Mapper195_Init(CartInfo *);\r
+void Mapper196_Init(CartInfo *);\r
+void Mapper197_Init(CartInfo *);\r
 void Mapper198_Init(CartInfo *);\r
 void Mapper199_Init(CartInfo *);\r
 void Mapper198_Init(CartInfo *);\r
 void Mapper199_Init(CartInfo *);\r
+void Mapper200_Init(CartInfo *);\r
 void Mapper205_Init(CartInfo *);\r
 void Mapper208_Init(CartInfo *);\r
 void Mapper209_Init(CartInfo *);\r
 void Mapper210_Init(CartInfo *);\r
 void Mapper211_Init(CartInfo *);\r
 void Mapper205_Init(CartInfo *);\r
 void Mapper208_Init(CartInfo *);\r
 void Mapper209_Init(CartInfo *);\r
 void Mapper210_Init(CartInfo *);\r
 void Mapper211_Init(CartInfo *);\r
-void Mapper215_Init(CartInfo *);\r
+//void Mapper215_Init(CartInfo *);\r
 void Mapper216_Init(CartInfo *);\r
 void Mapper216_Init(CartInfo *);\r
-void Mapper217_Init(CartInfo *);\r
+//void Mapper217_Init(CartInfo *);\r
 void Mapper220_Init(CartInfo *);\r
 void Mapper222_Init(CartInfo *);\r
 void Mapper220_Init(CartInfo *);\r
 void Mapper222_Init(CartInfo *);\r
+void Mapper226_Init(CartInfo *);\r
 void Mapper235_Init(CartInfo *);\r
 void Mapper236_Init(CartInfo *);\r
 void Mapper237_Init(CartInfo *);\r
 void Mapper235_Init(CartInfo *);\r
 void Mapper236_Init(CartInfo *);\r
 void Mapper237_Init(CartInfo *);\r
+void Mapper240_Init(CartInfo *);\r
 void Mapper245_Init(CartInfo *);\r
 void Mapper249_Init(CartInfo *);\r
 void Mapper250_Init(CartInfo *);\r
 void Mapper245_Init(CartInfo *);\r
 void Mapper249_Init(CartInfo *);\r
 void Mapper250_Init(CartInfo *);\r
+void Mapper253_Init(CartInfo *);\r
 void Mapper254_Init(CartInfo *);\r
 void Mapper254_Init(CartInfo *);\r
+\r
+#endif\r
diff --git a/mappers/113.c b/mappers/113.c
deleted file mode 100644 (file)
index 525f131..0000000
+++ /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 (file)
index e649af6..0000000
+++ /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);
-}
-
index 5d2cb28..91938d5 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
diff --git a/mappers/156.c b/mappers/156.c
new file mode 100644 (file)
index 0000000..8e40a19
--- /dev/null
@@ -0,0 +1,126 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2009 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * DIS23C01 DAOU ROM CONTROLLER, Korea\r
+ * Metal Force (K)\r
+ * Buzz and Waldog (K)\r
+ * General's Son (K)\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0;\r
+// uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&prg, 1, "PREG"},\r
+  {chrlo, 8, "CRLO"},\r
+  {chrhi, 8, "CRHI"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint32 i;\r
+  for(i=0; i<8; i++)\r
+    setchr1(i<<10, chrlo[i]|(chrhi[i] << 8));\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg16(0x8000,prg);\r
+  setprg16(0xC000,~0);\r
+  if(mirrisused)\r
+    setmirror(mirr ^ 1);\r
+  else\r
+    setmirror(MI_0);\r
+}\r
+\r
+static DECLFW(M156Write)\r
+{\r
+  switch(A) {\r
+   case 0xC000:\r
+   case 0xC001:\r
+   case 0xC002:\r
+   case 0xC003: chrlo[A&3] = V; Sync(); break;\r
+   case 0xC004:\r
+   case 0xC005:\r
+   case 0xC006:\r
+   case 0xC007: chrhi[A&3] = V; Sync(); break;\r
+   case 0xC008:\r
+   case 0xC009:\r
+   case 0xC00A:\r
+   case 0xC00B: chrlo[4+(A&3)] = V; Sync(); break;\r
+   case 0xC00C:\r
+   case 0xC00D:\r
+   case 0xC00E:\r
+   case 0xC00F: chrhi[4+(A&3)] = V; Sync(); break;\r
+   case 0xC010: prg = V; Sync(); break;\r
+   case 0xC014: mirr = V; mirrisused = 1; Sync(); break;\r
+  }\r
+}\r
+\r
+static void M1566Reset()\r
+{\r
+       for(int i=0;i<8;i++)\r
+       {\r
+               chrlo[i]=0;\r
+               chrhi[i]=0;\r
+       }\r
+       prg=0;\r
+       mirr=0;\r
+       mirrisused = 0;\r
+}\r
+\r
+static void M156Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x6000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetWriteHandler(0xC000,0xCFFF,M156Write);\r
+\r
+       M1566Reset();\r
+}\r
+\r
+static void M156Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper156_Init(CartInfo *info)\r
+{\r
+  info->Power=M156Power;\r
+  info->Close=M156Close;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index 2e8d013..002d3cb 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
-static void FP_FASTAPASS(1) BandaiIRQHook(int a)
+static void BandaiIRQHook(int a)
 {
   if(IRQa)
   {
 {
   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).
 // 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;
 static void PRGO(void)
 {
  uint32 base=(mapbyte1[0]&1)<<4;
@@ -110,21 +110,21 @@ static DECLFW(Mapper153_write)
                    IRQLatch|=V<<8;
                   break;
         }
                    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. */
  /* 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];
 
 
 static uint8 BarcodeData[256];
@@ -260,7 +260,7 @@ int FCEUI_DatachSet(const uint8 *rcode)
         return(1);
 }
 
         return(1);
 }
 
-static void FP_FASTAPASS(1) BarcodeIRQHook(int a)
+static void BarcodeIRQHook(int a)
 {
  BandaiIRQHook(a);
 
 {
  BandaiIRQHook(a);
 
@@ -291,7 +291,7 @@ static DECLFR(Mapper157_read)
 
 void Mapper157_init(void)
 {
 
 void Mapper157_init(void)
 {
FCEUGameInfo.cspecial = SIS_DATACH;
GameInfo->cspecial = SIS_DATACH;
  MapIRQHook=BarcodeIRQHook;
  SetWriteHandler(0x6000,0xFFFF,Mapper16_write);
  SetReadHandler(0x6000,0x7FFF,Mapper157_read);
  MapIRQHook=BarcodeIRQHook;
  SetWriteHandler(0x6000,0xFFFF,Mapper16_write);
  SetReadHandler(0x6000,0x7FFF,Mapper157_read);
index 7fae1a8..c20bc28 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
 
 
-static void FP_FASTAPASS(1) FFEIRQHook(int a)
+static void FFEIRQHook(int a)
 {
   if(IRQa)
   {
 {
   if(IRQa)
   {
index b682b26..030c055 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -23,7 +23,7 @@
 #define K4buf mapbyte2
 #define K4buf2 mapbyte3
 
 #define K4buf mapbyte2
 #define K4buf2 mapbyte3
 
-void FP_FASTAPASS(1) JalecoIRQHook(int a)
+void JalecoIRQHook(int a)
 {
   if(IRQa && IRQCount)
   {
 {
   if(IRQa && IRQCount)
   {
diff --git a/mappers/180.c b/mappers/180.c
deleted file mode 100644 (file)
index bd877c8..0000000
+++ /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 (file)
index e69de29..0000000
diff --git a/mappers/184.c b/mappers/184.c
deleted file mode 100644 (file)
index 70fd6b1..0000000
+++ /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 (file)
index ec13308..0000000
+++ /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);
-}
-
index 03e77e6..d566470 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -37,8 +37,8 @@ static DECLFW(Mapper201_write)
 
 void Mapper201_init(void)
 {
 
 void Mapper201_init(void)
 {
-  ROM_BANK32(0);
-  VROM_BANK8(0);
+  ROM_BANK32(~0);
+  VROM_BANK8(~0);
   SetWriteHandler(0x8000,0xffff,Mapper201_write);
 }
 
   SetWriteHandler(0x8000,0xffff,Mapper201_write);
 }
 
index cac2a88..7c02f97 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 6ab5d52..0187b8a 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index edca423..543364b 100644 (file)
@@ -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\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2003 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static DECLFW(Mapper204_write)\r
+{\r
+ int tmp2=A&0x6;\r
+ int tmp1=tmp2+((tmp2==0x6)?0:(A&1));\r
+ MIRROR_SET((A>>4)&1);\r
+ ROM_BANK16(0x8000,tmp1);\r
+ ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1)));\r
+ VROM_BANK8(tmp1);\r
+}\r
+\r
+void Mapper204_init(void)\r
+{\r
+ ROM_BANK32(~0);\r
+ VROM_BANK8(~0);\r
+ SetWriteHandler(0x8000,0xFFFF,Mapper204_write);\r
+}\r
index 8d60d4c..c8b8cd9 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -82,7 +82,7 @@ DECLFW(Mapper21_write)
          case 0xf006:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break;
  }
 }
          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
 {
   #define LCYCS ((227*2)+1)
   //#define LCYCS 341
index e5677b6..b069fc3 100644 (file)
@@ -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"\r
+\r
+static DECLFW(Mapper212_write)\r
+{\r
+  if((A&0x4000)==0x4000)\r
+   {\r
+     ROM_BANK32((A&6)>>1);\r
+   }\r
+  else\r
+   {\r
+     ROM_BANK16(0x8000,A&7);\r
+     ROM_BANK16(0xc000,A&7);\r
+   }\r
+ VROM_BANK8(A&7);\r
+ MIRROR_SET((A>>3)&1);\r
+}\r
+\r
+void Mapper212_init(void)\r
+{\r
+ ROM_BANK32(~0);\r
+ VROM_BANK8(~0);\r
+ SetWriteHandler(0x8000,0xFFFF,Mapper212_write);\r
+}\r
index c537f6c..e0b8d82 100644 (file)
@@ -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"\r
+\r
+static DECLFW(Mapper213_write)\r
+{\r
+ ROM_BANK32((A>>1)&3);\r
+ VROM_BANK8((A>>3)&7);\r
+}\r
+\r
+void Mapper213_init(void)\r
+{\r
+ ROM_BANK32(0);\r
+ VROM_BANK8(0);\r
+ SetWriteHandler(0x8000,0xFFFF,Mapper213_write);\r
+}\r
index deaf47d..03a73ce 100644 (file)
@@ -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"\r
+\r
+static DECLFW(Mapper214_write)\r
+{\r
+// FCEU_printf("%02x:%02x\n",A,V);\r
+ ROM_BANK16(0x8000,(A>>2)&3);\r
+ ROM_BANK16(0xC000,(A>>2)&3);\r
+ VROM_BANK8(A&3);\r
+}\r
+\r
+void Mapper214_init(void)\r
+{\r
+ ROM_BANK16(0x8000,0);\r
+ ROM_BANK16(0xC000,0);\r
+ VROM_BANK8(0);\r
+ SetWriteHandler(0x8000,0xFFFF,Mapper214_write);\r
+}\r
index c9c3297..1bf4cbd 100644 (file)
@@ -94,4 +94,3 @@ void Mapper217_init(void)
   DoCHR217();
 }
 */
   DoCHR217();
 }
 */
-
index 4a08094..eee5365 100644 (file)
@@ -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
  *
  * You 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"
  */
 
 #include "mapinc.h"
index 14e38f2..60c97c8 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -58,7 +58,7 @@ DECLFW(Mapper225_write)
  else
   banks=0;
 
  else
   banks=0;
 
 VROM_BANK8(((A&0x003f)+(banks<<6)));
+ VROM_BANK8(((A&0x003f)+(banks<<6)));
  if(A&0x1000)
   {
    if(A&0x40)
  if(A&0x1000)
   {
    if(A&0x40)
diff --git a/mappers/226.c b/mappers/226.c
deleted file mode 100644 (file)
index bde4f52..0000000
+++ /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
index 457e79e..8b5cff9 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
+//zero 14-apr-2012 - redid this entirely to match bizhawk
+
 #define rg mapbyte1
 
 static void DoSync(uint32 A)
 {
 #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);
 
  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)
 {
 }
 
 static DECLFW(Mapper227_write)
 {
- rg[A&1]=V;
  DoSync(A);
 }
 
 static void M227Reset(void)
 {
  DoSync(A);
 }
 
 static void M227Reset(void)
 {
- rg[0]=rg[1]=0;
  DoSync(0);
 }
 
  DoSync(0);
 }
 
@@ -72,7 +87,7 @@ static void M227Restore(int version)
 
 void Mapper227_init(void)
 {
 
 void Mapper227_init(void)
 {
-  SetWriteHandler(0x6000,0xffff,Mapper227_write);
+  SetWriteHandler(0x8000,0xffff,Mapper227_write);
   MapperReset=M227Reset;
   GameStateRestore=M227Restore;
   M227Reset();
   MapperReset=M227Reset;
   GameStateRestore=M227Restore;
   M227Reset();
index bfae3a6..a63218e 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "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)
 {
 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)
 {
 }
 
 static void A52Reset(void)
 {
Mapper228_write(0,0);
   Mapper228_write(0x8000, 0);
 }
 
 void Mapper228_init(void)
 {
 }
 
 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);
 }
 
 }
 
index a78dd73..acc31a3 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
diff --git a/mappers/23.c b/mappers/23.c
deleted file mode 100644 (file)
index d61a555..0000000
+++ /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;
-}
-
index cbf1fbe..32550e5 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 9b8d1fc..0f467ec 100644 (file)
@@ -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
  *      
  * You 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 "mapinc.h"
index 548db8c..6beafb2 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index d8ca53f..1835d57 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
diff --git a/mappers/240.c b/mappers/240.c
deleted file mode 100644 (file)
index dbbfe19..0000000
+++ /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);
-}
-
index 2fa4171..72c0be5 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
 DECLFW(Mapper242_write)
 {
   ROM_BANK32((A>>3)&0xF);
 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 0:MIRROR_SET(0);break;
    case 1:MIRROR_SET(1);break;
-   case 2:onemir(0);break;
-   case 3:onemir(1);break;
   }
 }
 
   }
 }
 
index 13ea2c1..68a7563 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 8623233..4ae017e 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 3368856..115ead0 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -34,7 +34,7 @@ static int swaparoo;
 
 static int acount=0;
 
 
 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)
 {
   #define LCYCS 341
 //  #define LCYCS ((227*2)+1)
@@ -222,10 +222,9 @@ static void DoSawV(void)
    }
 }
 
    }
 }
 
-#if 0
 static INLINE void DoSQVHQ(int x)
 {
 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)
  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;
 {
  static uint8 b3=0;
  static int32 phaseacc=0;
- int32 V;
+ uint32 V; //mbg merge 7/17/06 made uint32
 
  if(VPSG2[2]&0x80)
  {
 
  if(VPSG2[2]&0x80)
  {
@@ -292,7 +291,6 @@ static void DoSawVHQ(void)
  }
  CVBC[2]=SOUNDTS;
 }
  }
  CVBC[2]=SOUNDTS;
 }
-#endif
 
 
 void VRC6Sound(int Count)
 
 
 void VRC6Sound(int Count)
@@ -306,7 +304,6 @@ void VRC6Sound(int Count)
      CVBC[x]=Count;
 }
 
      CVBC[x]=Count;
 }
 
-#if 0
 void VRC6SoundHQ(void)
 {
     DoSQV1HQ();
 void VRC6SoundHQ(void)
 {
     DoSQV1HQ();
@@ -319,21 +316,19 @@ void VRC6SyncHQ(int32 ts)
  int x;
  for(x=0;x<3;x++) CVBC[x]=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;
 
 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)
         {
 
         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;
          if(FSettings.soundq>=1)
          {
           sfun[0]=DoSQV1HQ;
@@ -341,7 +336,6 @@ static void VRC6_ESI(void)
           sfun[2]=DoSawVHQ;
          }
          else
           sfun[2]=DoSawVHQ;
          }
          else
-#endif
          {
           sfun[0]=DoSQV1;
           sfun[1]=DoSQV2;
          {
           sfun[0]=DoSQV1;
           sfun[1]=DoSQV2;
index f8c1d73..e099cc9 100644 (file)
@@ -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
  *
  * You 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"
  */
 
 #include "mapinc.h"
 #define K4sel mapbyte1[0]
 
 static int acount=0;
 #define K4sel mapbyte1[0]
 
 static int acount=0;
+static int weirdo=0;
 static DECLFW(Mapper25_write)
 {
 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);
 
         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);
 
          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)
         {
         }
         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
 {
 //  #define LCYCS ((227*2))
   #define LCYCS 341
index d65f18d..405340e 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 4b5cd73..e1afc22 100644 (file)
@@ -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"\r
+\r
+static uint32 regchr[9];\r
+\r
+static DECLFW(Mapper27_write)\r
+{\r
+ int regnum;\r
+ A&=0xF00F;\r
+ if((A>=0xB000) && (A<=0xE003)) {\r
+    regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1);\r
+    if(A&1)\r
+       regchr[regnum]=(regchr[regnum]&0x00F)|(V<<4);\r
+    else\r
+       regchr[regnum]=(regchr[regnum]&0x1F0)|(V&0xF);\r
+    VROM_BANK1(regnum<<10,regchr[regnum]);\r
+ }\r
+ switch(A)\r
+ {\r
+  case 0x8000: ROM_BANK8(0x8000|((regchr[8]&2)<<13),V); break;\r
+  case 0xA000: ROM_BANK8(0xa000,V); break;\r
+  case 0x9000: switch(V&3){\r
+                  case 0:setmirror(MI_V);break;\r
+                  case 1:setmirror(MI_H);break;\r
+                  case 2:setmirror(MI_0);break;\r
+                  case 3:setmirror(MI_1);break;\r
+               }\r
+  case 0x9002: regchr[8]=V; break;\r
+  case 0xF000: //X6502_IRQEnd(FCEU_IQEXT);\r
+               IRQLatch=(IRQLatch&0xF0)|(V&0x0F);\r
+                           break;\r
+  case 0xF001: //X6502_IRQEnd(FCEU_IQEXT);\r
+               IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4);\r
+                           break;\r
+  case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1);\r
+                           X6502_IRQEnd(FCEU_IQEXT);\r
+               break;\r
+  case 0xF002: IRQa=V&3;\r
+                           if(IRQa&0x02) IRQCount=IRQLatch-1;\r
+//                           X6502_IRQEnd(FCEU_IQEXT);\r
+                           break;\r
+ }\r
+// if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline);\r
+}\r
+\r
+static void Mapper27_hb(void)\r
+{\r
+//   FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch);\r
+        if(IRQa&0x2){\r
+           if(IRQCount==0xFF){\r
+             X6502_IRQBegin(FCEU_IQEXT);\r
+              IRQCount=IRQLatch+1;\r
+         } else {\r
+           IRQCount++;\r
+           }\r
+        }\r
+}\r
+\r
+void Mapper27_init(void)\r
+{\r
+  int i;\r
+  for (i=0; i<9; i++) {\r
+    regchr[i]=0;\r
+  }\r
+  IRQa=0;\r
+  IRQCount=IRQLatch=0;\r
+  SetWriteHandler(0x8000,0xffff,Mapper27_write);\r
+  GameHBIRQHook=Mapper27_hb;\r
+}\r
+\r
index 13e4bba..b538947 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index f3362c0..1324663 100644 (file)
@@ -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
  *
  * You 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 "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 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)
 {
 
 void Mapper48_init(void)
 {
-        SetWriteHandler(0x8000,0xffff,Mapper33_write);
+        SetWriteHandler(0x8000,0xbfff,Mapper33_write);
         SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite);
         GameHBIRQHook=heho;
         is48=1;
         SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite);
         GameHBIRQHook=heho;
         is48=1;
index 471a7cc..9cdc24c 100644 (file)
@@ -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
  *
  * You 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 "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)
  {
 {
  if(IRQa)
  {
index dfb6908..84aed5d 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index bf31ac2..10774bd 100644 (file)
@@ -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
  *
  * You 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 "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)
  {
 {
  if(IRQa)
  {
diff --git a/mappers/43.c b/mappers/43.c
deleted file mode 100644 (file)
index ef7d40d..0000000
+++ /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;
-}
index 8c4ef6d..7e1a907 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 8d7f515..629d86d 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
 
-static void FP_FASTAPASS(1) Mapper50IRQ(int a)
+static void Mapper50IRQ(int a)
 {
  if(IRQa)
  {
 {
  if(IRQa)
  {
index cc1fbbd..c2c723e 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 30ddb8b..4dd9e95 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index c6c5bf5..35fd900 100644 (file)
@@ -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
  *
  * You 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 "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;}
 
 
 #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)
   {
 {
   if(IRQa)
   {
index b48087c..a2b2ee1 100644 (file)
@@ -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
  *
  * You 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)
 #include "mapinc.h"
 
 static DECLFW(Mapper60_write)
@@ -37,5 +37,5 @@ void Mapper60_init(void)
         ROM_BANK32(0);
         SetWriteHandler(0x8000,0xffff, Mapper60_write);
 }
         ROM_BANK32(0);
         SetWriteHandler(0x8000,0xffff, Mapper60_write);
 }
-
+*/
 
 
index 4303932..10b9e6d 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 4d03c88..6da991c 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index d817694..1a8cb8b 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
 
-void FP_FASTAPASS(1) IREMIRQHook(int a)
+void IREMIRQHook(int a)
 {
   if(IRQa)
   {
 {
   if(IRQa)
   {
index 9d560f9..ee2390a 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -58,7 +58,7 @@ static DECLFW(Mapper67_write)
   case 0xf800:ROM_BANK16(0x8000,V);break;
  }
 }
   case 0xf800:ROM_BANK16(0x8000,V);break;
  }
 }
-static void FP_FASTAPASS(1) SunIRQHook(int a)
+static void SunIRQHook(int a)
 {
   if(IRQa)
   {
 {
   if(IRQa)
   {
diff --git a/mappers/68.c b/mappers/68.c
deleted file mode 100644 (file)
index 69eaefc..0000000
+++ /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;
-}
index 948c304..5d15243 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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);
  */
 
 #include "mapinc.h"
 
 static void AYSound(int Count);
-//static void AYSoundHQ(void);
+static void AYSoundHQ(void);
 static void DoAYSQ(int x);
 static void DoAYSQ(int x);
-//static void DoAYSQHQ(int x);
+static void DoAYSQHQ(int x);
 
 #define sunselect mapbyte1[0]
 #define sungah    mapbyte1[1]
 
 #define sunselect mapbyte1[0]
 #define sungah    mapbyte1[1]
@@ -39,7 +39,7 @@ static DECLFR(SUN5AWRAM)
 {
  if((sungah&0xC0)==0x40)
   return X.DB;
 {
  if((sungah&0xC0)==0x40)
   return X.DB;
- return CartBR(A);
+ return CartBROB(A);
 }
 
 static DECLFW(Mapper69_SWL)
 }
 
 static DECLFW(Mapper69_SWL)
@@ -51,22 +51,22 @@ static DECLFW(Mapper69_SWH)
 {
              int x;
              GameExpSound.Fill=AYSound;
 {
              int x;
              GameExpSound.Fill=AYSound;
-             GameExpSound.HiFill=0;//AYSoundHQ;
-             if(FSettings.SndRate);
+             GameExpSound.HiFill=AYSoundHQ;
+             if(FSettings.SndRate)
              switch(sunindex)
              {
               case 0:
               case 1:
              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 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 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++)
               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;
                      break;
              }
              MapperExRAM[sunindex]=V;
@@ -133,7 +133,6 @@ static void DoAYSQ(int x)
     CAYBC[x]=end;
 
     if(amp)
     CAYBC[x]=end;
 
     if(amp)
-       if(!(MapperExRAM[0x7]&(1<<x)))
     for(V=start;V<end;V++)
     {
      if(dcount[x])
     for(V=start;V<end;V++)
     {
      if(dcount[x])
@@ -147,10 +146,9 @@ static void DoAYSQ(int x)
     }
 }
 
     }
 }
 
-#if 0
 static void DoAYSQHQ(int x)
 {
 static void DoAYSQHQ(int x)
 {
- int32 V;
+ uint32 V; //mbg merge 7/17/06 made uitn32
  int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<4;
  int32 amp=(MapperExRAM[0x8+x]&15)<<6;
 
  int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<4;
  int32 amp=(MapperExRAM[0x8+x]&15)<<6;
 
@@ -172,7 +170,6 @@ static void DoAYSQHQ(int x)
  }
  CAYBC[x]=SOUNDTS;
 }
  }
  CAYBC[x]=SOUNDTS;
 }
-#endif
 
 static void AYSound(int Count)
 {
 
 static void AYSound(int Count)
 {
@@ -184,14 +181,12 @@ static void AYSound(int Count)
      CAYBC[x]=Count;
 }
 
      CAYBC[x]=Count;
 }
 
-#if 0
 static void AYSoundHQ(void)
 {
     DoAYSQHQ(0);
     DoAYSQHQ(1);
     DoAYSQHQ(2);
 }
 static void AYSoundHQ(void)
 {
     DoAYSQHQ(0);
     DoAYSQHQ(1);
     DoAYSQHQ(2);
 }
-#endif
 
 static void AYHiSync(int32 ts)
 {
 
 static void AYHiSync(int32 ts)
 {
@@ -201,7 +196,7 @@ static void AYHiSync(int32 ts)
   CAYBC[x]=ts;
 }
 
   CAYBC[x]=ts;
 }
 
-static void FP_FASTAPASS(1) SunIRQHook(int a)
+static void SunIRQHook(int a)
 {
   if(IRQa)
   {
 {
   if(IRQa)
   {
index 9b1a99d..05b46a3 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 480a035..857f800 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index b49fa24..dc87fed 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -38,7 +38,7 @@ static DECLFW(Mapper73_write)
  }
 }
 
  }
 }
 
-static void FP_FASTAPASS(1) Mapper73IRQHook(int a)
+static void Mapper73IRQHook(int a)
 {
  if(IRQa)
  {
 {
  if(IRQa)
  {
index f2b00bd..9b5a31c 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index a59ef1e..8dd75d8 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 06f15cc..be6cd36 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 9148eae..9e8412a 100644 (file)
@@ -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
  *
  * You 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
+ * TXC mapper variation, F-15 City War
  */
 
 #include "mapinc.h"
  */
 
 #include "mapinc.h"
index 53c91a2..a8f9cb8 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 1e7982e..d569fa0 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -24,7 +24,7 @@ static uint32 lastA;
 static int isfu;
 static uint8 CCache[8];
 
 static int isfu;
 static uint8 CCache[8];
 
-static void FP_FASTAPASS(1) Fudou_PPU(uint32 A)
+static void Fudou_PPU(uint32 A)
 {
  static int last=-1;
  static uint8 z;
 {
  static int last=-1;
  static uint8 z;
@@ -87,7 +87,8 @@ static void booga(int version)
 
 void Mapper80_init(void)
 {
 
 void Mapper80_init(void)
 {
- SetWriteHandler(0x4020,0x7fff,Mapper80_write);
+ SetWriteHandler(0x4020,0x7eff,Mapper80_write);// 7f00-7fff battery backed ram inside mapper chip,\r
+                                               // controlled by 7ef8 register, A8 - enable, FF - disable (?)\r
  MapStateRestore=booga;
  isfu=0;
 }
  MapStateRestore=booga;
  isfu=0;
 }
index b4288b1..674b677 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 9a3bcd7..ca26388 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You 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 "mapinc.h"
 
+static uint8 is2kbank, isnot2kbank, dipreg;
 
 /*void Mapper83_init(void)
 {             
  
 } 
 */
 
 /*void Mapper83_init(void)
 {             
  
 } 
 */
-static void FP_FASTAPASS(1) m83IRQHook(int a)
+static void m83IRQHook(int a)
 {
   if(IRQa)
   {
 {
   if(IRQa)
   {
@@ -50,6 +51,11 @@ static DECLFR(rdlow)
  return mapbyte4[A&3];
 }
 
  return mapbyte4[A&3];
 }
 
+static DECLFR(rd5000)
+{
+ return dipreg;
+}
+
 static void m83prg(void)
 {
   ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); 
 static void m83prg(void)
 {
   ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); 
@@ -58,19 +64,19 @@ static void m83prg(void)
 
 static void m83chr(void)
 {
 
 static void m83chr(void)
 {
-//  if(0)
-//  {
-//    VROM_BANK2(0x0000,mapbyte2[0]);
-//    VROM_BANK2(0x0800,mapbyte2[1]);
-//    VROM_BANK2(0x1000,mapbyte2[6]);
-//    VROM_BANK2(0x1800,mapbyte2[7]);
-//  }
-//  else
-//  {
+  if(is2kbank&&!isnot2kbank)
+  {
+    VROM_BANK2(0x0000,mapbyte2[0]);
+    VROM_BANK2(0x0800,mapbyte2[1]);
+    VROM_BANK2(0x1000,mapbyte2[6]);
+    VROM_BANK2(0x1800,mapbyte2[7]);
+  }
+  else
+  {
     int x;
     for(x=0;x<8;x++)
        VROM_BANK1(x*0x400,mapbyte2[x]|((mapbyte1[0]&0x30)<<4));
     int x;
     for(x=0;x<8;x++)
        VROM_BANK1(x*0x400,mapbyte2[x]|((mapbyte1[0]&0x30)<<4));
-//  }
+  }
 }
 
 static DECLFW(Mapper83_write)
 }
 
 static DECLFW(Mapper83_write)
@@ -78,7 +84,7 @@ static DECLFW(Mapper83_write)
  //printf("$%04x:$%02x\n",A,V);
  switch(A)
  {
  //printf("$%04x:$%02x\n",A,V);
  switch(A)
  {
-  case 0x8000:
+  case 0x8000: is2kbank = 1;
   case 0xB000:
   case 0xB0FF:
   case 0xB1FF:
   case 0xB000:
   case 0xB0FF:
   case 0xB1FF:
@@ -105,10 +111,10 @@ static DECLFW(Mapper83_write)
   case 0x8302:ROM_BANK8(0xC000,V);break;
   case 0x8310:mapbyte2[0]=V;m83chr();break;
   case 0x8311:mapbyte2[1]=V;m83chr();break;
   case 0x8302:ROM_BANK8(0xC000,V);break;
   case 0x8310:mapbyte2[0]=V;m83chr();break;
   case 0x8311:mapbyte2[1]=V;m83chr();break;
-  case 0x8312:mapbyte2[2]=V;m83chr();break;
-  case 0x8313:mapbyte2[3]=V;m83chr();break;
-  case 0x8314:mapbyte2[4]=V;m83chr();break;
-  case 0x8315:mapbyte2[5]=V;m83chr();break;
+  case 0x8312:mapbyte2[2]=V;isnot2kbank = 1;m83chr();break; // 2 mappers in one :)
+  case 0x8313:mapbyte2[3]=V;isnot2kbank = 1;m83chr();break;
+  case 0x8314:mapbyte2[4]=V;isnot2kbank = 1;m83chr();break;
+  case 0x8315:mapbyte2[5]=V;isnot2kbank = 1;m83chr();break;
   case 0x8316:mapbyte2[6]=V;m83chr();break;
   case 0x8317:mapbyte2[7]=V;m83chr();break;
   case 0x8318:mapbyte1[1]=V;m83prg();break;
   case 0x8316:mapbyte2[6]=V;m83chr();break;
   case 0x8317:mapbyte2[7]=V;m83chr();break;
   case 0x8318:mapbyte1[1]=V;m83prg();break;
@@ -117,13 +123,23 @@ static DECLFW(Mapper83_write)
  
 }
 
  
 }
 
+static void m83Reset(void)
+{
+ dipreg^=1;
+}
+
 void Mapper83_init(void)
 {
 void Mapper83_init(void)
 {
+ is2kbank = 0;
+ isnot2kbank = 0;
+ dipreg = 0;
  ROM_BANK8(0xc000,0x1e);
  ROM_BANK8(0xe000,0x1f);
 
  MapIRQHook=m83IRQHook;
  ROM_BANK8(0xc000,0x1e);
  ROM_BANK8(0xe000,0x1f);
 
  MapIRQHook=m83IRQHook;
+ MapperReset=m83Reset;
 
 
+ SetReadHandler(0x5000,0x5000,rd5000); // title scren dip switch
  SetReadHandler(0x5100,0x5103,rdlow);
  SetWriteHandler(0x5100,0x5103,wrlow);
  SetWriteHandler(0x8000,0xffff,Mapper83_write);
  SetReadHandler(0x5100,0x5103,rdlow);
  SetWriteHandler(0x5100,0x5103,wrlow);
  SetWriteHandler(0x8000,0xffff,Mapper83_write);
index e2ae206..dfe6434 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -34,11 +34,11 @@ void DoVRC7Sound(void)
 {
  int32 z,a;
 
 {
  int32 z,a;
 
//if(FSettings.soundq>=1) return;
+ if(FSettings.soundq>=1) return;
  z=((SOUNDTS<<16)/soundtsinc)>>4;
  a=z-dwave;
 
  z=((SOUNDTS<<16)/soundtsinc)>>4;
  a=z-dwave;
 
- moocow(VRC7Sound, (int32 *)&Wave[dwave], a, 1);
+ moocow(VRC7Sound, &Wave[dwave], a, 1);
 
  dwave+=a;
 }
 
  dwave+=a;
 }
@@ -56,7 +56,7 @@ void UpdateOPL(int Count)
  a=z-dwave;
 
  if(VRC7Sound && a)
  a=z-dwave;
 
  if(VRC7Sound && a)
-  moocow(VRC7Sound, (int32 *)&Wave[dwave], a, 1);
+  moocow(VRC7Sound, &Wave[dwave], a, 1);
 
  dwave=0;
 }
 
  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)
 {
   #define ACBOO 341
 //  #define ACBOO ((227*2)+1)
index 8404985..f95b639 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index a3a6f09..e742735 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 8858103..6dc7fc9 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index e2ad374..1230836 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 2990c0e..f0e7beb 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 7a55536..6f3081f 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
index 4bee951..242915a 100644 (file)
@@ -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/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/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/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/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/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/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/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/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/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/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/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/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/69.c
+MM_C += mappers/6.c
 MM_C += mappers/71.c
 MM_C += mappers/72.c
 MM_C += mappers/73.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/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/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
 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/emu2413.c
 MM_C += mappers/mmc2and4.c
 MM_C += mappers/simple.c
+MM_C += mappers/156.c
 
 MOBJS += $(patsubst %.c,%.o,$(MM_C))
 
 
 MOBJS += $(patsubst %.c,%.o,$(MM_C))
 
index 022d736..d34cc6b 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -25,7 +25,7 @@
 #define latcha2 mapbyte2[1]
 
 
 #define latcha2 mapbyte2[1]
 
 
-static void FP_FASTAPASS(1) latchcheck(uint32 VAddr)
+static void latchcheck(uint32 VAddr)
 {
      uint8 l,h;
 
 {
      uint8 l,h;
 
index c393d09..8310fbb 100644 (file)
@@ -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
  *
  * You 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 "mapinc.h"
@@ -55,7 +55,7 @@ static DECLFW(Mapper96_write)
  setchr4r(0x10,0x1000,(latche&4)|3);
 }
 
  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;
 {
  if((A&0x3000)!=0x2000) return;
  //if((A&0x3ff)>=0x3c0) return;
@@ -83,18 +83,6 @@ void Mapper96_init(void)
  GameStateRestore=M96Sync;
 }
 
  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 (file)
--- a/svga.h
+++ b/svga.h
@@ -41,6 +41,7 @@ typedef struct {
           int UsrLastSLine[2];
           int SnapName;
           unsigned int SndRate;
           int UsrLastSLine[2];
           int SnapName;
           unsigned int SndRate;
+          int soundq;
 } FCEUS;
 
 extern FCEUS FSettings;
 } FCEUS;
 
 extern FCEUS FSettings;
diff --git a/types.h b/types.h
index 485b019..76eb7ed 100644 (file)
--- a/types.h
+++ b/types.h
@@ -35,6 +35,10 @@ typedef uint32_t uint32;
 //typedef unsigned short uint16;
 //typedef unsigned long  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;
 #ifdef __GNUC__
  typedef unsigned long long uint64;
  typedef long long int64;
diff --git a/unif.c b/unif.c
index 03430f5..6354131 100644 (file)
--- a/unif.c
+++ b/unif.c
@@ -1,22 +1,22 @@
 /* FCE Ultra - NES/Famicom Emulator\r
 /* FCE Ultra - NES/Famicom Emulator\r
- *\r
- * Copyright notice for this file:\r
- *  Copyright (C) 2002 Xodnizel\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
+*\r
+* Copyright notice for this file:\r
+*  Copyright (C) 2002 Xodnizel\r
+*\r
+* This program is free software; you can redistribute it and/or modify\r
+* it under the terms of the GNU General Public License as published by\r
+* the Free Software Foundation; either version 2 of the License, or\r
+* (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+*/\r
 \r
 /* TODO:  Battery backup file saving, mirror force    */\r
 /* **INCOMPLETE**             */\r
 \r
 /* TODO:  Battery backup file saving, mirror force    */\r
 /* **INCOMPLETE**             */\r
 #include <string.h>\r
 \r
 \r
 #include <string.h>\r
 \r
 \r
-#include  "types.h"\r
-#include  "fce.h"\r
-#include  "cart.h"\r
-#include  "unif.h"\r
-#include  "ines.h"\r
-#include  "general.h"\r
-#include  "state.h"\r
-#include  "endian.h"\r
-#include  "file.h"\r
-#include  "memory.h"\r
-#include  "input.h"\r
-#include  "md5.h"\r
-\r
-#include  "svga.h"\r
+#include "types.h"\r
+#include "fce.h"\r
+#include "cart.h"\r
+#include "unif.h"\r
+#include "ines.h"\r
+#include "endian.h"\r
+#include "memory.h"\r
+#include "md5.h"\r
+#include "state.h"\r
+#include "file.h"\r
+#include "input.h"\r
+#include "driver.h"\r
+#include "svga.h"\r
 \r
 typedef struct {\r
 \r
 typedef struct {\r
-           char ID[4];\r
-           uint32 info;\r
+       char ID[4];\r
+       uint32 info;\r
 } UNIF_HEADER;\r
 \r
 typedef struct {\r
 } UNIF_HEADER;\r
 \r
 typedef struct {\r
-           char *name;\r
-           void (*init)(CartInfo *);\r
-          int flags;\r
+       char *name;\r
+       void (*init)(CartInfo *);\r
+       int flags;\r
 } BMAPPING;\r
 \r
 typedef struct {\r
 } BMAPPING;\r
 \r
 typedef struct {\r
-           char *name;\r
-           int (*init)(int fp);\r
+       char *name;\r
+       int (*init)(int fp);\r
 } BFMAPPING;\r
 \r
 static CartInfo UNIFCart;\r
 \r
 static int vramo;\r
 static int mirrortodo;\r
 } BFMAPPING;\r
 \r
 static CartInfo UNIFCart;\r
 \r
 static int vramo;\r
 static int mirrortodo;\r
-static char *boardname;\r
-static char *sboardname;\r
+static uint8 *boardname;\r
+static uint8 *sboardname;\r
 \r
 static uint32 CHRRAMSize;\r
 uint8 *UNIFchrrama=0;\r
 \r
 static uint32 CHRRAMSize;\r
 uint8 *UNIFchrrama=0;\r
@@ -77,502 +76,544 @@ static uint32 mallocedsizes[32];
 \r
 static int FixRomSize(uint32 size, uint32 minimum)\r
 {\r
 \r
 static int FixRomSize(uint32 size, uint32 minimum)\r
 {\r
-  int x=1;\r
+       uint32 x=1; //mbg merge 7/17/06 made uint\r
 \r
 \r
-  if(size<minimum)\r
-   return minimum;\r
-  while(x<size)\r
-   x<<=1;\r
-  return x;\r
+       if(size<minimum)\r
+               return minimum;\r
+       while(x<size)\r
+               x<<=1;\r
+       return x;\r
 }\r
 \r
 static void FreeUNIF(void)\r
 {\r
 }\r
 \r
 static void FreeUNIF(void)\r
 {\r
- int x;\r
- if(UNIFchrrama)\r
-  {free(UNIFchrrama);UNIFchrrama=0;}\r
- if(boardname)\r
-  {free(boardname);boardname=0;}\r
- for(x=0;x<32;x++)\r
- {\r
-  if(malloced[x])\r
-   {free(malloced[x]);malloced[x]=0;}\r
- }\r
      int x;\r
      if(UNIFchrrama)\r
+       {free(UNIFchrrama);UNIFchrrama=0;}\r
      if(boardname)\r
+       {free(boardname);boardname=0;}\r
      for(x=0;x<32;x++)\r
      {\r
+               if(malloced[x])\r
+               {free(malloced[x]);malloced[x]=0;}\r
      }\r
 }\r
 \r
 static void ResetUNIF(void)\r
 {\r
 }\r
 \r
 static void ResetUNIF(void)\r
 {\r
- int x;\r
- for(x=0;x<32;x++)\r
-  malloced[x]=0;\r
- vramo=0;\r
- boardname=0;\r
- mirrortodo=0;\r
- memset(&UNIFCart,0,sizeof(UNIFCart));\r
- UNIFchrrama=0;\r
      int x;\r
      for(x=0;x<32;x++)\r
+               malloced[x]=0;\r
      vramo=0;\r
      boardname=0;\r
      mirrortodo=0;\r
      memset(&UNIFCart,0,sizeof(UNIFCart));\r
      UNIFchrrama=0;\r
 }\r
 \r
 static uint8 exntar[2048];\r
 \r
 static void MooMirroring(void)\r
 {\r
 }\r
 \r
 static uint8 exntar[2048];\r
 \r
 static void MooMirroring(void)\r
 {\r
- if(mirrortodo<0x4)\r
-  SetupCartMirroring(mirrortodo,1,0);\r
- else if(mirrortodo==0x4)\r
- {\r
-  SetupCartMirroring(4,1,exntar);\r
-  AddExState(exntar, 2048, 0,"EXNR");\r
- }\r
- else\r
-  SetupCartMirroring(0,0,0);\r
      if(mirrortodo<0x4)\r
+               SetupCartMirroring(mirrortodo,1,0);\r
      else if(mirrortodo==0x4)\r
      {\r
+               SetupCartMirroring(4,1,exntar);\r
+               AddExState(exntar, 2048, 0,"EXNR");\r
      }\r
      else\r
+               SetupCartMirroring(0,0,0);\r
 }\r
 \r
 static int DoMirroring(int fp)\r
 {\r
 }\r
 \r
 static int DoMirroring(int fp)\r
 {\r
- uint8 t;\r
- t=FCEU_fgetc(fp);\r
- mirrortodo=t;\r
-\r
- {\r
-  static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"};\r
-  if(t<6)\r
-   FCEU_printf(" Name/Attribute Table Mirroring: %s\n",stuffo[t]);\r
- }\r
- return(1);\r
      uint8 t;\r
      t=FCEU_fgetc(fp);\r
      mirrortodo=t;\r
+\r
      {\r
+               static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"};\r
+               if(t<6)\r
+                       FCEU_printf(" Name/Attribute Table Mirroring: %s\n",stuffo[t]);\r
      }\r
      return(1);\r
 }\r
 \r
 static int NAME(int fp)\r
 {\r
 }\r
 \r
 static int NAME(int fp)\r
 {\r
- char namebuf[100];\r
- int index;\r
- int t;\r
-\r
- FCEU_printf(" Name: ");\r
- index=0;\r
-\r
- while((t=FCEU_fgetc(fp))>0)\r
-  if(index<99)\r
-   namebuf[index++]=t;\r
-\r
- namebuf[index]=0;\r
- FCEU_printf("%s\n",namebuf);\r
-\r
if(!FCEUGameInfo.name)\r
- {\r
-  FCEUGameInfo.name=malloc(strlen(namebuf)+1);\r
-  strcpy((char *)FCEUGameInfo.name,namebuf);\r
- }\r
- return(1);\r
      char namebuf[100];\r
      int index;\r
      int t;\r
+\r
      FCEU_printf(" Name: ");\r
      index=0;\r
+\r
      while((t=FCEU_fgetc(fp))>0)\r
+               if(index<99)\r
+                       namebuf[index++]=t;\r
+\r
      namebuf[index]=0;\r
      FCEU_printf("%s\n",namebuf);\r
+\r
      if(!GameInfo->name)\r
      {\r
+               GameInfo->name=(uint8*)malloc(strlen(namebuf)+1); //mbg merge 7/17/06 added cast\r
+               strcpy((char*)GameInfo->name,namebuf); //mbg merge 7/17/06 added cast\r
      }\r
      return(1);\r
 }\r
 static int DINF(int fp)\r
 {\r
 }\r
 static int DINF(int fp)\r
 {\r
- char name[100], method[100];\r
- uint8 d, m;\r
- uint16 y;\r
- int t;\r
-\r
- if(FCEU_fread(name,1,100,fp)!=100)\r
-  return(0);\r
- if((t=FCEU_fgetc(fp))==EOF) return(0);\r
- d=t;\r
- if((t=FCEU_fgetc(fp))==EOF) return(0);\r
- m=t;\r
- if((t=FCEU_fgetc(fp))==EOF) return(0);\r
- y=t;\r
- if((t=FCEU_fgetc(fp))==EOF) return(0);\r
- y|=t<<8;\r
- if(FCEU_fread(method,1,100,fp)!=100)\r
-  return(0);\r
- name[99]=method[99]=0;\r
- FCEU_printf(" Dumped by: %s\n",name);\r
- FCEU_printf(" Dumped with: %s\n",method);\r
- {\r
-  char *months[12]={"January","February","March","April","May","June","July",\r
-                   "August","September","October","November","December"};\r
-  FCEU_printf(" Dumped on: %s %d, %d\n",months[(m-1)%12],d,y);\r
- }\r
- return(1);\r
      char name[100], method[100];\r
      uint8 d, m;\r
      uint16 y;\r
      int t;\r
+\r
      if(FCEU_fread(name,1,100,fp)!=100)\r
+               return(0);\r
      if((t=FCEU_fgetc(fp))==EOF) return(0);\r
      d=t;\r
      if((t=FCEU_fgetc(fp))==EOF) return(0);\r
      m=t;\r
      if((t=FCEU_fgetc(fp))==EOF) return(0);\r
      y=t;\r
      if((t=FCEU_fgetc(fp))==EOF) return(0);\r
      y|=t<<8;\r
      if(FCEU_fread(method,1,100,fp)!=100)\r
+               return(0);\r
      name[99]=method[99]=0;\r
      FCEU_printf(" Dumped by: %s\n",name);\r
      FCEU_printf(" Dumped with: %s\n",method);\r
      {\r
+               char *months[12]={"January","February","March","April","May","June","July",\r
+                       "August","September","October","November","December"};\r
+               FCEU_printf(" Dumped on: %s %d, %d\n",months[(m-1)%12],d,y);\r
      }\r
      return(1);\r
 }\r
 \r
 static int CTRL(int fp)\r
 {\r
 }\r
 \r
 static int CTRL(int fp)\r
 {\r
- int t;\r
      int t;\r
 \r
 \r
- if((t=FCEU_fgetc(fp))==EOF)\r
-  return(0);\r
- /* The information stored in this byte isn't very helpful, but it's\r
-    better than nothing...maybe.\r
- */\r
      if((t=FCEU_fgetc(fp))==EOF)\r
+               return(0);\r
      /* The information stored in this byte isn't very helpful, but it's\r
+       better than nothing...maybe.\r
      */\r
 \r
 \r
if(t&1) FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD;\r
else FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_NONE;\r
      if(t&1) GameInfo->input[0]=GameInfo->input[1]=SI_GAMEPAD;\r
      else GameInfo->input[0]=GameInfo->input[1]=SI_NONE;\r
 \r
 \r
if(t&2) FCEUGameInfo.input[1]=SI_ZAPPER;\r
//else if(t&0x10) FCEUGameInfo->input[1]=SI_POWERPAD;\r
      if(t&2) GameInfo->input[1]=SI_ZAPPER;\r
      //else if(t&0x10) GameInfo->input[1]=SI_POWERPAD;\r
 \r
 \r
- return(1);\r
      return(1);\r
 }\r
 \r
 static int TVCI(int fp)\r
 {\r
 }\r
 \r
 static int TVCI(int fp)\r
 {\r
- int t;\r
- if( (t=FCEU_fgetc(fp)) ==EOF)\r
-  return(0);\r
- if(t<=2)\r
- {\r
-  char *stuffo[3]={"NTSC","PAL","NTSC and PAL"};\r
-  if(t==0)\r
-  {\r
-   FCEUGameInfo.vidsys=GIV_NTSC;\r
-   FCEUI_SetVidSystem(0);\r
-  }\r
-  else if(t==1)\r
-  {\r
-   FCEUGameInfo.vidsys=GIV_PAL;\r
-   FCEUI_SetVidSystem(1);\r
-  }\r
-  FCEU_printf(" TV Standard Compatibility: %s\n",stuffo[t]);\r
- }\r
- return(1);\r
      int t;\r
      if( (t=FCEU_fgetc(fp)) ==EOF)\r
+               return(0);\r
      if(t<=2)\r
      {\r
+               char *stuffo[3]={"NTSC","PAL","NTSC and PAL"};\r
+               if(t==0)\r
+               {\r
+                       GameInfo->vidsys=GIV_NTSC;\r
+                       FCEUI_SetVidSystem(0);\r
+               }\r
+               else if(t==1)\r
+               {\r
+                       GameInfo->vidsys=GIV_PAL;\r
+                       FCEUI_SetVidSystem(1);\r
+               }\r
+               FCEU_printf(" TV Standard Compatibility: %s\n",stuffo[t]);\r
      }\r
      return(1);\r
 }\r
 \r
 static int EnableBattery(int fp)\r
 {\r
 }\r
 \r
 static int EnableBattery(int fp)\r
 {\r
- FCEU_printf(" Battery-backed.\n");\r
- if(FCEU_fgetc(fp)==EOF)\r
-  return(0);\r
- UNIFCart.battery=1;\r
- return(1);\r
      FCEU_printf(" Battery-backed.\n");\r
      if(FCEU_fgetc(fp)==EOF)\r
+               return(0);\r
      UNIFCart.battery=1;\r
      return(1);\r
 }\r
 \r
 static int LoadPRG(int fp)\r
 {\r
 }\r
 \r
 static int LoadPRG(int fp)\r
 {\r
- int z,t;\r
- z=uchead.ID[3]-'0';\r
-\r
- if(z<0 || z>15)\r
-  return(0);\r
- FCEU_printf(" PRG ROM %d size: %d",z,(int) uchead.info);\r
- if(malloced[z])\r
-  free(malloced[z]);\r
- t=FixRomSize(uchead.info,2048);\r
- if(!(malloced[z]=(uint8 *)FCEU_malloc(t)))\r
-  return(0);\r
- mallocedsizes[z]=t;\r
- memset(malloced[z]+uchead.info,0xFF,t-uchead.info);\r
- if(FCEU_fread(malloced[z],1,uchead.info,fp)!=uchead.info)\r
- {\r
-  FCEU_printf("Read Error!\n");\r
-  return(0);\r
- }\r
- else\r
-  FCEU_printf("\n");\r
-\r
- SetupCartPRGMapping(z,malloced[z],t,0);\r
- return(1);\r
      int z,t;\r
      z=uchead.ID[3]-'0';\r
+\r
      if(z<0 || z>15)\r
+               return(0);\r
      FCEU_printf(" PRG ROM %d size: %d",z,(int) uchead.info);\r
      if(malloced[z])\r
+               free(malloced[z]);\r
      t=FixRomSize(uchead.info,2048);\r
      if(!(malloced[z]=(uint8 *)FCEU_malloc(t)))\r
+               return(0);\r
      mallocedsizes[z]=t;\r
      memset(malloced[z]+uchead.info,0xFF,t-uchead.info);\r
      if(FCEU_fread(malloced[z],1,uchead.info,fp)!=uchead.info)\r
      {\r
+               FCEU_printf("Read Error!\n");\r
+               return(0);\r
      }\r
      else\r
+               FCEU_printf("\n");\r
+\r
      SetupCartPRGMapping(z,malloced[z],t,0);\r
      return(1);\r
 }\r
 \r
 static int SetBoardName(int fp)\r
 {\r
 }\r
 \r
 static int SetBoardName(int fp)\r
 {\r
if(!(boardname=FCEU_malloc(uchead.info+1)))\r
-  return(0);\r
- FCEU_fread(boardname,1,uchead.info,fp);\r
- boardname[uchead.info]=0;\r
- FCEU_printf(" Board name: %s\n",boardname);\r
- sboardname=boardname;\r
- if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4))\r
-  sboardname+=4;\r
- return(1);\r
      if(!(boardname=(uint8 *)FCEU_malloc(uchead.info+1)))\r
+               return(0);\r
      FCEU_fread(boardname,1,uchead.info,fp);\r
      boardname[uchead.info]=0;\r
      FCEU_printf(" Board name: %s\n",boardname);\r
      sboardname=boardname;\r
      if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4))\r
+               sboardname+=4;\r
      return(1);\r
 }\r
 \r
 static int LoadCHR(int fp)\r
 {\r
 }\r
 \r
 static int LoadCHR(int fp)\r
 {\r
- int z,t;\r
- z=uchead.ID[3]-'0';\r
- if(z<0 || z>15)\r
-  return(0);\r
- FCEU_printf(" CHR ROM %d size: %d",z,(int) uchead.info);\r
- if(malloced[16+z])\r
-  free(malloced[16+z]);\r
- t=FixRomSize(uchead.info,8192);\r
- if(!(malloced[16+z]=(uint8 *)FCEU_malloc(t)))\r
-  return(0);\r
- mallocedsizes[16+z]=t;\r
- memset(malloced[16+z]+uchead.info,0xFF,t-uchead.info);\r
- if(FCEU_fread(malloced[16+z],1,uchead.info,fp)!=uchead.info)\r
- {\r
-  FCEU_printf("Read Error!\n");\r
-  return(0);\r
- }\r
- else\r
-  FCEU_printf("\n");\r
-\r
- SetupCartCHRMapping(z,malloced[16+z],t,0);\r
- return(1);\r
      int z,t;\r
      z=uchead.ID[3]-'0';\r
      if(z<0 || z>15)\r
+               return(0);\r
      FCEU_printf(" CHR ROM %d size: %d",z,(int) uchead.info);\r
      if(malloced[16+z])\r
+               free(malloced[16+z]);\r
      t=FixRomSize(uchead.info,8192);\r
      if(!(malloced[16+z]=(uint8 *)FCEU_malloc(t)))\r
+               return(0);\r
      mallocedsizes[16+z]=t;\r
      memset(malloced[16+z]+uchead.info,0xFF,t-uchead.info);\r
      if(FCEU_fread(malloced[16+z],1,uchead.info,fp)!=uchead.info)\r
      {\r
+               FCEU_printf("Read Error!\n");\r
+               return(0);\r
      }\r
      else\r
+               FCEU_printf("\n");\r
+\r
      SetupCartCHRMapping(z,malloced[16+z],t,0);\r
      return(1);\r
 }\r
 \r
 \r
 #define BMCFLAG_FORCE4 1\r
 #define BMCFLAG_16KCHRR  2\r
 #define BMCFLAG_32KCHRR  4\r
 }\r
 \r
 \r
 #define BMCFLAG_FORCE4 1\r
 #define BMCFLAG_16KCHRR  2\r
 #define BMCFLAG_32KCHRR  4\r
+#define BMCFLAG_EXPCHRR 8\r
 \r
 static BMAPPING bmap[] = {\r
 \r
 \r
 static BMAPPING bmap[] = {\r
 \r
-/* Sachen Carts */\r
- { "TC-U01-1.5M", TCU01_Init,0},\r
- { "Sachen-8259A", S8259A_Init,0},\r
- { "Sachen-8259B", S8259B_Init,0},\r
- { "Sachen-8259C", S8259C_Init,0},\r
- { "Sachen-8259D", S8259D_Init,0},\r
- { "Sachen-74LS374N", S74LS374N_Init,0},\r
- { "Sachen-74LS374NA", S74LS374NA_Init,0}, //seems to be custom mapper\r
- { "SA-016-1M", SA0161M_Init,0},\r
- { "SA-72007", SA72007_Init,0},\r
- { "SA-72008", SA72008_Init,0},\r
- { "SA-0036", SA0036_Init,0},\r
- { "SA-0037", SA0037_Init,0},\r
- { "SA-NROM", TCA01_Init,0},\r
-\r
-// /* AVE carts. */\r
-// { "MB-91", MB91_Init,0},  // DeathBots\r
-// { "NINA-06", NINA06_Init,0},  // F-15 City War\r
-// { "NINA-03", NINA03_Init,0},  // Tiles of Fate\r
-// { "NINA-001", NINA001_Init,0}, // Impossible Mission 2\r
-\r
- { "ANROM", ANROM_Init,0},\r
-\r
- { "HKROM", HKROM_Init,0},\r
-\r
- { "EWROM", EWROM_Init,0},\r
- { "EKROM", EKROM_Init,0},\r
- { "ELROM", ELROM_Init,0},\r
- { "ETROM", ETROM_Init,0},\r
-\r
- { "SAROM", SAROM_Init,0},\r
- { "SBROM", SBROM_Init,0},\r
- { "SCROM", SCROM_Init,0},\r
- { "SEROM", SEROM_Init,0},\r
- { "SGROM", SGROM_Init,0},\r
- { "SKROM", SKROM_Init,0},\r
- { "SLROM", SLROM_Init,0},\r
- { "SL1ROM", SL1ROM_Init,0},\r
- { "SNROM", SNROM_Init,0},\r
- { "SOROM", SOROM_Init,0},\r
-\r
- { "TGROM", TGROM_Init,0},\r
- { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4},\r
-\r
- { "TEROM", TEROM_Init,0},\r
- { "TFROM", TFROM_Init,0},\r
- { "TLROM", TLROM_Init,0},\r
- { "TKROM", TKROM_Init,0},\r
- { "TSROM", TSROM_Init,0},\r
-\r
- { "TLSROM", TLSROM_Init,0},\r
- { "TKSROM", TKSROM_Init,0},\r
- { "TQROM", TQROM_Init,0},\r
- { "TVROM", TLROM_Init,BMCFLAG_FORCE4},\r
-\r
- { "CPROM", CPROM_Init,BMCFLAG_16KCHRR},\r
- { "CNROM", CNROM_Init,0},\r
- { "NROM", NROM_Init,0 }, //NROM256_Init,0 },\r
- { "NROM-128", NROM_Init,0 }, //NROM128_Init,0 },\r
- { "NROM-256", NROM_Init,0 }, //NROM256_Init,0 },\r
- { "RROM", NROM_Init,0 }, //NROM128_Init,0 },\r
- { "RROM-128", NROM_Init,0 }, //NROM128_Init,0 },\r
- { "MHROM", MHROM_Init,0},\r
- { "UNROM", UNROM_Init,0},\r
- { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0},\r
- { "MARIO1-MALEE2", MALEE_Init,0},\r
-\r
- { "CC-21", UNLCC21_Init,0},\r
-\r
- { "H2288", UNLH2288_Init,0},\r
- { "KOF97", UNLKOF97_Init,0},\r
- { "SL1632", UNLSL1632_Init,0},\r
- { "SHERO", UNLSHeroes_Init,0},\r
- { "8237", UNL8237_Init,0},\r
- { "8157", UNL8157_Init,0},\r
- { "T-262", BMCT262_Init,0},\r
- { "FK23C", BMCFK23C_Init,0},\r
- { "Supervision16in1", Supervision16_Init,0},\r
- { "NovelDiamond9999999in1", Novel_Init,0},\r
- { "Super24in1SC03", Super24_Init,0},\r
- { "42in1ResetSwitch", BMC42in1r_Init, 0},\r
- { "64in1NoRepeat", BMC64in1nr_Init, 0},\r
- { "13in1JY110", BMC13in1JY110_Init, 0},\r
- { "70in1", BMC70in1_Init, 0},\r
- { "70in1B", BMC70in1B_Init, 0},\r
- { "GK-192", Mapper58_Init, 0},\r
- { "SuperHIK8in1", Mapper45_Init,0},\r
-\r
- { "DREAMTECH01", DreamTech01_Init,0},\r
- { "KONAMI-QTAI", Mapper190_Init,0},\r
-\r
- { "TEK90", Mapper90_Init,0},\r
-\r
- {0,0,0}\r
+       /* Sachen Carts */\r
+       { "TC-U01-1.5M", TCU01_Init,0},\r
+       { "Sachen-8259A", S8259A_Init,0},\r
+       { "Sachen-8259B", S8259B_Init,0},\r
+       { "Sachen-8259C", S8259C_Init,0},\r
+       { "Sachen-8259D", S8259D_Init,0},\r
+       { "Sachen-74LS374N", S74LS374N_Init,0},\r
+       { "Sachen-74LS374NA", S74LS374NA_Init,0}, //seems to be custom mapper\r
+       { "SA-002", TCU02_Init, 0},\r
+       { "SA-016-1M", SA0161M_Init,0},\r
+       { "SA-72007", SA72007_Init,0},\r
+       { "SA-72008", SA72008_Init,0},\r
+       { "SA-009", SA009_Init,0},\r
+       { "SA-0036", SA0036_Init,0},\r
+       { "SA-0037", SA0037_Init,0},\r
+       { "SA-NROM", TCA01_Init,0},\r
+\r
+       // /* AVE carts. */\r
+       // { "MB-91", MB91_Init,0},  // DeathBots\r
+       // { "NINA-06", NINA06_Init,0},  // F-15 City War\r
+       // { "NINA-03", NINA03_Init,0},  // Tiles of Fate\r
+       // { "NINA-001", NINA001_Init,0}, // Impossible Mission 2\r
+\r
+       { "ANROM", ANROM_Init,0},\r
+\r
+       { "HKROM", HKROM_Init,0},\r
+\r
+       { "EWROM", EWROM_Init,0},\r
+       { "EKROM", EKROM_Init,0},\r
+       { "ELROM", ELROM_Init,0},\r
+       { "ETROM", ETROM_Init,0},\r
+\r
+       { "SAROM", SAROM_Init,0},\r
+       { "SBROM", SBROM_Init,0},\r
+       { "SCROM", SCROM_Init,0},\r
+       { "SEROM", SEROM_Init,0},\r
+       { "SGROM", SGROM_Init,0},\r
+       { "SKROM", SKROM_Init,0},\r
+       { "SLROM", SLROM_Init,0},\r
+       { "SL1ROM", SL1ROM_Init,0},\r
+       { "SNROM", SNROM_Init,0},\r
+       { "SOROM", SOROM_Init,0},\r
+\r
+       { "TGROM", TGROM_Init,0},\r
+       { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4},\r
+\r
+       { "TBROM", TBROM_Init,0},\r
+       { "TEROM", TEROM_Init,0},\r
+       { "TFROM", TFROM_Init,0},\r
+       { "TLROM", TLROM_Init,0},\r
+       { "TKROM", TKROM_Init,0},\r
+       { "TSROM", TSROM_Init,0},\r
+\r
+       { "TLSROM", TLSROM_Init,0},\r
+       { "TKSROM", TKSROM_Init,0},\r
+       { "TQROM", TQROM_Init,0},\r
+       { "TVROM", TLROM_Init,BMCFLAG_FORCE4},\r
+\r
+       { "NTBROM", Mapper68_Init,0},\r
+\r
+       { "CPROM", CPROM_Init,BMCFLAG_16KCHRR},\r
+       { "CNROM", CNROM_Init,0},\r
+       { "NROM", NROM_Init,0 }, //NROM256_Init,0 },\r
+       { "NROM-128", NROM_Init,0 }, //NROM128_Init,0 },\r
+       { "NROM-256", NROM_Init,0 }, //NROM256_Init,0 },\r
+       { "RROM", NROM_Init,0 }, //NROM128_Init,0 },\r
+       { "RROM-128", NROM_Init,0 }, //NROM128_Init,0 },\r
+       { "MHROM", MHROM_Init,0},\r
+       { "UNROM", UNROM_Init,0},\r
+       { "UOROM", UNROM_Init,0},\r
+       { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0},\r
+       { "MARIO1-MALEE2", MALEE_Init,0},\r
+       { "3D-BLOCK", UNL3DBlock_Init, 0},\r
+       { "SMB2J", UNLSMB2J_Init, 0},\r
+       { "AX5705", UNLAX5705_Init, 0},\r
+       { "CC-21", UNLCC21_Init,0},\r
+       { "H2288", UNLH2288_Init,0},\r
+       { "KOF97", UNLKOF97_Init,0},\r
+       { "SL1632", UNLSL1632_Init,0},\r
+       { "SHERO", UNLSHeroes_Init,0},\r
+       { "8237", UNL8237_Init,0},\r
+       { "8237A", UNL8237A_Init,0},\r
+       { "8157", UNL8157_Init,0},\r
+       { "T-262", BMCT262_Init,0},\r
+       { "FK23C", BMCFK23C_Init,0},\r
+       { "A65AS", BMCA65AS_Init,0},\r
+       { "C-N22M", UNLCN22M_Init,0},\r
+       { "EDU2000", UNLEDU2000_Init,0},\r
+       { "603-5052", UNL6035052_Init,0},\r
+       { "N625092", UNLN625092_Init,0},\r
+       { "Supervision16in1", Supervision16_Init,0},\r
+       { "NovelDiamond9999999in1", Novel_Init,0},\r
+       { "Super24in1SC03", Super24_Init,0},\r
+       { "64in1NoRepeat", BMC64in1nr_Init, 0},\r
+       { "13in1JY110", BMC13in1JY110_Init, 0},\r
+       { "70in1", BMC70in1_Init, 0},\r
+       { "70in1B", BMC70in1B_Init, 0},\r
+       { "D1038", BMCD1038_Init, 0},\r
+       { "GK-192", BMCGK192_Init, 0},\r
+       { "SuperHIK8in1", Mapper45_Init,0},\r
+       { "22211", UNL22211_Init,0},\r
+       { "TF1201", UNLTF1201_Init, 0},\r
+       { "GS-2004", BMCGS2004_Init, 0},\r
+       { "GS-2013", BMCGS2013_Init, 0},\r
+       { "KS7032", UNLKS7032_Init, 0},\r
+       { "T-230", UNLT230_Init, 0},\r
+       { "190in1", BMC190in1_Init, 0},\r
+       { "Ghostbusters63in1", BMCGhostbusters63in1_Init, 0},\r
+       { "BS-5",BMCBS5_Init, 0},\r
+       { "411120-C",BMC411120C_Init, 0},\r
+       { "830118C",BMC830118C_Init, 0},\r
+       { "T-227-1",BMCT2271_Init,0},\r
+\r
+       { "DREAMTECH01", DreamTech01_Init,0},\r
+       { "KONAMI-QTAI", Mapper190_Init,0},\r
+\r
+       { "DANCE", UNLDANCE_Init,0},\r
+       { "OneBus", UNLOneBus_Init,0},\r
+       { "SC-127", UNLSC127_Init,0},\r
+\r
+       { "TEK90", Mapper90_Init,0},\r
+\r
+ { "FK23C", BMCFK23C_Init,BMCFLAG_EXPCHRR},\r
+ { "FK23CA", BMCFK23CA_Init,BMCFLAG_EXPCHRR},\r
+\r
+       {0,0,0}\r
 };\r
 \r
 static BFMAPPING bfunc[] = {\r
 };\r
 \r
 static BFMAPPING bfunc[] = {\r
- { "CTRL", CTRL },\r
- { "TVCI", TVCI },\r
- { "BATR", EnableBattery },\r
- { "MIRR", DoMirroring },\r
- { "PRG",  LoadPRG },\r
- { "CHR",  LoadCHR },\r
- { "NAME", NAME  },\r
- { "MAPR", SetBoardName },\r
- { "DINF", DINF },\r
- { 0, 0 }\r
      { "CTRL", CTRL },\r
      { "TVCI", TVCI },\r
      { "BATR", EnableBattery },\r
      { "MIRR", DoMirroring },\r
      { "PRG",  LoadPRG },\r
      { "CHR",  LoadCHR },\r
      { "NAME", NAME  },\r
      { "MAPR", SetBoardName },\r
      { "DINF", DINF },\r
      { 0, 0 }\r
 };\r
 \r
 int LoadUNIFChunks(int fp)\r
 {\r
 };\r
 \r
 int LoadUNIFChunks(int fp)\r
 {\r
-   int x;\r
-   int t;\r
-   for(;;)\r
-   {\r
-    t=FCEU_fread(&uchead,1,4,fp);\r
-    if(t<4)\r
-    {\r
-     if(t>0)\r
-      return 0;\r
-     return 1;\r
-    }\r
-    if(!(FCEU_read32(&uchead.info,fp)))\r
-     return 0;\r
-    t=0;\r
-    x=0;\r
-       //printf("Funky: %s\n",((uint8 *)&uchead));\r
-    while(bfunc[x].name)\r
-    {\r
-     if(!memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name)))\r
-     {\r
-      if(!bfunc[x].init(fp))\r
-       return 0;\r
-      t=1;\r
-      break;\r
-     }\r
-     x++;\r
-    }\r
-    if(!t)\r
-     if(FCEU_fseek(fp,uchead.info,SEEK_CUR))\r
-      return(0);\r
-   }\r
+       int x;\r
+       int t;\r
+       for(;;)\r
+       {\r
+               t=FCEU_fread(&uchead,1,4,fp);\r
+               if(t<4)\r
+               {\r
+                       if(t>0)\r
+                               return 0;\r
+                       return 1;\r
+               }\r
+               if(!(FCEU_read32le(&uchead.info,fp)))\r
+                       return 0;\r
+               t=0;\r
+               x=0;\r
+               //printf("Funky: %s\n",((uint8 *)&uchead));\r
+               while(bfunc[x].name)\r
+               {\r
+                       if(!memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name)))\r
+                       {\r
+                               if(!bfunc[x].init(fp))\r
+                                       return 0;\r
+                               t=1;\r
+                               break;\r
+                       }\r
+                       x++;\r
+               }\r
+               if(!t)\r
+                       if(FCEU_fseek(fp,uchead.info,SEEK_CUR)<0)\r
+                               return(0);\r
+       }\r
 }\r
 \r
 static int InitializeBoard(void)\r
 {\r
 }\r
 \r
 static int InitializeBoard(void)\r
 {\r
-   int x=0;\r
+       int x=0;\r
 \r
 \r
-   if(!sboardname) return(0);\r
+       if(!sboardname) return(0);\r
 \r
 \r
-   while(bmap[x].name)\r
-   {\r
-    if(!strcmp(sboardname,(char *)bmap[x].name))\r
-    {\r
-     if(!malloced[16])\r
-     {\r
+       while(bmap[x].name)\r
+       {\r
+               if(!strcmp((char *)sboardname,(char *)bmap[x].name))\r
+               {\r
+                       if(!malloced[16])\r
+                       {\r
       if(bmap[x].flags & BMCFLAG_16KCHRR)\r
         CHRRAMSize = 16384;\r
       if(bmap[x].flags & BMCFLAG_16KCHRR)\r
         CHRRAMSize = 16384;\r
+      else if(bmap[x].flags & BMCFLAG_32KCHRR)\r
+        CHRRAMSize = 32768;\r
+      else if(bmap[x].flags & BMCFLAG_EXPCHRR)\r
+        CHRRAMSize = 128 * 1024;\r
       else\r
       else\r
-  CHRRAMSize = 8192;\r
-      if((UNIFchrrama=(uint8 *)FCEU_malloc(CHRRAMSize)))\r
-      {\r
-       SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1);\r
-       AddExState(UNIFchrrama, CHRRAMSize, 0,"CHRR");\r
-      }\r
-      else\r
-       return(-1);\r
-     }\r
-     if(bmap[x].flags&BMCFLAG_FORCE4)\r
-      mirrortodo=4;\r
-     MooMirroring();\r
-     bmap[x].init(&UNIFCart);\r
-     return(1);\r
-    }\r
-    x++;\r
-   }\r
-   FCEU_PrintError("Board type not supported.");\r
-   return(0);\r
+        CHRRAMSize = 8192;\r
+                               if((UNIFchrrama=(uint8 *)FCEU_malloc(CHRRAMSize)))\r
+                               {\r
+                                       SetupCartCHRMapping(0,UNIFchrrama,CHRRAMSize,1);\r
+                                       AddExState(UNIFchrrama, CHRRAMSize, 0,"CHRR");\r
+                               }\r
+                               else\r
+                                       return(-1);\r
+                       }\r
+                       if(bmap[x].flags&BMCFLAG_FORCE4)\r
+                               mirrortodo=4;\r
+                       MooMirroring();\r
+                       bmap[x].init(&UNIFCart);\r
+                       return(1);\r
+               }\r
+               x++;\r
+       }\r
+       FCEU_PrintError("Board type not supported.");\r
+       return(0);\r
 }\r
 \r
 static void UNIFGI(int h, void *param)\r
 {\r
 }\r
 \r
 static void UNIFGI(int h, void *param)\r
 {\r
- switch(h)\r
- {\r
-  case GI_RESETM2:\r
-                if(UNIFCart.Reset)\r
-                 UNIFCart.Reset();\r
+       switch(h)\r
+       {\r
+       case GI_RESETSAVE:\r
+               //FCEU_ClearGameSave(&UNIFCart);\r
                break;\r
                break;\r
-  case GI_POWER:\r
-                if(UNIFCart.Power)\r
-                 UNIFCart.Power();\r
+\r
+       case GI_RESETM2:\r
+               if(UNIFCart.Reset)\r
+                       UNIFCart.Reset();\r
+               break;\r
+       case GI_POWER:\r
+               if(UNIFCart.Power)\r
+                       UNIFCart.Power();\r
                if(UNIFchrrama) memset(UNIFchrrama,0,8192);\r
                break;\r
                if(UNIFchrrama) memset(UNIFchrrama,0,8192);\r
                break;\r
-  case GI_CLOSE:\r
-                FCEU_SaveGameSave(&UNIFCart);\r
+       case GI_CLOSE:\r
+               FCEU_SaveGameSave(&UNIFCart);\r
                if(UNIFCart.Close)\r
                if(UNIFCart.Close)\r
-                UNIFCart.Close();\r
-                FreeUNIF();\r
-               ResetExState(0,0);\r
-                break;\r
-  case GI_INFOSTRING:\r
+                       UNIFCart.Close();\r
+               FreeUNIF();\r
+               break;\r
+       case GI_INFOSTRING:\r
                {\r
                 char board[24];\r
                {\r
                 char board[24];\r
-                strncpy(board, sboardname, 20);\r
+                strncpy(board, (char *)sboardname, 20);\r
                 board[20] = 0;\r
                 sprintf(param, "UNIF, %s, %s%s", board, PAL?"PAL":"NTSC", UNIFCart.battery?", BB":"");\r
                }\r
                break;\r
                 board[20] = 0;\r
                 sprintf(param, "UNIF, %s, %s%s", board, PAL?"PAL":"NTSC", UNIFCart.battery?", BB":"");\r
                }\r
                break;\r
- }\r
      }\r
 }\r
 \r
 int UNIFLoad(const char *name, int fp)\r
 {\r
 }\r
 \r
 int UNIFLoad(const char *name, int fp)\r
 {\r
-        FCEU_fseek(fp,0,SEEK_SET);\r
-        FCEU_fread(&unhead,1,4,fp);\r
-        if(memcmp(&unhead,"UNIF",4))\r
-         return 0;\r
+       FCEU_fseek(fp,0,SEEK_SET);\r
+       FCEU_fread(&unhead,1,4,fp);\r
+       if(memcmp(&unhead,"UNIF",4))\r
+               return 0;\r
 \r
        ResetCartMapping();\r
 \r
 \r
        ResetCartMapping();\r
 \r
-        ResetExState(0,0);\r
-        ResetUNIF();\r
-        if(!FCEU_read32(&unhead.info,fp))\r
-        goto aborto;\r
-        if(FCEU_fseek(fp,0x20,SEEK_SET)<0)\r
-        goto aborto;\r
-        if(!LoadUNIFChunks(fp))\r
-        goto aborto;\r
+       ResetExState(0,0);\r
+       ResetUNIF();\r
+       if(!FCEU_read32le(&unhead.info,fp))\r
+               goto aborto;\r
+       if(FCEU_fseek(fp,0x20,SEEK_SET)<0)\r
+               goto aborto;\r
+       if(!LoadUNIFChunks(fp))\r
+               goto aborto;\r
        {\r
        {\r
-        int x;\r
-        struct md5_context md5;\r
-\r
-        md5_starts(&md5);\r
-\r
-        for(x=0;x<32;x++)\r
-         if(malloced[x])\r
-         {\r
-          md5_update(&md5,malloced[x],mallocedsizes[x]);\r
-         }\r
-         md5_finish(&md5,UNIFCart.MD5);\r
-          FCEU_printf(" ROM MD5:  0x");\r
-          for(x=0;x<16;x++)\r
-           FCEU_printf("%02x",UNIFCart.MD5[x]);\r
-          FCEU_printf("\n");\r
-         memcpy(FCEUGameInfo.MD5,UNIFCart.MD5,sizeof(UNIFCart.MD5));\r
+               int x;\r
+               struct md5_context md5;\r
+\r
+               md5_starts(&md5);\r
+\r
+               for(x=0;x<32;x++)\r
+                       if(malloced[x])\r
+                       {\r
+                               md5_update(&md5,malloced[x],mallocedsizes[x]);\r
+                       }\r
+                       md5_finish(&md5,UNIFCart.MD5);\r
+                       FCEU_printf(" ROM MD5:  0x");\r
+                       for(x=0;x<16;x++)\r
+                               FCEU_printf("%02x",UNIFCart.MD5[x]);\r
+                       FCEU_printf("\n");\r
+                       memcpy(&GameInfo->MD5,&UNIFCart.MD5,sizeof(UNIFCart.MD5));\r
        }\r
 \r
        }\r
 \r
-        if(!InitializeBoard())\r
-        goto aborto;\r
+       if(!InitializeBoard())\r
+               goto aborto;\r
 \r
        FCEU_LoadGameSave(&UNIFCart);\r
 \r
        FCEU_LoadGameSave(&UNIFCart);\r
-        GameInterface=UNIFGI;\r
-        return 1;\r
 \r
 \r
-       aborto:\r
+       //strcpy(LoadedRomFName,name); //For the debugger list\r
+       GameInterface=UNIFGI;\r
+       return 1;\r
+\r
+aborto:\r
 \r
        FreeUNIF();\r
        ResetUNIF();\r
 \r
        FreeUNIF();\r
        ResetUNIF();\r
diff --git a/unif.h b/unif.h
index c8b0ef1..2a179ea 100644 (file)
--- a/unif.h
+++ b/unif.h
@@ -15,7 +15,7 @@
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
  */\r
 \r
 void ANROM_Init(CartInfo *info);\r
  */\r
 \r
 void ANROM_Init(CartInfo *info);\r
@@ -46,7 +46,9 @@ void MALEE_Init(CartInfo *info);
 void CNROM_Init(CartInfo *info);\r
 void CPROM_Init(CartInfo *info);\r
 void GNROM_Init(CartInfo *info);\r
 void CNROM_Init(CartInfo *info);\r
 void CPROM_Init(CartInfo *info);\r
 void GNROM_Init(CartInfo *info);\r
+void UNL3DBlock_Init(CartInfo *info);\r
 \r
 \r
+void TBROM_Init(CartInfo *info);\r
 void TEROM_Init(CartInfo *info);\r
 void TFROM_Init(CartInfo *info);\r
 void TGROM_Init(CartInfo *info);\r
 void TEROM_Init(CartInfo *info);\r
 void TFROM_Init(CartInfo *info);\r
 void TGROM_Init(CartInfo *info);\r
@@ -62,6 +64,7 @@ void DEIROM_Init(CartInfo *info);
 \r
 void TCA01_Init(CartInfo *info);\r
 void TCU01_Init(CartInfo *info);\r
 \r
 void TCA01_Init(CartInfo *info);\r
 void TCU01_Init(CartInfo *info);\r
+void TCU02_Init(CartInfo *info);\r
 void S8259A_Init(CartInfo *info);\r
 void S8259B_Init(CartInfo *info);\r
 void S8259C_Init(CartInfo *info);\r
 void S8259A_Init(CartInfo *info);\r
 void S8259B_Init(CartInfo *info);\r
 void S8259C_Init(CartInfo *info);\r
@@ -72,6 +75,7 @@ void SA0161M_Init(CartInfo *info);
 \r
 void SA72007_Init(CartInfo *info);\r
 void SA72008_Init(CartInfo *info);\r
 \r
 void SA72007_Init(CartInfo *info);\r
 void SA72008_Init(CartInfo *info);\r
+void SA009_Init(CartInfo *info);\r
 void SA0036_Init(CartInfo *info);\r
 void SA0037_Init(CartInfo *info);\r
 \r
 void SA0036_Init(CartInfo *info);\r
 void SA0037_Init(CartInfo *info);\r
 \r
@@ -79,24 +83,51 @@ void Supervision16_Init(CartInfo *info);
 void Super24_Init(CartInfo *info);\r
 void Novel_Init(CartInfo *info);\r
 \r
 void Super24_Init(CartInfo *info);\r
 void Novel_Init(CartInfo *info);\r
 \r
-void BMC42in1r_Init(CartInfo *info);\r
 void BMC64in1nr_Init(CartInfo *info);\r
 void BMC70in1_Init(CartInfo *info);\r
 void BMC70in1B_Init(CartInfo *info);\r
 void BMC13in1JY110_Init(CartInfo *info);\r
 void BMCT262_Init(CartInfo *info);\r
 void BMCFK23C_Init(CartInfo *info);\r
 void BMC64in1nr_Init(CartInfo *info);\r
 void BMC70in1_Init(CartInfo *info);\r
 void BMC70in1B_Init(CartInfo *info);\r
 void BMC13in1JY110_Init(CartInfo *info);\r
 void BMCT262_Init(CartInfo *info);\r
 void BMCFK23C_Init(CartInfo *info);\r
+void BMCFK23CA_Init(CartInfo *info);\r
+void BMCD1038_Init(CartInfo *info);\r
+void BMCA65AS_Init(CartInfo *info);\r
+void BMCGK192_Init(CartInfo *info);\r
+void BMCGS2004_Init(CartInfo *info);\r
+void BMCGS2013_Init(CartInfo *info);\r
+void BMC190in1_Init(CartInfo *info);\r
+void BMCGhostbusters63in1_Init(CartInfo *info);\r
+void BMCBS5_Init(CartInfo *info);\r
 \r
 void DreamTech01_Init(CartInfo *info);\r
 void Mapper190_Init(CartInfo *info);\r
 void UNLCC21_Init(CartInfo *info);\r
 \r
 void DreamTech01_Init(CartInfo *info);\r
 void Mapper190_Init(CartInfo *info);\r
 void UNLCC21_Init(CartInfo *info);\r
+void UNLCN22M_Init(CartInfo *info);\r
 void UNLSL1632_Init(CartInfo *info);\r
 void UNLKOF97_Init(CartInfo *info);\r
 void UNLSL1632_Init(CartInfo *info);\r
 void UNLKOF97_Init(CartInfo *info);\r
-void UNLSonic_Init(CartInfo *info);\r
+void UNLA9746_Init(CartInfo *info);\r
 void UNLSHeroes_Init(CartInfo *info);\r
 void UNLH2288_Init(CartInfo *info);\r
 void UNL8237_Init(CartInfo *info);\r
 void UNLSHeroes_Init(CartInfo *info);\r
 void UNLH2288_Init(CartInfo *info);\r
 void UNL8237_Init(CartInfo *info);\r
+void UNL8237A_Init(CartInfo *info);\r
 void UNL8157_Init(CartInfo *info);\r
 void UNL8157_Init(CartInfo *info);\r
+void UNL22211_Init(CartInfo *info);\r
+void UNLTF1201_Init(CartInfo *info);\r
+void UNLKS7032_Init(CartInfo *info);\r
+void UNLT230_Init(CartInfo *info);\r
+void UNLAX5705_Init(CartInfo *info);\r
+void UNLDANCE_Init(CartInfo *info);\r
+void UNLOneBus_Init(CartInfo *info);\r
+void UNLSC127_Init(CartInfo *info);\r
+\r
+void UNLEDU2000_Init(CartInfo *info);\r
+void UNL6035052_Init(CartInfo *info);\r
+void UNLN625092_Init(CartInfo *info);\r
+void UNLSMB2J_Init(CartInfo *info);\r
+//void UNL09034A_Init(CartInfo *info);\r
+void BMC411120C_Init(CartInfo *info);\r
+void BMC830118C_Init(CartInfo *info);\r
+void BMCT2271_Init(CartInfo *info);\r
 \r
 extern uint8 *UNIFchrrama;  // Meh.  So I can stop CHR RAM\r
          // bank switcherooing with certain boards...\r
 \r
 extern uint8 *UNIFchrrama;  // Meh.  So I can stop CHR RAM\r
          // bank switcherooing with certain boards...\r