cleanups, savestates, input (combos), menu
[fceu.git] / mappers / 208.c
CommitLineData
d97315ac 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2003 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
23static uint8 PRGSel;
24static uint8 PBuf[4],PSel;
25static uint8 cmd;
26static uint8 DRegs[8];
27static uint32 count=0;
28static uint32 last=0;
29
30static DECLFW(M208Write1)
31{
32 PRGSel=(V&0x1)|((V>>3)&0x2);
33 setprg32(0x8000,PRGSel);
34}
35
36static DECLFW(M208Write2)
37{
38 static uint8 lut[256]={
39 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
40 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
41 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
42 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
43 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
48 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
49 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
50 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
51 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
55
56 };
57 if(A<=0x57FF) PSel=V;
58 else
59 PBuf[(A&0x03)]=V^lut[PSel];
60}
61
62static DECLFR(M208Read)
63{
64 return(PBuf[(A&0x3)]);
65}
66
67static void Sync(void)
68{
69 int x;
70
71 setchr2(0x0000,DRegs[0]>>1);
72 setchr2(0x0800,DRegs[1]>>1);
73 for(x=0;x<4;x++)
74 setchr1(0x1000+x*0x400,DRegs[2+x]);
75}
76
77static DECLFW(M208HWrite)
78{
79 switch(A&0xe001)
80 {
81 case 0xc000:IRQLatch=IRQCount=V;break;
82 case 0xc001:IRQCount=IRQLatch;last=count=0;break;
83 case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
84 case 0xe001:IRQa=1;break;
85 case 0x8000:cmd=V;break;
86 case 0x8001:DRegs[cmd&7]=V;
87 Sync();
88 break;
89
90 }
91}
92
93static void M208Power(void)
94{
95 PRGSel=3;
96 setprg32(0x8000,3);
97 SetWriteHandler(0x4800,0x4FFF,M208Write1);
98 SetWriteHandler(0x5000,0x5fff,M208Write2);
99 SetWriteHandler(0x8000,0xFFFF,M208HWrite);
100 SetReadHandler(0x5800,0x5FFF,M208Read);
101 SetReadHandler(0x8000,0xffff,CartBR);
102}
103
104static void sl(void)
105{
106 if(IRQa)
107 {
108 if(IRQCount>=0)
109 {
110 IRQCount--;
111 if(IRQCount<0)
112 {
113 X6502_IRQBegin(FCEU_IQEXT);
114 }
115 }
116 }
117}
118
119static void FP_FASTAPASS(1) foo(uint32 A)
120{
121 if((A&0x2000) && !(last&0x2000))
122 {
123 count++;
124 if(count==42)
125 {
126 sl();
127 count=0;
128 }
129 }
130 last=A;
131}
132
133void Mapper208_Init(CartInfo *info)
134{
135 info->Power=M208Power;
136 //GameHBIRQHook=sl;
137 PPU_hook=foo;
138}
139