diff --git a/Makefile.wii b/Makefile.wii index d68623b..6eb9481 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -34,7 +34,7 @@ LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lfat -lwiiuse -lbte -logc -lm -lz -lsamplerate +LIBS := -ldi -lfat -lwiiuse -lbte -logc -lm -lz -lsamplerate #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/source/ngc/gui/dvd.c b/source/ngc/gui/dvd.c index 21b3e55..d402392 100644 --- a/source/ngc/gui/dvd.c +++ b/source/ngc/gui/dvd.c @@ -15,32 +15,31 @@ * To keep libOGC stable, make sure you call DVD_Init before using * these functions. ***************************************************************************/ - #include "shared.h" +#ifdef HW_RVL +#include "di/di.h" +#endif -#ifdef HW_DOL -#include "dvd.h" -u64 DvdMaxOffset = 0x57057C00; - -/** DVD I/O Address base **/ -static vu32* const dvd = (u32*)0xCC006000; -static unsigned char *inquiry=(unsigned char *)0x80000004; - -/** Due to lack of memory, we'll use this little 2k keyhole for all DVD operations **/ -unsigned char DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32); +#ifndef HW_RVL +static u64 DvdMaxOffset = 0x57057C00; /* 1.4 GB max. */ +static vu32* const dvd = (u32*)0xCC006000; /* DVD I/O Address base */ +static u8 *inquiry=(unsigned char *)0x80000004; #else -#include "wdvd.h" -u64 DvdMaxOffset = 0x118244F00LL; +static u64 DvdMaxOffset = 0x118244F00LL; /* 4.7 GB max. */ #endif +/* 2k buffer for all DVD operations */ +u8 DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32); + + /*************************************************************************** * dvd_read * * Read DVD disc sectors ***************************************************************************/ -int dvd_read (void *dst, unsigned int len, u64 offset) +u32 dvd_read (void *dst, u32 len, u64 offset) { /*** We only allow 2k reads **/ if (len > 2048) return 0; @@ -48,10 +47,10 @@ int dvd_read (void *dst, unsigned int len, u64 offset) /*** Let's not read past end of DVD ***/ if(offset < DvdMaxOffset) { - -#ifdef HW_DOL unsigned char *buffer = (unsigned char *) (unsigned int) DVDreadbuffer; DCInvalidateRange((void *)buffer, len); + +#ifndef HW_RVL dvd[0] = 0x2E; dvd[1] = 0; dvd[2] = 0xA8000000; @@ -63,46 +62,29 @@ int dvd_read (void *dst, unsigned int len, u64 offset) /*** Enable reading with DMA ***/ while (dvd[7] & 1); - memcpy (dst, buffer, len); /*** Ensure it has completed ***/ if (dvd[0] & 0x4) return 0; - - return 1; -#elif WII_DVD - return WDVD_LowUnencryptedRead((unsigned char **)&dst, len, (u32)(offset >> 2)); +#else + int ret = DI_ReadDVD(buffer, len , (u32)(offset >> 2)); + if (ret) + { + char msg[50]; + u32 val; + DI_GetError(&val); + sprintf(msg, "DI Read Error: 0x%08X\n",val); + return 0; + } #endif + + memcpy (dst, buffer, len); + return 1; } return 0; } -/**************************************************************************** - * uselessinquiry - * - * As the name suggests, this function is quite useless. - * It's only purpose is to stop any pending DVD interrupts while we use the - * memcard interface. - * - * libOGC tends to foul up if you don't, and sometimes does if you do! - ****************************************************************************/ -#ifdef HW_DOL -void uselessinquiry () -{ - dvd[0] = 0; - dvd[1] = 0; - dvd[2] = 0x12000000; - dvd[3] = 0; - dvd[4] = 0x20; - dvd[5] = 0x80000000; - dvd[6] = 0x20; - dvd[7] = 1; - - while (dvd[7] & 1); -} -#endif - /**************************************************************************** * dvd_motor_off * @@ -110,9 +92,9 @@ void uselessinquiry () * * This can be used to prevent the Disc from spinning during playtime ****************************************************************************/ -#ifdef HW_DOL void dvd_motor_off( ) { +#ifndef HW_RVL dvd[0] = 0x2e; dvd[1] = 0; dvd[2] = 0xe3000000; @@ -126,8 +108,35 @@ void dvd_motor_off( ) /*** PSO Stops blackscreen at reload ***/ dvd[0] = 0x14; dvd[1] = 0; -} + +#else + DI_StopMotor(); #endif +} + +#ifndef HW_RVL +/**************************************************************************** + * uselessinquiry + * + * As the name suggests, this function is quite useless. + * It's only purpose is to stop any pending DVD interrupts while we use the + * memcard interface. + * + * libOGC tends to foul up if you don't, and sometimes does if you do! + ****************************************************************************/ +void uselessinquiry () +{ + dvd[0] = 0; + dvd[1] = 0; + dvd[2] = 0x12000000; + dvd[3] = 0; + dvd[4] = 0x20; + dvd[5] = 0x80000000; + dvd[6] = 0x20; + dvd[7] = 1; + + while (dvd[7] & 1); +} /**************************************************************************** * dvd_drive_detect() @@ -135,7 +144,6 @@ void dvd_motor_off( ) * Detect the DVD Drive Type * ****************************************************************************/ -#ifdef HW_DOL void dvd_drive_detect() { dvd[0] = 0x2e; diff --git a/source/ngc/gui/dvd.h b/source/ngc/gui/dvd.h index 6885e59..c7728d9 100644 --- a/source/ngc/gui/dvd.h +++ b/source/ngc/gui/dvd.h @@ -15,9 +15,15 @@ * To keep libOGC stable, make sure you call DVD_Init before using * these functions. ***************************************************************************/ +#ifndef _DVD_H_ +#define _DVD_H_ -extern int dvd_read (void *dst, unsigned int len, u64 offset); -extern void uselessinquiry (); +extern u32 dvd_read (void *dst, u32 len, u64 offset); extern void dvd_motor_off (); -extern void dvd_drive_detect(); +#ifndef HW_RVL +extern void uselessinquiry (); +extern void dvd_drive_detect(); +#endif + +#endif diff --git a/source/ngc/gui/fileio.h b/source/ngc/gui/fileio.h index c799d2e..8941670 100644 --- a/source/ngc/gui/fileio.h +++ b/source/ngc/gui/fileio.h @@ -5,8 +5,8 @@ * Only partial support is included, in that only the first file within the archive * is considered to be a ROM image. ***************************************************************************/ -#ifndef _UNZIP_H_ -#define _UNZIP_H_ +#ifndef _FILEIO_H_ +#define _FILEIO_H_ extern int IsZipFile (char *buffer); int UnZipDVD (unsigned char *outbuffer, u64 discoffset, int length); diff --git a/source/ngc/gui/filesel.c b/source/ngc/gui/filesel.c index 8774ac5..c261abc 100644 --- a/source/ngc/gui/filesel.c +++ b/source/ngc/gui/filesel.c @@ -11,11 +11,14 @@ * ***************************************************************************/ #include "shared.h" -#include "dvd.h" #include "iso9660.h" #include "font.h" #include "fileio.h" #include "history.h" +#include "dvd.h" +#ifdef HW_RVL +#include "di/di.h" +#endif #define PAGESIZE 12 @@ -31,12 +34,8 @@ static u8 UseSDCARD = 0; static u8 UseHistory = 0; static int LoadFile (unsigned char *buffer); -/* globals */ -FILE *sdfile; - - /*************************************************************************** - * FileSortCallback + * FileSortCallback (Marty Disibio) * * Quick sort callback to sort file entries with the following order: * . @@ -416,10 +415,23 @@ void OpenDVD () if (!getpvd()) { - ShowAction("Mounting DVD ... Wait"); + /* mount DVD */ + ShowAction("Mounting DVD ... Wait"); + #ifndef HW_RVL DVD_Mount(); -#endif +#else + DI_Mount(); + while(DI_GetStatus() & DVD_INIT); + if (!(DI_GetStatus() & DVD_READY)) + { + char msg[50]; + sprintf(msg, "DI Status Error: 0x%08X\n",DI_GetStatus()); + WaitPrompt(msg); + return; + } +#endif + haveDVDdir = 0; if (!getpvd()) { @@ -494,6 +506,11 @@ int OpenSD () return 1; } +/**************************************************************************** + * OpenHistory + * + * Function to load a recent file from SDCARD (Marty Disibio) + ****************************************************************************/ void OpenHistory() { int i; @@ -501,19 +518,15 @@ void OpenHistory() UseSDCARD = 1; UseHistory = 1; - /* don't mess with SD entries */ - haveSDdir = 0; + /* don't mess with other entries */ + haveSDdir = 0; + haveDVDdir = 0; /* reinit selector */ old_selection = selection = offset = old_offset = 0; - /* Reset SDCARD root directory */ - /* Make this empty because the history */ - /* entry will contain the entire path. */ - /*sprintf (rootSDdir, "");*/ - - /* Recreate the file listing from the history - * as if all of the roms were in the same directory. */ + /* Recreate the file listing from the history + * as if all of the roms were in the same directory. */ ShowAction("Reading Files ..."); maxfiles = 0; @@ -561,6 +574,7 @@ static int LoadFile (unsigned char *buffer) u64 discoffset = 0; char readbuffer[2048]; char fname[MAXPATHLEN]; + FILE *sdfile = NULL; if (rootdirlength == 0) return 0; diff --git a/source/ngc/gui/font.h b/source/ngc/gui/font.h index af9838a..8f064a8 100644 --- a/source/ngc/gui/font.h +++ b/source/ngc/gui/font.h @@ -4,6 +4,8 @@ * Based on Qoob MP3 Player Font * Added IPL font extraction *****************************************************************************/ +#ifndef _FONT_H +#define _FONT_H extern void init_font(void); extern void WriteCentre_HL( int y, char *string); @@ -21,3 +23,5 @@ extern int fheight; extern int font_size[256]; extern u16 back_framewidth; extern u8 SILENT; + +#endif diff --git a/source/ngc/gui/iso9660.h b/source/ngc/gui/iso9660.h index 6cf153c..ad2d76e 100644 --- a/source/ngc/gui/iso9660.h +++ b/source/ngc/gui/iso9660.h @@ -5,8 +5,8 @@ * This is not intended as a complete guide to ISO9660. * Here I use the bare minimum! ***************************************************************************/ - #ifndef _ISO9660_H - #define _ISO9660_H +#ifndef _ISO9660_H +#define _ISO9660_H #define MAXJOLIET 256 #define MAXFILES 1000 /** Restrict to 1000 files per dir **/ diff --git a/source/ngc/gui/memfile.c b/source/ngc/gui/memfile.c index cb7ba34..349b349 100644 --- a/source/ngc/gui/memfile.c +++ b/source/ngc/gui/memfile.c @@ -4,9 +4,11 @@ * ***************************************************************************/ #include "shared.h" -#include "dvd.h" #include "font.h" -#include "saveicon.h" /*** Nice little icon - thanks brakken! ***/ +#include "saveicon.h" +#ifndef HW_RVL +#include "dvd.h" +#endif #include #include diff --git a/source/ngc/ngc.c b/source/ngc/ngc.c index f69fce6..e6ab2dd 100644 --- a/source/ngc/ngc.c +++ b/source/ngc/ngc.c @@ -19,12 +19,12 @@ ***************************************************************************/ #include "shared.h" #include "gcaram.h" -#include "dvd.h" #include "font.h" #include "history.h" - -#ifdef WII_DVD -#include "wdvd.h" +#ifndef HW_RVL +#include "dvd.h" +#else +#include "di/di.h" #endif /*************************************************************************** @@ -46,6 +46,13 @@ static void load_bios() /* update BIOS flags */ config.bios_enabled |= 2; + + if (config.bios_enabled == 3) + { + /* initialize system */ + system_init (); + audio_init(48000); + } } static void init_machine() @@ -53,9 +60,6 @@ static void init_machine() /* Allocate cart_rom here */ cart_rom = memalign(32, 0xA00000); - /* BIOS support */ - load_bios(); - /* allocate global work bitmap */ memset (&bitmap, 0, sizeof (bitmap)); bitmap.width = 360; @@ -73,6 +77,9 @@ static void init_machine() /* default system */ input.system[0] = SYSTEM_GAMEPAD; input.system[1] = SYSTEM_GAMEPAD; + + /* BIOS support */ + load_bios(); } /************************************************** @@ -96,35 +103,25 @@ int frameticker = 0; int main (int argc, char *argv[]) { +#ifdef HW_RVL + /* initialize Wii DVD interface first */ + DI_Init(); +#endif + u16 usBetweenFrames; long long now, prev; int RenderedFrameCount = 0; int FrameCount = 0; - /* load hacked IOS with full access to DVD interface (WIP) */ -#ifdef WII_DVD - IOS_ReloadIOS(5); -#endif - /* Initialize OGC subsystems */ ogc_video__init(); ogc_input__init(); ogc_audio__init(); - /* Initialize DVD interface */ #ifndef HW_RVL + /* Initialize GC DVD interface */ DVD_Init (); dvd_drive_detect(); - -#elif WII_DVD - if (WDVD_Init()) - { - if (WDVD_Reset()) - { - u64 id; - WDVD_LowReadDiskId(&id); - } - } #endif /* Initialize SDCARD Interface (LibFAT) */ diff --git a/source/ngc/wdvd.c b/source/ngc/wdvd.c deleted file mode 100644 index aca9fae..0000000 --- a/source/ngc/wdvd.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Wii DVD interface API - * Copyright (C) 2008 Jeff Epler - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifdef WII_DVD -#include -#include -#include -#include "wdvd.h" - -static int di_fd = -1; -static s32 di_hid = 0; - - - -#include -#define DEBUG - -#ifdef DEBUG -#define debug_printf printf -#define debug_wait printf -#else -#define debug_printf(...) ; -#define debug_wait(...) ; -#endif - -bool WDVD_Init() -{ - if(di_fd >= 0) return 1; - - di_fd = IOS_Open("/dev/do", 0); - if(di_fd < 0) { - debug_printf("IOS_Open(/dev/di) failed with code %d\n", di_fd); - return 0; - } - - di_hid = iosCreateHeap(0x10000); - if(!di_hid) { - IOS_Close(di_fd); - di_fd = -1; - debug_printf("iosCreateHeap(0x20) failed with code %d\n", di_hid); - return 0; - } - - debug_printf("fd=%d hid=%d\n", di_fd, di_hid); - return 1; -} - -bool WDVD_Reset() -{ - bool result = false; - char *inbuf = (char*)iosAlloc(di_hid, 0x20); - char *outbuf = (char*)iosAlloc(di_hid, 0x20); - if(!inbuf || !outbuf) - goto out; - - ((u32*)inbuf)[0x00] = 0x8A000000; - ((u32*)inbuf)[0x01] = 1; - - result = IOS_Ioctl( di_fd, 0x8A, inbuf, 0x20, outbuf, 0x20); -out: - if(outbuf) iosFree(di_hid, outbuf); - if(inbuf) iosFree(di_hid, inbuf); - return result; -} - -#define max(a,b) ((a) > (b) ? (a) : (b)) - -unsigned char* ios_command = 0; -unsigned char* ios_out = 0; -unsigned int ios_outlen = 0; - -void WDVD_AllocCommand() -{ - if (ios_command == 0) - ios_command = (unsigned char*)iosAlloc(di_hid, 0x20); -} - -void WDVD_AllocOutput(unsigned int length) -{ - if (ios_out == 0 || ios_outlen != length) - { - if (ios_out) - iosFree(di_hid, ios_out); - - ios_out = (unsigned char*)iosAlloc(di_hid, max(length, 0x20)); - ios_outlen = length; - } -} - -int WDVD_LowUnencryptedRead(unsigned char **poutbuf, u32 len, u32 offset) -{ - WDVD_AllocCommand(); - WDVD_AllocOutput(len); - - unsigned char* inbuf = ios_command; - unsigned char* outbuf = ios_out; - - *poutbuf = ios_out; - int result = 0; - - if(!inbuf || !outbuf) { result = -1; goto out; } - - ((u32*)inbuf)[0] = 0x8d000000; - ((u32*)inbuf)[1] = len; - ((u32*)inbuf)[2] = offset; - -// memset(outbuf, 0x00, len); - - result = IOS_Ioctl(di_fd, 0x8d, inbuf, 0x20, outbuf, len); - - if (result != 1) - debug_printf("-> %d\n", result); - -// if(result >= 0) { -// memcpy(buf, outbuf, len); -// } - -out: - //if(outbuf) iosFree(di_hid, outbuf); - //if(inbuf) iosFree(di_hid, inbuf); - - return result; -} - -int WDVD_LowReadDiskId(u64 *id) -{ - int result; - char *inbuf = (char*)iosAlloc(di_hid, 0x20); - char *outbuf = (char*)iosAlloc(di_hid, 0x20); - if(!inbuf || !outbuf) { result = -1; goto out; } - ((u32*)inbuf)[0] = 0x70000000; - - *(u64*)outbuf = 0; - result = IOS_Ioctl(di_fd, 0x8D, inbuf, 0x20, outbuf, 0x20); - - *id = *(u64*) outbuf; - -out: - if(inbuf) iosFree(di_hid, inbuf); - if(outbuf) iosFree(di_hid, outbuf); - - return result; -} -#endif diff --git a/source/ngc/wdvd.h b/source/ngc/wdvd.h deleted file mode 100644 index 4f1af8a..0000000 --- a/source/ngc/wdvd.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Wii DVD interface API - * Copyright (C) 2008 Jeff Epler - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _WDVD_H_ -#define _WDVD_H_ -bool WDVD_Init(); -bool WDVD_Reset(); - -int WDVD_LowUnencryptedRead(unsigned char **outbuf, u32 len, u32 offset); -int WDVD_LowReadDiskId(u64 *id); -#endif