From 28230082eda1a6f8e895dc2a3645fe9f7e19a4e9 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Mon, 25 May 2009 17:07:34 +0000 Subject: [PATCH] +added optional Confirmation Prompt +improved File Selection code (removed global variables, sound effect) --- source/gx/config.c | 7 +- source/gx/config.h | 1 + source/gx/fileio/file_dvd.c | 41 +++------ source/gx/fileio/file_dvd.h | 5 +- source/gx/fileio/file_fat.c | 42 ++-------- source/gx/fileio/file_fat.h | 5 +- source/gx/gui/filesel.c | 160 +++++++++++++++++++++++------------- source/gx/gui/filesel.h | 19 ++--- source/gx/gui/gui.c | 31 ++++++- source/gx/gui/gui.h | 1 + source/gx/gui/menu.c | 4 +- source/gx/osd.h | 4 +- 12 files changed, 172 insertions(+), 148 deletions(-) diff --git a/source/gx/config.c b/source/gx/config.c index 289a0bd..ae8ecfc 100644 --- a/source/gx/config.c +++ b/source/gx/config.c @@ -98,15 +98,16 @@ void config_default(void) /* menu options */ #ifdef HW_RVL - config.sram_auto = 0; /* let's assume we always have a FAT device by default */ + config.sram_auto = 0; /* let's assume we always have a FAT device by default */ #else - config.sram_auto = -1; + config.sram_auto = -1; #endif config.state_auto = -1; - config.bg_color = 0; + config.bg_color = 0; config.bgm_volume = 100.0; config.sfx_volume = 100.0; config.screen_w = 658; + config.askConfirm = 0; /* restore saved configuration */ config_load(); diff --git a/source/gx/config.h b/source/gx/config.h index 5b187e0..02742ab 100644 --- a/source/gx/config.h +++ b/source/gx/config.h @@ -60,6 +60,7 @@ typedef struct int8 sram_auto; int8 state_auto; int16 screen_w; + uint8 askConfirm; } t_config; /* Global data */ diff --git a/source/gx/fileio/file_dvd.c b/source/gx/fileio/file_dvd.c index ddb9b9c..7070a61 100644 --- a/source/gx/fileio/file_dvd.c +++ b/source/gx/fileio/file_dvd.c @@ -27,6 +27,8 @@ #include "dvd.h" #include "unzip.h" #include "filesel.h" +#include "file_fat.h" +#include "file_dvd.h" /** Minimal ISO Directory Definition **/ #define RECLEN 0 /* Record length */ @@ -39,6 +41,8 @@ /** Minimal Primary Volume Descriptor **/ #define PVDROOT 0x9c +bool haveDVDdir = 0; + /** Static Variables **/ static u64 rootdir = 0; /* current root directory offset */ static u64 basedir = 0; /* base directory offset */ @@ -185,7 +189,6 @@ static int getentry(int entrycount) filelist[entrycount].offset <<= 11; filelist[entrycount].flags = filelist[entrycount].flags & 2; - filelist[entrycount].filename_offset = 0; /*** Prepare for next entry ***/ diroffset += dvdbuffer[diroffset]; @@ -201,31 +204,14 @@ static int getentry(int entrycount) * * Update DVD current root directory ***************************************************************************/ -int DVD_UpdateDir(bool go_up) +int DVD_UpdateDir(bool go_up, u64 offset, u32 length) { /* root has no parent directory */ if (go_up && (basedir == rootdir)) return 0; - /* by default, update current directory */ - rootdir = filelist[selection].offset; - rootdirlength = filelist[selection].length; - - /* reinit selector (previous value is saved for one level) */ - if (selection == 0) - { - selection = old_selection; - offset = old_offset; - old_selection = 0; - old_offset = 0; - } - else - { - /* save current selector value */ - old_selection = selection; - old_offset = offset; - selection = 0; - offset = 0; - } + /* simply update current root directory */ + rootdir = offset; + rootdirlength = length; return 1; } @@ -285,7 +271,7 @@ int DVD_ParseDirectory(void) * This functions return the actual size of data copied into the buffer * ****************************************************************************/ -int DVD_LoadFile(u8 *buffer) +int DVD_LoadFile(u8 *buffer, u32 selection) { /* file size */ int length = filelist[selection].length; @@ -344,9 +330,6 @@ int DVD_LoadFile(u8 *buffer) int DVD_Open(void) { - /* reset flags */ - useFAT = 0; - /* is DVD mounted ? */ if (!getpvd()) { @@ -400,11 +383,7 @@ int DVD_Open(void) haveFATdir = 0; /* reset File selector */ - maxfiles = max; - offset = 0; - selection = 0; - old_offset = 0; - old_selection = 0; + FileSelClear(max); return 1; } else diff --git a/source/gx/fileio/file_dvd.h b/source/gx/fileio/file_dvd.h index b9f7c83..1d568cc 100644 --- a/source/gx/fileio/file_dvd.h +++ b/source/gx/fileio/file_dvd.h @@ -25,9 +25,10 @@ #ifndef _FILE_DVD_H #define _FILE_DVD_H -extern int DVD_UpdateDir(bool go_up); +extern int DVD_UpdateDir(bool go_up,u64 offset, u32 length); extern int DVD_ParseDirectory(void); -extern int DVD_LoadFile(u8 *buffer); +extern int DVD_LoadFile(u8 *buffer,u32 selection); extern int DVD_Open(void); +extern bool haveDVDdir; #endif diff --git a/source/gx/fileio/file_fat.c b/source/gx/fileio/file_fat.c index cbd83ef..e0cc51f 100644 --- a/source/gx/fileio/file_fat.c +++ b/source/gx/fileio/file_fat.c @@ -27,6 +27,9 @@ #include "unzip.h" #include "filesel.h" #include "file_fat.h" +#include "file_dvd.h" + +bool haveFATdir = 0; /* current FAT directory */ static char fatdir[MAXPATHLEN]; @@ -40,17 +43,14 @@ static int useHistory = 0; * * Update FAT current root directory ***************************************************************************/ -int FAT_UpdateDir(bool go_up) +int FAT_UpdateDir(bool go_up, char *filename) { int size=0; char *test; char temp[1024]; - /* current directory doesn't change */ - if (strcmp(filelist[selection].filename,".") == 0) return 1; - /* go up to parent directory */ - if (strcmp(filelist[selection].filename,"..") == 0) + if (strcmp(filename,"..") == 0) { /* determine last subdirectory namelength */ sprintf(temp,"%s",fatdir); @@ -64,14 +64,6 @@ int FAT_UpdateDir(bool go_up) /* remove last subdirectory name */ size = strlen(fatdir) - size; fatdir[size-1] = 0; - - /* restore previous selector state */ - selection = old_selection; - offset = old_offset; - - /* reset old selection */ - old_selection = 0; - old_offset = 0; } else if (go_up) { @@ -81,15 +73,7 @@ int FAT_UpdateDir(bool go_up) else { /* by default, simply append folder name */ - sprintf(fatdir, "%s%s/",fatdir, filelist[selection].filename); - - /* save current selector state */ - old_selection = selection; - old_offset = offset; - - /* reset selection */ - selection = 0; - offset = 0; + sprintf(fatdir, "%s%s/",fatdir, filename); } return 1; } @@ -140,7 +124,7 @@ int FAT_ParseDirectory(void) * This functions return the actual size of data copied into the buffer * ****************************************************************************/ -int FAT_LoadFile(u8 *buffer) +int FAT_LoadFile(u8 *buffer, u32 selection) { /* If loading from history then we need to setup a few more things. */ if(useHistory) @@ -222,9 +206,6 @@ int FAT_Open(int type) int max = 0; char root[10] = ""; - /* reset flags */ - useFAT = 1; - /* FAT header */ #ifdef HW_RVL if (type == TYPE_SD) sprintf (root, "sd:"); @@ -254,7 +235,6 @@ int FAT_Open(int type) filelist[i].offset = 0; filelist[i].length = 0; filelist[i].flags = 0; - filelist[i].filename_offset = 0; strncpy(filelist[i].filename, history.entries[i].filename, MAXJOLIET-1); filelist[i].filename[MAXJOLIET-1] = '\0'; max++; @@ -286,12 +266,8 @@ int FAT_Open(int type) haveFATdir = 1; haveDVDdir = 0; - /* reset file selection */ - maxfiles = max; - offset = 0; - selection = 0; - old_offset = 0; - old_selection = 0; + /* reset File selector */ + FileSelClear(max); return 1; } else diff --git a/source/gx/fileio/file_fat.h b/source/gx/fileio/file_fat.h index 16e6745..4a232a4 100644 --- a/source/gx/fileio/file_fat.h +++ b/source/gx/fileio/file_fat.h @@ -31,9 +31,10 @@ #define TYPE_USB 2 #endif -extern int FAT_UpdateDir(bool go_up); +extern int FAT_UpdateDir(bool go_up, char *filename); extern int FAT_ParseDirectory(void); -extern int FAT_LoadFile(u8* buffer); +extern int FAT_LoadFile(u8* buffer,u32 selection); extern int FAT_Open(int type); +extern bool haveFATdir; #endif diff --git a/source/gx/gui/filesel.c b/source/gx/gui/filesel.c index 0588876..ea80896 100644 --- a/source/gx/gui/filesel.c +++ b/source/gx/gui/filesel.c @@ -36,18 +36,14 @@ #define PAGESIZE 11 #define PAGEOFFSET 120 -/* Global Variables */ -int maxfiles = 0; -int offset = 0; -int selection = 0; -int old_selection = 0; -int old_offset = 0; -int useFAT = 0; -int haveDVDdir = 0; -int haveFATdir = 0; - FILEENTRIES filelist[MAXFILES]; +static int offset = 0; +static int selection = 0; +static int old_selection = 0; +static int old_offset = 0; +static int maxfiles = 0; + /*****************************************************************************/ /* GUI Buttons data */ /*****************************************************************************/ @@ -151,11 +147,13 @@ int FileSortCallback(const void *f1, const void *f2) * ROM size is returned * ****************************************************************************/ -int FileSelector(unsigned char *buffer) +int FileSelector(unsigned char *buffer, bool useFAT) { short p; - int ret,i,yoffset,string_offset; - int size,go_up = 0; + int ret,i,yoffset; + int size = 0; + int go_up = 0; + int string_offset = 0; int old = -1; char text[MAXPATHLEN]; char fname[MAXPATHLEN]; @@ -192,6 +190,11 @@ int FileSelector(unsigned char *buffer) if (old != selection) { old = selection; + string_offset = 0; + + /* play sound effect */ + ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size, + ((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL); /* delete previous texture if any */ gxTextureClose(&bg_filesel[8].texture); @@ -200,8 +203,6 @@ int FileSelector(unsigned char *buffer) if (!filelist[selection].flags) { - strcpy(action_select.comment,"Load ROM File"); - /* get ROM filename without extension */ sprintf (text, "%s", filelist[selection].filename); if (strlen(text) >= 4) text[strlen(text) - 4] = 0; @@ -225,21 +226,27 @@ int FileSelector(unsigned char *buffer) fclose(snap); } } - else - { - /* update helper */ - if (!strcmp(filelist[selection].filename,"..")) - strcpy(action_select.comment,"Previous Directory"); - else - strcpy(action_select.comment,"Open Directory"); - } } -#ifdef HW_RVL - /* pointer is out of focus */ + /* update helper */ if (m->selected != -1) + { + /* out of focus */ strcpy(action_select.comment,""); -#endif + } + else if (!filelist[selection].flags) + { + /* this is a file */ + strcpy(action_select.comment,"Load ROM File"); + } + else + { + /* this is a directory */ + if (!strcmp(filelist[selection].filename,"..")) + strcpy(action_select.comment,"Previous Directory"); + else + strcpy(action_select.comment,"Open Directory"); + } /* Draw menu*/ GUI_DrawMenu(m); @@ -251,14 +258,9 @@ int FileSelector(unsigned char *buffer) if (i == selection) { /* scrolling text */ - string_offset = filelist[i].filename_offset/10; - if (string_offset >= strlen(filelist[i].filename)) - { - string_offset = 0; - filelist[i].filename_offset = 0; - } - sprintf(text, "%s ",filelist[i].filename + string_offset); - strncat(text, filelist[i].filename, string_offset); + if ((string_offset/10) >= strlen(filelist[i].filename)) string_offset = 0; + sprintf(text, "%s ",filelist[i].filename + string_offset/10); + strncat(text, filelist[i].filename, string_offset/10); gxDrawTexture(bar_over.texture,bar_over.x,yoffset+bar_over.y,bar_over.w,bar_over.h,255); if (filelist[i].flags) @@ -268,7 +270,7 @@ int FileSelector(unsigned char *buffer) if (FONT_write(text,18,dir_icon.x+dir_icon.w+6,yoffset+16,bar_over.w-dir_icon.w-14,(GXColor)WHITE)) { /* text scrolling */ - filelist[i].filename_offset ++; + string_offset ++; } } else @@ -276,7 +278,7 @@ int FileSelector(unsigned char *buffer) if (FONT_write(text,18,dir_icon.x,yoffset+16,bar_over.w-8,(GXColor)WHITE)) { /* text scrolling */ - filelist[i].filename_offset ++; + string_offset ++; } } } @@ -364,7 +366,6 @@ int FileSelector(unsigned char *buffer) /* highlight next item */ if (p & PAD_BUTTON_DOWN) { - filelist[selection].filename_offset = 0; selection++; if (selection == maxfiles) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; @@ -373,7 +374,6 @@ int FileSelector(unsigned char *buffer) /* highlight previous item */ else if (p & PAD_BUTTON_UP) { - filelist[selection].filename_offset = 0; selection--; if (selection < 0) { @@ -387,7 +387,6 @@ int FileSelector(unsigned char *buffer) /* go back one page */ else if (p & PAD_TRIGGER_L) { - filelist[selection].filename_offset = 0; selection -= PAGESIZE; if (selection < 0) { @@ -401,7 +400,6 @@ int FileSelector(unsigned char *buffer) /* go forward one page */ else if (p & PAD_TRIGGER_R) { - filelist[selection].filename_offset = 0; selection += PAGESIZE; if (selection > maxfiles - 1) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; @@ -410,7 +408,6 @@ int FileSelector(unsigned char *buffer) /* quit */ else if (p & PAD_TRIGGER_Z) { - filelist[selection].filename_offset = 0; GUI_DeleteMenu(m); gxTextureClose(&bar_over.texture); gxTextureClose(&dir_icon.texture); @@ -420,7 +417,7 @@ int FileSelector(unsigned char *buffer) /* open selected file or directory */ else if ((p & PAD_BUTTON_A) || (p & PAD_BUTTON_B)) { - filelist[selection].filename_offset = 0; + string_offset = 0; go_up = 0; if (p & PAD_BUTTON_B) @@ -435,7 +432,6 @@ int FileSelector(unsigned char *buffer) /* arrow buttons selected */ if (m->selected == m->max_buttons) /* up arrow */ { - filelist[selection].filename_offset = 0; selection--; if (selection < 0) { @@ -447,7 +443,6 @@ int FileSelector(unsigned char *buffer) } else if (m->selected == (m->max_buttons+1)) /* down arrow */ { - filelist[selection].filename_offset = 0; selection++; if (selection == maxfiles) selection = offset = 0; if ((selection - offset) >= PAGESIZE) offset += PAGESIZE; @@ -461,15 +456,40 @@ int FileSelector(unsigned char *buffer) /*** This is directory ***/ if (filelist[selection].flags) { + /* force going up */ + go_up = (selection == 0); + /* get new directory */ - if (useFAT) ret = FAT_UpdateDir(go_up); - else ret = DVD_UpdateDir(go_up); + if (useFAT) + ret = FAT_UpdateDir(go_up,filelist[selection].filename); + else + ret = DVD_UpdateDir(go_up,filelist[selection].offset,filelist[selection].length); /* get new entry list or quit */ if (ret) { - if (useFAT) maxfiles = FAT_ParseDirectory(); - else maxfiles = DVD_ParseDirectory(); + /* reinit selector (previous value is saved for one level) */ + if (selection == 0) + { + selection = old_selection; + offset = old_offset; + old_selection = 0; + old_offset = 0; + } + else + { + /* save current selector value */ + old_selection = selection; + old_offset = offset; + selection = 0; + offset = 0; + } + + /* get directory entries */ + if (useFAT) + maxfiles = FAT_ParseDirectory(); + else + maxfiles = DVD_ParseDirectory(); } else { @@ -493,22 +513,46 @@ int FileSelector(unsigned char *buffer) } else { - if (useFAT) size = FAT_LoadFile(buffer); - else size = DVD_LoadFile(buffer); - if (size) + /* user confirmation */ + if (GUI_ConfirmPrompt("WARNING", "Load File ?")) { - memfile_autosave(-1,config.state_auto); - reloadrom(size,filelist[selection].filename); - memfile_autoload(config.sram_auto,config.state_auto); + /* Load ROM file from device */ + if (useFAT) + size = FAT_LoadFile(buffer,selection); + else + size = DVD_LoadFile(buffer,selection); + + /* Reload emulation */ + if (size) + { + memfile_autosave(-1,config.state_auto); + reloadrom(size,filelist[selection].filename); + memfile_autoload(config.sram_auto,config.state_auto); + } + + /* Exit */ + GUI_MsgBoxClose(); + GUI_DeleteMenu(m); + gxTextureClose(&bar_over.texture); + gxTextureClose(&dir_icon.texture); + return size; } + + /* use canceled */ GUI_MsgBoxClose(); - GUI_DeleteMenu(m); - gxTextureClose(&bar_over.texture); - gxTextureClose(&dir_icon.texture); - return size; } } } } } } + + +void FileSelClear(u32 max) +{ + maxfiles = max; + offset = 0; + selection = 0; + old_offset = 0; + old_selection = 0; +} diff --git a/source/gx/gui/filesel.h b/source/gx/gui/filesel.h index 2b96ec2..f510c11 100644 --- a/source/gx/gui/filesel.h +++ b/source/gx/gui/filesel.h @@ -32,25 +32,16 @@ typedef struct { u64 offset; - unsigned int length; + u32 length; char flags; char filename[MAXJOLIET]; u16 filename_offset; }FILEENTRIES; - -/* Global Variables */ -extern FILEENTRIES filelist[MAXFILES]; -extern int maxfiles; -extern int offset; -extern int selection; -extern int old_selection; -extern int old_offset; -extern int useFAT; -extern int haveDVDdir; -extern int haveFATdir; - -extern int FileSelector(unsigned char *buffer); +/* Globals */ +extern int FileSelector(unsigned char *buffer, bool useFAT); extern int FileSortCallback(const void *f1, const void *f2); +extern void FileSelClear(u32 max); +extern FILEENTRIES filelist[MAXFILES]; #endif diff --git a/source/gx/gui/gui.c b/source/gx/gui/gui.c index c7ae9ec..c0cdb76 100644 --- a/source/gx/gui/gui.c +++ b/source/gx/gui/gui.c @@ -1398,10 +1398,39 @@ void GUI_WaitPrompt(char *title, char *msg) while (m_input.keys & PAD_BUTTON_A) VIDEO_WaitVSync(); while (!(m_input.keys & PAD_BUTTON_A)) VIDEO_WaitVSync(); - /* close message box if required */ + /* close message box */ GUI_MsgBoxClose(); } +int GUI_ConfirmPrompt(char *title, char *msg) +{ + if (config.askConfirm) + { + /* update message box */ + gxTextureClose(&message_box.throbber); + GUI_MsgBoxOpen(title, msg, 0); + + /* allocate textures */ + message_box.buttonA = gxTextureOpenPNG(Key_A_png,0); + message_box.buttonB = gxTextureOpenPNG(Key_B_png,0); + + /* wait for button A or button B*/ + s16 p = 0; + while (m_input.keys) VIDEO_WaitVSync(); + while (!(p & (PAD_BUTTON_A | PAD_BUTTON_B))) + { + VIDEO_WaitVSync(); + p = m_input.keys; + } + + /* return user choice */ + if (p & PAD_BUTTON_A) return 1; + else return 0; + } + + return 1; +} + /* Basic Fading */ void GUI_FadeOut() { diff --git a/source/gx/gui/gui.h b/source/gx/gui/gui.h index 811e621..a04dd50 100644 --- a/source/gx/gui/gui.h +++ b/source/gx/gui/gui.h @@ -291,6 +291,7 @@ extern void GUI_MsgBoxOpen(char *title, char *msg, bool throbber); extern void GUI_MsgBoxUpdate(gui_menu *parent, char *title, char *msg); extern void GUI_MsgBoxClose(void); extern void GUI_WaitPrompt(char *title, char *msg); +extern int GUI_ConfirmPrompt(char *title, char *msg); extern void GUI_FadeOut(); extern void GUI_SetBgColor(GXColor color); extern void GUI_Initialize(void); diff --git a/source/gx/gui/menu.c b/source/gx/gui/menu.c index 5018c32..d65fa37 100644 --- a/source/gx/gui/menu.c +++ b/source/gx/gui/menu.c @@ -1798,7 +1798,7 @@ static int loadmenu () if (DVD_Open()) { GUI_DeleteMenu(m); - size = FileSelector(cart_rom); + size = FileSelector(cart_rom,0); if (size) return 1; GUI_InitMenu(m); } @@ -1809,7 +1809,7 @@ static int loadmenu () if (FAT_Open(ret)) { GUI_DeleteMenu(m); - size = FileSelector(cart_rom); + size = FileSelector(cart_rom,1); if (size) return 1; GUI_InitMenu(m); } diff --git a/source/gx/osd.h b/source/gx/osd.h index d79a669..9354742 100644 --- a/source/gx/osd.h +++ b/source/gx/osd.h @@ -27,9 +27,9 @@ #define DEFAULT_PATH "/genplus" #ifdef HW_RVL -#define VERSION "version 1.3.xW" +#define VERSION "version 1.3.2W" #else -#define VERSION "version 1.3.XG" +#define VERSION "version 1.3.2G" #endif /* globals */