updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
authornotaz <notasas@gmail.com>
Mon, 30 Apr 2007 14:16:20 +0000 (14:16 +0000)
committernotaz <notasas@gmail.com>
Mon, 30 Apr 2007 14:16:20 +0000 (14:16 +0000)
git-svn-id: file:///home/notaz/opt/svn/fceu@117 be3aeb3a-fb24-0410-a615-afba39da0efa

170 files changed:
Makefile.base
boards/112.c [new file with mode: 0644]
boards/164.c [new file with mode: 0644]
boards/183.c [new file with mode: 0644]
boards/186.c [new file with mode: 0644]
boards/8157.c [new file with mode: 0644]
boards/8237.c [new file with mode: 0644]
boards/90.c [new file with mode: 0644]
boards/Makefile
boards/addrlatch.c [new file with mode: 0644]
boards/bonza.c [new file with mode: 0644]
boards/datalatch.c [new file with mode: 0644]
boards/deirom.c [new file with mode: 0644]
boards/dream.c [new file with mode: 0644]
boards/h2288.c
boards/karaoke.c [new file with mode: 0644]
boards/konami-qtai.c [new file with mode: 0644]
boards/malee.c
boards/mapinc.h
boards/mmc1.c [new file with mode: 0644]
boards/mmc3.c [new file with mode: 0644]
boards/mmc3.h [new file with mode: 0644]
boards/mmc5.c [new file with mode: 0644]
boards/n106.c [new file with mode: 0644]
boards/novel.c
boards/sachen.c
boards/simple.c [deleted file]
boards/subor.c [new file with mode: 0644]
boards/super24.c
boards/supervision.c
boards/tengen.c [new file with mode: 0644]
cart.c
cart.h
driver.h
drivers/gp2x/main.c
fce.c
fce.h
fds.c
fds.h
file.h
general.c
general.h
git.h
ines-bad.h [new file with mode: 0644]
ines-correct.h [new file with mode: 0644]
ines.c
ines.h
input.c
input.h
mappers/105.c [deleted file]
mappers/113.c
mappers/117.c
mappers/15.c
mappers/151.c
mappers/16.c
mappers/17.c
mappers/18.c
mappers/180.c
mappers/182.c [deleted file]
mappers/183.c [new file with mode: 0644]
mappers/187.c [new file with mode: 0644]
mappers/189.c
mappers/19.c [deleted file]
mappers/193.c [new file with mode: 0644]
mappers/200.c [new file with mode: 0644]
mappers/201.c [new file with mode: 0644]
mappers/202.c [new file with mode: 0644]
mappers/203.c [new file with mode: 0644]
mappers/204.c [new file with mode: 0644]
mappers/208.c [new file with mode: 0644]
mappers/21.c
mappers/211.c [new file with mode: 0644]
mappers/212.c [new file with mode: 0644]
mappers/213.c [new file with mode: 0644]
mappers/214.c [new file with mode: 0644]
mappers/215.c [new file with mode: 0644]
mappers/217.c [new file with mode: 0644]
mappers/22.c
mappers/225.c
mappers/226.c
mappers/227.c
mappers/228.c
mappers/229.c
mappers/23.c
mappers/230.c [new file with mode: 0644]
mappers/231.c [new file with mode: 0644]
mappers/232.c
mappers/234.c
mappers/235.c [new file with mode: 0644]
mappers/240.c
mappers/241.c [new file with mode: 0644]
mappers/242.c
mappers/244.c [new file with mode: 0644]
mappers/246.c
mappers/248.c [deleted file]
mappers/24and26.c
mappers/25.c
mappers/255.c [new file with mode: 0644]
mappers/27.c [new file with mode: 0644]
mappers/32.c
mappers/33.c
mappers/40.c
mappers/41.c
mappers/42.c
mappers/43.c
mappers/46.c
mappers/50.c [moved from mappers/112.c with 50% similarity]
mappers/51.c
mappers/57.c [moved from mappers/249.c with 64% similarity]
mappers/58.c [new file with mode: 0644]
mappers/59.c [new file with mode: 0644]
mappers/6.c
mappers/60.c [new file with mode: 0644]
mappers/61.c [moved from mappers/245.c with 58% similarity]
mappers/62.c [new file with mode: 0644]
mappers/64.c [deleted file]
mappers/65.c
mappers/67.c
mappers/68.c
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/88.c
mappers/89.c
mappers/90.c [deleted file]
mappers/91.c [new file with mode: 0644]
mappers/92.c
mappers/95.c
mappers/97.c
mappers/99.c
mappers/Makefile
mappers/emu2413.c [new file with mode: 0644]
mappers/emu2413.h [new file with mode: 0644]
mappers/emutypes.h [new file with mode: 0644]
mappers/fmopl.c [deleted file]
mappers/fmopl.h [deleted file]
mappers/mapinc.h
mappers/mapshare.h [deleted file]
mappers/mmc2and4.c
mappers/simple.c
mappers/vrc7snd.c [deleted file]
mappers/vrc7tone.h [new file with mode: 0644]
md5.c [new file with mode: 0644]
md5.h [new file with mode: 0644]
memory.h
nsf.c
nsf.h
sound.c
sound.h
state.c
state.h
svga.c
svga.h
unif.c
unif.h
video.c
vsuni.c [new file with mode: 0644]
vsuni.h [new file with mode: 0644]
x6502.h

index 734b1b1..af0e348 100644 (file)
@@ -1,11 +1,11 @@
 CFLAGS  = -Wall  ${TFLAGS}
-OBJECTS = fce.o video.o general.o endian.o svga.o sound.o nsf.o fds.o netplay.o ines.o state.o unif.o input.o file.o cart.o crc32.o memory.o cheat.o debug.o
+OBJECTS = fce.o video.o general.o endian.o svga.o sound.o nsf.o fds.o netplay.o ines.o state.o unif.o input.o file.o cart.o crc32.o memory.o cheat.o debug.o md5.o vsuni.o
 # x6502.o
 
 fceu:          fceu2
 include        mappers/Makefile
 include boards/Makefile
-include mbshare/Makefile
+#include mbshare/Makefile
 include input/Makefile
 
 fceu2:         ${OBJECTS} ${MOBJS} ${MUOBJS} ${MUSOBJS} ${INPOBJS} ${OBJDRIVER}
diff --git a/boards/112.c b/boards/112.c
new file mode 100644 (file)
index 0000000..a58cf5c
--- /dev/null
@@ -0,0 +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"
+
+static uint8 reg[8];
+static uint8 mirror, cmd;
+static uint8 *WRAM=NULL;
+static SFORMAT StateRegs[]=
+{
+  {&cmd, 1, "CMD"},
+  {&mirror, 1, "MIRR"},
+  {reg, 8, "REGS"},
+  {0}
+};
+
+static void Sync(void)
+{
+  setmirror(mirror^1);
+  setprg8(0x8000,reg[0]);
+  setprg8(0xA000,reg[1]);
+  setchr2(0x0000,reg[2]>>1);
+  setchr2(0x0800,reg[3]>>1);
+  setchr1(0x1000,reg[4]);
+  setchr1(0x1400,reg[5]);
+  setchr1(0x1800,reg[6]);
+  setchr1(0x1C00,reg[7]);
+}
+
+static DECLFW(M112Write)
+{
+  switch(A)
+  {
+    case 0xe000: mirror=V&1; Sync(); ;break;
+    case 0x8000: cmd=V&7; break;
+    case 0xa000: reg[cmd]=V; Sync(); break;
+  }
+}
+
+static void M112Close(void)
+{
+  if(WRAM)
+    FCEU_gfree(WRAM);
+  WRAM = NULL;
+}
+
+static void M112Power(void)
+{
+  Sync();
+  setprg16(0xC000,~0);
+  setprg8r(0x10,0x6000,0);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xFFFF,M112Write);
+  SetReadHandler(0x6000,0x7FFF,CartBR);
+  SetWriteHandler(0x6000,0x7FFF,CartBW);
+}
+
+static void StateRestore(int version)
+{
+  Sync();
+}
+
+void Mapper112_Init(CartInfo *info)
+{
+  info->Power=M112Power;
+  info->Close=M112Close;
+  GameStateRestore=StateRestore;
+  WRAM=(uint8*)FCEU_gmalloc(8192);
+  SetupCartPRGMapping(0x10,WRAM,8192,1);
+  AddExState(WRAM, 8192, 0, "WRAM");
+  AddExState(&StateRegs, ~0, 0, 0);
+}
diff --git a/boards/164.c b/boards/164.c
new file mode 100644 (file)
index 0000000..5b4bf05
--- /dev/null
@@ -0,0 +1,110 @@
+/* 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 uint8 cmd;
+static uint8 DRegs[8];
+
+static SFORMAT StateRegs[]=
+{
+  {&cmd, 1, "CMD"},
+  {DRegs, 8, "DREG"},
+  {0}
+};
+
+static void Sync(void)
+{
+  setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF));
+}
+
+static void StateRestore(int version)
+{
+  Sync();
+}
+
+static DECLFW(Write)
+{
+  switch (A&0x7300)
+  {
+    case 0x5100: DRegs[0]=V; Sync(); break;
+    case 0x5000: DRegs[1]=V; Sync(); break;
+  }
+}
+
+static DECLFW(Write2)
+{
+  switch (A&0x7300)
+  {
+    case 0x5200: DRegs[0]=V; Sync(); break;
+    case 0x5000: DRegs[1]=V; Sync(); break;
+  }
+}
+
+static uint8 WRAM[8192];
+static DECLFR(AWRAM)
+{
+  return(WRAM[A-0x6000]);
+}
+
+static DECLFW(BWRAM)
+{
+  WRAM[A-0x6000]=V;
+}
+
+static void Power(void)
+{
+  memset(DRegs,0,8);
+  DRegs[1]=0xFF;
+  setchr8(0);
+  cmd=0;
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x4020,0xFFFF,Write);
+  SetReadHandler(0x6000,0x7FFF,AWRAM);
+  SetWriteHandler(0x6000,0x7FFF,BWRAM);
+  Sync();
+}
+
+static void Power2(void)
+{
+  memset(DRegs,0,8);
+  DRegs[1]=0xFF;
+  setchr8(0);
+  cmd=0;
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x4020,0xFFFF,Write2);
+  SetReadHandler(0x6000,0x7FFF,AWRAM);
+  SetWriteHandler(0x6000,0x7FFF,BWRAM);
+  Sync();
+}
+
+void Mapper164_Init(CartInfo *info)
+{
+  info->Power=Power;
+  GameStateRestore=StateRestore;
+  AddExState(&StateRegs, ~0, 0, 0);
+}
+
+void Mapper163_Init(CartInfo *info)
+{
+  info->Power=Power2;
+  GameStateRestore=StateRestore;
+  AddExState(&StateRegs, ~0, 0, 0);
+}
diff --git a/boards/183.c b/boards/183.c
new file mode 100644 (file)
index 0000000..94cf072
--- /dev/null
@@ -0,0 +1,117 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * Gimmick Bootleg\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&0x7000)>>11)-6)|((A&8)>>3);\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
diff --git a/boards/186.c b/boards/186.c
new file mode 100644 (file)
index 0000000..3698c6c
--- /dev/null
@@ -0,0 +1,104 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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(32384);\r
+  SetupCartPRGMapping(0x10,WRAM,32384,1);\r
+  AddExState(WRAM, 32384, 0, "WRAM");\r
+  AddExState(StateRegs, ~0, 0, 0);\r
+}\r
diff --git a/boards/8157.c b/boards/8157.c
new file mode 100644 (file)
index 0000000..3c4a4fb
--- /dev/null
@@ -0,0 +1,77 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
+  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(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=0;\r
+  Sync();\r
+}\r
+\r
+static void UNL8157Reset(void)\r
+{\r
+  cmdreg=0;\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
diff --git a/boards/8237.c b/boards/8237.c
new file mode 100644 (file)
index 0000000..5b4e2df
--- /dev/null
@@ -0,0 +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
+ */
+
+#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");
+}
diff --git a/boards/90.c b/boards/90.c
new file mode 100644 (file)
index 0000000..489a540
--- /dev/null
@@ -0,0 +1,408 @@
+/* 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 int is209;
+
+static uint8 IRQMode;        // from $c001
+static uint8 IRQPre;         // from $c004
+static uint8 IRQPreSize;     // from $c007
+static uint8 IRQCount;       // from $c005
+static uint8 IRQXOR;         // Loaded from $C006
+static uint8 IRQa;           // $c002, $c003, and $c000
+
+static uint8 mul[2];
+static uint8 regie;
+
+static uint8 tkcom[4];
+static uint8 prgb[4];
+static uint8 chrlow[8];
+static uint8 chrhigh[8];
+
+static uint16 names[4];
+static uint8 tekker;
+
+static SFORMAT Tek_StateRegs[]={
+  {&IRQMode, 1, "IRQMODE"},
+  {&IRQPre, 1, "IRQPRE"},
+  {&IRQPreSize, 1, "IRQPRESIZE"},
+  {&IRQCount, 1, "IRQC"},
+  {&IRQXOR, 1, "IRQXOR"},
+  {&IRQa, 1, "IRQa"},
+  {mul, 2, "MUL"},
+  {&regie, 1, "REGI"},
+  {tkcom, 4, "TKCO"},
+  {prgb, 4, "PRGB"},
+  {chrlow, 4, "CHRL"},
+  {chrhigh, 8, "CHRH"},
+  {&names[0], 2|FCEUSTATE_RLSB, "NMS0"},
+  {&names[1], 2|FCEUSTATE_RLSB, "NMS1"},
+  {&names[2], 2|FCEUSTATE_RLSB, "NMS2"},
+  {&names[3], 2|FCEUSTATE_RLSB, "NMS3"},
+  {&tekker, 1, "TEKR"},
+  {0}
+};
+
+static DECLFR(M90Read)
+{
+  switch(A)
+  {
+    case 0x5800: return (mul[0]*mul[1]);
+    case 0x5801: return((mul[0]*mul[1])>>8);
+    case 0x5803: return (regie);
+    default: return(tekker);
+  }
+}
+
+static void mira(void)
+{
+  if(tkcom[0]&0x20 && is209)
+  {
+    int x;
+    if(tkcom[0]&0x40)        // Name tables are ROM-only
+    {
+      for(x=0;x<4;x++)
+         setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x);
+    }
+    else                        // Name tables can be RAM or ROM.
+    {
+      for(x=0;x<4;x++)
+      {
+        if((tkcom[2]&0x80)==(names[x]&0x80))        // RAM selected.
+          setntamem(NTARAM+((names[x]&0x1)<<10),1,x);
+        else
+          setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x);
+      }
+    }
+  }
+  else
+  {
+    switch(tkcom[1]&3)
+    {
+      case 0: setmirror(MI_V); break;
+      case 1: setmirror(MI_H); break;
+      case 2: setmirror(MI_0); break;
+      case 3: setmirror(MI_1); break;
+    }
+  }
+}
+
+static void tekprom(void)
+{
+  uint32 bankmode=((tkcom[3]&6)<<5);
+  switch(tkcom[0]&3)
+  {
+    case 1:              // 16 KB
+         setprg16(0x8000,(prgb[0]&0x1F)|((tkcom[3]&6)<<4));
+         setprg16(0xC000,(prgb[2]&0x1F)|((tkcom[3]&6)<<4));
+         break;
+    case 2:              //2 = 8 KB ??
+         if(tkcom[0]&0x4)
+         {
+           setprg8(0x8000,(prgb[0]&0x3F)|bankmode);
+           setprg8(0xa000,(prgb[1]&0x3F)|bankmode);
+           setprg8(0xc000,(prgb[2]&0x3F)|bankmode);
+           setprg8(0xe000,(prgb[3]&0x3F)|bankmode);
+         }
+         else
+         {
+           if(tkcom[0]&0x80)
+             setprg8(0x6000,(prgb[3]&0x3F)|bankmode);
+           setprg8(0x8000,(prgb[0]&0x3F)|bankmode);
+           setprg8(0xa000,(prgb[1]&0x3F)|bankmode);
+           setprg8(0xc000,(prgb[2]&0x3F)|bankmode);
+           setprg8(0xe000,((~0)&0x3F)|bankmode);
+         }
+         break;
+    case 0:
+    case 3:
+         setprg8(0x8000,(prgb[0]&0x3F)|bankmode);
+         setprg8(0xa000,(prgb[1]&0x3F)|bankmode);
+         setprg8(0xc000,(prgb[2]&0x3F)|bankmode);
+         setprg8(0xe000,(prgb[3]&0x3F)|bankmode);
+         break;
+  }
+}
+
+static void tekvrom(void)
+{
+  int x, bank=0, mask=0xFFFF;
+  if(!(tkcom[3]&0x20))
+  {
+    bank=(tkcom[3]&1)|((tkcom[3]&0x18)>>2);
+    switch (tkcom[0]&0x18)
+    {
+      case 0x00: bank<<=5; mask=0x1F; break;
+      case 0x08: bank<<=6; mask=0x3F; break;
+      case 0x10: bank<<=7; mask=0x7F; break;
+      case 0x18: bank<<=8; mask=0xFF; break;
+    }
+  }
+  switch(tkcom[0]&0x18)
+  {
+    case 0x00:      // 8KB
+         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);
+         break;
+    case 0x10:      // 2KB
+         for(x=0;x<8;x+=2)
+            setchr2(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank);
+         break;
+    case 0x18:      // 1KB
+         for(x=0;x<8;x++)
+            setchr1(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank);
+         break;
+  }
+}
+
+static DECLFW(M90Write)
+{
+  if(A==0x5800) mul[0]=V;
+  else if(A==0x5801) mul[1]=V;
+  else if(A==0x5803) regie=V;
+
+  A&=0xF007;
+  if(A>=0x8000 && A<=0x8003)
+  {
+    prgb[A&3]=V;
+    tekprom();
+  }
+  else if(A>=0x9000 && A<=0x9007)
+  {
+    chrlow[A&7]=V;
+    tekvrom();
+  }
+  else if(A>=0xa000 && A<=0xa007)
+  {
+    chrhigh[A&7]=V;
+    tekvrom();
+  }
+  else if(A>=0xb000 && A<=0xb007)
+  {
+    if(A&4)
+    {
+      names[A&3]&=0x00FF;
+      names[A&3]|=V<<8;
+    }
+    else
+    {
+      names[A&3]&=0xFF00;
+      names[A&3]|=V;
+    }
+    mira();
+  }
+  else if(A>=0xd000 && A<=0xdfff)
+  {
+    tkcom[A&3]=V;
+    tekprom();
+    tekvrom();
+    mira();
+/*
+  switch (A&3)
+  {
+   case 00: FCEU_printf("Main Control Register:\n");
+            FCEU_printf("  PGR Banking mode: %d\n",V&7);
+            FCEU_printf("  CHR Banking mode: %d\n",(V>>3)&3);
+            FCEU_printf("  6000-7FFF addresses mapping: %s\n",(V&0x80)?"Yes":"No");
+            FCEU_printf("  Nametable control: %s\n",(V&0x20)?"Enabled":"Disabled");
+            if(V&0x20)
+               FCEU_printf("  Nametable can be: %s\n",(V&0x40)?"ROM Only":"RAM or ROM");
+            break;
+   case 01: FCEU_printf("Mirroring mode: ");
+            switch (V&3)
+            {
+             case 00: FCEU_printf("Vertical\n");break;
+             case 01: FCEU_printf("Horizontal\n");break;
+             case 02: FCEU_printf("Nametable 0 only\n");break;
+             case 03: FCEU_printf("Nametable 1 only\n");break;
+            }
+            FCEU_printf("Mirroring flag: %s\n",(V&0x80)?"On":"Off");
+            break;
+   case 02: if((((tkcom[0])>>5)&3)==1)
+              FCEU_printf("Nametable ROM/RAM select mode: %d\n",V>>7);
+            break;
+   case 03:
+            FCEU_printf("CHR Banking mode: %s\n",(V&0x20)?"Entire CHR ROM":"256Kb Switching mode");
+            if(!(V&0x20)) FCEU_printf("256K CHR bank number: %02x\n",(V&1)|((V&0x18)>>2));
+            FCEU_printf("512K PRG bank number: %d\n",(V&6)>>1);
+            FCEU_printf("CHR Bank mirroring: %s\n",(V&0x80)?"Swapped":"Normal operate");
+  }
+*/
+  }
+  else switch(A)
+  {
+    case 0xc000: //FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable");
+                 IRQa=V&1;if(!(V&1)) X6502_IRQEnd(FCEU_IQEXT);break;
+    case 0xc002: //FCEU_printf("Disable IRQ (C002) scanline=%d\n", scanline);
+                 IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
+    case 0xc003: //FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline);
+                 IRQa=1;break;
+    case 0xc001: 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;
+    case 0xc004: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR);
+                 IRQPre=V^IRQXOR;break;
+    case 0xc005: //FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR);
+                 IRQCount=V^IRQXOR;break;
+    case 0xc006: //FCEU_printf("Xor Value: %d\n",V);
+                 IRQXOR=V;break;
+    case 0xc007: //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");
+                 IRQPreSize=V;break;
+  }
+}
+
+static void CCL(void)
+{
+  if((IRQMode>>6) == 1) // Count Up
+  {
+    IRQCount++;
+    if((IRQCount == 0) && IRQa)
+      X6502_IRQBegin(FCEU_IQEXT);
+  }
+  else if((IRQMode>>6) == 2) // Count down
+  {
+    IRQCount--;
+    if((IRQCount == 0xFF) && IRQa)
+      X6502_IRQBegin(FCEU_IQEXT);
+  }
+}
+
+static void ClockCounter(void)
+{
+  uint8 premask;
+
+  if(IRQMode & 0x4)
+    premask = 0x7;
+  else
+    premask = 0xFF;
+  if((IRQMode>>6) == 1) // Count up
+  {
+    IRQPre++;
+    if((IRQPre & premask) == 0) CCL();
+  }
+  else if((IRQMode>>6) == 2) // Count down
+  {
+    IRQPre--;
+    if((IRQPre & premask) == premask) CCL();
+  }
+}
+
+static void SLWrap(void)
+{
+  int x;
+  if((IRQMode&3)!=2) for(x=0;x<8;x++) ClockCounter();
+}
+
+static uint32 lastread;
+static void FP_FASTAPASS(1) M90PPU(uint32 A)
+{
+  if(lastread!=A)
+  {
+    lastread=A;
+    if((IRQMode&3)==2)
+    {
+      ClockCounter();
+      ClockCounter();
+    }
+  }
+}
+
+static void togglie()
+{
+  tekker>>=6;
+  if(tekker>3)
+    tekker=0;
+  else
+    tekker++;
+  tekker<<=6;
+  FCEU_printf("tekker=%04x\n",tekker);
+  memset(tkcom,0xff,sizeof(tkcom));
+  memset(prgb,0xff,sizeof(prgb));
+  tekprom();
+  tekvrom();
+}
+
+static void M90Restore(int version)
+{
+  tekprom();
+  tekvrom();
+  mira();
+}
+
+static void M90Power(void)
+{
+  SetWriteHandler(0x5000,0xffff,M90Write);
+  SetReadHandler(0x5000,0x5fff,M90Read);
+  SetReadHandler(0x6000,0xffff,CartBR);
+
+  mul[0]=mul[1]=regie=0xFF;
+
+  memset(tkcom,0xff,sizeof(tkcom));
+  memset(prgb,0xff,sizeof(prgb));
+  memset(chrlow,0xff,sizeof(chrlow));
+  memset(chrhigh,0xff,sizeof(chrhigh));
+  memset(names,0x00,sizeof(names));
+
+  tekker=0;
+
+  tekprom();
+  tekvrom();
+}
+
+
+void Mapper90_Init(CartInfo *info)
+{
+  is209=0;
+  info->Reset=togglie;
+  info->Power=M90Power;
+  PPU_hook = M90PPU;
+  GameHBIRQHook2 = SLWrap;
+  GameStateRestore=M90Restore;
+  AddExState(Tek_StateRegs, ~0, 0, 0);
+}
+
+void Mapper209_Init(CartInfo *info)
+{
+  is209=1;
+  info->Reset=togglie;
+  info->Power=M90Power;
+  PPU_hook = M90PPU;
+  GameHBIRQHook2 = SLWrap;
+  GameStateRestore=M90Restore;
+  AddExState(Tek_StateRegs, ~0, 0, 0);
+}
index 58dd4ef..b63f897 100644 (file)
@@ -1,9 +1,6 @@
-MUOBJS   =     boards/simple.o boards/malee.o boards/supervision.o boards/novel.o boards/super24.o boards/h2288.o boards/sachen.o
+MUOBJS += boards/mmc5.o boards/mmc3.o boards/mmc1.o boards/tengen.o boards/bonza.o boards/deirom.o
+MUOBJS += boards/dream.o boards/konami-qtai.o boards/n106.o boards/karaoke.o boards/90.o boards/112.o
+MUOBJS += boards/164.o boards/183.o boards/186.o boards/8237.o boards/8157.o boards/addrlatch.o
+MUOBJS += boards/datalatch.o boards/h2288.o boards/malee.o boards/novel.o boards/sachen.o
+MUOBJS += boards/subor.o boards/super24.o boards/supervision.o
 
-boards/simple.o:       boards/simple.c
-boards/malee.o:                boards/malee.c
-boards/supervision.o:  boards/supervision.c
-boards/novel.o:                boards/novel.c
-boards/super24.o:      boards/super24.c
-boards/h2288.o:                boards/h2288.c
-boards/sachen.o:       boards/sachen.c
diff --git a/boards/addrlatch.c b/boards/addrlatch.c
new file mode 100644 (file)
index 0000000..37be90a
--- /dev/null
@@ -0,0 +1,53 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint16 addrlatche;\r
+\r
+//------------------ UNLCC21 ---------------------------\r
+\r
+static DECLFW(UNLCC21Write)\r
+{\r
+  addrlatche=A;\r
+  setchr8(addrlatche&1);\r
+  setmirror(MI_0+((addrlatche&2)>>1));\r
+}\r
+\r
+static void UNLCC21Power(void)\r
+{\r
+  setprg32(0x8000,0);\r
+  setchr8(0);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xffff,UNLCC21Write);\r
+}\r
+\r
+static void UNLCC21Restore(int version)\r
+{\r
+  setchr8(addrlatche&1);\r
+  setmirror(MI_0+((addrlatche&2)>>1));\r
+}\r
+\r
+void UNLCC21_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLCC21Power;\r
+  GameStateRestore=UNLCC21Restore;\r
+  AddExState(&addrlatche, 2, 0, "ALATC");\r
+}\r
diff --git a/boards/bonza.c b/boards/bonza.c
new file mode 100644 (file)
index 0000000..5e572f1
--- /dev/null
@@ -0,0 +1,139 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg_reg;\r
+static uint8 chr_reg;\r
+\r
+static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt;\r
+static uint16 sim0data;\r
+static uint8 sim0array[128] =\r
+{\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,\r
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA,\r
+};\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&prg_reg, 1, "PREG"},\r
+  {&chr_reg, 1, "CREG"},\r
+  {0}\r
+};\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
+// FCEU_printf("%04x:%04x\n",A,V);\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\n",A,V);\r
+  sim0reg=V;\r
+  if(!sim0reg)\r
+  {\r
+    sim0bit=sim0byte=sim0parity=0;\r
+    sim0data=sim0array[0];\r
+    sim0bcnt=0x80;\r
+  }\r
+  else if(sim0reg&0x20)\r
+  {\r
+    sim0bcnt=0x20;\r
+  }\r
+}\r
+\r
+static DECLFR(M216Read5000)\r
+{\r
+  if(sim0reg&0x60)\r
+  {\r
+    sim0reg=(sim0reg^(sim0reg<<1))&0x40;\r
+    return sim0reg;\r
+  }\r
+  else\r
+  {\r
+    uint8 sim0out=0;\r
+    if(sim0bit<8)\r
+    {\r
+//       sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1;\r
+      sim0out=(sim0data&1)<<6;\r
+      sim0data>>=1;\r
+      sim0bit++;\r
+      sim0parity+=sim0data;\r
+    }\r
+    else if(sim0bit==8)\r
+    {\r
+      sim0bit++;\r
+      sim0out=sim0parity&1;\r
+    }\r
+    else if(sim0bit==9)\r
+    {\r
+      if(sim0byte==sim0bcnt)\r
+        sim0out=0x60;\r
+      else\r
+      {\r
+        sim0bit=0;\r
+        sim0byte++;\r
+        sim0data=sim0array[sim0byte];\r
+        sim0out=0;\r
+      }\r
+    }\r
+//    FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte);\r
+    return sim0out;\r
+  }\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/datalatch.c b/boards/datalatch.c
new file mode 100644 (file)
index 0000000..217adb4
--- /dev/null
@@ -0,0 +1,207 @@
+/* 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 uint8 latche;
+
+//------------------ CPROM ---------------------------
+
+static DECLFW(CPROMWrite)
+{
+  latche=V&3;
+  setchr4(0x1000,latche);
+}
+
+static void CPROMReset(void)
+{
+  setprg32(0x8000,0);
+  setchr8(0);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xffff,CPROMWrite);
+}
+
+static void CPROMRestore(int version)
+{
+  setchr4(0x1000,latche);
+}
+
+void CPROM_Init(CartInfo *info)
+{
+  info->Power=CPROMReset;
+  GameStateRestore=CPROMRestore;
+  AddExState(&latche, 1, 0, "LATC");
+}
+
+//------------------ CNROM ---------------------------
+
+DECLFW(CNROMWrite)
+{
+  latche=V&3;
+  setchr8(latche);
+}
+
+static void CNROMReset(void)
+{
+  setprg16(0x8000,0);
+  setprg16(0xC000,1);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xffff,CNROMWrite);
+}
+
+static void CNROMRestore(int version)
+{
+  setchr8(latche);
+}
+
+void CNROM_Init(CartInfo *info)
+{
+  info->Power=CNROMReset;
+  GameStateRestore=CNROMRestore;
+  AddExState(&latche, 1, 0, "LATC");
+}
+
+//------------------ NROM128 ---------------------------
+
+static void NROM128Reset(void)
+{
+  setprg16(0x8000,0);
+  setprg16(0xC000,0);
+  setchr8(0);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+}
+
+void NROM128_Init(CartInfo *info)
+{
+  info->Power=NROM128Reset;
+}
+
+//------------------ NROM256 ---------------------------
+
+static void NROM256Reset(void)
+{
+  setprg16(0x8000,0);
+  setprg16(0xC000,1);
+  setchr8(0);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+}
+
+void NROM256_Init(CartInfo *info)
+{
+  info->Power=NROM256Reset;
+}
+
+//------------------ MHROM ---------------------------
+
+static DECLFW(MHROMWrite)
+{
+  setprg32(0x8000,V>>4);
+  setchr8(V);
+  latche=V;
+}
+
+static void MHROMReset(void)
+{
+  setprg32(0x8000,0);
+  setchr8(0);
+  latche=0;
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+}
+
+static void MHROMRestore(int version)
+{
+  setprg32(0x8000,latche);
+  setchr8(latche);
+  SetWriteHandler(0x8000,0xffff,MHROMWrite);
+}
+
+void MHROM_Init(CartInfo *info)
+{ 
+  info->Power=MHROMReset;
+  AddExState(&latche, 1, 0,"LATC");
+  PRGmask32[0]&=1;
+  CHRmask8[0]&=1;
+  GameStateRestore=MHROMRestore;
+}
+
+//------------------ UNROM ---------------------------
+
+static void UNROMRestore(int version)
+{
+  setprg16(0x8000,latche);
+}
+
+static DECLFW(UNROMWrite)
+{
+  setprg16(0x8000,V);
+  latche=V;
+}
+
+static void UNROMReset(void)
+{
+  setprg16(0x8000,0);
+  setprg16(0xc000,~0);
+  setchr8(0);
+  SetWriteHandler(0x8000,0xffff,UNROMWrite);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  latche=0;
+}
+
+void UNROM_Init(CartInfo *info)
+{
+  info->Power=UNROMReset;
+  PRGmask16[0]&=7;
+  AddExState(&latche, 1, 0, "LATC");
+  GameStateRestore=UNROMRestore;
+}
+
+//------------------ GNROM ---------------------------
+
+static void GNROMSync()
+{
+  setchr8(latche&3);
+  setprg32(0x8000,(latche>>4)&3);
+}
+
+static DECLFW(GNROMWrite)
+{
+  latche=V&0x33;
+  GNROMSync();
+}
+
+static void GNROMStateRestore(int version)
+{
+  GNROMSync();
+}
+
+static void GNROMReset(void)
+{
+  latche=0;
+  GNROMSync();
+  SetWriteHandler(0x8000,0xffff,GNROMWrite);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+}
+
+void GNROM_Init(CartInfo *info)
+{
+  info->Power=GNROMReset;
+  AddExState(&latche, 1, 0, "LATC");
+  GameStateRestore=GNROMStateRestore;
+}
diff --git a/boards/deirom.c b/boards/deirom.c
new file mode 100644 (file)
index 0000000..7a1ed43
--- /dev/null
@@ -0,0 +1,82 @@
+/* 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 uint8 cmd;
+static uint8 DRegs[8];
+
+static SFORMAT DEI_StateRegs[]=
+{
+  {&cmd, 1, "CMD"},
+  {DRegs, 8, "DREG"},
+  {0}
+};
+
+static void Sync(void)
+{
+  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]);
+  setprg8(0xa000,DRegs[7]);
+}
+
+static void StateRestore(int version)
+{
+  Sync();
+}
+
+static DECLFW(DEIWrite)
+{
+  switch(A&0x8001)
+  {
+    case 0x8000: cmd=V&0x07; break;
+    case 0x8001: if(cmd<=0x05)
+                   V&=0x3F;
+                 else
+                   V&=0x0F;
+                 if(cmd<=0x01) V>>=1;
+                 DRegs[cmd&0x07]=V;
+                 Sync();
+                 break;
+  }
+}
+
+static void DEIPower(void)
+{
+  setprg8(0xc000,0xE);
+  setprg8(0xe000,0xF);
+  cmd=0;
+  memset(DRegs,0,8);
+  Sync();
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xFFFF,DEIWrite);
+}
+
+
+void DEIROM_Init(CartInfo *info)
+{
+  info->Power=DEIPower;
+  GameStateRestore=StateRestore;
+  AddExState(&DEI_StateRegs, ~0, 0, 0);
+}
diff --git a/boards/dream.c b/boards/dream.c
new file mode 100644 (file)
index 0000000..16214f7
--- /dev/null
@@ -0,0 +1,56 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 latch;\r
+\r
+static void DoPRG(void)\r
+{\r
+  setprg16(0x8000,latch);\r
+  setprg16(0xC000,8);\r
+}\r
+\r
+static DECLFW(DREAMWrite)\r
+{\r
+  latch=V&7;\r
+  DoPRG();\r
+}\r
+\r
+static void DREAMPower(void)\r
+{\r
+  latch=0;\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x5020,0x5020,DREAMWrite);\r
+  setchr8(0);\r
+  DoPRG();\r
+}\r
+\r
+static void Restore(int version)\r
+{\r
+  DoPRG();\r
+}\r
+\r
+void DreamTech01_Init(CartInfo *info)\r
+{\r
+  GameStateRestore=Restore;\r
+  info->Power=DREAMPower;\r
+  AddExState(&latch, 1, 0, "LATCH");\r
+}\r
index 9b9dcbc..c2c6621 100644 (file)
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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
- */
-
-/* Not finished.  Darn evil game... *Mumble*... */
-
-#include "mapinc.h"
-
-static uint8 cmd;
-static uint8 regs[8];
-
-static void DoPRG(void)
-{
- if(cmd&0x40)
- {
-  setprg8(0xC000,regs[4]);
-  setprg8(0xA000,regs[5]);
-  setprg8(0x8000,~1);
-  setprg8(0xE000,~0);
- }
- else
- {
-  setprg8(0x8000,regs[4]);
-  setprg8(0xA000,regs[5]);
-  setprg8(0xC000,~1);
-  setprg8(0xE000,~0);
- }
-}
-
-static void DoCHR(void)
-{
- uint32 base=(cmd&0x80)<<5;
-
- setchr2(0x0000^base,regs[0]);
- setchr2(0x0800^base,regs[2]);
-
- setchr1(0x1000^base,regs[6]);
- setchr1(0x1400^base,regs[1]);
- setchr1(0x1800^base,regs[7]);
- setchr1(0x1c00^base,regs[3]);
-}
-
-static DECLFW(H2288Write)
-{
- //printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W);
- //RAM[0x7FB]=0x60;
- switch(A&0xE001)
- {
-  case 0xa000:setmirror((V&1)^1);break;
-  case 0x8000://  DumpMem("out",0x0000,0xFFFF);
-             cmd=V;DoPRG();DoCHR();
-              X6502_Rebase();break;
-  case 0x8001:regs[cmd&7]=V;
-             if((cmd&7)==4 || (cmd&7)==5) {
-              DoPRG();
-               X6502_Rebase();
-             } else
-              DoCHR();
-             break;
- }
-}
-
-static DECLFR(H2288Read)
-{
- //printf("Rd: $%04x, $%04x\n",A,X.PC.W);
- return((X.DB&0xFE)|(A&(A>>8)));
-}
-
-static void H2288Reset(void)
-{
-  int x;
-
-  SetReadHandler(0x5800,0x5FFF,H2288Read);
-  SetReadHandler(0x8000,0xFFFF,CartBR);
-  SetWriteHandler(0x8000,0xFFFF,H2288Write);
-  for(x=0;x<8;x++) regs[x]=0;
-  cmd=0;
-  DoPRG();
-  DoCHR();
-}
-
-void H2288_Init(void)
-{
-  BoardPower=H2288Reset;
-}
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
diff --git a/boards/karaoke.c b/boards/karaoke.c
new file mode 100644 (file)
index 0000000..eccf9c2
--- /dev/null
@@ -0,0 +1,78 @@
+/* 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 uint8 DReg;
+static SFORMAT StateRegs[]=
+{
+  {&DReg, 1, "DREG"},
+  {0}
+};
+
+static void Sync(void)
+{
+  if(DReg)
+  {
+    if(DReg & 0x10)
+      setprg16(0x8000,(DReg&7));
+    else
+      setprg16(0x8000,(DReg&7)|8);
+  }
+  else
+    setprg16(0x8000,7);
+}
+
+static void StateRestore(int version)
+{
+  Sync();
+}
+
+static DECLFW(M188Write)
+{
+  DReg=V;
+  Sync();
+}
+
+static DECLFR(testr)
+{
+  return(3);
+}
+
+
+static void Power(void)
+{
+  setchr8(0);
+  setprg8(0xc000,0xE);
+  setprg8(0xe000,0xF);
+  DReg = 0;
+  Sync();
+  SetReadHandler(0x6000,0x7FFF,testr);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xFFFF,M188Write);
+}
+
+
+void Mapper188_Init(CartInfo *info)
+{
+  info->Power=Power;
+  GameStateRestore=StateRestore;
+  AddExState(&StateRegs, ~0, 0, 0);
+}
diff --git a/boards/konami-qtai.c b/boards/konami-qtai.c
new file mode 100644 (file)
index 0000000..ff552e1
--- /dev/null
@@ -0,0 +1,128 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * CAI Shogakko no Sansu\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 *CHRRAM=NULL;\r
+static uint8 SWRAM[4096];\r
+\r
+static uint8 regs[16];\r
+static uint8 WRAM[4096];\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&regs, 16, "REGS"},\r
+  {WRAM, 4096, "WRAM"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  if(regs[5]&0x40)\r
+  {\r
+    setchr4r(0,0x1000,regs[5]&0x3F);\r
+  }\r
+  else\r
+  {\r
+    setchr4r(0x10,0x0000,regs[5]);\r
+    setchr4r(0x10,0x1000,regs[5]^1);\r
+  }\r
+  setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F));\r
+  setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F));\r
+  setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F));\r
+  setprg8r(1,0xE000,~0);\r
+  setmirror((regs[0xA]&3));\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
+  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];\r
+}\r
+\r
+static DECLFR(AWRAM)\r
+{\r
+  return(WRAM[A-0x7000]);\r
+}\r
+static DECLFW(BWRAM)\r
+{\r
+  WRAM[A-0x7000]=V;\r
+}\r
+\r
+static DECLFR(ASWRAM)\r
+{\r
+  return(SWRAM[A-0x6000]);\r
+}\r
+static DECLFW(BSWRAM)\r
+{\r
+  SWRAM[A-0x6000]=V;\r
+}\r
+\r
+static void M190Power(void)\r
+{\r
+  setvram8(CHRRAM);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M190Write);\r
+// SetReadHandler(0xDA00,0xDA00,M190Read);\r
+// SetReadHandler(0xDB00,0xDB00,M190Read);\r
+  SetReadHandler(0xDC00,0xDC00,M190Read);\r
+  SetReadHandler(0xDD00,0xDD00,M190Read);\r
+  SetReadHandler(0x7000,0x7FFF,AWRAM);\r
+  SetWriteHandler(0x7000,0x7FFF,BWRAM);\r
+  SetReadHandler(0x6000,0x6FFF,ASWRAM);\r
+  SetWriteHandler(0x6000,0x6FFF,BSWRAM);\r
+  Sync();\r
+}\r
+\r
+static void M190Close(void)\r
+{\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  CHRRAM=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
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=SWRAM;\r
+    info->SaveGameLen[0]=4096;\r
+  }\r
+  GameStateRestore=StateRestore;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(8192);\r
+  SetupCartCHRMapping(0x10,CHRRAM,8192,1);\r
+  AddExState(CHRRAM, 8192, 0, "CHRRAM");\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
index f575159..b0f194e 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
-DECLFW(MWrite)
-{
- (GameMemBlock-0x7000)[A]=V;
-}
+static uint8 WRAM[2048];
 
 static void MALEEReset(void)
 {
@@ -31,15 +28,14 @@ static void MALEEReset(void)
   SetReadHandler(0x8000,0xFFFF,CartBR);
   SetReadHandler(0x6000,0x67ff,CartBR);
   SetReadHandler(0x7000,0x77FF,CartBR);
-  SetWriteHandler(0x7000,0x77FF,MWrite);
   setprg2r(1,0x6000,0);
   setprg32(0x8000,0);
   setchr8(0);
 }
 
-void MALEE_Init(void)
+void MALEE_Init(CartInfo *info)
 {
-  AddExState(GameMemBlock, 2048, 0,"RAM");
-  SetupCartPRGMapping(0x10,GameMemBlock,2048,1);
-  BoardPower=MALEEReset;
+  info->Power=MALEEReset;
+  SetupCartPRGMapping(0x10, WRAM, 2048, 1);
+  AddExState(WRAM, 2048, 0,"RAM");
 }
index e6d4c41..7c2b042 100644 (file)
@@ -1,11 +1,12 @@
-#include       "../types.h"
-#include        "../x6502.h"
-#include        "../fce.h"
-#include        "../version.h"
-#include        "../memory.h"
-#include       "../sound.h"
-#include        "../svga.h"
-#include       "../state.h"
-#define UNIFPRIV
-#include        "../unif.h"
-#include       "../cart.h"
+#include "../types.h"
+#include "../x6502.h"
+#include "../fce.h"
+#include "../ppu.h"
+#include "../memory.h"
+#include "../sound.h"
+#include "../state.h"
+#include "../cart.h"
+#include "../cheat.h"
+#include "../unif.h"
+#include "../svga.h"
+#include <string.h>
diff --git a/boards/mmc1.c b/boards/mmc1.c
new file mode 100644 (file)
index 0000000..0eefc59
--- /dev/null
@@ -0,0 +1,426 @@
+/* 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
+#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;\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
+  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
+\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 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
+static void MMC1MIRROR(void)\r
+{\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
+\r
+static uint64 lreset;\r
+static DECLFW(MMC1_write)\r
+{\r
+  int n=(A>>13)-4;\r
+  //FCEU_DispMessage("%016x",timestampbase+timestamp);\r
+  //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
+  if((timestampbase+timestamp)<(lreset+2)) return;\r
+\r
+  if(V&0x80)\r
+  {\r
+    DRegs[0]|=0xC;\r
+    BufferShift=Buffer=0;\r
+    MMC1PRG();\r
+    lreset=timestampbase+timestamp;\r
+    return;\r
+  }\r
+  Buffer|=(V&1)<<(BufferShift++);\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. */ // it is now!\r
+}\r
+\r
+static void MMC1CMReset(void)\r
+{\r
+  int i;\r
+  for(i=0;i<4;i++)\r
+     DRegs[i]=0;\r
+  Buffer = BufferShift = 0;\r
+  DRegs[0]=0x1F;\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
+         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 FP_FASTAPASS(1) 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
+  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
+    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
+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
diff --git a/boards/mmc3.c b/boards/mmc3.c
new file mode 100644 (file)
index 0000000..14ce5cb
--- /dev/null
@@ -0,0 +1,1408 @@
+/* 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=0;
+uint8 *WRAM=0;
+uint8 *CHRRAM=0;
+uint32 CHRRAMSize=0;
+uint8 EXPREGS[8]={0,0,0,0,0,0,0,0};    /* For bootleg games, mostly. */
+
+static uint8 A000B=0,A001B=0;
+static uint8 DRegBuf[8]={0,0,0,0,0,0,0,0};
+
+#undef IRQCount
+#undef IRQLatch
+#undef IRQa
+uint8 IRQCount=0,IRQLatch=0,IRQa=0;
+uint8 IRQReload=0;
+
+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=0;
+
+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)
+{
+ 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;
+       break;
+ }
+}
+
+DECLFW(MMC3_IRQWrite)
+{
+ 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 && !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();
+}
+
+static void genmmc3restore(int version)
+{
+ if(mwrap) mwrap(A000B&1);
+ FixMMC3PRG(MMC3_cmd);
+ FixMMC3CHR(MMC3_cmd);
+}
+
+static void GENCWRAP(uint32 A, uint8 V)
+{
+ 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)
+{
+ SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite);
+ SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
+ SetReadHandler(0x8000,0xFFFF,CartBR);
+ A001B=A000B=0;
+ setmirror(1);
+ if(mmc3opts&1)
+ {
+  if(wrams==1024)
+  {
+   FCEU_CheatAddRAM(1,0x7000,WRAM);
+   SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6);
+   SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6);
+  }
+  else
+  {
+   FCEU_CheatAddRAM(wrams>>10,0x6000,WRAM);
+   SetReadHandler(0x6000,0x6000+wrams-1,MAWRAM);
+   SetWriteHandler(0x6000,0x6000+wrams-1,MBWRAM);
+  }
+  if(!(mmc3opts&2))
+     FCEU_dwmemset(WRAM,0,wrams);
+ }
+ MMC3RegReset();
+ if(CHRRAM)
+  FCEU_dwmemset(CHRRAM,0,CHRRAMSize);
+}
+
+static void GenMMC3Close(void)
+{
+ if(CHRRAM)
+    FCEU_gfree(CHRRAM);
+ if(WRAM)
+    FCEU_gfree(WRAM);
+ CHRRAM=WRAM=NULL;
+}
+
+void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery)
+{
+pwrap=GENPWRAP;
+ cwrap=GENCWRAP;
+ mwrap=GENMWRAP;
+
+ wrams=wram<<10;
+
+ PRGmask8[0]&=(prg>>13)-1;
+ CHRmask1[0]&=(chr>>10)-1;
+ CHRmask2[0]&=(chr>>11)-1;
+
+ if(wram)
+ {
+  mmc3opts|=1;
+  WRAM=(uint8*)FCEU_gmalloc(wrams);
+  AddExState(WRAM, wrams, 0, "WRAM");
+ }
+
+ if(battery)
+ {
+  mmc3opts|=2;
+  info->SaveGame[0]=WRAM;
+  info->SaveGameLen[0]=wrams;
+ }
+
+ if(!chr)
+ {
+  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;
+ 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 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)
+{
+ uint32 NV=V;
+ if(EXPREGS[2]&8)
+    NV&=(1<<((EXPREGS[2]&7)+1))-1;
+ else
+    NV&=0;
+ NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4);
+                    // &0x10(not 0xf0) is valid given the original
+                    // description of mapper 45 by kevtris,
+                    // but this fixes Super 8 in 1.
+ 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;
+// FCEU_printf("write 0=%04x 1=%04x 2=%04x 3=%04x (%04x:%04x)\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3],A,V);
+ FixMMC3PRG(MMC3_cmd);
+ FixMMC3CHR(MMC3_cmd);
+}
+
+static void M45Reset(void)
+{
+ FCEU_dwmemset(EXPREGS,0,5);
+ MMC3RegReset();
+}
+
+static void M45Power(void)
+{
+ M45Reset();
+ 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)
+{
+//  FCEU_printf("%04x:%04x\n",A,V);
+//  if((V==0)||(V==1)) //Dai-2-Ji - Super Robot Taisen (As).nes
+  if((V==0)||(V==1)||(V==2)||(V==3)) //Ying Lie Qun Xia Zhuan (Chinese).nes, 4096 CHR RAM
+//  if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes
+//  if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese).nes, 4096 CHR RAM
+     setchr1r(0x10,A,V);
+  else
+     setchr1r(0x0,A,V);
+}
+
+void Mapper74_Init(CartInfo *info)
+{
+ GenMMC3_Init(info, 512, 256, 8, info->battery);
+ cwrap=M74CW;
+// CHRRAMSize=2048;
+ CHRRAMSize=4096;
+ 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;
+  IRQCount=V;
+ }
+ 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)
+{
+ setprg8(A,V);
+ if(EXPREGS[0]&0x80)
+    setprg16(0x8000,EXPREGS[0]&7);
+}
+
+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));
+}
+
+static DECLFW(M116Write)
+{
+ EXPREGS[0]=V;
+ FixMMC3PRG(MMC3_cmd);
+ 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;
+ 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 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 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: IRQCount=V; 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 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)*128));
+}
+
+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 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;
+  case 0xE001: IRQCount=V; break;
+  case 0xC001: IRQa=1; 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);
+}
+
+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);
+}
diff --git a/boards/mmc3.h b/boards/mmc3.h
new file mode 100644 (file)
index 0000000..e2c7149
--- /dev/null
@@ -0,0 +1,22 @@
+extern uint8 MMC3_cmd;\r
+extern uint8 *WRAM;\r
+//extern uint8 *CHRRAM;\r
+extern uint8 EXPREGS[8];\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 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
diff --git a/boards/mmc5.c b/boards/mmc5.c
new file mode 100644 (file)
index 0000000..d14ca0e
--- /dev/null
@@ -0,0 +1,839 @@
+/* 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);
+}
diff --git a/boards/n106.c b/boards/n106.c
new file mode 100644 (file)
index 0000000..2872d16
--- /dev/null
@@ -0,0 +1,472 @@
+/* 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 uint16 IRQCount;
+static uint8 IRQa;
+
+static uint8 WRAM[8192];
+static uint8 IRAM[128];
+
+static DECLFR(AWRAM)
+{
+  return(WRAM[A-0x6000]);
+}
+
+static DECLFW(BWRAM)
+{
+  WRAM[A-0x6000]=V;
+}
+
+void Mapper19_ESI(void);
+
+static uint8 NTAPage[4];
+
+static uint8 dopol;
+static uint8 gorfus;
+static uint8 gorko;
+
+static void NamcoSound(int Count);
+static void NamcoSoundHack(void);
+static void DoNamcoSound(int32 *Wave, int Count);
+//static void DoNamcoSoundHQ(void);
+static void SyncHQ(int32 ts);
+
+static int is210;        /* Lesser mapper. */
+
+static uint8 PRG[3];
+static uint8 CHR[8];
+
+static SFORMAT N106_StateRegs[]={
+  {PRG,3,"PRG"},
+  {CHR,8,"CHR"},
+  {NTAPage,4,"NTA"},
+  {0}
+};
+
+static void SyncPRG(void)
+{
+  setprg8(0x8000,PRG[0]);
+  setprg8(0xa000,PRG[1]);
+  setprg8(0xc000,PRG[2]);
+  setprg8(0xe000,0x3F);
+}
+
+static void FP_FASTAPASS(1) NamcoIRQHook(int a)
+{
+  if(IRQa)
+  {
+    IRQCount+=a;
+    if(IRQCount>=0x7FFF)
+    {
+      X6502_IRQBegin(FCEU_IQEXT);
+      IRQa=0;
+      IRQCount=0x7FFF; //7FFF;
+    }
+  }
+}
+
+static DECLFR(Namco_Read4800)
+{
+  uint8 ret=IRAM[dopol&0x7f];
+  /* Maybe I should call NamcoSoundHack() here? */
+  if(!fceuindbg)
+    if(dopol&0x80)
+      dopol=(dopol&0x80)|((dopol+1)&0x7f);
+  return ret;
+}
+
+static DECLFR(Namco_Read5000)
+{
+  return(IRQCount);
+}
+
+static DECLFR(Namco_Read5800)
+{
+  return(IRQCount>>8);
+}
+
+static void FASTAPASS(2) DoNTARAMROM(int w, uint8 V)
+{
+  NTAPage[w]=V;
+  if(V>=0xE0)
+    setntamem(NTARAM+((V&1)<<10), 1, w);
+  else
+  {
+    V&=CHRmask1[0];
+    setntamem(CHRptr[0]+(V<<10), 0, w);
+  }
+}
+
+static void FixNTAR(void)
+{
+  int x;
+  for(x=0;x<4;x++)
+     DoNTARAMROM(x,NTAPage[x]);
+}
+
+static void FASTAPASS(2) DoCHRRAMROM(int x, uint8 V)
+{
+  CHR[x]=V;
+  if(!is210 && !((gorfus>>((x>>2)+6))&1) && (V>=0xE0))
+  {
+    // printf("BLAHAHA: %d, %02x\n",x,V);
+    //setchr1r(0x10,x<<10,V&7);
+  }
+  else
+    setchr1(x<<10,V);
+}
+
+static void FixCRR(void)
+{
+  int x;
+  for(x=0;x<8;x++)
+     DoCHRRAMROM(x,CHR[x]);
+}
+
+static DECLFW(Mapper19C0D8_write)
+{
+  DoNTARAMROM((A-0xC000)>>11,V);
+}
+
+static uint32 FreqCache[8];
+static uint32 EnvCache[8];
+static uint32 LengthCache[8];
+
+static void FixCache(int a,int V)
+{
+  int w=(a>>3)&0x7;
+  switch(a&0x07)
+  {
+    case 0x00:FreqCache[w]&=~0x000000FF;FreqCache[w]|=V;break;
+    case 0x02:FreqCache[w]&=~0x0000FF00;FreqCache[w]|=V<<8;break;
+    case 0x04:FreqCache[w]&=~0x00030000;FreqCache[w]|=(V&3)<<16;
+              LengthCache[w]=(8-((V>>2)&7))<<2;
+              break;
+    case 0x07:EnvCache[w]=(double)(V&0xF)*576716;break;
+  }
+}
+
+static DECLFW(Mapper19_write)
+{
+  A&=0xF800;
+  if(A>=0x8000 && A<=0xb800)
+    DoCHRRAMROM((A-0x8000)>>11,V);
+  else switch(A)
+  {
+    case 0x4800:
+         if(dopol&0x40)
+         {
+           if(FSettings.SndRate)
+           {
+             NamcoSoundHack();
+             GameExpSound.Fill=NamcoSound;
+             GameExpSound.HiFill=0;//DoNamcoSoundHQ;
+             GameExpSound.HiSync=SyncHQ;
+           }
+           FixCache(dopol,V);
+         }
+         IRAM[dopol&0x7f]=V;
+         if(dopol&0x80)
+           dopol=(dopol&0x80)|((dopol+1)&0x7f);
+         break;
+    case 0xf800:
+         dopol=V;break;
+    case 0x5000:
+         IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
+    case 0x5800:
+         IRQCount&=0x00ff;IRQCount|=(V&0x7F)<<8;
+         IRQa=V&0x80;
+         X6502_IRQEnd(FCEU_IQEXT);
+         break;
+    case 0xE000:
+         gorko=V&0xC0;
+         PRG[0]=V&0x3F;
+         SyncPRG();
+         break;
+    case 0xE800:
+         gorfus=V&0xC0;
+         FixCRR();
+         PRG[1]=V&0x3F;
+         SyncPRG();
+         break;
+    case 0xF000:
+         PRG[2]=V&0x3F;
+         SyncPRG();
+         break;
+  }
+}
+
+static int dwave=0;
+
+static void NamcoSoundHack(void)
+{
+  int32 z,a;
+#if 0
+  if(FSettings.soundq>=1)
+  {
+    DoNamcoSoundHQ();
+    return;
+  }
+#endif
+  z=((SOUNDTS<<16)/soundtsinc)>>4;
+  a=z-dwave;
+  if(a) DoNamcoSound(&Wave[dwave], a);
+  dwave+=a;
+}
+
+static void NamcoSound(int Count)
+{
+  int32 z,a;
+  z=((SOUNDTS<<16)/soundtsinc)>>4;
+  a=z-dwave;
+  if(a) DoNamcoSound(&Wave[dwave], a);
+  dwave=0;
+}
+
+static uint32 PlayIndex[8];
+static int32 vcount[8];
+static int32 CVBC;
+
+#define TOINDEX        (16+1)
+
+// 16:15
+static void SyncHQ(int32 ts)
+{
+  CVBC=ts;
+}
+
+
+/* Things to do:
+        1        Read freq low
+        2        Read freq mid
+        3        Read freq high
+        4        Read envelope
+        ...?
+*/
+
+static INLINE uint32 FetchDuff(uint32 P, uint32 envelope)
+{
+  uint32 duff;
+  duff=IRAM[((IRAM[0x46+(P<<3)]+(PlayIndex[P]>>TOINDEX))&0xFF)>>1];
+  if((IRAM[0x46+(P<<3)]+(PlayIndex[P]>>TOINDEX))&1)
+    duff>>=4;
+  duff&=0xF;
+  duff=(duff*envelope)>>16;
+  return(duff);
+}
+
+#if 0
+static void DoNamcoSoundHQ(void)
+{
+  int32 P,V;
+  int32 cyclesuck=(((IRAM[0x7F]>>4)&7)+1)*15;
+
+  for(P=7;P>=(7-((IRAM[0x7F]>>4)&7));P--)
+  {
+    if((IRAM[0x44+(P<<3)]&0xE0) && (IRAM[0x47+(P<<3)]&0xF))
+    {
+      uint32 freq;
+      int32 vco;
+      uint32 duff2,lengo,envelope;
+
+      vco=vcount[P];
+      freq=FreqCache[P];
+      envelope=EnvCache[P];
+      lengo=LengthCache[P];
+
+      duff2=FetchDuff(P,envelope);
+      for(V=CVBC<<1;V<SOUNDTS<<1;V++)
+      {
+        WaveHi[V>>1]+=duff2;
+        if(!vco)
+        {
+          PlayIndex[P]+=freq;
+          while((PlayIndex[P]>>TOINDEX)>=lengo) PlayIndex[P]-=lengo<<TOINDEX;
+          duff2=FetchDuff(P,envelope);
+          vco=cyclesuck;
+        }
+        vco--;
+      }
+      vcount[P]=vco;
+    }
+  }
+  CVBC=SOUNDTS;
+}
+#endif
+
+static void DoNamcoSound(int32 *Wave, int Count)
+{
+  int P,V;
+  for(P=7;P>=7-((IRAM[0x7F]>>4)&7);P--)
+  {
+    if((IRAM[0x44+(P<<3)]&0xE0) && (IRAM[0x47+(P<<3)]&0xF))
+    {
+      int32 inc;
+      uint32 freq;
+      int32 vco;
+      uint32 duff,duff2,lengo,envelope;
+
+      vco=vcount[P];
+      freq=FreqCache[P];
+      envelope=EnvCache[P];
+      lengo=LengthCache[P];
+
+      if(!freq) {/*printf("Ack");*/  continue;}
+
+      {
+        int c=((IRAM[0x7F]>>4)&7)+1;
+        inc=(long double)(FSettings.SndRate<<15)/((long double)freq*21477272/((long double)0x400000*c*45));
+      }
+
+      duff=IRAM[(((IRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
+      if((IRAM[0x46+(P<<3)]+PlayIndex[P])&1)
+        duff>>=4;
+      duff&=0xF;
+      duff2=(duff*envelope)>>19;
+      for(V=0;V<Count*16;V++)
+      {
+        if(vco>=inc)
+        {
+          PlayIndex[P]++;
+          if(PlayIndex[P]>=lengo)
+            PlayIndex[P]=0;
+          vco-=inc;
+          duff=IRAM[(((IRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
+          if((IRAM[0x46+(P<<3)]+PlayIndex[P])&1)
+            duff>>=4;
+          duff&=0xF;
+          duff2=(duff*envelope)>>19;
+        }
+        Wave[V>>4]+=duff2;
+        vco+=0x8000;
+      }
+      vcount[P]=vco;
+    }
+  }
+}
+
+static void Mapper19_StateRestore(int version)
+{
+  SyncPRG();
+  FixNTAR();
+  FixCRR();
+  int x;
+  for(x=0x40;x<0x80;x++)
+     FixCache(x,IRAM[x]);
+}
+
+static void M19SC(void)
+{
+  if(FSettings.SndRate)
+    Mapper19_ESI();
+}
+
+void Mapper19_ESI(void)
+{
+  GameExpSound.RChange=M19SC;
+  memset(vcount,0,sizeof(vcount));
+  memset(PlayIndex,0,sizeof(PlayIndex));
+  CVBC=0;
+}
+
+void NSFN106_Init(void)
+{
+  SetWriteHandler(0xf800,0xffff,Mapper19_write);
+  SetWriteHandler(0x4800,0x4fff,Mapper19_write);
+  SetReadHandler(0x4800,0x4fff,Namco_Read4800);
+  Mapper19_ESI();
+}
+
+static int battery=0;
+
+static void N106_Power(void)
+{
+  int x;
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xffff,Mapper19_write);
+  SetWriteHandler(0x4020,0x5fff,Mapper19_write);
+  if(!is210)
+  {
+    SetWriteHandler(0xc000,0xdfff,Mapper19C0D8_write);
+    SetReadHandler(0x4800,0x4fff,Namco_Read4800);
+    SetReadHandler(0x5000,0x57ff,Namco_Read5000);
+    SetReadHandler(0x5800,0x5fff,Namco_Read5800);
+    NTAPage[0]=NTAPage[1]=NTAPage[2]=NTAPage[3]=0xFF;
+    FixNTAR();
+  }
+
+  SetReadHandler(0x6000,0x7FFF,AWRAM);
+  SetWriteHandler(0x6000,0x7FFF,BWRAM);
+  FCEU_CheatAddRAM(8,0x6000,WRAM);
+
+  gorfus=0xFF;
+  SyncPRG();
+  FixCRR();
+
+  if(!battery)
+  {
+    FCEU_dwmemset(WRAM,0,8192);
+    FCEU_dwmemset(IRAM,0,128);
+  }
+  for(x=0x40;x<0x80;x++)
+     FixCache(x,IRAM[x]);
+}
+
+void Mapper19_Init(CartInfo *info)
+{
+  is210=0;
+  battery=info->battery;
+  info->Power=N106_Power;
+
+  MapIRQHook=NamcoIRQHook;
+  GameStateRestore=Mapper19_StateRestore;
+  GameExpSound.RChange=M19SC;
+
+  if(FSettings.SndRate)
+    Mapper19_ESI();
+
+  AddExState(WRAM, 8192, 0, "WRAM");
+  AddExState(IRAM, 128, 0, "WRAM");
+  AddExState(N106_StateRegs, ~0, 0, 0);
+
+  if(info->battery)
+  {
+    info->SaveGame[0]=WRAM;
+    info->SaveGameLen[0]=8192;
+    info->SaveGame[1]=IRAM;
+    info->SaveGameLen[1]=128;
+  }
+}
+
+static void Mapper210_StateRestore(int version)
+{
+  SyncPRG();
+  FixCRR();
+}
+
+void Mapper210_Init(CartInfo *info)
+{
+  is210=1;
+  GameStateRestore=Mapper210_StateRestore;
+  info->Power=N106_Power;
+  AddExState(WRAM, 8192, 0, "WRAM");
+}
index fe3a37c..26e70ec 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
+static uint8 latch;
+
 static void DoNovel(void)
 {
- setprg32(0x8000,GameMemBlock[0]&3);
- setchr8(GameMemBlock[0]&7);
- X6502_Rebase();
+  setprg32(0x8000,latch&3);
+  setchr8(latch&7);
 }
 
 static DECLFW(NovelWrite)
 {
GameMemBlock[0]=A&0xFF;
- DoNovel();
 latch=A&0xFF;
 DoNovel();
 }
 
 static void NovelReset(void)
 {
   SetWriteHandler(0x8000,0xFFFF,NovelWrite);
-  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetReadHandler(0x8000,0xFFFF,CartBR);  
   setprg32(0x8000,0);
   setchr8(0);
 }
 
 static void NovelRestore(int version)
 {
- DoNovel();
 DoNovel();
 }
 
-void Novel_Init(void)
+void Novel_Init(CartInfo *info)
 {
-  AddExState(&GameMemBlock[0], 1, 0,"L1");
-  BoardPower=NovelReset;
+  AddExState(&latch, 1, 0,"L1");
+  info->Power=NovelReset;
   GameStateRestore=NovelRestore;
 }
index a26dd07..bcec3a9 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 static uint8 cmd;
 static uint8 latch[8];
-#define CHRRAM (GameMemBlock)
+
+static void MSync(uint8 mirr)
+{
+  switch(mirr&3)
+  {
+    case 0:setmirror(MI_V);break;
+    case 1:setmirror(MI_H);break;
+    case 2:setmirrorw(0,1,1,1);break;
+    case 3:setmirror(MI_0);break;
+  }
+}
 
 static void S74LS374NSynco(void)
 {
- setprg32(0x8000,latch[0]);
- X6502_Rebase();
- setchr8(latch[1]);
- setmirror(latch[2]&1);
-// setchr8(6);
+  setprg32(0x8000,latch[0]);
+  setchr8(latch[1]|latch[3]|latch[4]);
+  MSync(latch[2]);
 }
 
 static DECLFW(S74LS374NWrite)
 {
- //printf("$%04x:$%02x\n",A,V);
- A&=0x4101;
- if(A==0x4100)
-  cmd=V&7;
- else
- {
-  switch(cmd)
+  A&=0x4101;
+  if(A==0x4100)
+    cmd=V&7;
+  else
   {
-   case 0:latch[0]=0;latch[1]=3;break;
-   case 4:latch[1]&=3;latch[1]|=(V<<2);break;
-   case 5:latch[0]=V&0x7;break;
-   case 6:latch[1]&=0x1C;latch[1]|=V&3;break;
-   case 7:latch[2]=V&1;break;
+    switch(cmd)
+    {
+      case 2:latch[3]=(V&1)<<3;break;
+      case 4:latch[4]=(V&1)<<2;break;
+      case 5:latch[0]=V&0x7;break;
+      case 6:latch[1]=V&3;break;
+      case 7:latch[2]=V>>1;break;
+    }
+    S74LS374NSynco();
   }
-  S74LS374NSynco();
- }
 }
 
-static void S74LS374NReset(void)
+static void S74LS374NPower(void)
 {
- latch[0]=latch[2]=0;
- latch[1]=3;
- S74LS374NSynco();
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
+   latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
+   S74LS374NSynco();
+   SetReadHandler(0x8000,0xFFFF,CartBR);
+   SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
 }
 
 static void S74LS374NRestore(int version)
 {
- S74LS374NSynco();
  S74LS374NSynco();
 }
 
-void S74LS374N_Init(void)
+void S74LS374N_Init(CartInfo *info)
 {
BoardPower=S74LS374NReset;
- GameStateRestore=S74LS374NRestore;
AddExState(latch, 3, 0, "LATC");
- AddExState(&cmd, 1, 0, "CMD");
 info->Power=S74LS374NPower;
 GameStateRestore=S74LS374NRestore;
 AddExState(latch, 5, 0, "LATC");
 AddExState(&cmd, 1, 0, "CMD");
 }
 
-static int type;
-static void S8259Synco(void)
+static void S74LS374NASynco(void)
 {
int x;
-
setprg32(0x8000,latch[5]&7);
- X6502_Rebase();
 setprg32(0x8000,latch[0]);
+  setchr8(latch[1]);
 MSync(latch[2]);
+}
 
- if(!UNIFchrrama)      // No CHR RAM?  Then BS'ing is ok.
- {
-  if(!type)
+static DECLFW(S74LS374NAWrite)
+{
+  A&=0x4101;
+  if(A==0x4100)
+    cmd=V&7;
+  else
   {
-   for(x=0;x<4;x++)
-    setchr2(0x800*x,(x&1)|((latch[x]&7)<<1)|((latch[4]&7)<<4));
+    switch(cmd)
+    {
+      case 0:latch[0]=0;latch[1]=3;break;
+      case 2:latch[3]=(V&1)<<3;break;
+      case 4:latch[1]=(latch[1]&6)|(V&3);break;
+      case 5:latch[0]=V&1;break;
+      case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break;
+      case 7:latch[2]=V&1;break;
+    }
+    S74LS374NSynco();
   }
-  else
+}
+
+static void S74LS374NAPower(void)
+{
+   latch[0]=latch[2]=latch[3]=latch[4]=0;
+   latch[1]=3;
+   S74LS374NASynco();
+   SetReadHandler(0x8000,0xFFFF,CartBR);
+   SetWriteHandler(0x4100,0x7FFF,S74LS374NAWrite);
+}
+
+void S74LS374NA_Init(CartInfo *info)
+{
+  info->Power=S74LS374NAPower;
+  GameStateRestore=S74LS374NRestore;
+  AddExState(latch, 5, 0, "LATC");
+  AddExState(&cmd, 1, 0, "CMD");
+}
+
+static int type;
+//static int PPUbus;
+static void S8259Synco(void)
+{
+  int x;
+  setprg32(0x8000,latch[5]&7);
+
+  if(!UNIFchrrama)        // No CHR RAM?  Then BS'ing is ok.
   {
-   for(x=0;x<4;x++)
-    setchr2(0x800*x,(latch[x]&0x7)|((latch[4]&7)<<3));
+    for(x=0;x<4;x++)
+    {
+      int bank;
+      if(latch[7]&1)
+        bank=(latch[0]&0x7)|((latch[4]&7)<<3);
+      else
+        bank=(latch[x]&0x7)|((latch[4]&7)<<3);
+      switch (type)
+      {
+        case 00: bank=(bank<<1)|(x&1); setchr2(0x800*x,bank); break;
+        case 01: setchr2(0x800*x,bank); break;
+        case 02: bank=(bank<<2)|(x&3); setchr2(0x800*x,bank); break;
+        case 03: bank=latch[x]&7;
+                 switch (x&3)
+                 {
+                   case 01: bank|=(latch[4]&1)<<4;break;
+                   case 02: bank|=(latch[4]&2)<<3;break;
+                   case 03: bank|=((latch[4]&4)<<2)|((latch[6]&1)<<3);break;
+                 }
+                 setchr1(0x400*x,bank);
+                 setchr4(0x1000,~0);
+                 break;
+      }
+    }
   }
- }
- switch((latch[7]>>1)&3)
- {
-  case 0:setmirrorw(0,0,0,1);break;
-  case 1:setmirror(MI_H);break;
-  case 2:setmirror(MI_V);break;
-  case 3:setmirror(MI_0);break;
- }
+  MSync(latch[7]>>1);
 }
 
 static DECLFW(S8259Write)
 {
- A&=0x4101;
- if(A==0x4100) cmd=V;
- else
- {
-  latch[cmd&7]=V;
-  S8259Synco();
- }
+  A&=0x4101;
+  if(A==0x4100)
+    cmd=V;
+  else
+  {
+    latch[cmd&7]=V;
+    S8259Synco();
+  }
 }
 
 static void S8259Reset(void)
 {
- int x;
- cmd=0;
 int x;
 cmd=0;
 
- for(x=0;x<8;x++) latch[x]=0;
if(UNIFchrrama) setchr8(0);
 for(x=0;x<8;x++) latch[x]=0;
+  setchr8(0);
 
- S8259Synco();
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0x4100,0x7FFF,S8259Write);
 S8259Synco();
 SetReadHandler(0x8000,0xFFFF,CartBR);
 SetWriteHandler(0x4100,0x7FFF,S8259Write);
 }
 
 static void S8259Restore(int version)
 {
- S8259Synco();
+  S8259Synco();
+}
+
+void S8259A_Init(CartInfo *info) // Kevin's Horton 141 mapper
+{
+  info->Power=S8259Reset;
+  GameStateRestore=S8259Restore;
+  AddExState(latch, 8, 0, "LATC");
+  AddExState(&cmd, 1, 0, "CMD");
+  type=0;
 }
 
-void S8259A_Init(void)
+void S8259B_Init(CartInfo *info) // Kevin's Horton 138 mapper
 {
- BoardPower=S8259Reset;
- GameStateRestore=S8259Restore;
- AddExState(latch, 8, 0, "LATC");
- AddExState(&cmd, 1, 0, "CMD");
- type=0;
+  info->Power=S8259Reset;
+  GameStateRestore=S8259Restore;
+  AddExState(latch, 8, 0, "LATC");
+  AddExState(&cmd, 1, 0, "CMD");
+  type=1;
+}
 
- //if(!CHRsize[0])
- //{
- // SetupCartCHRMapping(0,CHRRAM,8192,1);
- // AddExState(CHRRAM, 8192, 0, "CHRR");
- //}
+void S8259C_Init(CartInfo *info) // Kevin's Horton 139 mapper
+{
+  info->Power=S8259Reset;
+  GameStateRestore=S8259Restore;
+  AddExState(latch, 8, 0, "LATC");
+  AddExState(&cmd, 1, 0, "CMD");
+  type=2;
 }
 
-void S8259B_Init(void)
+void S8259D_Init(CartInfo *info) // Kevin's Horton 137 mapper
 {
BoardPower=S8259Reset;
- GameStateRestore=S8259Restore;
- AddExState(latch, 8, 0, "LATC");
- AddExState(&cmd, 1, 0, "CMD");
type=1;
 info->Power=S8259Reset;
 GameStateRestore=S8259Restore;
 AddExState(latch, 8, 0, "LATC");
 AddExState(&cmd, 1, 0, "CMD");
 type=3;
 }
 
 static void(*WSync)(void);
 
 static void SA0161MSynco()
 {
- setprg32(0x8000,(latch[0]>>3)&1);
- X6502_Rebase();
- setchr8(latch[0]&7);
+  setprg32(0x8000,(latch[0]>>3)&1);
+  setchr8(latch[0]&7);
 }
 
 static DECLFW(SAWrite)
 {
- if(A&0x100)
- {
-  latch[0]=V;
-  WSync();
- }
 if(A&0x100)
 {
+    latch[0]=V;
+    WSync();
 }
 }
 
 static void SAReset(void)
 {
- latch[0]=0;
- WSync();
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0x4100,0x5FFF,SAWrite);
 latch[0]=0;
 WSync();
 SetReadHandler(0x8000,0xFFFF,CartBR);
 SetWriteHandler(0x4100,0x5FFF,SAWrite);
 }
 
-void SA0161M_Init(void)
+static void SA0161MRestore(int version)
 {
- WSync=SA0161MSynco;
- GameStateRestore=SA0161MSynco;
- BoardPower=SAReset;
- AddExState(&latch[0], 1, 0, "LATC");
+  SA0161MSynco();
+}
+
+void SA0161M_Init(CartInfo *info)
+{
+  WSync=SA0161MSynco;
+  GameStateRestore=SA0161MRestore;
+  info->Power=SAReset;
+  AddExState(&latch[0], 1, 0, "LATC");
 }
 
 static void SA72007Synco()
 {
- setprg32(0x8000,0);
- X6502_Rebase();
- setchr8(latch[0]>>7);
+  setprg32(0x8000,0);
+  setchr8(latch[0]>>7);
+}
+
+static void SA72007Restore(int version)
+{
+  SA72007Synco();
 }
 
-void SA72007_Init(void)
+void SA72007_Init(CartInfo *info)
 {
- WSync=SA72007Synco;
GameStateRestore=SA72007Synco;
BoardPower=SAReset;
- AddExState(&latch[0], 1, 0, "LATC");
 WSync=SA72007Synco;
 GameStateRestore=SA72007Restore;
 info->Power=SAReset;
 AddExState(&latch[0], 1, 0, "LATC");
 }
 
 static void SA72008Synco()
 {
- setprg32(0x8000,(latch[0]>>2)&1);
- X6502_Rebase();
- setchr8(latch[0]&3);
+  setprg32(0x8000,(latch[0]>>2)&1);
+  setchr8(latch[0]&3);
 }
 
-void SA72008_Init(void)
+static void SA72008Restore(int version)
 {
- WSync=SA72008Synco;
- GameStateRestore=SA72008Synco;
- BoardPower=SAReset;
- AddExState(&latch[0], 1, 0, "LATC");
+  SA72008Synco();
+}
+
+void SA72008_Init(CartInfo *info)
+{
+  WSync=SA72008Synco;
+  GameStateRestore=SA72008Restore;
+  info->Power=SAReset;
+  AddExState(&latch[0], 1, 0, "LATC");
 }
 
 static DECLFW(SADWrite)
 {
- latch[0]=V;
- WSync();
 latch[0]=V;
 WSync();
 }
 
 static void SADReset(void)
 {
- latch[0]=0;
- WSync();
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0x8000,0xFFFF,SADWrite);
 latch[0]=0;
 WSync();
 SetReadHandler(0x8000,0xFFFF,CartBR);
 SetWriteHandler(0x8000,0xFFFF,SADWrite);
 }
 
-static void SA0036Synco()
+static void SA0037Synco()
 {
- setprg32(0x8000,0);
- X6502_Rebase();
- setchr8(latch[0]>>7);
+  setprg32(0x8000,(latch[0]>>3)&1);
+  setchr8(latch[0]&7);
 }
 
-static void SA0037Synco()
+static void SA0037Restore(int version)
 {
- setprg32(0x8000,(latch[0]>>3)&1);
- X6502_Rebase();
- setchr8(latch[0]&7);
+  SA0037Synco();
 }
 
-void SA0036_Init(void)
+void SA0036_Init(CartInfo *info)
 {
WSync=SA0036Synco;
GameStateRestore=SA0036Synco;
BoardPower=SADReset;
- AddExState(&latch[0], 1, 0, "LATC");
 WSync=SA72007Synco;
 GameStateRestore=SA72007Restore;
 info->Power=SADReset;
 AddExState(&latch[0], 1, 0, "LATC");
 }
 
-void SA0037_Init(void)
+void SA0037_Init(CartInfo *info)
 {
- WSync=SA0037Synco;
GameStateRestore=SA0037Synco;
BoardPower=SADReset;
- AddExState(&latch[0], 1, 0, "LATC");
 WSync=SA0037Synco;
 GameStateRestore=SA0037Restore;
 info->Power=SADReset;
 AddExState(&latch[0], 1, 0, "LATC");
 }
 
 static void TCU01Synco()
 {
- setprg32(0x8000,(latch[0]>>2)&1);
- X6502_Rebase();
- setchr8((latch[0]>>3)&0xF);
+  setprg32(0x8000,(latch[0]>>2)&1);
+  setchr8((latch[0]>>3)&0xF);
 }
 
 static DECLFW(TCWrite)
 {
- if((A&0x103)==0x102)
-  latch[0]=V;
- TCU01Synco();
 if((A&0x103)==0x102)
+    latch[0]=V;
 TCU01Synco();
 }
 
 static void TCU01Reset(void)
 {
- latch[0]=0;
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0x4100,0xFFFF,TCWrite);
- TCU01Synco();
 latch[0]=0;
 SetReadHandler(0x8000,0xFFFF,CartBR);
 SetWriteHandler(0x4100,0xFFFF,TCWrite);
 TCU01Synco();
 }
 
-void TCU01_Init(void)
+static void TCU01Restore(int version)
 {
- GameStateRestore=TCU01Synco;
- BoardPower=TCU01Reset;
- AddExState(&latch[0], 1, 0, "LATC");
+  TCU01Synco();
 }
 
+void TCU01_Init(CartInfo *info)
+{
+  GameStateRestore=TCU01Restore;
+  info->Power=TCU01Reset;
+  AddExState(&latch[0], 1, 0, "LATC");
+}
+
+static DECLFR(TCA01Read)
+{
+  uint8 ret;
+  if((A&0x4100)==0x4100)
+    ret=(X.DB&0xC0)|((~A)&0x3F);
+  else
+    ret=X.DB;
+  return ret;
+}
+
+static void TCA01Reset(void)
+{
+  setprg16(0x8000,0);
+  setprg16(0xC000,1);
+  setchr8(0);
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetReadHandler(0x4100,0x5FFF,TCA01Read);
+}
+
+void TCA01_Init(CartInfo *info)
+{
+  info->Power=TCA01Reset;
+}
diff --git a/boards/simple.c b/boards/simple.c
deleted file mode 100644 (file)
index 5629a5f..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 CHRRAM (GameMemBlock)
-static uint8 latche;
-
-DECLFW(CPROMWrite)
-{
- latche=V&3;
- setvram4(0x1000,CHRRAM+((V&3)<<12));
-}
-
-static void CPROMReset(void)
-{
- setprg32(0x8000,0);
- setvram8(0);
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0x8000,0xffff,CPROMWrite);
-}
-
-static void CPROMRestore(int version)
-{
- setvram4(0x1000,CHRRAM+((latche)<<12));
-}
-
-void CPROM_Init(void)
-{
- BoardPower=CPROMReset;
- GameStateRestore=CPROMRestore;
- AddExState(&latche, 1, 0, "LATC");
-}
-
-DECLFW(CNROMWrite)
-{
- latche=V&3;
- setchr8(V&3);
-}
-
-static void CNROMReset(void)
-{
-  setprg16(0x8000,0);
-  setprg16(0xC000,1);
-  SetReadHandler(0x8000,0xFFFF,CartBR);
-  SetWriteHandler(0x8000,0xffff,CNROMWrite);
-}
-
-static void CNROMRestore(int version)
-{
- setchr8(latche);
-}
-
-void CNROM_Init(void)
-{
- BoardPower=CNROMReset;
- GameStateRestore=CNROMRestore;
- AddExState(&latche, 1, 0, "LATC");
-}
-
-static void NROM128Reset(void)
-{
-  setprg16(0x8000,0);
-  setprg16(0xC000,0);
-  setchr8(0);
-  SetReadHandler(0x8000,0xFFFF,CartBR);
-}
-
-static void NROM256Reset(void)
-{
-  setprg16(0x8000,0);
-  setprg16(0xC000,1);
-  setchr8(0);
-  SetReadHandler(0x8000,0xFFFF,CartBR);
-}
-void NROM128_Init(void)
-{
-  BoardPower=NROM128Reset;
-}
-
-void NROM256_Init(void)
-{
-  BoardPower=NROM256Reset;
-}
-
-static DECLFW(MHROMWrite)
-{
- setprg32(0x8000,V>>4);
- setchr8(V);
- latche=V;
- X6502_Rebase();
-}
-
-static void MHROMReset(void)
-{
- setprg32(0x8000,0);
- setchr8(0);
- latche=0;
- SetReadHandler(0x8000,0xFFFF,CartBR);
-}
-
-static void MHROMRestore(int version)
-{
- setprg32(0x8000,latche);
- setchr8(latche);
- SetWriteHandler(0x8000,0xffff,MHROMWrite);
-}
-
-void MHROM_Init(void)
-{
- BoardPower=MHROMReset;
- AddExState(&latche, 1, 0,"LATC");
- PRGmask32[0]&=1;
- CHRmask8[0]&=1;
- GameStateRestore=MHROMRestore;
-}
-
-static void UNROMRestore(int version)
-{
- setprg16(0x8000,latche);
-}
-
-static DECLFW(UNROMWrite)
-{
- setprg16(0x8000,V);
- latche=V;
- X6502_Rebase();
-}
-
-static void UNROMReset(void)
-{
- setprg16(0x8000,0);
- setprg16(0xc000,~0);
- setvram8(CHRRAM);
- SetWriteHandler(0x8000,0xffff,UNROMWrite);
- SetReadHandler(0x8000,0xFFFF,CartBR);
- latche=0;
-}
-
-void UNROM_Init(void)
-{
- BoardPower=UNROMReset;
- PRGmask16[0]&=7;
- AddExState(&latche, 1, 0, "LATC");
- AddExState(CHRRAM, 8192, 0, "CHRR");
- GameStateRestore=UNROMRestore;
-}
diff --git a/boards/subor.c b/boards/subor.c
new file mode 100644 (file)
index 0000000..31e5b65
--- /dev/null
@@ -0,0 +1,79 @@
+#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 7cf0646..4265b5c 100644 (file)
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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"
-//undef printf
-
-static int32 IRQCount,IRQLatch;
-static uint8 IRQa,resetmode,mbia;
-static uint8 sizer,bigbank,bigbank2;
-
-static uint8 DRegBuf[8],MMC3_cmd;
-
-static int masko8[8]={63,31,15,1,3,0,0,0};
-//static int masko1[8]={511,255,127,7,7,0,0,0};
-
-static void swsetprg8(uint32 A, uint32 V)
-{
- V&=masko8[sizer&7];
- V|=(bigbank*2);
- setprg8r((V/64)&15,A,V);
-}
-
-static void swsetchr1(uint32 A, uint32 V)
-{
- if(sizer&0x20)
-  setchr1r(0x10,A,V);
- else
- {
-//  V&=masko1[sizer&7];
-  V|=bigbank2*8;
-  setchr1r((V/512)&15,A,V);
- }
-}
-
-static void swsetchr2(uint32 A, uint32 V)
-{
- if(sizer&0x20)
-  setchr2r(0x10,A,V);
- else
- {
-  //V&=masko1[sizer&7]>>1;
-  V|=bigbank2*4;
-  setchr2r((V/256)&15,A,V);
- }
-}
-
-static void Sup24_hb(void)
-{
-     if(ScreenON || SpriteON)
-     {
-      resetmode=0;
-      if(IRQCount>=0)
-      {
-        IRQCount--;
-        if(IRQCount<0)
-        {
-         if(IRQa)
-         {
-            resetmode = 1;
-           X6502_IRQBegin(FCEU_IQEXT);
-         }
-        }
-      }
-     }
-}
-
-static DECLFW(Sup24IRQWrite)
-{
-        switch(A&0xE001)
-        {
-         case 0xc000:IRQLatch=V;
-                     if(resetmode==1)
-                      IRQCount=IRQLatch;
-                     break;
-         case 0xc001:resetmode=1;
-                     IRQCount=IRQLatch;
-                     break;
-         case 0xE000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);
-                     if(resetmode==1)
-                      {IRQCount=IRQLatch;}
-                     break;
-         case 0xE001:IRQa=1;
-                     if(resetmode==1)
-                       {IRQCount=IRQLatch;}
-                     break;
-        }
-}
-
-static INLINE void FixMMC3PRG(int V)
-{
-         swsetprg8(0xA000,DRegBuf[7]);
-         swsetprg8(0xE000,~0);
-          if(V&0x40)
-           {
-            swsetprg8(0xC000,DRegBuf[6]);
-            swsetprg8(0x8000,~1);
-           }
-          else
-           {
-            swsetprg8(0x8000,DRegBuf[6]);
-            swsetprg8(0xC000,~1);
-           }
-         X6502_Rebase();
-}
-
-static INLINE void FixMMC3CHR(int V)
-{
-           int cbase=(V&0x80)<<5;
-           swsetchr2((cbase^0x000),DRegBuf[0]>>1);
-           swsetchr2((cbase^0x800),DRegBuf[1]>>1);
-           swsetchr1(cbase^0x1000,DRegBuf[2]);
-           swsetchr1(cbase^0x1400,DRegBuf[3]);
-           swsetchr1(cbase^0x1800,DRegBuf[4]);
-           swsetchr1(cbase^0x1c00,DRegBuf[5]);
-}
-
-static DECLFW(Super24hiwrite)
-{
-       //printf("$%04x:$%02x, %d\n",A,V,scanline);
-        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: V>>=1;swsetchr2((cbase^0x000),V);break;
-                  case 1: V>>=1;swsetchr2((cbase^0x800),V);break;
-                  case 2: swsetchr1(cbase^0x1000,V); break;
-                  case 3: swsetchr1(cbase^0x1400,V); break;
-                  case 4: swsetchr1(cbase^0x1800,V); break;
-                  case 5: swsetchr1(cbase^0x1C00,V); break;
-                  case 6: if (MMC3_cmd&0x40) swsetprg8(0xC000,V);
-                          else swsetprg8(0x8000,V);
-                          X6502_Rebase();
-                          break;
-                  case 7: swsetprg8(0xA000,V);
-                          X6502_Rebase();
-                          break;
-                 }
-                }
-                break;
-
-        case 0xA000:
-               mbia=V;
-                setmirror((V&1)^1);
-                break;
- }
-}
-
-
-DECLFW(Super24Write)
-{
- //printf("$%04x:$%02x\n",A,V);
- switch(A)
- {
-  case 0x5ff0:sizer=V;
-             FixMMC3PRG(MMC3_cmd);
-             FixMMC3CHR(MMC3_cmd);
-             break;
-  case 0x5FF1:
-             bigbank=V;
-             FixMMC3PRG(MMC3_cmd);
-             break;
-  case 0x5FF2:
-             bigbank2=V;
-             FixMMC3CHR(MMC3_cmd);
-             break;
- }
-}
-
-static void Super24Reset(void)
-{
- SetWriteHandler(0x8000,0xBFFF,Super24hiwrite);
- SetWriteHandler(0x5000,0x7FFF,Super24Write);
- SetWriteHandler(0xC000,0xFFFF,Sup24IRQWrite);
- SetReadHandler(0x8000,0xFFFF,CartBR);
- GameHBIRQHook=Sup24_hb;
- IRQCount=IRQLatch=IRQa=resetmode=0;
- sizer=0x24;
- bigbank=159;
- bigbank2=0;
-
- MMC3_cmd=0;
- DRegBuf[6]=0;
- DRegBuf[7]=1;
-
- FixMMC3PRG(0);
- FixMMC3CHR(0);
-}
-
-static void MrRestore(int version)
-{
- FixMMC3PRG(MMC3_cmd);
- FixMMC3CHR(MMC3_cmd);
- setmirror((mbia&1)^1);
-}
-
-void Super24_Init(void)
-{
- BoardPower=Super24Reset;
- SetupCartCHRMapping(0x10, GameMemBlock, 8192, 1);
- GameStateRestore=MrRestore;
-
- AddExState(GameMemBlock, 8192, 0, "CHRR");
- AddExState(DRegBuf, 8, 0, "DREG");
- AddExState(&IRQCount, 4, 1, "IRQC");
- AddExState(&IRQLatch, 4, 1, "IQL1");
- AddExState(&IRQa, 1, 0, "IRQA");
- AddExState(&sizer, 1, 0, "SIZA");
- AddExState(&bigbank, 1, 0, "BIG1");
- AddExState(&bigbank2, 1, 0, "BIG2");
-}
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 *CHRRAM = NULL;\r
+static uint8 resetmode;\r
+static int masko8[8]={63,31,15,1,3,0,0,0};\r
+\r
+static void Super24PW(uint32 A, uint8 V)\r
+{\r
+ uint32 NV=V&masko8[EXPREGS[0]&7];\r
+ NV|=(EXPREGS[1]<<1);\r
+ setprg8r((NV>>6)&0xF,A,NV);\r
+}\r
+\r
+static void Super24CW(uint32 A, uint8 V)\r
+{\r
+ if(EXPREGS[0]&0x20)\r
+  setchr1r(0x10,A,V);\r
+ else\r
+ {\r
+  uint32 NV=V|(EXPREGS[2]<<3);\r
+  setchr1r((NV>>9)&0xF,A,NV);\r
+ }\r
+}\r
+\r
+static DECLFW(Super24Write)\r
+{\r
+ switch(A)\r
+ {\r
+  case 0x5FF0: EXPREGS[0]=V;\r
+               FixMMC3PRG(MMC3_cmd);\r
+               FixMMC3CHR(MMC3_cmd);\r
+               break;\r
+  case 0x5FF1: EXPREGS[1]=V;\r
+               FixMMC3PRG(MMC3_cmd);\r
+               break;\r
+  case 0x5FF2: EXPREGS[2]=V;\r
+               FixMMC3CHR(MMC3_cmd);\r
+               break;\r
+ }\r
+}\r
+\r
+static DECLFW(Super24IRQ)\r
+{\r
+  switch(A&0xE001)\r
+  {\r
+    case 0xc000: IRQLatch=V;\r
+                 if(resetmode==1)\r
+                   IRQCount=IRQLatch;\r
+                 break;\r
+    case 0xc001: resetmode=1;\r
+                 IRQCount=IRQLatch;\r
+                 break;\r
+    case 0xE000: IRQa=0;\r
+                 X6502_IRQEnd(FCEU_IQEXT);\r
+                 if(resetmode==1)\r
+                   IRQCount=IRQLatch;\r
+                 break;\r
+    case 0xE001: IRQa=1;\r
+                 if(resetmode==1)\r
+                   IRQCount=IRQLatch;\r
+                 break;\r
+  }\r
+}\r
+\r
+static void Super24HB(void)\r
+{\r
+  resetmode=0;\r
+  if(IRQCount!=0)\r
+  {\r
+    IRQCount--;\r
+    if(IRQCount==0)\r
+    {\r
+      if(IRQa)\r
+      {\r
+        resetmode=1;\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+static void Super24Power(void)\r
+{\r
+ EXPREGS[0]=0x24;\r
+ EXPREGS[1]=159;\r
+ EXPREGS[2]=0;\r
+ GenMMC3Power();\r
+ SetWriteHandler(0x5000,0x7FFF,Super24Write);\r
+ SetWriteHandler(0xC000,0xFFFF,Super24IRQ);\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+}\r
+\r
+static void Super24Reset(void)\r
+{\r
+ EXPREGS[0]=0x24;\r
+ EXPREGS[1]=159;\r
+ EXPREGS[2]=0;\r
+ MMC3RegReset();\r
+}\r
+\r
+static void Super24Close(void)\r
+{\r
+ if(CHRRAM)\r
+  FCEU_gfree(CHRRAM);\r
+ CHRRAM = NULL;\r
+}\r
+\r
+void Super24_Init(CartInfo *info)\r
+{\r
+ info->Power=Super24Power;\r
+ info->Reset=Super24Reset;\r
+ info->Close=Super24Close;\r
+ cwrap=Super24CW;\r
+ pwrap=Super24PW;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(8192);\r
+ SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);\r
+ GameHBIRQHook=Super24HB;\r
+ AddExState(CHRRAM, 8192, 0, "CHRR");\r
+ AddExState(EXPREGS, 3, 0, "BIG2");\r
+}\r
index cb2890f..953c068 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
-#define CHRRAM (GameMemBlock+16)
+static uint8 cmd0, cmd1;
 
 static void DoSuper(void)
 {
- setprg8r((GameMemBlock[0]&0xC)>>2,0x6000,((GameMemBlock[0]&0x3)<<4)|0xF);
- if(GameMemBlock[0]&0x10)
+ setprg8r((cmd0&0xC)>>2,0x6000,((cmd0&0x3)<<4)|0xF);
+ if(cmd0&0x10)
  {
-  setprg16r((GameMemBlock[0]&0xC)>>2,0x8000,((GameMemBlock[0]&0x3)<<3)|(GameMemBlock[1]&7));
-  setprg16r((GameMemBlock[0]&0xC)>>2,0xc000,((GameMemBlock[0]&0x3)<<3)|7);
+  setprg16r((cmd0&0xC)>>2,0x8000,((cmd0&0x3)<<3)|(cmd1&7));
+  setprg16r((cmd0&0xC)>>2,0xc000,((cmd0&0x3)<<3)|7);
  }
  else
   setprg32r(4,0x8000,0);
-
- setmirror(((GameMemBlock[0]&0x20)>>5)^1);
- X6502_Rebase();
+ setmirror(((cmd0&0x20)>>5)^1);
 }
 
 static DECLFW(SuperWrite)
 {
- if(!(GameMemBlock[0]&0x10))
+ if(!(cmd0&0x10))
  {
-  GameMemBlock[0]=V;
+  cmd0=V;
   DoSuper();
  }
 }
 
 static DECLFW(SuperHi)
 {
GameMemBlock[1]=V;
cmd1=V;
  DoSuper();
 }
 
@@ -56,10 +54,10 @@ static void SuperReset(void)
 {
   SetWriteHandler(0x6000,0x7FFF,SuperWrite);
   SetWriteHandler(0x8000,0xFFFF,SuperHi);
-  SetReadHandler(0x6000,0xFFFF,CartBR);
-  GameMemBlock[0]=GameMemBlock[1]=0;
+  SetReadHandler(0x6000,0xFFFF,CartBR);  
+  cmd0=cmd1=0;
   setprg32r(4,0x8000,0);
-  setvram8(CHRRAM);
+  setchr8(0);
 }
 
 static void SuperRestore(int version)
@@ -67,11 +65,10 @@ static void SuperRestore(int version)
  DoSuper();
 }
 
-void Supervision16_Init(void)
+void Supervision16_Init(CartInfo *info)
 {
-  AddExState(&GameMemBlock[0], 1, 0,"L1");
-  AddExState(&GameMemBlock[1], 1, 0,"L2");
-  AddExState(CHRRAM, 8192, 0, "CHRR");
-  BoardPower=SuperReset;
+  AddExState(&cmd0, 1, 0,"L1");
+  AddExState(&cmd1, 1, 0,"L2");
+  info->Power=SuperReset;
   GameStateRestore=SuperRestore;
 }
diff --git a/boards/tengen.c b/boards/tengen.c
new file mode 100644 (file)
index 0000000..84f050a
--- /dev/null
@@ -0,0 +1,198 @@
+/* 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 uint8 cmd,mir,rmode,IRQmode;
+static uint8 DRegs[11];
+static uint8 IRQCount,IRQa,IRQLatch;
+
+static SFORMAT Rambo_StateRegs[]={
+        {&cmd, 1, "CMD"},
+        {&mir, 1, "MIR"},
+        {&rmode, 1, "RMOD"},
+        {&IRQmode, 1, "IRQM"},
+        {&IRQCount, 1, "IRQC"},
+        {&IRQa, 1, "IRQA"},
+        {&IRQLatch, 1, "IRQL"},
+        {DRegs, 11, "DREG"},
+        {0}
+};
+
+static void FP_FASTAPASS(2) (*setchr1wrap)(unsigned int A, unsigned int V);
+static int nomirror;
+
+static void FP_FASTAPASS(1) RAMBO1_IRQHook(int a)
+{
+ static int smallcount;
+ if(!IRQmode) return;
+
+ smallcount+=a;
+ while(smallcount>=4)
+ {
+  smallcount-=4;
+  IRQCount--;
+  if(IRQCount==0xFF)
+      if(IRQa) X6502_IRQBegin(FCEU_IQEXT);
+ }
+}
+
+static void RAMBO1_hb(void)
+{
+      if(IRQmode) return;
+  if(scanline==240) return;        /* hmm.  Maybe that should be an mmc3-only call in fce.c. */
+      rmode=0;
+      IRQCount--;
+      if(IRQCount==0xFF)
+      {
+       if(IRQa)
+       {
+        rmode = 1;
+        X6502_IRQBegin(FCEU_IQEXT);
+       }
+      }
+}
+
+static void Synco(void)
+{
+ int x;
+
+ if(cmd&0x20)
+ {
+  setchr1wrap(0x0000,DRegs[0]);
+  setchr1wrap(0x0800,DRegs[1]);
+  setchr1wrap(0x0400,DRegs[8]);
+  setchr1wrap(0x0c00,DRegs[9]);
+ }
+ else
+ {
+  setchr1wrap(0x0000,(DRegs[0]&0xFE));
+  setchr1wrap(0x0400,(DRegs[0]&0xFE)|1);
+  setchr1wrap(0x0800,(DRegs[1]&0xFE));
+  setchr1wrap(0x0C00,(DRegs[1]&0xFE)|1);
+ }
+
+ for(x=0;x<4;x++)
+  setchr1wrap(0x1000+x*0x400,DRegs[2+x]);
+
+ setprg8(0x8000,DRegs[6]);
+ setprg8(0xA000,DRegs[7]);
+
+ setprg8(0xC000,DRegs[10]);
+}
+
+
+static DECLFW(RAMBO1_write)
+{
+ switch(A&0xF001)
+  {
+    case 0xa000: mir=V&1;
+                 if(!nomirror)
+                   setmirror(mir^1);
+                 break;
+    case 0x8000: cmd = V;
+                 break;
+    case 0x8001: if((cmd&0xF)<10)
+                     DRegs[cmd&0xF]=V;
+                    else if((cmd&0xF)==0xF)
+                     DRegs[10]=V;
+                    Synco();
+                    break;
+    case 0xc000: IRQLatch=V;
+                 if(rmode==1)
+                   IRQCount=IRQLatch;
+                 break;
+    case 0xc001: rmode=1;
+                    IRQCount=IRQLatch;
+                    IRQmode=V&1;
+                    break;
+    case 0xE000: IRQa=0;
+                 X6502_IRQEnd(FCEU_IQEXT);
+                 if(rmode==1)
+                   IRQCount=IRQLatch;
+                 break;
+    case 0xE001: IRQa=1;
+                 if(rmode==1)
+                   IRQCount=IRQLatch;
+                    break;
+  }
+}
+
+static void RAMBO1_Restore(int version)
+{
+ Synco();
+ if(!nomirror)
+  setmirror(mir^1);
+}
+
+static void RAMBO1_init(void)
+{
+        int x;
+        for(x=0;x<11;x++)
+         DRegs[x]=~0;
+  cmd=mir=0;
+        if(!nomirror)
+         setmirror(1);
+        Synco();
+        GameHBIRQHook=RAMBO1_hb;
+        MapIRQHook=RAMBO1_IRQHook;
+        GameStateRestore=RAMBO1_Restore;
+        SetWriteHandler(0x8000,0xffff,RAMBO1_write);
+        AddExState(Rambo_StateRegs, ~0, 0, 0);
+}
+
+static void FP_FASTAPASS(2) CHRWrap(unsigned int A, unsigned int V)
+{
+ setchr1(A,V);
+}
+
+void Mapper64_init(void)
+{
+        setchr1wrap=CHRWrap;
+        nomirror=0;
+        RAMBO1_init();
+}
+
+static int MirCache[8];
+static unsigned int PPUCHRBus;
+
+static void FP_FASTAPASS(2) MirWrap(unsigned int A, unsigned int V)
+{
+ MirCache[A>>10]=(V>>7)&1;
+ if(PPUCHRBus==(A>>10))
+  setmirror(MI_0+((V>>7)&1));
+ setchr1(A,V);
+}
+
+static void FP_FASTAPASS(1) MirrorFear(uint32 A)
+{
+ A&=0x1FFF;
+ A>>=10;
+ PPUCHRBus=A;
+ setmirror(MI_0+MirCache[A]);
+}
+
+void Mapper158_init(void)
+{
+        setchr1wrap=MirWrap;
+        PPU_hook=MirrorFear;
+        nomirror=1;
+        RAMBO1_init();
+}
diff --git a/cart.c b/cart.c
index 6a32021..f888397 100644 (file)
--- a/cart.c
+++ b/cart.c
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include <string.h>
 #include <stdlib.h>
-#include <stdio.h>     /* For GG loading code. */
+#include <stdio.h>
 
 #include "types.h"
-#include "version.h"
 #include "fce.h"
+#include "ppu.h"
+
 #include "cart.h"
 #include "memory.h"
+#include "x6502.h"
 
 #include "general.h"
+
 #include "svga.h"
+#include "file.h"
+
+#define FCEUPPU_LineUpdate(...)
 
 /*
    This file contains all code for coordinating the mapping in of the
@@ -43,8 +49,9 @@ uint8 *VPageG[8];
 uint8 *MMC5SPRVPage[8];
 uint8 *MMC5BGVPage[8];
 
-/* 16 are (sort of) reserved for UNIF/iNES and 16 to map other stuff. */
+static uint8 PRGIsRAM[32];  /* This page is/is not PRG RAM. */
 
+/* 16 are (sort of) reserved for UNIF/iNES and 16 to map other stuff. */
 static int CHRram[32];
 static int PRGram[32];
 
@@ -74,29 +81,39 @@ uint8 geniech[3];
 
 uint32 genieaddr[3];
 
-static INLINE void setpageptr(int s, uint32 A, uint8 *p)
+static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram)
 {
  uint32 AB=A>>11;
  int x;
 
- for(x=(s>>1)-1;x>=0;x--)
-  Page[AB+x]=p-A;
+ if(p)
+  for(x=(s>>1)-1;x>=0;x--)
+  {
+   PRGIsRAM[AB+x]=ram;
+   Page[AB+x]=p-A;
+  }
+ else
+  for(x=(s>>1)-1;x>=0;x--)
+  {
+   PRGIsRAM[AB+x]=0;
+   Page[AB+x]=0;
+  }
 }
 
-static char nothing[8192];
+static uint8 nothing[8192];
 void ResetCartMapping(void)
 {
  int x;
 
  for(x=0;x<32;x++)
  {
-  Page[x]=(uint8 *)(nothing-x*2048);
+  Page[x]=nothing-x*2048;
   PRGptr[x]=CHRptr[x]=0;
   PRGsize[x]=CHRsize[x]=0;
  }
  for(x=0;x<8;x++)
  {
-  MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=(uint8 *)(nothing-0x400*x);
+  MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=nothing-0x400*x;
  }
 
 }
@@ -133,12 +150,23 @@ DECLFR(CartBR)
  return Page[A>>11][A];
 }
 
-void FASTAPASS(3) GINLINE setprg2r(int r, unsigned int A, unsigned int V)
+DECLFW(CartBW)
 {
-  if(!PRGptr[r]) return;
-  V&=PRGmask2[r];
+ //printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]);
+ if(PRGIsRAM[A>>11] && Page[A>>11])
+  Page[A>>11][A]=V;
+}
+
+DECLFR(CartBROB)
+{
+ if(!Page[A>>11]) return(X.DB);
+ return Page[A>>11][A];
+}
 
-  setpageptr(2,A,(&PRGptr[r][V<<11]));
+void FASTAPASS(3) setprg2r(int r, unsigned int A, unsigned int V)
+{
+  V&=PRGmask2[r];
+  setpageptr(2,A,PRGptr[r]?(&PRGptr[r][V<<11]):0,PRGram[r]);
 }
 
 void FASTAPASS(2) setprg2(uint32 A, uint32 V)
@@ -146,11 +174,10 @@ void FASTAPASS(2) setprg2(uint32 A, uint32 V)
  setprg2r(0,A,V);
 }
 
-void FASTAPASS(3) GINLINE setprg4r(int r, unsigned int A, unsigned int V)
+void FASTAPASS(3) setprg4r(int r, unsigned int A, unsigned int V)
 {
-  if(!PRGptr[r]) return;
   V&=PRGmask4[r];
-  setpageptr(4,A,(&PRGptr[r][V<<12]));
+  setpageptr(4,A,PRGptr[r]?(&PRGptr[r][V<<12]):0,PRGram[r]);
 }
 
 void FASTAPASS(2) setprg4(uint32 A, uint32 V)
@@ -158,21 +185,19 @@ void FASTAPASS(2) setprg4(uint32 A, uint32 V)
  setprg4r(0,A,V);
 }
 
-void FASTAPASS(3) GINLINE setprg8r(int r, unsigned int A, unsigned int V)
+void FASTAPASS(3) setprg8r(int r, unsigned int A, unsigned int V)
 {
-  if(!PRGptr[r]) return;
-
   if(PRGsize[r]>=8192)
   {
    V&=PRGmask8[r];
-   setpageptr(8,A,(&PRGptr[r][V<<13]));
+   setpageptr(8,A,PRGptr[r]?(&PRGptr[r][V<<13]):0,PRGram[r]);
   }
   else
   {
    uint32 VA=V<<2;
    int x;
    for(x=0;x<4;x++)
-    setpageptr(2,A+(x<<11),(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]));
+    setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
   }
 }
 
@@ -181,14 +206,12 @@ void FASTAPASS(2) setprg8(uint32 A, uint32 V)
  setprg8r(0,A,V);
 }
 
-void FASTAPASS(3) GINLINE setprg16r(int r, unsigned int A, unsigned int V)
+void FASTAPASS(3) setprg16r(int r, unsigned int A, unsigned int V)
 {
-  if(!PRGptr[r]) return;
-
   if(PRGsize[r]>=16384)
   {
    V&=PRGmask16[r];
-   setpageptr(16,A,(&PRGptr[r][V<<14]));
+   setpageptr(16,A,PRGptr[r]?(&PRGptr[r][V<<14]):0,PRGram[r]);
   }
   else
   {
@@ -196,7 +219,7 @@ void FASTAPASS(3) GINLINE setprg16r(int r, unsigned int A, unsigned int V)
    int x;
 
    for(x=0;x<8;x++)
-    setpageptr(2,A+(x<<11),(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]));
+    setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
   }
 }
 
@@ -205,13 +228,12 @@ void FASTAPASS(2) setprg16(uint32 A, uint32 V)
  setprg16r(0,A,V);
 }
 
-void FASTAPASS(3) GINLINE setprg32r(int r,unsigned int A, unsigned int V)
+void FASTAPASS(3) setprg32r(int r,unsigned int A, unsigned int V)
 {
-  if(!PRGptr[r]) return;
   if(PRGsize[r]>=32768)
   {
    V&=PRGmask32[r];
-   setpageptr(32,A,(&PRGptr[r][V<<15]));
+   setpageptr(32,A,PRGptr[r]?(&PRGptr[r][V<<15]):0,PRGram[r]);
   }
   else
   {
@@ -219,7 +241,7 @@ void FASTAPASS(3) GINLINE setprg32r(int r,unsigned int A, unsigned int V)
    int x;
 
    for(x=0;x<16;x++)
-    setpageptr(2,A+(x<<11),(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]));
+    setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
   }
 }
 
@@ -228,9 +250,10 @@ void FASTAPASS(2) setprg32(uint32 A, uint32 V)
  setprg32r(0,A,V);
 }
 
-void GINLINE FASTAPASS(3) setchr1r(int r, unsigned int A, unsigned int V)
+void FASTAPASS(3) setchr1r(int r, unsigned int A, unsigned int V)
 {
   if(!CHRptr[r]) return;
+  FCEUPPU_LineUpdate();
   V&=CHRmask1[r];
   if(CHRram[r])
    PPUCHRRAM|=(1<<(A>>10));
@@ -239,9 +262,10 @@ void GINLINE FASTAPASS(3) setchr1r(int r, unsigned int A, unsigned int V)
   VPageR[(A)>>10]=&CHRptr[r][(V)<<10]-(A);
 }
 
-void GINLINE FASTAPASS(3) setchr2r(int r, unsigned int A, unsigned int V)
+void FASTAPASS(3) setchr2r(int r, unsigned int A, unsigned int V)
 {
   if(!CHRptr[r]) return;
+  FCEUPPU_LineUpdate();
   V&=CHRmask2[r];
   VPageR[(A)>>10]=VPageR[((A)>>10)+1]=&CHRptr[r][(V)<<11]-(A);
   if(CHRram[r])
@@ -250,9 +274,10 @@ void GINLINE FASTAPASS(3) setchr2r(int r, unsigned int A, unsigned int V)
    PPUCHRRAM&=~(3<<(A>>10));
 }
 
-void GINLINE FASTAPASS(3) setchr4r(int r, unsigned int A, unsigned int V)
+void FASTAPASS(3) setchr4r(int r, unsigned int A, unsigned int V)
 {
   if(!CHRptr[r]) return;
+  FCEUPPU_LineUpdate();
   V&=CHRmask4[r];
   VPageR[(A)>>10]=VPageR[((A)>>10)+1]=
   VPageR[((A)>>10)+2]=VPageR[((A)>>10)+3]=&CHRptr[r][(V)<<12]-(A);
@@ -262,11 +287,12 @@ void GINLINE FASTAPASS(3) setchr4r(int r, unsigned int A, unsigned int V)
    PPUCHRRAM&=~(15<<(A>>10));
 }
 
-void GINLINE FASTAPASS(2) setchr8r(int r, unsigned int V)
+void FASTAPASS(2) setchr8r(int r, unsigned int V)
 {
   int x;
 
   if(!CHRptr[r]) return;
+  FCEUPPU_LineUpdate();
   V&=CHRmask8[r];
   for(x=7;x>=0;x--)
    VPageR[x]=&CHRptr[r][V<<13];
@@ -291,7 +317,7 @@ void FASTAPASS(2) setchr4(unsigned int A, unsigned int V)
  setchr4r(0,A,V);
 }
 
-void FASTAPASS(2) setchr8(unsigned int V)
+void FASTAPASS(1) setchr8(unsigned int V)
 {
  setchr8r(0,V);
 }
@@ -314,12 +340,14 @@ void FASTAPASS(2) setvram4(uint32 A, uint8 *p)
 
 void FASTAPASS(3) setvramb1(uint8 *p, uint32 A, uint32 b)
 {
+  FCEUPPU_LineUpdate();
   VPageR[A>>10]=p-A+(b<<10);
   PPUCHRRAM|=(1<<(A>>10));
 }
 
 void FASTAPASS(3) setvramb2(uint8 *p, uint32 A, uint32 b)
 {
+  FCEUPPU_LineUpdate();
   VPageR[(A>>10)]=VPageR[(A>>10)+1]=p-A+(b<<11);
   PPUCHRRAM|=(3<<(A>>10));
 }
@@ -328,6 +356,7 @@ void FASTAPASS(3) setvramb4(uint8 *p, uint32 A, uint32 b)
 {
   int x;
 
+  FCEUPPU_LineUpdate();
   for(x=3;x>=0;x--)
    VPageR[(A>>10)+x]=p-A+(b<<12);
   PPUCHRRAM|=(15<<(A>>10));
@@ -337,6 +366,7 @@ void FASTAPASS(2) setvramb8(uint8 *p, uint32 b)
 {
   int x;
 
+  FCEUPPU_LineUpdate();
   for(x=7;x>=0;x--)
    VPageR[x]=p+(b<<13);
   PPUCHRRAM|=255;
@@ -346,6 +376,7 @@ void FASTAPASS(2) setvramb8(uint8 *p, uint32 b)
 
 void FASTAPASS(3) setntamem(uint8 *p, int ram, uint32 b)
 {
+ FCEUPPU_LineUpdate();
  vnapage[b]=p;
  PPUNTARAM&=~(1<<b);
  if(ram)
@@ -355,6 +386,7 @@ void FASTAPASS(3) setntamem(uint8 *p, int ram, uint32 b)
 static int mirrorhard=0;
 void setmirrorw(int a, int b, int c, int d)
 {
+ FCEUPPU_LineUpdate();
  vnapage[0]=NTARAM+a*0x400;
  vnapage[1]=NTARAM+b*0x400;
  vnapage[2]=NTARAM+c*0x400;
@@ -363,6 +395,7 @@ void setmirrorw(int a, int b, int c, int d)
 
 void FASTAPASS(1) setmirror(int t)
 {
+  FCEUPPU_LineUpdate();
   if(!mirrorhard)
   {
    switch(t)
@@ -387,7 +420,10 @@ void FASTAPASS(1) setmirror(int t)
 void SetupCartMirroring(int m, int hard, uint8 *extra)
 {
  if(m<4)
+ {
+  mirrorhard = 0;
   setmirror(m);
+ }
  else
  {
   vnapage[0]=NTARAM;
@@ -411,9 +447,13 @@ void OpenGenie(void)
 
  if(!GENIEROM)
  {
-  if(!(GENIEROM=FCEU_malloc(4096+1024))) return;
+  char *fn;
+
+  if(!(GENIEROM=(uint8 *)FCEU_malloc(4096+1024))) return;
 
-  if(!(fp=fopen(FCEU_MakeFName(FCEUMKF_GGROM,0,0),"rb")))
+  fn=FCEU_MakeFName(FCEUMKF_GGROM,0,0);
+  fp=fopen(fn,"rb");
+  if(!fp)
   {
    FCEU_PrintError("Error opening Game Genie ROM image!");
    free(GENIEROM);
@@ -429,7 +469,7 @@ void OpenGenie(void)
    fclose(fp);
    return;
   }
-  if(GENIEROM[0]==0x4E)        /* iNES ROM image */
+  if(GENIEROM[0]==0x4E)  /* iNES ROM image */
   {
    if(fread(GENIEROM,1,4096,fp)!=4096)
     goto grerr;
@@ -462,6 +502,15 @@ void CloseGenie(void)
  VPageR=VPage;
 }
 
+void FCEU_KillGenie(void)
+{
+ if(GENIEROM)
+ {
+  free(GENIEROM);
+  GENIEROM=0;
+ }
+}
+
 static DECLFR(GenieRead)
 {
  return GENIEROM[A&4095];
@@ -488,14 +537,14 @@ static DECLFW(GenieWrite)
   case 0x8001:genieaddr[((A-1)&0xF)>>2]&=0xFF;genieaddr[((A-1)&0xF)>>2]|=(V|0x80)<<8;break;
 
   case 0x8000:if(!V)
-               FixGenieMap();
-              else
-              {
-               modcon=V^0xFF;
-               if(V==0x71)
-               modcon=0;
-              }
-              break;
+         FixGenieMap();
+        else
+        {
+         modcon=V^0xFF;
+         if(V==0x71)
+    modcon=0;
+        }
+        break;
  }
 }
 
@@ -505,7 +554,7 @@ static DECLFR(GenieFix1)
 {
  uint8 r=GenieBackup[0](A);
 
- if((modcon>>1)&1)             // No check
+ if((modcon>>1)&1)    // No check
   return genieval[0];
  else if(r==geniech[0])
   return genieval[0];
@@ -517,7 +566,7 @@ static DECLFR(GenieFix2)
 {
  uint8 r=GenieBackup[1](A);
 
- if((modcon>>2)&1)              // No check
+ if((modcon>>2)&1)        // No check
   return genieval[1];
  else if(r==geniech[1])
   return genieval[1];
@@ -529,7 +578,7 @@ static DECLFR(GenieFix3)
 {
  uint8 r=GenieBackup[2](A);
 
- if((modcon>>3)&1)              // No check
+ if((modcon>>3)&1)        // No check
   return genieval[2];
  else if(r==geniech[2])
   return genieval[2];
@@ -549,7 +598,7 @@ void FixGenieMap(void)
 
  VPageR=VPage;
  FlushGenieRW();
-
+ //printf("Rightyo\n");
  for(x=0;x<3;x++)
   if((modcon>>(4+x))&1)
   {
@@ -588,3 +637,54 @@ void GeniePower(void)
 }
 
 
+void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
+{
+ if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
+ {
+  FILE *sp;
+  char *soot;
+
+  soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
+  if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL)
+  {
+   FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot);
+  }
+  else
+  {
+   int x;
+
+   for(x=0;x<4;x++)
+    if(LocalHWInfo->SaveGame[x])
+    {
+     fwrite(LocalHWInfo->SaveGame[x],1,
+      LocalHWInfo->SaveGameLen[x],sp);
+    }
+  }
+  free(soot);
+ }
+}
+
+// hack, movie.c has to communicate with this function somehow
+int disableBatteryLoading=0;
+
+void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
+{
+ if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading)
+ {
+  FILE *sp;
+  char *soot;
+
+  soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
+  sp=FCEUD_UTF8fopen(soot,"rb");
+  if(sp!=NULL)
+  {
+   int x;
+   for(x=0;x<4;x++)
+    if(LocalHWInfo->SaveGame[x])
+     fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp);
+  }
+  free(soot);
+ }
+}
+
+
diff --git a/cart.h b/cart.h
index 2a91681..140c54e 100644 (file)
--- a/cart.h
+++ b/cart.h
@@ -1,3 +1,32 @@
+#ifndef _CART_H
+#define _CART_H
+
+typedef struct {
+  /* Set by mapper/board code: */
+  void (*Power)(void);
+  void (*Reset)(void);
+  void (*Close)(void);
+  uint8 *SaveGame[4];     /* Pointers to memory to save/load. */
+  uint32 SaveGameLen[4];  /* How much memory to save/load. */
+
+  /* Set by iNES/UNIF loading code. */
+  int mirror;    /* As set in the header or chunk.
+           iNES/UNIF specific.  Intended
+           to help support games like "Karnov"
+           that are not really MMC3 but are
+           set to mapper 4.
+        */
+  int battery;      /* Presence of an actual battery. */
+  uint8 MD5[16];
+  uint32 CRC32;     /* Should be set by the iNES/UNIF loading
+           code, used by mapper/board code, maybe
+           other code in the future.
+        */
+} CartInfo;
+
+void FCEU_SaveGameSave(CartInfo *LocalHWInfo);
+void FCEU_LoadGameSave(CartInfo *LocalHWInfo);
+
 extern uint8 *Page[32],*VPage[8],*MMC5SPRVPage[8],*MMC5BGVPage[8];
 
 void ResetCartMapping(void);
@@ -5,7 +34,9 @@ void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram);
 void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram);
 void SetupCartMirroring(int m, int hard, uint8 *extra);
 
+DECLFR(CartBROB);
 DECLFR(CartBR);
+DECLFW(CartBW);
 
 extern uint8 *PRGptr[32];
 extern uint8 *CHRptr[32];
@@ -44,7 +75,7 @@ void FASTAPASS(2) setchr8r(int r, unsigned int V);
 void FASTAPASS(2) setchr1(unsigned int A, unsigned int V);
 void FASTAPASS(2) setchr2(unsigned int A, unsigned int V);
 void FASTAPASS(2) setchr4(unsigned int A, unsigned int V);
-void FASTAPASS(2) setchr8(unsigned int V);
+void FASTAPASS(1) setchr8(unsigned int V);
 
 void FASTAPASS(2) setvram4(uint32 A, uint8 *p);
 void FASTAPASS(1) setvram8(uint8 *p);
@@ -69,3 +100,7 @@ void GeniePower(void);
 
 void OpenGenie(void);
 void CloseGenie(void);
+void FCEU_KillGenie(void);
+
+#endif // ndef _CART_H
+
index cfaf2cf..aa6a2c7 100644 (file)
--- a/driver.h
+++ b/driver.h
@@ -59,18 +59,34 @@ void FCEUI_DisableFourScore(int s);
 
 #include "version.h"
 
-#define SI_NONE     0
-#define SI_GAMEPAD  1
-#define SI_ZAPPER   2
-#define SI_POWERPAD 3
-#define SI_ARKANOID 4
-
-#define SIFC_NONE      0
-#define SIFC_ARKANOID  1
-#define SIFC_SHADOW    2
+#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 SIFC_NONE      0
+#define SIFC_ARKANOID  1
+#define SIFC_SHADOW      2
 #define SIFC_4PLAYER    3
-#define SIFC_FKB       4
-#define SIFC_OEKA      5
+#define SIFC_FKB      4
+#define SIFC_SUBORKB    5
+#define SIFC_HYPERSHOT  6
+#define SIFC_MAHJONG  7
+#define SIFC_QUIZKING  8
+#define SIFC_FTRAINERA  9
+#define SIFC_FTRAINERB  10
+#define SIFC_OEKAKIDS  11
+#define SIFC_BWORLD      12
+#define SIFC_TOPRIDER  13
+
+#define SIS_NONE  0
+#define SIS_DATACH  1
+#define SIS_NWC    2
+#define SIS_VSUNISYSTEM  3
+#define SIS_NSF    4
+
 
 /* New interface functions */
 
index ad36e01..95ed4bd 100644 (file)
@@ -193,7 +193,7 @@ static void DoArgs(int argc, char *argv[])
 {
         static char *cortab[5]={"none","gamepad","zapper","powerpad","arkanoid"};
         static int cortabi[5]={SI_NONE,SI_GAMEPAD,
-                               SI_ZAPPER,SI_POWERPAD,SI_ARKANOID};
+                               SI_ZAPPER,SI_POWERPADA,SI_ARKANOID};
        static char *fccortab[5]={"none","arkanoid","shadow","4player","fkb"};
        static int fccortabi[5]={SIFC_NONE,SIFC_ARKANOID,SIFC_SHADOW,
                                 SIFC_4PLAYER,SIFC_FKB};
diff --git a/fce.c b/fce.c
index 53abd93..e36a86c 100644 (file)
--- a/fce.c
+++ b/fce.c
@@ -97,7 +97,7 @@ void (*GameInterface)(int h);
 void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
 
 void (*GameStateRestore)(int version);
-void (*GameHBIRQHook)(void);
+void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void);
 
 readfunc ARead[0x10000];
 writefunc BWrite[0x10000];
@@ -973,6 +973,8 @@ static void DoHBlank(void)
   Fixit2();
   X6502_Run(85-6-16);
  }
+ if(GameHBIRQHook2 && (ScreenON || SpriteON))
+  GameHBIRQHook2();
  //PPU_hook(0,-1);
  //fprintf(stderr,"%3d: $%04x\n",scanline,RefreshAddr);
  scanline++;
@@ -1044,7 +1046,7 @@ void ResetGameLoaded(void)
         if(GameLoaded) CloseGame();
         GameStateRestore=0;
         PPU_hook=0;
-        GameHBIRQHook=0;
+        GameHBIRQHook=GameHBIRQHook2=0;
        GameExpSound.Fill=0;
        GameExpSound.RChange=0;
         if(GameExpSound.Kill)
@@ -1063,6 +1065,10 @@ void ResetGameLoaded(void)
 }
 
 char lastLoadedGameName [2048];
+int UNIFLoad(const char *name, int fp);
+int iNESLoad(const char *name, int fp);
+int FDSLoad(const char *name, int fp);
+int NSFLoad(int fp);
 
 FCEUGI *FCEUI_LoadGame(char *name)
 {
@@ -1255,8 +1261,12 @@ void EmLoop(void)
   X6502_Run(256);
   {
    if(ScreenON || SpriteON)
+   {
     if(GameHBIRQHook)
      GameHBIRQHook();
+    if(GameHBIRQHook2)
+     GameHBIRQHook2();
+   }
 
    X6502_Run(85-16);
 
diff --git a/fce.h b/fce.h
index 8734f4c..04d050a 100644 (file)
--- a/fce.h
+++ b/fce.h
@@ -5,6 +5,8 @@ void asmcpu_unpack(void);
 void asmcpu_pack(void);
 #endif
 
+#define fceuindbg 0
+
 extern int GameLoaded;
 void ResetGameLoaded(void);
 
@@ -72,7 +74,7 @@ extern writefunc BWrite[0x10000];
 
 extern void (*GameInterface)(int h);
 extern void FP_FASTAPASS(1) (*PPU_hook)(uint32 A);
-extern void (*GameHBIRQHook)(void);
+extern void (*GameHBIRQHook)(void), (*GameHBIRQHook2)(void);
 extern void (*GameStateRestore)(int version);
 
 #define GI_RESETM2     1
@@ -83,6 +85,9 @@ extern void (*GameStateRestore)(int version);
 extern FCEUGI FCEUGameInfo;
 extern int GameAttributes;
 
+extern uint8 pale;
+extern uint8 vsdip;
+
 
 #endif
 
diff --git a/fds.c b/fds.c
index 455acc5..f0640a0 100644 (file)
--- a/fds.c
+++ b/fds.c
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "types.h"
-#include "x6502.h"
-#include "version.h"
-#include "fce.h"
-#include "fds.h"
-#include "svga.h"
-#include "sound.h"
-#include "general.h"
-#include "state.h"
-#include "file.h"
-#include "memory.h"
-#include "cart.h"
-
-/*     TODO:  Add code to put a delay in between the time a disk is inserted
-       and the when it can be successfully read/written to.  This should
-       prevent writes to wrong places OR add code to prevent disk ejects
-       when the virtual motor is on(mmm...virtual motor).
-*/
-
-static DECLFR(FDSRead4030);
-static DECLFR(FDSRead4031);
-static DECLFR(FDSRead4032);
-static DECLFR(FDSRead4033);
-static DECLFW(FDSWrite4020);
-static DECLFW(FDSWrite4021);
-static DECLFW(FDSWrite4022);
-static DECLFW(FDSWrite4023);
-static DECLFW(FDSWrite4024);
-static DECLFW(FDSWrite4025);
-static DECLFW(FDSWaveWrite);
-static DECLFR(FDSWaveRead);
-
-static DECLFR(FDSSRead);
-static DECLFW(FDSSWrite);
-static DECLFR(FDSBIOSRead);
-static DECLFR(FDSRAMRead);
-static DECLFW(FDSRAMWrite);
-static void FDSInit(void);
-static void FDSReset(void);
-static void FP_FASTAPASS(1) FDSFix(int a);
-
-#define FDSRAM GameMemBlock
-#define mapbyte1 (GameMemBlock+32768)
-#define mapbyte2 (GameMemBlock+32768+8)
-#define mapbyte3 (GameMemBlock+32768+16)
-#define mapbyte4 (GameMemBlock+32768+24)        // 8 bytes
-#define CHRRAM   (GameMemBlock+32768+32+64)
-
-#define IRQLatch       (*(int32*)(CHRRAM+8192))
-#define IRQCount       (*(int32*)(CHRRAM+8192+4))
-#define IRQa           (*(CHRRAM+8192+8))
-
-static void FDSClose(void);
-static uint8 header[16];
-#define writeskip mapbyte2[0]
-
-static char FDSSaveName[2048];
-
-uint8 FDSBIOS[8192];
-uint8 *diskdata[4]={0,0,0,0};
-
-#define SideWrite mapbyte2[1]
-#define DiskPtr (*(uint32*)(mapbyte2+4))
-#define dsr0 mapbyte2[2]
-#define dsr1 mapbyte2[3]
-
-#define DC_INC         1
-
-#define DiskSeekIRQ (*(int32*)(mapbyte3+4))
-#define SelectDisk mapbyte3[0]
-#define InDisk    mapbyte3[1]
-
-static void FDSReset(void)
-{
-        memset(mapbyte1,0,8);
-        memset(mapbyte2,0,8);
-        memset(mapbyte3+4,0,4);
-        memset(mapbyte4,0,8);
-}
-
-void FDSGI(int h)
-{
- switch(h)
- {
-  case GI_CLOSE: FDSClose();break;
-  case GI_POWER: FDSReset();FDSInit();break;
- }
-}
-
-static void FDSStateRestore(int version)
-{
- setmirror(((mapbyte1[5]&8)>>3)^1);
-}
-
-void FDSSound();
-void FDSSoundReset(void);
-void FDSSoundStateAdd(void);
-static void RenderSound(void);
-
-static void FDSInit(void)
-{
- dsr0=0;
- dsr1=0x41;
- setmirror(1);
- if(InDisk!=255)
-  dsr1&=0xFE;
-
- setprg8r(0,0xe000,0);          // BIOS
- setprg32r(1,0x6000,0);         // 32KB RAM
- setchr8(0);           // 8KB CHR RAM
-
- MapIRQHook=FDSFix;
- GameStateRestore=FDSStateRestore;
-
- SetReadHandler(0x4030,0x4030,FDSRead4030);
- SetReadHandler(0x4031,0x4031,FDSRead4031);
- SetReadHandler(0x4032,0x4032,FDSRead4032);
- SetReadHandler(0x4033,0x4033,FDSRead4033);
-
- SetWriteHandler(0x4020,0x4020,FDSWrite4020);
- SetWriteHandler(0x4021,0x4021,FDSWrite4021);
- SetWriteHandler(0x4022,0x4022,FDSWrite4022);
- SetWriteHandler(0x4023,0x4023,FDSWrite4023);
- SetWriteHandler(0x4024,0x4024,FDSWrite4024);
- SetWriteHandler(0x4025,0x4025,FDSWrite4025);
-
- SetWriteHandler(0x6000,0xdfff,FDSRAMWrite);
- SetReadHandler(0x6000,0xdfff,FDSRAMRead);
- SetReadHandler(0xE000,0xFFFF,FDSBIOSRead);
-
- IRQCount=IRQLatch=IRQa=0;
-
- FDSSoundReset();
-}
-
-void FDSControl(int what)
-{
- switch(what)
- {
-  case FDS_IDISK:dsr1&=0xFE;
-                 if(InDisk==255)
-                {
-                 FCEU_DispMessage("Disk %d Side %s Inserted",
-                 SelectDisk>>1,(SelectDisk&1)?"B":"A");
-                 InDisk=SelectDisk;
-                }
-                else
-                 FCEU_DispMessage("Jamming disks is a BAD IDEA");
-                break;
-  case FDS_EJECT:
-                if(InDisk!=255)
-                 FCEU_DispMessage("Disk Ejected");
-                else
-                 FCEU_DispMessage("Cannot Eject Air");
-                dsr1|=1;
-                InDisk=255;
-                break;
-  case FDS_SELECT:
-                 if(InDisk!=255)
-                 {
-                  FCEU_DispMessage("Eject disk before selecting.");
-                  break;
-                 }
-                 SelectDisk=((SelectDisk+1)%header[4])&3;
-                 FCEU_DispMessage("Disk %d Side %s Selected",
-                       SelectDisk>>1,(SelectDisk&1)?"B":"A");
-                 break;
- }
-}
-
-static void FP_FASTAPASS(1) FDSFix(int a)
-{
- if(IRQa)
- {
-  IRQCount-=a;
-  if(IRQCount<=0)
-  {
-   IRQa=0;
-   dsr0|=1;
-   dsr0&=~2;
-   IRQCount=0xFFFF;
-   X6502_IRQBegin(FCEU_IQEXT);
-  }
- }
- if(DiskSeekIRQ>0)
- {
-  DiskSeekIRQ-=a;
-  if(DiskSeekIRQ<=0)
-  {
-   if(mapbyte1[5]&0x80)
-   {
-    dsr0&=~1;
-    dsr0|=2;
-    TriggerIRQ();
-   }
-  }
- }
-}
-
-void DiskControl(int which)
-{
-if(mapbyte1[5]&1)
- {
-  switch(which)
-  {
-  case DC_INC:
-              if(DiskPtr<64999) DiskPtr++;
-              //DiskSeekIRQ=160+100;
-              //DiskSeekIRQ=140;
-              //DiskSeekIRQ=160;
-               DiskSeekIRQ=150;
-              break;
-  }
- }
-}
-static DECLFR(FDSRead4030)
-{
-       X6502_IRQEnd(FCEU_IQEXT);
-       return dsr0;
-}
-
-static DECLFR(FDSRead4031)
-{
-       static uint8 z=0;
-       if(InDisk!=255)
-       {
-         z=diskdata[InDisk][DiskPtr];
-         DiskControl(DC_INC);
-       }
-        return z;
-}
-
-static DECLFR(FDSRead4032)
-{
-       return dsr1;
-}
-
-static DECLFR(FDSRead4033)
-{
-       return 0x80; // battery
-}
-
-static DECLFW(FDSRAMWrite)
-{
- (FDSRAM-0x6000)[A]=V;
-}
-
-static DECLFR(FDSBIOSRead)
-{
- return (FDSBIOS-0xE000)[A];
-}
-
-static DECLFR(FDSRAMRead)
-{
- return (FDSRAM-0x6000)[A];
-}
-
-/* Begin FDS sound */
-
-#define FDSClock (1789772.7272727272727272/8)
-
-typedef struct {
-        int64 cycles;           // Cycles per PCM sample
-        int64 count;           // Cycle counter
-       int64 envcount;         // Envelope cycle counter
-       uint32 b19shiftreg60;
-       uint32 b24adder66;
-       uint32 b24latch68;
-       uint32 b17latch76;
-        int32 clockcount;      // Counter to divide frequency by 8.
-       uint8 b8shiftreg88;     // Modulation register.
-       uint8 amplitude[2];     // Current amplitudes.
-        uint8 mwave[0x20];      // Modulation waveform
-        uint8 cwave[0x40];      // Game-defined waveform(carrier)
-        uint8 SPSG[0xB];
-} FDSSOUND;
-
-static FDSSOUND fdso;
-
-#define        SPSG    fdso.SPSG
-#define b19shiftreg60  fdso.b19shiftreg60
-#define b24adder66     fdso.b24adder66
-#define b24latch68     fdso.b24latch68
-#define b17latch76     fdso.b17latch76
-#define b8shiftreg88   fdso.b8shiftreg88
-#define clockcount     fdso.clockcount
-#define amplitude      fdso.amplitude
-
-void FDSSoundStateAdd(void)
-{
- AddExState(fdso.cwave,64,0,"WAVE");
- AddExState(fdso.mwave,32,0,"MWAV");
- AddExState(amplitude,2,0,"AMPL");
- AddExState(SPSG,0xB,0,"SPSG");
-
- AddExState(&b8shiftreg88,1,0,"B88");
-
- AddExState(&clockcount, 4, 1, "CLOC");
- AddExState(&b19shiftreg60,4,1,"B60");
- AddExState(&b24adder66,4,1,"B66");
- AddExState(&b24latch68,4,1,"B68");
- AddExState(&b17latch76,4,1,"B76");
-
-}
-
-static DECLFR(FDSSRead)
-{
- switch(A&0xF)
- {
-  case 0x0:return(amplitude[0]|(X.DB&0xC0));
-  case 0x2:return(amplitude[1]|(X.DB&0xC0));
- }
- return(X.DB);
-}
-
-static DECLFW(FDSSWrite)
-{
- if(FSettings.SndRate)
-  RenderSound();
- A-=0x4080;
- switch(A)
- {
-  case 0x0:
-  case 0x4:
-           if(!(V&0x80))
-           {
-             // if(V&0x40) amplitude[(A&0xF)>>2]=0;
-             // else amplitude[(A&0xF)>>2]=0x3F;
-           }
-           else
-            amplitude[(A&0xF)>>2]=V&0x3F;
-           break;
-  case 0x7: b17latch76=0;SPSG[0x5]=0;break;
-  case 0x8:
-          //printf("%d:$%02x\n",SPSG[0x5],V);
-          fdso.mwave[SPSG[0x5]&0x1F]=V&0x7;
-           SPSG[0x5]=(SPSG[0x5]+1)&0x1F;
-          break;
- }
- //if(A>=0x7 && A!=0x8 && A<=0xF)
- //if(A==0xA || A==0x9) printf("$%04x:$%02x\n",A,V);
- SPSG[A]=V;
-}
-
-// $4080 - Fundamental wave amplitude data register 92
-// $4082 - Fundamental wave frequency data register 58
-// $4083 - Same as $4082($4083 is the upper 4 bits).
-
-// $4084 - Modulation amplitude data register 78
-// $4086 - Modulation frequency data register 72
-// $4087 - Same as $4086($4087 is the upper 4 bits)
-
-
-static void DoEnv()
-{
- int x;
-
- for(x=0;x<2;x++)
-  if(!(SPSG[x<<2]&0x80) && !(SPSG[0x9+x]&0x80))
-  {
-   static int counto[2]={0,0};
-
-   if(counto[x]<=0)
-   {
-    if(SPSG[x<<2]&0x40)
-    {
-     if(amplitude[x]<0x3F)
-      amplitude[x]++;
-    }
-    else
-    {
-     if(amplitude[x]>0)
-      amplitude[x]--;
-    }
-    counto[x]=(SPSG[x<<2]&0x3F);
-   }
-   else
-    counto[x]--;
-  }
-}
-
-static DECLFR(FDSWaveRead)
-{
- return(fdso.cwave[A&0x3f]|(X.DB&0xC0));
-}
-
-static DECLFW(FDSWaveWrite)
-{
- if(SPSG[0x9]&0x80)
-  fdso.cwave[A&0x3f]=V&0x3F;
-}
-
-static INLINE void ClockRise(void)
-{
- if(!clockcount)
- {
-  b19shiftreg60=(SPSG[0x2]|((SPSG[0x3]&0xF)<<8));
-  b17latch76=(SPSG[0x6]|((SPSG[0x07]&0x3)<<8))+b17latch76;
-
-  if(!(SPSG[0x7]&0x80))
-  {
-   b8shiftreg88=(amplitude[1]*((fdso.mwave[(b17latch76>>11)&0x1F]&7)));
-   //b8shiftreg88=((fdso.mwave[(b17latch76>>11)&0x1F]&7))|(amplitude[1]<<3);
-  }
-  else
-  { b8shiftreg88=0;}
- }
- else
- {
-  b19shiftreg60<<=1;
-  b8shiftreg88>>=1;
- }
- b24adder66=(b24latch68+b19shiftreg60)&0xFFFFFF;
-}
-
-static INLINE void ClockFall(void)
-{
-// if(!(SPSG[0x7]&0x80))
- {
-  if(!(b8shiftreg88&1))
-   b24latch68=b24adder66;
- }
- clockcount=(clockcount+1)&7;
-}
-
-static INLINE int32 FDSDoSound(void)
-{
- fdso.count+=fdso.cycles;
- if(fdso.count>=((int64)1<<40))
- {
-  dogk:
-  fdso.count-=(int64)1<<40;
-  ClockRise();
-  ClockFall();
- }
- if(fdso.count>=32768) goto dogk;
-
- fdso.envcount-=fdso.cycles;
- if(fdso.envcount<=0)
- {
-  // Fix this?
-  fdso.envcount+=((int64)1<<40)*FDSClock/1024;
-  DoEnv();
- }
-
- // Might need to emulate applying the amplitude to the waveform a bit better...
- return (fdso.cwave[b24latch68>>18]*amplitude[0]);
-}
-
-static int32 FBC=0;
-
-static void RenderSound(void)
-{
- int32 end, start;
- int32 x;
-
- start=FBC;
- end=(SOUNDTS<<16)/soundtsinc;
- if(end<=start)
-  return;
- FBC=end;
-
- if(!(SPSG[0x9]&0x80))
-  for(x=start;x<end;x++)
-  {
-   uint32 t=FDSDoSound();
-   Wave[x>>4]+=t>>3;
-  }
-}
-
-void FDSSound(int c)
-{
-  RenderSound();
-  FBC=c;
-}
-
-static void FDS_ESI(void)
-{
- if(FSettings.SndRate)
- {
-  fdso.cycles=((int64)1<<40)*FDSClock;
-  fdso.cycles/=FSettings.SndRate OVERSAMPLE;
- }
-//  fdso.cycles=(int64)32768*FDSClock/(FSettings.SndRate OVERSAMPLE);
- SetReadHandler(0x4040,0x407f,FDSWaveRead);
- SetWriteHandler(0x4040,0x407f,FDSWaveWrite);
- SetWriteHandler(0x4080,0x408A,FDSSWrite);
- SetReadHandler(0x4090,0x4092,FDSSRead);
-}
-
-void FDSSoundReset(void)
-{
- memset(&fdso,0,sizeof(fdso));
- FDS_ESI();
- GameExpSound.Fill=FDSSound;
- GameExpSound.RChange=FDS_ESI;
-}
-
-
-static DECLFW(FDSWrite4020)
-{
-       X6502_IRQEnd(FCEU_IQEXT);
-       IRQLatch&=0xFF00;
-       IRQLatch|=V;
-       mapbyte1[0]=V;
-}
-static DECLFW(FDSWrite4021)
-{
-       X6502_IRQEnd(FCEU_IQEXT);
-       IRQLatch&=0xFF;
-       IRQLatch|=V<<8;
-       mapbyte1[1]=V;
-}
-static DECLFW(FDSWrite4022)
-{
-       X6502_IRQEnd(FCEU_IQEXT);
-       IRQCount=IRQLatch;
-       IRQa=V&2;
-       mapbyte1[2]=V;
-}
-static DECLFW(FDSWrite4023)
-{
-       mapbyte1[3]=V;
-}
-static DECLFW(FDSWrite4024)
-{
-        if(InDisk!=255 && !(mapbyte1[5]&0x4) && mapbyte1[3]&0x1)
-        {
-         if(DiskPtr>=0 && DiskPtr<65000)
-         {
-          if(writeskip) writeskip--;
-          else if(DiskPtr>=2)
-          {
-           SideWrite|=1<<InDisk;
-           diskdata[InDisk][DiskPtr-2]=V;
-          }
-         }
-        }
-}
-static DECLFW(FDSWrite4025)
-{
-       if(InDisk!=255)
-       {
-         if(!(V&0x40))
-         {
-          if(mapbyte1[5]&0x40 && !(V&0x10))
-          {
-           DiskSeekIRQ=200;
-           DiskPtr-=2;
-          }
-          if(DiskPtr<0) DiskPtr=0;
-         }
-         if(!(V&0x4)) writeskip=2;
-         if(V&2) {DiskPtr=0;DiskSeekIRQ=200;}
-         if(V&0x40) DiskSeekIRQ=200;
-       }
-       mapbyte1[5]=V;
-        setmirror(((V>>3)&1)^1);
-}
-static void FreeFDSMemory(void)
-{
- int x;
-
- for(x=0;x<header[4];x++)
-  if(diskdata[x])
-  {
-   free(diskdata[x]);
-   diskdata[x]=0;
-  }
-}
-
-int FDSLoad(char *name, int fp)
-{
- FILE *zp;
- int x;
-
- FCEU_fseek(fp,0,SEEK_SET);
- FCEU_fread(header,16,1,fp);
-
- if(memcmp(header,"FDS\x1a",4))
- {
-  if(!(memcmp(header+1,"*NINTENDO-HVC*",14)))
-  {
-   long t;
-   t=FCEU_fgetsize(fp);
-   if(t<65500)
-    t=65500;
-   header[4]=t/65500;
-   header[0]=0;
-   FCEU_fseek(fp,0,SEEK_SET);
-  }
-  else
-   return 0;
- }
-
- if(header[4]>4) header[4]=4;
- if(!header[4]) header[4]|=1;
- for(x=0;x<header[4];x++)
- {
-  diskdata[x]=FCEU_malloc(65500);
-  if(!diskdata[x])
-  {
-   int zol;
-   for(zol=0;zol<x;zol++)
-    free(diskdata[zol]);
-   return 0;
-  }
-  FCEU_fread(diskdata[x],1,65500,fp);
- }
-
- if(!(zp=fopen(FCEU_MakeFName(FCEUMKF_FDSROM,0,0),"rb")))
- {
-  FCEU_PrintError("FDS BIOS ROM image missing!");
-  FreeFDSMemory();
-  return 0;
- }
-
- if(fread(FDSBIOS,1,8192,zp)!=8192)
- {
-  fclose(zp);
-  FreeFDSMemory();
-  FCEU_PrintError("Error reading FDS BIOS ROM image");
-  return 0;
- }
-
- fclose(zp);
-
- FCEUGameInfo.type=GIT_FDS;
- strcpy(FDSSaveName,name);
- GameInterface=FDSGI;
-
- SelectDisk=0;
- InDisk=255;
-
- ResetExState();
- FDSSoundStateAdd();
-
- for(x=0;x<header[4];x++)
- {
-  char temp[5];
-  sprintf(temp,"DDT%d",x);
-  AddExState(diskdata[x],65500,0,temp);
- }
-
- AddExState(FDSRAM,32768,0,"FDSR");
- AddExState(mapbyte1,32,0,"MPBY");
- AddExState(CHRRAM,8192,0,"CHRR");
- AddExState(&IRQCount, 4, 1, "IRQC");
- AddExState(&IRQLatch, 4, 1, "IQL1");
- AddExState(&IRQa, 1, 0, "IRQA");
-
-
- ResetCartMapping();
-
- SetupCartCHRMapping(0,CHRRAM,8192,1);
- SetupCartMirroring(0,0,0);
-
- return 1;
-}
-
-void FDSClose(void)
-{
-  int fp;
-  int x;
-
-  fp=FCEU_fopen(FDSSaveName,"wb");
-  if(!fp) return;
-
-  if(header[0])                        // Does it have a 16-byte FWNES-style header?
-   if(FCEU_fwrite(header,1,16,fp)!=16) // Write it out.  Should be nicer than fseek()'ing if the file is compressed.  Hopefully...
-    goto fdswerr;
-
-  for(x=0;x<header[4];x++)
-  {
-   if(FCEU_fwrite(diskdata[x],1,65500,fp)!=65500)
-   {
-    fdswerr:
-    FCEU_PrintError("Error writing FDS image \"%s\"!",FDSSaveName);
-    FCEU_fclose(fp);
-    return;
-   }
-  }
-  FreeFDSMemory();
-  FCEU_fclose(fp);
-}
+/* 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
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "types.h"\r
+#include "x6502.h"\r
+#include "fce.h"\r
+#include "fds.h"\r
+#include "sound.h"\r
+#include "general.h"\r
+#include "state.h"\r
+#include "file.h"\r
+#include "memory.h"\r
+#include "cart.h"\r
+#include "md5.h"\r
+#include "netplay.h"\r
+\r
+#include "svga.h"\r
+\r
+/*  TODO:  Add code to put a delay in between the time a disk is inserted\r
+       and the when it can be successfully read/written to.  This should\r
+       prevent writes to wrong places OR add code to prevent disk ejects\r
+       when the virtual motor is on(mmm...virtual motor).\r
+*/\r
+\r
+static DECLFR(FDSRead4030);\r
+static DECLFR(FDSRead4031);\r
+static DECLFR(FDSRead4032);\r
+static DECLFR(FDSRead4033);\r
+\r
+static DECLFW(FDSWrite);\r
+\r
+static DECLFW(FDSWaveWrite);\r
+static DECLFR(FDSWaveRead);\r
+\r
+static DECLFR(FDSSRead);\r
+static DECLFW(FDSSWrite);\r
+static DECLFR(FDSBIOSRead);\r
+static DECLFR(FDSRAMRead);\r
+static DECLFW(FDSRAMWrite);\r
+static void FDSInit(void);\r
+static void FP_FASTAPASS(1) FDSFix(int a);\r
+\r
+#define FDSRAM GameMemBlock\r
+#define CHRRAM (GameMemBlock+32768)\r
+\r
+static uint8 FDSRegs[6];\r
+static int32 IRQLatch,IRQCount;\r
+static uint8 IRQa;\r
+static void FDSClose(void);\r
+\r
+static uint8 FDSBIOS[8192];\r
+\r
+/* Original disk data backup, to help in creating save states. */\r
+static uint8 *diskdatao[8]={0,0,0,0,0,0,0,0};\r
+\r
+static uint8 *diskdata[8]={0,0,0,0,0,0,0,0};\r
+\r
+static unsigned int TotalSides;\r
+static uint8 DiskWritten=0;    /* Set to 1 if disk was written to. */\r
+static uint8 writeskip;\r
+static uint32 DiskPtr;\r
+static int32 DiskSeekIRQ;\r
+static uint8 SelectDisk,InDisk;\r
+\r
+#define DC_INC    1\r
+\r
+void FDSGI(int h)\r
+{\r
+ switch(h)\r
+ {\r
+  case GI_CLOSE: FDSClose();break;\r
+  case GI_POWER: FDSInit();break;\r
+ }\r
+}\r
+\r
+static void FDSStateRestore(int version)\r
+{\r
+ int x;\r
+\r
+ setmirror(((FDSRegs[5]&8)>>3)^1);\r
+\r
+ if(version >= 9810)\r
+  for(x=0;x<TotalSides;x++)\r
+  {\r
+   int b;\r
+   for(b=0; b<65500; b++)\r
+    diskdata[x][b] ^= diskdatao[x][b];\r
+  }\r
+\r
+}\r
+\r
+void FDSSound();\r
+void FDSSoundReset(void);\r
+void FDSSoundStateAdd(void);\r
+static void RenderSound(void);\r
+//static void RenderSoundHQ(void);\r
+\r
+static void FDSInit(void)\r
+{\r
+ memset(FDSRegs,0,sizeof(FDSRegs));\r
+ writeskip=DiskPtr=DiskSeekIRQ=0;\r
+ setmirror(1);\r
+\r
+ setprg8r(0,0xe000,0);    // BIOS\r
+ setprg32r(1,0x6000,0);   // 32KB RAM\r
+ setchr8(0);     // 8KB CHR RAM\r
+\r
+ MapIRQHook=FDSFix;\r
+ GameStateRestore=FDSStateRestore;\r
+\r
+ SetReadHandler(0x4030,0x4030,FDSRead4030);\r
+ SetReadHandler(0x4031,0x4031,FDSRead4031);\r
+ SetReadHandler(0x4032,0x4032,FDSRead4032);\r
+ SetReadHandler(0x4033,0x4033,FDSRead4033);\r
+\r
+ SetWriteHandler(0x4020,0x4025,FDSWrite);\r
+\r
+ SetWriteHandler(0x6000,0xdfff,FDSRAMWrite);\r
+ SetReadHandler(0x6000,0xdfff,FDSRAMRead);\r
+ SetReadHandler(0xE000,0xFFFF,FDSBIOSRead);\r
+ IRQCount=IRQLatch=IRQa=0;\r
+\r
+ FDSSoundReset();\r
+ InDisk=0;\r
+ SelectDisk=0;\r
+}\r
+\r
+void FCEU_FDSInsert(void)\r
+{\r
+       if(TotalSides==0)\r
+       {\r
+        FCEU_DispMessage("Not FDS; can't eject disk.");\r
+               return;\r
+       }\r
+       if(InDisk==255)\r
+        {\r
+         FCEU_DispMessage("Disk %d Side %s Inserted",SelectDisk>>1,(SelectDisk&1)?"B":"A");\r
+         InDisk=SelectDisk;\r
+        }\r
+        else\r
+        {\r
+         FCEU_DispMessage("Disk %d Side %s Ejected",SelectDisk>>1,(SelectDisk&1)?"B":"A");\r
+         InDisk=255;\r
+        }\r
+}\r
+/*\r
+void FCEU_FDSEject(void)\r
+{\r
+         InDisk=255;\r
+}\r
+*/\r
+void FCEU_FDSSelect(void)\r
+{\r
+       if(TotalSides==0)\r
+       {\r
+         FCEU_DispMessage("Not FDS; can't select disk.");\r
+         return;\r
+       }\r
+       if(InDisk!=255)\r
+        {\r
+         FCEU_DispMessage("Eject disk before selecting.");\r
+        return;\r
+        }\r
+           SelectDisk=((SelectDisk+1)%TotalSides)&3;\r
+           FCEU_DispMessage("Disk %d Side %c Selected",SelectDisk>>1,(SelectDisk&1)?'B':'A');\r
+}\r
+\r
+static void FP_FASTAPASS(1) FDSFix(int a)\r
+{\r
+ if((IRQa&2) && IRQCount)\r
+ {\r
+  IRQCount-=a;\r
+  if(IRQCount<=0)\r
+  {\r
+   if(!(IRQa&1))\r
+   {\r
+    IRQa&=~2;\r
+    IRQCount=IRQLatch=0;\r
+   }\r
+   else\r
+    IRQCount=IRQLatch;\r
+   //IRQCount=IRQLatch; //0xFFFF;\r
+   X6502_IRQBegin(FCEU_IQEXT);\r
+   //printf("IRQ: %d\n",timestamp);\r
+//   printf("IRQ: %d\n",scanline);\r
+  }\r
+ }\r
+ if(DiskSeekIRQ>0)\r
+ {\r
+  DiskSeekIRQ-=a;\r
+  if(DiskSeekIRQ<=0)\r
+  {\r
+   if(FDSRegs[5]&0x80)\r
+   {\r
+    X6502_IRQBegin(FCEU_IQEXT2);\r
+   }\r
+  }\r
+ }\r
+}\r
+\r
+static DECLFR(FDSRead4030)\r
+{\r
+       uint8 ret=0;\r
+\r
+       /* Cheap hack. */\r
+       if(X.IRQlow&FCEU_IQEXT) ret|=1;\r
+       if(X.IRQlow&FCEU_IQEXT2) ret|=2;\r
+\r
+       if(!fceuindbg)\r
+       {\r
+        X6502_IRQEnd(FCEU_IQEXT);\r
+        X6502_IRQEnd(FCEU_IQEXT2);\r
+       }\r
+       return ret;\r
+}\r
+\r
+static DECLFR(FDSRead4031)\r
+{\r
+       static uint8 z=0;\r
+       if(InDisk!=255)\r
+       {\r
+         z=diskdata[InDisk][DiskPtr];\r
+        if(!fceuindbg)\r
+        {\r
+          if(DiskPtr<64999) DiskPtr++;\r
+          DiskSeekIRQ=150;\r
+          X6502_IRQEnd(FCEU_IQEXT2);\r
+        }\r
+       }\r
+        return z;\r
+}\r
+static DECLFR(FDSRead4032)\r
+{\r
+        uint8 ret;\r
+\r
+        ret=X.DB&~7;\r
+        if(InDisk==255)\r
+         ret|=5;\r
+\r
+        if(InDisk==255 || !(FDSRegs[5]&1) || (FDSRegs[5]&2))\r
+         ret|=2;\r
+        return ret;\r
+}\r
+\r
+static DECLFR(FDSRead4033)\r
+{\r
+       return 0x80; // battery\r
+}\r
+\r
+static DECLFW(FDSRAMWrite)\r
+{\r
+ (FDSRAM-0x6000)[A]=V;\r
+}\r
+\r
+static DECLFR(FDSBIOSRead)\r
+{\r
+ return (FDSBIOS-0xE000)[A];\r
+}\r
+\r
+static DECLFR(FDSRAMRead)\r
+{\r
+ return (FDSRAM-0x6000)[A];\r
+}\r
+\r
+/* Begin FDS sound */\r
+\r
+#define FDSClock (1789772.7272727272727272/2)\r
+\r
+typedef struct {\r
+  int64 cycles;     // Cycles per PCM sample\r
+  int64 count;    // Cycle counter\r
+  int64 envcount;    // Envelope cycle counter\r
+       uint32 b19shiftreg60;\r
+       uint32 b24adder66;\r
+       uint32 b24latch68;\r
+       uint32 b17latch76;\r
+  int32 clockcount;  // Counter to divide frequency by 8.\r
+  uint8 b8shiftreg88;  // Modulation register.\r
+  uint8 amplitude[2];  // Current amplitudes.\r
+       uint8 speedo[2];\r
+       uint8 mwcount;\r
+       uint8 mwstart;\r
+        uint8 mwave[0x20];      // Modulation waveform\r
+        uint8 cwave[0x40];      // Game-defined waveform(carrier)\r
+        uint8 SPSG[0xB];\r
+} FDSSOUND;\r
+\r
+static FDSSOUND fdso;\r
+\r
+#define  SPSG  fdso.SPSG\r
+#define b19shiftreg60  fdso.b19shiftreg60\r
+#define b24adder66  fdso.b24adder66\r
+#define b24latch68  fdso.b24latch68\r
+#define b17latch76  fdso.b17latch76\r
+#define b8shiftreg88  fdso.b8shiftreg88\r
+#define clockcount  fdso.clockcount\r
+#define amplitude  fdso.amplitude\r
+#define speedo    fdso.speedo\r
+\r
+void FDSSoundStateAdd(void)\r
+{\r
+ AddExState(fdso.cwave,64,0,"WAVE");\r
+ AddExState(fdso.mwave,32,0,"MWAV");\r
+ AddExState(amplitude,2,0,"AMPL");\r
+ AddExState(SPSG,0xB,0,"SPSG");\r
+\r
+ AddExState(&b8shiftreg88,1,0,"B88");\r
+\r
+ AddExState(&clockcount, 4, 1, "CLOC");\r
+ AddExState(&b19shiftreg60,4,1,"B60");\r
+ AddExState(&b24adder66,4,1,"B66");\r
+ AddExState(&b24latch68,4,1,"B68");\r
+ AddExState(&b17latch76,4,1,"B76");\r
+\r
+}\r
+\r
+static DECLFR(FDSSRead)\r
+{\r
+ switch(A&0xF)\r
+ {\r
+  case 0x0:return(amplitude[0]|(X.DB&0xC0));\r
+  case 0x2:return(amplitude[1]|(X.DB&0xC0));\r
+ }\r
+ return(X.DB);\r
+}\r
+\r
+static DECLFW(FDSSWrite)\r
+{\r
+ if(FSettings.SndRate)\r
+ {\r
+#if 0\r
+  if(FSettings.soundq>=1)\r
+   RenderSoundHQ();\r
+  else\r
+#endif\r
+   RenderSound();\r
+ }\r
+ A-=0x4080;\r
+ switch(A)\r
+ {\r
+  case 0x0:\r
+  case 0x4: if(V&0x80)\r
+            amplitude[(A&0xF)>>2]=V&0x3F; //)>0x20?0x20:(V&0x3F);\r
+           break;\r
+  case 0x5://printf("$%04x:$%02x\n",A,V);\r
+               break;\r
+  case 0x7: b17latch76=0;SPSG[0x5]=0;//printf("$%04x:$%02x\n",A,V);\r
+               break;\r
+  case 0x8:\r
+          b17latch76=0;\r
+       //   printf("%d:$%02x, $%02x\n",SPSG[0x5],V,b17latch76);\r
+          fdso.mwave[SPSG[0x5]&0x1F]=V&0x7;\r
+           SPSG[0x5]=(SPSG[0x5]+1)&0x1F;\r
+          break;\r
+ }\r
+ //if(A>=0x7 && A!=0x8 && A<=0xF)\r
+ //if(A==0xA || A==0x9)\r
+ //printf("$%04x:$%02x\n",A,V);\r
+ SPSG[A]=V;\r
+}\r
+\r
+// $4080 - Fundamental wave amplitude data register 92\r
+// $4082 - Fundamental wave frequency data register 58\r
+// $4083 - Same as $4082($4083 is the upper 4 bits).\r
+\r
+// $4084 - Modulation amplitude data register 78\r
+// $4086 - Modulation frequency data register 72\r
+// $4087 - Same as $4086($4087 is the upper 4 bits)\r
+\r
+\r
+static void DoEnv()\r
+{\r
+ int x;\r
+\r
+ for(x=0;x<2;x++)\r
+  if(!(SPSG[x<<2]&0x80) && !(SPSG[0x3]&0x40))\r
+  {\r
+   static int counto[2]={0,0};\r
+\r
+   if(counto[x]<=0)\r
+   {\r
+    if(!(SPSG[x<<2]&0x80))\r
+    {\r
+     if(SPSG[x<<2]&0x40)\r
+     {\r
+      if(amplitude[x]<0x3F)\r
+       amplitude[x]++;\r
+     }\r
+     else\r
+     {\r
+      if(amplitude[x]>0)\r
+       amplitude[x]--;\r
+     }\r
+    }\r
+    counto[x]=(SPSG[x<<2]&0x3F);\r
+   }\r
+   else\r
+    counto[x]--;\r
+  }\r
+}\r
+\r
+static DECLFR(FDSWaveRead)\r
+{\r
+ return(fdso.cwave[A&0x3f]|(X.DB&0xC0));\r
+}\r
+\r
+static DECLFW(FDSWaveWrite)\r
+{\r
+ //printf("$%04x:$%02x, %d\n",A,V,SPSG[0x9]&0x80);\r
+ if(SPSG[0x9]&0x80)\r
+  fdso.cwave[A&0x3f]=V&0x3F;\r
+}\r
+\r
+static int ta;\r
+static INLINE void ClockRise(void)\r
+{\r
+ if(!clockcount)\r
+ {\r
+  ta++;\r
+\r
+  b19shiftreg60=(SPSG[0x2]|((SPSG[0x3]&0xF)<<8));\r
+  b17latch76=(SPSG[0x6]|((SPSG[0x07]&0xF)<<8))+b17latch76;\r
+\r
+  if(!(SPSG[0x7]&0x80))\r
+  {\r
+   int t=fdso.mwave[(b17latch76>>13)&0x1F]&7;\r
+   int t2=amplitude[1];\r
+   int adj = 0;\r
+\r
+   if((t&3))\r
+   {\r
+    if((t&4))\r
+     adj -= (t2 * ((4 - (t&3) ) ));\r
+    else\r
+     adj += (t2 * ( (t&3) ));\r
+   }\r
+   adj *= 2;\r
+   if(adj > 0x7F) adj = 0x7F;\r
+   if(adj < -0x80) adj = -0x80;\r
+   //if(adj) printf("%d ",adj);\r
+   b8shiftreg88=0x80 + adj;\r
+  }\r
+  else\r
+  {\r
+   b8shiftreg88=0x80;\r
+  }\r
+ }\r
+ else\r
+ {\r
+  b19shiftreg60<<=1;\r
+  b8shiftreg88>>=1;\r
+ }\r
+// b24adder66=(b24latch68+b19shiftreg60)&0x3FFFFFF;\r
+ b24adder66=(b24latch68+b19shiftreg60)&0x1FFFFFF;\r
+}\r
+\r
+static INLINE void ClockFall(void)\r
+{\r
+ //if(!(SPSG[0x7]&0x80))\r
+ {\r
+  if((b8shiftreg88&1)) // || clockcount==7)\r
+   b24latch68=b24adder66;\r
+ }\r
+ clockcount=(clockcount+1)&7;\r
+}\r
+\r
+static INLINE int32 FDSDoSound(void)\r
+{\r
+ fdso.count+=fdso.cycles;\r
+ if(fdso.count>=((int64)1<<40))\r
+ {\r
+  dogk:\r
+  fdso.count-=(int64)1<<40;\r
+  ClockRise();\r
+  ClockFall();\r
+  fdso.envcount--;\r
+  if(fdso.envcount<=0)\r
+  {\r
+   fdso.envcount+=SPSG[0xA]*3;\r
+   DoEnv();\r
+  }\r
+ }\r
+ if(fdso.count>=32768) goto dogk;\r
+\r
+ // Might need to emulate applying the amplitude to the waveform a bit better...\r
+ {\r
+  int k=amplitude[0];\r
+  if(k>0x20) k=0x20;\r
+  return (fdso.cwave[b24latch68>>19]*k)*4/((SPSG[0x9]&0x3)+2);\r
+ }\r
+}\r
+\r
+static int32 FBC=0;\r
+\r
+static void RenderSound(void)\r
+{\r
+ int32 end, start;\r
+ int32 x;\r
+\r
+ start=FBC;\r
+ end=(SOUNDTS<<16)/soundtsinc;\r
+ if(end<=start)\r
+  return;\r
+ FBC=end;\r
+\r
+ if(!(SPSG[0x9]&0x80))\r
+  for(x=start;x<end;x++)\r
+  {\r
+   uint32 t=FDSDoSound();\r
+   t+=t>>1;\r
+   t>>=4;\r
+   Wave[x>>4]+=t; //(t>>2)-(t>>3); //>>3;\r
+  }\r
+}\r
+\r
+#if 0\r
+static void RenderSoundHQ(void)\r
+{\r
+ int32 x;\r
+\r
+ if(!(SPSG[0x9]&0x80))\r
+  for(x=FBC;x<SOUNDTS;x++)\r
+  {\r
+   uint32 t=FDSDoSound();\r
+   t+=t>>1;\r
+   WaveHi[x]+=t; //(t<<2)-(t<<1);\r
+  }\r
+ FBC=SOUNDTS;\r
+}\r
+#endif\r
+\r
+static void HQSync(int32 ts)\r
+{\r
+ FBC=ts;\r
+}\r
+\r
+void FDSSound(int c)\r
+{\r
+  RenderSound();\r
+  FBC=c;\r
+}\r
+\r
+/*\r
+static DECLFR(FDSBIOSPatch)\r
+{\r
+ if(FDSRegs[5]&0x4)\r
+ {\r
+  X.X=FDSRead4031(0x4031);\r
+  FDSWrite(0x4024,X.A);\r
+  X.A=X.X;\r
+  return(0x60);\r
+ }\r
+ else\r
+ {\r
+  return(0x58);\r
+  //puts("Write");\r
+ }\r
+}\r
+*/\r
+\r
+static void FDS_ESI(void)\r
+{\r
+ if(FSettings.SndRate)\r
+ {\r
+#if 0\r
+  if(FSettings.soundq>=1)\r
+  {\r
+   fdso.cycles=(int64)1<<39;\r
+  }\r
+  else\r
+#endif\r
+  {\r
+   fdso.cycles=((int64)1<<40)*FDSClock;\r
+   fdso.cycles/=FSettings.SndRate *16;\r
+  }\r
+ }\r
+//  fdso.cycles=(int64)32768*FDSClock/(FSettings.SndRate *16);\r
+ SetReadHandler(0x4040,0x407f,FDSWaveRead);\r
+ SetWriteHandler(0x4040,0x407f,FDSWaveWrite);\r
+ SetWriteHandler(0x4080,0x408A,FDSSWrite);\r
+ SetReadHandler(0x4090,0x4092,FDSSRead);\r
+\r
+ //SetReadHandler(0xE7A3,0xE7A3,FDSBIOSPatch);\r
+}\r
+\r
+void FDSSoundReset(void)\r
+{\r
+ memset(&fdso,0,sizeof(fdso));\r
+ FDS_ESI();\r
+ GameExpSound.HiSync=HQSync;\r
+ GameExpSound.HiFill=0;//RenderSoundHQ;\r
+ GameExpSound.Fill=FDSSound;\r
+ GameExpSound.RChange=FDS_ESI;\r
+}\r
+\r
+static DECLFW(FDSWrite)\r
+{\r
+ //extern int scanline;\r
+ //FCEU_printf("$%04x:$%02x, %d\n",A,V,scanline);\r
+ switch(A)\r
+ {\r
+  case 0x4020:\r
+       X6502_IRQEnd(FCEU_IQEXT);\r
+       IRQLatch&=0xFF00;\r
+       IRQLatch|=V;\r
+//  printf("$%04x:$%02x\n",A,V);\r
+        break;\r
+  case 0x4021:\r
+        X6502_IRQEnd(FCEU_IQEXT);\r
+       IRQLatch&=0xFF;\r
+       IRQLatch|=V<<8;\r
+//  printf("$%04x:$%02x\n",A,V);\r
+        break;\r
+  case 0x4022:\r
+       X6502_IRQEnd(FCEU_IQEXT);\r
+       IRQCount=IRQLatch;\r
+       IRQa=V&3;\r
+//  printf("$%04x:$%02x\n",A,V);\r
+        break;\r
+  case 0x4023:break;\r
+  case 0x4024:\r
+        if(InDisk!=255 && !(FDSRegs[5]&0x4) && (FDSRegs[3]&0x1))\r
+        {\r
+         if(DiskPtr>=0 && DiskPtr<65500)\r
+         {\r
+          if(writeskip) writeskip--;\r
+          else if(DiskPtr>=2)\r
+          {\r
+          DiskWritten=1;\r
+           diskdata[InDisk][DiskPtr-2]=V;\r
+          }\r
+         }\r
+        }\r
+        break;\r
+  case 0x4025:\r
+       X6502_IRQEnd(FCEU_IQEXT2);\r
+       if(InDisk!=255)\r
+       {\r
+         if(!(V&0x40))\r
+         {\r
+          if(FDSRegs[5]&0x40 && !(V&0x10))\r
+          {\r
+           DiskSeekIRQ=200;\r
+           DiskPtr-=2;\r
+          }\r
+          if(DiskPtr<0) DiskPtr=0;\r
+         }\r
+         if(!(V&0x4)) writeskip=2;\r
+         if(V&2) {DiskPtr=0;DiskSeekIRQ=200;}\r
+         if(V&0x40) DiskSeekIRQ=200;\r
+       }\r
+        setmirror(((V>>3)&1)^1);\r
+        break;\r
+ }\r
+ FDSRegs[A&7]=V;\r
+}\r
+\r
+static void FreeFDSMemory(void)\r
+{\r
+ int x;\r
+\r
+ for(x=0;x<TotalSides;x++)\r
+  if(diskdata[x])\r
+  {\r
+   free(diskdata[x]);\r
+   diskdata[x]=0;\r
+  }\r
+}\r
+\r
+static int SubLoad(int fp)\r
+{\r
+ struct md5_context md5;\r
+ uint8 header[16];\r
+ int x;\r
+\r
+ FCEU_fread(header,16,1,fp);\r
+\r
+ if(memcmp(header,"FDS\x1a",4))\r
+ {\r
+  if(!(memcmp(header+1,"*NINTENDO-HVC*",14)))\r
+  {\r
+   long t;\r
+   t=FCEU_fgetsize(fp);\r
+   if(t<65500)\r
+    t=65500;\r
+   TotalSides=t/65500;\r
+   FCEU_fseek(fp,0,SEEK_SET);\r
+  }\r
+  else\r
+   return(0);\r
+ }\r
+ else\r
+  TotalSides=header[4];\r
+\r
+ md5_starts(&md5);\r
+\r
+ if(TotalSides>8) TotalSides=8;\r
+ if(TotalSides<1) TotalSides=1;\r
+\r
+ for(x=0;x<TotalSides;x++)\r
+ {\r
+  diskdata[x]=(uint8 *)FCEU_malloc(65500);\r
+  if(!diskdata[x])\r
+  {\r
+   int zol;\r
+   for(zol=0;zol<x;zol++)\r
+    free(diskdata[zol]);\r
+   return 0;\r
+  }\r
+  FCEU_fread(diskdata[x],1,65500,fp);\r
+  md5_update(&md5,diskdata[x],65500);\r
+ }\r
+ md5_finish(&md5,FCEUGameInfo.MD5);\r
+ return(1);\r
+}\r
+\r
+static void PreSave(void)\r
+{\r
+ int x;\r
+\r
+ //if(DiskWritten)\r
+  for(x=0;x<TotalSides;x++)\r
+  {\r
+   int b;\r
+   for(b=0; b<65500; b++)\r
+    diskdata[x][b] ^= diskdatao[x][b];\r
+  }\r
+}\r
+\r
+static void PostSave(void)\r
+{\r
+ int x;\r
+\r
+ //if(DiskWritten)\r
+  for(x=0;x<TotalSides;x++)\r
+  {\r
+   int b;\r
+\r
+   for(b=0; b<65500; b++)\r
+    diskdata[x][b] ^= diskdatao[x][b];\r
+  }\r
+\r
+}\r
+\r
+int FDSLoad(const char *name, int fp)\r
+{\r
+ FILE *zp;\r
+ int x;\r
+ char *fn;\r
+\r
+ FCEU_fseek(fp,0,SEEK_SET);\r
+\r
+ if(!SubLoad(fp))\r
+  return(0);\r
+\r
+\r
+ fn = FCEU_MakeFName(FCEUMKF_FDSROM,0,0);\r
+\r
+ if(!(zp=FCEUD_UTF8fopen(fn,"rb")))\r
+ {\r
+  FCEU_PrintError("FDS BIOS ROM image missing!");\r
+  FreeFDSMemory();\r
+  free(fn);\r
+  return 0;\r
+ }\r
+\r
+ free(fn);\r
+\r
+ if(fread(FDSBIOS,1,8192,zp)!=8192)\r
+ {\r
+  fclose(zp);\r
+  FreeFDSMemory();\r
+  FCEU_PrintError("Error reading FDS BIOS ROM image.");\r
+  return 0;\r
+ }\r
+\r
+ fclose(zp);\r
+\r
+\r
+ {\r
+  int tp;\r
+  char *fn=FCEU_MakeFName(FCEUMKF_FDS,0,0);\r
+\r
+  int x;\r
+  for(x=0;x<TotalSides;x++)\r
+  {\r
+   diskdatao[x]=(uint8 *)FCEU_malloc(65500);\r
+   memcpy(diskdatao[x],diskdata[x],65500);\r
+  }\r
+\r
+  if((tp=FCEU_fopen(fn,"rb")))\r
+  {\r
+   FreeFDSMemory();\r
+   if(!SubLoad(tp))\r
+   {\r
+    FCEU_PrintError("Error reading auxillary FDS file.");\r
+    free(fn);\r
+    return(0);\r
+   }\r
+   FCEU_fclose(tp);\r
+   DiskWritten=1;  /* For save state handling. */\r
+  }\r
+  free(fn);\r
+ }\r
+\r
+ FCEUGameInfo.type=GIT_FDS;\r
+ GameInterface=FDSGI;\r
+\r
+ SelectDisk=0;\r
+ InDisk=255;\r
+\r
+ ResetExState(PreSave,PostSave);\r
+ FDSSoundStateAdd();\r
+\r
+ for(x=0;x<TotalSides;x++)\r
+ {\r
+  char temp[5];\r
+  sprintf(temp,"DDT%d",x);\r
+  AddExState(diskdata[x],65500,0,temp);\r
+ }\r
+\r
+ AddExState(FDSRAM,32768,0,"FDSR");\r
+ AddExState(FDSRegs,sizeof(FDSRegs),0,"FREG");\r
+ AddExState(CHRRAM,8192,0,"CHRR");\r
+ AddExState(&IRQCount, 4, 1, "IRQC");\r
+ AddExState(&IRQLatch, 4, 1, "IQL1");\r
+ AddExState(&IRQa, 1, 0, "IRQA");\r
+ AddExState(&writeskip,1,0,"WSKI");\r
+ AddExState(&DiskPtr,4,1,"DPTR");\r
+ AddExState(&DiskSeekIRQ,4,1,"DSIR");\r
+ AddExState(&SelectDisk,1,0,"SELD");\r
+ AddExState(&InDisk,1,0,"INDI");\r
+ AddExState(&DiskWritten,1,0,"DSKW");\r
+\r
+ ResetCartMapping();\r
+ SetupCartCHRMapping(0,CHRRAM,8192,1);\r
+ SetupCartMirroring(0,0,0);\r
+ memset(CHRRAM,0,8192);\r
+ memset(FDSRAM,0,32768);\r
+\r
+ FCEU_printf(" Sides: %d\n\n",TotalSides);\r
+\r
+ FCEUI_SetVidSystem(0);\r
+\r
+ return 1;\r
+}\r
+\r
+void FDSClose(void)\r
+{\r
+ FILE *fp;\r
+ int x;\r
+ char *fn=FCEU_MakeFName(FCEUMKF_FDS,0,0);\r
+\r
+ if(!DiskWritten) return;\r
+\r
+ if(!(fp=FCEUD_UTF8fopen(fn,"wb")))\r
+ {\r
+  free(fn);\r
+  return;\r
+ }\r
+ free(fn);\r
+\r
+ for(x=0;x<TotalSides;x++)\r
+ {\r
+  if(fwrite(diskdata[x],1,65500,fp)!=65500)\r
+  {\r
+   FCEU_PrintError("Error saving FDS image!");\r
+   fclose(fp);\r
+   return;\r
+  }\r
+ }\r
+ FreeFDSMemory();\r
+ fclose(fp);\r
+}\r
diff --git a/fds.h b/fds.h
index 9e526db..4269d70 100644 (file)
--- a/fds.h
+++ b/fds.h
@@ -1,8 +1,5 @@
-void FDSControl(int what);
-
-#define FDS_IDISK  1
-#define FDS_EJECT  2
-#define FDS_SELECT 3
-
-int FDSLoad(char *name, int fp);
-void FDSSoundReset(void);
+void FDSSoundReset(void);\r
+\r
+void FCEU_FDSInsert(void);\r
+//void FCEU_FDSEject(void);\r
+void FCEU_FDSSelect(void);\r
diff --git a/file.h b/file.h
index 3c70f97..fcce1ab 100644 (file)
--- a/file.h
+++ b/file.h
@@ -10,3 +10,5 @@ int FASTAPASS(1) FCEU_fgetc(int stream);
 long FASTAPASS(1) FCEU_fgetsize(int stream);
 int FASTAPASS(1) FCEU_fisarchive(int stream);
 
+#define FCEUD_UTF8fopen fopen
+
index 4b0c0cf..f01bae6 100644 (file)
--- a/general.c
+++ b/general.c
@@ -83,6 +83,11 @@ char *FCEU_MakeFName(int type, int id1, char *cd1)
                       sprintf(((char*)ret),"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1);
                    }
                     break;
+  case FCEUMKF_FDS:if(odirs[FCEUIOD_NV])
+                   sprintf((char*)ret,"%s"PSS"%s.fds",odirs[FCEUIOD_NV],FileBase);
+                  else
+                   sprintf((char*)ret,"%s"PSS"sav"PSS"%s.fds",BaseDirectory,FileBase);
+                  break;
   case FCEUMKF_SAV:if(odirs[FCEUIOD_NV])
                    {
                     sprintf(((char*)ret),"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
index 2a874ff..14ca5f0 100644 (file)
--- a/general.h
+++ b/general.h
@@ -12,3 +12,5 @@ char *FCEU_MakeFName(int type, int id1, char *cd1);
 #define FCEUMKF_FDSROM 5
 #define FCEUMKF_PALETTE        6
 #define FCEUMKF_GGROM  7
+#define FCEUMKF_IPS    8
+#define FCEUMKF_FDS    9
diff --git a/git.h b/git.h
index 5dbc2b7..bbe6405 100644 (file)
--- a/git.h
+++ b/git.h
@@ -1,22 +1,29 @@
-#ifndef __FCEU_GIT
-#define __FCEU_GIT
-/* Mmm...git. Almost as funny as "gimp". */
-#define GIT_CART        0      /* Cart. */
-#define GIT_VSUNI       1      /* VS Unisystem. */
-#define GIT_FDS         2      /* Famicom Disk System. */
-#define GIT_NSF         3      /* NES Sound Format. */
-
-#define GIV_NTSC       0       /* NTSC emulation. */
-#define GIV_PAL                1       /* PAL emulation. */
-#define GIV_USER       2       /* What was set by FCEUI_SetVidSys(). */
-       
-typedef struct {
-       char *name;
-        int type;       /* GIT_* */
-        int vidsys;     /* Current emulated video system; GIV_* */
-        int input[2];   /* Desired input for emulated input ports 1 and 2; -1
-                           for unknown desired input. */
-       int inputfc;    /* Desired Famicom expansion port device. -1 for unknown
-                          desired input. */
-} FCEUGI;
-#endif
+#ifndef __FCEU_GIT\r
+#define __FCEU_GIT\r
+/* Mmm...git. Almost as funny as "gimp". */\r
+#define GIT_CART  0  /* Cart. */\r
+#define GIT_VSUNI       1  /* VS Unisystem. */\r
+#define GIT_FDS   2  /* Famicom Disk System. */\r
+#define GIT_NSF   3  /* NES Sound Format. */\r
+\r
+#define GIV_NTSC  0  /* NTSC emulation. */\r
+#define GIV_PAL    1  /* PAL emulation. */\r
+#define GIV_USER  2  /* What was set by FCEUI_SetVidSys(). */\r
+       \r
+typedef struct {\r
+  uint8 *name;  /* Game name, UTF8 encoding */\r
+\r
+        int type;       /* GIT_* */\r
+        int vidsys;     /* Current emulated video system; GIV_* */\r
+        int input[2];   /* Desired input for emulated input ports 1 and 2; -1\r
+                           for unknown desired input. */\r
+  int inputfc;  /* Desired Famicom expansion port device. -1 for unknown\r
+                          desired input. */\r
+  int cspecial;  /* Special cart expansion: DIP switches, barcode\r
+                          reader, etc.\r
+                       */\r
+       uint8 MD5[16];\r
+  int soundrate;  /* For Ogg Vorbis expansion sound wacky support.  0 for default. */\r
+  int soundchan;  /* Number of sound channels. */\r
+} FCEUGI;\r
+#endif\r
diff --git a/ines-bad.h b/ines-bad.h
new file mode 100644 (file)
index 0000000..20f0cf7
--- /dev/null
@@ -0,0 +1,38 @@
+{ 0xecf78d8a13a030a6LL, "Ai Sensei no Oshiete", INESB_HACKED },
+{ 0x10f90ba5bd55c22eLL, "Alien Syndrome", INESB_HACKED },
+{ 0x4712856d3e12f21fLL, "Akumajou Densetsu", INESB_HACKED },
+{ 0x0d69ab3ad28ad1c2LL, "Banana", INESB_INCOMPLETE },
+{ 0x85d2c348a161cdbfLL, "Bio Senshi Dan", INESB_HACKED },
+{ 0x18fdb7c16aa8cb5cLL, "Bucky O'Hare", INESB_CORRUPT },
+{ 0xe27c48302108d11bLL, "Chibi Maruko Chan", INESB_HACKED },
+{ 0x9d1f505c6ba507bfLL, "Contra", INESB_HACKED },
+{ 0x60936436d3ea0ab6LL, "Crisis Force", INESB_HACKED },
+{ 0xcf31097ddbb03c5dLL, "Crystalis (Prototype)", INESB_CORRUPT },
+{ 0x92080a8ce94200eaLL, "Digital Devil Story II", INESB_HACKED },
+{ 0x97f133d8bc1c28dbLL, "Dragon Ball", INESB_HACKED },
+{ 0x6c2a2f95c2fe4b6eLL, "Dragon Ball", INESB_HACKED },
+{ 0x767aaff62963c58fLL, "Dragon Ball", INESB_HACKED },
+{ 0x500b267abb323005LL, "Dragon Warrior 4", INESB_CORRUPT },
+{ 0x02bdcf375704784bLL, "Erika to Satoru no Yume Bouken", INESB_HACKED },
+{ 0xd4fea9d2633b9186LL, "Famista 91", INESB_HACKED },
+{ 0xfdf8c812839b61f0LL, "Famista 92", INESB_HACKED },
+{ 0xb5bb1d0fb47d0850LL, "Famista 93", INESB_HACKED },
+{ 0x30471e773f7cdc89LL, "Famista 94", INESB_HACKED },
+{ 0x76c5c44ffb4a0bd7LL, "Fantasy Zone", INESB_HACKED },
+{ 0x27da2b0c500dc346LL, "Fire Emblem", INESB_HACKED },
+{ 0xb470bfb90e2b1049LL, "Fire Emblem Gaiden", INESB_HACKED },
+{ 0x23214fe456fba2ceLL, "Ganbare Goemon 2", INESB_HACKED },
+{ 0xbf8b22524e8329d9LL, "Ganbare Goemon Gaiden", INESB_HACKED },
+{ 0xa97041c3da0134e3LL, "Gegege no Kitarou 2", INESB_INCOMPLETE },
+{ 0x805db49a86db5449LL, "Goonies", INESB_HACKED },
+{ 0xc5abdaa65ac49b6bLL, "Gradius 2", INESB_HACKED },
+{ 0x04afae4ad480c11cLL, "Gradius 2", INESB_HACKED },
+{ 0x9b4bad37b5498992LL, "Gradius 2", INESB_HACKED },
+{ 0xb068d4ac10ef848eLL, "Highway Star", INESB_HACKED },
+{ 0xbf5175271e5019c3LL, "Kaiketsu Yanchamaru 3", INESB_HACKED },
+{ 0xfb4b508a236bbba3LL, "Salamander", INESB_HACKED },
+{ 0x3716c4bebf885344LL, "Super Mario Bros.", INESB_HACKED },
+{ 0x1895afc6eef26c7dLL, "Super Mario Bros.", INESB_HACKED },
+{ 0x103fc85d978b861bLL, "Sweet Home", INESB_CORRUPT },
+{ 0xfffda4407d80885aLL, "Sweet Home", INESB_CORRUPT },
+{ 0, 0, 0 }
diff --git a/ines-correct.h b/ines-correct.h
new file mode 100644 (file)
index 0000000..666cf00
--- /dev/null
@@ -0,0 +1,194 @@
+    {0x9cbadc25,5,8},  /* JustBreed */
+
+{0x6e68e31a,16,8},     /* Dragon Ball 3*/
+{0x3f15d20d,153,8},    /* Famicom Jump 2 */
+    {0x983d8175,157,8},  /* Datach Battle Rush */
+    {0x894efdbc,157,8},  /* Datach Crayon Shin Chan */
+    {0x19e81461,157,8},  /* Datach DBZ */
+    {0xbe06853f,157,8},  /* Datach J-League */
+    {0x0be0a328,157,8},  /* Datach SD Gundam Wars */
+    {0x5b457641,157,8},  /* Datach Ultraman Club */
+    {0xf51a7f46,157,8},  /* Datach Yuu Yuu Hakusho */
+
+    {0xe62e3382,71,-1},  /* Mig-29 Soviet Fighter */
+    {0x21a653c7,4,-1},  /* Super Sky Kid */
+
+{0xdd4d9a62,209,-1},   /* Shin Samurai Spirits 2 */
+    {0x063b1151,209,-1},  /* Power Rangers 4 */
+    {0xdd8ced31,209,-1},  /* Power Rangers 3 */
+
+{0x60bfeb0c,90,-1},     /* MK 2*/
+    {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 */
+    {0x07eb2c12,208,-1},  /* Street Fighter IV */
+    {0x96ce586e,189,8},  /* Street Fighter 2 YOKO */
+    {0x7678f1d5,207,8},  /* Fudou Myouou Den */
+    {0x276237b3,206,0},  /* Karnov */
+    {0x4e1c1e3c,206,0},  /* Karnov */
+
+        /* Some entries to sort out the minor 33/48 mess. */
+{0xaebd6549,48,8},     /* Bakushou!! Jinsei Gekijou 3 */
+    {0x6cdc0cd9,48,8},  /* Bubble Bobble 2 */
+    //{0x10e24006,48,8},  /* Flintstones 2 - bad dump? */
+    {0x40c0ad47,48,8},  /* Flintstones 2 */
+    {0xa7b0536c,48,8},  /* Don Doko Don 2 */
+    {0x99c395f9,48,8},  /* Captain Saver */
+    {0x1500e835,48,8},  /* Jetsons (J) */
+
+  {0x637134e8,193,1},  /* Fighting Hero */
+  {0xcbf4366f,158,8},  /* Alien Syndrome (U.S. unlicensed) */
+  {0xb19a55dd,64,8},  /* Road Runner */
+  //{0x3eafd012,116,-1},  /* AV Girl Fighting */
+  {0x1d0f4d6b,2,1},  /* Black Bass thinging */
+  {0xf92be3ec,64,-1},  /* Rolling Thunder */
+  {0x345ee51a,245,-1},  /* DQ4c */
+  {0xf518dd58,7,8},  /* Captain Skyhawk */
+  {0x7ccb12a3,43,-1},  /* SMB2j */
+  {0x6f12afc5,235,-1},  /* Golden Game 150-in-1 */
+        {0xccc03440,156,-1},   
+  {0xc9ee15a7,3,-1},  /* 3 is probably best.  41 WILL NOT WORK. */
+
+    {0x3e1271d5,79,1},  /* Tiles of Fate */
+  {0x8eab381c,113,1},  /* Death Bots */
+
+  {0xd4a76b07,79,0},  /* F-15 City Wars*/
+        {0xa4fbb438,79,0},
+
+  {0x1eb4a920,79,1},  /* Double Strike */
+  {0x345d3a1a,11,1},  /* Castle of Deceit */
+  {0x62ef6c79,232,8},  /* Quattro Sports -Aladdin */
+  {0x5caa3e61,144,1},  /* Death Race */
+  {0xd2699893,88,0},  /*  Dragon Spirit */
+
+{0x2f27cdef,155,8},  /* Tatakae!! Rahmen Man */
+    {0xcfd4a281,155,8},  /* Money Game.  Yay for money! */
+    {0xd1691028,154,8},  /* Devil Man */
+
+  {0xc68363f6,180,0},  /* Crazy Climber */
+  {0xbe939fce,9,1},  /* Punchout*/
+  {0x5e66eaea,13,1},  /* Videomation */
+  {0xaf5d7aa2,-1,0},  /* Clu Clu Land */
+
+{0xc2730c30,34,0},  /* Deadly Towers */
+{0x932ff06e,34,1},  /* Classic Concentration */
+{0x4c7c1af3,34,1},  /* Caesar's Palace */
+        
+{0x15141401,4,8},       /* Asmik Kun Land */
+{0x59280bec,4,8},       /* Jackie Chan */
+{0x4cccd878,4,8},  /* Cat Ninden Teyandee */
+{0x9eefb4b4,4,8},  /* Pachi Slot Adventure 2 */
+{0x5337f73c,4,8},  /* Niji no Silk Road */
+{0x7474ac92,4,8},  /* Kabuki: Quantum Fighter */
+
+{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 */
+
+{0x84382231,9,0},  /* Punch Out (J) */
+
+{0xe28f2596,0,1},  /* Pac Land (J) */
+{0xfcdaca80,0,0},  /* Elevator Action */
+{0xe492d45a,0,0},  /* Zippy Race */
+{0x32fa246f,0,0},  /* Tag Team Pro Wrestling */
+{0xc05a365b,0,0},  /* Exed Exes (J) */
+{0xb3c30bea,0,0},  /* Xevious (J) */
+
+{0x804f898a,2,1},      /* Dragon Unit */
+{0xe1b260da,2,1},  /* Argos no Senshi */
+{0x6d65cac6,2,0},  /* Terra Cresta */
+{0x9ea1dc76,2,0},      /* Rainbow Islands */
+{0x28c11d24,2,1},  /* Sukeban Deka */
+{0x02863604,2,1},      /* Sukeban Deka */
+{0x2bb6a0f8,2,1},      /* Sherlock Holmes */
+{0x55773880,2,1},  /* Gilligan's Island */
+{0x419461d0,2,1},  /* Super Cars */
+{0x6e0eb43e,2,1},  /* Puss n Boots */
+{0x266ce198,2,1},  /* City Adventure Touch */
+
+//{0x48349b0b,1,8},      /* Dragon Quest 2 */
+{0xd09b74dc,1,8},  /* Great Tank (J) */
+{0xe8baa782,1,8},  /* Gun Hed (J) */
+{0x970bd9c2,1,8},      /* Hanjuku Hero */
+{0xcd7a2fd7,1,8},  /* Hanjuku Hero */
+{0x63469396,1,8},  /* Hokuto no Ken 4 */
+{0x291bcd7d,1,8},      /* Pachio Kun 2 */
+{0xf74dfc91,1,-1},      /* Win, Lose, or Draw */
+
+        {0x3f56a392,1,8},      /* Captain Ed (J) */
+        {0x078ced30,1,8},      /* Choujin - Ultra Baseball */
+   {0x391aa1b8,1,8},  /* Bloody Warriors (J) */
+   {0x61a852ea,1,8},  /* Battle Stadium - Senbatsu Pro Yakyuu */
+   {0xfe364be5,1,8},  /* Deep Dungeon 4 */
+   {0xd8ee7669,1,8},  /* Adventures of Rad Gravity */
+   {0xa5e8d2cd,1,8},  /* Breakthru */
+   {0xf6fa4453,1,8},  /* Bigfoot */
+   {0x37ba3261,1,8},  /* Back to the Future 2 and 3 */
+   {0x934db14a,1,-1},  /* All-Pro Basketball */
+   {0xe94d5181,1,8},  /* Mirai Senshi - Lios */
+   {0x7156cb4d,1,8},  /* Muppet Adventure Carnival thingy */
+   {0x5b6ca654,1,8},  /* Barbie rev X*/
+   {0x57c12280,1,8},  /* Demon Sword */
+   {0x70f67ab7,1,8},  /* Musashi no Bouken */
+   {0xa9a4ea4c,1,8},  /* Satomi Hakkenden */
+   {0xcc3544b0,1,8},  /* Triathron */
+
+   {0x1d41cc8c,3,1},  /* Gyruss */
+   {0xd8eff0df,3,1},  /* Gradius (J) */
+   {0xdbf90772,3,0},  /* Alpha Mission */
+   {0xd858033d,3,0},  /* Armored Scrum Object */
+   {0xcf322bb3,3,1},  /* John Elway's Quarterback */
+   {0x9bde3267,3,1},  /* Adventures of Dino Riki */
+   {0x02cc3973,3,1},  /* Ninja Kid */
+   {0xb5d28ea2,3,1},  /* Mystery Quest - mapper 3?*/
+   {0xbc065fc3,3,1},  /* Pipe Dream */
+
+   {0x5b837e8d,1,8},  /* Alien Syndrome */
+   {0x283ad224,32,8},  /* Ai Sensei no Oshiete */
+   {0x5555fca3,32,8},  /* "" ""    */
+        {0x243a8735,32,0x10|4}, /* Major League */
+
+{0x6bc65d7e,66,1},  /* Youkai Club*/
+{0xc2df0a00,66,1},  /* Bio Senshi Dan(hacked) */
+{0xbde3ae9b,66,1},  /* Doraemon */
+{0xd26efd78,66,1},  /* SMB Duck Hunt */
+{0x811f06d9,66,1},  /* Dragon Power */
+{0x3293afea,66,1},  /* Mississippi Satsujin Jiken */
+{0xe84274c5,66,1},  /* "" "" */
+{0x9552e8df,66,1},  /* Dragon Ball */
+
+        {0xba51ac6f,78,2},
+   {0x3d1c3137,78,8},  /* Uchuusen - Cosmo Carrier */
+
+   {0xbda8f8e4,152,8},  /* Gegege no Kitarou 2 */
+   {0x026c5fca,152,8},  /* Saint Seiya Ougon Densetsu */
+   {0x0f141525,152,8},  /* Arkanoid 2 (Japanese) */
+   {0xb1a94b82,152,8},  /* Pocket Zaurus */
+
+   {0xbba58be5,70,-1},  /* Family Trainer - Manhattan Police */
+   {0x370ceb65,70,-1},  /* Family Trainer - Meiro Dai Sakusen */
+   {0xdd8ed0f7,70,1},  /* Kamen Rider Club */
+
+   {0x90c773c1,118,-1},  /* Goal! 2 */
+   {0xb9b4d9e0,118,-1},  /* NES Play Action Football */
+   {0x78b657ac,118,-1},  /* Armadillo */
+   {0x37b62d04,118,-1},  /* Ys 3 */
+        {0x07d92c31,118,-1},   /* RPG Jinsei Game */
+   {0x2705eaeb,234,-1},  /* Maxi 15 */
+   {0x404b2e8b,4,2},  /* Rad Racer 2 */
+   {0x2cc381f6,191,-1},  /* Sugoro Quest - Dice no Senshitachi (As).nes */
+   {0x555a555e,191,-1},
+   {0xa912b064,51|0x800,8},  /* 11-in-1 Ball Games(has CHR ROM when it shouldn't) */
+   {0xc5e5c5b2,115,-1}, /* Bao Qing Tian (As).nes */
+
+        {0,-1,-1}
diff --git a/ines.c b/ines.c
index 3ffcfce..679fb92 100644 (file)
--- a/ines.c
+++ b/ines.c
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef GP2X
-#include <unistd.h>
-#endif
-
-#include "types.h"
-#include "x6502.h"
-#include "fce.h"
-#define INESPRIV
-#include "ines.h"
-#include "version.h"
-#include "svga.h"
-#include "general.h"
-#include "state.h"
-#include "file.h"
-#include "memory.h"
-#include "cart.h"
-#include "crc32.h"
-#include "cheat.h"
-
-static DECLFR(VSRead);
-
-static uint8 *trainerpoo=0;
-static uint8 *ROM=NULL;
-uint8 *VROM=NULL;
-
-
-static uint32 ROM_size;
-uint32 VROM_size;
-
-static void CheckVSUni(void);
-static int MMC_init(int type);
-void (*MapClose)(void);
-void (*MapperReset)(void);
-
-static int MapperNo;
-static int SaveGame=0;
-
-static iNES_HEADER head;
-
-/*  MapperReset() is called when the NES is reset(with the reset button).
-    Mapperxxx_init is called when the NES has been powered on.
-*/
-
-static void iNESGI(int h)
-{
- switch(h)
- {
-  case GI_RESETM2:
-               if(MapperReset)
-                MapperReset();
-               break;
-  case GI_POWER:
-               SetReadHandler(0x8000,0xFFFF,CartBR);
-                MMC_init(MapperNo);
-               break;
-  case GI_CLOSE:
-               {
-                FILE *sp;
-
-                if(ROM) {free(ROM);ROM=0;}
-                if(VROM) {free(VROM);VROM=0;}
-
-                if(SaveGame)
-                {
-                 char *soot;
-                 SaveGame=0;
-                 soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
-                 sp=fopen(soot,"wb");
-                 if (sp==NULL)
-                  FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot);
-                 else
-                 {
-                  void *ptr;
-                  uint32 amount;
-                  ptr=WRAM;
-                  amount=8192;
-
-                  if(MapperNo==1)
-                  {
-                    extern uint8 MMC1WRAMsize;
-                    if(MMC1WRAMsize==2) ptr=WRAM+8192;
-                  }
-                  else if(MapperNo==5)
-                  {
-                   extern uint8 MMC5WRAMsize;
-                   if(MMC5WRAMsize==4)
-                    amount=32768;
-                  }
-
-                  fwrite(ptr,1,amount,sp);
-                  fclose(sp);
-#ifdef GP2X
-                  sync();
-#endif
-                 }
-                }
-                if(MapClose) MapClose();
-                if(trainerpoo) {free(trainerpoo);trainerpoo=0;}
-               }
-               break;
-     }
-}
-
-uint32 iNESGameCRC32;
-
-struct CRCMATCH        {
-       uint32 crc;
-       char *name;
-};
-
-static void CheckBad(void)
-{
- int x;
- #define CRCNT 7
- struct CRCMATCH tab[CRCNT]={
-       {0x28d183ac,"Antarctic Adventure"},
-       {0x7095ac65,"Akumajo Densetsu"},
-       {0x1bd7ed5a,"Gradius 2"},
-       {0x81c3aa66,"Crisis Force"},
-       {0xfe3088df,"Fire Emblem Gaiden"},
-       {0xfa8339a5,"Bucky O'Hare"},
-       {0x3c539d78,"Ganbare Goemon 2"},
-       };
-  for(x=0;x<CRCNT;x++)
-   if(tab[x].crc == iNESGameCRC32)
-   {
-    FCEU_PrintError("The copy of the game you have loaded, %s, is a bad dump, has been hacked, or both.  It will not work correctly on FCE Ultra.  Use a good copy of the ROM image instead.",tab[x].name);
-    break;
-   }
-}
-
-struct INPSEL {
-       uint32 crc32;
-       int input1;
-       int input2;
-       int inputfc;
-};
-
-/* This is mostly for my personal use.  So HA. */
-static void SetInput(void)
-{
- static struct INPSEL moo[]=
-       {
-        {0xad9c63e2,SI_GAMEPAD,-1,SIFC_SHADOW},        /* Space Shadow */
-        {0x24598791,-1,SI_ZAPPER,0},   /* Duck Hunt */
-        {0xff24d794,-1,SI_ZAPPER,0},   /* Hogan's Alley */
-        {0xbeb8ab01,-1,SI_ZAPPER,0},   /* Gumshoe */
-        {0xde8fd935,-1,SI_ZAPPER,0},   /* To the Earth */
-        {0xedc3662b,-1,SI_ZAPPER,0},   /* Operation Wolf */
-        {0x23d17f5e,SI_GAMEPAD,SI_ZAPPER,0},   /* The Lone Ranger */
-        {0xb8b9aca3,-1,SI_ZAPPER,0},  /* Wild Gunman */
-        {0x5112dc21,-1,SI_ZAPPER,0},  /* Wild Gunman */
-        {0x4318a2f8,-1,SI_ZAPPER,0},  /* Barker Bill's Trick Shooting */
-        {0x5ee6008e,-1,SI_ZAPPER,0},  /* Mechanized Attack */
-        {0x3e58a87e,-1,SI_ZAPPER,0},  /* Freedom Force */
-        {0x851eb9be,SI_GAMEPAD,SI_ZAPPER,0},   /* Shooting Range */
-        {0x74bea652,SI_GAMEPAD,SI_ZAPPER,0},   /* Supergun 3-in-1 */
-        {0x32fb0583,-1,SI_ARKANOID,0}, /* Arkanoid(NES) */
-        {0xd89e5a67,-1,-1,SIFC_ARKANOID}, /* Arkanoid (J) */
-        {0x0f141525,-1,-1,SIFC_ARKANOID}, /* Arkanoid 2(J) */
-
-        {0xf7606810,-1,-1,SIFC_FKB},   /* Family BASIC 2.0A */
-        {0x895037bc,-1,-1,SIFC_FKB},   /* Family BASIC 2.1a */
-        {0xb2530afc,-1,-1,SIFC_FKB},   /* Family BASIC 3.0 */
-        {0,-1,-1,-1}
-       };
- int x=0;
-
- while(moo[x].input1>=0 || moo[x].input2>=0 || moo[x].inputfc>=0)
- {
-  if(moo[x].crc32==iNESGameCRC32)
-  {
-   FCEUGameInfo.input[0]=moo[x].input1;
-   FCEUGameInfo.input[1]=moo[x].input2;
-   FCEUGameInfo.inputfc=moo[x].inputfc;
-   break;
-  }
-  x++;
- }
-}
-
-struct CHINF {
-       uint32 crc32;
-       int32 mapper;
-       int32 mirror;
-};
-
-#define SAVCNT 14
-static void CheckHInfo(void)
-{
- /* ROM images that have the battery-backed bit set in the header that really
-    don't have battery-backed RAM is not that big of a problem, so I'll
-    treat this differently.
- */
-
- static uint32 savie[SAVCNT]=
-       {
-        0x7cab2e9b,0x3ee43cda,0xe1383deb,      /* Mouryou Senki Madara */
-        0x3b3f88f0,0x2545214c,                 /* Dragon Warrior PRG 0 and 1 */
-        0x8c5a784e,    /* DW 2 */
-        0xa86a5318,    /* DW 3 */
-        0x506e259d,    /* DW 4 */
-        0xcebd2a31,0xb8b88130, /* Final Fantasy */
-        0x466efdc2,    /* FF(J) */
-        0xc9556b36,    /* FF1+2*/
-        0xd29db3c7,    /* FF2 */
-        0x57e220d0,    /* FF3 */
-       };
-
- static struct CHINF moo[]=
-       {
-        {0xc68363f6,180,0},    /* Crazy Climber */
-        {0xbe939fce,9,1},      /* Punchout*/
-        {0x5e66eaea,13,1},     /* Videomation */
-        {0xaf5d7aa2,-1,0},     /* Clu Clu Land */
-
-        {0xc2730c30,34,0},     /* Deadly Towers */
-        {0x932ff06e,34,1},     /* Classic Concentration */
-        {0x4c7c1af3,34,1},     /* Caesar's Palace */
-        {0x9ea1dc76,2,0},      /* Rainbow Islands */
-
-        {0x9eefb4b4,4,8},      /* Pachi Slot Adventure 2 */
-        {0x5337f73c,4,8},      /* Niji no Silk Road */
-        {0x7474ac92,4,8},      /* Kabuki: Quantum Fighter */
-
-        {0x970bd9c2,1,8},      /* Hanjuku Hero */
-
-        {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 */
-
-        {0x84382231,9,0},      /* Punch Out (J) */
-
-        {0xfcdaca80,0,0},      /* Elevator Action */
-        {0xe492d45a,0,0},      /* Zippy Race */
-        {0x32fa246f,0,0},      /* Tag Team Pro Wrestling */
-        {0x6d65cac6,2,0},      /* Terra Cresta */
-        {0x28c11d24,2,1},      /* Sukeban Deka */
-         {0x02863604,2,1},      /* Sukeban Deka */
-         {0x2bb6a0f8,2,1},      /* Sherlock Holmes */
-        {0x55773880,2,1},      /* Gilligan's Island */
-        {0x419461d0,2,1},      /* Super Cars */
-        {0x6e0eb43e,2,1},      /* Puss n Boots */
-        {0xfc3e5c86,2,1},      /* Trojan */
-
-        {0x291bcd7d,1,8},      /* Pachio Kun 2 */
-        {0xf74dfc91,1,-1},     /* Win, Lose, or Draw */
-
-        {0x59280bec,4,8},      /* Jackie Chan */
-
-        {0xfe364be5,1,8},      /* Deep Dungeon 4 */
-        {0xd8ee7669,1,8},      /* Adventures of Rad Gravity */
-        {0xa5e8d2cd,1,8},      /* Breakthru */
-        {0xf6fa4453,1,8},      /* Bigfoot */
-        {0x37ba3261,1,8},      /* Back to the Future 2 and 3 */
-        {0x934db14a,1,-1},     /* All-Pro Basketball */
-        {0xe94d5181,1,8},      /* Mirai Senshi - Lios */
-        {0x7156cb4d,1,8},      /* Muppet Adventure Carnival thingy */
-        {0x5b6ca654,1,8},      /* Barbie rev X*/
-        {0x57c12280,1,8},      /* Demon Sword */
-
-        {0xcf322bb3,3,1},      /* John Elway's Quarterback */
-        {0x9bde3267,3,1},      /* Adventures of Dino Riki */
-        {0x02cc3973,3,8},      /* Ninja Kid */
-        {0xb5d28ea2,3,1},      /* Mystery Quest - mapper 3?*/
-        {0xbc065fc3,3,1},      /* Pipe Dream */
-
-        {0x5b837e8d,1,8},      /* Alien Syndrome */
-        {0x283ad224,32,8},     /* Ai Sensei no Oshiete */
-        {0x5555fca3,32,8},     /* "" ""                */
-        {0x243a8735,32,0x10|4}, /* Major League */
-
-        {0x6bc65d7e,66,1},     /* Youkai Club*/
-        {0xc2df0a00,66,1},     /* Bio Senshi Dan(hacked) */
-        {0xbde3ae9b,66,1},     /* Doraemon */
-        {0xd26efd78,66,1},     /* SMB Duck Hunt */
-        {0x811f06d9,66,1},     /* Dragon Power */
-
-        {0x3293afea,66,1},     /* Mississippi Satsujin Jiken */
-        {0xe84274c5,66,1},     /* "" "" */
-
-
-        {0x6e68e31a,16,8},     /* Dragon Ball 3*/
-
-        {0xba51ac6f,78,2},
-        {0x3d1c3137,78,8},
-
-        {0xbda8f8e4,152,8},    /* Gegege no Kitarou 2 */
-        {0x026c5fca,152,8},    /* Saint Seiya Ougon Densetsu */
-        {0x0f141525,152,8},    /* Arkanoid 2 (Japanese) */
-        {0xb1a94b82,152,8},    /* Pocket Zaurus */
-
-        {0x3f15d20d,153,8},    /* Famicom Jump 2 */
-
-        {0xbba58be5,70,-1},    /* Family Trainer - Manhattan Police */
-        {0x370ceb65,70,-1},    /* Family Trainer - Meiro Dai Sakusen */
-        {0xdd8ed0f7,70,1},     /* Kamen Rider Club */
-
-        {0x90c773c1,118,-1},   /* Goal! 2 */
-        {0xb9b4d9e0,118,-1},   /* NES Play Action Football */
-        {0x78b657ac,118,-1},   /* Armadillo */
-        {0x37b62d04,118,-1},   /* Ys 3 */
-        {0x07d92c31,118,-1},   /* RPG Jinsei Game */
-        {0x2705eaeb,234,-1},   /* Maxi 15 */
-        {0x404b2e8b,4,2},      /* Rad Racer 2 */
-
-        {0x1356f6a6,4,8},      /* "Cattou Ninden Teyandee" English tranlation.
-                                   Should I have even bothered to do this? */
-        {0x50fd4fd6,4,8},      /* "" "" */
-
-        {0xa912b064,51|0x800,8},       /* 11-in-1 Ball Games(has CHR ROM when it shouldn't) */
-        {0,-1,-1}
-       };
- int tofix=0;
- int x=0;
-
- do
- {
-  if(moo[x].crc32==iNESGameCRC32)
-  {
-   if(moo[x].mapper>=0)
-   {
-    if(moo[x].mapper&0x800 && VROM_size)
-    {
-     VROM_size=0;
-     free(VROM);
-     tofix|=8;
-    }
-    if(MapperNo!=(moo[x].mapper&0xFF))
-    {
-     tofix|=1;
-     MapperNo=moo[x].mapper&0xFF;
-    }
-   }
-   if(moo[x].mirror>=0)
-   {
-    if(moo[x].mirror==8)
-    {
-     if(Mirroring==2)  /* Anything but hard-wired(four screen). */
-     {
-      tofix|=2;
-      Mirroring=0;
-     }
-    }
-    else if(Mirroring!=moo[x].mirror)
-    {
-     if(Mirroring!=(moo[x].mirror&~4))
-      if((moo[x].mirror&~4)<=2)        /* Don't complain if one-screen mirroring
-                                  needs to be set(the iNES header can't
-                                  hold this information).
-                               */
-       tofix|=2;
-     Mirroring=moo[x].mirror;
-    }
-   }
-   break;
-  }
-  x++;
- } while(moo[x].mirror>=0 || moo[x].mapper>=0);
-
- for(x=0;x<SAVCNT;x++)
- {
-  if(savie[x]==iNESGameCRC32)
-  {
-   if(!(head.ROM_type&2))
-   {
-    tofix|=4;
-    head.ROM_type|=2;
-   }
-  }
- }
-
- /* Games that use these iNES mappers tend to have the four-screen bit set
-    when it should not be.
- */
- if((MapperNo==118 || MapperNo==24 || MapperNo==26) && (Mirroring==2))
- {
-  Mirroring=0;
-  tofix|=2;
- }
-
- if(tofix)
- {
-  char gigastr[768];
-  strcpy(gigastr,"The iNES header contains incorrect information.  For now, the information will be corrected in RAM.  ");
-  if(tofix&1)
-   sprintf(gigastr+strlen(gigastr),"The mapper number should be set to %d.  ",MapperNo);
-  if(tofix&2)
-  {
-   char *mstr[3]={"Horizontal","Vertical","Four-screen"};
-   sprintf(gigastr+strlen(gigastr),"Mirroring should be set to \"%s\".  ",mstr[Mirroring&3]);
-  }
-  if(tofix&4)
-   strcat(gigastr,"The battery-backed bit should be set.  ");
-  if(tofix&8)
-   strcat(gigastr,"This game should not have any CHR ROM.  ");
-  strcat(gigastr,"\n");
-  FCEUD_PrintError(gigastr);
- }
-}
-
-int iNESLoad(char *name, int fp)
-{
-        FILE *sp;
-
-       if(FCEU_fread(&head,1,16,fp)!=16)
-        return 0;
-
-        if(memcmp(&head,"NES\x1a",4))
-         return 0;
-
-        if(!memcmp((char *)(&head)+0x7,"DiskDude",8))
-        {
-         memset((char *)(&head)+0x7,0,0x9);
-        }
-
-        if(!memcmp((char *)(&head)+0x7,"demiforce",9))
-        {
-         memset((char *)(&head)+0x7,0,0x9);
-        }
-
-        if(!memcmp((char *)(&head)+0xA,"Ni03",4))
-        {
-         if(!memcmp((char *)(&head)+0x7,"Dis",3))
-          memset((char *)(&head)+0x7,0,0x9);
-         else
-          memset((char *)(&head)+0xA,0,0x6);
-        }
-
-        if(!head.ROM_size)
-         head.ROM_size++;
-
-        ROM_size = head.ROM_size;
-        VROM_size = head.VROM_size;
-       ROM_size=uppow2(ROM_size);
-
-        if(VROM_size)
-        VROM_size=uppow2(VROM_size);
-
-        MapperNo = (head.ROM_type>>4);
-        MapperNo|=(head.ROM_type2&0xF0);
-
-        Mirroring = (head.ROM_type&1);
-       if(head.ROM_type&8) Mirroring=2;
-
-        if(!(ROM=(uint8 *)FCEU_malloc(ROM_size<<14)))
-        return 0;
-
-        if (VROM_size)
-         if(!(VROM=(uint8 *)FCEU_malloc(VROM_size<<13)))
-        {
-         free(ROM);
-         return 0;
-        }
-
-        memset(ROM,0xFF,ROM_size<<14);
-        if(VROM_size) memset(VROM,0xFF,VROM_size<<13);
-        if(head.ROM_type&4)    /* Trainer */
-       {
-        if(!(trainerpoo=FCEU_malloc(512)))
-         return(0);
-        FCEU_fread(trainerpoo,512,1,fp);
-       }
-       ResetCartMapping();
-       SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0);
-        SetupCartPRGMapping(1,WRAM,8192,1);
-
-        FCEU_fread(ROM,0x4000,head.ROM_size,fp);
-
-       if(VROM_size)
-        FCEU_fread(VROM,0x2000,head.VROM_size,fp);
-
-        printf("File %s loaded.\n",name);
-
-       iNESGameCRC32=CalcCRC32(0,ROM,ROM_size<<14);
-       if(VROM_size)
-        iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13);
-        printf("\n PRG ROM:  %3d x 16k\n CHR ROM:  %3d x  8k\n ROM CRC32:  %08x\n Mapper:  %d\n Mirroring: %s\n",head.ROM_size,head.VROM_size,iNESGameCRC32,MapperNo,Mirroring==2?"None(Four-screen)":Mirroring?"Vertical":"Horizontal");
-        if(head.ROM_type&2) puts(" Battery-backed.");
-        if(head.ROM_type&4) puts(" Trained.");
-       puts("");
-
-       CheckBad();
-       SetInput();
-       CheckHInfo();
-       CheckVSUni();
-        //if(MapperNo!=4 && MapperNo!=118 && MapperNo!=119) exit(1); // Testing
-
-       /* Must remain here because above functions might change value of
-          VROM_size and free(VROM).
-       */
-       if(VROM_size)
-         SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0);
-
-        if(Mirroring==2)
-         SetupCartMirroring(4,1,ExtraNTARAM);
-        else if(Mirroring>=0x10)
-        SetupCartMirroring(2+(Mirroring&1),1,0);
-       else
-         SetupCartMirroring(Mirroring&1,(Mirroring&4)>>2,0);
-
-        if(MapperNo==5) DetectMMC5WRAMSize();
-       else if(MapperNo==1) DetectMMC1WRAMSize();
-
-        if(head.ROM_type&2)
-        {
-         char *soot;
-
-         SaveGame=1;
-         soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
-         sp=fopen(soot,"rb");
-         if(sp!=NULL)
-         {
-         void *ptr;
-         uint32 amount;
-
-         ptr=WRAM;
-         amount=8192;
-         if(MapperNo==1)
-         {
-          extern uint8 MMC1WRAMsize;
-          if(MMC1WRAMsize==2) ptr=WRAM+8192;
-         }
-         else if(MapperNo==5)
-         {
-          extern uint8 MMC5WRAMsize;
-           if(MMC5WRAMsize==4)
-           amount=32768;
-         }
-          if(fread(ptr,1,amount,sp)==amount)
-           printf("  WRAM Save File \"%s\" loaded...\n",soot);
-          fclose(sp);
-         }
-
-   }
-       GameInterface=iNESGI;
-        return 1;
-}
-
-#include       "banksw.h"
-
-
-void FASTAPASS(1) onemir(uint8 V)
-{
-       if(Mirroring==2) return;
-        if(V>1)
-         V=1;
-       Mirroring=0x10|V;
-       setmirror(MI_0+V);
-}
-
-void FASTAPASS(1) MIRROR_SET2(uint8 V)
-{
-       if(Mirroring==2) return;
-       Mirroring=V;
-       setmirror(V);
-}
-
-void FASTAPASS(1) MIRROR_SET(uint8 V)
-{
-       if(Mirroring==2) return;
-       V^=1;
-       Mirroring=V;
-       setmirror(V);
-}
-
-static void NONE_init(void)
-{
-        ROM_BANK16(0x8000,0);
-        ROM_BANK16(0xC000,~0);
-
-        if(VROM_size)
-        VROM_BANK8(0);
-        else
-        setvram8(CHRRAM);
-}
-
-static uint8 secdata[2][32]=
-{
- {
-  0xff, 0xbf, 0xb7, 0x97, 0x97, 0x17, 0x57, 0x4f,
-  0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90, 0x94, 0x14,
-  0x56, 0x4e, 0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90,
-  0xd4, 0x5c, 0x3e, 0x26, 0x87, 0x83, 0x13, 0x00
- },
- {
-  0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,
-  0x00, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x94, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- }
-};
-
-static uint8 *secptr;
-
-static void CheckVSUni(void)
-{
-        FCEUGameInfo.type=GIT_VSUNI;
-
-       /* FCE Ultra doesn't complain when headers for these games are bad. */
-       secptr=0;
-       switch(iNESGameCRC32)
-       {
-        default:FCEUGameInfo.type=0;break;
-
-        case 0xffbef374: pale=1;break; /* Castlevania */
-
-        case 0x98e3c75a:
-        case 0x7cff0f84: pale=2;break; /* SMB */
-
-        case 0xef7af338: pale=2;break; /* Ice Climber */
-        case 0xabe1a0c2: FCEUGameInfo.input[0]=SI_ZAPPER;break; /*Duck hunt */
-        case 0x16aa4e2d: pale=7;FCEUGameInfo.input[0]=SI_ZAPPER;break; /* hoganal ^_^ */
-        case 0x2b85420e: pale=3;break; /* Dr Mario */
-
-        case 0xfb0ddde7: pale=2;break;
-        case 0xc95321a8: pale=6;break; /* Excitebike */
-        case 0xb1c4c508: pale=1;break; /* Golf */
-
-        case 0x66471efe: break;
-        case 0xca3e9b1a: pale=7;break; /* Pinball*/
-
-        case 0xf735d926: pale=7; break; /* Gradius */
-
-        case 0x2019fe65:
-        case 0x31678411:MapperNo=68;pale=7;break; /* Platoon */
-
-        case 0x74f713b4:pale=4;break; /* Goonies */
-        case 0x9ae2baa0:pale=5;break; /* Slalom */
-        case 0xe45485a5:secptr=secdata[1];vsdip=0x20;MapperNo=4;break; /* RBI Baseball */
-        case 0x21a653c7:vsdip=0x20;MapperNo=4;break; /* Super Sky Kid */
-         case 0xe9a6f17d:vsdip=0x20;break; /* Tetris */
-
-         case 0x159ef3c1:break; /* Star Luster */
-         case 0x9768e5e0:break; /* Stroke and Match Golf */
-
-        /* FCE Ultra doesn't have correct palettes for the following games. */
-        case 0x0fa322c2:pale=2;break; /* Clu Clu Land */
-
-        case 0x766c2cac:       /* Soccer */
-        case 0x01357944:       /* Battle City */
-        case 0xb2816bf9:break; /* Battle City (Bootleg) */
-
-        case 0x832cf592:FCEUGameInfo.input[0]=SI_ZAPPER;break; /* Freedom Force */
-        case 0x63abf889:break; /* Ladies Golf */
-        case 0x8c0c2df5:pale=2;MapperNo=1;Mirroring=1;break; /* Top Gun */
-        case 0x52c501d0:vsdip=0x80;MapperNo=4;secptr=secdata[0];break;
-                       /* TKO Boxing */
-       }
-
-       if(MapperNo==99)
-        Mirroring=2;
-}
-
-
-static int VSindex;
-
-static DECLFR(VSRead)
-{
- //printf("$%04x, $%04x\n",A,X.PC);
- switch(A)
- {
-  default:
-  case 0x5e00: VSindex=0;return 0xFF;
-  case 0x5e01: return(secptr[(VSindex++)&0x1F]);
- }
-}
-
-static void DoVSHooks(void)
-{
- if(secptr)
-  SetReadHandler(0x5e00,0x5e01,VSRead);
-}
-
-void (*MapInitTab[256])(void)=
-{
-       0,
-       Mapper1_init,Mapper2_init,Mapper3_init,Mapper4_init,
-       Mapper5_init,Mapper6_init,Mapper7_init,Mapper8_init,
-       Mapper9_init,Mapper10_init,Mapper11_init,0,
-       Mapper13_init,0,Mapper15_init,Mapper16_init,
-       Mapper17_init,Mapper18_init,Mapper19_init,0,
-       Mapper21_init,Mapper22_init,Mapper23_init,Mapper24_init,
-       Mapper25_init,Mapper26_init,0,0,
-       0,0,0,Mapper32_init,
-       Mapper33_init,Mapper34_init,0,0,
-       0,0,0,Mapper40_init,
-       Mapper41_init,Mapper42_init,Mapper43_init,Mapper44_init,
-       Mapper45_init,Mapper46_init,Mapper47_init,Mapper33_init,Mapper49_init,0,Mapper51_init,Mapper52_init,
-       0,0,0,0,0,0,0,0,
-       0,0,0,Mapper64_init,
-       Mapper65_init,Mapper66_init,Mapper67_init,Mapper68_init,
-       Mapper69_init,Mapper70_init,Mapper71_init,Mapper72_init,
-       Mapper73_init,0,Mapper75_init,Mapper76_init,
-       Mapper77_init,Mapper78_init,Mapper79_init,Mapper80_init,
-       0,Mapper82_init,Mapper83_init,0,
-       Mapper85_init,Mapper86_init,Mapper87_init,Mapper88_init,
-       Mapper89_init,Mapper90_init,0,Mapper92_init,
-       Mapper93_init,Mapper94_init,Mapper95_init,Mapper96_init,
-       Mapper97_init,0,Mapper99_init,0,
-       0,0,0,0,Mapper105_init,0,0,0,
-       0,0,0,Mapper112_init,Mapper113_init,0,0,0,
-       Mapper117_init,Mapper118_init,Mapper119_init,0,0,0,0,0,
-       0,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,Mapper140_init,
-       0,0,0,0,0,0,0,0,
-       0,0,Mapper151_init,Mapper152_init,Mapper153_init,0,0,0,
-       0,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,Mapper180_init,
-       0,Mapper182_init,0,Mapper184_init,Mapper185_init,0,0,0,
-       Mapper189_init,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,0,
-       0,0,0,0,0,0,0,0,
-       0,0,0,0,Mapper225_init,Mapper226_init,Mapper227_init,Mapper228_init,
-       Mapper229_init,0,0,Mapper232_init,0,Mapper234_init,Mapper43_init,0,
-       0,0,0,Mapper240_init,0,Mapper242_init,0,0,
-       Mapper245_init,Mapper246_init,0,Mapper248_init,Mapper249_init,Mapper250_init,0,0,0,0,0
-};
-
-static DECLFW(BWRAM)
-{
-                WRAM[A-0x6000]=V;
-}
-
-static DECLFR(AWRAM)
-{
-                return WRAM[A-0x6000];
-}
-
-void (*MapStateRestore)(int version);
-void iNESStateRestore(int version)
-{
- int x;
-
- if(!MapperNo) return;
-
- for(x=0;x<4;x++)
-  setprg8(0x8000+x*8192,PRGBankList[x]);
-
- if(VROM_size)
-  for(x=0;x<8;x++)
-    setchr1(0x400*x,CHRBankList[x]);
-
- switch(Mirroring)
- {
-   case 0:setmirror(MI_H);break;
-   case 1:setmirror(MI_V);break;
-   case 0x12:
-   case 0x10:setmirror(MI_0);break;
-   case 0x13:
-   case 0x11:setmirror(MI_1);break;
- }
- if(MapStateRestore) MapStateRestore(version);
-}
-
-static int MMC_init(int type)
-{
-        int x;
-
-        GameStateRestore=iNESStateRestore;
-        MapClose=0;
-       MapperReset=0;
-        MapStateRestore=0;
-
-        setprg8r(1,0x6000,0);
-
-        SetReadHandler(0x6000,0x7FFF,AWRAM);
-        SetWriteHandler(0x6000,0x7FFF,BWRAM);
-        FCEU_CheatAddRAM(8,0x6000,WRAM);
-
-       /* This statement represents atrocious code.  I need to rewrite
-          all of the iNES mapper code... */
-       IRQCount=IRQLatch=IRQa=0;
-        if(head.ROM_type&2)
-       {
-        extern uint8 MMC5WRAMsize,MMC1WRAMsize;
-        if(type==5 && MMC5WRAMsize==4)
-         memset(GameMemBlock+32768,0,sizeof(GameMemBlock)-32768);
-        else if(type==1 && MMC1WRAMsize==2)
-        {
-         memset(GameMemBlock,0,8192);
-         memset(GameMemBlock+16384,0,sizeof(GameMemBlock)-16384);
-        }
-        else
-          memset(GameMemBlock+8192,0,sizeof(GameMemBlock)-8192);
-       }
-       else
-         memset(GameMemBlock,0,sizeof(GameMemBlock));
-        if(head.ROM_type&4)
-        memcpy(WRAM+4096,trainerpoo,512);
-
-        NONE_init();
-
-       if(FCEUGameInfo.type==GIT_VSUNI)
-        DoVSHooks();
-        if(type==5)
-        {
-          MMC5HackVROMMask=CHRmask4[0];
-          MMC5HackExNTARAMPtr=MapperExRAM+0x6000;
-          MMC5Hack=1;
-          MMC5HackVROMPTR=VROM;
-          MMC5HackCHRMode=0;
-        }
-        ResetExState();
-        AddExState(WRAM, 8192, 0, "WRAM");
-        if(type==19 || type==5 || type==6 || type==69 || type==85)
-         AddExState(MapperExRAM, 32768, 0, "MEXR");
-        if((!VROM_size || type==6 || type==19 || type==119) &&
-          (type!=13 && type!=96))
-         AddExState(CHRRAM, 8192, 0, "CHRR");
-        if(head.ROM_type&8)
-         AddExState(ExtraNTARAM, 2048, 0, "EXNR");
-
-       /* Exclude some mappers whose emulation code handle save state stuff
-          themselves. */
-       if(type && type!=13 && type!=96)
-       {
-         AddExState(mapbyte1, 32, 0, "MPBY");
-         AddExState(&Mirroring, 1, 0, "MIRR");
-         AddExState(&IRQCount, 4, 1, "IRQC");
-         AddExState(&IRQLatch, 4, 1, "IQL1");
-         AddExState(&IRQa, 1, 0, "IRQA");
-         AddExState(PRGBankList, 4, 0, "PBL");
-         for(x=0;x<8;x++)
-         {
-          char tak[8];
-          sprintf(tak,"CBL%d",x);
-          AddExState(&CHRBankList[x], 2, 1,tak);
-         }
-       }
-
-        if(MapInitTab[type]) MapInitTab[type]();
-        else if(type)
-        {
-         FCEU_PrintError("iNES mapper #%d is not supported at all.",type);
-        }
-        return 1;
-}
+/* 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
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "types.h"\r
+#include "x6502.h"\r
+#include "fce.h"\r
+#include "cart.h"\r
+#include "ppu.h"\r
+\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 "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
+static uint8 *trainerpoo=0;\r
+static uint8 *ROM=NULL;\r
+//static\r
+uint8 *VROM=NULL;\r
+\r
+static CartInfo iNESCart;\r
+\r
+uint8 iNESMirroring=0;\r
+uint16 iNESCHRBankList[8]={0,0,0,0,0,0,0,0};\r
+int32 iNESIRQLatch=0,iNESIRQCount=0;\r
+uint8 iNESIRQa=0;\r
+\r
+uint32 ROM_size=0;\r
+uint32 VROM_size=0;\r
+\r
+static void iNESPower(void);\r
+static int NewiNES_Init(int num);\r
+\r
+void (*MapClose)(void);\r
+void (*MapperReset)(void);\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
+    Mapperxxx_init is called when the NES has been powered on.\r
+*/\r
+\r
+static DECLFR(TrainerRead)\r
+{\r
+ return(trainerpoo[A&0x1FF]);\r
+}\r
+\r
+static void iNESGI(int h)\r
+{\r
+ switch(h)\r
+ {\r
+  case GI_RESETM2:\r
+               if(MapperReset)\r
+                MapperReset();\r
+               if(iNESCart.Reset)\r
+                iNESCart.Reset();\r
+               break;\r
+  case GI_POWER:\r
+                if(iNESCart.Power)\r
+                 iNESCart.Power();\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
+               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
+               }\r
+               break;\r
+     }\r
+}\r
+\r
+uint32 iNESGameCRC32=0;\r
+\r
+struct CRCMATCH  {\r
+       uint32 crc;\r
+       char *name;\r
+};\r
+\r
+struct INPSEL {\r
+       uint32 crc32;\r
+       int input1;\r
+       int input2;\r
+       int inputfc;\r
+};\r
+\r
+/* This is mostly for my personal use.  So HA. */\r
+static void SetInput(void)\r
+{\r
+ static struct INPSEL moo[]=\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
+       };\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
+}\r
+\r
+#define INESB_INCOMPLETE  1\r
+#define INESB_CORRUPT     2\r
+#define INESB_HACKED      4\r
+\r
+struct BADINF {\r
+       uint64 md5partial;\r
+       char *name;\r
+       uint32 type;\r
+};\r
+\r
+\r
+static struct BADINF BadROMImages[]=\r
+{\r
+ #include "ines-bad.h"\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
+\r
+}\r
+\r
+\r
+struct CHINF {\r
+       uint32 crc32;\r
+       int32 mapper;\r
+       int32 mirror;\r
+};\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
+\r
+    Lower 64 bits of the MD5 hash.\r
+ */\r
+\r
+ static uint64 savie[]=\r
+       {\r
+   0x498c10dc463cfe95LL,  /* Battle Fleet */\r
+   0x6917ffcaca2d8466LL,  /* Famista '90 */\r
+\r
+         0xd63dcc68c2b20adcLL,    /* Final Fantasy J */\r
+         0x012df596e2b31174LL,    /* Final Fantasy 1+2 */\r
+         0xf6b359a720549ecdLL,    /* Final Fantasy 2 */\r
+         0x5a30da1d9b4af35dLL,    /* Final Fantasy 3 */\r
+\r
+   0x2ee3417ba8b69706LL,  /* Hydlide 3*/\r
+\r
+   0xebbce5a54cf3ecc0LL,  /* Justbreed */\r
+\r
+   0x6a858da551ba239eLL,  /* Kaijuu Monogatari */\r
+   0xa40666740b7d22feLL,  /* Mindseeker */\r
+\r
+         0x77b811b2760104b9LL,    /* Mouryou Senki Madara */\r
+\r
+   0x11b69122efe86e8cLL,  /* RPG Jinsei Game */\r
+\r
+   0xa70b495314f4d075LL,  /* Ys 3 */\r
+\r
+\r
+   0xc04361e499748382LL,  /* AD&D Heroes of the Lance */\r
+   0xb72ee2337ced5792LL,  /* AD&D Hillsfar */\r
+   0x2b7103b7a27bd72fLL,  /* AD&D Pool of Radiance */\r
+\r
+        0x854d7947a3177f57LL,    /* Crystalis */\r
+\r
+   0xb0bcc02c843c1b79LL,  /* DW */\r
+   0x4a1f5336b86851b6LL,  /* DW */\r
+\r
+   0x2dcf3a98c7937c22LL,  /* DW 2 */\r
+   0x733026b6b72f2470LL,  /* Dw 3 */\r
+   0x98e55e09dfcc7533LL,  /* DW 4*/\r
+   0x8da46db592a1fcf4LL,  /* Faria */\r
+   0x91a6846d3202e3d6LL,  /* Final Fantasy */\r
+   0xedba17a2c4608d20LL,  /* ""    */\r
+\r
+         0x94b9484862a26cbaLL,    /* Legend of Zelda */\r
+         0x04a31647de80fdabLL,    /*      ""      */\r
+\r
+         0x9aa1dc16c05e7de5LL,    /* Startropics */\r
+         0x1b084107d0878bd0LL,    /* Startropics 2*/\r
+\r
+         0x836c0ff4f3e06e45LL,    /* Zelda 2 */\r
+\r
+   0      /* Abandon all hope if the game has 0 in the lower 64-bits of its MD5 hash */\r
+       };\r
+\r
+ static struct CHINF moo[]=\r
+       {\r
+  #include "ines-correct.h"\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
+}\r
+\r
+typedef struct {\r
+       int mapper;\r
+       void (*init)(CartInfo *);\r
+} NewMI;\r
+\r
+int iNESLoad(const char *name, int fp)\r
+{\r
+        struct md5_context md5;\r
+\r
+       if(FCEU_fread(&head,1,16,fp)!=16)\r
+        return 0;\r
+\r
+        if(memcmp(&head,"NES\x1a",4))\r
+         return 0;\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
+\r
+        if(!memcmp((char *)(&head)+0x7,"demiforce",9))\r
+        {\r
+         memset((char *)(&head)+0x7,0,0x9);\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
+       {\r
+//   FCEU_PrintError("No PRG ROM!");\r
+//   return(0);\r
+   ROM_size=256;\r
+         //head.ROM_size++;\r
+       }\r
+  else\r
+   ROM_size=head.ROM_size;\r
+\r
+//    ROM_size = head.ROM_size;\r
+        VROM_size = head.VROM_size;\r
+       ROM_size=uppow2(ROM_size);\r
+\r
+        if(VROM_size)\r
+        VROM_size=uppow2(VROM_size);\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
+        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
+\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
+        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
+        SetupCartPRGMapping(1,WRAM,8192,1);\r
+\r
+        FCEU_fread(ROM,0x4000,head.ROM_size,fp);\r
+\r
+       if(VROM_size)\r
+        FCEU_fread(VROM,0x2000,head.VROM_size,fp);\r
+\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
+        iNESGameCRC32=CalcCRC32(iNESGameCRC32,VROM,VROM_size<<13);\r
+         md5_update(&md5,VROM,VROM_size<<13);\r
+       }\r
+       md5_finish(&md5,iNESCart.MD5);\r
+       memcpy(FCEUGameInfo.MD5,iNESCart.MD5,sizeof(iNESCart.MD5));\r
+\r
+       iNESCart.CRC32=iNESGameCRC32;\r
+\r
+        FCEU_printf(" PRG ROM:  %3d x 16KiB\n CHR ROM:  %3d x  8KiB\n ROM CRC32:  0x%08lx\n",\r
+               head.ROM_size,head.VROM_size,iNESGameCRC32);\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
+       SetInput();\r
+       CheckHInfo();\r
+       {\r
+        int x;\r
+        uint64 partialmd5=0;\r
+\r
+        for(x=0;x<8;x++)\r
+        {\r
+         partialmd5 |= (uint64)iNESCart.MD5[7-x] << (x*8);\r
+        }\r
+\r
+        FCEU_VSUniCheck(partialmd5, &MapperNo, &Mirroring);\r
+       }\r
+       /* Must remain here because above functions might change value of\r
+          VROM_size and free(VROM).\r
+       */\r
+       if(VROM_size)\r
+         SetupCartCHRMapping(0,VROM,VROM_size*0x2000,0);\r
+\r
+        if(Mirroring==2)\r
+         SetupCartMirroring(4,1,ExtraNTARAM);\r
+        else if(Mirroring>=0x10)\r
+        SetupCartMirroring(2+(Mirroring&1),1,0);\r
+       else\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
+  //  if(ROM) free(ROM);\r
+  //  if(VROM) free(VROM);\r
+  //  ROM=VROM=0;\r
+  //  return(0);\r
+       // }\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
+       FCEU_LoadGameSave(&iNESCart);\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
+       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
+void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V)\r
+{\r
+ V&=7;\r
+ PPUCHRRAM|=(1<<(A>>10));\r
+ CHRBankList[(A)>>10]=V;\r
+ VPage[(A)>>10]=&CHRRAM[V<<10]-(A);\r
+}\r
+\r
+void FASTAPASS(2) VRAM_BANK4(uint32 A, uint32 V)\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
+}\r
+void FASTAPASS(2) VROM_BANK1(uint32 A,uint32 V)\r
+{\r
+ setchr1(A,V);\r
+ CHRBankList[(A)>>10]=V;\r
+}\r
+\r
+void FASTAPASS(2) VROM_BANK2(uint32 A,uint32 V)\r
+{\r
+ setchr2(A,V);\r
+ CHRBankList[(A)>>10]=(V<<1);\r
+ CHRBankList[((A)>>10)+1]=(V<<1)+1;\r
+}\r
+\r
+void FASTAPASS(2) VROM_BANK4(uint32 A, uint32 V)\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
+}\r
+\r
+void FASTAPASS(1) VROM_BANK8(uint32 V)\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
+}\r
+\r
+void FASTAPASS(2) ROM_BANK8(uint32 A, uint32 V)\r
+{\r
+ setprg8(A,V);\r
+ if(A>=0x8000)\r
+  PRGBankList[((A-0x8000)>>13)]=V;\r
+}\r
+\r
+void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V)\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
+void FASTAPASS(1) ROM_BANK32(uint32 V)\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
+}\r
+\r
+void FASTAPASS(1) onemir(uint8 V)\r
+{\r
+       if(Mirroring==2) return;\r
+        if(V>1)\r
+         V=1;\r
+       Mirroring=0x10|V;\r
+       setmirror(MI_0+V);\r
+}\r
+\r
+void FASTAPASS(1) MIRROR_SET2(uint8 V)\r
+{\r
+       if(Mirroring==2) return;\r
+       Mirroring=V;\r
+       setmirror(V);\r
+}\r
+\r
+void FASTAPASS(1) MIRROR_SET(uint8 V)\r
+{\r
+       if(Mirroring==2) return;\r
+       V^=1;\r
+       Mirroring=V;\r
+       setmirror(V);\r
+}\r
+\r
+static void NONE_init(void)\r
+{\r
+        ROM_BANK16(0x8000,0);\r
+        ROM_BANK16(0xC000,~0);\r
+\r
+        if(VROM_size)\r
+        VROM_BANK8(0);\r
+        else\r
+        setvram8(CHRRAM);\r
+}\r
+\r
+void (*MapInitTab[256])(void)=\r
+{\r
+    0,0,\r
+//    Mapper2_init,Mapper3_init,\r
+    0,0,\r
+    0,0,\r
+    Mapper6_init,Mapper7_init,Mapper8_init,Mapper9_init,\r
+    Mapper10_init,Mapper11_init,\r
+    0,\r
+//    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
+    Mapper57_init,Mapper58_init,Mapper59_init,Mapper60_init,\r
+    Mapper61_init,Mapper62_init,\r
+    0,\r
+    Mapper64_init,Mapper65_init,Mapper66_init,Mapper67_init,\r
+    Mapper68_init,Mapper69_init,Mapper70_init,Mapper71_init,\r
+    Mapper72_init,Mapper73_init,\r
+    0,\r
+    Mapper75_init,Mapper76_init,Mapper77_init,Mapper78_init,\r
+    Mapper79_init,Mapper80_init,\r
+    0,\r
+    Mapper82_init,Mapper83_init,\r
+    0,\r
+       Mapper85_init,Mapper86_init,Mapper87_init,Mapper88_init,\r
+    Mapper89_init,\r
+    0,\r
+    Mapper91_init,Mapper92_init,Mapper93_init,Mapper94_init,\r
+    0,\r
+    Mapper96_init,Mapper97_init,\r
+    0,\r
+    Mapper99_init,\r
+    0,0,0,0,0,0,0,\r
+    Mapper107_init,\r
+    0,0,0,0,\r
+    0,Mapper113_init,\r
+    0,0,0,\r
+    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
+    Mapper140_init,\r
+    0,0,0,\r
+    Mapper144_init,\r
+    0,0,0,0,0,0,\r
+    Mapper151_init,Mapper152_init,Mapper153_init,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,Mapper185_init,\r
+    0,0,0,\r
+    Mapper189_init,\r
+    0,\r
+//    Mapper191_init,\r
+    0,\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
+    Mapper211_init,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,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
+};\r
+\r
+static DECLFW(BWRAM)\r
+{\r
+                WRAM[A-0x6000]=V;\r
+}\r
+\r
+static DECLFR(AWRAM)\r
+{\r
+                return WRAM[A-0x6000];\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
+ 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
+        int x;\r
+       int type=MapperNo;\r
+\r
+        SetReadHandler(0x8000,0xFFFF,CartBR);\r
+        GameStateRestore=iNESStateRestore;\r
+        MapClose=0;\r
+       MapperReset=0;\r
+        MapStateRestore=0;\r
+\r
+        setprg8r(1,0x6000,0);\r
+\r
+        SetReadHandler(0x6000,0x7FFF,AWRAM);\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
+\r
+       /* This statement represents atrocious code.  I need to rewrite\r
+          all of the iNES mapper code... */\r
+       IRQCount=IRQLatch=IRQa=0;\r
+        if(head.ROM_type&2)\r
+         memset(GameMemBlock+8192,0,sizeof(GameMemBlock)-8192);\r
+       else\r
+         memset(GameMemBlock,0,sizeof(GameMemBlock));\r
+\r
+        NONE_init();\r
+\r
+        ResetExState(0,0);\r
+       if(FCEUGameInfo.type == GIT_VSUNI)\r
+        AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0);\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
+\r
+       /* Exclude some mappers whose emulation code handle save state stuff\r
+          themselves. */\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
+       }\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
+typedef struct {\r
+           int number;\r
+           void (*init)(CartInfo *);\r
+} BMAPPING;\r
+\r
+static BMAPPING bmap[] = {\r
+    {1,   Mapper1_Init},\r
+    {2,   UNROM_Init},\r
+    {3,   CNROM_Init},\r
+    {4,   Mapper4_Init},\r
+    {5,   Mapper5_Init},\r
+    {12,  Mapper12_Init},\r
+    {13,  CPROM_Init},\r
+    {19,  Mapper19_Init},\r
+    {44,  Mapper44_Init},\r
+    {45,  Mapper45_Init},\r
+    {47,  Mapper47_Init},\r
+    {49,  Mapper49_Init},\r
+    {52,  Mapper52_Init},\r
+    {74,  Mapper74_Init},\r
+    {90,  Mapper90_Init},\r
+    {95,  Mapper95_Init},\r
+    {105, Mapper105_Init},\r
+    {112, Mapper112_Init},\r
+    {114, Mapper114_Init},\r
+        {115, Mapper115_Init},\r
+        {116, Mapper116_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
+    {141, S8259A_Init},\r
+    {143, TCA01_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
+       {155, Mapper155_Init},\r
+    {160, Mapper90_Init},\r
+    {163, Mapper163_Init},\r
+       {164, Mapper164_Init},\r
+    {165, Mapper165_Init},\r
+    {182, Mapper182_Init},\r
+    {183, Mapper183_Init},\r
+    {186, Mapper186_Init},\r
+        {187, Mapper187_Init},\r
+       {188, Mapper188_Init},\r
+    {191, Mapper191_Init},\r
+    {205, Mapper205_Init},\r
+    {206, DEIROM_Init},\r
+        {208, Mapper208_Init},\r
+    {209, Mapper209_Init},\r
+       {210, Mapper210_Init},\r
+    {215, Mapper215_Init},\r
+    {216, Mapper216_Init},\r
+    {217, Mapper217_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
+\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
+}\r
diff --git a/ines.h b/ines.h
index a27cf74..aaa44ca 100644 (file)
--- a/ines.h
+++ b/ines.h
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1998 Bero
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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
- */
-
-#ifdef INESPRIV
-
-void iNESStateRestore(int version);
-extern uint32 iNESGameCRC32;
-
-extern uint8 *VROM;
-extern uint32 VROM_size;
-
-extern void (*MapStateRestore)(int version);
-extern void (*MapClose)(void);
-extern void (*MapperReset)(void);
-
-/* This order is necessary */
-#define WRAM          (GameMemBlock)
-#define sizeofWRAM    8192
-
-#define MapperExRAM   (GameMemBlock+sizeofWRAM)
-#define sizeofMapperExRAM  32768
-/* for the MMC5 code to work properly.  It might be fixed later... */
-
-
-#define CHRRAM        (GameMemBlock+sizeofWRAM+sizeofMapperExRAM)
-#define sizeofCHRRAM 8192
-
-#define ExtraNTARAM   (GameMemBlock+sizeofWRAM+sizeofMapperExRAM+sizeofCHRRAM)
-#define sizeofExtraNTARAM 2048
-
-#define PRGBankList    (ExtraNTARAM+sizeofExtraNTARAM)
-
-#define mapbyte1       (PRGBankList+4)
-#define mapbyte2       (mapbyte1+8)
-#define mapbyte3       (mapbyte2+8)
-#define mapbyte4       (mapbyte3+8)
-uint16 iNESCHRBankList[8];
-int32 iNESIRQLatch,iNESIRQCount;
-uint8 iNESMirroring;
-uint8 iNESIRQa;
-
-#define IRQa iNESIRQa
-#define Mirroring iNESMirroring
-#define IRQCount iNESIRQCount
-#define IRQLatch iNESIRQLatch
-#define CHRBankList iNESCHRBankList
-#else
-int iNESLoad(char *name, int fp);
-#endif
-
-       typedef struct {
-               char ID[4]; /*NES^Z*/
-                uint8 ROM_size;
-                uint8 VROM_size;
-                uint8 ROM_type;
-                uint8 ROM_type2;
-                uint8 reserve[8];
-       } iNES_HEADER;
-
-void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V);
-void FASTAPASS(2) VRAM_BANK4(uint32 A,uint32 V);
-
-void FASTAPASS(2) VROM_BANK1(uint32 A,uint32 V);
-void FASTAPASS(2) VROM_BANK2(uint32 A,uint32 V);
-void FASTAPASS(2) VROM_BANK4(uint32 A, uint32 V);
-void FASTAPASS(1) VROM_BANK8(uint32 V);
-void FASTAPASS(2) ROM_BANK8(uint32 A, uint32 V);
-void FASTAPASS(2) ROM_BANK16(uint32 A, uint32 V);
-void FASTAPASS(2) ROM_BANK32(uint32 V);
-
-extern uint8 vmask;
-extern uint32 vmask1;
-extern uint32 vmask2;
-extern uint32 vmask4;
-extern uint32 pmask8;
-extern uint8 pmask16;
-extern uint8 pmask32;
-
-void FASTAPASS(1) onemir(uint8 V);
-void FASTAPASS(1) MIRROR_SET2(uint8 V);
-void FASTAPASS(1) MIRROR_SET(uint8 V);
-
-
-void DetectMMC1WRAMSize(void);
-void DetectMMC5WRAMSize(void);
-
-void Mapper0_init(void);
-void Mapper1_init(void);
-void Mapper2_init(void);
-void Mapper3_init(void);
-void Mapper4_init(void);
-void Mapper5_init(void);
-void Mapper6_init(void);
-void Mapper7_init(void);
-void Mapper8_init(void);
-void Mapper9_init(void);
-void Mapper10_init(void);
-void Mapper11_init(void);
-void Mapper12_init(void);
-void Mapper13_init(void);
-void Mapper14_init(void);
-void Mapper15_init(void);
-void Mapper16_init(void);
-void Mapper17_init(void);
-void Mapper18_init(void);
-void Mapper19_init(void);
-void Mapper20_init(void);
-void Mapper21_init(void);
-void Mapper22_init(void);
-void Mapper23_init(void);
-void Mapper24_init(void);
-void Mapper25_init(void);
-void Mapper26_init(void);
-void Mapper27_init(void);
-void Mapper28_init(void);
-void Mapper29_init(void);
-void Mapper30_init(void);
-void Mapper31_init(void);
-void Mapper32_init(void);
-void Mapper33_init(void);
-void Mapper34_init(void);
-void Mapper35_init(void);
-void Mapper36_init(void);
-void Mapper37_init(void);
-void Mapper38_init(void);
-void Mapper39_init(void);
-void Mapper40_init(void);
-void Mapper41_init(void);
-void Mapper42_init(void);
-void Mapper43_init(void);
-void Mapper44_init(void);
-void Mapper45_init(void);
-void Mapper46_init(void);
-void Mapper47_init(void);
-void Mapper48_init(void);
-void Mapper49_init(void);
-void Mapper50_init(void);
-void Mapper51_init(void);
-void Mapper52_init(void);
-void Mapper53_init(void);
-void Mapper54_init(void);
-void Mapper55_init(void);
-void Mapper56_init(void);
-void Mapper57_init(void);
-void Mapper58_init(void);
-void Mapper59_init(void);
-void Mapper60_init(void);
-void Mapper61_init(void);
-void Mapper62_init(void);
-void Mapper63_init(void);
-void Mapper64_init(void);
-void Mapper65_init(void);
-void Mapper66_init(void);
-void Mapper67_init(void);
-void Mapper68_init(void);
-void Mapper69_init(void);
-void Mapper70_init(void);
-void Mapper71_init(void);
-void Mapper72_init(void);
-void Mapper73_init(void);
-void Mapper74_init(void);
-void Mapper75_init(void);
-void Mapper76_init(void);
-void Mapper77_init(void);
-void Mapper78_init(void);
-void Mapper79_init(void);
-void Mapper80_init(void);
-void Mapper81_init(void);
-void Mapper82_init(void);
-void Mapper83_init(void);
-void Mapper84_init(void);
-void Mapper85_init(void);
-void Mapper86_init(void);
-void Mapper87_init(void);
-void Mapper88_init(void);
-void Mapper89_init(void);
-void Mapper90_init(void);
-void Mapper91_init(void);
-void Mapper92_init(void);
-void Mapper93_init(void);
-void Mapper94_init(void);
-void Mapper95_init(void);
-void Mapper96_init(void);
-void Mapper97_init(void);
-void Mapper98_init(void);
-void Mapper99_init(void);
-void Mapper100_init(void);
-void Mapper101_init(void);
-void Mapper102_init(void);
-void Mapper103_init(void);
-void Mapper104_init(void);
-void Mapper105_init(void);
-void Mapper106_init(void);
-void Mapper107_init(void);
-void Mapper108_init(void);
-void Mapper109_init(void);
-void Mapper110_init(void);
-void Mapper111_init(void);
-void Mapper112_init(void);
-void Mapper113_init(void);
-void Mapper114_init(void);
-void Mapper115_init(void);
-void Mapper116_init(void);
-void Mapper117_init(void);
-void Mapper118_init(void);
-void Mapper119_init(void);
-void Mapper120_init(void);
-void Mapper121_init(void);
-void Mapper122_init(void);
-void Mapper123_init(void);
-void Mapper124_init(void);
-void Mapper125_init(void);
-void Mapper126_init(void);
-void Mapper127_init(void);
-void Mapper128_init(void);
-void Mapper129_init(void);
-void Mapper130_init(void);
-void Mapper131_init(void);
-void Mapper132_init(void);
-void Mapper133_init(void);
-void Mapper134_init(void);
-void Mapper135_init(void);
-void Mapper136_init(void);
-void Mapper137_init(void);
-void Mapper138_init(void);
-void Mapper139_init(void);
-void Mapper140_init(void);
-void Mapper141_init(void);
-void Mapper142_init(void);
-void Mapper143_init(void);
-void Mapper144_init(void);
-void Mapper145_init(void);
-void Mapper146_init(void);
-void Mapper147_init(void);
-void Mapper148_init(void);
-void Mapper149_init(void);
-void Mapper150_init(void);
-void Mapper151_init(void);
-void Mapper152_init(void);
-void Mapper153_init(void);
-void Mapper154_init(void);
-void Mapper155_init(void);
-void Mapper156_init(void);
-void Mapper157_init(void);
-void Mapper158_init(void);
-void Mapper159_init(void);
-void Mapper160_init(void);
-void Mapper161_init(void);
-void Mapper162_init(void);
-void Mapper163_init(void);
-void Mapper164_init(void);
-void Mapper165_init(void);
-void Mapper166_init(void);
-void Mapper167_init(void);
-void Mapper168_init(void);
-void Mapper169_init(void);
-void Mapper170_init(void);
-void Mapper171_init(void);
-void Mapper172_init(void);
-void Mapper173_init(void);
-void Mapper174_init(void);
-void Mapper175_init(void);
-void Mapper176_init(void);
-void Mapper177_init(void);
-void Mapper178_init(void);
-void Mapper179_init(void);
-void Mapper180_init(void);
-void Mapper181_init(void);
-void Mapper182_init(void);
-void Mapper183_init(void);
-void Mapper184_init(void);
-void Mapper185_init(void);
-void Mapper186_init(void);
-void Mapper187_init(void);
-void Mapper188_init(void);
-void Mapper189_init(void);
-void Mapper190_init(void);
-void Mapper191_init(void);
-void Mapper192_init(void);
-void Mapper193_init(void);
-void Mapper194_init(void);
-void Mapper195_init(void);
-void Mapper196_init(void);
-void Mapper197_init(void);
-void Mapper198_init(void);
-void Mapper199_init(void);
-void Mapper200_init(void);
-void Mapper201_init(void);
-void Mapper202_init(void);
-void Mapper203_init(void);
-void Mapper204_init(void);
-void Mapper205_init(void);
-void Mapper206_init(void);
-void Mapper207_init(void);
-void Mapper208_init(void);
-void Mapper209_init(void);
-void Mapper210_init(void);
-void Mapper211_init(void);
-void Mapper212_init(void);
-void Mapper213_init(void);
-void Mapper214_init(void);
-void Mapper215_init(void);
-void Mapper216_init(void);
-void Mapper217_init(void);
-void Mapper218_init(void);
-void Mapper219_init(void);
-void Mapper220_init(void);
-void Mapper221_init(void);
-void Mapper222_init(void);
-void Mapper223_init(void);
-void Mapper224_init(void);
-void Mapper225_init(void);
-void Mapper226_init(void);
-void Mapper227_init(void);
-void Mapper228_init(void);
-void Mapper229_init(void);
-void Mapper230_init(void);
-void Mapper231_init(void);
-void Mapper232_init(void);
-void Mapper233_init(void);
-void Mapper234_init(void);
-void Mapper235_init(void);
-void Mapper236_init(void);
-void Mapper237_init(void);
-void Mapper238_init(void);
-void Mapper239_init(void);
-void Mapper240_init(void);
-void Mapper241_init(void);
-void Mapper242_init(void);
-void Mapper243_init(void);
-void Mapper244_init(void);
-void Mapper245_init(void);
-void Mapper246_init(void);
-void Mapper247_init(void);
-void Mapper248_init(void);
-void Mapper249_init(void);
-void Mapper250_init(void);
-void Mapper251_init(void);
-void Mapper252_init(void);
-void Mapper253_init(void);
-void Mapper254_init(void);
-void Mapper255_init(void);
-
-void VRC6_ESI(int t);
-void VRC7_ESI(void);
-void Mapper5_ESI(void);
-void Mapper69_ESI(void);
-void Mapper19_ESI(void);
+/* 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
+#include "cart.h"\r
+#ifdef INESPRIV\r
+\r
+void iNESStateRestore(int version);\r
+extern uint32 iNESGameCRC32;\r
+\r
+extern uint8 *VROM;\r
+\r
+extern uint32 VROM_size;\r
+extern uint32 ROM_size;\r
+\r
+extern void (*MapStateRestore)(int version);\r
+extern void (*MapClose)(void);\r
+extern void (*MapperReset)(void);\r
+\r
+/* This order is necessary */\r
+#define WRAM    (GameMemBlock)\r
+#define sizeofWRAM    8192\r
+\r
+#define MapperExRAM   (GameMemBlock+sizeofWRAM)\r
+#define sizeofMapperExRAM  32768\r
+/* for the MMC5 code to work properly.  It might be fixed later... */\r
+\r
+#define CHRRAM  (GameMemBlock+sizeofWRAM+sizeofMapperExRAM)\r
+#define sizeofCHRRAM 8192\r
+\r
+#define ExtraNTARAM   (GameMemBlock+sizeofWRAM+sizeofMapperExRAM+sizeofCHRRAM)\r
+#define sizeofExtraNTARAM 2048\r
+\r
+#define PRGBankList    (ExtraNTARAM+sizeofExtraNTARAM)\r
+\r
+#define mapbyte1       (PRGBankList+4)\r
+#define mapbyte2       (mapbyte1+8)\r
+#define mapbyte3       (mapbyte2+8)\r
+#define mapbyte4       (mapbyte3+8)\r
+extern uint16 iNESCHRBankList[8];\r
+extern int32 iNESIRQLatch,iNESIRQCount;\r
+extern uint8 iNESMirroring;\r
+extern uint8 iNESIRQa;\r
+\r
+#define IRQa iNESIRQa\r
+#define Mirroring iNESMirroring\r
+#define IRQCount iNESIRQCount\r
+#define IRQLatch iNESIRQLatch\r
+#define CHRBankList iNESCHRBankList\r
+#else\r
+#endif\r
+\r
+       typedef struct {\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
+void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V);\r
+void FASTAPASS(2) VRAM_BANK4(uint32 A,uint32 V);\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
+\r
+extern uint8 vmask;\r
+extern uint32 vmask1;\r
+extern uint32 vmask2;\r
+extern uint32 vmask4;\r
+extern uint32 pmask8;\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
+\r
+void Mapper0_init(void);\r
+void Mapper1_init(void);\r
+//void Mapper2_init(void);\r
+//void Mapper3_init(void);\r
+void Mapper6_init(void);\r
+void Mapper7_init(void);\r
+void Mapper8_init(void);\r
+void Mapper9_init(void);\r
+void Mapper10_init(void);\r
+void Mapper11_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 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 Mapper24_init(void);\r
+void Mapper25_init(void);\r
+void Mapper26_init(void);\r
+void Mapper27_init(void);\r
+void Mapper28_init(void);\r
+void Mapper29_init(void);\r
+void Mapper30_init(void);\r
+void Mapper31_init(void);\r
+void Mapper32_init(void);\r
+void Mapper33_init(void);\r
+void Mapper34_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 Mapper40_init(void);\r
+void Mapper41_init(void);\r
+void Mapper42_init(void);\r
+void Mapper43_init(void);\r
+void Mapper44_init(void);\r
+void Mapper45_init(void);\r
+void Mapper46_init(void);\r
+void Mapper47_init(void);\r
+void Mapper48_init(void);\r
+void Mapper49_init(void);\r
+void Mapper50_init(void);\r
+void Mapper51_init(void);\r
+void Mapper53_init(void);\r
+void Mapper54_init(void);\r
+void Mapper55_init(void);\r
+void Mapper56_init(void);\r
+void Mapper57_init(void);\r
+void Mapper58_init(void);\r
+void Mapper59_init(void);\r
+void Mapper60_init(void);\r
+void Mapper61_init(void);\r
+void Mapper62_init(void);\r
+void Mapper63_init(void);\r
+void Mapper64_init(void);\r
+void Mapper65_init(void);\r
+void Mapper66_init(void);\r
+void Mapper67_init(void);\r
+void Mapper68_init(void);\r
+void Mapper69_init(void);\r
+void Mapper70_init(void);\r
+void Mapper71_init(void);\r
+void Mapper72_init(void);\r
+void Mapper73_init(void);\r
+void Mapper74_init(void);\r
+void Mapper75_init(void);\r
+void Mapper76_init(void);\r
+void Mapper77_init(void);\r
+void Mapper78_init(void);\r
+void Mapper79_init(void);\r
+void Mapper80_init(void);\r
+void Mapper81_init(void);\r
+void Mapper82_init(void);\r
+void Mapper83_init(void);\r
+void Mapper84_init(void);\r
+void Mapper85_init(void);\r
+void Mapper86_init(void);\r
+void Mapper87_init(void);\r
+void Mapper88_init(void);\r
+void Mapper89_init(void);\r
+void Mapper91_init(void);\r
+void Mapper92_init(void);\r
+void Mapper93_init(void);\r
+void Mapper94_init(void);\r
+void Mapper96_init(void);\r
+void Mapper97_init(void);\r
+void Mapper98_init(void);\r
+void Mapper99_init(void);\r
+void Mapper100_init(void);\r
+void Mapper101_init(void);\r
+void Mapper102_init(void);\r
+void Mapper103_init(void);\r
+void Mapper104_init(void);\r
+void Mapper106_init(void);\r
+void Mapper107_init(void);\r
+void Mapper108_init(void);\r
+void Mapper109_init(void);\r
+void Mapper110_init(void);\r
+void Mapper111_init(void);\r
+//void Mapper112_init(void);\r
+void Mapper113_init(void);\r
+//void Mapper114_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 Mapper122_init(void);\r
+void Mapper123_init(void);\r
+void Mapper124_init(void);\r
+void Mapper126_init(void);\r
+void Mapper127_init(void);\r
+void Mapper128_init(void);\r
+void Mapper129_init(void);\r
+void Mapper130_init(void);\r
+void Mapper131_init(void);\r
+void Mapper132_init(void);\r
+void Mapper134_init(void);\r
+void Mapper135_init(void);\r
+void Mapper136_init(void);\r
+void Mapper137_init(void);\r
+//void Mapper138_init(void);\r
+void Mapper139_init(void);\r
+void Mapper140_init(void);\r
+void Mapper141_init(void);\r
+void Mapper142_init(void);\r
+void Mapper143_init(void);\r
+void Mapper144_init(void);\r
+//void Mapper145_init(void);\r
+//void Mapper146_init(void);\r
+//void Mapper147_init(void);\r
+//void Mapper149_init(void);\r
+void Mapper150_init(void);\r
+void Mapper151_init(void);\r
+void Mapper152_init(void);\r
+void Mapper153_init(void);\r
+void Mapper154_init(void);\r
+void Mapper156_init(void);\r
+void Mapper157_init(void);\r
+void Mapper158_init(void);\r
+void Mapper159_init(void);\r
+void Mapper160_init(void);\r
+void Mapper161_init(void);\r
+void Mapper162_init(void);\r
+void Mapper166_init(void);\r
+void Mapper167_init(void);\r
+void Mapper168_init(void);\r
+void Mapper169_init(void);\r
+void Mapper170_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 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 Mapper184_init(void);\r
+void Mapper185_init(void);\r
+void Mapper189_init(void);\r
+//void Mapper191_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 Mapper198_init(void);\r
+void Mapper199_init(void);\r
+void Mapper200_init(void);\r
+void Mapper201_init(void);\r
+void Mapper202_init(void);\r
+void Mapper203_init(void);\r
+void Mapper204_init(void);\r
+void Mapper207_init(void);\r
+void Mapper211_init(void);\r
+void Mapper212_init(void);\r
+void Mapper213_init(void);\r
+void Mapper214_init(void);\r
+void Mapper218_init(void);\r
+void Mapper219_init(void);\r
+void Mapper220_init(void);\r
+void Mapper221_init(void);\r
+void Mapper222_init(void);\r
+void Mapper223_init(void);\r
+void Mapper224_init(void);\r
+void Mapper225_init(void);\r
+void Mapper226_init(void);\r
+void Mapper227_init(void);\r
+void Mapper228_init(void);\r
+void Mapper229_init(void);\r
+void Mapper230_init(void);\r
+void Mapper231_init(void);\r
+void Mapper232_init(void);\r
+void Mapper233_init(void);\r
+void Mapper234_init(void);\r
+void Mapper235_init(void);\r
+void Mapper236_init(void);\r
+void Mapper237_init(void);\r
+void Mapper238_init(void);\r
+void Mapper239_init(void);\r
+void Mapper240_init(void);\r
+void Mapper241_init(void);\r
+void Mapper242_init(void);\r
+void Mapper244_init(void);\r
+void Mapper245_init(void);\r
+void Mapper246_init(void);\r
+void Mapper247_init(void);\r
+void Mapper249_init(void);\r
+void Mapper251_init(void);\r
+void Mapper252_init(void);\r
+void Mapper253_init(void);\r
+void Mapper255_init(void);\r
+\r
+void NSFVRC6_Init(void);\r
+void NSFMMC5_Init(void);\r
+void NSFAY_Init(void);\r
+void NSFN106_Init(void);\r
+void NSFVRC7_Init(void);\r
+void Mapper19_ESI(void);\r
+\r
+void Mapper1_Init(CartInfo *);\r
+void Mapper4_Init(CartInfo *);\r
+void Mapper5_Init(CartInfo *);\r
+void Mapper12_Init(CartInfo *);\r
+void Mapper19_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 Mapper74_Init(CartInfo *);\r
+void Mapper90_Init(CartInfo *);\r
+void Mapper95_Init(CartInfo *);\r
+void Mapper105_Init(CartInfo *);\r
+void Mapper112_Init(CartInfo *);\r
+void Mapper114_Init(CartInfo *);\r
+void Mapper115_Init(CartInfo *);\r
+void Mapper116_Init(CartInfo *);\r
+void Mapper118_Init(CartInfo *);\r
+void Mapper119_Init(CartInfo *);\r
+void Mapper125_Init(CartInfo *);\r
+void Mapper155_Init(CartInfo *);\r
+void Mapper163_Init(CartInfo *);\r
+void Mapper164_Init(CartInfo *);\r
+void Mapper165_Init(CartInfo *);\r
+void Mapper182_Init(CartInfo *);\r
+void Mapper183_Init(CartInfo *);\r
+void Mapper186_Init(CartInfo *);\r
+void Mapper187_Init(CartInfo *);\r
+void Mapper188_Init(CartInfo *);\r
+void Mapper191_Init(CartInfo *);\r
+void Mapper205_Init(CartInfo *);\r
+void Mapper208_Init(CartInfo *);\r
+void Mapper209_Init(CartInfo *);\r
+void Mapper210_Init(CartInfo *);\r
+void Mapper215_Init(CartInfo *);\r
+void Mapper216_Init(CartInfo *);\r
+void Mapper217_Init(CartInfo *);\r
+void Mapper245_Init(CartInfo *);\r
+void Mapper249_Init(CartInfo *);\r
+void Mapper250_Init(CartInfo *);\r
+void Mapper254_Init(CartInfo *);\r
diff --git a/input.c b/input.c
index e4223bc..1548e41 100644 (file)
--- a/input.c
+++ b/input.c
@@ -31,6 +31,8 @@
 #include "state.h"
 #include "movie.h"
 
+#include "fds.h"
+#include "vsuni.h"
 #include "dprintf.h"
 
 extern INPUTC *FCEU_InitZapper(int w);
@@ -61,6 +63,14 @@ static INPUTC DummyJPort={0,0,0,0,0};
 static INPUTC *JPorts[2]={&DummyJPort,&DummyJPort};
 static INPUTCFC *FCExp=0;
 
+/* This function is a quick hack to get the NSF player to use emulated gamepad
+   input.
+*/
+uint8 FCEU_GetJoyJoy(void)
+{
+ return(joy[0]|joy[1]|joy[2]|joy[3]);
+}
+
 static uint8 FP_FASTAPASS(1) ReadGPVS(int w)
 {
                 uint8 ret=0;
@@ -195,7 +205,7 @@ void UpdateInput(void)
        if(netplay) NetplayUpdate(&joy[0],&joy[1]);
        #endif
        if (current < 0) FCEUMOV_AddJoy(joy);
-       FlushCommandQueue();
+       //FlushCommandQueue();
 }
 
 static DECLFR(VSUNIRead0)
@@ -255,7 +265,7 @@ static void FASTAPASS(1) SetInputStuff(int x)
          break;
          case SI_ARKANOID:JPorts[x]=FCEU_InitArkanoid(x);break;
          case SI_ZAPPER:JPorts[x]=FCEU_InitZapper(x);break;
-          case SI_POWERPAD:JPorts[x]=FCEU_InitPowerpad(x);break;
+          case SI_POWERPADA:JPorts[x]=FCEU_InitPowerpad(x);break;
          case SI_NONE:JPorts[x]=&DummyJPort;break;
          }
 
@@ -351,17 +361,74 @@ void FCEU_DoSimpleCommand(int cmd)
 {
  switch(cmd)
  {
-//   case FCEUNPCMD_FDSINSERT: FCEU_FDSInsert();break;
-//   case FCEUNPCMD_FDSSELECT: FCEU_FDSSelect();break;
+   case FCEUNPCMD_FDSINSERT: FCEU_FDSInsert();break;
+   case FCEUNPCMD_FDSSELECT: FCEU_FDSSelect();break;
 //   case FCEUNPCMD_FDSEJECT: FCEU_FDSEject();break;
-//   case FCEUNPCMD_VSUNICOIN: FCEU_VSUniCoin(); break;
-//   case FCEUNPCMD_VSUNIDIP0 ... (FCEUNPCMD_VSUNIDIP0 + 7): FCEU_VSUniToggleDIP(cmd - FCEUNPCMD_VSUNIDIP0);break;
+   case FCEUNPCMD_VSUNICOIN: FCEU_VSUniCoin(); break;
+   case FCEUNPCMD_VSUNIDIP0 ... (FCEUNPCMD_VSUNIDIP0 + 7): FCEU_VSUniToggleDIP(cmd - FCEUNPCMD_VSUNIDIP0);break;
    case FCEUNPCMD_POWER: PowerNES();break;
    case FCEUNPCMD_RESET: ResetNES();break;
    default: printf("FCEU_DoSimpleCommand: can't handle cmd %i\n", cmd); break;
  }
 }
 
+void FCEU_QSimpleCommand(int cmd)
+{
+// if(FCEUnetplay)
+//  FCEUNET_SendCommand(cmd, 0);
+// else
+ {
+  // totally wrong:
+//  if(!FCEUMOV_IsPlaying())
+//   FCEU_DoSimpleCommand(cmd);
+//  else
+//   FCEUMOV_AddCommand(cmd);
+
+  FCEU_DoSimpleCommand(cmd);
+//  if(FCEUMOV_IsRecording())
+//   FCEUMOV_AddCommand(cmd);
+ }
+}
+
+void FCEUI_FDSSelect(void)
+{
+ FCEU_QSimpleCommand(FCEUNPCMD_FDSSELECT);
+}
+
+int FCEUI_FDSInsert(void)
+{
+ FCEU_QSimpleCommand(FCEUNPCMD_FDSINSERT);
+ return(1);
+}
+
+/*
+int FCEUI_FDSEject(void)
+{
+    FCEU_QSimpleCommand(FCEUNPCMD_FDSEJECT);
+    return(1);
+}
+*/
+void FCEUI_VSUniToggleDIP(int w)
+{
+ FCEU_QSimpleCommand(FCEUNPCMD_VSUNIDIP0 + w);
+}
+
+void FCEUI_VSUniCoin(void)
+{
+ FCEU_QSimpleCommand(FCEUNPCMD_VSUNICOIN);
+}
+
+void FCEUI_ResetNES(void)
+{
+       FCEU_QSimpleCommand(FCEUNPCMD_RESET);
+}
+
+void FCEUI_PowerNES(void)
+{
+        FCEU_QSimpleCommand(FCEUNPCMD_POWER);
+}
+
+
 
 SFORMAT FCEUCTRL_STATEINFO[]={
  { joy_readbit, 2, "JYRB"},
diff --git a/input.h b/input.h
index 8c301cf..3adc898 100644 (file)
--- a/input.h
+++ b/input.h
@@ -24,3 +24,10 @@ extern void (*InputScanlineHook)(uint8 *buf, int line);
 
 void FCEU_DoSimpleCommand(int cmd);
 
+void FCEUI_FDSSelect(void);
+int FCEUI_FDSInsert(void);
+void FCEUI_VSUniToggleDIP(int w);
+void FCEUI_VSUniCoin(void);
+void FCEUI_ResetNES(void);
+void FCEUI_PowerNES(void);
+
diff --git a/mappers/105.c b/mappers/105.c
deleted file mode 100644 (file)
index 07f4ceb..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 MMC1_reg mapbyte1
-#define MMC1_buf mapbyte2[0]
-#define MMC1_sft mapbyte3[0]
-#define lastn    mapbyte2[1]
-
-#define NWCDIP 0xE
-
-static void FP_FASTAPASS(1) NWCIRQHook(int a)
-{
-       if(!(MMC1_reg[1]&0x10))
-       {
-        IRQCount+=a;
-        if((IRQCount|(NWCDIP<<25))>=0x3e000000)
-          {
-          IRQCount=0;
-          X6502_IRQBegin(FCEU_IQEXT);
-         }
-       }
-}
-
-
-static void MMC1PRG(void)
-{
-       if(MMC1_reg[1]&8)
-       {
-        switch(MMC1_reg[0]&0xC)
-         {
-           case 0xC: ROM_BANK16(0x8000,8+(MMC1_reg[3]&7));
-                     ROM_BANK16(0xC000,15);
-                     break;
-           case 0x8: ROM_BANK16(0xC000,8+((MMC1_reg[3])&7));
-                     ROM_BANK16(0x8000,8);
-                     break;
-           case 0x0:
-           case 0x4:
-                     ROM_BANK16(0x8000,8+(MMC1_reg[3]&6));
-                     ROM_BANK16(0xc000,8+((MMC1_reg[3]&6)+1));
-                     break;
-         }
-       }
-       else
-       {
-        ROM_BANK32((MMC1_reg[1]>>1)&3);
-       }
-        X6502_Rebase();
-}
-
-DECLFW(Mapper105_write)
-{
-        int n=(A>>13)-4;
-
-        if (V&0x80)
-        {
-         MMC1_sft=MMC1_buf=0;
-         return;
-        }
-
-        if(lastn!=n)
-        {
-         MMC1_sft=MMC1_buf=0;
-        }
-        lastn=n;
-
-       //MMC1_reg[n]&=~((1)<<(MMC1_sft));
-        MMC1_buf|=(V&1)<<(MMC1_sft++);
-
-  if (MMC1_sft==5)
-       {
-        if(n==3) V&=0xF;
-        else     V&=0x1F;
-
-        MMC1_reg[n]=V=MMC1_buf;
-        MMC1_sft = MMC1_buf=0;
-
-        switch(n){
-        case 0:
-                switch(MMC1_reg[0]&3)
-                {
-                 case 2: MIRROR_SET(0);break;
-                 case 3: MIRROR_SET(1);break;
-                 case 0: onemir(0);break;
-                 case 1: onemir(1);break;
-                }
-                MMC1PRG();
-                break;
-        case 1:
-               if(MMC1_reg[1]&0x10)
-                {IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);}
-                MMC1PRG();
-                break;
-        case 3:
-                MMC1PRG();
-                break;
-        }
-  }
-}
-
-
-void Mapper105_init(void)
-{
-        int i;
-        for(i=0;i<4;i++) MMC1_reg[i]=0;
-        MMC1_sft = MMC1_buf =0;
-        MMC1_reg[0]=0xC;
-        ROM_BANK32(0);
-       SetWriteHandler(0x8000,0xFFFF,Mapper105_write);
-       MapIRQHook=NWCIRQHook;
-}
-
index 4662ed5..525f131 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 DECLFW(Mapper113_write)
 {
         ROM_BANK32((V>>3)&7);
-        VROM_BANK8(V&7);
-        X6502_Rebase();
+        VROM_BANK8(((V>>3)&8)|(V&7));
+        //printf("$%04x:$%02x\n",A,V);
 }
 
 
 /*      Deathbots */
 DECLFW(Mapper113_writeh)
 {
-        ROM_BANK32(V&0xF);
-        X6502_Rebase();
+        //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;
+        }
 }
 
 
index 6f1051c..f7302b4 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 DECLFW(Mapper117_write)
 {
+ //if(A>=0xc000)
+ //printf("$%04x:$%02x, %d,%d\n",A,V,scanline,timestamp);
  switch(A)
  {
-  case 0xc003:IRQCount=V;break;
-  case 0xc001:IRQa=V;break;
+  case 0xc001:IRQLatch=V;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 0xa000:VROM_BANK1(0x0000,V);break;
   case 0xa001:VROM_BANK1(0x0400,V);break;
   case 0xa002:VROM_BANK1(0x0800,V);break;
@@ -36,30 +40,25 @@ DECLFW(Mapper117_write)
   case 0xa005:VROM_BANK1(0x1400,V);break;
   case 0xa006:VROM_BANK1(0x1800,V);break;
   case 0xa007:VROM_BANK1(0x1c00,V);break;
-  case 0x8000:ROM_BANK8(0x8000,V);
-              X6502_Rebase();break;
-  case 0x8001:ROM_BANK8(0xa000,V);
-              X6502_Rebase();break;
-  case 0x8002:ROM_BANK8(0xc000,V);
-              X6502_Rebase();break;
-  case 0x8003:ROM_BANK8(0xe000,V);
-              X6502_Rebase();break;
+  case 0x8000:ROM_BANK8(0x8000,V);break;
+  case 0x8001:ROM_BANK8(0xa000,V);break;
+  case 0x8002:ROM_BANK8(0xc000,V);break;
+  case 0x8003:ROM_BANK8(0xe000,V);break;
  }
 }
 
 static void Mapper117_hb(void)
 {
- if(IRQa)
+ //if(scanline==0x40) X6502_IRQBegin(FCEU_IQEXT);
+ //return;
+ if(IRQa==3 && IRQCount)
  {
-        if(IRQCount<=0)
-        {
-         IRQa=0;
-         TriggerIRQ();
-        }
-        else
-        {
-         IRQCount--;
-        }
+  IRQCount--;
+  if(!IRQCount)
+  {
+   IRQa&=1;
+   X6502_IRQBegin(FCEU_IQEXT);
+  }
  }
 }
 
index e3ad005..e649af6 100644 (file)
@@ -1,8 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #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;
+        }
+}
 
 
-DECLFW(Mapper15_write)
+static DECLFW(Mapper15_write)
 {
-switch(A)
- {
-  case 0x8000:
-        if(V&0x80)
-        {
-        ROM_BANK8(0x8000,(V<<1)+1);
-        ROM_BANK8(0xA000,(V<<1));
-        ROM_BANK8(0xC000,(V<<1)+2);
-        ROM_BANK8(0xE000,(V<<1)+1);
-        }
-        else
-        {
-        ROM_BANK16(0x8000,V);
-        ROM_BANK16(0xC000,V+1);
-        }
-        MIRROR_SET((V>>6)&1);
-        X6502_Rebase();
-        break;
-  case 0x8001:
-        MIRROR_SET(0);
-        ROM_BANK16(0x8000,V);
-        ROM_BANK16(0xc000,~0);
-        X6502_Rebase();
-        break;
-  case 0x8002:
-        if(V&0x80)
-        {
-         ROM_BANK8(0x8000,((V<<1)+1));
-         ROM_BANK8(0xA000,((V<<1)+1));
-         ROM_BANK8(0xC000,((V<<1)+1));
-         ROM_BANK8(0xE000,((V<<1)+1));
-        }
-        else
-        {
-         ROM_BANK8(0x8000,(V<<1));
-         ROM_BANK8(0xA000,(V<<1));
-         ROM_BANK8(0xC000,(V<<1));
-         ROM_BANK8(0xE000,(V<<1));
-        }
-        X6502_Rebase();
-        break;
-  case 0x8003:
-        MIRROR_SET((V>>6)&1);
-        if(V&0x80)
-        {
-         ROM_BANK8(0xC000,(V<<1)+1);
-         ROM_BANK8(0xE000,(V<<1));
-        }
-        else
-        {
-         ROM_BANK16(0xC000,V);
-        }
-        X6502_Rebase();
-        break;
- }
+ mapbyte1[0]=V;
+ mapbyte1[1]=A&3;
+ Sync();
+}
+
+static void StateRestore(int version)
+{
+ Sync();
 }
 
 void Mapper15_init(void)
 {
-        ROM_BANK32(0);
-       SetWriteHandler(0x8000,0xFFFF,Mapper15_write);
+        mapbyte1[0]=mapbyte1[1]=0;
+        Sync();
+        GameStateRestore=StateRestore;
+        SetWriteHandler(0x8000,0xFFFF,Mapper15_write);
 }
 
index e7c123e..5d2cb28 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -26,12 +26,9 @@ DECLFW(Mapper151_write)
 {
  switch(A&0xF000)
  {
-  case 0x8000:ROM_BANK8(0x8000,V);
-              X6502_Rebase();break;
-  case 0xA000:ROM_BANK8(0xA000,V);
-              X6502_Rebase();break;
-  case 0xC000:ROM_BANK8(0xC000,V);
-              X6502_Rebase();break;
+  case 0x8000:ROM_BANK8(0x8000,V);break;
+  case 0xA000:ROM_BANK8(0xA000,V);break;
+  case 0xC000:ROM_BANK8(0xC000,V);break;
   case 0xe000:VROM_BANK4(0x0000,V);break;
   case 0xf000:VROM_BANK4(0x1000,V);break;
  }
index 58dd0b1..fd922fb 100644 (file)
@@ -2,7 +2,7 @@
  *
  * Copyright notice for this file:
  *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -43,10 +43,7 @@ static DECLFW(Mapper16_write)
         if(A<=0x7)
          VROM_BANK1(A<<10,V);
         else if(A==0x8)
-       {
          ROM_BANK16(0x8000,V);
-         X6502_Rebase();
-       }
         else switch(A) {
          case 0x9: switch(V&3) {
                     case 0x00:MIRROR_SET2(1);break;
@@ -81,40 +78,39 @@ static void PRGO(void)
  uint32 base=(mapbyte1[0]&1)<<4;
  ROM_BANK16(0x8000,(mapbyte2[0]&0xF)|base);
  ROM_BANK16(0xC000,base|0xF);
- X6502_Rebase();
 }
 
 static DECLFW(Mapper153_write)
 {
-       A&=0xF;
+        A&=0xF;
         if(A<=0x7)
-       {
-        mapbyte1[A&7]=V;
-        PRGO();
-       }
+        {
+         mapbyte1[A&7]=V;
+         PRGO();
+        }
         else if(A==0x8)
-       {
-        mapbyte2[0]=V;
-        PRGO();
-       }
-       else switch(A) {
-        case 0x9: switch(V&3) {
-                           case 0x00:MIRROR_SET2(1);break;
+        {
+         mapbyte2[0]=V;
+         PRGO();
+        }
+        else switch(A) {
+         case 0x9: switch(V&3) {
+                           case 0x00:MIRROR_SET2(1);break;
                     case 0x01:MIRROR_SET2(0);break;
                     case 0x02:onemir(0);break;
                     case 0x03:onemir(1);break;
                    }
                    break;
          case 0xA:X6502_IRQEnd(FCEU_IQEXT);
-                 IRQa=V&1;
-                 IRQCount=IRQLatch;
-                 break;
+                    IRQa=V&1;
+                  IRQCount=IRQLatch;
+                  break;
          case 0xB:IRQLatch&=0xFF00;
-                 IRQLatch|=V;
-                 break;
+                  IRQLatch|=V;
+                   break;
          case 0xC:IRQLatch&=0xFF;
-                 IRQLatch|=V<<8;
-                 break;
+                   IRQLatch|=V<<8;
+                  break;
         }
 }
 
@@ -131,3 +127,179 @@ void Mapper153_init(void)
  /* 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 int BarcodeReadPos;
+static int BarcodeCycleCount;
+static uint32 BarcodeOut;
+
+int FCEUI_DatachSet(const uint8 *rcode)
+{
+        int    prefix_parity_type[10][6] = {
+                {0,0,0,0,0,0}, {0,0,1,0,1,1}, {0,0,1,1,0,1}, {0,0,1,1,1,0},
+                {0,1,0,0,1,1}, {0,1,1,0,0,1}, {0,1,1,1,0,0}, {0,1,0,1,0,1},
+                {0,1,0,1,1,0}, {0,1,1,0,1,0}
+        };
+        int    data_left_odd[10][7] = {
+                {0,0,0,1,1,0,1}, {0,0,1,1,0,0,1}, {0,0,1,0,0,1,1}, {0,1,1,1,1,0,1},
+                {0,1,0,0,0,1,1}, {0,1,1,0,0,0,1}, {0,1,0,1,1,1,1}, {0,1,1,1,0,1,1},
+                {0,1,1,0,1,1,1}, {0,0,0,1,0,1,1}
+        };
+        int    data_left_even[10][7] = {
+                {0,1,0,0,1,1,1}, {0,1,1,0,0,1,1}, {0,0,1,1,0,1,1}, {0,1,0,0,0,0,1},
+                {0,0,1,1,1,0,1}, {0,1,1,1,0,0,1}, {0,0,0,0,1,0,1}, {0,0,1,0,0,0,1},
+                {0,0,0,1,0,0,1}, {0,0,1,0,1,1,1}
+        };
+        int    data_right[10][7] = {
+                {1,1,1,0,0,1,0}, {1,1,0,0,1,1,0}, {1,1,0,1,1,0,0}, {1,0,0,0,0,1,0},
+                {1,0,1,1,1,0,0}, {1,0,0,1,1,1,0}, {1,0,1,0,0,0,0}, {1,0,0,0,1,0,0},
+                {1,0,0,1,0,0,0}, {1,1,1,0,1,0,0}
+        };
+        uint8 code[13+1];
+        uint32 tmp_p=0;
+        int i, j;
+        int len;
+
+        for(i=len=0;i<13;i++)
+        {
+         if(!rcode[i]) break;
+
+         if((code[i]=rcode[i]-'0') > 9)
+          return(0);
+         len++;
+        }
+        if(len!=13 && len!=12 && len!=8 && len!=7) return(0);
+
+        #define BS(x) BarcodeData[tmp_p]=x;tmp_p++
+
+        for(j=0;j<32;j++)
+        {
+         BS(0x00);
+        }
+
+        /* Left guard bars */
+        BS(1);        BS(0); BS(1);
+
+        if(len==13 || len==12)
+        {
+         uint32 csum;
+
+          for(i=0;i<6;i++)
+          if(prefix_parity_type[code[0]][i])
+          {
+           for(j=0;j<7;j++)
+           {
+            BS(data_left_even[code[i+1]][j]);
+           }
+          }
+          else
+           for(j=0;j<7;j++)
+           {
+            BS(data_left_odd[code[i+1]][j]);
+           }
+
+         /* Center guard bars */
+         BS(0); BS(1); BS(0); BS(1); BS(0);
+
+         for(i=7;i<12;i++)
+          for(j=0;j<7;j++)
+          {
+           BS(data_right[code[i]][j]);
+          }
+         csum=0;
+         for(i=0;i<12;i++) csum+=code[i]*((i&1)?3:1);
+         csum=(10-(csum%10))%10;
+         //printf("%d\n",csum);
+         for(j=0;j<7;j++)
+         {
+          BS(data_right[csum][j]);
+         }
+
+        }
+        else if(len==8 || len==7)
+        {
+         uint32 csum=0;
+
+         for(i=0;i<7;i++) csum+=(i&1)?code[i]:(code[i]*3);
+
+         csum=(10-(csum%10))%10;
+
+         for(i=0;i<4;i++)
+          for(j=0;j<7;j++)
+          {
+           BS(data_left_odd[code[i]][j]);
+          }
+
+
+         /* Center guard bars */
+         BS(0); BS(1); BS(0); BS(1); BS(0);
+
+         for(i=4;i<7;i++)
+          for(j=0;j<7;j++)
+          {
+           BS(data_right[code[i]][j]);
+          }
+
+         for(j=0;j<7;j++)
+          { BS(data_right[csum][j]);}
+
+        }
+
+        /* Right guard bars */
+        BS(1); BS(0); BS(1);
+
+        for(j=0;j<32;j++)
+        {
+         BS(0x00);
+        }
+
+        BS(0xFF);
+        #undef BS
+        BarcodeReadPos=0;
+        BarcodeOut=0x8;
+        BarcodeCycleCount=0;
+        return(1);
+}
+
+static void FP_FASTAPASS(1) BarcodeIRQHook(int a)
+{
+ BandaiIRQHook(a);
+
+ BarcodeCycleCount+=a;
+
+ if(BarcodeCycleCount >= 1000)
+ {
+  BarcodeCycleCount -= 1000;
+  if(BarcodeData[BarcodeReadPos]==0xFF)
+  {
+   BarcodeOut=0;
+  }
+  else
+  {
+   BarcodeOut=(BarcodeData[BarcodeReadPos]^1)<<3;
+   BarcodeReadPos++;
+  }
+ }
+}
+
+static DECLFR(Mapper157_read)
+{
+ uint8 ret;
+
+ ret=BarcodeOut;
+ return(ret);
+}
+
+void Mapper157_init(void)
+{
+ FCEUGameInfo.cspecial = SIS_DATACH;
+ MapIRQHook=BarcodeIRQHook;
+ SetWriteHandler(0x6000,0xFFFF,Mapper16_write);
+ SetReadHandler(0x6000,0x7FFF,Mapper157_read);
+
+ BarcodeData[0]=0xFF;
+ BarcodeReadPos=0;
+ BarcodeOut=0;
+ BarcodeCycleCount=0;
+}
index 1e76421..7fae1a8 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -27,10 +27,9 @@ static void FP_FASTAPASS(1) FFEIRQHook(int a)
   if(IRQa)
   {
    IRQCount+=a;
-
    if(IRQCount>=0x10000)
    {
-    TriggerIRQ();
+    X6502_IRQBegin(FCEU_IQEXT);
     IRQa=0;
     IRQCount=0;
    }
@@ -42,24 +41,20 @@ DECLFW(Mapper17_write)
 {
         switch(A){
         default:
-                  break;
+                   break;
         case 0x42FE:
                    onemir((V>>4)&1);
                    break;
         case 0x42FF:
                    MIRROR_SET((V>>4)&1);
-                  break;
-        case 0x4501:IRQa=V&1;break;
+                   break;
+        case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
         case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break;
         case 0x4503:IRQCount&=0x00FF;IRQCount|=V<<8;IRQa=1;break;
-        case 0x4504: ROM_BANK8(0x8000,V);
-                     X6502_Rebase();break;
-        case 0x4505: ROM_BANK8(0xA000,V);
-                     X6502_Rebase();break;
-        case 0x4506: ROM_BANK8(0xC000,V);
-                     X6502_Rebase();break;
-        case 0x4507: ROM_BANK8(0xE000,V);
-                     X6502_Rebase();break;
+        case 0x4504: ROM_BANK8(0x8000,V);break;
+        case 0x4505: ROM_BANK8(0xA000,V);break;
+        case 0x4506: ROM_BANK8(0xC000,V);break;
+        case 0x4507: ROM_BANK8(0xE000,V);break;
         case 0x4510: VROM_BANK1(0x0000,V);break;
         case 0x4511: VROM_BANK1(0x0400,V);break;
         case 0x4512: VROM_BANK1(0x0800,V);break;
index 13b3ab9..b682b26 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -39,38 +39,37 @@ void FP_FASTAPASS(1) JalecoIRQHook(int a)
 
 DECLFW(Mapper18_write)
 {
-       A&=0xF003;
-       if(A>=0x8000 && A<=0x9001)
-       {
+        A&=0xF003;
+        if(A>=0x8000 && A<=0x9001)
+        {
          int x=((A>>1)&1)|((A-0x8000)>>11);
 
          K4buf2[x]&=(0xF0)>>((A&1)<<2);
          K4buf2[x]|=(V&0xF)<<((A&1)<<2);
          ROM_BANK8(0x8000+(x<<13),K4buf2[x]);
-         X6502_Rebase();
-       }
-       else if(A>=0xa000 && A<=0xd003)
-       {
-        int x=((A>>1)&1)|((A-0xA000)>>11);
+        }
+        else if(A>=0xa000 && A<=0xd003)
+        {
+         int x=((A>>1)&1)|((A-0xA000)>>11);
 
          K4buf[x]&=(0xF0)>>((A&1)<<2);
          K4buf[x]|=(V&0xF)<<((A&1)<<2);
          VROM_BANK1(x<<10,K4buf[x]);
-       }
+        }
         else switch(A)
         {
-        case 0xe000:IRQLatch&=0xFFF0;IRQLatch|=(V&0x0f);break;
-        case 0xe001:IRQLatch&=0xFF0F;IRQLatch|=(V&0x0f)<<4;break;
-        case 0xe002:IRQLatch&=0xF0FF;IRQLatch|=(V&0x0f)<<8;break;
-        case 0xe003:IRQLatch&=0x0FFF;IRQLatch|=(V&0x0f)<<12;break;
-        case 0xf000:IRQCount=IRQLatch;
-                    break;
-        case 0xf001:IRQa=V&1;
-                    X6502_IRQEnd(FCEU_IQEXT);
-                    break;
-        case 0xf002:MIRROR_SET2(V&1);
-                    if(V&2) onemir(0);
-                    break;
+           case 0xe000:IRQLatch&=0xFFF0;IRQLatch|=(V&0x0f);break;
+         case 0xe001:IRQLatch&=0xFF0F;IRQLatch|=(V&0x0f)<<4;break;
+          case 0xe002:IRQLatch&=0xF0FF;IRQLatch|=(V&0x0f)<<8;break;
+         case 0xe003:IRQLatch&=0x0FFF;IRQLatch|=(V&0x0f)<<12;break;
+         case 0xf000:IRQCount=IRQLatch;
+                     break;
+         case 0xf001:IRQa=V&1;
+                     X6502_IRQEnd(FCEU_IQEXT);
+                     break;
+         case 0xf002:MIRROR_SET2(V&1);
+                     if(V&2) onemir(0);
+                      break;
         }
 }
 
index 45342dc..bd877c8 100644 (file)
@@ -4,8 +4,7 @@
 
 DECLFW(Mapper180_write)
 {
-  ROM_BANK16(0xC000,V);
-  X6502_Rebase();
+ROM_BANK16(0xC000,V);
 }
 
 void Mapper180_init(void)
diff --git a/mappers/182.c b/mappers/182.c
deleted file mode 100644 (file)
index a7f65e5..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "mapinc.h"
-
-DECLFW(Mapper182_write)
-{
-  switch(A&0xf003)
-  {
-   case 0xe003:IRQCount=V;IRQa=1;break;
-   case 0x8001:MIRROR_SET(V&1);break;
-   case 0xA000:mapbyte1[0]=V;break;
-   case 0xC000:
-               switch(mapbyte1[0]&7)
-               {
-                case 0:VROM_BANK2(0x0000,V>>1);break;
-                case 1:VROM_BANK1(0x1400,V);break;
-                case 2:VROM_BANK2(0x0800,V>>1);break;
-                case 3:VROM_BANK1(0x1c00,V);break;
-                case 4:ROM_BANK8(0x8000,V);
-                       X6502_Rebase();break;
-                case 5:ROM_BANK8(0xA000,V);
-                       X6502_Rebase();break;
-                case 6:VROM_BANK1(0x1000,V);break;
-                case 7:VROM_BANK1(0x1800,V);break;
-               }
-               break;
-
-
-  }
-}
-
-void blop(void)
-{
- if(IRQa)
-  {
-   if(IRQCount)
-   {
-    IRQCount--;
-    if(!IRQCount)
-    {
-     IRQa=0;
-     TriggerIRQ();
-    }
-   }
-  }
-}
-void Mapper182_init(void)
-{
- SetWriteHandler(0x8000,0xFFFF,Mapper182_write);
- GameHBIRQHook=blop;
-}
-
diff --git a/mappers/183.c b/mappers/183.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/mappers/187.c b/mappers/187.c
new file mode 100644 (file)
index 0000000..c9925df
--- /dev/null
@@ -0,0 +1,170 @@
+/* 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 uint8 LastWr;
+static uint8 ExtMode;
+static uint8 cmd;
+static uint8 DRegs[8];
+static uint32 count=0;
+static uint32 last=0;
+static int safe=0;
+static uint8 poofish;
+
+static void Sync(void)
+{
+ int x;
+ uint32 base=0;
+
+ if(cmd&0x80) base=0x1000;
+ setchr2(0x0000^base,(0x100|DRegs[0])>>1);
+ setchr2(0x0800^base,(0x100|DRegs[1])>>1);
+ for(x=0;x<4;x++)
+  setchr1((0x1000^base)+x*0x400,DRegs[2+x]);
+
+ if(ExtMode&0x80)
+ {
+  if(ExtMode&0x20)
+   setprg32(0x8000,(ExtMode&0x1F)>>1);
+  else
+  {
+   setprg16(0x8000,(ExtMode&0x1F));
+   setprg16(0xc000,(ExtMode&0x1F));
+  }
+ }
+ else
+ {
+  setprg8(0x8000,DRegs[6]);
+  setprg8(0xa000,DRegs[7]);
+  setprg8(0xc000,~1);
+  setprg8(0xe000,~0);
+ }
+}
+
+static DECLFW(M187Write)
+{
+// FCEU_printf("Write: %04x:%04x (%04x,%d)\n",A,V,X.PC,scanline);
+ LastWr=V;
+ if(A==0x5000)
+  ExtMode=V;
+ Sync();
+}
+
+static DECLFW(M187HWrite)
+{
+// FCEU_printf("Write: %04x:%04x (%04x,%d)\n",A,V,X.PC,scanline);
+ //if(A==0x8003 && X.PC<0x800) FCEUI_DumpMem("dmp",0x0000,0xFFFF);
+ //printf("$%04x:$%02x, %04x\n",A,V,X.PC);
+ LastWr=V;
+
+ if(A==0x8003)
+ {
+//  if(V==0x28 || V==0x2A)
+   poofish=V;
+ }
+ else if(A==0x8000) poofish=0;
+
+ switch(A)
+ {
+  case 0xc000:IRQLatch=IRQCount=V;break;
+  case 0xc001:IRQCount=IRQLatch;last=count=0;break;
+  case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
+  case 0xe001:IRQa=1;break;
+  case 0xa000:MIRROR_SET(V&1);break;
+
+  case 0x8000:cmd=V;safe=1;break;
+  case 0x8001:
+              if(safe)
+              {
+               //printf("Cmd: %d, %02x, %04x\n",cmd&0x7,V,X.PC);
+               DRegs[cmd&7]=V;
+               Sync();
+               safe=0;
+              }
+                if(poofish==0x28)
+                  setprg8(0xC000,0x17);
+                else if(poofish==0x2A)
+                  setprg8(0xA000,0x0F);
+              break;
+
+ }
+}
+
+static DECLFR(ProtRead)
+{
+ switch(LastWr&0x3)
+ {
+  case 0x1:
+  case 0x0: return(0x83);
+  case 0x2: return(0x42);
+ }
+ return(0);
+}
+
+DECLFW(Write_IRQFM);
+
+static void M187Power(void)
+{
+ Write_IRQFM(0x4017,0x40);
+ SetWriteHandler(0x5000,0x5fff,M187Write);
+ SetWriteHandler(0x8000,0xFFFF,M187HWrite);
+ SetReadHandler(0x5000,0x5FFF,ProtRead);
+ SetWriteHandler(0x6000,0x7FFF,M187Write);
+ SetReadHandler(0x8000,0xffff,CartBR);
+ Sync();
+}
+
+static void sl(void)
+{
+ if(IRQa)
+ {
+  if(IRQCount>=0)
+  {
+   IRQCount--;
+   if(IRQCount<0)
+   {
+    X6502_IRQBegin(FCEU_IQEXT);
+   }
+  }
+ }
+}
+
+static void FP_FASTAPASS(1) foo(uint32 A)
+{
+ if((A&0x2000) && !(last&0x2000))
+ {
+  count++;
+  if(count==42)
+  {
+   sl();
+   count=0;
+  }
+ }
+ last=A;
+}
+
+void Mapper187_Init(CartInfo *info)
+{
+ info->Power=M187Power;
+// GameHBIRQHook=sl;
+ PPU_hook=foo;
+}
+
index bdcf4b7..68df5b5 100644 (file)
@@ -8,31 +8,45 @@
 #define cmd mapbyte1[0]
 static DECLFW(Mapper189_write)
 {
- if(A==0x4120)
- {
-  ROM_BANK32(V>>4);
-  X6502_Rebase();
- }
+ //if(A>=0xc000) printf("$%04x:$%02x\n",A,V);
+ if((A&0xF100)==0x4100) ROM_BANK32(V>>4);
+ else if((A&0xF100)==0x6100) ROM_BANK32(V&3);
  else switch(A&0xE001)
  {
   case 0xa000:MIRROR_SET(V&1);break;
   case 0x8000:cmd=V;break;
   case 0x8001:switch(cmd&7)
-             {
-              case 0:VROM_BANK2(0x0000,V>>1);break;
-              case 1:VROM_BANK2(0x0800,V>>1);break;
-              case 2:VROM_BANK1(0x1000,V);break;
+              {
+               case 0:VROM_BANK2(0x0000,V>>1);break;
+               case 1:VROM_BANK2(0x0800,V>>1);break;
+               case 2:VROM_BANK1(0x1000,V);break;
                case 3:VROM_BANK1(0x1400,V);break;
                case 4:VROM_BANK1(0x1800,V);break;
                case 5:VROM_BANK1(0x1C00,V);break;
-             }
-             break;
+              }
+   case 0xc000:IRQLatch=V;break;
+   case 0xc001:IRQCount=IRQLatch;break;
+   case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
+   case 0xe001:IRQa=1;break;
+              break;
 
  }
 }
+void m189irq(void)
+{
+ if(IRQa)
+ {
+  if(IRQCount)
+  {
+   IRQCount--;
+   if(!IRQCount) X6502_IRQBegin(FCEU_IQEXT);
+  }
+ }
 
+}
 void Mapper189_init(void)
 {
+  GameHBIRQHook=m189irq;
   SetWriteHandler(0x4120,0xFFFF,Mapper189_write);
   SetReadHandler(0x6000,0x7FFF,0);
   ROM_BANK32(0);
diff --git a/mappers/19.c b/mappers/19.c
deleted file mode 100644 (file)
index 0258b47..0000000
+++ /dev/null
@@ -1,289 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 dopol mapbyte1[0]
-#define gorfus mapbyte1[1]
-#define gorko mapbyte1[2]
-
-static void NamcoSound(int Count);
-static void NamcoSoundHack(void);
-
-static int32 inc;
-void FP_FASTAPASS(1) NamcoIRQHook(int a)
-{
-  if(IRQa)
-  {
-   IRQCount+=a;
-   if(IRQCount>=0x7fff)
-   {
-    X6502_IRQBegin(FCEU_IQEXT);
-    IRQa=0;
-    IRQCount=0x7fff;
-   }
-  }
-}
-
-DECLFR(Namco_Read4800)
-{
-       uint8 ret=MapperExRAM[dopol&0x7f];
-       if(dopol&0x80)
-        dopol=(dopol&0x80)|((dopol+1)&0x7f);
-       return ret;
-}
-
-DECLFR(Namco_Read5000)
-{
- return(IRQCount);
-}
-
-DECLFR(Namco_Read5800)
-{
- return(IRQCount>>8);
-}
-
-static void FASTAPASS(2) DoNTARAMROM(int w, uint8 V)
-{
-        mapbyte2[w]=V;
-        //if(V>=0xE0)
-       // setntamem(NTARAM+((V&1)<<10), 1, w);
-       if((V>=0xE0)) // || ((gorko>>(6+(w>>1)))&1) )
-        setntamem(NTARAM+((V&1)<<10), 1, w);
-       else
-       {
-        V&=CHRmask1[0];
-        setntamem(VROM+(V<<10), 0, w);
-       }
-//     else
-//      setntamem(NTARAM+((V&1)<<10), 1, w);
-}
-
-static void FixNTAR(void)
-{
- int x;
-
- for(x=0;x<4;x++)
-  DoNTARAMROM(x,mapbyte2[x]);
-}
-
-static void FASTAPASS(2) DoCHRRAMROM(int x, uint8 V)
-{
-         mapbyte3[x]=V;
-         if(!((gorfus>>((x>>2)+6))&1) && (V>=0xE0))
-          VRAM_BANK1(x<<10,V&7);
-         else
-          VROM_BANK1(x<<10,V);
-}
-
-static void FixCRR(void)
-{
- int x;
- for(x=0;x<8;x++)
-  DoCHRRAMROM(x,mapbyte3[x]);
-}
-
-static DECLFW(Mapper19_write)
-{
-       A&=0xF800;
-
-       if(A>=0x8000 && A<=0xb800)
-        DoCHRRAMROM((A-0x8000)>>11,V);
-       else if(A>=0xC000 && A<=0xd800)
-        DoNTARAMROM((A-0xC000)>>11,V);
-        else switch(A)
-       {
-        case 0x4800:
-                  if(dopol&0x40)
-                   {
-                    if(FSettings.SndRate)
-                   {
-                    NamcoSoundHack();
-                     GameExpSound.Fill=NamcoSound;
-                   }
-                   }
-                  MapperExRAM[dopol&0x7f]=V;
-                   if(dopol&0x80)
-                    dopol=(dopol&0x80)|((dopol+1)&0x7f);
-                   break;
-
-        case 0xf800: dopol=V;break;
-        case 0x5000: IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
-        case 0x5800: IRQCount&=0x00ff;IRQCount|=(V&0x7F)<<8;
-                     IRQa=V&0x80;
-                     X6502_IRQEnd(FCEU_IQEXT);
-                     break;
-
-        case 0xE000:gorko=V&0xC0;
-                   //FixNTAR();
-                    ROM_BANK8(0x8000,V);
-                    X6502_Rebase();
-                    break;
-        case 0xE800:gorfus=V&0xC0;
-                   FixCRR();
-                    ROM_BANK8(0xA000,V);
-                    X6502_Rebase();
-                    break;
-        case 0xF000:
-                    ROM_BANK8(0xC000,V);
-                    X6502_Rebase();
-                    break;
-        }
-}
-
-static int dwave=0;
-static void DoNamcoSound(uint32 *Wave, int Count);
-
-static void NamcoSoundHack(void)
-{
- int32 z,a;
-
- z=((SOUNDTS<<16)/soundtsinc)>>4;
- a=z-dwave;
- if(a)
-  DoNamcoSound(&Wave[dwave], a);
- dwave+=a;
-}
-
-static void NamcoSound(int Count)
-{
- int32 z,a;
-
- z=((SOUNDTS<<16)/soundtsinc)>>4;
- a=z-dwave;
- if(a)
-   DoNamcoSound(&Wave[dwave], a);
- dwave=0;
-}
-
-static uint8 PlayIndex[8];
-static int32 vcount[8];
-
-static void DoNamcoSound(uint32 *Wave, int Count)
-{
-       int P,V;
-
-
-      //FCEU_DispMessage("%d",MapperExRAM[0x7F]>>4);
-      for(P=7;P>=7-((MapperExRAM[0x7F]>>4)&7);P--)
-      {
-       if((MapperExRAM[0x44+(P<<3)]&0xE0) && (MapperExRAM[0x47+(P<<3)]&0xF))
-       {
-       uint32 freq;
-       int32 vco;
-       uint32 duff,duff2,lengo,envelope;
-        //uint64 ta;
-
-        vco=vcount[P];
-        freq=MapperExRAM[0x40+(P<<3)];
-        freq|=MapperExRAM[0x42+(P<<3)]<<8;
-        freq|=(MapperExRAM[0x44+(P<<3)]&3)<<16;
-
-        if(!freq) continue;
-
-       {
-        int c=((MapperExRAM[0x7F]>>4)&7)+1;
-
-        inc=(long double)(FSettings.SndRate<<15)/((long double)freq*
-               21477272/((long double)0x400000*c*45));
-       }
-
-        envelope=((MapperExRAM[0x47+(P<<3)]&0xF)<<18)/15;
-        duff=MapperExRAM[(((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])>>1)&0xFF)];
-        if((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&1)
-         duff>>=4;
-        duff&=0xF;
-        duff2=(duff*envelope)>>14;
-
-        lengo=((8-((MapperExRAM[0x44+(P<<3)]>>2)&7)))<<2;
-        for(V=0;V<Count OVERSAMPLE;V++)
-        {
-         if(vco>=inc)
-         {
-          PlayIndex[P]++;
-          if(PlayIndex[P]>=lengo)
-           PlayIndex[P]=0;
-          vco-=inc;
-          duff=MapperExRAM[(((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
-          if((MapperExRAM[0x46+(P<<3)]+PlayIndex[P])&1)
-           duff>>=4;
-          duff&=0xF;
-          duff2=(duff*envelope)>>14;
-         }
-          Wave[V>>4]+=duff2;
-          vco+=0x8000;
-        }
-        vcount[P]=vco;
-       }
-      }
-}
-
-static void Mapper19_StateRestore(int version)
-{
- FixNTAR();
- if(version>=80)
-  FixCRR();
-}
-
-static void M19SC(void)
-{
- if(FSettings.SndRate)
-  Mapper19_ESI();
-}
-
-void Mapper19_ESI(void)
-{
-  GameExpSound.RChange=M19SC;
-  SetWriteHandler(0xf800,0xffff,Mapper19_write);
-  SetWriteHandler(0x4800,0x4fff,Mapper19_write);
-  SetReadHandler(0x4800,0x4fff,Namco_Read4800);
-}
-
-void Mapper19_init(void)
-{
-        if(!Mirroring)
-        {
-         DoNTARAMROM(0,0xE0);
-         DoNTARAMROM(1,0xE0);
-         DoNTARAMROM(2,0xE1);
-         DoNTARAMROM(3,0xE1);
-        }
-        else
-        {
-         DoNTARAMROM(0,0xE0);
-         DoNTARAMROM(2,0xE0);
-         DoNTARAMROM(1,0xE1);
-         DoNTARAMROM(3,0xE1);
-        }
-        VROM_BANK8(~0);
-        SetWriteHandler(0x8000,0xffff,Mapper19_write);
-        SetWriteHandler(0x4020,0x5fff,Mapper19_write);
-        SetReadHandler(0x4800,0x4fff,Namco_Read4800);
-       SetReadHandler(0x5000,0x57ff,Namco_Read5000);
-       SetReadHandler(0x5800,0x5fff,Namco_Read5800);
-
-        MapIRQHook=NamcoIRQHook;
-        MapStateRestore=Mapper19_StateRestore;
-        GameExpSound.RChange=M19SC;
-        if(FSettings.SndRate)
-         Mapper19_ESI();
-        gorfus=0xFF;
-}
-
diff --git a/mappers/193.c b/mappers/193.c
new file mode 100644 (file)
index 0000000..0afa247
--- /dev/null
@@ -0,0 +1,20 @@
+#include "mapinc.h"
+
+static DECLFW(m193w)
+{
+  //printf("$%04x:$%02x\n",A,V);
+ switch(A&3)
+ {
+  case 0:VROM_BANK4(0x0000,V>>2);break;
+  case 1:VROM_BANK2(0x1000,V>>1);break;
+  case 2:VROM_BANK2(0x1800,V>>1);break;
+  case 3:ROM_BANK8(0x8000,V);break;
+ }
+}
+
+void Mapper193_init(void)
+{
+ ROM_BANK32(~0);
+ SetWriteHandler(0x4018,0x7fff,m193w);
+ SetReadHandler(0x4018,0x7fff,0);
+}
diff --git a/mappers/200.c b/mappers/200.c
new file mode 100644 (file)
index 0000000..ec13308
--- /dev/null
@@ -0,0 +1,36 @@
+/* FCE Ultra - NES/Famicom Emulator
+ *
+ * Copyright notice for this file:
+ *  Copyright (C) 2003 CaH4e3
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "mapinc.h"
+
+static DECLFW(Mapper200_write)
+{
+//  FCEU_printf("%04x, %02x\n",A,V);
+  ROM_BANK16(0x8000,A&0x07);
+  ROM_BANK16(0xC000,A&0x07);
+  VROM_BANK8(A&0x07);
+  MIRROR_SET((A&0x08)>>3);
+}
+
+void Mapper200_init(void)
+{
+  SetWriteHandler(0x8000,0xffff,Mapper200_write);
+}
+
diff --git a/mappers/201.c b/mappers/201.c
new file mode 100644 (file)
index 0000000..03e77e6
--- /dev/null
@@ -0,0 +1,44 @@
+/* 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(Mapper201_write)
+{
+//  FCEU_printf("%04x, %02x\n",A,V);
+  if(A&0x08)
+  {
+     ROM_BANK32(A&0x03);
+     VROM_BANK8(A&0x03);
+  }
+  else
+  {
+     ROM_BANK32(0);
+     VROM_BANK8(0);
+  }
+}
+
+void Mapper201_init(void)
+{
+  ROM_BANK32(0);
+  VROM_BANK8(0);
+  SetWriteHandler(0x8000,0xffff,Mapper201_write);
+}
+
diff --git a/mappers/202.c b/mappers/202.c
new file mode 100644 (file)
index 0000000..cac2a88
--- /dev/null
@@ -0,0 +1,39 @@
+/* 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 DECLFW(Mapper202_write)
+{
+ int tmp=(A>>1)&0x7;
+
+ MIRROR_SET(A&1);
+ ROM_BANK16(0x8000,tmp);
+ ROM_BANK16(0xc000,tmp+(((tmp&0x6)==0x6)?1:0));
+ VROM_BANK8(tmp);
+}
+
+void Mapper202_init(void)
+{
+ ROM_BANK16(0x8000,0);
+ ROM_BANK16(0xc000,0);
+ VROM_BANK8(0);
+ SetWriteHandler(0x8000,0xFFFF,Mapper202_write);
+}
diff --git a/mappers/203.c b/mappers/203.c
new file mode 100644 (file)
index 0000000..6ab5d52
--- /dev/null
@@ -0,0 +1,36 @@
+/* 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 DECLFW(Mapper203_write)
+{
+ ROM_BANK16(0x8000,(V>>2)&3);
+ ROM_BANK16(0xc000,(V>>2)&3);
+ VROM_BANK8(V&3);
+}
+
+void Mapper203_init(void)
+{
+ ROM_BANK16(0x8000,0);
+ ROM_BANK16(0xc000,0);
+ VROM_BANK8(0);
+ SetWriteHandler(0x8000,0xFFFF,Mapper203_write);
+}
diff --git a/mappers/204.c b/mappers/204.c
new file mode 100644 (file)
index 0000000..3d79918
--- /dev/null
@@ -0,0 +1,38 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
diff --git a/mappers/208.c b/mappers/208.c
new file mode 100644 (file)
index 0000000..29b7efe
--- /dev/null
@@ -0,0 +1,139 @@
+/* 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 uint8 PRGSel;
+static uint8 PBuf[4],PSel;
+static uint8 cmd;
+static uint8 DRegs[8];
+static uint32 count=0;
+static uint32 last=0;
+
+static DECLFW(M208Write1)
+{
+ PRGSel=(V&0x1)|((V>>3)&0x2);
+ setprg32(0x8000,PRGSel);
+}
+
+static DECLFW(M208Write2)
+{
+ 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
+
+ };
+ if(A<=0x57FF) PSel=V;
+ else
+  PBuf[(A&0x03)]=V^lut[PSel];
+}
+
+static DECLFR(M208Read)
+{
+ return(PBuf[(A&0x3)]);
+}
+
+static void Sync(void)
+{
+ int x;
+
+ setchr2(0x0000,DRegs[0]>>1);
+ setchr2(0x0800,DRegs[1]>>1);
+ for(x=0;x<4;x++)
+  setchr1(0x1000+x*0x400,DRegs[2+x]);
+}
+
+static DECLFW(M208HWrite)
+{
+ switch(A&0xe001)
+ {
+  case 0xc000:IRQLatch=IRQCount=V;break;
+  case 0xc001:IRQCount=IRQLatch;last=count=0;break;
+  case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
+  case 0xe001:IRQa=1;break;
+  case 0x8000:cmd=V;break;
+  case 0x8001:DRegs[cmd&7]=V;
+                Sync();
+                break;
+
+ }
+}
+
+static void M208Power(void)
+{
+ PRGSel=3;
+ setprg32(0x8000,3);
+ SetWriteHandler(0x4800,0x4FFF,M208Write1);
+ SetWriteHandler(0x5000,0x5fff,M208Write2);
+ SetWriteHandler(0x8000,0xFFFF,M208HWrite);
+ SetReadHandler(0x5800,0x5FFF,M208Read);
+ SetReadHandler(0x8000,0xffff,CartBR);
+}
+
+static void sl(void)
+{
+ if(IRQa)
+ {
+  if(IRQCount>=0)
+  {
+   IRQCount--;
+   if(IRQCount<0)
+   {
+    X6502_IRQBegin(FCEU_IQEXT);
+   }
+  }
+ }
+}
+
+static void FP_FASTAPASS(1) foo(uint32 A)
+{
+ if((A&0x2000) && !(last&0x2000))
+ {
+  count++;
+  if(count==42)
+  {
+   sl();
+   count=0;
+  }
+ }
+ last=A;
+}
+
+void Mapper208_Init(CartInfo *info)
+{
+ info->Power=M208Power;
+ //GameHBIRQHook=sl;
+ PPU_hook=foo;
+}
+
index ba20a86..8d60d4c 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -28,24 +28,20 @@ static int acount=0;
 
 DECLFW(Mapper21_write)
 {
-       A|=((A>>5)&0xF);
+        A|=((A>>5)&0xF);
 
-       if((A&0xF000)==0xA000)
-       {
-         ROM_BANK8(0xA000,V);
-          X6502_Rebase();
-       }
-       else if((A&0xF000)==0x8000)
-       {
+        if((A&0xF000)==0xA000)
+          ROM_BANK8(0xA000,V);
+        else if((A&0xF000)==0x8000)
+        {
          if(K4sel&2)
           ROM_BANK8(0xC000,V);
          else
           ROM_BANK8(0x8000,V);
-         X6502_Rebase();
-       }
-       else if(A>=0xb000 && A<=0xefff)
-       {
-         A&=0xF006;
+         }
+        else if(A>=0xb000 && A<=0xefff)
+        {
+          A&=0xF006;
           {
            int x=((A>>2)&1)|((A-0xB000)>>11);
 
@@ -54,47 +50,50 @@ DECLFW(Mapper21_write)
            VROM_BANK1(x<<10,K4buf[x]);
           }
 
-       }
-       else switch(A&0xF006)
+        }
+        else switch(A&0xF006)
         {
-        case 0x9000:
-                    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;
-        case 0x9006:
-        case 0x9004:
-        case 0x9002:if((K4sel&2)!=(V&2))
-                    {
-                     uint8 swa;
-                     swa=PRGBankList[0];
-                     ROM_BANK8(0x8000,PRGBankList[2]);
-                     ROM_BANK8(0xc000,swa);
-                     X6502_Rebase();
-                    }
-                    K4sel=V;
-                    break;
-        case 0xf000:IRQLatch&=0xF0;IRQLatch|=V&0xF;break;
+         case 0x9000:
+                     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;
+         case 0x9006:
+         case 0x9004:
+         case 0x9002:if((K4sel&2)!=(V&2))
+                     {
+                           uint8 swa;
+                      swa=PRGBankList[0];
+                       ROM_BANK8(0x8000,PRGBankList[2]);
+                      ROM_BANK8(0xc000,swa);
+                      }
+                     K4sel=V;
+                     break;
+         case 0xf000:IRQLatch&=0xF0;IRQLatch|=V&0xF;break;
          case 0xf002:IRQLatch&=0x0F;IRQLatch|=V<<4;break;
-        case 0xf004:IRQCount=IRQLatch;
-                    IRQa=V&2;K4IRQ=V&1;break;
-        case 0xf006:IRQa=K4IRQ;break;
+         case 0xf004:IRQCount=IRQLatch;acount=0;
+                     IRQa=V&2;K4IRQ=V&1;
+                     X6502_IRQEnd(FCEU_IQEXT);
+                     break;
+         case 0xf006:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break;
  }
 }
 static void FP_FASTAPASS(1) KonamiIRQHook(int a)
 {
-  #define LCYCS 114
+  #define LCYCS ((227*2)+1)
+  //#define LCYCS 341
   if(IRQa)
-   {
-    acount+=a;
+  {
+//    acount+=a*3;
+    acount+=a*4;
     if(acount>=LCYCS)
     {
      doagainbub:acount-=LCYCS;IRQCount++;
-     if(IRQCount&0x100) {TriggerIRQ();IRQCount=IRQLatch;}
+     if(IRQCount&0x100) {X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;}
      if(acount>=LCYCS) goto doagainbub;
     }
  }
diff --git a/mappers/211.c b/mappers/211.c
new file mode 100644 (file)
index 0000000..5e6c5b2
--- /dev/null
@@ -0,0 +1,146 @@
+#include "mapinc.h"\r
+\r
+static uint8 mul[2];\r
+static uint8 regie;\r
+#define tkcom1 mapbyte1[1]\r
+#define tkcom2 mapbyte1[2]\r
+#define tkcom3 mapbyte1[3]\r
+\r
+#define prgb        mapbyte2\r
+#define chr     mapbyte3\r
+\r
+static uint16 names[4];\r
+static uint8  tekker;\r
+\r
+static DECLFR(tekread)\r
+{\r
+// FCEU_printf("READ READ READ: $%04x, $%04x, $%04x\n",A,X.PC,tekker);\r
+ switch(A)\r
+ {\r
+  case 0x5000:return(tekker);\r
+  case 0x5800:return(mul[0]*mul[1]);\r
+  case 0x5801:return((mul[0]*mul[1])>>8);\r
+  case 0x5803:return(regie);\r
+  default:break;\r
+ }\r
+ return(X.DB);\r
+}\r
+\r
+static void mira(void)\r
+{\r
+  int x;\r
+  if(tkcom1&0x40)        // Name tables are ROM-only\r
+  {\r
+   for(x=0;x<4;x++)\r
+    setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10), 0, x);\r
+  }\r
+  else                        // Name tables can be RAM or ROM.\r
+  {\r
+  for(x=0;x<4;x++)\r
+  {\r
+   if(((tkcom3&0x80)==(names[x]&0x80)))        // RAM selected.\r
+    setntamem(NTARAM + ((names[x]&0x1)<<10),1,x);\r
+   else\r
+    setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10), 0, x);\r
+  }\r
+  }\r
+}\r
+\r
+static void tekprom(void)\r
+{\r
+ switch(tkcom1&3)\r
+  {\r
+   case 1:              // 16 KB\r
+          ROM_BANK16(0x8000,prgb[0]);\r
+          ROM_BANK16(0xC000,prgb[2]);\r
+          break;\r
+\r
+   case 2:              //2 = 8 KB ??\r
+          ROM_BANK8(0x8000,prgb[0]);\r
+          ROM_BANK8(0xa000,prgb[1]);\r
+          ROM_BANK8(0xc000,prgb[2]);\r
+          ROM_BANK8(0xe000,~0);\r
+               break;\r
+  }\r
+}\r
+\r
+static void tekvrom(void)\r
+{\r
+ int x;\r
+ switch(tkcom1&0x18)\r
+  {\r
+   case 0x00:      // 8KB\r
+           setchr8(chr[0]);\r
+               break;\r
+   case 0x08:      // 4KB\r
+          for(x=0;x<8;x+=4)\r
+           setchr4(x<<10,chr[x]);\r
+              break;\r
+   case 0x10:      // 2KB\r
+              for(x=0;x<8;x+=2)\r
+           setchr2(x<<10,chr[x]);\r
+              break;\r
+   case 0x18:      // 1KB\r
+              for(x=0;x<8;x++)\r
+               setchr1(x<<10,chr[x]);\r
+              break;\r
+ }\r
+}\r
+\r
+static DECLFW(Mapper211_write)\r
+{\r
+ if(A==0x5800) mul[0]=V;\r
+ else if(A==0x5801) mul[1]=V;\r
+ else if(A==0x5803) regie=V;\r
+\r
+ A&=0xF007;\r
+ if(A>=0x8000 && A<=0x8003)\r
+ {\r
+  prgb[A&3]=V;\r
+  tekprom();\r
+ }\r
+ else if(A>=0x9000 && A<=0x9007)\r
+ {\r
+  chr[A&7]=V;\r
+  tekvrom();\r
+ }\r
+ else if(A>=0xb000 && A<=0xb007)\r
+ {\r
+   names[A&3]=V&3;\r
+   mira();\r
+ }\r
+ else switch(A)\r
+ {\r
+   case 0xc002:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;\r
+   case 0xc003:\r
+   case 0xc004:if(!IRQa) {IRQa=1;IRQCount=IRQLatch;} break;\r
+   case 0xc005:IRQCount=IRQLatch=V;\r
+               X6502_IRQEnd(FCEU_IQEXT);break;\r
+   case 0xd000: tkcom1=V; mira(); break;\r
+   case 0xd001: tkcom3=V; mira(); break;\r
+ }\r
+}\r
+\r
+static void Mapper211_hb(void)\r
+{\r
+ if(IRQCount) IRQCount--;\r
+ if(!IRQCount)\r
+ {\r
+  if(IRQa) X6502_IRQBegin(FCEU_IQEXT);\r
+  IRQa=0;\r
+ }\r
+}\r
+static void togglie()\r
+{\r
+  tekker^=0xFF;\r
+}\r
+\r
+void Mapper211_init(void)\r
+{\r
+  tekker=0xFF;\r
+  MapperReset=togglie;\r
+  SetWriteHandler(0x5000,0xffff,Mapper211_write);\r
+  SetReadHandler(0x5000,0x5fff,tekread);\r
+  GameHBIRQHook=Mapper211_hb;\r
+}\r
+\r
diff --git a/mappers/212.c b/mappers/212.c
new file mode 100644 (file)
index 0000000..b069fc3
--- /dev/null
@@ -0,0 +1,23 @@
+#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
diff --git a/mappers/213.c b/mappers/213.c
new file mode 100644 (file)
index 0000000..e0b8d82
--- /dev/null
@@ -0,0 +1,14 @@
+#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
diff --git a/mappers/214.c b/mappers/214.c
new file mode 100644 (file)
index 0000000..03a73ce
--- /dev/null
@@ -0,0 +1,17 @@
+#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
diff --git a/mappers/215.c b/mappers/215.c
new file mode 100644 (file)
index 0000000..772691c
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+#include "mapinc.h"
+
+static uint8 cmdin;
+static uint8 cmd;
+static uint8 regs[8];
+static uint8 master,chrm;
+
+static void DoPRG215(void)
+{
+ if(master&0x80)
+ {
+   setprg16(0x8000,master&0x1F);
+   setprg16(0xc000,master&0x1F);
+ }
+ else
+ {
+   setprg8(0x8000,regs[4]); 6
+   setprg8(0xA000,regs[6]); 7   0, 2, 5, 3, 6, 1, 7, 4
+   setprg8(0xC000,~1);
+   setprg8(0xE000,~0);
+ }
+
+}
+
+static void DoCHR215(void)
+{
+ uint32 base=(cmd&0x80)<<5;
+ int orie=(chrm&0x4)<<6;
+
+ setchr2(0x0000^base,(orie|regs[0])>>1); 0
+ setchr2(0x0800^base,(orie|regs[5])>>1); 1
+
+ setchr1(0x1000,orie|regs[1]); 2
+ setchr1(0x1400,orie|regs[3]); 3
+ setchr1(0x1800,orie|regs[7]); 4
+ setchr1(0x1c00,orie|regs[2]); 5
+}
+
+static DECLFW(Write215_write)
+{
+ switch(A&0xF001)
+ {
+  case 0xF001:IRQCount=V+2;break;
+  case 0xF000:X6502_IRQEnd(FCEU_IQEXT);break;
+ }
+ if(A==0x5000)
+ {
+  master=V;
+  DoPRG215();
+//  DoCHR215();
+ }
+ else if(A==0x5001)
+ {
+  chrm=V;
+  DoCHR215();
+ }
+ else
+ switch(A&0xE001)
+ {
+  case 0xC000:setmirror(((V|(V>>7))&1)^1);break;
+  case 0xa000:cmd=V;cmdin=1;DoCHR215();break;
+  case 0x8001:if(!cmdin) break;
+              regs[cmd&7]=V;
+              DoPRG215();
+              DoCHR215();
+              cmdin=0;
+              break;
+ }
+}
+
+static void hooko215(void)
+{
+ if(IRQCount)
+ {
+  IRQCount--;
+  if(!IRQCount)
+  {
+     X6502_IRQBegin(FCEU_IQEXT);
+  }
+ }
+}
+
+void Mapper215_init(void)
+{
+  int x;
+  for(x=0;x<8;x++) regs[x]=0;
+  master=chrm=cmd=cmdin=IRQCount=0;
+  GameHBIRQHook=hooko215;
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x5000,0xFFFF,Write215_write);
+  DoPRG215();
+  DoCHR215();
+}
+
+*/
diff --git a/mappers/217.c b/mappers/217.c
new file mode 100644 (file)
index 0000000..6f7a251
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+#include "mapinc.h"
+
+static uint8 cmdin;
+static uint8 cmd;
+static uint8 regs[8];
+static uint8 master,chrm;
+
+static void DoPRG217(void)
+{
+ if(master&0x80)
+ {
+   setprg16(0x8000,master&0x1F);
+   setprg16(0xc000,master&0x1F);
+ }
+ else
+ {
+   setprg8(0x8000,regs[1]);
+   setprg8(0xA000,regs[3]);
+   setprg8(0xC000,~1);
+   setprg8(0xE000,~0);
+ }
+}
+
+static void DoCHR217(void)
+{
+ uint32 base=(cmd&0x80)<<5;
+ int orie=(chrm&0x4)<<6;
+
+ setchr2(0x0000^base,(orie|regs[0])>>1);
+ setchr2(0x0800^base,(orie|regs[7])>>1);
+
+ setchr1(0x1000,orie|regs[5]);
+ setchr1(0x1400,orie|regs[2]);
+ setchr1(0x1800,orie|regs[6]);
+ setchr1(0x1c00,orie|regs[4]);
+}
+
+static DECLFW(Write217_write)
+{
+// if(A==0x5000)
+// {
+//  master=V;
+//  DoPRG217();
+// }
+// else if(A==0x5001)
+// {
+//  chrm=V;
+//  DoCHR217();
+// }
+// else if(A==0x5007)
+// {
+// }
+
+ switch(A&0xE001)
+ {
+  case 0x4000:master=V;DoPRG217();break;
+  case 0x8000:IRQCount=V;break;
+  case 0xc001:break;
+  case 0xe000:X6502_IRQEnd(FCEU_IQEXT);break;
+  case 0xe001:break;
+  case 0xa001:setmirror((V&1)^1);break;
+  case 0x8001:cmd=V;cmdin=1;DoPRG217();DoCHR217();break;
+  case 0xa000:if(!cmdin) break;
+              regs[cmd&7]=V;
+              DoPRG217();
+              DoCHR217();
+              cmdin=0;
+              break;
+ }
+}
+
+static void hooko217(void)
+{
+ if(IRQCount)
+ {
+  IRQCount--;
+  if(!IRQCount)
+  {
+     X6502_IRQBegin(FCEU_IQEXT);
+  }
+ }
+}
+
+void Mapper217_init(void)
+{
+  int x;
+  for(x=0;x<8;x++) regs[x]=0;
+  master=chrm=cmd=cmdin=IRQCount=0;
+  GameHBIRQHook=hooko217;
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x5000,0xFFFF,Write217_write);
+  DoPRG217();
+  DoCHR217();
+}
+*/
\ No newline at end of file
index a40e05f..4a08094 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -30,12 +30,10 @@ DECLFW(Mapper22_write)
          {
           switch(A&0xF000)
           {
-          case 0x8000:ROM_BANK8(0x8000,V);
-                      X6502_Rebase();break;
-          case 0xa000:ROM_BANK8(0xA000,V);
-                      X6502_Rebase();break;
+          case 0x8000:ROM_BANK8(0x8000,V);break;
+          case 0xa000:ROM_BANK8(0xA000,V);break;
           case 0x9000:switch(V&3)
-                     {
+                      {
                        case 0x00:MIRROR_SET2(1);break;
                        case 0x01:MIRROR_SET2(0);break;
                        case 0x02:onemir(0);break;
@@ -46,20 +44,20 @@ DECLFW(Mapper22_write)
          }
         else
         {
-         A&=0xF003;
-         if(A>=0xb000 && A<=0xe003)
-         {
-          int x=(A&1)|((A-0xB000)>>11);
+          A&=0xF003;
+          if(A>=0xb000 && A<=0xe003)
+          {
+           int x=(A&1)|((A-0xB000)>>11);
 
-          K4buf[x]&=(0xF0)>>((A&2)<<1);
-          K4buf[x]|=(V&0xF)<<((A&2)<<1);
-          VROM_BANK1(x<<10,K4buf[x]>>1);
-         }
+           K4buf[x]&=(0xF0)>>((A&2)<<1);
+           K4buf[x]|=(V&0xF)<<((A&2)<<1);
+           VROM_BANK1(x<<10,K4buf[x]>>1);
+          }
         }
 }
 
 
 void Mapper22_init(void)
 {
-       SetWriteHandler(0x8000,0xffff,Mapper22_write);
+        SetWriteHandler(0x8000,0xffff,Mapper22_write);
 }
index 23992fc..14e38f2 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -76,7 +76,6 @@ DECLFW(Mapper225_write)
   {
     ROM_BANK32(((((A>>7)&0x1F)+(banks<<5))));
   }
-  X6502_Rebase();
 }
 
 void Mapper225_init(void)
index 45dc067..bde4f52 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -31,7 +31,6 @@ static void DoPRG(void)
   }
   else
    ROM_BANK32(b);
-  X6502_Rebase();
 }
 
 static DECLFW(Mapper226_write)
@@ -75,7 +74,7 @@ void Mapper226_init(void)
   M26Reset();
 }
 
-#ifdef OLD     // What the heck is this??
+#ifdef OLD        // What the heck is this??
 DECLFW(Mapper226_write)
 {
  MIRROR_SET((A>>13)&1);
index 2754369..457e79e 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -30,11 +30,11 @@ static void DoSync(uint32 A)
  rg[1]=A>>8;
 
  MIRROR_SET((A>>1)&1);
- if(A&1)       //32 KB
+ if(A&1)        //32 KB
  {
   ROM_BANK32(p);
  }
- else          //16 KB
+ else                //16 KB
  {
   ROM_BANK16(0x8000,(p<<1)|((A&4)>>2));
   ROM_BANK16(0xc000,(p<<1)|((A&4)>>2));
@@ -51,7 +51,6 @@ static void DoSync(uint32 A)
   else
    ROM_BANK16(0xC000,(p<<1)&(~7));
  }
- X6502_Rebase();
 }
 
 static DECLFW(Mapper227_write)
@@ -73,7 +72,7 @@ static void M227Restore(int version)
 
 void Mapper227_init(void)
 {
-  SetWriteHandler(0x8000,0xffff,Mapper227_write);
+  SetWriteHandler(0x6000,0xffff,Mapper227_write);
   MapperReset=M227Reset;
   GameStateRestore=M227Restore;
   M227Reset();
index e38063d..bfae3a6 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -27,16 +27,16 @@ static DECLFW(Mapper228_write)
  MIRROR_SET((A>>13)&1);
 
  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;
 
  ROM_BANK16(0x8000,pagel);
  ROM_BANK16(0xC000,pageh);
  VROM_BANK8( (V&0x3) | ((A&0xF)<<2) );
- X6502_Rebase();
 }
 
 static void A52Reset(void)
index 46c898b..a78dd73 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -37,7 +37,6 @@ else
  ROM_BANK16(0xC000,A&0x1f);
  }
  VROM_BANK8(A);
- X6502_Rebase();
 }
 
 }
index db96e8e..d61a555 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -23,8 +23,8 @@
 #define K4buf mapbyte2
 #define K4IRQ mapbyte1[1]
 #define K4sel mapbyte1[0]
-
-DECLFW(Mapper23_write)
+static int acount=0;
+static DECLFW(Mapper23_write)
 {
  if((A&0xF000)==0x8000)
  {
@@ -32,13 +32,9 @@ DECLFW(Mapper23_write)
    ROM_BANK8(0xC000,V);
   else
    ROM_BANK8(0x8000,V);
-  X6502_Rebase();
- }
+  }
   else if((A&0xF000)==0xA000)
-  {
    ROM_BANK8(0xA000,V);
-   X6502_Rebase();
-  }
   else
   {
    A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3);
@@ -56,7 +52,7 @@ DECLFW(Mapper23_write)
     {
      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);IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;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:
@@ -67,34 +63,34 @@ DECLFW(Mapper23_write)
                   swa=PRGBankList[0];
                   ROM_BANK8(0x8000,PRGBankList[2]);
                   ROM_BANK8(0xc000,swa);
-                  X6502_Rebase();
                  }
                  K4sel=V;
                  break;
      case 0x9000:
-               switch(V&0x3)
-               {
+            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;
+                      case 1:MIRROR_SET(1);break;
+                     case 2:onemir(0);break;
+                     case 3:onemir(1);break;
+                }
+                break;
   }
  }
 }
 
 void FP_FASTAPASS(1) KonamiIRQHook2(int a)
 {
-  static int acount=0;
+  #define LCYCS 341
   if(IRQa)
-   {
-    acount+=(a<<1)+a;
-    if(acount>=342)
+  {
+   acount+=a*3;
+    if(acount>=LCYCS)
     {
-     doagainbub:acount-=342;IRQCount++;
+     doagainbub:acount-=LCYCS;IRQCount++;
      if(IRQCount&0x100) {X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;}
-     if(acount>=342) goto doagainbub;
+     if(acount>=LCYCS) goto doagainbub;
     }
  }
 }
diff --git a/mappers/230.c b/mappers/230.c
new file mode 100644 (file)
index 0000000..cbf1fbe
--- /dev/null
@@ -0,0 +1,62 @@
+/* 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"
+
+#define rom_sw mapbyte1[0]
+
+void Mapper230_Reset(void)
+{
+        rom_sw ^= 1; //1 - rom_sw;
+
+        if( rom_sw ) {
+                ROM_BANK16(0x8000,0);
+                ROM_BANK16(0xc000,7);
+        } else {
+                ROM_BANK16(0x8000,8);
+                ROM_BANK16(0xc000,39);
+        }
+        MIRROR_SET2(1);
+}
+
+static DECLFW(Mapper230_write)
+{
+        if( rom_sw ) {
+                ROM_BANK16( 0x8000, V&0x07 );
+        } else {
+                if( V & 0x20 ) {
+                        ROM_BANK16( 0x8000, (V&0x1F)+8 );
+                        ROM_BANK16( 0xc000, (V&0x1F)+8 );
+                } else {
+                        ROM_BANK32( ((V&0x1E) >> 1) + 4 );
+                }
+                MIRROR_SET2( ((V & 0x40) >> 6) );
+        }
+}
+
+void Mapper230_init(void)
+{
+        ROM_BANK16(0x8000,0);
+        ROM_BANK16(0xc000,7);
+        SetWriteHandler(0x8000, 0xffff, Mapper230_write);
+        MapperReset = Mapper230_Reset;
+        rom_sw = 1;
+}
+
diff --git a/mappers/231.c b/mappers/231.c
new file mode 100644 (file)
index 0000000..9b8d1fc
--- /dev/null
@@ -0,0 +1,41 @@
+/* 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 DECLFW(Mapper231_write)
+{
+ if(A&0x20)
+  ROM_BANK32((A>>1)&0xF);
+ else
+ {
+  ROM_BANK16(0x8000,(A&0x1E));
+  ROM_BANK16(0xc000,(A&0x1E));
+ }
+ MIRROR_SET((A>>7)&1);
+}
+
+void Mapper231_init(void)
+{
+   ROM_BANK16(0x8000,0);
+   ROM_BANK16(0xc000,0);
+   SetWriteHandler(0x8000,0xffff,Mapper231_write);
+}
+
index 5084ba4..548db8c 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -24,16 +24,15 @@ static void DoIt(void)
 {
   ROM_BANK16(0x8000,(mapbyte1[1]&3) | ((mapbyte1[0]&0x18)>>1));
   ROM_BANK16(0xc000,3|(((mapbyte1[0])&0x18)>>1));
-  X6502_Rebase();
 }
 
 DECLFW(Mapper232_write)
 {
-       if(A<=0x9FFF)
-        mapbyte1[0]=V;
-       else
-        mapbyte1[1]=V;
-       DoIt();
+        if(A<=0x9FFF)
+         mapbyte1[0]=V;
+        else
+         mapbyte1[1]=V;
+        DoIt();
 }
 
 static void QuattroReset(void)
index 4a2b9ee..d8ca53f 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -35,7 +35,6 @@ static void DoBS(void)
   ROM_BANK32(r1&0xF);
   VROM_BANK8( ((r1&0xF)<<2) | ((r2>>4)&3) );
  }
- X6502_Rebase();
 }
 
 static void R1Set(uint8 V)
@@ -92,17 +91,17 @@ static void M15Reset(void)
 void Mapper234_init(void)
 {
         SetWriteHandler(0xff80,0xff9f,R1W);
-       SetReadHandler(0xff80,0xff9f,R1R);
+        SetReadHandler(0xff80,0xff9f,R1R);
 
-       SetWriteHandler(0xffe8,0xfff7,R2W);
-       SetReadHandler(0xffe8,0xfff7,R2R);
+        SetWriteHandler(0xffe8,0xfff7,R2W);
+        SetReadHandler(0xffe8,0xfff7,R2R);
 
-       SetReadHandler(0x6000,0x7FFF,0);
-       SetWriteHandler(0x6000,0x7FFF,0);
+        SetReadHandler(0x6000,0x7FFF,0);
+        SetWriteHandler(0x6000,0x7FFF,0);
 
-       M15Reset();
+        M15Reset();
 
-       GameStateRestore=M15Restore;
-       MapperReset=M15Reset;
+        GameStateRestore=M15Restore;
+        MapperReset=M15Reset;
 }
 
diff --git a/mappers/235.c b/mappers/235.c
new file mode 100644 (file)
index 0000000..e54907e
--- /dev/null
@@ -0,0 +1,54 @@
+/* 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(Mapper235_write)
+{
+  uint32 m;
+  int z;
+
+  if(A&0x400)
+   onemir(0);
+  else
+   setmirror(((A>>13)&1)^1);
+  m=A&0x1f;
+
+  z=(A>>8)&3;
+
+   if(A&0x800)
+   {
+    setprg16r(0x10|z,0x8000,(m<<1)|((A>>12)&1));
+    setprg16r(0x10|z,0xC000,(m<<1)|((A>>12)&1));
+
+   }
+   else
+    setprg32r(0x10|z,0x8000,m);
+}
+
+void Mapper235_init(void)
+{
+ /* Fixme:  Possible crashy bug if header is bad. */
+ SetupCartPRGMapping(0x10,PRGptr[0],1024*1024,0);
+ SetupCartPRGMapping(0x12,PRGptr[0]+1024*1024,1024,0);
+ setprg32r(0x10,0x8000,0);
+ SetReadHandler(0x8000,0xffff,CartBROB);
+ SetWriteHandler(0x8000,0xffff,Mapper235_write);
+}
index 0869349..dbbfe19 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -28,7 +28,6 @@ DECLFW(Mapper240_write)
  {
   ROM_BANK32(V>>4);
   VROM_BANK8(V&0xF);
-  X6502_Rebase();
  }
 }
 
diff --git a/mappers/241.c b/mappers/241.c
new file mode 100644 (file)
index 0000000..c0fe7fe
--- /dev/null
@@ -0,0 +1,27 @@
+#include "mapinc.h"
+
+static DECLFW(M241wr)
+{
+//  FCEU_printf("Wr: $%04x:$%02x, $%04x\n",A,V,X.PC);
+ if(A<0x8000)
+ {
+// printf("$%04x:$%02x, $%04x\n",A,V,X.PC);
+ }
+ else
+  ROM_BANK32(V);
+}
+
+static DECLFR(M241rd)
+{
+ //DumpMem("out",0x8000,0xffff);
+ //printf("Rd: $%04x, $%04x\n",A,X.PC);
+ return(0x50);
+}
+
+void Mapper241_init(void)
+{
+ ROM_BANK32(0);
+ SetWriteHandler(0x5000,0x5fff,M241wr);
+ SetWriteHandler(0x8000,0xFFFF,M241wr);
+ SetReadHandler(0x4020,0x5fff,M241rd);
+}
index 3b4dced..2fa4171 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -24,7 +24,6 @@
 DECLFW(Mapper242_write)
 {
   ROM_BANK32((A>>3)&0xF);
-  X6502_Rebase();
   switch(V&3)
   {
    case 0:MIRROR_SET(0);break;
diff --git a/mappers/244.c b/mappers/244.c
new file mode 100644 (file)
index 0000000..13ea2c1
--- /dev/null
@@ -0,0 +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(Mapper244_write_1)
+{
+  ROM_BANK32((A-0x8065)&0x03);
+}
+
+static DECLFW(Mapper244_write_2)
+{
+  VROM_BANK8((A-0x80A5)&0x07);
+}
+
+void Mapper244_init(void)
+{
+  ROM_BANK32(0);
+  SetWriteHandler(0x8065,0x80a4,Mapper244_write_1);
+  SetWriteHandler(0x80a5,0x80e4,Mapper244_write_2);
+}
index d36b277..8623233 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -25,14 +25,10 @@ DECLFW(Mapper246_write)
 {
  switch(A&0xF007)
  {
- case 0x6000:ROM_BANK8(0x8000,V);
-             X6502_Rebase();break;
- case 0x6001:ROM_BANK8(0xA000,V);
-             X6502_Rebase();break;
- case 0x6002:ROM_BANK8(0xC000,V);
-             X6502_Rebase();break;
- case 0x6003:ROM_BANK8(0xE000,V);
-             X6502_Rebase();break;
+ case 0x6000:ROM_BANK8(0x8000,V);break;
+ case 0x6001:ROM_BANK8(0xA000,V);break;
+ case 0x6002:ROM_BANK8(0xC000,V);break;
+ case 0x6003:ROM_BANK8(0xE000,V);break;
  case 0x6004:VROM_BANK2(0x0000,V);break;
  case 0x6005:VROM_BANK2(0x0800,V);break;
  case 0x6006:VROM_BANK2(0x1000,V);break;
diff --git a/mappers/248.c b/mappers/248.c
deleted file mode 100644 (file)
index e2dff8c..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 cmd mapbyte1[0]
-#define lpa mapbyte1[1]
-#define prgl mapbyte2
-
-static void PRGSynco(void)
-{
- if(lpa&0x80)
- {
-  ROM_BANK16(0x8000,lpa&0xF);
- }
- else
- {
-  ROM_BANK8(0x8000,prgl[0]&0x1F);
-  ROM_BANK8(0xa000,prgl[1]&0x1F);
- }
- X6502_Rebase();
-}
-
-static DECLFW(Mapper248_writelow)
-{
- lpa=V;
- PRGSynco();
-}
-
-static DECLFW(Mapper248_write)
-{
- switch(A&0xF001)
- {
-  case 0xa000:MIRROR_SET(V&1);break; // Not sure if this is right.  Mirroring may be hard wired...
-  case 0xc000:IRQLatch=V;break;
-  case 0xc001:IRQCount=IRQLatch;break;
-  case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
-  case 0xe001:IRQa=1;break;
-  case 0x8000:cmd=V;break;
-  case 0x8001:switch(cmd&7)
-             {
-              case 0:VROM_BANK2(0x000,V>>1);break;
-              case 1:VROM_BANK2(0x800,V>>1);break;
-              case 2:VROM_BANK1(0x1000,V);break;
-              case 3:VROM_BANK1(0x1400,V);break;
-              case 4:VROM_BANK1(0x1800,V);break;
-              case 5:VROM_BANK1(0x1c00,V);break;
-              case 6:prgl[0]=V;PRGSynco();break;
-              case 7:prgl[1]=V;PRGSynco();break;
-             }
-             break;
- }
-}
-
-static void Mapper248_hb(void)
-{
- if(IRQa)
- {
-         IRQCount--;
-         if(IRQCount<0)
-         {
-         X6502_IRQBegin(FCEU_IQEXT);
-         IRQCount=IRQLatch;
-         }
- }
-}
-
-void Mapper248_init(void)
-{
-  SetWriteHandler(0x6000,0x6fff,Mapper248_writelow);
-  SetWriteHandler(0x8000,0xffff,Mapper248_write);
-  GameHBIRQHook=Mapper248_hb;
-}
-
index 50f732a..3368856 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
+static void (*sfun[3])(void);
+
 #define vrctemp mapbyte1[0]
-#define regb000 mapbyte3[0]
-#define regb001 mapbyte3[1]
-#define regb002 mapbyte3[2]
-#define exchstat mapbyte4[0]
 #define VPSG2 mapbyte3
 #define VPSG mapbyte2
 
@@ -33,81 +31,74 @@ static void DoSQV2(void);
 static void DoSawV(void);
 
 static int swaparoo;
-static int32 inc;
-static DECLFW(VRC6PSGW90)
-{
- DoSQV1();VPSG[0]=V;
-}
-static DECLFW(VRC6PSGW91)
-{
- DoSQV1();VPSG[2]=V;
-}
-static DECLFW(VRC6PSGW92)
-{
- DoSQV1();VPSG[3]=V;
-}
-static DECLFW(VRC6PSGWA0)
-{
- DoSQV2();VPSG[4]=V;
-}
-static DECLFW(VRC6PSGWA1)
-{
- DoSQV2();VPSG[6]=V;
-}
-static DECLFW(VRC6PSGWA2)
-{
- DoSQV2();VPSG[7]=V;
-}
-static DECLFW(VRC6PSGWB0)
-{
- DoSawV();VPSG2[0]=V;
-}
-static DECLFW(VRC6PSGWB1)
-{
- DoSawV();VPSG2[1]=V;
-}
-static DECLFW(VRC6PSGWB2)
-{
- DoSawV();VPSG2[2]=V;
-}
 
 static int acount=0;
 
 static void FP_FASTAPASS(1) KonamiIRQHook(int a)
 {
-  #define LCYCS 114
+  #define LCYCS 341
+//  #define LCYCS ((227*2)+1)
   if(IRQa)
   {
-   acount+=a;
+   acount+=a*3;
    if(acount>=LCYCS)
    {
     doagainbub:acount-=LCYCS;IRQCount++;
-    if(IRQCount==0x100) {TriggerIRQ();IRQCount=IRQLatch;}
+    if(IRQCount==0x100)
+    {
+     X6502_IRQBegin(FCEU_IQEXT);
+     IRQCount=IRQLatch;
+    }
     if(acount>=LCYCS) goto doagainbub;
    }
  }
 }
 
-DECLFW(Mapper24_write)
+static DECLFW(VRC6SW)
 {
-       if(swaparoo)
-        A=(A&0xFFFC)|((A>>1)&1)|((A<<1)&2);
+        A&=0xF003;
+        if(A>=0x9000 && A<=0x9002)
+        {
+         VPSG[A&3]=V;
+         if(sfun[0]) sfun[0]();
+        }
+        else if(A>=0xa000 && A<=0xa002)
+        {
+         VPSG[4|(A&3)]=V;
+         if(sfun[1]) sfun[1]();
+        }
+        else if(A>=0xb000 && A<=0xb002)
+        {
+         VPSG2[A&3]=V;
+         if(sfun[2]) sfun[2]();
+        }
 
+}
+
+static DECLFW(Mapper24_write)
+{
+        if(swaparoo)
+         A=(A&0xFFFC)|((A>>1)&1)|((A<<1)&2);
+        if(A>=0x9000 && A<=0xb002)
+        {
+         VRC6SW(A,V);
+         return;
+        }
+        A&=0xF003;
+//        if(A>=0xF000) printf("%d, %d, $%04x:$%02x\n",scanline,timestamp,A,V);
         switch(A&0xF003)
-       {
-         case 0x8000:ROM_BANK16(0x8000,V);
-                     X6502_Rebase();break;
+        {
+         case 0x8000:ROM_BANK16(0x8000,V);break;
          case 0xB003:
-                switch(V&0xF)
-                {
-                 case 0x0:MIRROR_SET2(1);break;
-                 case 0x4:MIRROR_SET2(0);break;
-                 case 0x8:onemir(0);break;
-                 case 0xC:onemir(1);break;
-                }
-                break;
-         case 0xC000:ROM_BANK8(0xC000,V);
-                     X6502_Rebase();break;
+                    switch(V&0xF)
+                 {
+                  case 0x0:MIRROR_SET2(1);break;
+                  case 0x4:MIRROR_SET2(0);break;
+                  case 0x8:onemir(0);break;
+                  case 0xC:onemir(1);break;
+                 }
+                 break;
+         case 0xC000:ROM_BANK8(0xC000,V);break;
          case 0xD000:VROM_BANK1(0x0000,V);break;
          case 0xD001:VROM_BANK1(0x0400,V);break;
          case 0xD002:VROM_BANK1(0x0800,V);break;
@@ -116,113 +107,73 @@ DECLFW(Mapper24_write)
          case 0xE001:VROM_BANK1(0x1400,V);break;
          case 0xE002:VROM_BANK1(0x1800,V);break;
          case 0xE003:VROM_BANK1(0x1c00,V);break;
-         case 0xF000:IRQLatch=V;break;
+         case 0xF000:IRQLatch=V;
+                        //acount=0;
+                        break;
          case 0xF001:IRQa=V&2;
                      vrctemp=V&1;
-                     if(V&2) {IRQCount=IRQLatch;}
-                    //acount=0;
+                     if(V&2)
+                     {
+                      IRQCount=IRQLatch;
+                      acount=0;
+                     }
+                     X6502_IRQEnd(FCEU_IQEXT);
                      break;
-         case 0xf002:IRQa=vrctemp;break;
+         case 0xf002:IRQa=vrctemp;
+                     X6502_IRQEnd(FCEU_IQEXT);break;
          case 0xF003:break;
   }
 }
 
-static int CVBC[3]={0,0,0};
-static int32 vcount[2];
+static int32 CVBC[3];
+static int32 vcount[3];
+static int32 dcount[2];
 
-static void DoSQV1(void)
+static INLINE void DoSQV(int x)
 {
-    uint8 amp;
-    int32 freq;
-    int V;
-    int32 start,end;
-
-    start=CVBC[0];
-    end=(SOUNDTS<<16)/soundtsinc;
-    if(end<=start) return;
-    CVBC[0]=end;
-
-    if(VPSG[0x3]&0x80)
+ int32 V;
+ int32 amp=(((VPSG[x<<2]&15)<<8)*6/8)>>4;
+ int32 start,end;
+
+ start=CVBC[x];
+ end=(SOUNDTS<<16)/soundtsinc;
+ if(end<=start) return;
+ CVBC[x]=end;
+
+ if(VPSG[(x<<2)|0x2]&0x80)
+ {
+  if(VPSG[x<<2]&0x80)
+  {
+   for(V=start;V<end;V++)
+    Wave[V>>4]+=amp;
+  }
+  else
+  {
+   int32 thresh=(VPSG[x<<2]>>4)&7;
+   int32 freq=((VPSG[(x<<2)|0x1]|((VPSG[(x<<2)|0x2]&15)<<8))+1)<<17;
+   for(V=start;V<end;V++)
+   {
+    if(dcount[x]>thresh)        /* Greater than, not >=.  Important. */
+     Wave[V>>4]+=amp;
+    vcount[x]-=nesincsize;
+    while(vcount[x]<=0)            /* Should only be <0 in a few circumstances. */
     {
-     amp=(VPSG[0]&15)<<4;
-     if(VPSG[0]&0x80)
-     {
-      for(V=start;V<end;V++)
-       Wave[V>>4]+=amp;
-     }
-     else
-     {
-      unsigned long dcycs;
-      freq=(((VPSG[0x2]|((VPSG[0x3]&15)<<8))+1));
-      inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/((long double)PSG_base/freq);
-      switch(VPSG[0]&0x70)
-      {
-       default:
-       case 0x00:dcycs=inc>>4;break;
-       case 0x10:dcycs=inc>>3;break;
-       case 0x20:dcycs=(inc*3)>>4;break;
-       case 0x30:dcycs=inc>>2;break;
-       case 0x40:dcycs=(inc*5)>>4;break;
-       case 0x50:dcycs=(inc*6)>>4;break;
-       case 0x60:dcycs=(inc*7)>>4;break;
-       case 0x70:dcycs=inc>>1;break;
-      }
-             for(V=start;V<end;V++)
-              {
-               if(vcount[0]<dcycs)
-                 Wave[V>>4]+=amp;
-               vcount[0]+=0x1000;
-               if(vcount[0]>=inc) vcount[0]-=inc;
-               }
-     }
+     vcount[x]+=freq;
+     dcount[x]=(dcount[x]+1)&15;
     }
+   }
+  }
+ }
 }
-static void DoSQV2(void)
-{
-    uint8 amp;
-    int32 freq;
-    int V;
-    int32 start,end;
 
-    start=CVBC[1];
-    end=(SOUNDTS<<16)/soundtsinc;
   if(end<=start) return;
-    CVBC[1]=end;
+static void DoSQV1(void)
+{
DoSQV(0);
+}
 
-    if(VPSG[0x7]&0x80)
-    {
-     amp=(VPSG[4]&15)<<4;
-     if(VPSG[4]&0x80)
-     {
-      for(V=start;V<end;V++)
-       Wave[V>>4]+=amp;
-     }
-     else
-     {
-      unsigned long dcycs;
-      freq=(((VPSG[0x6]|((VPSG[0x7]&15)<<8))+1));
-      inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/((long double)PSG_base/freq);
-      switch(VPSG[4]&0x70)
-      {
-       default:
-       case 0x00:dcycs=inc>>4;break;
-       case 0x10:dcycs=inc>>3;break;
-       case 0x20:dcycs=(inc*3)>>4;break;
-       case 0x30:dcycs=inc>>2;break;
-       case 0x40:dcycs=(inc*5)>>4;break;
-       case 0x50:dcycs=(inc*6)>>4;break;
-       case 0x60:dcycs=(inc*7)>>4;break;
-       case 0x70:dcycs=inc>>1;break;
-      }
-             for(V=start;V<end;V++)
-              {
-               if(vcount[1]<dcycs)
-                 Wave[V>>4]+=amp;
-               vcount[1]+=0x1000;
-               if(vcount[1]>=inc) vcount[1]-=inc;
-               }
-     }
-    }
+static void DoSQV2(void)
+{
+ DoSQV(1);
 }
 
 static void DoSawV(void)
@@ -237,7 +188,7 @@ static void DoSawV(void)
 
    if(VPSG2[2]&0x80)
    {
-    static int64 saw1phaseacc=0;
+    static int32 saw1phaseacc=0;
     uint32 freq3;
     static uint8 b3=0;
     static int32 phaseacc=0;
@@ -247,13 +198,13 @@ static void DoSawV(void)
 
     for(V=start;V<end;V++)
     {
-     saw1phaseacc-=nesincsizeLL;
+     saw1phaseacc-=nesincsize;
      if(saw1phaseacc<=0)
      {
-      int64 t;
+      int32 t;
       rea:
       t=freq3;
-      t<<=50;  // 49 + 1
+      t<<=18;
       saw1phaseacc+=t;
       phaseacc+=VPSG2[0]&0x3f;
       b3++;
@@ -264,90 +215,161 @@ static void DoSawV(void)
       }
       if(saw1phaseacc<=0)
        goto rea;
-      duff=(((phaseacc>>3)&0x1f)<<4);
+      duff=(((phaseacc>>3)&0x1f)<<4)*6/8;
       }
      Wave[V>>4]+=duff;
     }
    }
 }
 
-void VRC6Sound(int Count)
+#if 0
+static INLINE void DoSQVHQ(int x)
 {
-    int x;
+ int32 V;
+ int32 amp=((VPSG[x<<2]&15)<<8)*6/8;
 
-    DoSQV1();
-    DoSQV2();
-    DoSawV();
-    for(x=0;x<3;x++)
-     CVBC[x]=Count;
+ if(VPSG[(x<<2)|0x2]&0x80)
+ {
+  if(VPSG[x<<2]&0x80)
+  {
+   for(V=CVBC[x];V<SOUNDTS;V++)
+    WaveHi[V]+=amp;
+  }
+  else
+  {
+   int32 thresh=(VPSG[x<<2]>>4)&7;
+   for(V=CVBC[x];V<SOUNDTS;V++)
+   {
+    if(dcount[x]>thresh)        /* Greater than, not >=.  Important. */
+     WaveHi[V]+=amp;
+    vcount[x]--;
+    if(vcount[x]<=0)            /* Should only be <0 in a few circumstances. */
+    {
+     vcount[x]=(VPSG[(x<<2)|0x1]|((VPSG[(x<<2)|0x2]&15)<<8))+1;
+     dcount[x]=(dcount[x]+1)&15;
+    }
+   }
+  }
+ }
+ CVBC[x]=SOUNDTS;
 }
 
-static int satype=0;
+static void DoSQV1HQ(void)
+{
+ DoSQVHQ(0);
+}
 
-void VRC6SoundC(void)
+static void DoSQV2HQ(void)
 {
-  int x;
+ DoSQVHQ(1);
+}
 
-  if(FSettings.SndRate)
-   VRC6_ESI(satype);
-  else
+static void DoSawVHQ(void)
+{
+ static uint8 b3=0;
+ static int32 phaseacc=0;
+ int32 V;
+
+ if(VPSG2[2]&0x80)
+ {
+  for(V=CVBC[2];V<SOUNDTS;V++)
   {
-   for(x=000;x<0x1000;x+=4)
+   WaveHi[V]+=(((phaseacc>>3)&0x1f)<<8)*6/8;
+   vcount[2]--;
+   if(vcount[2]<=0)
    {
-          SetWriteHandler(0x9000+x,0x9002+x,0);
-          SetWriteHandler(0xa000+x,0xa002+x,0);
-          SetWriteHandler(0xb000+x,0xb002+x,0);
+    vcount[2]=(VPSG2[1]+((VPSG2[2]&15)<<8)+1)<<1;
+    phaseacc+=VPSG2[0]&0x3f;
+    b3++;
+    if(b3==7)
+    {
+     b3=0;
+     phaseacc=0;
+   }
+
    }
   }
+ }
+ CVBC[2]=SOUNDTS;
 }
+#endif
+
 
-void VRC6_ESI(int t)
+void VRC6Sound(int Count)
 {
-        int x;
+    int x;
 
-       satype=t;
+    DoSQV1();
+    DoSQV2();
+    DoSawV();
+    for(x=0;x<3;x++)
+     CVBC[x]=Count;
+}
 
-        GameExpSound.RChange=VRC6SoundC;
+#if 0
+void VRC6SoundHQ(void)
+{
+    DoSQV1HQ();
+    DoSQV2HQ();
+    DoSawVHQ();
+}
+
+void VRC6SyncHQ(int32 ts)
+{
+ int x;
+ for(x=0;x<3;x++) CVBC[x]=ts;
+}
+#endif
+
+static void VRC6_ESI(void)
+{
+        GameExpSound.RChange=VRC6_ESI;
         GameExpSound.Fill=VRC6Sound;
+        GameExpSound.HiFill=0;//VRC6SoundHQ;
+        GameExpSound.HiSync=0;//VRC6SyncHQ;
+
+        memset(CVBC,0,sizeof(CVBC));
+        memset(vcount,0,sizeof(vcount));
+        memset(dcount,0,sizeof(dcount));
         if(FSettings.SndRate)
-         for(x=000;x<0x1000;x+=4)
+        {
+#if 0
+         if(FSettings.soundq>=1)
+         {
+          sfun[0]=DoSQV1HQ;
+          sfun[1]=DoSQV2HQ;
+          sfun[2]=DoSawVHQ;
+         }
+         else
+#endif
          {
-          uint32 a;
-
-          a=0x9000+x;
-          SetWriteHandler(a,a,VRC6PSGW90);
-          SetWriteHandler(a+(1^t),a+(1^t),VRC6PSGW91);
-          SetWriteHandler(a+(2^t),a+(2^t),VRC6PSGW92);
-
-          a=0xa000+x;
-          SetWriteHandler(a,a,VRC6PSGWA0);
-          SetWriteHandler(a+(1^t),a+(1^t),VRC6PSGWA1);
-          SetWriteHandler(a+(2^t),a+(2^t),VRC6PSGWA2);
-
-          a=0xb000+x;
-          SetWriteHandler(a,a,VRC6PSGWB0);
-          SetWriteHandler(a+(1^t),a+(1^t),VRC6PSGWB1);
-          SetWriteHandler(a+(2^t),a+(2^t),VRC6PSGWB2);
+          sfun[0]=DoSQV1;
+          sfun[1]=DoSQV2;
+          sfun[2]=DoSawV;
          }
+        }
+        else
+         memset(sfun,0,sizeof(sfun));
 }
 
 void Mapper24_init(void)
 {
         SetWriteHandler(0x8000,0xffff,Mapper24_write);
-        if(FSettings.SndRate)
-         VRC6_ESI(0);
-        GameExpSound.RChange=VRC6SoundC;
+        VRC6_ESI();
         MapIRQHook=KonamiIRQHook;
-       swaparoo=0;
+        swaparoo=0;
 }
 
 void Mapper26_init(void)
 {
         SetWriteHandler(0x8000,0xffff,Mapper24_write);
-       if(FSettings.SndRate)
-         VRC6_ESI(3);
-       GameExpSound.RChange=VRC6SoundC;
+        VRC6_ESI();
         MapIRQHook=KonamiIRQHook;
-       swaparoo=1;
+        swaparoo=1;
 }
 
+void NSFVRC6_Init(void)
+{
+        VRC6_ESI();
+        SetWriteHandler(0x8000,0xbfff,VRC6SW);
+}
index 0735b9b..f8c1d73 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 #define K4IRQ mapbyte1[1]
 #define K4sel mapbyte1[0]
 
-DECLFW(Mapper25_write)
+static int acount=0;
+static DECLFW(Mapper25_write)
 {
-       A=(A&0xF003)|((A&0xC)>>2);
+        A=(A&0xF003)|((A&0xC)>>2);
 
-       if((A&0xF000)==0xA000)
-       {
-         ROM_BANK8(0xA000,V);
-          X6502_Rebase();
-       }
-       else if(A>=0xB000 && A<=0xEFFF)
-       {
+        if((A&0xF000)==0xA000)
+          ROM_BANK8(0xA000,V);
+        else if(A>=0xB000 && A<=0xEFFF)
+        {
          int x=(A&1)|((A-0xB000)>>11);
 
          K4buf[x]&=(0xF0)>>((A&2)<<1);
          K4buf[x]|=(V&0xF)<<((A&2)<<1);
          VROM_BANK1(x<<10,K4buf[x]);
-       }
-       else if((A&0xF000)==0x8000)
-       {
+        }
+        else if((A&0xF000)==0x8000)
+        {
          if(K4sel&2)
           ROM_BANK8(0xC000,V);
          else
           ROM_BANK8(0x8000,V);
-         X6502_Rebase();
-       }
-       else switch(A)
-       {
-        case 0x9000: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;
-        case 0x9001:if((K4sel&2)!=(V&2))
-                    {
-                     uint8 swa;
-                     swa=PRGBankList[0];
-                     ROM_BANK8(0x8000,PRGBankList[2]);
-                     ROM_BANK8(0xc000,swa);
-                      X6502_Rebase();
-                    }
-                    K4sel=V;
-                    break;
-       case 0xf000:IRQLatch&=0xF0;IRQLatch|=V&0xF;break;
-       case 0xf002:IRQLatch&=0x0F;IRQLatch|=V<<4;break;
-       case 0xf001:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;break;
-       case 0xf003:IRQa=K4IRQ;break;
+        }
+        else switch(A)
+        {
+         case 0x9000: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;
+         case 0x9001:if((K4sel&2)!=(V&2))
+                     {
+                           uint8 swa;
+                      swa=PRGBankList[0];
+                       ROM_BANK8(0x8000,PRGBankList[2]);
+                      ROM_BANK8(0xc000,swa);
+                     }
+                     K4sel=V;
+                     break;
+        case 0xf000:IRQLatch&=0xF0;IRQLatch|=V&0xF;break;
+        case 0xf002:IRQLatch&=0x0F;IRQLatch|=V<<4;break;
+        case 0xf001:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;acount=0;X6502_IRQEnd(FCEU_IQEXT);break;
+        case 0xf003:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break;
  }
 }
 
 static void FP_FASTAPASS(1) KonamiIRQHook(int a)
 {
-  static int count=0;
-  #define LCYCS 114
+//  #define LCYCS ((227*2))
+  #define LCYCS 341
   if(IRQa)
   {
-   count+=a;
-   if(count>=LCYCS)
+   acount+=a*3;
+  // acount+=a*4;
+   if(acount>=LCYCS)
    {
-    doagainbub:count-=LCYCS;IRQCount++;
-    if(IRQCount&0x100) {count=0;TriggerIRQ();IRQCount=IRQLatch;}
-    if(count>=LCYCS) goto doagainbub;
+    doagainbub:acount-=LCYCS;IRQCount++;
+    if(IRQCount&0x100)
+    {//acount=0;
+     X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;
+        }
+    if(acount>=LCYCS) goto doagainbub;
    }
  }
 }
diff --git a/mappers/255.c b/mappers/255.c
new file mode 100644 (file)
index 0000000..ede7af3
--- /dev/null
@@ -0,0 +1,67 @@
+/* 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(Mapper255_write)
+{
+ uint32 pbank=(A>>7)&0x1F;
+ uint32 cbank=A&0x3F;
+ uint32 rbank=(A>>14)&1;
+
+// printf("$%04x:$%02x\n",A,V);
+// printf("%2x:%2x:%2x,%2x\n",pbank,cbank,rbank,(A&0x40)>>6);
+
+ if(A&0x1000)
+ {
+  ROM_BANK16(0x8000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6));
+  ROM_BANK16(0xc000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6));
+ }
+ else
+ {
+  ROM_BANK32(pbank|(rbank<<5));
+ }
+ MIRROR_SET((A>>13)&1);
+ VROM_BANK8((rbank<<6)|cbank);
+}
+
+static DECLFW(Mapper255_wl)
+{
+// printf("Wr: $%04x:$%02x\n",A,V);
+ mapbyte1[A&3]=V&0xF;
+}
+
+static DECLFR(Mapper255_read)
+{
+ //printf("Rd: $%04x\n",A);
+ return(mapbyte1[A&3]); //|(X.DB&0xF0));
+}
+
+void Mapper255_init(void)
+{
+ mapbyte1[0]=mapbyte1[1]=0xF;
+ ROM_BANK32(0);
+ VROM_BANK8(0);
+ SetWriteHandler(0x5800,0x5FFF,Mapper255_wl);
+ SetWriteHandler(0x8000,0xffff,Mapper255_write);
+ SetReadHandler(0x5800,0x5FFF,Mapper255_read);
+}
diff --git a/mappers/27.c b/mappers/27.c
new file mode 100644 (file)
index 0000000..9dbe5cf
--- /dev/null
@@ -0,0 +1,74 @@
+#include "mapinc.h"\r
+\r
+static uint32 regchr[9];\r
+\r
+static DECLFW(Mapper27_write)\r
+{\r
+ A&=0xF00F;\r
+ int regnum;\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]&0x0F)|(V<<4);\r
+    else\r
+       regchr[regnum]=(regchr[regnum]&0xFF0)|(V&0xF);\r
+    VROM_BANK1(regnum<<10,regchr[regnum]);\r
+ }\r
+ switch(A)\r
+ {\r
+  case 0x8000: if(regchr[8]&2)\r
+                  ROM_BANK8(0xc000,V);\r
+               else\r
+                  ROM_BANK8(0x8000,V);\r
+               break;\r
+  case 0xA000: ROM_BANK8(0xa000,V); break;\r
+  case 0x9000:\r
+               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;\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 fd455d2..13e4bba 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -28,20 +28,16 @@ static DECLFW(Mapper32_write)
  switch(A>>12)
  {
   case 0x8:
-          mapbyte1[1]=V;
+           mapbyte1[1]=V;
            if(IREMCon) {ROM_BANK8(0xc000,V);ROM_BANK8(0x8000,~1);}
            else {ROM_BANK8(0x8000,V);ROM_BANK8(0xc000,~1);}
-           X6502_Rebase();
            break;
-  case 0x9:MIRROR_SET2(V&1);
-           IREMCon=(V>>1)&1;
+  case 0x9:IREMCon=(V>>1)&1;
            if(IREMCon) {ROM_BANK8(0xc000,mapbyte1[1]);ROM_BANK8(0x8000,~1);}
            else {ROM_BANK8(0x8000,mapbyte1[1]); ROM_BANK8(0xc000,~1);}
            MIRROR_SET(V&1);
-           X6502_Rebase();
            break;
   case 0xa:ROM_BANK8(0xA000,V);
-           X6502_Rebase();
            break;
  }
 
index a675ec0..f3362c0 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
+static int is48;
+
 static DECLFW(Mapper33_write)
 {
-        A&=0xF003;
+        //printf("%04x:%02x, %d\n",A,V,scanline);
 
-       //printf("$%04x:$%02x, %d\n",A,V,scanline);
+        A&=0xF003;
         if(A>=0xA000 && A<=0xA003)
          VROM_BANK1(0x1000+((A&3)<<10),V);
-        else switch(A){
-        case 0x8000:if(!mapbyte1[0])
-                     MIRROR_SET((V>>6)&1);
-                    ROM_BANK8(0x8000,V);
-                    X6502_Rebase();
-                    break;
-        case 0x8001:ROM_BANK8(0xA000,V);
-                    X6502_Rebase();break;
-        case 0x8002:VROM_BANK2(0x0000,V);break;
-        case 0x8003:VROM_BANK2(0x0800,V);break;
-       case 0xc000:IRQLatch=V;break;
-       case 0xc001:IRQCount=IRQLatch;break;
-        case 0xc003:IRQa=0;break;
-        case 0xc002:IRQa=1;break;
-        case 0xe000:mapbyte1[0]=1;MIRROR_SET((V>>6)&1);break;
+        else switch(A)
+        {
+          case 0x8000:if(!is48) MIRROR_SET((V>>6)&1);
+                     ROM_BANK8(0x8000,V);
+                     break;
+         case 0x8001:ROM_BANK8(0xA000,V); break;
+         case 0x8002:VROM_BANK2(0x0000,V);break;
+         case 0x8003:VROM_BANK2(0x0800,V);break;
+        }
+}
+
+static DECLFW(Mapper48_HiWrite)
+{
+        switch(A&0xF003)
+        {
+         case 0xc000:IRQLatch=V;break;
+         case 0xc001:IRQCount=IRQLatch;break;
+         case 0xc003:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
+         case 0xc002:IRQa=1;break;
+         case 0xe000:MIRROR_SET((V>>6)&1);break;
         }
 }
 
@@ -52,7 +59,7 @@ static void heho(void)
    IRQCount++;
    if(IRQCount==0x100)
    {
-    TriggerIRQ();
+    X6502_IRQBegin(FCEU_IQEXT);
     IRQa=0;
    }
  }
@@ -60,6 +67,14 @@ static void heho(void)
 
 void Mapper33_init(void)
 {
-       SetWriteHandler(0x8000,0xffff,Mapper33_write);
-       GameHBIRQHook=heho;
+        SetWriteHandler(0x8000,0xffff,Mapper33_write);
+        is48=0;
+}
+
+void Mapper48_init(void)
+{
+        SetWriteHandler(0x8000,0xffff,Mapper33_write);
+        SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite);
+        GameHBIRQHook=heho;
+        is48=1;
 }
index d608de2..471a7cc 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -25,10 +25,9 @@ static DECLFW(Mapper40_write)
 {
  switch(A&0xe000)
  {
-  case 0x8000:IRQa=0;IRQCount=0;break;
+  case 0x8000:IRQa=0;IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break;
   case 0xa000:IRQa=1;break;
-  case 0xe000:ROM_BANK8(0xc000,V&7);
-              X6502_Rebase();break;
+  case 0xe000:ROM_BANK8(0xc000,V&7);break;
  }
 }
 
@@ -37,11 +36,11 @@ static void FP_FASTAPASS(1) Mapper40IRQ(int a)
  if(IRQa)
  {
         if(IRQCount<4096)
-        IRQCount+=a;
-       else
+         IRQCount+=a;
+        else
         {
          IRQa=0;
-         TriggerIRQ();
+         X6502_IRQBegin(FCEU_IQEXT);
         }
  }
 }
index ce63408..dfb6908 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -28,24 +28,29 @@ DECLFW(Mapper41_write)
 {
  if(A<0x8000)
  {
- ROM_BANK32(A&7);
- X6502_Rebase();
- MIRROR_SET((A>>5)&1);
- calreg=A;
- calchr&=0x3;
- calchr|=(A>>1)&0xC;
- VROM_BANK8(calchr);
+  ROM_BANK32(A&7);
+  MIRROR_SET((A>>5)&1);
+  calreg=A;
+  calchr&=0x3;
+  calchr|=(A>>1)&0xC;
+  VROM_BANK8(calchr);
  }
  else if(calreg&0x4)
  {
- calchr&=0xC;
- calchr|=A&3;
- VROM_BANK8(calchr);
 calchr&=0xC;
 calchr|=A&3;
 VROM_BANK8(calchr);
  }
 }
 
+static void M41Reset(void)
+{
+ calreg=calchr=0;
+}
+
 void Mapper41_init(void)
 {
+ MapperReset=M41Reset;
  ROM_BANK32(0);
  SetWriteHandler(0x8000,0xffff,Mapper41_write);
  SetWriteHandler(0x6000,0x67ff,Mapper41_write);
index 6bab879..bf31ac2 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 static DECLFW(Mapper42_write)
 {
+// FCEU_printf("%04x:%04x\n",A,V);
  switch(A&0xe003)
  {
-  case 0xe000:mapbyte1[0]=V;ROM_BANK8(0x6000,V&0xF);
-              X6502_Rebase();break;
+  case 0x8000:VROM_BANK8(V);break;
+  case 0xe000:mapbyte1[0]=V;ROM_BANK8(0x6000,V&0xF);break;
   case 0xe001:MIRROR_SET((V>>3)&1);break;
-  case 0xe002:IRQa=V&2;if(!IRQa) IRQCount=0;break;
+  case 0xe002:IRQa=V&2;if(!IRQa) IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break;
  }
 }
 
@@ -36,13 +37,12 @@ static void FP_FASTAPASS(1) Mapper42IRQ(int a)
 {
  if(IRQa)
  {
-        if(IRQCount<24576)
-         IRQCount+=a;
+        IRQCount+=a;
+        if(IRQCount>=32768) IRQCount-=32768;
+        if(IRQCount>=24576)
+         X6502_IRQBegin(FCEU_IQEXT);
         else
-        {
-         IRQa=0;
-         TriggerIRQ();
-        }
+         X6502_IRQEnd(FCEU_IQEXT);
  }
 }
 
@@ -56,7 +56,7 @@ void Mapper42_init(void)
 {
   ROM_BANK8(0x6000,0);
   ROM_BANK32(~0);
-  SetWriteHandler(0xe000,0xffff,Mapper42_write);
+  SetWriteHandler(0x6000,0xffff,Mapper42_write);
   SetReadHandler(0x6000,0x7fff,CartBR);
   MapStateRestore=Mapper42_StateRestore;
   MapIRQHook=Mapper42IRQ;
index 0ca0cee..ef7d40d 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 
 
-DECLFW(Mapper43_write)
+static DECLFW(Mapper43_write)
 {
 uint32 m;
-  int z;
-
-  if(A&0x400)
-   onemir(0);
//printf("$%04x:$%02x\n",A,V);
+ if((A&0x8122)==0x8122)
+ {
+  X6502_IRQEnd(FCEU_IQEXT);
+  if(V&2) IRQa=1;
   else
-   MIRROR_SET((A>>13)&1);
-  m=A&0x1f;
+   IRQCount=IRQa=0;
+ }
+}
 
-  z=(A>>8)&3;
+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);
+}
 
-  switch(CHRmask8[0])
+static void FP_FASTAPASS(1) M43Ho(int a)
+{
+ IRQCount+=a;
+ if(IRQa)
+  if(IRQCount>=4096)
   {
-   default:
-   case 0xFF:
-             if(z&2)
-              m|=0x20;
-             break;
-   case 0x1FF:
-             m|=z<<5;
-             break;
+   X6502_IRQBegin(FCEU_IQEXT);
   }
-
-   if(A&0x800)
-   {
-    ROM_BANK16(0x8000,(m<<1)|((A&0x1000)>>12));
-    ROM_BANK16(0xC000,(m<<1)|((A&0x1000)>>12));
-   }
-   else
-    ROM_BANK32(m);
-   X6502_Rebase();
 }
 
+//static DECLFR(boo)
+//{
+// printf("$%04x\n",A);
+// return( ROM[0x2000*8 +0x1000 +(A-0x5000)]);
+//}
+
 void Mapper43_init(void)
 {
- ROM_BANK32(0);
+ 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 ab8133e..8c4ef6d 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -30,7 +30,6 @@ DECLFW(Mapper46_writel)
   A64reg=V;
   ROM_BANK32((A64wr&1)+((A64reg&0xF)<<1));
   VROM_BANK8(((A64wr>>4)&7)+((A64reg&0xF0)>>1));
-  X6502_Rebase();
 }
 
 DECLFW(Mapper46_write)
@@ -38,7 +37,6 @@ DECLFW(Mapper46_write)
   A64wr=V;
   ROM_BANK32((V&1)+((A64reg&0xF)<<1));
   VROM_BANK8(((V>>4)&7)+((A64reg&0xF0)>>1));
-  X6502_Rebase();
 }
 
 void Mapper46_init(void)
similarity index 50%
rename from mappers/112.c
rename to mappers/50.c
index 273d550..8d7f515 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 #include "mapinc.h"
 
 
+static void FP_FASTAPASS(1) Mapper50IRQ(int a)
+{
+ if(IRQa)
+ {
+        if(IRQCount<4096)
+         IRQCount+=a;
+        else
+        {
+         IRQa=0;
+         X6502_IRQBegin(FCEU_IQEXT);
+        }
+ }
+}
 
-DECLFW(Mapper112_write)
+static void M50Restore(int version)
 {
-switch(A)
+ setprg8(0xc000,mapbyte1[0]);
+}
+
+static DECLFW(M50W)
 {
- case 0xe000:MIRROR_SET(V&1);break;
- case 0x8000:mapbyte1[0]=V;break;
- case 0xa000:switch(mapbyte1[0])
-            {
-            case 0:ROM_BANK8(0x8000,V);break;
-            case 1:ROM_BANK8(0xA000,V);break;
-                case 2: V&=0xFE;VROM_BANK1(0,V);
-                        VROM_BANK1(0x400,(V+1));break;
-                case 3: V&=0xFE;VROM_BANK1(0x800,V);
-                        VROM_BANK1(0xC00,(V+1));break;
-            case 4:VROM_BANK1(0x1000,V);break;
-            case 5:VROM_BANK1(0x1400,V);break;
-            case 6:VROM_BANK1(0x1800,V);break;
-            case 7:VROM_BANK1(0x1c00,V);break;
-            }
-            X6502_Rebase();
-            break;
+ if((A&0xD060)==0x4020)
+ {
+  if(A&0x100)
+  {
+   IRQa=V&1;
+   if(!IRQa) IRQCount=0;
+   X6502_IRQEnd(FCEU_IQEXT);
+  }
+  else
+  {
+   V=((V&1)<<2)|((V&2)>>1)|((V&4)>>1)|(V&8);
+   mapbyte1[0]=V;
+   setprg8(0xc000,V);
+  }
  }
 }
 
-void Mapper112_init(void)
+void Mapper50_init(void)
 {
-  SetWriteHandler(0x8000,0xffff,Mapper112_write);
+  SetWriteHandler(0x4020,0x5fff,M50W);
+  SetReadHandler(0x6000,0xffff,CartBR);
+  MapStateRestore=M50Restore;
+  MapIRQHook=Mapper50IRQ;
+
+  setprg8(0x6000,0xF);
+  setprg8(0x8000,0x8);
+  setprg8(0xa000,0x9);
+  setprg8(0xc000,0x0);
+  setprg8(0xe000,0xB);
 }
 
index 90986ea..cc1fbbd 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -26,7 +26,7 @@
 static uint32 Get8K(uint32 A)
 {
  uint32 bank;
-
  bank=(page<<2)|((A>>13)&1);
 
  if(A&0x4000 && !(mode&1)) bank|=0xC;
@@ -45,7 +45,6 @@ static void Synco(void)
   MIRROR_SET2(0);
  for(x=0x6000;x<0x10000;x+=8192)
   ROM_BANK8(x,Get8K(x));
- X6502_Rebase();
 }
 
 static DECLFW(Write)
similarity index 64%
rename from mappers/249.c
rename to mappers/57.c
index 6225d49..b64d270 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
-uint8 doh;
 
-static DECLFW(Mapper249_write)
+
+static DECLFW(Mapper57_write)
 {
- switch(A&0xe001)
+ A&=0x8800;
+ if(A==0x8800)
  {
-  case 0x8000:doh=V;break;
-  case 0x8001:switch(doh&7)
-               {
-                case 0:VROM_BANK2(0x0000,V>>1);break;
-                case 1:VROM_BANK2(0x0800,V>>1);break;
-                case 2:VROM_BANK1(0x1000,V);break;
-//              case 6:ROM_BANK8(0xa000,V);break;
-//              case 2:ROM_BANK8(0x8000,V);break;
-               }
+  mapbyte1[0]=V;
+  if(V&0x80)
+   ROM_BANK32(2|(V>>6));
+  else
+  {
+   ROM_BANK16(0x8000,(V>>5)&3);
+   ROM_BANK16(0xc000,(V>>5)&3);
+  }
+  MIRROR_SET((V&0x8)>>3);
  }
-// printf("$%04x:$%02x\n",A,V);
+ else
+  mapbyte1[1]=V;
+ VROM_BANK8((mapbyte1[1]&3)|(mapbyte1[0]&7)|((mapbyte1[0]&0x10)>>1));
+ //printf("$%04x:$%02x\n",A,V);
 }
 
-void Mapper249_init(void)
+void Mapper57_init(void)
 {
 SetWriteHandler(0x8000,0xffff,Mapper249_write);
SetWriteHandler(0x8000,0xffff,Mapper57_write);
 }
-
diff --git a/mappers/58.c b/mappers/58.c
new file mode 100644 (file)
index 0000000..d3cc505
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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(M58Write)
+{
+ //printf("$%04x:$%02x\n",A,V);
+ if(A&0x40)
+ {
+  ROM_BANK16(0x8000,(A&0x07));
+  ROM_BANK16(0xc000,(A&0x07));
+ }
+ else
+  ROM_BANK32((A&0x06)>>1);
+
+ VROM_BANK8((A&0x38)>>3);
+ MIRROR_SET2((V&2)>>1);
+}
+
+void Mapper58_init(void)
+{
+ ROM_BANK32(0);
+ VROM_BANK8(0);
+ SetWriteHandler(0x8000,0xFFFF,M58Write);
+}
diff --git a/mappers/59.c b/mappers/59.c
new file mode 100644 (file)
index 0000000..30ddb8b
--- /dev/null
@@ -0,0 +1,47 @@
+/* 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 int ay;
+static DECLFW(Mapper59_write)
+{
+ //printf("$%04x:$%02x\n",A,V);
+ setprg32(0x8000,(A&0x70)>>4);
+ setchr8(A&0x7);
+ //if(A&0x100)
+ // setprg32r(0x10,0x8000,0);
+ ay=A;
+ MIRROR_SET2((A&0x8)>>3);
+}
+
+static DECLFR(m59rd)
+{
+ if(ay&0x100) return(0);
+ else
+  return(CartBR(A));
+}
+
+void Mapper59_init(void)
+{
+ setprg32(0x8000,0);
+ SetReadHandler(0x8000,0xffff,m59rd);
+ SetWriteHandler(0x8000,0xffff,Mapper59_write);
+}
index 29caa6a..45a8f0d 100644 (file)
@@ -1,77 +1,80 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 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)
-{
-  if(IRQa)
-  {
-   IRQCount+=a;
-   if(IRQCount>=0x10000)
-   {
-    TriggerIRQ();
-    IRQa=0;
-    IRQCount=0;
-   }
-  }
-}
-
-DECLFW(Mapper6_write)
-{
-        if(A<0x8000)
-        {
-                switch(A){
-                case 0x42FF:MIRROR_SET((V>>4)&1);break;
-                case 0x42FE:onemir((V>>3)&2);break;
-                case 0x4501:IRQa=0;break;
-                case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break;
-                case 0x4503:IRQCount&=0xFF;IRQCount|=V<<8;IRQa=1;break;
-                }
-        } else {
-        ROM_BANK16(0x8000,V>>2);
-        FVRAM_BANK8(0x0000,V&3);
-        X6502_Rebase();
-        }
-}
-void Mapper6_StateRestore(int version)
-{
- int x;
- for(x=0;x<8;x++)
-  if(PPUCHRRAM&(1<<x))
-  {
-   if(CHRBankList[x]>7)
-    VPage[x]=&MapperExRAM[(CHRBankList[x]&31)*0x400]-(x*0x400);
-   else VPage[x]=&CHRRAM[(CHRBankList[x]&7)*0x400]-(x*0x400);
-  }
-}
-void Mapper6_init(void)
-{
-MapIRQHook=FFEIRQHook;
-ROM_BANK16(0xc000,7);
-
-SetWriteHandler(0x4020,0x5fff,Mapper6_write);
-SetWriteHandler(0x8000,0xffff,Mapper6_write);
-MapStateRestore=Mapper6_StateRestore;
-}
-
+/* 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
+#include "mapinc.h"\r
+\r
+static uint8 FFEmode;\r
+\r
+#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;}\r
+\r
+static void FP_FASTAPASS(1) FFEIRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+   IRQCount+=a;\r
+   if(IRQCount>=0x10000)\r
+   {\r
+    X6502_IRQBegin(FCEU_IQEXT);\r
+    IRQa=0;\r
+    IRQCount=0;\r
+   }\r
+  }\r
+}\r
+\r
+DECLFW(Mapper6_write)\r
+{\r
+        if(A<0x8000)\r
+        {\r
+                switch(A){\r
+                case 0x42FF:MIRROR_SET((V>>4)&1);break;\r
+                case 0x42FE:onemir((V>>3)&2); FFEmode=V&0x80;break;\r
+                case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;\r
+                case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break;\r
+                case 0x4503:IRQCount&=0xFF;IRQCount|=V<<8;IRQa=1;break;\r
+                }\r
+        } else {\r
+         switch (FFEmode)\r
+         {\r
+           case 0x80:  setchr8(V); break;\r
+           default: ROM_BANK16(0x8000,V>>2);\r
+                    FVRAM_BANK8(0x0000,V&3);\r
+         }\r
+        }\r
+}\r
+void Mapper6_StateRestore(int version)\r
+{\r
+ int x;\r
+ for(x=0;x<8;x++)\r
+  if(PPUCHRRAM&(1<<x))\r
+  {\r
+   if(CHRBankList[x]>7)\r
+    VPage[x]=&MapperExRAM[(CHRBankList[x]&31)*0x400]-(x*0x400);\r
+   else VPage[x]=&CHRRAM[(CHRBankList[x]&7)*0x400]-(x*0x400);\r
+  }\r
+}\r
+void Mapper6_init(void)\r
+{\r
+MapIRQHook=FFEIRQHook;\r
+ROM_BANK16(0xc000,7);\r
+\r
+SetWriteHandler(0x4020,0x5fff,Mapper6_write);\r
+SetWriteHandler(0x8000,0xffff,Mapper6_write);\r
+MapStateRestore=Mapper6_StateRestore;\r
+}\r
diff --git a/mappers/60.c b/mappers/60.c
new file mode 100644 (file)
index 0000000..b48087c
--- /dev/null
@@ -0,0 +1,41 @@
+/* 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(Mapper60_write)
+{
+  if(A&0x80) {
+         ROM_BANK16(0x8000,(A&0x70)>>4);
+         ROM_BANK16(0xC000,(A&0x70)>>4);
+  }
+  else
+         ROM_BANK32((A&0x70)>>5);
+  VROM_BANK8(A&7);
+  MIRROR_SET((A&8)>>3);
+}
+
+void Mapper60_init(void)
+{
+        ROM_BANK32(0);
+        SetWriteHandler(0x8000,0xffff, Mapper60_write);
+}
+
+
similarity index 58%
rename from mappers/245.c
rename to mappers/61.c
index ae20c18..4303932 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
-static void Synco(void)
-{
- ROM_BANK8(0x8000,mapbyte2[0]);
- ROM_BANK8(0xA000,mapbyte2[1]);
- ROM_BANK8(0xc000,0x3e);
- ROM_BANK8(0xe000,0x3f);
- X6502_Rebase();
-}
-static DECLFW(Mapper245_write)
+
+static DECLFW(Mapper61_write)
 {
- switch(A&0xe001)
+// printf("$%04x:$%02x\n",A,V);
+ switch(A&0x30)
  {
-  case 0xa000:mapbyte1[1]=V;Synco();break;
-  case 0x8000:mapbyte1[0]=V;break;
-  case 0x8001:switch(mapbyte1[0]&7)
-               {
-//              default:printf("ark\n");break;
-                case 6:mapbyte2[0]=V;Synco();break;
-                case 7:mapbyte2[1]=V;Synco();break;
-               }break;
-  //case 0xa001:MIRROR_SET2(V>>7);break;
+  case 0x00:
+  case 0x30:
+          ROM_BANK32(A&0xF);
+          break;
+  case 0x20:
+  case 0x10:
+          ROM_BANK16(0x8000,((A&0xF)<<1)| (((A&0x20)>>4)) );
+          ROM_BANK16(0xC000,((A&0xF)<<1)| (((A&0x20)>>4)) );
+          break;
  }
-// printf("$%04x:$%02x\n",A,V);
+ #ifdef moo
+ if(!(A&0x10))
+  ROM_BANK32(A&0xF);
+ else
+ {
+  ROM_BANK16(0x8000,((A&0xF)<<1)| (((A&0x10)>>4)^1) );
+  ROM_BANK16(0xC000,((A&0xF)<<1)| (((A&0x10)>>4)^1) );
+ }
+ #endif
+ MIRROR_SET((A&0x80)>>7);
 }
 
-void Mapper245_init(void)
+void Mapper61_init(void)
 {
 SetWriteHandler(0x8000,0xffff,Mapper245_write);
SetWriteHandler(0x8000,0xffff,Mapper61_write);
 }
-
diff --git a/mappers/62.c b/mappers/62.c
new file mode 100644 (file)
index 0000000..ed0f01d
--- /dev/null
@@ -0,0 +1,41 @@
+/* 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(Mapper62_write)
+{
+  VROM_BANK8(((A&0x1F)<<2)|(V&0x03));
+  if((A&0x20)>>5) {
+     ROM_BANK16(0x8000,(A&0x40)|((A>>8)&0x3F));
+     ROM_BANK16(0xc000,(A&0x40)|((A>>8)&0x3F));
+  }
+  else
+     ROM_BANK32(((A&0x40)|((A>>8)&0x3F))>>1);
+  MIRROR_SET((A&0x80)>>7);
+}
+
+void Mapper62_init(void)
+{
+        SetWriteHandler(0x8000,0xffff, Mapper62_write);
+        ROM_BANK32(0);
+}
+
+
diff --git a/mappers/64.c b/mappers/64.c
deleted file mode 100644 (file)
index 68c7696..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 cmd   mapbyte1[0]
-#define mir   mapbyte1[1]
-#define rmode mapbyte1[2]
-#define regsl mapbyte2
-#define regsh mapbyte3
-
-static void RAMBO1_hb(void)
-{
-      rmode=0;
-      if(IRQCount>=0)
-      {
-        IRQCount--;
-        if(IRQCount<0)
-        {
-         if(IRQa)
-         {
-//         printf("IRQ: %d\n",scanline);
-            rmode = 1;
-            X6502_IRQBegin(FCEU_IQEXT);
-         }
-        }
-      }
-}
-
-static void Synco(void)
-{
- int x;
-
- if(cmd&0x20)
- {
-  setchr1(0x0000,regsl[0]);
-  setchr1(0x0800,regsl[1]);
-  setchr1(0x0400,regsh[0]);
-  setchr1(0x0c00,regsh[1]);
- }
- else
- {
-  setchr2(0x0000,regsl[0]>>1);
-  setchr2(0x0800,regsl[1]>>1);
- }
-
- for(x=0;x<4;x++)
-  setchr1(0x1000+x*0x400,regsl[2+x]);
-
- setprg8(0x8000,regsl[6]);
- setprg8(0xA000,regsl[7]);
-
- setprg8(0xC000,regsh[7]);
- X6502_Rebase();
-}
-
-
-static DECLFW(RAMBO1_write)
-{
- //if(A>=0xC000 && A<=0xFFFF) printf("$%04x:$%02x, %d, %d\n",A,V,scanline,timestamp);
- switch(A&0xF001)
- {
-        case 0xa000:mir=V&1;
-                   setmirror(mir^1);
-                   break;
-        case 0x8000:cmd = V;
-                   break;
-        case 0x8001:
-                   if((cmd&15)<8)
-                    regsl[cmd&7]=V;
-                   else
-                    regsh[cmd&7]=V;
-                   Synco();
-                   break;
-        case 0xc000:IRQLatch=V;
-                    if(rmode==1)
-                     {
-                      IRQCount=IRQLatch;
-                     }
-                    break;
-        case 0xc001:rmode=1;
-                    IRQCount=IRQLatch;
-                    break;
-        case 0xE000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);
-                    if(rmode==1)
-                     {IRQCount=IRQLatch;}
-                    break;
-        case 0xE001:IRQa=1;
-                    if(rmode==1)
-                     {IRQCount=IRQLatch;}
-                    break;
-  }
-}
-
-static void RAMBO1_Restore(int version)
-{
- if(version<74)
- {
-  int x;
-
-  x=mapbyte1[1];        // was MMC3_cmd
-  cmd=x;
-
-  regsl[0]=CHRBankList[0];
-  regsl[1]=CHRBankList[2];
-  regsh[0]=CHRBankList[1];
-  regsh[1]=CHRBankList[3];
-
-  for(x=0;x<4;x++)
-   regsl[2+x]=CHRBankList[4+x];
-
-  regsl[6]=PRGBankList[0];
-  regsl[7]=PRGBankList[1];
-  regsh[7]=PRGBankList[2];
-  mir=Mirroring^1;
- }
- Synco();
- setmirror(mir^1);
-}
-
-void Mapper64_init(void)
-{
-       int x;
-
-       for(x=0;x<8;x++)
-        regsl[x]=regsh[x]=~0;
-       cmd=0;
-       mir=0;
-       setmirror(1);
-       Synco();
-       GameHBIRQHook=RAMBO1_hb;
-       GameStateRestore=RAMBO1_Restore;
-       SetWriteHandler(0x8000,0xffff,RAMBO1_write);
-}
index 51983ef..d817694 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -26,42 +26,45 @@ void FP_FASTAPASS(1) IREMIRQHook(int a)
   if(IRQa)
   {
    IRQCount-=a;
-   if(IRQCount<=0-4)
+   if(IRQCount<-4)
    {
-    TriggerIRQ();
+    X6502_IRQBegin(FCEU_IQEXT);
     IRQa=0;
     IRQCount=0xFFFF;
    }
   }
 }
 
-DECLFW(Mapper65_write)
+static DECLFW(Mapper65_write)
 {
-switch(A)
-{
-case 0x8000:ROM_BANK8(0x8000,V);
-            X6502_Rebase();break;
-case 0x9000:MIRROR_SET2((V>>6)&1);break;
-case 0x9003:IRQa=V&0x80;break;
-case 0x9004:IRQCount=IRQLatch;break;
-case 0x9005:          IRQLatch&=0x00FF;
-                      IRQLatch|=V<<8;
-                      break;
-case 0x9006:          IRQLatch&=0xFF00;IRQLatch|=V;
-                      break;
-case 0xB000:VROM_BANK1(0x0000,V);break;
-case 0xB001:VROM_BANK1(0x0400,V);break;
-case 0xB002:VROM_BANK1(0x0800,V);break;
-case 0xB003:VROM_BANK1(0x0C00,V);break;
-case 0xB004:VROM_BANK1(0x1000,V);break;
-case 0xB005:VROM_BANK1(0x1400,V);break;
-case 0xB006:VROM_BANK1(0x1800,V);break;
-case 0xB007:VROM_BANK1(0x1C00,V);break;
-case 0xa000:ROM_BANK8(0xA000,V);
-            X6502_Rebase();break;
-case 0xC000:ROM_BANK8(0xC000,V);
-            X6502_Rebase();break;
+ //if(A>=0x9000 && A<=0x9006)
+ // printf("$%04x:$%02x, %d\n",A,V,scanline);
+ switch(A)
+ {
+  //default: printf("$%04x:$%02x\n",A,V);
+  //        break;
+  case 0x8000:ROM_BANK8(0x8000,V);break;
+ // case 0x9000:printf("$%04x:$%02x\n",A,V);MIRROR_SET2((V>>6)&1);break;
+  case 0x9001:MIRROR_SET(V>>7);break;
+  case 0x9003:IRQa=V&0x80;X6502_IRQEnd(FCEU_IQEXT);break;
+  case 0x9004:IRQCount=IRQLatch;break;
+  case 0x9005:          IRQLatch&=0x00FF;
+                        IRQLatch|=V<<8;
+                        break;
+  case 0x9006:          IRQLatch&=0xFF00;IRQLatch|=V;
+                        break;
+  case 0xB000:VROM_BANK1(0x0000,V);break;
+  case 0xB001:VROM_BANK1(0x0400,V);break;
+  case 0xB002:VROM_BANK1(0x0800,V);break;
+  case 0xB003:VROM_BANK1(0x0C00,V);break;
+  case 0xB004:VROM_BANK1(0x1000,V);break;
+  case 0xB005:VROM_BANK1(0x1400,V);break;
+  case 0xB006:VROM_BANK1(0x1800,V);break;
+  case 0xB007:VROM_BANK1(0x1C00,V);break;
+  case 0xa000:ROM_BANK8(0xA000,V);break;
+  case 0xC000:ROM_BANK8(0xC000,V);break;
  }
+ //MIRROR_SET2(1);
 }
 
 void Mapper65_init(void)
index f5bbb2b..9d560f9 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -23,7 +23,7 @@
 
 #define suntoggle mapbyte1[0]
 
-DECLFW(Mapper67_write)
+static DECLFW(Mapper67_write)
 {
  A&=0xF800;
  if((A&0x800) && A<=0xb800)
@@ -34,11 +34,18 @@ DECLFW(Mapper67_write)
  {
   case 0xc800:
   case 0xc000:if(!suntoggle)
-              {IRQCount&=0xFF;IRQCount|=V<<8;}
-              else{IRQCount&=0xFF00;IRQCount|=V;}
+              {
+               IRQCount&=0xFF;
+               IRQCount|=V<<8;
+              }
+              else
+              {
+               IRQCount&=0xFF00;
+               IRQCount|=V;
+              }
               suntoggle^=1;
               break;
-  case 0xd800:suntoggle=0;IRQa=V&0x10;break;
+  case 0xd800:suntoggle=0;IRQa=V&0x10;X6502_IRQEnd(FCEU_IQEXT);break;
 
   case 0xe800:switch(V&3)
               {
@@ -48,8 +55,7 @@ DECLFW(Mapper67_write)
                case 3:onemir(1);break;
               }
               break;
-  case 0xf800:ROM_BANK16(0x8000,V);
-              X6502_Rebase();break;
+  case 0xf800:ROM_BANK16(0x8000,V);break;
  }
 }
 static void FP_FASTAPASS(1) SunIRQHook(int a)
@@ -58,7 +64,11 @@ static void FP_FASTAPASS(1) SunIRQHook(int a)
   {
    IRQCount-=a;
    if(IRQCount<=0)
-   {TriggerIRQ();IRQa=0;IRQCount=0xFFFF;}
+   {
+    X6502_IRQBegin(FCEU_IQEXT);
+    IRQa=0;
+    IRQCount=0xFFFF;
+   }
   }
 }
 void Mapper67_init(void)
index f1e5f68..9c25f1b 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -24,16 +24,16 @@ static void Fixerit(void)
 {
  switch(mapbyte2[0]&3)
  {
-  case 0:vnapage[0]=vnapage[2]=VROM+(((mapbyte1[0]|128)&CHRmask1[0])<<10);
-        vnapage[1]=vnapage[3]=VROM+(((mapbyte1[1]|128)&CHRmask1[0])<<10);
-        break;
-  case 1:vnapage[0]=vnapage[1]=VROM+(((mapbyte1[0]|128)&CHRmask1[0])<<10);
-         vnapage[2]=vnapage[3]=VROM+(((mapbyte1[1]|128)&CHRmask1[0])<<10);
+  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;
-  case 2:vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=VROM+(((mapbyte1[0]|128)&CHRmask1[0])<<10);
-        break;
-  case 3:vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=VROM+(((mapbyte1[1]|128)&CHRmask1[0])<<10);
-        break;
  }
 }
 
@@ -49,12 +49,12 @@ DECLFW(Mapper68_write)
  {
   case 0xc000:mapbyte1[0]=V;
               if(VROM_size && mapbyte2[0]&0x10)
-              Fixerit();
+               Fixerit();
               break;
 
   case 0xd000:mapbyte1[1]=V;
-             if(VROM_size && mapbyte2[0]&0x10)
-              Fixerit();
+              if(VROM_size && mapbyte2[0]&0x10)
+               Fixerit();
               break;
 
   case 0xe000: mapbyte2[0]=V;
@@ -69,13 +69,12 @@ DECLFW(Mapper68_write)
                 }
                }
                else if(VROM_size)
-              {
-               Fixerit();
-               PPUNTARAM=0;
-              }
+               {
+                Fixerit();
+                PPUNTARAM=0;
+               }
                break;
-  case 0xf000: ROM_BANK16(0x8000,V);
-               X6502_Rebase();break;
+  case 0xf000: ROM_BANK16(0x8000,V);break;
  }
 }
 
@@ -93,7 +92,7 @@ static void Mapper68_StateRestore(int version)
               }
               else if(VROM_size)
               {
-               Fixerit();
+                Fixerit();
                 PPUNTARAM=0;
               }
 }
index 3e427bb..948c304 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
  */
 
 #include "mapinc.h"
+
 static void AYSound(int Count);
+//static void AYSoundHQ(void);
 static void DoAYSQ(int x);
-static void DoAYNoise(void);
+//static void DoAYSQHQ(int x);
 
 #define sunselect mapbyte1[0]
 #define sungah    mapbyte1[1]
-#define sunindex  mapbyte1[2]
-
-static uint16 znreg;
-static int32 inc;
+static uint8 sunindex;
 
-DECLFW(SUN5BWRAM)
+static DECLFW(SUN5BWRAM)
 {
  if((sungah&0xC0)==0xC0)
   (WRAM-0x6000)[A]=V;
 }
 
-DECLFR(SUN5AWRAM)
+static DECLFR(SUN5AWRAM)
 {
  if((sungah&0xC0)==0x40)
   return X.DB;
  return CartBR(A);
 }
 
-DECLFW(Mapper69_SWL)
+static DECLFW(Mapper69_SWL)
 {
   sunindex=V%14;
 }
-DECLFW(Mapper69_SWH)
+
+static DECLFW(Mapper69_SWH)
 {
+             int x;
              GameExpSound.Fill=AYSound;
+             GameExpSound.HiFill=0;//AYSoundHQ;
+             if(FSettings.SndRate);
              switch(sunindex)
              {
               case 0:
               case 1:
-              case 8:DoAYSQ(0);break;
+              case 8:/*if(FSettings.soundq>=1) DoAYSQHQ(0); else*/ DoAYSQ(0);break;
               case 2:
               case 3:
-              case 9:DoAYSQ(1);break;
+              case 9:/*if(FSettings.soundq>=1) DoAYSQHQ(1); else*/ DoAYSQ(1);break;
               case 4:
               case 5:
-              case 10:DoAYSQ(2);break;
-              case 6:DoAYNoise();znreg=0xFFFF;break;
-              case 7:DoAYNoise();
-                     DoAYSQ(0);
-                     DoAYSQ(1);
-                     DoAYSQ(2);break;
+              case 10:/*if(FSettings.soundq>=1) DoAYSQHQ(2); else*/ DoAYSQ(2);break;
+              case 7:
+                     for(x=0;x<2;x++)
+                        /*if(FSettings.soundq>=1) DoAYSQHQ(x); else*/ DoAYSQ(x);
+                     break;
              }
              MapperExRAM[sunindex]=V;
 }
 
-DECLFW(Mapper69_write)
+static DECLFW(Mapper69_write)
 {
  switch(A&0xE000)
  {
@@ -91,14 +93,10 @@ DECLFW(Mapper69_write)
                         }
                         else
                          setprg8(0x6000,V);
-                        X6502_Rebase();
                         break;
-                case 9:ROM_BANK8(0x8000,V);
-                         X6502_Rebase();break;
-                case 0xa:ROM_BANK8(0xa000,V);
-                         X6502_Rebase();break;
-                case 0xb:ROM_BANK8(0xc000,V);
-                         X6502_Rebase();break;
+                case 9:ROM_BANK8(0x8000,V);break;
+                case 0xa:ROM_BANK8(0xa000,V);break;
+                case 0xb:ROM_BANK8(0xc000,V);break;
                 case 0xc:
                          switch(V&3)
                          {
@@ -108,165 +106,152 @@ DECLFW(Mapper69_write)
                           case 3:onemir(1);break;
                          }
                          break;
-             case 0xd:IRQa=V;break;
-             case 0xe:IRQCount&=0xFF00;IRQCount|=V;break;
-             case 0xf:IRQCount&=0x00FF;IRQCount|=V<<8;break;
+             case 0xd:IRQa=V;X6502_IRQEnd(FCEU_IQEXT);break;
+             case 0xe:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
+             case 0xf:IRQCount&=0x00FF;IRQCount|=V<<8;X6502_IRQEnd(FCEU_IQEXT);break;
              }
              break;
  }
 }
 
-static int32 vcount[4];
-static int CAYBC[4]={0,0,0,0};
+static int32 vcount[3];
+static int32 dcount[3];
+static int CAYBC[3];
+
 static void DoAYSQ(int x)
 {
-    int V;
-    uint32 freq;
-    unsigned char amp;
+    int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<(4+17);
+    int32 amp=(MapperExRAM[0x8+x]&15)<<2;
     int32 start,end;
+    int V;
+
+    amp+=amp>>1;
 
     start=CAYBC[x];
     end=(SOUNDTS<<16)/soundtsinc;
     if(end<=start) return;
     CAYBC[x]=end;
 
-    if(!(MapperExRAM[0x7]&(1<<x)))
+    if(amp)
+       if(!(MapperExRAM[0x7]&(1<<x)))
+    for(V=start;V<end;V++)
     {
-      long vcoo;
-      freq=(MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1;
-      inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/
-        ((long double)PSG_base/freq);
-                            amp=MapperExRAM[0x8+x]&15;
-              amp<<=3;
-              vcoo=vcount[x];
-             if(amp)
-              for(V=start;V<end;V++)
-               {
-                if(vcoo<(inc>>1))
-                  Wave[V>>4]+=amp;
-                vcoo+=0x1000;
-                if(vcoo>=inc) vcoo-=inc;
-                }
-              vcount[x]=vcoo;
+     if(dcount[x])
+      Wave[V>>4]+=amp;
+     vcount[x]-=nesincsize;
+     while(vcount[x]<=0)
+     {
+      dcount[x]^=1;
+      vcount[x]+=freq;
      }
+    }
 }
-static void DoAYNoise(void)
-{
-    int V;
-    uint32 freq;
-    unsigned char amp;
-    int32 start,end;
-
-    start=CAYBC[3];
-    end=(SOUNDTS<<16)/soundtsinc;
-    if(end<=start) return;
-    CAYBC[3]=end;
-
-        amp=0;
-        for(V=0;V<3;V++)
-         {
-          if(!(MapperExRAM[0x7]&(8<<V)))
-          {
-          //if(MapperExRAM[0x8+V]&0x10) amp+=MapperExRAM[0x20]&15;
-                                //else
-                                amp+=MapperExRAM[0x8+V]&15;
-          }
-         }
-     amp<<=3;
-
-     if(amp)
-       {
-        freq=PSG_base/(MapperExRAM[0x6]+1);
-        if(freq>44100)
-         inc=((freq<<11)/(FSettings.SndRate OVERSAMPLE))<<4;
-        else
-         inc=(freq<<15)/(FSettings.SndRate OVERSAMPLE);
 
-         for(V=start;V<end;V++)
-          {
-             static uint32 mixer;
-
-             if(vcount[3]>=32768)
-             {
-               unsigned char feedback;
-               mixer=0;
-               if(znreg&1) mixer+=amp;
-               feedback=((znreg>>13)&1)^((znreg>>14)&1);
-               znreg=(znreg<<1)+(feedback);
-               vcount[3]-=32768;
-             }
-             Wave[V>>4]+=mixer;
-             vcount[3]+=inc;
-           }
-       }
+#if 0
+static void DoAYSQHQ(int x)
+{
+ int32 V;
+ int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<4;
+ int32 amp=(MapperExRAM[0x8+x]&15)<<6;
 
+ amp+=amp>>1;
 
+ if(!(MapperExRAM[0x7]&(1<<x)))
+ {
+  for(V=CAYBC[x];V<SOUNDTS;V++)
+  {
+   if(dcount[x])
+    WaveHi[V]+=amp;
+   vcount[x]--;
+   if(vcount[x]<=0)
+   {
+    dcount[x]^=1;
+    vcount[x]=freq;
+   }
+  }
+ }
+ CAYBC[x]=SOUNDTS;
 }
+#endif
+
 static void AYSound(int Count)
 {
     int x;
     DoAYSQ(0);
     DoAYSQ(1);
     DoAYSQ(2);
-    DoAYNoise();
-    for(x=0;x<4;x++)
+    for(x=0;x<3;x++)
      CAYBC[x]=Count;
 }
 
+#if 0
+static void AYSoundHQ(void)
+{
+    DoAYSQHQ(0);
+    DoAYSQHQ(1);
+    DoAYSQHQ(2);
+}
+#endif
+
+static void AYHiSync(int32 ts)
+{
+ int x;
+
+ for(x=0;x<3;x++)
+  CAYBC[x]=ts;
+}
+
 static void FP_FASTAPASS(1) SunIRQHook(int a)
 {
   if(IRQa)
   {
    IRQCount-=a;
    if(IRQCount<=0)
-   {TriggerIRQ();IRQa=0;IRQCount=0xFFFF;}
+   {X6502_IRQBegin(FCEU_IQEXT);IRQa=0;IRQCount=0xFFFF;}
   }
 }
 
 void Mapper69_StateRestore(int version)
 {
-   if(version>=19)
+   if(mapbyte1[1]&0x40)
    {
-    if(mapbyte1[1]&0x40)
-    {
-     if(mapbyte1[1]&0x80) // Select WRAM
-      setprg8r(0x10,0x6000,0);
-    }
-    else
-     setprg8(0x6000,mapbyte1[1]);
+    if(mapbyte1[1]&0x80) // Select WRAM
+     setprg8r(0x10,0x6000,0);
    }
    else
-    mapbyte1[1]=0xC0;
+    setprg8(0x6000,mapbyte1[1]);
 }
 
-static void M69SC(void)
+void Mapper69_ESI(void)
 {
- if(FSettings.SndRate)
-  Mapper69_ESI();
- else
-  SetWriteHandler(0xc000,0xffff,(writefunc)0);
+ GameExpSound.RChange=Mapper69_ESI;
+ GameExpSound.HiSync=AYHiSync;
+ memset(dcount,0,sizeof(dcount));
+ memset(vcount,0,sizeof(vcount));
+ memset(CAYBC,0,sizeof(CAYBC));
 }
 
-void Mapper69_ESI(void)
+void NSFAY_Init(void)
 {
- GameExpSound.RChange=M69SC;
- if(FSettings.SndRate)
- {
-  SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
-  SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
- }
+ sunindex=0;
+ SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
+ SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
+ Mapper69_ESI();
 }
 
 void Mapper69_init(void)
 {
+ sunindex=0;
+
  SetupCartPRGMapping(0x10,WRAM,8192,1);
 
  SetWriteHandler(0x8000,0xbfff,Mapper69_write);
+ SetWriteHandler(0xc000,0xdfff,Mapper69_SWL);
+ SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
  SetWriteHandler(0x6000,0x7fff,SUN5BWRAM);
  SetReadHandler(0x6000,0x7fff,SUN5AWRAM);
  Mapper69_ESI();
  MapIRQHook=SunIRQHook;
  MapStateRestore=Mapper69_StateRestore;
- znreg=0;
 }
 
index 4c34706..9b1a99d 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -29,8 +29,7 @@ switch(A&0xF000)
  case 0xF000:
  case 0xE000:
  case 0xD000:
- case 0xC000:ROM_BANK16(0x8000,V);
-             X6502_Rebase();break;
+ case 0xC000:ROM_BANK16(0x8000,V);break;
  case 0x9000:onemir((V>>3)&2);break;
  }
 }
index c0a2c63..480a035 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -25,10 +25,7 @@ DECLFW(Mapper72_write)
 {
  mapbyte1[0]=V;
  if(V&0x80)
- {
   ROM_BANK16(0x8000,V&0xF);
-  X6502_Rebase();
- }
  if(V&0x40)
   VROM_BANK8(V&0xF);
 }
index 0911fd8..b49fa24 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 
 
-DECLFW(Mapper73_write)
+static DECLFW(Mapper73_write)
 {
-switch(A&0xF000)
+ //if(A>=0xd000 && A<=0xdfff)
+  X6502_IRQEnd(FCEU_IQEXT);        /* How are IRQs acknowledged on this chip? */
+ switch(A&0xF000)
  {
case 0x8000:IRQCount&=0xFFF0;IRQCount|=(V&0xF);break;
case 0x9000:IRQCount&=0xFF0F;IRQCount|=(V&0xF)<<4;break;
case 0xa000:IRQCount&=0xF0FF;IRQCount|=(V&0xF)<<8;break;
case 0xb000:IRQCount&=0x0FFF;IRQCount|=(V&0xF)<<12;break;
case 0xc000:IRQa=V&2;break;
case 0xf000:ROM_BANK16(0x8000,V);
-             X6502_Rebase();break;
 //default: printf("$%04x:$%02x\n",A,V);break;
 case 0x8000:IRQCount&=0xFFF0;IRQCount|=(V&0xF);break;
 case 0x9000:IRQCount&=0xFF0F;IRQCount|=(V&0xF)<<4;break;
 case 0xa000:IRQCount&=0xF0FF;IRQCount|=(V&0xF)<<8;break;
 case 0xb000:IRQCount&=0x0FFF;IRQCount|=(V&0xF)<<12;break;
 case 0xc000:IRQa=V&2;break;
+  case 0xf000:ROM_BANK16(0x8000,V);break;
  }
 }
 
@@ -45,7 +47,7 @@ static void FP_FASTAPASS(1) Mapper73IRQHook(int a)
   {
    IRQCount&=0xFFFF;
    IRQa=0;
-   TriggerIRQ();
+   X6502_IRQBegin(FCEU_IQEXT);
   }
  }
 }
index cf0c6ee..f2b00bd 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -28,16 +28,13 @@ DECLFW(Mapper75_write)
 {
 switch(A&0xF000)
  {
- case 0x8000:ROM_BANK8(0x8000,V);
-             X6502_Rebase();break;
+ case 0x8000:ROM_BANK8(0x8000,V);break;
  case 0x9000:
              VROM_BANK4(0x0000,map75ar[0]|((V&2)<<3));
              VROM_BANK4(0x1000,map75ar[1]|((V&4)<<2));
              map75sel=V;MIRROR_SET(V&1);break;
- case 0xa000:ROM_BANK8(0xa000,V);
-             X6502_Rebase();break;
- case 0xc000:ROM_BANK8(0xc000,V);
-             X6502_Rebase();break;
+ case 0xa000:ROM_BANK8(0xa000,V);break;
+ case 0xc000:ROM_BANK8(0xc000,V);break;
  case 0xe000:V&=0xF;map75ar[0]=V;V|=(map75sel&2)<<3;VROM_BANK4(0x0000,V);break;
  case 0xf000:V&=0xF;map75ar[1]=V;V|=(map75sel&4)<<2;VROM_BANK4(0x1000,V);break;
  }
index 40aa821..a59ef1e 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
  */
 
 #include "mapinc.h"
+static uint8 MMC3_cmd;
 
-
-
-DECLFW(Mapper76_write)
+static DECLFW(Mapper76_write)
 {
         switch(A&0xE001){
         case 0x8000:
@@ -35,12 +34,10 @@ DECLFW(Mapper76_write)
                 case 4: VROM_BANK2(0x1000,V);break;
                 case 5: VROM_BANK2(0x1800,V);break;
                 case 6:
-                        if (MMC3_cmd&0x40) ROM_BANK8(0xC000,V);
+                        if(MMC3_cmd&0x40) ROM_BANK8(0xC000,V);
                         else ROM_BANK8(0x8000,V);
-                        X6502_Rebase();
                         break;
                 case 7: ROM_BANK8(0xA000,V);
-                        X6502_Rebase();
                         break;
                }
                break;
index e3c0e52..06f15cc 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -27,18 +27,16 @@ static DECLFW(Mapper77_write)
  mapbyte1[0]=V;
  ROM_BANK32(V&0x7);
  VROM_BANK2(0x0000, (V&0xf0)>>4);
- X6502_Rebase();
 }
 
 static void Mapper77_StateRestore(int version)
 {
  int x;
-
- if(version>=72)
+ if(version>=7200)
  {
   ROM_BANK32(mapbyte1[0]&0x7);
   VROM_BANK2(0x0000, (mapbyte1[0]&0xf0)>>4);
-  X6502_Rebase();
  }
  for(x=2;x<8;x++)
   VRAM_BANK1(x*0x400,x);
index 1e9d219..9148eae 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -27,7 +27,6 @@ DECLFW(Mapper79_write)
  if(A<0x8000 && ((A^0x4100)==0))
  {
   ROM_BANK32((V>>3)&1);
-  X6502_Rebase();
  }
  VROM_BANK8(V);
 }
index 46a7d00..53c91a2 100644 (file)
@@ -1,8 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
+ *  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
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
 #include "mapinc.h"
 
-
-
-DECLFW(Mapper8_write)
+static DECLFW(Mapper8_write)
 {
         ROM_BANK16(0x8000,V>>3);
         VROM_BANK8(V&7);
-        X6502_Rebase();
 }
 
 void Mapper8_init(void)
 {
-       ROM_BANK32(0);
+        ROM_BANK32(0);
         SetWriteHandler(0x8000,0xFFFF,Mapper8_write);
 }
 
index b867398..1e7982e 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
+static uint32 lastA;
+static int isfu;
+static uint8 CCache[8];
 
+static void FP_FASTAPASS(1) Fudou_PPU(uint32 A)
+{
+ static int last=-1;
+ static uint8 z;
+  
+ if(A>=0x2000) return;
+
+ A>>=10;
+ lastA=A;
+
+ z=CCache[A];
+ if(z!=last)
+ {
+  onemir(z);
+  last=z;
+ }
+}
+
+static void mira()
+{
+ if(isfu)
+ {
+  int x;
+  CCache[0]=CCache[1]=mapbyte2[0]>>7;
+  CCache[2]=CCache[3]=mapbyte2[1]>>7;
 
-DECLFW(Mapper80_write)
+  for(x=0;x<4;x++)
+   CCache[4+x]=mapbyte2[2+x]>>7;
+
+  onemir(CCache[lastA]);
+ }
+ else
+  MIRROR_SET2(mapbyte1[0]&1);
+}
+
+static DECLFW(Mapper80_write)
 {
-switch(A)
+ switch(A)
  {
-  case 0x7ef0: VROM_BANK1(0x000,V);VROM_BANK1(0x400,(V+1));break;
-  case 0x7ef1: VROM_BANK1(0x800,V);VROM_BANK1(0xC00,(V+1));break;
+  case 0x7ef0: mapbyte2[0]=V;VROM_BANK2(0x0000,(V>>1)&0x3F);mira();break;
+  case 0x7ef1: mapbyte2[1]=V;VROM_BANK2(0x0800,(V>>1)&0x3f);mira();break;
 
-  case 0x7ef2: VROM_BANK1(0x1000,V);break;
-  case 0x7ef3: VROM_BANK1(0x1400,V);break;
-  case 0x7ef4: VROM_BANK1(0x1800,V);break;
-  case 0x7ef5: VROM_BANK1(0x1c00,V);break;
+  case 0x7ef2: mapbyte2[2]=V;VROM_BANK1(0x1000,V);mira();break;
+  case 0x7ef3: mapbyte2[3]=V;VROM_BANK1(0x1400,V);mira();break;
+  case 0x7ef4: mapbyte2[4]=V;VROM_BANK1(0x1800,V);mira();break;
+  case 0x7ef5: mapbyte2[5]=V;VROM_BANK1(0x1c00,V);mira();break;
+  case 0x7ef6: mapbyte1[0]=V;mira();break;
   case 0x7efa:
-  case 0x7efb: ROM_BANK8(0x8000,V);
-               X6502_Rebase();break;
+  case 0x7efb: ROM_BANK8(0x8000,V);break;
   case 0x7efd:
-  case 0x7efc: ROM_BANK8(0xA000,V);
-               X6502_Rebase();break;
+  case 0x7efc: ROM_BANK8(0xA000,V);break;
   case 0x7efe:
-  case 0x7eff: ROM_BANK8(0xC000,V);
-               X6502_Rebase();break;
+  case 0x7eff: ROM_BANK8(0xC000,V);break;
  }
 }
 
+static void booga(int version)
+{
+ mira();
+}
+
 void Mapper80_init(void)
 {
-SetWriteHandler(0x4020,0x7fff,Mapper80_write);
+ SetWriteHandler(0x4020,0x7fff,Mapper80_write);
+ MapStateRestore=booga;
+ isfu=0;
 }
 
+void Mapper207_init(void)
+{
+ Mapper80_init();
+ isfu=1;
+ PPU_hook=Fudou_PPU;
+}
index a4f643e..b4288b1 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -20,7 +20,7 @@
 
 #include "mapinc.h"
 
-#define ctrl   mapbyte1[6]
+#define ctrl        mapbyte1[6]
 
 static void DoCHR(void)
 {
@@ -43,15 +43,12 @@ static DECLFW(Mapper82_write)
   switch(A)
   {
    case 0x7ef6:ctrl=V&3;
-              MIRROR_SET2(V&1);
-              DoCHR();
-              break;
-   case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);
-               X6502_Rebase();break;
-   case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);
-               X6502_Rebase();break;
-   case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);
-               X6502_Rebase();break;
+               MIRROR_SET2(V&1);
+                DoCHR();
+                 break;
+   case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);break;
+   case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);break;
+   case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);break;
   }
 }
 
index 5cc7d03..3ab004f 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
-void FP_FASTAPASS(1) m83IRQHook(int a)
+
+/*void Mapper83_init(void)
+{             
+} 
+*/
+static void FP_FASTAPASS(1) m83IRQHook(int a)
 {
   if(IRQa)
   {
    IRQCount-=a;
    if(IRQCount<0)
    {
-    TriggerIRQ();
+    X6502_IRQBegin(FCEU_IQEXT);
     IRQa=0;
     IRQCount=0xFFFF;
    }
@@ -46,9 +52,8 @@ static DECLFR(rdlow)
 
 static void m83prg(void)
 {
-  ROM_BANK16(0x8000,mapbyte1[0]&0x3F);
+  ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); 
   ROM_BANK16(0xC000,(mapbyte1[0]&0x30)|0xF);
-  X6502_Rebase();
 }
 
 static void m83chr(void)
@@ -82,11 +87,11 @@ static DECLFW(Mapper83_write)
               case 0x03:onemir(1);break;
               }
               break;
-  case 0x8200:IRQCount&=0xFF00;IRQCount|=V;break;
+  case 0x8200:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
   case 0x8201:IRQa=1;IRQCount&=0xFF;IRQCount|=V<<8;break;
-  //case 0x8300:ROM_BANK8(0x8000,V);break;
-  //case 0x8301:ROM_BANK8(0xA000,V);break;
-  //case 0x8302:ROM_BANK8(0xC000,V);break;
+  case 0x8300:ROM_BANK8(0x8000,V);break;
+  case 0x8301:ROM_BANK8(0xA000,V);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;
@@ -95,14 +100,14 @@ static DECLFW(Mapper83_write)
   case 0x8315:mapbyte2[5]=V;m83chr();break;
   case 0x8316:mapbyte2[6]=V;m83chr();break;
   case 0x8317:mapbyte2[7]=V;m83chr();break;
+  case 0x8318:mapbyte1[1]=V;m83prg();break;
  }
 // printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W);
-
 }
 
 void Mapper83_init(void)
 {
-
  ROM_BANK8(0xc000,0x1e);
  ROM_BANK8(0xe000,0x1f);
 
@@ -111,4 +116,5 @@ void Mapper83_init(void)
  SetReadHandler(0x5100,0x5103,rdlow);
  SetWriteHandler(0x5100,0x5103,wrlow);
  SetWriteHandler(0x8000,0xffff,Mapper83_write);
+ mapbyte1[1]=0xF;
 }
index c93788b..bae3b66 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 #include "mapinc.h"
 
 #define vrctemp mapbyte1[0]
-#define indox  mapbyte1[1]
+static uint8 indox;
+
+#include "emu2413.h"
 
 static int acount=0;
 
-void KillOPL(void);
-void UpdateOPL(int Count);
-void vrc7translate(uint8 A, uint8 V);
-void LoadOPL(void);
-extern uint8 VRC7Instrument[16][8];
-extern uint8 VRC7Chan[3][6];
+static OPLL *VRC7Sound=NULL;
+static int dwave=0;
+
+void DoVRC7Sound(void)
+{
+ int32 z,a;
+
+ //if(FSettings.soundq>=1) return;
+ z=((SOUNDTS<<16)/soundtsinc)>>4;
+ a=z-dwave;
+
+ moocow(VRC7Sound, &Wave[dwave], a, 1);
+
+ dwave+=a;
+}
+
+void UpdateOPLNEO(int32 *Wave, int Count)
+{
+ moocow(VRC7Sound, Wave, Count, 4);
+}
+
+void UpdateOPL(int Count)
+{
+ int32 z,a;
+
+  z=((SOUNDTS<<16)/soundtsinc)>>4;
+ a=z-dwave;
+
+ if(VRC7Sound && a)
+  moocow(VRC7Sound, &Wave[dwave], a, 1);
+
+ dwave=0;
+}
 
 static INLINE void DaMirror(int V)
 {
@@ -40,55 +69,64 @@ static INLINE void DaMirror(int V)
 
 DECLFW(Mapper85_write)
 {
-       A|=(A&8)<<1;
-
-       if(A>=0xa000 && A<=0xDFFF)
-       {
-        A&=0xF010;
-        {
-         int x=((A>>4)&1)|((A-0xA000)>>11);
-         mapbyte3[x]=V;
-         setchr1(x<<10,V);
-        }
-       }
-       else if(A==0x9030)
-       {
-        if(FSettings.SndRate)
-          vrc7translate(indox,V);
-         GameExpSound.Fill=UpdateOPL;
-       }
-       else switch(A&0xF010)
+        A|=(A&8)<<1;
+
+        if(A>=0xa000 && A<=0xDFFF)
+        {
+        // printf("$%04x, $%04x\n",X.PC,A);
+         A&=0xF010;
+         {
+          int x=((A>>4)&1)|((A-0xA000)>>11);
+           mapbyte3[x]=V;
+          setchr1(x<<10,V);
+         }
+        }
+        else if(A==0x9030)
+        {
+         if(FSettings.SndRate)
+         {
+          OPLL_writeReg(VRC7Sound, indox, V);
+          GameExpSound.Fill=UpdateOPL;
+          GameExpSound.NeoFill=UpdateOPLNEO;
+         }
+        }
+        else switch(A&0xF010)
         {
-         case 0x8000:mapbyte2[0]=V;setprg8(0x8000,V);
-                     X6502_Rebase();break;
-         case 0x8010:mapbyte2[1]=V;setprg8(0xa000,V);
-                     X6502_Rebase();break;
-         case 0x9000:mapbyte2[2]=V;setprg8(0xc000,V);
-                     X6502_Rebase();break;
+         case 0x8000:mapbyte2[0]=V;setprg8(0x8000,V);break;
+         case 0x8010:mapbyte2[1]=V;setprg8(0xa000,V);break;
+         case 0x9000:mapbyte2[2]=V;setprg8(0xc000,V);break;
          case 0x9010:indox=V;break;
          case 0xe000:mapbyte2[3]=V;DaMirror(V);break;
          case 0xE010:IRQLatch=V;
+                     X6502_IRQEnd(FCEU_IQEXT);
                      break;
          case 0xF000:IRQa=V&2;
                      vrctemp=V&1;
-                     if(V&2) {IRQCount=IRQLatch;acount=0;}
+                     if(V&2) {IRQCount=IRQLatch;}
+                     acount=0;
+                     X6502_IRQEnd(FCEU_IQEXT);
                      break;
          case 0xf010:if(vrctemp) IRQa=1;
                      else IRQa=0;
+                     X6502_IRQEnd(FCEU_IQEXT);
                      break;
         }
 }
 
 static void FP_FASTAPASS(1) KonamiIRQHook(int a)
 {
+  #define ACBOO 341
+//  #define ACBOO ((227*2)+1)
   if(IRQa)
    {
-    acount+=(a<<1)+a;
-    if(acount>=339)
+    acount+=a*3;
+
+    if(acount>=ACBOO)
     {
-     doagainbub:acount-=339;IRQCount++;
-     if(IRQCount&0x100) {TriggerIRQ();IRQCount=IRQLatch;}
-     if(acount>=339) goto doagainbub;
+     doagainbub:acount-=ACBOO;
+     IRQCount++;
+     if(IRQCount&0x100) {X6502_IRQBegin(FCEU_IQEXT);IRQCount=IRQLatch;}
+     if(acount>=ACBOO) goto doagainbub;
     }
  }
 }
@@ -97,7 +135,7 @@ void Mapper85_StateRestore(int version)
 {
  int x;
 
- if(version<72)
+ if(version<7200)
  {
   for(x=0;x<8;x++)
    mapbyte3[x]=CHRBankList[x];
@@ -111,22 +149,37 @@ void Mapper85_StateRestore(int version)
  for(x=0;x<3;x++)
   setprg8(0x8000+x*8192,mapbyte2[x]);
  DaMirror(mapbyte2[3]);
- LoadOPL();
//LoadOPL();
 }
 
 static void M85SC(void)
 {
-  KillOPL();
+ if(VRC7Sound)
+  OPLL_set_rate(VRC7Sound, FSettings.SndRate);
 }
 
-void VRC7_ESI(void)
+static void M85SKill(void)
+{
+ if(VRC7Sound)
+  OPLL_delete(VRC7Sound);
+ VRC7Sound=NULL;
+}
+
+static void VRC7SI(void)
+{
+  GameExpSound.RChange=M85SC;
+  GameExpSound.Kill=M85SKill;
+
+  VRC7Sound=OPLL_new(3579545, FSettings.SndRate?FSettings.SndRate:44100);
+  OPLL_reset(VRC7Sound);
+  OPLL_reset(VRC7Sound);
+}
+
+void NSFVRC7_Init(void)
 {
-   if(FSettings.SndRate)
-   {
     SetWriteHandler(0x9010,0x901F,Mapper85_write);
     SetWriteHandler(0x9030,0x903F,Mapper85_write);
-   }
-   GameExpSound.RChange=M85SC;
+    VRC7SI();
 }
 
 void Mapper85_init(void)
@@ -134,10 +187,9 @@ void Mapper85_init(void)
   MapIRQHook=KonamiIRQHook;
   SetWriteHandler(0x8000,0xffff,Mapper85_write);
   GameStateRestore=Mapper85_StateRestore;
-  VRC7_ESI();
   if(!VROM_size)
    SetupCartCHRMapping(0, CHRRAM, 8192, 1);
-  AddExState(VRC7Instrument, 16, 0, "VC7I");
-  AddExState(VRC7Chan, sizeof(VRC7Chan), 0, "V7CH");
-
+  //AddExState(VRC7Instrument, 16, 0, "VC7I");
+  //AddExState(VRC7Chan, sizeof(VRC7Chan), 0, "V7CH");
+  VRC7SI();
 }
index 60777b8..8404985 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 DECLFW(Mapper86_write)
 {
- VROM_BANK8((V&3)|((V>>4)&4));
- ROM_BANK32((V>>4)&3);
- X6502_Rebase();
+ if(A>=0x6000 && A<=0x6fFF)
+ {
+  VROM_BANK8((V&3)|((V>>4)&4));
+  ROM_BANK32((V>>4)&3);
+ }
+ //else
+ //if(A!=0x6000)
+ // printf("$%04x:$%02x\n",A,V);
 }
-
 void Mapper86_init(void)
 {
- SetWriteHandler(0x6000,0x6000,Mapper86_write);
+ SetWriteHandler(0x6000,0x6fff,Mapper86_write);
+ SetWriteHandler(0x4020,0xffff,Mapper86_write);
 }
index 84c9ded..96ef0ed 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
+static int mn;
 static DECLFW(Mapper88_write)
 {
  //if(A>=0x8002 || A<0x8000)
  //if(A==0xc000)
  // printf("$%04x:$%02x\n",A,V);
- switch(A) //&0xc001)
+ switch(A&0x8001) //&0xc001)
  {
-             //case 0xc000:
-             //MIRROR_SET((V&0x40)>>6);
-             //onemir((V&0x40)>>6);
-             //break;
-  case 0x8000:mapbyte1[0]=V;break;
+  case 0x8000:mapbyte1[0]=V;
+              if(mn)
+               onemir((V>>6)&1);
+              break;
   case 0x8001:
-             switch(mapbyte1[0]&7)
-             {
-              case 0:VROM_BANK2(0,V>>1);break;
-              case 1:VROM_BANK2(0x800,V>>1);break;
-              case 2:VROM_BANK1(0x1000,V|0x40);break;
-              case 3:VROM_BANK1(0x1400,V|0x40);break;
-              case 4:VROM_BANK1(0x1800,V|0x40);break;
-              case 5:VROM_BANK1(0x1c00,V|0x40);break;
-              case 6:ROM_BANK8(0x8000,V);
-                      X6502_Rebase();break;
-              case 7:ROM_BANK8(0xA000,V);
-                      X6502_Rebase();break;
-             }
-             break;
+              switch(mapbyte1[0]&7)
+              {
+               case 0:VROM_BANK2(0,V>>1);break;
+               case 1:VROM_BANK2(0x800,V>>1);break;
+               case 2:VROM_BANK1(0x1000,V|0x40);break;
+               case 3:VROM_BANK1(0x1400,V|0x40);break;
+               case 4:VROM_BANK1(0x1800,V|0x40);break;
+               case 5:VROM_BANK1(0x1c00,V|0x40);break;
+               case 6:ROM_BANK8(0x8000,V);break;
+               case 7:ROM_BANK8(0xA000,V);break;
+              }
+              break;
 
  }
 }
 
 void Mapper88_init(void)
 {
+  mn=0;
   SetWriteHandler(0x8000,0xffff,Mapper88_write);
 }
 
+void Mapper154_init(void)
+{
+ mn=1;
+ SetWriteHandler(0x8000,0xffff,Mapper88_write);
+}
index cdc028a..a3a6f09 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -25,7 +25,6 @@ DECLFW(Mapper89_write)
  VROM_BANK8((V&7)|((V>>4)&8));
  ROM_BANK16(0x8000,(V>>4)&7);
  onemir((V>>3)&1);
- X6502_Rebase();
 }
 
 void Mapper89_init(void)
diff --git a/mappers/90.c b/mappers/90.c
deleted file mode 100644 (file)
index 35ceb0d..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 tkcom1 mapbyte1[1]
-#define tkcom2 mapbyte1[2]
-
-#define prgb   mapbyte2
-#define unkl   (mapbyte2+4)
-#define chrlow  mapbyte3
-#define chrhigh mapbyte4
-
-static uint8 tekker=0x80;
-
-static DECLFR(tekread)
-{
- return tekker;
-}
-
-static void tekprom(void)
-{
- switch(tkcom1&3)
-  {
-   case 1:              // 16 KB
-          ROM_BANK16(0x8000,prgb[0]);
-          ROM_BANK16(0xC000,prgb[2]);
-          break;
-
-   case 2:              //2 = 8 KB ??
-   case 3:
-          ROM_BANK8(0x8000,prgb[0]);
-          ROM_BANK8(0xa000,prgb[1]);
-          ROM_BANK8(0xc000,prgb[2]);
-          ROM_BANK8(0xe000,prgb[3]);
-          break;
-  }
-  X6502_Rebase();
-}
-
-static void tekvrom(void)
-{
- int x;
- switch(tkcom1&0x18)
-  {
-   case 0x00:      // 8KB
-           VROM_BANK8(chrlow[0]|(chrhigh[0]<<8));
-          break;
-   case 0x08:      // 4KB
-          for(x=0;x<8;x+=4)
-           VROM_BANK4(x<<10,chrlow[x]|(chrhigh[x]<<8));
-         break;
-   case 0x10:      // 2KB
-         for(x=0;x<8;x+=2)
-           VROM_BANK2(x<<10,chrlow[x]|(chrhigh[x]<<8));
-         break;
-   case 0x18:      // 1KB
-          for(x=0;x<8;x++)
-           VROM_BANK1(x<<10,chrlow[x]|(chrhigh[x]<<8));
-          break;
- }
-}
-
-static DECLFW(Mapper90_write)
-{
- A&=0xF007;
-
- if(A>=0x8000 && A<=0x8003)
- {
-  prgb[A&3]=V;
-  tekprom();
- }
- else if(A>=0x9000 && A<=0x9007)
- {
-  chrlow[A&7]=V;
-  tekvrom();
- }
- else if(A>=0xa000 && A<=0xa007)
- {
-  chrhigh[A&7]=V;
-  tekvrom();
- }
- else if(A>=0xb000 && A<=0xb003)
- {
-  unkl[A&3]=V;
- }
- else switch(A)
- {
-   case 0xc004:
-   case 0xc000:IRQLatch=V;break;
-
-   case 0xc005:
-   case 0xc001:X6502_IRQEnd(FCEU_IQEXT);
-               IRQCount=V;break;
-   case 0xc006:
-   case 0xc002:X6502_IRQEnd(FCEU_IQEXT);
-               IRQa=0;
-               IRQCount=IRQLatch;
-               break;
-   case 0xc007:
-   case 0xc003:IRQa=1;break;
-
-   case 0xd000:tkcom1=V;break;
-   case 0xd001:switch(V&3){
-                  case 0x00:MIRROR_SET(0);break;
-                  case 0x01:MIRROR_SET(1);break;
-                  case 0x02:onemir(0);break;
-                  case 0x03:onemir(1);break;
-               }
-              break;
-   break;
- }
-}
-
-static void Mapper90_hb(void)
-{
- if(IRQa)
- {
-  if(IRQCount)
-  {
-   IRQCount--;
-   if(!IRQCount)
-   {
-    X6502_IRQBegin(FCEU_IQEXT);
-    IRQCount=IRQLatch;
-   }
-  }
- }
-}
-
-void Mapper90_init(void)
-{
-  tekker^=0x80;
-  SetWriteHandler(0x8000,0xffff,Mapper90_write);
-  SetReadHandler(0x5000,0x5000,tekread);
-  GameHBIRQHook=Mapper90_hb;
-}
-
diff --git a/mappers/91.c b/mappers/91.c
new file mode 100644 (file)
index 0000000..8858103
--- /dev/null
@@ -0,0 +1,59 @@
+/* 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(Mapper91_write)
+{
+//if(A>=0x7001)
+//printf("$%04x:$%02x, %d\n",A,V,scanline);
+ A&=0xF007;
+
+ if(A>=0x6000 && A<=0x6003) VROM_BANK2((A&3)*2048,V);
+ else switch(A&0xF003)
+ {
+  case 0x7000:
+  case 0x7001:ROM_BANK8(0x8000+(A&1)*8192,V);break;
+  case 0x7002:IRQa=IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break;
+  case 0x7003:IRQa=1;X6502_IRQEnd(FCEU_IQEXT);break;
+//  default: printf("Iyee: $%04x:$%02x\n",A,V);break;
+ }
+ //if(A>=0x7000)
+ // printf("$%04x:$%02x, %d\n",A,V,scanline);
+}
+
+static void Mapper91_hb(void)
+{
+ if(IRQCount<8 && IRQa)
+ {
+  IRQCount++;
+  if(IRQCount>=8)
+  {
+    X6502_IRQBegin(FCEU_IQEXT);   
+  } 
+ }
+}
+
+void Mapper91_init(void)
+{
+  SetWriteHandler(0x4020,0xFFFF,Mapper91_write);
+  GameHBIRQHook=Mapper91_hb;
+} 
+
index 4b8ce71..e2ad374 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -29,12 +29,12 @@ static DECLFW(Mapper92_write)
 
  if(A>=0x9000)
  {
-  if(reg==0xD) { ROM_BANK16(0xc000,bank); X6502_Rebase(); }
+  if(reg==0xD) ROM_BANK16(0xc000,bank);
   else if(reg==0xE) VROM_BANK8(bank);
  }
  else
  {
-  if(reg==0xB) { ROM_BANK16(0xc000,bank); X6502_Rebase(); }
+  if(reg==0xB) ROM_BANK16(0xc000,bank);
   else if(reg==0x7) VROM_BANK8(bank);
  }
 }
index 4b208be..11b6a8e 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
 
 #include "mapinc.h"
 
+static uint8 lastA;
+static uint8 DRegs[8];
+static uint8 cmd;
+static uint8 MirCache[8];
+
+static SFORMAT DB_StateRegs[]={
+        {DRegs, 8, "DREG"},
+        {&cmd, 1, "CMD"},
+        {&lastA, 1, "LAST"},
+        {0}
+};
 
-#define dbarray mapbyte1
 static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A)
 {
  static int last=-1;
@@ -29,10 +39,11 @@ static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A)
 
  if(A>=0x2000) return;
 
- A>>=13;
+ A>>=10;
 
z=dbarray[A];
lastA=A;
 
+ z=MirCache[A];
  if(z!=last)
  {
   onemir(z);
@@ -40,39 +51,86 @@ static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A)
  }
 }
 
+static void toot(void)
+{
+ int x;
+
+ MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1;
+ MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1;
 
-DECLFW(Mapper95_write)
+ for(x=0;x<4;x++)
+  MirCache[4+x]=(DRegs[2+x]>>5)&1;
+ onemir(MirCache[lastA]);
+}
+
+static DECLFW(Mapper95_write)
 {
-        switch(A&0xF001){
-
-        case 0x8000:
-        MMC3_cmd = V;
-        break;
-
-        case 0x8001:
-                switch(MMC3_cmd&7){
-                case 0: dbarray[0]=dbarray[1]=(V&0x20)>>4;onemir((V&0x20)>>4);V>>=1;VROM_BANK2(0x0000,V);break;
-                case 1: dbarray[2]=dbarray[3]=(V&0x20)>>4;onemir((V&0x20)>>4);V>>=1;VROM_BANK2(0x0800,V);break;
-                case 2: dbarray[4]=(V&0x20)>>4;onemir((V&0x20)>>4);VROM_BANK1(0x1000,V); break;
-                case 3: dbarray[5]=(V&0x20)>>4;onemir((V&0x20)>>4);VROM_BANK1(0x1400,V); break;
-                case 4: dbarray[6]=(V&0x20)>>4;onemir((V&0x20)>>4);VROM_BANK1(0x1800,V); break;
-                case 5: dbarray[7]=(V&0x20)>>4;onemir((V&0x20)>>4);VROM_BANK1(0x1C00,V); break;
-                case 6:
-                        ROM_BANK8(0x8000,V);
-                        X6502_Rebase();
-                        break;
-                case 7:
-                        ROM_BANK8(0xA000,V);
-                        X6502_Rebase();
-                        break;
+        switch(A&0xF001)
+        {
+
+         case 0x8000:
+         cmd = V;
+         break;
+
+         case 0x8001:
+                switch(cmd&0x07)
+                {
+                 case 0: DRegs[0]=(V&0x3F)>>1;toot();V>>=1;setchr2(0x0000,V&0x1F);break;
+                 case 1: DRegs[1]=(V&0x3F)>>1;toot();V>>=1;setchr2(0x0800,V&0x1F);break;
+                 case 2: DRegs[2]=V&0x3F;toot();setchr1(0x1000,V&0x1F); break;
+                 case 3: DRegs[3]=V&0x3F;toot();setchr1(0x1400,V&0x1F); break;
+                 case 4: DRegs[4]=V&0x3F;toot();setchr1(0x1800,V&0x1F); break;
+                 case 5: DRegs[5]=V&0x3F;toot();setchr1(0x1C00,V&0x1F); break;
+                 case 6: DRegs[6]=V&0x3F;
+                         setprg8(0x8000,V);
+                         break;
+                 case 7: DRegs[7]=V&0x3F;
+                         setprg8(0xA000,V);
+                         break;
                 }
                 break;
+        }
 }
+
+static void DBSync()
+{
+ int x;
+
+ setchr2(0x0000,DRegs[0]);
+ setchr2(0x0800,DRegs[1]);
+
+ for(x=0;x<4;x++)
+  setchr1(0x1000+x*0x400,DRegs[2+x]);
+
+ setprg8(0x8000,DRegs[6]);
+ setprg8(0xa000,DRegs[7]);
+ toot();
+}
+
+static void DBPower(void)
+{
+ memset(DRegs,0x3F,8);
+ DRegs[0]=DRegs[1]=0x1F;
+
+ DBSync();
+
+ setprg8(0xc000,0x3E);
+ setprg8(0xe000,0x3F);
+
+ SetReadHandler(0x8000,0xffff,CartBR);
+ SetWriteHandler(0x8000,0xffff,Mapper95_write);
+}
+
+static void StateRestore(int version)
+{
+ DBSync();
 }
 
-void Mapper95_init(void)
+void Mapper95_Init(CartInfo *info)
 {
-  SetWriteHandler(0x8000,0xffff,Mapper95_write);
+  info->Power=DBPower;
+  AddExState(DB_StateRegs, ~0, 0, 0);
   PPU_hook=dragonbust_ppu;
+  GameStateRestore=StateRestore;
 }
 
index e02b12d..2990c0e 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -25,7 +25,6 @@
 DECLFW(Mapper97_write)
 {
 ROM_BANK16(0xC000,V&15);
-X6502_Rebase();
 switch(V>>6)
  {
  case 0:break;
index c71611e..7a55536 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -26,10 +26,12 @@ static DECLFW(morko)
 {
  VROM_BANK8((V>>2)&1);
  oldmorko(A,V);
+ setprg8(0x8000,V&0x4);        /* Special for VS Gumshoe */
 }
 
 void Mapper99_init(void)
 {
+ ROM_BANK32(0);
  oldmorko=GetWriteHandler(0x4016);
  SetWriteHandler(0x4016,0x4016,morko);
 }
index c95ca8f..a29a0bf 100644 (file)
@@ -1,74 +1,13 @@
-MOBJS   =      mappers/mmc2and4.o mappers/simple.o mappers/112.o mappers/117.o mappers/15.o mappers/151.o mappers/16.o mappers/17.o mappers/18.o mappers/180.o mappers/184.o mappers/19.o  mappers/21.o mappers/22.o mappers/225.o mappers/226.o mappers/228.o mappers/229.o mappers/23.o mappers/24and26.o mappers/240.o mappers/246.o mappers/25.o mappers/32.o mappers/33.o mappers/40.o mappers/41.o mappers/6.o mappers/64.o mappers/65.o mappers/67.o mappers/68.o mappers/69.o mappers/71.o mappers/73.o mappers/75.o mappers/76.o mappers/79.o mappers/8.o mappers/80.o mappers/85.o mappers/90.o mappers/95.o mappers/97.o mappers/99.o mappers/182.o mappers/vrc7snd.o mappers/46.o mappers/43.o mappers/42.o mappers/113.o mappers/86.o mappers/89.o mappers/83.o mappers/77.o mappers/92.o mappers/105.o mappers/88.o mappers/248.o mappers/fmopl.o mappers/242.o mappers/232.o mappers/72.o mappers/234.o mappers/227.o mappers/82.o mappers/189.o mappers/245.o mappers/249.o mappers/51.o
+MOBJS += mappers/6.o mappers/8.o mappers/15.o mappers/16.o mappers/17.o mappers/18.o mappers/21.o mappers/22.o
+MOBJS += mappers/23.o mappers/24and26.o mappers/25.o mappers/27.o mappers/32.o mappers/33.o mappers/40.o
+MOBJS += mappers/41.o mappers/42.o mappers/43.o mappers/46.o mappers/50.o mappers/51.o mappers/57.o mappers/58.o
+MOBJS += mappers/59.o mappers/60.o mappers/61.o mappers/62.o mappers/65.o mappers/67.o mappers/68.o mappers/69.o
+MOBJS += mappers/71.o mappers/72.o mappers/73.o mappers/75.o mappers/76.o mappers/77.o mappers/79.o mappers/80.o
+MOBJS += mappers/82.o mappers/83.o mappers/85.o mappers/86.o mappers/88.o mappers/89.o mappers/91.o mappers/92.o
+MOBJS += mappers/95.o mappers/97.o mappers/99.o mappers/113.o mappers/117.o mappers/151.o mappers/180.o mappers/183.o
+MOBJS += mappers/184.o mappers/187.o mappers/189.o mappers/193.o mappers/200.o mappers/201.o mappers/202.o mappers/203.o
+MOBJS += mappers/204.o mappers/208.o mappers/211.o mappers/212.o mappers/213.o mappers/214.o mappers/215.o
+MOBJS += mappers/217.o mappers/225.o mappers/226.o mappers/227.o mappers/228.o mappers/229.o mappers/230.o mappers/231.o
+MOBJS += mappers/232.o mappers/234.o mappers/235.o mappers/240.o mappers/241.o mappers/242.o mappers/244.o mappers/246.o
+MOBJS += mappers/255.o mappers/emu2413.o mappers/mmc2and4.o mappers/simple.o
 
-fmopl.o:       mappers/fmopl.c mappers/fmopl.h
-vrc7snd.o:     mappers/vrc7snd.c
-
-mappers/simple.o:       mappers/simple.c
-mappers/mmc2and4.o:     mappers/mmc2and4.c
-
-mappers/112.o:         mappers/112.c
-mappers/117.o:         mappers/117.c
-mappers/15.o:          mappers/15.c
-mappers/151.o:         mappers/151.c
-mappers/16.o:          mappers/16.c
-mappers/17.o:          mappers/17.c
-mappers/18.o:          mappers/18.c
-mappers/19.o:          mappers/19.c
-mappers/180.o:         mappers/180.c
-mappers/184.o:         mappers/184.c
-mappers/21.o:          mappers/21.c
-mappers/22.o:          mappers/22.c
-mappers/23.o:          mappers/23.c
-mappers/24and26.o:     mappers/24and26.c
-mappers/25.o:          mappers/25.c
-mappers/225.o:         mappers/225.c
-mappers/226.o:         mappers/226.c
-mappers/228.o:         mappers/228.c
-mappers/229.o:         mappers/229.c
-mappers/240.o:         mappers/240.c
-mappers/246.o:         mappers/246.c
-mappers/32.o:          mappers/32.c
-mappers/33.o:          mappers/33.c
-mappers/40.o:          mappers/40.c
-mappers/41.o:          mappers/41.c
-mappers/6.o:           mappers/6.c
-mappers/64.o:          mappers/64.c
-mappers/65.o:          mappers/65.c
-mappers/67.o:          mappers/67.c
-mappers/68.o:          mappers/68.c
-mappers/69.o:          mappers/69.c
-mappers/71.o:          mappers/71.c
-mappers/73.o:          mappers/73.c
-mappers/75.o:          mappers/75.c
-mappers/76.o:          mappers/76.c
-mappers/79.o:          mappers/79.c
-mappers/8.o:           mappers/8.c
-mappers/80.o:          mappers/80.c
-mappers/85.o:          mappers/85.c
-mappers/90.o:          mappers/90.c
-mappers/95.o:          mappers/95.c
-mappers/97.o:          mappers/97.c
-mappers/99.o:          mappers/99.c
-mappers/182.o:         mappers/182.c
-mappers/46.o:           mappers/46.c
-mappers/43.o:           mappers/43.c
-mappers/42.o:           mappers/42.c
-mappers/113.o:          mappers/113.c
-mappers/86.o:          mappers/86.c
-mappers/89.o:          mappers/89.c
-mappers/83.o:          mappers/83.c
-mappers/77.o:          mappers/77.c
-mappers/92.o:          mappers/92.c
-mappers/105.o:         mappers/105.c
-mappers/88.o:          mappers/88.c
-mappers/248.o:         mappers/248.c
-mappers/242.o:         mappers/242.c
-mappers/232.o:         mappers/232.c
-mappers/72.o:          mappers/72.c
-mappers/234.o:         mappers/234.c
-mappers/227.o:         mappers/227.c
-mappers/82.o:          mappers/82.c
-mappers/189.o:         mappers/189.c
-mappers/245.o:         mappers/245.c
-mappers/249.o:         mappers/249.c
-mappers/51.o:          mappers/51.c
diff --git a/mappers/emu2413.c b/mappers/emu2413.c
new file mode 100644 (file)
index 0000000..49aa339
--- /dev/null
@@ -0,0 +1,1300 @@
+/***********************************************************************************
+
+  emu2413.c -- YM2413 emulator written by Mitsutaka Okazaki 2001
+
+  2001 01-08 : Version 0.10 -- 1st version.
+  2001 01-15 : Version 0.20 -- semi-public version.
+  2001 01-16 : Version 0.30 -- 1st public version.
+  2001 01-17 : Version 0.31 -- Fixed bassdrum problem.
+             : Version 0.32 -- LPF implemented.
+  2001 01-18 : Version 0.33 -- Fixed the drum problem, refine the mix-down method.
+                            -- Fixed the LFO bug.
+  2001 01-24 : Version 0.35 -- Fixed the drum problem,
+                               support undocumented EG behavior.
+  2001 02-02 : Version 0.38 -- Improved the performance.
+                               Fixed the hi-hat and cymbal model.
+                               Fixed the default percussive datas.
+                               Noise reduction.
+                               Fixed the feedback problem.
+  2001 03-03 : Version 0.39 -- Fixed some drum bugs.
+                               Improved the performance.
+  2001 03-04 : Version 0.40 -- Improved the feedback.
+                               Change the default table size.
+                               Clock and Rate can be changed during play.
+  2001 06-24 : Version 0.50 -- Improved the hi-hat and the cymbal tone.
+                               Added VRC7 patch (OPLL_reset_patch is changed).
+                               Fixed OPLL_reset() bug.
+                               Added OPLL_setMask, OPLL_getMask and OPLL_toggleMask.
+                               Added OPLL_writeIO.
+  2001 09-28 : Version 0.51 -- Removed the noise table.
+  2002 01-28 : Version 0.52 -- Added Stereo mode.
+  2002 02-07 : Version 0.53 -- Fixed some drum bugs.
+  2002 02-20 : Version 0.54 -- Added the best quality mode.
+  2002 03-02 : Version 0.55 -- Removed OPLL_init & OPLL_close.
+  2002 05-30 : Version 0.60 -- Fixed HH&CYM generator and all voice datas.
+
+  2004 01-24 : Modified by xodnizel to remove code not needed for the VRC7, among other things.
+
+  References:
+    fmopl.c        -- 1999,2000 written by Tatsuyuki Satoh (MAME development).
+    fmopl.c(fixed) -- (C) 2002 Jarek Burczynski.
+    s_opl.c        -- 2001 written by Mamiya (NEZplug development).
+    fmgen.cpp      -- 1999,2000 written by cisc.
+    fmpac.ill      -- 2000 created by NARUTO.
+    MSX-Datapack
+    YMU757 data sheet
+    YM2143 data sheet
+
+**************************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include "emu2413.h"
+
+static const unsigned char default_inst[15][8] = {
+ #include "vrc7tone.h"
+};
+
+/* Size of Sintable ( 8 -- 18 can be used. 9 recommended.)*/
+#define PG_BITS 9
+#define PG_WIDTH (1<<PG_BITS)
+
+/* Phase increment counter */
+#define DP_BITS 18
+#define DP_WIDTH (1<<DP_BITS)
+#define DP_BASE_BITS (DP_BITS - PG_BITS)
+
+/* Dynamic range (Accuracy of sin table) */
+#define DB_BITS 8
+#define DB_STEP (48.0/(1<<DB_BITS))
+#define DB_MUTE (1<<DB_BITS)
+
+/* Dynamic range of envelope */
+#define EG_STEP 0.375
+#define EG_BITS 7
+#define EG_MUTE (1<<EG_BITS)
+
+/* Dynamic range of total level */
+#define TL_STEP 0.75
+#define TL_BITS 6
+#define TL_MUTE (1<<TL_BITS)
+
+/* Dynamic range of sustine level */
+#define SL_STEP 3.0
+#define SL_BITS 4
+#define SL_MUTE (1<<SL_BITS)
+
+#define EG2DB(d) ((d)*(e_int32)(EG_STEP/DB_STEP))
+#define TL2EG(d) ((d)*(e_int32)(TL_STEP/EG_STEP))
+#define SL2EG(d) ((d)*(e_int32)(SL_STEP/EG_STEP))
+
+#define DB_POS(x) (e_uint32)((x)/DB_STEP)
+#define DB_NEG(x) (e_uint32)(DB_MUTE+DB_MUTE+(x)/DB_STEP)
+
+/* Bits for liner value */
+#define DB2LIN_AMP_BITS 11
+#define SLOT_AMP_BITS (DB2LIN_AMP_BITS)
+
+/* Bits for envelope phase incremental counter */
+#define EG_DP_BITS 22
+#define EG_DP_WIDTH (1<<EG_DP_BITS)
+
+/* Bits for Pitch and Amp modulator */
+#define PM_PG_BITS 8
+#define PM_PG_WIDTH (1<<PM_PG_BITS)
+#define PM_DP_BITS 16
+#define PM_DP_WIDTH (1<<PM_DP_BITS)
+#define AM_PG_BITS 8
+#define AM_PG_WIDTH (1<<AM_PG_BITS)
+#define AM_DP_BITS 16
+#define AM_DP_WIDTH (1<<AM_DP_BITS)
+
+/* PM table is calcurated by PM_AMP * pow(2,PM_DEPTH*sin(x)/1200) */
+#define PM_AMP_BITS 8
+#define PM_AMP (1<<PM_AMP_BITS)
+
+/* PM speed(Hz) and depth(cent) */
+#define PM_SPEED 6.4
+#define PM_DEPTH 13.75
+
+/* AM speed(Hz) and depth(dB) */
+#define AM_SPEED 3.7
+//#define AM_DEPTH 4.8
+#define AM_DEPTH 2.4
+
+/* Cut the lower b bit(s) off. */
+#define HIGHBITS(c,b) ((c)>>(b))
+
+/* Leave the lower b bit(s). */
+#define LOWBITS(c,b) ((c)&((1<<(b))-1))
+
+/* Expand x which is s bits to d bits. */
+#define EXPAND_BITS(x,s,d) ((x)<<((d)-(s)))
+
+/* Expand x which is s bits to d bits and fill expanded bits '1' */
+#define EXPAND_BITS_X(x,s,d) (((x)<<((d)-(s)))|((1<<((d)-(s)))-1))
+
+/* Adjust envelope speed which depends on sampling rate. */
+#define rate_adjust(x) (rate==49716?x:(e_uint32)((double)(x)*clk/72/rate + 0.5))        /* added 0.5 to round the value*/
+
+#define MOD(o,x) (&(o)->slot[(x)<<1])
+#define CAR(o,x) (&(o)->slot[((x)<<1)|1])
+
+#define BIT(s,b) (((s)>>(b))&1)
+
+/* Input clock */
+static e_uint32 clk = 844451141;
+/* Sampling rate */
+static e_uint32 rate = 3354932;
+
+/* WaveTable for each envelope amp */
+static e_uint16 fullsintable[PG_WIDTH];
+static e_uint16 halfsintable[PG_WIDTH];
+
+static e_uint16 *waveform[2] = { fullsintable, halfsintable };
+
+/* LFO Table */
+static e_int32 pmtable[PM_PG_WIDTH];
+static e_int32 amtable[AM_PG_WIDTH];
+
+/* Phase delta for LFO */
+static e_uint32 pm_dphase;
+static e_uint32 am_dphase;
+
+/* dB to Liner table */
+static e_int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2];
+
+/* Liner to Log curve conversion table (for Attack rate). */
+static e_uint16 AR_ADJUST_TABLE[1 << EG_BITS];
+
+/* Definition of envelope mode */
+enum
+{ SETTLE, ATTACK, DECAY, SUSHOLD, SUSTINE, RELEASE, FINISH };
+
+/* Phase incr table for Attack */
+static e_uint32 dphaseARTable[16][16];
+/* Phase incr table for Decay and Release */
+static e_uint32 dphaseDRTable[16][16];
+
+/* KSL + TL Table */
+static e_uint32 tllTable[16][8][1 << TL_BITS][4];
+static e_int32 rksTable[2][8][2];
+
+/* Phase incr table for PG */
+static e_uint32 dphaseTable[512][8][16];
+
+/***************************************************
+
+                  Create tables
+
+****************************************************/
+INLINE static e_int32
+Min (e_int32 i, e_int32 j)
+{
+  if(i < j)
+    return i;
+  else
+    return j;
+}
+
+/* Table for AR to LogCurve. */
+static void
+makeAdjustTable (void)
+{
+  e_int32 i;
+
+  AR_ADJUST_TABLE[0] = (1 << EG_BITS);
+  for (i = 1; i < 128; i++)
+    AR_ADJUST_TABLE[i] = (e_uint16) ((double) (1 << EG_BITS) - 1 - (1 << EG_BITS) * log (i) / log (128));
+}
+
+
+/* Table for dB(0 -- (1<<DB_BITS)-1) to Liner(0 -- DB2LIN_AMP_WIDTH) */
+static void
+makeDB2LinTable (void)
+{
+  e_int32 i;
+
+  for (i = 0; i < DB_MUTE + DB_MUTE; i++)
+  {
+    DB2LIN_TABLE[i] = (e_int16) ((double) ((1 << DB2LIN_AMP_BITS) - 1) * pow (10, -(double) i * DB_STEP / 20));
+    if(i >= DB_MUTE) DB2LIN_TABLE[i] = 0;
+    DB2LIN_TABLE[i + DB_MUTE + DB_MUTE] = (e_int16) (-DB2LIN_TABLE[i]);
+  }
+}
+
+/* Liner(+0.0 - +1.0) to dB((1<<DB_BITS) - 1 -- 0) */
+static e_int32
+lin2db (double d)
+{
+  if(d == 0)
+    return (DB_MUTE - 1);
+  else
+    return Min (-(e_int32) (20.0 * log10 (d) / DB_STEP), DB_MUTE-1);  /* 0 -- 127 */
+}
+
+
+/* Sin Table */
+static void
+makeSinTable (void)
+{
+  e_int32 i;
+
+  for (i = 0; i < PG_WIDTH / 4; i++)
+  {
+    fullsintable[i] = (e_uint32) lin2db (sin (2.0 * PI * i / PG_WIDTH) );
+  }
+
+  for (i = 0; i < PG_WIDTH / 4; i++)
+  {
+    fullsintable[PG_WIDTH / 2 - 1 - i] = fullsintable[i];
+  }
+
+  for (i = 0; i < PG_WIDTH / 2; i++)
+  {
+    fullsintable[PG_WIDTH / 2 + i] = (e_uint32) (DB_MUTE + DB_MUTE + fullsintable[i]);
+  }
+
+  for (i = 0; i < PG_WIDTH / 2; i++)
+    halfsintable[i] = fullsintable[i];
+  for (i = PG_WIDTH / 2; i < PG_WIDTH; i++)
+    halfsintable[i] = fullsintable[0];
+}
+
+/* Table for Pitch Modulator */
+static void
+makePmTable (void)
+{
+  e_int32 i;
+
+  for (i = 0; i < PM_PG_WIDTH; i++)
+    pmtable[i] = (e_int32) ((double) PM_AMP * pow (2, (double) PM_DEPTH * sin (2.0 * PI * i / PM_PG_WIDTH) / 1200));
+}
+
+/* Table for Amp Modulator */
+static void
+makeAmTable (void)
+{
+  e_int32 i;
+
+  for (i = 0; i < AM_PG_WIDTH; i++)
+    amtable[i] = (e_int32) ((double) AM_DEPTH / 2 / DB_STEP * (1.0 + sin (2.0 * PI * i / PM_PG_WIDTH)));
+}
+
+/* Phase increment counter table */
+static void
+makeDphaseTable (void)
+{
+  e_uint32 fnum, block, ML;
+  e_uint32 mltable[16] =
+    { 1, 1 * 2, 2 * 2, 3 * 2, 4 * 2, 5 * 2, 6 * 2, 7 * 2, 8 * 2, 9 * 2, 10 * 2, 10 * 2, 12 * 2, 12 * 2, 15 * 2, 15 * 2 };
+
+  for (fnum = 0; fnum < 512; fnum++)
+    for (block = 0; block < 8; block++)
+      for (ML = 0; ML < 16; ML++)
+        dphaseTable[fnum][block][ML] = rate_adjust (((fnum * mltable[ML]) << block) >> (20 - DP_BITS));
+}
+
+static void
+makeTllTable (void)
+{
+#define dB2(x) ((x)*2)
+
+  static double kltable[16] = {
+    dB2 (0.000), dB2 (9.000), dB2 (12.000), dB2 (13.875), dB2 (15.000), dB2 (16.125), dB2 (16.875), dB2 (17.625),
+    dB2 (18.000), dB2 (18.750), dB2 (19.125), dB2 (19.500), dB2 (19.875), dB2 (20.250), dB2 (20.625), dB2 (21.000)
+  };
+
+  e_int32 tmp;
+  e_int32 fnum, block, TL, KL;
+
+  for (fnum = 0; fnum < 16; fnum++)
+    for (block = 0; block < 8; block++)
+      for (TL = 0; TL < 64; TL++)
+        for (KL = 0; KL < 4; KL++)
+        {
+          if(KL == 0)
+          {
+            tllTable[fnum][block][TL][KL] = TL2EG (TL);
+          }
+          else
+          {
+            tmp = (e_int32) (kltable[fnum] - dB2 (3.000) * (7 - block));
+            if(tmp <= 0)
+              tllTable[fnum][block][TL][KL] = TL2EG (TL);
+            else
+              tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp >> (3 - KL)) / EG_STEP) + TL2EG (TL);
+          }
+        }
+}
+
+#ifdef USE_SPEC_ENV_SPEED
+static double attacktime[16][4] = {
+  {0, 0, 0, 0},
+  {1730.15, 1400.60, 1153.43, 988.66},
+  {865.08, 700.30, 576.72, 494.33},
+  {432.54, 350.15, 288.36, 247.16},
+  {216.27, 175.07, 144.18, 123.58},
+  {108.13, 87.54, 72.09, 61.79},
+  {54.07, 43.77, 36.04, 30.90},
+  {27.03, 21.88, 18.02, 15.45},
+  {13.52, 10.94, 9.01, 7.72},
+  {6.76, 5.47, 4.51, 3.86},
+  {3.38, 2.74, 2.25, 1.93},
+  {1.69, 1.37, 1.13, 0.97},
+  {0.84, 0.70, 0.60, 0.54},
+  {0.50, 0.42, 0.34, 0.30},
+  {0.28, 0.22, 0.18, 0.14},
+  {0.00, 0.00, 0.00, 0.00}
+};
+
+static double decaytime[16][4] = {
+  {0, 0, 0, 0},
+  {20926.60, 16807.20, 14006.00, 12028.60},
+  {10463.30, 8403.58, 7002.98, 6014.32},
+  {5231.64, 4201.79, 3501.49, 3007.16},
+  {2615.82, 2100.89, 1750.75, 1503.58},
+  {1307.91, 1050.45, 875.37, 751.79},
+  {653.95, 525.22, 437.69, 375.90},
+  {326.98, 262.61, 218.84, 187.95},
+  {163.49, 131.31, 109.42, 93.97},
+  {81.74, 65.65, 54.71, 46.99},
+  {40.87, 32.83, 27.36, 23.49},
+  {20.44, 16.41, 13.68, 11.75},
+  {10.22, 8.21, 6.84, 5.87},
+  {5.11, 4.10, 3.42, 2.94},
+  {2.55, 2.05, 1.71, 1.47},
+  {1.27, 1.27, 1.27, 1.27}
+};
+#endif
+
+/* Rate Table for Attack */
+static void
+makeDphaseARTable (void)
+{
+  e_int32 AR, Rks, RM, RL;
+#ifdef USE_SPEC_ENV_SPEED
+  e_uint32 attacktable[16][4];
+
+  for (RM = 0; RM < 16; RM++)
+    for (RL = 0; RL < 4; RL++)
+    {
+      if(RM == 0)
+        attacktable[RM][RL] = 0;
+      else if(RM == 15)
+        attacktable[RM][RL] = EG_DP_WIDTH;
+      else
+        attacktable[RM][RL] = (e_uint32) ((double) (1 << EG_DP_BITS) / (attacktime[RM][RL] * 3579545 / 72000));
+
+    }
+#endif
+
+  for (AR = 0; AR < 16; AR++)
+    for (Rks = 0; Rks < 16; Rks++)
+    {
+      RM = AR + (Rks >> 2);
+      RL = Rks & 3;
+      if(RM > 15)
+        RM = 15;
+      switch (AR)
+      {
+      case 0:
+        dphaseARTable[AR][Rks] = 0;
+        break;
+      case 15:
+        dphaseARTable[AR][Rks] = 0;/*EG_DP_WIDTH;*/
+        break;
+      default:
+#ifdef USE_SPEC_ENV_SPEED
+        dphaseARTable[AR][Rks] = rate_adjust (attacktable[RM][RL]);
+#else
+        dphaseARTable[AR][Rks] = rate_adjust ((3 * (RL + 4) << (RM + 1)));
+#endif
+        break;
+      }
+    }
+}
+
+/* Rate Table for Decay and Release */
+static void
+makeDphaseDRTable (void)
+{
+  e_int32 DR, Rks, RM, RL;
+
+#ifdef USE_SPEC_ENV_SPEED
+  e_uint32 decaytable[16][4];
+
+  for (RM = 0; RM < 16; RM++)
+    for (RL = 0; RL < 4; RL++)
+      if(RM == 0)
+        decaytable[RM][RL] = 0;
+      else
+        decaytable[RM][RL] = (e_uint32) ((double) (1 << EG_DP_BITS) / (decaytime[RM][RL] * 3579545 / 72000));
+#endif
+
+  for (DR = 0; DR < 16; DR++)
+    for (Rks = 0; Rks < 16; Rks++)
+    {
+      RM = DR + (Rks >> 2);
+      RL = Rks & 3;
+      if(RM > 15)
+        RM = 15;
+      switch (DR)
+      {
+      case 0:
+        dphaseDRTable[DR][Rks] = 0;
+        break;
+      default:
+#ifdef USE_SPEC_ENV_SPEED
+        dphaseDRTable[DR][Rks] = rate_adjust (decaytable[RM][RL]);
+#else
+        dphaseDRTable[DR][Rks] = rate_adjust ((RL + 4) << (RM - 1));
+#endif
+        break;
+      }
+    }
+}
+
+static void
+makeRksTable (void)
+{
+
+  e_int32 fnum8, block, KR;
+
+  for (fnum8 = 0; fnum8 < 2; fnum8++)
+    for (block = 0; block < 8; block++)
+      for (KR = 0; KR < 2; KR++)
+      {
+        if(KR != 0)
+          rksTable[fnum8][block][KR] = (block << 1) + fnum8;
+        else
+          rksTable[fnum8][block][KR] = block >> 1;
+      }
+}
+
+/************************************************************
+
+                      Calc Parameters
+
+************************************************************/
+
+INLINE static e_uint32
+calc_eg_dphase (OPLL_SLOT * slot)
+{
+
+  switch (slot->eg_mode)
+  {
+  case ATTACK:
+    return dphaseARTable[slot->patch.AR][slot->rks];
+
+  case DECAY:
+    return dphaseDRTable[slot->patch.DR][slot->rks];
+
+  case SUSHOLD:
+    return 0;
+
+  case SUSTINE:
+    return dphaseDRTable[slot->patch.RR][slot->rks];
+
+  case RELEASE:
+    if(slot->sustine)
+      return dphaseDRTable[5][slot->rks];
+    else if(slot->patch.EG)
+      return dphaseDRTable[slot->patch.RR][slot->rks];
+    else
+      return dphaseDRTable[7][slot->rks];
+
+  case FINISH:
+    return 0;
+
+  default:
+    return 0;
+  }
+}
+
+/*************************************************************
+
+                    OPLL internal interfaces
+
+*************************************************************/
+
+#define UPDATE_PG(S)  (S)->dphase = dphaseTable[(S)->fnum][(S)->block][(S)->patch.ML]
+#define UPDATE_TLL(S)\
+(((S)->type==0)?\
+((S)->tll = tllTable[((S)->fnum)>>5][(S)->block][(S)->patch.TL][(S)->patch.KL]):\
+((S)->tll = tllTable[((S)->fnum)>>5][(S)->block][(S)->volume][(S)->patch.KL]))
+#define UPDATE_RKS(S) (S)->rks = rksTable[((S)->fnum)>>8][(S)->block][(S)->patch.KR]
+#define UPDATE_WF(S)  (S)->sintbl = waveform[(S)->patch.WF]
+#define UPDATE_EG(S)  (S)->eg_dphase = calc_eg_dphase(S)
+#define UPDATE_ALL(S)\
+  UPDATE_PG(S);\
+  UPDATE_TLL(S);\
+  UPDATE_RKS(S);\
+  UPDATE_WF(S); \
+  UPDATE_EG(S)                  /* EG should be updated last. */
+
+
+/* Slot key on  */
+INLINE static void
+slotOn (OPLL_SLOT * slot)
+{
+  slot->eg_mode = ATTACK;
+  slot->eg_phase = 0;
+  slot->phase = 0;
+}
+
+/* Slot key on without reseting the phase */
+INLINE static void
+slotOn2 (OPLL_SLOT * slot)
+{
+  slot->eg_mode = ATTACK;
+  slot->eg_phase = 0;
+}
+
+/* Slot key off */
+INLINE static void
+slotOff (OPLL_SLOT * slot)
+{
+  if(slot->eg_mode == ATTACK)
+    slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS);
+  slot->eg_mode = RELEASE;
+}
+
+/* Channel key on */
+INLINE static void
+keyOn (OPLL * opll, e_int32 i)
+{
+  if(!opll->slot_on_flag[i * 2])
+    slotOn (MOD(opll,i));
+  if(!opll->slot_on_flag[i * 2 + 1])
+    slotOn (CAR(opll,i));
+  opll->key_status[i] = 1;
+}
+
+/* Channel key off */
+INLINE static void
+keyOff (OPLL * opll, e_int32 i)
+{
+  if(opll->slot_on_flag[i * 2 + 1])
+    slotOff (CAR(opll,i));
+  opll->key_status[i] = 0;
+}
+
+/* Set sustine parameter */
+INLINE static void
+setSustine (OPLL * opll, e_int32 c, e_int32 sustine)
+{
+  CAR(opll,c)->sustine = sustine;
+  if(MOD(opll,c)->type)
+    MOD(opll,c)->sustine = sustine;
+}
+
+/* Volume : 6bit ( Volume register << 2 ) */
+INLINE static void
+setVolume (OPLL * opll, e_int32 c, e_int32 volume)
+{
+  CAR(opll,c)->volume = volume;
+}
+
+INLINE static void
+setSlotVolume (OPLL_SLOT * slot, e_int32 volume)
+{
+  slot->volume = volume;
+}
+
+/* Set F-Number ( fnum : 9bit ) */
+INLINE static void
+setFnumber (OPLL * opll, e_int32 c, e_int32 fnum)
+{
+  CAR(opll,c)->fnum = fnum;
+  MOD(opll,c)->fnum = fnum;
+}
+
+/* Set Block data (block : 3bit ) */
+INLINE static void
+setBlock (OPLL * opll, e_int32 c, e_int32 block)
+{
+  CAR(opll,c)->block = block;
+  MOD(opll,c)->block = block;
+}
+
+INLINE static void update_key_status (OPLL * opll)
+{
+  int ch;
+
+  for (ch = 0; ch < 6; ch++)
+    opll->slot_on_flag[ch * 2] = opll->slot_on_flag[ch * 2 + 1] = (opll->HiFreq[ch]) & 0x10;
+}
+
+/***********************************************************
+
+                      Initializing
+
+***********************************************************/
+
+static void
+OPLL_SLOT_reset (OPLL_SLOT * slot, int type)
+{
+  slot->type = type;
+  slot->sintbl = waveform[0];
+  slot->phase = 0;
+  slot->dphase = 0;
+  slot->output[0] = 0;
+  slot->output[1] = 0;
+  slot->feedback = 0;
+  slot->eg_mode = SETTLE;
+  slot->eg_phase = EG_DP_WIDTH;
+  slot->eg_dphase = 0;
+  slot->rks = 0;
+  slot->tll = 0;
+  slot->sustine = 0;
+  slot->fnum = 0;
+  slot->block = 0;
+  slot->volume = 0;
+  slot->pgout = 0;
+  slot->egout = 0;
+}
+
+static void
+internal_refresh (void)
+{
+  makeDphaseTable ();
+  makeDphaseARTable ();
+  makeDphaseDRTable ();
+  pm_dphase = (e_uint32) rate_adjust (PM_SPEED * PM_DP_WIDTH / (clk / 72));
+  am_dphase = (e_uint32) rate_adjust (AM_SPEED * AM_DP_WIDTH / (clk / 72));
+}
+
+static void
+maketables (e_uint32 c, e_uint32 r)
+{
+  if(c != clk)
+  {
+    clk = c;
+    makePmTable ();
+    makeAmTable ();
+    makeDB2LinTable ();
+    makeAdjustTable ();
+    makeTllTable ();
+    makeRksTable ();
+    makeSinTable ();
+    //makeDefaultPatch ();
+  }
+
+  if(r != rate)
+  {
+    rate = r;
+    internal_refresh ();
+  }
+}
+
+OPLL *OPLL_new (e_uint32 clk, e_uint32 rate)
+{
+  OPLL *opll;
+
+  maketables (clk, rate);
+
+  opll = (OPLL *) calloc (sizeof (OPLL), 1);
+  if(opll == NULL)
+    return NULL;
+
+  opll->mask = 0;
+
+  OPLL_reset (opll);
+
+  return opll;
+}
+
+
+void
+OPLL_delete (OPLL * opll)
+{
+  free (opll);
+}
+
+/* Reset whole of OPLL except patch datas. */
+void
+OPLL_reset (OPLL * opll)
+{
+  e_int32 i;
+
+  if(!opll)
+    return;
+
+  opll->adr = 0;
+  opll->out = 0;
+
+  opll->pm_phase = 0;
+  opll->am_phase = 0;
+
+  opll->mask = 0;
+
+  for (i = 0; i < 12; i++)
+    OPLL_SLOT_reset(&opll->slot[i], i%2);
+
+  for (i = 0; i < 6; i++)
+  {
+    opll->key_status[i] = 0;
+    //setPatch (opll, i, 0);
+  }
+
+  for (i = 0; i < 0x40; i++)
+    OPLL_writeReg (opll, i, 0);
+
+#ifndef EMU2413_COMPACTION
+  opll->realstep = (e_uint32) ((1 << 31) / rate);
+  opll->opllstep = (e_uint32) ((1 << 31) / (clk / 72));
+  opll->oplltime = 0;
+#endif
+}
+
+/* Force Refresh (When external program changes some parameters). */
+void
+OPLL_forceRefresh (OPLL * opll)
+{
+  e_int32 i;
+
+  if(opll == NULL)
+    return;
+
+  for (i = 0; i < 12; i++)
+  {
+    UPDATE_PG (&opll->slot[i]);
+    UPDATE_RKS (&opll->slot[i]);
+    UPDATE_TLL (&opll->slot[i]);
+    UPDATE_WF (&opll->slot[i]);
+    UPDATE_EG (&opll->slot[i]);
+  }
+}
+
+void
+OPLL_set_rate (OPLL * opll, e_uint32 r)
+{
+  if(opll->quality)
+    rate = 49716;
+  else
+    rate = r;
+  internal_refresh ();
+  rate = r;
+}
+
+void
+OPLL_set_quality (OPLL * opll, e_uint32 q)
+{
+  opll->quality = q;
+  OPLL_set_rate (opll, rate);
+}
+
+/*********************************************************
+
+                 Generate wave data
+
+*********************************************************/
+/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 2PI). */
+#if( SLOT_AMP_BITS - PG_BITS ) > 0
+#define wave2_2pi(e)  ( (e) >> ( SLOT_AMP_BITS - PG_BITS ))
+#else
+#define wave2_2pi(e)  ( (e) << ( PG_BITS - SLOT_AMP_BITS ))
+#endif
+
+/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 4PI). */
+#if( SLOT_AMP_BITS - PG_BITS - 1 ) == 0
+#define wave2_4pi(e)  (e)
+#elif( SLOT_AMP_BITS - PG_BITS - 1 ) > 0
+#define wave2_4pi(e)  ( (e) >> ( SLOT_AMP_BITS - PG_BITS - 1 ))
+#else
+#define wave2_4pi(e)  ( (e) << ( 1 + PG_BITS - SLOT_AMP_BITS ))
+#endif
+
+/* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 8PI). */
+#if( SLOT_AMP_BITS - PG_BITS - 2 ) == 0
+#define wave2_8pi(e)  (e)
+#elif( SLOT_AMP_BITS - PG_BITS - 2 ) > 0
+#define wave2_8pi(e)  ( (e) >> ( SLOT_AMP_BITS - PG_BITS - 2 ))
+#else
+#define wave2_8pi(e)  ( (e) << ( 2 + PG_BITS - SLOT_AMP_BITS ))
+#endif
+
+
+
+/* Update AM, PM unit */
+static void
+update_ampm (OPLL * opll)
+{
+  opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1);
+  opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1);
+  opll->lfo_am = amtable[HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)];
+  opll->lfo_pm = pmtable[HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)];
+}
+
+/* PG */
+INLINE static void
+calc_phase (OPLL_SLOT * slot, e_int32 lfo)
+{
+  if(slot->patch.PM)
+    slot->phase += (slot->dphase * lfo) >> PM_AMP_BITS;
+  else
+    slot->phase += slot->dphase;
+
+  slot->phase &= (DP_WIDTH - 1);
+
+  slot->pgout = HIGHBITS (slot->phase, DP_BASE_BITS);
+}
+
+/* EG */
+static void
+calc_envelope (OPLL_SLOT * slot, e_int32 lfo)
+{
+#define S2E(x) (SL2EG((e_int32)(x/SL_STEP))<<(EG_DP_BITS-EG_BITS))
+
+  static e_uint32 SL[16] = {
+    S2E (0.0), S2E (3.0), S2E (6.0), S2E (9.0), S2E (12.0), S2E (15.0), S2E (18.0), S2E (21.0),
+    S2E (24.0), S2E (27.0), S2E (30.0), S2E (33.0), S2E (36.0), S2E (39.0), S2E (42.0), S2E (48.0)
+  };
+
+  e_uint32 egout;
+
+  switch (slot->eg_mode)
+  {
+
+  case ATTACK:
+    egout = AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)];
+    slot->eg_phase += slot->eg_dphase;
+    if((EG_DP_WIDTH & slot->eg_phase)||(slot->patch.AR==15))
+    {
+      egout = 0;
+      slot->eg_phase = 0;
+      slot->eg_mode = DECAY;
+      UPDATE_EG (slot);
+    }
+    break;
+
+  case DECAY:
+    egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS);
+    slot->eg_phase += slot->eg_dphase;
+    if(slot->eg_phase >= SL[slot->patch.SL])
+    {
+      if(slot->patch.EG)
+      {
+        slot->eg_phase = SL[slot->patch.SL];
+        slot->eg_mode = SUSHOLD;
+        UPDATE_EG (slot);
+      }
+      else
+      {
+        slot->eg_phase = SL[slot->patch.SL];
+        slot->eg_mode = SUSTINE;
+        UPDATE_EG (slot);
+      }
+    }
+    break;
+
+  case SUSHOLD:
+    egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS);
+    if(slot->patch.EG == 0)
+    {
+      slot->eg_mode = SUSTINE;
+      UPDATE_EG (slot);
+    }
+    break;
+
+  case SUSTINE:
+  case RELEASE:
+    egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS);
+    slot->eg_phase += slot->eg_dphase;
+    if(egout >= (1 << EG_BITS))
+    {
+      slot->eg_mode = FINISH;
+      egout = (1 << EG_BITS) - 1;
+    }
+    break;
+
+  case FINISH:
+    egout = (1 << EG_BITS) - 1;
+    break;
+
+  default:
+    egout = (1 << EG_BITS) - 1;
+    break;
+  }
+
+  if(slot->patch.AM)
+    egout = EG2DB (egout + slot->tll) + lfo;
+  else
+    egout = EG2DB (egout + slot->tll);
+
+  if(egout >= DB_MUTE)
+    egout = DB_MUTE - 1;
+
+  slot->egout = egout;
+}
+
+/* CARRIOR */
+INLINE static e_int32
+calc_slot_car (OPLL_SLOT * slot, e_int32 fm)
+{
+  slot->output[1] = slot->output[0];
+
+  if(slot->egout >= (DB_MUTE - 1))
+  {
+    slot->output[0] = 0;
+  }
+  else
+  {
+    slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout+wave2_8pi(fm))&(PG_WIDTH-1)] + slot->egout];
+  }
+
+  return (slot->output[1] + slot->output[0]) >> 1;
+}
+
+/* MODULATOR */
+INLINE static e_int32
+calc_slot_mod (OPLL_SLOT * slot)
+{
+  e_int32 fm;
+
+  slot->output[1] = slot->output[0];
+
+  if(slot->egout >= (DB_MUTE - 1))
+  {
+    slot->output[0] = 0;
+  }
+  else if(slot->patch.FB != 0)
+  {
+    fm = wave2_4pi (slot->feedback) >> (7 - slot->patch.FB);
+    slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + fm)&(PG_WIDTH-1)] + slot->egout];
+  }
+  else
+  {
+    slot->output[0] = DB2LIN_TABLE[slot->sintbl[slot->pgout] + slot->egout];
+  }
+
+  slot->feedback = (slot->output[1] + slot->output[0]) >> 1;
+
+  return slot->feedback;
+
+}
+
+static INLINE e_int16 calc (OPLL * opll)
+{
+  e_int32 inst = 0, out = 0;
+  e_int32 i;
+
+  update_ampm (opll);
+
+  for (i = 0; i < 12; i++)
+  {
+    calc_phase(&opll->slot[i],opll->lfo_pm);
+    calc_envelope(&opll->slot[i],opll->lfo_am);
+  }
+
+  for (i = 0; i < 6; i++)
+    if(!(opll->mask & OPLL_MASK_CH (i)) && (CAR(opll,i)->eg_mode != FINISH))
+      inst += calc_slot_car (CAR(opll,i), calc_slot_mod(MOD(opll,i)));
+
+  out = inst;
+  return (e_int16) out;
+}
+
+void moocow(OPLL* opll, e_int32 *buf, e_int32 len, int shift)
+{
+ while(len > 0)
+ {
+  *buf+=(calc(opll)+32768)<<shift;
+  buf++;
+  len--;
+ }
+}
+
+#ifdef EMU2413_COMPACTION
+e_int16
+OPLL_calc (OPLL * opll)
+{
+  return calc (opll);
+}
+#else
+e_int16
+OPLL_calc (OPLL * opll)
+{
+  if(!opll->quality)
+   return calc (opll);
+
+  while (opll->realstep > opll->oplltime)
+  {
+    opll->oplltime += opll->opllstep;
+    opll->prev = opll->next;
+    opll->next = calc (opll);
+  }
+
+  opll->oplltime -= opll->realstep;
+  opll->out = (e_int16) (((double) opll->next * (opll->opllstep - opll->oplltime)
+                          + (double) opll->prev * opll->oplltime) / opll->opllstep);
+
+  return (e_int16) opll->out;
+}
+#endif
+
+e_uint32
+OPLL_setMask (OPLL * opll, e_uint32 mask)
+{
+  e_uint32 ret;
+
+  if(opll)
+  {
+    ret = opll->mask;
+    opll->mask = mask;
+    return ret;
+  }
+  else
+    return 0;
+}
+
+e_uint32
+OPLL_toggleMask (OPLL * opll, e_uint32 mask)
+{
+  e_uint32 ret;
+
+  if(opll)
+  {
+    ret = opll->mask;
+    opll->mask ^= mask;
+    return ret;
+  }
+  else
+    return 0;
+}
+
+/****************************************************
+
+                       I/O Ctrl
+
+*****************************************************/
+
+static void setInstrument(OPLL * opll, e_uint i, e_uint inst)
+{
+ const e_uint8 *src;
+ OPLL_PATCH *modp, *carp;
+
+ opll->patch_number[i]=inst;
+
+ if(inst)
+  src=default_inst[inst-1];
+ else
+  src=opll->CustInst;
+
+ modp=&MOD(opll,i)->patch;
+ carp=&CAR(opll,i)->patch;
+
+ modp->AM=(src[0]>>7)&1;
+ modp->PM=(src[0]>>6)&1;
+ modp->EG=(src[0]>>5)&1;
+ modp->KR=(src[0]>>4)&1;
+ modp->ML=(src[0]&0xF);
+
+ carp->AM=(src[1]>>7)&1;
+ carp->PM=(src[1]>>6)&1;
+ carp->EG=(src[1]>>5)&1;
+ carp->KR=(src[1]>>4)&1;
+ carp->ML=(src[1]&0xF);
+
+ modp->KL=(src[2]>>6)&3;
+ modp->TL=(src[2]&0x3F);
+
+ carp->KL = (src[3] >> 6) & 3;
+ carp->WF = (src[3] >> 4) & 1;
+
+ modp->WF = (src[3] >> 3) & 1;
+
+ modp->FB = (src[3]) & 7;
+
+ modp->AR = (src[4]>>4)&0xF;
+ modp->DR = (src[4]&0xF);
+
+ carp->AR = (src[5]>>4)&0xF;
+ carp->DR = (src[5]&0xF);
+
+ modp->SL = (src[6]>>4)&0xF;
+ modp->RR = (src[6]&0xF);
+
+ carp->SL = (src[7]>>4)&0xF;
+ carp->RR = (src[7]&0xF);
+}
+
+
+void
+OPLL_writeReg (OPLL * opll, e_uint32 reg, e_uint32 data)
+{
+
+  e_int32 i, v, ch;
+
+  data = data & 0xff;
+  reg = reg & 0x3f;
+
+  switch (reg)
+  {
+   case 0x00:
+    opll->CustInst[0]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_PG (MOD(opll,i));
+        UPDATE_RKS (MOD(opll,i));
+        UPDATE_EG (MOD(opll,i));
+      }
+    }
+    break;
+
+  case 0x01:
+    opll->CustInst[1]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_PG (CAR(opll,i));
+        UPDATE_RKS (CAR(opll,i));
+        UPDATE_EG (CAR(opll,i));
+      }
+    }
+    break;
+
+  case 0x02:
+    opll->CustInst[2]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_TLL(MOD(opll,i));
+      }
+    }
+    break;
+
+  case 0x03:
+    opll->CustInst[3]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_WF(MOD(opll,i));
+        UPDATE_WF(CAR(opll,i));
+      }
+    }
+    break;
+
+  case 0x04:
+    opll->CustInst[4]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_EG (MOD(opll,i));
+      }
+    }
+    break;
+
+  case 0x05:
+    opll->CustInst[5]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_EG(CAR(opll,i));
+      }
+    }
+    break;
+
+  case 0x06:
+    opll->CustInst[6]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+        UPDATE_EG (MOD(opll,i));
+      }
+    }
+    break;
+
+  case 0x07:
+    opll->CustInst[7]=data;
+    for (i = 0; i < 6; i++)
+    {
+      if(opll->patch_number[i] == 0)
+      {
+        setInstrument(opll, i, 0);
+         UPDATE_EG (CAR(opll,i));
+      }
+    }
+    break;
+
+  case 0x10:
+  case 0x11:
+  case 0x12:
+  case 0x13:
+  case 0x14:
+  case 0x15:
+    ch = reg - 0x10;
+    opll->LowFreq[ch]=data;
+    setFnumber (opll, ch, data + ((opll->HiFreq[ch] & 1) << 8));
+    UPDATE_ALL (MOD(opll,ch));
+    UPDATE_ALL (CAR(opll,ch));
+    break;
+
+  case 0x20:
+  case 0x21:
+  case 0x22:
+  case 0x23:
+  case 0x24:
+  case 0x25:
+    ch = reg - 0x20;
+    opll->HiFreq[ch]=data;
+
+    setFnumber (opll, ch, ((data & 1) << 8) + opll->LowFreq[ch]);
+    setBlock (opll, ch, (data >> 1) & 7);
+    setSustine (opll, ch, (data >> 5) & 1);
+    if(data & 0x10)
+      keyOn (opll, ch);
+    else
+      keyOff (opll, ch);
+    UPDATE_ALL (MOD(opll,ch));
+    UPDATE_ALL (CAR(opll,ch));
+    update_key_status (opll);
+    break;
+
+  case 0x30:
+  case 0x31:
+  case 0x32:
+  case 0x33:
+  case 0x34:
+  case 0x35:
+    opll->InstVol[reg-0x30]=data;
+    i = (data >> 4) & 15;
+    v = data & 15;
+    setInstrument(opll, reg-0x30, i);
+    setVolume (opll, reg - 0x30, v << 2);
+    UPDATE_ALL (MOD(opll,reg - 0x30));
+    UPDATE_ALL (CAR(opll,reg - 0x30));
+    break;
+
+  default:
+    break;
+
+  }
+}
+
+void
+OPLL_writeIO (OPLL * opll, e_uint32 adr, e_uint32 val)
+{
+  if(adr & 1)
+    OPLL_writeReg (opll, opll->adr, val);
+  else
+    opll->adr = val;
+}
+
diff --git a/mappers/emu2413.h b/mappers/emu2413.h
new file mode 100644 (file)
index 0000000..906b4c5
--- /dev/null
@@ -0,0 +1,134 @@
+#ifndef _EMU2413_H_
+#define _EMU2413_H_
+
+#include "emutypes.h"
+
+#ifdef EMU2413_DLL_EXPORTS
+  #define EMU2413_API __declspec(dllexport)
+#elif defined(EMU2413_DLL_IMPORTS)
+  #define EMU2413_API __declspec(dllimport)
+#else
+  #define EMU2413_API
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PI 3.14159265358979323846
+
+enum {OPLL_VRC7_TONE=0} ;
+
+/* voice data */
+typedef struct {
+  e_uint32 TL,FB,EG,ML,AR,DR,SL,RR,KR,KL,AM,PM,WF ;
+} OPLL_PATCH ;
+
+/* slot */
+typedef struct {
+
+  OPLL_PATCH patch;
+
+  e_int32 type ;          /* 0 : modulator 1 : carrier */
+
+  /* OUTPUT */
+  e_int32 feedback ;
+  e_int32 output[2] ;   /* Output value of slot */
+
+  /* for Phase Generator (PG) */
+  e_uint16 *sintbl ;    /* Wavetable */
+  e_uint32 phase ;      /* Phase */
+  e_uint32 dphase ;     /* Phase increment amount */
+  e_uint32 pgout ;      /* output */
+
+  /* for Envelope Generator (EG) */
+  e_int32 fnum ;          /* F-Number */
+  e_int32 block ;         /* Block */
+  e_int32 volume ;        /* Current volume */
+  e_int32 sustine ;       /* Sustine 1 = ON, 0 = OFF */
+  e_uint32 tll ;              /* Total Level + Key scale level*/
+  e_uint32 rks ;        /* Key scale offset (Rks) */
+  e_int32 eg_mode ;       /* Current state */
+  e_uint32 eg_phase ;   /* Phase */
+  e_uint32 eg_dphase ;  /* Phase increment amount */
+  e_uint32 egout ;      /* output */
+
+} OPLL_SLOT ;
+
+/* Mask */
+#define OPLL_MASK_CH(x) (1<<(x))
+
+/* opll */
+typedef struct {
+
+  e_uint32 adr ;
+  e_int32 out ;
+
+#ifndef EMU2413_COMPACTION
+  e_uint32 realstep ;
+  e_uint32 oplltime ;
+  e_uint32 opllstep ;
+  e_int32 prev, next ;
+#endif
+
+  /* Register */
+  e_uint8 LowFreq[6];
+  e_uint8 HiFreq[6];
+  e_uint8 InstVol[6];
+
+  e_uint8 CustInst[8];
+
+  e_int32 slot_on_flag[6 * 2] ;
+
+  /* Pitch Modulator */
+  e_uint32 pm_phase ;
+  e_int32 lfo_pm ;
+
+  /* Amp Modulator */
+  e_int32 am_phase ;
+  e_int32 lfo_am ;
+
+  e_uint32 quality;
+
+  /* Channel Data */
+  e_int32 patch_number[6];
+  e_int32 key_status[6] ;
+
+  /* Slot */
+  OPLL_SLOT slot[6 * 2] ;
+
+  e_uint32 mask ;
+
+} OPLL ;
+
+/* Create Object */
+EMU2413_API OPLL *OPLL_new(e_uint32 clk, e_uint32 rate) ;
+EMU2413_API void OPLL_delete(OPLL *) ;
+
+/* Setup */
+EMU2413_API void OPLL_reset(OPLL *) ;
+EMU2413_API void OPLL_set_rate(OPLL *opll, e_uint32 r) ;
+EMU2413_API void OPLL_set_quality(OPLL *opll, e_uint32 q) ;
+
+/* Port/Register access */
+EMU2413_API void OPLL_writeIO(OPLL *, e_uint32 reg, e_uint32 val) ;
+EMU2413_API void OPLL_writeReg(OPLL *, e_uint32 reg, e_uint32 val) ;
+
+/* Synthsize */
+EMU2413_API e_int16 OPLL_calc(OPLL *) ;
+
+/* Misc */
+EMU2413_API void OPLL_forceRefresh(OPLL *) ;
+
+/* Channel Mask */
+EMU2413_API e_uint32 OPLL_setMask(OPLL *, e_uint32 mask) ;
+EMU2413_API e_uint32 OPLL_toggleMask(OPLL *, e_uint32 mask) ;
+
+
+void moocow(OPLL* opll, e_int32 *buf, e_int32 len, int shift);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/mappers/emutypes.h b/mappers/emutypes.h
new file mode 100644 (file)
index 0000000..fdef420
--- /dev/null
@@ -0,0 +1,44 @@
+#ifndef _EMUTYPES_H_
+#define _EMUTYPES_H_
+
+#ifndef INLINE
+
+#if defined(_MSC_VER)
+#define INLINE __forceinline
+#elif defined(__GNUC__)
+#define INLINE __inline__
+#elif defined(_MWERKS_)
+#define INLINE inline
+#else
+#define INLINE
+#endif
+#endif
+
+#if defined(EMU_DLL_IMPORTS)
+#define EMU2149_DLL_IMPORTS
+#define EMU2212_DLL_IMPORTS
+#define EMU2413_DLL_IMPORTS
+#define EMU8950_DLL_IMPORTS
+#define EMU76489_DLL_IMPORTS
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned int e_uint;
+typedef signed int e_int;
+
+typedef unsigned char e_uint8 ;
+typedef signed char e_int8 ;
+
+typedef unsigned short e_uint16 ;
+typedef signed short e_int16 ;
+
+typedef unsigned int e_uint32 ;
+typedef signed int e_int32 ;
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/mappers/fmopl.c b/mappers/fmopl.c
deleted file mode 100644 (file)
index b2fc12c..0000000
+++ /dev/null
@@ -1,871 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1999,2000 Tatsuyuki Satoh
- *  Copyright (C) 2001,2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 
- */
-
-/* This file has been heavily modified from the original(mostly unused
-   code was removed).  If you want to use it for anything other than
-   VRC7 sound emulation, you should get the original from the AdPlug
-   source distribution or the MAME(version 0.37b16) source distribution
-   (but be careful about the different licenses).
-        - Xodnizel
-*/
-   
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <math.h>
-#include "mapinc.h"
-#include "fmopl.h"
-
-#ifndef PI
-#define PI 3.14159265358979323846
-#endif
-
-/* -------------------- preliminary define section --------------------- */
-/* attack/decay rate time rate */
-#define OPL_ARRATE     141280  /* RATE 4 =  2826.24ms @ 3.6MHz */
-#define OPL_DRRATE    1956000  /* RATE 4 = 39280.64ms @ 3.6MHz */
-
-#define DELTAT_MIXING_LEVEL (1) /* DELTA-T ADPCM MIXING LEVEL */
-
-#define FREQ_BITS 24                   /* frequency turn          */
-
-/* counter bits = 20 , octerve 7 */
-#define FREQ_RATE   (1<<(FREQ_BITS-20))
-#define TL_BITS    (FREQ_BITS+2)
-
-/* final output shift , limit minimum and maximum */
-#define OPL_OUTSB   (TL_BITS+3-16)             /* OPL output final shift 16bit */
-#define OPL_MAXOUT (0x7fff<<OPL_OUTSB<<3)
-#define OPL_MINOUT (-0x8000<<OPL_OUTSB<<3)
-
-/* -------------------- quality selection --------------------- */
-
-/* sinwave entries */
-/* used static memory = SIN_ENT * 4 (byte) */
-#define SIN_ENT 2048
-
-/* output level entries (envelope,sinwave) */
-/* envelope counter lower bits */
-#define ENV_BITS 16
-/* envelope output entries */
-#define EG_ENT   4096
-/* used dynamic memory = EG_ENT*4*4(byte)or EG_ENT*6*4(byte) */
-/* used static  memory = EG_ENT*4 (byte)                     */
-
-#define EG_OFF   ((2*EG_ENT)<<ENV_BITS)  /* OFF          */
-#define EG_DED   EG_OFF
-#define EG_DST   (EG_ENT<<ENV_BITS)      /* DECAY  START */
-#define EG_AED   EG_DST
-#define EG_AST   0                       /* ATTACK START */
-
-#define EG_STEP (96.0/EG_ENT) /* OPL is 0.1875 dB step  */
-
-/* LFO table entries */
-#define VIB_ENT 512
-#define VIB_SHIFT (32-9)
-#define AMS_ENT 512
-#define AMS_SHIFT (32-9)
-
-#define VIB_RATE 256
-
-/* -------------------- local defines , macros --------------------- */
-
-/* register number to channel number , slot offset */
-#define SLOT1 0
-#define SLOT2 1
-
-/* envelope phase */
-#define ENV_MOD_RR  0x00
-#define ENV_MOD_DR  0x01
-#define ENV_MOD_AR  0x02
-
-/* -------------------- tables --------------------- */
-static const int slot_array[32]=
-{
-        0, 2, 4, 1, 3, 5,-1,-1,
-        6, 8,10, 7, 9,11,-1,-1,
-       12,14,16,13,15,17,-1,-1,
-       -1,-1,-1,-1,-1,-1,-1,-1
-};
-
-/* key scale level */
-/* table is 3dB/OCT , DV converts this in TL step at 6dB/OCT */
-#define DV (EG_STEP/2)
-static const UINT32 KSL_TABLE[8*16]=
-{
-       /* OCT 0 */
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-       /* OCT 1 */
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-        0.000/DV, 0.750/DV, 1.125/DV, 1.500/DV,
-        1.875/DV, 2.250/DV, 2.625/DV, 3.000/DV,
-       /* OCT 2 */
-        0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
-        0.000/DV, 1.125/DV, 1.875/DV, 2.625/DV,
-        3.000/DV, 3.750/DV, 4.125/DV, 4.500/DV,
-        4.875/DV, 5.250/DV, 5.625/DV, 6.000/DV,
-       /* OCT 3 */
-        0.000/DV, 0.000/DV, 0.000/DV, 1.875/DV,
-        3.000/DV, 4.125/DV, 4.875/DV, 5.625/DV,
-        6.000/DV, 6.750/DV, 7.125/DV, 7.500/DV,
-        7.875/DV, 8.250/DV, 8.625/DV, 9.000/DV,
-       /* OCT 4 */
-        0.000/DV, 0.000/DV, 3.000/DV, 4.875/DV,
-        6.000/DV, 7.125/DV, 7.875/DV, 8.625/DV,
-        9.000/DV, 9.750/DV,10.125/DV,10.500/DV,
-       10.875/DV,11.250/DV,11.625/DV,12.000/DV,
-       /* OCT 5 */
-        0.000/DV, 3.000/DV, 6.000/DV, 7.875/DV,
-        9.000/DV,10.125/DV,10.875/DV,11.625/DV,
-       12.000/DV,12.750/DV,13.125/DV,13.500/DV,
-       13.875/DV,14.250/DV,14.625/DV,15.000/DV,
-       /* OCT 6 */
-        0.000/DV, 6.000/DV, 9.000/DV,10.875/DV,
-       12.000/DV,13.125/DV,13.875/DV,14.625/DV,
-       15.000/DV,15.750/DV,16.125/DV,16.500/DV,
-       16.875/DV,17.250/DV,17.625/DV,18.000/DV,
-       /* OCT 7 */
-        0.000/DV, 9.000/DV,12.000/DV,13.875/DV,
-       15.000/DV,16.125/DV,16.875/DV,17.625/DV,
-       18.000/DV,18.750/DV,19.125/DV,19.500/DV,
-       19.875/DV,20.250/DV,20.625/DV,21.000/DV
-};
-#undef DV
-
-/* sustain lebel table (3db per step) */
-/* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/
-#define SC(db) (db*((3/EG_STEP)*(1<<ENV_BITS)))+EG_DST
-static const INT32 SL_TABLE[16]={
- SC( 0),SC( 1),SC( 2),SC(3 ),SC(4 ),SC(5 ),SC(6 ),SC( 7),
- SC( 8),SC( 9),SC(10),SC(11),SC(12),SC(13),SC(14),SC(31)
-};
-#undef SC
-
-#define TL_MAX (EG_ENT*2) /* limit(tl + ksr + envelope) + sinwave */
-/* TotalLevel : 48 24 12  6  3 1.5 0.75 (dB) */
-/* TL_TABLE[ 0      to TL_MAX          ] : plus  section */
-/* TL_TABLE[ TL_MAX to TL_MAX+TL_MAX-1 ] : minus section */
-static INT32 *TL_TABLE;
-
-/* pointers to TL_TABLE with sinwave output offset */
-static INT32 **SIN_TABLE;
-
-/* LFO table */
-static INT32 *AMS_TABLE;
-static INT32 *VIB_TABLE;
-
-/* envelope output curve table */
-/* attack + decay + OFF */
-static INT32 ENV_CURVE[2*EG_ENT+1];
-
-/* multiple table */
-#define ML 2
-static const UINT32 MUL_TABLE[16]= {
-/* 1/2, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 */
-   0.50*ML, 1.00*ML, 2.00*ML, 3.00*ML, 4.00*ML, 5.00*ML, 6.00*ML, 7.00*ML,
-   8.00*ML, 9.00*ML,10.00*ML,10.00*ML,12.00*ML,12.00*ML,15.00*ML,15.00*ML
-};
-#undef ML
-
-/* dummy attack / decay rate ( when rate == 0 ) */
-static INT32 RATE_0[16]=
-{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-
-/* -------------------- static state --------------------- */
-
-/* lock level of common table */
-static int num_lock = 0;
-
-/* work table */
-static void *cur_chip = NULL;  /* current chip point */
-/* currenct chip state */
-/* static OPLSAMPLE  *bufL,*bufR; */
-static OPL_CH *S_CH;
-static OPL_CH *E_CH;
-OPL_SLOT *SLOT7_1,*SLOT7_2,*SLOT8_1,*SLOT8_2;
-
-static INT32 outd[1];
-static INT32 ams;
-static INT32 vib;
-INT32  *ams_table;
-INT32  *vib_table;
-static INT32 amsIncr;
-static INT32 vibIncr;
-static INT32 feedback2;                /* connect for SLOT 2 */
-
-/* --------------------- subroutines  --------------------- */
-
-INLINE int Limit( int val, int max, int min ) {
-       if ( val > max )
-               val = max;
-       else if ( val < min )
-               val = min;
-
-       return val;
-}
-
-/* ----- key on  ----- */
-INLINE void OPL_KEYON(OPL_SLOT *SLOT)
-{
-       /* sin wave restart */
-       SLOT->Cnt = 0;
-       /* set attack */
-       SLOT->evm = ENV_MOD_AR;
-       SLOT->evs = SLOT->evsa;
-       SLOT->evc = EG_AST;
-       SLOT->eve = EG_AED;
-}
-/* ----- key off ----- */
-INLINE void OPL_KEYOFF(OPL_SLOT *SLOT)
-{
-       if( SLOT->evm > ENV_MOD_RR)
-       {
-               /* set envelope counter from envleope output */
-               SLOT->evm = ENV_MOD_RR;
-               if( !(SLOT->evc&EG_DST) )
-                       //SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST;
-                       SLOT->evc = EG_DST;
-               SLOT->eve = EG_DED;
-               SLOT->evs = SLOT->evsr;
-       }
-}
-
-/* ---------- calcrate Envelope Generator & Phase Generator ---------- */
-/* return : envelope output */
-INLINE UINT32 OPL_CALC_SLOT( OPL_SLOT *SLOT )
-{
-       /* calcrate envelope generator */
-       if( (SLOT->evc+=SLOT->evs) >= SLOT->eve )
-       {
-               switch( SLOT->evm ){
-               case ENV_MOD_AR: /* ATTACK -> DECAY1 */
-                       /* next DR */
-                       SLOT->evm = ENV_MOD_DR;
-                       SLOT->evc = EG_DST;
-                       SLOT->eve = SLOT->SL;
-                       SLOT->evs = SLOT->evsd;
-                       break;
-               case ENV_MOD_DR: /* DECAY -> SL or RR */
-                       SLOT->evc = SLOT->SL;
-                       SLOT->eve = EG_DED;
-                       if(SLOT->eg_typ)
-                       {
-                               SLOT->evs = 0;
-                       }
-                       else
-                       {
-                               SLOT->evm = ENV_MOD_RR;
-                               SLOT->evs = SLOT->evsr;
-                       }
-                       break;
-               case ENV_MOD_RR: /* RR -> OFF */
-                       SLOT->evc = EG_OFF;
-                       SLOT->eve = EG_OFF+1;
-                       SLOT->evs = 0;
-                       break;
-               }
-       }
-       /* calcrate envelope */
-       return SLOT->TLL+ENV_CURVE[SLOT->evc>>ENV_BITS]+(SLOT->ams ? ams : 0);
-}
-
-/* set algorythm connection */
-static void set_algorythm( OPL_CH *CH)
-{
-       INT32 *carrier = &outd[0];
-       CH->connect1 = CH->CON ? carrier : &feedback2;
-       CH->connect2 = carrier;
-}
-
-/* ---------- frequency counter for operater update ---------- */
-INLINE void CALC_FCSLOT(OPL_CH *CH,OPL_SLOT *SLOT)
-{
-       int ksr;
-
-       /* frequency step counter */
-       SLOT->Incr = CH->fc * SLOT->mul;
-       ksr = CH->kcode >> SLOT->KSR;
-
-       if( SLOT->ksr != ksr )
-       {
-               SLOT->ksr = ksr;
-               /* attack , decay rate recalcration */
-               SLOT->evsa = SLOT->AR[ksr];
-               SLOT->evsd = SLOT->DR[ksr];
-               SLOT->evsr = SLOT->RR[ksr];
-       }
-       SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl);
-}
-
-/* set multi,am,vib,EG-TYP,KSR,mul */
-INLINE void set_mul(FM_OPL *OPL,int slot,int v)
-{
-       OPL_CH   *CH   = &OPL->P_CH[slot/2];
-       OPL_SLOT *SLOT = &CH->SLOT[slot&1];
-
-       SLOT->mul    = MUL_TABLE[v&0x0f];
-       SLOT->KSR    = (v&0x10) ? 0 : 2;
-       SLOT->eg_typ = (v&0x20)>>5;
-       SLOT->vib    = (v&0x40);
-       SLOT->ams    = (v&0x80);
-       CALC_FCSLOT(CH,SLOT);
-}
-
-/* set ksl & tl */
-INLINE void set_ksl_tl(FM_OPL *OPL,int slot,int v)
-{
-       OPL_CH   *CH   = &OPL->P_CH[slot/2];
-       OPL_SLOT *SLOT = &CH->SLOT[slot&1];
-       int ksl = v>>6; /* 0 / 1.5 / 3 / 6 db/OCT */
-
-//     if(slot&1) 
-//         if(ksl) {sprintf(errmsg,"doh");howlong=255;ksl=0;}
-
-       SLOT->ksl = ksl ? ksl : 31;
-//     SLOT->ksl = ksl ? 3-ksl : 31;
-       SLOT->TL  = (v&0x3f)*(0.75/EG_STEP); /* 0.75db step */
-
-       if( !(OPL->mode&0x80) )
-       {       /* not CSM latch total level */
-               SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl);
-       }
-}
-
-/* set attack rate & decay rate  */
-INLINE void set_ar_dr(FM_OPL *OPL,int slot,int v)
-{
-       OPL_CH   *CH   = &OPL->P_CH[slot/2];
-       OPL_SLOT *SLOT = &CH->SLOT[slot&1];
-       int ar = v>>4;
-       int dr = v&0x0f;
-
-       SLOT->AR = ar ? &OPL->AR_TABLE[ar<<2] : RATE_0;
-       SLOT->evsa = SLOT->AR[SLOT->ksr];
-       if( SLOT->evm == ENV_MOD_AR ) SLOT->evs = SLOT->evsa;
-
-       SLOT->DR = dr ? &OPL->DR_TABLE[dr<<2] : RATE_0;
-       SLOT->evsd = SLOT->DR[SLOT->ksr];
-       if( SLOT->evm == ENV_MOD_DR ) SLOT->evs = SLOT->evsd;
-}
-
-/* set sustain level & release rate */
-INLINE void set_sl_rr(FM_OPL *OPL,int slot,int v)
-{
-       OPL_CH   *CH   = &OPL->P_CH[slot/2];
-       OPL_SLOT *SLOT = &CH->SLOT[slot&1];
-       int sl = v>>4;
-       int rr = v & 0x0f;
-
-       SLOT->SL = SL_TABLE[sl];
-       if( SLOT->evm == ENV_MOD_DR ) SLOT->eve = SLOT->SL;
-       SLOT->RR = &OPL->DR_TABLE[rr<<2];
-       SLOT->evsr = SLOT->RR[SLOT->ksr];
-       if( SLOT->evm == ENV_MOD_RR ) SLOT->evs = SLOT->evsr;
-}
-
-/* operator output calcrator */
-#define OP_OUT(slot,env,con)   slot->wavetable[((slot->Cnt+con)/(0x1000000/SIN_ENT))&(SIN_ENT-1)][env]
-/* ---------- calcrate one of channel ---------- */
-INLINE void OPL_CALC_CH( OPL_CH *CH )
-{
-       UINT32 env_out;
-       OPL_SLOT *SLOT;
-
-       feedback2 = 0;
-       /* SLOT 1 */
-       SLOT = &CH->SLOT[SLOT1];
-       env_out=OPL_CALC_SLOT(SLOT);
-       if( env_out < EG_ENT-1 )
-       {
-               /* PG */
-               if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
-               else          SLOT->Cnt += SLOT->Incr;
-               /* connectoion */
-               if(CH->FB)
-               {
-                       int feedback1 = (CH->op1_out[0]+CH->op1_out[1])>>CH->FB;
-                       CH->op1_out[1] = CH->op1_out[0];
-                       *CH->connect1 += CH->op1_out[0] = OP_OUT(SLOT,env_out,feedback1);
-               }
-               else
-               {
-                       *CH->connect1 += OP_OUT(SLOT,env_out,0);
-               }
-       }else
-       {
-               CH->op1_out[1] = CH->op1_out[0];
-               CH->op1_out[0] = 0;
-       }
-       /* SLOT 2 */
-       SLOT = &CH->SLOT[SLOT2];
-       env_out=OPL_CALC_SLOT(SLOT);
-       if( env_out < EG_ENT-1 )
-       {
-               /* PG */
-               if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE);
-               else          SLOT->Cnt += SLOT->Incr;
-               /* connectoion */
-               outd[0] += OP_OUT(SLOT,env_out, feedback2);
-       }
-}
-
-/* ----------- initialize time tabls ----------- */
-static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE )
-{
-       int i;
-       double rate;
-
-       /* make attack rate & decay rate tables */
-       for (i = 0;i < 4;i++) OPL->AR_TABLE[i] = OPL->DR_TABLE[i] = 0;
-       for (i = 4;i <= 60;i++){
-               rate  = OPL->freqbase;                                          /* frequency rate */
-               if( i < 60 ) rate *= 1.0+(i&3)*0.25;            /* b0-1 : x1 , x1.25 , x1.5 , x1.75 */
-               rate *= 1<<((i>>2)-1);                                          /* b2-5 : shift bit */
-               rate *= (double)(EG_ENT<<ENV_BITS);
-               OPL->AR_TABLE[i] = rate / ARRATE;
-               OPL->DR_TABLE[i] = rate / DRRATE;
-       }
-       for (i = 60;i < 76;i++)
-       {
-               OPL->AR_TABLE[i] = EG_AED-1;
-               OPL->DR_TABLE[i] = OPL->DR_TABLE[60];
-       }
-}
-
-/* ---------- generic table initialize ---------- */
-static int OPLOpenTable( void )
-{
-       int s,t;
-       double rate;
-       int i,j;
-       double pom;
-
-       /* allocate dynamic tables */
-       if( (TL_TABLE = malloc(TL_MAX*2*sizeof(INT32))) == NULL)
-               return 0;
-       if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(INT32 *))) == NULL)
-       {
-               free(TL_TABLE);
-               return 0;
-       }
-       if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(INT32))) == NULL)
-       {
-               free(TL_TABLE);
-               free(SIN_TABLE);
-               return 0;
-       }
-       if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(INT32))) == NULL)
-       {
-               free(TL_TABLE);
-               free(SIN_TABLE);
-               free(AMS_TABLE);
-               return 0;
-       }
-       /* make total level table */
-       for (t = 0;t < EG_ENT-1 ;t++){
-               rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20);   /* dB -> voltage */
-               TL_TABLE[       t] =  (int)rate;
-               TL_TABLE[TL_MAX+t] = -TL_TABLE[t];
-
-       }
-       /* fill volume off area */
-       for ( t = EG_ENT-1; t < TL_MAX ;t++){
-               TL_TABLE[t] = TL_TABLE[TL_MAX+t] = 0;
-       }
-
-       /* make sinwave table (total level offet) */
-       /* degree 0 = degree 180                   = off */
-       SIN_TABLE[0] = SIN_TABLE[SIN_ENT/2]         = &TL_TABLE[EG_ENT-1];
-       for (s = 1;s <= SIN_ENT/4;s++){
-               pom = sin(2*PI*s/SIN_ENT); /* sin     */
-               pom = 20*log10(1/pom);     /* decibel */
-               j = pom / EG_STEP;         /* TL_TABLE steps */
-
-        /* degree 0   -  90    , degree 180 -  90 : plus section */
-               SIN_TABLE[          s] = SIN_TABLE[SIN_ENT/2-s] = &TL_TABLE[j];
-        /* degree 180 - 270    , degree 360 - 270 : minus section */
-               SIN_TABLE[SIN_ENT/2+s] = SIN_TABLE[SIN_ENT  -s] = &TL_TABLE[TL_MAX+j];
-
-       }
-       for (s = 0;s < SIN_ENT;s++)
-       {
-               SIN_TABLE[SIN_ENT*1+s] = s<(SIN_ENT/2) ? SIN_TABLE[s] : &TL_TABLE[EG_ENT];
-               SIN_TABLE[SIN_ENT*2+s] = SIN_TABLE[s % (SIN_ENT/2)];
-               SIN_TABLE[SIN_ENT*3+s] = (s/(SIN_ENT/4))&1 ? &TL_TABLE[EG_ENT] : SIN_TABLE[SIN_ENT*2+s];
-       }
-
-       /* envelope counter -> envelope output table */
-       for (i=0; i<EG_ENT; i++)
-       {
-               /* ATTACK curve */
-               pom = pow( ((double)(EG_ENT-1-i)/EG_ENT) , 8 ) * EG_ENT;
-               /* if( pom >= EG_ENT ) pom = EG_ENT-1; */
-               ENV_CURVE[i] = (int)pom;
-               /* DECAY ,RELEASE curve */
-               ENV_CURVE[(EG_DST>>ENV_BITS)+i]= i;
-       }
-       /* off */
-       ENV_CURVE[EG_OFF>>ENV_BITS]= EG_ENT-1;
-       /* make LFO ams table */
-       for (i=0; i<AMS_ENT; i++)
-       {
-               pom = (1.0+sin(2*PI*i/AMS_ENT))/2; /* sin */
-               AMS_TABLE[i]         = (1.0/EG_STEP)*pom; /* 1dB   */
-               AMS_TABLE[AMS_ENT+i] = (4.8/EG_STEP)*pom; /* 4.8dB */
-       }
-       /* make LFO vibrate table */
-       for (i=0; i<VIB_ENT; i++)
-       {
-               /* 100cent = 1seminote = 6% ?? */
-               pom = (double)VIB_RATE*0.06*sin(2*PI*i/VIB_ENT); /* +-100sect step */
-               VIB_TABLE[i]         = VIB_RATE + (pom*0.07); /* +- 7cent */
-               VIB_TABLE[VIB_ENT+i] = VIB_RATE + (pom*0.14); /* +-14cent */
-       }
-       return 1;
-}
-
-
-static void OPLCloseTable( void )
-{
-       free(TL_TABLE);
-       free(SIN_TABLE);
-       free(AMS_TABLE);
-       free(VIB_TABLE);
-}
-
-/* CSM Key Controll */
-INLINE void CSMKeyControll(OPL_CH *CH)
-{
-       OPL_SLOT *slot1 = &CH->SLOT[SLOT1];
-       OPL_SLOT *slot2 = &CH->SLOT[SLOT2];
-       /* all key off */
-       OPL_KEYOFF(slot1);
-       OPL_KEYOFF(slot2);
-       /* total level latch */
-       slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl);
-       slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl);
-       /* key on */
-       CH->op1_out[0] = CH->op1_out[1] = 0;
-       OPL_KEYON(slot1);
-       OPL_KEYON(slot2);
-}
-
-/* ---------- opl initialize ---------- */
-static void OPL_initalize(FM_OPL *OPL)
-{
-       int fn;
-
-       /* frequency base */
-       OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / OPL->rate) / 72  : 0;
-       /* make time tables */
-       init_timetables( OPL , OPL_ARRATE , OPL_DRRATE );
-       /* make fnumber -> increment counter table */
-       for( fn=0 ; fn < 1024 ; fn++ )
-       {
-               OPL->FN_TABLE[fn] = OPL->freqbase * fn * FREQ_RATE * (1<<7) / 2;
-       }
-       /* LFO freq.table */
-       OPL->amsIncr = OPL->rate ? (double)AMS_ENT*(1<<AMS_SHIFT) / OPL->rate * 3.7 * ((double)OPL->clock/3600000) : 0;
-       OPL->vibIncr = OPL->rate ? (double)VIB_ENT*(1<<VIB_SHIFT) / OPL->rate * 6.4 * ((double)OPL->clock/3600000) : 0;
-}
-
-/* ---------- write a OPL registers ---------- */
-static void OPLWriteReg(FM_OPL *OPL, int r, int v)
-{
-       OPL_CH *CH;
-       int slot;
-       int block_fnum;
-
-       switch(r&0xe0)
-       {
-       case 0x00: /* 00-1f:controll */
-               switch(r&0x1f)
-               {
-               case 0x01:
-                       /* wave selector enable */
-                       if(OPL->type&OPL_TYPE_WAVESEL)
-                       {
-                               OPL->wavesel = v&0x20;
-                               if(!OPL->wavesel)
-                               {
-                                       /* preset compatible mode */
-                                       int c;
-                                       for(c=0;c<OPL->max_ch;c++)
-                                       {
-                                               OPL->P_CH[c].SLOT[SLOT1].wavetable = &SIN_TABLE[0];
-                                               OPL->P_CH[c].SLOT[SLOT2].wavetable = &SIN_TABLE[0];
-                                       }
-                               }
-                       }
-                       return;
-               }
-               break;
-       case 0x20:      /* am,vib,ksr,eg type,mul */
-               slot = slot_array[r&0x1f];
-               if(slot == -1) return;
-               set_mul(OPL,slot,v);
-               return;
-       case 0x40:
-               slot = slot_array[r&0x1f];
-               if(slot == -1) return;
-               set_ksl_tl(OPL,slot,v);
-               return;
-       case 0x60:
-               slot = slot_array[r&0x1f];
-               if(slot == -1) return;
-               set_ar_dr(OPL,slot,v);
-               return;
-       case 0x80:
-               slot = slot_array[r&0x1f];
-               if(slot == -1) return;
-               set_sl_rr(OPL,slot,v);
-               return;
-       case 0xa0:
-               switch(r)
-               {
-               case 0xbd:
-                       /* amsep,vibdep,r,bd,sd,tom,tc,hh */
-                       {
-                       OPL->ams_table = &AMS_TABLE[v&0x80 ? AMS_ENT : 0];
-                       OPL->vib_table = &VIB_TABLE[v&0x40 ? VIB_ENT : 0];
-                       }
-                       return;
-               }
-               /* keyon,block,fnum */
-               if( (r&0x0f) > 8) return;
-               CH = &OPL->P_CH[r&0x0f];
-               if(!(r&0x10))
-               {       /* a0-a8 */
-                       block_fnum  = (CH->block_fnum&0x1f00) | v;
-               }
-               else
-               {       /* b0-b8 */
-                       int keyon = (v>>5)&1;
-                       block_fnum = ((v&0x1f)<<8) | (CH->block_fnum&0xff);
-                       if(CH->keyon != keyon)
-                       {
-                               if( (CH->keyon=keyon) )
-                               {
-                                       CH->op1_out[0] = CH->op1_out[1] = 0;
-                                       OPL_KEYON(&CH->SLOT[SLOT1]);
-                                       OPL_KEYON(&CH->SLOT[SLOT2]);
-                               }
-                               else
-                               {
-                                       OPL_KEYOFF(&CH->SLOT[SLOT1]);
-                                       OPL_KEYOFF(&CH->SLOT[SLOT2]);
-                               }
-                       }
-               }
-               /* update */
-               if(CH->block_fnum != block_fnum)
-               {
-                       int blockRv = 7-(block_fnum>>10);
-                       int fnum   = block_fnum&0x3ff;
-                       CH->block_fnum = block_fnum;
-
-                       CH->ksl_base = KSL_TABLE[block_fnum>>6];
-                       CH->fc = OPL->FN_TABLE[fnum]>>blockRv;
-                       CH->kcode = CH->block_fnum>>9;
-                       if( (OPL->mode&0x40) && CH->block_fnum&0x100) CH->kcode |=1;
-                       CALC_FCSLOT(CH,&CH->SLOT[SLOT1]);
-                       CALC_FCSLOT(CH,&CH->SLOT[SLOT2]);
-               }
-               return;
-       case 0xc0:
-               /* FB,C */
-               if( (r&0x0f) > 8) return;
-               CH = &OPL->P_CH[r&0x0f];
-               {
-               int feedback = (v>>1)&7;
-               CH->FB   = feedback ? (8+1) - feedback : 0;
-               CH->CON = v&1;
-               set_algorythm(CH);
-               }
-               return;
-       case 0xe0: /* wave type */
-               slot = slot_array[r&0x1f];
-               if(slot == -1) return;
-               CH = &OPL->P_CH[slot/2];
-               if(OPL->wavesel)
-               {
-                       CH->SLOT[slot&1].wavetable = &SIN_TABLE[(v&0x03)*SIN_ENT];
-               }
-               return;
-       }
-}
-
-/* lock/unlock for common table */
-static int OPL_LockTable(void)
-{
-       num_lock++;
-       if(num_lock>1) return 0;
-       /* first time */
-       cur_chip = NULL;
-       /* allocate total level table (128kb space) */
-       if( !OPLOpenTable() )
-       {
-               num_lock--;
-               return -1;
-       }
-       return 0;
-}
-
-static void OPL_UnLockTable(void)
-{
-       if(num_lock) num_lock--;
-       if(num_lock) return;
-       /* last time */
-       cur_chip = NULL;
-       OPLCloseTable();
-}
-
-/*******************************************************************************/
-/*             YM3812 local section                                                   */
-/*******************************************************************************/
-
-/* ---------- update one of chip ----------- */
-void YM3812UpdateOne(FM_OPL *OPL, UINT32 *buffer, int length)
-{
-    int i;
-       UINT32 *buf = buffer;
-       UINT32 amsCnt  = OPL->amsCnt;
-       UINT32 vibCnt  = OPL->vibCnt;
-       OPL_CH *CH,*R_CH;
-
-       if( (void *)OPL != cur_chip ){
-               cur_chip = (void *)OPL;
-               /* channel pointers */
-               S_CH = OPL->P_CH;
-               E_CH = &S_CH[6];
-               /* LFO state */
-               amsIncr = OPL->amsIncr;
-               vibIncr = OPL->vibIncr;
-               ams_table = OPL->ams_table;
-               vib_table = OPL->vib_table;
-       }
-       R_CH = E_CH;
-    for( i=0; i < length ; i++ )
-       {
-               /*            channel A         channel B         channel C      */
-               /* LFO */
-               ams = ams_table[(amsCnt+=amsIncr)>>AMS_SHIFT];
-               vib = vib_table[(vibCnt+=vibIncr)>>VIB_SHIFT];
-               outd[0] = 0;
-               /* FM part */
-               for(CH=S_CH ; CH < R_CH ; CH++)
-                       OPL_CALC_CH(CH);
-               /* limit check */
-               //data = Limit( outd[0] , OPL_MAXOUT, OPL_MINOUT );
-               /* store to sound buffer */
-                {
-                 int32 d=outd[0]>>OPL_OUTSB;
-                 if(d<-32768) d=-32768;
-                 d+=32768;
-                 buf[i] += d;
-                }
-       }
-
-       OPL->amsCnt = amsCnt;
-       OPL->vibCnt = vibCnt;
-}
-
-/* ---------- reset one of chip ---------- */
-void OPLResetChip(FM_OPL *OPL)
-{
-       int c,s;
-       int i;
-
-       /* reset chip */
-       OPL->mode   = 0;        /* normal mode */
-
-       /* reset with register write */
-       OPLWriteReg(OPL,0x01,0); /* wabesel disable */
-       for(i = 0xff ; i >= 0x20 ; i-- ) OPLWriteReg(OPL,i,0);
-       /* reset OPerator paramater */
-       for( c = 0 ; c < OPL->max_ch ; c++ )
-       {
-               OPL_CH *CH = &OPL->P_CH[c];
-               /* OPL->P_CH[c].PAN = OPN_CENTER; */
-               for(s = 0 ; s < 2 ; s++ )
-               {
-                       /* wave table */
-                       CH->SLOT[s].wavetable = &SIN_TABLE[0];
-                       /* CH->SLOT[s].evm = ENV_MOD_RR; */
-                       CH->SLOT[s].evc = EG_OFF;
-                       CH->SLOT[s].eve = EG_OFF+1;
-                       CH->SLOT[s].evs = 0;
-               }
-       }
-}
-
-/* ----------  Create one of vietual YM3812 ----------       */
-/* 'rate'  is sampling rate and 'bufsiz' is the size of the  */
-FM_OPL *OPLCreate(int type, int clock, int rate)
-{
-       char *ptr;
-       FM_OPL *OPL;
-       int state_size;
-       int max_ch = 9; /* normaly 9 channels */
-
-       if( OPL_LockTable() ==-1) return NULL;
-       /* allocate OPL state space */
-       state_size  = sizeof(FM_OPL);
-       state_size += sizeof(OPL_CH)*max_ch;
-
-       /* allocate memory block */
-       ptr = malloc(state_size);
-       if(ptr==NULL) return NULL;
-       /* clear */
-       memset(ptr,0,state_size);
-       OPL        = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL);
-       OPL->P_CH  = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch;
-
-       /* set channel state pointer */
-       OPL->type  = type;
-       OPL->clock = clock;
-       OPL->rate  = rate;
-       OPL->max_ch = max_ch;
-       /* init grobal tables */
-       OPL_initalize(OPL);
-       /* reset chip */
-       OPLResetChip(OPL);
-
-       return OPL;
-}
-
-/* ----------  Destroy one of vietual YM3812 ----------       */
-void OPLDestroy(FM_OPL *OPL)
-{
-       OPL_UnLockTable();
-       free(OPL);
-}
-
-/* ---------- YM3812 I/O interface ---------- */
-void OPLWrite(FM_OPL *OPL,UINT8 a,UINT8 v)
-{
-       OPLWriteReg(OPL,a,v);
-}
diff --git a/mappers/fmopl.h b/mappers/fmopl.h
deleted file mode 100644 (file)
index f11a087..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1999,2000 Tatsuyuki Satoh
- *  Copyright (C) 2001,2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 
- */
-/* This file has been heavily modified from the original(mostly unused
-   code was removed).  If you want to use it for anything other than
-   VRC7 sound emulation, you should get the original from the AdPlug
-   source distribution or the MAME(version 0.37b16) source distribution
-   (but be careful about the different licenses).
-        - Xodnizel
-*/
-
-#ifndef __FMOPL_H_
-#define __FMOPL_H_
-
-/* --- system optimize --- */
-/* select bit size of output : 8 or 16 */
-#define OPL_OUTPUT_BIT 16
-
-/* compiler dependence */
-#ifndef OSD_CPU_H
-#define OSD_CPU_H
-
-typedef unsigned char  UINT8;   /* unsigned  8bit */
-typedef unsigned short UINT16;  /* unsigned 16bit */
-typedef unsigned long  UINT32;  /* unsigned 32bit */
-typedef signed char            INT8;    /* signed  8bit   */
-typedef signed short   INT16;   /* signed 16bit   */
-typedef signed long            INT32;   /* signed 32bit   */
-#endif
-
-#if (OPL_OUTPUT_BIT==16)
-typedef INT16 OPLSAMPLE;
-#endif
-#if (OPL_OUTPUT_BIT==8)
-typedef unsigned char  OPLSAMPLE;
-#endif
-
-
-/* !!!!! here is private section , do not access there member direct !!!!! */
-
-#define OPL_TYPE_WAVESEL   0x01  /* waveform select    */
-
-/* Saving is necessary for member of the 'R' mark for suspend/resume */
-/* ---------- OPL one of slot  ---------- */
-typedef struct fm_opl_slot {
-       INT32 TL;               /* total level     :TL << 8            */
-       INT32 TLL;              /* adjusted now TL                     */
-       UINT8  KSR;             /* key scale rate  :(shift down bit)   */
-       INT32 *AR;              /* attack rate     :&AR_TABLE[AR<<2]   */
-       INT32 *DR;              /* decay rate      :&DR_TALBE[DR<<2]   */
-       INT32 SL;               /* sustin level    :SL_TALBE[SL]       */
-       INT32 *RR;              /* release rate    :&DR_TABLE[RR<<2]   */
-       UINT8 ksl;              /* keyscale level  :(shift down bits)  */
-       UINT8 ksr;              /* key scale rate  :kcode>>KSR         */
-       UINT32 mul;             /* multiple        :ML_TABLE[ML]       */
-       UINT32 Cnt;             /* frequency count :                   */
-       UINT32 Incr;    /* frequency step  :                   */
-       /* envelope generator state */
-       UINT8 eg_typ;   /* envelope type flag                  */
-       UINT8 evm;              /* envelope phase                      */
-       INT32 evc;              /* envelope counter                    */
-       INT32 eve;              /* envelope counter end point          */
-       INT32 evs;              /* envelope counter step               */
-       INT32 evsa;     /* envelope step for AR :AR[ksr]           */
-       INT32 evsd;     /* envelope step for DR :DR[ksr]           */
-       INT32 evsr;     /* envelope step for RR :RR[ksr]           */
-       /* LFO */
-       UINT8 ams;              /* ams flag                            */
-       UINT8 vib;              /* vibrate flag                        */
-       /* wave selector */
-       INT32 **wavetable;
-}OPL_SLOT;
-
-/* ---------- OPL one of channel  ---------- */
-typedef struct fm_opl_channel {
-       OPL_SLOT SLOT[2];
-       UINT8 CON;                      /* connection type                     */
-       UINT8 FB;                       /* feed back       :(shift down bit)   */
-       INT32 *connect1;        /* slot1 output pointer                */
-       INT32 *connect2;        /* slot2 output pointer                */
-       INT32 op1_out[2];       /* slot1 output for selfeedback        */
-       /* phase generator state */
-       UINT32  block_fnum;     /* block+fnum      :                   */
-       UINT8 kcode;            /* key code        : KeyScaleCode      */
-       UINT32  fc;                     /* Freq. Increment base                */
-       UINT32  ksl_base;       /* KeyScaleLevel Base step             */
-       UINT8 keyon;            /* key on/off flag                     */
-} OPL_CH;
-
-/* OPL state */
-typedef struct fm_opl_f {
-       UINT8 type;                     /* chip type                         */
-       int clock;                      /* master clock  (Hz)                */
-       int rate;                       /* sampling rate (Hz)                */
-       double freqbase;        /* frequency base                    */
-       double TimerBase;       /* Timer base time (==sampling time) */
-       UINT8 address;          /* address register                  */
-       UINT32 mode;            /* Reg.08 : CSM , notesel,etc.       */
-
-       /* FM channel slots */
-       OPL_CH *P_CH;           /* pointer of CH                     */
-       int     max_ch;                 /* maximum channel                   */
-
-       /* time tables */
-       INT32 AR_TABLE[75];     /* atttack rate tables */
-       INT32 DR_TABLE[75];     /* decay rate tables   */
-       UINT32 FN_TABLE[1024];  /* fnumber -> increment counter */
-       /* LFO */
-       INT32 *ams_table;
-       INT32 *vib_table;
-       INT32 amsCnt;
-       INT32 amsIncr;
-       INT32 vibCnt;
-       INT32 vibIncr;
-       /* wave selector enable flag */
-       UINT8 wavesel;
-
-} FM_OPL;
-
-/* ---------- Generic interface section ---------- */
-#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
-
-FM_OPL *OPLCreate(int type, int clock, int rate);
-void OPLDestroy(FM_OPL *OPL);
-
-void OPLResetChip(FM_OPL *OPL);
-void OPLWrite(FM_OPL *OPL,UINT8 a,UINT8 v);
-
-/* YM3626/YM3812 local section */
-void YM3812UpdateOne(FM_OPL *OPL, UINT32 *buffer, int length);
-
-#endif
index ebe446c..9eec5c9 100644 (file)
@@ -1,12 +1,13 @@
-#include        "../types.h"
-#include        "../x6502.h"
-#include        "../fce.h"
+#include "../types.h"
+#include "../x6502.h"
+#include "../fce.h"
+#include "../ppu.h"
 #define INESPRIV
-#include        "../ines.h"
-#include        "../version.h"
-#include        "../memory.h"
-#include       "../sound.h"
-#include        "../svga.h"
-#include       "../state.h"
-#include       "../cart.h"
-#include       "mapshare.h"
+#include "../cart.h"
+#include "../ines.h"
+#include "../memory.h"
+#include "../sound.h"
+#include "../state.h"
+#include "../svga.h"
+#include "../dprintf.h"
+#include <string.h>
diff --git a/mappers/mapshare.h b/mappers/mapshare.h
deleted file mode 100644 (file)
index 4853050..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-void MMC3_hb(void);
-
-#define resetmode mapbyte1[0]
-#define MMC3_cmd mapbyte1[1]
-
index 1b23e49..022d736 100644 (file)
@@ -1,7 +1,7 @@
 /* FCE Ultra - NES/Famicom Emulator
  *
  * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
+ *  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
@@ -64,16 +64,14 @@ static void FP_FASTAPASS(1) latchcheck(uint32 VAddr)
      }
 }
 
-DECLFW(Mapper9_write)  // $Axxx
+DECLFW(Mapper9_write)        // $Axxx
 {
  ROM_BANK8(0x8000,V);
- X6502_Rebase();
 }
 
 DECLFW(Mapper10_write)
 {
  ROM_BANK16(0x8000,V);
- X6502_Rebase();
 }
 
 DECLFW(Mapper9and10_write)
@@ -81,19 +79,19 @@ DECLFW(Mapper9and10_write)
        switch(A&0xF000)
        {
         case 0xB000:
-                if (latcha1==0xFD) { VROM_BANK4(0x0000,V);}
+                if(latcha1==0xFD) { VROM_BANK4(0x0000,V);}
                 MMC4reg[0]=V;
                 break;
         case 0xC000:
-                if (latcha1==0xFE) {VROM_BANK4(0x0000,V);}
+                if(latcha1==0xFE) {VROM_BANK4(0x0000,V);}
                 MMC4reg[1]=V;
                 break;
         case 0xD000:
-                if (latcha2==0xFD) {VROM_BANK4(0x1000,V);}
+                if(latcha2==0xFD) {VROM_BANK4(0x1000,V);}
                 MMC4reg[2]=V;
                 break;
         case 0xE000:
-                if (latcha2==0xFE) {VROM_BANK4(0x1000,V);}
+                if(latcha2==0xFE) {VROM_BANK4(0x1000,V);}
                 MMC4reg[3]=V;
                 break;
         case 0xF000:
@@ -109,7 +107,7 @@ void Mapper9_init(void)
         ROM_BANK8(0xA000,~2);
         ROM_BANK8(0x8000,0);
         SetWriteHandler(0xA000,0xAFFF,Mapper9_write);
-       SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
+        SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
         PPU_hook=latchcheck;
 }
 
@@ -117,7 +115,7 @@ void Mapper10_init(void)
 {
         latcha1=latcha2=0xFE;
         SetWriteHandler(0xA000,0xAFFF,Mapper10_write);
-       SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
+        SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
         PPU_hook=latchcheck;
 }
 
index de6c42f..b2c76d8 100644 (file)
@@ -2,7 +2,7 @@
  *
  * Copyright notice for this file:
  *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
+ *  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
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
-#include <string.h>
+
 #include "mapinc.h"
 
 static uint8 latche;
 
-static DECLFW(Mapper2_write)
-{
-       latche=V;
-        ROM_BANK16(0x8000,V);
-        X6502_Rebase();
-}
-
-void Mapper2_init(void)
-{
-  SetWriteHandler(0x8000,0xFFFF,Mapper2_write);
-  AddExState(&latche, 1, 0, "LATC");
-}
-
-static DECLFW(Mapper3_write)
-{
-        VROM_BANK8(V);
-       latche=V;
-}
-
-void Mapper3_init(void)
-{
-       SetWriteHandler(0x8000,0xFFFF,Mapper3_write);
-       AddExState(&latche, 1, 0, "LATC");
-}
-
-DECLFW(Mapper7_write)
-{
+//static DECLFW(Mapper2_write)
+//{
+//    latche=V;
+//    ROM_BANK16(0x8000,V);
+//}
+//
+//void Mapper2_init(void)
+//{
+//    SetWriteHandler(0x8000,0xFFFF,Mapper2_write);
+//    AddExState(&latche, 1, 0, "LATC");
+//}
+
+//static DECLFW(Mapper3_write)
+//{
+//  VROM_BANK8(V);
+//  latche=V;
+//}
+
+//void Mapper3_init(void)
+//{
+//        SetWriteHandler(0x8000,0xFFFF,Mapper3_write);
+//        AddExState(&latche, 1, 0, "LATC");
+//}
+
+static DECLFW(Mapper7_write)
+{
+//    FCEU_printf("%04x,%04x\n",A,V);
       ROM_BANK32(V&0xF);
       onemir((V>>4)&1);
       latche=V;
-      X6502_Rebase();
 }
 
 void Mapper7_init(void)
@@ -61,70 +60,69 @@ void Mapper7_init(void)
         onemir(0);
         ROM_BANK32(0);
         SetWriteHandler(0x8000,0xFFFF,Mapper7_write);
-       AddExState(&latche, 1, 0, "LATC");
+        AddExState(&latche, 1, 0, "LATC");
 }
 
-DECLFW(Mapper11_write)
+static DECLFW(Mapper11_write)
 {
-        ROM_BANK32(V);
+        ROM_BANK32(V&0xF);
         VROM_BANK8(V>>4);
-       latche=V;
-        X6502_Rebase();
+        latche=V;
 }
 
 void Mapper11_init(void)
 {
         ROM_BANK32(0);
-       SetWriteHandler(0x8000,0xFFFF,Mapper11_write);
-       AddExState(&latche, 1, 0, "LATC");
-}
-
-static DECLFW(Mapper13_write)
-{
-       setchr4r(0x10,0x1000,V&3);
-       setprg32(0x8000,(V>>4)&3);
-       latche=V;
-       X6502_Rebase();
-}
-
-static void Mapper13_StateRestore(int version)
-{
-       setchr4r(0x10,0x0000,0);
-        setchr4r(0x10,0x1000,latche&3);
-        setprg32(0x8000,(latche>>4)&3);
-       X6502_Rebase();
-}
-
-void Mapper13_init(void)
-{
-       SetWriteHandler(0x8000,0xFFFF,Mapper13_write);
-       GameStateRestore=Mapper13_StateRestore;
-       AddExState(&latche, 1, 0, "LATC");
-       AddExState(MapperExRAM, 16384, 0, "CHRR");
-       SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1);
-
-       latche=0;
-        Mapper13_StateRestore(VERSION_NUMERIC);
-}
-
-DECLFW(Mapper34_write)
-{
-switch(A)
+        SetWriteHandler(0x8000,0xFFFF,Mapper11_write);
+        AddExState(&latche, 1, 0, "LATC");
+}
+void Mapper144_init(void)
+{
+       ROM_BANK32(0);
+        SetWriteHandler(0x8001,0xFFFF,Mapper11_write);
+        AddExState(&latche, 1, 0, "LATC");
+
+}
+//static DECLFW(Mapper13_write)
+//{
+//        setchr4r(0x10,0x1000,V&3);
+//        setprg32(0x8000,(V>>4)&3);
+//        latche=V;
+//}
+
+//static void Mapper13_StateRestore(int version)
+//{
+//        setchr4r(0x10,0x0000,0);
+//        setchr4r(0x10,0x1000,latche&3);
+//        setprg32(0x8000,(latche>>4)&3);
+//}
+
+//void Mapper13_init(void)
+//{
+//        SetWriteHandler(0x8000,0xFFFF,Mapper13_write);
+//        GameStateRestore=Mapper13_StateRestore;
+//        AddExState(&latche, 1, 0, "LATC");
+//        AddExState(MapperExRAM, 16384, 0, "CHRR");
+//        SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1);
+//        latche=0;
+//        Mapper13_StateRestore(FCEU_VERSION_NUMERIC);
+//}
+
+static DECLFW(Mapper34_write)
+{
+ switch(A)
  {
- case 0x7FFD:ROM_BANK32(V);
-             X6502_Rebase();break;
- case 0x7FFE:VROM_BANK4(0x0000,V);break;
- case 0x7fff:VROM_BANK4(0x1000,V);break;
+  case 0x7FFD:ROM_BANK32(V);break;
+  case 0x7FFE:VROM_BANK4(0x0000,V);break;
+  case 0x7fff:VROM_BANK4(0x1000,V);break;
  }
  if(A>=0x8000)
- {
   ROM_BANK32(V);
-  X6502_Rebase();
- }
 }
 
 void Mapper34_init(void)
 {
+ ROM_BANK32(0);
   SetWriteHandler(0x7ffd,0xffff,Mapper34_write);
 }
 
@@ -133,7 +131,6 @@ DECLFW(Mapper66_write)
  VROM_BANK8(V&0xF);
  ROM_BANK32((V>>4));
  latche=V;
- X6502_Rebase();
 }
 
 void Mapper66_init(void)
@@ -147,9 +144,8 @@ DECLFW(Mapper152_write)
 {
  ROM_BANK16(0x8000,(V>>4)&0x7);
  VROM_BANK8(V&0xF);
- onemir((V>>7)&1);     /* Saint Seiya...hmm. */
+ onemir((V>>7)&1);        /* Saint Seiya...hmm. */
  latche=V;
- X6502_Rebase();
 }
 
 void Mapper152_init(void)
@@ -164,7 +160,6 @@ static DECLFW(Mapper70_write)
  ROM_BANK16(0x8000,V>>4);
  VROM_BANK8(V&0xF);
  latche=V;
- X6502_Rebase();
 }
 
 void Mapper70_init(void)
@@ -175,12 +170,11 @@ void Mapper70_init(void)
 /* Should be two separate emulation functions for this "mapper".  Sigh.  URGE TO KILL RISING. */
 static DECLFW(Mapper78_write)
 {
- //printf("$%04x:$%02x\n",A,V);
+ //printf("$%04x:$%02x\n",A,V&0x8);
  ROM_BANK16(0x8000,V&0x7);
  VROM_BANK8(V>>4);
  onemir((V>>3)&1);
  latche=V;
- X6502_Rebase();
 }
 
 void Mapper78_init(void)
@@ -206,7 +200,6 @@ DECLFW(Mapper93_write)
   ROM_BANK16(0x8000,V>>4);
   MIRROR_SET(V&1);
   latche=V;
-  X6502_Rebase();
 }
 
 void Mapper93_init(void)
@@ -220,7 +213,6 @@ DECLFW(Mapper94_write)
 {
  ROM_BANK16(0x8000,V>>2);
  latche=V;
- X6502_Rebase();
 }
 
 void Mapper94_init(void)
@@ -241,23 +233,21 @@ static DECLFW(Mapper96_write)
  setprg32(0x8000,V&3);
  setchr4r(0x10,0x0000,(latche&4)|M96LA);
  setchr4r(0x10,0x1000,(latche&4)|3);
- X6502_Rebase();
 }
 
 static void FP_FASTAPASS(1) M96Hook(uint32 A)
 {
- if((A&0x3000)!=0x2000)
-  return;
+ if((A&0x3000)!=0x2000) return;
//if((A&0x3ff)>=0x3c0) return;
  M96LA=(A>>8)&3;
  setchr4r(0x10,0x0000,(latche&4)|M96LA);
 }
 
-static void M96Sync()
+static void M96Sync(int v)
 {
  setprg32(0x8000,latche&3);
  setchr4r(0x10,0x0000,(latche&4)|M96LA);
  setchr4r(0x10,0x1000,(latche&4)|3);
- X6502_Rebase();
 }
 
 void Mapper96_init(void)
@@ -268,7 +258,8 @@ void Mapper96_init(void)
  AddExState(&M96LA, 1, 0, "LAVA");
  SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1);
  latche=M96LA=0;
- M96Sync();
+ M96Sync(0);
+ setmirror(MI_0);
  GameStateRestore=M96Sync;
 }
 
@@ -276,7 +267,6 @@ static DECLFW(Mapper140_write)
 {
  VROM_BANK8(V&0xF);
  ROM_BANK32((V>>4)&0xF);
- X6502_Rebase();
 }
 
 void Mapper140_init(void)
@@ -285,34 +275,68 @@ void Mapper140_init(void)
  SetWriteHandler(0x6000,0x7FFF,Mapper140_write);
 }
 
-static void M185Sync()
+static void M185Sync(int version)
 {
- int x;
+//   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
 
- if(!(mapbyte1[0]&3))
-// if(!(mapbyte1[0]==0x21))
- {
-  for(x=0;x<8;x++)
-   setchr1r(0x10,x<<10,0);
-  }
- else
-  setchr8(0);
+//  if((mapbyte1[0]&3)==1)                     // 6, 3
+//  if(mapbyte1[0]&1)                          // 1, 2, 3, 5
+//  if(mapbyte1[0]&2)                          // 1, 2, 4, 5,
+  if((mapbyte1[0]&2)||((mapbyte1[0]&3)==1)) // 1, 2, 3, 4, 5
+   setchr8(0);
+  else
+   setchr8r(0x10,0);
 }
 
 static DECLFW(Mapper185_write)
 {
- mapbyte1[0]=V;
- M185Sync();
- // printf("Wr: $%04x:$%02x\n",A,V);
+  mapbyte1[0]=V;
+  M185Sync(0);
 }
 
 void Mapper185_init(void)
 {
- memset(MapperExRAM,0xFF,1024);
- MapStateRestore=M185Sync;
- mapbyte1[0]=0;
- M185Sync();
+  int x;
+  for(x=0;x<8192;x++)
+   MapperExRAM[x]=0xff;
+  MapStateRestore=M185Sync;
+  mapbyte1[0]=0;
+  M185Sync(0);
+  SetupCartCHRMapping(0x10,MapperExRAM,8192,0);
+  SetWriteHandler(0x8000,0xFFFF,Mapper185_write);
+}
+
 
- SetupCartCHRMapping(0x10,MapperExRAM,1024,0);
- SetWriteHandler(0x8000,0xFFFF,Mapper185_write);
+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);
+}
+
+static DECLFW(m107w)
+{
+ ROM_BANK32((V>>1)&0x3);
+ VROM_BANK8(V&0x7);
+}
+
+void Mapper107_init(void)
+{
+ SetWriteHandler(0x8000,0xffff,m107w);
+}
+
diff --git a/mappers/vrc7snd.c b/mappers/vrc7snd.c
deleted file mode 100644 (file)
index ea02830..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 <stdio.h>
-#include <stdlib.h>
-#include "mapinc.h"
-#include "fmopl.h"
-
-static void VRC7_LoadInstrument(uint8 Chan);
-void vrc7translate(uint8 Reg,uint8 V);
-
-FM_OPL *fmob=0;
-uint8 VRC7Chan[3][6];
-static void InitOPL(void);
-
-void OPL2_setreg(uint8 A, uint8 V)
-{
- if(fmob)
-  OPLWrite(fmob,A,V);
-}
-
-
-void LoadOPL(void)
-{
- int x;
- int y;
-
- for(x=y=0;x<0x40;x++)
-  y|=MapperExRAM[x];
- if(y)
- {
-  InitOPL();
-  for(x=0;x<6;x++)
-  {
-   VRC7_LoadInstrument(x);
-   vrc7translate(0x10+x,VRC7Chan[0][x]);
-  }
- }
-}
-
-static int dwave=0;
-
-void VRC7Update(void)
-{
- int32 z,a;
-
- z=((SOUNDTS<<16)/soundtsinc)>>4;
- a=z-dwave;
-
- if(a && fmob)
-  YM3812UpdateOne(fmob, &Wave[dwave], a);
- dwave+=a;
-}
-
-void UpdateOPL(int Count)
-{
- int32 z,a;
-
- z=((SOUNDTS<<16)/soundtsinc)>>4;
- a=z-dwave;
-
- if(fmob && a)
-  YM3812UpdateOne(fmob, &Wave[dwave], a);
-
- dwave=0;
-}
-
-void KillOPL(void)
-{
- if(fmob) OPLDestroy(fmob);
- fmob=0;
-}
-
-static void InitOPL(void)
-{
-        int x;
-
-       if(!fmob)
-       {
-         if(!( fmob=OPLCreate(OPL_TYPE_WAVESEL,1789772*2,FSettings.SndRate)))
-         return;
-       }
-       GameExpSound.Kill=KillOPL;
-        OPLResetChip(fmob);
-
-        for(x=0x1;x<0xF6;x++)
-         OPL2_setreg(x,0);
-        OPL2_setreg(0xBD,0xC0);
-        OPL2_setreg(1,0x20);      /* Enable waveform type manipulation */
-}
-
-/*     This following code is in the public domain, but the author, Quietust(see       */
-/*     the "AUTHORS" file, would appreciate credit to go to him if this code */
-/*     is used.                */
-
-uint8 VRC7Instrument[16][8] = {
-       {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},      /* Custom instrument. */
-       {0x03,0x01,0x14,0x80,0xC2,0x90,0x43,0x14},      /* Currently working on this one */
-       {0x13,0x41,0x10,0x0B,0xFF,0xF2,0x32,0xD6},
-       {0x01,0x01,0x10,0x08,0xF0,0xF4,0x00,0x04},      /* 90% perfect */
-       {0x21,0x41,0x1B,0x08,0x66,0x80,0x30,0x85},
-       {0x22,0x21,0x20,0x03,0x75,0x70,0x24,0x14},
-       {0x02,0x01,0x06,0x00,0xF0,0xF2,0x03,0x95},      /* Do not touch! 98% perfect! */
-       {0x21,0x41,0x18,0x10,0x93,0xE0,0x21,0x15},
-       {0x01,0x22,0x13,0x00,0xF0,0x82,0x00,0x15},
-       {0x05,0x01,0x22,0x00,0x60,0xE3,0xA0,0xF5},      /* 90% perfect */
-       {0x85,0x01,0x20,0x00,0xD7,0xA2,0x22,0xF5},      /* 90% perfect */
-       {0x07,0x81,0x2B,0x05,0xF4,0xF2,0x14,0xF4},      /* 95% perfect */
-       {0x21,0x41,0x20,0x18,0xF3,0x80,0x13,0x95},
-       {0x01,0x02,0x20,0x00,0xF9,0x92,0x41,0x75},      /* Do not touch! 98% perfect! */
-       {0x21,0x62,0x0E,0x00,0x84,0x85,0x45,0x15},      /* 90% perfect */
-       {0x21,0x62,0x0E,0x00,0xA1,0xA0,0x34,0x16}       /* Do not touch! 98% perfect! */
-};
-
-static uint8 InstTrans[6] = {0x00,0x01,0x02,0x08,0x09,0x0A};
-
-static void VRC7_LoadInstrument(uint8 Chan)
-{
-       uint8 *i;
-       uint8 x = InstTrans[Chan];
-       uint8 y = (VRC7Chan[2][Chan] >> 4) & 0xF;
-
-       i=VRC7Instrument[y];
-
-       OPL2_setreg((0x20+x),i[0]);
-       OPL2_setreg((0x23+x),i[1]);
-       OPL2_setreg((0x40+x),i[2]);
-       OPL2_setreg((0x43+x),((i[3] & 0xC0)
-               | ((VRC7Chan[2][Chan] << 2) & 0x3C)));  // quiet
-       OPL2_setreg(0xe0+x,(i[3] >> 3) & 0x01);
-       OPL2_setreg(0xe3+x,(i[3] >> 4) & 0x01);
-       OPL2_setreg(0xC0+Chan,(i[3] << 1) & 0x0E);
-       OPL2_setreg(0x60+x,i[4]);
-       OPL2_setreg(0x63+x,i[5]);
-       OPL2_setreg(0x80+x,i[6]);
-       OPL2_setreg(0x83+x,i[7]);
-}
-
-void vrc7translate(uint8 Reg,uint8 V)
-{
-       uint8 x = Reg & 0x0F, y;
-        if(!fmob) InitOPL();
-
-       MapperExRAM[Reg]=V;
-
-       VRC7Update();
-       switch ((Reg & 0xF0) >> 4)
-       {
-        case 0:
-               if (x & 0x08) break;
-               VRC7Instrument[0][x] = V;
-               for (y = 0; y < 6; y++)
-                if (!(VRC7Chan[2][y]&0xF0))
-                 VRC7_LoadInstrument(y);
-               break;
-        case 1:
-               if(x>5) break;
-               VRC7Chan[0][x] = V;
-               OPL2_setreg(0xA0 + x,(VRC7Chan[0][x] << 1) & 0xFE);
-               OPL2_setreg(0xB0 + x,((VRC7Chan[0][x] >> 7) & 0x01) | ((VRC7Chan[1][x] << 1) & 0x3E));
-               break;
-        case 2:
-               if(x>5) break;
-               VRC7Chan[1][x] = V;
-               OPL2_setreg(0xB0 + x,(((VRC7Chan[0][x] >> 7) & 0x01) | ((VRC7Chan[1][x] << 1) & 0x3E)));
-               break;
-        case 3:
-               if(x>5) break;
-               VRC7Chan[2][x] = V;
-               VRC7_LoadInstrument(x);
-               break;
-       }
-}
diff --git a/mappers/vrc7tone.h b/mappers/vrc7tone.h
new file mode 100644 (file)
index 0000000..d136307
--- /dev/null
@@ -0,0 +1,17 @@
+/* VRC7 instruments, January 17, 2004 update -Xodnizel */
+        {0x03, 0x21, 0x04, 0x06, 0x8D, 0xF2, 0x42, 0x17}, 
+        {0x13, 0x41, 0x05, 0x0E, 0x99, 0x96, 0x63, 0x12}, 
+        {0x31, 0x11, 0x10, 0x0A, 0xF0, 0x9C, 0x32, 0x02}, 
+        {0x21, 0x61, 0x1D, 0x07, 0x9F, 0x64, 0x20, 0x27}, 
+        {0x22, 0x21, 0x1E, 0x06, 0xF0, 0x76, 0x08, 0x28}, 
+        {0x02, 0x01, 0x06, 0x00, 0xF0, 0xF2, 0x03, 0x95}, 
+        {0x21, 0x61, 0x1C, 0x07, 0x82, 0x81, 0x16, 0x07}, 
+        {0x23, 0x21, 0x1A, 0x17, 0xEF, 0x82, 0x25, 0x15}, 
+        {0x25, 0x11, 0x1F, 0x00, 0x86, 0x41, 0x20, 0x11}, 
+        {0x85, 0x01, 0x1F, 0x0F, 0xE4, 0xA2, 0x11, 0x12}, 
+        {0x07, 0xC1, 0x2B, 0x45, 0xB4, 0xF1, 0x24, 0xF4},
+        {0x61, 0x23, 0x11, 0x06, 0x96, 0x96, 0x13, 0x16}, 
+        {0x01, 0x02, 0xD3, 0x05, 0x82, 0xA2, 0x31, 0x51}, 
+        {0x61, 0x22, 0x0D, 0x02, 0xC3, 0x7F, 0x24, 0x05},
+        {0x21, 0x62, 0x0E, 0x00, 0xA1, 0xA0, 0x44, 0x17},
+
diff --git a/md5.c b/md5.c
new file mode 100644 (file)
index 0000000..174d3ee
--- /dev/null
+++ b/md5.c
@@ -0,0 +1,246 @@
+/*\r
+ * RFC 1321 compliant MD5 implementation,\r
+ * by Christophe Devine <devine@cr0.net>;\r
+ * this program is licensed under the GPL.\r
+ */\r
+\r
+/* Modified October 3, 2003, to remove testing code, and add\r
+   include of "types.h".\r
\r
+   Added simple MD5 to ASCII string conversion function.\r
+   -Xodnizel\r
+*/\r
+\r
+#include <string.h>\r
+#include "types.h"\r
+#include "md5.h"\r
+\r
+#define GET_UINT32(n,b,i)           \\r
+{                 \\r
+    (n) = ( (uint32) (b)[(i) + 3] << 24 )       \\r
+        | ( (uint32) (b)[(i) + 2] << 16 )       \\r
+        | ( (uint32) (b)[(i) + 1] <<  8 )       \\r
+        | ( (uint32) (b)[(i)    ]       );      \\r
+}\r
+\r
+#define PUT_UINT32(n,b,i)           \\r
+{                 \\r
+    (b)[(i)    ] = (uint8) ( (n)       );       \\r
+    (b)[(i) + 1] = (uint8) ( (n) >>  8 );       \\r
+    (b)[(i) + 2] = (uint8) ( (n) >> 16 );       \\r
+    (b)[(i) + 3] = (uint8) ( (n) >> 24 );       \\r
+}\r
+\r
+void md5_starts( struct md5_context *ctx )\r
+{\r
+    ctx->total[0] = 0;\r
+    ctx->total[1] = 0;\r
+    ctx->state[0] = 0x67452301;\r
+    ctx->state[1] = 0xEFCDAB89;\r
+    ctx->state[2] = 0x98BADCFE;\r
+    ctx->state[3] = 0x10325476;\r
+}\r
+\r
+void md5_process( struct md5_context *ctx, uint8 data[64] )\r
+{\r
+    uint32 A, B, C, D, X[16];\r
+\r
+    GET_UINT32( X[0],  data,  0 );\r
+    GET_UINT32( X[1],  data,  4 );\r
+    GET_UINT32( X[2],  data,  8 );\r
+    GET_UINT32( X[3],  data, 12 );\r
+    GET_UINT32( X[4],  data, 16 );\r
+    GET_UINT32( X[5],  data, 20 );\r
+    GET_UINT32( X[6],  data, 24 );\r
+    GET_UINT32( X[7],  data, 28 );\r
+    GET_UINT32( X[8],  data, 32 );\r
+    GET_UINT32( X[9],  data, 36 );\r
+    GET_UINT32( X[10], data, 40 );\r
+    GET_UINT32( X[11], data, 44 );\r
+    GET_UINT32( X[12], data, 48 );\r
+    GET_UINT32( X[13], data, 52 );\r
+    GET_UINT32( X[14], data, 56 );\r
+    GET_UINT32( X[15], data, 60 );\r
+\r
+#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))\r
+\r
+#define P(a,b,c,d,k,s,t)        \\r
+{                   \\r
+    a += F(b,c,d) + X[k] + t; a = S(a,s) + b;     \\r
+}\r
+\r
+    A = ctx->state[0];\r
+    B = ctx->state[1];\r
+    C = ctx->state[2];\r
+    D = ctx->state[3];\r
+\r
+#define F(x,y,z) (z ^ (x & (y ^ z)))\r
+\r
+    P( A, B, C, D,  0,  7, 0xD76AA478 );\r
+    P( D, A, B, C,  1, 12, 0xE8C7B756 );\r
+    P( C, D, A, B,  2, 17, 0x242070DB );\r
+    P( B, C, D, A,  3, 22, 0xC1BDCEEE );\r
+    P( A, B, C, D,  4,  7, 0xF57C0FAF );\r
+    P( D, A, B, C,  5, 12, 0x4787C62A );\r
+    P( C, D, A, B,  6, 17, 0xA8304613 );\r
+    P( B, C, D, A,  7, 22, 0xFD469501 );\r
+    P( A, B, C, D,  8,  7, 0x698098D8 );\r
+    P( D, A, B, C,  9, 12, 0x8B44F7AF );\r
+    P( C, D, A, B, 10, 17, 0xFFFF5BB1 );\r
+    P( B, C, D, A, 11, 22, 0x895CD7BE );\r
+    P( A, B, C, D, 12,  7, 0x6B901122 );\r
+    P( D, A, B, C, 13, 12, 0xFD987193 );\r
+    P( C, D, A, B, 14, 17, 0xA679438E );\r
+    P( B, C, D, A, 15, 22, 0x49B40821 );\r
+\r
+#undef F\r
+\r
+#define F(x,y,z) (y ^ (z & (x ^ y)))\r
+\r
+    P( A, B, C, D,  1,  5, 0xF61E2562 );\r
+    P( D, A, B, C,  6,  9, 0xC040B340 );\r
+    P( C, D, A, B, 11, 14, 0x265E5A51 );\r
+    P( B, C, D, A,  0, 20, 0xE9B6C7AA );\r
+    P( A, B, C, D,  5,  5, 0xD62F105D );\r
+    P( D, A, B, C, 10,  9, 0x02441453 );\r
+    P( C, D, A, B, 15, 14, 0xD8A1E681 );\r
+    P( B, C, D, A,  4, 20, 0xE7D3FBC8 );\r
+    P( A, B, C, D,  9,  5, 0x21E1CDE6 );\r
+    P( D, A, B, C, 14,  9, 0xC33707D6 );\r
+    P( C, D, A, B,  3, 14, 0xF4D50D87 );\r
+    P( B, C, D, A,  8, 20, 0x455A14ED );\r
+    P( A, B, C, D, 13,  5, 0xA9E3E905 );\r
+    P( D, A, B, C,  2,  9, 0xFCEFA3F8 );\r
+    P( C, D, A, B,  7, 14, 0x676F02D9 );\r
+    P( B, C, D, A, 12, 20, 0x8D2A4C8A );\r
+\r
+#undef F\r
+    \r
+#define F(x,y,z) (x ^ y ^ z)\r
+\r
+    P( A, B, C, D,  5,  4, 0xFFFA3942 );\r
+    P( D, A, B, C,  8, 11, 0x8771F681 );\r
+    P( C, D, A, B, 11, 16, 0x6D9D6122 );\r
+    P( B, C, D, A, 14, 23, 0xFDE5380C );\r
+    P( A, B, C, D,  1,  4, 0xA4BEEA44 );\r
+    P( D, A, B, C,  4, 11, 0x4BDECFA9 );\r
+    P( C, D, A, B,  7, 16, 0xF6BB4B60 );\r
+    P( B, C, D, A, 10, 23, 0xBEBFBC70 );\r
+    P( A, B, C, D, 13,  4, 0x289B7EC6 );\r
+    P( D, A, B, C,  0, 11, 0xEAA127FA );\r
+    P( C, D, A, B,  3, 16, 0xD4EF3085 );\r
+    P( B, C, D, A,  6, 23, 0x04881D05 );\r
+    P( A, B, C, D,  9,  4, 0xD9D4D039 );\r
+    P( D, A, B, C, 12, 11, 0xE6DB99E5 );\r
+    P( C, D, A, B, 15, 16, 0x1FA27CF8 );\r
+    P( B, C, D, A,  2, 23, 0xC4AC5665 );\r
+\r
+#undef F\r
+\r
+#define F(x,y,z) (y ^ (x | ~z))\r
+\r
+    P( A, B, C, D,  0,  6, 0xF4292244 );\r
+    P( D, A, B, C,  7, 10, 0x432AFF97 );\r
+    P( C, D, A, B, 14, 15, 0xAB9423A7 );\r
+    P( B, C, D, A,  5, 21, 0xFC93A039 );\r
+    P( A, B, C, D, 12,  6, 0x655B59C3 );\r
+    P( D, A, B, C,  3, 10, 0x8F0CCC92 );\r
+    P( C, D, A, B, 10, 15, 0xFFEFF47D );\r
+    P( B, C, D, A,  1, 21, 0x85845DD1 );\r
+    P( A, B, C, D,  8,  6, 0x6FA87E4F );\r
+    P( D, A, B, C, 15, 10, 0xFE2CE6E0 );\r
+    P( C, D, A, B,  6, 15, 0xA3014314 );\r
+    P( B, C, D, A, 13, 21, 0x4E0811A1 );\r
+    P( A, B, C, D,  4,  6, 0xF7537E82 );\r
+    P( D, A, B, C, 11, 10, 0xBD3AF235 );\r
+    P( C, D, A, B,  2, 15, 0x2AD7D2BB );\r
+    P( B, C, D, A,  9, 21, 0xEB86D391 );\r
+\r
+#undef F\r
+\r
+    ctx->state[0] += A;\r
+    ctx->state[1] += B;\r
+    ctx->state[2] += C;\r
+    ctx->state[3] += D;\r
+}\r
+\r
+void md5_update( struct md5_context *ctx, uint8 *input, uint32 length )\r
+{\r
+    uint32 left, fill;\r
+\r
+    if( ! length ) return;\r
+\r
+    left = ( ctx->total[0] >> 3 ) & 0x3F;\r
+    fill = 64 - left;\r
+\r
+    ctx->total[0] += length <<  3;\r
+    ctx->total[1] += length >> 29;\r
+\r
+    ctx->total[0] &= 0xFFFFFFFF;\r
+    ctx->total[1] += ctx->total[0] < ( length << 3 );\r
+\r
+    if( left && length >= fill )\r
+    {\r
+        memcpy( (void *) (ctx->buffer + left), (void *) input, fill );\r
+        md5_process( ctx, ctx->buffer );\r
+        length -= fill;\r
+        input  += fill;\r
+        left = 0;\r
+    }\r
+\r
+    while( length >= 64 )\r
+    {\r
+        md5_process( ctx, input );\r
+        length -= 64;\r
+        input  += 64;\r
+    }\r
+\r
+    if( length )\r
+    {\r
+        memcpy( (void *) (ctx->buffer + left), (void *) input, length );\r
+    }\r
+}\r
+\r
+static uint8 md5_padding[64] =\r
+{\r
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\r
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
+};\r
+\r
+void md5_finish( struct md5_context *ctx, uint8 digest[16] )\r
+{\r
+    uint32 last, padn;\r
+    uint8 msglen[8];\r
+\r
+    PUT_UINT32( ctx->total[0], msglen, 0 );\r
+    PUT_UINT32( ctx->total[1], msglen, 4 );\r
+\r
+    last = ( ctx->total[0] >> 3 ) & 0x3F;\r
+    padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );\r
+\r
+    md5_update( ctx, md5_padding, padn );\r
+    md5_update( ctx, msglen, 8 );\r
+\r
+    PUT_UINT32( ctx->state[0], digest,  0 );\r
+    PUT_UINT32( ctx->state[1], digest,  4 );\r
+    PUT_UINT32( ctx->state[2], digest,  8 );\r
+    PUT_UINT32( ctx->state[3], digest, 12 );\r
+}\r
+\r
+\r
+/* Uses a static buffer, so beware of how it's used. */\r
+char *md5_asciistr(uint8 digest[16])\r
+{\r
+ static char str[33];\r
+ static char trans[16]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};\r
+ int x;\r
+\r
+ for(x=0;x<16;x++)\r
+ {\r
+  str[x*2]=trans[digest[x]&0x0F];\r
+  str[x*2+1]=trans[digest[x]>>4];\r
+ }\r
+ return(str);\r
+}\r
diff --git a/md5.h b/md5.h
new file mode 100644 (file)
index 0000000..39c01ec
--- /dev/null
+++ b/md5.h
@@ -0,0 +1,18 @@
+#ifndef _MD5_H\r
+#define _MD5_H\r
+\r
+struct md5_context\r
+{\r
+    uint32 total[2];\r
+    uint32 state[4];\r
+    uint8 buffer[64];\r
+};\r
+\r
+void md5_starts( struct md5_context *ctx );\r
+void md5_update( struct md5_context *ctx, uint8 *input, uint32 length );\r
+void md5_finish( struct md5_context *ctx, uint8 digest[16] );\r
+\r
+/* Uses a static buffer, so beware of how it's used. */\r
+char *md5_asciistr(uint8 digest[16]);\r
+\r
+#endif /* md5.h */\r
index 122a858..32df99a 100644 (file)
--- a/memory.h
+++ b/memory.h
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-/*              Various macros for faster memory stuff 
-               (at least that's the idea) 
+/*              Various macros for faster memory stuff
+               (at least that's the idea)
 */
 
 #define FCEU_dwmemset(d,c,n) {int _x; for(_x=n-4;_x>=0;_x-=4) *(uint32 *)&(d)[_x]=c;}
 
 void *FCEU_malloc(uint32 size);
 void FCEU_free(void *ptr);
+#define FCEU_gmalloc FCEU_malloc
+#define FCEU_gfree FCEU_free
 void FASTAPASS(3) FCEU_memmove(void *d, void *s, uint32 l);
diff --git a/nsf.c b/nsf.c
index 2db647c..9e09cfb 100644 (file)
--- a/nsf.c
+++ b/nsf.c
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "types.h"
-#include "x6502.h"
-#include "fce.h"
-#include "svga.h"
-#include "video.h"
-#include "sound.h"
-#include "ines.h"
-#include "nsf.h"
-#include "nsfbgnew.h"
-#include "general.h"
-#include "memory.h"
-#include "file.h"
-#include "fds.h"
-#include "cart.h"
-#include "input.h"
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-uint8 SongReload;
-uint8 CurrentSong;
-
-static int sinetable[32];
-
-
-static uint8 NSFROM[0x30+6]=
-{
-/* 0x00 */
-
-0x08,0x48,0x8A,0x48,0x98,0x48,          /* Store regs           */
-0xA9,0xFF,
-0x8D,0xF2,0x5F,                                /* NMI has occured      */
-0x68,0xA8,0x68,0xAA,0x68,0x28,
-0x40,     /* Restore regs         */
-
-/* 0x12 */
-
-0xAD,0xF2,0x5F,                                /* See if an NMI occured */
-0xF0,0xFB,                             /* If it hasn't, loop    */
-
-0xA9,0x00,
-0x8D,0xF2,0x5F,                                /* Clear play pending reg*/
-
-
-0xAD,0xF0,0x5F,                         /* See if we need to init. */
-0xF0,0x09,                              /* If 0, go to JMP         */
-
-0xAD,0xF1,0x5F,                         /* Confirm and load A      */
-0xAE,0xF3,0x5F,                         /* Load X with PAL/NTSC byte */
-
-0x20,0x00,0x00,                         /* JSR to init routine     */
-
-0x20,0x00,0x00,                         /* JSR to play routine  */
-
-0x4C,0x12,0x38,                         /* Loop                 */
-
-0xA2,0xFF,0x9A,                                /* Initialize the stack pointer. */
-0x4C,0x12,0x38
-};
-
-static DECLFR(NSFROMRead)
-{
- return (NSFROM-0x3800)[A];
-}
-
-
-
-static uint8 *NSFDATA=0;
-static int NSFMaxBank;
-
-static int NSFSize;
-static uint8 BSon;
-static uint16 PlayAddr;
-static uint16 InitAddr;
-static uint16 LoadAddr;
-
-NSF_HEADER NSFHeader;
-
-void NSFGI(int h)
-{
- switch(h)
- {
- case GI_CLOSE:
-  if(NSFDATA) {free(NSFDATA);NSFDATA=0;}
-  break;
- case GI_POWER: NSF_init();break;
- }
-}
-
-// First 32KB is reserved for sound chip emulation in the iNES mapper code.
-
-#define WRAM (GameMemBlock+32768)
-#define FDSMEM (GameMemBlock+32768)
-
-static INLINE void BANKSET(uint32 A, uint32 bank)
-{
- bank&=NSFMaxBank;
- if(NSFHeader.SoundChip&4)
-  memcpy(FDSMEM+(A-0x6000),NSFDATA+(bank<<12),4096);
- else
-  setprg4(A,bank);
-}
-
-int NSFLoad(int fp)
-{
-  int x;
-
-  FCEU_fseek(fp,0,SEEK_SET);
-  FCEU_fread(&NSFHeader,1,0x80,fp);
-  if (memcmp(NSFHeader.ID,"NESM\x1a",5))
-                  return 0;
-  NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0;
-
-  LoadAddr=NSFHeader.LoadAddressLow;
-  LoadAddr|=NSFHeader.LoadAddressHigh<<8;
-
-  InitAddr=NSFHeader.InitAddressLow;
-  InitAddr|=NSFHeader.InitAddressHigh<<8;
-
-  PlayAddr=NSFHeader.PlayAddressLow;
-  PlayAddr|=NSFHeader.PlayAddressHigh<<8;
-
-  NSFSize=FCEU_fgetsize(fp)-0x80;
-
-  NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096);
-  NSFMaxBank=uppow2(NSFMaxBank);
-
-  if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096)))
-   return 0;
-
-  FCEU_fseek(fp,0x80,SEEK_SET);
-  memset(NSFDATA,0x00,NSFMaxBank*4096);
-  FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp);
-
-  NSFMaxBank--;
-
-  BSon=0;
-  for(x=0;x<8;x++)
-   BSon|=NSFHeader.BankSwitch[x];
-
- FCEUGameInfo.type=GIT_NSF;
- FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_NONE;
-
- for(x=0;;x++)
- {
-  if(NSFROM[x]==0x20)
-  {
-   NSFROM[x+1]=InitAddr&0xFF;
-   NSFROM[x+2]=InitAddr>>8;
-   NSFROM[x+4]=PlayAddr&0xFF;
-   NSFROM[x+5]=PlayAddr>>8;
-   break;
-  }
- }
-
- if(NSFHeader.VideoSystem==0)
-  FCEUGameInfo.vidsys=GIV_NTSC;
- else if(NSFHeader.VideoSystem==1)
-  FCEUGameInfo.vidsys=GIV_PAL;
-
- {
-  double fruit=0;
-  for(x=0;x<32;x++)
-  {
-   double ta,no;
-
-   ta=sin(fruit)*7;
-   ta+=modf(ta,&no);
-   sinetable[x]=ta;
-   fruit+=(double)M_PI*2/32;
-  }
- }
- GameInterface=NSFGI;
-
- puts("NSF Loaded.  File information:\n");
- printf(" Name:       %s\n Artist:     %s\n Copyright:  %s\n\n",NSFHeader.SongName,NSFHeader.Artist,NSFHeader.Copyright);
- if(NSFHeader.SoundChip)
- {
-  static char *tab[6]={"Konami VRCVI","Konami VRCVII","Nintendo FDS","Nintendo MMC5","Namco 106","Sunsoft FME-07"};
-  for(x=0;x<6;x++)
-   if(NSFHeader.SoundChip&(1<<x))
-   {
-    printf(" Expansion hardware:  %s\n",tab[x]);
-    break;
-   }
- }
- if(BSon)
-  puts(" Bank-switched.");
- printf(" Load address:  $%04x\n Init address:  $%04x\n Play address:  $%04x\n",LoadAddr,InitAddr,PlayAddr);
- printf(" %s\n",(NSFHeader.VideoSystem&1)?"PAL":"NTSC");
- printf(" Starting song:  %d / %d\n\n",NSFHeader.StartingSong,NSFHeader.TotalSongs);
- return 1;
-}
-
-static DECLFW(BWRAM)
-{
-                (WRAM-0x6000)[A]=V;
-}
-
-static DECLFW(NSFFDSWrite)
-{
-       (FDSMEM-0x6000)[A]=V;
-}
-
-static DECLFR(NSFFDSRead)
-{
-       return (FDSMEM-0x6000)[A];
-}
-
-static DECLFR(AWRAM)
-{
-       return WRAM[A-0x6000];
-}
-
-void NSF_init(void)
-{
-  if(NSFHeader.SoundChip&4)
-  {
-   memset(FDSMEM,0x00,32768+8192);
-   SetWriteHandler(0x6000,0xDFFF,NSFFDSWrite);
-   SetReadHandler(0x6000,0xFFFF,NSFFDSRead);
-  }
-  else
-  {
-   memset(WRAM,0x00,8192);
-   SetReadHandler(0x6000,0x7FFF,AWRAM);
-   SetWriteHandler(0x6000,0x7FFF,BWRAM);
-   ResetCartMapping();
-   SetupCartPRGMapping(0,NSFDATA,((NSFMaxBank+1)*4096),0);
-   SetReadHandler(0x8000,0xFFFF,CartBR);
-  }
-
-  if(BSon)
-  {
-   int32 x;
-   for(x=0;x<8;x++)
-   {
-    if(NSFHeader.SoundChip&4 && x>=6)
-     BANKSET(0x6000+(x-6)*4096,NSFHeader.BankSwitch[x]);
-    BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]);
-   }
-  }
-  else
-  {
-   int32 x;
-    for(x=(LoadAddr&0x7000);x<0x8000;x+=0x1000)
-     BANKSET(0x8000+x,((x-(LoadAddr&0x7000))>>12));
-  }
-
-  SetWriteHandler(0x2000,0x3fff,0);
-  SetReadHandler(0x2000,0x37ff,0);
-  SetReadHandler(0x3836,0x3FFF,0);
-  SetReadHandler(0x3800,0x3835,NSFROMRead);
-
-  SetWriteHandler(0x4020,0x5fff,NSF_write);
-  SetReadHandler(0x4020,0x5fff,NSF_read);
-
-
-  if(NSFHeader.SoundChip&1) {
-   VRC6_ESI(0);
-  } else if (NSFHeader.SoundChip&2) {
-   VRC7_ESI();
-  } else if (NSFHeader.SoundChip&4) {
-   FDSSoundReset();
-  } else if (NSFHeader.SoundChip&8) {
-   Mapper5_ESI();
-  } else if (NSFHeader.SoundChip&0x10) {
-   Mapper19_ESI();
-  } else if (NSFHeader.SoundChip&0x20) {
-   Mapper69_ESI();
-  }
-  CurrentSong=NSFHeader.StartingSong;
-  SongReload=1;
-}
-
-static uint8 DoUpdateStuff=0;
-DECLFW(NSF_write)
-{
-switch(A)
-{
- case 0x5FF2:if((X.PC&0xF000)==0x3000) DoUpdateStuff=V;break;
-
- case 0x5FF6:
- case 0x5FF7:if(!(NSFHeader.SoundChip&4)) return;
- case 0x5FF8:
- case 0x5FF9:
- case 0x5FFA:
- case 0x5FFB:
- case 0x5FFC:
- case 0x5FFD:
- case 0x5FFE:
- case 0x5FFF:if(!BSon) return;
-             A&=0xF;
-             BANKSET((A*4096),V);
-             X6502_Rebase();
-            break;
-}
-}
-
-DECLFR(NSF_read)
-{
- int x;
-
- if((X.PC&0xF000)==0x3000)
- switch(A)
- {
- case 0x5ff0:x=SongReload;SongReload=0;return x;
- case 0x5ff1:
-            {
-             memset(RAM,0x00,0x800);
-             memset(WRAM,0x00,8192);
-             BWrite[0x4015](0x4015,0xF);
-             for(x=0;x<0x14;x++)
-              {if(x!=0x11) BWrite[0x4015](0x4015,0);}
-             BWrite[0x4015](0x4015,0x0);
-             for(x=0;x<0x14;x++)
-              {if(x!=0x11) BWrite[0x4015](0x4015,0);}
-            BWrite[0x4011](0x4011,0x40);
-             BWrite[0x4015](0x4015,0xF);
-            BWrite[0x4017](0x4017,0x40);
-            if(NSFHeader.SoundChip&4)
-             BWrite[0x4089](0x4089,0x80);
-             if(BSon)
-             {
-              for(x=0;x<8;x++)
-              BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]);
-              X6502_Rebase();
-             }
-             return (CurrentSong-1);
-            }
- case 0x5FF2:return DoUpdateStuff;
- case 0x5FF3:return PAL;
- }
- return 0;
-}
-static int32 *Bufpl;
-void DrawNSF(uint8 *XBuf)
-{
- char snbuf[16];
- static int z=0;
- int x,y;
- uint8 *XBuf2,*tmpb;
-
- XBuf+=8;
- XBuf2=XBuf;
-
- tmpb=NSFBG+8;
- for(y=120;y;y--)
-  {
-   uint8 *offs;
-
-   offs=tmpb+sinetable[((z+y)>>2)&31];
-   memcpy(XBuf2,offs,256);
-   memcpy(XBuf2+(120*272),offs,256);
-
-   XBuf2+=272;
-   tmpb+=272;
-  }
- tmpb=NSFBG+8;
- z=(z+1)&127;
-
- DrawTextTrans(XBuf+10*272+4+(((31-strlen((char *)(NSFHeader.SongName)))<<2)), 272, NSFHeader.SongName, 38);
- DrawTextTrans(XBuf+30*272+4+(((31-strlen((char *)(NSFHeader.Artist)))<<2)), 272, NSFHeader.Artist, 38);
- DrawTextTrans(XBuf+50*272+4+(((31-strlen((char *)(NSFHeader.Copyright)))<<2)), 272, NSFHeader.Copyright, 38);
-
- DrawTextTrans(XBuf+90*272+4+(((31-strlen("Song:"))<<2)), 272, (uint8 *)"Song:", 38);
- sprintf(snbuf,"<%d/%d>",CurrentSong,NSFHeader.TotalSongs);
- DrawTextTrans(XBuf+102*272+4+(((31-strlen(snbuf))<<2)), 272, (uint8 *)snbuf, 38);
-
- GetSoundBuffer(&Bufpl);
-  for(x=0;x<256;x++)
-   XBuf[x+(224-((((Bufpl[x]>>(7)^128)&255)*3)>>3))*272]=38;
-}
-
-void NSFControl(int z)
-{
- if(z==1)
- {
-  if(CurrentSong<NSFHeader.TotalSongs) CurrentSong++;
- }
- else if(z==2)
- {
-  if(CurrentSong>1) CurrentSong--;
- }
- SongReload=0xFF;
-}
+/* 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
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <math.h>\r
+\r
+#include "types.h"\r
+#include "x6502.h"\r
+#include "fce.h"\r
+#include "video.h"\r
+#include "sound.h"\r
+#include "nsf.h"\r
+#include "general.h"\r
+#include "memory.h"\r
+#include "file.h"\r
+#include "fds.h"\r
+#include "cart.h"\r
+#include "input.h"\r
+\r
+#include "svga.h"\r
+\r
+#ifndef M_PI\r
+#define M_PI 3.14159265358979323846\r
+#endif\r
+\r
+static uint8 SongReload;\r
+static int CurrentSong;\r
+\r
+static DECLFW(NSF_write);\r
+static DECLFR(NSF_read);\r
+\r
+static int vismode=1;\r
+\r
+static uint8 NSFROM[0x30+6]=\r
+{\r
+/* 0x00 - NMI */\r
+0x8D,0xF4,0x3F,       /* Stop play routine NMIs. */\r
+0xA2,0xFF,0x9A,       /* Initialize the stack pointer. */\r
+0xAD,0xF0,0x3F,       /* See if we need to init. */\r
+0xF0,0x09,            /* If 0, go to play routine playing. */\r
+\r
+0xAD,0xF1,0x3F,       /* Confirm and load A      */\r
+0xAE,0xF3,0x3F,       /* Load X with PAL/NTSC byte */\r
+\r
+0x20,0x00,0x00,       /* JSR to init routine     */\r
+\r
+0xA9,0x00,\r
+0xAA,\r
+0xA8,\r
+0x20,0x00,0x00,       /* JSR to play routine  */\r
+0x8D,0xF5,0x3F,        /* Start play routine NMIs. */\r
+0x90,0xFE,             /* Loopie time. */\r
+\r
+/* 0x20 */\r
+0x8D,0xF3,0x3F,        /* Init init NMIs */\r
+0x18,\r
+0x90,0xFE        /* Loopie time. */\r
+};\r
+\r
+static DECLFR(NSFROMRead)\r
+{\r
+ return (NSFROM-0x3800)[A];\r
+}\r
+\r
+static int doreset=0;\r
+static int NSFNMIFlags;\r
+static uint8 *NSFDATA=0;\r
+static int NSFMaxBank;\r
+\r
+static int NSFSize;\r
+static uint8 BSon;\r
+static uint16 PlayAddr;\r
+static uint16 InitAddr;\r
+static uint16 LoadAddr;\r
+\r
+static NSF_HEADER NSFHeader;\r
+\r
+void NSFMMC5_Close(void);\r
+static uint8 *ExWRAM=0;\r
+\r
+void NSFGI(int h)\r
+{\r
+ switch(h)\r
+ {\r
+ case GI_CLOSE:\r
+  if(NSFDATA) {free(NSFDATA);NSFDATA=0;}\r
+  if(ExWRAM) {free(ExWRAM);ExWRAM=0;}\r
+  if(NSFHeader.SoundChip&1) {\r
+//   NSFVRC6_Init();\r
+  } else if(NSFHeader.SoundChip&2) {\r
+//   NSFVRC7_Init();\r
+  } else if(NSFHeader.SoundChip&4) {\r
+//   FDSSoundReset();\r
+  } else if(NSFHeader.SoundChip&8) {\r
+   NSFMMC5_Close();\r
+  } else if(NSFHeader.SoundChip&0x10) {\r
+//   NSFN106_Init();\r
+  } else if(NSFHeader.SoundChip&0x20) {\r
+//   NSFAY_Init();\r
+  }\r
+  break;\r
+ case GI_RESETM2:\r
+ case GI_POWER: NSF_init();break;\r
+ }\r
+}\r
+\r
+// First 32KB is reserved for sound chip emulation in the iNES mapper code.\r
+\r
+static INLINE void BANKSET(uint32 A, uint32 bank)\r
+{\r
+ bank&=NSFMaxBank;\r
+ if(NSFHeader.SoundChip&4)\r
+  memcpy(ExWRAM+(A-0x6000),NSFDATA+(bank<<12),4096);\r
+ else\r
+  setprg4(A,bank);\r
+}\r
+\r
+int NSFLoad(int fp)\r
+{\r
+  int x;\r
+\r
+  FCEU_fseek(fp,0,SEEK_SET);\r
+  FCEU_fread(&NSFHeader,1,0x80,fp);\r
+  if(memcmp(NSFHeader.ID,"NESM\x1a",5))\r
+                  return 0;\r
+  NSFHeader.SongName[31]=NSFHeader.Artist[31]=NSFHeader.Copyright[31]=0;\r
+\r
+  LoadAddr=NSFHeader.LoadAddressLow;\r
+  LoadAddr|=NSFHeader.LoadAddressHigh<<8;\r
+\r
+  if(LoadAddr<0x6000)\r
+  {\r
+   FCEUD_PrintError("Invalid load address.");\r
+   return(0);\r
+  }\r
+  InitAddr=NSFHeader.InitAddressLow;\r
+  InitAddr|=NSFHeader.InitAddressHigh<<8;\r
+\r
+  PlayAddr=NSFHeader.PlayAddressLow;\r
+  PlayAddr|=NSFHeader.PlayAddressHigh<<8;\r
+\r
+  NSFSize=FCEU_fgetsize(fp)-0x80;\r
+\r
+  NSFMaxBank=((NSFSize+(LoadAddr&0xfff)+4095)/4096);\r
+  NSFMaxBank=uppow2(NSFMaxBank);\r
+\r
+  if(!(NSFDATA=(uint8 *)FCEU_malloc(NSFMaxBank*4096)))\r
+   return 0;\r
+\r
+  FCEU_fseek(fp,0x80,SEEK_SET);\r
+  memset(NSFDATA,0x00,NSFMaxBank*4096);\r
+  FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp);\r
+\r
+  NSFMaxBank--;\r
+\r
+  BSon=0;\r
+  for(x=0;x<8;x++)\r
+   BSon|=NSFHeader.BankSwitch[x];\r
+\r
+ FCEUGameInfo.type=GIT_NSF;\r
+ FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD;\r
+ FCEUGameInfo.cspecial=SIS_NSF;\r
+\r
+ for(x=0;;x++)\r
+ {\r
+  if(NSFROM[x]==0x20)\r
+  {\r
+   NSFROM[x+1]=InitAddr&0xFF;\r
+   NSFROM[x+2]=InitAddr>>8;\r
+   NSFROM[x+8]=PlayAddr&0xFF;\r
+   NSFROM[x+9]=PlayAddr>>8;\r
+   break;\r
+  }\r
+ }\r
+\r
+ if(NSFHeader.VideoSystem==0)\r
+  FCEUGameInfo.vidsys=GIV_NTSC;\r
+ else if(NSFHeader.VideoSystem==1)\r
+  FCEUGameInfo.vidsys=GIV_PAL;\r
+\r
+ GameInterface=NSFGI;\r
+\r
+ FCEU_printf("NSF Loaded.  File information:\n\n");\r
+ FCEU_printf(" Name:       %s\n Artist:     %s\n Copyright:  %s\n\n",NSFHeader.SongName,NSFHeader.Artist,NSFHeader.Copyright);\r
+ if(NSFHeader.SoundChip)\r
+ {\r
+  static char *tab[6]={"Konami VRCVI","Konami VRCVII","Nintendo FDS","Nintendo MMC5","Namco 106","Sunsoft FME-07"};\r
+\r
+  for(x=0;x<6;x++)\r
+   if(NSFHeader.SoundChip&(1<<x))\r
+   {\r
+    FCEU_printf(" Expansion hardware:  %s\n",tab[x]);\r
+    NSFHeader.SoundChip=1<<x;  /* Prevent confusing weirdness if more than one bit is set. */\r
+    break;\r
+   }\r
+ }\r
+ if(BSon)\r
+  FCEU_printf(" Bank-switched.\n");\r
+ FCEU_printf(" Load address:  $%04x\n Init address:  $%04x\n Play address:  $%04x\n",LoadAddr,InitAddr,PlayAddr);\r
+ FCEU_printf(" %s\n",(NSFHeader.VideoSystem&1)?"PAL":"NTSC");\r
+ FCEU_printf(" Starting song:  %d / %d\n\n",NSFHeader.StartingSong,NSFHeader.TotalSongs);\r
+\r
+ if(NSFHeader.SoundChip&4)\r
+  ExWRAM=FCEU_gmalloc(32768+8192);\r
+ else\r
+  ExWRAM=FCEU_gmalloc(8192);\r
+\r
+ FCEUI_SetVidSystem(NSFHeader.VideoSystem);\r
+\r
+ return 1;\r
+}\r
+\r
+static DECLFR(NSFVectorRead)\r
+{\r
+ if(((NSFNMIFlags&1) && SongReload) || (NSFNMIFlags&2) || doreset)\r
+ {\r
+  if(A==0xFFFA) return(0x00);\r
+  else if(A==0xFFFB) return(0x38);\r
+  else if(A==0xFFFC) return(0x20);\r
+  else if(A==0xFFFD) {doreset=0;return(0x38);}\r
+  return(X.DB);\r
+ }\r
+ else\r
+  return(CartBR(A));\r
+}\r
+\r
+void NSFVRC6_Init(void);\r
+void NSFVRC7_Init(void);\r
+void NSFMMC5_Init(void);\r
+void NSFN106_Init(void);\r
+void NSFAY_Init(void);\r
+\r
+void NSF_init(void)\r
+{\r
+  doreset=1;\r
+\r
+  ResetCartMapping();\r
+  if(NSFHeader.SoundChip&4)\r
+  {\r
+   SetupCartPRGMapping(0,ExWRAM,32768+8192,1);\r
+   setprg32(0x6000,0);\r
+   setprg8(0xE000,4);\r
+   memset(ExWRAM,0x00,32768+8192);\r
+   SetWriteHandler(0x6000,0xDFFF,CartBW);\r
+   SetReadHandler(0x6000,0xFFFF,CartBR);\r
+  }\r
+  else\r
+  {\r
+   memset(ExWRAM,0x00,8192);\r
+   SetReadHandler(0x6000,0x7FFF,CartBR);\r
+   SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+   SetupCartPRGMapping(0,NSFDATA,((NSFMaxBank+1)*4096),0);\r
+   SetupCartPRGMapping(1,ExWRAM,8192,1);\r
+   setprg8r(1,0x6000,0);\r
+   SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  }\r
+\r
+  if(BSon)\r
+  {\r
+   int32 x;\r
+   for(x=0;x<8;x++)\r
+   {\r
+    if(NSFHeader.SoundChip&4 && x>=6)\r
+     BANKSET(0x6000+(x-6)*4096,NSFHeader.BankSwitch[x]);\r
+    BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]);\r
+   }\r
+  }\r
+  else\r
+  {\r
+   int32 x;\r
+   for(x=(LoadAddr&0xF000);x<0x10000;x+=0x1000)\r
+    BANKSET(x,((x-(LoadAddr&0x7000))>>12));\r
+  }\r
+\r
+  SetReadHandler(0xFFFA,0xFFFD,NSFVectorRead);\r
+\r
+  SetWriteHandler(0x2000,0x3fff,0);\r
+  SetReadHandler(0x2000,0x37ff,0);\r
+  SetReadHandler(0x3836,0x3FFF,0);\r
+  SetReadHandler(0x3800,0x3835,NSFROMRead);\r
+\r
+  SetWriteHandler(0x5ff6,0x5fff,NSF_write);\r
+\r
+  SetWriteHandler(0x3ff0,0x3fff,NSF_write);\r
+  SetReadHandler(0x3ff0,0x3fff,NSF_read);\r
+\r
+\r
+  if(NSFHeader.SoundChip&1) {\r
+   NSFVRC6_Init();\r
+  } else if(NSFHeader.SoundChip&2) {\r
+   NSFVRC7_Init();\r
+  } else if(NSFHeader.SoundChip&4) {\r
+   FDSSoundReset();\r
+  } else if(NSFHeader.SoundChip&8) {\r
+   NSFMMC5_Init();\r
+  } else if(NSFHeader.SoundChip&0x10) {\r
+   NSFN106_Init();\r
+  } else if(NSFHeader.SoundChip&0x20) {\r
+   NSFAY_Init();\r
+  }\r
+  CurrentSong=NSFHeader.StartingSong;\r
+  SongReload=0xFF;\r
+  NSFNMIFlags=0;\r
+}\r
+\r
+static DECLFW(NSF_write)\r
+{\r
+ switch(A)\r
+ {\r
+  case 0x3FF3:NSFNMIFlags|=1;break;\r
+  case 0x3FF4:NSFNMIFlags&=~2;break;\r
+  case 0x3FF5:NSFNMIFlags|=2;break;\r
+\r
+  case 0x5FF6:\r
+  case 0x5FF7:if(!(NSFHeader.SoundChip&4)) return;\r
+  case 0x5FF8:\r
+  case 0x5FF9:\r
+  case 0x5FFA:\r
+  case 0x5FFB:\r
+  case 0x5FFC:\r
+  case 0x5FFD:\r
+  case 0x5FFE:\r
+  case 0x5FFF:if(!BSon) return;\r
+              A&=0xF;\r
+              BANKSET((A*4096),V);\r
+             break;\r
+ }\r
+}\r
+\r
+static DECLFR(NSF_read)\r
+{\r
+ int x;\r
+\r
+ switch(A)\r
+ {\r
+ case 0x3ff0:x=SongReload;\r
+            if(!fceuindbg)\r
+             SongReload=0;\r
+            return x;\r
+ case 0x3ff1:\r
+           if(!fceuindbg)\r
+           {\r
+             memset(RAM,0x00,0x800);\r
+\r
+             BWrite[0x4015](0x4015,0x0);\r
+             for(x=0;x<0x14;x++)\r
+              BWrite[0x4000+x](0x4000+x,0);\r
+             BWrite[0x4015](0x4015,0xF);\r
+\r
+            if(NSFHeader.SoundChip&4)\r
+            {\r
+        BWrite[0x4017](0x4017,0xC0);  /* FDS BIOS writes $C0 */\r
+             BWrite[0x4089](0x4089,0x80);\r
+             BWrite[0x408A](0x408A,0xE8);\r
+            }\r
+            else\r
+            {\r
+             memset(ExWRAM,0x00,8192);\r
+             BWrite[0x4017](0x4017,0xC0);\r
+              BWrite[0x4017](0x4017,0xC0);\r
+              BWrite[0x4017](0x4017,0x40);\r
+            }\r
+\r
+             if(BSon)\r
+             {\r
+              for(x=0;x<8;x++)\r
+              BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]);\r
+             }\r
+             return (CurrentSong-1);\r
+            }\r
+ case 0x3FF3:return PAL;\r
+ }\r
+ return 0;\r
+}\r
+\r
+uint8 FCEU_GetJoyJoy(void);\r
+\r
+static int special=0;\r
+\r
+void DrawNSF(uint8 *XBuf)\r
+{\r
+ char snbuf[16];\r
+ int x;\r
+\r
+ if(vismode==0) return;\r
+\r
+ memset(XBuf,0,256*240);\r
+\r
+\r
+ {\r
+  int32 *Bufpl;\r
+  int32 mul=0;\r
+\r
+  int l;\r
+  l=GetSoundBuffer(&Bufpl);\r
+\r
+  if(special==0)\r
+  {\r
+   if(FSettings.SoundVolume)\r
+    mul=8192*240/(16384*FSettings.SoundVolume/50);\r
+   for(x=0;x<256;x++)\r
+   {\r
+    uint32 y;\r
+    y=142+((Bufpl[(x*l)>>8]*mul)>>14);\r
+    if(y<240)\r
+     XBuf[x+y*256]=3;\r
+   }\r
+  }\r
+  else if(special==1)\r
+  {\r
+   if(FSettings.SoundVolume)\r
+    mul=8192*240/(8192*FSettings.SoundVolume/50);\r
+   for(x=0;x<256;x++)\r
+   {\r
+    double r;\r
+    uint32 xp,yp;\r
+\r
+    r=(Bufpl[(x*l)>>8]*mul)>>14;\r
+    xp=128+r*cos(x*M_PI*2/256);\r
+    yp=120+r*sin(x*M_PI*2/256);\r
+    xp&=255;\r
+    yp%=240;\r
+    XBuf[xp+yp*256]=3;\r
+   }\r
+  }\r
+  else if(special==2)\r
+  {\r
+   static double theta=0;\r
+   if(FSettings.SoundVolume)\r
+    mul=8192*240/(16384*FSettings.SoundVolume/50);\r
+   for(x=0;x<128;x++)\r
+   {\r
+    double xc,yc;\r
+    double r,t;\r
+    uint32 m,n;\r
+\r
+    xc=(double)128-x;\r
+    yc=0-((double)( ((Bufpl[(x*l)>>8]) *mul)>>14));\r
+    t=M_PI+atan(yc/xc);\r
+    r=sqrt(xc*xc+yc*yc);\r
+\r
+    t+=theta;\r
+    m=128+r*cos(t);\r
+    n=120+r*sin(t);\r
+\r
+    if(m<256 && n<240)\r
+     XBuf[m+n*256]=3;\r
+\r
+   }\r
+   for(x=128;x<256;x++)\r
+   {\r
+    double xc,yc;\r
+    double r,t;\r
+    uint32 m,n;\r
+\r
+    xc=(double)x-128;\r
+    yc=(double)((Bufpl[(x*l)>>8]*mul)>>14);\r
+    t=atan(yc/xc);\r
+    r=sqrt(xc*xc+yc*yc);\r
+\r
+    t+=theta;\r
+    m=128+r*cos(t);\r
+    n=120+r*sin(t);\r
+\r
+    if(m<256 && n<240)\r
+     XBuf[m+n*256]=3;\r
+\r
+   }\r
+   theta+=(double)M_PI/256;\r
+  }\r
+ }\r
+\r
+ DrawTextTrans(XBuf+10*256+4+(((31-strlen((char*)NSFHeader.SongName))<<2)), 256, NSFHeader.SongName, 6);\r
+ DrawTextTrans(XBuf+26*256+4+(((31-strlen((char*)NSFHeader.Artist))<<2)), 256,NSFHeader.Artist, 6);\r
+ DrawTextTrans(XBuf+42*256+4+(((31-strlen((char*)NSFHeader.Copyright))<<2)), 256,NSFHeader.Copyright, 6);\r
+\r
+ DrawTextTrans(XBuf+70*256+4+(((31-strlen("Song:"))<<2)), 256, (uint8*)"Song:", 6);\r
+ sprintf(snbuf,"<%d/%d>",CurrentSong,NSFHeader.TotalSongs);\r
+ DrawTextTrans(XBuf+82*256+4+(((31-strlen(snbuf))<<2)), 256, (uint8*)snbuf, 6);\r
+\r
+ {\r
+  static uint8 last=0;\r
+  uint8 tmp;\r
+  tmp=FCEU_GetJoyJoy();\r
+  if((tmp&JOY_RIGHT) && !(last&JOY_RIGHT))\r
+  {\r
+   if(CurrentSong<NSFHeader.TotalSongs)\r
+   {\r
+    CurrentSong++;\r
+    SongReload=0xFF;\r
+   }\r
+  }\r
+  else if((tmp&JOY_LEFT) && !(last&JOY_LEFT))\r
+  {\r
+   if(CurrentSong>1)\r
+   {\r
+    CurrentSong--;\r
+    SongReload=0xFF;\r
+   }\r
+  }\r
+  else if((tmp&JOY_UP) && !(last&JOY_UP))\r
+  {\r
+   CurrentSong+=10;\r
+   if(CurrentSong>NSFHeader.TotalSongs) CurrentSong=NSFHeader.TotalSongs;\r
+   SongReload=0xFF;\r
+  }\r
+  else if((tmp&JOY_DOWN) && !(last&JOY_DOWN))\r
+  {\r
+   CurrentSong-=10;\r
+   if(CurrentSong<1) CurrentSong=1;\r
+   SongReload=0xFF;\r
+  }\r
+  else if((tmp&JOY_START) && !(last&JOY_START))\r
+   SongReload=0xFF;\r
+  else if((tmp&JOY_A) && !(last&JOY_A))\r
+  {\r
+   special=(special+1)%3;\r
+  }\r
+  last=tmp;\r
+ }\r
+}\r
+\r
+void DoNSFFrame(void)\r
+{\r
+ if(((NSFNMIFlags&1) && SongReload) || (NSFNMIFlags&2))\r
+  TriggerNMI();\r
+}\r
+\r
+void FCEUI_NSFSetVis(int mode)\r
+{\r
+ vismode=mode;\r
+}\r
+\r
+int FCEUI_NSFChange(int amount)\r
+{\r
+   CurrentSong+=amount;\r
+   if(CurrentSong<1) CurrentSong=1;\r
+   else if(CurrentSong>NSFHeader.TotalSongs) CurrentSong=NSFHeader.TotalSongs;\r
+   SongReload=0xFF;\r
+\r
+   return(CurrentSong);\r
+}\r
+\r
+/* Returns total songs */\r
+int FCEUI_NSFGetInfo(uint8 *name, uint8 *artist, uint8 *copyright, int maxlen)\r
+{\r
+ strncpy((char*)name,(char*)NSFHeader.SongName,maxlen);\r
+ strncpy((char*)artist,(char*)NSFHeader.Artist,maxlen);\r
+ strncpy((char*)copyright,(char*)NSFHeader.Copyright,maxlen);\r
+ return(NSFHeader.TotalSongs);\r
+}\r
diff --git a/nsf.h b/nsf.h
index 3333201..c7bbb19 100644 (file)
--- a/nsf.h
+++ b/nsf.h
@@ -1,53 +1,47 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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
- */
-
-typedef struct {
-                char ID[5]; /*NESM^Z*/
-                uint8 Version;
-                uint8 TotalSongs;
-                uint8 StartingSong;
-                uint8 LoadAddressLow;
-                uint8 LoadAddressHigh;
-                uint8 InitAddressLow;
-                uint8 InitAddressHigh;
-                uint8 PlayAddressLow;
-                uint8 PlayAddressHigh;
-                uint8 SongName[32];
-                uint8 Artist[32];
-                uint8 Copyright[32];
-                uint8 NTSCspeed[2];              // Unused
-                uint8 BankSwitch[8];
-                uint8 PALspeed[2];               // Unused
-                uint8 VideoSystem;
-                uint8 SoundChip;
-                uint8 Expansion[4];
-                uint8 reserve[8];
-        } NSF_HEADER;
-int NSFLoad(int fp);
-DECLFW(NSF_write);
-DECLFR(NSF_read);
-void NSF_init(void);
-extern uint8 CurrentSong;
-extern uint8 SongReload;
-void DrawNSF(uint8 *XBuf);
-void NSFControl(int z);
-extern NSF_HEADER NSFHeader;
-void NSFDealloc(void);
-void NSFDodo(void);
+/* 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
+typedef struct {\r
+                char ID[5]; /*NESM^Z*/\r
+                uint8 Version;\r
+                uint8 TotalSongs;\r
+                uint8 StartingSong;\r
+                uint8 LoadAddressLow;\r
+                uint8 LoadAddressHigh;\r
+                uint8 InitAddressLow;\r
+                uint8 InitAddressHigh;\r
+                uint8 PlayAddressLow;\r
+                uint8 PlayAddressHigh;\r
+                uint8 SongName[32];\r
+                uint8 Artist[32];\r
+                uint8 Copyright[32];\r
+                uint8 NTSCspeed[2];        // Unused\r
+                uint8 BankSwitch[8];\r
+                uint8 PALspeed[2];         // Unused\r
+                uint8 VideoSystem;\r
+                uint8 SoundChip;\r
+                uint8 Expansion[4];\r
+                uint8 reserve[8];\r
+        } NSF_HEADER;\r
+void NSF_init(void);\r
+void DrawNSF(uint8 *XBuf);\r
+void NSFDealloc(void);\r
+void NSFDodo(void);\r
+void DoNSFFrame(void);\r
diff --git a/sound.c b/sound.c
index 0951e6f..9fb3216 100644 (file)
--- a/sound.c
+++ b/sound.c
@@ -83,6 +83,7 @@ static const uint32 SNoiseFreqTable[0x10]=
 static uint32 NoiseFreqTable[0x10];
 
 int64 nesincsizeLL;
+int64 nesincsize;
 
 static const uint8 NTSCPCMTable[0x10]=
 {
@@ -330,15 +331,6 @@ static DECLFW(Write_PSG)
             X6502_IRQEnd(FCEU_IQDPCM);
           }
            break;
- case 0x17:
-          V&=0xC0;
-           fcnt=0;
-           if(V&0x80)
-            FrameSoundUpdate();
-           fhcnt=fhinc;
-           X6502_IRQEnd(FCEU_IQFCOUNT);
-          SIRQStat&=~0x40;
-           break;
  }
  PSG[A]=V;
 }
@@ -851,12 +843,25 @@ static void RDoNoise(void)
    }
 }
 
+DECLFW(Write_IRQFM)
+{
+ V=(V&0xC0)>>6;
+ fcnt=0;
+ if(V&0x2)
+  FrameSoundUpdate();
+ fcnt=1;
+ fhcnt=fhinc;
+ X6502_IRQEnd(FCEU_IQFCOUNT);
+ SIRQStat&=~0x40;
+// IRQFrameMode=V;
+}
+
 void SetNESSoundMap(void)
 {
   SetWriteHandler(0x4000,0x4013,Write_PSG);
   SetWriteHandler(0x4011,0x4011,Write0x11);
   SetWriteHandler(0x4015,0x4015,Write_PSG);
-  SetWriteHandler(0x4017,0x4017,Write_PSG);
+  SetWriteHandler(0x4017,0x4017,Write_IRQFM);
   SetReadHandler(0x4015,0x4015,Read_PSG);
 }
 
@@ -917,6 +922,7 @@ static void FilterSound(uint32 *in, int32 *out, int16 *outMono, int count)
 
 
 
+static int32 inbuf=0;
 int FlushEmulateSound(void)
 {
   int x;
@@ -962,12 +968,15 @@ int FlushEmulateSound(void)
   for(x=0;x<5;x++)
    ChannelBC[x]=end&0xF;
   soundtsoffs=(soundtsinc*(end&0xF))>>16;
-  return(end>>4);
+  end>>=4;
+  inbuf=end;
+  return(end);
 }
 
-void GetSoundBuffer(int32 **W)
+int GetSoundBuffer(int32 **W)
 {
  *W=WaveNSF;
+ return inbuf;
 }
 
 void PowerSound(void)
@@ -1023,7 +1032,8 @@ void SetSoundVariables(void)
   if(GameExpSound.RChange)
    GameExpSound.RChange();
 
-  nesincsizeLL=(int64)((int64)562949953421312*(long double)(PAL?PAL_CPU:NTSC_CPU)/(FSettings.SndRate OVERSAMPLE));
+  nesincsizeLL=(int64)((int64)562949953421312*(double)(PAL?PAL_CPU:NTSC_CPU)/(FSettings.SndRate OVERSAMPLE));
+  nesincsize=(int64)(((int64)1<<17)*(double)(PAL?PAL_CPU:NTSC_CPU)/(FSettings.SndRate * 16));
   PSG_base=(uint32)(PAL?(long double)PAL_CPU/16:(long double)NTSC_CPU/16);
 
   for(x=0;x<0x10;x++)
diff --git a/sound.h b/sound.h
index 02c6a68..9cffd4c 100644 (file)
--- a/sound.h
+++ b/sound.h
@@ -27,11 +27,17 @@ typedef struct {
           void (*Fill)(int Count);
           void (*RChange)(void);
           void (*Kill)(void);
+
+          // from 0.98.15, currently unused
+           void (*NeoFill)(int32 *Wave, int Count);
+          void (*HiFill)(void);
+          void (*HiSync)(int32 ts);
 } EXPSOUND;
 
 extern EXPSOUND GameExpSound;
 
 extern int64 nesincsizeLL;
+extern int64 nesincsize;
 extern uint8 PSG[];
 extern uint32 PSG_base;
 extern int32 PCMIRQCount;
@@ -62,7 +68,9 @@ extern uint8 fcnt;
 extern int32 fhcnt;
 extern int32 fhinc;
 
-void GetSoundBuffer(int32 **W);
+uint8 FCEU_GetJoyJoy(void);
+
+int GetSoundBuffer(int32 **W);
 int FlushEmulateSound(void);
 extern uint32 Wave[2048];
 extern int32 WaveFinal[2048];
diff --git a/state.c b/state.c
index e306eda..c50223d 100644 (file)
--- a/state.c
+++ b/state.c
 #include "memory.h"
 #include "ppu.h"
 
-static SFORMAT SFMDATA[64];
+static void (*SPreSave)(void) = 0;
+static void (*SPostSave)(void) = 0;
+
+#define SFMDATA_SIZE (64)
+static SFORMAT SFMDATA[SFMDATA_SIZE];
 static int SFEXINDEX;
 static int stateversion;
 
@@ -313,7 +317,11 @@ void SaveState(void)
          totalsize+=WriteStateChunk(st,3,FCEUPPU_STATEINFO);
          totalsize+=WriteStateChunk(st,4,FCEUCTRL_STATEINFO);
          totalsize+=WriteStateChunk(st,5,SFSND);
+
+
+         if(SPreSave) SPreSave();
          totalsize+=WriteStateChunk(st,0x10,SFMDATA);
+         if(SPostSave) SPostSave();
 
          fseek(st,4,SEEK_SET);
          write32(totalsize,st);
@@ -418,27 +426,48 @@ void SaveStateRefresh(void)
  SaveStateStatus[0]=-1;
 }
 
-void ResetExState(void)
+void ResetExState(void (*PreSave)(void), void (*PostSave)(void))
 {
  int x;
  for(x=0;x<SFEXINDEX;x++)
-  free(SFMDATA[x].desc);
+ {
+  if(SFMDATA[x].desc)
+   free(SFMDATA[x].desc);
+ }
+ SPreSave = PreSave;
+ SPostSave = PostSave;
  SFEXINDEX=0;
 }
 
+
 void AddExState(void *v, uint32 s, int type, char *desc)
 {
- SFMDATA[SFEXINDEX].desc=FCEU_malloc(5);
- if(SFMDATA[SFEXINDEX].desc)
+ if(desc)
  {
+  SFMDATA[SFEXINDEX].desc=(char *)FCEU_malloc(5);
   strcpy(SFMDATA[SFEXINDEX].desc,desc);
-  SFMDATA[SFEXINDEX].v=v;
-  SFMDATA[SFEXINDEX].s=s;
-  if(type) SFMDATA[SFEXINDEX].s|=RLSB;
-  if(SFEXINDEX<63) SFEXINDEX++;
  }
+ else
+//  SFMDATA[SFEXINDEX].desc=0;
+  return; // do not support recursive save structures
+ SFMDATA[SFEXINDEX].v=v;
+ SFMDATA[SFEXINDEX].s=s;
+ if(type) SFMDATA[SFEXINDEX].s|=RLSB;
+ if(SFEXINDEX<SFMDATA_SIZE-1)
+        SFEXINDEX++;
+ else
+ {
+        static int once=1;
+        if(once)
+        {
+                once=0;
+                FCEU_PrintError("Error in AddExState: SFEXINDEX overflow.\nSomebody made SFMDATA_SIZE too small.");
+        }
+ }
+ SFMDATA[SFEXINDEX].v=0;               // End marker.
 }
 
+
 /* Old state loading code follows */
 
 uint8 *StateBuffer;
diff --git a/state.h b/state.h
index 3d94900..8ccdaf9 100644 (file)
--- a/state.h
+++ b/state.h
@@ -37,8 +37,9 @@ typedef struct {
           char *desc;
 } SFORMAT;
 
-void ResetExState(void);
+void ResetExState(void (*PreSave)(void), void (*PostSave)(void));
 void AddExState(void *v, uint32 s, int type, char *desc);
 
 #define RLSB           0x80000000
+#define FCEUSTATE_RLSB RLSB
 
diff --git a/svga.c b/svga.c
index 76d21f1..1133a28 100644 (file)
--- a/svga.c
+++ b/svga.c
@@ -139,8 +139,8 @@ static uint8 StateShow=0;
 uint8 Exit=0;
 
 uint8 DIPS=0;
-uint8 vsdip=0;
-int coinon=0;
+//uint8 vsdip=0;
+//int coinon=0;
 
 uint8 pale=0;
 uint8 CommandQueue=0;
@@ -249,11 +249,11 @@ void DriverInterface(int w, void *d)
   case DES_FDSINSERT:if(netplay!=2) CommandQueue=2;break;
   case DES_FDSEJECT:if(netplay!=2) CommandQueue=3;break;
   case DES_FDSSELECT:if(netplay!=2) CommandQueue=1;break;
-
+/*
   case DES_NSFINC:NSFControl(1);break;
   case DES_NSFDEC:NSFControl(2);break;
   case DES_NSFRES:NSFControl(0);break;
-
+*/
   case DES_VSUNIDIPSET:CommandQueue=10+(int)d;break;
   case DES_VSUNITOGGLEDIPVIEW:CommandQueue=10;break;
   case DES_VSUNICOIN:CommandQueue=19;break;
@@ -538,6 +538,7 @@ void WritePalette(void)
     }
 }
 
+#if 0
 void FlushCommandQueue(void)
 {
   if(!netplay && CommandQueue) {DoCommand(CommandQueue);CommandQueue=0;}
@@ -569,3 +570,5 @@ void DoCommand(uint8 c)
   case 50: case 51:StateShow=180;CurrentState=c-42;CheckStates();break;
  }
 }
+#endif
+
diff --git a/svga.h b/svga.h
index cebd555..35f4b43 100644 (file)
--- a/svga.h
+++ b/svga.h
@@ -39,7 +39,7 @@ typedef struct {
           int FirstSLine;
           int LastSLine;
 
-          /* Driver code(user)-specified first and last rendered scanlines. 
+          /* Driver code(user)-specified first and last rendered scanlines.
              Usr*SLine[0] is for NTSC, Usr*SLine[1] is for PAL.
            */
           int UsrFirstSLine[2];
@@ -52,6 +52,7 @@ extern FCEUS FSettings;
 
 void FCEU_PrintError(char *format, ...);
 void FCEU_DispMessage(char *format, ...);
+#define FCEU_printf printf
 
 void SetNESDeemph(uint8 d, int force);
 void DrawTextTrans(uint8 *dest, uint32 width, uint8 *textmsg, uint8 fgcolor);
diff --git a/unif.c b/unif.c
index bcd2d3d..e5bb8e1 100644 (file)
--- a/unif.c
+++ b/unif.c
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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
- */
-
-/* TODO:  Battery backup file saving, mirror force */
-/* **INCOMPLETE**                                 */
-/* Override stuff: CHR RAM instead of CHR ROM,
-                  mirroring.
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef GP2X
-#include <unistd.h>
-#endif
-
-
-#include       "types.h"
-#include        "fce.h"
-#include        "unif.h"
-#include        "version.h"
-#include       "svga.h"
-#include        "general.h"
-#include       "state.h"
-#include       "endian.h"
-#include       "file.h"
-#include       "cart.h"
-#include       "memory.h"
-#include       "input.h"
-
-typedef struct {
-           char ID[4];
-           uint32 info;
-} UNIF_HEADER;
-
-typedef struct {
-           char *name;
-           void (*init)(void);
-          int flags;
-} BMAPPING;
-
-typedef struct {
-           char *name;
-           int (*init)(int fp);
-} BFMAPPING;
-
-void (*BoardClose)(void);
-void (*BoardPower)(void);
-void (*BoardReset)(void);
-
-static int vramo;
-static int mirrortodo;
-int UNIFbattery;
-static char *boardname;
-static char *sboardname;
-char *UNIFchrrama;
-
-static UNIF_HEADER unhead;
-static UNIF_HEADER uchead;
-
-
-static uint8 *malloced[32];
-
-static int FixRomSize(uint32 size, uint32 minimum)
-{
-  int x=1;
-
-  if(size<minimum)
-   return minimum;
-  while(x<size)
-   x<<=1;
-  return x;
-}
-
-static void FreeUNIF(void)
-{
- int x;
- if(UNIFchrrama)
-  {free(UNIFchrrama);UNIFchrrama=0;}
- if(boardname)
-  {free(boardname);boardname=0;}
- for(x=0;x<32;x++)
- {
-  if(malloced[x])
-   {free(malloced[x]);malloced[x]=0;}
- }
-}
-
-static void ResetUNIF(void)
-{
- int x;
- for(x=0;x<32;x++)
-  malloced[x]=0;
- vramo=0;
- UNIFbattery=0;
- boardname=0;
- mirrortodo=0;
- BoardReset=BoardPower=BoardClose=0;
- UNIFchrrama=0;
-}
-
-static uint8 exntar[2048];
-
-static void MooMirroring(void)
-{
- if(mirrortodo<0x4)
-  SetupCartMirroring(mirrortodo,1,0);
- else if(mirrortodo==0x4)
- {
-  SetupCartMirroring(4,1,exntar);
-  AddExState(exntar, 2048, 0,"EXNR");
- }
- else
-  SetupCartMirroring(0,0,0);
-}
-
-static int DoMirroring(int fp)
-{
- uint8 t;
- t=FCEU_fgetc(fp);
- mirrortodo=t;
-
- {
-  static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"};
-  if(t<6)
-   printf(" Name/Attribute Table Mirroring: %s\n",stuffo[t]);
- }
- return(1);
-}
-
-static int CTRL(int fp)
-{
- int t;
-
- if((t=FCEU_fgetc(fp))==EOF)
-  return(0);
- /* The information stored in this byte isn't very helpful, but it's
-    better than nothing...maybe.
- */
-
- if(t&1) FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD;
- else FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_NONE;
-
- if(t&2) FCEUGameInfo.input[1]=SI_ZAPPER;
- else if(t&0x10) FCEUGameInfo.input[1]=SI_POWERPAD;
-
- return(1);
-}
-
-static int TVCI(int fp)
-{
- int t;
- if( (t=FCEU_fgetc(fp)) ==EOF)
-  return(0);
- if(t<=2)
- {
-  char *stuffo[3]={"NTSC","PAL","NTSC and PAL"};
-  if(t==0)
-   FCEUGameInfo.vidsys=GIV_NTSC;
-  else if(t==1)
-   FCEUGameInfo.vidsys=GIV_PAL;
-  printf(" TV Standard Compatibility: %s\n",stuffo[t]);
- }
- return(1);
-}
-
-static int EnableBattery(int fp)
-{
- puts(" Battery-backed.");
- if(FCEU_fgetc(fp)==EOF)
-  return(0);
- UNIFbattery=1;
- return(1);
-}
-
-static int LoadPRG(int fp)
-{
- int z,t;
- z=uchead.ID[3]-'0';
-
- if(z<0 || z>15)
-  return(0);
- printf(" PRG ROM %d size: %d",z,(int) uchead.info);
- if(malloced[z])
-  free(malloced[z]);
- t=FixRomSize(uchead.info,2048);
- if(!(malloced[z]=FCEU_malloc(t)))
-  return(0);
- memset(malloced[z]+uchead.info,0xFF,t-uchead.info);
- if(FCEU_fread(malloced[z],1,uchead.info,fp)!=uchead.info)
- {
-  puts("Read Error!");
-  return(0);
- }
- else
-  puts("");
-
- SetupCartPRGMapping(z,malloced[z],t,0);
- return(1);
-}
-
-static int SetBoardName(int fp)
-{
- if(!(boardname=FCEU_malloc(uchead.info+1)))
-  return(0);
- FCEU_fread(boardname,1,uchead.info,fp);
- boardname[uchead.info]=0;
- printf(" Board name: %s\n",boardname);
- sboardname=boardname;
- if(!memcmp(boardname,"NES-",4) || !memcmp(boardname,"UNL-",4) || !memcmp(boardname,"HVC-",4) || !memcmp(boardname,"BTL-",4) || !memcmp(boardname,"BMC-",4))
-  sboardname+=4;
- return(1);
-}
-
-static int LoadCHR(int fp)
-{
- int z,t;
- z=uchead.ID[3]-'0';
- if(z<0 || z>15)
-  return(0);
- printf(" CHR ROM %d size: %d",z,(int) uchead.info);
- if(malloced[16+z])
-  free(malloced[16+z]);
- t=FixRomSize(uchead.info,8192);
- if(!(malloced[16+z]=FCEU_malloc(t)))
-  return(0);
- memset(malloced[16+z]+uchead.info,0xFF,t-uchead.info);
- if(FCEU_fread(malloced[16+z],1,uchead.info,fp)!=uchead.info)
- {
-  puts("Read Error!");
-  return(0);
- }
- else
-  puts("");
-
- SetupCartCHRMapping(z,malloced[16+z],t,0);
- return(1);
-}
-
-
-#define BMCFLAG_FORCE4 1
-#define BMCFLAG_CHRROK 2       // Ok for generic UNIF code to make available
-                               // 8KB of CHR RAM if no CHR ROM is present.
-#define BMC 48
-
-BMAPPING bmap[BMC] = {
-
-/* Sachen Carts */
- { "TC-U01-1.5M", TCU01_Init,0},
- { "Sachen-8259B", S8259B_Init,BMCFLAG_CHRROK},
- { "Sachen-8259A", S8259A_Init,BMCFLAG_CHRROK},
- { "Sachen-74LS374N", S74LS374N_Init,0},
- { "SA-016-1M", SA0161M_Init,0},
- { "SA-72007", SA72007_Init,0},
- { "SA-72008", SA72008_Init,0},
- { "SA-0036", SA0036_Init,0},
- { "SA-0037", SA0037_Init,0},
-
- { "H2288", H2288_Init,0},
-// /* AVE carts. */
-// { "MB-91", MB91_Init,0},    // DeathBots
-// { "NINA-06", NINA06_Init,0},        // F-15 City War
-// { "NINA-03", NINA03_Init,0},        // Tiles of Fate
-// { "NINA-001", NINA001_Init,0}, // Impossible Mission 2
-
- { "HKROM", HKROM_Init,0},
-
- { "EWROM", EWROM_Init,0},
- { "EKROM", EKROM_Init,0},
- { "ELROM", ELROM_Init,0},
- { "ETROM", ETROM_Init,0},
-
- { "SAROM", SAROM_Init,0},
- { "SBROM", SBROM_Init,0},
- { "SCROM", SCROM_Init,0},
- { "SEROM", SEROM_Init,0},
- { "SGROM", SGROM_Init,0},
- { "SKROM", SKROM_Init,0},
- { "SLROM", SLROM_Init,0},
- { "SL1ROM", SL1ROM_Init,0},
- { "SNROM", SNROM_Init,0},
- { "SOROM", SOROM_Init,0},
-
- { "TGROM", TGROM_Init,0},
- { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4},
- { "TFROM", TFROM_Init,0},
- { "TLROM", TLROM_Init,0},
- { "TKROM", TKROM_Init,0},
- { "TSROM", TSROM_Init,0},
-
- { "TLSROM", TLSROM_Init,0},
- { "TKSROM", TKSROM_Init,0},
- { "TQROM", TQROM_Init,0},
- { "TVROM", TLROM_Init,BMCFLAG_FORCE4},
-
- { "CPROM", CPROM_Init,0},
- { "CNROM", CNROM_Init,0},
- { "NROM", NROM256_Init,0 },
- { "RROM", NROM128_Init,0 },
- { "RROM-128", NROM128_Init,0 },
- { "NROM-128", NROM128_Init,0 },
- { "NROM-256", NROM256_Init,0 },
- { "MHROM", MHROM_Init,0},
- { "UNROM", UNROM_Init,0},
- { "MARIO1-MALEE2", MALEE_Init,0},
- { "Supervision16in1", Supervision16_Init,0},
- { "NovelDiamond9999999in1", Novel_Init,0},
- { "Super24in1SC03", Super24_Init,0}
-};
-
-#define BMF 7
-BFMAPPING bfunc[BMF] = {
- { "CTRL", CTRL },
- { "TVCI", TVCI },
- { "BATR", EnableBattery },
- { "MIRR", DoMirroring },
- { "PRG",  LoadPRG },
- { "CHR",  LoadCHR },
- { "MAPR", SetBoardName }
-};
-
-int LoadUNIFChunks(int fp)
-{
-   int x;
-   int t;
-   for(;;)
-   {
-    t=FCEU_fread(&uchead,1,4,fp);
-    if(t<4)
-    {
-     if(t>0)
-      return 0;
-     return 1;
-    }
-    if(!(FCEU_read32(&uchead.info,fp)))
-     return 0;
-    t=0;
-    for(x=0;x<BMF;x++)
-    {
-     if(memcmp(&uchead,bfunc[x].name,strlen(bfunc[x].name)))
-      continue;
-     if(!bfunc[x].init(fp))
-      return 0;
-     t=1;
-     break;
-    }
-    if(!t)
-     if(FCEU_fseek(fp,uchead.info,SEEK_CUR))
-      return(0);
-   }
-}
-
-static int InitializeBoard(void)
-{
-   int x;
-
-   for(x=0;x<BMC;x++)
-   {
-    if(strcmp(sboardname,bmap[x].name)) continue;
-    if(!malloced[16] && (bmap[x].flags&BMCFLAG_CHRROK))
-    {
-     UNIFchrrama=FCEU_malloc(8192);
-     if((malloced[16]=(uint8 *)UNIFchrrama))
-     {
-      SetupCartCHRMapping(0,(uint8 *)UNIFchrrama,8192,1);
-      AddExState(UNIFchrrama, 8192, 0,"CHRR");
-     }
-     else
-      return(-1);
-    }
-    if(bmap[x].flags&BMCFLAG_FORCE4)
-     mirrortodo=4;
-    MooMirroring();
-    bmap[x].init();
-    return(1);
-   }
-   FCEU_PrintError("Board type not supported.");
-   return(0);
-}
-
-static void UNIFGI(int h)
-{
- switch(h)
- {
-  case GI_RESETM2:
-               if(BoardReset) BoardReset();
-               break;
-  case GI_POWER:
-                if(BoardPower) BoardPower();
-               if(UNIFchrrama) memset(UNIFchrrama,0,8192);
-               break;
-  case GI_CLOSE:
-                if(BoardClose)
-                 BoardClose();
-                FreeUNIF();
-                break;
- }
-}
-
-int UNIFLoad(char *name, int fp)
-{
-        FCEU_fseek(fp,0,SEEK_SET);
-        FCEU_fread(&unhead,1,4,fp);
-        if(memcmp(&unhead,"UNIF",4))
-         return 0;
-
-       ResetCartMapping();
-
-        ResetExState();
-        ResetUNIF();
-        if(!FCEU_read32(&unhead.info,fp))
-        goto aborto;
-        if(FCEU_fseek(fp,0x20,SEEK_SET)<0)
-        goto aborto;
-        if(!LoadUNIFChunks(fp))
-        goto aborto;
-        if(!InitializeBoard())
-        goto aborto;
-
-        GameInterface=UNIFGI;
-        return 1;
-
-       aborto:
-
-       FreeUNIF();
-       ResetUNIF();
-       return 0;
-}
-
-static FILE *fssp=0;
-
-void UNIFOpenWRAM(int t, char *ext, int override)
-{
- if(UNIFbattery|override)
- {
-  fssp=fopen(FCEU_MakeFName(FCEUMKF_SAV,0,(ext?ext:"sav")),(t==UOW_RD)?"rb":"wb");
- }
-}
-
-void UNIFWriteWRAM(uint8 *p, int size)
-{
- if(fssp)
-  fwrite(p, size, 1, fssp);
-}
-
-void UNIFReadWRAM(uint8 *p, int size)
-{
- if(fssp)
-  fread(p, size, 1, fssp);
-}
-void UNIFCloseWRAM(void)
-{
- if(fssp)
-  fclose(fssp);
- fssp=0;
-#ifdef GP2X
- sync();
-#endif
-}
+/* 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
+/* TODO:  Battery backup file saving, mirror force    */\r
+/* **INCOMPLETE**             */\r
+/* Override stuff: CHR RAM instead of CHR ROM,   mirroring. */\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\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
+\r
+typedef struct {\r
+           char ID[4];\r
+           uint32 info;\r
+} UNIF_HEADER;\r
+\r
+typedef struct {\r
+           char *name;\r
+           void (*init)(CartInfo *);\r
+          int flags;\r
+} BMAPPING;\r
+\r
+typedef struct {\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
+static uint8 *boardname;\r
+static uint8 *sboardname;\r
+\r
+static uint32 CHRRAMSize;\r
+uint8 *UNIFchrrama=0;\r
+\r
+static UNIF_HEADER unhead;\r
+static UNIF_HEADER uchead;\r
+\r
+\r
+static uint8 *malloced[32];\r
+static uint32 mallocedsizes[32];\r
+\r
+static int FixRomSize(uint32 size, uint32 minimum)\r
+{\r
+  int x=1;\r
+\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
+ 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
+ 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
+ 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
+ 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
+ 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
+}\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
+}\r
+\r
+static int CTRL(int fp)\r
+{\r
+ int t;\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
+ if(t&1) FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_GAMEPAD;\r
+ else FCEUGameInfo.input[0]=FCEUGameInfo.input[1]=SI_NONE;\r
+\r
+ if(t&2) FCEUGameInfo.input[1]=SI_ZAPPER;\r
+ //else if(t&0x10) FCEUGameInfo->input[1]=SI_POWERPAD;\r
+\r
+ return(1);\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
+}\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
+}\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
+}\r
+\r
+static int SetBoardName(int fp)\r
+{\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
+ 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
+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
+ { "H2288", UNLH2288_Init,0},\r
+ { "8237", UNL8237_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
+ { "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
+ { "GNROM", GNROM_Init,0},\r
+ { "NROM", NROM256_Init,0 },\r
+ { "RROM", NROM128_Init,0 },\r
+ { "RROM-128", NROM128_Init,0 },\r
+ { "NROM-128", NROM128_Init,0 },\r
+ { "NROM-256", NROM256_Init,0 },\r
+ { "MHROM", MHROM_Init,0},\r
+ { "UNROM", UNROM_Init,0},\r
+ { "MARIO1-MALEE2", MALEE_Init,0},\r
+\r
+ { "CC-21", UNLCC21_Init,0},\r
+\r
+ { "8157", UNL8157_Init,0},\r
+ { "Supervision16in1", Supervision16_Init,0},\r
+ { "NovelDiamond9999999in1", Novel_Init,0},\r
+ { "Super24in1SC03", Super24_Init,0},\r
+ { "SuperHIK8in1", Mapper45_Init,0},\r
+ { "DREAMTECH01", DreamTech01_Init,0},\r
+ { "KONAMI-QTAI", Mapper190_Init,0},\r
+ {0,0,0}\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
+};\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
+}\r
+\r
+static int InitializeBoard(void)\r
+{\r
+   int x=0;\r
+\r
+   if(!sboardname) return(0);\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
+      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
+}\r
+\r
+static void UNIFGI(int h)\r
+{\r
+ switch(h)\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
+  case GI_CLOSE:\r
+                FCEU_SaveGameSave(&UNIFCart);\r
+               if(UNIFCart.Close)\r
+                UNIFCart.Close();\r
+                FreeUNIF();\r
+                break;\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
+\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
+       {\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
+       }\r
+\r
+        if(!InitializeBoard())\r
+        goto aborto;\r
+\r
+       FCEU_LoadGameSave(&UNIFCart);\r
+        GameInterface=UNIFGI;\r
+        return 1;\r
+\r
+       aborto:\r
+\r
+       FreeUNIF();\r
+       ResetUNIF();\r
+\r
+\r
+       return 0;\r
+}\r
diff --git a/unif.h b/unif.h
index 1db41dd..f423765 100644 (file)
--- a/unif.h
+++ b/unif.h
@@ -1,94 +1,88 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You 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
- */
-
-#ifndef UNIFPRIV
-int UNIFLoad(char *name, int fp);
-#endif
-
-void TCU01_Init(void);
-void S8259B_Init(void);
-void S8259A_Init(void);
-void S74LS374N_Init(void);
-void SA0161M_Init(void);
-
-void SA72007_Init(void);
-void SA72008_Init(void);
-void SA0036_Init(void);
-void SA0037_Init(void);
-
-void H2288_Init(void);
-
-void HKROM_Init(void);
-
-void ETROM_Init(void);
-void EKROM_Init(void);
-void ELROM_Init(void);
-void EWROM_Init(void);
-
-void SAROM_Init(void);
-void SBROM_Init(void);
-void SCROM_Init(void);
-void SEROM_Init(void);
-void SGROM_Init(void);
-void SKROM_Init(void);
-void SLROM_Init(void);
-void SL1ROM_Init(void);
-void SNROM_Init(void);
-void SOROM_Init(void);
-
-void NROM_Init(void);
-void NROM256_Init(void);
-void NROM128_Init(void);
-void MHROM_Init(void);
-void UNROM_Init(void);
-void MALEE_Init(void);
-void Supervision16_Init(void);
-void Super24_Init(void);
-void Novel_Init(void);
-void CNROM_Init(void);
-void CPROM_Init(void);
-
-void TFROM_Init(void);
-void TGROM_Init(void);
-void TKROM_Init(void);
-void TSROM_Init(void);
-void TLROM_Init(void);
-void TLSROM_Init(void);
-void TKSROM_Init(void);
-void TQROM_Init(void);
-void TQROM_Init(void);
-
-
-void UNIFOpenWRAM(int t, char *ext, int override);
-void UNIFWriteWRAM(uint8 *p, int size);
-void UNIFReadWRAM(uint8 *p, int size);
-void UNIFCloseWRAM(void);
-#define        UOW_RD  0
-#define UOW_WR 1
-
-extern void (*BoardClose)(void);
-extern void (*BoardPower)(void);
-extern void (*BoardReset)(void);
-
-#define UNIFMemBlock (GameMemBlock+32768)
-
-extern int UNIFbattery;
-extern char *UNIFchrrama;      // Meh.  So I can't stop CHR RAM 
-                               // bank switcherooing with certain boards...
+/* 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
+void TCA01_Init(CartInfo *info);\r
+void TCU01_Init(CartInfo *info);\r
+void S8259A_Init(CartInfo *info);\r
+void S8259B_Init(CartInfo *info);\r
+void S8259C_Init(CartInfo *info);\r
+void S8259D_Init(CartInfo *info);\r
+void S74LS374N_Init(CartInfo *info);\r
+void S74LS374NA_Init(CartInfo *info);\r
+void SA0161M_Init(CartInfo *info);\r
+\r
+void SA72007_Init(CartInfo *info);\r
+void SA72008_Init(CartInfo *info);\r
+void SA0036_Init(CartInfo *info);\r
+void SA0037_Init(CartInfo *info);\r
+\r
+void UNLH2288_Init(CartInfo *info);\r
+void UNL8237_Init(CartInfo *info);\r
+void UNL8157_Init(CartInfo *info);\r
+\r
+void HKROM_Init(CartInfo *info);\r
+\r
+void ETROM_Init(CartInfo *info);\r
+void EKROM_Init(CartInfo *info);\r
+void ELROM_Init(CartInfo *info);\r
+void EWROM_Init(CartInfo *info);\r
+\r
+void SAROM_Init(CartInfo *info);\r
+void SBROM_Init(CartInfo *info);\r
+void SCROM_Init(CartInfo *info);\r
+void SEROM_Init(CartInfo *info);\r
+void SGROM_Init(CartInfo *info);\r
+void SKROM_Init(CartInfo *info);\r
+void SLROM_Init(CartInfo *info);\r
+void SL1ROM_Init(CartInfo *info);\r
+void SNROM_Init(CartInfo *info);\r
+void SOROM_Init(CartInfo *info);\r
+\r
+void NROM_Init(CartInfo *info);\r
+void NROM256_Init(CartInfo *info);\r
+void NROM128_Init(CartInfo *info);\r
+void MHROM_Init(CartInfo *info);\r
+void UNROM_Init(CartInfo *info);\r
+void MALEE_Init(CartInfo *info);\r
+void Supervision16_Init(CartInfo *info);\r
+void Super24_Init(CartInfo *info);\r
+void Novel_Init(CartInfo *info);\r
+void CNROM_Init(CartInfo *info);\r
+void CPROM_Init(CartInfo *info);\r
+void GNROM_Init(CartInfo *info);\r
+\r
+void TEROM_Init(CartInfo *info);\r
+void TFROM_Init(CartInfo *info);\r
+void TGROM_Init(CartInfo *info);\r
+void TKROM_Init(CartInfo *info);\r
+void TSROM_Init(CartInfo *info);\r
+void TLROM_Init(CartInfo *info);\r
+void TLSROM_Init(CartInfo *info);\r
+void TKSROM_Init(CartInfo *info);\r
+void TQROM_Init(CartInfo *info);\r
+void TQROM_Init(CartInfo *info);\r
+\r
+void DEIROM_Init(CartInfo *info);\r
+void DreamTech01_Init(CartInfo *info);\r
+void Mapper190_Init(CartInfo *info);\r
+void UNLCC21_Init(CartInfo *info);\r
+\r
+extern uint8 *UNIFchrrama;  // Meh.  So I can stop CHR RAM\r
+                               // bank switcherooing with certain boards...\r
diff --git a/video.c b/video.c
index adcb786..397f82e 100644 (file)
--- a/video.c
+++ b/video.c
@@ -46,8 +46,6 @@ uint8 *XBuf=NULL;
 
 int InitVirtualVideo(void)
 {
- uint32 m;
-
  if(!XBuf)             /* Some driver code may allocate XBuf externally. */
   if(!(XBuf = (uint8*) (FCEU_malloc(320 * 240))))
    return 0;
diff --git a/vsuni.c b/vsuni.c
new file mode 100644 (file)
index 0000000..3fb3bcd
--- /dev/null
+++ b/vsuni.c
@@ -0,0 +1,419 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2003 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
+#include <string.h>\r
+#include <stdio.h>\r
+\r
+#include "types.h"\r
+#include "x6502.h"\r
+#include "fce.h"\r
+#include "input.h"\r
+#include "netplay.h"\r
+#include "vsuni.h"\r
+#include "state.h"\r
+\r
+#include "svga.h"\r
+\r
+#define IOPTION_GUN       0x1\r
+#define IOPTION_SWAPDIRAB       0x2\r
+\r
+#define IOPTION_PREDIP    0x10\r
+typedef struct\r
+{\r
+        char *name;\r
+        uint64 md5partial;\r
+        int mapper;\r
+        int mirroring;\r
+        int ppu;\r
+        int ioption;\r
+        int predip;\r
+} VSUNIENTRY;\r
+\r
+VSUNIENTRY *curvs;\r
+\r
+static uint8 DIPS=0;\r
+uint8 vsdip=0;\r
+\r
+void FCEUI_VSUniToggleDIPView(void)\r
+{\r
+ DIPS=!DIPS;\r
+}\r
+\r
+void FCEU_VSUniToggleDIP(int w)\r
+{\r
+ vsdip^=1<<w;\r
+}\r
+\r
+void FCEUI_VSUniSetDIP(int w, int state)\r
+{\r
+ if(((vsdip >> w) & 1) != state)\r
+  FCEUI_VSUniToggleDIP(w);\r
+}\r
+\r
+uint8 FCEUI_VSUniGetDIPs(void)\r
+{\r
+ return(vsdip);\r
+}\r
+\r
+static uint8 secdata[2][32]=\r
+{\r
+ {\r
+  0xff, 0xbf, 0xb7, 0x97, 0x97, 0x17, 0x57, 0x4f,\r
+  0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90, 0x94, 0x14,\r
+  0x56, 0x4e, 0x6f, 0x6b, 0xeb, 0xa9, 0xb1, 0x90,\r
+  0xd4, 0x5c, 0x3e, 0x26, 0x87, 0x83, 0x13, 0x00\r
+ },\r
+ {\r
+  0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,\r
+  0x00, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x94, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+ }\r
+};\r
+\r
+static uint8 *secptr;\r
+\r
+static uint8 VSindex;\r
+\r
+static DECLFR(VSSecRead)\r
+{\r
+ switch(A)\r
+ {\r
+  case 0x5e00: VSindex=0;return X.DB;\r
+  case 0x5e01: return(secptr[(VSindex++)&0x1F]);\r
+ }\r
+ return(0x00);\r
+}\r
+uint8 coinon=0;\r
+\r
+void FCEU_VSUniCoin(void)\r
+{\r
+ coinon=6;\r
+}\r
+\r
+static int curppu;\r
+static int64 curmd5;\r
+\r
+#define RP2C04_001      1\r
+#define RP2C04_002      2\r
+#define RP2C04_003      3\r
+#define RP2C05_004      4\r
+#define RCP2C03B  5\r
+#define RC2C05_01       6\r
+#define RC2C05_02       7\r
+#define RC2C05_03       8\r
+#define RC2C05_04       9\r
+\r
+static readfunc OldReadPPU;\r
+static writefunc OldWritePPU[2];\r
+\r
+static DECLFR(A2002_Gumshoe)\r
+{\r
+ return( (OldReadPPU(A)&~0x3F) | 0x1C);\r
+}\r
+\r
+static DECLFR(A2002_Topgun)\r
+{\r
+ return( (OldReadPPU(A)&~0x3F) | 0x1B);\r
+}\r
+\r
+static DECLFR(A2002_MBJ)  // Mighty Bomb Jack\r
+{\r
+ return( (OldReadPPU(A)&~0x3F) | 0x3D);\r
+}\r
+\r
+static DECLFW(B2000_2001_2C05)\r
+{\r
+ OldWritePPU[(A&1)^1](A ^ 1, V);\r
+}\r
+static uint8 xevselect = 0;\r
+static DECLFR(XevRead)\r
+{\r
+ //printf("%04x\n",A);\r
+ if(A == 0x54FF)\r
+ {\r
+  return(0x5);\r
+ }\r
+ else if(A == 0x5678)\r
+ {\r
+  return(xevselect?0:1);\r
+ }\r
+ else if(A == 0x578F)\r
+ {\r
+  return(xevselect?0xd1:0x89);\r
+ }\r
+ else if(A == 0x5567)\r
+ {\r
+  xevselect ^=1;\r
+  return(xevselect?0x37:0x3E);\r
+ }\r
+ return(X.DB);\r
+}\r
+\r
+void FCEU_VSUniSwap(uint8 *j0, uint8 *j1)\r
+{\r
+ if(curvs->ioption & IOPTION_SWAPDIRAB)\r
+ {\r
+  uint16 t=*j0;\r
+  *j0=(*j0&0xC)|(*j1&0xF3);\r
+  *j1=(*j1&0xC)|(t&0xF3);\r
+ }\r
+}\r
+\r
+void FCEU_VSUniPower(void)\r
+{\r
+ coinon = 0;\r
+ VSindex = 0;\r
+\r
+ if(secptr)\r
+  SetReadHandler(0x5e00,0x5e01,VSSecRead);\r
+\r
+ if(curppu == RC2C05_04)\r
+ {\r
+  OldReadPPU = GetReadHandler(0x2002);\r
+  SetReadHandler(0x2002, 0x2002, A2002_Topgun);\r
+ }\r
+ else if(curppu == RC2C05_03)\r
+ {\r
+  OldReadPPU = GetReadHandler(0x2002);\r
+  SetReadHandler(0x2002, 0x2002, A2002_Gumshoe);\r
+ }\r
+ else if(curppu == RC2C05_02)\r
+ {\r
+  OldReadPPU = GetReadHandler(0x2002);\r
+  SetReadHandler(0x2002, 0x2002, A2002_MBJ);\r
+ }\r
+ if(curppu == RC2C05_04 || curppu == RC2C05_01 || curppu == RC2C05_03 || curppu == RC2C05_02)\r
+ {\r
+  OldWritePPU[0] = GetWriteHandler(0x2000);\r
+  OldWritePPU[1] = GetWriteHandler(0x2001);\r
+  SetWriteHandler(0x2000, 0x2001, B2000_2001_2C05);\r
+ }\r
+ if(curmd5 == 0x2d396247cf58f9faLL) /* Super Xevious */\r
+ {\r
+  SetReadHandler(0x5400,0x57FF,XevRead);\r
+ }\r
+}\r
+\r
+/* Games that will probably not be supported ever(or for a long time), since they require\r
+   dual-system:\r
+\r
+   Balloon Fight\r
+   VS Mahjong\r
+   VS Tennis\r
+   Wrecking Crew\r
+*/\r
+\r
+/* Games/PPU list.  Information copied from MAME.  ROMs are exchangable, so don't take\r
+   this list as "this game must use this PPU".\r
+\r
+RP2C04-001:\r
+- Baseball\r
+- Freedom Force\r
+- Gradius\r
+- Hogan's Alley\r
+- Mach Rider (Japan, Fighting Course)\r
+- Pinball\r
+- Platoon\r
+- Super Xevious\r
+\r
+RP2C04-002:\r
+- Castlevania\r
+- Ladies golf\r
+- Mach Rider (Endurance Course)\r
+- Raid on Bungeling Bay (Japan)\r
+- Slalom\r
+- Stroke N' Match Golf\r
+- Wrecking Crew\r
+\r
+RP2C04-003:\r
+- Dr mario\r
+- Excite Bike\r
+- Goonies\r
+- Soccer\r
+- TKO Boxing\r
+\r
+RP2c05-004:\r
+- Clu Clu Land\r
+- Excite Bike (Japan)\r
+- Ice Climber\r
+- Ice Climber Dual (Japan)\r
+- Super Mario Bros.\r
+\r
+Rcp2c03b:\r
+- Battle City\r
+- Duck Hunt\r
+- Mahjang\r
+- Pinball (Japan)\r
+- Rbi Baseball\r
+- Star Luster\r
+- Stroke and Match Golf (Japan)\r
+- Super Skykid\r
+- Tennis\r
+- Tetris\r
+\r
+RC2C05-01:\r
+- Ninja Jajamaru Kun (Japan)\r
+\r
+RC2C05-02:\r
+- Mighty Bomb Jack (Japan)\r
+\r
+RC2C05-03:\r
+- Gumshoe\r
+\r
+RC2C05-04:\r
+- Top Gun\r
+*/\r
+\r
+VSUNIENTRY VSUniGames[]  =\r
+{\r
+ {"Baseball",    0x691d4200ea42be45LL, 99, 2,RP2C04_001,0},\r
+  {"Battle City",  0x8540949d74c4d0ebLL, 99, 2,RP2C04_001,0},\r
+  {"Battle City(Bootleg)",0x8093cbe7137ac031LL, 99, 2,RP2C04_001,0},\r
+\r
+  {"Clu Clu Land",  0x1b8123218f62b1eeLL, 99, 2,RP2C05_004,IOPTION_SWAPDIRAB},\r
+  {"Dr Mario",    0xe1af09c477dc0081LL,  1, 0,RP2C04_003,IOPTION_SWAPDIRAB},\r
+  {"Duck Hunt",    0x47735d1e5f1205bbLL, 99, 2,RCP2C03B  ,IOPTION_GUN},\r
+  {"Excitebike",    0x3dcd1401bcafde77LL, 99, 2,RP2C04_003,0},\r
+  {"Excitebike (J)",    0x7ea51c9d007375f0LL, 99, 2,RP2C05_004,0},\r
+  {"Freedom Force",  0xed96436bd1b5e688LL,  4, 0,RP2C04_001,IOPTION_GUN}, /* Wrong color in game select screen? */\r
+  {"Stroke and Match Golf",0x612325606e82bc66LL, 99, 2,RP2C04_002,IOPTION_SWAPDIRAB|IOPTION_PREDIP,0x01},\r
+\r
+  {"Goonies",    0x3b0085c4ff29098eLL, 151,1,RP2C04_003,0},\r
+  {"Gradius",    0x50687ae63bdad976LL,151, 1,RP2C04_001,IOPTION_SWAPDIRAB},\r
+  {"Gumshoe",    0xb8500780bf69ce29LL, 99, 2,RC2C05_03,IOPTION_GUN},\r
+  {"Hogan's Alley",  0xd78b7f0bb621fb45LL, 99, 2,RP2C04_001,IOPTION_GUN},\r
+  {"Ice Climber",  0xd21e999513435e2aLL, 99, 2,RP2C05_004,IOPTION_SWAPDIRAB},\r
+  {"Ladies Golf",  0x781b24be57ef6785LL, 99, 2,RP2C04_002,IOPTION_SWAPDIRAB|IOPTION_PREDIP,0x1},\r
+\r
+  {"Mach Rider",  0x015672618af06441LL, 99, 2, RP2C04_002,0},\r
+  {"Mach Rider (J)",  0xa625afb399811a8aLL, 99, 2, RP2C04_001,0},\r
+  {"Mighty Bomb Jack",  0xe6a89f4873fac37bLL, 0, 2, RC2C05_02,0},\r
+  {"Ninja Jajamaru Kun",  0xb26a2c31474099c0LL, 99, 2,RC2C05_01 ,IOPTION_SWAPDIRAB},\r
+  {"Pinball",    0xc5f49d3de7f2e9b8LL, 99, 2,RP2C04_001,IOPTION_PREDIP,0x01},\r
+  {"Pinball (J)",    0x66ab1a3828cc901cLL, 99, 2,RCP2C03B,IOPTION_PREDIP,0x1},\r
+  {"Platoon",    0x160f237351c19f1fLL, 68, 1,RP2C04_001,0},\r
+  {"RBI Baseball",       0x6a02d345812938afLL,  4, 1,RP2C04_001 ,IOPTION_SWAPDIRAB},\r
+  {"Soccer",    0xd4e7a9058780eda3LL, 99, 2,RP2C04_003,IOPTION_SWAPDIRAB},\r
+  {"Star Luster",  0x8360e134b316d94cLL, 99, 2,RCP2C03B  ,0},\r
+  {"Stroke and Match Golf (J)",0x869bb83e02509747LL, 99, 2,RCP2C03B,IOPTION_SWAPDIRAB|IOPTION_PREDIP,0x1},\r
+  {"Super Sky Kid",  0x78d04c1dd4ec0101LL,  4, 1,RCP2C03B  ,IOPTION_SWAPDIRAB | IOPTION_PREDIP,0x20},\r
+\r
+  {"Super Xevious",  0x2d396247cf58f9faLL,  206, 0,RP2C04_001,0},\r
+  {"Tetris",    0x531a5e8eea4ce157LL, 99, 2,RCP2C03B  ,IOPTION_PREDIP,0x20},\r
+  {"Top Gun",    0xf1dea36e6a7b531dLL,  2, 0,RC2C05_04 ,0},\r
+  {"VS Castlevania",     0x92fd6909c81305b9LL,  2, 1,RP2C04_002,0},\r
+  {"VS Slalom",    0x4889b5a50a623215LL,  0, 1,RP2C04_002,0},\r
+  {"VS Super Mario Bros",0x39d8cfa788e20b6cLL, 99, 2,RP2C05_004,0},\r
+  {"VS TKO Boxing",  0x6e1ee06171d8ce3aLL,4, 1,RP2C04_003,IOPTION_PREDIP,0x00},\r
+ {0}\r
+};\r
+\r
+void FCEU_VSUniCheck(uint64 md5partial, int *MapperNo, uint8 *Mirroring)\r
+{\r
+ VSUNIENTRY *vs = VSUniGames;\r
+\r
+ while(vs->name)\r
+ {\r
+  if(md5partial == vs->md5partial)\r
+  {\r
+\r
+   if(vs->ppu < RCP2C03B) pale = vs->ppu;\r
+   //puts(vs->name);\r
+   *MapperNo = vs->mapper;\r
+   *Mirroring = vs->mirroring;\r
+   FCEUGameInfo.type = GIT_VSUNI;\r
+   FCEUGameInfo.cspecial = SIS_VSUNISYSTEM;\r
+   FCEUGameInfo.inputfc = SIFC_NONE;\r
+   curppu = vs->ppu;\r
+   curmd5 = md5partial;\r
+\r
+   secptr = 0;\r
+\r
+   {\r
+    static int64 tko=0x6e1ee06171d8ce3aULL, rbi=0x6a02d345812938afULL;\r
+    if(md5partial == tko)\r
+     secptr=secdata[0];\r
+    if(md5partial == rbi)\r
+     secptr = secdata[1];\r
+   }\r
+\r
+   vsdip = 0x0;\r
+   if(vs->ioption & IOPTION_PREDIP)\r
+   {\r
+    vsdip= vs->predip;\r
+   }\r
+   if(vs->ioption & IOPTION_GUN)\r
+   {\r
+    FCEUGameInfo.input[0] = SI_ZAPPER;\r
+    FCEUGameInfo.input[1] = SI_NONE;\r
+   }\r
+   else\r
+   {\r
+    FCEUGameInfo.input[0] = FCEUGameInfo.input[1] = SI_GAMEPAD;\r
+   }\r
+   curvs = vs;\r
+   return;\r
+  }\r
+  vs++;\r
+ }\r
+}\r
+\r
+void FCEU_VSUniDraw(uint8 *XBuf)\r
+{\r
+  uint32 *dest;\r
+  int y,x;\r
+\r
+  if(!DIPS) return;\r
+\r
+  dest=(uint32 *)(XBuf+256*12+164);\r
+  for(y=24;y;y--,dest+=(256-72)>>2)\r
+  {\r
+   for(x=72>>2;x;x--,dest++)\r
+    *dest=0;\r
+  }\r
+\r
+  dest=(uint32 *)(XBuf+256*(12+4)+164+6 );\r
+  for(y=16;y;y--,dest+=(256>>2)-16)\r
+   for(x=8;x;x--)\r
+   {\r
+    *dest=0x01010101;\r
+    dest+=2;\r
+   }\r
+\r
+  dest=(uint32 *)(XBuf+256*(12+4)+164+6 );\r
+  for(x=0;x<8;x++,dest+=2)\r
+  {\r
+   uint32 *da=dest+(256>>2);\r
+\r
+   if(!((vsdip>>x)&1))\r
+    da+=(256>>2)*10;\r
+   for(y=4;y;y--,da+=256>>2)\r
+    *da=0;\r
+  }\r
+}\r
+\r
+\r
+SFORMAT FCEUVSUNI_STATEINFO[]={\r
+  { &vsdip, 1, "vsdp"},\r
+  { &coinon, 1, "vscn"},\r
+  { &VSindex, 1, "vsin"},\r
+  { 0}\r
+};\r
diff --git a/vsuni.h b/vsuni.h
new file mode 100644 (file)
index 0000000..14fb715
--- /dev/null
+++ b/vsuni.h
@@ -0,0 +1,7 @@
+void FCEU_VSUniPower(void);\r
+void FCEU_VSUniCheck(uint64 md5partial, int *, uint8 *);\r
+void FCEU_VSUniDraw(uint8 *XBuf);\r
+\r
+void FCEU_VSUniToggleDIP(int);  /* For movies and netplay */\r
+void FCEU_VSUniCoin(void);\r
+void FCEU_VSUniSwap(uint8 *j0, uint8 *j1);\r
diff --git a/x6502.h b/x6502.h
index 1a44b30..f13bbdd 100644 (file)
--- a/x6502.h
+++ b/x6502.h
@@ -52,6 +52,8 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a);
 #define FCEU_IQDPCM     0x10
 #define FCEU_IQFCOUNT   0x20
 #define FCEU_IQTEMP     0x80
+// from 0.98.15
+#define FCEU_IQEXT2    0x02
 
 #if defined(DEBUG_ASM_6502)
 #define TriggerIRQ TriggerIRQ_d