2009-05-03 22:30:17 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogcsys.h>
|
2009-06-12 13:50:14 +02:00
|
|
|
#include <unistd.h>
|
2009-05-03 22:30:17 +02:00
|
|
|
|
2009-06-13 02:24:36 +02:00
|
|
|
#include "usbloader/wdvd.h"
|
|
|
|
#include "usbloader/usbstorage.h"
|
|
|
|
#include "usbloader/disc.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
|
|
|
#include "mload/mload.h"
|
2009-05-06 11:51:16 +02:00
|
|
|
#include "video.h"
|
2009-06-01 17:50:18 +02:00
|
|
|
#include "audio.h"
|
|
|
|
#include "menu.h"
|
2009-05-15 22:03:19 +02:00
|
|
|
#include "fatmounter.h"
|
2009-06-13 02:24:36 +02:00
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
2009-05-03 22:30:17 +02:00
|
|
|
|
2009-06-05 00:13:39 +02:00
|
|
|
//Wiilight stuff
|
|
|
|
static vu32 *_wiilight_reg = (u32*)0xCD0000C0;
|
|
|
|
void wiilight(int enable) { // Toggle wiilight (thanks Bool for wiilight source)
|
|
|
|
u32 val = (*_wiilight_reg&~0x20);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (enable && Settings.wiilight) val |= 0x20;
|
2009-06-05 00:13:39 +02:00
|
|
|
*_wiilight_reg=val;
|
|
|
|
}
|
|
|
|
|
2009-05-03 22:30:17 +02:00
|
|
|
/* Variables */
|
|
|
|
u8 shutdown = 0;
|
|
|
|
u8 reset = 0;
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void __Sys_ResetCallback(void) {
|
|
|
|
/* Reboot console */
|
|
|
|
reset = 1;
|
2009-05-03 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void __Sys_PowerCallback(void) {
|
|
|
|
/* Poweroff console */
|
|
|
|
shutdown = 1;
|
2009-05-03 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_Init(void) {
|
|
|
|
/* Initialize video subsytem */
|
|
|
|
//VIDEO_Init();
|
2009-05-03 22:30:17 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
/* Set RESET/POWER button callback */
|
|
|
|
SYS_SetResetCallback(__Sys_ResetCallback);
|
|
|
|
SYS_SetPowerCallback(__Sys_PowerCallback);
|
2009-05-03 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
static void _ExitApp() {
|
|
|
|
ExitGUIThreads();
|
|
|
|
StopGX();
|
|
|
|
ShutdownAudio();
|
2009-06-01 17:50:18 +02:00
|
|
|
|
|
|
|
SDCard_deInit();
|
2009-07-30 07:41:12 +02:00
|
|
|
USBDevice_deInit();
|
2009-06-12 01:02:05 +02:00
|
|
|
mload_set_ES_ioctlv_vector(NULL);
|
2009-07-30 07:41:12 +02:00
|
|
|
mload_close();
|
2009-06-01 17:50:18 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_Reboot(void) {
|
|
|
|
/* Restart console */
|
|
|
|
_ExitApp();
|
|
|
|
STM_RebootSystem();
|
2009-05-03 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
int Sys_IosReload(int IOS) {
|
2009-06-12 13:50:14 +02:00
|
|
|
s32 ret = -1;
|
2009-05-06 11:51:16 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
//shutdown SD and USB before IOS Reload in DiscWait
|
2009-05-15 22:03:19 +02:00
|
|
|
SDCard_deInit();
|
2009-06-01 17:50:18 +02:00
|
|
|
USBDevice_deInit();
|
2009-05-06 11:51:16 +02:00
|
|
|
|
|
|
|
WPAD_Flush(0);
|
|
|
|
WPAD_Disconnect(0);
|
|
|
|
WPAD_Shutdown();
|
|
|
|
|
2009-06-12 01:02:05 +02:00
|
|
|
WDVD_Close();
|
2009-05-06 11:51:16 +02:00
|
|
|
|
2009-06-14 01:39:42 +02:00
|
|
|
USBStorage_Deinit();
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
if (IOS == 249 || IOS == 222 || IOS == 223) {
|
|
|
|
for (int i = 0; i < 10; i++) {
|
2009-06-12 13:50:14 +02:00
|
|
|
ret = IOS_ReloadIOS(IOS);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (ret < 0) return ret;
|
|
|
|
if (IOS == 222 || IOS == 223) load_ehc_module();
|
2009-06-12 13:50:14 +02:00
|
|
|
ret = WBFS_Init(WBFS_DEVICE_USB);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (!(ret < 0)) break;
|
2009-06-12 13:50:14 +02:00
|
|
|
sleep(1);
|
|
|
|
USBStorage_Deinit();
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
|
|
|
if (ret>=0) {
|
|
|
|
ret = Disc_Init();
|
|
|
|
if (ret>=0) {
|
|
|
|
ret = WBFS_Open();
|
|
|
|
}
|
|
|
|
} else Sys_BackToLoader();
|
2009-05-06 11:51:16 +02:00
|
|
|
}
|
2009-06-12 13:50:14 +02:00
|
|
|
|
|
|
|
PAD_Init();
|
|
|
|
Wpad_Init();
|
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
|
|
|
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
2009-07-30 07:41:12 +02:00
|
|
|
//reinitialize SD and USB
|
2009-06-01 17:50:18 +02:00
|
|
|
SDCard_Init();
|
|
|
|
USBDevice_Init();
|
2009-05-06 11:51:16 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-06-01 17:50:18 +02:00
|
|
|
#define ShutdownToDefault 0
|
|
|
|
#define ShutdownToIdle 1
|
|
|
|
#define ShutdownToStandby 2
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
static void _Sys_Shutdown(int SHUTDOWN_MODE) {
|
|
|
|
_ExitApp();
|
|
|
|
WPAD_Flush(0);
|
|
|
|
WPAD_Disconnect(0);
|
|
|
|
WPAD_Shutdown();
|
|
|
|
|
|
|
|
/* Poweroff console */
|
|
|
|
if ((CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE && SHUTDOWN_MODE != ShutdownToStandby) || SHUTDOWN_MODE == ShutdownToIdle) {
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* Set LED mode */
|
|
|
|
ret = CONF_GetIdleLedMode();
|
|
|
|
if (ret >= 0 && ret <= 2)
|
|
|
|
STM_SetLedMode(ret);
|
|
|
|
|
|
|
|
/* Shutdown to idle */
|
|
|
|
STM_ShutdownToIdle();
|
|
|
|
} else {
|
|
|
|
/* Shutdown to standby */
|
|
|
|
STM_ShutdownToStandby();
|
|
|
|
}
|
2009-05-03 22:30:17 +02:00
|
|
|
}
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_Shutdown(void) {
|
|
|
|
_Sys_Shutdown(ShutdownToDefault);
|
2009-06-01 17:50:18 +02:00
|
|
|
}
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_ShutdownToIdel(void) {
|
|
|
|
_Sys_Shutdown(ShutdownToIdle);
|
2009-06-01 17:50:18 +02:00
|
|
|
}
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_ShutdownToStandby(void) {
|
|
|
|
_Sys_Shutdown(ShutdownToStandby);
|
2009-06-01 17:50:18 +02:00
|
|
|
}
|
2009-05-03 22:30:17 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_LoadMenu(void) {
|
|
|
|
_ExitApp();
|
|
|
|
/* Return to the Wii system menu */
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2009-05-03 22:30:17 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
void Sys_BackToLoader(void) {
|
|
|
|
if (*((u32*) 0x80001800)) {
|
|
|
|
_ExitApp();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
// Channel Version
|
|
|
|
Sys_LoadMenu();
|
2009-06-01 17:50:18 +02:00
|
|
|
}
|