merge mapper code from FCEUX
[fceu.git] / boards / 01-222.c
diff --git a/boards/01-222.c b/boards/01-222.c
new file mode 100644 (file)
index 0000000..c0e7320
--- /dev/null
@@ -0,0 +1,103 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * TXC mappers\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[4], cmd, is172, is173;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 4, "REGS"},\r
+  {&cmd, 1, "CMD"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg32(0x8000,(reg[2]>>2)&1);\r
+  if(is172)\r
+    setchr8((((cmd^reg[2])>>3)&2)|(((cmd^reg[2])>>5)&1)); // 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to\r
+                                                          // rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary\r
+  else\r
+    setchr8(reg[2]&3);\r
+}\r
+\r
+static DECLFW(UNL22211WriteLo)\r
+{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+  reg[A&3]=V;\r
+}\r
+\r
+static DECLFW(UNL22211WriteHi)\r
+{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+  cmd=V;\r
+  Sync();\r
+}\r
+\r
+static DECLFR(UNL22211ReadLo)\r
+{\r
+    return (reg[1]^reg[2])|(is173?0x01:0x40);\r
+//  if(reg[3])\r
+//    return reg[2];\r
+//  else\r
+//    return X.DB;\r
+}\r
+\r
+static void UNL22211Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetReadHandler(0x4100,0x4100,UNL22211ReadLo);\r
+  SetWriteHandler(0x4100,0x4103,UNL22211WriteLo);\r
+  SetWriteHandler(0x8000,0xFFFF,UNL22211WriteHi);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNL22211_Init(CartInfo *info)\r
+{\r
+  is172=0;\r
+  is173=0;\r
+  info->Power=UNL22211Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper172_Init(CartInfo *info)\r
+{\r
+  is172=1;  \r
+  is173=0;\r
+  info->Power=UNL22211Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void Mapper173_Init(CartInfo *info)\r
+{\r
+  is172=0;  \r
+  is173=1;\r
+  info->Power=UNL22211Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r