--- /dev/null
+/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 reg_prg[4];\r
+static uint8 reg_chr[4];\r
+static uint8 dip_switch;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {reg_prg, 4, "PREGS"},\r
+ {reg_chr, 4, "CREGS"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ setprg8(0x8000,reg_prg[0]);\r
+ setprg8(0xa000,reg_prg[1]);\r
+ setprg8(0xc000,reg_prg[2]);\r
+ setprg8(0xe000,reg_prg[3]);\r
+ setchr2(0x0000,reg_chr[0]);\r
+ setchr2(0x0800,reg_chr[1]);\r
+ setchr2(0x1000,reg_chr[2]);\r
+ setchr2(0x1800,reg_chr[3]);\r
+ setmirror(MI_V);\r
+}\r
+\r
+static DECLFW(MBS5Write)\r
+{\r
+ int bank_sel = (A&0xC00)>>10;\r
+ switch (A&0xF000)\r
+ {\r
+ case 0x8000:\r
+ reg_chr[bank_sel]=A&0x1F;\r
+ break;\r
+ case 0xA000:\r
+ if(A&(1<<(dip_switch+4)))\r
+ reg_prg[bank_sel]=A&0x0F;\r
+ break;\r
+ }\r
+ Sync();\r
+}\r
+\r
+static void MBS5Reset(void)\r
+{\r
+ dip_switch++;\r
+ dip_switch&=3;\r
+ reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0; \r
+ Sync();\r
+}\r
+\r
+static void MBS5Power(void)\r
+{\r
+ dip_switch=0;\r
+ reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0; \r
+ Sync();\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+ SetWriteHandler(0x8000,0xFFFF,MBS5Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+ Sync();\r
+}\r
+\r
+void BMCBS5_Init(CartInfo *info)\r
+{\r
+ info->Power=MBS5Power;\r
+ info->Reset=MBS5Reset;\r
+ GameStateRestore=StateRestore;\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+}\r