updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[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
d97315ac 5 * Copyright (C) 2002 Xodnizel
c62d2810 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 */
d97315ac 21
c62d2810 22#include "mapinc.h"
23
24static uint8 latche;
25
d97315ac 26//static DECLFW(Mapper2_write)
27//{
28// latche=V;
29// ROM_BANK16(0x8000,V);
30//}
31//
32//void Mapper2_init(void)
33//{
34// SetWriteHandler(0x8000,0xFFFF,Mapper2_write);
35// AddExState(&latche, 1, 0, "LATC");
36//}
37
38//static DECLFW(Mapper3_write)
39//{
40// VROM_BANK8(V);
41// latche=V;
42//}
43
44//void Mapper3_init(void)
45//{
46// SetWriteHandler(0x8000,0xFFFF,Mapper3_write);
47// AddExState(&latche, 1, 0, "LATC");
48//}
49
50static DECLFW(Mapper7_write)
51{
52// FCEU_printf("%04x,%04x\n",A,V);
c62d2810 53 ROM_BANK32(V&0xF);
54 onemir((V>>4)&1);
55 latche=V;
56}
57
58void Mapper7_init(void)
59{
60 onemir(0);
5232c20c 61 ROM_BANK32(0);
c62d2810 62 SetWriteHandler(0x8000,0xFFFF,Mapper7_write);
d97315ac 63 AddExState(&latche, 1, 0, "LATC");
c62d2810 64}
65
d97315ac 66static DECLFW(Mapper11_write)
c62d2810 67{
d97315ac 68 ROM_BANK32(V&0xF);
c62d2810 69 VROM_BANK8(V>>4);
d97315ac 70 latche=V;
c62d2810 71}
72
73void Mapper11_init(void)
74{
75 ROM_BANK32(0);
d97315ac 76 SetWriteHandler(0x8000,0xFFFF,Mapper11_write);
77 AddExState(&latche, 1, 0, "LATC");
78}
79void Mapper144_init(void)
80{
81 ROM_BANK32(0);
82 SetWriteHandler(0x8001,0xFFFF,Mapper11_write);
83 AddExState(&latche, 1, 0, "LATC");
84
85}
86//static DECLFW(Mapper13_write)
87//{
88// setchr4r(0x10,0x1000,V&3);
89// setprg32(0x8000,(V>>4)&3);
90// latche=V;
91//}
92
93//static void Mapper13_StateRestore(int version)
94//{
95// setchr4r(0x10,0x0000,0);
96// setchr4r(0x10,0x1000,latche&3);
97// setprg32(0x8000,(latche>>4)&3);
98//}
99
100//void Mapper13_init(void)
101//{
102// SetWriteHandler(0x8000,0xFFFF,Mapper13_write);
103// GameStateRestore=Mapper13_StateRestore;
104// AddExState(&latche, 1, 0, "LATC");
105// AddExState(MapperExRAM, 16384, 0, "CHRR");
106// SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1);
107// latche=0;
108// Mapper13_StateRestore(FCEU_VERSION_NUMERIC);
109//}
110
111static DECLFW(Mapper34_write)
112{
113 switch(A)
c62d2810 114 {
d97315ac 115 case 0x7FFD:ROM_BANK32(V);break;
116 case 0x7FFE:VROM_BANK4(0x0000,V);break;
117 case 0x7fff:VROM_BANK4(0x1000,V);break;
c62d2810 118 }
c0bf6f9f 119 if(A>=0x8000)
c0bf6f9f 120 ROM_BANK32(V);
c62d2810 121}
122
123void Mapper34_init(void)
124{
d97315ac 125 ROM_BANK32(0);
c62d2810 126 SetWriteHandler(0x7ffd,0xffff,Mapper34_write);
127}
128
129DECLFW(Mapper66_write)
130{
131 VROM_BANK8(V&0xF);
132 ROM_BANK32((V>>4));
133 latche=V;
134}
135
136void Mapper66_init(void)
137{
138 ROM_BANK32(0);
139 SetWriteHandler(0x6000,0xffff,Mapper66_write);
140 AddExState(&latche, 1, 0, "LATC");
141}
142
143DECLFW(Mapper152_write)
144{
145 ROM_BANK16(0x8000,(V>>4)&0x7);
146 VROM_BANK8(V&0xF);
d97315ac 147 onemir((V>>7)&1); /* Saint Seiya...hmm. */
c62d2810 148 latche=V;
149}
150
151void Mapper152_init(void)
152{
153 onemir(0);
154 SetWriteHandler(0x6000,0xffff,Mapper152_write);
155 AddExState(&latche, 1, 0, "LATC");
156}
157
158static DECLFW(Mapper70_write)
159{
160 ROM_BANK16(0x8000,V>>4);
161 VROM_BANK8(V&0xF);
162 latche=V;
163}
164
165void Mapper70_init(void)
166{
167 SetWriteHandler(0x6000,0xffff,Mapper70_write);
168 AddExState(&latche, 1, 0, "LATC");
169}
170/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */
171static DECLFW(Mapper78_write)
172{
d97315ac 173 //printf("$%04x:$%02x\n",A,V&0x8);
c62d2810 174 ROM_BANK16(0x8000,V&0x7);
175 VROM_BANK8(V>>4);
176 onemir((V>>3)&1);
177 latche=V;
178}
179
180void Mapper78_init(void)
181{
182 SetWriteHandler(0x8000,0xffff,Mapper78_write);
183 AddExState(&latche, 1, 0, "LATC");
184}
185
186DECLFW(Mapper87_write)
187{
188 VROM_BANK8(V>>1);
189 latche=V;
190}
191
192void Mapper87_init(void)
193{
194 SetWriteHandler(0x6000,0xffff,Mapper87_write);
195 AddExState(&latche, 1, 0, "LATC");
196}
197
198DECLFW(Mapper93_write)
199{
200 ROM_BANK16(0x8000,V>>4);
201 MIRROR_SET(V&1);
202 latche=V;
203}
204
205void Mapper93_init(void)
206{
207 SetWriteHandler(0x8000,0xffff,Mapper93_write);
208 AddExState(&latche, 1, 0, "LATC");
209}
210
211
212DECLFW(Mapper94_write)
213{
214 ROM_BANK16(0x8000,V>>2);
215 latche=V;
216}
217
218void Mapper94_init(void)
219{
220 SetWriteHandler(0x8000,0xffff,Mapper94_write);
221 AddExState(&latche, 1, 0, "LATC");
222}
223
224/* I might want to add some code to the mapper 96 PPU hook function
225 to not change CHR banks if the attribute table is being accessed,
226 if I make emulation a little more accurate in the future.
227*/
228
229static uint8 M96LA;
230static DECLFW(Mapper96_write)
231{
232 latche=V;
233 setprg32(0x8000,V&3);
234 setchr4r(0x10,0x0000,(latche&4)|M96LA);
235 setchr4r(0x10,0x1000,(latche&4)|3);
236}
237
238static void FP_FASTAPASS(1) M96Hook(uint32 A)
239{
d97315ac 240 if((A&0x3000)!=0x2000) return;
241 //if((A&0x3ff)>=0x3c0) return;
c62d2810 242 M96LA=(A>>8)&3;
243 setchr4r(0x10,0x0000,(latche&4)|M96LA);
244}
245
d97315ac 246static void M96Sync(int v)
c62d2810 247{
248 setprg32(0x8000,latche&3);
249 setchr4r(0x10,0x0000,(latche&4)|M96LA);
250 setchr4r(0x10,0x1000,(latche&4)|3);
251}
252
253void Mapper96_init(void)
254{
255 SetWriteHandler(0x8000,0xffff,Mapper96_write);
256 PPU_hook=M96Hook;
257 AddExState(&latche, 1, 0, "LATC");
258 AddExState(&M96LA, 1, 0, "LAVA");
259 SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1);
260 latche=M96LA=0;
d97315ac 261 M96Sync(0);
262 setmirror(MI_0);
c62d2810 263 GameStateRestore=M96Sync;
264}
265
266static DECLFW(Mapper140_write)
267{
268 VROM_BANK8(V&0xF);
269 ROM_BANK32((V>>4)&0xF);
270}
271
272void Mapper140_init(void)
273{
274 ROM_BANK32(0);
275 SetWriteHandler(0x6000,0x7FFF,Mapper140_write);
276}
277
d97315ac 278static void M185Sync(int version)
c62d2810 279{
d97315ac 280// on off
281//1 0x0F, 0xF0 - Bird Week
282//2 0x33, 0x00 - B-Wings
283//3 0x11, 0x00 - Mighty Bomb Jack
284//4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen
285//5 0xFF, 0x00 - Sansuu 3 Nen
286//6 0x21, 0x13 - Spy vs Spy
c62d2810 287
d97315ac 288// if((mapbyte1[0]&3)==1) // 6, 3
289// if(mapbyte1[0]&1) // 1, 2, 3, 5
290// if(mapbyte1[0]&2) // 1, 2, 4, 5,
291 if((mapbyte1[0]&2)||((mapbyte1[0]&3)==1)) // 1, 2, 3, 4, 5
292 setchr8(0);
293 else
294 setchr8r(0x10,0);
c62d2810 295}
296
297static DECLFW(Mapper185_write)
298{
d97315ac 299 mapbyte1[0]=V;
300 M185Sync(0);
c62d2810 301}
302
303void Mapper185_init(void)
304{
d97315ac 305 int x;
306 for(x=0;x<8192;x++)
307 MapperExRAM[x]=0xff;
308 MapStateRestore=M185Sync;
309 mapbyte1[0]=0;
310 M185Sync(0);
311 SetupCartCHRMapping(0x10,MapperExRAM,8192,0);
312 SetWriteHandler(0x8000,0xFFFF,Mapper185_write);
313}
314
c62d2810 315
d97315ac 316static DECLFW(M156Write)
317{
318 if(A>=0xc000 && A<=0xC003)
319 VROM_BANK1((A&3)*1024,V);
320 else if(A>=0xc008 && A<=0xc00b)
321 VROM_BANK1(0x1000+(A&3)*1024,V);
322 if(A==0xc010) ROM_BANK16(0x8000,V);
323// printf("$%04x:$%02x\n",A,V);
c62d2810 324}
d97315ac 325
326void Mapper156_init(void)
327{
328 onemir(0);
329 SetWriteHandler(0xc000,0xc010,M156Write);
330}
331
332static DECLFW(m107w)
333{
334 ROM_BANK32((V>>1)&0x3);
335 VROM_BANK8(V&0x7);
336}
337
338void Mapper107_init(void)
339{
340 SetWriteHandler(0x8000,0xffff,m107w);
341}
342