2012-06-13 23:16:36 +02:00
|
|
|
|
|
|
|
#include <ogc/machine/processor.h>
|
|
|
|
#include <ogc/lwp_threads.h>
|
|
|
|
#include <ogc/lwp_watchdog.h>
|
2012-01-21 21:57:41 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <stdlib.h>
|
2012-06-13 23:16:36 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
#include "sha1.h"
|
|
|
|
#include "fs.h"
|
2012-07-16 16:05:57 +02:00
|
|
|
#include "mload.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "sys.h"
|
|
|
|
#include "channel/channel_launcher.h"
|
2012-08-22 21:09:21 +02:00
|
|
|
#include "loader/nk.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "gecko/gecko.h"
|
|
|
|
#include "memory/mem2.hpp"
|
|
|
|
#include "memory/memory.h"
|
|
|
|
#include "wiiuse/wpad.h"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
/* Variables */
|
2012-08-22 21:09:21 +02:00
|
|
|
bool reset = false;
|
|
|
|
bool shutdown = false;
|
2012-01-21 21:57:41 +01:00
|
|
|
bool exiting = false;
|
|
|
|
|
2012-08-22 21:09:21 +02:00
|
|
|
bool priiloader_def = false;
|
|
|
|
bool return_to_hbc = false;
|
|
|
|
bool return_to_menu = false;
|
|
|
|
bool return_to_priiloader = false;
|
|
|
|
bool return_to_disable = false;
|
|
|
|
bool return_to_bootmii = false;
|
|
|
|
bool return_to_neek2o = false;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-05-16 00:29:28 +02:00
|
|
|
extern void __exception_closeall();
|
|
|
|
extern u32 __PADDisableRecalibration(s32 disable);
|
|
|
|
|
2012-05-12 18:03:14 +02:00
|
|
|
void __Wpad_PowerCallback()
|
2012-01-30 17:55:27 +01:00
|
|
|
{
|
|
|
|
/* Poweroff console */
|
|
|
|
shutdown = 1;
|
|
|
|
}
|
|
|
|
|
2012-01-21 21:57:41 +01:00
|
|
|
void Open_Inputs(void)
|
|
|
|
{
|
2012-01-30 17:55:27 +01:00
|
|
|
/* Initialize Wiimote subsystem */
|
|
|
|
PAD_Init();
|
|
|
|
WPAD_Init();
|
|
|
|
|
|
|
|
/* Set POWER button callback */
|
|
|
|
WPAD_SetPowerButtonCallback(__Wpad_PowerCallback);
|
|
|
|
|
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
|
2012-02-04 18:31:13 +01:00
|
|
|
|
|
|
|
WPAD_SetIdleTimeout(60*5); // idle after 5 minutes
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Close_Inputs(void)
|
|
|
|
{
|
2012-02-04 18:31:13 +01:00
|
|
|
u32 cnt;
|
|
|
|
|
|
|
|
/* Disconnect Wiimotes */
|
|
|
|
for (cnt = 0; cnt < 4; cnt++)
|
|
|
|
WPAD_Disconnect(cnt);
|
|
|
|
|
|
|
|
/* Shutdown Wiimote subsystem */
|
|
|
|
WPAD_Shutdown();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Sys_Exiting(void)
|
|
|
|
{
|
|
|
|
return reset || shutdown || exiting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_Test(void)
|
|
|
|
{
|
|
|
|
if(reset || shutdown) Close_Inputs();
|
|
|
|
|
|
|
|
if (reset) SYS_ResetSystem(SYS_RESTART, 0, 0);
|
|
|
|
else if (shutdown) SYS_ResetSystem(SYS_POWEROFF, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_ExitTo(int option)
|
|
|
|
{
|
2012-02-11 13:03:46 +01:00
|
|
|
priiloader_def = option == PRIILOADER_DEF;
|
2012-01-21 21:57:41 +01:00
|
|
|
return_to_hbc = option == EXIT_TO_HBC;
|
|
|
|
return_to_menu = option == EXIT_TO_MENU;
|
|
|
|
return_to_priiloader = option == EXIT_TO_PRIILOADER;
|
|
|
|
return_to_disable = option == EXIT_TO_DISABLE;
|
|
|
|
return_to_bootmii = option == EXIT_TO_BOOTMII;
|
2012-08-22 21:09:21 +02:00
|
|
|
return_to_neek2o = option == EXIT_TO_NEEK2O;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
//magic word to force wii menu in priiloader.
|
|
|
|
if(return_to_menu)
|
2012-07-23 17:29:26 +02:00
|
|
|
{
|
|
|
|
*Priiloader_CFG1 = 0x50756E65;
|
|
|
|
*Priiloader_CFG2 = 0x50756E65;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
else if(return_to_priiloader)
|
2012-07-23 17:29:26 +02:00
|
|
|
{
|
|
|
|
*Priiloader_CFG1 = 0x4461636F;
|
|
|
|
*Priiloader_CFG2 = 0x4461636F;
|
|
|
|
}
|
2012-02-11 13:03:46 +01:00
|
|
|
else
|
2012-07-23 17:29:26 +02:00
|
|
|
{
|
|
|
|
*Priiloader_CFG1 = 0xFFFFFFFF;
|
|
|
|
*Priiloader_CFG2 = 0xFFFFFFFF;
|
|
|
|
}
|
|
|
|
DCFlushRange((void*)Priiloader_CFG1, 4);
|
|
|
|
DCFlushRange((void*)Priiloader_CFG2, 4);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_Exit(void)
|
|
|
|
{
|
2012-05-19 14:29:24 +02:00
|
|
|
if(return_to_disable)
|
|
|
|
return;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
/* Shutdown Inputs */
|
|
|
|
Close_Inputs();
|
|
|
|
|
2012-08-22 21:09:21 +02:00
|
|
|
if(return_to_neek2o)
|
|
|
|
{
|
|
|
|
Launch_nk(0x1000144574641LL, NULL);
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
2012-05-19 14:58:43 +02:00
|
|
|
WII_Initialize();
|
2012-05-19 14:29:24 +02:00
|
|
|
if(return_to_menu || return_to_priiloader || priiloader_def)
|
2012-05-06 18:32:07 +02:00
|
|
|
Sys_LoadMenu();
|
|
|
|
else if(return_to_bootmii)
|
|
|
|
IOS_ReloadIOS(254);
|
|
|
|
|
|
|
|
//else
|
2012-06-20 18:45:25 +02:00
|
|
|
WII_LaunchTitle(HBC_108);
|
|
|
|
WII_LaunchTitle(HBC_JODI);
|
|
|
|
WII_LaunchTitle(HBC_HAXX);
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void __Sys_ResetCallback(void)
|
|
|
|
{
|
|
|
|
reset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __Sys_PowerCallback(void)
|
|
|
|
{
|
|
|
|
shutdown = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_Init(void)
|
|
|
|
{
|
|
|
|
/* Set RESET/POWER button callback */
|
|
|
|
SYS_SetResetCallback(__Sys_ResetCallback);
|
|
|
|
SYS_SetPowerCallback(__Sys_PowerCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_LoadMenu(void)
|
|
|
|
{
|
|
|
|
/* Return to the Wii system menu */
|
2012-06-14 17:27:57 +02:00
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2012-05-19 14:29:24 +02:00
|
|
|
}
|