merge mappers from FCEU-mm
[fceu.git] / boards / KS7032.c
diff --git a/boards/KS7032.c b/boards/KS7032.c
new file mode 100644 (file)
index 0000000..c93fc15
--- /dev/null
@@ -0,0 +1,97 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * FDS Conversion\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[8], cmd, IRQa = 0, isirqused = 0;\r
+static int32 IRQCount;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&cmd, 1, "CMD"},\r
+  {reg, 8, "REGS"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&IRQCount, 4, "IRQC"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg8(0x6000,reg[4]);\r
+  setprg8(0x8000,reg[1]);\r
+  setprg8(0xA000,reg[2]);\r
+  setprg8(0xC000,reg[3]);\r
+  setprg8(0xE000,~0);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(UNLKS7032Write)\r
+{\r
+//  FCEU_printf("bs %04x %02x\n",A,V);\r
+  switch(A&0xF000)\r
+  {\r
+//    case 0x8FFF: reg[4]=V; Sync(); break;\r
+    case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); isirqused = 1; break;\r
+    case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); isirqused = 1; break;\r
+    case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); isirqused = 1; break;\r
+    case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); isirqused = 1; break;\r
+    case 0xC000: if(isirqused) { X6502_IRQEnd(FCEU_IQEXT); IRQa=1; } break;\r
+    case 0xE000: cmd=V&7; break;\r
+    case 0xF000: reg[cmd]=V; Sync(); break;\r
+  }\r
+}\r
+\r
+static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount+=a;\r
+    if(IRQCount>=0xFFFF)\r
+    {\r
+      IRQa=0;\r
+      IRQCount=0;\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+    }\r
+  }\r
+}\r
+\r
+static void UNLKS7032Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLKS7032_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLKS7032Power;\r
+  MapIRQHook=UNLSMB2JIRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r