Merge branch 'host_config' into 'experimental'

add F4-text UI for selecting host file directory.

This only displays folders. Return enters a folder as usual. Press Space to select a folder

(Space also selects a file in the ROM/disk image file selector)

See merge request !8
This commit is contained in:
Dagen Brock 2017-04-05 09:39:43 -05:00
commit e403bdc8f7
3 changed files with 169 additions and 148 deletions

View File

@ -169,11 +169,13 @@ char g_cfg_opts_strvals[CFG_MAX_OPTS][CFG_OPT_MAXSTR];
char g_cfg_opt_buf[CFG_OPT_MAXSTR]; char g_cfg_opt_buf[CFG_OPT_MAXSTR];
char *g_cfg_rom_path = "ROM"; char *g_cfg_rom_path = "ROM";
char *g_cfg_file_def_name = "Undefined"; const char *g_cfg_file_def_name = "Undefined";
char **g_cfg_file_strptr = 0; char **g_cfg_file_strptr = 0;
int g_cfg_file_min_size = 1024; int g_cfg_file_min_size = 1024;
int g_cfg_file_max_size = 2047*1024*1024; int g_cfg_file_max_size = 2047*1024*1024;
int g_cfg_file_dir_only = 0;
#define MAX_PARTITION_BLK_SIZE 65536 #define MAX_PARTITION_BLK_SIZE 65536
extern Cfg_menu g_cfg_main_menu[]; extern Cfg_menu g_cfg_main_menu[];
@ -240,7 +242,7 @@ Cfg_menu g_cfg_rom_menu[] = {
Cfg_menu g_cfg_host_menu[] = { Cfg_menu g_cfg_host_menu[] = {
{ "Host FST Configuration", g_cfg_host_menu, 0, 0, CFGTYPE_MENU }, { "Host FST Configuration", g_cfg_host_menu, 0, 0, CFGTYPE_MENU },
{ "Shared Host Folder", KNMP(g_cfg_host_path), CFGTYPE_STR }, { "Shared Host Folder", KNMP(g_cfg_host_path), CFGTYPE_DIR },
{ "Read Only,0,No,1,Yes", KNMP(g_cfg_host_read_only), CFGTYPE_INT }, { "Read Only,0,No,1,Yes", KNMP(g_cfg_host_read_only), CFGTYPE_INT },
{ "", 0, 0, 0, 0 }, { "", 0, 0, 0, 0 },
{ "Back to Main Config", g_cfg_main_menu, 0, 0, CFGTYPE_MENU }, { "Back to Main Config", g_cfg_main_menu, 0, 0, CFGTYPE_MENU },
@ -534,15 +536,8 @@ config_init_menus(Cfg_menu *menuptr)
menuptr->defptr = &(defptr->intval); menuptr->defptr = &(defptr->intval);
break; break;
case CFGTYPE_STR: case CFGTYPE_STR:
str_ptr = (char **)menuptr->ptr;
str = *str_ptr;
// We need to malloc this string since all
// string values must be dynamically alloced
defptr->strval = str; // this can have a copy
*str_ptr = gsplus_malloc_str(str);
menuptr->defptr = &(defptr->strval);
break;
case CFGTYPE_FILE: case CFGTYPE_FILE:
case CFGTYPE_DIR:
str_ptr = (char **)menuptr->ptr; str_ptr = (char **)menuptr->ptr;
str = *str_ptr; str = *str_ptr;
// We need to malloc this string since all // We need to malloc this string since all
@ -775,13 +770,8 @@ config_parse_option(char *buf, int pos, int len, int line)
*iptr = val; *iptr = val;
break; break;
case CFGTYPE_STR: case CFGTYPE_STR:
strptr = (char **)menuptr->ptr;
if(strptr && *strptr) {
free(*strptr);
}
*strptr = gsplus_malloc_str(&buf[pos]);
break;
case CFGTYPE_FILE: case CFGTYPE_FILE:
case CFGTYPE_DIR:
strptr = (char **)menuptr->ptr; strptr = (char **)menuptr->ptr;
if(strptr && *strptr) { if(strptr && *strptr) {
free(*strptr); free(*strptr);
@ -1319,28 +1309,25 @@ config_write_config_gsplus_file()
menuptr = defptr->menuptr; menuptr = defptr->menuptr;
defval = defptr->intval; defval = defptr->intval;
type = menuptr->cfgtype; type = menuptr->cfgtype;
if(type == CFGTYPE_INT) {
switch (type) {
case CFGTYPE_INT:
curval = *((int *)menuptr->ptr); curval = *((int *)menuptr->ptr);
if(curval != defval) { if(curval != defval) {
fprintf(fconf, "%s = %d\n", menuptr->name_str, fprintf(fconf, "%s = %d\n", menuptr->name_str,
curval); curval);
} }
} break;
if(type == CFGTYPE_STR) { case CFGTYPE_STR:
curstr = *((char **)menuptr->ptr); case CFGTYPE_FILE:
defstr = *((char **)menuptr->defptr); case CFGTYPE_DIR:
if(strcmp(curstr, defstr) != 0) {
fprintf(fconf, "%s = %s\n", menuptr->name_str,
curstr);
}
}
if(type == CFGTYPE_FILE) {
curstr = *((char **)menuptr->ptr); curstr = *((char **)menuptr->ptr);
defstr = *((char **)menuptr->defptr); defstr = *((char **)menuptr->defptr);
if(strcmp(curstr, defstr) != 0) { if(strcmp(curstr, defstr) != 0) {
fprintf(fconf, "%s = %s\n", menuptr->name_str, fprintf(fconf, "%s = %s\n", menuptr->name_str,
curstr); curstr);
} }
break;
} }
} }
@ -2282,7 +2269,10 @@ cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change)
curval = -1; curval = -1;
defval = -1; defval = -1;
curstr = 0; curstr = 0;
if(type == CFGTYPE_INT) {
switch(type) {
case CFGTYPE_INT:
iptr = (int*)menuptr->ptr; // OG Added cast iptr = (int*)menuptr->ptr; // OG Added cast
curval = *iptr; curval = *iptr;
iptr = (int*)menuptr->defptr; // OG Added cast iptr = (int*)menuptr->defptr; // OG Added cast
@ -2291,8 +2281,10 @@ cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change)
g_cfg_opt_buf[3] = 'D'; /* checkmark */ g_cfg_opt_buf[3] = 'D'; /* checkmark */
g_cfg_opt_buf[4] = '\t'; g_cfg_opt_buf[4] = '\t';
} }
} break;
if(type == CFGTYPE_STR) { case CFGTYPE_STR:
case CFGTYPE_FILE:
case CFGTYPE_DIR:
str_ptr = (char **)menuptr->ptr; str_ptr = (char **)menuptr->ptr;
curstr = *str_ptr; curstr = *str_ptr;
str_ptr = (char **)menuptr->defptr; str_ptr = (char **)menuptr->defptr;
@ -2301,30 +2293,30 @@ cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change)
g_cfg_opt_buf[3] = 'D'; /* checkmark */ g_cfg_opt_buf[3] = 'D'; /* checkmark */
g_cfg_opt_buf[4] = '\t'; g_cfg_opt_buf[4] = '\t';
} }
} break;
if(type == CFGTYPE_FILE) {
str_ptr = (char **)menuptr->ptr;
curstr = *str_ptr;
str_ptr = (char **)menuptr->defptr;
defstr = *str_ptr;
if(strcmp(curstr,defstr) == 0) {
g_cfg_opt_buf[3] = 'D'; /* checkmark */
g_cfg_opt_buf[4] = '\t';
}
}
// If it's a menu, give it a special menu indicator // If it's a menu, give it a special menu indicator
if(type == CFGTYPE_MENU) { case CFGTYPE_MENU:
g_cfg_opt_buf[1] = '\t'; g_cfg_opt_buf[1] = '\t';
g_cfg_opt_buf[2] = 'M'; /* return-like symbol */ g_cfg_opt_buf[2] = 'M'; /* return-like symbol */
g_cfg_opt_buf[3] = '\t'; g_cfg_opt_buf[3] = '\t';
g_cfg_opt_buf[4] = ' '; g_cfg_opt_buf[4] = ' ';
break;
} }
// Decide what to display on the "right" side // Decide what to display on the "right" side
str = 0; str = 0;
opt_num = -1; opt_num = -1;
if(type == CFGTYPE_INT || type == CFGTYPE_FILE) {
switch(type) {
case CFGTYPE_INT:
case CFGTYPE_FILE:
case CFGTYPE_DIR:
g_cfg_opt_buf[bufpos++] = ' '; g_cfg_opt_buf[bufpos++] = ' ';
g_cfg_opt_buf[bufpos++] = '='; g_cfg_opt_buf[bufpos++] = '=';
g_cfg_opt_buf[bufpos++] = ' '; g_cfg_opt_buf[bufpos++] = ' ';
@ -2335,8 +2327,9 @@ cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change)
break; break;
} }
} }
} break;
if(type == CFGTYPE_STR) {
case CFGTYPE_STR:
g_cfg_opt_buf[bufpos++] = ' '; g_cfg_opt_buf[bufpos++] = ' ';
g_cfg_opt_buf[bufpos++] = '='; g_cfg_opt_buf[bufpos++] = '=';
g_cfg_opt_buf[bufpos++] = ' '; g_cfg_opt_buf[bufpos++] = ' ';
@ -2347,6 +2340,7 @@ cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change)
break; break;
} }
} }
break;
} }
if(change != 0) { if(change != 0) {
@ -2396,22 +2390,28 @@ cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change)
if(opt_num >= 0) { if(opt_num >= 0) {
str = &(g_cfg_opts_strs[opt_num][0]); str = &(g_cfg_opts_strs[opt_num][0]);
} else { } else {
if(type == CFGTYPE_INT) { switch(type) {
case CFGTYPE_INT:
str = &(g_cfg_opts_strs[0][0]); str = &(g_cfg_opts_strs[0][0]);
snprintf(str, CFG_OPT_MAXSTR, "%d", curval); snprintf(str, CFG_OPT_MAXSTR, "%d", curval);
} else if (type == CFGTYPE_STR) { break;
case CFGTYPE_STR:
str = &(g_cfg_opts_strs[0][0]); str = &(g_cfg_opts_strs[0][0]);
printf("curstr is: %s str is: %s\n", curstr,str); //printf("curstr is: %s str is: %s\n", curstr,str);
snprintf(str, CFG_OPT_MAXSTR, "%s", curstr); snprintf(str, CFG_OPT_MAXSTR, "%s", curstr);
} else if (type == CFGTYPE_DISK) { break;
case CFGTYPE_DISK:
str = &(g_cfg_opts_strs[0][0]), str = &(g_cfg_opts_strs[0][0]),
cfg_get_disk_name(str, CFG_OPT_MAXSTR, type_ext, 1); cfg_get_disk_name(str, CFG_OPT_MAXSTR, type_ext, 1);
str = cfg_shorten_filename(str, 68); str = cfg_shorten_filename(str, 68);
} else if (type == CFGTYPE_FILE) { break;
case CFGTYPE_FILE:
case CFGTYPE_DIR:
str = &(g_cfg_opts_strs[0][0]); str = &(g_cfg_opts_strs[0][0]);
snprintf(str, CFG_OPT_MAXSTR, "%s", curstr); snprintf(str, CFG_OPT_MAXSTR, "%s", curstr);
str = cfg_shorten_filename(str, 68); str = cfg_shorten_filename(str, 68);
} else { break;
default:
str = ""; str = "";
} }
} }
@ -2778,6 +2778,8 @@ cfg_file_readdir(const char *pathptr)
} }
} }
} }
if (g_cfg_file_dir_only && !is_dir) continue;
cfg_file_add_dirent(&g_cfg_dirlist, direntptr->d_name, is_dir, cfg_file_add_dirent(&g_cfg_dirlist, direntptr->d_name, is_dir,
stat_buf.st_size, -1, -1); stat_buf.st_size, -1, -1);
} }
@ -2964,8 +2966,8 @@ cfg_file_draw()
cfg_shorten_filename(g_cfg_file_def_name, 40)); cfg_shorten_filename(g_cfg_file_def_name, 40));
} }
cfg_htab_vtab(2, 1); cfg_htab_vtab(2, 1);
cfg_printf("Configuration file path: %-56s", cfg_printf("Configuration file path: %-40s",
cfg_shorten_filename(&g_config_gsplus_name[0], 56)); cfg_shorten_filename(&g_config_gsplus_name[0], 40));
cfg_htab_vtab(2, 2); cfg_htab_vtab(2, 2);
cfg_printf("Current directory: %-50s", cfg_printf("Current directory: %-50s",
cfg_shorten_filename(&g_cfg_cwd_str[0], 50)); cfg_shorten_filename(&g_cfg_cwd_str[0], 50));
@ -3084,7 +3086,7 @@ cfg_file_update_ptr(char *str)
g_config_gsplus_update_needed = 1; g_config_gsplus_update_needed = 1;
} }
void void
cfg_file_selected() cfg_file_selected(int select_dir)
{ {
#ifndef __OS2__ #ifndef __OS2__
struct stat stat_buf; struct stat stat_buf;
@ -3113,13 +3115,15 @@ cfg_file_selected()
} }
ret = cfg_stat(&g_cfg_file_path[0], &stat_buf); ret = cfg_stat(&g_cfg_file_path[0], &stat_buf);
fmt = stat_buf.st_mode & S_IFMT; fmt = stat_buf.st_mode & S_IFMT;
#if 0
cfg_printf("Stat'ing %s, st_mode is: %08x\n", &g_cfg_file_path[0], cfg_printf("Stat'ing %s, st_mode is: %08x\n", &g_cfg_file_path[0],
(int)stat_buf.st_mode); (int)stat_buf.st_mode);
#endif
if(ret != 0) { if(ret != 0) {
printf("stat %s returned %d, errno: %d\n", &g_cfg_file_path[0], printf("stat %s returned %d, errno: %d\n", &g_cfg_file_path[0],
ret, errno); ret, errno);
} else { } else {
if(fmt == S_IFDIR) { if(fmt == S_IFDIR && !select_dir) {
/* it's a directory */ /* it's a directory */
strncpy(&g_cfg_file_curpath[0], &g_cfg_file_path[0], strncpy(&g_cfg_file_curpath[0], &g_cfg_file_path[0],
CFG_PATH_MAX); CFG_PATH_MAX);
@ -3190,8 +3194,8 @@ cfg_file_handle_key(int key)
} }
break; break;
case 0x0d: /* return */ case 0x0d: /* return */
glog("Selected disk image file"); //glog("Selected disk image file");
cfg_file_selected(); cfg_file_selected(0);
break; break;
case 0x09: /* tab */ case 0x09: /* tab */
g_cfg_file_pathfield = !g_cfg_file_pathfield; g_cfg_file_pathfield = !g_cfg_file_pathfield;
@ -3206,6 +3210,9 @@ cfg_file_handle_key(int key)
} }
} }
break; break;
case 0x20: /* space -- selects file/directory */
cfg_file_selected(g_cfg_file_dir_only);
break;
default: default:
printf("key: %02x\n", key); printf("key: %02x\n", key);
} }
@ -3240,7 +3247,7 @@ config_control_panel()
(0xf << BIT_ALL_STAT_TEXT_COLOR) | ALL_STAT_ALTCHARSET; (0xf << BIT_ALL_STAT_TEXT_COLOR) | ALL_STAT_ALTCHARSET;
g_a2_new_all_stat[0] = g_cur_a2_stat; g_a2_new_all_stat[0] = g_cur_a2_stat;
g_new_a2_stat_cur_line = 0; g_new_a2_stat_cur_line = 0;
cfg_printf("In config_control_panel\n"); //cfg_printf("In config_control_panel\n");
for(i = 0; i < 20; i++) { for(i = 0; i < 20; i++) {
// Toss any queued-up keypresses // Toss any queued-up keypresses
if(adb_read_c000() & 0x80) { if(adb_read_c000() & 0x80) {
@ -3385,6 +3392,7 @@ config_control_panel()
case 0x0d: case 0x0d:
type = menuptr[menu_line].cfgtype; type = menuptr[menu_line].cfgtype;
ptr = menuptr[menu_line].ptr; ptr = menuptr[menu_line].ptr;
str = menuptr[menu_line].str;
switch(type & 0xf) { switch(type & 0xf) {
case CFGTYPE_MENU: case CFGTYPE_MENU:
menuptr = (Cfg_menu *)ptr; menuptr = (Cfg_menu *)ptr;
@ -3392,6 +3400,7 @@ config_control_panel()
break; break;
case CFGTYPE_DISK: case CFGTYPE_DISK:
g_cfg_slotdrive = type >> 4; g_cfg_slotdrive = type >> 4;
g_cfg_file_dir_only = 0;
cfg_file_init(); cfg_file_init();
break; break;
case CFGTYPE_FUNC: case CFGTYPE_FUNC:
@ -3401,9 +3410,18 @@ config_control_panel()
break; break;
case CFGTYPE_FILE: case CFGTYPE_FILE:
g_cfg_slotdrive = 0xfff; g_cfg_slotdrive = 0xfff;
g_cfg_file_def_name = *((char **)ptr); g_cfg_file_def_name = str /* *((char **)ptr) */; // was ptr
g_cfg_file_strptr = (char **)ptr; g_cfg_file_strptr = (char **)ptr;
g_cfg_file_dir_only = 0;
cfg_file_init(); cfg_file_init();
break;
case CFGTYPE_DIR:
g_cfg_slotdrive = 0xfff;
g_cfg_file_def_name = str /* *((char **)ptr) */; // was ptr
g_cfg_file_strptr = (char **)ptr;
g_cfg_file_dir_only = 1;
cfg_file_init();
break;
} }
break; break;
case 0x1b: case 0x1b:

View File

@ -35,6 +35,7 @@
#define CFGTYPE_FUNC 4 #define CFGTYPE_FUNC 4
#define CFGTYPE_FILE 5 #define CFGTYPE_FILE 5
#define CFGTYPE_STR 6 #define CFGTYPE_STR 6
#define CFGTYPE_DIR 7
/* CFGTYPE limited to just 4 bits: 0-15 */ /* CFGTYPE limited to just 4 bits: 0-15 */
/* Cfg_menu, Cfg_dirent and Cfg_listhdr are defined in defc.h */ /* Cfg_menu, Cfg_dirent and Cfg_listhdr are defined in defc.h */
@ -44,3 +45,33 @@ STRUCT(Cfg_defval) {
int intval; int intval;
char *strval; char *strval;
}; };
int cfg_get_fd_size(char *filename);
int cfg_partition_read_block(FILE *file, void *buf, int blk, int blk_size);
int cfg_partition_find_by_name_or_num(FILE *file, const char *partnamestr, int part_num, Disk *dsk);
int cfg_maybe_insert_disk(int slot, int drive, const char *namestr);
int cfg_stat(char *path, struct stat *sb);
int cfg_partition_make_list(char *filename, FILE *file);
void cfg_htab_vtab(int x, int y);
void cfg_home(void);
void cfg_cleol(void);
void cfg_putchar(int c);
void cfg_printf(const char *fmt, ...);
void cfg_print_num(int num, int max_len);
void cfg_get_disk_name(char *outstr, int maxlen, int type_ext, int with_extras);
void cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change);
void cfg_get_base_path(char *pathptr, const char *inptr, int go_up);
void cfg_file_init(void);
void cfg_free_alldirents(Cfg_listhdr *listhdrptr);
void cfg_file_add_dirent(Cfg_listhdr *listhdrptr, const char *nameptr, int is_dir, int size, int image_start, int part_num);
int cfg_dirent_sortfn(const void *obj1, const void *obj2);
int cfg_str_match(const char *str1, const char *str2, int len);
void cfg_file_readdir(const char *pathptr);
char *cfg_shorten_filename(const char *in_ptr, int maxlen);
void cfg_fix_topent(Cfg_listhdr *listhdrptr);
void cfg_file_draw(void);
void cfg_partition_selected(void);
void cfg_file_update_ptr(char *str);
void cfg_file_selected(int);
void cfg_file_handle_key(int key);

View File

@ -180,34 +180,6 @@ void insert_disk(int slot, int drive, const char *name, int ejected, int force_s
void eject_named_disk(Disk *dsk, const char *name, const char *partition_name); void eject_named_disk(Disk *dsk, const char *name, const char *partition_name);
void eject_disk_by_num(int slot, int drive); void eject_disk_by_num(int slot, int drive);
void eject_disk(Disk *dsk); void eject_disk(Disk *dsk);
int cfg_get_fd_size(char *filename);
int cfg_partition_read_block(FILE *file, void *buf, int blk, int blk_size);
int cfg_partition_find_by_name_or_num(FILE *file, const char *partnamestr, int part_num, Disk *dsk);
int cfg_maybe_insert_disk(int slot, int drive, const char *namestr);
int cfg_stat(char *path, struct stat *sb);
int cfg_partition_make_list(char *filename, FILE *file);
void cfg_htab_vtab(int x, int y);
void cfg_home(void);
void cfg_cleol(void);
void cfg_putchar(int c);
void cfg_printf(const char *fmt, ...);
void cfg_print_num(int num, int max_len);
void cfg_get_disk_name(char *outstr, int maxlen, int type_ext, int with_extras);
void cfg_parse_menu(Cfg_menu *menuptr, int menu_pos, int highlight_pos, int change);
void cfg_get_base_path(char *pathptr, const char *inptr, int go_up);
void cfg_file_init(void);
void cfg_free_alldirents(Cfg_listhdr *listhdrptr);
void cfg_file_add_dirent(Cfg_listhdr *listhdrptr, const char *nameptr, int is_dir, int size, int image_start, int part_num);
int cfg_dirent_sortfn(const void *obj1, const void *obj2);
int cfg_str_match(const char *str1, const char *str2, int len);
void cfg_file_readdir(const char *pathptr);
char *cfg_shorten_filename(const char *in_ptr, int maxlen);
void cfg_fix_topent(Cfg_listhdr *listhdrptr);
void cfg_file_draw(void);
void cfg_partition_selected(void);
void cfg_file_update_ptr(char *str);
void cfg_file_selected(void);
void cfg_file_handle_key(int key);
void config_control_panel(void); void config_control_panel(void);