1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
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 int32 IRQCount,IRQLatch;
25 static uint8 IRQa,resetmode,mbia;
26 static uint8 sizer,bigbank,bigbank2;
28 static uint8 DRegBuf[8],MMC3_cmd;
30 static int masko8[8]={63,31,15,1,3,0,0,0};
31 //static int masko1[8]={511,255,127,7,7,0,0,0};
33 static void swsetprg8(uint32 A, uint32 V)
37 setprg8r((V/64)&15,A,V);
40 static void swsetchr1(uint32 A, uint32 V)
46 // V&=masko1[sizer&7];
48 setchr1r((V/512)&15,A,V);
52 static void swsetchr2(uint32 A, uint32 V)
58 //V&=masko1[sizer&7]>>1;
60 setchr2r((V/256)&15,A,V);
64 static void Sup24_hb(void)
66 if(ScreenON || SpriteON)
77 X6502_IRQBegin(FCEU_IQEXT);
84 static DECLFW(Sup24IRQWrite)
88 case 0xc000:IRQLatch=V;
92 case 0xc001:resetmode=1;
95 case 0xE000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);
106 static INLINE void FixMMC3PRG(int V)
108 swsetprg8(0xA000,DRegBuf[7]);
109 swsetprg8(0xE000,~0);
112 swsetprg8(0xC000,DRegBuf[6]);
113 swsetprg8(0x8000,~1);
117 swsetprg8(0x8000,DRegBuf[6]);
118 swsetprg8(0xC000,~1);
122 static INLINE void FixMMC3CHR(int V)
124 int cbase=(V&0x80)<<5;
125 swsetchr2((cbase^0x000),DRegBuf[0]>>1);
126 swsetchr2((cbase^0x800),DRegBuf[1]>>1);
127 swsetchr1(cbase^0x1000,DRegBuf[2]);
128 swsetchr1(cbase^0x1400,DRegBuf[3]);
129 swsetchr1(cbase^0x1800,DRegBuf[4]);
130 swsetchr1(cbase^0x1c00,DRegBuf[5]);
133 static DECLFW(Super24hiwrite)
135 //printf("$%04x:$%02x, %d\n",A,V,scanline);
139 if((V&0x40) != (MMC3_cmd&0x40))
141 if((V&0x80) != (MMC3_cmd&0x80))
148 int cbase=(MMC3_cmd&0x80)<<5;
149 DRegBuf[MMC3_cmd&0x7]=V;
150 switch(MMC3_cmd&0x07)
152 case 0: V>>=1;swsetchr2((cbase^0x000),V);break;
153 case 1: V>>=1;swsetchr2((cbase^0x800),V);break;
154 case 2: swsetchr1(cbase^0x1000,V); break;
155 case 3: swsetchr1(cbase^0x1400,V); break;
156 case 4: swsetchr1(cbase^0x1800,V); break;
157 case 5: swsetchr1(cbase^0x1C00,V); break;
158 case 6: if (MMC3_cmd&0x40) swsetprg8(0xC000,V);
159 else swsetprg8(0x8000,V);
161 case 7: swsetprg8(0xA000,V);
177 //printf("$%04x:$%02x\n",A,V);
181 FixMMC3PRG(MMC3_cmd);
182 FixMMC3CHR(MMC3_cmd);
186 FixMMC3PRG(MMC3_cmd);
190 FixMMC3CHR(MMC3_cmd);
195 static void Super24Reset(void)
197 SetWriteHandler(0x8000,0xBFFF,Super24hiwrite);
198 SetWriteHandler(0x5000,0x7FFF,Super24Write);
199 SetWriteHandler(0xC000,0xFFFF,Sup24IRQWrite);
200 SetReadHandler(0x8000,0xFFFF,CartBR);
201 GameHBIRQHook=Sup24_hb;
202 IRQCount=IRQLatch=IRQa=resetmode=0;
215 static void MrRestore(int version)
217 FixMMC3PRG(MMC3_cmd);
218 FixMMC3CHR(MMC3_cmd);
219 setmirror((mbia&1)^1);
222 void Super24_Init(void)
224 BoardPower=Super24Reset;
225 SetupCartCHRMapping(0x10, GameMemBlock, 8192, 1);
226 GameStateRestore=MrRestore;
228 AddExState(GameMemBlock, 8192, 0, "CHRR");
229 AddExState(DRegBuf, 8, 0, "DREG");
230 AddExState(&IRQCount, 4, 1, "IRQC");
231 AddExState(&IRQLatch, 4, 1, "IQL1");
232 AddExState(&IRQa, 1, 0, "IRQA");
233 AddExState(&sizer, 1, 0, "SIZA");
234 AddExState(&bigbank, 1, 0, "BIG1");
235 AddExState(&bigbank2, 1, 0, "BIG2");