merge mapper code from FCEUX
[fceu.git] / boards / bmc70in1.c
index 9d4eb28..75baaa5 100644 (file)
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2005 CaH4e3
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#include "mapinc.h"
-
-static uint8 is_large_banks;
-static uint8 large_bank;
-static uint8 prg_bank;
-static uint8 chr_bank;
-static uint8 bank_mode;
-static uint8 mirroring;
-static SFORMAT StateRegs[]=
-{
-  {&large_bank, 1, "LB"},
-  {&prg_bank, 1, "PRG"},
-  {&chr_bank, 1, "CHR"},
-  {&bank_mode, 1, "BM"},
-  {&mirroring, 1, "MIRR"},
-  {0}
-};
-
-static void Sync(void)
-{
-  switch (bank_mode)
-  {
-    case 0x00:
-    case 0x10: setprg16(0x8000,large_bank|prg_bank);
-               setprg16(0xC000,large_bank|7);
-               break;
-    case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1);
-               break;
-    case 0x30: setprg16(0x8000,large_bank|prg_bank);
-               setprg16(0xC000,large_bank|prg_bank);
-               break;
-  }
-  setmirror(mirroring);
-  if(!is_large_banks)
-    setchr8(chr_bank);
-}
-
-static DECLFR(BMC70in1Read)
-{
-  if(bank_mode==0x10)
-    if(is_large_banks)
-      return CartBR((A&0xFFF0)|0x06);
-    else
-      return CartBR((A&0xFFF0)|0x0d);
-  else
-    return CartBR(A);
-}
-
-static DECLFW(BMC70in1Write)
-{
-  if(A&0x4000)
-  {
-    bank_mode=A&0x30;
-    prg_bank=A&7;
-  }
-  else
-  {
-    mirroring=((A&0x20)>>5)^1;
-    if(is_large_banks)
-      large_bank=(A&3)<<3;
-    else
-      chr_bank=A&7;
-  }
-  Sync();
-}
-
-static void BMC70in1Power(void)
-{
-  setchr8(0);
-  bank_mode=0;
-  large_bank=0;
-  Sync();
-  SetReadHandler(0x8000,0xFFFF,BMC70in1Read);
-  SetWriteHandler(0x8000,0xffff,BMC70in1Write);
-}
-
-static void StateRestore(int version)
-{
-  Sync();
-}
-
-void BMC70in1_Init(CartInfo *info)
-{
-  is_large_banks=0;
-  info->Power=BMC70in1Power;
-  GameStateRestore=StateRestore;
-  AddExState(&StateRegs, ~0, 0, 0);
-}
-
-void BMC70in1B_Init(CartInfo *info)
-{
-  is_large_banks=1;
-  info->Power=BMC70in1Power;
-  GameStateRestore=StateRestore;
-  AddExState(&StateRegs, ~0, 0, 0);
-}
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 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
+#include "mapinc.h"\r
+\r
+static uint8 is_large_banks, hw_switch;\r
+static uint8 large_bank;\r
+static uint8 prg_bank;\r
+static uint8 chr_bank;\r
+static uint8 bank_mode;\r
+static uint8 mirroring;\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&large_bank, 1, "LB"},\r
+  {&hw_switch, 1, "DIPSW"},\r
+  {&prg_bank, 1, "PRG"},\r
+  {&chr_bank, 1, "CHR"},\r
+  {&bank_mode, 1, "BM"},\r
+  {&mirroring, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+  switch (bank_mode)\r
+  {\r
+    case 0x00:\r
+    case 0x10: setprg16(0x8000,large_bank|prg_bank);\r
+               setprg16(0xC000,large_bank|7);\r
+               break;\r
+    case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1);\r
+               break;\r
+    case 0x30: setprg16(0x8000,large_bank|prg_bank);\r
+               setprg16(0xC000,large_bank|prg_bank);\r
+               break;\r
+  }\r
+  setmirror(mirroring);\r
+  if(!is_large_banks)\r
+    setchr8(chr_bank);\r
+}\r
+\r
+static DECLFR(BMC70in1Read)\r
+{\r
+  if(bank_mode==0x10)\r
+//    if(is_large_banks)\r
+      return CartBR((A&0xFFF0)|hw_switch);\r
+//    else\r
+//      return CartBR((A&0xFFF0)|hw_switch);\r
+  else\r
+    return CartBR(A);\r
+}\r
+\r
+static DECLFW(BMC70in1Write)\r
+{\r
+  if(A&0x4000)\r
+  {\r
+    bank_mode=A&0x30;\r
+    prg_bank=A&7;\r
+  }\r
+  else\r
+  {\r
+    mirroring=((A&0x20)>>5)^1;\r
+    if(is_large_banks)\r
+      large_bank=(A&3)<<3;\r
+    else\r
+      chr_bank=A&7;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void BMC70in1Reset(void)\r
+{\r
+  bank_mode=0;\r
+  large_bank=0;\r
+  Sync();\r
+  hw_switch++;\r
+  hw_switch&=0xf;\r
+}\r
+\r
+static void BMC70in1Power(void)\r
+{\r
+  setchr8(0);\r
+  bank_mode=0;\r
+  large_bank=0;\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,BMC70in1Read);\r
+  SetWriteHandler(0x8000,0xffff,BMC70in1Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void BMC70in1_Init(CartInfo *info)\r
+{\r
+  is_large_banks=0;\r
+  hw_switch=0xd;\r
+  info->Power=BMC70in1Power;\r
+  info->Reset=BMC70in1Reset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r
+\r
+void BMC70in1B_Init(CartInfo *info)\r
+{\r
+  is_large_banks=1;\r
+  hw_switch=0x6;\r
+  info->Power=BMC70in1Power;\r
+  info->Reset=BMC70in1Reset;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r