merge mapper code from FCEUX
[fceu.git] / boards / 01-222.c
... / ...
CommitLineData
1/* FCE Ultra - NES/Famicom Emulator\r
2 *\r
3 * Copyright notice for this file:\r
4 * Copyright (C) 2006 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 * TXC mappers\r
20 */\r
21\r
22#include "mapinc.h"\r
23\r
24static uint8 reg[4], cmd, is172, is173;\r
25static SFORMAT StateRegs[]=\r
26{\r
27 {reg, 4, "REGS"},\r
28 {&cmd, 1, "CMD"},\r
29 {0}\r
30};\r
31\r
32static void Sync(void)\r
33{\r
34 setprg32(0x8000,(reg[2]>>2)&1);\r
35 if(is172)\r
36 setchr8((((cmd^reg[2])>>3)&2)|(((cmd^reg[2])>>5)&1)); // 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to\r
37 // rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary\r
38 else\r
39 setchr8(reg[2]&3);\r
40}\r
41\r
42static DECLFW(UNL22211WriteLo)\r
43{\r
44// FCEU_printf("bs %04x %02x\n",A,V);\r
45 reg[A&3]=V;\r
46}\r
47\r
48static DECLFW(UNL22211WriteHi)\r
49{\r
50// FCEU_printf("bs %04x %02x\n",A,V);\r
51 cmd=V;\r
52 Sync();\r
53}\r
54\r
55static DECLFR(UNL22211ReadLo)\r
56{\r
57 return (reg[1]^reg[2])|(is173?0x01:0x40);\r
58// if(reg[3])\r
59// return reg[2];\r
60// else\r
61// return X.DB;\r
62}\r
63\r
64static void UNL22211Power(void)\r
65{\r
66 Sync();\r
67 SetReadHandler(0x8000,0xFFFF,CartBR);\r
68 SetReadHandler(0x4100,0x4100,UNL22211ReadLo);\r
69 SetWriteHandler(0x4100,0x4103,UNL22211WriteLo);\r
70 SetWriteHandler(0x8000,0xFFFF,UNL22211WriteHi);\r
71}\r
72\r
73static void StateRestore(int version)\r
74{\r
75 Sync();\r
76}\r
77\r
78void UNL22211_Init(CartInfo *info)\r
79{\r
80 is172=0;\r
81 is173=0;\r
82 info->Power=UNL22211Power;\r
83 GameStateRestore=StateRestore;\r
84 AddExState(&StateRegs, ~0, 0, 0);\r
85}\r
86\r
87void Mapper172_Init(CartInfo *info)\r
88{\r
89 is172=1; \r
90 is173=0;\r
91 info->Power=UNL22211Power;\r
92 GameStateRestore=StateRestore;\r
93 AddExState(&StateRegs, ~0, 0, 0);\r
94}\r
95\r
96void Mapper173_Init(CartInfo *info)\r
97{\r
98 is172=0; \r
99 is173=1;\r
100 info->Power=UNL22211Power;\r
101 GameStateRestore=StateRestore;\r
102 AddExState(&StateRegs, ~0, 0, 0);\r
103}\r