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