5b4bf054e4b5da71967589bcab6cdc8de772bfd0
[fceu.git] / boards / 164.c
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];
25
26 static SFORMAT StateRegs[]=
27 {
28   {&cmd, 1, "CMD"},
29   {DRegs, 8, "DREG"},
30   {0}
31 };
32
33 static void Sync(void)
34 {
35   setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF));
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;
76   setchr8(0);
77   cmd=0;
78   SetReadHandler(0x8000,0xFFFF,CartBR);
79   SetWriteHandler(0x4020,0xFFFF,Write);
80   SetReadHandler(0x6000,0x7FFF,AWRAM);
81   SetWriteHandler(0x6000,0x7FFF,BWRAM);
82   Sync();
83 }
84
85 static void Power2(void)
86 {
87   memset(DRegs,0,8);
88   DRegs[1]=0xFF;
89   setchr8(0);
90   cmd=0;
91   SetReadHandler(0x8000,0xFFFF,CartBR);
92   SetWriteHandler(0x4020,0xFFFF,Write2);
93   SetReadHandler(0x6000,0x7FFF,AWRAM);
94   SetWriteHandler(0x6000,0x7FFF,BWRAM);
95   Sync();
96 }
97
98 void Mapper164_Init(CartInfo *info)
99 {
100   info->Power=Power;
101   GameStateRestore=StateRestore;
102   AddExState(&StateRegs, ~0, 0, 0);
103 }
104
105 void Mapper163_Init(CartInfo *info)
106 {
107   info->Power=Power2;
108   GameStateRestore=StateRestore;
109   AddExState(&StateRegs, ~0, 0, 0);
110 }