#endif
#include <zlib.h>
+unsigned int cdrIsoMultidiskCount;
+unsigned int cdrIsoMultidiskSelect;
+
static FILE *cdHandle = NULL;
static FILE *cddaHandle = NULL;
static FILE *subHandle = NULL;
static unsigned int initial_offset = 0;
static boolean playing = FALSE;
static boolean cddaBigEndian = FALSE;
+// offsets of cddaHandle file
static unsigned int cdda_cur_sector;
-static unsigned int cdda_start_sector;
+static unsigned int cdda_first_sector;
+// toc_sector - file_sector
+static unsigned int cdda_toc_delta;
/* Frame offset into CD image where pregap data would be found if it was there.
* If a game seeks there we must *not* return subchannel data since it's
* not in the CD image, so that cdrom code can fake subchannel data instead.
if (d < CD_FRAMESIZE_RAW)
break;
+ if (cdda_cur_sector < cdda_first_sector)
+ memset(sndbuffer + s, 0, CD_FRAMESIZE_RAW);
+
s += d;
cdda_cur_sector++;
}
- if (subHandle != NULL) {
- fseek(subHandle, cdda_cur_sector * SUB_FRAMESIZE, SEEK_SET);
- fread(subbuffer, 1, SUB_FRAMESIZE, subHandle);
-
- if (subChanRaw) DecodeRawSubData();
- }
-
if (s == 0) {
playing = FALSE;
initial_offset = 0;
unsigned int size;
unsigned int dontcare[6];
} index_entry;
- char psar_sig[9];
+ char psar_sig[11];
unsigned int t, cd_length, cdimg_base;
+ unsigned int offsettab[8], psisoimg_offs;
const char *ext = NULL;
int i, ret;
goto fail_io;
}
+ psisoimg_offs = pbp_hdr.psar_offs;
fread(psar_sig, 1, sizeof(psar_sig), cdHandle);
- psar_sig[8] = 0;
- if (strcmp(psar_sig, "PSISOIMG") != 0) {
+ psar_sig[10] = 0;
+ if (strcmp(psar_sig, "PSTITLEIMG") == 0) {
+ // multidisk image?
+ ret = fseek(cdHandle, pbp_hdr.psar_offs + 0x200, SEEK_SET);
+ if (ret != 0) {
+ fprintf(stderr, "failed to seek to %x\n", pbp_hdr.psar_offs + 0x200);
+ goto fail_io;
+ }
+
+ if (fread(&offsettab, 1, sizeof(offsettab), cdHandle) != sizeof(offsettab)) {
+ fprintf(stderr, "failed to read offsettab\n");
+ goto fail_io;
+ }
+
+ for (i = 0; i < sizeof(offsettab) / sizeof(offsettab[0]); i++) {
+ if (offsettab[i] == 0)
+ break;
+ }
+ cdrIsoMultidiskCount = i;
+ if (cdrIsoMultidiskCount == 0) {
+ fprintf(stderr, "multidisk eboot has 0 images?\n");
+ goto fail_io;
+ }
+
+ if (cdrIsoMultidiskSelect >= cdrIsoMultidiskCount)
+ cdrIsoMultidiskSelect = 0;
+
+ psisoimg_offs += offsettab[cdrIsoMultidiskSelect];
+
+ ret = fseek(cdHandle, psisoimg_offs, SEEK_SET);
+ if (ret != 0) {
+ fprintf(stderr, "failed to seek to %x\n", psisoimg_offs);
+ goto fail_io;
+ }
+
+ fread(psar_sig, 1, sizeof(psar_sig), cdHandle);
+ psar_sig[10] = 0;
+ }
+
+ if (strcmp(psar_sig, "PSISOIMG00") != 0) {
fprintf(stderr, "bad psar_sig: %s\n", psar_sig);
goto fail_io;
}
// seek to TOC
- ret = fseek(cdHandle, pbp_hdr.psar_offs + 0x800, SEEK_SET);
+ ret = fseek(cdHandle, psisoimg_offs + 0x800, SEEK_SET);
if (ret != 0) {
- fprintf(stderr, "failed to seek to %x\n", pbp_hdr.psar_offs);
+ fprintf(stderr, "failed to seek to %x\n", psisoimg_offs + 0x800);
goto fail_io;
}
sec2msf(t, ti[numtracks].length);
// seek to ISO index
- ret = fseek(cdHandle, pbp_hdr.psar_offs + 0x4000, SEEK_SET);
+ ret = fseek(cdHandle, psisoimg_offs + 0x4000, SEEK_SET);
if (ret != 0) {
fprintf(stderr, "failed to seek to ISO index\n");
goto fail_io;
if (compr_img->index_table == NULL)
goto fail_io;
- cdimg_base = pbp_hdr.psar_offs + 0x100000;
+ cdimg_base = psisoimg_offs + 0x100000;
for (i = 0; i < compr_img->index_len; i++) {
ret = fread(&index_entry, 1, sizeof(index_entry), cdHandle);
if (ret != sizeof(index_entry)) {
unsigned char rsv_06[2];
} ciso_hdr;
const char *ext = NULL;
- unsigned int index, plain;
+ unsigned int index = 0, plain;
int i, ret;
if (strlen(isofile) >= 5)
subChanMixed = FALSE;
subChanRaw = FALSE;
pregapOffset = 0;
+ cdrIsoMultidiskCount = 1;
CDR_getBuffer = ISOgetBuffer;
cdimg_read_func = cdread_normal;
if (numtracks > 1 && ti[1].handle == NULL) {
ti[1].handle = fopen(GetIsoFile(), "rb");
}
- cdda_cur_sector = cdda_start_sector = 0;
+ cdda_cur_sector = cdda_toc_delta = 0;
return 0;
}
// sector: byte 0 - minute; byte 1 - second; byte 2 - frame
// does NOT uses bcd format
static long CALLBACK ISOplay(unsigned char *time) {
- unsigned int i, abs_sect;
- int file_sect;
+ unsigned int i, abs_sect, start_sect = 0;
+ int track_offset, file_sect;
if (numtracks <= 1)
return 0;
// find the track
abs_sect = msf2sec((char *)time);
- for (i = numtracks; i > 1; i--)
- if (msf2sec(ti[i].start) <= abs_sect + 2 * 75)
+ for (i = numtracks; i > 1; i--) {
+ start_sect = msf2sec(ti[i].start);
+ if (start_sect <= abs_sect + 2 * 75)
break;
+ }
- file_sect = ti[i].start_offset + (abs_sect - msf2sec(ti[i].start));
+ track_offset = abs_sect - start_sect;
+ file_sect = ti[i].start_offset + track_offset;
if (file_sect < 0)
file_sect = 0;
if (ti[i].handle != NULL)
break;
- cdda_start_sector = abs_sect - file_sect;
- cddaHandle = ti[i].handle;
+ cdda_first_sector = 0;
+ if (i == 1)
+ cdda_first_sector = file_sect - track_offset;
- if (pregapOffset && (unsigned int)(pregapOffset - file_sect) < 2 * 75) {
- // get out of the missing pregap to avoid noise
- file_sect = pregapOffset;
- }
+ cdda_toc_delta = abs_sect - file_sect;
+ cddaHandle = ti[i].handle;
if (SPU_playCDDAchannel != NULL) {
startCDDA(file_sect);
stat->Type = 0x01;
}
- sec = cdda_start_sector + cdda_cur_sector;
+ sec = cdda_cur_sector + cdda_toc_delta;
sec2msf(sec, (char *)stat->Time);
return 0;