2012-10-14 19:18:13 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
|
|
|
|
#include "frag.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "cios.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "wdvd.h"
|
2012-10-21 17:28:00 +02:00
|
|
|
#include "video_tinyload.h"
|
2012-10-14 19:18:13 +02:00
|
|
|
|
|
|
|
/* Constants */
|
2012-10-20 15:24:30 +02:00
|
|
|
#define PART_INFO_OFFSET 0x10000
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2013-12-18 19:33:40 +01:00
|
|
|
s32 Disc_Open(u8 type)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
2021-11-29 18:36:30 +01:00
|
|
|
if(type > 0)// if not a wii disc (wbfs ext or wbfs drive)
|
2013-12-18 19:33:40 +01:00
|
|
|
{ /* Reset drive */
|
|
|
|
s32 ret = WDVD_Reset();
|
|
|
|
if(ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
2012-10-14 19:18:13 +02:00
|
|
|
|
|
|
|
/* Read disc ID */
|
2013-12-18 19:33:40 +01:00
|
|
|
return WDVD_ReadDiskId((u8*)Disc_ID);
|
2012-10-14 19:18:13 +02:00
|
|
|
}
|
|
|
|
|
2021-11-29 18:36:30 +01:00
|
|
|
void Disc_SetLowMem(void)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
|
|
|
/* Setup low memory */
|
|
|
|
*Sys_Magic = 0x0D15EA5E; // Standard Boot Code
|
|
|
|
*Sys_Version = 0x00000001; // Version
|
|
|
|
*Arena_L = 0x00000000; // Arena Low
|
2022-02-07 14:19:27 +01:00
|
|
|
*BI2 = 0x817E5480; // BI2
|
2012-10-14 19:18:13 +02:00
|
|
|
*Bus_Speed = 0x0E7BE2C0; // Console Bus Speed
|
|
|
|
*CPU_Speed = 0x2B73A840; // Console CPU Speed
|
|
|
|
*Assembler = 0x38A00040; // Assembler
|
2012-10-20 15:24:30 +02:00
|
|
|
*OS_Thread = 0x80431A80; // Thread Init
|
2012-10-14 19:18:13 +02:00
|
|
|
*Dev_Debugger = 0x81800000; // Dev Debugger Monitor Address
|
|
|
|
*Simulated_Mem = 0x01800000; // Simulated Memory Size
|
2021-11-29 18:36:30 +01:00
|
|
|
*(vu32 *) 0xCD00643C = 0x00000000; // 32Mhz on Bus
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2022-02-16 15:51:02 +01:00
|
|
|
if(CurrentIOS.Type != IOS_TYPE_HERMES && CurrentIOS.Revision >= 18)
|
|
|
|
*GameID_Address = 0x80000000; // Fix for Sam & Max (WiiPower)
|
|
|
|
|
2012-10-20 17:43:48 +02:00
|
|
|
/* Copy Disc ID */
|
|
|
|
memcpy((void*)Online_Check, (void*)Disc_ID, 4);
|
2013-01-05 21:06:29 +01:00
|
|
|
}
|
|
|
|
|
2012-10-20 15:24:30 +02:00
|
|
|
/* Thanks Tinyload */
|
|
|
|
static struct {
|
|
|
|
u32 offset;
|
|
|
|
u32 type;
|
|
|
|
} partition_table[32] ATTRIBUTE_ALIGN(32);
|
2012-10-14 19:18:13 +02:00
|
|
|
|
2012-10-20 15:24:30 +02:00
|
|
|
static struct {
|
|
|
|
u32 count;
|
|
|
|
u32 offset;
|
|
|
|
u32 pad[6];
|
|
|
|
} part_table_info ATTRIBUTE_ALIGN(32);
|
|
|
|
|
|
|
|
s32 Disc_FindPartition(u32 *outbuf)
|
|
|
|
{
|
|
|
|
u32 offset = 0;
|
|
|
|
u32 cnt = 0;
|
2012-10-14 19:18:13 +02:00
|
|
|
|
|
|
|
/* Read partition info */
|
2012-10-20 15:24:30 +02:00
|
|
|
s32 ret = WDVD_UnencryptedRead(&part_table_info, sizeof(part_table_info), PART_INFO_OFFSET);
|
2012-10-14 19:18:13 +02:00
|
|
|
if(ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Read partition table */
|
2012-10-20 15:24:30 +02:00
|
|
|
ret = WDVD_UnencryptedRead(&partition_table, sizeof(partition_table), part_table_info.offset);
|
|
|
|
if(ret < 0)
|
2012-10-14 19:18:13 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Find game partition */
|
2012-10-20 15:24:30 +02:00
|
|
|
for(cnt = 0; cnt < part_table_info.count; cnt++)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
|
|
|
/* Game partition */
|
2012-10-20 15:24:30 +02:00
|
|
|
if(partition_table[cnt].type == 0)
|
2012-10-21 17:28:00 +02:00
|
|
|
{
|
2012-10-20 15:24:30 +02:00
|
|
|
offset = partition_table[cnt].offset;
|
2012-10-21 17:28:00 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-10-14 19:18:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No game partition found */
|
2012-10-20 15:24:30 +02:00
|
|
|
if(offset == 0)
|
2012-10-14 19:18:13 +02:00
|
|
|
return -1;
|
2012-10-20 15:24:30 +02:00
|
|
|
WDVD_Seek(offset);
|
2012-10-14 19:18:13 +02:00
|
|
|
|
|
|
|
/* Set output buffer */
|
|
|
|
*outbuf = offset;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GXRModeObj *Disc_SelectVMode(u8 videoselected, u32 *rmode_reg)
|
|
|
|
{
|
|
|
|
GXRModeObj *rmode = VIDEO_GetPreferredMode(0);
|
|
|
|
|
|
|
|
/* Get video mode configuration */
|
|
|
|
bool progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable();
|
|
|
|
|
|
|
|
/* Select video mode register */
|
|
|
|
switch (CONF_GetVideo())
|
|
|
|
{
|
|
|
|
case CONF_VIDEO_PAL:
|
|
|
|
if (CONF_GetEuRGB60() > 0)
|
|
|
|
{
|
|
|
|
*rmode_reg = VI_EURGB60;
|
|
|
|
rmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*rmode_reg = VI_PAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONF_VIDEO_MPAL:
|
|
|
|
*rmode_reg = VI_MPAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONF_VIDEO_NTSC:
|
|
|
|
*rmode_reg = VI_NTSC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-20 15:24:30 +02:00
|
|
|
const char DiscRegion = ((u8*)Disc_ID)[3];
|
2012-10-14 19:18:13 +02:00
|
|
|
switch(videoselected)
|
|
|
|
{
|
|
|
|
case 0: // DEFAULT (DISC/GAME)
|
|
|
|
/* Select video mode */
|
2012-10-20 15:24:30 +02:00
|
|
|
switch(DiscRegion)
|
2012-10-14 19:18:13 +02:00
|
|
|
{
|
|
|
|
case 'W':
|
|
|
|
break; // Don't overwrite wiiware video modes.
|
|
|
|
// PAL
|
|
|
|
case 'D':
|
|
|
|
case 'F':
|
|
|
|
case 'P':
|
|
|
|
case 'X':
|
|
|
|
case 'Y':
|
|
|
|
if(CONF_GetVideo() != CONF_VIDEO_PAL)
|
|
|
|
{
|
|
|
|
*rmode_reg = VI_PAL;
|
|
|
|
rmode = progressive ? &TVNtsc480Prog : &TVNtsc480IntDf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
// NTSC
|
|
|
|
case 'E':
|
|
|
|
case 'J':
|
|
|
|
default:
|
|
|
|
if(CONF_GetVideo() != CONF_VIDEO_NTSC)
|
|
|
|
{
|
|
|
|
*rmode_reg = VI_NTSC;
|
|
|
|
rmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: // SYSTEM
|
|
|
|
break;
|
|
|
|
case 2: // PAL50
|
|
|
|
rmode = &TVPal528IntDf;
|
|
|
|
*rmode_reg = rmode->viTVMode >> 2;
|
|
|
|
break;
|
|
|
|
case 3: // PAL60
|
|
|
|
rmode = progressive ? &TVNtsc480Prog : &TVEurgb60Hz480IntDf;
|
|
|
|
*rmode_reg = progressive ? TVEurgb60Hz480Prog.viTVMode >> 2 : rmode->viTVMode >> 2;
|
|
|
|
break;
|
|
|
|
case 4: // NTSC
|
|
|
|
rmode = progressive ? &TVNtsc480Prog : &TVNtsc480IntDf;
|
|
|
|
*rmode_reg = rmode->viTVMode >> 2;
|
|
|
|
break;
|
|
|
|
case 5: // PROGRESSIVE 480P
|
|
|
|
rmode = &TVNtsc480Prog;
|
2012-10-20 15:24:30 +02:00
|
|
|
*rmode_reg = DiscRegion == 'P' ? TVEurgb60Hz480Prog.viTVMode >> 2 : rmode->viTVMode >> 2;
|
2012-10-14 19:18:13 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rmode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Disc_SetVMode(GXRModeObj *rmode, u32 rmode_reg)
|
|
|
|
{
|
2012-10-21 17:28:00 +02:00
|
|
|
/* Remove Load Bar */
|
|
|
|
video_clear();
|
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
/* Set video mode register */
|
|
|
|
*Video_Mode = rmode_reg;
|
|
|
|
DCFlushRange((void*)Video_Mode, 4);
|
|
|
|
|
|
|
|
/* Set video mode */
|
|
|
|
if(rmode != 0)
|
|
|
|
VIDEO_Configure(rmode);
|
|
|
|
|
|
|
|
/* Setup video */
|
|
|
|
VIDEO_SetBlack(FALSE);
|
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
if(rmode->viTVMode & VI_NON_INTERLACE)
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
else while(VIDEO_GetNextField())
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
|
|
|
|
/* Set black and flush */
|
|
|
|
VIDEO_SetBlack(TRUE);
|
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
if(rmode->viTVMode & VI_NON_INTERLACE)
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
else while(VIDEO_GetNextField())
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 wbfsDev = 0;
|
|
|
|
u32 wbfs_part_idx = 0;
|
|
|
|
FragList *frag_list = NULL;
|
2014-03-23 18:40:31 +01:00
|
|
|
|
|
|
|
void copy_frag_list(FragList *src)
|
|
|
|
{
|
|
|
|
if(src == NULL)
|
|
|
|
return;
|
|
|
|
frag_list = malloc(sizeof(FragList)); //internal copy
|
|
|
|
memcpy(frag_list, src, sizeof(FragList));
|
|
|
|
}
|
|
|
|
|
2012-10-14 19:18:13 +02:00
|
|
|
static int set_frag_list()
|
|
|
|
{
|
|
|
|
// (+1 for header which is same size as fragment)
|
|
|
|
int size = sizeof(Fragment) * (frag_list->num + 1);
|
|
|
|
DCFlushRange(frag_list, size);
|
|
|
|
return WDVD_SetFragList(wbfsDev, frag_list, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Disc_SetUSB(const u8 *id, bool frag)
|
|
|
|
{
|
|
|
|
/* ENABLE USB in cIOS */
|
|
|
|
if(id)
|
|
|
|
{
|
2022-02-16 15:51:02 +01:00
|
|
|
if(frag)// true for wii games in wbfs folder
|
2012-10-14 19:18:13 +02:00
|
|
|
return set_frag_list();
|
2022-02-16 15:51:02 +01:00
|
|
|
/* for WBFS partitioned drives */
|
2012-10-14 19:18:13 +02:00
|
|
|
s32 part = -1;
|
|
|
|
if(CurrentIOS.Type == IOS_TYPE_HERMES)
|
|
|
|
part = wbfs_part_idx ? wbfs_part_idx - 1 : 0;
|
|
|
|
return WDVD_SetUSBMode(wbfsDev, (u8*)id, part);
|
|
|
|
}
|
2022-02-16 15:51:02 +01:00
|
|
|
/* DISABLE USB in cIOS for actual disc */
|
2012-10-14 19:18:13 +02:00
|
|
|
return WDVD_SetUSBMode(0, NULL, -1);
|
|
|
|
}
|