From f25d317460b3a6d39093f0d6f4a71db8649d4550 Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Fri, 1 Jul 2011 00:15:14 +0000 Subject: [PATCH] Some work on the disc tray code. Got rid of an unsafe global, changed and commented it a bit. This is some messy work of mine, gotta admit >< git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4785 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/CDVD/CDVD.cpp | 50 ++++++++++++++++++++++++------------- pcsx2/CDVD/CDVDaccess.cpp | 4 --- pcsx2/gui/AppCoreThread.cpp | 1 + 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index db2645ea05..c1654a2877 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -496,7 +496,6 @@ s32 cdvdCtrlTrayOpen() DiscSwapTimerSeconds = cdvd.RTC.second; // remember the PS2 time when this happened cdvd.Status = CDVD_STATUS_TRAY_OPEN; cdvd.Ready = CDVD_NOTREADY; - trayState = 1; return 0; // needs to be 0 for success according to homebrew test "CDVD" } @@ -506,7 +505,6 @@ s32 cdvdCtrlTrayClose() DevCon.WriteLn( Color_Green, L"Close virtual disk tray"); cdvd.Status = CDVD_STATUS_PAUSE; cdvd.Ready = CDVD_READY1; - trayState = 0; return 0; // needs to be 0 for success according to homebrew test "CDVD" } @@ -601,9 +599,6 @@ void SaveStateBase::cdvdFreeze() if( cdvd.Reading ) cdvd.RErr = DoCDVDreadTrack( cdvd.Readed ? cdvd.Sector : cdvd.SeekToSector, cdvd.ReadMode); - - // Also close the tray! - trayState = 0; } } @@ -938,16 +933,21 @@ static uint cdvdStartSeek( uint newsector, CDVD_MODE_TYPE mode ) u8 monthmap[13] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; void cdvdVsync() { + static u8 timeout = 0; // For closing the disk tray cdvd.RTCcount++; if (cdvd.RTCcount < ((gsRegionMode == Region_NTSC) ? 60 : 50)) return; cdvd.RTCcount = 0; if ( cdvd.Status == CDVD_STATUS_TRAY_OPEN ) { - if ( cdvd.RTC.second != DiscSwapTimerSeconds) - { - cdvdCtrlTrayClose(); - } + // Fixme: Hacky and unsafe (rama) + timeout++; + //Console.Warning( "timeout = %d",timeout ); + } + if (timeout > 2) + { + cdvdCtrlTrayClose(); + timeout = 0; } cdvd.RTC.second++; @@ -1026,8 +1026,11 @@ u8 cdvdRead(u8 key) case 0x0B: // TRAY-STATE (if tray has been opened) { - CDVD_LOG("cdvdRead0B(Tray) %x", trayState); - return /*tray*/ trayState; + CDVD_LOG("cdvdRead0B(Tray) (1 open, 0 closed): %x", cdvd.Status); + if (cdvd.Status == CDVD_STATUS_TRAY_OPEN) + return 1; + else + return 0; break; } case 0x0C: // CRT MINUTE @@ -1416,7 +1419,6 @@ static void cdvdWrite16(u8 rt) // SCOMMAND // cdvdTN diskInfo; // cdvdTD trackInfo; // int i, lbn, type, min, sec, frm, address; - static bool oldTrayState = 0; int address; u8 tmp; @@ -1474,18 +1476,30 @@ static void cdvdWrite16(u8 rt) // SCOMMAND case 0x05: // CdTrayReqState (0:1) - resets the tray open detection - //Console.Warning("CdTrayReqState. trayState = %d oldTrayState = %d",trayState, oldTrayState); + // Fixme: This function is believed to change some status flag + // when the Tray state (stored as "1" in cdvd.Status) is different between 2 successive calls. + // Cdvd.Status can be different than 1 here, yet we may still have to report an open status. + // Gonna have to investigate further. (rama) + + //Console.Warning("CdTrayReqState. cdvd.Status = %d", cdvd.Status); SetResultSize(1); - if (trayState != oldTrayState) - cdvd.Result[0] = 1; - else - cdvd.Result[0] = 0; // old behaviour was always this - oldTrayState = trayState; + if (cdvd.Status == CDVD_STATUS_TRAY_OPEN) + { + //Console.Warning( "reporting Open status" ); + cdvd.Result[0] = 1; + } + else + { + //Console.Warning( "reporting Close status" ); + cdvd.Result[0] = 0; // old behaviour was always this + } + break; case 0x06: // CdTrayCtrl (1:1) SetResultSize(1); + //Console.Warning( "CdTrayCtrl, param = %d", cdvd.Param[0]); if(cdvd.Param[0] == 0) cdvd.Result[0] = cdvdCtrlTrayOpen(); else diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index ca39f2f876..30ff5aa552 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -295,10 +295,6 @@ void CDVDsys_ChangeSource( CDVD_SourceType type ) { GetCorePlugins().Close( PluginId_CDVD ); - static bool firstRun = true; - if (!firstRun) cdvdCtrlTrayOpen(); - firstRun = false; - switch( m_CurrentSourceType = type ) { case CDVDsrc_Iso: diff --git a/pcsx2/gui/AppCoreThread.cpp b/pcsx2/gui/AppCoreThread.cpp index e7cdf11ab7..3ac678bd7b 100644 --- a/pcsx2/gui/AppCoreThread.cpp +++ b/pcsx2/gui/AppCoreThread.cpp @@ -387,6 +387,7 @@ void AppCoreThread::OnResumeInThread( bool isSuspended ) { GetCorePlugins().Close( PluginId_CDVD ); CDVDsys_ChangeSource( g_Conf->CdvdSource ); + cdvdCtrlTrayOpen(); m_resetCdvd = false; }