-/* 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
- *
- * BMC 42-in-1 reset switch
- */
-
-#include "mapinc.h"
-
-static uint8 hrd_sw;
-static uint8 latche;
-static SFORMAT StateRegs[]=
-{
- {&latche, 1, "LATCHE"},
- {&hrd_sw, 1, "HRDSW"},
- {0}
-};
-
-static void Sync(void)
-{
- if(!(latche&0x20))
- setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f);
- else
- {
- setprg16r(hrd_sw,0x8000,latche&0x1f);
- setprg16r(hrd_sw,0xC000,latche&0x1f);
- }
- switch((latche>>6)&3)
- {
- case 0: setmirrorw(0,0,0,1); break;
- case 1: setmirror(MI_V); break;
- case 2: setmirror(MI_H); break;
- case 3: setmirror(MI_1); break;
- }
-}
-
-static DECLFW(BMC42in1rWrite)
-{
- latche=V;
- Sync();
-}
-
-static void BMC42in1rReset(void)
-{
- hrd_sw^=1;
- Sync();
-}
-
-static void BMC42in1rPower(void)
-{
- latche=0x00;
- hrd_sw=0;
- setchr8(0);
- Sync();
- SetWriteHandler(0x8000,0xFFFF,BMC42in1rWrite);
- SetReadHandler(0x8000,0xFFFF,CartBR);
-}
-
-static void StateRestore(int version)
-{
- Sync();
-}
-
-void BMC42in1r_Init(CartInfo *info)
-{
- info->Power=BMC42in1rPower;
- info->Reset=BMC42in1rReset;
- AddExState(&StateRegs, ~0, 0, 0);
- GameStateRestore=StateRestore;
-}
-
-
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ * Copyright (C) 2005 CaH4e3\r
+ * Copyright (C) 2009 qeed\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
+ * BMC 42-in-1 "reset switch" + "select switch"\r
+ *\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 isresetbased = 0;\r
+static uint8 latche[2], reset;\r
+static SFORMAT StateRegs[]=\r
+{\r
+ {&reset, 1, "RST"},\r
+ {latche, 2, "LATC"},\r
+ {0}\r
+};\r
+\r
+static void Sync(void)\r
+{\r
+ uint8 bank;\r
+ if(isresetbased)\r
+ bank = (latche[0]&0x1f)|(reset<<5)|((latche[1]&1)<<6);\r
+ else\r
+ bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1)<<6);\r
+ if(!(latche[0] & 0x20))\r
+ setprg32(0x8000,bank >> 1);\r
+ else\r
+ {\r
+ setprg16(0x8000,bank);\r
+ setprg16(0xC000,bank);\r
+ }\r
+ setmirror((latche[0]>>6)&1);\r
+ setchr8(0);\r
+}\r
+\r
+static DECLFW(M226Write)\r
+{\r
+ latche[A & 1] = V;\r
+ Sync();\r
+}\r
+\r
+static void M226Power(void)\r
+{\r
+ latche[0] = latche[1] = reset = 0;\r
+ Sync();\r
+ SetWriteHandler(0x8000,0xFFFF,M226Write);\r
+ SetReadHandler(0x8000,0xFFFF,CartBR);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+ Sync();\r
+}\r
+\r
+void Mapper226_Init(CartInfo *info)\r
+{\r
+ isresetbased = 0;\r
+ info->Power=M226Power;\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+ GameStateRestore=StateRestore;\r
+}\r
+\r
+static void BMC42in1Reset(void)\r
+{\r
+ reset ^= 1;\r
+ Sync();\r
+}\r
+\r
+void BMC42in1r_Init(CartInfo *info)\r
+{\r
+ isresetbased = 1;\r
+ info->Power=M226Power;\r
+ info->Reset=BMC42in1Reset;\r
+ AddExState(&StateRegs, ~0, 0, 0);\r
+ GameStateRestore=StateRestore;\r
+}\r