1 /* FCE Ultra - NES/Famicom Emulator
\r
3 * Copyright notice for this file:
\r
4 * Copyright (C) 2005 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 * Lethal Weapon (VRC4 mapper)
\r
25 static uint8 prg0, prg1, mirr, swap;
\r
26 static uint8 chr[8];
\r
27 static uint8 IRQCount;
\r
28 static uint8 IRQPre;
\r
31 static SFORMAT StateRegs[]=
\r
38 {&IRQCount, 1, "IRQC"},
\r
39 {&IRQPre, 1, "IRQP"},
\r
44 static void SyncPrg(void)
\r
49 setprg8(0xC000,prg0);
\r
53 setprg8(0x8000,prg0);
\r
56 setprg8(0xA000,prg1);
\r
60 static void SyncChr(void)
\r
64 setchr1(i<<10,chr[i]);
\r
68 static void StateRestore(int version)
\r
74 static DECLFW(UNLTF1201Write)
\r
76 A=(A&0xF003)|((A&0xC)>>2);
\r
77 if((A>=0xB000)&&(A<=0xE003))
\r
79 int ind=(((A>>11)-6)|(A&1))&7;
\r
81 chr[ind]=(chr[ind]&(0xF0>>sar))|((V&0x0F)<<sar);
\r
84 else switch (A&0xF003)
\r
86 case 0x8000: prg0=V; SyncPrg(); break;
\r
87 case 0xA000: prg1=V; SyncPrg(); break;
\r
88 case 0x9000: mirr=V&1; SyncChr(); break;
\r
89 case 0x9001: swap=V&3; SyncPrg(); break;
\r
90 case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;
\r
91 case 0xF002: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;
\r
93 case 0xF003: IRQa=V&2; X6502_IRQEnd(FCEU_IQEXT); if(scanline<240) IRQCount-=8; break;
\r
97 static void UNLTF1201IRQCounter(void)
\r
104 X6502_IRQBegin(FCEU_IQEXT);
\r
109 static void UNLTF1201Power(void)
\r
111 IRQPre=IRQCount=IRQa=0;
\r
112 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
113 SetWriteHandler(0x8000,0xFFFF,UNLTF1201Write);
\r
118 void UNLTF1201_Init(CartInfo *info)
\r
120 info->Power=UNLTF1201Power;
\r
121 GameHBIRQHook=UNLTF1201IRQCounter;
\r
122 GameStateRestore=StateRestore;
\r
123 AddExState(&StateRegs, ~0, 0, 0);
\r