2009-05-30 23:45:59 +02:00
|
|
|
/*
|
|
|
|
* loadMii loader v0.3
|
|
|
|
* main.c
|
|
|
|
* http://code.google.com/p/loadmii
|
|
|
|
*
|
|
|
|
* Copyright 2009 The Lemon Man
|
|
|
|
* Thanks to luccax, Wiipower, Aurelio and crediar
|
|
|
|
* GX added by dimok (thanks to Tantric)
|
|
|
|
* usbGecko powered by Nuke
|
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
2009-05-30 19:33:35 +02:00
|
|
|
#include <fat.h>
|
|
|
|
#include <sdcard/wiisd_io.h>
|
2009-05-30 23:45:59 +02:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
2009-05-30 19:33:35 +02:00
|
|
|
#include <stdlib.h>
|
2009-06-09 20:26:47 +02:00
|
|
|
#include <string.h>
|
2009-05-30 23:45:59 +02:00
|
|
|
#include <ogc/machine/processor.h>
|
2009-05-06 12:23:58 +02:00
|
|
|
|
2009-05-30 23:45:59 +02:00
|
|
|
#include "pngu/pngu.h"
|
2009-05-30 19:33:35 +02:00
|
|
|
#include "video.h"
|
|
|
|
#include "filelist.h"
|
|
|
|
#include "dolloader.h"
|
2009-05-30 23:45:59 +02:00
|
|
|
#include "elfloader.h"
|
|
|
|
#include "cfg.h"
|
2009-06-09 20:26:47 +02:00
|
|
|
#include "fatmounter.h"
|
2009-05-30 23:45:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
PNGUPROP imgProp;
|
|
|
|
IMGCTX ctx;
|
|
|
|
|
|
|
|
|
2009-05-30 19:33:35 +02:00
|
|
|
u8 * GetImageData(void) {
|
2009-05-30 23:45:59 +02:00
|
|
|
|
2009-05-30 19:33:35 +02:00
|
|
|
u8 * data = NULL;
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-05-30 19:33:35 +02:00
|
|
|
int ret;
|
2009-05-16 21:12:36 +02:00
|
|
|
|
2009-06-14 12:08:41 +02:00
|
|
|
if (CONF_GetAspectRatio()) {
|
|
|
|
ctx = PNGU_SelectImageFromBuffer(background169_png);
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
ctx = PNGU_SelectImageFromBuffer(background_png);
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-03 20:53:31 +02:00
|
|
|
|
2009-05-30 19:33:35 +02:00
|
|
|
ret = PNGU_GetImageProperties(ctx, &imgProp);
|
|
|
|
if (ret != PNGU_OK)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int len = imgProp.imgWidth * imgProp.imgHeight * 4;
|
|
|
|
|
|
|
|
if(len%32) len += (32-len%32);
|
|
|
|
data = (u8 *)memalign (32, len);
|
|
|
|
ret = PNGU_DecodeTo4x4RGBA8 (ctx, imgProp.imgWidth, imgProp.imgHeight, data, 255);
|
|
|
|
DCFlushRange(data, len);
|
|
|
|
|
|
|
|
PNGU_ReleaseImageContext(ctx);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2009-05-30 23:45:59 +02:00
|
|
|
|
2009-05-30 19:33:35 +02:00
|
|
|
void Background_Show(int x, int y, int z, u8 * data, int angle, int scaleX, int scaleY, int alpha)
|
|
|
|
{
|
|
|
|
/* Draw image */
|
|
|
|
Menu_DrawImg(x, y, z, imgProp.imgWidth, imgProp.imgHeight, data, angle, scaleX, scaleY, alpha);
|
2009-05-30 23:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-14 12:08:41 +02:00
|
|
|
int main(int argc, char **argv)
|
2009-06-09 20:26:47 +02:00
|
|
|
{
|
2009-05-30 23:45:59 +02:00
|
|
|
u32 cookie;
|
|
|
|
FILE *exeFile = NULL;
|
2009-05-30 19:33:35 +02:00
|
|
|
void *exeBuffer = (void *)EXECUTABLE_MEM_ADDR;
|
2009-05-30 23:45:59 +02:00
|
|
|
int exeSize = 0;
|
|
|
|
u32 exeEntryPointAddress = 0;
|
|
|
|
entrypoint exeEntryPoint;
|
2009-06-09 20:26:47 +02:00
|
|
|
/* int videomod */
|
|
|
|
InitVideo();
|
|
|
|
/* get imagedata */
|
|
|
|
u8 * imgdata = GetImageData();
|
|
|
|
/* fadein of image */
|
|
|
|
for(int i = 0; i < 255; i = i+10)
|
|
|
|
{
|
|
|
|
if(i>255) i = 255;
|
|
|
|
Background_Show(0, 0, 0, imgdata, 0, 1, 1, i);
|
|
|
|
Menu_Render();
|
|
|
|
}
|
|
|
|
/* check devices */
|
|
|
|
SDCard_Init();
|
|
|
|
USBDevice_Init();
|
|
|
|
char cfgpath[256];
|
2009-06-14 12:08:41 +02:00
|
|
|
|
2009-06-09 20:26:47 +02:00
|
|
|
sprintf(cfgpath, "SD:/config/GXGlobal.cfg");
|
|
|
|
if(!cfg_parsefile(cfgpath, &cfg_set)) //no cfg-File on SD: try USB:
|
|
|
|
{
|
|
|
|
sprintf(cfgpath, "USB:/config/GXGlobal.cfg");
|
|
|
|
cfg_parsefile(cfgpath, &cfg_set);
|
|
|
|
}
|
|
|
|
if(update_path[0] == '\0') // non cfg-File loaded or update_path not set
|
|
|
|
{
|
|
|
|
/* Open dol File and check exist */
|
|
|
|
strcpy(cfgpath, "SD:/apps/usbloader_gx/boot.dol");
|
|
|
|
exeFile = fopen (cfgpath ,"rb");
|
|
|
|
if (exeFile==NULL)
|
|
|
|
{
|
|
|
|
strcpy(cfgpath, "SD:/apps/usbloader_gx/boot.elf");
|
|
|
|
exeFile = fopen (cfgpath ,"rb");
|
|
|
|
}
|
|
|
|
if (exeFile==NULL)
|
|
|
|
{
|
|
|
|
strcpy(cfgpath, "USB:/apps/usbloader_gx/boot.dol");
|
|
|
|
exeFile = fopen (cfgpath ,"rb");
|
|
|
|
}
|
|
|
|
if (exeFile==NULL)
|
|
|
|
{
|
|
|
|
strcpy(cfgpath, "USB:/apps/usbloader_gx/boot.elf");
|
|
|
|
exeFile = fopen (cfgpath ,"rb");
|
|
|
|
}
|
|
|
|
if (exeFile==NULL)
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(cfgpath, "%sboot.dol", update_path);
|
|
|
|
/* Open dol File and check exist */
|
|
|
|
exeFile = fopen (cfgpath, "rb");
|
|
|
|
if (exeFile==NULL)
|
|
|
|
{
|
|
|
|
sprintf(cfgpath, "%sboot.elf", update_path);
|
|
|
|
exeFile = fopen (cfgpath,"rb");
|
|
|
|
}
|
|
|
|
if (exeFile==NULL)
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2009-05-30 23:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fseek (exeFile, 0, SEEK_END);
|
|
|
|
exeSize = ftell(exeFile);
|
|
|
|
fseek (exeFile, 0, SEEK_SET);
|
2009-06-09 20:26:47 +02:00
|
|
|
|
|
|
|
if(fread (exeBuffer, 1, exeSize, exeFile) != (unsigned int) exeSize)
|
|
|
|
{
|
2009-05-30 23:45:59 +02:00
|
|
|
printf("Can't open DOL File...\n");
|
2009-06-09 20:26:47 +02:00
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
2009-05-30 23:45:59 +02:00
|
|
|
}
|
|
|
|
fclose (exeFile);
|
2009-06-14 12:08:41 +02:00
|
|
|
|
2009-06-09 20:26:47 +02:00
|
|
|
/* load entry point */
|
|
|
|
struct __argv args;
|
|
|
|
bzero(&args, sizeof(args));
|
|
|
|
args.argvMagic = ARGV_MAGIC;
|
|
|
|
args.length = strlen(cfgpath) + 2;
|
|
|
|
args.commandLine = (char*)malloc(args.length);
|
|
|
|
if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
strcpy(args.commandLine, cfgpath);
|
|
|
|
args.commandLine[args.length - 1] = '\x00';
|
|
|
|
args.argc = 1;
|
|
|
|
args.argv = &args.commandLine;
|
|
|
|
args.endARGV = args.argv + 1;
|
2009-05-30 19:33:35 +02:00
|
|
|
|
|
|
|
int ret = valid_elf_image(exeBuffer);
|
2009-06-09 20:26:47 +02:00
|
|
|
if (ret == 1)
|
|
|
|
exeEntryPointAddress = load_elf_image(exeBuffer);
|
|
|
|
else
|
|
|
|
exeEntryPointAddress = load_dol_image(exeBuffer, &args);
|
|
|
|
|
|
|
|
/* fadeout of image */
|
|
|
|
for(int i = 255; i > 1; i = i-7)
|
|
|
|
{
|
|
|
|
if(i < 0) i = 0;
|
|
|
|
Background_Show(0, 0, 0, imgdata, 0, 1, 1, i);
|
|
|
|
Menu_Render();
|
2009-05-30 19:33:35 +02:00
|
|
|
}
|
2009-06-09 20:26:47 +02:00
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
|
|
|
StopGX();
|
2009-05-30 23:45:59 +02:00
|
|
|
if (exeEntryPointAddress == 0) {
|
2009-06-09 20:26:47 +02:00
|
|
|
printf("EntryPointAddress failed...\n");
|
2009-05-30 23:45:59 +02:00
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);;
|
2009-05-30 19:33:35 +02:00
|
|
|
}
|
2009-05-30 23:45:59 +02:00
|
|
|
exeEntryPoint = (entrypoint) exeEntryPointAddress;
|
2009-06-09 20:26:47 +02:00
|
|
|
/* cleaning up and load dol */
|
2009-05-30 23:45:59 +02:00
|
|
|
SYS_ResetSystem(SYS_SHUTDOWN, 0, 0);
|
|
|
|
_CPU_ISR_Disable (cookie);
|
|
|
|
__exception_closeall ();
|
|
|
|
exeEntryPoint ();
|
|
|
|
_CPU_ISR_Restore (cookie);
|
|
|
|
return 0;
|
|
|
|
}
|