merge mappers from FCEU-mm
[fceu.git] / boards / KS7037.c
diff --git a/boards/KS7037.c b/boards/KS7037.c
new file mode 100644 (file)
index 0000000..d980a6f
--- /dev/null
@@ -0,0 +1,135 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2011 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;\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static void(*WSync)(void);\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&cmd, 1, "CMD"},\r
+  {reg, 8, "REGS"},\r
+  {0}\r
+};\r
+\r
+static void SyncKS7037(void)\r
+{\r
+  setprg4r(0x10,0x6000,0);\r
+  setprg4(0x7000,15);\r
+  setprg8(0x8000,reg[6]);\r
+  setprg4(0xA000,~3);\r
+  setprg4r(0x10,0xB000,1);\r
+  setprg8(0xC000,reg[7]);\r
+  setprg8(0xE000,~0);\r
+  setchr8(0);\r
+  setmirrorw(reg[2]&1,reg[4]&1,reg[3]&1,reg[5]&1);\r
+}\r
+\r
+static void SyncLH10(void)\r
+{\r
+  setprg8(0x6000,~1);\r
+  setprg8(0x8000,reg[6]);\r
+  setprg8(0xA000,reg[7]);\r
+  setprg8r(0x10,0xC000,0);\r
+  setprg8(0xE000,~0);\r
+  setchr8(0);\r
+  setmirror(0);\r
+}\r
+\r
+static DECLFW(UNLKS7037Write)\r
+{\r
+  switch(A & 0xE001)\r
+  {\r
+    case 0x8000: cmd = V & 7; break;\r
+    case 0x8001: reg[cmd] = V; WSync(); break;\r
+  }\r
+}\r
+\r
+static void UNLKS7037Power(void)\r
+{\r
+  reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0;\r
+  WSync();\r
+  SetReadHandler(0x6000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetWriteHandler(0x8000,0x9FFF,UNLKS7037Write);\r
+  SetWriteHandler(0xA000,0xBFFF,CartBW);\r
+  SetWriteHandler(0xC000,0xFFFF,UNLKS7037Write);\r
+}\r
+\r
+static void LH10Power(void)\r
+{\r
+  reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0;\r
+  WSync();\r
+  SetReadHandler(0x6000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xBFFF,UNLKS7037Write);\r
+  SetWriteHandler(0xC000,0xDFFF,CartBW);\r
+  SetWriteHandler(0xE000,0xFFFF,UNLKS7037Write);\r
+}\r
+\r
+static void Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  WSync();\r
+}\r
+\r
+void UNLKS7037_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLKS7037Power;\r
+  info->Close=Close;\r
+  \r
+  WSync = SyncKS7037;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void LH10_Init(CartInfo *info)\r
+{\r
+  info->Power=LH10Power;\r
+  info->Close=Close;\r
+  \r
+  WSync = SyncLH10;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r