e2d0dd92 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
4 | * Copyright (C) 2005 CaH4e3 |
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 | |
22 | #include "mapinc.h" |
23 | |
24 | static uint16 IRQCount; |
25 | static uint8 IRQa; |
26 | static uint8 prg_reg[2]; |
27 | static uint8 chr_reg[8]; |
28 | |
29 | static SFORMAT StateRegs[]= |
30 | { |
31 | {&IRQCount, 2, "IRQC"}, |
32 | {&IRQa, 2, "IRQA"}, |
33 | {prg_reg, 2, "PRG"}, |
34 | {chr_reg, 8, "CHR"}, |
35 | {0} |
36 | }; |
37 | |
38 | static void M222IRQ(void) |
39 | { |
40 | if(IRQa) |
41 | { |
42 | IRQCount++; |
43 | if(IRQCount>=240) |
44 | { |
45 | X6502_IRQBegin(FCEU_IQEXT); |
46 | IRQa=0; |
47 | } |
48 | } |
49 | } |
50 | |
51 | static void Sync(void) |
52 | { |
53 | setprg8(0x8000,prg_reg[0]); |
54 | setprg8(0xA000,prg_reg[1]); |
55 | int i; |
56 | for(i=0; i<8; i++) |
57 | setchr1(i<<10,chr_reg[i]); |
58 | } |
59 | |
60 | static DECLFW(M222Write) |
61 | { |
62 | switch(A&0xF003) |
63 | { |
64 | case 0x8000: prg_reg[0]=V; break; |
65 | case 0xA000: prg_reg[1]=V; break; |
66 | case 0xB000: chr_reg[0]=V; break; |
67 | case 0xB002: chr_reg[1]=V; break; |
68 | case 0xC000: chr_reg[2]=V; break; |
69 | case 0xC002: chr_reg[3]=V; break; |
70 | case 0xD000: chr_reg[4]=V; break; |
71 | case 0xD002: chr_reg[5]=V; break; |
72 | case 0xE000: chr_reg[6]=V; break; |
73 | case 0xE002: chr_reg[7]=V; break; |
74 | case 0xF000: IRQCount=IRQa=V; |
75 | X6502_IRQEnd(FCEU_IQEXT); |
76 | break; |
77 | } |
78 | Sync(); |
79 | } |
80 | |
81 | static void M222Power(void) |
82 | { |
83 | setprg16(0xC000,~0); |
84 | SetReadHandler(0x8000,0xFFFF,CartBR); |
85 | SetWriteHandler(0x8000,0xFFFF,M222Write); |
86 | } |
87 | |
88 | static void StateRestore(int version) |
89 | { |
90 | Sync(); |
91 | } |
92 | |
93 | void Mapper222_Init(CartInfo *info) |
94 | { |
95 | info->Power=M222Power; |
96 | GameHBIRQHook=M222IRQ; |
97 | GameStateRestore=StateRestore; |
98 | AddExState(&StateRegs, ~0, 0, 0); |
99 | } |