merge mapper code from FCEUX
[fceu.git] / boards / 95.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
386f5371 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e2d0dd92 19 */
20
21#include "mapinc.h"
386f5371 22#include "../ines.h"
e2d0dd92 23
24static uint8 lastA;
25static uint8 DRegs[8];
26static uint8 cmd;
27static uint8 MirCache[8];
28
29static SFORMAT DB_StateRegs[]={
30 {DRegs, 8, "DREG"},
31 {&cmd, 1, "CMD"},
32 {&lastA, 1, "LAST"},
33 {0}
34};
35
36static void toot(void)
37{
38 int x;
39
40 MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1;
41 MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1;
42
43 for(x=0;x<4;x++)
44 MirCache[4+x]=(DRegs[2+x]>>5)&1;
45 onemir(MirCache[lastA]);
46}
47
48static void Sync()
49{
50 setchr2(0x0000,DRegs[0]&0x1F);
51 setchr2(0x0800,DRegs[1]&0x1F);
52 setchr1(0x1000,DRegs[2]&0x1F);
53 setchr1(0x1400,DRegs[3]&0x1F);
54 setchr1(0x1800,DRegs[4]&0x1F);
55 setchr1(0x1C00,DRegs[5]&0x1F);
56 setprg8(0x8000,DRegs[6]&0x1F);
57 setprg8(0xa000,DRegs[7]&0x1F);
58 toot();
59}
60
61static DECLFW(Mapper95_write)
62{
63 switch(A&0xF001)
64 {
65 case 0x8000: cmd = V; break;
66 case 0x8001:
67 switch(cmd&0x07)
68 {
69 case 0: DRegs[0]=(V&0x3F)>>1; break;
70 case 1: DRegs[1]=(V&0x3F)>>1; break;
71 case 2: DRegs[2]=V&0x3F; break;
72 case 3: DRegs[3]=V&0x3F; break;
73 case 4: DRegs[4]=V&0x3F; break;
74 case 5: DRegs[5]=V&0x3F; break;
75 case 6: DRegs[6]=V&0x3F; break;
76 case 7: DRegs[7]=V&0x3F; break;
77 }
78 Sync();
79 }
80}
81
386f5371 82static void dragonbust_ppu(uint32 A)
e2d0dd92 83{
84 static int last=-1;
85 static uint8 z;
86
87 if(A>=0x2000) return;
88
89 A>>=10;
90 lastA=A;
91 z=MirCache[A];
92 if(z!=last)
93 {
94 onemir(z);
95 last=z;
96 }
97}
98
99static void DBPower(void)
100{
101 memset(DRegs,0x3F,8);
102 DRegs[0]=DRegs[1]=0x1F;
103
104 Sync();
105
106 setprg8(0xc000,0x3E);
107 setprg8(0xe000,0x3F);
108
109 SetReadHandler(0x8000,0xffff,CartBR);
110 SetWriteHandler(0x8000,0xffff,Mapper95_write);
111}
112
113static void StateRestore(int version)
114{
115 Sync();
116}
117
118void Mapper95_Init(CartInfo *info)
119{
120 info->Power=DBPower;
121 AddExState(DB_StateRegs, ~0, 0, 0);
122 PPU_hook=dragonbust_ppu;
123 GameStateRestore=StateRestore;
124}
125