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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 static uint8 latch[8];
26 static void S74LS374MSync(uint8 mirr)
30 case 0:setmirror(MI_V);break;
31 case 1:setmirror(MI_H);break;
32 case 2:setmirrorw(0,1,1,1);break;
33 case 3:setmirror(MI_0);break;
37 static void S74LS374NSynco(void)
39 setprg32(0x8000,latch[0]);
40 setchr8(latch[1]|latch[3]|latch[4]);
41 S74LS374MSync(latch[2]);
44 static DECLFW(S74LS374NWrite)
53 case 2:latch[0]=V&1; latch[3]=(V&1)<<3;break;
54 case 4:latch[4]=(V&1)<<2;break;
55 case 5:latch[0]=V&7;break;
56 case 6:latch[1]=V&3;break;
57 case 7:latch[2]=V>>1;break;
63 static DECLFR(S74LS374NRead)
66 if((A&0x4100)==0x4100)
67 ret=(X.DB&0xC0)|((~cmd)&0x3F);
73 static void S74LS374NPower(void)
75 latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
77 SetReadHandler(0x8000,0xFFFF,CartBR);
78 SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
79 SetReadHandler(0x4100,0x5fff,S74LS374NRead);
82 static void S74LS374NRestore(int version)
87 void S74LS374N_Init(CartInfo *info)
89 info->Power=S74LS374NPower;
90 GameStateRestore=S74LS374NRestore;
91 AddExState(latch, 5, 0, "LATC");
92 AddExState(&cmd, 1, 0, "CMD");
95 static void S74LS374NASynco(void)
97 setprg32(0x8000,latch[0]);
99 S74LS374MSync(latch[2]);
102 static DECLFW(S74LS374NAWrite)
111 case 0:latch[0]=0;latch[1]=3;break;
112 case 2:latch[3]=(V&1)<<3;break;
113 case 4:latch[1]=(latch[1]&6)|(V&3);break;
114 case 5:latch[0]=V&1;break;
115 case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break;
116 case 7:latch[2]=V&1;break;
122 static void S74LS374NAPower(void)
124 latch[0]=latch[2]=latch[3]=latch[4]=0;
127 SetReadHandler(0x8000,0xFFFF,CartBR);
128 SetWriteHandler(0x4100,0x7FFF,S74LS374NAWrite);
131 void S74LS374NA_Init(CartInfo *info)
133 info->Power=S74LS374NAPower;
134 GameStateRestore=S74LS374NRestore;
135 AddExState(latch, 5, 0, "LATC");
136 AddExState(&cmd, 1, 0, "CMD");
140 static void S8259Synco(void)
143 setprg32(0x8000,latch[5]&7);
145 if(!UNIFchrrama) // No CHR RAM? Then BS'ing is ok.
151 bank=(latch[0]&0x7)|((latch[4]&7)<<3);
153 bank=(latch[x]&0x7)|((latch[4]&7)<<3);
156 case 00: bank=(bank<<1)|(x&1); setchr2(0x800*x,bank); break;
157 case 01: setchr2(0x800*x,bank); break;
158 case 02: bank=(bank<<2)|(x&3); setchr2(0x800*x,bank); break;
159 case 03: bank=latch[x]&7;
162 case 01: bank|=(latch[4]&1)<<4;break;
163 case 02: bank|=(latch[4]&2)<<3;break;
164 case 03: bank|=((latch[4]&4)<<2)|((latch[6]&1)<<3);break;
166 setchr1(0x400*x,bank);
173 S74LS374MSync(latch[7]>>1);
178 static DECLFW(S8259Write)
190 static void S8259Reset(void)
195 for(x=0;x<8;x++) latch[x]=0;
199 SetReadHandler(0x8000,0xFFFF,CartBR);
200 SetWriteHandler(0x4100,0x7FFF,S8259Write);
203 static void S8259Restore(int version)
208 void S8259A_Init(CartInfo *info) // Kevin's Horton 141 mapper
210 info->Power=S8259Reset;
211 GameStateRestore=S8259Restore;
212 AddExState(latch, 8, 0, "LATC");
213 AddExState(&cmd, 1, 0, "CMD");
217 void S8259B_Init(CartInfo *info) // Kevin's Horton 138 mapper
219 info->Power=S8259Reset;
220 GameStateRestore=S8259Restore;
221 AddExState(latch, 8, 0, "LATC");
222 AddExState(&cmd, 1, 0, "CMD");
226 void S8259C_Init(CartInfo *info) // Kevin's Horton 139 mapper
228 info->Power=S8259Reset;
229 GameStateRestore=S8259Restore;
230 AddExState(latch, 8, 0, "LATC");
231 AddExState(&cmd, 1, 0, "CMD");
235 void S8259D_Init(CartInfo *info) // Kevin's Horton 137 mapper
237 info->Power=S8259Reset;
238 GameStateRestore=S8259Restore;
239 AddExState(latch, 8, 0, "LATC");
240 AddExState(&cmd, 1, 0, "CMD");
244 static void(*WSync)(void);
246 static DECLFW(SAWrite)
255 static void SAPower(void)
259 SetReadHandler(0x8000,0xFFFF,CartBR);
260 SetWriteHandler(0x4100,0x5FFF,SAWrite);
263 static void SARestore(int version)
268 static DECLFW(SADWrite)
274 static void SADPower(void)
278 SetReadHandler(0x8000,0xFFFF,CartBR);
279 SetWriteHandler(0x8000,0xFFFF,SADWrite);
282 static void SA0161MSynco()
284 setprg32(0x8000,(latch[0]>>3)&1);
288 static void SA72007Synco()
291 setchr8(latch[0]>>7);
294 static void SA72008Synco()
296 setprg32(0x8000,(latch[0]>>2)&1);
300 void SA0161M_Init(CartInfo *info)
303 GameStateRestore=SARestore;
305 AddExState(&latch[0], 1, 0, "LATC");
308 void SA72007_Init(CartInfo *info)
311 GameStateRestore=SARestore;
313 AddExState(&latch[0], 1, 0, "LATC");
316 void SA72008_Init(CartInfo *info)
319 GameStateRestore=SARestore;
321 AddExState(&latch[0], 1, 0, "LATC");
324 void SA0036_Init(CartInfo *info)
327 GameStateRestore=SARestore;
328 info->Power=SADPower;
329 AddExState(&latch[0], 1, 0, "LATC");
332 void SA0037_Init(CartInfo *info)
335 GameStateRestore=SARestore;
336 info->Power=SADPower;
337 AddExState(&latch[0], 1, 0, "LATC");
340 static void TCU01Synco()
342 setprg32(0x8000,(latch[0]>>2)&1);
343 setchr8((latch[0]>>3)&0xF);
346 static DECLFW(TCWrite)
355 static void TCU01Reset(void)
358 SetReadHandler(0x8000,0xFFFF,CartBR);
359 SetWriteHandler(0x4100,0xFFFF,TCWrite);
363 static void TCU01Restore(int version)
368 void TCU01_Init(CartInfo *info)
370 GameStateRestore=TCU01Restore;
371 info->Power=TCU01Reset;
372 AddExState(&latch[0], 1, 0, "LATC");
375 static DECLFR(TCA01Read)
378 if((A&0x4100)==0x4100)
379 ret=(X.DB&0xC0)|((~A)&0x3F);
385 static void TCA01Reset(void)
390 SetReadHandler(0x8000,0xFFFF,CartBR);
391 SetReadHandler(0x4100,0x5FFF,TCA01Read);
394 void TCA01_Init(CartInfo *info)
396 info->Power=TCA01Reset;