From 759b9ac159993c219e99fb646b331eca2e9ad8db Mon Sep 17 00:00:00 2001 From: dsbomb Date: Sun, 6 Apr 2008 23:49:30 +0000 Subject: [PATCH] Improved MemCard mounting. B at main menu goes back to game. 7z files on DVD can now be browsed --- source/drivers/gamecube/gcdvd.c | 1 - source/drivers/gamecube/info.c | 3 ++ source/drivers/gamecube/memstate.c | 33 +++++++++------------ source/drivers/gamecube/sz.c | 46 ++++++++++-------------------- 4 files changed, 31 insertions(+), 52 deletions(-) diff --git a/source/drivers/gamecube/gcdvd.c b/source/drivers/gamecube/gcdvd.c index 6adf918..6264b8d 100644 --- a/source/drivers/gamecube/gcdvd.c +++ b/source/drivers/gamecube/gcdvd.c @@ -726,7 +726,6 @@ int LoadDVDFile( unsigned char *buffer ) ****************************************************************************/ static int havedir = 0; int OpenDVD() { - int i, j; haveSDdir = 0; havedir = offset = selection = 0; diff --git a/source/drivers/gamecube/info.c b/source/drivers/gamecube/info.c index 7fb2b6c..f1f7b1e 100644 --- a/source/drivers/gamecube/info.c +++ b/source/drivers/gamecube/info.c @@ -1082,6 +1082,9 @@ int ConfigScreen() } } + if (j & PAD_BUTTON_B ) { + quit = 1; + } if ( menu == configmenucount ) menu = 0; diff --git a/source/drivers/gamecube/memstate.c b/source/drivers/gamecube/memstate.c index 90d83fa..1bc7e44 100644 --- a/source/drivers/gamecube/memstate.c +++ b/source/drivers/gamecube/memstate.c @@ -320,7 +320,8 @@ int MountTheCard() *(unsigned long*)(0xcc006800) |= 1<<13; /*** Disable Encryption ***/ uselessinquiry(); VIDEO_WaitVSync(); - CardError = CARD_Mount(CARDSLOT, SysArea, NULL); /*** Don't need or want a callback ***/ + //CardError = CARD_Mount(CARDSLOT, SysArea, NULL); /*** Don't need or want a callback ***/ + CardError = CARD_Mount(CARDSLOT, SysArea, CardRemoved); if ( CardError == 0 ) return 0; else { @@ -329,7 +330,7 @@ int MountTheCard() tries++; } - return 1; + return -1; } /**************************************************************************** @@ -338,9 +339,7 @@ int MountTheCard() * This is based on the code from libogc ****************************************************************************/ -void MCManage(int mode, int slot) -{ - +void MCManage(int mode, int slot) { char mcFilename[80]; int CardError; card_dir CardDir; @@ -360,7 +359,7 @@ void MCManage(int mode, int slot) CARD_Init("FCEU", "00"); /*** Try for memory card in slot A ***/ - CardError = CARD_Mount(CARDSLOT, SysArea, CardRemoved ); + CardError = MountTheCard(); if ( CardError >= 0 ) { @@ -418,7 +417,7 @@ void MCManage(int mode, int slot) CardError = CARD_Close(&CardFile); sprintf(debug, "Saved %d bytes successfully!", savedBytes); - WaitPrompt(debug); + ShowAction(debug); } else WaitPrompt("Save Failed!"); @@ -430,20 +429,16 @@ void MCManage(int mode, int slot) case 1: { /*** Load state ***/ /*** Look for this file ***/ CardError = CARD_FindFirst(CARDSLOT, &CardDir, true); - memopen(); /*** Clear the buffer ***/ - found = 0; - while ( CardError != CARD_ERROR_NOFILE ) - { + while ( CardError != CARD_ERROR_NOFILE ) { CardError = CARD_FindNext(&CardDir); if ( strcmp(CardDir.filename, mcFilename) == 0 ) found = 1; } - if ( found == 0 ) - { + if ( found == 0 ) { WaitPrompt("No Save Game Found"); CARD_Unmount(CARDSLOT); return; @@ -459,8 +454,7 @@ void MCManage(int mode, int slot) int sbo = SectorSize; actualSize -= SectorSize; - while( actualSize > 0 ) - { + while( actualSize > 0 ) { CARD_Read(&CardFile, &statebuffer[sbo], SectorSize, sbo); actualSize -= SectorSize; sbo += SectorSize; @@ -472,7 +466,7 @@ void MCManage(int mode, int slot) CARD_Unmount(CARDSLOT); sprintf(debug, "Loaded %d bytes successfully!", savedBytes); - WaitPrompt(debug); + ShowAction(debug); } break; /*** End load ***/ @@ -493,13 +487,12 @@ void SD_Manage(int mode, int slot){ int filesize = 0; int len = 0; - //sprintf (filepath, "dev%d:\\%s\\%08x.fcs", slot, SAVEDIR, iNESGameCRC32); - sprintf (path, "dev%d:\\%08x.fcs", slot, iNESGameCRC32); + sprintf (path, "dev%d:\\%s\\%08x.fcs", slot, SAVEDIR, iNESGameCRC32); if (mode == 0) ShowAction ("Saving STATE to SD..."); else ShowAction ("Loading STATE from SD..."); - handle = (mode == 0) ? SDCARD_OpenFile (path, "wb") : SDCARD_OpenFile (path, "rb"); + handle = SDCARD_OpenFile(path, (mode == 0) ? "wb" : "rb"); if (handle == NULL){ sprintf(msg, "Couldn't open %s", path); @@ -529,7 +522,7 @@ void SD_Manage(int mode, int slot){ SDCARD_CloseFile (handle); sprintf (msg, "Loaded %d bytes successfully", offset); - WaitPrompt(msg); + ShowAction(msg); GCFCEUSS_Load(); return ; diff --git a/source/drivers/gamecube/sz.c b/source/drivers/gamecube/sz.c index 0489332..c72a2bb 100644 --- a/source/drivers/gamecube/sz.c +++ b/source/drivers/gamecube/sz.c @@ -53,38 +53,31 @@ unsigned char dvdsf_buffer[DVD_SECTOR_SIZE]; u64 dvdsf_last_offset = 0; u64 dvdsf_last_length = 0; -int dvd_buffered_read(void *dst, u32 len, u64 offset) -{ +int dvd_buffered_read(void *dst, u32 len, u64 offset) { int ret = 0; // only read data if the data inside dvdsf_buffer cannot be used - if(offset != dvdsf_last_offset || len > dvdsf_last_length) - { + if(offset != dvdsf_last_offset || len > dvdsf_last_length) { memset(&dvdsf_buffer, '\0', DVD_SECTOR_SIZE); ret = dvd_read(&dvdsf_buffer, len, offset); dvdsf_last_offset = offset; dvdsf_last_length = len; - } memcpy(dst, &dvdsf_buffer, len); return ret; } -int dvd_safe_read(void *dst_v, u32 len, u64 offset) -{ +int dvd_safe_read(void *dst_v, u32 len, u64 offset) { unsigned char buffer[DVD_SECTOR_SIZE]; // buffer for one dvd sector // if read size and length are a multiply of DVD_(OFFSET,LENGTH)_MULTIPLY and length < DVD_MAX_READ_LENGTH // we don't need to fix anything - if(len % DVD_LENGTH_MULTIPLY == 0 && offset % DVD_OFFSET_MULTIPLY == 0 && len <= DVD_MAX_READ_LENGTH) - { + if(len % DVD_LENGTH_MULTIPLY == 0 && offset % DVD_OFFSET_MULTIPLY == 0 && len <= DVD_MAX_READ_LENGTH) { int ret = dvd_buffered_read(buffer, len, offset); memcpy(dst_v, &buffer, len); return ret; - } - else - { + } else { // no errors yet -> ret = 0 // the return value of dvd_read will be OR'd with ret // because dvd_read does return 1 on error and 0 on success and @@ -105,8 +98,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) bufferOffset = 0; // fix first issue (offset is not a multiply of 32) - if(offset % DVD_OFFSET_MULTIPLY) - { + if(offset % DVD_OFFSET_MULTIPLY) { // calcualte offset of the prior 32 byte position i = currentOffset - (currentOffset % DVD_OFFSET_MULTIPLY); @@ -117,8 +109,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) k = DVD_OFFSET_MULTIPLY - j; // maybe we'll only need to copy a few bytes and we therefore don't even reach the next sector - if(k > len) - { + if(k > len) { k = len; } @@ -133,14 +124,12 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) } // fix second issue (more than 2048 bytes are needed) - if(bytesToRead > DVD_MAX_READ_LENGTH) - { + if(bytesToRead > DVD_MAX_READ_LENGTH) { // calculate the number of 2048 bytes sector needed to get all data i = (bytesToRead - (bytesToRead % DVD_MAX_READ_LENGTH)) / DVD_MAX_READ_LENGTH; // read data in 2048 byte sector - for(j = 0; j < i; j++) - { + for(j = 0; j < i; j++) { ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read sector memcpy(&dst[bufferOffset], buffer, DVD_MAX_READ_LENGTH); // copy to output buffer @@ -152,8 +141,7 @@ int dvd_safe_read(void *dst_v, u32 len, u64 offset) } // fix third issue (length is not a multiply of 32) - if(bytesToRead) - { + if(bytesToRead) { ret |= dvd_buffered_read(buffer, DVD_MAX_READ_LENGTH, currentOffset); // read 32 byte from the dvd memcpy(&dst[bufferOffset], buffer, bytesToRead); // copy bytes to output buffer } @@ -204,20 +192,17 @@ SZ_RESULT SzDvdFileSeekImp(void *object, CFileSize pos) return SZ_OK; } -SZ_RESULT SzDvdIsArchive(u64 dvd_offset) -{ +SZ_RESULT SzDvdIsArchive(u64 dvd_offset) { // 7z signautre static Byte Signature[6] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C}; Byte Candidate[6]; // read the data from the DVD - dvd_safe_read (&Candidate, 6, dvd_offset); + int res = dvd_safe_read (&Candidate, 6, dvd_offset); size_t i; - for(i = 0; i < 6; i++) - { - if(Candidate[i] != Signature[i]) - { + for(i = 0; i < 6; i++) { + if(Candidate[i] != Signature[i]) { return SZE_FAIL; } } @@ -234,8 +219,7 @@ void SzDisplayError(SZ_RESULT res) static u64 rootdir; static int rootdirlength; -void SzParse(void) -{ +void SzParse(void) { // save the offset and the length of this file inside the archive stream structure SzArchiveStream.offset = filelist[selection].offset; SzArchiveStream.len = filelist[selection].length;