mirror of
https://github.com/dborth/fceugx.git
synced 2024-12-04 22:34:14 +01:00
Apparently, no one plays this. It wasn't loading any ROMs. Fixed that, and DVD reading in GC mode (but zip support may be broken).
This commit is contained in:
parent
3868e2ba51
commit
d5a048208f
@ -29,15 +29,13 @@
|
||||
|
||||
FILEENTRIES filelist[MAXFILES];
|
||||
int maxfiles = 0;
|
||||
int offset = 0;
|
||||
u64 offset = 0;
|
||||
int selection = 0;
|
||||
|
||||
/*** DVD Read Buffer ***/
|
||||
|
||||
unsigned char readbuffer[2048] ATTRIBUTE_ALIGN(32);
|
||||
unsigned char DVDreadbuffer[2048] ATTRIBUTE_ALIGN (32);
|
||||
volatile long *dvd=(volatile long *)0xCC006000;
|
||||
static unsigned char *inquiry=(unsigned char *)0x80000004;
|
||||
extern void SendDriveCode( int model );
|
||||
extern int font_height;
|
||||
extern bool isZipFile();
|
||||
@ -53,7 +51,7 @@ extern int choosenSDSlot;
|
||||
extern int CentreTextPosition( char *text );*/
|
||||
|
||||
/** true if we the emulator is running on a wii **/
|
||||
bool isWii = false;
|
||||
extern bool isWii;
|
||||
|
||||
int UseSDCARD = 0;
|
||||
sd_file * filehandle;
|
||||
@ -189,23 +187,20 @@ unsigned int dvd_read_id(void *dst)
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int dvd_read(void *dst, unsigned int len, u64 offset)
|
||||
{
|
||||
unsigned int dvd_read(void *dst, unsigned int len, u64 offset) {
|
||||
unsigned char* buffer = (unsigned char*)(unsigned int)readbuffer;
|
||||
|
||||
unsigned char* buffer = (unsigned char*)(unsigned int)DVDreadbuffer;
|
||||
u32 offset32 = (u32)(offset >> 2);
|
||||
if (len > 2048)
|
||||
return 0;
|
||||
|
||||
if (len > 2048 )
|
||||
return 1;
|
||||
|
||||
DCInvalidateRange ((void *) buffer, len);
|
||||
|
||||
if (offset < 0x57057C00 || (isWii == true && offset < 0x1FD3E0000LL)) // don't read past the end of the dvd
|
||||
{
|
||||
DCInvalidateRange((void *) buffer, len);
|
||||
// don't read past 8,543,666,176 (DVD9)
|
||||
if (offset < 0x57057C00 || (isWii == true && offset < 0x1FD3E0000LL)) {
|
||||
offset >>= 2;
|
||||
dvd[0] = 0x2E;
|
||||
dvd[1] = 0;
|
||||
dvd[2] = 0xA8000000;
|
||||
dvd[3] = offset32;
|
||||
dvd[3] = (u32)offset;
|
||||
dvd[4] = len;
|
||||
dvd[5] = (unsigned long)buffer;
|
||||
dvd[6] = len;
|
||||
@ -213,13 +208,12 @@ unsigned int dvd_read(void *dst, unsigned int len, u64 offset)
|
||||
while (dvd[7] & 1);
|
||||
memcpy (dst, buffer, len);
|
||||
} else // Let's not read past end of DVD
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
if (dvd[0] & 0x4) /* Ensure it has completed */
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void dvd_reset(void)
|
||||
@ -242,57 +236,55 @@ void dvd_reset(void)
|
||||
static int IsJoliet = 0;
|
||||
static u64 rootdir = 0;
|
||||
static int rootdirlength = 0;
|
||||
static int shadowroot, shadowlength;
|
||||
int IsPVD()
|
||||
{
|
||||
int IsPVD() {
|
||||
int sector = 16;
|
||||
// u32 offset32;
|
||||
u32 rootdir32;
|
||||
|
||||
IsJoliet = rootdir = 0;
|
||||
rootdir = rootdirlength = 0;
|
||||
IsJoliet = -1;
|
||||
|
||||
/*** Read the ISO section looking for a valid
|
||||
Primary Volume Decriptor.
|
||||
Spec says first 8 characters are id ***/
|
||||
// Look for Joliet PVD first
|
||||
while ( sector < 32 ) {
|
||||
|
||||
dvd_read( &readbuffer, 2048, sector << 11 );
|
||||
if ( memcmp( &readbuffer, "\2CD001\1", 8 ) == 0 ) {
|
||||
//memcpy(&offset32, &readbuffer[PVDROOT + EXTENT], 4);
|
||||
//memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
//rootdir = (u64)offset32;
|
||||
memcpy(&rootdir, &readbuffer[PVDROOT + EXTENT], 4);
|
||||
memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
IsJoliet = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
sector++;
|
||||
}
|
||||
|
||||
if ( IsJoliet == 0 ) {
|
||||
sector = 16;
|
||||
|
||||
while ( sector < 32 ) {
|
||||
|
||||
if ( memcmp( &readbuffer, "\1CD001\1", 8 ) == 0 ) {
|
||||
/*memcpy(&offset32, &readbuffer[PVDROOT + EXTENT], 4);
|
||||
memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
rootdir = (u64)offset32;*/
|
||||
memcpy(&rootdir, &readbuffer[PVDROOT + EXTENT], 4);
|
||||
int res = dvd_read( &readbuffer, 2048, (u64)sector << 11 );
|
||||
if (res) {
|
||||
if ( memcmp( &readbuffer, "\2CD001\1", 8 ) == 0 ) {
|
||||
memcpy(&rootdir32, &readbuffer[PVDROOT + EXTENT], 4);
|
||||
rootdir = (u64)rootdir32;
|
||||
rootdir <<= 11;
|
||||
memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
IsJoliet = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
sector++;
|
||||
}
|
||||
} else
|
||||
return 0;
|
||||
sector++;
|
||||
}
|
||||
|
||||
rootdir <<= 11;
|
||||
shadowroot = rootdir;
|
||||
shadowlength = rootdirlength;
|
||||
if (IsJoliet > 0)
|
||||
return 1;
|
||||
|
||||
return IsJoliet;
|
||||
sector = 16;
|
||||
// Look for standard ISO9660 PVD
|
||||
while ( sector < 32 ) {
|
||||
int res = dvd_read( &readbuffer, 2048, (u64)sector << 11 );
|
||||
if (res) {
|
||||
if ( memcmp( &readbuffer, "\1CD001\1", 8 ) == 0 ) {
|
||||
memcpy(&rootdir32, &readbuffer[PVDROOT + EXTENT], 4);
|
||||
rootdir = (u64)rootdir32;
|
||||
rootdir <<= 11;
|
||||
memcpy(&rootdirlength, &readbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
IsJoliet = 0;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
return 0;
|
||||
sector++;
|
||||
}
|
||||
|
||||
return (IsJoliet == 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -301,37 +293,36 @@ int IsPVD()
|
||||
* Retrieve the current file directory entry
|
||||
****************************************************************************/
|
||||
static int diroffset = 0;
|
||||
int getfiles( int filecount )
|
||||
{
|
||||
char fname[256];
|
||||
int getfiles( int filecount ) {
|
||||
char fname[MAXJOLIET+1];
|
||||
char *ptr;
|
||||
char *filename;
|
||||
char *filenamelength;
|
||||
char *rr;
|
||||
int j;
|
||||
//u32 offset32;
|
||||
u32 offset32;
|
||||
|
||||
/*** Do some basic checks ***/
|
||||
if ( filecount == MAXFILES ) return 0;
|
||||
if ( diroffset >= 2048 ) return 0;
|
||||
|
||||
/*** Now decode this entry ***/
|
||||
if ( readbuffer[diroffset] != 0 )
|
||||
{
|
||||
|
||||
if ( readbuffer[diroffset] != 0 ) {
|
||||
ptr = (char *)&readbuffer[0];
|
||||
ptr += diroffset;
|
||||
filename = ptr + FILENAME;
|
||||
filenamelength = ptr + FILENAME_LENGTH;
|
||||
|
||||
/* Check for wrap round - illegal in ISO spec,
|
||||
* but certain crap writers do it! */
|
||||
if ( diroffset + readbuffer[diroffset] > 2048 ) return 0;
|
||||
|
||||
if ( *filenamelength ) {
|
||||
|
||||
memset(&fname, 0, 128);
|
||||
|
||||
/*** Return the values needed ***/
|
||||
if ( IsJoliet == 1 ) strcpy(fname, filename);
|
||||
if (!IsJoliet)
|
||||
strcpy(fname, filename);
|
||||
else {
|
||||
for ( j = 0; j < ( *filenamelength >> 1 ); j++ ) {
|
||||
fname[j] = filename[j*2+1];
|
||||
@ -339,14 +330,13 @@ int getfiles( int filecount )
|
||||
|
||||
fname[j] = 0;
|
||||
|
||||
if ( strlen(fname) >= MAXJOLIET ) fname[MAXJOLIET-1] = 0;
|
||||
|
||||
if ( strlen(fname) >= MAXJOLIET ) fname[MAXJOLIET] = 0;
|
||||
if ( strlen(fname) == 0 ) fname[0] = filename[0];
|
||||
}
|
||||
|
||||
if ( strlen(fname) == 0 ) strcpy(fname,"ROOT");
|
||||
else {
|
||||
if ( fname[0] == 1 ) strcpy(fname,"..");
|
||||
if ( fname[0] == 1 ) strcpy(fname,"..");
|
||||
else{
|
||||
//fname[ *filenamelength ] = 0;
|
||||
/*
|
||||
@ -362,13 +352,9 @@ int getfiles( int filecount )
|
||||
rr = strstr (fname, ";"); //if ( fname[ strlen(fname) - 2 ] == ';' )
|
||||
if (rr != NULL) *rr = 0; //fname[ strlen(fname) - 2 ] = 0;*/
|
||||
|
||||
/*strcpy(filelist[filecount].filename, fname);
|
||||
memcpy(&offset32, &readbuffer[diroffset + EXTENT], 4);
|
||||
memcpy(&cdfiles[filecount].length, &readbuffer[diroffset + FILE_LENGTH], 4);
|
||||
memcpy(&cdfiles[filecount].flags, &readbuffer[diroffset + FILE_FLAGS], 1);
|
||||
cdfiles[filecount].offset = (u64)offset32;*/
|
||||
strcpy(filelist[filecount].filename, fname);
|
||||
memcpy(&filelist[filecount].offset, &readbuffer[diroffset + EXTENT], 4);
|
||||
memcpy(&offset32, &readbuffer[diroffset + EXTENT], 4);
|
||||
filelist[filecount].offset = (u64)offset32;
|
||||
memcpy(&filelist[filecount].length, &readbuffer[diroffset + FILE_LENGTH], 4);
|
||||
memcpy(&filelist[filecount].flags, &readbuffer[diroffset + FILE_FLAGS], 1);
|
||||
|
||||
@ -389,12 +375,10 @@ int getfiles( int filecount )
|
||||
*
|
||||
* Parse the isodirectory, returning the number of files found
|
||||
****************************************************************************/
|
||||
|
||||
int parsedir()
|
||||
{
|
||||
int parsedir() {
|
||||
int pdlength;
|
||||
int pdoffset;
|
||||
int rdoffset;
|
||||
u64 pdoffset;
|
||||
u64 rdoffset;
|
||||
int len = 0;
|
||||
int filecount = 0;
|
||||
|
||||
@ -408,12 +392,11 @@ int parsedir()
|
||||
/*** Get as many files as possible ***/
|
||||
while ( len < pdlength )
|
||||
{
|
||||
if (dvd_read (&readbuffer, 2048, pdoffset) == 0) return 0;
|
||||
//dvd_read(&readbuffer, 2048, pdoffset);
|
||||
if (dvd_read (&readbuffer, 2048, pdoffset) == 0)
|
||||
return 0;
|
||||
diroffset = 0;
|
||||
|
||||
while ( getfiles( filecount ) )
|
||||
{
|
||||
while ( getfiles( filecount ) ) {
|
||||
if ( filecount < MAXFILES )
|
||||
filecount++;
|
||||
}
|
||||
@ -421,7 +404,6 @@ int parsedir()
|
||||
len += 2048;
|
||||
pdoffset = rdoffset + len;
|
||||
}
|
||||
|
||||
return filecount;
|
||||
}
|
||||
|
||||
@ -433,7 +415,6 @@ int updateSDdirname()
|
||||
int size=0;
|
||||
char *test;
|
||||
char temp[1024];
|
||||
// char tmpCompare[1024];
|
||||
|
||||
/* current directory doesn't change */
|
||||
if (strcmp(filelist[selection].filename,".") == 0) return 0;
|
||||
@ -571,16 +552,14 @@ bool inSz = false;
|
||||
//#define PADCAL 70
|
||||
extern int PADCAL;
|
||||
|
||||
void FileSelector()
|
||||
{
|
||||
void FileSelector() {
|
||||
short p;
|
||||
short q = 0;
|
||||
signed char a;
|
||||
int haverom = 0;
|
||||
int redraw = 1;
|
||||
|
||||
while ( haverom == 0 )
|
||||
{
|
||||
while ( haverom == 0 ) {
|
||||
if ( redraw ) ShowFiles( offset, selection );
|
||||
|
||||
redraw = 0;
|
||||
@ -589,14 +568,13 @@ void FileSelector()
|
||||
|
||||
if (p & PAD_BUTTON_B) return;
|
||||
|
||||
if ( ( p & PAD_BUTTON_DOWN ) || ( a < -PADCAL ) ){
|
||||
if ( ( p & PAD_BUTTON_DOWN ) || ( a < -PADCAL ) ) {
|
||||
selection++;
|
||||
if (selection == maxfiles) selection = offset = 0;
|
||||
if ((selection - offset) >= PAGESIZE) offset += PAGESIZE;
|
||||
redraw = 1;
|
||||
} // End of down
|
||||
if ( ( p & PAD_BUTTON_UP ) || ( a > PADCAL ) )
|
||||
{
|
||||
if ( ( p & PAD_BUTTON_UP ) || ( a > PADCAL ) ) {
|
||||
selection--;
|
||||
if ( selection < 0 ){
|
||||
selection = maxfiles - 1;
|
||||
@ -607,8 +585,7 @@ void FileSelector()
|
||||
redraw = 1;
|
||||
} // End of Up
|
||||
|
||||
if ( (p & PAD_BUTTON_LEFT) || (p & PAD_TRIGGER_L) )
|
||||
{
|
||||
if ( (p & PAD_BUTTON_LEFT) || (p & PAD_TRIGGER_L) ) {
|
||||
/*** Go back a page ***/
|
||||
selection -= PAGESIZE;
|
||||
if ( selection < 0 ) {
|
||||
@ -620,8 +597,7 @@ void FileSelector()
|
||||
redraw = 1;
|
||||
}
|
||||
|
||||
if (( p & PAD_BUTTON_RIGHT ) || (p & PAD_TRIGGER_R))
|
||||
{
|
||||
if (( p & PAD_BUTTON_RIGHT ) || (p & PAD_TRIGGER_R)) {
|
||||
/*** Go forward a page ***/
|
||||
selection += PAGESIZE;
|
||||
if ( selection > maxfiles - 1 ) selection = offset = 0;
|
||||
@ -630,25 +606,20 @@ void FileSelector()
|
||||
}
|
||||
|
||||
if ( p & PAD_BUTTON_A ) {
|
||||
if ( filelist[selection].flags ) /*** This is directory ***/
|
||||
{
|
||||
if (UseSDCARD)
|
||||
{
|
||||
if ( filelist[selection].flags ) { /*** This is directory ***/
|
||||
if (UseSDCARD) {
|
||||
//if ( filelist[selection].filename[0] == 0x2e) {
|
||||
/* update current directory and set new entry list if directory has changed */
|
||||
int status = updateSDdirname();
|
||||
if (status == 1)
|
||||
{
|
||||
if (status == 1) {
|
||||
maxfiles = parseSDdirectory();
|
||||
if (!maxfiles)
|
||||
{
|
||||
if (!maxfiles) {
|
||||
WaitPrompt ("Error reading directory !");
|
||||
haverom = 1; // quit SD menu
|
||||
haveSDdir = 0; // reset everything at next access
|
||||
}
|
||||
}
|
||||
else if (status == -1)
|
||||
{
|
||||
else if (status == -1) {
|
||||
haverom = 1; // quit SD menu
|
||||
haveSDdir = 0; // reset everything at next access
|
||||
}
|
||||
@ -658,268 +629,198 @@ void FileSelector()
|
||||
offset = selection = 0;
|
||||
maxfiles = parsedir();
|
||||
}
|
||||
} else if (selection == 0 && inSz == true) {
|
||||
rootdir = filelist[1].offset;
|
||||
rootdirlength = filelist[1].length;
|
||||
offset = 0;
|
||||
maxfiles = parsedir();
|
||||
inSz = false;
|
||||
SzClose();
|
||||
} else if (inSz == false && SzDvdIsArchive(filelist[selection].offset) == SZ_OK) {
|
||||
// parse the 7zip file
|
||||
SzParse();
|
||||
if(SzRes == SZ_OK) {
|
||||
inSz = true;
|
||||
offset = selection = 0;
|
||||
} else {
|
||||
SzDisplayError(SzRes);
|
||||
}
|
||||
else if(selection == 0 && inSz == true)
|
||||
{
|
||||
} else if (inSz == true) {
|
||||
// extract the selected ROM from the 7zip file to the buffer
|
||||
if(SzExtractROM(filelist[selection].offset, nesromptr) == true) {
|
||||
haverom = 1;
|
||||
inSz = false;
|
||||
|
||||
// go one directory up
|
||||
rootdir = filelist[1].offset;
|
||||
rootdirlength = filelist[1].length;
|
||||
offset = 0;
|
||||
maxfiles = parsedir();
|
||||
inSz = false;
|
||||
SzClose();
|
||||
}
|
||||
else if(inSz == false && SzDvdIsArchive(filelist[selection].offset) == SZ_OK)
|
||||
{
|
||||
// parse the 7zip file
|
||||
SzParse();
|
||||
if(SzRes == SZ_OK)
|
||||
{
|
||||
inSz = true;
|
||||
offset = selection = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
SzDisplayError(SzRes);
|
||||
}
|
||||
}
|
||||
else if(inSz == true)
|
||||
{
|
||||
// extract the selected ROM from the 7zip file to the buffer
|
||||
if(SzExtractROM(filelist[selection].offset, nesromptr) == true)
|
||||
{
|
||||
haverom = 1;
|
||||
inSz = false;
|
||||
|
||||
// go one directory up
|
||||
rootdir = filelist[1].offset;
|
||||
rootdirlength = filelist[1].length;
|
||||
offset = selection = 0;
|
||||
maxfiles = parsedir();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rootdir = filelist[selection].offset;
|
||||
rootdirlength = filelist[selection].length;
|
||||
// Now load the DVD file to it's offset
|
||||
LoadDVDFile(nesromptr);
|
||||
haverom = 1;
|
||||
}
|
||||
redraw = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadDVDFile
|
||||
****************************************************************************/
|
||||
int LoadDVDFile( unsigned char *buffer )
|
||||
{
|
||||
u64 offset;
|
||||
int blocks;
|
||||
int i;
|
||||
u64 discoffset;
|
||||
|
||||
/*** SDCard Addition ***/
|
||||
if (UseSDCARD) GetSDInfo ();
|
||||
if (rootdirlength == 0) return 0;
|
||||
|
||||
/*** How many 2k blocks to read ***/
|
||||
blocks = rootdirlength / 2048;
|
||||
offset = 0;
|
||||
discoffset = rootdir;
|
||||
|
||||
ShowAction("Loading ... Wait");
|
||||
if (UseSDCARD) SDCARD_ReadFile (filehandle, &readbuffer, 2048);
|
||||
else dvd_read(&readbuffer, 2048, discoffset);
|
||||
|
||||
if ( isZipFile() == false )
|
||||
{
|
||||
if (UseSDCARD) SDCARD_SeekFile (filehandle, 0, SDCARD_SEEK_SET);
|
||||
for ( i = 0; i < blocks; i++ )
|
||||
{
|
||||
if (UseSDCARD) SDCARD_ReadFile (filehandle, &readbuffer, 2048);
|
||||
else dvd_read(&readbuffer, 2048, discoffset);
|
||||
memcpy(&buffer[offset], &readbuffer, 2048);
|
||||
offset += 2048;
|
||||
discoffset += 2048;
|
||||
}
|
||||
|
||||
/*** And final cleanup ***/
|
||||
if( rootdirlength % 2048 )
|
||||
{
|
||||
i = rootdirlength % 2048;
|
||||
if (UseSDCARD) SDCARD_ReadFile (filehandle, &readbuffer, i);
|
||||
else dvd_read(&readbuffer, 2048, discoffset);
|
||||
memcpy(&buffer[offset], &readbuffer, i);
|
||||
}
|
||||
} else {
|
||||
return unzipDVDFile( buffer, discoffset, rootdirlength);
|
||||
}
|
||||
if (UseSDCARD) SDCARD_CloseFile (filehandle);
|
||||
|
||||
return rootdirlength;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* OpenDVD
|
||||
*
|
||||
* This function performs the swap task for softmodders.
|
||||
* For Viper/Qoob users, sector 0 is read, and if it contains all nulls
|
||||
* an ISO disc is assumed.
|
||||
****************************************************************************/
|
||||
static int havedir = 0;
|
||||
|
||||
int OpenDVD()
|
||||
{
|
||||
|
||||
int i, j;
|
||||
int driveid=-99;
|
||||
|
||||
haveSDdir = 0;
|
||||
|
||||
/*** Get Drive Type ***/
|
||||
dvd_inquiry();
|
||||
driveid = (int)inquiry[2];
|
||||
|
||||
/*** Make sure it's one I now about ***/
|
||||
if ( ( driveid != 4 ) && ( driveid != 6 ) && ( driveid != 8 ) ) {
|
||||
isWii = true;
|
||||
}
|
||||
|
||||
memset(&readbuffer, 0x80, 2048);
|
||||
dvd_read(&readbuffer, 2048,0);
|
||||
|
||||
for ( i = j = 0; i < 2048; i++ )
|
||||
j += readbuffer[i];
|
||||
|
||||
if ( j ) {
|
||||
if ( IsXenoGCImage( (char *)&readbuffer ) )
|
||||
j = 0;
|
||||
}
|
||||
|
||||
/*** Was there any data in sector 0 ? ***/
|
||||
// do not do all this stuff here if we are running on a Wii
|
||||
// because the modchip will take care of this.
|
||||
havedir = offset = selection = 0;
|
||||
if (isWii == false && j ) {
|
||||
/*** Yes - so start swap sequence ***/
|
||||
ShowAction("Stopping DVD ... Wait");
|
||||
dvd_motor_off();
|
||||
WaitPrompt("Insert an ISO 9660 DVD");
|
||||
ShowAction("Resetting DVD ... Wait");
|
||||
dvd_reset();
|
||||
|
||||
/*** Now the fun begins
|
||||
This is essentially the cactus implementation from gc-linux
|
||||
sequence of events. There may well be a better way to do it
|
||||
from inside libogc, but no documentation is available. ***/
|
||||
|
||||
/*** Reset the DVD Drive, to enable the firmware update ***/
|
||||
/*** Reset
|
||||
Unlock
|
||||
SendCode
|
||||
Enable Extension
|
||||
Unlock
|
||||
Motor On
|
||||
SetStatus
|
||||
ReadID ***/
|
||||
|
||||
ShowAction("Sending Drive Code ... Wait");
|
||||
dvd_unlock();
|
||||
SendDriveCode(driveid);
|
||||
dvd_extension();
|
||||
dvd_unlock();
|
||||
ShowAction("Mounting DVD ... Wait");
|
||||
dvd_motor_on_extra();
|
||||
dvd_setstatus();
|
||||
dvd_read_id((void *)0x80000000);
|
||||
}
|
||||
|
||||
/*** At this point I should have an unlocked DVD ... so let's do the ISO ***/
|
||||
if ( havedir != 1 ) {
|
||||
if ( IsPVD() )
|
||||
{
|
||||
/*** Have a valid PVD, so start reading directory entries ***/
|
||||
maxfiles = parsedir();
|
||||
if ( maxfiles ) {
|
||||
offset = selection = 0;
|
||||
FileSelector();
|
||||
havedir = 1;
|
||||
maxfiles = parsedir();
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
rootdir = filelist[selection].offset;
|
||||
rootdirlength = filelist[selection].length;
|
||||
// Now load the DVD file to it's offset
|
||||
LoadDVDFile(nesromptr);
|
||||
haverom = 1;
|
||||
}
|
||||
} else
|
||||
FileSelector();
|
||||
redraw = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
/****************************************************************************
|
||||
* LoadDVDFile
|
||||
****************************************************************************/
|
||||
int LoadDVDFile( unsigned char *buffer )
|
||||
{
|
||||
u64 offset;
|
||||
int blocks;
|
||||
int i;
|
||||
u64 discoffset;
|
||||
|
||||
/*** SDCard Addition ***/
|
||||
if (UseSDCARD) GetSDInfo();
|
||||
if (rootdirlength == 0) return 0;
|
||||
|
||||
/*** How many 2k blocks to read ***/
|
||||
blocks = rootdirlength / 2048;
|
||||
offset = 0;
|
||||
discoffset = rootdir;
|
||||
|
||||
ShowAction("Loading ... Wait");
|
||||
if (UseSDCARD) SDCARD_ReadFile (filehandle, &readbuffer, 2048);
|
||||
else dvd_read(&readbuffer, 2048, discoffset);
|
||||
|
||||
if ( isZipFile() == false ) {
|
||||
if (UseSDCARD) SDCARD_SeekFile (filehandle, 0, SDCARD_SEEK_SET);
|
||||
for ( i = 0; i < blocks; i++ ) {
|
||||
if (UseSDCARD) SDCARD_ReadFile (filehandle, &readbuffer, 2048);
|
||||
else dvd_read(&readbuffer, 2048, discoffset);
|
||||
memcpy(&buffer[offset], &readbuffer, 2048);
|
||||
offset += 2048;
|
||||
discoffset += 2048;
|
||||
}
|
||||
|
||||
/*** And final cleanup ***/
|
||||
if( rootdirlength % 2048 ) {
|
||||
i = rootdirlength % 2048;
|
||||
if (UseSDCARD) SDCARD_ReadFile (filehandle, &readbuffer, i);
|
||||
else dvd_read(&readbuffer, 2048, discoffset);
|
||||
memcpy(&buffer[offset], &readbuffer, i);
|
||||
}
|
||||
} else {
|
||||
return unzipDVDFile( buffer, discoffset, rootdirlength);
|
||||
}
|
||||
if (UseSDCARD) SDCARD_CloseFile (filehandle);
|
||||
|
||||
return rootdirlength;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* OpenDVD
|
||||
*
|
||||
* This function performs the swap task for softmodders.
|
||||
* For Viper/Qoob users, sector 0 is read, and if it contains all nulls
|
||||
* an ISO disc is assumed.
|
||||
****************************************************************************/
|
||||
static int havedir = 0;
|
||||
int OpenDVD() {
|
||||
int i, j;
|
||||
haveSDdir = 0;
|
||||
|
||||
havedir = offset = selection = 0;
|
||||
|
||||
// Mount the DVD if necessary
|
||||
if (!IsPVD()) {
|
||||
ShowAction("Mounting DVD");
|
||||
DVD_Mount();
|
||||
ShowAction("Done Mounting");
|
||||
havedir = 0;
|
||||
if (!IsPVD()) {
|
||||
WaitPrompt("No vallid ISO9660 DVD");
|
||||
return 0; // No correct ISO9660 DVD
|
||||
}
|
||||
}
|
||||
|
||||
int OpenSD ()
|
||||
/*** At this point I should have an unlocked DVD ... so let's do the ISO ***/
|
||||
if ( havedir != 1 ) {
|
||||
if ( IsPVD() ) {
|
||||
/*** Have a valid PVD, so start reading directory entries ***/
|
||||
maxfiles = parsedir();
|
||||
if ( maxfiles ) {
|
||||
offset = selection = 0;
|
||||
FileSelector();
|
||||
havedir = 1;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
FileSelector();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OpenSD () {
|
||||
UseSDCARD = 1;
|
||||
char msg[128];
|
||||
|
||||
if (choosenSDSlot != sdslot) haveSDdir = 0;
|
||||
|
||||
if (haveSDdir == 0) {
|
||||
/* don't mess with DVD entries */
|
||||
havedir = 0;
|
||||
|
||||
/* Reset SDCARD root directory */
|
||||
sprintf(rootSDdir,"dev%d:\\fceu\\roms",choosenSDSlot);
|
||||
sdslot = choosenSDSlot;
|
||||
|
||||
/* Parse initial root directory and get entries list */
|
||||
ShowAction("Reading Directory ...");
|
||||
if ((maxfiles = parseSDdirectory ())) {
|
||||
sprintf (msg, "Found %d entries", maxfiles);
|
||||
ShowAction(msg);
|
||||
/* Select an entry */
|
||||
FileSelector ();
|
||||
|
||||
/* memorize last entries list, actual root directory and selection for next access */
|
||||
haveSDdir = 1;
|
||||
} else {
|
||||
/* no entries found */
|
||||
sprintf (msg, "Error reading dev%d:\\fceu\\roms", choosenSDSlot);
|
||||
WaitPrompt (msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Retrieve previous entries list and made a new selection */
|
||||
else FileSelector ();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SDCard Get Info
|
||||
****************************************************************************/
|
||||
void GetSDInfo () {
|
||||
char fname[SDCARD_MAX_PATH_LEN];
|
||||
rootdirlength = 0;
|
||||
|
||||
/* Check filename length */
|
||||
if ((strlen(rootSDdir)+1+strlen(filelist[selection].filename)) < SDCARD_MAX_PATH_LEN)
|
||||
sprintf(fname, "%s\\%s",rootSDdir,filelist[selection].filename);
|
||||
|
||||
else
|
||||
{
|
||||
UseSDCARD = 1;
|
||||
char msg[128];
|
||||
|
||||
if (choosenSDSlot != sdslot) haveSDdir = 0;
|
||||
|
||||
if (haveSDdir == 0)
|
||||
{
|
||||
/* don't mess with DVD entries */
|
||||
havedir = 0;
|
||||
|
||||
/* Reset SDCARD root directory */
|
||||
sprintf(rootSDdir,"dev%d:\\fceu\\roms",choosenSDSlot);
|
||||
sdslot = choosenSDSlot;
|
||||
|
||||
/* Parse initial root directory and get entries list */
|
||||
ShowAction("Reading Directory ...");
|
||||
if ((maxfiles = parseSDdirectory ()))
|
||||
{
|
||||
sprintf (msg, "Found %d entries", maxfiles);
|
||||
WaitPrompt (msg);
|
||||
/* Select an entry */
|
||||
FileSelector ();
|
||||
|
||||
/* memorize last entries list, actual root directory and selection for next access */
|
||||
haveSDdir = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no entries found */
|
||||
sprintf (msg, "Error reading dev%d:\\fceu\\roms", choosenSDSlot);
|
||||
WaitPrompt (msg);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Retrieve previous entries list and made a new selection */
|
||||
else FileSelector ();
|
||||
|
||||
return 1;
|
||||
WaitPrompt ("Maximum Filename Length reached !");
|
||||
haveSDdir = 0; // reset everything before next access
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SDCard Get Info
|
||||
****************************************************************************/
|
||||
void GetSDInfo () {
|
||||
char fname[SDCARD_MAX_PATH_LEN];
|
||||
rootdirlength = 0;
|
||||
|
||||
/* Check filename length */
|
||||
if ((strlen(rootSDdir)+1+strlen(filelist[selection].filename)) < SDCARD_MAX_PATH_LEN)
|
||||
sprintf(fname, "%s\\%s",rootSDdir,filelist[selection].filename);
|
||||
|
||||
else
|
||||
{
|
||||
WaitPrompt ("Maximum Filename Length reached !");
|
||||
haveSDdir = 0; // reset everything before next access
|
||||
}
|
||||
|
||||
filehandle = SDCARD_OpenFile (fname, "rb");
|
||||
if (filehandle == NULL)
|
||||
{
|
||||
WaitPrompt ("Unable to open file!");
|
||||
return;
|
||||
}
|
||||
rootdirlength = SDCARD_GetFileSize (filehandle);
|
||||
filehandle = SDCARD_OpenFile (fname, "rb");
|
||||
if (filehandle == NULL)
|
||||
{
|
||||
WaitPrompt ("Unable to open file!");
|
||||
return;
|
||||
}
|
||||
rootdirlength = SDCARD_GetFileSize (filehandle);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
#define MAXFILES 1000
|
||||
|
||||
typedef struct {
|
||||
char filename[MAXJOLIET];
|
||||
char filename[MAXJOLIET+1];
|
||||
char sdcardpath[SDCARD_MAX_PATH_LEN];
|
||||
u64 offset;
|
||||
unsigned int length;
|
||||
|
@ -24,7 +24,7 @@ extern void ShowAction( char *msg );
|
||||
extern void WaitPrompt( char *msg );
|
||||
|
||||
extern unsigned char readbuffer[2048];
|
||||
extern unsigned int dvd_read(void *dst, unsigned int len, unsigned int offset);
|
||||
extern unsigned int dvd_read(void *dst, unsigned int len, u64 offset);
|
||||
|
||||
#define ZIPCHUNK 2048
|
||||
|
||||
@ -122,7 +122,6 @@ int unzipDVDFile( unsigned char *outbuffer,
|
||||
|
||||
if ( res != Z_OK )
|
||||
return 0;
|
||||
|
||||
/*** Set ZipChunk for first pass ***/
|
||||
zipoffset = ( sizeof(PKZIPHEADER) + FLIP16(pkzip.filenameLength) + FLIP16(pkzip.extraDataLength ));
|
||||
zipchunk = ZIPCHUNK - zipoffset;
|
||||
@ -181,4 +180,3 @@ int unzipDVDFile( unsigned char *outbuffer,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -810,11 +810,10 @@ void ShowROMInfo()
|
||||
* Media Select Screen
|
||||
****************************************************************************/
|
||||
|
||||
int mediacount = 3;
|
||||
char mediamenu[3][30] = {
|
||||
int mediacount = 4;
|
||||
char mediamenu[4][30] = {
|
||||
{ "Load from DVD" }, { "Load from SDCARD"},
|
||||
//{ "Rom loading in SDCARD: SLOT A" },
|
||||
{ "Return to previous" }
|
||||
{ "SD Gecko: Slot A" }, { "Return to previous" }
|
||||
};
|
||||
|
||||
unsigned char msstext[][512] = {
|
||||
@ -824,10 +823,9 @@ unsigned char msstext[][512] = {
|
||||
{ "How can You wait this long?! The games are waiting for You!!" }
|
||||
};
|
||||
|
||||
//int choosenSDSlot = 0;
|
||||
int choosenSDSlot = 0;
|
||||
|
||||
int MediaSelect()
|
||||
{
|
||||
int MediaSelect() {
|
||||
int menu = 0;
|
||||
int quit = 0;
|
||||
short j;
|
||||
@ -867,10 +865,10 @@ int MediaSelect()
|
||||
OpenSD();
|
||||
return 1;
|
||||
break;
|
||||
/*case 2: choosenSDSlot ^= 1; //Pick Slot
|
||||
sprintf(mediamenu[2], (!choosenSDSlot) ? "Rom loading in SDCARD: SLOT A" : "Rom loading in SDCARD: SLOT B");
|
||||
break;*/
|
||||
case 2: quit = 1; //Previous
|
||||
case 2: choosenSDSlot ^= 1; //Pick Slot
|
||||
sprintf(mediamenu[2], "SD Gecko: %s", (!choosenSDSlot) ? "Slot A" : "Slot B");
|
||||
break;
|
||||
case 3: quit = 1; //Previous
|
||||
break;
|
||||
|
||||
default: break ;
|
||||
@ -1036,10 +1034,10 @@ int ConfigScreen()
|
||||
break;
|
||||
|
||||
case 2: // Load new Game
|
||||
//if (MediaSelect()) {
|
||||
// if (GCMemROM() >= 0) return 1;/* Fix by Garglub. Thanks! */
|
||||
//}
|
||||
MediaSelect();
|
||||
if (MediaSelect()) {
|
||||
if (GCMemROM() >= 0)
|
||||
return 1;/* Fix by Garglub. Thanks! */
|
||||
}
|
||||
scrollerx = 320 - MARGIN;
|
||||
break;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <gctypes.h>
|
||||
#include "../../types.h"
|
||||
#include "common.h"
|
||||
|
||||
@ -51,15 +52,26 @@ static void reset_cb() {
|
||||
}
|
||||
|
||||
extern int WaitPromptChoice (char *msg, char *bmsg, char *amsg);
|
||||
int choosenSDSlot = 0;
|
||||
bool isWii = false;
|
||||
static unsigned char *inquiry=(unsigned char *)0x80000004;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
initDisplay();
|
||||
SYS_SetResetCallback (reset_cb);
|
||||
InitialiseSound();
|
||||
SDCARD_Init ();
|
||||
|
||||
int driveid = -1;
|
||||
|
||||
/*** Get Drive Type ***/
|
||||
dvd_inquiry();
|
||||
driveid = (int)inquiry[2];
|
||||
|
||||
/*** Make sure it's one I now about ***/
|
||||
if ( ( driveid != 4 ) && ( driveid != 6 ) && ( driveid != 8 ) ) {
|
||||
isWii = true;
|
||||
}
|
||||
|
||||
/*** Minimal Emulation Loop ***/
|
||||
if ( !FCEUI_Initialize() ) {
|
||||
printf("Ooops - unable to initialize system\n");
|
||||
@ -77,12 +89,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
cleanSFMDATA();
|
||||
GCMemROM();
|
||||
|
||||
choosenSDSlot = !WaitPromptChoice("Choose a SLOT to load Roms from SDCARD", "SLOT B", "SLOT A");
|
||||
ConfigScreen();
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
uint8 *gfx;
|
||||
int32 *sound;
|
||||
int32 ssize;
|
||||
|
Loading…
Reference in New Issue
Block a user