merge mappers from FCEU-mm
[fceu.git] / boards / 82.c
diff --git a/boards/82.c b/boards/82.c
new file mode 100644 (file)
index 0000000..7dfd276
--- /dev/null
@@ -0,0 +1,105 @@
+/* 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
+ * Taito X1-017 board, battery backed\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 regs[9], ctrl;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {regs, 9, "REGS"},\r
+  {&ctrl, 1, "CTRL"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint32 swap = ((ctrl & 2) << 11);\r
+  setchr2(0x0000^swap,regs[0]>>1);  \r
+  setchr2(0x0800^swap,regs[1]>>1);  \r
+  setchr1(0x1000^swap,regs[2]);  \r
+  setchr1(0x1400^swap,regs[3]);  \r
+  setchr1(0x1800^swap,regs[4]);  \r
+  setchr1(0x1c00^swap,regs[5]);  \r
+  setprg8r(0x10,0x6000,0);\r
+  setprg8(0x8000,regs[6]);\r
+  setprg8(0xA000,regs[7]);\r
+  setprg8(0xC000,regs[8]);\r
+  setprg8(0xE000,~0);\r
+  setmirror(ctrl & 1);\r
+}\r
+\r
+static DECLFW(M82Write)\r
+{\r
+  if(A <= 0x7ef5)\r
+    regs[A & 7] = V;\r
+  else\r
+    switch(A)\r
+    {\r
+      case 0x7ef6: ctrl = V & 3; break;\r
+      case 0x7efa: regs[6] = V >> 2; break;\r
+      case 0x7efb: regs[7] = V >> 2; break;\r
+      case 0x7efc: regs[8] = V >> 2; break;\r
+    }\r
+  Sync();\r
+}\r
+\r
+static void M82Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x6000,0xffff,CartBR);\r
+  SetWriteHandler(0x6000,0x7fff,CartBW);\r
+  SetWriteHandler(0x7ef0,0x7efc,M82Write);  // external WRAM might end at $73FF\r
+}\r
+\r
+static void M82Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper82_Init(CartInfo *info)\r
+{\r
+  info->Power=M82Power;\r
+  info->Power=M82Close;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+  if(info->battery)\r
+  {\r
+    info->SaveGame[0]=WRAM;\r
+    info->SaveGameLen[0]=WRAMSIZE;\r
+  }\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r