X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fcdrom.c;h=7a25c57dab25d714b53b2585baace3b5eb523e34;hb=2e88c3173da3048d8502f4ab0ee70fe215f549eb;hp=d6ee5204e922fe61b17cc5a61585736b4d284b6d;hpb=cc3577fe62b69ce1dcdce40ef2557ca800b02344;p=pcsx_rearmed.git diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index d6ee5204..7a25c57d 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -46,9 +46,10 @@ cdrStruct cdr; static unsigned char *pTransfer; +static s16 read_buf[CD_FRAMESIZE_RAW/2]; /* CD-ROM magic numbers */ -#define CdlSync 0 /* nocash documentation : "Uh, actually, returns error code 40h = Invalid Command...?" */ +#define CdlSync 0 /* nocash documentation : "Uh, actually, returns error code 40h = Invalid Command...?" */ #define CdlNop 1 #define CdlSetloc 2 #define CdlPlay 3 @@ -83,12 +84,12 @@ static unsigned char *pTransfer; char *CmdName[0x100]= { "CdlSync", "CdlNop", "CdlSetloc", "CdlPlay", "CdlForward", "CdlBackward", "CdlReadN", "CdlStandby", - "CdlStop", "CdlPause", "CdlReset", "CdlMute", + "CdlStop", "CdlPause", "CdlReset", "CdlMute", "CdlDemute", "CdlSetfilter", "CdlSetmode", "CdlGetparam", "CdlGetlocL", "CdlGetlocP", "CdlReadT", "CdlGetTN", "CdlGetTD", "CdlSeekL", "CdlSeekP", "CdlSetclock", "CdlGetclock", "CdlTest", "CdlID", "CdlReadS", - "CdlInit", NULL, "CDlReadToc", NULL + "CdlInit", NULL, "CDlReadToc", NULL }; unsigned char Test04[] = { 0 }; @@ -382,7 +383,7 @@ static void ReadTrack(const u8 *time) { CDR_LOG("ReadTrack *** %02x:%02x:%02x\n", tmp[0], tmp[1], tmp[2]); - cdr.RErr = CDR_readTrack(tmp); + cdr.NoErr = CDR_readTrack(tmp); memcpy(cdr.Prev, tmp, 3); if (CheckSBI(time)) @@ -431,6 +432,10 @@ static void AddIrqQueue(unsigned short irq, unsigned long ecycle) { static void cdrPlayInterrupt_Autopause() { + u32 abs_lev_max = 0; + boolean abs_lev_chselect; + u32 i; + if ((cdr.Mode & MODE_AUTOPAUSE) && cdr.TrackChanged) { CDR_LOG( "CDDA STOP\n" ); @@ -446,10 +451,19 @@ static void cdrPlayInterrupt_Autopause() StopCdda(); } else if (((cdr.Mode & MODE_REPORT) || cdr.FastForward || cdr.FastBackward)) { - cdr.Result[0] = cdr.StatP; cdr.Result[1] = cdr.subq.Track; cdr.Result[2] = cdr.subq.Index; + + abs_lev_chselect = cdr.subq.Absolute[1] & 0x01; + + /* 8 is a hack. For accuracy, it should be 588. */ + for (i = 0; i < 8; i++) + { + abs_lev_max = MAX_VALUE(abs_lev_max, abs(read_buf[i * 2 + abs_lev_chselect])); + } + abs_lev_max = MIN_VALUE(abs_lev_max, 32767); + abs_lev_max |= abs_lev_chselect << 15; if (cdr.subq.Absolute[2] & 0x10) { cdr.Result[3] = cdr.subq.Relative[0]; @@ -462,8 +476,8 @@ static void cdrPlayInterrupt_Autopause() cdr.Result[5] = cdr.subq.Absolute[2]; } - cdr.Result[6] = 0; - cdr.Result[7] = 0; + cdr.Result[6] = abs_lev_max >> 0; + cdr.Result[7] = abs_lev_max >> 8; // Rayman: Logo freeze (resultready + dataready) cdr.ResultReady = 1; @@ -490,7 +504,6 @@ void cdrPlayInterrupt() cdr.Seeked = SEEK_DONE; if (cdr.Irq == 0) { cdr.Stat = Complete; - cdr.RErr = 1; setIrq(); } @@ -513,11 +526,18 @@ void cdrPlayInterrupt() StopCdda(); cdr.TrackChanged = TRUE; } + else { + CDR_readCDDA(cdr.SetSectorPlay[0], cdr.SetSectorPlay[1], cdr.SetSectorPlay[2], (u8 *)read_buf); + } if (!cdr.Irq && !cdr.Stat && (cdr.Mode & (MODE_AUTOPAUSE|MODE_REPORT))) cdrPlayInterrupt_Autopause(); - if (!cdr.Play) return; + if (CDR_readCDDA && !cdr.Muted && !Config.Cdda) { + cdrAttenuate(read_buf, CD_FRAMESIZE_RAW / 4, 1); + if (SPU_playCDDAchannel) + SPU_playCDDAchannel(read_buf, CD_FRAMESIZE_RAW); + } cdr.SetSectorPlay[2]++; if (cdr.SetSectorPlay[2] == 75) { @@ -550,6 +570,8 @@ void cdrInterrupt() { int error = 0; int delay; unsigned int seekTime = 0; + u8 set_loc[3]; + int i; // Reschedule IRQ if (cdr.Stat) { @@ -583,14 +605,41 @@ void cdrInterrupt() { break; case CdlSetloc: + CDR_LOG("CDROM setloc command (%02X, %02X, %02X)\n", cdr.Param[0], cdr.Param[1], cdr.Param[2]); + + // MM must be BCD, SS must be BCD and <0x60, FF must be BCD and <0x75 + if (((cdr.Param[0] & 0x0F) > 0x09) || (cdr.Param[0] > 0x99) || ((cdr.Param[1] & 0x0F) > 0x09) || (cdr.Param[1] >= 0x60) || ((cdr.Param[2] & 0x0F) > 0x09) || (cdr.Param[2] >= 0x75)) + { + CDR_LOG("Invalid/out of range seek to %02X:%02X:%02X\n", cdr.Param[0], cdr.Param[1], cdr.Param[2]); + error = ERROR_INVALIDARG; + goto set_error; + } + else + { + for (i = 0; i < 3; i++) + { + set_loc[i] = btoi(cdr.Param[i]); + } + + i = msf2sec(cdr.SetSectorPlay); + i = abs(i - msf2sec(set_loc)); + if (i > 16) + cdr.Seeked = SEEK_PENDING; + + memcpy(cdr.SetSector, set_loc, 3); + cdr.SetSector[3] = 0; + cdr.SetlocPending = 1; + } break; do_CdlPlay: case CdlPlay: StopCdda(); - /* It would set it to SEEK_DONE*/ - cdr.Seeked = SEEK_PENDING; - + if (cdr.Seeked == SEEK_PENDING) { + // XXX: wrong, should seek instead.. + cdr.Seeked = SEEK_DONE; + } + cdr.FastBackward = 0; cdr.FastForward = 0; @@ -637,6 +686,7 @@ void cdrInterrupt() { ReadTrack(cdr.SetSectorPlay); cdr.TrackChanged = FALSE; + StopReading(); if (!Config.Cdda) CDR_play(cdr.SetSectorPlay); @@ -656,7 +706,7 @@ void cdrInterrupt() { case CdlForward: // TODO: error 80 if stopped cdr.Stat = Complete; - cdr.RErr = 1; + // GameShark CD Player: Calls 2x + Play 2x cdr.FastForward = 1; cdr.FastBackward = 0; @@ -666,7 +716,7 @@ void cdrInterrupt() { cdr.Stat = Complete; // GameShark CD Player: Calls 2x + Play 2x - cdr.FastBackward =1; + cdr.FastBackward = 1; cdr.FastForward = 0; break; @@ -681,7 +731,6 @@ void cdrInterrupt() { case CdlStandby + 0x100: cdr.Stat = Complete; - cdr.RErr = 1; break; case CdlStop: @@ -709,15 +758,16 @@ void cdrInterrupt() { cdr.StatP &= ~STATUS_ROTATING; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; - cdr.RErr = 1; break; case CdlPause: /* Gundam Battle Assault 2: much slower (*) - Fixes boot, gameplay + Hokuto no Ken 2: slower - Fixes intro + subtitles + InuYasha - Feudal Fairy Tale: slower - Fixes battles */ @@ -725,10 +775,8 @@ void cdrInterrupt() { * The timings from Duckstation are based upon hardware tests. * Mednafen's timing don't work for Gundam Battle Assault 2 in PAL/50hz mode, * seems to be timing sensitive as it can depend on the CPU's clock speed. - * - * We will need to get around this for Bedlam/Rise 2 later... * */ - if (cdr.DriveState != DRIVESTATE_STANDBY) + if (cdr.DriveState == DRIVESTATE_STANDBY) { delay = 7000; } @@ -745,12 +793,11 @@ void cdrInterrupt() { cdr.StatP &= ~STATUS_READ; cdr.Result[0] = cdr.StatP; cdr.Stat = Complete; - cdr.RErr = 1; break; case CdlReset: cdr.Muted = FALSE; - cdr.Mode = 0x20; /* Needed for This is Football 2, Pooh's Party and possibly others. */ + cdr.Mode = 0x20; /* This fixes This is Football 2, Pooh's Party lockups */ AddIrqQueue(CdlReset + 0x100, 4100000); no_busy_error = 1; start_rotating = 1; @@ -758,7 +805,6 @@ void cdrInterrupt() { case CdlReset + 0x100: cdr.Stat = Complete; - cdr.RErr = 1; break; case CdlMute: @@ -779,6 +825,7 @@ void cdrInterrupt() { break; case CdlGetparam: + /* Gameblabla : According to mednafen, Result size should be 5 and done this way. */ SetResultSize(5); cdr.Result[1] = cdr.Mode; cdr.Result[2] = 0; @@ -795,9 +842,6 @@ void cdrInterrupt() { case CdlGetlocP: SetResultSize(8); memcpy(&cdr.Result, &cdr.subq, 8); - - if (!cdr.Play && !cdr.Reading) - cdr.Result[1] = 0; // HACK? break; case CdlReadT: // SetSession? @@ -808,7 +852,6 @@ void cdrInterrupt() { case CdlReadT + 0x100: cdr.Stat = Complete; - cdr.RErr = 1; break; case CdlGetTN: @@ -908,7 +951,6 @@ void cdrInterrupt() { /* This adds the string "PCSX" in Playstation bios boot screen */ memcpy((char *)&cdr.Result[4], "PCSX", 4); cdr.Stat = Complete; - cdr.RErr = 1; break; case CdlInit: @@ -932,7 +974,6 @@ void cdrInterrupt() { case CdlReadToc + 0x100: cdr.Stat = Complete; - cdr.RErr = 1; no_busy_error = 1; break; @@ -987,7 +1028,7 @@ void cdrInterrupt() { - fixes cutscenes C-12 - Final Resistance - doesn't like seek */ - + /* By nicolasnoble from PCSX Redux : "It LOOKS like this logic is wrong, therefore disabling it with `&& false` for now. @@ -997,6 +1038,7 @@ void cdrInterrupt() { tries to protect itself against errors by preventing from issuing a GetLocP while it knows the last status was "seek". But this makes the logic just softlock as it'll never get a notification about the fact the drive is done seeking and the read actually started. + In other words, this state machine here is probably wrong in assuming the response to ReadS/ReadN is done right away. It's rather when it's done seeking, and the read has actually started. This probably requires a bit more work to make sure seek delays are processed properly. @@ -1007,12 +1049,12 @@ void cdrInterrupt() { */ cdr.StatP |= STATUS_READ; cdr.StatP &= ~STATUS_SEEK; + CDREAD_INT(((cdr.Mode & 0x80) ? (cdReadTime) : cdReadTime * 2) + seekTime); cdr.Result[0] = cdr.StatP; start_rotating = 1; break; - case CdlSync: default: CDR_LOG_I("Invalid command: %02x\n", Irq); @@ -1132,9 +1174,9 @@ void cdrReadInterrupt() { buf = CDR_getBuffer(); if (buf == NULL) - cdr.RErr = 0; + cdr.NoErr = 0; - if (cdr.RErr == 0) { + if (!cdr.NoErr) { CDR_LOG_I("cdrReadInterrupt() Log: err\n"); memset(cdr.Transfer, 0, DATA_SIZE); cdr.Stat = DiskError; @@ -1167,6 +1209,19 @@ void cdrReadInterrupt() { int ret = xa_decode_sector(&cdr.Xa, cdr.Transfer+4, cdr.FirstSector); if (!ret) { cdrAttenuate(cdr.Xa.pcm, cdr.Xa.nsamples, cdr.Xa.stereo); + /* + * Gameblabla - + * This is a hack for Megaman X4, Castlevania etc... + * that regressed from the new m_locationChanged and CDROM timings changes. + * It is mostly noticeable in Castevania however and the stuttering can be very jarring. + * + * According to PCSX redux authors, we shouldn't cause a location change if + * the sector difference is too small. + * I attempted to go with that approach but came empty handed. + * So for now, let's just set cdr.m_locationChanged to false when playing back any ADPCM samples. + * This does not regress Crash Team Racing's intro at least. + */ + cdr.m_locationChanged = FALSE; SPU_playADPCMchannel(&cdr.Xa); cdr.FirstSector = 0; } @@ -1260,9 +1315,6 @@ unsigned char cdrRead1(void) { } void cdrWrite1(unsigned char rt) { - u8 set_loc[3]; - int i; - CDR_LOG_IO("cdr w1: %02x\n", rt); switch (cdr.Ctrl & 3) { @@ -1296,31 +1348,6 @@ void cdrWrite1(unsigned char rt) { AddIrqQueue(cdr.Cmd, 0x800); switch (cdr.Cmd) { - case CdlSetloc: - CDR_LOG("CDROM setloc command (%02X, %02X, %02X)\n", cdr.Param[0], cdr.Param[1], cdr.Param[2]); - - // MM must be BCD, SS must be BCD and <0x60, FF must be BCD and <0x75 - if (((cdr.Param[0] & 0x0F) > 0x09) || (cdr.Param[0] > 0x99) || ((cdr.Param[1] & 0x0F) > 0x09) || (cdr.Param[1] >= 0x60) || ((cdr.Param[2] & 0x0F) > 0x09) || (cdr.Param[2] >= 0x75)) - { - CDR_LOG("Invalid/out of range seek to %02X:%02X:%02X\n", cdr.Param[0], cdr.Param[1], cdr.Param[2]); - } - else - { - for (i = 0; i < 3; i++) - { - set_loc[i] = btoi(cdr.Param[i]); - } - - i = msf2sec(cdr.SetSectorPlay); - i = abs(i - msf2sec(set_loc)); - if (i > 16) - cdr.Seeked = SEEK_PENDING; - - memcpy(cdr.SetSector, set_loc, 3); - cdr.SetSector[3] = 0; - cdr.SetlocPending = 1; - } - break; case CdlReadN: case CdlReadS: @@ -1469,7 +1496,7 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) { ptr = (u8 *)PSXM(madr); - if (ptr == NULL) { + if (ptr == INVALID_PTR) { CDR_LOG("psxDma3() Log: *** DMA 3 *** NULL Pointer!\n"); break; } @@ -1542,9 +1569,7 @@ void cdrReset() { cdr.DriveState = DRIVESTATE_STANDBY; cdr.StatP = STATUS_ROTATING; pTransfer = cdr.Transfer; - cdr.SetlocPending = 0; - cdr.m_locationChanged = FALSE; - + // BIOS player - default values cdr.AttenuatorLeftToLeft = 0x80; cdr.AttenuatorLeftToRight = 0x00;