1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2009 CaH4e3
\r
6 * This program is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * This program is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program; if not, write to the Free Software
\r
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
\r
23 static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock;
\r
24 static int32 IRQa, IRQCount, IRQLatch, IRQClock;
\r
25 static uint8 *WRAM=NULL;
\r
26 static uint32 WRAMSIZE;
\r
27 static uint8 *CHRRAM=NULL;
\r
28 static uint32 CHRRAMSIZE;
\r
30 static SFORMAT StateRegs[]=
\r
32 {chrlo, 8, "CHRLO"},
\r
33 {chrhi, 8, "CHRHI"},
\r
36 {&vlock, 1, "VLOCK"},
\r
38 {&IRQCount, 4, "IRQC"},
\r
39 {&IRQLatch, 4, "IRQL"},
\r
40 {&IRQClock, 4, "IRQK"},
\r
44 static void Sync(void)
\r
47 setprg8r(0x10,0x6000,0);
\r
48 setprg8(0x8000,prg[0]);
\r
49 setprg8(0xa000,prg[1]);
\r
54 uint32 chr = chrlo[i]|(chrhi[i]<<8);
\r
60 else if(chrlo[i]==0x88)
\r
65 if(((chrlo[i]==4)||(chrlo[i]==5))&&!vlock)
\r
66 setchr1r(0x10,i<<10,chr&1);
\r
72 case 0: setmirror(MI_V); break;
\r
73 case 1: setmirror(MI_H); break;
\r
74 case 2: setmirror(MI_0); break;
\r
75 case 3: setmirror(MI_1); break;
\r
79 static DECLFW(M253Write)
\r
81 if((A>=0xB000)&&(A<=0xE00C))
\r
83 uint8 ind=((((A&8)|(A>>8))>>3)+2)&7;
\r
85 chrlo[ind]=(chrlo[ind]&(0xF0>>sar))|((V&0x0F)<<sar);
\r
93 case 0x8010: prg[0]=V; Sync(); break;
\r
94 case 0xA010: prg[1]=V; Sync(); break;
\r
95 case 0x9400: mirr=V&3; Sync(); break;
\r
96 case 0xF000: IRQLatch = (IRQLatch & 0xF0) | (V & 0x0F); break;
\r
97 case 0xF004: IRQLatch = (IRQLatch & 0x0F) | (V << 4); break;
\r
102 IRQCount = IRQLatch;
\r
105 X6502_IRQEnd(FCEU_IQEXT);
\r
110 static void M253Power(void)
\r
113 SetReadHandler(0x6000,0x7FFF,CartBR);
\r
114 SetWriteHandler(0x6000,0x7FFF,CartBW);
\r
115 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
116 SetWriteHandler(0x8000,0xFFFF,M253Write);
\r
119 static void M253Close(void)
\r
124 FCEU_gfree(CHRRAM);
\r
128 static void M253IRQ(int cycles)
\r
132 if((IRQClock+=cycles)>=0x72)
\r
135 if(IRQCount==0xFF)
\r
137 IRQCount = IRQLatch;
\r
138 IRQa = IRQa|((IRQa&1)<<1);
\r
139 X6502_IRQBegin(FCEU_IQEXT);
\r
147 static void StateRestore(int version)
\r
152 void Mapper253_Init(CartInfo *info)
\r
154 info->Power=M253Power;
\r
155 info->Close=M253Close;
\r
156 MapIRQHook=M253IRQ;
\r
157 GameStateRestore=StateRestore;
\r
160 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE);
\r
161 SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1);
\r
162 AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM");
\r
165 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
166 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
167 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
170 info->SaveGame[0]=WRAM;
\r
171 info->SaveGameLen[0]=WRAMSIZE;
\r
174 AddExState(&StateRegs, ~0, 0, 0);
\r