2012-01-21 21:57:41 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <ogcsys.h>
|
|
|
|
|
#include <unistd.h>
|
2012-05-15 23:33:53 +02:00
|
|
|
|
#include <ogc/lwp_threads.h>
|
2012-01-21 21:57:41 +01:00
|
|
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
|
#include <ogc/machine/processor.h>
|
|
|
|
|
|
|
|
|
|
#include "disc.h"
|
|
|
|
|
#include "wdvd.h"
|
|
|
|
|
#include "sys.h"
|
|
|
|
|
|
|
|
|
|
#include "fst.h"
|
|
|
|
|
#include "wbfs.h"
|
|
|
|
|
#include "frag.h"
|
|
|
|
|
#include "wip.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
|
|
2012-06-16 19:03:23 +02:00
|
|
|
|
#include "utils.h"
|
2012-07-16 16:05:57 +02:00
|
|
|
|
#include "cios.h"
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
2012-08-05 15:48:15 +02:00
|
|
|
|
#include "devicemounter/usbstorage.h"
|
2012-12-08 17:17:35 +01:00
|
|
|
|
#include "gecko/gecko.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
|
#include "memory/memory.h"
|
|
|
|
|
|
2012-11-18 14:40:26 +01:00
|
|
|
|
struct discHdr wii_hdr ATTRIBUTE_ALIGN(32);
|
|
|
|
|
struct gc_discHdr gc_hdr ATTRIBUTE_ALIGN(32);
|
|
|
|
|
static u8 *diskid = (u8*)0x80000000;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
2012-07-12 02:34:32 +02:00
|
|
|
|
s32 Disc_Open(bool boot_disc)
|
2012-01-21 21:57:41 +01:00
|
|
|
|
{
|
|
|
|
|
/* Reset drive */
|
|
|
|
|
s32 ret = WDVD_Reset();
|
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
|
|
|
|
|
|
memset(diskid, 0, 32);
|
|
|
|
|
|
|
|
|
|
/* Read disc ID */
|
2012-01-23 16:57:30 +01:00
|
|
|
|
ret = WDVD_ReadDiskId(diskid);
|
2012-03-18 14:29:17 +01:00
|
|
|
|
|
2012-05-04 07:09:40 +02:00
|
|
|
|
/* Directly set Audio Streaming for GC*/
|
2012-07-12 02:34:32 +02:00
|
|
|
|
if(boot_disc)
|
2012-08-17 17:48:11 +02:00
|
|
|
|
gprintf("Setting Audio Streaming for GC Games %s\n", WDVD_SetStreaming() == 0 ? "succeed" : "failed");
|
2012-03-18 14:29:17 +01:00
|
|
|
|
|
2012-01-23 16:57:30 +01:00
|
|
|
|
return ret;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 Disc_Wait(void)
|
|
|
|
|
{
|
|
|
|
|
u32 cover = 0;
|
|
|
|
|
int icounter = 0;
|
|
|
|
|
|
|
|
|
|
/* Wait for disc */
|
|
|
|
|
while (!(cover & 0x2))
|
|
|
|
|
{
|
|
|
|
|
/* Get cover status */
|
|
|
|
|
s32 ret = WDVD_GetCoverStatus(&cover);
|
|
|
|
|
if (ret < 0) return ret;
|
|
|
|
|
|
|
|
|
|
// 10 tries to make sure it doesn<73>t "freeze" in Install dialog
|
|
|
|
|
// if no Game Disc is insert
|
|
|
|
|
icounter++;
|
|
|
|
|
sleep(1);
|
|
|
|
|
if(icounter > 10)
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 Disc_ReadHeader(void *outbuf)
|
|
|
|
|
{
|
|
|
|
|
/* Read Wii disc header */
|
|
|
|
|
return WDVD_UnencryptedRead(outbuf, sizeof(struct discHdr), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 Disc_ReadGCHeader(void *outbuf)
|
|
|
|
|
{
|
|
|
|
|
/* Read GC disc header */
|
|
|
|
|
return WDVD_UnencryptedRead(outbuf, sizeof(struct gc_discHdr), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 Disc_Type(bool gc)
|
|
|
|
|
{
|
|
|
|
|
s32 ret;
|
|
|
|
|
u32 check;
|
|
|
|
|
u32 magic;
|
|
|
|
|
|
|
|
|
|
if (!gc)
|
|
|
|
|
{
|
|
|
|
|
check = WII_MAGIC;
|
2012-11-18 14:40:26 +01:00
|
|
|
|
ret = Disc_ReadHeader(&wii_hdr);
|
|
|
|
|
magic = wii_hdr.magic;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
check = GC_MAGIC;
|
2012-11-18 14:40:26 +01:00
|
|
|
|
ret = Disc_ReadGCHeader(&gc_hdr);
|
|
|
|
|
if(strcmp((char *)gc_hdr.id, "GCOPDV") == 0)
|
2012-05-24 20:48:26 +02:00
|
|
|
|
magic = GC_MAGIC;
|
2012-03-09 19:15:07 +01:00
|
|
|
|
else
|
2012-11-18 14:40:26 +01:00
|
|
|
|
magic = gc_hdr.magic;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-24 20:48:26 +02:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
return ret;
|
2012-01-21 21:57:41 +01:00
|
|
|
|
|
|
|
|
|
/* Check magic word */
|
|
|
|
|
if (magic != check) return -1;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 Disc_IsWii(void)
|
|
|
|
|
{
|
|
|
|
|
return Disc_Type(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 Disc_IsGC(void)
|
|
|
|
|
{
|
|
|
|
|
return Disc_Type(1);
|
|
|
|
|
}
|