initial fce ultra 0.81 import
[fceu.git] / mappers / simple.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 1998 BERO
5 * Copyright (C) 2002 Ben Parnell
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include "mapinc.h"
23
24static uint8 latche;
25
26static DECLFW(Mapper2_write)
27{
28 latche=V;
29 ROM_BANK16(0x8000,V);
30}
31
32void Mapper2_init(void)
33{
34 SetWriteHandler(0x8000,0xFFFF,Mapper2_write);
35 AddExState(&latche, 1, 0, "LATC");
36}
37
38static DECLFW(Mapper3_write)
39{
40 VROM_BANK8(V);
41 latche=V;
42}
43
44void Mapper3_init(void)
45{
46 SetWriteHandler(0x8000,0xFFFF,Mapper3_write);
47 AddExState(&latche, 1, 0, "LATC");
48}
49
50DECLFW(Mapper7_write)
51{
52 ROM_BANK32(V&0xF);
53 onemir((V>>4)&1);
54 latche=V;
55}
56
57void Mapper7_init(void)
58{
59 onemir(0);
60 SetWriteHandler(0x8000,0xFFFF,Mapper7_write);
61 AddExState(&latche, 1, 0, "LATC");
62}
63
64DECLFW(Mapper11_write)
65{
66 ROM_BANK32(V);
67 VROM_BANK8(V>>4);
68 latche=V;
69}
70
71void Mapper11_init(void)
72{
73 ROM_BANK32(0);
74 SetWriteHandler(0x8000,0xFFFF,Mapper11_write);
75 AddExState(&latche, 1, 0, "LATC");
76}
77
78static DECLFW(Mapper13_write)
79{
80 setchr4r(0x10,0x1000,V&3);
81 setprg32(0x8000,(V>>4)&3);
82 latche=V;
83}
84
85static void Mapper13_StateRestore(int version)
86{
87 setchr4r(0x10,0x0000,0);
88 setchr4r(0x10,0x1000,latche&3);
89 setprg32(0x8000,(latche>>4)&3);
90}
91
92void Mapper13_init(void)
93{
94 SetWriteHandler(0x8000,0xFFFF,Mapper13_write);
95 GameStateRestore=Mapper13_StateRestore;
96 AddExState(&latche, 1, 0, "LATC");
97 AddExState(MapperExRAM, 16384, 0, "CHRR");
98 SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1);
99
100 latche=0;
101 Mapper13_StateRestore(VERSION_NUMERIC);
102}
103
104DECLFW(Mapper34_write)
105{
106switch(A)
107 {
108 case 0x7FFD:ROM_BANK32(V);break;
109 case 0x7FFE:VROM_BANK4(0x0000,V);break;
110 case 0x7fff:VROM_BANK4(0x1000,V);break;
111 }
112if(A>=0x8000)
113 ROM_BANK32(V);
114}
115
116void Mapper34_init(void)
117{
118 SetWriteHandler(0x7ffd,0xffff,Mapper34_write);
119}
120
121DECLFW(Mapper66_write)
122{
123 VROM_BANK8(V&0xF);
124 ROM_BANK32((V>>4));
125 latche=V;
126}
127
128void Mapper66_init(void)
129{
130 ROM_BANK32(0);
131 SetWriteHandler(0x6000,0xffff,Mapper66_write);
132 AddExState(&latche, 1, 0, "LATC");
133}
134
135DECLFW(Mapper152_write)
136{
137 ROM_BANK16(0x8000,(V>>4)&0x7);
138 VROM_BANK8(V&0xF);
139 onemir((V>>7)&1); /* Saint Seiya...hmm. */
140 latche=V;
141}
142
143void Mapper152_init(void)
144{
145 onemir(0);
146 SetWriteHandler(0x6000,0xffff,Mapper152_write);
147 AddExState(&latche, 1, 0, "LATC");
148}
149
150static DECLFW(Mapper70_write)
151{
152 ROM_BANK16(0x8000,V>>4);
153 VROM_BANK8(V&0xF);
154 latche=V;
155}
156
157void Mapper70_init(void)
158{
159 SetWriteHandler(0x6000,0xffff,Mapper70_write);
160 AddExState(&latche, 1, 0, "LATC");
161}
162/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */
163static DECLFW(Mapper78_write)
164{
165 //printf("$%04x:$%02x\n",A,V);
166 ROM_BANK16(0x8000,V&0x7);
167 VROM_BANK8(V>>4);
168 onemir((V>>3)&1);
169 latche=V;
170}
171
172void Mapper78_init(void)
173{
174 SetWriteHandler(0x8000,0xffff,Mapper78_write);
175 AddExState(&latche, 1, 0, "LATC");
176}
177
178DECLFW(Mapper87_write)
179{
180 VROM_BANK8(V>>1);
181 latche=V;
182}
183
184void Mapper87_init(void)
185{
186 SetWriteHandler(0x6000,0xffff,Mapper87_write);
187 AddExState(&latche, 1, 0, "LATC");
188}
189
190DECLFW(Mapper93_write)
191{
192 ROM_BANK16(0x8000,V>>4);
193 MIRROR_SET(V&1);
194 latche=V;
195}
196
197void Mapper93_init(void)
198{
199 SetWriteHandler(0x8000,0xffff,Mapper93_write);
200 AddExState(&latche, 1, 0, "LATC");
201}
202
203
204DECLFW(Mapper94_write)
205{
206 ROM_BANK16(0x8000,V>>2);
207 latche=V;
208}
209
210void Mapper94_init(void)
211{
212 SetWriteHandler(0x8000,0xffff,Mapper94_write);
213 AddExState(&latche, 1, 0, "LATC");
214}
215
216/* I might want to add some code to the mapper 96 PPU hook function
217 to not change CHR banks if the attribute table is being accessed,
218 if I make emulation a little more accurate in the future.
219*/
220
221static uint8 M96LA;
222static DECLFW(Mapper96_write)
223{
224 latche=V;
225 setprg32(0x8000,V&3);
226 setchr4r(0x10,0x0000,(latche&4)|M96LA);
227 setchr4r(0x10,0x1000,(latche&4)|3);
228}
229
230static void FP_FASTAPASS(1) M96Hook(uint32 A)
231{
232 if(A<0x2000)
233 return;
234 M96LA=(A>>8)&3;
235 setchr4r(0x10,0x0000,(latche&4)|M96LA);
236}
237
238static void M96Sync()
239{
240 setprg32(0x8000,latche&3);
241 setchr4r(0x10,0x0000,(latche&4)|M96LA);
242 setchr4r(0x10,0x1000,(latche&4)|3);
243}
244
245void Mapper96_init(void)
246{
247 SetWriteHandler(0x8000,0xffff,Mapper96_write);
248 PPU_hook=M96Hook;
249 AddExState(&latche, 1, 0, "LATC");
250 AddExState(&M96LA, 1, 0, "LAVA");
251 SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1);
252 latche=M96LA=0;
253 M96Sync();
254 GameStateRestore=M96Sync;
255}
256
257static DECLFW(Mapper140_write)
258{
259 VROM_BANK8(V&0xF);
260 ROM_BANK32((V>>4)&0xF);
261}
262
263void Mapper140_init(void)
264{
265 ROM_BANK32(0);
266 SetWriteHandler(0x6000,0x7FFF,Mapper140_write);
267}
268
269static void M185Sync()
270{
271 int x;
272
273 if(!(mapbyte1[0]&3))
274// if(!(mapbyte1[0]==0x21))
275 {
276 for(x=0;x<8;x++)
277 setchr1r(0x10,x<<10,0);
278 }
279 else
280 setchr8(0);
281}
282
283static DECLFW(Mapper185_write)
284{
285 mapbyte1[0]=V;
286 M185Sync();
287 // printf("Wr: $%04x:$%02x\n",A,V);
288}
289
290void Mapper185_init(void)
291{
292 memset(MapperExRAM,0xFF,1024);
293 MapStateRestore=M185Sync;
294 mapbyte1[0]=0;
295 M185Sync();
296
297 SetupCartCHRMapping(0x10,MapperExRAM,1024,0);
298 SetWriteHandler(0x8000,0xFFFF,Mapper185_write);
299}