From bd7517b0c952c8927be73201f610e485dc11e072 Mon Sep 17 00:00:00 2001 From: NicknineTheEagle Date: Thu, 19 Jan 2023 15:41:32 +0300 Subject: [PATCH] CDROM: Try to reject non-PS1 discs --- src/core/cdrom.cpp | 39 ++++++++++++++++++++++++++++----------- src/core/cdrom.h | 1 + 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 256e29652..dc3ba790b 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -296,6 +296,7 @@ static Command s_command = Command::None; static Command s_command_second_response = Command::None; static DriveState s_drive_state = DriveState::Idle; static DiscRegion s_disc_region = DiscRegion::Other; +static bool s_ps1_disc = false; static StatusRegister s_status = {}; static SecondaryStatusRegister s_secondary_status = {}; @@ -664,15 +665,17 @@ DiscRegion CDROM::GetDiscRegion() } bool CDROM::IsMediaPS1Disc() +{ + return s_ps1_disc; +} + +bool CDROM::IsMediaAudioCD() { if (!m_reader.HasMedia()) return false; - // Check for a data track as the first track. - if (m_reader.GetMedia()->GetTrackMode(1) == CDImage::TrackMode::Audio) - return false; - - return true; + // Check for an audio track as the first track. + return (m_reader.GetMedia()->GetTrackMode(1) == CDImage::TrackMode::Audio); } bool CDROM::DoesMediaRegionMatchConsole() @@ -717,10 +720,23 @@ void CDROM::InsertMedia(std::unique_ptr media) if (CanReadMedia()) RemoveMedia(true); - // set the region from the system area of the disc - s_disc_region = System::GetRegionForImage(media.get()); - Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s", Settings::GetDiscRegionName(s_disc_region), - Settings::GetConsoleRegionName(System::GetRegion())); + // check if it's a valid PS1 disc + std::string exe_name; + std::vector exe_buffer; + s_ps1_disc = System::ReadExecutableFromImage(media.get(), &exe_name, &exe_buffer); + + if (s_ps1_disc) + { + // set the region from the system area of the disc + s_disc_region = System::GetRegionForImage(media.get()); + Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s", + Settings::GetDiscRegionName(s_disc_region), Settings::GetConsoleRegionName(System::GetRegion())); + } + else + { + s_disc_region = DiscRegion::Other; + Log_InfoPrint("Inserting new media, non-PS1 disc"); + } // motor automatically spins up if (s_drive_state != DriveState::ShellOpening) @@ -749,6 +765,7 @@ std::unique_ptr CDROM::RemoveMedia(bool for_disc_swap) s_secondary_status.shell_open = true; s_secondary_status.ClearActiveBits(); s_disc_region = DiscRegion::Other; + s_ps1_disc = false; // If the drive was doing anything, we need to abort the command. ClearDriveState(); @@ -2636,12 +2653,12 @@ void CDROM::DoIDRead() } else { - if (!IsMediaPS1Disc()) + if (IsMediaAudioCD()) { stat_byte |= STAT_ID_ERROR; flags_byte |= (1 << 7) | (1 << 4); // Unlicensed + Audio CD } - else if (!DoesMediaRegionMatchConsole()) + else if (!IsMediaPS1Disc() || !DoesMediaRegionMatchConsole()) { stat_byte |= STAT_ID_ERROR; flags_byte |= (1 << 7); // Unlicensed diff --git a/src/core/cdrom.h b/src/core/cdrom.h index a75c4785c..4ab7d517b 100644 --- a/src/core/cdrom.h +++ b/src/core/cdrom.h @@ -22,6 +22,7 @@ const std::string& GetMediaFileName(); const CDImage* GetMedia(); DiscRegion GetDiscRegion(); bool IsMediaPS1Disc(); +bool IsMediaAudioCD(); bool DoesMediaRegionMatchConsole(); void InsertMedia(std::unique_ptr media);