merge mappers from FCEU-mm
[fceu.git] / boards / bmc64in1nr.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2005 CaH4e3\r
5  *\r
6  * This program is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 2 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * This program is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program; if not, write to the Free Software\r
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19  *\r
20  * BMC 42-in-1 "reset switch" type\r
21  */\r
22 \r
23 #include "mapinc.h"\r
24 \r
25 static uint8 regs[4];\r
26 \r
27 static SFORMAT StateRegs[]=\r
28 {\r
29   {regs, 4, "REGS"},\r
30   {0}\r
31 };\r
32 \r
33 static void Sync(void)\r
34 {\r
35   if(regs[0]&0x80)\r
36   {\r
37     if(regs[1]&0x80)\r
38       setprg32(0x8000,regs[1]&0x1F);\r
39     else\r
40     {\r
41       int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);\r
42       setprg16(0x8000,bank);\r
43       setprg16(0xC000,bank);\r
44     }\r
45   }\r
46   else\r
47   {\r
48     int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);\r
49     setprg16(0xC000,bank);\r
50   }\r
51   if(regs[0]&0x20)\r
52     setmirror(MI_H);\r
53   else\r
54     setmirror(MI_V);\r
55   setchr8((regs[2]<<2)|((regs[0]>>1)&3));\r
56 }\r
57 \r
58 static DECLFW(BMC64in1nrWriteLo)\r
59 {\r
60   regs[A&3]=V;\r
61   Sync();\r
62 }\r
63 \r
64 static DECLFW(BMC64in1nrWriteHi)\r
65 {\r
66   regs[3]=V;\r
67   Sync();\r
68 }\r
69 \r
70 static void BMC64in1nrPower(void)\r
71 {\r
72   regs[0]=0x80;\r
73   regs[1]=0x43;\r
74   regs[2]=regs[3]=0;\r
75   Sync();\r
76   SetWriteHandler(0x5000,0x5003,BMC64in1nrWriteLo);\r
77   SetWriteHandler(0x8000,0xFFFF,BMC64in1nrWriteHi);\r
78   SetReadHandler(0x8000,0xFFFF,CartBR);\r
79 }\r
80 \r
81 static void StateRestore(int version)\r
82 {\r
83   Sync();\r
84 }\r
85 \r
86 void BMC64in1nr_Init(CartInfo *info)\r
87 {\r
88   info->Power=BMC64in1nrPower;\r
89   AddExState(&StateRegs, ~0, 0, 0);\r
90   GameStateRestore=StateRestore;\r
91 }\r
92 \r
93 \r