Skip to content

Commit

Permalink
sync cdvdman_fill_toc with OPL
Browse files Browse the repository at this point in the history
  • Loading branch information
rickgaiser committed Aug 30, 2023
1 parent 2d7504f commit fa5bfa1
Showing 1 changed file with 55 additions and 65 deletions.
120 changes: 55 additions & 65 deletions iop/cdvdman/src/ncmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ static void lba_to_msf(s32 lba, u8 *m, u8 *s, u8 *f)

//-------------------------------------------------------------------------
typedef struct {
u8 addr_ctrl;
u8 ctrl_adr;
u8 track_no;
u8 index_no;
u8 reserved[3];
u8 zero;
u8 point;
u8 min;
u8 sec;
u8 frm;
u8 zero; // always zero
u8 abs_min;
u8 abs_sec;
u8 abs_frm;
Expand All @@ -76,9 +78,10 @@ typedef struct {
//-------------------------------------------------------------------------
static int cdvdman_fill_toc(u8 *tocBuff)
{

u8 discType = cdvdman_stat.disc_type_reg & 0xFF;

DPRINTF("cdvdman_fill_toc tocBuff=0x%08x discType=0x%02X\n", (int)tocBuff, discType);
DPRINTF("cdvdman_fill_toc tocBuff=%08x discType=%02X\n", (int)tocBuff, discType);

if (tocBuff == NULL) {
return 0;
Expand All @@ -90,96 +93,83 @@ static int cdvdman_fill_toc(u8 *tocBuff)
toc_t *t = (toc_t *)tocBuff;
u8 min, sec, frm;

memset(tocBuff, 0, 1024);

// Number of FirstTrack,
// Always 1 until PS2CCDA support get's added.
t->a0.addr_ctrl = 0x00;
t->a0.track_no = 0x00;
t->a0.index_no = 0xA0; // ???
t->a0.abs_min = itob(1);
t->a0.abs_min = itob(0);
t->a0.abs_min = itob(0);

// Number of LastTrack
// Always 1 until PS2CCDA support get's added.
t->a1.addr_ctrl = 0x00;
t->a1.track_no = 0x00;
t->a1.index_no = 0xA1; // ???
t->a1.abs_min = itob(1);
t->a1.abs_min = itob(0);
t->a1.abs_min = itob(0);

// DiskLength
memset(tocBuff, 0, sizeof(toc_t));

// source: http://www.13thmonkey.org/documentation/SCSI/mmc2r11a.pdf, p. 17
// also table 308, p.230
// control field = 4 - Data track, recorded uninterrupted, digital copy prohibited
// ADR = 1 (Mode-1 Q)
t->a0.ctrl_adr = 0x41;
t->a0.track_no = 0x00; // always 0 for lead-in

// Number of First Track
t->a0.point = 0xA0;
t->a0.min = t->a0.sec = t->a0.frm = 0;
t->a0.abs_min = 1; // Number of First Track
t->a0.abs_sec = 0; // 0 - CD-DA or CD-ROM
t->a0.abs_frm = 0;

// Number of Last Track
t->a1.ctrl_adr = 0; // ?? should be 0x41
t->a1.track_no = 0;
t->a1.point = 0xA1;
t->a1.min = t->a1.sec = t->a1.frm = 0;
t->a1.abs_min = 1; // Number of Last Track, always 1 until PS2CCDA support get's added.
t->a1.abs_sec = 0;
t->a1.abs_frm = 0;

// Disk Length
t->a2.ctrl_adr = 0; // ?? should be 0x41
t->a2.track_no = 0;
t->a2.point = 0xA2;
t->a2.min = t->a2.sec = t->a2.frm = 0;
lba_to_msf(mediaLsnCount, &min, &sec, &frm);
t->a2.addr_ctrl = 0x00;
t->a2.track_no = 0x00;
t->a2.index_no = 0xA2; // ???
t->a2.abs_min = itob(min);
t->a2.abs_sec = itob(sec);
t->a2.abs_frm = itob(frm);

// Later when PS2CCDA is added the tracks need to get filled in toc too.
// ?? do we need to show here also first data track ??
// t->track[0].point = 0x01;

// Later if PS2CCDA is added the tracks need to get filled in toc too.
break;

case SCECdPS2DVD:
case SCECdDVDV:
// Toc for single layer DVD.
memset(tocBuff, 0, 2048);

u8 dual = 0;
if ((!(cdvdman_settings.common.flags & IOPCORE_COMPAT_EMU_DVDDL)) || (cdvdman_settings.common.layer1_start > 0))
dual = 1;

// Write only what we need, memset has cleared the above buffers.
// Single Layer - Values are fixed.
tocBuff[0] = 0x04;
tocBuff[0] = dual ? 0x24 : 0x04;
tocBuff[1] = 0x02;
tocBuff[2] = 0xF2;
tocBuff[4] = 0x86;
tocBuff[5] = 0x72;
tocBuff[3] = 0x00;

tocBuff[4] = dual ? 0x41 : 0x86;
tocBuff[5] = dual ? 0x95 : 0x72;

// These values are fixed on all discs, except position 14 which is the OTP/PTP flags which are 0 in single layer.

tocBuff[12] = 0x01;
tocBuff[13] = 0x02;
tocBuff[14] = 0x01;
tocBuff[14] = dual ? 0x21 : 0x01; // OTP/PTP flag
tocBuff[15] = 0x00;

tocBuff[17] = 0x03;

u32 maxlsn = mediaLsnCount + (0x30000 - 1);
u32 maxlsn = (cdvdman_settings.common.layer1_start ? cdvdman_settings.common.layer1_start : mediaLsnCount) + (0x30000 - 1);
tocBuff[20] = (maxlsn >> 24) & 0xFF;
tocBuff[21] = (maxlsn >> 16) & 0xff;
tocBuff[22] = (maxlsn >> 8) & 0xff;
tocBuff[23] = (maxlsn >> 0) & 0xff;
break;

default:
// Check if we are DVD9 game and fill toc for it.

if (!(cdvdman_settings.common.flags & IOPCORE_COMPAT_EMU_DVDDL)) {
memset(tocBuff, 0, 2048);

// Dual sided - Values are fixed.
tocBuff[0] = 0x24;
tocBuff[1] = 0x02;
tocBuff[2] = 0xF2;
tocBuff[4] = 0x41;
tocBuff[5] = 0x95;

// These values are fixed on all discs, except position 14 which is the OTP/PTP flags.
tocBuff[12] = 0x01;
tocBuff[13] = 0x02;
tocBuff[14] = 0x21; // PTP
tocBuff[15] = 0x10;

// Values are fixed.
tocBuff[17] = 0x03;

u32 l1s = mediaLsnCount + 0x30000 - 1;
tocBuff[20] = (l1s >> 24);
tocBuff[21] = (l1s >> 16) & 0xff;
tocBuff[22] = (l1s >> 8) & 0xff;
tocBuff[23] = (l1s >> 0) & 0xff;

return 1;
}

// Not known type.
DPRINTF("cdvdman_fill_toc unimplemented for discType=%02X\n", discType);
return 0;
Expand Down

0 comments on commit fa5bfa1

Please sign in to comment.