2012-10-14 19:18:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2012 FIX94
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#include "Config.hpp"
|
|
|
|
#include "ChannelHandler.hpp"
|
|
|
|
#include "video_tinyload.h"
|
|
|
|
#include "apploader.h"
|
|
|
|
#include "patchcode.h"
|
2012-10-20 15:24:30 +02:00
|
|
|
#include "memory.h"
|
|
|
|
#include "utils.h"
|
2012-10-14 19:18:13 +02:00
|
|
|
#include "disc.h"
|
|
|
|
#include "fst.h"
|
|
|
|
#include "wdvd.h"
|
|
|
|
#include "gecko.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
IOS_Info CurrentIOS;
|
|
|
|
|
|
|
|
/* Boot Variables */
|
2012-10-20 00:01:30 +02:00
|
|
|
u32 GameIOS = 0;
|
2012-10-14 19:18:13 +02:00
|
|
|
u32 vmode_reg = 0;
|
|
|
|
GXRModeObj *vmode = NULL;
|
|
|
|
|
2012-10-21 17:28:00 +02:00
|
|
|
u32 AppEntrypoint = 0;
|
2012-10-14 19:18:13 +02:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
extern void __exception_closeall();
|
|
|
|
extern s32 wbfsDev;
|
|
|
|
extern u32 wbfs_part_idx;
|
|
|
|
extern FragList *frag_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
the_CFG normalCFG;
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
InitGecko();
|
|
|
|
gprintf("WiiFlow External Booter by FIX94\n");
|
|
|
|
memcpy(&normalCFG, (void*)0x93100000, sizeof(the_CFG));
|
|
|
|
VIDEO_Init();
|
|
|
|
video_init();
|
|
|
|
prog10();
|
|
|
|
|
|
|
|
configbytes[0] = normalCFG.configbytes[0];
|
|
|
|
configbytes[1] = normalCFG.configbytes[1];
|
|
|
|
hooktype = normalCFG.hooktype;
|
|
|
|
debuggerselect = normalCFG.debugger;
|
|
|
|
CurrentIOS = normalCFG.IOS;
|
2012-10-20 00:01:30 +02:00
|
|
|
set_wip_list(normalCFG.wip_list, normalCFG.wip_count);
|
2012-10-14 19:18:13 +02:00
|
|
|
app_gameconfig_set(normalCFG.gameconf, normalCFG.gameconfsize);
|
|
|
|
ocarina_set_codes(normalCFG.codelist, normalCFG.codelistend, normalCFG.cheats, normalCFG.cheatSize);
|
|
|
|
frag_list = normalCFG.fragments;
|
|
|
|
wbfsDev = normalCFG.wbfsDevice;
|
|
|
|
wbfs_part_idx = normalCFG.wbfsPart;
|
2012-10-20 15:24:30 +02:00
|
|
|
prog10();
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2012-10-20 17:43:48 +02:00
|
|
|
/* Setup Low Memory */
|
|
|
|
Disc_SetLowMemPre();
|
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
if(normalCFG.BootType == TYPE_WII_GAME)
|
|
|
|
{
|
|
|
|
WDVD_Init();
|
2012-10-21 17:28:00 +02:00
|
|
|
if(CurrentIOS.Type == IOS_TYPE_D2X)
|
|
|
|
{
|
|
|
|
s32 ret = BlockIOSReload();
|
|
|
|
gprintf("Block IOS Reload using d2x %s.\n", ret < 0 ? "failed" : "succeeded");
|
|
|
|
}
|
2012-10-14 19:18:13 +02:00
|
|
|
if(normalCFG.GameBootType == TYPE_WII_DISC)
|
|
|
|
{
|
|
|
|
Disc_SetUSB(NULL, false);
|
|
|
|
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
|
|
|
Hermes_Disable_EHC();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Disc_SetUSB((u8*)normalCFG.gameID, normalCFG.GameBootType == TYPE_WII_WBFS_EXT);
|
|
|
|
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
2012-11-12 21:12:00 +01:00
|
|
|
Hermes_shadow_mload();
|
2012-10-14 19:18:13 +02:00
|
|
|
}
|
2012-10-20 15:24:30 +02:00
|
|
|
prog(20);
|
2012-10-14 19:18:13 +02:00
|
|
|
Disc_Open();
|
2012-10-20 15:24:30 +02:00
|
|
|
u32 offset = 0;
|
2012-10-14 19:18:13 +02:00
|
|
|
Disc_FindPartition(&offset);
|
2012-10-20 00:01:30 +02:00
|
|
|
WDVD_OpenPartition(offset, &GameIOS);
|
2012-10-14 19:18:13 +02:00
|
|
|
vmode = Disc_SelectVMode(normalCFG.vidMode, &vmode_reg);
|
2012-10-21 17:28:00 +02:00
|
|
|
AppEntrypoint = Apploader_Run(normalCFG.vidMode, vmode, normalCFG.vipatch, normalCFG.countryString,
|
|
|
|
normalCFG.patchVidMode, normalCFG.aspectRatio, normalCFG.returnTo);
|
2012-10-14 19:18:13 +02:00
|
|
|
WDVD_Close();
|
|
|
|
}
|
|
|
|
else if(normalCFG.BootType == TYPE_CHANNEL)
|
|
|
|
{
|
|
|
|
ISFS_Initialize();
|
2012-10-20 15:24:30 +02:00
|
|
|
*Disc_ID = TITLE_LOWER(normalCFG.title);
|
2012-10-14 19:18:13 +02:00
|
|
|
vmode = Disc_SelectVMode(normalCFG.vidMode, &vmode_reg);
|
2012-10-21 17:28:00 +02:00
|
|
|
AppEntrypoint = LoadChannel(normalCFG.title, &GameIOS);
|
2012-10-14 19:18:13 +02:00
|
|
|
PatchChannel(normalCFG.vidMode, vmode, normalCFG.vipatch, normalCFG.countryString,
|
2012-10-20 15:24:30 +02:00
|
|
|
normalCFG.patchVidMode, normalCFG.aspectRatio);
|
2012-10-14 19:18:13 +02:00
|
|
|
ISFS_Deinitialize();
|
|
|
|
}
|
2012-10-20 00:01:30 +02:00
|
|
|
gprintf("Entrypoint: %08x, Requested Game IOS: %i\n", AppEntrypoint, GameIOS);
|
2012-10-14 19:18:13 +02:00
|
|
|
setprog(320);
|
|
|
|
|
2012-10-20 00:01:30 +02:00
|
|
|
/* Setup Low Memory */
|
|
|
|
Disc_SetLowMem(GameIOS);
|
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
/* Set time */
|
|
|
|
Disc_SetTime();
|
|
|
|
|
|
|
|
/* Set an appropriate video mode */
|
|
|
|
Disc_SetVMode(vmode, vmode_reg);
|
|
|
|
|
|
|
|
/* Shutdown IOS subsystems */
|
|
|
|
u32 level = IRQ_Disable();
|
|
|
|
__IOS_ShutdownSubsystems();
|
|
|
|
__exception_closeall();
|
|
|
|
|
|
|
|
/* Originally from tueidj - taken from NeoGamma (thx) */
|
|
|
|
*(vu32*)0xCC003024 = 1;
|
|
|
|
|
|
|
|
if(AppEntrypoint == 0x3400)
|
|
|
|
{
|
|
|
|
if(hooktype)
|
|
|
|
{
|
|
|
|
asm volatile (
|
|
|
|
"lis %r3, returnpoint@h\n"
|
|
|
|
"ori %r3, %r3, returnpoint@l\n"
|
|
|
|
"mtlr %r3\n"
|
|
|
|
"lis %r3, 0x8000\n"
|
|
|
|
"ori %r3, %r3, 0x18A8\n"
|
|
|
|
"nop\n"
|
|
|
|
"mtctr %r3\n"
|
|
|
|
"bctr\n"
|
|
|
|
"returnpoint:\n"
|
|
|
|
"bl DCDisable\n"
|
|
|
|
"bl ICDisable\n"
|
|
|
|
"li %r3, 0\n"
|
|
|
|
"mtsrr1 %r3\n"
|
|
|
|
"lis %r4, AppEntrypoint@h\n"
|
|
|
|
"ori %r4,%r4,AppEntrypoint@l\n"
|
|
|
|
"lwz %r4, 0(%r4)\n"
|
|
|
|
"mtsrr0 %r4\n"
|
|
|
|
"rfi\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
asm volatile (
|
|
|
|
"isync\n"
|
|
|
|
"lis %r3, AppEntrypoint@h\n"
|
|
|
|
"ori %r3, %r3, AppEntrypoint@l\n"
|
|
|
|
"lwz %r3, 0(%r3)\n"
|
|
|
|
"mtsrr0 %r3\n"
|
|
|
|
"mfmsr %r3\n"
|
|
|
|
"li %r4, 0x30\n"
|
|
|
|
"andc %r3, %r3, %r4\n"
|
|
|
|
"mtsrr1 %r3\n"
|
|
|
|
"rfi\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-10-21 17:28:00 +02:00
|
|
|
else if(hooktype)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
|
|
|
asm volatile (
|
2012-10-21 17:28:00 +02:00
|
|
|
"lis %r3, AppEntrypoint@h\n"
|
|
|
|
"ori %r3, %r3, AppEntrypoint@l\n"
|
|
|
|
"lwz %r3, 0(%r3)\n"
|
|
|
|
"mtlr %r3\n"
|
|
|
|
"lis %r3, 0x8000\n"
|
|
|
|
"ori %r3, %r3, 0x18A8\n"
|
|
|
|
"nop\n"
|
|
|
|
"mtctr %r3\n"
|
|
|
|
"bctr\n"
|
2012-10-14 19:18:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
asm volatile (
|
2012-10-21 17:28:00 +02:00
|
|
|
"lis %r3, AppEntrypoint@h\n"
|
|
|
|
"ori %r3, %r3, AppEntrypoint@l\n"
|
|
|
|
"lwz %r3, 0(%r3)\n"
|
|
|
|
"mtlr %r3\n"
|
|
|
|
"blr\n"
|
2012-10-14 19:18:13 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
IRQ_Restore(level);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|