Skip to content

Commit

Permalink
Merge pull request #107 from lioncash/tiny-cleanup
Browse files Browse the repository at this point in the history
Tiny cleanup of WII_IPC_HLE.cpp.
  • Loading branch information
neobrain committed Feb 26, 2014
2 parents 6959a93 + 4094c35 commit 66d1f16
Showing 1 changed file with 34 additions and 47 deletions.
81 changes: 34 additions & 47 deletions Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp
Expand Up @@ -90,7 +90,6 @@ void EnqueReplyCallback(u64 userdata, int)

void Init()
{

_dbg_assert_msg_(WII_IPC_HLE, g_DeviceMap.empty(), "DeviceMap isn't empty on init");
CWII_IPC_HLE_Device_es::m_ContentFile = "";
u32 i;
Expand All @@ -107,8 +106,7 @@ void Init()
g_DeviceMap[i] = new CWII_IPC_HLE_Device_fs(i, std::string("/dev/fs")); i++;

// IOS allows two ES devices at a time<
u32 j;
for (j=0; j<ES_MAX_COUNT; j++)
for (u32 j=0; j<ES_MAX_COUNT; j++)
{
g_DeviceMap[i] = es_handles[j] = new CWII_IPC_HLE_Device_es(i, std::string("/dev/es")); i++;
es_inuse[j] = false;
Expand All @@ -124,10 +122,10 @@ void Init()
g_DeviceMap[i] = new CWII_IPC_HLE_Device_usb_kbd(i, std::string("/dev/usb/kbd")); i++;
g_DeviceMap[i] = new CWII_IPC_HLE_Device_sdio_slot0(i, std::string("/dev/sdio/slot0")); i++;
g_DeviceMap[i] = new CWII_IPC_HLE_Device_stub(i, std::string("/dev/sdio/slot1")); i++;
#if defined(__LIBUSB__) || defined(_WIN32)
#if defined(__LIBUSB__) || defined(_WIN32)
g_DeviceMap[i] = new CWII_IPC_HLE_Device_hid(i, std::string("/dev/usb/hid")); i++;
#else
g_DeviceMap[i] = new CWII_IPC_HLE_Device_stub(i, std::string("/dev/usb/hid")); i++;
g_DeviceMap[i] = new CWII_IPC_HLE_Device_stub(i, std::string("/dev/usb/hid")); i++;
#endif
g_DeviceMap[i] = new CWII_IPC_HLE_Device_stub(i, std::string("/dev/usb/oh1")); i++;
g_DeviceMap[i] = new IWII_IPC_HLE_Device(i, std::string("_Unimplemented_Device_")); i++;
Expand All @@ -139,37 +137,36 @@ void Reset(bool _bHard)
{
CoreTiming::RemoveAllEvents(enque_reply);

u32 i;
for (i=0; i<IPC_MAX_FDS; i++)
for (u32 i=0; i<IPC_MAX_FDS; i++)
{
if (g_FdMap[i] != NULL && !g_FdMap[i]->IsHardware())
{
// close all files and delete their resources
g_FdMap[i]->Close(0, true);
delete g_FdMap[i];
}

g_FdMap[i] = NULL;
}

u32 j;
for (j=0; j<ES_MAX_COUNT; j++)
for (u32 j=0; j<ES_MAX_COUNT; j++)
{
es_inuse[j] = false;
}

TDeviceMap::iterator itr = g_DeviceMap.begin();
while (itr != g_DeviceMap.end())
for (const auto& entry : g_DeviceMap)
{
if (itr->second)
if (entry.second)
{
// Force close
itr->second->Close(0, true);
entry.second->Close(0, true);

// Hardware should not be deleted unless it is a hard reset
if (_bHard)
delete itr->second;
delete entry.second;
}
++itr;
}

if (_bHard)
{
g_DeviceMap.erase(g_DeviceMap.begin(), g_DeviceMap.end());
Expand All @@ -191,14 +188,12 @@ void Shutdown()

void SetDefaultContentFile(const std::string& _rFilename)
{
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
while (itr != g_DeviceMap.end())
for (const auto& entry : g_DeviceMap)
{
if (itr->second && itr->second->GetDeviceName().find(std::string("/dev/es")) == 0)
if (entry.second && entry.second->GetDeviceName().find(std::string("/dev/es")) == 0)
{
((CWII_IPC_HLE_Device_es*)itr->second)->LoadWAD(_rFilename);
((CWII_IPC_HLE_Device_es*)entry.second)->LoadWAD(_rFilename);
}
++itr;
}
}

Expand All @@ -214,27 +209,26 @@ void SDIO_EventNotify()
if (pDevice)
pDevice->EventNotify();
}

int getFreeDeviceId()
{
u32 i;
for (i=0; i<IPC_MAX_FDS; i++)
for (u32 i=0; i<IPC_MAX_FDS; i++)
{
if (g_FdMap[i] == NULL)
{
return i;
}
}

return -1;
}

IWII_IPC_HLE_Device* GetDeviceByName(const std::string& _rDeviceName)
{
TDeviceMap::const_iterator itr = g_DeviceMap.begin();
while (itr != g_DeviceMap.end())
for (const auto& entry : g_DeviceMap)
{
if (itr->second && itr->second->GetDeviceName() == _rDeviceName)
return itr->second;
++itr;
if (entry.second && entry.second->GetDeviceName() == _rDeviceName)
return entry.second;
}

return NULL;
Expand Down Expand Up @@ -269,22 +263,17 @@ void DoState(PointerWrap &p)
p.Do(reply_queue);
p.Do(last_reply_time);

TDeviceMap::const_iterator itr;

itr = g_DeviceMap.begin();
while (itr != g_DeviceMap.end())
for (const auto& entry : g_DeviceMap)
{
if (itr->second->IsHardware())
{
itr->second->DoState(p);
}
++itr;
if (entry.second->IsHardware())
{
entry.second->DoState(p);
}
}

if (p.GetMode() == PointerWrap::MODE_READ)
{
u32 i;
for (i=0; i<IPC_MAX_FDS; i++)
for (u32 i=0; i<IPC_MAX_FDS; i++)
{
u32 exists = 0;
p.Do(exists);
Expand All @@ -309,7 +298,8 @@ void DoState(PointerWrap &p)
g_FdMap[i] = NULL;
}
}
for (i=0; i<ES_MAX_COUNT; i++)

for (u32 i=0; i<ES_MAX_COUNT; i++)
{
p.Do(es_inuse[i]);
u32 handleID = es_handles[i]->GetDeviceID();
Expand All @@ -320,8 +310,7 @@ void DoState(PointerWrap &p)
}
else
{
u32 i;
for (i=0; i<IPC_MAX_FDS; i++)
for (u32 i=0; i<IPC_MAX_FDS; i++)
{
u32 exists = g_FdMap[i] ? 1 : 0;
p.Do(exists);
Expand All @@ -340,7 +329,8 @@ void DoState(PointerWrap &p)
}
}
}
for (i=0; i<ES_MAX_COUNT; i++)

for (u32 i=0; i<ES_MAX_COUNT; i++)
{
p.Do(es_inuse[i]);
u32 handleID = es_handles[i]->GetDeviceID();
Expand Down Expand Up @@ -370,7 +360,6 @@ void ExecuteCommand(u32 _Address)
std::string DeviceName;
Memory::GetString(DeviceName, Memory::Read_U32(_Address + 0xC));


WARN_LOG(WII_IPC_HLE, "Trying to open %s as %d", DeviceName.c_str(), DeviceID);
if (DeviceID >= 0)
{
Expand All @@ -388,12 +377,12 @@ void ExecuteCommand(u32 _Address)
break;
}
}

if (j == ES_MAX_COUNT)
{
Memory::Write_U32(FS_EESEXHAUSTED, _Address + 4);
CmdSuccess = true;
}

}
else if (DeviceName.find("/dev/") == 0)
{
Expand Down Expand Up @@ -430,7 +419,6 @@ void ExecuteCommand(u32 _Address)
pDevice = NULL;
}
}

}
else
{
Expand All @@ -445,8 +433,7 @@ void ExecuteCommand(u32 _Address)
{
CmdSuccess = pDevice->Close(_Address);

u32 j;
for (j=0; j<ES_MAX_COUNT; j++)
for (u32 j=0; j<ES_MAX_COUNT; j++)
{
if (es_handles[j] == g_FdMap[DeviceID])
{
Expand Down

0 comments on commit 66d1f16

Please sign in to comment.