From e789cc84e297c44813ea4640eac54409685d70a9 Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Fri, 1 Jul 2011 00:58:11 +0000 Subject: [PATCH] Tray code once more: Added the tray state variable to the cdvd struct, making it safer and taking care of a previously unhandled situation. Surprisingly this didn't break old savestate compatibility. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4786 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/CDVD/CDVD.cpp | 13 +++++-------- pcsx2/CDVD/CDVD.h | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index c1654a2877..5844d7a97a 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -505,7 +505,7 @@ s32 cdvdCtrlTrayClose() DevCon.WriteLn( Color_Green, L"Close virtual disk tray"); cdvd.Status = CDVD_STATUS_PAUSE; cdvd.Ready = CDVD_READY1; - + cdvd.TrayTimeout = 0; // Reset so it can't get closed twice by cdvdVsync() return 0; // needs to be 0 for success according to homebrew test "CDVD" } @@ -933,21 +933,18 @@ 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 ) - { - // Fixme: Hacky and unsafe (rama) - timeout++; - //Console.Warning( "timeout = %d",timeout ); + { + cdvd.TrayTimeout++; } - if (timeout > 2) + if (cdvd.TrayTimeout > 3) { cdvdCtrlTrayClose(); - timeout = 0; + cdvd.TrayTimeout = 0; } cdvd.RTC.second++; diff --git a/pcsx2/CDVD/CDVD.h b/pcsx2/CDVD/CDVD.h index ca5ee28108..24a2e12bbf 100644 --- a/pcsx2/CDVD/CDVD.h +++ b/pcsx2/CDVD/CDVD.h @@ -126,6 +126,7 @@ struct cdvdStruct { u8 mg_kbit[16];//last BIT key 'seen' u8 mg_kcon[16];//last content key 'seen' + u8 TrayTimeout; u8 Action; // the currently scheduled emulated action u32 SeekToSector; // Holds the destination sector during seek operations. u32 ReadTime; // Avg. time to read one block of data (in Iop cycles)