merge mappers from FCEU-mm
[fceu.git] / boards / 91.c
diff --git a/boards/91.c b/boards/91.c
new file mode 100644 (file)
index 0000000..0fed9df
--- /dev/null
@@ -0,0 +1,95 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2012 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 cregs[4], pregs[2];\r
+static uint8 IRQCount, IRQa;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {cregs, 4, "CREG"},\r
+  {pregs, 2, "PREG"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 1, "IRQC"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x8000,pregs[0]);\r
+  setprg8(0xa000,pregs[1]);\r
+  setprg8(0xc000,~1);\r
+  setprg8(0xe000,~0);\r
+  setchr2(0x0000,cregs[0]);\r
+  setchr2(0x0800,cregs[1]);\r
+  setchr2(0x1000,cregs[2]);\r
+  setchr2(0x1800,cregs[3]);\r
+}\r
+\r
+static DECLFW(M91Write0)\r
+{\r
+  cregs[A & 3] = V;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M91Write1)\r
+{\r
+  switch (A & 3)\r
+  {\r
+    case 0:\r
+    case 1: pregs[A & 1] = V; Sync(); break;\r
+    case 2: IRQa = IRQCount = 0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+    case 3: IRQa = 1; X6502_IRQEnd(FCEU_IQEXT); break;\r
+  }\r
+}\r
+\r
+static void M91Power(void)\r
+{\r
+  Sync();\r
+  SetWriteHandler(0x6000,0x6fff,M91Write0);\r
+  SetWriteHandler(0x7000,0x7fff,M91Write1);\r
+  SetReadHandler(0x8000,0xffff,CartBR);\r
+}\r
+\r
+static void M91IRQHook(void)\r
+{\r
+  if(IRQCount<8 && IRQa)\r
+  {\r
+    IRQCount++;\r
+    if(IRQCount>=8)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);   \r
+    } \r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper91_Init(CartInfo *info)\r
+{\r
+  info->Power=M91Power;\r
+  GameHBIRQHook=M91IRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r