merge mappers from FCEU-mm
[fceu.git] / boards / 117.c
CommitLineData
e2d0dd92 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Xodnizel
5 *
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.
10 *
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.
15 *
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
43725da7 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e2d0dd92 19 */
20
21#include "mapinc.h"
22
386f5371 23static uint8 prgreg[4], chrreg[8], mirror;
e2d0dd92 24static uint8 IRQa, IRQCount, IRQLatch;
25
26static SFORMAT StateRegs[]=
27{
28 {&IRQa, 1, "IRQA"},
29 {&IRQCount, 1, "IRQC"},
30 {&IRQLatch, 1, "IRQL"},
43725da7 31 {prgreg, 4, "PREG"},
32 {chrreg, 8, "CREG"},
386f5371 33 {&mirror, 1, "MREG"},
e2d0dd92 34 {0}
35};
36
37static void Sync(void)
38{
39 setprg8(0x8000,prgreg[0]);
40 setprg8(0xa000,prgreg[1]);
41 setprg8(0xc000,prgreg[2]);
42 setprg8(0xe000,prgreg[3]);
43725da7 43 int i;
e2d0dd92 44 for(i=0; i<8; i++)
45 setchr1(i<<10,chrreg[i]);
386f5371 46 setmirror(mirror^1);
e2d0dd92 47}
48
49static DECLFW(M117Write)
50{
51 if(A<0x8004)
52 {
53 prgreg[A&3]=V;
54 Sync();
55 }
56 else if((A>=0xA000)&&(A<=0xA007))
57 {
58 chrreg[A&7]=V;
59 Sync();
60 }
61 else switch(A)
62 {
63 case 0xc001: IRQLatch=V; break;
64 case 0xc003: IRQCount=IRQLatch; IRQa|=2; break;
65 case 0xe000: IRQa&=~1; IRQa|=V&1; X6502_IRQEnd(FCEU_IQEXT); break;
66 case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break;
386f5371 67 case 0xd000: mirror=V&1;
e2d0dd92 68 }
69}
70
71static void M117Power(void)
72{
73 prgreg[0]=~3; prgreg[1]=~2; prgreg[2]=~1; prgreg[3]=~0;
74 Sync();
75 SetReadHandler(0x8000,0xFFFF,CartBR);
76 SetWriteHandler(0x8000,0xFFFF,M117Write);
77}
78
79static void M117IRQHook(void)
80{
81 if(IRQa==3&&IRQCount)
82 {
83 IRQCount--;
84 if(!IRQCount)
85 {
86 IRQa&=1;
87 X6502_IRQBegin(FCEU_IQEXT);
88 }
89 }
90}
91
92static void StateRestore(int version)
93{
94 Sync();
95}
96
97void Mapper117_Init(CartInfo *info)
98{
99 info->Power=M117Power;
100 GameHBIRQHook=M117IRQHook;
101 GameStateRestore=StateRestore;
102 AddExState(&StateRegs, ~0, 0, 0);
103}
104