merge mappers from FCEU-mm
[fceu.git] / boards / vrc7.c
diff --git a/boards/vrc7.c b/boards/vrc7.c
new file mode 100644 (file)
index 0000000..67936dd
--- /dev/null
@@ -0,0 +1,134 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2009 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
+ * YOKO Mortal Kombat V Pro, VRC7 pirate clone\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg[3], chr[8], mirr;\r
+static uint8 IRQLatch, IRQa, IRQd;\r
+static uint32 IRQCount, CycleCount;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {prg, 3, "PRG"},\r
+  {chr, 8, "CHR"},\r
+  {&mirr, 1, "MIRR"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQd, 1, "IRQD"},\r
+  {&IRQLatch, 1, "IRQC"},\r
+  {&IRQCount, 4, "IRQC"},\r
+  {&CycleCount, 4, "CYCC"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  uint8 i;\r
+  setprg8(0x8000,prg[0]);\r
+  setprg8(0xa000,prg[1]);\r
+  setprg8(0xc000,prg[2]);\r
+  setprg8(0xe000,~0);\r
+  for(i=0; i<8; i++)\r
+    setchr1(i<<10,chr[i]);\r
+  switch(mirr&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(UNLVRC7Write)\r
+{\r
+  switch(A&0xF008)\r
+  {\r
+    case 0x8000: prg[0]=V; Sync(); break;\r
+    case 0x8008: prg[1]=V; Sync(); break;\r
+    case 0x9000: prg[2]=V; Sync(); break;\r
+    case 0xa000: chr[0]=V; Sync(); break;\r
+    case 0xa008: chr[1]=V; Sync(); break;\r
+    case 0xb000: chr[2]=V; Sync(); break;\r
+    case 0xb008: chr[3]=V; Sync(); break;\r
+    case 0xc000: chr[4]=V; Sync(); break;\r
+    case 0xc008: chr[5]=V; Sync(); break;\r
+    case 0xd000: chr[6]=V; Sync(); break;\r
+    case 0xd008: chr[7]=V; Sync(); break;\r
+    case 0xe000: mirr=V; Sync(); break;\r
+    case 0xe008:\r
+      IRQLatch=V;\r
+      X6502_IRQEnd(FCEU_IQEXT);\r
+      break;\r
+    case 0xf000:\r
+      IRQa=V&2;\r
+      IRQd=V&1;\r
+      if(V&2)\r
+        IRQCount=IRQLatch;\r
+      CycleCount=0;\r
+      X6502_IRQEnd(FCEU_IQEXT);\r
+      break;\r
+    case 0xf008:\r
+      if(IRQd)\r
+        IRQa=1;\r
+      else\r
+        IRQa=0;\r
+      X6502_IRQEnd(FCEU_IQEXT);\r
+      break;\r
+  } \r
+}\r
+\r
+static void UNLVRC7Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLVRC7Write);\r
+}\r
+\r
+static void UNLVRC7IRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    CycleCount+=a*3;\r
+    while(CycleCount>=341)\r
+    {\r
+      CycleCount-=341;\r
+      IRQCount++;\r
+      if(IRQCount==248)\r
+      {\r
+        X6502_IRQBegin(FCEU_IQEXT);\r
+        IRQCount=IRQLatch;\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLVRC7_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLVRC7Power;\r
+  MapIRQHook=UNLVRC7IRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r