merge mapper code from FCEUX
[fceu.git] / boards / 199.c
diff --git a/boards/199.c b/boards/199.c
new file mode 100644 (file)
index 0000000..ed21278
--- /dev/null
@@ -0,0 +1,97 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2006 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
+ * Dragon Ball Z 2 - Gekishin Freeza! (C)\r
+ * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C)\r
+ * San Guo Zhi 2 (C)\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+#include "mmc3.h"\r
+\r
+static uint8 *CHRRAM=NULL; // and here too\r
+\r
+static void M199PW(uint32 A, uint8 V)\r
+{\r
+  setprg8(A,V);\r
+  setprg8(0xC000,EXPREGS[0]);\r
+  setprg8(0xE000,EXPREGS[1]);\r
+}\r
+\r
+static void M199CW(uint32 A, uint8 V)\r
+{\r
+  setchr1r((V<8)?0x10:0x00,A,V);\r
+  setchr1r((DRegBuf[0]<8)?0x10:0x00,0x0000,DRegBuf[0]);\r
+  setchr1r((EXPREGS[2]<8)?0x10:0x00,0x0400,EXPREGS[2]);\r
+  setchr1r((DRegBuf[1]<8)?0x10:0x00,0x0800,DRegBuf[1]);\r
+  setchr1r((EXPREGS[3]<8)?0x10:0x00,0x0c00,EXPREGS[3]);\r
+}\r
+\r
+static void M199MW(uint8 V)\r
+{\r
+//    FCEU_printf("%02x\n",V);\r
+  switch(V&3)\r
+  {\r
+    case 0: setmirror(MI_V); break;\r
+    case 1: setmirror(MI_H); break;\r
+    case 2: setmirror(MI_0); break;\r
+    case 3: setmirror(MI_1); break;\r
+  }\r
+}\r
+\r
+static DECLFW(M199Write)\r
+{\r
+  if((A==0x8001)&&(MMC3_cmd&8))\r
+  {\r
+//    FCEU_printf("%02x=>%02x\n",MMC3_cmd,V);\r
+    EXPREGS[MMC3_cmd&3]=V;\r
+    FixMMC3PRG(MMC3_cmd);\r
+    FixMMC3CHR(MMC3_cmd);\r
+  }\r
+  else    \r
+    if(A<0xC000)\r
+      MMC3_CMDWrite(A,V);\r
+    else\r
+      MMC3_IRQWrite(A,V);\r
+}\r
+\r
+static void M199Power(void)\r
+{\r
+  EXPREGS[0]=~1;\r
+  EXPREGS[1]=~0;\r
+  EXPREGS[2]=1;\r
+  EXPREGS[3]=3;\r
+  GenMMC3Power();\r
+  SetWriteHandler(0x8000,0xFFFF,M199Write);\r
+}\r
+\r
+void Mapper199_Init(CartInfo *info)\r
+{\r
+  int CHRRAMSize=1024*8;\r
+  GenMMC3_Init(info, 512, 256, 8, info->battery);\r
+  cwrap=M199CW;\r
+  pwrap=M199PW;\r
+  mwrap=M199MW;\r
+  info->Power=M199Power;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
+  SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
+  AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+  AddExState(EXPREGS, 4, 0, "EXPR");\r
+}\r