Commit | Line | Data |
---|---|---|
ef79bbde P |
1 | /*************************************************************************** |
2 | * Copyright (C) 2007 PCSX-df Team * | |
3 | * Copyright (C) 2009 Wei Mingzhi * | |
77160d47 | 4 | * Copyright (C) 2012 notaz * |
ef79bbde P |
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 * | |
18 | * Free Software Foundation, Inc., * | |
deebc67f | 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * |
ef79bbde P |
20 | ***************************************************************************/ |
21 | ||
22 | #include "psxcommon.h" | |
23 | #include "plugins.h" | |
24 | #include "cdrom.h" | |
25 | #include "cdriso.h" | |
ae4e7dc9 | 26 | #include "ppf.h" |
ef79bbde P |
27 | |
28 | #ifdef _WIN32 | |
29 | #include <process.h> | |
30 | #include <windows.h> | |
deebc67f | 31 | #define strcasecmp _stricmp |
ef79bbde P |
32 | #else |
33 | #include <pthread.h> | |
34 | #include <sys/time.h> | |
349f7d81 | 35 | #include <unistd.h> |
ef79bbde | 36 | #endif |
9a92bffb | 37 | #include <zlib.h> |
ef79bbde | 38 | |
0c2871a7 | 39 | unsigned int cdrIsoMultidiskCount; |
40 | unsigned int cdrIsoMultidiskSelect; | |
41 | ||
ef79bbde P |
42 | static FILE *cdHandle = NULL; |
43 | static FILE *cddaHandle = NULL; | |
44 | static FILE *subHandle = NULL; | |
45 | ||
46 | static boolean subChanMixed = FALSE; | |
47 | static boolean subChanRaw = FALSE; | |
8aa91443 | 48 | static boolean subChanMissing = FALSE; |
ef79bbde | 49 | |
deebc67f | 50 | static boolean multifile = FALSE; |
51 | ||
81abe4d5 | 52 | static unsigned char cdbuffer[CD_FRAMESIZE_RAW]; |
ef79bbde P |
53 | static unsigned char subbuffer[SUB_FRAMESIZE]; |
54 | ||
55 | static unsigned char sndbuffer[CD_FRAMESIZE_RAW * 10]; | |
56 | ||
57 | #define CDDA_FRAMETIME (1000 * (sizeof(sndbuffer) / CD_FRAMESIZE_RAW) / 75) | |
58 | ||
59 | #ifdef _WIN32 | |
60 | static HANDLE threadid; | |
61 | #else | |
62 | static pthread_t threadid; | |
63 | #endif | |
64 | static unsigned int initial_offset = 0; | |
38b8102c | 65 | static boolean playing = FALSE; |
ef79bbde | 66 | static boolean cddaBigEndian = FALSE; |
77160d47 | 67 | // cdda sectors in toc, byte offset in file |
9a92bffb | 68 | static unsigned int cdda_cur_sector; |
2058d51f | 69 | static unsigned int cdda_first_sector; |
77160d47 | 70 | static unsigned int cdda_file_offset; |
8aa91443 | 71 | /* Frame offset into CD image where pregap data would be found if it was there. |
72 | * If a game seeks there we must *not* return subchannel data since it's | |
73 | * not in the CD image, so that cdrom code can fake subchannel data instead. | |
74 | * XXX: there could be multiple pregaps but PSX dumps only have one? */ | |
75 | static unsigned int pregapOffset; | |
ef79bbde | 76 | |
deebc67f | 77 | #define cddaCurPos cdda_cur_sector |
78 | ||
9a92bffb | 79 | // compressed image stuff |
80 | static struct { | |
81 | unsigned char buff_raw[16][CD_FRAMESIZE_RAW]; | |
82 | unsigned char buff_compressed[CD_FRAMESIZE_RAW * 16 + 100]; | |
83 | unsigned int *index_table; | |
84 | unsigned int index_len; | |
0877957a | 85 | unsigned int block_shift; |
9a92bffb | 86 | unsigned int current_block; |
87 | unsigned int sector_in_blk; | |
88 | } *compr_img; | |
89 | ||
77160d47 | 90 | int (*cdimg_read_func)(FILE *f, unsigned int base, void *dest, int sector); |
9a92bffb | 91 | |
ef79bbde P |
92 | char* CALLBACK CDR__getDriveLetter(void); |
93 | long CALLBACK CDR__configure(void); | |
94 | long CALLBACK CDR__test(void); | |
95 | void CALLBACK CDR__about(void); | |
96 | long CALLBACK CDR__setfilename(char *filename); | |
97 | long CALLBACK CDR__getStatus(struct CdrStat *stat); | |
98 | ||
19c03d80 | 99 | static void DecodeRawSubData(void); |
100 | ||
ef79bbde | 101 | struct trackinfo { |
deebc67f | 102 | enum {DATA=1, CDDA} type; |
ef79bbde P |
103 | char start[3]; // MSF-format |
104 | char length[3]; // MSF-format | |
38b8102c | 105 | FILE *handle; // for multi-track images CDDA |
77160d47 | 106 | unsigned int start_offset; // byte offset from start of above file |
ef79bbde P |
107 | }; |
108 | ||
109 | #define MAXTRACKS 100 /* How many tracks can a CD hold? */ | |
110 | ||
111 | static int numtracks = 0; | |
112 | static struct trackinfo ti[MAXTRACKS]; | |
113 | ||
114 | // get a sector from a msf-array | |
115 | static unsigned int msf2sec(char *msf) { | |
116 | return ((msf[0] * 60 + msf[1]) * 75) + msf[2]; | |
117 | } | |
118 | ||
119 | static void sec2msf(unsigned int s, char *msf) { | |
120 | msf[0] = s / 75 / 60; | |
121 | s = s - msf[0] * 75 * 60; | |
122 | msf[1] = s / 75; | |
123 | s = s - msf[1] * 75; | |
124 | msf[2] = s; | |
125 | } | |
126 | ||
127 | // divide a string of xx:yy:zz into m, s, f | |
128 | static void tok2msf(char *time, char *msf) { | |
129 | char *token; | |
130 | ||
131 | token = strtok(time, ":"); | |
132 | if (token) { | |
133 | msf[0] = atoi(token); | |
134 | } | |
135 | else { | |
136 | msf[0] = 0; | |
137 | } | |
138 | ||
139 | token = strtok(NULL, ":"); | |
140 | if (token) { | |
141 | msf[1] = atoi(token); | |
142 | } | |
143 | else { | |
144 | msf[1] = 0; | |
145 | } | |
146 | ||
147 | token = strtok(NULL, ":"); | |
148 | if (token) { | |
149 | msf[2] = atoi(token); | |
150 | } | |
151 | else { | |
152 | msf[2] = 0; | |
153 | } | |
154 | } | |
155 | ||
156 | #ifndef _WIN32 | |
157 | static long GetTickCount(void) { | |
158 | static time_t initial_time = 0; | |
159 | struct timeval now; | |
160 | ||
161 | gettimeofday(&now, NULL); | |
162 | ||
163 | if (initial_time == 0) { | |
164 | initial_time = now.tv_sec; | |
165 | } | |
166 | ||
167 | return (now.tv_sec - initial_time) * 1000L + now.tv_usec / 1000L; | |
168 | } | |
169 | #endif | |
170 | ||
171 | // this thread plays audio data | |
172 | #ifdef _WIN32 | |
173 | static void playthread(void *param) | |
174 | #else | |
175 | static void *playthread(void *param) | |
176 | #endif | |
177 | { | |
983a7cfd | 178 | long osleep, d, t, i, s; |
ef79bbde | 179 | unsigned char tmp; |
77160d47 | 180 | int ret = 0, sector_offs; |
ef79bbde P |
181 | |
182 | t = GetTickCount(); | |
183 | ||
184 | while (playing) { | |
9a92bffb | 185 | s = 0; |
186 | for (i = 0; i < sizeof(sndbuffer) / CD_FRAMESIZE_RAW; i++) { | |
77160d47 | 187 | sector_offs = cdda_cur_sector - cdda_first_sector; |
188 | if (sector_offs < 0) { | |
189 | d = CD_FRAMESIZE_RAW; | |
190 | memset(sndbuffer + s, 0, d); | |
191 | } | |
192 | else { | |
193 | d = cdimg_read_func(cddaHandle, cdda_file_offset, | |
194 | sndbuffer + s, sector_offs); | |
195 | if (d < CD_FRAMESIZE_RAW) | |
196 | break; | |
197 | } | |
2058d51f | 198 | |
9a92bffb | 199 | s += d; |
200 | cdda_cur_sector++; | |
ef79bbde | 201 | } |
19c03d80 | 202 | |
ef79bbde P |
203 | if (s == 0) { |
204 | playing = FALSE; | |
ef79bbde P |
205 | initial_offset = 0; |
206 | break; | |
207 | } | |
208 | ||
209 | if (!cdr.Muted && playing) { | |
210 | if (cddaBigEndian) { | |
211 | for (i = 0; i < s / 2; i++) { | |
212 | tmp = sndbuffer[i * 2]; | |
213 | sndbuffer[i * 2] = sndbuffer[i * 2 + 1]; | |
214 | sndbuffer[i * 2 + 1] = tmp; | |
215 | } | |
216 | } | |
217 | ||
53598a71 | 218 | // can't do it yet due to readahead.. |
219 | //cdrAttenuate((short *)sndbuffer, s / 4, 1); | |
983a7cfd | 220 | do { |
221 | ret = SPU_playCDDAchannel((short *)sndbuffer, s); | |
222 | if (ret == 0x7761) | |
223 | usleep(6 * 1000); | |
224 | } while (ret == 0x7761 && playing); // rearmed_wait | |
ef79bbde | 225 | } |
983a7cfd | 226 | |
227 | if (ret != 0x676f) { // !rearmed_go | |
228 | // do approx sleep | |
229 | long now; | |
230 | ||
231 | // HACK: stop feeding data while emu is paused | |
232 | extern int stop; | |
233 | while (stop && playing) | |
234 | usleep(10000); | |
235 | ||
236 | now = GetTickCount(); | |
237 | osleep = t - now; | |
238 | if (osleep <= 0) { | |
239 | osleep = 1; | |
240 | t = now; | |
241 | } | |
242 | else if (osleep > CDDA_FRAMETIME) { | |
243 | osleep = CDDA_FRAMETIME; | |
244 | t = now; | |
245 | } | |
246 | ||
247 | usleep(osleep * 1000); | |
248 | t += CDDA_FRAMETIME; | |
249 | } | |
250 | ||
ef79bbde P |
251 | } |
252 | ||
253 | #ifdef _WIN32 | |
254 | _endthread(); | |
255 | #else | |
256 | pthread_exit(0); | |
257 | return NULL; | |
258 | #endif | |
259 | } | |
260 | ||
261 | // stop the CDDA playback | |
262 | static void stopCDDA() { | |
263 | if (!playing) { | |
264 | return; | |
265 | } | |
266 | ||
267 | playing = FALSE; | |
268 | #ifdef _WIN32 | |
269 | WaitForSingleObject(threadid, INFINITE); | |
270 | #else | |
271 | pthread_join(threadid, NULL); | |
272 | #endif | |
ef79bbde P |
273 | } |
274 | ||
275 | // start the CDDA playback | |
77160d47 | 276 | static void startCDDA(void) { |
ef79bbde | 277 | if (playing) { |
ef79bbde P |
278 | stopCDDA(); |
279 | } | |
280 | ||
ef79bbde P |
281 | playing = TRUE; |
282 | ||
283 | #ifdef _WIN32 | |
284 | threadid = (HANDLE)_beginthread(playthread, 0, NULL); | |
285 | #else | |
286 | pthread_create(&threadid, NULL, playthread, NULL); | |
287 | #endif | |
288 | } | |
289 | ||
290 | // this function tries to get the .toc file of the given .bin | |
291 | // the necessary data is put into the ti (trackinformation)-array | |
292 | static int parsetoc(const char *isofile) { | |
293 | char tocname[MAXPATHLEN]; | |
294 | FILE *fi; | |
e999be41 | 295 | char linebuf[256], tmp[256], name[256]; |
ef79bbde P |
296 | char *token; |
297 | char time[20], time2[20]; | |
e999be41 | 298 | unsigned int t, sector_offs, sector_size; |
299 | unsigned int current_zero_gap = 0; | |
ef79bbde P |
300 | |
301 | numtracks = 0; | |
302 | ||
303 | // copy name of the iso and change extension from .bin to .toc | |
304 | strncpy(tocname, isofile, sizeof(tocname)); | |
305 | tocname[MAXPATHLEN - 1] = '\0'; | |
306 | if (strlen(tocname) >= 4) { | |
307 | strcpy(tocname + strlen(tocname) - 4, ".toc"); | |
308 | } | |
309 | else { | |
310 | return -1; | |
311 | } | |
312 | ||
313 | if ((fi = fopen(tocname, "r")) == NULL) { | |
314 | // try changing extension to .cue (to satisfy some stupid tutorials) | |
315 | strcpy(tocname + strlen(tocname) - 4, ".cue"); | |
316 | if ((fi = fopen(tocname, "r")) == NULL) { | |
317 | // if filename is image.toc.bin, try removing .bin (for Brasero) | |
318 | strcpy(tocname, isofile); | |
319 | t = strlen(tocname); | |
320 | if (t >= 8 && strcmp(tocname + t - 8, ".toc.bin") == 0) { | |
321 | tocname[t - 4] = '\0'; | |
322 | if ((fi = fopen(tocname, "r")) == NULL) { | |
323 | return -1; | |
324 | } | |
325 | } | |
326 | else { | |
327 | return -1; | |
328 | } | |
329 | } | |
92f43ab0 | 330 | // check if it's really a TOC named as a .cue |
331 | fgets(linebuf, sizeof(linebuf), fi); | |
332 | token = strtok(tmp, " "); | |
333 | if (strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) { | |
334 | fclose(fi); | |
335 | return -1; | |
336 | } | |
337 | fseek(fi, 0, SEEK_SET); | |
ef79bbde P |
338 | } |
339 | ||
340 | memset(&ti, 0, sizeof(ti)); | |
341 | cddaBigEndian = TRUE; // cdrdao uses big-endian for CD Audio | |
342 | ||
e999be41 | 343 | sector_size = CD_FRAMESIZE_RAW; |
19c03d80 | 344 | sector_offs = 2 * 75; |
345 | ||
ef79bbde P |
346 | // parse the .toc file |
347 | while (fgets(linebuf, sizeof(linebuf), fi) != NULL) { | |
348 | // search for tracks | |
e999be41 | 349 | strncpy(tmp, linebuf, sizeof(linebuf)); |
350 | token = strtok(tmp, " "); | |
ef79bbde P |
351 | |
352 | if (token == NULL) continue; | |
353 | ||
354 | if (!strcmp(token, "TRACK")) { | |
e999be41 | 355 | sector_offs += current_zero_gap; |
356 | current_zero_gap = 0; | |
357 | ||
ef79bbde P |
358 | // get type of track |
359 | token = strtok(NULL, " "); | |
360 | numtracks++; | |
361 | ||
362 | if (!strncmp(token, "MODE2_RAW", 9)) { | |
363 | ti[numtracks].type = DATA; | |
364 | sec2msf(2 * 75, ti[numtracks].start); // assume data track on 0:2:0 | |
365 | ||
366 | // check if this image contains mixed subchannel data | |
367 | token = strtok(NULL, " "); | |
e999be41 | 368 | if (token != NULL && !strncmp(token, "RW", 2)) { |
369 | sector_size = CD_FRAMESIZE_RAW + SUB_FRAMESIZE; | |
ef79bbde | 370 | subChanMixed = TRUE; |
e999be41 | 371 | if (!strncmp(token, "RW_RAW", 6)) |
372 | subChanRaw = TRUE; | |
ef79bbde P |
373 | } |
374 | } | |
375 | else if (!strncmp(token, "AUDIO", 5)) { | |
376 | ti[numtracks].type = CDDA; | |
377 | } | |
378 | } | |
379 | else if (!strcmp(token, "DATAFILE")) { | |
380 | if (ti[numtracks].type == CDDA) { | |
381 | sscanf(linebuf, "DATAFILE \"%[^\"]\" #%d %8s", name, &t, time2); | |
19c03d80 | 382 | ti[numtracks].start_offset = t; |
e999be41 | 383 | t = t / sector_size + sector_offs; |
ef79bbde P |
384 | sec2msf(t, (char *)&ti[numtracks].start); |
385 | tok2msf((char *)&time2, (char *)&ti[numtracks].length); | |
386 | } | |
387 | else { | |
388 | sscanf(linebuf, "DATAFILE \"%[^\"]\" %8s", name, time); | |
389 | tok2msf((char *)&time, (char *)&ti[numtracks].length); | |
390 | } | |
391 | } | |
392 | else if (!strcmp(token, "FILE")) { | |
393 | sscanf(linebuf, "FILE \"%[^\"]\" #%d %8s %8s", name, &t, time, time2); | |
394 | tok2msf((char *)&time, (char *)&ti[numtracks].start); | |
e999be41 | 395 | t += msf2sec(ti[numtracks].start) * sector_size; |
19c03d80 | 396 | ti[numtracks].start_offset = t; |
e999be41 | 397 | t = t / sector_size + sector_offs; |
ef79bbde P |
398 | sec2msf(t, (char *)&ti[numtracks].start); |
399 | tok2msf((char *)&time2, (char *)&ti[numtracks].length); | |
400 | } | |
e999be41 | 401 | else if (!strcmp(token, "ZERO") || !strcmp(token, "SILENCE")) { |
402 | // skip unneeded optional fields | |
403 | while (token != NULL) { | |
404 | token = strtok(NULL, " "); | |
405 | if (strchr(token, ':') != NULL) | |
406 | break; | |
407 | } | |
408 | if (token != NULL) { | |
409 | tok2msf(token, tmp); | |
410 | current_zero_gap = msf2sec(tmp); | |
411 | } | |
8aa91443 | 412 | if (numtracks > 1) { |
413 | t = ti[numtracks - 1].start_offset; | |
e999be41 | 414 | t /= sector_size; |
8aa91443 | 415 | pregapOffset = t + msf2sec(ti[numtracks - 1].length); |
416 | } | |
19c03d80 | 417 | } |
e999be41 | 418 | else if (!strcmp(token, "START")) { |
419 | token = strtok(NULL, " "); | |
420 | if (token != NULL && strchr(token, ':')) { | |
421 | tok2msf(token, tmp); | |
422 | t = msf2sec(tmp); | |
423 | ti[numtracks].start_offset += (t - current_zero_gap) * sector_size; | |
424 | t = msf2sec(ti[numtracks].start) + t; | |
425 | sec2msf(t, (char *)&ti[numtracks].start); | |
426 | } | |
427 | } | |
ef79bbde P |
428 | } |
429 | ||
430 | fclose(fi); | |
431 | ||
432 | return 0; | |
433 | } | |
434 | ||
435 | // this function tries to get the .cue file of the given .bin | |
436 | // the necessary data is put into the ti (trackinformation)-array | |
437 | static int parsecue(const char *isofile) { | |
438 | char cuename[MAXPATHLEN]; | |
38b8102c | 439 | char filepath[MAXPATHLEN]; |
440 | char *incue_fname; | |
ef79bbde P |
441 | FILE *fi; |
442 | char *token; | |
443 | char time[20]; | |
444 | char *tmp; | |
19c03d80 | 445 | char linebuf[256], tmpb[256], dummy[256]; |
38b8102c | 446 | unsigned int incue_max_len; |
77160d47 | 447 | unsigned int t, file_len, mode, sector_offs; |
448 | unsigned int sector_size = 2352; | |
ef79bbde P |
449 | |
450 | numtracks = 0; | |
451 | ||
452 | // copy name of the iso and change extension from .bin to .cue | |
453 | strncpy(cuename, isofile, sizeof(cuename)); | |
454 | cuename[MAXPATHLEN - 1] = '\0'; | |
455 | if (strlen(cuename) >= 4) { | |
456 | strcpy(cuename + strlen(cuename) - 4, ".cue"); | |
457 | } | |
458 | else { | |
459 | return -1; | |
460 | } | |
461 | ||
462 | if ((fi = fopen(cuename, "r")) == NULL) { | |
463 | return -1; | |
464 | } | |
465 | ||
466 | // Some stupid tutorials wrongly tell users to use cdrdao to rip a | |
467 | // "bin/cue" image, which is in fact a "bin/toc" image. So let's check | |
468 | // that... | |
469 | if (fgets(linebuf, sizeof(linebuf), fi) != NULL) { | |
470 | if (!strncmp(linebuf, "CD_ROM_XA", 9)) { | |
471 | // Don't proceed further, as this is actually a .toc file rather | |
472 | // than a .cue file. | |
473 | fclose(fi); | |
474 | return parsetoc(isofile); | |
475 | } | |
476 | fseek(fi, 0, SEEK_SET); | |
477 | } | |
478 | ||
38b8102c | 479 | // build a path for files referenced in .cue |
480 | strncpy(filepath, cuename, sizeof(filepath)); | |
22bbabf6 | 481 | tmp = strrchr(filepath, '/'); |
38b8102c | 482 | if (tmp == NULL) |
22bbabf6 | 483 | tmp = strrchr(filepath, '\\'); |
484 | if (tmp != NULL) | |
485 | tmp++; | |
486 | else | |
38b8102c | 487 | tmp = filepath; |
488 | *tmp = 0; | |
489 | filepath[sizeof(filepath) - 1] = 0; | |
490 | incue_fname = tmp; | |
491 | incue_max_len = sizeof(filepath) - (tmp - filepath) - 1; | |
492 | ||
ef79bbde P |
493 | memset(&ti, 0, sizeof(ti)); |
494 | ||
19c03d80 | 495 | file_len = 0; |
496 | sector_offs = 2 * 75; | |
497 | ||
ef79bbde P |
498 | while (fgets(linebuf, sizeof(linebuf), fi) != NULL) { |
499 | strncpy(dummy, linebuf, sizeof(linebuf)); | |
500 | token = strtok(dummy, " "); | |
501 | ||
502 | if (token == NULL) { | |
503 | continue; | |
504 | } | |
505 | ||
19c03d80 | 506 | if (!strcmp(token, "TRACK")) { |
ef79bbde P |
507 | numtracks++; |
508 | ||
77160d47 | 509 | sector_size = 0; |
ef79bbde P |
510 | if (strstr(linebuf, "AUDIO") != NULL) { |
511 | ti[numtracks].type = CDDA; | |
77160d47 | 512 | sector_size = 2352; |
ef79bbde | 513 | } |
77160d47 | 514 | else if (sscanf(linebuf, " TRACK %u MODE%u/%u", &t, &mode, §or_size) == 3) |
ef79bbde | 515 | ti[numtracks].type = DATA; |
77160d47 | 516 | else { |
517 | SysPrintf(".cue: failed to parse TRACK\n"); | |
518 | ti[numtracks].type = numtracks == 1 ? DATA : CDDA; | |
ef79bbde | 519 | } |
77160d47 | 520 | if (sector_size == 0) |
521 | sector_size = 2352; | |
ef79bbde P |
522 | } |
523 | else if (!strcmp(token, "INDEX")) { | |
77160d47 | 524 | if (sscanf(linebuf, " INDEX %02d %8s", &t, time) != 2) |
525 | SysPrintf(".cue: failed to parse INDEX\n"); | |
19c03d80 | 526 | tok2msf(time, (char *)&ti[numtracks].start); |
ef79bbde | 527 | |
19c03d80 | 528 | t = msf2sec(ti[numtracks].start); |
77160d47 | 529 | ti[numtracks].start_offset = t * sector_size; |
19c03d80 | 530 | t += sector_offs; |
ef79bbde | 531 | sec2msf(t, ti[numtracks].start); |
19c03d80 | 532 | |
533 | // default track length to file length | |
77160d47 | 534 | t = file_len - ti[numtracks].start_offset / sector_size; |
19c03d80 | 535 | sec2msf(t, ti[numtracks].length); |
536 | ||
537 | if (numtracks > 1 && ti[numtracks].handle == NULL) { | |
538 | // this track uses the same file as the last, | |
539 | // start of this track is last track's end | |
540 | t = msf2sec(ti[numtracks].start) - msf2sec(ti[numtracks - 1].start); | |
541 | sec2msf(t, ti[numtracks - 1].length); | |
38b8102c | 542 | } |
8aa91443 | 543 | if (numtracks > 1 && pregapOffset == -1) |
77160d47 | 544 | pregapOffset = ti[numtracks].start_offset / sector_size; |
19c03d80 | 545 | } |
546 | else if (!strcmp(token, "PREGAP")) { | |
547 | if (sscanf(linebuf, " PREGAP %8s", time) == 1) { | |
548 | tok2msf(time, dummy); | |
549 | sector_offs += msf2sec(dummy); | |
38b8102c | 550 | } |
8aa91443 | 551 | pregapOffset = -1; // mark to fill track start_offset |
19c03d80 | 552 | } |
553 | else if (!strcmp(token, "FILE")) { | |
385c023b | 554 | t = sscanf(linebuf, " FILE \"%256[^\"]\"", tmpb); |
555 | if (t != 1) | |
556 | sscanf(linebuf, " FILE %256s", tmpb); | |
19c03d80 | 557 | |
558 | // absolute path? | |
559 | ti[numtracks + 1].handle = fopen(tmpb, "rb"); | |
560 | if (ti[numtracks + 1].handle == NULL) { | |
561 | // relative to .cue? | |
562 | tmp = strrchr(tmpb, '\\'); | |
563 | if (tmp == NULL) | |
564 | tmp = strrchr(tmpb, '/'); | |
38b8102c | 565 | if (tmp != NULL) |
19c03d80 | 566 | tmp++; |
567 | else | |
568 | tmp = tmpb; | |
569 | strncpy(incue_fname, tmp, incue_max_len); | |
570 | ti[numtracks + 1].handle = fopen(filepath, "rb"); | |
38b8102c | 571 | } |
ef79bbde | 572 | |
19c03d80 | 573 | // update global offset if this is not first file in this .cue |
deebc67f | 574 | if (numtracks + 1 > 1) { |
575 | multifile = 1; | |
19c03d80 | 576 | sector_offs += file_len; |
deebc67f | 577 | } |
19c03d80 | 578 | |
579 | file_len = 0; | |
38b8102c | 580 | if (ti[numtracks + 1].handle == NULL) { |
19c03d80 | 581 | SysPrintf(_("\ncould not open: %s\n"), filepath); |
582 | continue; | |
38b8102c | 583 | } |
19c03d80 | 584 | fseek(ti[numtracks + 1].handle, 0, SEEK_END); |
585 | file_len = ftell(ti[numtracks + 1].handle) / 2352; | |
586 | ||
587 | if (numtracks == 0 && strlen(isofile) >= 4 && | |
588 | strcmp(isofile + strlen(isofile) - 4, ".cue") == 0) | |
589 | { | |
38b8102c | 590 | // user selected .cue as image file, use it's data track instead |
591 | fclose(cdHandle); | |
592 | cdHandle = fopen(filepath, "rb"); | |
ef79bbde P |
593 | } |
594 | } | |
595 | } | |
596 | ||
597 | fclose(fi); | |
598 | ||
ef79bbde P |
599 | return 0; |
600 | } | |
601 | ||
602 | // this function tries to get the .ccd file of the given .img | |
603 | // the necessary data is put into the ti (trackinformation)-array | |
604 | static int parseccd(const char *isofile) { | |
605 | char ccdname[MAXPATHLEN]; | |
606 | FILE *fi; | |
607 | char linebuf[256]; | |
608 | unsigned int t; | |
609 | ||
610 | numtracks = 0; | |
611 | ||
612 | // copy name of the iso and change extension from .img to .ccd | |
613 | strncpy(ccdname, isofile, sizeof(ccdname)); | |
614 | ccdname[MAXPATHLEN - 1] = '\0'; | |
615 | if (strlen(ccdname) >= 4) { | |
616 | strcpy(ccdname + strlen(ccdname) - 4, ".ccd"); | |
617 | } | |
618 | else { | |
619 | return -1; | |
620 | } | |
621 | ||
622 | if ((fi = fopen(ccdname, "r")) == NULL) { | |
623 | return -1; | |
624 | } | |
625 | ||
626 | memset(&ti, 0, sizeof(ti)); | |
627 | ||
628 | while (fgets(linebuf, sizeof(linebuf), fi) != NULL) { | |
629 | if (!strncmp(linebuf, "[TRACK", 6)){ | |
630 | numtracks++; | |
631 | } | |
632 | else if (!strncmp(linebuf, "MODE=", 5)) { | |
633 | sscanf(linebuf, "MODE=%d", &t); | |
634 | ti[numtracks].type = ((t == 0) ? CDDA : DATA); | |
635 | } | |
636 | else if (!strncmp(linebuf, "INDEX 1=", 8)) { | |
637 | sscanf(linebuf, "INDEX 1=%d", &t); | |
638 | sec2msf(t + 2 * 75, ti[numtracks].start); | |
77160d47 | 639 | ti[numtracks].start_offset = t * 2352; |
ef79bbde P |
640 | |
641 | // If we've already seen another track, this is its end | |
642 | if (numtracks > 1) { | |
643 | t = msf2sec(ti[numtracks].start) - msf2sec(ti[numtracks - 1].start); | |
644 | sec2msf(t, ti[numtracks - 1].length); | |
645 | } | |
646 | } | |
647 | } | |
648 | ||
649 | fclose(fi); | |
650 | ||
651 | // Fill out the last track's end based on size | |
652 | if (numtracks >= 1) { | |
653 | fseek(cdHandle, 0, SEEK_END); | |
654 | t = ftell(cdHandle) / 2352 - msf2sec(ti[numtracks].start) + 2 * 75; | |
655 | sec2msf(t, ti[numtracks].length); | |
656 | } | |
657 | ||
658 | return 0; | |
659 | } | |
660 | ||
661 | // this function tries to get the .mds file of the given .mdf | |
662 | // the necessary data is put into the ti (trackinformation)-array | |
663 | static int parsemds(const char *isofile) { | |
664 | char mdsname[MAXPATHLEN]; | |
665 | FILE *fi; | |
666 | unsigned int offset, extra_offset, l, i; | |
667 | unsigned short s; | |
668 | ||
669 | numtracks = 0; | |
670 | ||
671 | // copy name of the iso and change extension from .mdf to .mds | |
672 | strncpy(mdsname, isofile, sizeof(mdsname)); | |
673 | mdsname[MAXPATHLEN - 1] = '\0'; | |
674 | if (strlen(mdsname) >= 4) { | |
675 | strcpy(mdsname + strlen(mdsname) - 4, ".mds"); | |
676 | } | |
677 | else { | |
678 | return -1; | |
679 | } | |
680 | ||
681 | if ((fi = fopen(mdsname, "rb")) == NULL) { | |
682 | return -1; | |
683 | } | |
684 | ||
685 | memset(&ti, 0, sizeof(ti)); | |
686 | ||
687 | // check if it's a valid mds file | |
688 | fread(&i, 1, sizeof(unsigned int), fi); | |
689 | i = SWAP32(i); | |
690 | if (i != 0x4944454D) { | |
691 | // not an valid mds file | |
692 | fclose(fi); | |
693 | return -1; | |
694 | } | |
695 | ||
696 | // get offset to session block | |
697 | fseek(fi, 0x50, SEEK_SET); | |
698 | fread(&offset, 1, sizeof(unsigned int), fi); | |
699 | offset = SWAP32(offset); | |
700 | ||
701 | // get total number of tracks | |
702 | offset += 14; | |
703 | fseek(fi, offset, SEEK_SET); | |
704 | fread(&s, 1, sizeof(unsigned short), fi); | |
705 | s = SWAP16(s); | |
706 | numtracks = s; | |
707 | ||
708 | // get offset to track blocks | |
709 | fseek(fi, 4, SEEK_CUR); | |
710 | fread(&offset, 1, sizeof(unsigned int), fi); | |
711 | offset = SWAP32(offset); | |
712 | ||
713 | // skip lead-in data | |
714 | while (1) { | |
715 | fseek(fi, offset + 4, SEEK_SET); | |
716 | if (fgetc(fi) < 0xA0) { | |
717 | break; | |
718 | } | |
719 | offset += 0x50; | |
720 | } | |
721 | ||
722 | // check if the image contains mixed subchannel data | |
723 | fseek(fi, offset + 1, SEEK_SET); | |
77160d47 | 724 | subChanMixed = subChanRaw = (fgetc(fi) ? TRUE : FALSE); |
ef79bbde P |
725 | |
726 | // read track data | |
727 | for (i = 1; i <= numtracks; i++) { | |
728 | fseek(fi, offset, SEEK_SET); | |
729 | ||
730 | // get the track type | |
731 | ti[i].type = ((fgetc(fi) == 0xA9) ? CDDA : DATA); | |
732 | fseek(fi, 8, SEEK_CUR); | |
733 | ||
734 | // get the track starting point | |
735 | ti[i].start[0] = fgetc(fi); | |
736 | ti[i].start[1] = fgetc(fi); | |
737 | ti[i].start[2] = fgetc(fi); | |
738 | ||
ef79bbde P |
739 | fread(&extra_offset, 1, sizeof(unsigned int), fi); |
740 | extra_offset = SWAP32(extra_offset); | |
741 | ||
19c03d80 | 742 | // get track start offset (in .mdf) |
743 | fseek(fi, offset + 0x28, SEEK_SET); | |
744 | fread(&l, 1, sizeof(unsigned int), fi); | |
745 | l = SWAP32(l); | |
77160d47 | 746 | ti[i].start_offset = l; |
19c03d80 | 747 | |
8aa91443 | 748 | // get pregap |
749 | fseek(fi, extra_offset, SEEK_SET); | |
750 | fread(&l, 1, sizeof(unsigned int), fi); | |
751 | l = SWAP32(l); | |
752 | if (l != 0 && i > 1) | |
77160d47 | 753 | pregapOffset = msf2sec(ti[i].start); |
8aa91443 | 754 | |
755 | // get the track length | |
756 | fread(&l, 1, sizeof(unsigned int), fi); | |
757 | l = SWAP32(l); | |
758 | sec2msf(l, ti[i].length); | |
759 | ||
ef79bbde P |
760 | offset += 0x50; |
761 | } | |
762 | ||
763 | fclose(fi); | |
764 | return 0; | |
765 | } | |
766 | ||
0877957a | 767 | static int handlepbp(const char *isofile) { |
9a92bffb | 768 | struct { |
769 | unsigned int sig; | |
770 | unsigned int dontcare[8]; | |
771 | unsigned int psar_offs; | |
772 | } pbp_hdr; | |
773 | struct { | |
774 | unsigned char type; | |
775 | unsigned char pad0; | |
776 | unsigned char track; | |
777 | char index0[3]; | |
778 | char pad1; | |
779 | char index1[3]; | |
780 | } toc_entry; | |
781 | struct { | |
782 | unsigned int offset; | |
783 | unsigned int size; | |
784 | unsigned int dontcare[6]; | |
785 | } index_entry; | |
0c2871a7 | 786 | char psar_sig[11]; |
9a92bffb | 787 | unsigned int t, cd_length, cdimg_base; |
0c2871a7 | 788 | unsigned int offsettab[8], psisoimg_offs; |
9a92bffb | 789 | const char *ext = NULL; |
790 | int i, ret; | |
791 | ||
792 | if (strlen(isofile) >= 4) | |
793 | ext = isofile + strlen(isofile) - 4; | |
794 | if (ext == NULL || (strcmp(ext, ".pbp") != 0 && strcmp(ext, ".PBP") != 0)) | |
795 | return -1; | |
796 | ||
797 | numtracks = 0; | |
798 | ||
799 | ret = fread(&pbp_hdr, 1, sizeof(pbp_hdr), cdHandle); | |
800 | if (ret != sizeof(pbp_hdr)) { | |
f29fbd53 | 801 | SysPrintf("failed to read pbp\n"); |
9a92bffb | 802 | goto fail_io; |
803 | } | |
804 | ||
805 | ret = fseek(cdHandle, pbp_hdr.psar_offs, SEEK_SET); | |
806 | if (ret != 0) { | |
f29fbd53 | 807 | SysPrintf("failed to seek to %x\n", pbp_hdr.psar_offs); |
9a92bffb | 808 | goto fail_io; |
809 | } | |
810 | ||
0c2871a7 | 811 | psisoimg_offs = pbp_hdr.psar_offs; |
9a92bffb | 812 | fread(psar_sig, 1, sizeof(psar_sig), cdHandle); |
0c2871a7 | 813 | psar_sig[10] = 0; |
814 | if (strcmp(psar_sig, "PSTITLEIMG") == 0) { | |
815 | // multidisk image? | |
816 | ret = fseek(cdHandle, pbp_hdr.psar_offs + 0x200, SEEK_SET); | |
817 | if (ret != 0) { | |
f29fbd53 | 818 | SysPrintf("failed to seek to %x\n", pbp_hdr.psar_offs + 0x200); |
0c2871a7 | 819 | goto fail_io; |
820 | } | |
821 | ||
822 | if (fread(&offsettab, 1, sizeof(offsettab), cdHandle) != sizeof(offsettab)) { | |
f29fbd53 | 823 | SysPrintf("failed to read offsettab\n"); |
0c2871a7 | 824 | goto fail_io; |
825 | } | |
826 | ||
827 | for (i = 0; i < sizeof(offsettab) / sizeof(offsettab[0]); i++) { | |
828 | if (offsettab[i] == 0) | |
829 | break; | |
830 | } | |
831 | cdrIsoMultidiskCount = i; | |
832 | if (cdrIsoMultidiskCount == 0) { | |
f29fbd53 | 833 | SysPrintf("multidisk eboot has 0 images?\n"); |
0c2871a7 | 834 | goto fail_io; |
835 | } | |
836 | ||
837 | if (cdrIsoMultidiskSelect >= cdrIsoMultidiskCount) | |
838 | cdrIsoMultidiskSelect = 0; | |
839 | ||
840 | psisoimg_offs += offsettab[cdrIsoMultidiskSelect]; | |
841 | ||
842 | ret = fseek(cdHandle, psisoimg_offs, SEEK_SET); | |
843 | if (ret != 0) { | |
f29fbd53 | 844 | SysPrintf("failed to seek to %x\n", psisoimg_offs); |
0c2871a7 | 845 | goto fail_io; |
846 | } | |
847 | ||
848 | fread(psar_sig, 1, sizeof(psar_sig), cdHandle); | |
849 | psar_sig[10] = 0; | |
850 | } | |
851 | ||
852 | if (strcmp(psar_sig, "PSISOIMG00") != 0) { | |
f29fbd53 | 853 | SysPrintf("bad psar_sig: %s\n", psar_sig); |
9a92bffb | 854 | goto fail_io; |
855 | } | |
856 | ||
857 | // seek to TOC | |
0c2871a7 | 858 | ret = fseek(cdHandle, psisoimg_offs + 0x800, SEEK_SET); |
9a92bffb | 859 | if (ret != 0) { |
f29fbd53 | 860 | SysPrintf("failed to seek to %x\n", psisoimg_offs + 0x800); |
9a92bffb | 861 | goto fail_io; |
862 | } | |
863 | ||
864 | // first 3 entries are special | |
865 | fseek(cdHandle, sizeof(toc_entry), SEEK_CUR); | |
866 | fread(&toc_entry, 1, sizeof(toc_entry), cdHandle); | |
867 | numtracks = btoi(toc_entry.index1[0]); | |
868 | ||
869 | fread(&toc_entry, 1, sizeof(toc_entry), cdHandle); | |
870 | cd_length = btoi(toc_entry.index1[0]) * 60 * 75 + | |
871 | btoi(toc_entry.index1[1]) * 75 + btoi(toc_entry.index1[2]); | |
872 | ||
873 | for (i = 1; i <= numtracks; i++) { | |
874 | fread(&toc_entry, 1, sizeof(toc_entry), cdHandle); | |
875 | ||
876 | ti[i].type = (toc_entry.type == 1) ? CDDA : DATA; | |
877 | ||
878 | ti[i].start_offset = btoi(toc_entry.index0[0]) * 60 * 75 + | |
879 | btoi(toc_entry.index0[1]) * 75 + btoi(toc_entry.index0[2]); | |
77160d47 | 880 | ti[i].start_offset *= 2352; |
9a92bffb | 881 | ti[i].start[0] = btoi(toc_entry.index1[0]); |
882 | ti[i].start[1] = btoi(toc_entry.index1[1]); | |
883 | ti[i].start[2] = btoi(toc_entry.index1[2]); | |
884 | ||
885 | if (i > 1) { | |
886 | t = msf2sec(ti[i].start) - msf2sec(ti[i - 1].start); | |
887 | sec2msf(t, ti[i - 1].length); | |
888 | } | |
889 | } | |
77160d47 | 890 | t = cd_length - ti[numtracks].start_offset / 2352; |
9a92bffb | 891 | sec2msf(t, ti[numtracks].length); |
892 | ||
893 | // seek to ISO index | |
0c2871a7 | 894 | ret = fseek(cdHandle, psisoimg_offs + 0x4000, SEEK_SET); |
9a92bffb | 895 | if (ret != 0) { |
f29fbd53 | 896 | SysPrintf("failed to seek to ISO index\n"); |
9a92bffb | 897 | goto fail_io; |
898 | } | |
899 | ||
900 | compr_img = calloc(1, sizeof(*compr_img)); | |
901 | if (compr_img == NULL) | |
902 | goto fail_io; | |
903 | ||
0877957a | 904 | compr_img->block_shift = 4; |
9a92bffb | 905 | compr_img->current_block = (unsigned int)-1; |
906 | ||
907 | compr_img->index_len = (0x100000 - 0x4000) / sizeof(index_entry); | |
908 | compr_img->index_table = malloc((compr_img->index_len + 1) * sizeof(compr_img->index_table[0])); | |
909 | if (compr_img->index_table == NULL) | |
910 | goto fail_io; | |
911 | ||
0c2871a7 | 912 | cdimg_base = psisoimg_offs + 0x100000; |
9a92bffb | 913 | for (i = 0; i < compr_img->index_len; i++) { |
914 | ret = fread(&index_entry, 1, sizeof(index_entry), cdHandle); | |
915 | if (ret != sizeof(index_entry)) { | |
f29fbd53 | 916 | SysPrintf("failed to read index_entry #%d\n", i); |
9a92bffb | 917 | goto fail_index; |
918 | } | |
919 | ||
920 | if (index_entry.size == 0) | |
921 | break; | |
922 | ||
923 | compr_img->index_table[i] = cdimg_base + index_entry.offset; | |
924 | } | |
925 | compr_img->index_table[i] = cdimg_base + index_entry.offset + index_entry.size; | |
926 | ||
927 | return 0; | |
928 | ||
929 | fail_index: | |
930 | free(compr_img->index_table); | |
931 | compr_img->index_table = NULL; | |
932 | fail_io: | |
0877957a | 933 | if (compr_img != NULL) { |
934 | free(compr_img); | |
935 | compr_img = NULL; | |
936 | } | |
937 | return -1; | |
938 | } | |
939 | ||
940 | static int handlecbin(const char *isofile) { | |
941 | struct | |
942 | { | |
943 | char magic[4]; | |
944 | unsigned int header_size; | |
945 | unsigned long long total_bytes; | |
946 | unsigned int block_size; | |
947 | unsigned char ver; // 1 | |
948 | unsigned char align; | |
949 | unsigned char rsv_06[2]; | |
950 | } ciso_hdr; | |
951 | const char *ext = NULL; | |
0c2871a7 | 952 | unsigned int index = 0, plain; |
0877957a | 953 | int i, ret; |
954 | ||
955 | if (strlen(isofile) >= 5) | |
956 | ext = isofile + strlen(isofile) - 5; | |
957 | if (ext == NULL || (strcasecmp(ext + 1, ".cbn") != 0 && strcasecmp(ext, ".cbin") != 0)) | |
958 | return -1; | |
959 | ||
960 | ret = fread(&ciso_hdr, 1, sizeof(ciso_hdr), cdHandle); | |
961 | if (ret != sizeof(ciso_hdr)) { | |
f29fbd53 | 962 | SysPrintf("failed to read ciso header\n"); |
0877957a | 963 | return -1; |
964 | } | |
965 | ||
966 | if (strncmp(ciso_hdr.magic, "CISO", 4) != 0 || ciso_hdr.total_bytes <= 0 || ciso_hdr.block_size <= 0) { | |
f29fbd53 | 967 | SysPrintf("bad ciso header\n"); |
0877957a | 968 | return -1; |
969 | } | |
970 | if (ciso_hdr.header_size != 0 && ciso_hdr.header_size != sizeof(ciso_hdr)) { | |
971 | ret = fseek(cdHandle, ciso_hdr.header_size, SEEK_SET); | |
972 | if (ret != 0) { | |
f29fbd53 | 973 | SysPrintf("failed to seek to %x\n", ciso_hdr.header_size); |
0877957a | 974 | return -1; |
975 | } | |
976 | } | |
977 | ||
978 | compr_img = calloc(1, sizeof(*compr_img)); | |
979 | if (compr_img == NULL) | |
980 | goto fail_io; | |
981 | ||
982 | compr_img->block_shift = 0; | |
983 | compr_img->current_block = (unsigned int)-1; | |
984 | ||
985 | compr_img->index_len = ciso_hdr.total_bytes / ciso_hdr.block_size; | |
986 | compr_img->index_table = malloc((compr_img->index_len + 1) * sizeof(compr_img->index_table[0])); | |
987 | if (compr_img->index_table == NULL) | |
988 | goto fail_io; | |
989 | ||
990 | ret = fread(compr_img->index_table, sizeof(compr_img->index_table[0]), compr_img->index_len, cdHandle); | |
991 | if (ret != compr_img->index_len) { | |
f29fbd53 | 992 | SysPrintf("failed to read index table\n"); |
0877957a | 993 | goto fail_index; |
994 | } | |
995 | ||
996 | for (i = 0; i < compr_img->index_len + 1; i++) { | |
997 | index = compr_img->index_table[i]; | |
998 | plain = index & 0x80000000; | |
999 | index &= 0x7fffffff; | |
1000 | compr_img->index_table[i] = (index << ciso_hdr.align) | plain; | |
1001 | } | |
1002 | if ((long long)index << ciso_hdr.align >= 0x80000000ll) | |
f29fbd53 | 1003 | SysPrintf("warning: ciso img too large, expect problems\n"); |
0877957a | 1004 | |
1005 | return 0; | |
1006 | ||
1007 | fail_index: | |
1008 | free(compr_img->index_table); | |
1009 | compr_img->index_table = NULL; | |
1010 | fail_io: | |
1011 | if (compr_img != NULL) { | |
1012 | free(compr_img); | |
1013 | compr_img = NULL; | |
1014 | } | |
9a92bffb | 1015 | return -1; |
1016 | } | |
1017 | ||
ef79bbde P |
1018 | // this function tries to get the .sub file of the given .img |
1019 | static int opensubfile(const char *isoname) { | |
1020 | char subname[MAXPATHLEN]; | |
1021 | ||
1022 | // copy name of the iso and change extension from .img to .sub | |
1023 | strncpy(subname, isoname, sizeof(subname)); | |
1024 | subname[MAXPATHLEN - 1] = '\0'; | |
1025 | if (strlen(subname) >= 4) { | |
1026 | strcpy(subname + strlen(subname) - 4, ".sub"); | |
1027 | } | |
1028 | else { | |
1029 | return -1; | |
1030 | } | |
1031 | ||
1032 | subHandle = fopen(subname, "rb"); | |
1033 | if (subHandle == NULL) { | |
1034 | return -1; | |
1035 | } | |
1036 | ||
1037 | return 0; | |
1038 | } | |
1039 | ||
ae4e7dc9 | 1040 | static int opensbifile(const char *isoname) { |
1041 | char sbiname[MAXPATHLEN]; | |
1042 | int s; | |
1043 | ||
1044 | strncpy(sbiname, isoname, sizeof(sbiname)); | |
1045 | sbiname[MAXPATHLEN - 1] = '\0'; | |
1046 | if (strlen(sbiname) >= 4) { | |
1047 | strcpy(sbiname + strlen(sbiname) - 4, ".sbi"); | |
1048 | } | |
1049 | else { | |
1050 | return -1; | |
1051 | } | |
1052 | ||
1053 | fseek(cdHandle, 0, SEEK_END); | |
1054 | s = ftell(cdHandle) / 2352; | |
1055 | ||
1056 | return LoadSBI(sbiname, s); | |
1057 | } | |
1058 | ||
77160d47 | 1059 | static int cdread_normal(FILE *f, unsigned int base, void *dest, int sector) |
9a92bffb | 1060 | { |
77160d47 | 1061 | fseek(f, base + sector * CD_FRAMESIZE_RAW, SEEK_SET); |
81abe4d5 | 1062 | return fread(dest, 1, CD_FRAMESIZE_RAW, f); |
9a92bffb | 1063 | } |
1064 | ||
77160d47 | 1065 | static int cdread_sub_mixed(FILE *f, unsigned int base, void *dest, int sector) |
9a92bffb | 1066 | { |
1067 | int ret; | |
1068 | ||
77160d47 | 1069 | fseek(f, base + sector * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE), SEEK_SET); |
81abe4d5 | 1070 | ret = fread(dest, 1, CD_FRAMESIZE_RAW, f); |
9a92bffb | 1071 | fread(subbuffer, 1, SUB_FRAMESIZE, f); |
1072 | ||
1073 | if (subChanRaw) DecodeRawSubData(); | |
1074 | ||
1075 | return ret; | |
1076 | } | |
1077 | ||
1078 | static int uncompress2(void *out, unsigned long *out_size, void *in, unsigned long in_size) | |
1079 | { | |
1080 | static z_stream z; | |
1081 | int ret = 0; | |
1082 | ||
1083 | if (z.zalloc == NULL) { | |
1084 | // XXX: one-time leak here.. | |
1085 | z.next_in = Z_NULL; | |
1086 | z.avail_in = 0; | |
1087 | z.zalloc = Z_NULL; | |
1088 | z.zfree = Z_NULL; | |
1089 | z.opaque = Z_NULL; | |
1090 | ret = inflateInit2(&z, -15); | |
1091 | } | |
1092 | else | |
1093 | ret = inflateReset(&z); | |
1094 | if (ret != Z_OK) | |
1095 | return ret; | |
1096 | ||
1097 | z.next_in = in; | |
1098 | z.avail_in = in_size; | |
1099 | z.next_out = out; | |
1100 | z.avail_out = *out_size; | |
1101 | ||
1102 | ret = inflate(&z, Z_NO_FLUSH); | |
1103 | //inflateEnd(&z); | |
1104 | ||
1105 | *out_size -= z.avail_out; | |
1106 | return ret == 1 ? 0 : ret; | |
1107 | } | |
1108 | ||
77160d47 | 1109 | static int cdread_compressed(FILE *f, unsigned int base, void *dest, int sector) |
9a92bffb | 1110 | { |
0877957a | 1111 | unsigned long cdbuffer_size, cdbuffer_size_expect; |
9a92bffb | 1112 | unsigned int start_byte, size; |
0877957a | 1113 | int is_compressed; |
9a92bffb | 1114 | int ret, block; |
1115 | ||
77160d47 | 1116 | if (base) |
1117 | sector += base / 2352; | |
1118 | ||
0877957a | 1119 | block = sector >> compr_img->block_shift; |
1120 | compr_img->sector_in_blk = sector & ((1 << compr_img->block_shift) - 1); | |
9a92bffb | 1121 | |
1122 | if (block == compr_img->current_block) { | |
1123 | //printf("hit sect %d\n", sector); | |
1124 | goto finish; | |
1125 | } | |
1126 | ||
1127 | if (sector >= compr_img->index_len * 16) { | |
f29fbd53 | 1128 | SysPrintf("sector %d is past img end\n", sector); |
9a92bffb | 1129 | return -1; |
1130 | } | |
1131 | ||
0877957a | 1132 | start_byte = compr_img->index_table[block] & 0x7fffffff; |
9a92bffb | 1133 | if (fseek(cdHandle, start_byte, SEEK_SET) != 0) { |
f29fbd53 | 1134 | SysPrintf("seek error for block %d at %x: ", |
9a92bffb | 1135 | block, start_byte); |
1136 | perror(NULL); | |
1137 | return -1; | |
1138 | } | |
1139 | ||
0877957a | 1140 | is_compressed = !(compr_img->index_table[block] & 0x80000000); |
1141 | size = (compr_img->index_table[block + 1] & 0x7fffffff) - start_byte; | |
9a92bffb | 1142 | if (size > sizeof(compr_img->buff_compressed)) { |
f29fbd53 | 1143 | SysPrintf("block %d is too large: %u\n", block, size); |
9a92bffb | 1144 | return -1; |
1145 | } | |
1146 | ||
0877957a | 1147 | if (fread(is_compressed ? compr_img->buff_compressed : compr_img->buff_raw[0], |
1148 | 1, size, cdHandle) != size) { | |
f29fbd53 | 1149 | SysPrintf("read error for block %d at %x: ", block, start_byte); |
9a92bffb | 1150 | perror(NULL); |
1151 | return -1; | |
1152 | } | |
1153 | ||
0877957a | 1154 | if (is_compressed) { |
1155 | cdbuffer_size_expect = sizeof(compr_img->buff_raw[0]) << compr_img->block_shift; | |
1156 | cdbuffer_size = cdbuffer_size_expect; | |
1157 | ret = uncompress2(compr_img->buff_raw[0], &cdbuffer_size, compr_img->buff_compressed, size); | |
1158 | if (ret != 0) { | |
f29fbd53 | 1159 | SysPrintf("uncompress failed with %d for block %d, sector %d\n", |
0877957a | 1160 | ret, block, sector); |
1161 | return -1; | |
1162 | } | |
1163 | if (cdbuffer_size != cdbuffer_size_expect) | |
f29fbd53 | 1164 | SysPrintf("cdbuffer_size: %lu != %lu, sector %d\n", cdbuffer_size, |
0877957a | 1165 | cdbuffer_size_expect, sector); |
9a92bffb | 1166 | } |
9a92bffb | 1167 | |
1168 | // done at last! | |
1169 | compr_img->current_block = block; | |
1170 | ||
1171 | finish: | |
1172 | if (dest != cdbuffer) // copy avoid HACK | |
81abe4d5 | 1173 | memcpy(dest, compr_img->buff_raw[compr_img->sector_in_blk], |
1174 | CD_FRAMESIZE_RAW); | |
1175 | return CD_FRAMESIZE_RAW; | |
9a92bffb | 1176 | } |
1177 | ||
77160d47 | 1178 | static int cdread_2048(FILE *f, unsigned int base, void *dest, int sector) |
9a92bffb | 1179 | { |
1180 | int ret; | |
1181 | ||
77160d47 | 1182 | fseek(f, base + sector * 2048, SEEK_SET); |
81abe4d5 | 1183 | ret = fread((char *)dest + 12 * 2, 1, 2048, f); |
9a92bffb | 1184 | |
1185 | // not really necessary, fake mode 2 header | |
81abe4d5 | 1186 | memset(cdbuffer, 0, 12 * 2); |
1187 | sec2msf(sector + 2 * 75, (char *)&cdbuffer[12]); | |
1188 | cdbuffer[12 + 3] = 1; | |
9a92bffb | 1189 | |
1190 | return ret; | |
1191 | } | |
1192 | ||
1193 | static unsigned char * CALLBACK ISOgetBuffer_compr(void) { | |
1194 | return compr_img->buff_raw[compr_img->sector_in_blk] + 12; | |
1195 | } | |
1196 | ||
1197 | static unsigned char * CALLBACK ISOgetBuffer(void) { | |
81abe4d5 | 1198 | return cdbuffer + 12; |
9a92bffb | 1199 | } |
1200 | ||
ef79bbde P |
1201 | static void PrintTracks(void) { |
1202 | int i; | |
1203 | ||
1204 | for (i = 1; i <= numtracks; i++) { | |
1205 | SysPrintf(_("Track %.2d (%s) - Start %.2d:%.2d:%.2d, Length %.2d:%.2d:%.2d\n"), | |
1206 | i, (ti[i].type == DATA ? "DATA" : "AUDIO"), | |
1207 | ti[i].start[0], ti[i].start[1], ti[i].start[2], | |
1208 | ti[i].length[0], ti[i].length[1], ti[i].length[2]); | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | // This function is invoked by the front-end when opening an ISO | |
1213 | // file for playback | |
1214 | static long CALLBACK ISOopen(void) { | |
9a92bffb | 1215 | boolean isMode1ISO = FALSE; |
1216 | ||
ef79bbde P |
1217 | if (cdHandle != NULL) { |
1218 | return 0; // it's already open | |
1219 | } | |
1220 | ||
1221 | cdHandle = fopen(GetIsoFile(), "rb"); | |
1222 | if (cdHandle == NULL) { | |
1223 | return -1; | |
1224 | } | |
1225 | ||
1226 | SysPrintf(_("Loaded CD Image: %s"), GetIsoFile()); | |
1227 | ||
1228 | cddaBigEndian = FALSE; | |
1229 | subChanMixed = FALSE; | |
1230 | subChanRaw = FALSE; | |
8aa91443 | 1231 | pregapOffset = 0; |
0c2871a7 | 1232 | cdrIsoMultidiskCount = 1; |
deebc67f | 1233 | multifile = 0; |
ef79bbde | 1234 | |
9a92bffb | 1235 | CDR_getBuffer = ISOgetBuffer; |
1236 | cdimg_read_func = cdread_normal; | |
1237 | ||
92f43ab0 | 1238 | if (parsetoc(GetIsoFile()) == 0) { |
ef79bbde P |
1239 | SysPrintf("[+toc]"); |
1240 | } | |
1241 | else if (parseccd(GetIsoFile()) == 0) { | |
1242 | SysPrintf("[+ccd]"); | |
1243 | } | |
1244 | else if (parsemds(GetIsoFile()) == 0) { | |
1245 | SysPrintf("[+mds]"); | |
1246 | } | |
92f43ab0 | 1247 | else if (parsecue(GetIsoFile()) == 0) { |
1248 | SysPrintf("[+cue]"); | |
1249 | } | |
0877957a | 1250 | if (handlepbp(GetIsoFile()) == 0) { |
9a92bffb | 1251 | SysPrintf("[pbp]"); |
1252 | CDR_getBuffer = ISOgetBuffer_compr; | |
1253 | cdimg_read_func = cdread_compressed; | |
1254 | } | |
0877957a | 1255 | else if (handlecbin(GetIsoFile()) == 0) { |
1256 | SysPrintf("[cbin]"); | |
1257 | CDR_getBuffer = ISOgetBuffer_compr; | |
1258 | cdimg_read_func = cdread_compressed; | |
1259 | } | |
ef79bbde P |
1260 | |
1261 | if (!subChanMixed && opensubfile(GetIsoFile()) == 0) { | |
1262 | SysPrintf("[+sub]"); | |
1263 | } | |
ae4e7dc9 | 1264 | if (opensbifile(GetIsoFile()) == 0) { |
1265 | SysPrintf("[+sbi]"); | |
1266 | } | |
ef79bbde | 1267 | |
9a92bffb | 1268 | fseek(cdHandle, 0, SEEK_END); |
c9e5423e | 1269 | |
1270 | // maybe user selected metadata file instead of main .bin .. | |
1271 | if (ftell(cdHandle) < 2352 * 0x10) { | |
1272 | static const char *exts[] = { ".bin", ".BIN", ".img", ".IMG" }; | |
1273 | char tmp[MAXPATHLEN], *p; | |
1274 | FILE *tmpf; | |
1275 | size_t i; | |
1276 | ||
1277 | strncpy(tmp, GetIsoFile(), sizeof(tmp)); | |
1278 | tmp[MAXPATHLEN - 1] = '\0'; | |
1279 | if (strlen(tmp) >= 4) { | |
1280 | p = tmp + strlen(tmp) - 4; | |
1281 | for (i = 0; i < sizeof(exts) / sizeof(exts[0]); i++) { | |
1282 | strcpy(p, exts[i]); | |
1283 | tmpf = fopen(tmp, "rb"); | |
1284 | if (tmpf != NULL) { | |
1285 | fclose(cdHandle); | |
1286 | cdHandle = tmpf; | |
1287 | fseek(cdHandle, 0, SEEK_END); | |
1288 | break; | |
1289 | } | |
1290 | } | |
1291 | } | |
1292 | } | |
1293 | ||
1294 | // guess whether it is mode1/2048 | |
9a92bffb | 1295 | if (ftell(cdHandle) % 2048 == 0) { |
1296 | unsigned int modeTest = 0; | |
1297 | fseek(cdHandle, 0, SEEK_SET); | |
1298 | fread(&modeTest, 4, 1, cdHandle); | |
1299 | if (SWAP32(modeTest) != 0xffffff00) { | |
1300 | SysPrintf("[2048]"); | |
1301 | isMode1ISO = TRUE; | |
1302 | } | |
1303 | } | |
1304 | fseek(cdHandle, 0, SEEK_SET); | |
1305 | ||
ef79bbde P |
1306 | SysPrintf(".\n"); |
1307 | ||
1308 | PrintTracks(); | |
1309 | ||
9a92bffb | 1310 | if (subChanMixed) |
1311 | cdimg_read_func = cdread_sub_mixed; | |
1312 | else if (isMode1ISO) | |
1313 | cdimg_read_func = cdread_2048; | |
1314 | ||
38b8102c | 1315 | // make sure we have another handle open for cdda |
1316 | if (numtracks > 1 && ti[1].handle == NULL) { | |
1317 | ti[1].handle = fopen(GetIsoFile(), "rb"); | |
1318 | } | |
77160d47 | 1319 | cdda_cur_sector = 0; |
1320 | cdda_file_offset = 0; | |
38b8102c | 1321 | |
ef79bbde P |
1322 | return 0; |
1323 | } | |
1324 | ||
1325 | static long CALLBACK ISOclose(void) { | |
38b8102c | 1326 | int i; |
1327 | ||
ef79bbde P |
1328 | if (cdHandle != NULL) { |
1329 | fclose(cdHandle); | |
1330 | cdHandle = NULL; | |
1331 | } | |
1332 | if (subHandle != NULL) { | |
1333 | fclose(subHandle); | |
1334 | subHandle = NULL; | |
1335 | } | |
1336 | stopCDDA(); | |
38b8102c | 1337 | cddaHandle = NULL; |
1338 | ||
9a92bffb | 1339 | if (compr_img != NULL) { |
1340 | free(compr_img->index_table); | |
1341 | free(compr_img); | |
1342 | compr_img = NULL; | |
1343 | } | |
1344 | ||
38b8102c | 1345 | for (i = 1; i <= numtracks; i++) { |
1346 | if (ti[i].handle != NULL) { | |
1347 | fclose(ti[i].handle); | |
1348 | ti[i].handle = NULL; | |
1349 | } | |
1350 | } | |
1351 | numtracks = 0; | |
c0ee7ac6 | 1352 | ti[1].type = 0; |
ae4e7dc9 | 1353 | UnloadSBI(); |
38b8102c | 1354 | |
c0ee7ac6 | 1355 | memset(cdbuffer, 0, sizeof(cdbuffer)); |
1356 | CDR_getBuffer = ISOgetBuffer; | |
1357 | ||
38b8102c | 1358 | return 0; |
1359 | } | |
1360 | ||
1361 | static long CALLBACK ISOinit(void) { | |
1362 | assert(cdHandle == NULL); | |
1363 | assert(subHandle == NULL); | |
1364 | ||
1365 | return 0; // do nothing | |
1366 | } | |
1367 | ||
1368 | static long CALLBACK ISOshutdown(void) { | |
1369 | ISOclose(); | |
ef79bbde P |
1370 | return 0; |
1371 | } | |
1372 | ||
1373 | // return Starting and Ending Track | |
1374 | // buffer: | |
1375 | // byte 0 - start track | |
1376 | // byte 1 - end track | |
1377 | static long CALLBACK ISOgetTN(unsigned char *buffer) { | |
1378 | buffer[0] = 1; | |
1379 | ||
1380 | if (numtracks > 0) { | |
1381 | buffer[1] = numtracks; | |
1382 | } | |
1383 | else { | |
1384 | buffer[1] = 1; | |
1385 | } | |
1386 | ||
1387 | return 0; | |
1388 | } | |
1389 | ||
1390 | // return Track Time | |
1391 | // buffer: | |
1392 | // byte 0 - frame | |
1393 | // byte 1 - second | |
1394 | // byte 2 - minute | |
1395 | static long CALLBACK ISOgetTD(unsigned char track, unsigned char *buffer) { | |
858ad511 | 1396 | if (track == 0) { |
858ad511 | 1397 | unsigned int sect; |
1398 | unsigned char time[3]; | |
1399 | sect = msf2sec(ti[numtracks].start) + msf2sec(ti[numtracks].length); | |
ab948f7e | 1400 | sec2msf(sect, (char *)time); |
858ad511 | 1401 | buffer[2] = time[0]; |
1402 | buffer[1] = time[1]; | |
1403 | buffer[0] = time[2]; | |
1404 | } | |
1405 | else if (numtracks > 0 && track <= numtracks) { | |
ef79bbde P |
1406 | buffer[2] = ti[track].start[0]; |
1407 | buffer[1] = ti[track].start[1]; | |
1408 | buffer[0] = ti[track].start[2]; | |
1409 | } | |
1410 | else { | |
1411 | buffer[2] = 0; | |
1412 | buffer[1] = 2; | |
1413 | buffer[0] = 0; | |
1414 | } | |
1415 | ||
1416 | return 0; | |
1417 | } | |
1418 | ||
1419 | // decode 'raw' subchannel data ripped by cdrdao | |
1420 | static void DecodeRawSubData(void) { | |
1421 | unsigned char subQData[12]; | |
1422 | int i; | |
1423 | ||
1424 | memset(subQData, 0, sizeof(subQData)); | |
1425 | ||
1426 | for (i = 0; i < 8 * 12; i++) { | |
1427 | if (subbuffer[i] & (1 << 6)) { // only subchannel Q is needed | |
1428 | subQData[i >> 3] |= (1 << (7 - (i & 7))); | |
1429 | } | |
1430 | } | |
1431 | ||
1432 | memcpy(&subbuffer[12], subQData, 12); | |
1433 | } | |
1434 | ||
1435 | // read track | |
1436 | // time: byte 0 - minute; byte 1 - second; byte 2 - frame | |
1437 | // uses bcd format | |
1438 | static long CALLBACK ISOreadTrack(unsigned char *time) { | |
19c03d80 | 1439 | int sector = MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2])); |
c0ee7ac6 | 1440 | long ret; |
19c03d80 | 1441 | |
ef79bbde P |
1442 | if (cdHandle == NULL) { |
1443 | return -1; | |
1444 | } | |
1445 | ||
8aa91443 | 1446 | if (pregapOffset) { |
1447 | subChanMissing = FALSE; | |
1448 | if (sector >= pregapOffset) { | |
1449 | sector -= 2 * 75; | |
1450 | if (sector < pregapOffset) | |
1451 | subChanMissing = TRUE; | |
1452 | } | |
1453 | } | |
1454 | ||
c0ee7ac6 | 1455 | ret = cdimg_read_func(cdHandle, 0, cdbuffer, sector); |
1456 | if (ret < 0) | |
1457 | return -1; | |
ef79bbde | 1458 | |
9a92bffb | 1459 | if (subHandle != NULL) { |
1460 | fseek(subHandle, sector * SUB_FRAMESIZE, SEEK_SET); | |
1461 | fread(subbuffer, 1, SUB_FRAMESIZE, subHandle); | |
ef79bbde | 1462 | |
9a92bffb | 1463 | if (subChanRaw) DecodeRawSubData(); |
ef79bbde P |
1464 | } |
1465 | ||
1466 | return 0; | |
1467 | } | |
1468 | ||
ef79bbde P |
1469 | // plays cdda audio |
1470 | // sector: byte 0 - minute; byte 1 - second; byte 2 - frame | |
1471 | // does NOT uses bcd format | |
1472 | static long CALLBACK ISOplay(unsigned char *time) { | |
77160d47 | 1473 | unsigned int i; |
38b8102c | 1474 | |
7b8da7ab | 1475 | if (numtracks <= 1) |
1476 | return 0; | |
1477 | ||
38b8102c | 1478 | // find the track |
77160d47 | 1479 | cdda_cur_sector = msf2sec((char *)time); |
2058d51f | 1480 | for (i = numtracks; i > 1; i--) { |
77160d47 | 1481 | cdda_first_sector = msf2sec(ti[i].start); |
1482 | if (cdda_first_sector <= cdda_cur_sector + 2 * 75) | |
38b8102c | 1483 | break; |
2058d51f | 1484 | } |
77160d47 | 1485 | cdda_file_offset = ti[i].start_offset; |
19c03d80 | 1486 | |
38b8102c | 1487 | // find the file that contains this track |
1488 | for (; i > 1; i--) | |
1489 | if (ti[i].handle != NULL) | |
1490 | break; | |
1491 | ||
2058d51f | 1492 | cddaHandle = ti[i].handle; |
8aa91443 | 1493 | |
77160d47 | 1494 | if (SPU_playCDDAchannel != NULL) |
1495 | startCDDA(); | |
1496 | ||
ef79bbde P |
1497 | return 0; |
1498 | } | |
1499 | ||
1500 | // stops cdda audio | |
1501 | static long CALLBACK ISOstop(void) { | |
1502 | stopCDDA(); | |
1503 | return 0; | |
1504 | } | |
1505 | ||
1506 | // gets subchannel data | |
1507 | static unsigned char* CALLBACK ISOgetBufferSub(void) { | |
8aa91443 | 1508 | if ((subHandle != NULL || subChanMixed) && !subChanMissing) { |
ef79bbde P |
1509 | return subbuffer; |
1510 | } | |
1511 | ||
1512 | return NULL; | |
1513 | } | |
1514 | ||
1515 | static long CALLBACK ISOgetStatus(struct CdrStat *stat) { | |
deebc67f | 1516 | u32 sect; |
1517 | ||
ef79bbde | 1518 | CDR__getStatus(stat); |
deebc67f | 1519 | |
ef79bbde P |
1520 | if (playing) { |
1521 | stat->Type = 0x02; | |
1522 | stat->Status |= 0x80; | |
ef79bbde P |
1523 | } |
1524 | else { | |
deebc67f | 1525 | // BIOS - boot ID (CD type) |
1526 | stat->Type = ti[1].type; | |
1527 | } | |
1528 | ||
1529 | // relative -> absolute time | |
1530 | sect = cddaCurPos; | |
1531 | sec2msf(sect, (char *)stat->Time); | |
1532 | ||
1533 | return 0; | |
1534 | } | |
1535 | ||
1536 | // read CDDA sector into buffer | |
1537 | long CALLBACK ISOreadCDDA(unsigned char m, unsigned char s, unsigned char f, unsigned char *buffer) { | |
1538 | unsigned char msf[3] = {m, s, f}; | |
1539 | unsigned int file, track, track_start = 0; | |
1540 | int ret; | |
1541 | ||
1542 | cddaCurPos = msf2sec((char *)msf); | |
1543 | ||
1544 | // find current track index | |
1545 | for (track = numtracks; ; track--) { | |
1546 | track_start = msf2sec(ti[track].start); | |
1547 | if (track_start <= cddaCurPos) | |
1548 | break; | |
1549 | if (track == 1) | |
1550 | break; | |
1551 | } | |
1552 | ||
1553 | // data tracks play silent | |
1554 | if (ti[track].type != CDDA) { | |
1555 | memset(buffer, 0, CD_FRAMESIZE_RAW); | |
1556 | return 0; | |
1557 | } | |
1558 | ||
1559 | file = 1; | |
1560 | if (multifile) { | |
1561 | // find the file that contains this track | |
1562 | for (file = track; file > 1; file--) | |
1563 | if (ti[file].handle != NULL) | |
1564 | break; | |
ef79bbde P |
1565 | } |
1566 | ||
deebc67f | 1567 | ret = cdimg_read_func(ti[file].handle, ti[track].start_offset, |
1568 | buffer, cddaCurPos - track_start); | |
1569 | if (ret != CD_FRAMESIZE_RAW) { | |
1570 | memset(buffer, 0, CD_FRAMESIZE_RAW); | |
1571 | return -1; | |
1572 | } | |
1573 | ||
1574 | if (cddaBigEndian) { | |
1575 | int i; | |
1576 | unsigned char tmp; | |
1577 | ||
1578 | for (i = 0; i < CD_FRAMESIZE_RAW / 2; i++) { | |
1579 | tmp = buffer[i * 2]; | |
1580 | buffer[i * 2] = buffer[i * 2 + 1]; | |
1581 | buffer[i * 2 + 1] = tmp; | |
1582 | } | |
1583 | } | |
858ad511 | 1584 | |
ef79bbde P |
1585 | return 0; |
1586 | } | |
1587 | ||
1588 | void cdrIsoInit(void) { | |
1589 | CDR_init = ISOinit; | |
1590 | CDR_shutdown = ISOshutdown; | |
1591 | CDR_open = ISOopen; | |
1592 | CDR_close = ISOclose; | |
1593 | CDR_getTN = ISOgetTN; | |
1594 | CDR_getTD = ISOgetTD; | |
1595 | CDR_readTrack = ISOreadTrack; | |
1596 | CDR_getBuffer = ISOgetBuffer; | |
1597 | CDR_play = ISOplay; | |
1598 | CDR_stop = ISOstop; | |
1599 | CDR_getBufferSub = ISOgetBufferSub; | |
1600 | CDR_getStatus = ISOgetStatus; | |
deebc67f | 1601 | CDR_readCDDA = ISOreadCDDA; |
ef79bbde P |
1602 | |
1603 | CDR_getDriveLetter = CDR__getDriveLetter; | |
1604 | CDR_configure = CDR__configure; | |
1605 | CDR_test = CDR__test; | |
1606 | CDR_about = CDR__about; | |
1607 | CDR_setfilename = CDR__setfilename; | |
1608 | ||
1609 | numtracks = 0; | |
1610 | } | |
1611 | ||
1612 | int cdrIsoActive(void) { | |
1613 | return (cdHandle != NULL); | |
1614 | } |