merge mapper code from FCEUX
[fceu.git] / mappers / mmc2and4.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
d97315ac 4 * Copyright (C) 2002 Xodnizel
c62d2810 5 *
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.
10 *
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.
15 *
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
386f5371 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c62d2810 19 */
20
21#include "mapinc.h"
22
23#define MMC4reg mapbyte1
24#define latcha1 mapbyte2[0]
25#define latcha2 mapbyte2[1]
26
27
386f5371 28static void latchcheck(uint32 VAddr)
c62d2810 29{
30 uint8 l,h;
31
32 h=VAddr>>8;
33
c0bf6f9f 34 if(h>=0x20 || ((h&0xF)!=0xF))
c62d2810 35 return;
36
37 l=VAddr&0xF0;
38
39 if(h<0x10)
40 {
41 if(l==0xD0)
42 {
43 VROM_BANK4(0x0000,MMC4reg[0]);
44 latcha1=0xFD;
45 }
46 else if(l==0xE0)
47 {
48 VROM_BANK4(0x0000,MMC4reg[1]);
49 latcha1=0xFE;
50 }
51 }
52 else
53 {
54 if(l==0xD0)
55 {
56 VROM_BANK4(0x1000,MMC4reg[2]);
57 latcha2=0xFD;
58 }
59 else if(l==0xE0)
60 {
61 VROM_BANK4(0x1000,MMC4reg[3]);
62 latcha2=0xFE;
63 }
64 }
65}
66
d97315ac 67DECLFW(Mapper9_write) // $Axxx
c62d2810 68{
69 ROM_BANK8(0x8000,V);
70}
71
72DECLFW(Mapper10_write)
73{
74 ROM_BANK16(0x8000,V);
75}
76
77DECLFW(Mapper9and10_write)
78{
79 switch(A&0xF000)
80 {
81 case 0xB000:
d97315ac 82 if(latcha1==0xFD) { VROM_BANK4(0x0000,V);}
c62d2810 83 MMC4reg[0]=V;
84 break;
85 case 0xC000:
d97315ac 86 if(latcha1==0xFE) {VROM_BANK4(0x0000,V);}
c62d2810 87 MMC4reg[1]=V;
88 break;
89 case 0xD000:
d97315ac 90 if(latcha2==0xFD) {VROM_BANK4(0x1000,V);}
c62d2810 91 MMC4reg[2]=V;
92 break;
93 case 0xE000:
d97315ac 94 if(latcha2==0xFE) {VROM_BANK4(0x1000,V);}
c62d2810 95 MMC4reg[3]=V;
96 break;
97 case 0xF000:
98 MIRROR_SET(V&1);
99 break;
100 }
101}
102
103void Mapper9_init(void)
104{
105 latcha1=0xFE;
106 latcha2=0xFE;
107 ROM_BANK8(0xA000,~2);
108 ROM_BANK8(0x8000,0);
109 SetWriteHandler(0xA000,0xAFFF,Mapper9_write);
d97315ac 110 SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
c62d2810 111 PPU_hook=latchcheck;
112}
113
114void Mapper10_init(void)
115{
116 latcha1=latcha2=0xFE;
117 SetWriteHandler(0xA000,0xAFFF,Mapper10_write);
d97315ac 118 SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
c62d2810 119 PPU_hook=latchcheck;
120}
121