2012-08-12 23:26:24 +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>
|
|
|
|
|
2012-09-07 23:24:15 +02:00
|
|
|
#include "Config.hpp"
|
|
|
|
#include "ChannelHandler.hpp"
|
|
|
|
|
2012-08-12 23:26:24 +02:00
|
|
|
#include "apploader.h"
|
|
|
|
#include "patchcode.h"
|
|
|
|
#include "disc.h"
|
|
|
|
#include "fst.h"
|
2012-09-07 23:24:15 +02:00
|
|
|
#include "wdvd.h"
|
2012-09-28 19:24:04 +02:00
|
|
|
#include "gecko.h"
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
IOS_Info CurrentIOS;
|
|
|
|
|
|
|
|
/* Boot Variables */
|
|
|
|
u32 vmode_reg = 0;
|
|
|
|
entry_point p_entry;
|
|
|
|
GXRModeObj *vmode = NULL;
|
|
|
|
|
|
|
|
u32 AppEntrypoint;
|
|
|
|
|
2012-09-28 19:24:04 +02:00
|
|
|
extern "C" {
|
|
|
|
extern void __exception_closeall();
|
|
|
|
extern s32 wbfsDev;
|
|
|
|
extern u32 wbfs_part_idx;
|
|
|
|
extern FragList *frag_list;
|
|
|
|
}
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
VIDEO_Init();
|
2012-09-28 19:24:04 +02:00
|
|
|
InitGecko();
|
|
|
|
gprintf("WiiFlow External Booter by FIX94\n");
|
|
|
|
|
2012-08-12 23:26:24 +02:00
|
|
|
configbytes[0] = conf->configbytes[0];
|
|
|
|
configbytes[1] = conf->configbytes[1];
|
|
|
|
hooktype = conf->hooktype;
|
|
|
|
debuggerselect = conf->debugger;
|
|
|
|
CurrentIOS = conf->IOS;
|
|
|
|
app_gameconfig_set(conf->gameconf, conf->gameconfsize);
|
|
|
|
ocarina_set_codes(conf->codelist, conf->codelistend, conf->cheats, conf->cheatSize);
|
2012-09-28 19:24:04 +02:00
|
|
|
frag_list = conf->fragments;
|
|
|
|
wbfsDev = conf->wbfsDevice;
|
|
|
|
wbfs_part_idx = conf->wbfsPart;
|
2012-08-12 23:26:24 +02:00
|
|
|
|
|
|
|
if(conf->BootType == TYPE_WII_GAME)
|
|
|
|
{
|
|
|
|
WDVD_Init();
|
2012-09-28 19:24:04 +02:00
|
|
|
if(conf->GameBootType == TYPE_WII_DISC)
|
|
|
|
Disc_SetUSB(NULL, false);
|
|
|
|
else
|
|
|
|
Disc_SetUSB((u8*)conf->gameID, conf->GameBootType == TYPE_WII_WBFS_EXT);
|
|
|
|
Disc_Open();
|
|
|
|
Disc_SetLowMem();
|
2012-08-12 23:26:24 +02:00
|
|
|
u64 offset = 0;
|
|
|
|
Disc_FindPartition(&offset);
|
2012-09-28 19:24:04 +02:00
|
|
|
gprintf("Partition Offset: %08x\n", offset);
|
2012-08-12 23:26:24 +02:00
|
|
|
WDVD_OpenPartition(offset);
|
2012-09-28 19:24:04 +02:00
|
|
|
vmode = Disc_SelectVMode(conf->vidMode, &vmode_reg);
|
2012-08-12 23:26:24 +02:00
|
|
|
Apploader_Run(&p_entry, conf->vidMode, vmode, conf->vipatch, conf->countryString, conf->patchVidMode,
|
|
|
|
conf->aspectRatio, conf->returnTo);
|
|
|
|
AppEntrypoint = (u32)p_entry;
|
2012-09-28 19:24:04 +02:00
|
|
|
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
|
|
|
{
|
|
|
|
if(conf->GameBootType == TYPE_WII_DISC)
|
|
|
|
Hermes_Disable_EHC();
|
|
|
|
else
|
|
|
|
Hermes_shadow_mload(conf->mload_rev);
|
|
|
|
}
|
2012-09-07 23:24:15 +02:00
|
|
|
WDVD_Close();
|
2012-08-12 23:26:24 +02:00
|
|
|
}
|
|
|
|
else if(conf->BootType == TYPE_CHANNEL)
|
|
|
|
{
|
2012-09-08 11:51:51 +02:00
|
|
|
ISFS_Initialize();
|
2012-09-07 22:10:04 +02:00
|
|
|
AppEntrypoint = LoadChannel();
|
2012-09-28 19:24:04 +02:00
|
|
|
Disc_SetLowMem();
|
|
|
|
vmode = Disc_SelectVMode(conf->vidMode, &vmode_reg);
|
2012-08-12 23:26:24 +02:00
|
|
|
PatchChannel(conf->vidMode, vmode, conf->vipatch, conf->countryString,
|
|
|
|
conf->patchVidMode, conf->aspectRatio);
|
2012-09-08 11:51:51 +02:00
|
|
|
ISFS_Deinitialize();
|
2012-08-12 23:26:24 +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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (hooktype)
|
|
|
|
{
|
|
|
|
asm volatile (
|
|
|
|
"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"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
asm volatile (
|
|
|
|
"lis %r3, AppEntrypoint@h\n"
|
|
|
|
"ori %r3, %r3, AppEntrypoint@l\n"
|
|
|
|
"lwz %r3, 0(%r3)\n"
|
|
|
|
"mtlr %r3\n"
|
|
|
|
"blr\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
IRQ_Restore(level);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|