From c47e766bc40d15048d7e07a1cefa67710994ef28 Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 23 Jul 2021 01:20:14 +0200 Subject: [PATCH] The migration of the legacy SCSI controller is now perfectly seamless, thanks, Ryuzaki! --- src/config.c | 40 +++++++++++++++++++++++++------------- src/device.c | 15 ++++++++++++-- src/include/86box/config.h | 3 +++ src/include/86box/scsi.h | 1 - src/scsi/scsi.c | 7 ------- src/win/win_media_menu.c | 6 +++--- src/win/win_settings.c | 34 +------------------------------- src/win/win_stbar.c | 22 ++++++++------------- 8 files changed, 54 insertions(+), 74 deletions(-) diff --git a/src/config.c b/src/config.c index 7d317d37e..f9347a0a4 100644 --- a/src/config.c +++ b/src/config.c @@ -158,6 +158,23 @@ find_section(char *name) } +void * +config_find_section(char *name) +{ + return (void *) find_section(name); +} + + +void +config_rename_section(void *priv, char *name) +{ + section_t *sec = (section_t *) priv; + + memset(sec->name, 0x00, sizeof(sec->name)); + memcpy(sec->name, name, MIN(128, strlen(name) + 1)); +} + + static entry_t * find_entry(section_t *section, char *name) { @@ -1015,7 +1032,7 @@ load_storage_controllers(void) { char *cat = "Storage controllers"; char *p, temp[512]; - int c; + int c, min = 0; int free_p = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ @@ -1023,12 +1040,13 @@ load_storage_controllers(void) /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ p = config_get_string(cat, "scsicard", NULL); - if (p != NULL) - scsi_card_current_legacy = scsi_card_get_from_internal_name(p); - else - scsi_card_current_legacy = 0; + if (p != NULL) { + scsi_card_current[0] = scsi_card_get_from_internal_name(p); + min++; + } + config_delete_var(cat, "scsi_card"); - for (c = 0; c < SCSI_BUS_MAX; c++) { + for (c = min; c < SCSI_BUS_MAX; c++) { sprintf(temp, "scsicard_%d", c + 1); p = config_get_string(cat, temp, NULL); @@ -1816,9 +1834,9 @@ load_other_peripherals(void) if (backwards_compat2) { p = config_get_string(cat, "scsicard", NULL); if (p != NULL) - scsi_card_current_legacy = scsi_card_get_from_internal_name(p); + scsi_card_current[0] = scsi_card_get_from_internal_name(p); else - scsi_card_current_legacy = 0; + scsi_card_current[0] = 0; config_delete_var(cat, "scsicard"); p = config_get_string(cat, "fdc", NULL); @@ -2421,12 +2439,6 @@ save_storage_controllers(void) char temp[512]; int c; - if (scsi_card_current_legacy == 0) - config_delete_var(cat, "scsicard"); - else - config_set_string(cat, "scsicard", - scsi_card_get_internal_name(scsi_card_current_legacy)); - for (c = 0; c < SCSI_BUS_MAX; c++) { sprintf(temp, "scsicard_%d", c + 1); diff --git a/src/device.c b/src/device.c index 8f3e153bc..439f558a1 100644 --- a/src/device.c +++ b/src/device.c @@ -90,11 +90,22 @@ device_init(void) void device_set_context(device_context_t *c, const device_t *d, int inst) { + void *sec, *single_sec; + memset(c, 0, sizeof(device_context_t)); c->dev = d; - if (inst) + if (inst) { sprintf(c->name, "%s #%i", d->name, inst); - else + + /* If this is the first instance and a numbered section is not present, but a non-numbered + section of the same name is, rename the non-numbered section to numbered. */ + if (inst == 1) { + sec = config_find_section(c->name); + single_sec = config_find_section((char *) d->name); + if ((sec == NULL) && (single_sec != NULL)) + config_rename_section(single_sec, c->name); + } + } else sprintf(c->name, "%s", d->name); } diff --git a/src/include/86box/config.h b/src/include/86box/config.h index eaca8bcf6..549306daa 100644 --- a/src/include/86box/config.h +++ b/src/include/86box/config.h @@ -158,6 +158,9 @@ extern void config_set_mac(char *head, char *name, int val); extern void config_set_string(char *head, char *name, char *val); extern void config_set_wstring(char *head, char *name, wchar_t *val); +extern void * config_find_section(char *name); +extern void config_rename_section(void *priv, char *name); + #ifdef __cplusplus } #endif diff --git a/src/include/86box/scsi.h b/src/include/86box/scsi.h index 8ac215337..16d10bb98 100644 --- a/src/include/86box/scsi.h +++ b/src/include/86box/scsi.h @@ -22,7 +22,6 @@ #define EMU_SCSI_H extern int scsi_card_current[4]; -extern int scsi_card_current_legacy; extern int scsi_card_available(int card); #ifdef EMU_DEVICE_H diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index d4f540969..fd619d172 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -46,7 +46,6 @@ #endif -int scsi_card_current_legacy = 0; int scsi_card_current[SCSI_BUS_MAX] = { 0, 0 }; static uint8_t next_scsi_bus = 0; @@ -170,12 +169,6 @@ scsi_card_init(void) if (machines[machine].flags & MACHINE_SCSI) max--; - /* This is for grandfathering legacy single-controller configurations. */ - if (scsi_cards[scsi_card_current_legacy].device) { - device_add(scsi_cards[scsi_card_current_legacy].device); - max--; - } - /* Do not initialize any controllers if we have do not have any SCSI bus left. */ if (max > 0) { diff --git a/src/win/win_media_menu.c b/src/win/win_media_menu.c index ff6c34557..1d4e16327 100644 --- a/src/win/win_media_menu.c +++ b/src/win/win_media_menu.c @@ -295,7 +295,7 @@ is_valid_cdrom(int i) { if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && !MACHINE_HAS_IDE && memcmp(hdc_get_internal_name(hdc_current), "ide", 3)) return 0; - if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current_legacy == 0) && + if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) return 0; @@ -307,7 +307,7 @@ is_valid_zip(int i) { if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && !MACHINE_HAS_IDE && memcmp(hdc_get_internal_name(hdc_current), "ide", 3)) return 0; - if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current_legacy == 0) && + if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) return 0; @@ -319,7 +319,7 @@ is_valid_mo(int i) { if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && !MACHINE_HAS_IDE && memcmp(hdc_get_internal_name(hdc_current), "ide", 3)) return 0; - if ((mo_drives[i].bus_type == MO_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current_legacy == 0) && + if ((mo_drives[i].bus_type == MO_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) return 0; diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 31e33c587..90e2a00d4 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -103,7 +103,7 @@ static int temp_lpt_devices[3]; static int temp_serial[4], temp_lpt[3]; /* Other peripherals category */ -static int temp_fdc_card, temp_hdc, temp_scsi_card_legacy, temp_ide_ter, temp_ide_qua; +static int temp_fdc_card, temp_hdc, temp_ide_ter, temp_ide_qua; static int temp_scsi_card[SCSI_BUS_MAX]; static int temp_bugger; static int temp_postcard; @@ -370,7 +370,6 @@ win_settings_init(void) temp_serial[i] = serial_enabled[i]; /* Other peripherals category */ - temp_scsi_card_legacy = scsi_card_current_legacy; for (i = 0; i < SCSI_BUS_MAX; i++) temp_scsi_card[i] = scsi_card_current[i]; temp_fdc_card = fdc_type; @@ -488,7 +487,6 @@ win_settings_changed(void) i = i || (temp_serial[j] != serial_enabled[j]); /* Peripherals category */ - i = i || (scsi_card_current_legacy != temp_scsi_card_legacy); for (j = 0; j < SCSI_BUS_MAX; j++) i = i || (temp_scsi_card[j] != scsi_card_current[j]); i = i || (fdc_type != temp_fdc_card); @@ -577,7 +575,6 @@ win_settings_save(void) serial_enabled[i] = temp_serial[i]; /* Peripherals category */ - scsi_card_current_legacy = temp_scsi_card_legacy; for (i = 0; i < SCSI_BUS_MAX; i++) scsi_card_current[i] = temp_scsi_card[i]; hdc_current = temp_hdc; @@ -1629,14 +1626,6 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) scsi_dev = scsi_card_getdevice(c); if (device_is_valid(scsi_dev, machines[temp_machine].flags)) { - if (c == 0) - settings_add_string(hdlg, IDC_COMBO_SCSI, win_get_string(IDS_2103)); - else - settings_add_string(hdlg, IDC_COMBO_SCSI, (LPARAM) device_name); - - if ((c == 0) || (c == temp_scsi_card_legacy)) - settings_set_cur_sel(hdlg, IDC_COMBO_SCSI, d); - for (e = 0; e < SCSI_BUS_MAX; e++) { if (c == 0) settings_add_string(hdlg, IDC_COMBO_SCSI_1 + e, win_get_string(IDS_2103)); @@ -1655,16 +1644,6 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) c++; } - settings_show_window(hdlg, IDT_1717, temp_scsi_card_legacy != 0); - settings_show_window(hdlg, IDC_COMBO_SCSI, temp_scsi_card_legacy != 0); - settings_show_window(hdlg, IDC_CONFIGURE_SCSI, temp_scsi_card_legacy != 0); - if (temp_scsi_card_legacy != 0) { - settings_enable_window(hdlg, IDC_COMBO_SCSI, d); - settings_enable_window(hdlg, IDC_CONFIGURE_SCSI, scsi_card_has_config(temp_scsi_card_legacy)); - } else { - settings_enable_window(hdlg, IDC_COMBO_SCSI, 0); - settings_enable_window(hdlg, IDC_CONFIGURE_SCSI, 0); - } for (c = 0; c < SCSI_BUS_MAX; c++) { settings_enable_window(hdlg, IDC_COMBO_SCSI_1 + c, d); settings_enable_window(hdlg, IDC_CONFIGURE_SCSI_1 + c, scsi_card_has_config(temp_scsi_card[c])); @@ -1704,16 +1683,6 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) settings_enable_window(hdlg, IDC_CONFIGURE_HDC, hdc_has_config(temp_hdc)); break; - case IDC_CONFIGURE_SCSI: - temp_scsi_card_legacy = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI)]; - temp_deviceconfig |= deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card_legacy)); - break; - - case IDC_COMBO_SCSI: - temp_scsi_card_legacy = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI)]; - settings_enable_window(hdlg, IDC_CONFIGURE_SCSI, scsi_card_has_config(temp_scsi_card_legacy)); - break; - case IDC_CONFIGURE_SCSI_1 ... IDC_CONFIGURE_SCSI_4: c = LOWORD(wParam) - IDC_CONFIGURE_SCSI_1; temp_scsi_card[c] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI_1 + c)]; @@ -1749,7 +1718,6 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_SAVESETTINGS: temp_hdc = settings_list_to_hdc[settings_get_cur_sel(hdlg, IDC_COMBO_HDC)]; temp_fdc_card = settings_list_to_fdc[settings_get_cur_sel(hdlg, IDC_COMBO_FDC)]; - temp_scsi_card_legacy = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI)]; for (c = 0; c < SCSI_BUS_MAX; c++) temp_scsi_card[c] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI_1 + c)]; temp_ide_ter = settings_get_check(hdlg, IDC_CHECK_IDE_TER); diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index f67c0881c..7dc1d0785 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -503,8 +503,7 @@ ui_sb_update_panes(void) !ide_int && memcmp(hdc_name, "ide", 3)) continue; - if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && - !scsi_int && (scsi_card_current_legacy == 0) && + if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && !scsi_int && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; @@ -517,8 +516,7 @@ ui_sb_update_panes(void) !ide_int && memcmp(hdc_name, "ide", 3)) continue; - if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && - !scsi_int && (scsi_card_current_legacy == 0) && + if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && !scsi_int && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; @@ -531,8 +529,7 @@ ui_sb_update_panes(void) !ide_int && memcmp(hdc_name, "ide", 3)) continue; - if ((mo_drives[i].bus_type == MO_BUS_SCSI) && - !scsi_int && (scsi_card_current_legacy == 0) && + if ((mo_drives[i].bus_type == MO_BUS_SCSI) && !scsi_int && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; @@ -551,7 +548,7 @@ ui_sb_update_panes(void) sb_parts++; if (c_ide && (ide_int || !memcmp(hdc_name, "xtide", 5) || !memcmp(hdc_name, "ide", 3))) sb_parts++; - if (c_scsi && (scsi_int || (scsi_card_current_legacy != 0) || (scsi_card_current[0] != 0) || (scsi_card_current[1] != 0) || + if (c_scsi && (scsi_int || (scsi_card_current[0] != 0) || (scsi_card_current[1] != 0) || (scsi_card_current[2] != 0) || (scsi_card_current[3] != 0))) sb_parts++; if (do_net) @@ -582,8 +579,7 @@ ui_sb_update_panes(void) if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && !ide_int && memcmp(hdc_name, "ide", 3)) continue; - if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && - !scsi_int && (scsi_card_current_legacy == 0) && + if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && !scsi_int && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; @@ -600,8 +596,7 @@ ui_sb_update_panes(void) if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && !ide_int && memcmp(hdc_name, "ide", 3)) continue; - if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && - !scsi_int && (scsi_card_current_legacy == 0) && + if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && !scsi_int && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; @@ -618,8 +613,7 @@ ui_sb_update_panes(void) if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && !ide_int && memcmp(hdc_name, "ide", 3)) continue; - if ((mo_drives[i].bus_type == MO_BUS_SCSI) && - !scsi_int && (scsi_card_current_legacy == 0) && + if ((mo_drives[i].bus_type == MO_BUS_SCSI) && !scsi_int && (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; @@ -659,7 +653,7 @@ ui_sb_update_panes(void) sb_map[SB_HDD | HDD_BUS_IDE] = sb_parts; sb_parts++; } - if (c_scsi && (scsi_int || (scsi_card_current_legacy != 0) || (scsi_card_current[0] != 0) || (scsi_card_current[1] != 0) || + if (c_scsi && (scsi_int || (scsi_card_current[0] != 0) || (scsi_card_current[1] != 0) || (scsi_card_current[2] != 0) || (scsi_card_current[3] != 0))) { edge += icon_width; iStatusWidths[sb_parts] = edge;