MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / cdvdRotationTime

Function cdvdRotationTime

pcsx2/CDVD/CDVD.cpp:827–872  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

825 return CDVD_TYPE_DETCT; //Detecting any kind of disc existing
826}
827static u32 cdvdRotationTime(CDVD_MODE_TYPE mode)
828{
829 // CAV rotation is constant (minimum speed to maintain exact speed on outer dge
830 if (cdvd.SpindlCtrl & CDVD_SPINDLE_CAV)
831 {
832 // Calculate rotations per second from RPM
833 const float rotationPerSecond = static_cast<float>(((mode == MODE_CDROM) ? CD_MAX_ROTATION_X1 : DVD_MAX_ROTATION_X1) * cdvd.Speed) / 60.0f;
834 // Calculate MS per rotation by dividing 1 second of milliseconds by the number of rotations.
835 const float msPerRotation = 1000.0f / rotationPerSecond;
836 // Calculate how many cycles 1 millisecond takes in IOP clocks, multiply by the time for 1 rotation.
837 return static_cast<u32>((static_cast<float>(PSXCLK) / 1000.0f) * msPerRotation);
838 }
839 else
840 {
841 int numSectors = 0;
842 int offset = 0;
843
844 //CLV adjusts its speed based on where it is on the disc, so we can take the max RPM and use the sector to work it out
845 // Sector counts are taken from google for Single layer, Dual layer DVD's and for 700MB CD's
846 switch (cdvd.DiscType)
847 {
848 case CDVD_TYPE_DETCTDVDS:
849 case CDVD_TYPE_PS2DVD:
850 case CDVD_TYPE_DETCTDVDD:
851 numSectors = 2298496;
852
853 u32 layer1Start;
854 s32 dualType;
855 // Layer 1 needs an offset as it goes back to the middle of the disc
856 cdvdReadDvdDualInfo(&dualType, &layer1Start);
857 if (cdvd.SeekToSector >= layer1Start)
858 offset = layer1Start;
859 break;
860 default: // Pretty much every CD format
861 numSectors = 360000;
862 break;
863 }
864 // CLV speeds are reversed, so the centre is the fastest position.
865 const float sectorSpeed = (1.0f - ((static_cast<float>(cdvd.SeekToSector - offset) / numSectors) * 0.60f)) + 0.40f;
866
867 const float rotationPerSecond = static_cast<float>(((mode == MODE_CDROM) ? CD_MAX_ROTATION_X1 : DVD_MAX_ROTATION_X1) * std::min(static_cast<float>(cdvd.Speed), (mode == MODE_CDROM) ? 10.3f : 1.6f) * sectorSpeed) / 60.0f;
868 const float msPerRotation = 1000.0f / rotationPerSecond;
869 //DevCon.Warning("Rotations per second %f, msPerRotation cycles per ms %f total cycles per ms %d cycles per rotation %d", rotationPerSecond, msPerRotation, (u32)(PSXCLK / 1000), (u32)((PSXCLK / 1000) * msPerRotation));
870 return static_cast<u32>((static_cast<float>(PSXCLK) / 1000.0f) * msPerRotation);
871 }
872}
873
874static uint cdvdBlockReadTime(CDVD_MODE_TYPE mode) noexcept
875{

Callers 3

cdvdResetFunction · 0.85
cdvdStartSeekFunction · 0.85
cdvdWrite04Function · 0.85

Calls 2

cdvdReadDvdDualInfoFunction · 0.85
minFunction · 0.50

Tested by

no test coverage detected