From 48470a20cac0a981b2ddb92483141047437d6211 Mon Sep 17 00:00:00 2001 From: Rachel Bryk Date: Wed, 8 Jan 2014 20:34:14 -0500 Subject: [PATCH] Code cleanup Move enums for max SI and EXI devices to their respective .h file, and rename them. Use only those enums in BootManager.cpp. Same thing in Movie.cpp Change one instance of MAX_BBMOTES to MAX_WIIMOTES in Movie.cpp, since movies do not support balance board. --- Source/Core/Core/BootManager.cpp | 42 ++++++++++++++++++-------------- Source/Core/Core/HW/EXI.cpp | 17 +++++-------- Source/Core/Core/HW/EXI.h | 5 ++++ Source/Core/Core/HW/SI.cpp | 16 ++++-------- Source/Core/Core/HW/SI.h | 6 +++++ Source/Core/Core/Movie.cpp | 10 ++++---- 6 files changed, 51 insertions(+), 45 deletions(-) diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 11f9f67780..e12eb4349b 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -37,6 +37,8 @@ #include "Movie.h" #include "NetPlayProto.h" #include "HW/WiimoteReal/WiimoteReal.h" +#include "HW/SI.h" +#include "HW/EXI.h" namespace BootManager { @@ -48,12 +50,12 @@ struct ConfigCache bool valid, bCPUThread, bSkipIdle, bEnableFPRF, bMMU, bDCBZOFF, m_EnableJIT, bDSPThread, bVBeamSpeedHack, bSyncGPU, bFastDiscSpeed, bMergeBlocks, bDSPHLE, bHLE_BS2, bTLBHack, bUseFPS; int iCPUCore, Volume; - int iWiimoteSource[5]; - SIDevices Pads[4]; + int iWiimoteSource[MAX_BBMOTES]; + SIDevices Pads[MAX_SI_CHANNELS]; unsigned int framelimit; - TEXIDevices m_EXIDevice[2]; + TEXIDevices m_EXIDevice[MAX_EXI_CHANNELS]; std::string strBackend, sBackend; - bool bSetFramelimit, bSetEXIDevice[2], bSetUseFPS, bSetVolume, bSetPads[4], bSetWiimoteSource[5]; + bool bSetFramelimit, bSetEXIDevice[MAX_EXI_CHANNELS], bSetUseFPS, bSetVolume, bSetPads[MAX_SI_CHANNELS], bSetWiimoteSource[MAX_BBMOTES]; }; static ConfigCache config_cache; @@ -109,8 +111,6 @@ bool BootCore(const std::string& _rFilename) config_cache.bHLE_BS2 = StartUp.bHLE_BS2; config_cache.m_EnableJIT = SConfig::GetInstance().m_EnableJIT; config_cache.bDSPThread = StartUp.bDSPThread; - config_cache.m_EXIDevice[0] = SConfig::GetInstance().m_EXIDevice[0]; - config_cache.m_EXIDevice[1] = SConfig::GetInstance().m_EXIDevice[1]; config_cache.Volume = SConfig::GetInstance().m_Volume; config_cache.sBackend = SConfig::GetInstance().sBackend; config_cache.framelimit = SConfig::GetInstance().m_Framelimit; @@ -119,14 +119,17 @@ bool BootCore(const std::string& _rFilename) { config_cache.iWiimoteSource[i] = g_wiimote_sources[i]; } - for (unsigned int i = 0; i < 4; ++i) + for (unsigned int i = 0; i < MAX_SI_CHANNELS; ++i) { config_cache.Pads[i] = SConfig::GetInstance().m_SIDevice[i]; } - std::fill_n(config_cache.bSetWiimoteSource, 5, false); - std::fill_n(config_cache.bSetPads, 4, false); - config_cache.bSetEXIDevice[0] = false; - config_cache.bSetEXIDevice[1] = false; + for (unsigned int i = 0; i < MAX_EXI_CHANNELS; ++i) + { + config_cache.m_EXIDevice[i] = SConfig::GetInstance().m_EXIDevice[i]; + } + std::fill_n(config_cache.bSetWiimoteSource, (int)MAX_BBMOTES, false); + std::fill_n(config_cache.bSetPads, (int)MAX_SI_CHANNELS, false); + std::fill_n(config_cache.bSetEXIDevice, (int)MAX_EXI_CHANNELS, false); config_cache.bSetFramelimit = false; // General settings @@ -155,7 +158,7 @@ bool BootCore(const std::string& _rFilename) game_ini.Get("DSP", "Backend", &SConfig::GetInstance().sBackend, SConfig::GetInstance().sBackend.c_str()); VideoBackend::ActivateBackend(StartUp.m_strVideoBackend); - for (unsigned int i = 0; i < 4; ++i) + for (unsigned int i = 0; i < MAX_SI_CHANNELS; ++i) { int source; game_ini.Get("Controls", StringFromFormat("PadType%u", i).c_str(), &source, -1); @@ -188,7 +191,7 @@ bool BootCore(const std::string& _rFilename) { config_cache.bSetWiimoteSource[WIIMOTE_BALANCE_BOARD] = true; g_wiimote_sources[WIIMOTE_BALANCE_BOARD] = source; - WiimoteReal::ChangeWiimoteSource(4, source); + WiimoteReal::ChangeWiimoteSource(WIIMOTE_BALANCE_BOARD, source); } } } @@ -268,14 +271,10 @@ void Stop() SConfig::GetInstance().m_Framelimit = config_cache.framelimit; if (config_cache.bSetUseFPS) SConfig::GetInstance().b_UseFPS = config_cache.bUseFPS; - if (config_cache.bSetEXIDevice[0]) - SConfig::GetInstance().m_EXIDevice[0] = config_cache.m_EXIDevice[0]; - if (config_cache.bSetEXIDevice[1]) - SConfig::GetInstance().m_EXIDevice[1] = config_cache.m_EXIDevice[1]; if (config_cache.bSetVolume) SConfig::GetInstance().m_Volume = config_cache.Volume; - for (unsigned int i = 0; i < 4; ++i) + for (unsigned int i = 0; i < MAX_SI_CHANNELS; ++i) { if (config_cache.bSetPads[i]) { @@ -283,6 +282,13 @@ void Stop() } } + for (unsigned int i = 0; i < MAX_EXI_CHANNELS; ++i) + { + if (config_cache.bSetEXIDevice[i]) + { + SConfig::GetInstance().m_EXIDevice[i] = config_cache.m_EXIDevice[i]; + } + } if (StartUp.bWii) { for (unsigned int i = 0; i < MAX_BBMOTES; ++i) diff --git a/Source/Core/Core/HW/EXI.cpp b/Source/Core/Core/HW/EXI.cpp index 30b7728fe9..4e9c9057ef 100644 --- a/Source/Core/Core/HW/EXI.cpp +++ b/Source/Core/Core/HW/EXI.cpp @@ -20,16 +20,11 @@ namespace ExpansionInterface static int changeDevice; -enum -{ - NUM_CHANNELS = 3 -}; - -CEXIChannel *g_Channels[NUM_CHANNELS]; +CEXIChannel *g_Channels[MAX_EXI_CHANNELS]; void Init() { initSRAM(); - for (u32 i = 0; i < NUM_CHANNELS; i++) + for (u32 i = 0; i < MAX_EXI_CHANNELS; i++) g_Channels[i] = new CEXIChannel(i); if (Movie::IsPlayingInput() && Movie::IsUsingMemcard() && Movie::IsConfigSaved()) @@ -111,9 +106,9 @@ void Read32(u32& _uReturnValue, const u32 _iAddress) u32 iRegister = (iAddr >> 2) % 5; u32 iChannel = (iAddr >> 2) / 5; - _dbg_assert_(EXPANSIONINTERFACE, iChannel < NUM_CHANNELS); + _dbg_assert_(EXPANSIONINTERFACE, iChannel < MAX_EXI_CHANNELS); - if (iChannel < NUM_CHANNELS) + if (iChannel < MAX_EXI_CHANNELS) { g_Channels[iChannel]->Read32(_uReturnValue, iRegister); } @@ -130,9 +125,9 @@ void Write32(const u32 _iValue, const u32 _iAddress) u32 iRegister = (iAddr >> 2) % 5; u32 iChannel = (iAddr >> 2) / 5; - _dbg_assert_(EXPANSIONINTERFACE, iChannel < NUM_CHANNELS); + _dbg_assert_(EXPANSIONINTERFACE, iChannel < MAX_EXI_CHANNELS); - if (iChannel < NUM_CHANNELS) + if (iChannel < MAX_EXI_CHANNELS) g_Channels[iChannel]->Write32(_iValue, iRegister); } diff --git a/Source/Core/Core/HW/EXI.h b/Source/Core/Core/HW/EXI.h index 5043526d24..f93af36f43 100644 --- a/Source/Core/Core/HW/EXI.h +++ b/Source/Core/Core/HW/EXI.h @@ -10,6 +10,11 @@ #include "Thread.h" class PointerWrap; +enum +{ + MAX_EXI_CHANNELS = 3 +}; + namespace ExpansionInterface { diff --git a/Source/Core/Core/HW/SI.cpp b/Source/Core/Core/HW/SI.cpp index 7f46b9a101..39e9e216a7 100644 --- a/Source/Core/Core/HW/SI.cpp +++ b/Source/Core/Core/HW/SI.cpp @@ -32,12 +32,6 @@ enum SIInterruptType }; static void GenerateSIInterrupt(SIInterruptType _SIInterrupt); -// SI number of channels -enum -{ - NUMBER_OF_CHANNELS = 0x04 -}; - // SI Internal Hardware Addresses enum { @@ -208,7 +202,7 @@ union USIEXIClockCount }; // STATE_TO_SAVE -static SSIChannel g_Channel[NUMBER_OF_CHANNELS]; +static SSIChannel g_Channel[MAX_SI_CHANNELS]; static USIPoll g_Poll; static USIComCSR g_ComCSR; static USIStatusReg g_StatusReg; @@ -217,7 +211,7 @@ static u8 g_SIBuffer[128]; void DoState(PointerWrap &p) { - for(int i = 0; i < NUMBER_OF_CHANNELS; i++) + for(int i = 0; i < MAX_SI_CHANNELS; i++) { p.Do(g_Channel[i].m_InHi.Hex); p.Do(g_Channel[i].m_InLo.Hex); @@ -254,7 +248,7 @@ void DoState(PointerWrap &p) void Init() { - for (int i = 0; i < NUMBER_OF_CHANNELS; i++) + for (int i = 0; i < MAX_SI_CHANNELS; i++) { g_Channel[i].m_Out.Hex = 0; g_Channel[i].m_InHi.Hex = 0; @@ -282,7 +276,7 @@ void Init() void Shutdown() { - for (int i = 0; i < NUMBER_OF_CHANNELS; i++) + for (int i = 0; i < MAX_SI_CHANNELS; i++) RemoveDevice(i); GBAConnectionWaiter_Shutdown(); } @@ -554,7 +548,7 @@ void AddDevice(ISIDevice* pDevice) { int _iDeviceNumber = pDevice->GetDeviceNumber(); - //_dbg_assert_(SERIALINTERFACE, _iDeviceNumber < NUMBER_OF_CHANNELS); + //_dbg_assert_(SERIALINTERFACE, _iDeviceNumber < MAX_SI_CHANNELS); // delete the old device RemoveDevice(_iDeviceNumber); diff --git a/Source/Core/Core/HW/SI.h b/Source/Core/Core/HW/SI.h index c5c8b0dbca..792f63063e 100644 --- a/Source/Core/Core/HW/SI.h +++ b/Source/Core/Core/HW/SI.h @@ -10,6 +10,12 @@ class PointerWrap; class ISIDevice; +// SI number of channels +enum +{ + MAX_SI_CHANNELS = 0x04 +}; + namespace SerialInterface { diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 2189218ab7..b02b74be90 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -372,14 +372,14 @@ void ChangePads(bool instantly) int controllers = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < MAX_SI_CHANNELS; i++) if (SConfig::GetInstance().m_SIDevice[i] == SIDEVICE_GC_CONTROLLER || SConfig::GetInstance().m_SIDevice[i] == SIDEVICE_GC_TARUKONGA) controllers |= (1 << i); if (instantly && (g_numPads & 0x0F) == controllers) return; - for (int i = 0; i < 4; i++) + for (int i = 0; i < MAX_SI_CHANNELS; i++) if (instantly) // Changes from savestates need to be instantaneous SerialInterface::AddDevice(IsUsingPad(i) ? (IsUsingBongo(i) ? SIDEVICE_GC_TARUKONGA : SIDEVICE_GC_CONTROLLER) : SIDEVICE_NONE, i); else @@ -390,7 +390,7 @@ void ChangeWiiPads(bool instantly) { int controllers = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < MAX_WIIMOTES; i++) if (g_wiimote_sources[i] != WIIMOTE_SRC_NONE) controllers |= (1 << i); @@ -398,7 +398,7 @@ void ChangeWiiPads(bool instantly) if (instantly && (g_numPads >> 4) == controllers) return; - for (int i = 0; i < MAX_BBMOTES; i++) + for (int i = 0; i < MAX_WIIMOTES; i++) { g_wiimote_sources[i] = IsUsingWiimote(i) ? WIIMOTE_SRC_EMU : WIIMOTE_SRC_NONE; GetUsbPointer()->AccessWiiMote(i | 0x100)->Activate(IsUsingWiimote(i)); @@ -424,7 +424,7 @@ bool BeginRecordingInput(int controllers) g_rerecords = 0; - for (int i = 0; i < 4; i++) + for (int i = 0; i < MAX_SI_CHANNELS; i++) if (SConfig::GetInstance().m_SIDevice[i] == SIDEVICE_GC_TARUKONGA) bongos |= (1 << i);