merge mapper code from FCEUX
[fceu.git] / boards / 43.c
diff --git a/boards/43.c b/boards/43.c
new file mode 100644 (file)
index 0000000..ee12dec
--- /dev/null
@@ -0,0 +1,94 @@
+/* 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
+\r
+//ccording to nestopia, BTL_SMB2_C, otherwise known as UNL-SMB2J\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg;\r
+static uint8 IRQa;\r
+static uint32 IRQCount;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQCount, 4, "IRQC"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {&reg, 1, "REG"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  setprg4(0x5000,16);  \r
+  setprg8(0x6000,2);\r
+  setprg8(0x8000,1);\r
+  setprg8(0xa000,0);\r
+  setprg8(0xc000,reg);\r
+  setprg8(0xe000,9);\r
+  setchr8(0);\r
+}\r
+\r
+static DECLFW(M43Write)\r
+{\r
+  int transo[8]={4,3,4,4,4,7,5,6};\r
+  switch(A&0xf1ff)\r
+  {\r
+    case 0x4022: reg=transo[V&7]; Sync(); break;\r
+    case 0x8122: IRQa=V&1; IRQCount=0; break;\r
+  }\r
+}\r
+\r
+static void M43Power(void)\r
+{\r
+  reg=0;\r
+  Sync();\r
+//  SetReadHandler(0x5000,0x5fff,CartBR);\r
+  SetReadHandler(0x5000,0xffff,CartBR);\r
+  SetWriteHandler(0x4020,0xffff,M43Write);\r
+}\r
+\r
+static void M43Reset(void)\r
+{\r
+}\r
+\r
+static void M43IRQHook(int a)\r
+{\r
+ IRQCount+=a;\r
+ if(IRQa)\r
+  if(IRQCount>=4096)\r
+  {\r
+   IRQa=0;\r
+   X6502_IRQBegin(FCEU_IQEXT);\r
+  }\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper43_Init(CartInfo *info)\r
+{\r
+  info->Reset=M43Reset;\r
+  info->Power=M43Power;\r
+  MapIRQHook=M43IRQHook;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r