2019-09-14 20:28:47 +10:00
|
|
|
#include "host_interface.h"
|
2019-11-16 15:27:57 +10:00
|
|
|
#include "bios.h"
|
2020-01-02 19:14:06 +10:00
|
|
|
#include "cdrom.h"
|
2019-10-11 02:20:21 +10:00
|
|
|
#include "common/audio_stream.h"
|
2020-01-10 13:31:12 +10:00
|
|
|
#include "common/byte_stream.h"
|
|
|
|
|
#include "common/file_system.h"
|
2020-07-01 00:35:13 +10:00
|
|
|
#include "common/image.h"
|
2020-01-10 13:31:12 +10:00
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/string_util.h"
|
2020-07-01 00:35:13 +10:00
|
|
|
#include "controller.h"
|
2020-07-31 17:09:18 +10:00
|
|
|
#include "cpu_code_cache.h"
|
2020-08-02 00:25:07 +10:00
|
|
|
#include "cpu_core.h"
|
2020-01-02 19:14:06 +10:00
|
|
|
#include "dma.h"
|
|
|
|
|
#include "gpu.h"
|
2020-07-31 17:09:18 +10:00
|
|
|
#include "gte.h"
|
2019-11-08 01:07:39 +10:00
|
|
|
#include "host_display.h"
|
2020-08-02 00:25:07 +10:00
|
|
|
#include "pgxp.h"
|
2020-04-21 02:50:45 +10:00
|
|
|
#include "save_state_version.h"
|
2021-01-24 02:52:52 +10:00
|
|
|
#include "spu.h"
|
2019-09-14 20:28:47 +10:00
|
|
|
#include "system.h"
|
2020-12-26 00:08:04 +10:00
|
|
|
#include "texture_replacements.h"
|
2020-01-04 15:25:15 +10:00
|
|
|
#include <cmath>
|
2020-01-07 18:52:33 +10:00
|
|
|
#include <cstring>
|
2020-05-17 00:22:16 +10:00
|
|
|
#include <cwchar>
|
2020-02-15 22:30:26 +09:00
|
|
|
#include <stdlib.h>
|
2019-09-14 21:54:46 +10:00
|
|
|
Log_SetChannel(HostInterface);
|
2019-09-14 20:28:47 +10:00
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
HostInterface* g_host_interface;
|
|
|
|
|
|
2020-05-16 22:18:02 +10:00
|
|
|
HostInterface::HostInterface()
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
Assert(!g_host_interface);
|
|
|
|
|
g_host_interface = this;
|
|
|
|
|
|
2020-05-16 22:18:02 +10:00
|
|
|
// we can get the program directory at construction time
|
2021-04-24 16:03:28 +10:00
|
|
|
m_program_directory = FileSystem::GetPathDirectory(FileSystem::GetProgramPath());
|
2020-05-16 22:18:02 +10:00
|
|
|
}
|
2020-04-05 22:59:06 +10:00
|
|
|
|
|
|
|
|
HostInterface::~HostInterface()
|
|
|
|
|
{
|
|
|
|
|
// system should be shut down prior to the destructor
|
2020-07-31 17:09:18 +10:00
|
|
|
Assert(System::IsShutdown() && !m_audio_stream && !m_display);
|
|
|
|
|
Assert(g_host_interface == this);
|
|
|
|
|
g_host_interface = nullptr;
|
2020-04-05 22:59:06 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool HostInterface::Initialize()
|
2019-11-04 00:39:48 +10:00
|
|
|
{
|
2020-04-05 22:59:06 +10:00
|
|
|
return true;
|
2019-11-04 00:39:48 +10:00
|
|
|
}
|
2019-09-14 20:28:47 +10:00
|
|
|
|
2020-09-06 21:03:27 +10:00
|
|
|
void HostInterface::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
if (!System::IsShutdown())
|
|
|
|
|
System::Shutdown();
|
|
|
|
|
}
|
2019-09-14 21:54:46 +10:00
|
|
|
|
2021-06-08 18:38:12 +02:00
|
|
|
bool HostInterface::BootSystem(std::shared_ptr<SystemBootParameters> parameters)
|
2019-11-16 15:27:57 +10:00
|
|
|
{
|
2020-02-16 00:14:28 +09:00
|
|
|
if (!AcquireHostDisplay())
|
|
|
|
|
{
|
2021-03-29 13:59:22 -06:00
|
|
|
ReportError(g_host_interface->TranslateString("System", "Failed to acquire host display."));
|
2020-06-06 03:44:57 +10:00
|
|
|
OnSystemDestroyed();
|
2020-02-16 00:14:28 +09:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set host display settings
|
2020-07-31 17:09:18 +10:00
|
|
|
m_display->SetDisplayLinearFiltering(g_settings.display_linear_filtering);
|
|
|
|
|
m_display->SetDisplayIntegerScaling(g_settings.display_integer_scaling);
|
2021-02-27 13:53:03 +10:00
|
|
|
m_display->SetDisplayStretch(g_settings.display_stretch);
|
2020-02-16 00:14:28 +09:00
|
|
|
|
|
|
|
|
// create the audio stream. this will never fail, since we'll just fall back to null
|
2022-06-24 05:35:42 +02:00
|
|
|
m_audio_stream = CreateAudioStream();
|
|
|
|
|
m_audio_stream->Reconfigure(AUDIO_SAMPLE_RATE, AUDIO_SAMPLE_RATE, AUDIO_CHANNELS, g_settings.audio_buffer_size);
|
|
|
|
|
|
|
|
|
|
if (System::IsValid())
|
|
|
|
|
g_spu.SetAudioStream(m_audio_stream.get());
|
2020-02-16 00:14:28 +09:00
|
|
|
|
2021-06-08 18:38:12 +02:00
|
|
|
if (!System::Boot(*parameters))
|
2020-02-16 00:14:28 +09:00
|
|
|
{
|
2021-02-19 01:48:44 +10:00
|
|
|
if (!System::IsStartupCancelled())
|
|
|
|
|
{
|
2021-03-29 13:59:22 -06:00
|
|
|
ReportError(
|
2021-02-19 01:48:44 +10:00
|
|
|
g_host_interface->TranslateString("System", "System failed to boot. The log may contain more information."));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 02:56:12 +10:00
|
|
|
OnSystemDestroyed();
|
|
|
|
|
m_audio_stream.reset();
|
|
|
|
|
ReleaseHostDisplay();
|
2019-11-16 15:27:57 +10:00
|
|
|
return false;
|
2020-02-16 00:14:28 +09:00
|
|
|
}
|
|
|
|
|
|
2020-07-01 00:35:13 +10:00
|
|
|
UpdateSoftwareCursor();
|
2020-02-16 00:14:28 +09:00
|
|
|
OnSystemCreated();
|
2019-09-23 01:28:00 +10:00
|
|
|
|
2020-06-09 02:05:55 +10:00
|
|
|
m_audio_stream->PauseOutput(false);
|
2019-09-14 21:54:46 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-01 21:29:09 +10:00
|
|
|
void HostInterface::ResetSystem()
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
System::Reset();
|
2020-08-22 13:01:52 +10:00
|
|
|
AddOSDMessage(TranslateStdString("OSDMessage", "System reset."));
|
2019-12-01 21:29:09 +10:00
|
|
|
}
|
|
|
|
|
|
2020-12-17 01:12:56 +10:00
|
|
|
void HostInterface::PauseSystem(bool paused)
|
|
|
|
|
{
|
|
|
|
|
if (paused == System::IsPaused() || System::IsShutdown())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
System::SetState(paused ? System::State::Paused : System::State::Running);
|
|
|
|
|
if (!paused)
|
|
|
|
|
m_audio_stream->EmptyBuffers();
|
|
|
|
|
m_audio_stream->PauseOutput(paused);
|
|
|
|
|
|
|
|
|
|
OnSystemPaused(paused);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-16 15:27:57 +10:00
|
|
|
void HostInterface::DestroySystem()
|
2019-11-08 01:07:39 +10:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
if (System::IsShutdown())
|
2020-02-16 00:14:28 +09:00
|
|
|
return;
|
|
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
System::Shutdown();
|
2020-02-16 00:14:28 +09:00
|
|
|
m_audio_stream.reset();
|
2020-07-01 00:35:13 +10:00
|
|
|
UpdateSoftwareCursor();
|
2020-02-16 00:14:28 +09:00
|
|
|
ReleaseHostDisplay();
|
|
|
|
|
OnSystemDestroyed();
|
2019-11-08 01:07:39 +10:00
|
|
|
}
|
|
|
|
|
|
2019-11-16 15:27:57 +10:00
|
|
|
void HostInterface::ReportError(const char* message)
|
|
|
|
|
{
|
|
|
|
|
Log_ErrorPrint(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HostInterface::ReportMessage(const char* message)
|
|
|
|
|
{
|
2020-12-17 01:17:26 +10:00
|
|
|
Log_InfoPrint(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HostInterface::ReportDebuggerMessage(const char* message)
|
|
|
|
|
{
|
|
|
|
|
Log_InfoPrintf("(Debugger) %s", message);
|
2019-11-16 15:27:57 +10:00
|
|
|
}
|
|
|
|
|
|
2020-02-26 19:25:57 +10:00
|
|
|
bool HostInterface::ConfirmMessage(const char* message)
|
|
|
|
|
{
|
2021-02-04 17:54:51 -07:00
|
|
|
Log_WarningPrintf("ConfirmMessage(\"%s\") -> Yes", message);
|
2020-02-26 19:25:57 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-10 13:31:12 +10:00
|
|
|
void HostInterface::ReportFormattedError(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
ReportError(message.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HostInterface::ReportFormattedMessage(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
ReportMessage(message.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 01:17:26 +10:00
|
|
|
void HostInterface::ReportFormattedDebuggerMessage(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
ReportDebuggerMessage(message.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-26 19:25:57 +10:00
|
|
|
bool HostInterface::ConfirmFormattedMessage(const char* format, ...)
|
|
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
return ConfirmMessage(message.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 23:52:31 +10:00
|
|
|
void HostInterface::AddFormattedOSDMessage(float duration, const char* format, ...)
|
2019-12-01 21:33:56 +10:00
|
|
|
{
|
2021-11-16 23:52:31 +10:00
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
AddOSDMessage(std::move(message), duration);
|
2019-12-01 21:33:56 +10:00
|
|
|
}
|
|
|
|
|
|
2021-11-16 23:52:31 +10:00
|
|
|
void HostInterface::AddKeyedFormattedOSDMessage(std::string key, float duration, const char* format, ...)
|
2020-01-10 13:31:12 +10:00
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string message = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
2021-11-16 23:52:31 +10:00
|
|
|
AddKeyedOSDMessage(std::move(key), std::move(message), duration);
|
2020-01-02 19:14:06 +10:00
|
|
|
}
|
|
|
|
|
|
2020-09-23 22:53:51 +10:00
|
|
|
std::string HostInterface::GetBIOSDirectory()
|
2020-09-23 02:11:30 +10:00
|
|
|
{
|
2020-09-23 22:53:51 +10:00
|
|
|
std::string dir = GetStringSettingValue("BIOS", "SearchDirectory", "");
|
|
|
|
|
if (!dir.empty())
|
|
|
|
|
return dir;
|
|
|
|
|
|
2020-09-23 02:11:30 +10:00
|
|
|
return GetUserDirectoryRelativePath("bios");
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-16 15:27:57 +10:00
|
|
|
std::optional<std::vector<u8>> HostInterface::GetBIOSImage(ConsoleRegion region)
|
|
|
|
|
{
|
2020-09-23 22:53:51 +10:00
|
|
|
std::string bios_dir = GetBIOSDirectory();
|
|
|
|
|
std::string bios_name;
|
2019-11-16 15:27:57 +10:00
|
|
|
switch (region)
|
|
|
|
|
{
|
|
|
|
|
case ConsoleRegion::NTSC_J:
|
2020-09-23 22:53:51 +10:00
|
|
|
bios_name = GetStringSettingValue("BIOS", "PathNTSCJ", "");
|
2019-11-16 15:27:57 +10:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ConsoleRegion::PAL:
|
2020-10-29 14:26:07 -07:00
|
|
|
bios_name = GetStringSettingValue("BIOS", "PathPAL", "");
|
2019-11-16 15:27:57 +10:00
|
|
|
break;
|
|
|
|
|
|
2020-09-22 23:08:07 +10:00
|
|
|
case ConsoleRegion::NTSC_U:
|
2019-11-16 15:27:57 +10:00
|
|
|
default:
|
2020-09-23 22:53:51 +10:00
|
|
|
bios_name = GetStringSettingValue("BIOS", "PathNTSCU", "");
|
2019-11-16 15:27:57 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 05:58:53 +02:00
|
|
|
//auto-detect
|
2020-09-23 22:53:51 +10:00
|
|
|
if (bios_name.empty())
|
|
|
|
|
return FindBIOSImageInDirectory(region, bios_dir.c_str());
|
2020-09-22 23:08:07 +10:00
|
|
|
|
|
|
|
|
// try the configured path
|
|
|
|
|
std::optional<BIOS::Image> image = BIOS::LoadImageFromFile(
|
2020-09-23 22:53:51 +10:00
|
|
|
StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", bios_dir.c_str(), bios_name.c_str()).c_str());
|
2020-09-22 23:08:07 +10:00
|
|
|
if (!image.has_value())
|
2021-10-25 02:11:11 +02:00
|
|
|
return FindBIOSImageInDirectory(region, bios_dir.c_str());
|
2020-09-22 23:08:07 +10:00
|
|
|
|
|
|
|
|
BIOS::Hash found_hash = BIOS::GetHash(*image);
|
2020-09-23 22:53:51 +10:00
|
|
|
Log_DevPrintf("Hash for BIOS '%s': %s", bios_name.c_str(), found_hash.ToString().c_str());
|
2020-09-22 23:08:07 +10:00
|
|
|
|
|
|
|
|
if (!BIOS::IsValidHashForRegion(region, found_hash))
|
2020-09-23 22:53:51 +10:00
|
|
|
Log_WarningPrintf("Hash for BIOS '%s' does not match region. This may cause issues.", bios_name.c_str());
|
2020-09-22 23:08:07 +10:00
|
|
|
|
|
|
|
|
return image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<std::vector<u8>> HostInterface::FindBIOSImageInDirectory(ConsoleRegion region, const char* directory)
|
|
|
|
|
{
|
|
|
|
|
Log_InfoPrintf("Searching for a %s BIOS in '%s'...", Settings::GetConsoleRegionDisplayName(region), directory);
|
|
|
|
|
|
|
|
|
|
FileSystem::FindResultsArray results;
|
|
|
|
|
FileSystem::FindFiles(
|
|
|
|
|
directory, "*", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES | FILESYSTEM_FIND_RELATIVE_PATHS, &results);
|
|
|
|
|
|
|
|
|
|
std::string fallback_path;
|
|
|
|
|
std::optional<BIOS::Image> fallback_image;
|
2021-01-05 12:20:21 +10:00
|
|
|
const BIOS::ImageInfo* fallback_info = nullptr;
|
2020-09-22 23:08:07 +10:00
|
|
|
|
|
|
|
|
for (const FILESYSTEM_FIND_DATA& fd : results)
|
|
|
|
|
{
|
2021-01-04 23:38:42 -08:00
|
|
|
if (fd.Size != BIOS::BIOS_SIZE && fd.Size != BIOS::BIOS_SIZE_PS2 && fd.Size != BIOS::BIOS_SIZE_PS3)
|
2020-09-22 23:08:07 +10:00
|
|
|
{
|
|
|
|
|
Log_WarningPrintf("Skipping '%s': incorrect size", fd.FileName.c_str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string full_path(
|
|
|
|
|
StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", directory, fd.FileName.c_str()));
|
|
|
|
|
|
|
|
|
|
std::optional<BIOS::Image> found_image = BIOS::LoadImageFromFile(full_path.c_str());
|
|
|
|
|
if (!found_image)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
BIOS::Hash found_hash = BIOS::GetHash(*found_image);
|
|
|
|
|
Log_DevPrintf("Hash for BIOS '%s': %s", fd.FileName.c_str(), found_hash.ToString().c_str());
|
|
|
|
|
|
2021-01-05 12:20:21 +10:00
|
|
|
const BIOS::ImageInfo* ii = BIOS::GetImageInfoForHash(found_hash);
|
|
|
|
|
|
2020-09-22 23:08:07 +10:00
|
|
|
if (BIOS::IsValidHashForRegion(region, found_hash))
|
|
|
|
|
{
|
2021-01-05 12:20:21 +10:00
|
|
|
Log_InfoPrintf("Using BIOS '%s': %s", fd.FileName.c_str(), ii ? ii->description : "");
|
2020-09-22 23:08:07 +10:00
|
|
|
return found_image;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 12:20:21 +10:00
|
|
|
// don't let an unknown bios take precedence over a known one
|
|
|
|
|
if (!fallback_path.empty() && (fallback_info || !ii))
|
|
|
|
|
continue;
|
|
|
|
|
|
2020-09-22 23:08:07 +10:00
|
|
|
fallback_path = std::move(full_path);
|
|
|
|
|
fallback_image = std::move(found_image);
|
2021-01-05 12:20:21 +10:00
|
|
|
fallback_info = ii;
|
2020-09-22 23:08:07 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!fallback_image.has_value())
|
|
|
|
|
{
|
|
|
|
|
g_host_interface->ReportFormattedError(
|
|
|
|
|
g_host_interface->TranslateString("HostInterface", "No BIOS image found for %s region"),
|
|
|
|
|
Settings::GetConsoleRegionDisplayName(region));
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-05 12:20:21 +10:00
|
|
|
if (!fallback_info)
|
2021-10-25 02:11:11 +02:00
|
|
|
return std::nullopt;
|
2022-06-24 05:58:53 +02:00
|
|
|
|
|
|
|
|
Log_WarningPrintf("Falling back to possibly-incompatible image '%s': %s", fallback_path.c_str(),
|
|
|
|
|
fallback_info->description);
|
2021-01-05 12:20:21 +10:00
|
|
|
|
2020-09-22 23:08:07 +10:00
|
|
|
return fallback_image;
|
|
|
|
|
}
|
2019-11-16 15:27:57 +10:00
|
|
|
|
2020-07-04 20:45:54 +10:00
|
|
|
std::string HostInterface::GetShaderCacheBasePath() const
|
2020-06-19 00:18:17 +10:00
|
|
|
{
|
2020-07-04 20:45:54 +10:00
|
|
|
return GetUserDirectoryRelativePath("cache/");
|
2020-06-19 00:18:17 +10:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 02:05:55 +10:00
|
|
|
void HostInterface::LoadSettings(SettingsInterface& si)
|
2020-05-01 01:01:50 +10:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
g_settings.Load(si);
|
2020-08-19 23:26:57 +10:00
|
|
|
}
|
|
|
|
|
|
2020-08-20 22:25:49 +10:00
|
|
|
void HostInterface::FixIncompatibleSettings(bool display_osd_messages)
|
2020-08-19 23:26:57 +10:00
|
|
|
{
|
2020-12-30 17:39:29 +10:00
|
|
|
if (g_settings.disable_all_enhancements)
|
|
|
|
|
{
|
2021-01-05 17:58:55 +10:00
|
|
|
Log_WarningPrintf("All enhancements disabled by config setting.");
|
2020-12-30 17:39:29 +10:00
|
|
|
g_settings.cpu_overclock_enable = false;
|
|
|
|
|
g_settings.cpu_overclock_active = false;
|
2021-08-15 13:21:02 +10:00
|
|
|
g_settings.enable_8mb_ram = false;
|
2020-12-30 17:39:29 +10:00
|
|
|
g_settings.gpu_resolution_scale = 1;
|
|
|
|
|
g_settings.gpu_multisamples = 1;
|
|
|
|
|
g_settings.gpu_per_sample_shading = false;
|
|
|
|
|
g_settings.gpu_true_color = false;
|
|
|
|
|
g_settings.gpu_scaled_dithering = false;
|
|
|
|
|
g_settings.gpu_texture_filter = GPUTextureFilter::Nearest;
|
|
|
|
|
g_settings.gpu_disable_interlacing = false;
|
|
|
|
|
g_settings.gpu_force_ntsc_timings = false;
|
|
|
|
|
g_settings.gpu_widescreen_hack = false;
|
|
|
|
|
g_settings.gpu_pgxp_enable = false;
|
|
|
|
|
g_settings.gpu_24bit_chroma_smoothing = false;
|
2021-05-23 13:35:10 +10:00
|
|
|
g_settings.cdrom_read_speedup = 1;
|
|
|
|
|
g_settings.cdrom_seek_speedup = 1;
|
2020-12-30 17:39:29 +10:00
|
|
|
g_settings.cdrom_mute_cd_audio = false;
|
|
|
|
|
g_settings.texture_replacements.enable_vram_write_replacements = false;
|
|
|
|
|
g_settings.bios_patch_fast_boot = false;
|
|
|
|
|
g_settings.bios_patch_tty_enable = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 18:39:15 +10:00
|
|
|
if (g_settings.display_integer_scaling && g_settings.display_linear_filtering)
|
|
|
|
|
{
|
|
|
|
|
Log_WarningPrintf("Disabling linear filter due to integer upscaling.");
|
|
|
|
|
g_settings.display_linear_filtering = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 21:58:47 +10:00
|
|
|
if (g_settings.display_integer_scaling && g_settings.display_stretch)
|
2021-02-27 13:53:03 +10:00
|
|
|
{
|
|
|
|
|
Log_WarningPrintf("Disabling stretch due to integer upscaling.");
|
|
|
|
|
g_settings.display_stretch = false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 23:26:57 +10:00
|
|
|
if (g_settings.gpu_pgxp_enable)
|
|
|
|
|
{
|
|
|
|
|
if (g_settings.gpu_renderer == GPURenderer::Software)
|
|
|
|
|
{
|
2020-08-20 22:25:49 +10:00
|
|
|
if (display_osd_messages)
|
2020-08-22 13:01:52 +10:00
|
|
|
{
|
2020-08-29 22:07:33 +10:00
|
|
|
AddOSDMessage(
|
|
|
|
|
TranslateStdString("OSDMessage", "PGXP is incompatible with the software renderer, disabling PGXP."), 10.0f);
|
2020-08-22 13:01:52 +10:00
|
|
|
}
|
2020-08-19 23:26:57 +10:00
|
|
|
g_settings.gpu_pgxp_enable = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-23 01:06:25 +10:00
|
|
|
|
|
|
|
|
#ifndef WITH_MMAP_FASTMEM
|
|
|
|
|
if (g_settings.cpu_fastmem_mode == CPUFastmemMode::MMap)
|
|
|
|
|
{
|
2020-12-01 13:23:02 +10:00
|
|
|
Log_WarningPrintf("mmap fastmem is not available on this platform, using LUT instead.");
|
2020-11-23 01:06:25 +10:00
|
|
|
g_settings.cpu_fastmem_mode = CPUFastmemMode::LUT;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-01-23 19:00:54 +10:00
|
|
|
|
2021-08-05 19:45:14 +10:00
|
|
|
#if defined(__ANDROID__) && defined(__arm__) && !defined(__aarch64__) && !defined(_M_ARM64)
|
|
|
|
|
if (g_settings.rewind_enable)
|
|
|
|
|
{
|
2021-08-15 11:54:54 +10:00
|
|
|
AddOSDMessage(TranslateStdString("OSDMessage", "Rewind is not supported on 32-bit ARM for Android."), 30.0f);
|
2021-08-05 19:45:14 +10:00
|
|
|
g_settings.rewind_enable = false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-05-01 01:01:50 +10:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 02:05:55 +10:00
|
|
|
void HostInterface::CheckForSettingsChanges(const Settings& old_settings)
|
2020-01-24 14:51:52 +10:00
|
|
|
{
|
2020-10-27 11:57:41 +10:00
|
|
|
if (System::IsValid() && (g_settings.gpu_renderer != old_settings.gpu_renderer ||
|
2020-12-26 23:22:24 +10:00
|
|
|
g_settings.gpu_use_debug_device != old_settings.gpu_use_debug_device ||
|
|
|
|
|
g_settings.gpu_threaded_presentation != old_settings.gpu_threaded_presentation))
|
2020-10-27 11:57:41 +10:00
|
|
|
{
|
|
|
|
|
AddFormattedOSDMessage(5.0f, TranslateString("OSDMessage", "Switching to %s%s GPU renderer."),
|
|
|
|
|
Settings::GetRendererName(g_settings.gpu_renderer),
|
|
|
|
|
g_settings.gpu_use_debug_device ? " (debug)" : "");
|
|
|
|
|
RecreateSystem();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-20 21:30:11 +10:00
|
|
|
if (System::IsValid())
|
2020-01-24 14:51:52 +10:00
|
|
|
{
|
2021-01-23 19:00:54 +10:00
|
|
|
System::ClearMemorySaveStates();
|
|
|
|
|
|
2020-09-29 23:29:28 +10:00
|
|
|
if (g_settings.cpu_overclock_active != old_settings.cpu_overclock_active ||
|
|
|
|
|
(g_settings.cpu_overclock_active &&
|
|
|
|
|
(g_settings.cpu_overclock_numerator != old_settings.cpu_overclock_numerator ||
|
|
|
|
|
g_settings.cpu_overclock_denominator != old_settings.cpu_overclock_denominator)))
|
|
|
|
|
{
|
|
|
|
|
System::UpdateOverclock();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 14:43:55 +10:00
|
|
|
if (g_settings.cpu_execution_mode != old_settings.cpu_execution_mode ||
|
2021-12-26 00:05:20 +01:00
|
|
|
g_settings.cpu_fastmem_mode != old_settings.cpu_fastmem_mode ||
|
|
|
|
|
g_settings.cpu_fastmem_rewrite != old_settings.cpu_fastmem_rewrite)
|
2020-02-16 00:14:40 +09:00
|
|
|
{
|
2021-12-26 00:05:20 +01:00
|
|
|
if (g_settings.cpu_execution_mode != old_settings.cpu_execution_mode)
|
|
|
|
|
{
|
|
|
|
|
AddFormattedOSDMessage(
|
|
|
|
|
5.0f, TranslateString("OSDMessage", "Switching to %s CPU execution mode."),
|
|
|
|
|
TranslateString("CPUExecutionMode", Settings::GetCPUExecutionModeDisplayName(g_settings.cpu_execution_mode))
|
|
|
|
|
.GetCharArray());
|
|
|
|
|
}
|
2020-10-18 14:43:55 +10:00
|
|
|
CPU::CodeCache::Reinitialize();
|
2020-08-29 22:07:33 +10:00
|
|
|
CPU::ClearICache();
|
2020-02-16 00:14:40 +09:00
|
|
|
}
|
2020-02-05 17:43:15 +09:00
|
|
|
|
2020-08-08 16:44:12 +10:00
|
|
|
if (g_settings.cpu_execution_mode == CPUExecutionMode::Recompiler &&
|
2021-05-22 14:55:25 +10:00
|
|
|
(g_settings.cpu_recompiler_memory_exceptions != old_settings.cpu_recompiler_memory_exceptions ||
|
|
|
|
|
g_settings.cpu_recompiler_block_linking != old_settings.cpu_recompiler_block_linking ||
|
|
|
|
|
g_settings.cpu_recompiler_icache != old_settings.cpu_recompiler_icache))
|
2020-08-08 16:44:12 +10:00
|
|
|
{
|
2021-05-22 14:55:25 +10:00
|
|
|
AddOSDMessage(TranslateStdString("OSDMessage", "Recompiler options changed, flushing all blocks."), 5.0f);
|
2020-08-08 16:44:12 +10:00
|
|
|
CPU::CodeCache::Flush();
|
|
|
|
|
|
2021-05-22 14:55:25 +10:00
|
|
|
if (g_settings.cpu_recompiler_icache != old_settings.cpu_recompiler_icache)
|
|
|
|
|
CPU::ClearICache();
|
2020-08-29 22:07:33 +10:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
if (g_settings.gpu_resolution_scale != old_settings.gpu_resolution_scale ||
|
2020-10-31 00:38:06 +10:00
|
|
|
g_settings.gpu_multisamples != old_settings.gpu_multisamples ||
|
|
|
|
|
g_settings.gpu_per_sample_shading != old_settings.gpu_per_sample_shading ||
|
2020-11-21 13:32:58 +10:00
|
|
|
g_settings.gpu_use_thread != old_settings.gpu_use_thread ||
|
2021-05-19 13:43:49 +10:00
|
|
|
g_settings.gpu_use_software_renderer_for_readbacks != old_settings.gpu_use_software_renderer_for_readbacks ||
|
2020-07-31 17:09:18 +10:00
|
|
|
g_settings.gpu_fifo_size != old_settings.gpu_fifo_size ||
|
|
|
|
|
g_settings.gpu_max_run_ahead != old_settings.gpu_max_run_ahead ||
|
|
|
|
|
g_settings.gpu_true_color != old_settings.gpu_true_color ||
|
|
|
|
|
g_settings.gpu_scaled_dithering != old_settings.gpu_scaled_dithering ||
|
2020-09-11 22:20:19 +10:00
|
|
|
g_settings.gpu_texture_filter != old_settings.gpu_texture_filter ||
|
2020-07-31 17:09:18 +10:00
|
|
|
g_settings.gpu_disable_interlacing != old_settings.gpu_disable_interlacing ||
|
|
|
|
|
g_settings.gpu_force_ntsc_timings != old_settings.gpu_force_ntsc_timings ||
|
2020-11-03 14:17:51 +10:00
|
|
|
g_settings.gpu_24bit_chroma_smoothing != old_settings.gpu_24bit_chroma_smoothing ||
|
2020-12-30 16:26:20 +10:00
|
|
|
g_settings.gpu_downsample_mode != old_settings.gpu_downsample_mode ||
|
2020-07-31 17:09:18 +10:00
|
|
|
g_settings.display_crop_mode != old_settings.display_crop_mode ||
|
2020-08-10 22:37:30 +10:00
|
|
|
g_settings.display_aspect_ratio != old_settings.display_aspect_ratio ||
|
2020-08-20 21:30:11 +10:00
|
|
|
g_settings.gpu_pgxp_enable != old_settings.gpu_pgxp_enable ||
|
2020-12-23 01:10:49 +10:00
|
|
|
g_settings.gpu_pgxp_depth_buffer != old_settings.gpu_pgxp_depth_buffer ||
|
2020-08-20 21:30:11 +10:00
|
|
|
g_settings.display_active_start_offset != old_settings.display_active_start_offset ||
|
2020-12-03 22:31:21 +10:00
|
|
|
g_settings.display_active_end_offset != old_settings.display_active_end_offset ||
|
|
|
|
|
g_settings.display_line_start_offset != old_settings.display_line_start_offset ||
|
2021-01-23 19:00:54 +10:00
|
|
|
g_settings.display_line_end_offset != old_settings.display_line_end_offset ||
|
2021-01-24 02:52:52 +10:00
|
|
|
g_settings.rewind_enable != old_settings.rewind_enable ||
|
2021-01-26 02:48:40 +10:00
|
|
|
g_settings.runahead_frames != old_settings.runahead_frames)
|
2020-02-05 17:43:15 +09:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
g_gpu->UpdateSettings();
|
2020-02-05 17:43:15 +09:00
|
|
|
}
|
2020-02-22 00:19:10 +09:00
|
|
|
|
2021-05-01 02:56:29 +10:00
|
|
|
if (g_settings.gpu_widescreen_hack != old_settings.gpu_widescreen_hack ||
|
|
|
|
|
g_settings.display_aspect_ratio != old_settings.display_aspect_ratio ||
|
2021-04-29 02:42:08 +10:00
|
|
|
(g_settings.display_aspect_ratio == DisplayAspectRatio::Custom &&
|
|
|
|
|
(g_settings.display_aspect_ratio_custom_numerator != old_settings.display_aspect_ratio_custom_numerator ||
|
|
|
|
|
g_settings.display_aspect_ratio_custom_denominator != old_settings.display_aspect_ratio_custom_denominator)))
|
|
|
|
|
{
|
|
|
|
|
GTE::UpdateAspectRatio();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-02 00:25:07 +10:00
|
|
|
if (g_settings.gpu_pgxp_enable != old_settings.gpu_pgxp_enable ||
|
2021-02-18 00:40:06 +10:00
|
|
|
(g_settings.gpu_pgxp_enable && (g_settings.gpu_pgxp_culling != old_settings.gpu_pgxp_culling ||
|
2021-06-12 22:02:28 +10:00
|
|
|
g_settings.gpu_pgxp_vertex_cache != old_settings.gpu_pgxp_vertex_cache ||
|
2021-02-18 00:40:06 +10:00
|
|
|
g_settings.gpu_pgxp_cpu != old_settings.gpu_pgxp_cpu)))
|
2020-08-02 00:25:07 +10:00
|
|
|
{
|
|
|
|
|
if (g_settings.IsUsingCodeCache())
|
|
|
|
|
{
|
2020-10-03 01:05:56 +10:00
|
|
|
AddOSDMessage(g_settings.gpu_pgxp_enable ?
|
|
|
|
|
TranslateStdString("OSDMessage", "PGXP enabled, recompiling all blocks.") :
|
|
|
|
|
TranslateStdString("OSDMessage", "PGXP disabled, recompiling all blocks."),
|
|
|
|
|
5.0f);
|
2020-08-02 00:25:07 +10:00
|
|
|
CPU::CodeCache::Flush();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 22:44:52 +10:00
|
|
|
if (old_settings.gpu_pgxp_enable)
|
|
|
|
|
PGXP::Shutdown();
|
|
|
|
|
|
2020-08-02 00:25:07 +10:00
|
|
|
if (g_settings.gpu_pgxp_enable)
|
|
|
|
|
PGXP::Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 21:08:04 +10:00
|
|
|
if (g_settings.cdrom_readahead_sectors != old_settings.cdrom_readahead_sectors)
|
|
|
|
|
g_cdrom.SetReadaheadSectors(g_settings.cdrom_readahead_sectors);
|
2020-04-27 16:15:38 +10:00
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
if (g_settings.memory_card_types != old_settings.memory_card_types ||
|
2020-08-15 20:38:54 +10:00
|
|
|
g_settings.memory_card_paths != old_settings.memory_card_paths ||
|
|
|
|
|
(g_settings.memory_card_use_playlist_title != old_settings.memory_card_use_playlist_title &&
|
2021-03-27 15:18:23 +10:00
|
|
|
System::HasMediaSubImages()) ||
|
|
|
|
|
g_settings.memory_card_directory != old_settings.memory_card_directory)
|
2020-05-10 00:44:37 +10:00
|
|
|
{
|
2021-05-24 19:55:07 +10:00
|
|
|
System::UpdateMemoryCardTypes();
|
2020-05-10 00:44:37 +10:00
|
|
|
}
|
2020-04-29 20:00:22 +10:00
|
|
|
|
2021-01-23 19:00:54 +10:00
|
|
|
if (g_settings.rewind_enable != old_settings.rewind_enable ||
|
|
|
|
|
g_settings.rewind_save_frequency != old_settings.rewind_save_frequency ||
|
2021-01-24 02:52:52 +10:00
|
|
|
g_settings.rewind_save_slots != old_settings.rewind_save_slots ||
|
|
|
|
|
g_settings.runahead_frames != old_settings.runahead_frames)
|
2021-01-23 19:00:54 +10:00
|
|
|
{
|
|
|
|
|
System::UpdateMemorySaveStateSettings();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-26 00:08:04 +10:00
|
|
|
if (g_settings.texture_replacements.enable_vram_write_replacements !=
|
|
|
|
|
old_settings.texture_replacements.enable_vram_write_replacements ||
|
|
|
|
|
g_settings.texture_replacements.preload_textures != old_settings.texture_replacements.preload_textures)
|
|
|
|
|
{
|
|
|
|
|
g_texture_replacements.Reload();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
g_dma.SetMaxSliceTicks(g_settings.dma_max_slice_ticks);
|
|
|
|
|
g_dma.SetHaltTicks(g_settings.dma_halt_ticks);
|
2020-01-24 14:51:52 +10:00
|
|
|
}
|
|
|
|
|
|
2020-03-22 12:53:56 +10:00
|
|
|
bool controllers_updated = false;
|
2020-02-16 00:14:44 +09:00
|
|
|
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
if (g_settings.controller_types[i] != old_settings.controller_types[i])
|
2020-03-22 12:53:56 +10:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
if (!System::IsShutdown() && !controllers_updated)
|
2020-03-22 12:53:56 +10:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
System::UpdateControllers();
|
|
|
|
|
System::ResetControllers();
|
2020-07-01 00:35:13 +10:00
|
|
|
UpdateSoftwareCursor();
|
2020-03-22 12:53:56 +10:00
|
|
|
controllers_updated = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 00:14:44 +09:00
|
|
|
OnControllerTypeChanged(i);
|
2020-03-22 12:53:56 +10:00
|
|
|
}
|
2020-07-01 00:33:45 +10:00
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
if (!System::IsShutdown() && !controllers_updated)
|
2020-07-01 00:35:13 +10:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
System::UpdateControllerSettings();
|
2020-07-01 00:35:13 +10:00
|
|
|
UpdateSoftwareCursor();
|
|
|
|
|
}
|
2020-02-16 00:14:44 +09:00
|
|
|
}
|
|
|
|
|
|
2021-01-20 23:59:40 -08:00
|
|
|
if (g_settings.multitap_mode != old_settings.multitap_mode)
|
|
|
|
|
System::UpdateMultitaps();
|
|
|
|
|
|
2021-07-12 22:44:02 +10:00
|
|
|
if (m_display && (g_settings.display_linear_filtering != old_settings.display_linear_filtering ||
|
|
|
|
|
g_settings.display_integer_scaling != old_settings.display_integer_scaling ||
|
|
|
|
|
g_settings.display_stretch != old_settings.display_stretch))
|
2021-02-27 13:53:03 +10:00
|
|
|
{
|
2021-07-11 14:01:04 +10:00
|
|
|
m_display->SetDisplayLinearFiltering(g_settings.display_linear_filtering);
|
|
|
|
|
m_display->SetDisplayIntegerScaling(g_settings.display_integer_scaling);
|
|
|
|
|
m_display->SetDisplayStretch(g_settings.display_stretch);
|
2021-02-27 13:53:03 +10:00
|
|
|
}
|
2020-06-09 02:05:55 +10:00
|
|
|
}
|
|
|
|
|
|
2021-04-29 02:42:08 +10:00
|
|
|
void HostInterface::OnHostDisplayResized()
|
|
|
|
|
{
|
|
|
|
|
if (System::IsValid())
|
|
|
|
|
{
|
2021-05-01 02:56:29 +10:00
|
|
|
if (g_settings.gpu_widescreen_hack && g_settings.display_aspect_ratio == DisplayAspectRatio::MatchWindow)
|
2021-04-29 02:42:08 +10:00
|
|
|
GTE::UpdateAspectRatio();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 02:05:55 +10:00
|
|
|
std::string HostInterface::GetUserDirectoryRelativePath(const char* format, ...) const
|
|
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string formatted_path = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
if (m_user_directory.empty())
|
|
|
|
|
{
|
|
|
|
|
return formatted_path;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-19 22:39:04 +02:00
|
|
|
return StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", m_user_directory.c_str(),
|
2020-06-09 02:05:55 +10:00
|
|
|
formatted_path.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string HostInterface::GetProgramDirectoryRelativePath(const char* format, ...) const
|
|
|
|
|
{
|
|
|
|
|
std::va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
std::string formatted_path = StringUtil::StdStringFromFormatV(format, ap);
|
|
|
|
|
va_end(ap);
|
2020-06-08 02:53:53 +10:00
|
|
|
|
2020-06-09 02:05:55 +10:00
|
|
|
if (m_program_directory.empty())
|
|
|
|
|
{
|
|
|
|
|
return formatted_path;
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-05-01 00:58:32 +10:00
|
|
|
{
|
2020-09-19 22:39:04 +02:00
|
|
|
return StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", m_program_directory.c_str(),
|
2020-06-09 02:05:55 +10:00
|
|
|
formatted_path.c_str());
|
2020-05-01 00:58:32 +10:00
|
|
|
}
|
2020-01-24 14:51:52 +10:00
|
|
|
}
|
|
|
|
|
|
2021-03-27 15:18:23 +10:00
|
|
|
std::string HostInterface::GetMemoryCardDirectory() const
|
|
|
|
|
{
|
|
|
|
|
if (g_settings.memory_card_directory.empty())
|
|
|
|
|
return GetUserDirectoryRelativePath("memcards");
|
|
|
|
|
else
|
|
|
|
|
return g_settings.memory_card_directory;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-09 02:05:55 +10:00
|
|
|
std::string HostInterface::GetSharedMemoryCardPath(u32 slot) const
|
|
|
|
|
{
|
2021-03-27 15:18:23 +10:00
|
|
|
if (g_settings.memory_card_directory.empty())
|
|
|
|
|
{
|
|
|
|
|
return GetUserDirectoryRelativePath("memcards" FS_OSPATH_SEPARATOR_STR "shared_card_%u.mcd", slot + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "shared_card_%u.mcd",
|
|
|
|
|
g_settings.memory_card_directory.c_str(), slot + 1);
|
|
|
|
|
}
|
2020-06-09 02:05:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string HostInterface::GetGameMemoryCardPath(const char* game_code, u32 slot) const
|
|
|
|
|
{
|
2021-03-27 15:18:23 +10:00
|
|
|
if (g_settings.memory_card_directory.empty())
|
|
|
|
|
{
|
|
|
|
|
return GetUserDirectoryRelativePath("memcards" FS_OSPATH_SEPARATOR_STR "%s_%u.mcd", game_code, slot + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s_%u.mcd",
|
|
|
|
|
g_settings.memory_card_directory.c_str(), game_code, slot + 1);
|
|
|
|
|
}
|
2020-06-09 02:05:55 +10:00
|
|
|
}
|
|
|
|
|
|
2020-07-21 19:49:04 +10:00
|
|
|
bool HostInterface::GetBoolSettingValue(const char* section, const char* key, bool default_value /*= false*/)
|
2020-07-01 00:33:45 +10:00
|
|
|
{
|
2020-07-21 19:49:04 +10:00
|
|
|
std::string value = GetStringSettingValue(section, key, "");
|
2020-07-01 00:33:45 +10:00
|
|
|
if (value.empty())
|
|
|
|
|
return default_value;
|
|
|
|
|
|
|
|
|
|
std::optional<bool> bool_value = StringUtil::FromChars<bool>(value);
|
|
|
|
|
return bool_value.value_or(default_value);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-21 19:49:04 +10:00
|
|
|
int HostInterface::GetIntSettingValue(const char* section, const char* key, int default_value /*= 0*/)
|
2020-07-01 00:33:45 +10:00
|
|
|
{
|
2020-07-21 19:49:04 +10:00
|
|
|
std::string value = GetStringSettingValue(section, key, "");
|
2020-07-01 00:33:45 +10:00
|
|
|
if (value.empty())
|
|
|
|
|
return default_value;
|
|
|
|
|
|
2020-07-21 19:49:04 +10:00
|
|
|
std::optional<int> int_value = StringUtil::FromChars<int>(value);
|
2020-07-01 00:33:45 +10:00
|
|
|
return int_value.value_or(default_value);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 00:35:13 +10:00
|
|
|
float HostInterface::GetFloatSettingValue(const char* section, const char* key, float default_value /*= 0.0f*/)
|
2020-07-01 00:33:45 +10:00
|
|
|
{
|
2020-07-21 19:49:04 +10:00
|
|
|
std::string value = GetStringSettingValue(section, key, "");
|
2020-07-01 00:33:45 +10:00
|
|
|
if (value.empty())
|
|
|
|
|
return default_value;
|
|
|
|
|
|
|
|
|
|
std::optional<float> float_value = StringUtil::FromChars<float>(value);
|
|
|
|
|
return float_value.value_or(default_value);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 20:03:25 +01:00
|
|
|
TinyString HostInterface::TranslateString(const char* context, const char* str,
|
|
|
|
|
const char* disambiguation /*= nullptr*/, int n /*= -1*/) const
|
2020-08-22 13:01:52 +10:00
|
|
|
{
|
2021-03-12 20:03:25 +01:00
|
|
|
TinyString result(str);
|
|
|
|
|
if (n >= 0)
|
|
|
|
|
{
|
|
|
|
|
const std::string number = std::to_string(n);
|
|
|
|
|
result.Replace("%n", number.c_str());
|
|
|
|
|
result.Replace("%Ln", number.c_str());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
2020-08-22 13:01:52 +10:00
|
|
|
}
|
|
|
|
|
|
2021-03-12 20:03:25 +01:00
|
|
|
std::string HostInterface::TranslateStdString(const char* context, const char* str,
|
|
|
|
|
const char* disambiguation /*= nullptr*/, int n /*= -1*/) const
|
2020-08-22 13:01:52 +10:00
|
|
|
{
|
2021-03-12 20:03:25 +01:00
|
|
|
std::string result(str);
|
|
|
|
|
if (n >= 0)
|
|
|
|
|
{
|
|
|
|
|
const std::string number = std::to_string(n);
|
|
|
|
|
// Made to mimick Qt's behaviour
|
|
|
|
|
// https://github.com/qt/qtbase/blob/255459250d450286a8c5c492dab3f6d3652171c9/src/corelib/kernel/qcoreapplication.cpp#L2099
|
|
|
|
|
size_t percent_pos = 0;
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
while ((percent_pos = result.find('%', percent_pos + len)) != std::string::npos)
|
|
|
|
|
{
|
|
|
|
|
len = 1;
|
|
|
|
|
if (percent_pos + len == result.length())
|
|
|
|
|
break;
|
|
|
|
|
if (result[percent_pos + len] == 'L')
|
|
|
|
|
{
|
|
|
|
|
++len;
|
|
|
|
|
if (percent_pos + len == result.length())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (result[percent_pos + len] == 'n')
|
|
|
|
|
{
|
|
|
|
|
++len;
|
|
|
|
|
result.replace(percent_pos, len, number);
|
|
|
|
|
len = number.length();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2020-08-22 13:01:52 +10:00
|
|
|
}
|
|
|
|
|
|
2020-01-24 14:51:53 +10:00
|
|
|
void HostInterface::ToggleSoftwareRendering()
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
if (System::IsShutdown() || g_settings.gpu_renderer == GPURenderer::Software)
|
2020-01-24 14:51:53 +10:00
|
|
|
return;
|
|
|
|
|
|
2020-08-02 00:25:07 +10:00
|
|
|
const GPURenderer new_renderer = g_gpu->IsHardwareRenderer() ? GPURenderer::Software : g_settings.gpu_renderer;
|
2020-01-24 14:51:53 +10:00
|
|
|
|
2020-10-22 02:07:48 -07:00
|
|
|
AddFormattedOSDMessage(5.0f, TranslateString("OSDMessage", "Switching to %s renderer..."),
|
|
|
|
|
Settings::GetRendererDisplayName(new_renderer));
|
2020-07-31 17:09:18 +10:00
|
|
|
System::RecreateGPU(new_renderer);
|
2020-01-24 14:51:53 +10:00
|
|
|
}
|
|
|
|
|
|
2020-07-01 00:35:13 +10:00
|
|
|
void HostInterface::UpdateSoftwareCursor()
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
if (System::IsShutdown())
|
2020-07-01 00:35:13 +10:00
|
|
|
{
|
2020-12-27 14:08:13 +10:00
|
|
|
SetMouseMode(false, false);
|
2020-07-01 00:35:13 +10:00
|
|
|
m_display->ClearSoftwareCursor();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Common::RGBA8Image* image = nullptr;
|
|
|
|
|
float image_scale = 1.0f;
|
2020-12-27 14:08:13 +10:00
|
|
|
bool relative_mode = false;
|
|
|
|
|
bool hide_cursor = false;
|
2020-07-01 00:35:13 +10:00
|
|
|
|
|
|
|
|
for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++)
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
Controller* controller = System::GetController(i);
|
2020-12-27 14:08:13 +10:00
|
|
|
if (controller && controller->GetSoftwareCursor(&image, &image_scale, &relative_mode))
|
|
|
|
|
{
|
|
|
|
|
hide_cursor = true;
|
2020-07-01 00:35:13 +10:00
|
|
|
break;
|
2020-12-27 14:08:13 +10:00
|
|
|
}
|
2020-07-01 00:35:13 +10:00
|
|
|
}
|
|
|
|
|
|
2020-12-27 14:08:13 +10:00
|
|
|
SetMouseMode(relative_mode, hide_cursor);
|
|
|
|
|
|
2020-07-01 00:35:13 +10:00
|
|
|
if (image && image->IsValid())
|
|
|
|
|
{
|
|
|
|
|
m_display->SetSoftwareCursor(image->GetPixels(), image->GetWidth(), image->GetHeight(), image->GetByteStride(),
|
|
|
|
|
image_scale);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_display->ClearSoftwareCursor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 00:14:28 +09:00
|
|
|
void HostInterface::RecreateSystem()
|
|
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
Assert(!System::IsShutdown());
|
|
|
|
|
|
2020-02-16 00:14:28 +09:00
|
|
|
std::unique_ptr<ByteStream> stream = ByteStream_CreateGrowableMemoryStream(nullptr, 8 * 1024);
|
2021-07-22 13:42:19 +10:00
|
|
|
if (!System::SaveState(stream.get(), 0) || !stream->SeekAbsolute(0))
|
2020-02-16 00:14:28 +09:00
|
|
|
{
|
|
|
|
|
ReportError("Failed to save state before system recreation. Shutting down.");
|
|
|
|
|
DestroySystem();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DestroySystem();
|
2020-03-02 11:08:16 +10:00
|
|
|
|
2021-06-08 18:38:12 +02:00
|
|
|
auto boot_params = std::make_shared<SystemBootParameters>();
|
|
|
|
|
boot_params->state_stream = std::move(stream);
|
|
|
|
|
if (!BootSystem(std::move(boot_params)))
|
2020-02-16 00:14:28 +09:00
|
|
|
{
|
|
|
|
|
ReportError("Failed to boot system after recreation.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-02-16 00:14:37 +09:00
|
|
|
}
|