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
25 static uint8 prg[4];
\r
26 static uint8 chr[8];
\r
27 static uint8 IRQCount;
\r
28 static uint8 IRQPre;
\r
31 static SFORMAT StateRegs[]=
\r
35 {&IRQCount, 1, "IRQCOUNT"},
\r
36 {&IRQPre, 1, "IRQPRE"},
\r
41 static void SyncPrg(void)
\r
44 setprg8(0x8000,prg[0]);
\r
45 setprg8(0xA000,prg[1]);
\r
46 setprg8(0xC000,prg[2]);
\r
50 static void SyncChr(void)
\r
54 setchr1(i<<10,chr[i]);
\r
57 static void StateRestore(int version)
\r
63 static DECLFW(M183Write)
\r
65 if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C))
\r
67 uint8 index=(((A&0x7000)>>11)-6)|((A&8)>>3);
\r
68 chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4));
\r
71 else switch (A&0xF80C)
\r
73 case 0x8800: prg[0]=V; SyncPrg(); break;
\r
74 case 0xA800: prg[1]=V; SyncPrg(); break;
\r
75 case 0xA000: prg[2]=V; SyncPrg(); break;
\r
76 case 0x9800: switch (V&3)
\r
78 case 0: setmirror(MI_V); break;
\r
79 case 1: setmirror(MI_H); break;
\r
80 case 2: setmirror(MI_0); break;
\r
81 case 3: setmirror(MI_1); break;
\r
84 case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;
\r
85 case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;
\r
86 case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;
\r
87 case 0xF00C: IRQPre=16; break;
\r
91 static void M183IRQCounter(void)
\r
96 if((IRQCount-IRQPre)==238)
\r
97 X6502_IRQBegin(FCEU_IQEXT);
\r
101 static void M183Power(void)
\r
103 IRQPre=IRQCount=IRQa=0;
\r
104 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
105 SetWriteHandler(0x8000,0xFFFF,M183Write);
\r
106 SetReadHandler(0x6000,0x7FFF,CartBR);
\r
111 void Mapper183_Init(CartInfo *info)
\r
113 info->Power=M183Power;
\r
114 GameHBIRQHook=M183IRQCounter;
\r
115 GameStateRestore=StateRestore;
\r
116 AddExState(&StateRegs, ~0, 0, 0);
\r