d97315ac |
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 cmd; |
24 | static uint8 DRegs[8]; |
d97315ac |
25 | static SFORMAT StateRegs[]= |
26 | { |
27 | {&cmd, 1, "CMD"}, |
28 | {DRegs, 8, "DREG"}, |
29 | {0} |
30 | }; |
31 | |
32 | static void Sync(void) |
33 | { |
34 | setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF)); |
e2d0dd92 |
35 | setchr8(0); |
d97315ac |
36 | } |
37 | |
38 | static void StateRestore(int version) |
39 | { |
40 | Sync(); |
41 | } |
42 | |
43 | static DECLFW(Write) |
44 | { |
45 | switch (A&0x7300) |
46 | { |
47 | case 0x5100: DRegs[0]=V; Sync(); break; |
48 | case 0x5000: DRegs[1]=V; Sync(); break; |
49 | } |
50 | } |
51 | |
52 | static DECLFW(Write2) |
53 | { |
54 | switch (A&0x7300) |
55 | { |
56 | case 0x5200: DRegs[0]=V; Sync(); break; |
57 | case 0x5000: DRegs[1]=V; Sync(); break; |
58 | } |
59 | } |
60 | |
61 | static uint8 WRAM[8192]; |
62 | static DECLFR(AWRAM) |
63 | { |
64 | return(WRAM[A-0x6000]); |
65 | } |
66 | |
67 | static DECLFW(BWRAM) |
68 | { |
69 | WRAM[A-0x6000]=V; |
70 | } |
71 | |
72 | static void Power(void) |
73 | { |
74 | memset(DRegs,0,8); |
75 | DRegs[1]=0xFF; |
d97315ac |
76 | cmd=0; |
77 | SetReadHandler(0x8000,0xFFFF,CartBR); |
78 | SetWriteHandler(0x4020,0xFFFF,Write); |
79 | SetReadHandler(0x6000,0x7FFF,AWRAM); |
80 | SetWriteHandler(0x6000,0x7FFF,BWRAM); |
81 | Sync(); |
82 | } |
83 | |
e2d0dd92 |
84 | static void M163HB(void) |
85 | { |
86 | if(scanline==127&&DRegs[1]&0x80) |
87 | setchr4(0x0000,1); |
88 | } |
89 | |
90 | |
d97315ac |
91 | static void Power2(void) |
92 | { |
93 | memset(DRegs,0,8); |
94 | DRegs[1]=0xFF; |
d97315ac |
95 | cmd=0; |
96 | SetReadHandler(0x8000,0xFFFF,CartBR); |
97 | SetWriteHandler(0x4020,0xFFFF,Write2); |
98 | SetReadHandler(0x6000,0x7FFF,AWRAM); |
99 | SetWriteHandler(0x6000,0x7FFF,BWRAM); |
100 | Sync(); |
101 | } |
102 | |
103 | void Mapper164_Init(CartInfo *info) |
104 | { |
105 | info->Power=Power; |
106 | GameStateRestore=StateRestore; |
107 | AddExState(&StateRegs, ~0, 0, 0); |
108 | } |
109 | |
110 | void Mapper163_Init(CartInfo *info) |
111 | { |
112 | info->Power=Power2; |
e2d0dd92 |
113 | GameHBIRQHook=M163HB; |
d97315ac |
114 | GameStateRestore=StateRestore; |
115 | AddExState(&StateRegs, ~0, 0, 0); |
116 | } |