forked from p1pkin/demul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gdrom.c
279 lines (230 loc) · 5.28 KB
/
Gdrom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* Demul
* Copyright (C) 2006 Demul Team
*
* Demul is not free software: you can't redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Demul isn't distributed in the hope that it will be useful,
* and WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#include <stdio.h>
#include <string.h>
#include "console.h"
#include "gdrom.h"
#include "asic.h"
#include "sh4.h"
#include "counters.h"
#include "plugins.h"
u8 ReadGdrom8(u32 mem) {
switch (mem & 0x007fffff) {
case 0x005f7018: return gdrom.busy;
case 0x005f708C: return gdrGetStatus();
case 0x005f7090: return gdrom.cntlo;
case 0x005f7094: return gdrom.cnthi;
case 0x005f709C:
ASIC8(0x6904) &= ~1;
return gdrom.busy;
default:
return 0;
}
}
u16 ReadGdrom16(u32 mem) {
u16 value = ((u16*)buffer)[index++];
if ((count -= 2) == 0) {
count = index * 2;
index = 0;
gdrom.busy &= 0x37;
gdrom.busy |= 0x40;
hwInt(0x0100);
}
return value;
}
void WriteGdrom8(u32 mem, u8 value) {
switch (mem & 0x007fffff) {
case 0x005f7018: gdrom.busy = value; return;
case 0x005f7084: gdrom.ftrs = value; return;
case 0x005f7088: gdrom.irsn = value; return;
case 0x005f708C: gdrom.stat = value; return;
case 0x005f7090: gdrom.cntlo = value; return;
case 0x005f7094: gdrom.cnthi = value; return;
case 0x005f709C:
switch (value) {
case 0x00:
gdrom.busy &= 0x76;
gdrom.busy |= 0x01;
hwInt(0x0100);
return;
case 0xa0:
index = 0;
gdrom.busy &= 0xfe;
gdrom.busy |= 0x08;
return;
default:
//Printf("gdrom unknown command 0x%02x", value);
return;
}
default:
return;
}
}
void WriteGdrom16(u32 mem, u16 value) {
u16 *data = (u16*)&buffer;
data[index++] = value;
if (index == 6) {
index = 0;
gdrom.busy &= 0xf7;
gdrom.busy |= 0x80;
switch (buffer[0]) {
case 0x00:
gdrom.busy &= 0x37;
gdrom.busy |= 0x40;
hwInt(0x0100);
break;
case 0x10:
{
u8 *src = &rom[2188];
u8 *dst = buffer;
u32 size = buffer[4];
memcpy(dst, src, size);
count = size;
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
break;
}
case 0x11:
{
u8 *src = &rom[1976] + buffer[2];
u8 *dst = buffer;
u32 size = buffer[4];
memcpy(dst, src, size);
count = size;
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
break;
}
/*
case 0x13:
gdrom.busy = 0x58;//(gdrom.busy & 0x37) | 0x40;
buffer[0] = 0x00f0;
buffer[1] = 0x0002;
buffer[2] = 0x0000;
buffer[3] = 0x0000;
buffer[4] = 0x003a;
buffer[5] = 0x0000;
hwInt(31, 0x0100);
break;
*/
case 0x14:
{
u8 size[2] = { buffer[4], buffer[3] };
gdrReadTOC(buffer, (u32) * (u16*)size);
count = (u32) * (u16*)size;
gdrom.cntlo = size[0];
gdrom.cnthi = size[1];
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
break;
}
case 0x15:
{
u32 session = buffer[2];
u32 size = (u32)buffer[4];
gdrReadInfoSession(buffer, session, size);
count = size;
gdrom.cntlo = (u8)size;
gdrom.cnthi = 0;
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
break;
}
case 0x20:
case 0x21:
gdrom.busy &= 0x37;
gdrom.busy |= 0x40;
hwInt(0x0100);
break;
case 0x30:
{
u32 length = ((u32)buffer[9] << 8) | ((u32)buffer[10]);
u32 sector = ((u32)buffer[2] << 16) | ((u32)buffer[3] << 8) | ((u32)buffer[4]);
u32 mode = ((u32)buffer[1]);
gdrReadSectors(buffer, sector, length, mode);
if (gdrom.ftrs & 1) {
position = 0;
bufsize = length * 2048;
gdrom.busy &= 0xf7;
gdrom.busy |= 0x80;
} else {
count = length * 2048;
gdrom.cntlo = ((count >> 0) & 0xff);
gdrom.cnthi = ((count >> 8) & 0xff);
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
}
break;
}
case 0x40:
{
u8 *src;
u8 *dst = buffer;
u32 size = (u32)buffer[4];
switch (buffer[1] & 3) {
case 0: src = &rom[2024]; break;
case 1: src = &rom[2124]; break;
case 2: src = &rom[2140]; break;
case 3: src = &rom[2164]; break;
}
memcpy(dst, src, size);
count = size;
gdrom.cntlo = ((size >> 0) & 0xff);
gdrom.cnthi = ((size >> 8) & 0xff);
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
break;
}
case 0x70:
gdrom.busy = 0x50;
hwInt(0x0100);
break;
case 0x71:
{
static u32 flag = 0;
if (!flag) {
u8 *src = &rom[0];
u8 *dst = buffer;
memcpy(dst, src, 0x3f4);
count = 0x03f4;
gdrom.cntlo = 0xf4;
gdrom.cnthi = 0x03;
flag = 1;
} else {
u8 *src = &rom[0x3f8];
u8 *dst = buffer;
memcpy(dst, src, 0x3c0);
count = 0x03c0;
gdrom.cntlo = 0xC0;
gdrom.cnthi = 0x03;
flag = 0;
}
gdrom.busy &= 0x76;
gdrom.busy |= 0x08;
hwInt(0x0100);
break;
}
default:
//Printf("gdrom packet unknown command 0x%02x", buffer[0]);
break;
}
}
}