bcbdfc1a3b098fb3b0cc55db07c270589d47c2ba
[fceu.git] / boards / bmc42in1r.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2005 CaH4e3\r
5  *  Copyright (C) 2009 qeed\r
6  *\r
7  * This program is free software; you can redistribute it and/or modify\r
8  * it under the terms of the GNU General Public License as published by\r
9  * the Free Software Foundation; either version 2 of the License, or\r
10  * (at your option) any later version.\r
11  *\r
12  * This program is distributed in the hope that it will be useful,\r
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15  * GNU General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU General Public License\r
18  * along with this program; if not, write to the Free Software\r
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
20  *\r
21  * BMC 42-in-1\r
22  * it seems now, mapper not reset-based,\r
23  * tested on real hardware and it does menus switch by pressing just Select, not Reset\r
24  * new registers behaviour proven this too\r
25  *\r
26  */\r
27 \r
28 #include "mapinc.h"\r
29 \r
30 static uint8 latche[2];\r
31 static SFORMAT StateRegs[]=\r
32 {\r
33   {&latche, sizeof(latche), "LATCHE"},\r
34   {0}\r
35 };\r
36 \r
37 static void Sync(void)\r
38 {\r
39   uint8 bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1))<<6;\r
40   if(!(latche[0] & 0x20))\r
41       setprg32(0x8000,bank >> 1);\r
42   else\r
43   {\r
44       setprg16(0x8000,bank);\r
45       setprg16(0xC000,bank);\r
46   }\r
47   setmirror((latche[0]>>6)&1);\r
48   setchr8(0);\r
49 }\r
50 \r
51 static DECLFW(M226Write)\r
52 {\r
53     latche[A & 1] = V;\r
54     Sync();\r
55 }\r
56 \r
57 static void M226Power(void)\r
58 {\r
59   latche[0] = latche[1] = 0;\r
60   Sync();\r
61   SetWriteHandler(0x8000,0xFFFF,M226Write);\r
62   SetReadHandler(0x8000,0xFFFF,CartBR);\r
63 }\r
64 \r
65 static void StateRestore(int version)\r
66 {\r
67   Sync();\r
68 }\r
69 \r
70 void Mapper226_Init(CartInfo *info)\r
71 {\r
72   info->Power=M226Power;\r
73   AddExState(&StateRegs, ~0, 0, 0);\r
74   GameStateRestore=StateRestore;\r
75 }\r
76 \r