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
23 static uint8 reg[16], IRQa;
\r
24 static uint32 IRQCount;
\r
25 static uint8 *WRAM=NULL;
\r
26 static uint32 WRAMSIZE;
\r
28 static SFORMAT StateRegs[]=
\r
31 {&IRQCount, 4, "IRQC"},
\r
36 static void Sync(void)
\r
38 setchr1(0x0000,reg[0]&0xfe);
\r
39 setchr1(0x0400,reg[1]|1);
\r
40 setchr1(0x0800,reg[2]&0xfe);
\r
41 setchr1(0x0c00,reg[3]|1);
\r
42 setchr1(0x1000,reg[4]);
\r
43 setchr1(0x1400,reg[5]);
\r
44 setchr1(0x1800,reg[6]);
\r
45 setchr1(0x1c00,reg[7]);
\r
46 setprg8r(0x10,0x6000,0);
\r
47 setprg8(0x8000,(reg[0x8]&0xf)|0x10);
\r
48 setprg8(0xA000,(reg[0x9]&0x1f));
\r
49 setprg8(0xC000,(reg[0xa]&0x1f));
\r
50 setprg8(0xE000,(reg[0xb]&0xf)|0x10);
\r
51 setmirror((reg[0xc]&1)^1);
\r
54 static DECLFW(M106Write)
\r
59 case 0xD: IRQa=0; IRQCount=0; X6502_IRQEnd(FCEU_IQEXT); break;
\r
60 case 0xE: IRQCount=(IRQCount&0xFF00)|V; break;
\r
61 case 0xF: IRQCount=(IRQCount&0x00FF)|(V<<8); IRQa=1; break;
\r
62 default: reg[A]=V; Sync(); break;
\r
66 static void M106Power(void)
\r
68 reg[8]=reg[9]=reg[0xa]=reg[0xb]=-1;
\r
70 SetReadHandler(0x6000,0x7FFF,CartBR);
\r
71 SetReadHandler(0x8000,0xFFFF,CartBR);
\r
72 SetWriteHandler(0x6000,0x7FFF,CartBW);
\r
73 SetWriteHandler(0x8000,0xFFFF,M106Write);
\r
76 static void M106Reset(void)
\r
80 static void M106Close(void)
\r
87 void FP_FASTAPASS(1) M106CpuHook(int a)
\r
92 if(IRQCount>0x10000)
\r
94 X6502_IRQBegin(FCEU_IQEXT);
\r
100 static void StateRestore(int version)
\r
105 void Mapper106_Init(CartInfo *info)
\r
107 info->Reset=M106Reset;
\r
108 info->Power=M106Power;
\r
109 info->Close=M106Close;
\r
110 MapIRQHook=M106CpuHook;
\r
111 GameStateRestore=StateRestore;
\r
114 WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
\r
115 SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
\r
116 AddExState(WRAM, WRAMSIZE, 0, "WRAM");
\r
118 AddExState(&StateRegs, ~0, 0, 0);
\r