2012-01-21 22:15:45 +01:00
|
|
|
#include <gccore.h>
|
2012-02-25 23:34:52 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2012-03-11 20:47:24 +01:00
|
|
|
#include <string.h>
|
2012-01-23 16:57:30 +01:00
|
|
|
#include "gc.h"
|
2012-02-25 23:34:52 +01:00
|
|
|
#include "gecko.h"
|
2012-02-27 17:05:10 +01:00
|
|
|
#include "fileOps.h"
|
2012-02-28 19:44:41 +01:00
|
|
|
#include "utils.h"
|
2012-03-11 20:47:24 +01:00
|
|
|
#include "memory/mem2.hpp"
|
2012-06-13 22:30:35 +02:00
|
|
|
#include "loader/video_sys.h"
|
2012-01-21 22:15:45 +01:00
|
|
|
|
2012-02-02 23:22:46 +01:00
|
|
|
#define SRAM_ENGLISH 0
|
|
|
|
#define SRAM_GERMAN 1
|
|
|
|
#define SRAM_FRENCH 2
|
|
|
|
#define SRAM_SPANISH 3
|
|
|
|
#define SRAM_ITALIAN 4
|
|
|
|
#define SRAM_DUTCH 5
|
|
|
|
|
2012-01-21 22:15:45 +01:00
|
|
|
syssram* __SYS_LockSram();
|
|
|
|
u32 __SYS_UnlockSram(u32 write);
|
|
|
|
u32 __SYS_SyncSram(void);
|
2012-05-08 22:38:50 +02:00
|
|
|
DML_CFG *DMLCfg = NULL;
|
2012-01-21 22:15:45 +01:00
|
|
|
|
2012-03-25 21:52:35 +02:00
|
|
|
void GC_SetVideoMode(u8 videomode)
|
2012-01-21 22:15:45 +01:00
|
|
|
{
|
2012-06-13 22:30:35 +02:00
|
|
|
syssram *sram = __SYS_LockSram();
|
2012-01-23 16:57:30 +01:00
|
|
|
static GXRModeObj *rmode;
|
2012-03-25 21:52:35 +02:00
|
|
|
int memflag = 0;
|
2012-02-21 18:21:12 +01:00
|
|
|
|
2012-06-13 22:30:35 +02:00
|
|
|
if((CUSTOM_VIDEO_HaveComponentCable() && (CONF_GetProgressiveScan() > 0)) || videomode > 3)
|
2012-02-21 18:21:12 +01:00
|
|
|
sram->flags |= 0x80; //set progressive flag
|
|
|
|
else
|
|
|
|
sram->flags &= 0x7F; //clear progressive flag
|
|
|
|
|
2012-03-25 21:52:35 +02:00
|
|
|
if(videomode == 1 || videomode == 3 || videomode == 5)
|
2012-01-23 16:57:30 +01:00
|
|
|
{
|
2012-03-25 21:52:35 +02:00
|
|
|
memflag = 1;
|
|
|
|
sram->flags |= 0x01; // Set bit 0 to set the video mode to PAL
|
|
|
|
sram->ntd |= 0x40; //set pal60 flag
|
2012-01-23 16:57:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-25 21:52:35 +02:00
|
|
|
sram->flags &= 0xFE; // Clear bit 0 to set the video mode to NTSC
|
|
|
|
sram->ntd &= 0xBF; //clear pal60 flag
|
|
|
|
}
|
|
|
|
|
|
|
|
if(videomode == 1)
|
2012-06-13 22:30:35 +02:00
|
|
|
rmode = &CUSTOM_TVPal528IntDf;
|
2012-03-25 21:52:35 +02:00
|
|
|
else if(videomode == 2)
|
2012-06-13 22:30:35 +02:00
|
|
|
rmode = &CUSTOM_TVNtsc480IntDf;
|
2012-03-25 21:52:35 +02:00
|
|
|
else if(videomode == 3)
|
|
|
|
{
|
2012-06-13 22:30:35 +02:00
|
|
|
rmode = &CUSTOM_TVEurgb60Hz480IntDf;
|
2012-03-25 21:52:35 +02:00
|
|
|
memflag = 5;
|
|
|
|
}
|
|
|
|
else if(videomode == 4)
|
2012-06-13 22:30:35 +02:00
|
|
|
rmode = &CUSTOM_TVNtsc480Prog;
|
2012-03-25 21:52:35 +02:00
|
|
|
else if(videomode == 5)
|
|
|
|
{
|
2012-06-13 22:30:35 +02:00
|
|
|
rmode = &CUSTOM_TVEurgb60Hz480Prog;
|
2012-03-25 21:52:35 +02:00
|
|
|
memflag = 5;
|
2012-01-23 16:57:30 +01:00
|
|
|
}
|
2012-02-21 18:01:57 +01:00
|
|
|
|
2012-01-21 22:15:45 +01:00
|
|
|
__SYS_UnlockSram(1); // 1 -> write changes
|
|
|
|
while(!__SYS_SyncSram());
|
|
|
|
|
2012-01-23 16:57:30 +01:00
|
|
|
/* Set video mode to PAL or NTSC */
|
2012-03-25 21:52:35 +02:00
|
|
|
*(vu32*)0x800000CC = memflag;
|
2012-03-11 20:47:24 +01:00
|
|
|
DCFlushRange((void *)(0x800000CC), 4);
|
|
|
|
ICInvalidateRange((void *)(0x800000CC), 4);
|
2012-03-25 21:52:35 +02:00
|
|
|
|
2012-06-13 22:30:35 +02:00
|
|
|
/* Set video mode */
|
|
|
|
if (rmode != 0)
|
|
|
|
CUSTOM_VIDEO_Configure(rmode);
|
2012-03-25 21:52:35 +02:00
|
|
|
|
2012-06-13 22:30:35 +02:00
|
|
|
/* Setup video */
|
|
|
|
CUSTOM_VIDEO_SetBlack(TRUE);
|
|
|
|
CUSTOM_VIDEO_Flush();
|
|
|
|
CUSTOM_VIDEO_WaitVSync();
|
|
|
|
if(rmode->viTVMode & VI_NON_INTERLACE)
|
|
|
|
CUSTOM_VIDEO_WaitVSync();
|
2012-02-02 23:22:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u8 get_wii_language()
|
|
|
|
{
|
|
|
|
switch (CONF_GetLanguage())
|
|
|
|
{
|
|
|
|
case CONF_LANG_GERMAN:
|
|
|
|
return SRAM_GERMAN;
|
|
|
|
case CONF_LANG_FRENCH:
|
|
|
|
return SRAM_FRENCH;
|
|
|
|
case CONF_LANG_SPANISH:
|
|
|
|
return SRAM_SPANISH;
|
|
|
|
case CONF_LANG_ITALIAN:
|
|
|
|
return SRAM_ITALIAN;
|
|
|
|
case CONF_LANG_DUTCH:
|
|
|
|
return SRAM_DUTCH;
|
|
|
|
default:
|
|
|
|
return SRAM_ENGLISH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-11 20:47:24 +01:00
|
|
|
void GC_SetLanguage(u8 lang)
|
2012-02-02 23:22:46 +01:00
|
|
|
{
|
|
|
|
if (lang == 0)
|
|
|
|
lang = get_wii_language();
|
|
|
|
else
|
|
|
|
lang--;
|
|
|
|
|
|
|
|
syssram *sram;
|
|
|
|
sram = __SYS_LockSram();
|
|
|
|
sram->lang = lang;
|
|
|
|
|
|
|
|
__SYS_UnlockSram(1); // 1 -> write changes
|
|
|
|
while(!__SYS_SyncSram());
|
2012-02-25 23:34:52 +01:00
|
|
|
}
|
|
|
|
|
2012-04-24 21:42:18 +02:00
|
|
|
int GC_GameIsInstalled(char *discid, const char* partition, const char* dmlgamedir)
|
2012-02-25 23:34:52 +01:00
|
|
|
{
|
2012-03-06 22:04:23 +01:00
|
|
|
char folder[50];
|
2012-03-05 10:48:13 +01:00
|
|
|
char source[300];
|
2012-03-06 22:04:23 +01:00
|
|
|
snprintf(folder, sizeof(folder), dmlgamedir, partition);
|
2012-03-05 11:01:07 +01:00
|
|
|
snprintf(source, sizeof(source), "%s/%s/game.iso", folder, discid);
|
2012-02-25 23:34:52 +01:00
|
|
|
|
2012-04-22 15:39:26 +02:00
|
|
|
FILE *f = fopen(source, "rb");
|
|
|
|
if(f)
|
2012-02-25 23:34:52 +01:00
|
|
|
{
|
2012-03-05 10:48:13 +01:00
|
|
|
gprintf("Found on %s: %s\n", partition, source);
|
2012-02-25 23:34:52 +01:00
|
|
|
fclose(f);
|
2012-04-24 21:42:18 +02:00
|
|
|
return 1;
|
2012-02-25 23:34:52 +01:00
|
|
|
}
|
2012-04-22 15:39:26 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(source, sizeof(source), "%s/%s/sys/boot.bin", folder, discid);
|
|
|
|
f = fopen(source, "rb");
|
|
|
|
if(f)
|
|
|
|
{
|
|
|
|
gprintf("Found on %s: %s\n", partition, source);
|
|
|
|
fclose(f);
|
2012-04-24 21:42:18 +02:00
|
|
|
return 2;
|
2012-04-22 15:39:26 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 21:42:18 +02:00
|
|
|
return 0;
|
2012-02-25 23:34:52 +01:00
|
|
|
}
|
2012-03-11 20:47:24 +01:00
|
|
|
|
2012-05-02 18:08:22 +02:00
|
|
|
void DML_New_SetOptions(char *GamePath, char *CheatPath, char *NewCheatPath, bool cheats, bool debugger, u8 NMM, u8 nodisc, u8 DMLvideoMode)
|
2012-03-11 20:47:24 +01:00
|
|
|
{
|
|
|
|
gprintf("Wiiflow DML: Launch game 'sd:/games/%s/game.iso' through memory (new method)\n", GamePath);
|
|
|
|
|
2012-05-18 22:13:26 +02:00
|
|
|
DMLCfg = (DML_CFG*)MEM1_alloc(sizeof(DML_CFG));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(DMLCfg == NULL)
|
|
|
|
return;
|
2012-03-11 20:47:24 +01:00
|
|
|
memset(DMLCfg, 0, sizeof(DML_CFG));
|
|
|
|
|
|
|
|
DMLCfg->Magicbytes = 0xD1050CF6;
|
|
|
|
DMLCfg->CfgVersion = 0x00000001;
|
2012-03-30 14:53:10 +02:00
|
|
|
DMLCfg->VideoMode |= DML_VID_NONE;
|
2012-03-11 20:47:24 +01:00
|
|
|
|
2012-03-12 17:14:56 +01:00
|
|
|
DMLCfg->Config |= DML_CFG_ACTIVITY_LED; //Sorry but I like it lol, option will may follow
|
2012-03-19 19:08:48 +01:00
|
|
|
DMLCfg->Config |= DML_CFG_PADHOOK; //Makes life easier, l+z+b+digital down...
|
2012-03-12 17:14:56 +01:00
|
|
|
|
2012-03-19 19:08:48 +01:00
|
|
|
if(GamePath != NULL)
|
|
|
|
{
|
2012-04-24 21:42:18 +02:00
|
|
|
if(GC_GameIsInstalled(GamePath, "sd", "%s:/games") == 2)
|
|
|
|
snprintf(DMLCfg->GamePath, sizeof(DMLCfg->GamePath), "/games/%s/", GamePath);
|
|
|
|
else
|
|
|
|
snprintf(DMLCfg->GamePath, sizeof(DMLCfg->GamePath), "/games/%s/game.iso", GamePath);
|
2012-03-19 19:08:48 +01:00
|
|
|
DMLCfg->Config |= DML_CFG_GAME_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CheatPath != NULL && NewCheatPath != NULL && cheats)
|
2012-03-11 20:47:24 +01:00
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
if(strstr(CheatPath, "sd:/") == NULL)
|
|
|
|
{
|
|
|
|
fsop_CopyFile(CheatPath, NewCheatPath, NULL, NULL);
|
|
|
|
ptr = &NewCheatPath[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ptr = &CheatPath[3];
|
|
|
|
strncpy(DMLCfg->CheatPath, ptr, sizeof(DMLCfg->CheatPath));
|
|
|
|
DMLCfg->Config |= DML_CFG_CHEAT_PATH;
|
|
|
|
}
|
2012-03-12 17:14:56 +01:00
|
|
|
|
2012-03-19 19:08:48 +01:00
|
|
|
if(cheats)
|
|
|
|
DMLCfg->Config |= DML_CFG_CHEATS;
|
2012-03-11 20:47:24 +01:00
|
|
|
if(debugger)
|
|
|
|
DMLCfg->Config |= DML_CFG_DEBUGGER;
|
2012-03-12 17:14:56 +01:00
|
|
|
if(NMM > 0)
|
2012-03-11 20:47:24 +01:00
|
|
|
DMLCfg->Config |= DML_CFG_NMM;
|
2012-03-12 17:14:56 +01:00
|
|
|
if(NMM > 1)
|
|
|
|
DMLCfg->Config |= DML_CFG_NMM_DEBUG;
|
2012-03-17 17:52:17 +01:00
|
|
|
if(nodisc > 0)
|
2012-03-16 22:36:49 +01:00
|
|
|
DMLCfg->Config |= DML_CFG_NODISC;
|
2012-03-12 17:14:56 +01:00
|
|
|
|
2012-05-02 18:08:22 +02:00
|
|
|
if(DMLvideoMode > 3)
|
|
|
|
DMLCfg->VideoMode |= DML_VID_PROG_PATCH;
|
2012-03-11 20:47:24 +01:00
|
|
|
}
|
|
|
|
|
2012-03-11 20:59:15 +01:00
|
|
|
void DML_Old_SetOptions(char *GamePath, char *CheatPath, char *NewCheatPath, bool cheats)
|
2012-03-11 20:47:24 +01:00
|
|
|
{
|
|
|
|
gprintf("Wiiflow DML: Launch game 'sd:/games/%s/game.iso' through boot.bin (old method)\n", GamePath);
|
|
|
|
FILE *f;
|
|
|
|
f = fopen("sd:/games/boot.bin", "wb");
|
|
|
|
fwrite(GamePath, 1, strlen(GamePath) + 1, f);
|
|
|
|
fclose(f);
|
|
|
|
|
2012-03-11 20:59:15 +01:00
|
|
|
if(cheats && strstr(CheatPath, NewCheatPath) == NULL)
|
2012-03-11 20:47:24 +01:00
|
|
|
fsop_CopyFile(CheatPath, NewCheatPath, NULL, NULL);
|
|
|
|
|
|
|
|
//Tell DML to boot the game from sd card
|
|
|
|
*(vu32*)0x80001800 = 0xB002D105;
|
|
|
|
DCFlushRange((void *)(0x80001800), 4);
|
|
|
|
ICInvalidateRange((void *)(0x80001800), 4);
|
|
|
|
|
|
|
|
*(vu32*)0xCC003024 |= 7;
|
|
|
|
}
|
2012-04-26 19:35:13 +02:00
|
|
|
|
|
|
|
void DML_New_SetBootDiscOption()
|
|
|
|
{
|
|
|
|
gprintf("Booting GC game\n");
|
|
|
|
|
2012-05-18 22:13:26 +02:00
|
|
|
DMLCfg = (DML_CFG*)MEM1_alloc(sizeof(DML_CFG));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(DMLCfg == NULL)
|
|
|
|
return;
|
2012-04-26 19:35:13 +02:00
|
|
|
memset(DMLCfg, 0, sizeof(DML_CFG));
|
|
|
|
|
|
|
|
DMLCfg->Magicbytes = 0xD1050CF6;
|
|
|
|
DMLCfg->CfgVersion = 0x00000001;
|
|
|
|
|
|
|
|
DMLCfg->Config |= DML_CFG_BOOT_DISC;
|
2012-05-08 22:38:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DML_New_WriteOptions()
|
|
|
|
{
|
|
|
|
if(DMLCfg == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//Write options into memory
|
|
|
|
memcpy((void *)0x80001700, DMLCfg, sizeof(DML_CFG));
|
|
|
|
DCFlushRange((void *)(0x80001700), sizeof(DML_CFG));
|
2012-04-26 19:35:13 +02:00
|
|
|
|
|
|
|
//DML v1.2+
|
2012-05-08 22:38:50 +02:00
|
|
|
memcpy((void *)0x81200000, DMLCfg, sizeof(DML_CFG));
|
|
|
|
DCFlushRange((void *)(0x81200000), sizeof(DML_CFG));
|
2012-04-26 19:35:13 +02:00
|
|
|
|
2012-05-18 22:13:26 +02:00
|
|
|
MEM1_free(DMLCfg);
|
2012-04-26 19:35:13 +02:00
|
|
|
}
|