1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Xodnizel
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 static uint8 latche, latcheinit, bus_conflict;
25 static uint16 addrreg0, addrreg1;
26 static uint8 *WRAM=NULL;
27 static uint32 WRAMSIZE;
28 static void(*WSync)(void);
30 static DECLFW(LatchWrite)
32 // FCEU_printf("bs %04x %02x\n",A,V);
40 static void LatchPower(void)
46 SetReadHandler(0x6000,0xFFFF,CartBR);
47 SetWriteHandler(0x6000,0x7FFF,CartBW);
51 SetReadHandler(0x8000,0xFFFF,CartBR);
53 SetWriteHandler(addrreg0,addrreg1,LatchWrite);
56 static void LatchClose(void)
63 static void StateRestore(int version)
68 static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc)
75 info->Power=LatchPower;
76 info->Close=LatchClose;
77 GameStateRestore=StateRestore;
81 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
82 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
85 info->SaveGame[0]=WRAM;
86 info->SaveGameLen[0]=WRAMSIZE;
88 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
90 AddExState(&latche, 1, 0, "LATC");
93 //------------------ CPROM ---------------------------
95 static void CPROMSync(void)
98 setchr4(0x1000,latche&3);
103 void CPROM_Init(CartInfo *info)
105 Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0);
108 //------------------ Map 184 ---------------------------
110 static void M184Sync(void)
112 setchr4(0x0000,latche);
113 setchr4(0x1000,latche>>4);
118 void Mapper184_Init(CartInfo *info)
120 Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0);
123 //------------------ CNROM ---------------------------
125 static void CNROMSync(void)
127 //mbg 8/10/08 - fixed this so that large homebrew roms would work.
132 setprg8r(0x10,0x6000,0); // Hayauchy IGO uses 2Kb or RAM
135 void CNROM_Init(CartInfo *info)
137 bool busc = MasterRomInfoParams.ContainsKey("busc");
138 Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, busc?1:0);
141 //------------------ ANROM ---------------------------
143 static void ANROMSync()
145 setprg32(0x8000,latche&0xf);
146 setmirror(MI_0+((latche>>4)&1));
150 void ANROM_Init(CartInfo *info)
152 Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF, 0, 0);
155 //------------------ Map 70 ---------------------------
157 static void M70Sync()
159 setprg16(0x8000,latche>>4);
164 void Mapper70_Init(CartInfo *info)
166 Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0);
169 //------------------ Map 152 ---------------------------
171 static void M152Sync()
173 setprg16(0x8000,(latche>>4)&7);
176 setmirror(MI_0+((latche>>7)&1)); /* Saint Seiya...hmm. */
179 void Mapper152_Init(CartInfo *info)
181 Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0);
184 //------------------ Map 78 ---------------------------
185 /* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */
186 static void M78Sync()
188 setprg16(0x8000,(latche&7));
191 setmirror(MI_0+((latche>>3)&1));
194 void Mapper78_Init(CartInfo *info)
196 Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0);
199 //------------------ MHROM ---------------------------
201 static void MHROMSync(void)
203 setprg32(0x8000,latche>>4);
207 void MHROM_Init(CartInfo *info)
209 Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0);
212 void Mapper140_Init(CartInfo *info)
214 Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0);
217 void Mapper240_Init(CartInfo *info)
219 Latch_Init(info, MHROMSync, 0, 0x4020, 0x5FFF, 0, 0);
223 //------------------ Map 87 ---------------------------
225 static void M87Sync(void)
229 setchr8(((latche>>1)&1)|((latche<<1)&2));
233 void Mapper87_Init(CartInfo *info)
235 Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0);
238 //------------------ Map 101 ---------------------------
240 static void M101Sync(void)
247 void Mapper101_Init(CartInfo *info)
249 Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0);
252 //------------------ Map 11 ---------------------------
254 static void M11Sync(void)
256 setprg32(0x8000,latche&0xf);
260 void Mapper11_Init(CartInfo *info)
262 Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0);
265 void Mapper144_Init(CartInfo *info)
267 Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0);
270 //------------------ Map 38 ---------------------------
272 static void M38Sync(void)
274 setprg32(0x8000,latche&3);
278 void Mapper38_Init(CartInfo *info)
280 Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF, 0, 0);
283 //------------------ Map 36 ---------------------------
285 static void M36Sync(void)
287 setprg32(0x8000,latche>>4);
288 setchr8((latche)&0xF);
291 void Mapper36_Init(CartInfo *info)
293 Latch_Init(info, M36Sync, 0, 0x8400, 0xfffe, 0, 0);
295 //------------------ UNROM ---------------------------
297 static void UNROMSync(void)
299 setprg16(0x8000,latche);
304 void UNROM_Init(CartInfo *info)
306 Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1);
309 //------------------ Map 93 ---------------------------
311 static void SSUNROMSync(void)
313 setprg16(0x8000,latche>>4);
318 void SUNSOFT_UNROM_Init(CartInfo *info)
320 Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0);
323 //------------------ Map 94 ---------------------------
325 static void M94Sync(void)
327 setprg16(0x8000,latche>>2);
332 void Mapper94_Init(CartInfo *info)
334 Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0);
337 //------------------ Map 180 ---------------------------
339 static void M180Sync(void)
342 setprg16(0xc000,latche);
346 void Mapper180_Init(CartInfo *info)
348 Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0);
351 //------------------ Map 107 ---------------------------
353 static void M107Sync(void)
355 setprg32(0x8000,(latche>>1)&3);
359 void Mapper107_Init(CartInfo *info)
361 Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0);
364 //------------------ Map 113 ---------------------------
366 static void M113Sync(void)
368 setprg32(0x8000,(latche>>3)&7);
369 setchr8(((latche>>3)&8)|(latche&7));
370 // setmirror(latche>>7); // only for HES 6in1
373 void Mapper113_Init(CartInfo *info)
375 Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0);
378 //------------------ A65AS ---------------------------
380 // actually, there is two cart in one... First have extra mirroring
381 // mode (one screen) and 32K bankswitching, second one have only
382 // 16 bankswitching mode and normal mirroring... But there is no any
383 // correlations between modes and they can be used in one mapper code.
385 static void BMCA65ASSync(void)
388 setprg32(0x8000,(latche>>1)&0x0F);
391 setprg16(0x8000,((latche&0x30)>>1)|(latche&7));
392 setprg16(0xC000,((latche&0x30)>>1)|7);
396 setmirror(MI_0+(((latche>>5)&1)));
398 setmirror(((latche>>3)&1)^1);
401 void BMCA65AS_Init(CartInfo *info)
403 Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0);
406 //------------------ NROM ---------------------------
409 static DECLFW(WriteHandler)
411 FCEU_printf("bs %04x %02x\n",A,V);
416 static void NROMPower(void)
418 setprg8r(0x10,0x6000,0); // Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB
423 SetReadHandler(0x6000,0x7FFF,CartBR);
424 SetWriteHandler(0x6000,0x7FFF,CartBW);
425 SetReadHandler(0x8000,0xFFFF,CartBR);
428 SetWriteHandler(0x4020,0xFFFF,WriteHandler);
432 void NROM_Init(CartInfo *info)
434 info->Power=NROMPower;
435 info->Close=LatchClose;
438 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
439 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
442 info->SaveGame[0]=WRAM;
443 info->SaveGameLen[0]=WRAMSIZE;
445 AddExState(WRAM, WRAMSIZE, 0, "WRAM");