c62d2810 |
1 | /* FCE Ultra - NES/Famicom Emulator |
2 | * |
3 | * Copyright notice for this file: |
d97315ac |
4 | * Copyright (C) 2002 Xodnizel |
c62d2810 |
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 | |
d97315ac |
23 | static uint8 lastA; |
24 | static uint8 DRegs[8]; |
25 | static uint8 cmd; |
26 | static uint8 MirCache[8]; |
27 | |
28 | static SFORMAT DB_StateRegs[]={ |
29 | {DRegs, 8, "DREG"}, |
30 | {&cmd, 1, "CMD"}, |
31 | {&lastA, 1, "LAST"}, |
32 | {0} |
33 | }; |
c62d2810 |
34 | |
c62d2810 |
35 | static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A) |
36 | { |
37 | static int last=-1; |
38 | static uint8 z; |
39 | |
40 | if(A>=0x2000) return; |
41 | |
d97315ac |
42 | A>>=10; |
c62d2810 |
43 | |
d97315ac |
44 | lastA=A; |
c62d2810 |
45 | |
d97315ac |
46 | z=MirCache[A]; |
c62d2810 |
47 | if(z!=last) |
48 | { |
49 | onemir(z); |
50 | last=z; |
51 | } |
52 | } |
53 | |
d97315ac |
54 | static void toot(void) |
55 | { |
56 | int x; |
57 | |
58 | MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1; |
59 | MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1; |
c62d2810 |
60 | |
d97315ac |
61 | for(x=0;x<4;x++) |
62 | MirCache[4+x]=(DRegs[2+x]>>5)&1; |
63 | onemir(MirCache[lastA]); |
64 | } |
65 | |
66 | static DECLFW(Mapper95_write) |
c62d2810 |
67 | { |
d97315ac |
68 | switch(A&0xF001) |
69 | { |
70 | |
71 | case 0x8000: |
72 | cmd = V; |
73 | break; |
74 | |
75 | case 0x8001: |
76 | switch(cmd&0x07) |
77 | { |
78 | case 0: DRegs[0]=(V&0x3F)>>1;toot();V>>=1;setchr2(0x0000,V&0x1F);break; |
79 | case 1: DRegs[1]=(V&0x3F)>>1;toot();V>>=1;setchr2(0x0800,V&0x1F);break; |
80 | case 2: DRegs[2]=V&0x3F;toot();setchr1(0x1000,V&0x1F); break; |
81 | case 3: DRegs[3]=V&0x3F;toot();setchr1(0x1400,V&0x1F); break; |
82 | case 4: DRegs[4]=V&0x3F;toot();setchr1(0x1800,V&0x1F); break; |
83 | case 5: DRegs[5]=V&0x3F;toot();setchr1(0x1C00,V&0x1F); break; |
84 | case 6: DRegs[6]=V&0x3F; |
85 | setprg8(0x8000,V); |
86 | break; |
87 | case 7: DRegs[7]=V&0x3F; |
88 | setprg8(0xA000,V); |
89 | break; |
c62d2810 |
90 | } |
91 | break; |
d97315ac |
92 | } |
c62d2810 |
93 | } |
d97315ac |
94 | |
95 | static void DBSync() |
96 | { |
97 | int x; |
98 | |
99 | setchr2(0x0000,DRegs[0]); |
100 | setchr2(0x0800,DRegs[1]); |
101 | |
102 | for(x=0;x<4;x++) |
103 | setchr1(0x1000+x*0x400,DRegs[2+x]); |
104 | |
105 | setprg8(0x8000,DRegs[6]); |
106 | setprg8(0xa000,DRegs[7]); |
107 | toot(); |
108 | } |
109 | |
110 | static void DBPower(void) |
111 | { |
112 | memset(DRegs,0x3F,8); |
113 | DRegs[0]=DRegs[1]=0x1F; |
114 | |
115 | DBSync(); |
116 | |
117 | setprg8(0xc000,0x3E); |
118 | setprg8(0xe000,0x3F); |
119 | |
120 | SetReadHandler(0x8000,0xffff,CartBR); |
121 | SetWriteHandler(0x8000,0xffff,Mapper95_write); |
122 | } |
123 | |
124 | static void StateRestore(int version) |
125 | { |
126 | DBSync(); |
c62d2810 |
127 | } |
128 | |
d97315ac |
129 | void Mapper95_Init(CartInfo *info) |
c62d2810 |
130 | { |
d97315ac |
131 | info->Power=DBPower; |
132 | AddExState(DB_StateRegs, ~0, 0, 0); |
c62d2810 |
133 | PPU_hook=dragonbust_ppu; |
d97315ac |
134 | GameStateRestore=StateRestore; |
c62d2810 |
135 | } |
136 | |