From 835834f8f4c7131c52495a2797018dd58adf921b Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 11 Jan 2023 19:03:07 +1000 Subject: [PATCH] SIO: Convert to namespace --- src/core/bus.cpp | 4 +- src/core/sio.cpp | 100 ++++++++++++++++++++++++++++++++++---------- src/core/sio.h | 81 ++++------------------------------- src/core/system.cpp | 8 ++-- 4 files changed, 91 insertions(+), 102 deletions(-) diff --git a/src/core/bus.cpp b/src/core/bus.cpp index 776191e5a..0a41c2405 100644 --- a/src/core/bus.cpp +++ b/src/core/bus.cpp @@ -1125,13 +1125,13 @@ ALWAYS_INLINE static TickCount DoSIOAccess(u32 offset, u32& value) { if constexpr (type == MemoryAccessType::Read) { - value = g_sio.ReadRegister(FIXUP_HALFWORD_OFFSET(size, offset)); + value = SIO::ReadRegister(FIXUP_HALFWORD_OFFSET(size, offset)); value = FIXUP_HALFWORD_READ_VALUE(size, offset, value); return 2; } else { - g_sio.WriteRegister(FIXUP_HALFWORD_OFFSET(size, offset), FIXUP_HALFWORD_WRITE_VALUE(size, offset, value)); + SIO::WriteRegister(FIXUP_HALFWORD_OFFSET(size, offset), FIXUP_HALFWORD_WRITE_VALUE(size, offset, value)); return 0; } } diff --git a/src/core/sio.cpp b/src/core/sio.cpp index b00c71bdb..83de12c78 100644 --- a/src/core/sio.cpp +++ b/src/core/sio.cpp @@ -2,18 +2,72 @@ // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "sio.h" +#include "common/bitfield.h" +#include "common/fifo_queue.h" #include "common/log.h" #include "controller.h" #include "interrupt_controller.h" #include "memory_card.h" #include "util/state_wrapper.h" +#include +#include Log_SetChannel(SIO); -SIO g_sio; +namespace SIO { -SIO::SIO() = default; +union SIO_CTRL +{ + u16 bits; -SIO::~SIO() = default; + BitField TXEN; + BitField DTROUTPUT; + BitField RXEN; + BitField TXOUTPUT; + BitField ACK; + BitField RTSOUTPUT; + BitField RESET; + BitField RXIMODE; + BitField TXINTEN; + BitField RXINTEN; + BitField ACKINTEN; +}; + +union SIO_STAT +{ + u32 bits; + + BitField TXRDY; + BitField RXFIFONEMPTY; + BitField TXDONE; + BitField RXPARITY; + BitField RXFIFOOVERRUN; + BitField RXBADSTOPBIT; + BitField RXINPUTLEVEL; + BitField DSRINPUTLEVEL; + BitField CTSINPUTLEVEL; + BitField INTR; + BitField TMR; +}; + +union SIO_MODE +{ + u16 bits; + + BitField reload_factor; + BitField character_length; + BitField parity_enable; + BitField parity_type; + BitField stop_bit_length; +}; + +static void SoftReset(); + +static SIO_CTRL s_SIO_CTRL = {}; +static SIO_STAT s_SIO_STAT = {}; +static SIO_MODE s_SIO_MODE = {}; +static u16 s_SIO_BAUD = 0; + +} // namespace SIO void SIO::Initialize() { @@ -29,10 +83,10 @@ void SIO::Reset() bool SIO::DoState(StateWrapper& sw) { - sw.Do(&m_SIO_CTRL.bits); - sw.Do(&m_SIO_STAT.bits); - sw.Do(&m_SIO_MODE.bits); - sw.Do(&m_SIO_BAUD); + sw.Do(&s_SIO_CTRL.bits); + sw.Do(&s_SIO_STAT.bits); + sw.Do(&s_SIO_MODE.bits); + sw.Do(&s_SIO_BAUD); return !sw.HasError(); } @@ -52,18 +106,18 @@ u32 SIO::ReadRegister(u32 offset) case 0x04: // SIO_STAT { - const u32 bits = m_SIO_STAT.bits; + const u32 bits = s_SIO_STAT.bits; return bits; } case 0x08: // SIO_MODE - return ZeroExtend32(m_SIO_MODE.bits); + return ZeroExtend32(s_SIO_MODE.bits); case 0x0A: // SIO_CTRL - return ZeroExtend32(m_SIO_CTRL.bits); + return ZeroExtend32(s_SIO_CTRL.bits); case 0x0E: // SIO_BAUD - return ZeroExtend32(m_SIO_BAUD); + return ZeroExtend32(s_SIO_BAUD); default: Log_ErrorPrintf("Unknown register read: 0x%X", offset); @@ -85,8 +139,8 @@ void SIO::WriteRegister(u32 offset, u32 value) { Log_DebugPrintf("SIO_CTRL <- 0x%04X", value); - m_SIO_CTRL.bits = Truncate16(value); - if (m_SIO_CTRL.RESET) + s_SIO_CTRL.bits = Truncate16(value); + if (s_SIO_CTRL.RESET) SoftReset(); return; @@ -95,14 +149,14 @@ void SIO::WriteRegister(u32 offset, u32 value) case 0x08: // SIO_MODE { Log_DebugPrintf("SIO_MODE <- 0x%08X", value); - m_SIO_MODE.bits = Truncate16(value); + s_SIO_MODE.bits = Truncate16(value); return; } case 0x0E: { Log_DebugPrintf("SIO_BAUD <- 0x%08X", value); - m_SIO_BAUD = Truncate16(value); + s_SIO_BAUD = Truncate16(value); return; } @@ -114,12 +168,12 @@ void SIO::WriteRegister(u32 offset, u32 value) void SIO::SoftReset() { - m_SIO_CTRL.bits = 0; - m_SIO_STAT.bits = 0; - m_SIO_STAT.DSRINPUTLEVEL = true; - m_SIO_STAT.CTSINPUTLEVEL = true; - m_SIO_STAT.TXDONE = true; - m_SIO_STAT.TXRDY = true; - m_SIO_MODE.bits = 0; - m_SIO_BAUD = 0xDC; + s_SIO_CTRL.bits = 0; + s_SIO_STAT.bits = 0; + s_SIO_STAT.DSRINPUTLEVEL = true; + s_SIO_STAT.CTSINPUTLEVEL = true; + s_SIO_STAT.TXDONE = true; + s_SIO_STAT.TXRDY = true; + s_SIO_MODE.bits = 0; + s_SIO_BAUD = 0xDC; } diff --git a/src/core/sio.h b/src/core/sio.h index 283f8a8c7..142c2b519 100644 --- a/src/core/sio.h +++ b/src/core/sio.h @@ -2,83 +2,18 @@ // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once -#include "common/bitfield.h" -#include "common/fifo_queue.h" #include "types.h" -#include -#include class StateWrapper; -class Controller; -class MemoryCard; +namespace SIO { -class SIO -{ -public: - SIO(); - ~SIO(); +void Initialize(); +void Shutdown(); +void Reset(); +bool DoState(StateWrapper& sw); - void Initialize(); - void Shutdown(); - void Reset(); - bool DoState(StateWrapper& sw); +u32 ReadRegister(u32 offset); +void WriteRegister(u32 offset, u32 value); - u32 ReadRegister(u32 offset); - void WriteRegister(u32 offset, u32 value); - -private: - union SIO_CTRL - { - u16 bits; - - BitField TXEN; - BitField DTROUTPUT; - BitField RXEN; - BitField TXOUTPUT; - BitField ACK; - BitField RTSOUTPUT; - BitField RESET; - BitField RXIMODE; - BitField TXINTEN; - BitField RXINTEN; - BitField ACKINTEN; - }; - - union SIO_STAT - { - u32 bits; - - BitField TXRDY; - BitField RXFIFONEMPTY; - BitField TXDONE; - BitField RXPARITY; - BitField RXFIFOOVERRUN; - BitField RXBADSTOPBIT; - BitField RXINPUTLEVEL; - BitField DSRINPUTLEVEL; - BitField CTSINPUTLEVEL; - BitField INTR; - BitField TMR; - }; - - union SIO_MODE - { - u16 bits; - - BitField reload_factor; - BitField character_length; - BitField parity_enable; - BitField parity_type; - BitField stop_bit_length; - }; - - void SoftReset(); - - SIO_CTRL m_SIO_CTRL = {}; - SIO_STAT m_SIO_STAT = {}; - SIO_MODE m_SIO_MODE = {}; - u16 m_SIO_BAUD = 0; -}; - -extern SIO g_sio; \ No newline at end of file +} // namespace SIO diff --git a/src/core/system.cpp b/src/core/system.cpp index 69dcd0b71..ed70b9c19 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1394,7 +1394,7 @@ bool System::Initialize(bool force_software_renderer) Timers::Initialize(); SPU::Initialize(); MDEC::Initialize(); - g_sio.Initialize(); + SIO::Initialize(); static constexpr float WARNING_DURATION = 15.0f; @@ -1450,7 +1450,7 @@ void System::DestroySystem() g_texture_replacements.Shutdown(); - g_sio.Shutdown(); + SIO::Shutdown(); MDEC::Shutdown(); SPU::Shutdown(); Timers::Shutdown(); @@ -1667,7 +1667,7 @@ bool System::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di if (!sw.DoMarker("MDEC") || !MDEC::DoState(sw)) return false; - if (!sw.DoMarker("SIO") || !g_sio.DoState(sw)) + if (!sw.DoMarker("SIO") || !SIO::DoState(sw)) return false; if (!sw.DoMarker("Events") || !TimingEvents::DoState(sw)) @@ -1747,7 +1747,7 @@ void System::InternalReset() Timers::Reset(); SPU::Reset(); MDEC::Reset(); - g_sio.Reset(); + SIO::Reset(); s_frame_number = 1; s_internal_frame_number = 0; TimingEvents::Reset();