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