From d21047daed45ad1618efba53488478d57d1bb75a Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Sun, 14 Dec 2008 12:38:52 +0000 Subject: [PATCH] added DVD file autosorting, fixed automatic savestate/sram, fixed interlaced video mode switch, fixed audio buffers reset --- source/ngc/fileio/file_dvd.c | 4 ++++ source/ngc/fileio/file_fat.c | 27 ------------------------ source/ngc/fileio/filesel.c | 40 ++++++++++++++++++++++++++---------- source/ngc/fileio/filesel.h | 2 +- source/ngc/filemem.c | 1 + source/ngc/gui/menu.c | 10 ++++++++- source/ngc/ngc.c | 1 + source/ngc/ogc_audio.c | 2 +- source/ngc/ogc_video.c | 4 ++-- source/ngc/ogc_video.h | 2 +- 10 files changed, 49 insertions(+), 44 deletions(-) diff --git a/source/ngc/fileio/file_dvd.c b/source/ngc/fileio/file_dvd.c index 964f068..bce83b7 100644 --- a/source/ngc/fileio/file_dvd.c +++ b/source/ngc/fileio/file_dvd.c @@ -275,6 +275,10 @@ int DVD_ParseDirectory () len += 2048; pdoffset = rdoffset + len; } + + /* Sort the file list */ + qsort(filelist, filecount, sizeof(FILEENTRIES), FileSortCallback); + return filecount; } diff --git a/source/ngc/fileio/file_fat.c b/source/ngc/fileio/file_fat.c index 41c990d..e9e0ec4 100644 --- a/source/ngc/fileio/file_fat.c +++ b/source/ngc/fileio/file_fat.c @@ -94,33 +94,6 @@ int FAT_UpdateDir(int go_up) return 1; } -/*************************************************************************** - * FileSortCallback (Marty Disibio) - * - * Quick sort callback to sort file entries with the following order: - * . - * .. - * - * - ***************************************************************************/ -static int FileSortCallback(const void *f1, const void *f2) -{ - /* Special case for implicit directories */ - if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.') - { - if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; } - if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; } - if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } - if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; } - } - - /* If one is a file and one is a directory the directory is first. */ - if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1; - if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1; - - return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); -} - /*************************************************************************** * FAT_ParseDirectory * diff --git a/source/ngc/fileio/filesel.c b/source/ngc/fileio/filesel.c index df334e0..f3d4102 100644 --- a/source/ngc/fileio/filesel.c +++ b/source/ngc/fileio/filesel.c @@ -39,7 +39,6 @@ int haveDVDdir = 0; int haveFATdir = 0; FILEENTRIES filelist[MAXFILES]; -char rom_filename[MAXJOLIET]; /*************************************************************************** * ShowFiles @@ -66,6 +65,33 @@ static void ShowFiles (int offset, int selection) SetScreen (); } +/*************************************************************************** + * FileSortCallback (Marty Disibio) + * + * Quick sort callback to sort file entries with the following order: + * . + * .. + * + * + ***************************************************************************/ +int FileSortCallback(const void *f1, const void *f2) +{ + /* Special case for implicit directories */ + if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.') + { + if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; } + if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; } + if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; } + if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; } + } + + /* If one is a file and one is a directory the directory is first. */ + if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1; + if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1; + + return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename); +} + /**************************************************************************** * FileSelector * @@ -203,16 +229,8 @@ int FileSelector(unsigned char *buffer) if (go_up) return 0; /* Load file */ - if (useFAT) ret = FAT_LoadFile(buffer); - else ret = DVD_LoadFile(buffer); - - if (ret) - { - /* get filename and remove extension */ - sprintf(rom_filename,"%s", filelist[selection].filename); - rom_filename[strlen(rom_filename) - 5] = 0; - } - return ret; + if (useFAT) return FAT_LoadFile(buffer); + else return DVD_LoadFile(buffer); } redraw = 1; } diff --git a/source/ngc/fileio/filesel.h b/source/ngc/fileio/filesel.h index 1621369..520c253 100644 --- a/source/ngc/fileio/filesel.h +++ b/source/ngc/fileio/filesel.h @@ -45,7 +45,6 @@ typedef struct /* Global Variables */ extern FILEENTRIES filelist[MAXFILES]; -extern char rom_filename[MAXJOLIET]; extern int maxfiles; extern int offset; extern int selection; @@ -56,5 +55,6 @@ extern int haveDVDdir; extern int haveFATdir; extern int FileSelector(unsigned char *buffer); +extern int FileSortCallback(const void *f1, const void *f2); #endif diff --git a/source/ngc/filemem.c b/source/ngc/filemem.c index 44818b8..ff93d10 100644 --- a/source/ngc/filemem.c +++ b/source/ngc/filemem.c @@ -47,6 +47,7 @@ static card_stat CardStatus; * 64k SRAM + 2k Icon */ static u8 savebuffer[0x26000] ATTRIBUTE_ALIGN (32); +char rom_filename[MAXJOLIET]; int ManageSRAM(u8 direction, u8 device); int ManageState(u8 direction, u8 device); diff --git a/source/ngc/gui/menu.c b/source/ngc/gui/menu.c index f4bc9ae..7024c7a 100644 --- a/source/ngc/gui/menu.c +++ b/source/ngc/gui/menu.c @@ -26,6 +26,7 @@ #include "font.h" #include "file_dvd.h" #include "file_fat.h" +#include "filesel.h" #ifdef HW_RVL #include @@ -889,6 +890,7 @@ int filemenu () * Load Rom menu * ****************************************************************************/ +extern char rom_filename[MAXJOLIET]; static u8 load_menu = 0; static u8 dvd_on = 0; @@ -946,6 +948,9 @@ int loadmenu () genromsize = size; memfile_autosave(); reloadrom(); + sprintf(rom_filename,"%s",filelist[selection].filename); + rom_filename[strlen(rom_filename) - 4] = 0; + memfile_autoload(); memfile_autoload(); return 1; } @@ -968,9 +973,12 @@ int loadmenu () size = FAT_Open(ret,cart_rom); if (size) { - genromsize = size; memfile_autosave(); + genromsize = size; reloadrom(); + sprintf(rom_filename,"%s",filelist[selection].filename); + rom_filename[strlen(rom_filename) - 4] = 0; + memfile_autoload(); memfile_autoload(); return 1; } diff --git a/source/ngc/ngc.c b/source/ngc/ngc.c index fe42764..3cfc431 100644 --- a/source/ngc/ngc.c +++ b/source/ngc/ngc.c @@ -263,6 +263,7 @@ int main (int argc, char *argv[]) ConfigRequested = 0; /* reset frame timings */ + frameticker = 0; prev = gettime(); FrameCount = 0; RenderedFrameCount = 0; diff --git a/source/ngc/ogc_audio.c b/source/ngc/ogc_audio.c index 051c7fd..a6c3b23 100644 --- a/source/ngc/ogc_audio.c +++ b/source/ngc/ogc_audio.c @@ -69,7 +69,6 @@ void ogc_audio__init(void) AUDIO_Init (NULL); AUDIO_SetDSPSampleRate (AI_SAMPLERATE_48KHZ); AUDIO_RegisterDMACallback (AudioSwitchBuffers); - memset(soundbuffer, 0, 16 * 3840); } void ogc_audio__reset(void) @@ -78,6 +77,7 @@ void ogc_audio__reset(void) IsPlaying = 0; mixbuffer = 0; playbuffer = 0; + memset(soundbuffer, 0, 16 * 3840); } void ogc_audio__update(void) diff --git a/source/ngc/ogc_video.c b/source/ngc/ogc_video.c index 6940388..2f1f957 100644 --- a/source/ngc/ogc_video.c +++ b/source/ngc/ogc_video.c @@ -537,8 +537,8 @@ void ogc_video__reset() if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); - /* reset frame counter */ - frameticker = 0; + /* reset frame counter (unless it's interlaced mode change) */ + if (!interlaced) frameticker = 0; /* Configure GX */ GX_SetViewport (0.0F, 0.0F, rmode->fbWidth, rmode->efbHeight, 0.0F, 1.0F); diff --git a/source/ngc/ogc_video.h b/source/ngc/ogc_video.h index 2ecb729..fd98674 100644 --- a/source/ngc/ogc_video.h +++ b/source/ngc/ogc_video.h @@ -26,7 +26,7 @@ extern void ogc_video__init(void); extern void ogc_video__update(void); -extern void ogc_video__reset(void); +extern void ogc_video__reset(); extern BOOL gc_pal; extern unsigned int *xfb[2];