Subversion Repositories psp

[/] [trunk/] [genplus/] [memz80.c] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 62 jack
/*
2
    memz80.c --
3
    Memory handlers for Z80 memory and port access, and the Z80 to
4
    VDP interface.
5
*/
6
 
7
#define LOG_PORT 0      /* 1= Log Z80 I/O port accesses */
8
 
9
#include "shared.h"
10
 
11
 
12
unsigned int cpu_readmem16(unsigned int address)
13
{
14
    switch((address >> 13) & 7)
15
    {
16
        case 0: /* Work RAM */
17
        case 1:
18
            return zram[address & 0x1FFF];
19
 
20
        case 2: /* YM2612 */
21
            return fm_read(address & 3);
22
 
23
        case 3: /* VDP */
24
            if((address & 0xFF00) == 0x7F00)
25
                return z80_vdp_r(address);
26
            return 0xFF;
27
 
28
        default: /* V-bus bank */
29
            return z80_read_banked_memory(zbank | (address & 0x7FFF));
30
    }
31
 
32
    return 0xFF;
33
}
34
 
35
 
36
void cpu_writemem16(unsigned int address, unsigned int data)
37
{
38
    switch((address >> 13) & 7)
39
    {
40
        case 0: /* Work RAM */
41
        case 1:
42
            zram[address & 0x1FFF] = data;
43
            return;
44
 
45
        case 2: /* YM2612 */
46
            fm_write(address & 3, data);
47
            return;
48
 
49
        case 3: /* Bank register and VDP */
50
            switch(address & 0xFF00)
51
            {
52
                case 0x6000:
53
                    gen_bank_w(data & 1);
54
                    return;
55
 
56
                case 0x7F00:
57
                    z80_vdp_w(address, data);
58
                    return;
59
 
60
                default:
61
                    z80_unused_w(address, data);
62
                    return;
63
            }
64
            return;
65
 
66
        default: /* V-bus bank */
67
            z80_write_banked_memory(zbank | (address & 0x7FFF), data);
68
            return;
69
    }
70
}
71
 
72
 
73
int z80_vdp_r(int address)
74
{
75
    switch(address & 0xFF)
76
    {
77
        case 0x00: /* VDP data port */
78
        case 0x02:
79
            return (vdp_data_r() >> 8) & 0xFF;
80
 
81
        case 0x01: /* VDP data port */
82
        case 0x03:
83
            return (vdp_data_r() & 0xFF);
84
 
85
        case 0x04: /* VDP control port */
86
        case 0x06:
87
            return (0xFF | ((vdp_ctrl_r() >> 8) & 3));
88
 
89
        case 0x05: /* VDP control port */
90
        case 0x07:
91
            return (vdp_ctrl_r() & 0xFF);
92
 
93
        case 0x08: /* HV counter */
94
        case 0x0A:
95
        case 0x0C:
96
        case 0x0E:
97
            return (vdp_hvc_r() >> 8) & 0xFF;
98
 
99
        case 0x09: /* HV counter */
100
        case 0x0B:
101
        case 0x0D:
102
        case 0x0F:
103
            return (vdp_hvc_r() & 0xFF);
104
 
105
        case 0x10: /* Unused (PSG) */
106
        case 0x11:
107
        case 0x12:
108
        case 0x13:
109
        case 0x14:
110
        case 0x15:
111
        case 0x16:
112
        case 0x17:
113
            return z80_lockup_r(address);
114
 
115
        case 0x18: /* Unused */
116
        case 0x19:
117
        case 0x1A:
118
        case 0x1B:
119
            return z80_unused_r(address);
120
 
121
        case 0x1C: /* Unused (test register) */
122
        case 0x1D:
123
        case 0x1E:
124
        case 0x1F:
125
            return z80_unused_r(address);
126
 
127
        default: /* Invalid VDP addresses */
128
            return z80_lockup_r(address);
129
    }
130
 
131
    return 0xFF;
132
}
133
 
134
 
135
void z80_vdp_w(int address, int data)
136
{
137
    switch(address & 0xFF)
138
    {
139
        case 0x00: /* VDP data port */
140
        case 0x01:
141
        case 0x02:
142
        case 0x03:
143
            vdp_data_w(data << 8 | data);
144
            return;
145
 
146
        case 0x04: /* VDP control port */
147
        case 0x05:
148
        case 0x06:
149
        case 0x07:
150
            vdp_ctrl_w(data << 8 | data);
151
            return;
152
 
153
        case 0x08: /* Unused (HV counter) */
154
        case 0x09:
155
        case 0x0A:
156
        case 0x0B:
157
        case 0x0C:
158
        case 0x0D:
159
        case 0x0E:
160
        case 0x0F:
161
            z80_lockup_w(address, data);
162
            return;
163
 
164
        case 0x11: /* PSG */
165
        case 0x13:
166
        case 0x15:
167
        case 0x17:
168
            psg_write(data);
169
            return;
170
 
171
        case 0x10: /* Unused */
172
        case 0x12:
173
        case 0x14:
174
        case 0x16:
175
            z80_unused_w(address, data);
176
 
177
        case 0x18: /* Unused */
178
        case 0x19:
179
        case 0x1A:
180
        case 0x1B:
181
            z80_unused_w(address, data);
182
            return;
183
 
184
        case 0x1C: /* Test register */
185
        case 0x1D:
186
        case 0x1E:
187
        case 0x1F:
188
            vdp_test_w(data << 8 | data);
189
            return;
190
 
191
        default: /* Invalid VDP addresses */
192
            z80_lockup_w(address, data);
193
            return;
194
    }
195
}
196
 
197
 
198
/*
199
    Port handlers. Ports are unused when not in Mark III compatability mode.
200
 
201
    Games that access ports anyway:
202
    - Thunder Force IV reads port $BF in it's interrupt handler.
203
*/
204
 
205
unsigned int cpu_readport16(unsigned int port)
206
{
207
#if LOG_PORT
208
    error("Z80 read port %04X (%04X)\n", port, z80_get_reg(Z80_PC));
209
#endif    
210
    return 0xFF;
211
}
212
 
213
void cpu_writeport16(unsigned int port, unsigned int data)
214
{
215
#if LOG_PORT
216
    error("Z80 write %02X to port %04X (%04X)\n", data, port, z80_get_reg(Z80_PC));
217
#endif
218
}
219
 
220
 
221
/*
222
    Handlers for access to unused addresses and those which make the
223
    machine lock up.
224
*/
225
void z80_unused_w(int address, int data)
226
{
227
    error("Z80 unused write %04X = %02X (%04X)\n", address, data, z80_get_reg(Z80_PC));
228
}
229
 
230
int z80_unused_r(int address)
231
{
232
    error("Z80 unused read %04X (%04X)\n", address, z80_get_reg(Z80_PC));
233
    return 0xFF;
234
}
235
 
236
void z80_lockup_w(int address, int data)
237
{
238
    error("Z80 lockup write %04X = %02X (%04X)\n", address, data, z80_get_reg(Z80_PC));
239
    gen_running = 0;
240
    z80_end_timeslice();
241
}
242
 
243
int z80_lockup_r(int address)
244
{
245
    error("Z80 lockup read %04X (%04X)\n", address, z80_get_reg(Z80_PC));
246
    gen_running = 0;
247
    z80_end_timeslice();
248
    return 0xFF;
249
}
250