updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[fceu.git] / boards / datalatch.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 static uint8 latche;
24
25 //------------------ CPROM ---------------------------
26
27 static DECLFW(CPROMWrite)
28 {
29   latche=V&3;
30   setchr4(0x1000,latche);
31 }
32
33 static void CPROMReset(void)
34 {
35   setprg32(0x8000,0);
36   setchr8(0);
37   SetReadHandler(0x8000,0xFFFF,CartBR);
38   SetWriteHandler(0x8000,0xffff,CPROMWrite);
39 }
40
41 static void CPROMRestore(int version)
42 {
43   setchr4(0x1000,latche);
44 }
45
46 void CPROM_Init(CartInfo *info)
47 {
48   info->Power=CPROMReset;
49   GameStateRestore=CPROMRestore;
50   AddExState(&latche, 1, 0, "LATC");
51 }
52
53 //------------------ CNROM ---------------------------
54
55 DECLFW(CNROMWrite)
56 {
57   latche=V&3;
58   setchr8(latche);
59 }
60
61 static void CNROMReset(void)
62 {
63   setprg16(0x8000,0);
64   setprg16(0xC000,1);
65   SetReadHandler(0x8000,0xFFFF,CartBR);
66   SetWriteHandler(0x8000,0xffff,CNROMWrite);
67 }
68
69 static void CNROMRestore(int version)
70 {
71   setchr8(latche);
72 }
73
74 void CNROM_Init(CartInfo *info)
75 {
76   info->Power=CNROMReset;
77   GameStateRestore=CNROMRestore;
78   AddExState(&latche, 1, 0, "LATC");
79 }
80
81 //------------------ NROM128 ---------------------------
82
83 static void NROM128Reset(void)
84 {
85   setprg16(0x8000,0);
86   setprg16(0xC000,0);
87   setchr8(0);
88   SetReadHandler(0x8000,0xFFFF,CartBR);
89 }
90
91 void NROM128_Init(CartInfo *info)
92 {
93   info->Power=NROM128Reset;
94 }
95
96 //------------------ NROM256 ---------------------------
97
98 static void NROM256Reset(void)
99 {
100   setprg16(0x8000,0);
101   setprg16(0xC000,1);
102   setchr8(0);
103   SetReadHandler(0x8000,0xFFFF,CartBR);
104 }
105
106 void NROM256_Init(CartInfo *info)
107 {
108   info->Power=NROM256Reset;
109 }
110
111 //------------------ MHROM ---------------------------
112
113 static DECLFW(MHROMWrite)
114 {
115   setprg32(0x8000,V>>4);
116   setchr8(V);
117   latche=V;
118 }
119
120 static void MHROMReset(void)
121 {
122   setprg32(0x8000,0);
123   setchr8(0);
124   latche=0;
125   SetReadHandler(0x8000,0xFFFF,CartBR);
126 }
127
128 static void MHROMRestore(int version)
129 {
130   setprg32(0x8000,latche);
131   setchr8(latche);
132   SetWriteHandler(0x8000,0xffff,MHROMWrite);
133 }
134
135 void MHROM_Init(CartInfo *info)
136
137   info->Power=MHROMReset;
138   AddExState(&latche, 1, 0,"LATC");
139   PRGmask32[0]&=1;
140   CHRmask8[0]&=1;
141   GameStateRestore=MHROMRestore;
142 }
143
144 //------------------ UNROM ---------------------------
145
146 static void UNROMRestore(int version)
147 {
148   setprg16(0x8000,latche);
149 }
150
151 static DECLFW(UNROMWrite)
152 {
153   setprg16(0x8000,V);
154   latche=V;
155 }
156
157 static void UNROMReset(void)
158 {
159   setprg16(0x8000,0);
160   setprg16(0xc000,~0);
161   setchr8(0);
162   SetWriteHandler(0x8000,0xffff,UNROMWrite);
163   SetReadHandler(0x8000,0xFFFF,CartBR);
164   latche=0;
165 }
166
167 void UNROM_Init(CartInfo *info)
168 {
169   info->Power=UNROMReset;
170   PRGmask16[0]&=7;
171   AddExState(&latche, 1, 0, "LATC");
172   GameStateRestore=UNROMRestore;
173 }
174
175 //------------------ GNROM ---------------------------
176
177 static void GNROMSync()
178 {
179   setchr8(latche&3);
180   setprg32(0x8000,(latche>>4)&3);
181 }
182
183 static DECLFW(GNROMWrite)
184 {
185   latche=V&0x33;
186   GNROMSync();
187 }
188
189 static void GNROMStateRestore(int version)
190 {
191   GNROMSync();
192 }
193
194 static void GNROMReset(void)
195 {
196   latche=0;
197   GNROMSync();
198   SetWriteHandler(0x8000,0xffff,GNROMWrite);
199   SetReadHandler(0x8000,0xFFFF,CartBR);
200 }
201
202 void GNROM_Init(CartInfo *info)
203 {
204   info->Power=GNROMReset;
205   AddExState(&latche, 1, 0, "LATC");
206   GameStateRestore=GNROMStateRestore;
207 }