merge mapper code from FCEUX
[fceu.git] / boards / 121.c
diff --git a/boards/121.c b/boards/121.c
new file mode 100644 (file)
index 0000000..63784f9
--- /dev/null
@@ -0,0 +1,91 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007-2008 Mad Dumper, 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
+ * Panda prince pirate.\r
+ * MK4, MK6, A9711 board, MAPPER 187 the same!\r
+ * UNL6035052_Init seems to be the same too, but with prot array in reverse\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 readbyte = 0;\r
+\r
+static DECLFW(M121Write)\r
+{\r
+//  FCEU_printf("write: %04x:%04x\n",A&0xE003,V);\r
+  if((A&0xF003)==0x8003)\r
+  {\r
+//    FCEU_printf("       prot write");\r
+//    FCEU_printf("write: %04x:%04x\n",A,V);\r
+    if     (V==0xAB) setprg8(0xE000,7);\r
+    else if(V==0x26) setprg8(0xE000,8);\r
+//    else if(V==0x26) setprg8(0xE000,1); // MK3\r
+//    else if(V==0x26) setprg8(0xE000,0x15); // sonic 3D blast, 8003 - command (0x26), 8001 - data 0x2A (<<1 = 0x15)\r
+    else if(V==0xFF) setprg8(0xE000,9);\r
+    else if(V==0x28) setprg8(0xC000,0xC);\r
+    else if(V==0xEC) setprg8(0xE000,0xD); \r
+//    else if(V==0xEC) setprg8(0xE000,0xC);//MK3\r
+    else if(V==0xEF) setprg8(0xE000,0xD); // damn mess, need real hardware to figure out bankswitching\r
+    else if(V==0x2A) setprg8(0xA000,0x0E);\r
+//    else if(V==0x2A) setprg8(0xE000,0x0C); // MK3\r
+    else if(V==0x20) setprg8(0xE000,0x13);\r
+    else if(V==0x29) setprg8(0xE000,0x1B);\r
+    else \r
+    {\r
+//      FCEU_printf(" unknown");\r
+      FixMMC3PRG(MMC3_cmd);\r
+      MMC3_CMDWrite(A,V);\r
+    }\r
+//      FCEU_printf("\n");\r
+  }\r
+  else\r
+  {\r
+//    FixMMC3PRG(MMC3_cmd);\r
+    MMC3_CMDWrite(A,V);\r
+  }\r
+}\r
+\r
+static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 };\r
+static DECLFW(M121LoWrite)\r
+{\r
+  EXPREGS[0] = prot_array[V&3];  // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter)\r
+//  FCEU_printf("write: %04x:%04x\n",A,V);\r
+}\r
+\r
+static DECLFR(M121Read)\r
+{ \r
+//  FCEU_printf("read:  %04x\n",A);\r
+  return EXPREGS[0];\r
+}\r
+\r
+static void M121Power(void)\r
+{\r
+  GenMMC3Power();\r
+//  Write_IRQFM(0x4017,0x40);\r
+  SetReadHandler(0x5000,0x5FFF,M121Read);\r
+  SetWriteHandler(0x5000,0x5FFF,M121LoWrite);\r
+  SetWriteHandler(0x8000,0x9FFF,M121Write);\r
+}\r
+\r
+void Mapper121_Init(CartInfo *info)\r
+{\r
+  GenMMC3_Init(info, 128, 256, 8, 0);\r
+  info->Power=M121Power;\r
+  AddExState(EXPREGS, 2, 0, "EXPR");\r
+}\r