1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2007 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * VRC-2/VRC-4 Konami
\r
27 static uint16 IRQCount;
\r
28 static uint8 IRQLatch,IRQa;
\r
29 static uint8 prgreg[2];
\r
30 static uint8 chrreg[8];
\r
31 static uint8 regcmd, irqcmd, mirr, big_bank;
\r
32 static uint16 acount=0;
\r
34 static uint8 *WRAM=NULL;
\r
35 static uint32 WRAMSIZE;
\r
37 static SFORMAT StateRegs[]=
\r
39 {prgreg, 2, "PREG"},
\r
40 {chrreg, 8, "CREG"},
\r
41 {®cmd, 1, "CMDR"},
\r
42 {&irqcmd, 1, "CMDI"},
\r
44 {&big_bank, 1, "BIGB"},
\r
45 {&IRQCount, 2, "IRQC"},
\r
46 {&IRQLatch, 1, "IRQL"},
\r
51 static void Sync(void)
\r
55 setprg8(0xC000,prgreg[0]|big_bank);
\r
56 setprg8(0x8000,((~1)&0x1F)|big_bank);
\r
60 setprg8(0x8000,prgreg[0]|big_bank);
\r
61 setprg8(0xC000,((~1)&0x1F)|big_bank);
\r
63 setprg8(0xA000,prgreg[1]|big_bank);
\r
64 setprg8(0xE000,((~0)&0x1F)|big_bank);
\r
71 setchr1(i<<10, chrreg[i]);
\r
75 case 0: setmirror(MI_V); break;
\r
76 case 1: setmirror(MI_H); break;
\r
77 case 2: setmirror(MI_0); break;
\r
78 case 3: setmirror(MI_1); break;
\r
82 static DECLFW(M23Write)
\r
84 // FCEU_printf("%04x:%04x\n",A,V);
\r
85 A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); // actually there is many-in-one mapper source, some pirate or
\r
86 // licensed games use various address bits for registers
\r
88 if((A>=0xB000)&&(A<=0xE003))
\r
91 big_bank=(V&8)<<2; // my personally many-in-one feature ;) just for support pirate cart 2-in-1
\r
94 uint16 i=((A>>1)&1)|((A-0xB000)>>11);
\r
95 chrreg[i]&=(0xF0)>>((A&1)<<2);
\r
96 chrreg[i]|=(V&0xF)<<((A&1)<<2);
\r
106 case 0x8003: if(is23)
\r
113 case 0xA003: if(is23)
\r
117 prgreg[0]=(V<<1)&0x1F;
\r
118 prgreg[1]=((V<<1)&0x1F)|1;
\r
123 case 0x9001: if(V!=0xFF) mirr=V; Sync(); break;
\r
125 case 0x9003: regcmd=V; Sync(); break;
\r
126 case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0xF0; IRQLatch|=V&0xF; break;
\r
127 case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0x0F; IRQLatch|=V<<4; break;
\r
128 case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount=0; IRQCount=IRQLatch; IRQa=V&2; irqcmd=V&1; break;
\r
129 case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa=irqcmd; break;
\r
133 static void M23Power(void)
\r
137 setprg8r(0x10,0x6000,0); // another many-in-one code, WRAM actually contain only WaiWaiWorld game
\r
138 SetReadHandler(0x6000,0x7FFF,CartBR);
\r
139 SetWriteHandler(0x6000,0x7FFF,CartBW);
\r
140 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
141 SetWriteHandler(0x8000,0xFFFF,M23Write);
\r
144 void FP_FASTAPASS(1) M23IRQHook(int a)
\r
152 while(acount>=LCYCS)
\r
158 X6502_IRQBegin(FCEU_IQEXT);
\r
166 static void StateRestore(int version)
\r
171 static void M23Close(void)
\r
177 void Mapper23_Init(CartInfo *info)
\r
180 info->Power=M23Power;
\r
181 info->Close=M23Close;
\r
182 MapIRQHook=M23IRQHook;
\r
183 GameStateRestore=StateRestore;
\r
186 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
187 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
188 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
190 AddExState(&StateRegs, ~0, 0, 0);
\r
193 void UNLT230_Init(CartInfo *info)
\r
196 info->Power=M23Power;
\r
197 info->Close=M23Close;
\r
198 MapIRQHook=M23IRQHook;
\r
199 GameStateRestore=StateRestore;
\r
202 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
203 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
204 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
206 AddExState(&StateRegs, ~0, 0, 0);
\r