mapper fixes for ncpu, debug is broken atm
[fceu.git] / mappers / mmc2and4.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Ben Parnell
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  X6502_Rebase();
71 }
72
73 DECLFW(Mapper10_write)
74 {
75  ROM_BANK16(0x8000,V);
76  X6502_Rebase();
77 }
78
79 DECLFW(Mapper9and10_write)
80 {
81        switch(A&0xF000)
82        {
83         case 0xB000:
84                 if (latcha1==0xFD) { VROM_BANK4(0x0000,V);}
85                 MMC4reg[0]=V;
86                 break;
87         case 0xC000:
88                 if (latcha1==0xFE) {VROM_BANK4(0x0000,V);}
89                 MMC4reg[1]=V;
90                 break;
91         case 0xD000:
92                 if (latcha2==0xFD) {VROM_BANK4(0x1000,V);}
93                 MMC4reg[2]=V;
94                 break;
95         case 0xE000:
96                 if (latcha2==0xFE) {VROM_BANK4(0x1000,V);}
97                 MMC4reg[3]=V;
98                 break;
99         case 0xF000:
100                 MIRROR_SET(V&1);
101                 break;
102         }
103 }
104
105 void Mapper9_init(void)
106 {
107         latcha1=0xFE;
108         latcha2=0xFE;
109         ROM_BANK8(0xA000,~2);
110         ROM_BANK8(0x8000,0);
111         SetWriteHandler(0xA000,0xAFFF,Mapper9_write);
112         SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
113         PPU_hook=latchcheck;
114 }
115
116 void Mapper10_init(void)
117 {
118         latcha1=latcha2=0xFE;
119         SetWriteHandler(0xA000,0xAFFF,Mapper10_write);
120         SetWriteHandler(0xB000,0xFFFF,Mapper9and10_write);
121         PPU_hook=latchcheck;
122 }
123