From a96cdceb41659da3a01311bbbbee7dbb9e2d89c3 Mon Sep 17 00:00:00 2001 From: "LGB (Gabor Lenart)" Date: Mon, 14 Mar 2022 11:03:42 +0100 Subject: [PATCH] sdcard: real umount fix + remove unused feature for #140 --- targets/mega65/sdcard.c | 15 +++++++++------ targets/mega65/ui.c | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/targets/mega65/sdcard.c b/targets/mega65/sdcard.c index 7cd333e8..3904484f 100644 --- a/targets/mega65/sdcard.c +++ b/targets/mega65/sdcard.c @@ -90,7 +90,6 @@ static struct { char *current_name; int internal; // is internal mount? FIXME: in this source it's a hard to understand 3-stated logic being 0,1 or -1 ... let's fix this! char *force_external_name; - char *default_external_name; Uint32 at_sector; // valid only if "internal", internal mount sector number Uint32 at_sector_initial; // internal mount sector number during only the first (reset/poweron) trap int monitoring_initial; // if true, at_sector_initial is monitored and changed, if false, not anymore @@ -338,7 +337,6 @@ int sdcard_init ( const char *fn, const int virtsd_flag, const int default_d81_i mount_info[a].current_name = xemu_strdup(""); mount_info[a].internal = -1; mount_info[a].force_external_name = NULL; - mount_info[a].default_external_name = NULL; mount_info[a].at_sector = 0; mount_info[a].at_sector_initial = 0; mount_info[a].monitoring_initial = 0; @@ -840,14 +838,14 @@ static int internal_mount ( const int unit ) Uint32 at_sector; if (!unit) { // must be 'image enabled' and 'disk present' bit set for "unit 0" - if ((sd_regs[0xB] & 0x03) != 0x03 || mount_info[0].force_external_name || mount_info[0].default_external_name) + if ((sd_regs[0xB] & 0x03) != 0x03 || mount_info[0].force_external_name) return 0; if (/*(sd_regs[0xB] & 0x04) ||*/ sd_is_read_only) // it seems checking the register as well causes RO mount for some reason, let's ignore for now! ro_flag = D81ACCESS_RO; at_sector = U8A_TO_U32(sd_regs + 0x0C); } else { // must be 'image enabled' and 'disk present' bit set for "unit 1" - if ((sd_regs[0xB] & 0x18) != 0x18 || mount_info[1].force_external_name || mount_info[1].default_external_name) + if ((sd_regs[0xB] & 0x18) != 0x18 || mount_info[1].force_external_name) return 0; if (/*(sd_regs[0xB] & 0x20) ||*/ sd_is_read_only) // see above at the similar line for drive-0 ro_flag = D81ACCESS_RO; @@ -883,7 +881,7 @@ static int internal_mount ( const int unit ) static int some_mount ( const int unit ) { - const char *extfn = mount_info[unit].force_external_name ? mount_info[unit].force_external_name : mount_info[unit].default_external_name; + const char *extfn = mount_info[unit].force_external_name; if (extfn) { // force external mount if (strcmp(mount_info[unit].current_name, extfn)) { DEBUGPRINT("SDCARD: D81: external mount #%d change from \"%s\" to \"%s\"" NL, unit, mount_info[unit].current_name, extfn); @@ -909,7 +907,7 @@ static int some_mount ( const int unit ) mount_info[unit].current_name[0] = '\0'; mount_info[unit].internal = -1; } /* else - DEBUGPRINT("SDCARD: D81: internal mount #%d failed?" NL, unit); */ + DEBUGPRINT("SDCARD: D81: internal mount #%d failed?" NL, unit); */ // FIXME: remove/rethink this part! internal_mount() can return with non-zero, zero or negative as answer!! return 0; } @@ -961,6 +959,11 @@ int sdcard_unmount ( const int unit ) d81access_close(unit); mount_info[unit].internal = 0; // FIXME ??? xemu_restrdup(&mount_info[unit].current_name, ""); + if (mount_info[unit].force_external_name) { + // We must null this out, otherwise next (even internal) mount will pick it up and use it again as this external mount! + free(mount_info[unit].force_external_name); + mount_info[unit].force_external_name = NULL; + } return 0; } diff --git a/targets/mega65/ui.c b/targets/mega65/ui.c index 54b46104..0f1efb10 100644 --- a/targets/mega65/ui.c +++ b/targets/mega65/ui.c @@ -67,7 +67,7 @@ static void ui_cb_attach_default_d81 ( const struct menu_st *m, int *query ) static void ui_cb_attach_d81 ( const struct menu_st *m, int *query ) { XEMUGUI_RETURN_CHECKED_ON_QUERY(query, 0); - const int drive = VOIDPTR_TO_INT(m->user_data) & 0x7F; + const int drive = VOIDPTR_TO_INT(m->user_data) & 1; // only two possible drives (or units, or WTF ...) const int creat = !!(VOIDPTR_TO_INT(m->user_data) & 0x80); char fnbuf[PATH_MAX + 1]; static char dir[PATH_MAX + 1] = "";