From 0098c60ee81f914a32e79fc92c9669d241d873d2 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 1 Jul 2025 19:00:15 +1000 Subject: [PATCH] SIO: Add debugging option to redirect to TTY Until I bother to finish my sio branch... --- src/core/bus.cpp | 2 +- src/core/settings.cpp | 2 ++ src/core/settings.h | 1 + src/core/sio.cpp | 9 +++++++-- src/duckstation-qt/advancedsettingswidget.cpp | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/bus.cpp b/src/core/bus.cpp index 8224312d4..873d2bd4d 100644 --- a/src/core/bus.cpp +++ b/src/core/bus.cpp @@ -953,7 +953,7 @@ void Bus::AddTTYCharacter(char ch) } s_tty_line_buffer.clear(); } - else + else if (ch != '\0') { s_tty_line_buffer += ch; } diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 4200dcf14..529a5851c 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -510,6 +510,7 @@ void Settings::Load(const SettingsInterface& si, const SettingsInterface& contro pio_flash_image_path = si.GetStringValue("PIO", "FlashImagePath"); pio_flash_write_enable = si.GetBoolValue("PIO", "FlashImageWriteEnable", false); pio_switch_active = si.GetBoolValue("PIO", "SwitchActive", true); + sio_redirect_to_tty = si.GetBoolValue("SIO", "RedirectToTTY", false); pcdrv_enable = si.GetBoolValue("PCDrv", "Enabled", false); pcdrv_enable_writes = si.GetBoolValue("PCDrv", "EnableWrites", false); @@ -797,6 +798,7 @@ void Settings::Save(SettingsInterface& si, bool ignore_base) const si.SetStringValue("PIO", "FlashImagePath", pio_flash_image_path.c_str()); si.SetBoolValue("PIO", "FlashImageWriteEnable", pio_flash_write_enable); si.SetBoolValue("PIO", "SwitchActive", pio_switch_active); + si.SetBoolValue("SIO", "RedirectToTTY", sio_redirect_to_tty); si.SetBoolValue("PCDrv", "Enabled", pcdrv_enable); si.SetBoolValue("PCDrv", "EnableWrites", pcdrv_enable_writes); diff --git a/src/core/settings.h b/src/core/settings.h index 148ac64d2..1dc788dad 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -340,6 +340,7 @@ struct Settings : public GPUSettings bool memory_card_fast_forward_access : 1 = false; bool pio_switch_active : 1 = true; bool pio_flash_write_enable : 1 = false; + bool sio_redirect_to_tty : 1 = false; bool pcdrv_enable_writes : 1 = false; // achievements diff --git a/src/core/sio.cpp b/src/core/sio.cpp index fb1b1ad87..969f243a2 100644 --- a/src/core/sio.cpp +++ b/src/core/sio.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #include "sio.h" +#include "bus.h" #include "controller.h" #include "util/state_wrapper.h" @@ -137,7 +138,11 @@ void SIO::WriteRegister(u32 offset, u32 value) { case 0x00: // SIO_DATA { - WARNING_LOG("SIO_DATA (W) <- 0x{:02X}", value); + if (g_settings.sio_redirect_to_tty) + Bus::AddTTYCharacter(static_cast(value)); + else + WARNING_LOG("SIO_DATA (W) <- 0x{:02X}", value); + return; } diff --git a/src/duckstation-qt/advancedsettingswidget.cpp b/src/duckstation-qt/advancedsettingswidget.cpp index 20e169257..20175ee37 100644 --- a/src/duckstation-qt/advancedsettingswidget.cpp +++ b/src/duckstation-qt/advancedsettingswidget.cpp @@ -317,6 +317,7 @@ void AdvancedSettingsWidget::addTweakOptions() addBooleanTweakOption(m_dialog, m_ui.tweakOptionTable, tr("Export Shared Memory"), "Hacks", "ExportSharedMemory", false); + addBooleanTweakOption(m_dialog, m_ui.tweakOptionTable, tr("Redirect SIO to TTY"), "SIO", "RedirectToTTY", false); addBooleanTweakOption(m_dialog, m_ui.tweakOptionTable, tr("Enable PCDrv"), "PCDrv", "Enabled", false); addBooleanTweakOption(m_dialog, m_ui.tweakOptionTable, tr("Enable PCDrv Writes"), "PCDrv", "EnableWrites", false); addDirectoryOption(m_dialog, m_ui.tweakOptionTable, tr("PCDrv Root Directory"), "PCDrv", "Root"); @@ -360,6 +361,7 @@ void AdvancedSettingsWidget::onResetToDefaultClicked() setBooleanTweakOption(m_ui.tweakOptionTable, i++, false); // Enable GDB Server setIntRangeTweakOption(m_ui.tweakOptionTable, i++, Settings::DEFAULT_GDB_SERVER_PORT); // GDB Server Port setBooleanTweakOption(m_ui.tweakOptionTable, i++, false); // Export Shared Memory + setBooleanTweakOption(m_ui.tweakOptionTable, i++, false); // Redirect SIO to TTY setBooleanTweakOption(m_ui.tweakOptionTable, i++, false); // Enable PCDRV setBooleanTweakOption(m_ui.tweakOptionTable, i++, false); // Enable PCDRV Writes setDirectoryOption(m_ui.tweakOptionTable, i++, ""); // PCDrv Root Directory