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-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "memory/mem2.hpp"
|
|
|
|
#include "memory/memory.h"
|
|
|
|
#include "wiiuse/wpad.h"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
/* Variables */
|
2012-12-27 21:22:40 +01:00
|
|
|
bool reset = false;
|
|
|
|
bool shutdown = false;
|
2012-12-07 21:10:05 +01:00
|
|
|
volatile u8 ExitOption = 0;
|
2012-08-26 14:05:04 +02:00
|
|
|
const char *NeekPath = NULL;
|
2013-02-07 13:25:39 +01:00
|
|
|
char wii_games_dir[64];
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2012-05-12 18:03:14 +02:00
|
|
|
void __Wpad_PowerCallback()
|
2012-01-30 17:55:27 +01:00
|
|
|
{
|
|
|
|
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-09-11 19:09:14 +02:00
|
|
|
WPAD_SetIdleTimeout(60 * 2); // idle after 2 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 */
|
2012-09-09 20:35:15 +02:00
|
|
|
for(cnt = 0; cnt < 4; cnt++)
|
2012-02-04 18:31:13 +01:00
|
|
|
WPAD_Disconnect(cnt);
|
|
|
|
|
|
|
|
/* Shutdown Wiimote subsystem */
|
|
|
|
WPAD_Shutdown();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Sys_Exiting(void)
|
|
|
|
{
|
2012-12-27 21:22:40 +01:00
|
|
|
DCFlushRange(&reset, 32);
|
|
|
|
DCFlushRange(&shutdown, 32);
|
2012-11-07 23:27:41 +01:00
|
|
|
return reset || shutdown;
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-08-26 14:05:04 +02:00
|
|
|
int Sys_GetExitTo(void)
|
|
|
|
{
|
|
|
|
return ExitOption;
|
|
|
|
}
|
2012-01-21 21:57:41 +01:00
|
|
|
void Sys_ExitTo(int option)
|
|
|
|
{
|
2012-08-26 14:05:04 +02:00
|
|
|
ExitOption = option;
|
2012-01-21 21:57:41 +01:00
|
|
|
//magic word to force wii menu in priiloader.
|
2012-08-26 14:05:04 +02:00
|
|
|
if(ExitOption == EXIT_TO_MENU)
|
2012-07-23 17:29:26 +02:00
|
|
|
{
|
|
|
|
*Priiloader_CFG1 = 0x50756E65;
|
|
|
|
*Priiloader_CFG2 = 0x50756E65;
|
|
|
|
}
|
2012-08-26 14:05:04 +02:00
|
|
|
else if(ExitOption == EXIT_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-08-26 14:05:04 +02:00
|
|
|
if(ExitOption == EXIT_TO_DISABLE)
|
2012-05-19 14:29:24 +02:00
|
|
|
return;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
/* Shutdown Inputs */
|
|
|
|
Close_Inputs();
|
2012-12-15 14:06:33 +01:00
|
|
|
/* Just shutdown console*/
|
|
|
|
if(ExitOption == BUTTON_CALLBACK)
|
|
|
|
SYS_ResetSystem(SYS_POWEROFF_STANDBY, 0, 0);
|
|
|
|
|
|
|
|
/* We wanna to boot sth */
|
2012-08-26 14:05:04 +02:00
|
|
|
WII_Initialize();
|
2012-09-10 00:38:42 +02:00
|
|
|
if(ExitOption == EXIT_TO_WFNK2O)
|
|
|
|
Launch_nk(0x1000144574641LL, NeekPath, 0);
|
|
|
|
else if(ExitOption == EXIT_TO_SMNK2O)
|
|
|
|
Launch_nk(0, NeekPath, 0);
|
2012-08-26 14:05:04 +02:00
|
|
|
else if(ExitOption == EXIT_TO_BOOTMII)
|
|
|
|
IOS_ReloadIOS(0xfe);
|
|
|
|
else if(ExitOption == EXIT_TO_HBC)
|
2012-08-22 21:09:21 +02:00
|
|
|
{
|
2012-12-07 23:40:16 +01:00
|
|
|
WII_LaunchTitle(HBC_LULZ);
|
2012-08-26 14:05:04 +02:00
|
|
|
WII_LaunchTitle(HBC_108);
|
|
|
|
WII_LaunchTitle(HBC_JODI);
|
|
|
|
WII_LaunchTitle(HBC_HAXX);
|
2012-08-22 21:09:21 +02:00
|
|
|
}
|
2012-09-09 20:35:15 +02:00
|
|
|
/* else Return to Menu */
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
exit(1);
|
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);
|
|
|
|
}
|
|
|
|
|
2012-08-25 17:10:57 +02:00
|
|
|
bool AHBRPOT_Patched(void)
|
|
|
|
{
|
|
|
|
return (*HW_AHBPROT == 0xFFFFFFFF);
|
|
|
|
}
|
2012-08-26 14:05:04 +02:00
|
|
|
|
|
|
|
void Sys_SetNeekPath(const char *Path)
|
|
|
|
{
|
|
|
|
NeekPath = Path;
|
|
|
|
}
|
2012-09-20 18:09:32 +02:00
|
|
|
|
|
|
|
bool ModeChecked = false;
|
|
|
|
bool DolphinMode = false;
|
|
|
|
bool Sys_DolphinMode(void)
|
|
|
|
{
|
|
|
|
if(ModeChecked)
|
|
|
|
return DolphinMode;
|
|
|
|
|
|
|
|
/* Thanks to skidau for that code! */
|
|
|
|
u32 ifpr11 = 0x12345678;
|
|
|
|
u32 ifpr12 = 0x9abcdef0;
|
|
|
|
u32 ofpr1 = 0x00000000;
|
|
|
|
u32 ofpr2 = 0x00000000;
|
|
|
|
asm volatile (
|
|
|
|
"lwz 3,%[ifpr11]\n\t"
|
|
|
|
"stw 3,8(1)\n\t"
|
|
|
|
"lwz 3,%[ifpr12]\n\t"
|
|
|
|
"stw 3,12(1)\n\t"
|
|
|
|
|
|
|
|
"lfd 1,8(1)\n\t"
|
|
|
|
"frsqrte 1, 1\n\t"
|
|
|
|
"stfd 1,8(1)\n\t"
|
|
|
|
|
|
|
|
"lwz 3,8(1)\n\t"
|
|
|
|
"stw 3, %[ofpr1]\n\t"
|
|
|
|
"lwz 3,12(1)\n\t"
|
|
|
|
"stw 3, %[ofpr2]\n\t"
|
|
|
|
|
|
|
|
:
|
|
|
|
[ofpr1]"=m" (ofpr1)
|
|
|
|
,[ofpr2]"=m" (ofpr2)
|
|
|
|
:
|
|
|
|
[ifpr11]"m" (ifpr11)
|
|
|
|
,[ifpr12]"m" (ifpr12)
|
|
|
|
|
|
|
|
);
|
|
|
|
if(ofpr1 != 0x56cc62b2)
|
|
|
|
{
|
|
|
|
gprintf("Dolphin-Emu\n");
|
|
|
|
DolphinMode = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gprintf("Real Wii\n");
|
|
|
|
DolphinMode = false;
|
|
|
|
}
|
|
|
|
ModeChecked = true;
|
|
|
|
return DolphinMode;
|
|
|
|
}
|
2013-01-27 14:42:54 +01:00
|
|
|
|
|
|
|
/* KILL IT */
|
|
|
|
s32 __IOS_LoadStartupIOS() { return 0; }
|