Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RachelBryk committed Jan 9, 2014
1 parent 3046d0e commit 48470a2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 45 deletions.
42 changes: 24 additions & 18 deletions Source/Core/Core/BootManager.cpp
Expand Up @@ -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
{
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -268,21 +271,24 @@ 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])
{
SConfig::GetInstance().m_SIDevice[i] = config_cache.Pads[i];
}

}
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)
Expand Down
17 changes: 6 additions & 11 deletions Source/Core/Core/HW/EXI.cpp
Expand Up @@ -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())
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/HW/EXI.h
Expand Up @@ -10,6 +10,11 @@
#include "Thread.h"
class PointerWrap;

enum
{
MAX_EXI_CHANNELS = 3
};

namespace ExpansionInterface
{

Expand Down
16 changes: 5 additions & 11 deletions Source/Core/Core/HW/SI.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/HW/SI.h
Expand Up @@ -10,6 +10,12 @@
class PointerWrap;
class ISIDevice;

// SI number of channels
enum
{
MAX_SI_CHANNELS = 0x04
};

namespace SerialInterface
{

Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Core/Movie.cpp
Expand Up @@ -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
Expand All @@ -390,15 +390,15 @@ 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);

// This is important for Wiimotes, because they can desync easily if they get re-activated
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));
Expand All @@ -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);

Expand Down

0 comments on commit 48470a2

Please sign in to comment.