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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 static uint8 cmd, dip;
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);
68 ret=((~cmd)&0x3F)^dip;
74 static void S74LS374NPower(void)
77 latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
79 SetReadHandler(0x8000,0xFFFF,CartBR);
80 SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
81 SetReadHandler(0x4100,0x5fff,S74LS374NRead);
84 static void S74LS374NReset(void)
87 latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
91 static void S74LS374NRestore(int version)
96 void S74LS374N_Init(CartInfo *info)
98 info->Power=S74LS374NPower;
99 info->Reset=S74LS374NReset;
100 GameStateRestore=S74LS374NRestore;
101 AddExState(latch, 5, 0, "LATC");
102 AddExState(&cmd, 1, 0, "CMD");
103 AddExState(&dip, 1, 0, "DIP");
106 static void S74LS374NASynco(void)
108 setprg32(0x8000,latch[0]);
110 S74LS374MSync(latch[2]);
113 static DECLFW(S74LS374NAWrite)
122 case 0:latch[0]=0;latch[1]=3;break;
123 case 2:latch[3]=(V&1)<<3;break;
124 case 4:latch[1]=(latch[1]&6)|(V&3);break;
125 case 5:latch[0]=V&1;break;
126 case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break;
127 case 7:latch[2]=V&1;break;
133 static void S74LS374NAPower(void)
135 latch[0]=latch[2]=latch[3]=latch[4]=0;
138 SetReadHandler(0x8000,0xFFFF,CartBR);
139 SetWriteHandler(0x4100,0x7FFF,S74LS374NAWrite);
142 void S74LS374NA_Init(CartInfo *info)
144 info->Power=S74LS374NAPower;
145 GameStateRestore=S74LS374NRestore;
146 AddExState(latch, 5, 0, "LATC");
147 AddExState(&cmd, 1, 0, "CMD");
151 static void S8259Synco(void)
154 setprg32(0x8000,latch[5]&7);
156 if(!UNIFchrrama) // No CHR RAM? Then BS'ing is ok.
162 bank=(latch[0]&0x7)|((latch[4]&7)<<3);
164 bank=(latch[x]&0x7)|((latch[4]&7)<<3);
167 case 00: bank=(bank<<1)|(x&1); setchr2(0x800*x,bank); break;
168 case 01: setchr2(0x800*x,bank); break;
169 case 02: bank=(bank<<2)|(x&3); setchr2(0x800*x,bank); break;
170 case 03: bank=latch[x]&7;
173 case 01: bank|=(latch[4]&1)<<4;break;
174 case 02: bank|=(latch[4]&2)<<3;break;
175 case 03: bank|=((latch[4]&4)<<2)|((latch[6]&1)<<3);break;
177 setchr1(0x400*x,bank);
184 S74LS374MSync(latch[7]>>1);
189 static DECLFW(S8259Write)
201 static void S8259Reset(void)
206 for(x=0;x<8;x++) latch[x]=0;
210 SetReadHandler(0x8000,0xFFFF,CartBR);
211 SetWriteHandler(0x4100,0x7FFF,S8259Write);
214 static void S8259Restore(int version)
219 void S8259A_Init(CartInfo *info) // Kevin's Horton 141 mapper
221 info->Power=S8259Reset;
222 GameStateRestore=S8259Restore;
223 AddExState(latch, 8, 0, "LATC");
224 AddExState(&cmd, 1, 0, "CMD");
228 void S8259B_Init(CartInfo *info) // Kevin's Horton 138 mapper
230 info->Power=S8259Reset;
231 GameStateRestore=S8259Restore;
232 AddExState(latch, 8, 0, "LATC");
233 AddExState(&cmd, 1, 0, "CMD");
237 void S8259C_Init(CartInfo *info) // Kevin's Horton 139 mapper
239 info->Power=S8259Reset;
240 GameStateRestore=S8259Restore;
241 AddExState(latch, 8, 0, "LATC");
242 AddExState(&cmd, 1, 0, "CMD");
246 void S8259D_Init(CartInfo *info) // Kevin's Horton 137 mapper
248 info->Power=S8259Reset;
249 GameStateRestore=S8259Restore;
250 AddExState(latch, 8, 0, "LATC");
251 AddExState(&cmd, 1, 0, "CMD");
255 static void(*WSync)(void);
257 static DECLFW(SAWrite)
266 static void SAPower(void)
270 SetReadHandler(0x8000,0xFFFF,CartBR);
271 SetWriteHandler(0x4100,0x5FFF,SAWrite);
274 static void SARestore(int version)
279 static DECLFW(SADWrite)
285 static void SADPower(void)
289 SetReadHandler(0x8000,0xFFFF,CartBR);
290 SetWriteHandler(0x8000,0xFFFF,SADWrite);
293 static void SA0161MSynco()
295 setprg32(0x8000,(latch[0]>>3)&1);
299 static void SA72007Synco()
302 setchr8(latch[0]>>7);
305 static void SA009Synco()
311 static void SA72008Synco()
313 setprg32(0x8000,(latch[0]>>2)&1);
317 void SA0161M_Init(CartInfo *info)
320 GameStateRestore=SARestore;
322 AddExState(&latch[0], 1, 0, "LATC");
325 void SA72007_Init(CartInfo *info)
328 GameStateRestore=SARestore;
330 AddExState(&latch[0], 1, 0, "LATC");
333 void SA72008_Init(CartInfo *info)
336 GameStateRestore=SARestore;
338 AddExState(&latch[0], 1, 0, "LATC");
341 void SA009_Init(CartInfo *info)
344 GameStateRestore=SARestore;
346 AddExState(&latch[0], 1, 0, "LATC");
349 void SA0036_Init(CartInfo *info)
352 GameStateRestore=SARestore;
353 info->Power=SADPower;
354 AddExState(&latch[0], 1, 0, "LATC");
357 void SA0037_Init(CartInfo *info)
360 GameStateRestore=SARestore;
361 info->Power=SADPower;
362 AddExState(&latch[0], 1, 0, "LATC");
365 // -----------------------------------------------
367 static void TCU01Synco()
369 setprg32(0x8000,((latch[0]&0x80)>>6)|((latch[0]>>2)&1));
370 setchr8((latch[0]>>3)&0xF);
373 static DECLFW(TCU01Write)
382 static void TCU01Power(void)
385 SetReadHandler(0x8000,0xFFFF,CartBR);
386 SetWriteHandler(0x4100,0xFFFF,TCU01Write);
390 static void TCU01Restore(int version)
395 void TCU01_Init(CartInfo *info)
397 GameStateRestore=TCU01Restore;
398 info->Power=TCU01Power;
399 AddExState(&latch[0], 1, 0, "LATC");
402 //-----------------------------------------------
404 static void TCU02Synco()
410 static DECLFW(TCU02Write)
419 static DECLFR(TCU02Read)
421 return (latch[0]&0x3F)|(X.DB&0xC0);
424 static void TCU02Power(void)
427 SetReadHandler(0x8000,0xFFFF,CartBR);
428 SetReadHandler(0x4100,0x4100,TCU02Read);
429 SetWriteHandler(0x4100,0xFFFF,TCU02Write);
433 static void TCU02Restore(int version)
438 void TCU02_Init(CartInfo *info)
440 GameStateRestore=TCU02Restore;
441 info->Power=TCU02Power;
442 AddExState(&latch[0], 1, 0, "LATC");
445 // ---------------------------------------------
447 static DECLFR(TCA01Read)
450 if((A&0x4100)==0x4100)
451 ret=(X.DB&0xC0)|((~A)&0x3F);
457 static void TCA01Power(void)
462 SetReadHandler(0x8000,0xFFFF,CartBR);
463 SetReadHandler(0x4100,0x5FFF,TCA01Read);
466 void TCA01_Init(CartInfo *info)
468 info->Power=TCA01Power;