updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[fceu.git] / boards / bonza.c
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