merge mapper code from FCEUX
[fceu.git] / boards / 175.c
diff --git a/boards/175.c b/boards/175.c
new file mode 100644 (file)
index 0000000..2830584
--- /dev/null
@@ -0,0 +1,88 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 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
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg, delay, mirr;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&reg, 1, "REG"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setchr8(reg);\r
+  if(!delay)\r
+  {\r
+  setprg16(0x8000,reg);\r
+  setprg8(0xC000,reg << 1);\r
+  }\r
+  setprg8(0xE000,(reg << 1) + 1);\r
+  setmirror(((mirr&4)>>2)^1);\r
+}\r
+\r
+static DECLFW(M175Write1)\r
+{\r
+  mirr = V;\r
+  delay = 1;\r
+  Sync();\r
+}\r
+\r
+static DECLFW(M175Write2)\r
+{\r
+  reg = V & 0x0F;\r
+  delay = 1;\r
+  Sync();\r
+}\r
+\r
+static DECLFR(M175Read)\r
+{\r
+  if(A==0xFFFC)\r
+  {\r
+    delay = 0;\r
+    Sync();\r
+  }\r
+  return CartBR(A);\r
+}\r
+\r
+static void M175Power(void)\r
+{\r
+  reg = mirr = delay = 0;\r
+  SetReadHandler(0x8000,0xFFFF,M175Read);\r
+  SetWriteHandler(0x8000,0x8000,M175Write1);\r
+  SetWriteHandler(0xA000,0xA000,M175Write2);\r
+  Sync();     \r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper175_Init(CartInfo *info)\r
+{\r
+  info->Power=M175Power;\r
+  GameStateRestore=StateRestore;\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r