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