merge mappers from FCEU-mm
[fceu.git] / boards / 12in1.c
diff --git a/boards/12in1.c b/boards/12in1.c
new file mode 100644 (file)
index 0000000..4a10a42
--- /dev/null
@@ -0,0 +1,79 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2009 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1")\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[4];\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 4, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+    uint8 bank = (reg[3]&3)<<3;\r
+    setchr4(0x0000, (reg[1]>>3)|(bank<<2));\r
+    setchr4(0x1000, (reg[2]>>3)|(bank<<2));\r
+    if(reg[3]&8)\r
+    {\r
+      setprg32(0x8000,((reg[2]&7)>>1)|bank);\r
+    }\r
+    else\r
+    {\r
+      setprg16(0x8000, (reg[1]&7)|bank);\r
+      setprg16(0xc000, 7|bank);\r
+    }\r
+    setmirror(((reg[3]&4)>>2)^1);\r
+}\r
+\r
+static DECLFW(BMC12IN1Write)\r
+{\r
+  switch(A)\r
+  {\r
+  case 0xafff: reg[0] = V; break;\r
+  case 0xbfff: reg[1] = V; break;\r
+  case 0xdfff: reg[2] = V; break;\r
+  case 0xefff: reg[3] = V; break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void BMC12IN1Power(void)\r
+{\r
+  reg[0]=reg[1]=reg[2]=reg[3]=0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,BMC12IN1Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMC12IN1_Init(CartInfo *info)\r
+{\r
+  info->Power=BMC12IN1Power;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r