merge mappers from FCEU-mm
[fceu.git] / boards / pec-586.c
diff --git a/boards/pec-586.c b/boards/pec-586.c
new file mode 100644 (file)
index 0000000..a810197
--- /dev/null
@@ -0,0 +1,124 @@
+/* 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
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg[7];\r
+static uint8 *WRAM=NULL;\r
+static uint32 WRAMSIZE;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {reg, 2, "REG"},\r
+  {0}\r
+};\r
+\r
+static uint8 bs_tbl[128] = {\r
+  0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33,\r
+  0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67,\r
+  0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33,\r
+  0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67,\r
+  0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32,\r
+  0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67,\r
+  0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30,\r
+  0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67,\r
+};\r
+\r
+static uint8 br_tbl[16] = {\r
+  0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, \r
+};\r
+\r
+static void Sync(void)\r
+{\r
+//  setchr4(0x0000,(reg[0]&0x80) >> 7);\r
+//  setchr4(0x1000,(reg[0]&0x80) >> 7);\r
+  setchr8(0);\r
+  setprg8r(0x10,0x6000,0);\r
+  setprg16(0x8000,bs_tbl[reg[0]&0x7f]>>4);\r
+  setprg16(0xc000,bs_tbl[reg[0]&0x7f]&0xf);\r
+  setmirror(MI_V);\r
+}\r
+\r
+static DECLFW(UNLPEC586Write)\r
+{\r
+  reg[(A&0x700)>>8]=V;\r
+  FCEU_printf("bs %04x %02x\n",A,V);\r
+  Sync();\r
+}\r
+\r
+static DECLFR(UNLPEC586Read)\r
+{\r
+  FCEU_printf("read %04x\n",A);\r
+  return (X.DB & 0xD8) | br_tbl[reg[4]>>4];\r
+}\r
+\r
+static void UNLPEC586Power(void)\r
+{\r
+  reg[0]=0x0E;\r
+  Sync();\r
+  setchr8(0);\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SetWriteHandler(0x6000,0x7FFF,CartBW);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x5000,0x5fff,UNLPEC586Write);\r
+  SetReadHandler(0x5000,0x5fff,UNLPEC586Read);\r
+}\r
+\r
+static void UNLPEC586IRQ(void)\r
+{\r
+//  if(reg[0]&0x80)\r
+  {\r
+    if(scanline==128) {\r
+      setchr4(0x0000,1);\r
+      setchr4(0x1000,0);\r
+    }\r
+    else {\r
+      setchr4(0x0000,0);\r
+      setchr4(0x1000,1);\r
+    }\r
+  }\r
+}\r
+\r
+static void UNLPEC586Close(void)\r
+{\r
+  if(WRAM)\r
+    FCEU_gfree(WRAM);\r
+  WRAM=NULL;\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLPEC586Init(CartInfo *info)\r
+{\r
+  info->Power=UNLPEC586Power;\r
+  info->Close=UNLPEC586Close;\r
+  GameHBIRQHook=UNLPEC586IRQ;\r
+  GameStateRestore=StateRestore;\r
+\r
+  WRAMSIZE=8192;\r
+  WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);\r
+  SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);\r
+  AddExState(WRAM, WRAMSIZE, 0, "WRAM");\r
+\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r