WiiFlow_Lite/source/main.cpp

147 lines
3.3 KiB
C++
Raw Normal View History

2012-01-21 21:57:41 +01:00
#include "video.hpp"
#include "menu/menu.hpp"
#include "loader/disc.h"
#include "loader/alt_ios.h"
#include "loader/sys.h"
#include "loader/wbfs.h"
#include "text.hpp"
#include <ogc/system.h>
#include <unistd.h>
#include "DeviceHandler.hpp"
#include "homebrew.h"
#include "gecko.h"
#include "wifi_gecko.h"
#include "cios.h"
2012-01-21 21:57:41 +01:00
#include "nand.hpp"
#include "defines.h"
#include "svnrev.h"
2012-01-21 21:57:41 +01:00
CMenu *mainMenu;
extern "C"
{
extern void __exception_setreload(int t);
void ShowError(const wstringEx &error) { mainMenu->error(error); }
void HideWaitMessage() { mainMenu->_hideWaitMessage(); }
}
2012-01-21 21:57:41 +01:00
int main(int argc, char **argv)
{
__exception_setreload(5);
geckoinit = InitGecko();
2012-01-21 21:57:41 +01:00
// Init video
2012-01-21 21:57:41 +01:00
CVideo vid;
vid.init();
MEM2_init(47); //Should be safe to use
vid.waitMessage(0.2f);
2012-01-21 21:57:41 +01:00
AllocSDGeckoBuffer();
gprintf(" \nWelcome to %s (%s-r%s)!\nThis is the debug output.\n", APP_NAME, APP_VERSION, SVN_REV);
2012-01-21 21:57:41 +01:00
char *gameid = NULL;
bool Emulator_boot = false;
2012-01-21 21:57:41 +01:00
for (int i = 0; i < argc; i++)
{
if (argv[i] != NULL && strcasestr(argv[i], "ios=") != NULL && strlen(argv[i]) > 4)
{
while(argv[i][0] && !isdigit(argv[i][0])) argv[i]++;
if (atoi(argv[i]) < 254 && atoi(argv[i]) > 0)
mainIOS = atoi(argv[i]);
}
else if (strlen(argv[i]) == 6)
{
gameid = argv[i];
for (int i=0; i < 5; i++)
if (!isalnum(gameid[i]))
gameid = NULL;
}
else if (argv[i] != NULL && strcasestr(argv[i], "EMULATOR_MAGIC") != NULL)
Emulator_boot = true;
2012-01-21 21:57:41 +01:00
}
#ifndef DOLPHIN
2012-01-21 21:57:41 +01:00
// Load Custom IOS
gprintf("Loading cIOS: %d\n", mainIOS);
2012-01-21 21:57:41 +01:00
bool iosOK = loadIOS(mainIOS, false);
2012-01-21 21:57:41 +01:00
u8 mainIOSBase = 0;
D2X(mainIOS, &mainIOSBase);
if(!mainIOSBase)
mainIOSBase = get_ios_base();
iosOK = iosOK && mainIOSBase > 0;
gprintf("Loaded cIOS: %u has base %u\n", mainIOS, mainIOSBase);
#else
bool iosOK = true;
#endif
2012-01-21 21:57:41 +01:00
// Init
Sys_Init();
Sys_ExitTo(EXIT_TO_HBC);
int ret = 1;
while(ret == 1)
2012-01-21 21:57:41 +01:00
{
Open_Inputs(); //(re)init wiimote
#ifndef DOLPHIN
const DISC_INTERFACE *handle = DeviceHandler::GetUSB0Interface();
bool deviceAvailable = false;
2012-01-21 21:57:41 +01:00
u8 timeout = 0;
DeviceHandler::Instance()->MountSD();
2012-01-21 21:57:41 +01:00
while(!deviceAvailable && timeout++ != 20)
{
deviceAvailable = (handle->startup() && handle->isInserted());
if(deviceAvailable)
break;
usleep(50000);
}
DeviceHandler::Instance()->MountAllUSB();
if(DeviceHandler::Instance()->IsInserted(SD))
deviceAvailable = true;
#else
bool deviceAvailable = true;
DeviceHandler::Instance()->MountAll();
sleep(1);
#endif
2012-01-21 21:57:41 +01:00
bool dipOK = Disc_Init() >= 0;
mainMenu = new CMenu(vid);
mainMenu->init();
if(!iosOK)
2012-01-21 21:57:41 +01:00
{
mainMenu->terror("errboot1", L"No cIOS found!\ncIOS d2x 249 base 56 and 250 base 57 are enough for all your games.");
break;
}
else if(!deviceAvailable)
{
mainMenu->terror("errboot2", L"Could not find a device to save configuration files on!");
2012-01-21 21:57:41 +01:00
break;
}
else if(!dipOK)
2012-01-21 21:57:41 +01:00
{
mainMenu->terror("errboot3", L"Could not initialize the DIP module!");
2012-01-21 21:57:41 +01:00
break;
}
else if(gameid != NULL && strlen(gameid) == 6)
mainMenu->directlaunch(gameid);
2012-01-21 21:57:41 +01:00
else
{
if(Emulator_boot)
mainMenu->m_Emulator_boot = true;
ret = mainMenu->main();
2012-01-21 21:57:41 +01:00
}
}
mainMenu->cleanup();
#ifndef DOLPHIN
2012-07-08 16:56:07 +02:00
ISFS_Deinitialize();
#endif
2012-01-21 21:57:41 +01:00
Sys_Exit();
exit(1);
2012-01-21 21:57:41 +01:00
return 0;
}