mappers updated to 0.98.16
[fceu.git] / boards / bonza.c
index 5e572f1..ba390e6 100644 (file)
-/* 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
+/* FCE Ultra - NES/Famicom Emulator
+ *
+ * Copyright notice for this file:
+ *  Copyright (C) 2002 CaH4e3
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "mapinc.h"
+
+static uint8 prg_reg;
+static uint8 chr_reg;
+
+static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt;
+static uint16 sim0data;
+static uint8 sim0array[128] =
+{
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
+  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA,
+};
+
+static SFORMAT StateRegs[]=
+{
+  {&prg_reg, 1, "PREG"},
+  {&chr_reg, 1, "CREG"},
+  {0}
+};
+
+static void Sync(void)
+{
+  setprg32(0x8000, prg_reg);
+  setchr8(chr_reg);
+}
+
+static void StateRestore(int version)
+{
+  Sync();
+}
+
+static DECLFW(M216WriteHi)
+{
+// FCEU_printf("%04x:%04x\n",A,V);
+  prg_reg=A&1;
+  chr_reg=(A&0x0E)>>1;
+  Sync();
+}
+
+static DECLFW(M216Write5000)
+{
+// FCEU_printf("WRITE: %04x:%04x\n",A,V);
+  sim0reg=V;
+  if(!sim0reg)
+  {
+    sim0bit=sim0byte=sim0parity=0;
+    sim0data=sim0array[0];
+    sim0bcnt=0x80;
+  }
+  else if(sim0reg&0x20)
+  {
+    sim0bcnt=0x20;
+  }
+}
+
+static DECLFR(M216Read5000)
+{
+  if(sim0reg&0x60)
+  {
+    sim0reg=(sim0reg^(sim0reg<<1))&0x40;
+    return sim0reg;
+  }
+  else
+  {
+    uint8 sim0out=0;
+    if(sim0bit<8)
+    {
+//       sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1;
+      sim0out=(sim0data&1)<<6;
+      sim0data>>=1;
+      sim0bit++;
+      sim0parity+=sim0data;
+    }
+    else if(sim0bit==8)
+    {
+      sim0bit++;
+      sim0out=sim0parity&1;
+    }
+    else if(sim0bit==9)
+    {
+      if(sim0byte==sim0bcnt)
+        sim0out=0x60;
+      else
+      {
+        sim0bit=0;
+        sim0byte++;
+        sim0data=sim0array[sim0byte];
+        sim0out=0;
+      }
+    }
+//    FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte);
+    return sim0out;
+  }
+}
+
+static void Power(void)
+{
+  prg_reg = 0;
+  chr_reg = 0;
+  Sync();
+  SetReadHandler(0x8000,0xFFFF,CartBR);
+  SetWriteHandler(0x8000,0xFFFF,M216WriteHi);
+  SetWriteHandler(0x5000,0x5000,M216Write5000);
+  SetReadHandler(0x5000,0x5000,M216Read5000);
+}
+
+
+void Mapper216_Init(CartInfo *info)
+{
+  info->Power=Power;
+  GameStateRestore=StateRestore;
+  AddExState(&StateRegs, ~0, 0, 0);
+}