From 62e0729de4b856d1230e5fd2d6558c188386a683 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 23 Apr 2023 10:30:44 +0800 Subject: Added global last_dir[] to record last file selector dir. --- include/gui.h | 3 +++ source/gui.c | 19 ++++++++++++++++++- source/main.c | 1 + source/snapshot.c | 1 - source/zx81.c | 2 -- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/gui.h b/include/gui.h index c5eeaed..77bfb60 100644 --- a/include/gui.h +++ b/include/gui.h @@ -21,6 +21,7 @@ #ifndef DS81_GUI_H #define DS81_GUI_H +void GUI_Init(void); int GUI_Menu(const char *opts[]); void GUI_Alert(int fatal, const char *text); void GUI_Config(void); @@ -30,4 +31,6 @@ int GUI_InputName(const char *prompt, const char *ext, char name[], int maxlen); int GUI_Input(const char *prompt, char text[], int maxlen); +extern char last_dir[FILENAME_MAX]; + #endif /* DS81_GUI_H */ diff --git a/source/gui.c b/source/gui.c index bf1feb5..c68fafd 100644 --- a/source/gui.c +++ b/source/gui.c @@ -59,6 +59,8 @@ typedef struct static FSEL_File fsel[FSEL_MAX_FILES]; +char last_dir[FILENAME_MAX] = "sdmc:/ZX81/"; + static void CheckPath(char *path) { @@ -180,7 +182,7 @@ static int LoadDir(const char *path, const char *filter) if ((dir = opendir(path))) { - if (strcmp(path, "/") != 0) + if (strcmp(path, "sdmc:/") != 0) { strcpy(fsel[no].name, ".."); fsel[no].is_dir = TRUE; @@ -216,6 +218,21 @@ static int LoadDir(const char *path, const char *filter) /* ---------------------------------------- PUBLIC INTERFACES */ +void GUI_Init(void) +{ + DIR *dir; + + if ((dir = opendir(last_dir))) + { + closedir(dir); + } + else + { + strcpy(last_dir, "sdmc:/"); + } +} + + int GUI_Menu(const char *opts[]) { int x,y; diff --git a/source/main.c b/source/main.c index 9e4e9b2..fbd7583 100644 --- a/source/main.c +++ b/source/main.c @@ -765,6 +765,7 @@ int main(int argc, char *argv[]) gfxInit(GSP_RGB565_OES, GSP_RGB565_OES, false); FB_Init(); + GUI_Init(); z80 = Z80Init(ZX81ReadMem, ZX81WriteMem, diff --git a/source/snapshot.c b/source/snapshot.c index b64d309..5be1358 100644 --- a/source/snapshot.c +++ b/source/snapshot.c @@ -137,7 +137,6 @@ void SNAP_Save(Z80 *cpu, SnapshotType type) void SNAP_Load(Z80 *cpu, const char *optional_name, SnapshotType type) { - static char last_dir[FILENAME_MAX] = "/"; char file[FILENAME_MAX]; FILE *fp = NULL; diff --git a/source/zx81.c b/source/zx81.c index 1335d0b..7626034 100644 --- a/source/zx81.c +++ b/source/zx81.c @@ -104,8 +104,6 @@ static int allow_save; static const Z80Byte *tape_image; static int tape_len; -static char last_dir[FILENAME_MAX] = "/"; - /* The keyboard */ static Z80Byte matrix[8]; -- cgit v1.2.3