cleanups, savestates, input (combos), menu
[fceu.git] / mappers / mmc2and4.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Xodnizel
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "mapinc.h"
22
23 #define MMC4reg mapbyte1
24 #define latcha1 mapbyte2[0]
25 #define latcha2 mapbyte2[1]
26
27
28 static void FP_FASTAPASS(1) latchcheck(uint32 VAddr)
29 {
30      uint8 l,h;
31
32      h=VAddr>>8;
33
34      if(h>=0x20 || ((h&0xF)!=0xF))
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
67 DECLFW(Mapper9_write)        // $Axxx
68 {
69  ROM_BANK8(0x8000,V);
70 }
71
72 DECLFW(Mapper10_write)
73 {
74  ROM_BANK16(0x8000,V);
75 }
76
77 DECLFW(Mapper9and10_write)
78 {
79        switch(A&0xF000)
80        {
81         case 0xB000:
82                 if(latcha1==0xFD) { VROM_BANK4(0x0000,V);}
83                 MMC4reg[0]=V;
84                 break;
85         case 0xC000:
86                 if(latcha1==0xFE) {VROM_BANK4(0x0000,V);}
87                 MMC4reg[1]=V;
88                 break;
89         case 0xD000:
90                 if(latcha2==0xFD) {VROM_BANK4(0x1000,V);}
91                 MMC4reg[2]=V;
92                 break;
93         case 0xE000:
94                 if(latcha2==0xFE) {VROM_BANK4(0x1000,V);}
95                 MMC4reg[3]=V;
96                 break;
97         case 0xF000:
98                 MIRROR_SET(V&1);
99                 break;
100         }
101 }
102
103 void 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);
110         SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
111         PPU_hook=latchcheck;
112 }
113
114 void Mapper10_init(void)
115 {
116         latcha1=latcha2=0xFE;
117         SetWriteHandler(0xA000,0xAFFF,Mapper10_write);
118         SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
119         PPU_hook=latchcheck;
120 }
121