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 MSync(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]);
44 static DECLFW(S74LS374NWrite)
53 case 2:latch[3]=(V&1)<<3;break;
54 case 4:latch[4]=(V&1)<<2;break;
55 case 5:latch[0]=V&0x7;break;
56 case 6:latch[1]=V&3;break;
57 case 7:latch[2]=V>>1;break;
63 static void S74LS374NPower(void)
65 latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
67 SetReadHandler(0x8000,0xFFFF,CartBR);
68 SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
71 static void S74LS374NRestore(int version)
76 void S74LS374N_Init(CartInfo *info)
78 info->Power=S74LS374NPower;
79 GameStateRestore=S74LS374NRestore;
80 AddExState(latch, 5, 0, "LATC");
81 AddExState(&cmd, 1, 0, "CMD");
84 static void S74LS374NASynco(void)
86 setprg32(0x8000,latch[0]);
91 static DECLFW(S74LS374NAWrite)
100 case 0:latch[0]=0;latch[1]=3;break;
101 case 2:latch[3]=(V&1)<<3;break;
102 case 4:latch[1]=(latch[1]&6)|(V&3);break;
103 case 5:latch[0]=V&1;break;
104 case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break;
105 case 7:latch[2]=V&1;break;
111 static void S74LS374NAPower(void)
113 latch[0]=latch[2]=latch[3]=latch[4]=0;
116 SetReadHandler(0x8000,0xFFFF,CartBR);
117 SetWriteHandler(0x4100,0x7FFF,S74LS374NAWrite);
120 void S74LS374NA_Init(CartInfo *info)
122 info->Power=S74LS374NAPower;
123 GameStateRestore=S74LS374NRestore;
124 AddExState(latch, 5, 0, "LATC");
125 AddExState(&cmd, 1, 0, "CMD");
130 static void S8259Synco(void)
133 setprg32(0x8000,latch[5]&7);
135 if(!UNIFchrrama) // No CHR RAM? Then BS'ing is ok.
141 bank=(latch[0]&0x7)|((latch[4]&7)<<3);
143 bank=(latch[x]&0x7)|((latch[4]&7)<<3);
146 case 00: bank=(bank<<1)|(x&1); setchr2(0x800*x,bank); break;
147 case 01: setchr2(0x800*x,bank); break;
148 case 02: bank=(bank<<2)|(x&3); setchr2(0x800*x,bank); break;
149 case 03: bank=latch[x]&7;
152 case 01: bank|=(latch[4]&1)<<4;break;
153 case 02: bank|=(latch[4]&2)<<3;break;
154 case 03: bank|=((latch[4]&4)<<2)|((latch[6]&1)<<3);break;
156 setchr1(0x400*x,bank);
165 static DECLFW(S8259Write)
177 static void S8259Reset(void)
182 for(x=0;x<8;x++) latch[x]=0;
186 SetReadHandler(0x8000,0xFFFF,CartBR);
187 SetWriteHandler(0x4100,0x7FFF,S8259Write);
190 static void S8259Restore(int version)
195 void S8259A_Init(CartInfo *info) // Kevin's Horton 141 mapper
197 info->Power=S8259Reset;
198 GameStateRestore=S8259Restore;
199 AddExState(latch, 8, 0, "LATC");
200 AddExState(&cmd, 1, 0, "CMD");
204 void S8259B_Init(CartInfo *info) // Kevin's Horton 138 mapper
206 info->Power=S8259Reset;
207 GameStateRestore=S8259Restore;
208 AddExState(latch, 8, 0, "LATC");
209 AddExState(&cmd, 1, 0, "CMD");
213 void S8259C_Init(CartInfo *info) // Kevin's Horton 139 mapper
215 info->Power=S8259Reset;
216 GameStateRestore=S8259Restore;
217 AddExState(latch, 8, 0, "LATC");
218 AddExState(&cmd, 1, 0, "CMD");
222 void S8259D_Init(CartInfo *info) // Kevin's Horton 137 mapper
224 info->Power=S8259Reset;
225 GameStateRestore=S8259Restore;
226 AddExState(latch, 8, 0, "LATC");
227 AddExState(&cmd, 1, 0, "CMD");
231 static void(*WSync)(void);
233 static void SA0161MSynco()
235 setprg32(0x8000,(latch[0]>>3)&1);
239 static DECLFW(SAWrite)
248 static void SAReset(void)
252 SetReadHandler(0x8000,0xFFFF,CartBR);
253 SetWriteHandler(0x4100,0x5FFF,SAWrite);
256 static void SA0161MRestore(int version)
261 void SA0161M_Init(CartInfo *info)
264 GameStateRestore=SA0161MRestore;
266 AddExState(&latch[0], 1, 0, "LATC");
269 static void SA72007Synco()
272 setchr8(latch[0]>>7);
275 static void SA72007Restore(int version)
280 void SA72007_Init(CartInfo *info)
283 GameStateRestore=SA72007Restore;
285 AddExState(&latch[0], 1, 0, "LATC");
288 static void SA72008Synco()
290 setprg32(0x8000,(latch[0]>>2)&1);
294 static void SA72008Restore(int version)
299 void SA72008_Init(CartInfo *info)
302 GameStateRestore=SA72008Restore;
304 AddExState(&latch[0], 1, 0, "LATC");
307 static DECLFW(SADWrite)
313 static void SADReset(void)
317 SetReadHandler(0x8000,0xFFFF,CartBR);
318 SetWriteHandler(0x8000,0xFFFF,SADWrite);
321 static void SA0037Synco()
323 setprg32(0x8000,(latch[0]>>3)&1);
327 static void SA0037Restore(int version)
332 void SA0036_Init(CartInfo *info)
335 GameStateRestore=SA72007Restore;
336 info->Power=SADReset;
337 AddExState(&latch[0], 1, 0, "LATC");
340 void SA0037_Init(CartInfo *info)
343 GameStateRestore=SA0037Restore;
344 info->Power=SADReset;
345 AddExState(&latch[0], 1, 0, "LATC");
348 static void TCU01Synco()
350 setprg32(0x8000,(latch[0]>>2)&1);
351 setchr8((latch[0]>>3)&0xF);
354 static DECLFW(TCWrite)
361 static void TCU01Reset(void)
364 SetReadHandler(0x8000,0xFFFF,CartBR);
365 SetWriteHandler(0x4100,0xFFFF,TCWrite);
369 static void TCU01Restore(int version)
374 void TCU01_Init(CartInfo *info)
376 GameStateRestore=TCU01Restore;
377 info->Power=TCU01Reset;
378 AddExState(&latch[0], 1, 0, "LATC");
381 static DECLFR(TCA01Read)
384 if((A&0x4100)==0x4100)
385 ret=(X.DB&0xC0)|((~A)&0x3F);
391 static void TCA01Reset(void)
396 SetReadHandler(0x8000,0xFFFF,CartBR);
397 SetReadHandler(0x4100,0x5FFF,TCA01Read);
400 void TCA01_Init(CartInfo *info)
402 info->Power=TCA01Reset;