CDROM: Try to reject non-PS1 discs

This commit is contained in:
NicknineTheEagle 2023-01-19 15:41:32 +03:00
parent 7270531c3d
commit bd7517b0c9
2 changed files with 29 additions and 11 deletions

View file

@ -296,6 +296,7 @@ static Command s_command = Command::None;
static Command s_command_second_response = Command::None; static Command s_command_second_response = Command::None;
static DriveState s_drive_state = DriveState::Idle; static DriveState s_drive_state = DriveState::Idle;
static DiscRegion s_disc_region = DiscRegion::Other; static DiscRegion s_disc_region = DiscRegion::Other;
static bool s_ps1_disc = false;
static StatusRegister s_status = {}; static StatusRegister s_status = {};
static SecondaryStatusRegister s_secondary_status = {}; static SecondaryStatusRegister s_secondary_status = {};
@ -664,15 +665,17 @@ DiscRegion CDROM::GetDiscRegion()
} }
bool CDROM::IsMediaPS1Disc() bool CDROM::IsMediaPS1Disc()
{
return s_ps1_disc;
}
bool CDROM::IsMediaAudioCD()
{ {
if (!m_reader.HasMedia()) if (!m_reader.HasMedia())
return false; return false;
// Check for a data track as the first track. // Check for an audio track as the first track.
if (m_reader.GetMedia()->GetTrackMode(1) == CDImage::TrackMode::Audio) return (m_reader.GetMedia()->GetTrackMode(1) == CDImage::TrackMode::Audio);
return false;
return true;
} }
bool CDROM::DoesMediaRegionMatchConsole() bool CDROM::DoesMediaRegionMatchConsole()
@ -717,10 +720,23 @@ void CDROM::InsertMedia(std::unique_ptr<CDImage> media)
if (CanReadMedia()) if (CanReadMedia())
RemoveMedia(true); RemoveMedia(true);
// check if it's a valid PS1 disc
std::string exe_name;
std::vector<u8> 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 // set the region from the system area of the disc
s_disc_region = System::GetRegionForImage(media.get()); s_disc_region = System::GetRegionForImage(media.get());
Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s", Settings::GetDiscRegionName(s_disc_region), Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s",
Settings::GetConsoleRegionName(System::GetRegion())); 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 // motor automatically spins up
if (s_drive_state != DriveState::ShellOpening) if (s_drive_state != DriveState::ShellOpening)
@ -749,6 +765,7 @@ std::unique_ptr<CDImage> CDROM::RemoveMedia(bool for_disc_swap)
s_secondary_status.shell_open = true; s_secondary_status.shell_open = true;
s_secondary_status.ClearActiveBits(); s_secondary_status.ClearActiveBits();
s_disc_region = DiscRegion::Other; s_disc_region = DiscRegion::Other;
s_ps1_disc = false;
// If the drive was doing anything, we need to abort the command. // If the drive was doing anything, we need to abort the command.
ClearDriveState(); ClearDriveState();
@ -2636,12 +2653,12 @@ void CDROM::DoIDRead()
} }
else else
{ {
if (!IsMediaPS1Disc()) if (IsMediaAudioCD())
{ {
stat_byte |= STAT_ID_ERROR; stat_byte |= STAT_ID_ERROR;
flags_byte |= (1 << 7) | (1 << 4); // Unlicensed + Audio CD flags_byte |= (1 << 7) | (1 << 4); // Unlicensed + Audio CD
} }
else if (!DoesMediaRegionMatchConsole()) else if (!IsMediaPS1Disc() || !DoesMediaRegionMatchConsole())
{ {
stat_byte |= STAT_ID_ERROR; stat_byte |= STAT_ID_ERROR;
flags_byte |= (1 << 7); // Unlicensed flags_byte |= (1 << 7); // Unlicensed

View file

@ -22,6 +22,7 @@ const std::string& GetMediaFileName();
const CDImage* GetMedia(); const CDImage* GetMedia();
DiscRegion GetDiscRegion(); DiscRegion GetDiscRegion();
bool IsMediaPS1Disc(); bool IsMediaPS1Disc();
bool IsMediaAudioCD();
bool DoesMediaRegionMatchConsole(); bool DoesMediaRegionMatchConsole();
void InsertMedia(std::unique_ptr<CDImage> media); void InsertMedia(std::unique_ptr<CDImage> media);