Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/gpgx/core/membnk.c
2 views
1
/***************************************************************************************
2
* Genesis Plus
3
* Z80 bank access to 68k bus
4
*
5
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code)
6
* Copyright (C) 2007-2011 Eke-Eke (Genesis Plus GX)
7
*
8
* Redistribution and use of this code or any derivative works are permitted
9
* provided that the following conditions are met:
10
*
11
* - Redistributions may not be sold, nor may they be used in a commercial
12
* product or activity.
13
*
14
* - Redistributions that are modified from the original source must include the
15
* complete source code, including the source code for all components used by a
16
* binary built from the modified sources. However, as a special exception, the
17
* source code distributed need not include anything that is normally distributed
18
* (in either source or binary form) with the major components (compiler, kernel,
19
* and so on) of the operating system on which the executable runs, unless that
20
* component itself accompanies the executable.
21
*
22
* - Redistributions must reproduce the above copyright notice, this list of
23
* conditions and the following disclaimer in the documentation and/or other
24
* materials provided with the distribution.
25
*
26
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
* POSSIBILITY OF SUCH DAMAGE.
37
*
38
****************************************************************************************/
39
40
#include "shared.h"
41
42
/*
43
Handlers for access to unused addresses and those which make the
44
machine lock up.
45
*/
46
47
unsigned int zbank_unused_r(unsigned int address)
48
{
49
#ifdef LOGERROR
50
error("Z80 bank unused read %06X (%x)\n", address, Z80.pc.d);
51
#endif
52
return 0xFF;
53
}
54
55
void zbank_unused_w(unsigned int address, unsigned int data)
56
{
57
#ifdef LOGERROR
58
error("Z80 bank unused write %06X = %02X (%x)\n", address, data, Z80.pc.d);
59
#endif
60
}
61
62
unsigned int zbank_lockup_r(unsigned int address)
63
{
64
#ifdef LOGERROR
65
error("Z80 bank lockup read %06X (%x)\n", address, Z80.pc.d);
66
#endif
67
if (!config.force_dtack)
68
{
69
Z80.cycles = 0xFFFFFFFF;
70
zstate = 0;
71
}
72
return 0xFF;
73
}
74
75
void zbank_lockup_w(unsigned int address, unsigned int data)
76
{
77
#ifdef LOGERROR
78
error("Z80 bank lockup write %06X = %02X (%x)\n", address, data, Z80.pc.d);
79
#endif
80
if (!config.force_dtack)
81
{
82
Z80.cycles = 0xFFFFFFFF;
83
zstate = 0;
84
}
85
}
86
87
/* I/O & Control registers */
88
unsigned int zbank_read_ctrl_io(unsigned int address)
89
{
90
switch ((address >> 8) & 0xFF)
91
{
92
case 0x00: /* I/O chip */
93
{
94
if (!(address & 0xE0))
95
{
96
return (io_68k_read((address >> 1) & 0x0F));
97
}
98
return zbank_unused_r(address);
99
}
100
101
case 0x11: /* BUSACK */
102
{
103
if (address & 1)
104
{
105
return zbank_unused_r(address);
106
}
107
return 0xFF;
108
}
109
110
case 0x30: /* TIME */
111
{
112
if (cart.hw.time_r)
113
{
114
unsigned int data = cart.hw.time_r(address);
115
if (address & 1)
116
{
117
return (data & 0xFF);
118
}
119
return (data >> 8);
120
}
121
return zbank_unused_r(address);
122
}
123
124
case 0x41: /* OS ROM */
125
{
126
if (address & 1)
127
{
128
return (gen_bankswitch_r() | 0xFE);
129
}
130
return zbank_unused_r(address);
131
}
132
133
case 0x10: /* MEMORY MODE */
134
case 0x12: /* RESET */
135
case 0x20: /* MEGA-CD */
136
case 0x40: /* TMSS */
137
case 0x44: /* RADICA */
138
case 0x50: /* SVP REGISTERS */
139
{
140
return zbank_unused_r(address);
141
}
142
143
default: /* Invalid address */
144
{
145
return zbank_lockup_r(address);
146
}
147
}
148
}
149
150
void zbank_write_ctrl_io(unsigned int address, unsigned int data)
151
{
152
switch ((address >> 8) & 0xFF)
153
{
154
case 0x00: /* I/O chip */
155
{
156
/* get /LWR only */
157
if ((address & 0xE1) == 0x01)
158
{
159
io_68k_write((address >> 1) & 0x0F, data);
160
return;
161
}
162
zbank_unused_w(address, data);
163
return;
164
}
165
166
case 0x11: /* BUSREQ */
167
{
168
if (!(address & 1))
169
{
170
gen_zbusreq_w(data & 1, Z80.cycles);
171
return;
172
}
173
zbank_unused_w(address, data);
174
return;
175
}
176
177
case 0x12: /* RESET */
178
{
179
if (!(address & 1))
180
{
181
gen_zreset_w(data & 1, Z80.cycles);
182
return;
183
}
184
zbank_unused_w(address, data);
185
return;
186
}
187
188
case 0x30: /* TIME */
189
{
190
cart.hw.time_w(address, data);
191
return;
192
}
193
194
case 0x41: /* OS ROM */
195
{
196
if ((config.bios & 1) && (address & 1))
197
{
198
gen_bankswitch_w(data & 1);
199
return;
200
}
201
zbank_unused_w(address, data);
202
return;
203
}
204
205
case 0x10: /* MEMORY MODE */
206
case 0x20: /* MEGA-CD */
207
case 0x40: /* TMSS */
208
case 0x44: /* RADICA */
209
case 0x50: /* SVP REGISTERS */
210
{
211
zbank_unused_w(address, data);
212
return;
213
}
214
215
default: /* Invalid address */
216
{
217
zbank_lockup_w(address, data);
218
return;
219
}
220
}
221
}
222
223
224
/* VDP */
225
unsigned int zbank_read_vdp(unsigned int address)
226
{
227
switch (address & 0xFD)
228
{
229
case 0x00: /* DATA */
230
{
231
return (vdp_68k_data_r() >> 8);
232
}
233
234
case 0x01: /* DATA */
235
{
236
return (vdp_68k_data_r() & 0xFF);
237
}
238
239
case 0x04: /* CTRL */
240
{
241
return (((vdp_68k_ctrl_r(Z80.cycles) >> 8) & 3) | 0xFC);
242
}
243
244
case 0x05: /* CTRL */
245
{
246
return (vdp_68k_ctrl_r(Z80.cycles) & 0xFF);
247
}
248
249
case 0x08: /* HVC */
250
case 0x0C:
251
{
252
return (vdp_hvc_r(Z80.cycles) >> 8);
253
}
254
255
case 0x09: /* HVC */
256
case 0x0D:
257
{
258
return (vdp_hvc_r(Z80.cycles) & 0xFF);
259
}
260
261
case 0x18: /* Unused */
262
case 0x19:
263
case 0x1C:
264
case 0x1D:
265
{
266
return zbank_unused_r(address);
267
}
268
269
default: /* Invalid address */
270
{
271
return zbank_lockup_r(address);
272
}
273
}
274
}
275
276
void zbank_write_vdp(unsigned int address, unsigned int data)
277
{
278
switch (address & 0xFC)
279
{
280
case 0x00: /* Data port */
281
{
282
vdp_68k_data_w(data << 8 | data);
283
return;
284
}
285
286
case 0x04: /* Control port */
287
{
288
vdp_68k_ctrl_w(data << 8 | data);
289
return;
290
}
291
292
case 0x10: /* PSG */
293
case 0x14:
294
{
295
if (address & 1)
296
{
297
SN76489_Write(Z80.cycles, data);
298
return;
299
}
300
zbank_unused_w(address, data);
301
return;
302
}
303
304
case 0x18: /* Unused */
305
{
306
zbank_unused_w(address, data);
307
return;
308
}
309
310
case 0x1C: /* TEST register */
311
{
312
vdp_test_w(data << 8 | data);
313
return;
314
}
315
316
default: /* Invalid address */
317
{
318
zbank_lockup_w(address, data);
319
return;
320
}
321
}
322
}
323
324