merge mapper code from FCEUX
[fceu.git] / boards / 830118C.c
1 /* FCE Ultra - NES/Famicom Emulator\r
2  *\r
3  * Copyright notice for this file:\r
4  *  Copyright (C) 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
19  */\r
20 \r
21 // M-022 MMC3 based 830118C T-106 4M + 4M\r
22 \r
23 #include "mapinc.h"\r
24 #include "mmc3.h"\r
25 \r
26 static uint8 reset_flag = 0;\r
27 \r
28 static void BMC830118CCW(uint32 A, uint8 V)\r
29 {\r
30     setchr1(A,(V&0x7F)|((EXPREGS[0]&0x0c)<<5));\r
31 }\r
32 \r
33 static void BMC830118CPW(uint32 A, uint8 V)\r
34 {\r
35       if((EXPREGS[0]&0x0C)==0x0C) \r
36       {  \r
37          if(A==0x8000)\r
38          {\r
39            setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));\r
40            setprg8(0xC000,(V&0x0F)|0x32);\r
41          }\r
42          else if(A==0xA000)\r
43          {\r
44            setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));\r
45            setprg8(0xE000,(V&0x0F)|0x32);\r
46          }\r
47       }\r
48       else\r
49       {\r
50          setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));\r
51       }\r
52 }\r
53 \r
54 static DECLFW(BMC830118CLoWrite)\r
55 {\r
56   EXPREGS[0] = V;\r
57   FixMMC3PRG(MMC3_cmd);\r
58   FixMMC3CHR(MMC3_cmd);\r
59 }\r
60 \r
61 static void BMC830118CReset(void)\r
62 {\r
63   EXPREGS[0]=0;\r
64   MMC3RegReset();\r
65 }\r
66 \r
67 static void BMC830118CPower(void)\r
68 {\r
69   EXPREGS[0] = 0;\r
70   GenMMC3Power();\r
71   SetWriteHandler(0x6800,0x68FF,BMC830118CLoWrite);\r
72 }\r
73 \r
74 void BMC830118C_Init(CartInfo *info)\r
75 {\r
76   GenMMC3_Init(info, 128, 128, 8, 0);\r
77   pwrap=BMC830118CPW;\r
78   cwrap=BMC830118CCW;\r
79   info->Power=BMC830118CPower;\r
80   info->Reset=BMC830118CReset;\r
81   AddExState(EXPREGS, 1, 0, "EXPR");\r
82 }\r