merge mapper code from FCEUX
[fceu.git] / boards / deirom.c
CommitLineData
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
386f5371 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
d97315ac 19 */
20
21#include "mapinc.h"
22
23static uint8 cmd;
24static uint8 DRegs[8];
25
26static SFORMAT DEI_StateRegs[]=
27{
28 {&cmd, 1, "CMD"},
29 {DRegs, 8, "DREG"},
30 {0}
31};
32
33static void Sync(void)
34{
386f5371 35 int x;
d97315ac 36 setchr2(0x0000,DRegs[0]);
37 setchr2(0x0800,DRegs[1]);
d97315ac 38 for(x=0;x<4;x++)
39 setchr1(0x1000+(x<<10),DRegs[2+x]);
40 setprg8(0x8000,DRegs[6]);
41 setprg8(0xa000,DRegs[7]);
42}
43
44static void StateRestore(int version)
45{
46 Sync();
47}
48
49static DECLFW(DEIWrite)
50{
51 switch(A&0x8001)
52 {
53 case 0x8000: cmd=V&0x07; break;
54 case 0x8001: if(cmd<=0x05)
55 V&=0x3F;
56 else
57 V&=0x0F;
58 if(cmd<=0x01) V>>=1;
59 DRegs[cmd&0x07]=V;
60 Sync();
61 break;
62 }
63}
64
65static void DEIPower(void)
66{
67 setprg8(0xc000,0xE);
68 setprg8(0xe000,0xF);
69 cmd=0;
70 memset(DRegs,0,8);
71 Sync();
72 SetReadHandler(0x8000,0xFFFF,CartBR);
73 SetWriteHandler(0x8000,0xFFFF,DEIWrite);
74}
75
76
77void DEIROM_Init(CartInfo *info)
78{
79 info->Power=DEIPower;
80 GameStateRestore=StateRestore;
81 AddExState(&DEI_StateRegs, ~0, 0, 0);
82}