initial fce ultra 0.81 import
[fceu.git] / boards / simple.c
1 /* FCE Ultra - NES/Famicom Emulator
2  *
3  * Copyright notice for this file:
4  *  Copyright (C) 2002 Ben Parnell
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 #define CHRRAM (GameMemBlock)
24 static uint8 latche;
25
26 DECLFW(CPROMWrite)
27 {
28  latche=V&3;
29  setvram4(0x1000,CHRRAM+((V&3)<<12));
30 }
31
32 static void CPROMReset(void)
33 {
34  setprg32(0x8000,0);
35  setvram8(0);
36  SetReadHandler(0x8000,0xFFFF,CartBR);
37  SetWriteHandler(0x8000,0xffff,CPROMWrite);
38 }
39
40 static void CPROMRestore(int version)
41 {
42  setvram4(0x1000,CHRRAM+((latche)<<12));
43 }
44
45 void CPROM_Init(void)
46 {
47  BoardPower=CPROMReset;
48  GameStateRestore=CPROMRestore;
49  AddExState(&latche, 1, 0, "LATC");
50 }
51
52 DECLFW(CNROMWrite)
53 {
54  latche=V&3;
55  setchr8(V&3);
56 }
57
58 static void CNROMReset(void)
59 {
60   setprg16(0x8000,0);
61   setprg16(0xC000,1);
62   SetReadHandler(0x8000,0xFFFF,CartBR);
63   SetWriteHandler(0x8000,0xffff,CNROMWrite);
64 }
65
66 static void CNROMRestore(int version)
67 {
68  setchr8(latche);
69 }
70
71 void CNROM_Init(void)
72 {
73  BoardPower=CNROMReset;
74  GameStateRestore=CNROMRestore;
75  AddExState(&latche, 1, 0, "LATC");
76 }
77
78 static void NROM128Reset(void)
79 {
80   setprg16(0x8000,0);
81   setprg16(0xC000,0);
82   setchr8(0);
83   SetReadHandler(0x8000,0xFFFF,CartBR);
84 }
85
86 static void NROM256Reset(void)
87 {
88   setprg16(0x8000,0);
89   setprg16(0xC000,1);
90   setchr8(0);
91   SetReadHandler(0x8000,0xFFFF,CartBR);
92 }
93 void NROM128_Init(void)
94 {
95   BoardPower=NROM128Reset;
96 }
97
98 void NROM256_Init(void)
99 {
100   BoardPower=NROM256Reset;
101 }
102
103 static DECLFW(MHROMWrite)
104 {
105  setprg32(0x8000,V>>4);
106  setchr8(V);
107  latche=V;
108 }
109
110 static void MHROMReset(void)
111 {
112  setprg32(0x8000,0);
113  setchr8(0);
114  latche=0;
115  SetReadHandler(0x8000,0xFFFF,CartBR);
116 }
117
118 static void MHROMRestore(int version)
119 {
120  setprg32(0x8000,latche);
121  setchr8(latche);
122  SetWriteHandler(0x8000,0xffff,MHROMWrite);
123 }
124
125 void MHROM_Init(void)
126
127  BoardPower=MHROMReset;
128  AddExState(&latche, 1, 0,"LATC");
129  PRGmask32[0]&=1;
130  CHRmask8[0]&=1;
131  GameStateRestore=MHROMRestore;
132 }
133
134 static void UNROMRestore(int version)
135 {
136  setprg16(0x8000,latche);
137 }
138
139 static DECLFW(UNROMWrite)
140 {
141  setprg16(0x8000,V);
142  latche=V;
143 }
144
145 static void UNROMReset(void)
146 {
147  setprg16(0x8000,0);
148  setprg16(0xc000,~0);
149  setvram8(CHRRAM);
150  SetWriteHandler(0x8000,0xffff,UNROMWrite);
151  SetReadHandler(0x8000,0xFFFF,CartBR);
152  latche=0;
153 }
154
155 void UNROM_Init(void)
156 {
157  BoardPower=UNROMReset;
158  PRGmask16[0]&=7;
159  AddExState(&latche, 1, 0, "LATC");
160  AddExState(CHRRAM, 8192, 0, "CHRR");
161  GameStateRestore=UNROMRestore;
162 }