diff options
author | Ian C <ianc@noddybox.co.uk> | 2004-09-22 23:45:13 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2004-09-22 23:45:13 +0000 |
commit | eadcbfa85ed30c5534f5b3646b27b37d2e6eae4d (patch) | |
tree | 48e33c8467de7bc8d9021191627684ff7bd473d9 /src | |
parent | 0922b7993ce1d18de8fe975b17fd33cd3841ae9c (diff) |
Updates
Diffstat (limited to 'src')
-rw-r--r-- | src/gui.c | 177 | ||||
-rw-r--r-- | src/main.c | 25 | ||||
-rw-r--r-- | src/snap.c | 4 | ||||
-rw-r--r-- | src/util.c | 3 |
4 files changed, 192 insertions, 17 deletions
@@ -31,6 +31,11 @@ static const char ident[]="$Id$"; #include <stdarg.h> #include <ctype.h> +#include <unistd.h> +#include <dirent.h> +#include <sys/stat.h> +#include <sys/param.h> + #include "gui.h" #include "gfx.h" #include "exit.h" @@ -56,6 +61,17 @@ static const char ident_h[]=ESPEC_GUI_H; #define LOGREY GFXRGB(100,100,100) #define GREEN GFXRGB(100,255,100) + +/* ---------------------------------------- TYPES +*/ +typedef struct +{ + char name[MAXPATHLEN+1]; + unsigned size; + int is_dir; +} FileEnt; + + /* ---------------------------------------- STATICS */ @@ -216,6 +232,32 @@ static int DoList(const char *title, int no, char * const list[], int *option) } break; + case SDLK_PAGEUP: + if (cur>0) + { + cur-=(max-1); + + if (cur<0) + cur=0; + + if (cur<top) + top=cur; + } + break; + + case SDLK_PAGEDOWN: + if (cur<no-1) + { + cur+=(max-1); + + if (cur>=no) + cur=no-1; + + if (cur>top+max-2) + top=cur-max+2; + } + break; + default: break; } @@ -225,6 +267,21 @@ static int DoList(const char *title, int no, char * const list[], int *option) } +static int CmpFile(const void *va,const void *vb) +{ + const FileEnt *a=(FileEnt *)va; + const FileEnt *b=(FileEnt *)vb; + + if ((a->is_dir)&&(!b->is_dir)) + return -1; + + if ((!a->is_dir)&&(b->is_dir)) + return 1; + + return strcmp(a->name,b->name); +} + + /* ---------------------------------------- EXPORTED INTERFACES */ int GUIMessage(GUIBoxType type, const char *title, const char *format,...) @@ -425,14 +482,120 @@ int GUIListOption(const char *title, int no, char * const list[], int option[]) int GUIFileSelect(const char *prompt, int load, const char *start_dir, char path[]) { - /* TODO */ - if (load) - strcpy(path,"/files/emu/spectrum/thrust1.tap"); - else - strcpy(path,"/files/emu/spectrum/testespec.tap"); + int done=FALSE; + int ret=FALSE; + char olddir[MAXPATHLEN+1]; + char pwd[MAXPATHLEN+1]; + + if (!load) + { + GUIMessage(eMessageBox,"OOPS","Save dialog not yet done"); + return FALSE; + } + + getcwd(olddir,MAXPATHLEN); + + chdir(start_dir); + + while(!done) + { + int f; + int sel; + DIR *d; + struct dirent *de; + struct stat sbuf; + FileEnt *fe=NULL; + char **list; + int no=0; + + getcwd(pwd,MAXPATHLEN); - /* strcpy(path,"/files/emu/spectrum/testespec.tap"); */ - return TRUE; + d=opendir("."); + + while(readdir(d)) + no++; + + rewinddir(d); + + fe=Malloc(sizeof *fe * no); + no=1; + + strcpy(fe[0].name,".."); + fe[0].is_dir=TRUE; + + while((de=readdir(d))) + { + if (stat(de->d_name,&sbuf)!=-1) + { + if (S_ISDIR(sbuf.st_mode) && de->d_name[0]!='.') + { + strcpy(fe[no].name,de->d_name); + fe[no].is_dir=TRUE; + no++; + } + else if (S_ISREG(sbuf.st_mode) && de->d_name[0]!='.') + { + strcpy(fe[no].name,de->d_name); + fe[no].is_dir=FALSE; + fe[no].size=(unsigned)sbuf.st_size; + no++; + } + } + } + + closedir(d); + + qsort(fe,no,sizeof *fe,CmpFile); + + list=Malloc(sizeof *list * no); + + for(f=0;f<no;f++) + { + list[f]=Malloc(80); + + if (fe[f].is_dir) + sprintf(list[f],"%-20.20s %9s",fe[f].name,"<DIR>"); + else + sprintf(list[f],"%-20.20s %9u",fe[f].name,fe[f].size); + } + + sel=DoList(pwd,no,list,NULL); + + if (sel==-1) + { + ret=FALSE; + done=TRUE; + } + else + { + if (fe[sel].is_dir) + { + chdir(fe[sel].name); + } + else + { + strcpy(path,pwd); + + if (path[strlen(path)]!='/') + strcat(path,"/"); + + strcat(path,fe[sel].name); + + done=TRUE; + ret=TRUE; + } + } + + for(f=0;f<no;f++) + { + free(list[f]); + } + + free(list); + free(de); + } + + return ret; } @@ -71,8 +71,8 @@ static void Usage(void) */ int main(int argc, char *argv[]) { - char tape_in[FILENAME_MAX]; - char tape_out[FILENAME_MAX]; + char tape_in[FILENAME_MAX]=""; + char tape_out[FILENAME_MAX]=""; Z80 *z80; SDL_Event *e; int quit; @@ -84,9 +84,6 @@ int main(int argc, char *argv[]) trace=IConfig(CONF_TRACE); - strcpy(tape_in,SConfig(CONF_TAPEDIR)); - strcpy(tape_out,SConfig(CONF_TAPEDIR)); - z80=Z80Init(SPECWriteMem, SPECReadMem, SPECWriteWord, @@ -265,22 +262,36 @@ int main(int argc, char *argv[]) case SDLK_F8: if (e->key.state==SDL_PRESSED) { + GFXKeyRepeat(TRUE); + if (GUIFileSelect("TAPE TO LOAD",TRUE, - tape_in,tape_in)) + tape_in[0] ? + Dirname(tape_in) : + SConfig(CONF_TAPEDIR), + tape_in)) { SPECMount(SPEC_TAPE_IN,tape_in); } + + GFXKeyRepeat(FALSE); } break; case SDLK_F9: if (e->key.state==SDL_PRESSED) { + GFXKeyRepeat(TRUE); + if (GUIFileSelect("TAPE TO SAVE",FALSE, - tape_out,tape_out)) + tape_out[0] ? + Dirname(tape_out) : + SConfig(CONF_TAPEDIR), + tape_out)) { SPECMount(SPEC_TAPE_OUT,tape_out); } + + GFXKeyRepeat(FALSE); } break; @@ -118,11 +118,11 @@ int TAPLoad(FILE *fp, Z80Byte id, Z80Word *addr, Z80Word *len, SNAP_Poke poke) blen=GetLSBWord(fp); } - Debug("blen=%u type=%u\n",id); - type=GetByte(fp); csum=id; + Debug("blen=%u type=%u id=%u\n",blen,type,id); + /* Have we found the requested block? */ if (id==type) @@ -28,6 +28,7 @@ static const char ident[]="$Id$"; #include <stdio.h> #include <string.h> #include <stdarg.h> +#include <sys/param.h> #include "util.h" #include "exit.h" @@ -85,7 +86,7 @@ const char *Basename(const char *path) const char *Dirname(const char *path) { - static char dir[FILENAME_MAX]; + static char dir[MAXPATHLEN+1]; char *p; strcpy(dir,path); |