From 3effa1238f67e3f61141830a932a076f1fe9326d Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 12 Mar 2020 13:51:53 +1000 Subject: [PATCH] CDROM: Return correct SCEx string based on disc region Fixes SCEI/SCEE displaying as SCEE in BIOS. --- src/core/cdrom.cpp | 52 ++++++++++++++++++++++++++++++--------------- src/core/cdrom.h | 3 ++- src/core/system.cpp | 3 ++- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 88fc17b89..a8b4d1d9e 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -3,6 +3,7 @@ #include "common/log.h" #include "common/state_wrapper.h" #include "dma.h" +#include "game_list.h" #include "imgui.h" #include "interrupt_controller.h" #include "settings.h" @@ -153,6 +154,11 @@ void CDROM::InsertMedia(std::unique_ptr media) if (HasMedia()) RemoveMedia(); + // set the region from the system area of the disc + m_disc_region = GameList::GetRegionForImage(media.get()); + Log_InfoPrintf("Inserting new media, disc region: %s, console region: %s", Settings::GetDiscRegionName(m_disc_region), + Settings::GetConsoleRegionName(m_system->GetRegion())); + m_reader.SetMedia(std::move(media)); } @@ -165,6 +171,7 @@ void CDROM::RemoveMedia() m_reader.RemoveMedia(); m_secondary_status.shell_open = true; + m_disc_region = DiscRegion::Other; // If the drive was doing anything, we need to abort the command. if (m_drive_state != DriveState::Idle) @@ -586,17 +593,10 @@ void CDROM::ExecuteCommand() case Command::GetID: { Log_DebugPrintf("CDROM GetID command"); - if (!HasMedia()) - { - SendErrorResponse(STAT_ERROR, 0x80); - } - else - { - SendACKAndStat(); + SendACKAndStat(); - m_drive_state = DriveState::ReadingID; - m_drive_event->Schedule(18000); - } + m_drive_state = DriveState::ReadingID; + m_drive_event->Schedule(18000); EndCommand(); return; @@ -1291,20 +1291,38 @@ void CDROM::DoChangeSessionComplete() void CDROM::DoIDRead() { - // TODO: This should depend on the disc type/region... - Log_DebugPrintf("ID read complete"); m_drive_state = DriveState::Idle; m_drive_event->Deactivate(); m_secondary_status.ClearActiveBits(); - m_secondary_status.motor_on = true; + m_secondary_status.motor_on = HasMedia(); m_sector_buffer.clear(); - static constexpr u8 response2[] = {0x00, 0x20, 0x00, 0x53, 0x43, 0x45, 0x41}; // last byte is 0x49 for EU + // TODO: Audio CD. + u8 stat_byte = m_secondary_status.bits; + u8 flags_byte = 0; + if (!HasMedia()) + { + flags_byte |= (1 << 6); // Disc Missing + } + else if (m_disc_region == DiscRegion::Other) + { + stat_byte |= STAT_ID_ERROR; + flags_byte |= (1 << 7); // Unlicensed + } + m_async_response_fifo.Clear(); - m_async_response_fifo.Push(m_secondary_status.bits); - m_async_response_fifo.PushRange(response2, countof(response2)); - SetAsyncInterrupt(Interrupt::Complete); + m_async_response_fifo.Push(stat_byte); + m_async_response_fifo.Push(flags_byte); + m_async_response_fifo.Push(0x20); // TODO: Disc type from TOC + m_async_response_fifo.Push(0x00); // TODO: Session info? + + static constexpr u32 REGION_STRING_LENGTH = 4; + static constexpr std::array, static_cast(DiscRegion::Count)> + region_strings = {{{'S', 'C', 'E', 'I'}, {'S', 'C', 'E', 'A'}, {'S', 'C', 'E', 'E'}, {0, 0, 0, 0}}}; + m_async_response_fifo.PushRange(region_strings[static_cast(m_disc_region)].data(), REGION_STRING_LENGTH); + + SetAsyncInterrupt((flags_byte != 0) ? Interrupt::Error : Interrupt::Complete); } void CDROM::DoTOCRead() diff --git a/src/core/cdrom.h b/src/core/cdrom.h index 2b11883f0..bab35be2e 100644 --- a/src/core/cdrom.h +++ b/src/core/cdrom.h @@ -1,10 +1,10 @@ #pragma once +#include "cdrom_async_reader.h" #include "common/bitfield.h" #include "common/cd_image.h" #include "common/cd_xa.h" #include "common/fifo_queue.h" #include "common/heap_array.h" -#include "cdrom_async_reader.h" #include "types.h" #include #include @@ -239,6 +239,7 @@ private: Command m_command = Command::None; DriveState m_drive_state = DriveState::Idle; + DiscRegion m_disc_region = DiscRegion::Other; StatusRegister m_status = {}; SecondaryStatusRegister m_secondary_status = {}; diff --git a/src/core/system.cpp b/src/core/system.cpp index 6555d556f..1ddf6b5e2 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -207,7 +207,8 @@ bool System::Boot(const SystemBootParameters& params) UpdateRunningGame(params.filename.c_str(), media.get()); // Insert CD, and apply fastboot patch if enabled. - m_cdrom->InsertMedia(std::move(media)); + if (media) + m_cdrom->InsertMedia(std::move(media)); if (m_cdrom->HasMedia() && (params.override_fast_boot.has_value() ? params.override_fast_boot.value() : GetSettings().bios_patch_fast_boot)) {