merge mapper code from FCEUX
[fceu.git] / boards / 187.c
CommitLineData
386f5371 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
19 */\r
20\r
21#include "mapinc.h"\r
22#include "mmc3.h"\r
23\r
24static void M187CW(uint32 A, uint8 V)\r
25{\r
26 if((A&0x1000)==((MMC3_cmd&0x80)<<5))\r
27 setchr1(A,V|0x100);\r
28 else\r
29 setchr1(A,V);\r
30}\r
31\r
32static void M187PW(uint32 A, uint8 V)\r
33{\r
34 if(EXPREGS[0]&0x80)\r
35 {\r
36 uint8 bank=EXPREGS[0]&0x1F;\r
37 if(EXPREGS[0]&0x20)\r
38 setprg32(0x8000,bank>>2);\r
39 else\r
40 {\r
41 setprg16(0x8000,bank);\r
42 setprg16(0xC000,bank);\r
43 }\r
44 }\r
45 else\r
46 setprg8(A,V&0x3F);\r
47}\r
48\r
49static DECLFW(M187Write8000)\r
50{\r
51 EXPREGS[2]=1;\r
52 MMC3_CMDWrite(A,V);\r
53}\r
54\r
55static DECLFW(M187Write8001)\r
56{\r
57 if(EXPREGS[2])\r
58 MMC3_CMDWrite(A,V);\r
59}\r
60\r
61static DECLFW(M187Write8003)\r
62{\r
63 EXPREGS[2]=0;\r
64 if(V==0x28)setprg8(0xC000,0x17);\r
65 else if(V==0x2A)setprg8(0xA000,0x0F);\r
66}\r
67\r
68\r
69static DECLFW(M187WriteLo)\r
70{\r
71 EXPREGS[1]=V;\r
72 if(A==0x5000)\r
73 {\r
74 EXPREGS[0]=V;\r
75 FixMMC3PRG(MMC3_cmd);\r
76 }\r
77}\r
78\r
79static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 };\r
80static DECLFR(M187Read)\r
81{\r
82 return prot_data[EXPREGS[1]&3];\r
83}\r
84\r
85static void M187Power(void)\r
86{\r
87 EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0;\r
88 GenMMC3Power();\r
89 SetReadHandler(0x5000,0x5FFF,M187Read);\r
90 SetWriteHandler(0x5000,0x5FFF,M187WriteLo);\r
91 SetWriteHandler(0x8000,0x8000,M187Write8000);\r
92 SetWriteHandler(0x8001,0x8001,M187Write8001);\r
93 SetWriteHandler(0x8003,0x8003,M187Write8003);\r
94}\r
95\r
96void Mapper187_Init(CartInfo *info)\r
97{\r
98 GenMMC3_Init(info, 256, 256, 0, 0);\r
99 pwrap=M187PW;\r
100 cwrap=M187CW;\r
101 info->Power=M187Power;\r
102 AddExState(EXPREGS, 3, 0, "EXPR");\r
103}\r