From 729b6d5069ff4a8fbd8ad2846922090a4377cbf7 Mon Sep 17 00:00:00 2001 From: OBattler Date: Thu, 22 Jul 2021 20:13:44 +0200 Subject: [PATCH 1/4] Added support for up to four SCSI controllers, closes #343. --- src/86box.c | 1 + src/config.c | 234 ++++++++++++++++++++++++-------- src/disk/mo.c | 38 ++++-- src/disk/zip.c | 38 ++++-- src/include/86box/hdd.h | 2 +- src/include/86box/language.h | 3 +- src/include/86box/resource.h | 125 +++++++++-------- src/include/86box/scsi.h | 3 +- src/include/86box/scsi_device.h | 7 +- src/include/86box/scsi_x54x.h | 6 +- src/scsi/scsi.c | 53 +++++++- src/scsi/scsi_aha154x.c | 6 +- src/scsi/scsi_buslogic.c | 27 ++-- src/scsi/scsi_cdrom.c | 25 +++- src/scsi/scsi_device.c | 26 ++-- src/scsi/scsi_disk.c | 31 ++++- src/scsi/scsi_ncr5380.c | 28 ++-- src/scsi/scsi_ncr53c8xx.c | 26 ++-- src/scsi/scsi_pcscsi.c | 13 +- src/scsi/scsi_spock.c | 18 +-- src/scsi/scsi_x54x.c | 60 ++++---- src/win/86Box.rc | 57 +++++--- src/win/win_media_menu.c | 12 +- src/win/win_settings.c | 109 ++++++++++----- src/win/win_stbar.c | 30 ++-- 25 files changed, 665 insertions(+), 313 deletions(-) diff --git a/src/86box.c b/src/86box.c index de6bebfcd..0a5c59258 100644 --- a/src/86box.c +++ b/src/86box.c @@ -796,6 +796,7 @@ pc_reset_hard_init(void) sound_reset(); + scsi_reset(); scsi_device_init(); /* Initialize the actual machine and its basic modules. */ diff --git a/src/config.c b/src/config.c index 0d4490025..7d317d37e 100644 --- a/src/config.c +++ b/src/config.c @@ -1014,17 +1014,29 @@ static void load_storage_controllers(void) { char *cat = "Storage controllers"; - char *p; + char *p, temp[512]; + int c; int free_p = 0; /* TODO: Backwards compatibility, get rid of this when enough time has passed. */ backwards_compat2 = (find_section(cat) == NULL); + /* 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 = scsi_card_get_from_internal_name(p); + scsi_card_current_legacy = scsi_card_get_from_internal_name(p); else - scsi_card_current = 0; + scsi_card_current_legacy = 0; + + for (c = 0; c < SCSI_BUS_MAX; c++) { + sprintf(temp, "scsicard_%d", c + 1); + + p = config_get_string(cat, temp, NULL); + if (p != NULL) + scsi_card_current[c] = scsi_card_get_from_internal_name(p); + else + scsi_card_current[c] = 0; + } p = config_get_string(cat, "fdc", NULL); if (p != NULL) @@ -1168,14 +1180,30 @@ load_hard_disks(void) } /* SCSI */ - sprintf(temp, "hdd_%02i_scsi_id", c+1); if (hdd[c].bus == HDD_BUS_SCSI) { - hdd[c].scsi_id = config_get_int(cat, temp, c); + sprintf(temp, "hdd_%02i_scsi_location", c+1); + sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c+2); + p = config_get_string(cat, temp, tmp2); + sscanf(p, "%01u:%02u", &board, &dev); + if (board >= SCSI_BUS_MAX) { + /* Invalid bus - check legacy ID */ + sprintf(temp, "hdd_%02i_scsi_id", c+1); + hdd[c].scsi_id = config_get_int(cat, temp, c+2); - if (hdd[c].scsi_id > 15) - hdd[c].scsi_id = 15; - } else + if (hdd[c].scsi_id > 15) + hdd[c].scsi_id = 15; + } else { + board %= SCSI_BUS_MAX; + dev &= 15; + hdd[c].scsi_id = (board<<4)+dev; + } + } else { + sprintf(temp, "hdd_%02i_scsi_location", c+1); config_delete_var(cat, temp); + } + + sprintf(temp, "hdd_%02i_scsi_id", c+1); + config_delete_var(cat, temp); memset(hdd[c].fn, 0x00, sizeof(hdd[c].fn)); memset(hdd[c].prev_fn, 0x00, sizeof(hdd[c].prev_fn)); @@ -1402,8 +1430,8 @@ load_floppy_and_cdrom_drives(void) /* Default values, needed for proper operation of the Settings dialog. */ cdrom[c].ide_channel = cdrom[c].scsi_device_id = c + 2; - sprintf(temp, "cdrom_%02i_ide_channel", c+1); if (cdrom[c].bus_type == CDROM_BUS_ATAPI) { + sprintf(temp, "cdrom_%02i_ide_channel", c+1); sprintf(tmp2, "%01u:%01u", (c+2)>>1, (c+2)&1); p = config_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); @@ -1413,17 +1441,38 @@ load_floppy_and_cdrom_drives(void) if (cdrom[c].ide_channel > 7) cdrom[c].ide_channel = 7; - } else { - sprintf(temp, "cdrom_%02i_scsi_id", c+1); - if (cdrom[c].bus_type == CDROM_BUS_SCSI) { + } else if (cdrom[c].bus_type == CDROM_BUS_SCSI) { + sprintf(temp, "cdrom_%02i_scsi_location", c+1); + sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c+2); + p = config_get_string(cat, temp, tmp2); + sscanf(p, "%01u:%02u", &board, &dev); + if (board >= SCSI_BUS_MAX) { + /* Invalid bus - check legacy ID */ + sprintf(temp, "cdrom_%02i_scsi_id", c+1); cdrom[c].scsi_device_id = config_get_int(cat, temp, c+2); - + if (cdrom[c].scsi_device_id > 15) cdrom[c].scsi_device_id = 15; - } else - config_delete_var(cat, temp); + } else { + board %= SCSI_BUS_MAX; + dev &= 15; + cdrom[c].scsi_device_id = (board<<4)+dev; + } } + if (cdrom[c].bus_type != CDROM_BUS_ATAPI) { + sprintf(temp, "cdrom_%02i_ide_channel", c+1); + config_delete_var(cat, temp); + } + + if (cdrom[c].bus_type != CDROM_BUS_SCSI) { + sprintf(temp, "cdrom_%02i_scsi_location", c+1); + config_delete_var(cat, temp); + } + + sprintf(temp, "cdrom_%02i_scsi_id", c+1); + config_delete_var(cat, temp); + sprintf(temp, "cdrom_%02i_image_path", c+1); p = config_get_string(cat, temp, ""); @@ -1514,8 +1563,8 @@ load_other_removable_devices(void) cdrom[c].ide_channel = cdrom[c].scsi_device_id = c + 2; config_delete_var(cat, temp); - sprintf(temp, "cdrom_%02i_ide_channel", c+1); if (cdrom[c].bus_type == CDROM_BUS_ATAPI) { + sprintf(temp, "cdrom_%02i_ide_channel", c+1); sprintf(tmp2, "%01u:%01u", (c+2)>>1, (c+2)&1); p = config_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); @@ -1525,17 +1574,17 @@ load_other_removable_devices(void) if (cdrom[c].ide_channel > 7) cdrom[c].ide_channel = 7; - } else { - sprintf(temp, "cdrom_%02i_scsi_id", c+1); - if (cdrom[c].bus_type == CDROM_BUS_SCSI) { - cdrom[c].scsi_device_id = config_get_int(cat, temp, c+2); - if (cdrom[c].scsi_device_id > 15) - cdrom[c].scsi_device_id = 15; - } else - config_delete_var(cat, temp); + config_delete_var(cat, temp); + } else if (cdrom[c].bus_type == CDROM_BUS_SCSI) { + sprintf(temp, "cdrom_%02i_scsi_id", c+1); + cdrom[c].scsi_device_id = config_get_int(cat, temp, c+2); + + if (cdrom[c].scsi_device_id > 15) + cdrom[c].scsi_device_id = 15; + + config_delete_var(cat, temp); } - config_delete_var(cat, temp); sprintf(temp, "cdrom_%02i_image_path", c+1); p = config_get_string(cat, temp, ""); @@ -1583,8 +1632,8 @@ load_other_removable_devices(void) /* Default values, needed for proper operation of the Settings dialog. */ zip_drives[c].ide_channel = zip_drives[c].scsi_device_id = c + 2; - sprintf(temp, "zip_%02i_ide_channel", c+1); if (zip_drives[c].bus_type == ZIP_BUS_ATAPI) { + sprintf(temp, "zip_%02i_ide_channel", c+1); sprintf(tmp2, "%01u:%01u", (c+2)>>1, (c+2)&1); p = config_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); @@ -1594,17 +1643,38 @@ load_other_removable_devices(void) if (zip_drives[c].ide_channel > 7) zip_drives[c].ide_channel = 7; - } else { - sprintf(temp, "zip_%02i_scsi_id", c+1); - if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { + } else if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { + sprintf(temp, "zip_%02i_scsi_location", c+1); + sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c+2); + p = config_get_string(cat, temp, tmp2); + sscanf(p, "%01u:%02u", &board, &dev); + if (board >= SCSI_BUS_MAX) { + /* Invalid bus - check legacy ID */ + sprintf(temp, "zip_%02i_scsi_id", c+1); zip_drives[c].scsi_device_id = config_get_int(cat, temp, c+2); - + if (zip_drives[c].scsi_device_id > 15) zip_drives[c].scsi_device_id = 15; - } else - config_delete_var(cat, temp); + } else { + board %= SCSI_BUS_MAX; + dev &= 15; + zip_drives[c].scsi_device_id = (board<<4)+dev; + } } + if (zip_drives[c].bus_type != ZIP_BUS_ATAPI) { + sprintf(temp, "zip_%02i_ide_channel", c+1); + config_delete_var(cat, temp); + } + + if (zip_drives[c].bus_type != ZIP_BUS_SCSI) { + sprintf(temp, "zip_%02i_scsi_location", c+1); + config_delete_var(cat, temp); + } + + sprintf(temp, "zip_%02i_scsi_id", c+1); + config_delete_var(cat, temp); + sprintf(temp, "zip_%02i_image_path", c+1); p = config_get_string(cat, temp, ""); @@ -1662,8 +1732,8 @@ load_other_removable_devices(void) /* Default values, needed for proper operation of the Settings dialog. */ mo_drives[c].ide_channel = mo_drives[c].scsi_device_id = c + 2; - sprintf(temp, "mo_%02i_ide_channel", c+1); if (mo_drives[c].bus_type == MO_BUS_ATAPI) { + sprintf(temp, "mo_%02i_ide_channel", c+1); sprintf(tmp2, "%01u:%01u", (c+2)>>1, (c+2)&1); p = config_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); @@ -1673,17 +1743,38 @@ load_other_removable_devices(void) if (mo_drives[c].ide_channel > 7) mo_drives[c].ide_channel = 7; - } else { - sprintf(temp, "mo_%02i_scsi_id", c+1); - if (mo_drives[c].bus_type == MO_BUS_SCSI) { + } else if (mo_drives[c].bus_type == MO_BUS_SCSI) { + sprintf(temp, "mo_%02i_scsi_location", c+1); + sprintf(tmp2, "%01u:%02u", SCSI_BUS_MAX, c+2); + p = config_get_string(cat, temp, tmp2); + sscanf(p, "%01u:%02u", &board, &dev); + if (board >= SCSI_BUS_MAX) { + /* Invalid bus - check legacy ID */ + sprintf(temp, "mo_%02i_scsi_id", c+1); mo_drives[c].scsi_device_id = config_get_int(cat, temp, c+2); - + if (mo_drives[c].scsi_device_id > 15) mo_drives[c].scsi_device_id = 15; - } else - config_delete_var(cat, temp); + } else { + board %= SCSI_BUS_MAX; + dev &= 15; + mo_drives[c].scsi_device_id = (board<<4)+dev; + } } + if (mo_drives[c].bus_type != MO_BUS_ATAPI) { + sprintf(temp, "mo_%02i_ide_channel", c+1); + config_delete_var(cat, temp); + } + + if (mo_drives[c].bus_type != MO_BUS_SCSI) { + sprintf(temp, "mo_%02i_scsi_location", c+1); + config_delete_var(cat, temp); + } + + sprintf(temp, "mo_%02i_scsi_id", c+1); + config_delete_var(cat, temp); + sprintf(temp, "mo_%02i_image_path", c+1); p = config_get_string(cat, temp, ""); @@ -1725,9 +1816,9 @@ load_other_peripherals(void) if (backwards_compat2) { p = config_get_string(cat, "scsicard", NULL); if (p != NULL) - scsi_card_current = scsi_card_get_from_internal_name(p); + scsi_card_current_legacy = scsi_card_get_from_internal_name(p); else - scsi_card_current = 0; + scsi_card_current_legacy = 0; config_delete_var(cat, "scsicard"); p = config_get_string(cat, "fdc", NULL); @@ -2327,12 +2418,24 @@ static void save_storage_controllers(void) { char *cat = "Storage controllers"; + char temp[512]; + int c; - if (scsi_card_current == 0) + 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)); + scsi_card_get_internal_name(scsi_card_current_legacy)); + + for (c = 0; c < SCSI_BUS_MAX; c++) { + sprintf(temp, "scsicard_%d", c + 1); + + if (scsi_card_current[c] == 0) + config_delete_var(cat, temp); + else + config_set_string(cat, temp, + scsi_card_get_internal_name(scsi_card_current[c])); + } if (fdc_type == FDC_INTERNAL) config_delete_var(cat, "fdc"); @@ -2442,10 +2545,16 @@ save_hard_disks(void) } sprintf(temp, "hdd_%02i_scsi_id", c+1); - if (hdd_is_valid(c) && (hdd[c].bus == HDD_BUS_SCSI)) - config_set_int(cat, temp, hdd[c].scsi_id); - else + config_delete_var(cat, temp); + + sprintf(temp, "hdd_%02i_scsi_location", c+1); + if (hdd[c].bus != HDD_BUS_SCSI) config_delete_var(cat, temp); + else { + sprintf(tmp2, "%01u:%02u", hdd[c].scsi_id>>4, + hdd[c].scsi_id & 15); + config_set_string(cat, temp, tmp2); + } sprintf(temp, "hdd_%02i_fn", c+1); if (hdd_is_valid(c) && (strlen(hdd[c].fn) != 0)) @@ -2542,10 +2651,15 @@ save_floppy_and_cdrom_drives(void) } sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - if (cdrom[c].bus_type != CDROM_BUS_SCSI) { + config_delete_var(cat, temp); + + sprintf(temp, "cdrom_%02i_scsi_location", c+1); + if (cdrom[c].bus_type != CDROM_BUS_SCSI) config_delete_var(cat, temp); - } else { - config_set_int(cat, temp, cdrom[c].scsi_device_id); + else { + sprintf(tmp2, "%01u:%02u", cdrom[c].scsi_device_id>>4, + cdrom[c].scsi_device_id & 15); + config_set_string(cat, temp, tmp2); } sprintf(temp, "cdrom_%02i_image_path", c + 1); @@ -2589,10 +2703,15 @@ save_other_removable_devices(void) } sprintf(temp, "zip_%02i_scsi_id", c + 1); - if (zip_drives[c].bus_type != ZIP_BUS_SCSI) { + config_delete_var(cat, temp); + + sprintf(temp, "zip_%02i_scsi_location", c+1); + if (zip_drives[c].bus_type != ZIP_BUS_SCSI) config_delete_var(cat, temp); - } else { - config_set_int(cat, temp, zip_drives[c].scsi_device_id); + else { + sprintf(tmp2, "%01u:%02u", zip_drives[c].scsi_device_id>>4, + zip_drives[c].scsi_device_id & 15); + config_set_string(cat, temp, tmp2); } sprintf(temp, "zip_%02i_image_path", c + 1); @@ -2624,10 +2743,15 @@ save_other_removable_devices(void) } sprintf(temp, "mo_%02i_scsi_id", c + 1); - if (mo_drives[c].bus_type != MO_BUS_SCSI) { + config_delete_var(cat, temp); + + sprintf(temp, "mo_%02i_scsi_location", c+1); + if (mo_drives[c].bus_type != MO_BUS_SCSI) config_delete_var(cat, temp); - } else { - config_set_int(cat, temp, mo_drives[c].scsi_device_id); + else { + sprintf(tmp2, "%01u:%02u", mo_drives[c].scsi_device_id>>4, + mo_drives[c].scsi_device_id & 15); + config_set_string(cat, temp, tmp2); } sprintf(temp, "mo_%02i_image_path", c + 1); diff --git a/src/disk/mo.c b/src/disk/mo.c index e5512b64d..fb02af39d 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -831,12 +831,13 @@ mo_sense_clear(mo_t *dev, int command) static void mo_set_phase(mo_t *dev, uint8_t phase) { - uint8_t scsi_id = dev->drv->scsi_device_id; + uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; if (dev->drv->bus_type != MO_BUS_SCSI) return; - scsi_devices[scsi_id].phase = phase; + scsi_devices[scsi_bus][scsi_id].phase = phase; } @@ -1343,9 +1344,11 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) int32_t blen = 0; int32_t *BufLen; uint32_t previous_pos = 0; + uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; if (dev->drv->bus_type == MO_BUS_SCSI) { - BufLen = &scsi_devices[dev->drv->scsi_device_id].buffer_length; + BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; dev->status &= ~ERR_STAT; } else { BufLen = &blen; @@ -2106,6 +2109,8 @@ mo_drive_reset(int c) mo_t *dev; scsi_device_t *sd; ide_t *id; + uint8_t scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = mo_drives[c].scsi_device_id & 0x0f; if (!mo_drives[c].priv) { mo_drives[c].priv = (mo_t *) malloc(sizeof(mo_t)); @@ -2119,7 +2124,7 @@ mo_drive_reset(int c) if (mo_drives[c].bus_type == MO_BUS_SCSI) { /* SCSI MO, attach to the SCSI bus. */ - sd = &scsi_devices[mo_drives[c].scsi_device_id]; + sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = mo_command; @@ -2158,14 +2163,24 @@ mo_hard_reset(void) { mo_t *dev; int c; + uint8_t scsi_id, scsi_bus; for (c = 0; c < MO_NUM; c++) { if ((mo_drives[c].bus_type == MO_BUS_ATAPI) || (mo_drives[c].bus_type == MO_BUS_SCSI)) { mo_log("MO hard_reset drive=%d\n", c); - /* Make sure to ignore any SCSI MO drive that has an out of range ID. */ - if ((mo_drives[c].bus_type == MO_BUS_SCSI) && (mo_drives[c].scsi_device_id >= SCSI_ID_MAX)) - continue; + if (mo_drives[c].bus_type == MO_BUS_SCSI) { + scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + scsi_id = mo_drives[c].scsi_device_id & 0x0f; + + /* Make sure to ignore any SCSI MO drive that has an out of range SCSI Bus. */ + if (scsi_bus >= SCSI_BUS_MAX) + continue; + + /* Make sure to ignore any SCSI MO drive that has an out of range ID. */ + if (scsi_id >= SCSI_ID_MAX) + continue; + } /* Make sure to ignore any ATAPI MO drive that has an out of range IDE channel. */ if ((mo_drives[c].bus_type == MO_BUS_ATAPI) && (mo_drives[c].ide_channel > 7)) @@ -2199,10 +2214,15 @@ mo_close(void) { mo_t *dev; int c; + uint8_t scsi_id, scsi_bus; for (c = 0; c < MO_NUM; c++) { - if (mo_drives[c].bus_type == MO_BUS_SCSI) - memset(&scsi_devices[mo_drives[c].scsi_device_id], 0x00, sizeof(scsi_device_t)); + if (mo_drives[c].bus_type == MO_BUS_SCSI) { + scsi_bus = (mo_drives[c].scsi_device_id >> 4) & 0x0f; + scsi_id = mo_drives[c].scsi_device_id & 0x0f; + + memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); + } dev = (mo_t *) mo_drives[c].priv; diff --git a/src/disk/zip.c b/src/disk/zip.c index b98b11364..38cbf2eda 100644 --- a/src/disk/zip.c +++ b/src/disk/zip.c @@ -1000,12 +1000,13 @@ zip_sense_clear(zip_t *dev, int command) static void zip_set_phase(zip_t *dev, uint8_t phase) { - uint8_t scsi_id = dev->drv->scsi_device_id; + uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; if (dev->drv->bus_type != ZIP_BUS_SCSI) return; - scsi_devices[scsi_id].phase = phase; + scsi_devices[scsi_bus][scsi_id].phase = phase; } @@ -1416,9 +1417,11 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) unsigned preamble_len; int32_t blen = 0; int32_t *BufLen; + uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; if (dev->drv->bus_type == ZIP_BUS_SCSI) { - BufLen = &scsi_devices[dev->drv->scsi_device_id].buffer_length; + BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; dev->status &= ~ERR_STAT; } else { BufLen = &blen; @@ -2330,6 +2333,8 @@ zip_drive_reset(int c) zip_t *dev; scsi_device_t *sd; ide_t *id; + uint8_t scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = zip_drives[c].scsi_device_id & 0x0f; if (!zip_drives[c].priv) { zip_drives[c].priv = (zip_t *) malloc(sizeof(zip_t)); @@ -2343,7 +2348,7 @@ zip_drive_reset(int c) if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { /* SCSI ZIP, attach to the SCSI bus. */ - sd = &scsi_devices[zip_drives[c].scsi_device_id]; + sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = zip_command; @@ -2382,14 +2387,24 @@ zip_hard_reset(void) { zip_t *dev; int c; + uint8_t scsi_id, scsi_bus; for (c = 0; c < ZIP_NUM; c++) { if ((zip_drives[c].bus_type == ZIP_BUS_ATAPI) || (zip_drives[c].bus_type == ZIP_BUS_SCSI)) { zip_log("ZIP hard_reset drive=%d\n", c); - /* Make sure to ignore any SCSI ZIP drive that has an out of range ID. */ - if ((zip_drives[c].bus_type == ZIP_BUS_SCSI) && (zip_drives[c].scsi_device_id >= SCSI_ID_MAX)) - continue; + if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { + scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + scsi_id = zip_drives[c].scsi_device_id & 0x0f; + + /* Make sure to ignore any SCSI ZIP drive that has an out of range SCSI bus. */ + if (scsi_bus >= SCSI_BUS_MAX) + continue; + + /* Make sure to ignore any SCSI ZIP drive that has an out of range ID. */ + if (scsi_id >= SCSI_ID_MAX) + continue; + } /* Make sure to ignore any ATAPI ZIP drive that has an out of range IDE channel. */ if ((zip_drives[c].bus_type == ZIP_BUS_ATAPI) && (zip_drives[c].ide_channel > 7)) @@ -2423,10 +2438,15 @@ zip_close(void) { zip_t *dev; int c; + uint8_t scsi_bus, scsi_id; for (c = 0; c < ZIP_NUM; c++) { - if (zip_drives[c].bus_type == ZIP_BUS_SCSI) - memset(&scsi_devices[zip_drives[c].scsi_device_id], 0x00, sizeof(scsi_device_t)); + if (zip_drives[c].bus_type == ZIP_BUS_SCSI) { + scsi_bus = (zip_drives[c].scsi_device_id >> 4) & 0x0f; + scsi_id = zip_drives[c].scsi_device_id & 0x0f; + + memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); + } dev = (zip_t *) zip_drives[c].priv; diff --git a/src/include/86box/hdd.h b/src/include/86box/hdd.h index 18e7a3ac7..96afcdde0 100644 --- a/src/include/86box/hdd.h +++ b/src/include/86box/hdd.h @@ -19,7 +19,7 @@ # define EMU_HDD_H -#define HDD_NUM 40 /* total of 40 images supported */ +#define HDD_NUM 88 /* total of 88 images supported */ /* Hard Disk bus types. */ diff --git a/src/include/86box/language.h b/src/include/86box/language.h index af52954c6..b791f27c8 100644 --- a/src/include/86box/language.h +++ b/src/include/86box/language.h @@ -161,6 +161,7 @@ #define IDS_4132 4132 // "This could mean that the parent..." #define IDS_4133 4133 // "Parent and child disk timestamps..." #define IDS_4134 4134 // "Could not fix VHD timestamp." +#define IDS_4135 4135 // "%01i:%02i" #define IDS_4352 4352 // "MFM/RLL" #define IDS_4353 4353 // "XT IDE" @@ -230,7 +231,7 @@ #define STR_NUM_2048 100 #define STR_NUM_3072 11 -#define STR_NUM_4096 39 +#define STR_NUM_4096 40 #define STR_NUM_4352 6 #define STR_NUM_4608 6 #define STR_NUM_5120 1 diff --git a/src/include/86box/resource.h b/src/include/86box/resource.h index 64ea4690a..86215fdfc 100644 --- a/src/include/86box/resource.h +++ b/src/include/86box/resource.h @@ -188,70 +188,79 @@ #define IDC_BUTTON_IDE_TER 1086 #define IDC_CHECK_IDE_QUA 1087 #define IDC_BUTTON_IDE_QUA 1088 +#define IDC_GROUP_SCSI 1089 +#define IDC_COMBO_SCSI_1 1090 +#define IDC_COMBO_SCSI_2 1091 +#define IDC_COMBO_SCSI_3 1092 +#define IDC_COMBO_SCSI_4 1093 +#define IDC_CONFIGURE_SCSI_1 1094 +#define IDC_CONFIGURE_SCSI_2 1095 +#define IDC_CONFIGURE_SCSI_3 1096 +#define IDC_CONFIGURE_SCSI_4 1097 -#define IDC_HARD_DISKS 1090 /* hard disks config */ -#define IDC_LIST_HARD_DISKS 1091 -#define IDC_BUTTON_HDD_ADD_NEW 1092 -#define IDC_BUTTON_HDD_ADD 1093 -#define IDC_BUTTON_HDD_REMOVE 1094 -#define IDC_COMBO_HD_BUS 1095 -#define IDC_COMBO_HD_CHANNEL 1096 -#define IDC_COMBO_HD_ID 1097 -#define IDC_COMBO_HD_LUN 1098 -#define IDC_COMBO_HD_CHANNEL_IDE 1099 +#define IDC_HARD_DISKS 1100 /* hard disks config */ +#define IDC_LIST_HARD_DISKS 1101 +#define IDC_BUTTON_HDD_ADD_NEW 1102 +#define IDC_BUTTON_HDD_ADD 1103 +#define IDC_BUTTON_HDD_REMOVE 1104 +#define IDC_COMBO_HD_BUS 1105 +#define IDC_COMBO_HD_CHANNEL 1106 +#define IDC_COMBO_HD_ID 1107 +#define IDC_COMBO_HD_LUN 1108 +#define IDC_COMBO_HD_CHANNEL_IDE 1109 -#define IDC_EDIT_HD_FILE_NAME 1100 /* add hard disk dialog */ -#define IDC_EDIT_HD_SPT 1101 -#define IDC_EDIT_HD_HPC 1102 -#define IDC_EDIT_HD_CYL 1103 -#define IDC_EDIT_HD_SIZE 1104 -#define IDC_COMBO_HD_TYPE 1105 -#define IDC_PBAR_IMG_CREATE 1106 -#define IDC_COMBO_HD_IMG_FORMAT 1107 -#define IDC_COMBO_HD_BLOCK_SIZE 1108 +#define IDC_EDIT_HD_FILE_NAME 1110 /* add hard disk dialog */ +#define IDC_EDIT_HD_SPT 1111 +#define IDC_EDIT_HD_HPC 1112 +#define IDC_EDIT_HD_CYL 1113 +#define IDC_EDIT_HD_SIZE 1114 +#define IDC_COMBO_HD_TYPE 1115 +#define IDC_PBAR_IMG_CREATE 1116 +#define IDC_COMBO_HD_IMG_FORMAT 1117 +#define IDC_COMBO_HD_BLOCK_SIZE 1118 -#define IDC_REMOV_DEVICES 1110 /* floppy and cd-rom drives config */ -#define IDC_LIST_FLOPPY_DRIVES 1111 -#define IDC_COMBO_FD_TYPE 1112 -#define IDC_CHECKTURBO 1113 -#define IDC_CHECKBPB 1114 -#define IDC_LIST_CDROM_DRIVES 1115 -#define IDC_COMBO_CD_BUS 1116 -#define IDC_COMBO_CD_ID 1117 -#define IDC_COMBO_CD_LUN 1118 -#define IDC_COMBO_CD_CHANNEL_IDE 1119 +#define IDC_REMOV_DEVICES 1120 /* floppy and cd-rom drives config */ +#define IDC_LIST_FLOPPY_DRIVES 1121 +#define IDC_COMBO_FD_TYPE 1122 +#define IDC_CHECKTURBO 1123 +#define IDC_CHECKBPB 1124 +#define IDC_LIST_CDROM_DRIVES 1125 +#define IDC_COMBO_CD_BUS 1126 +#define IDC_COMBO_CD_ID 1127 +#define IDC_COMBO_CD_LUN 1128 +#define IDC_COMBO_CD_CHANNEL_IDE 1129 -#define IDC_LIST_ZIP_DRIVES 1120 /* other removable devices config */ -#define IDC_COMBO_ZIP_BUS 1121 -#define IDC_COMBO_ZIP_ID 1122 -#define IDC_COMBO_ZIP_LUN 1123 -#define IDC_COMBO_ZIP_CHANNEL_IDE 1124 -#define IDC_CHECK250 1125 -#define IDC_COMBO_CD_SPEED 1126 -#define IDC_LIST_MO_DRIVES 1127 -#define IDC_COMBO_MO_BUS 1128 -#define IDC_COMBO_MO_ID 1129 -#define IDC_COMBO_MO_LUN 1130 -#define IDC_COMBO_MO_CHANNEL_IDE 1131 -#define IDC_COMBO_MO_TYPE 1132 +#define IDC_LIST_ZIP_DRIVES 1130 /* other removable devices config */ +#define IDC_COMBO_ZIP_BUS 1131 +#define IDC_COMBO_ZIP_ID 1132 +#define IDC_COMBO_ZIP_LUN 1133 +#define IDC_COMBO_ZIP_CHANNEL_IDE 1134 +#define IDC_CHECK250 1135 +#define IDC_COMBO_CD_SPEED 1136 +#define IDC_LIST_MO_DRIVES 1137 +#define IDC_COMBO_MO_BUS 1138 +#define IDC_COMBO_MO_ID 1139 +#define IDC_COMBO_MO_LUN 1140 +#define IDC_COMBO_MO_CHANNEL_IDE 1141 +#define IDC_COMBO_MO_TYPE 1142 -#define IDC_CHECK_BUGGER 1140 /* other periph config */ -#define IDC_CHECK_POSTCARD 1141 -#define IDC_COMBO_ISARTC 1142 -#define IDC_CONFIGURE_ISARTC 1143 -#define IDC_COMBO_FDC 1144 -#define IDC_CONFIGURE_FDC 1145 -#define IDC_GROUP_ISAMEM 1146 -#define IDC_COMBO_ISAMEM_1 1147 -#define IDC_COMBO_ISAMEM_2 1148 -#define IDC_COMBO_ISAMEM_3 1149 -#define IDC_COMBO_ISAMEM_4 1150 -#define IDC_CONFIGURE_ISAMEM_1 1151 -#define IDC_CONFIGURE_ISAMEM_2 1152 -#define IDC_CONFIGURE_ISAMEM_3 1153 -#define IDC_CONFIGURE_ISAMEM_4 1154 +#define IDC_CHECK_BUGGER 1150 /* other periph config */ +#define IDC_CHECK_POSTCARD 1151 +#define IDC_COMBO_ISARTC 1152 +#define IDC_CONFIGURE_ISARTC 1153 +#define IDC_COMBO_FDC 1154 +#define IDC_CONFIGURE_FDC 1155 +#define IDC_GROUP_ISAMEM 1156 +#define IDC_COMBO_ISAMEM_1 1157 +#define IDC_COMBO_ISAMEM_2 1158 +#define IDC_COMBO_ISAMEM_3 1159 +#define IDC_COMBO_ISAMEM_4 1160 +#define IDC_CONFIGURE_ISAMEM_1 1161 +#define IDC_CONFIGURE_ISAMEM_2 1162 +#define IDC_CONFIGURE_ISAMEM_3 1163 +#define IDC_CONFIGURE_ISAMEM_4 1164 -#define IDC_SLIDER_GAIN 1160 /* sound gain dialog */ +#define IDC_SLIDER_GAIN 1170 /* sound gain dialog */ #define IDC_EDIT_FILE_NAME 1200 /* new floppy image dialog */ #define IDC_COMBO_DISK_SIZE 1201 diff --git a/src/include/86box/scsi.h b/src/include/86box/scsi.h index 376a0cf30..8ac215337 100644 --- a/src/include/86box/scsi.h +++ b/src/include/86box/scsi.h @@ -21,7 +21,8 @@ #ifndef EMU_SCSI_H #define EMU_SCSI_H -extern int scsi_card_current; +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/include/86box/scsi_device.h b/src/include/86box/scsi_device.h index 0dddfdb97..6e9223648 100644 --- a/src/include/86box/scsi_device.h +++ b/src/include/86box/scsi_device.h @@ -21,6 +21,8 @@ /* Configuration. */ +#define SCSI_BUS_MAX 4 /* currently we support up to 4 controllers */ + #define SCSI_ID_MAX 16 /* 16 on wide buses */ #define SCSI_LUN_MAX 8 /* always 8 */ @@ -359,7 +361,7 @@ typedef struct { #define SCSI_REMOVABLE_DISK 0x8000 #define SCSI_REMOVABLE_CDROM 0x8005 -extern scsi_device_t scsi_devices[SCSI_ID_MAX]; +extern scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; extern int cdrom_add_error_and_subchannel(uint8_t *b, int real_sector_type); @@ -384,4 +386,7 @@ extern void scsi_device_identify(scsi_device_t *dev, uint8_t lun); extern void scsi_device_close_all(void); extern void scsi_device_init(void); +extern void scsi_reset(void); +extern uint8_t scsi_get_bus(void); + #endif /*SCSI_DEVICE_H*/ diff --git a/src/include/86box/scsi_x54x.h b/src/include/86box/scsi_x54x.h index 14017ce1b..af91ee7d2 100644 --- a/src/include/86box/scsi_x54x.h +++ b/src/include/86box/scsi_x54x.h @@ -382,7 +382,7 @@ typedef struct { uint8_t callback_phase :4, callback_sub_phase :4, - scsi_cmd_phase, pad, + scsi_cmd_phase, bus, sync, parity, shram_mode, Geometry, Control, @@ -429,7 +429,7 @@ typedef struct { PendingInterrupt, Lock, target_data_len, pad0; - uint32_t Base, fdc_address, rom_addr, /* address of BIOS ROM */ + uint32_t Base, fdc_address, rom_addr, /* address of BIOS ROM */ CmdParamLeft, Outgoing, transfer_size; @@ -441,7 +441,7 @@ typedef struct { BIOSMailboxInit, BIOSMailboxCount, BIOSMailboxOutAddr, BIOSMailboxOutPosCur, BIOSMailboxReq, - Residue, bus; /* Basically a copy of device flags */ + Residue, card_bus; /* Basically a copy of device flags */ /* 8 bytes */ uint64_t temp_period; diff --git a/src/scsi/scsi.c b/src/scsi/scsi.c index d61596898..d4f540969 100644 --- a/src/scsi/scsi.c +++ b/src/scsi/scsi.c @@ -26,6 +26,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> +#include <86box/machine.h> #include <86box/hdc.h> #include <86box/hdd.h> #include <86box/plat.h> @@ -45,8 +46,10 @@ #endif -int scsi_card_current = 0; -int scsi_card_last = 0; +int scsi_card_current_legacy = 0; +int scsi_card_current[SCSI_BUS_MAX] = { 0, 0 }; + +static uint8_t next_scsi_bus = 0; typedef const struct { @@ -88,6 +91,27 @@ static SCSI_CARD scsi_cards[] = { }; +void +scsi_reset(void) +{ + next_scsi_bus = 0; +} + + +uint8_t +scsi_get_bus(void) +{ + uint8_t ret = next_scsi_bus; + + if (next_scsi_bus >= SCSI_BUS_MAX) + return 0xff; + + next_scsi_bus++; + + return ret; +} + + int scsi_card_available(int card) { @@ -139,10 +163,27 @@ scsi_card_get_from_internal_name(char *s) void scsi_card_init(void) { - if (!scsi_cards[scsi_card_current].device) - return; + int i = 0, max = SCSI_BUS_MAX; - device_add(scsi_cards[scsi_card_current].device); + /* On-board SCSI controllers get the first bus, so if one is present, + increase our instance number here. */ + if (machines[machine].flags & MACHINE_SCSI) + max--; - scsi_card_last = scsi_card_current; + /* 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) { + for (i = 0; i < max; i++) { + if (!scsi_cards[scsi_card_current[i]].device) + continue; + + device_add_inst(scsi_cards[scsi_card_current[i]].device, i + 1); + } + } } diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 93767eba3..13744c3cd 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -40,6 +40,7 @@ #include <86box/fdc.h> #include <86box/isapnp.h> #include <86box/scsi.h> +#include <86box/scsi_device.h> #include <86box/scsi_aha154x.h> #include <86box/scsi_x54x.h> @@ -964,6 +965,7 @@ aha_init(const device_t *info) /* Call common initializer. */ dev = x54x_init(info); + dev->bus = scsi_get_bus(); /* * Set up the (initial) I/O address, IRQ and DMA info. @@ -976,7 +978,7 @@ aha_init(const device_t *info) dev->Irq = device_get_config_int("irq"); dev->DmaChannel = device_get_config_int("dma"); dev->rom_addr = device_get_config_hex20("bios_addr"); - if (!(dev->bus & DEVICE_MCA)) + if (!(dev->card_bus & DEVICE_MCA)) dev->fdc_address = device_get_config_hex16("fdc_addr"); else dev->fdc_address = 0; @@ -1121,7 +1123,7 @@ aha_init(const device_t *info) /* Initialize the device. */ x54x_device_reset(dev); - if (!(dev->bus & DEVICE_MCA) && !(dev->flags & X54X_ISAPNP)) { + if (!(dev->card_bus & DEVICE_MCA) && !(dev->flags & X54X_ISAPNP)) { /* Register our address space. */ x54x_io_set(dev, dev->Base, 4); diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index 77ace5474..b05a57bb7 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -559,13 +559,13 @@ buslogic_param_len(void *p) static void -BuslogicSCSIBIOSDMATransfer(ESCMD *ESCSICmd, uint8_t TargetID, int dir, int transfer_size) +BuslogicSCSIBIOSDMATransfer(x54x_t *dev, ESCMD *ESCSICmd, uint8_t TargetID, int dir, int transfer_size) { uint32_t DataPointer = ESCSICmd->DataPointer; int DataLength = ESCSICmd->DataLength; uint32_t Address; uint32_t TransferLength; - scsi_device_t *dev = &scsi_devices[TargetID]; + scsi_device_t *sd = &scsi_devices[dev->bus][TargetID]; if (ESCSICmd->DataDirection == 0x03) { /* Non-data command. */ @@ -577,16 +577,16 @@ BuslogicSCSIBIOSDMATransfer(ESCMD *ESCSICmd, uint8_t TargetID, int dir, int tran /* If the control byte is 0x00, it means that the transfer direction is set up by the SCSI command without checking its length, so do this procedure for both read/write commands. */ - if ((DataLength > 0) && (dev->buffer_length > 0)) { + if ((DataLength > 0) && (sd->buffer_length > 0)) { Address = DataPointer; - TransferLength = MIN(DataLength, dev->buffer_length); + TransferLength = MIN(DataLength, sd->buffer_length); if (dir && ((ESCSICmd->DataDirection == CCB_DATA_XFER_OUT) || (ESCSICmd->DataDirection == 0x00))) { buslogic_log("BusLogic BIOS DMA: Reading %i bytes from %08X\n", TransferLength, Address); - dma_bm_read(Address, (uint8_t *)dev->sc->temp_buffer, TransferLength, transfer_size); + dma_bm_read(Address, (uint8_t *)sd->sc->temp_buffer, TransferLength, transfer_size); } else if (!dir && ((ESCSICmd->DataDirection == CCB_DATA_XFER_IN) || (ESCSICmd->DataDirection == 0x00))) { buslogic_log("BusLogic BIOS DMA: Writing %i bytes at %08X\n", TransferLength, Address); - dma_bm_write(Address, (uint8_t *)dev->sc->temp_buffer, TransferLength, transfer_size); + dma_bm_write(Address, (uint8_t *)sd->sc->temp_buffer, TransferLength, transfer_size); } } } @@ -603,7 +603,7 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u uint8_t target_id = 0; #endif int phase; - scsi_device_t *sd = &scsi_devices[ESCSICmd->TargetId]; + scsi_device_t *sd = &scsi_devices[dev->bus][ESCSICmd->TargetId]; DataInBuf[0] = DataInBuf[1] = 0; @@ -654,7 +654,7 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u phase = sd->phase; if (phase != SCSI_PHASE_STATUS) { - BuslogicSCSIBIOSDMATransfer(ESCSICmd, ESCSICmd->TargetId, (phase == SCSI_PHASE_DATA_OUT), dev->transfer_size); + BuslogicSCSIBIOSDMATransfer(dev, ESCSICmd, ESCSICmd->TargetId, (phase == SCSI_PHASE_DATA_OUT), dev->transfer_size); scsi_device_command_phase1(sd); } @@ -664,7 +664,7 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u if (sd->status == SCSI_STATUS_OK) { DataInBuf[2] = CCB_COMPLETE; DataInBuf[3] = SCSI_STATUS_OK; - } else if (scsi_devices[ESCSICmd->TargetId].status == SCSI_STATUS_CHECK_CONDITION) { + } else if (scsi_devices[dev->bus][ESCSICmd->TargetId].status == SCSI_STATUS_CHECK_CONDITION) { DataInBuf[2] = CCB_COMPLETE; DataInBuf[3] = SCSI_STATUS_CHECK_CONDITION; } @@ -704,14 +704,14 @@ buslogic_cmds(void *p) memset(dev->DataBuf, 0, 8); for (i = 8; i < 15; i++) { dev->DataBuf[i - 8] = 0; - if (scsi_device_present(&scsi_devices[i]) && (i != buslogic_get_host_id(dev))) + if (scsi_device_present(&scsi_devices[dev->bus][i]) && (i != buslogic_get_host_id(dev))) dev->DataBuf[i - 8] |= 1; } dev->DataReplyLeft = 8; break; case 0x24: for (i = 0; i < 15; i++) { - if (scsi_device_present(&scsi_devices[i]) && (i != buslogic_get_host_id(dev))) + if (scsi_device_present(&scsi_devices[dev->bus][i]) && (i != buslogic_get_host_id(dev))) TargetsPresentMask |= (1 << i); } dev->DataBuf[0] = TargetsPresentMask & 0xFF; @@ -1532,13 +1532,14 @@ buslogic_init(const device_t *info) /* Call common initializer. */ dev = x54x_init(info); + dev->bus = scsi_get_bus(); dev->ven_data = malloc(sizeof(buslogic_data_t)); memset(dev->ven_data, 0x00, sizeof(buslogic_data_t)); bl = (buslogic_data_t *) dev->ven_data; - dev->bus = info->flags; + dev->card_bus = info->flags; if (!(info->flags & DEVICE_MCA) && !(info->flags & DEVICE_PCI)) { dev->Base = device_get_config_hex16("base"); dev->Irq = device_get_config_int("irq"); @@ -1668,7 +1669,7 @@ buslogic_init(const device_t *info) break; } - if ((dev->Base != 0) && !(dev->bus & DEVICE_MCA) && !(dev->bus & DEVICE_PCI)) { + if ((dev->Base != 0) && !(dev->card_bus & DEVICE_MCA) && !(dev->card_bus & DEVICE_PCI)) { x54x_io_set(dev, dev->Base, 4); } diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index d2864c397..ce9b9852c 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -798,12 +798,13 @@ scsi_cdrom_sense_clear(scsi_cdrom_t *dev, int command) static void scsi_cdrom_set_phase(scsi_cdrom_t *dev, uint8_t phase) { - uint8_t scsi_id = dev->drv->scsi_device_id; + uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; if (dev->drv->bus_type != CDROM_BUS_SCSI) return; - scsi_devices[scsi_id].phase = phase; + scsi_devices[scsi_bus][scsi_id].phase = phase; } @@ -1417,9 +1418,11 @@ scsi_cdrom_command(scsi_common_t *sc, uint8_t *cdb) int32_t blen = 0, *BufLen; uint8_t *b; uint32_t profiles[2] = { MMC_PROFILE_CD_ROM, MMC_PROFILE_DVD_ROM }; + uint8_t scsi_bus = (dev->drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_device_id & 0x0f; if (dev->drv->bus_type == CDROM_BUS_SCSI) { - BufLen = &scsi_devices[dev->drv->scsi_device_id].buffer_length; + BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; dev->status &= ~ERR_STAT; } else { BufLen = &blen; @@ -2687,10 +2690,18 @@ scsi_cdrom_drive_reset(int c) scsi_cdrom_t *dev; scsi_device_t *sd; ide_t *id; + uint8_t scsi_bus = (drv->scsi_device_id >> 4) & 0x0f; + uint8_t scsi_id = drv->scsi_device_id & 0x0f; - /* Make sure to ignore any SCSI CD-ROM drive that has an out of range ID. */ - if ((drv->bus_type == CDROM_BUS_SCSI) && (drv->scsi_device_id >= SCSI_ID_MAX)) - return; + if (drv->bus_type == CDROM_BUS_SCSI) { + /* Make sure to ignore any SCSI CD-ROM drive that has an out of range SCSI bus. */ + if (scsi_bus >= SCSI_BUS_MAX) + return; + + /* Make sure to ignore any SCSI CD-ROM drive that has an out of range ID. */ + if (scsi_id >= SCSI_ID_MAX) + return; + } /* Make sure to ignore any ATAPI CD-ROM drive that has an out of range IDE channel. */ if ((drv->bus_type == CDROM_BUS_ATAPI) && (drv->ide_channel > 7)) @@ -2717,7 +2728,7 @@ scsi_cdrom_drive_reset(int c) if (drv->bus_type == CDROM_BUS_SCSI) { /* SCSI CD-ROM, attach to the SCSI bus. */ - sd = &scsi_devices[drv->scsi_device_id]; + sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = scsi_cdrom_command; diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index 371dfedf5..09e44a914 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -27,7 +27,7 @@ #include <86box/scsi_device.h> -scsi_device_t scsi_devices[SCSI_ID_MAX]; +scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; uint8_t scsi_null_device_sense[18] = { 0x70,0,SENSE_ILLEGAL_REQUEST,0,0,0,0,0,0,0,0,0,ASC_INV_LUN,0,0,0,0,0 }; @@ -176,13 +176,15 @@ scsi_device_identify(scsi_device_t *dev, uint8_t lun) void scsi_device_close_all(void) { - int i; + int i, j; scsi_device_t *dev; - for (i = 0; i < SCSI_ID_MAX; i++) { - dev = &(scsi_devices[i]); - if (dev->command_stop && dev->sc) - dev->command_stop(dev->sc); + for (i = 0; i < SCSI_BUS_MAX; i++) { + for (j = 0; j < SCSI_ID_MAX; j++) { + dev = &(scsi_devices[i][j]); + if (dev->command_stop && dev->sc) + dev->command_stop(dev->sc); + } } } @@ -190,13 +192,15 @@ scsi_device_close_all(void) void scsi_device_init(void) { - int i; + int i, j; scsi_device_t *dev; - for (i = 0; i < SCSI_ID_MAX; i++) { - dev = &(scsi_devices[i]); + for (i = 0; i < SCSI_BUS_MAX; i++) { + for (j = 0; j < SCSI_ID_MAX; j++) { + dev = &(scsi_devices[i][j]); - memset(dev, 0, sizeof(scsi_device_t)); - dev->type = SCSI_NONE; + memset(dev, 0, sizeof(scsi_device_t)); + dev->type = SCSI_NONE; + } } } diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index c8e44b14d..85cefaacb 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -347,12 +347,13 @@ scsi_disk_sense_clear(scsi_disk_t *dev, int command) static void scsi_disk_set_phase(scsi_disk_t *dev, uint8_t phase) { - uint8_t scsi_id = dev->drv->scsi_id; + uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_id & 0x0f; if (dev->drv->bus != HDD_BUS_SCSI) return; - scsi_devices[scsi_id].phase = phase; + scsi_devices[scsi_bus][scsi_id].phase = phase; } @@ -572,8 +573,10 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) char device_identify[9] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', 0 }; char device_identify_ex[15] = { '8', '6', 'B', '_', 'H', 'D', '0', '0', ' ', 'v', '1', '.', '0', '0', 0 }; int block_desc = 0; + uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_id & 0x0f; - BufLen = &scsi_devices[dev->drv->scsi_id].buffer_length; + BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; last_sector = hdd_image_get_last_sector(dev->id); @@ -1073,8 +1076,10 @@ static uint8_t scsi_disk_phase_data_out(scsi_common_t *sc) { scsi_disk_t *dev = (scsi_disk_t *) sc; + uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_id & 0x0f; int i; - int32_t *BufLen = &scsi_devices[dev->drv->scsi_id].buffer_length; + int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; uint32_t last_sector = hdd_image_get_last_sector(dev->id); uint32_t c, h, s, last_to_write = 0; uint16_t block_desc_len, pos; @@ -1215,13 +1220,21 @@ scsi_disk_hard_reset(void) int c; scsi_disk_t *dev; scsi_device_t *sd; + uint8_t scsi_bus, scsi_id; for (c = 0; c < HDD_NUM; c++) { if (hdd[c].bus == HDD_BUS_SCSI) { scsi_disk_log("SCSI disk hard_reset drive=%d\n", c); + scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; + scsi_id = hdd[c].scsi_id & 0x0f; + + /* Make sure to ignore any SCSI disk that has an out of range SCSI bus. */ + if (scsi_bus >= SCSI_BUS_MAX) + continue; + /* Make sure to ignore any SCSI disk that has an out of range ID. */ - if (hdd[c].scsi_id >= SCSI_ID_MAX) + if (scsi_id >= SCSI_ID_MAX) continue; /* Make sure to ignore any SCSI disk whose image file name is empty. */ @@ -1240,7 +1253,7 @@ scsi_disk_hard_reset(void) dev = (scsi_disk_t *) hdd[c].priv; /* SCSI disk, attach to the SCSI bus. */ - sd = &scsi_devices[hdd[c].scsi_id]; + sd = &scsi_devices[scsi_bus][scsi_id]; sd->sc = (scsi_common_t *) dev; sd->command = scsi_disk_command; @@ -1268,10 +1281,14 @@ scsi_disk_close(void) { scsi_disk_t *dev; int c; + uint8_t scsi_bus, scsi_id; for (c = 0; c < HDD_NUM; c++) { if (hdd[c].bus == HDD_BUS_SCSI) { - memset(&scsi_devices[hdd[c].scsi_id], 0x00, sizeof(scsi_device_t)); + scsi_bus = (hdd[c].scsi_id >> 4) & 0x0f; + scsi_id = hdd[c].scsi_id & 0x0f; + + memset(&scsi_devices[scsi_bus][scsi_id], 0x00, sizeof(scsi_device_t)); hdd_image_close(c); diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index 1078f2f4f..11d1f570d 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -124,7 +124,7 @@ typedef struct { int8_t bios_ver; uint8_t block_count, block_count_num; uint8_t status_ctrl; - uint8_t pad[2]; + uint8_t bus, pad; rom_t bios_rom; mem_mapping_t mapping; @@ -236,7 +236,7 @@ ncr_reset(ncr5380_t *ncr_dev, ncr_t *ncr) timer_stop(&ncr_dev->timer); for (int i = 0; i < 8; i++) - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[ncr_dev->bus][i]); ncr_irq(ncr_dev, ncr, 0); } @@ -318,7 +318,7 @@ ncr_bus_read(ncr5380_t *ncr_dev) if (ncr->wait_data) { ncr->wait_data--; if (!ncr->wait_data) { - dev = &scsi_devices[ncr->target_id]; + dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; SET_BUS_STATE(ncr, ncr->new_phase); phase = (ncr->cur_bus & SCSI_PHASE_MESSAGE_IN); @@ -360,7 +360,7 @@ ncr_bus_update(void *priv, int bus) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr->target_id]; + scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; double p; uint8_t sel_data; int msglen; @@ -383,7 +383,7 @@ ncr_bus_update(void *priv, int bus) ncr_log("Select - target ID = %i\n", ncr->target_id); /*Once the device has been found and selected, mark it as busy*/ - if ((ncr->target_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[ncr->target_id])) { + if ((ncr->target_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[ncr_dev->bus][ncr->target_id])) { ncr->cur_bus |= BUS_BSY; ncr->state = STATE_SELECT; } else { @@ -395,7 +395,7 @@ ncr_bus_update(void *priv, int bus) case STATE_SELECT: if (!(bus & BUS_SEL)) { if (!(bus & BUS_ATN)) { - if ((ncr->target_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[ncr->target_id])) { + if ((ncr->target_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[ncr_dev->bus][ncr->target_id])) { ncr_log("Device found at ID %i, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); ncr->state = STATE_COMMAND; ncr->cur_bus = BUS_BSY | BUS_REQ; @@ -434,7 +434,7 @@ ncr_bus_update(void *priv, int bus) /*Reset data position to default*/ ncr->data_pos = 0; - dev = &scsi_devices[ncr->target_id]; + dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; ncr_log("SCSI Command 0x%02X for ID %d, status code=%02x\n", ncr->command[0], ncr->target_id, dev->status); dev->buffer_length = -1; @@ -462,7 +462,7 @@ ncr_bus_update(void *priv, int bus) } break; case STATE_DATAIN: - dev = &scsi_devices[ncr->target_id]; + dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { if (ncr->data_pos >= dev->buffer_length) { ncr->cur_bus &= ~BUS_REQ; @@ -487,7 +487,7 @@ ncr_bus_update(void *priv, int bus) } break; case STATE_DATAOUT: - dev = &scsi_devices[ncr->target_id]; + dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { dev->sc->temp_buffer[ncr->data_pos++] = BUS_GETDATA(bus); @@ -514,7 +514,7 @@ ncr_bus_update(void *priv, int bus) case STATE_STATUS: if ((bus & BUS_ACK) && !(ncr->bus_in & BUS_ACK)) { /*All transfers done, wait until next transfer*/ - scsi_device_identify(&scsi_devices[ncr->target_id], SCSI_LUN_USE_CDB); + scsi_device_identify(&scsi_devices[ncr_dev->bus][ncr->target_id], SCSI_LUN_USE_CDB); ncr->cur_bus &= ~BUS_REQ; ncr->new_phase = SCSI_PHASE_MESSAGE_IN; ncr->wait_data = 4; @@ -542,9 +542,9 @@ ncr_bus_update(void *priv, int bus) } break; case STATE_MESSAGE_ID: - if ((ncr->target_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[ncr->target_id])) { + if ((ncr->target_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[ncr_dev->bus][ncr->target_id])) { ncr_log("Device found at ID %i on MSGOUT, Current Bus BSY=%02x\n", ncr->target_id, ncr->cur_bus); - scsi_device_identify(&scsi_devices[ncr->target_id], ncr->msglun); + scsi_device_identify(&scsi_devices[ncr_dev->bus][ncr->target_id], ncr->msglun); ncr->state = STATE_COMMAND; ncr->cur_bus = BUS_BSY | BUS_REQ; ncr_log("CurBus BSY|REQ=%02x\n", ncr->cur_bus); @@ -1091,7 +1091,7 @@ ncr_callback(void *priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr->target_id]; + scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; ncr_log("DMA mode=%d, status ctrl = %02x\n", ncr->dma_mode, ncr_dev->status_ctrl); @@ -1166,6 +1166,8 @@ ncr_init(const device_t *info) ncr_dev->name = info->name; ncr_dev->type = info->local; + ncr_dev->bus = scsi_get_bus(); + switch(ncr_dev->type) { case 0: /* Longshine LCS6821N */ ncr_dev->rom_addr = device_get_config_hex20("bios_addr"); diff --git a/src/scsi/scsi_ncr53c8xx.c b/src/scsi/scsi_ncr53c8xx.c index 5d4dda794..35a46381e 100644 --- a/src/scsi/scsi_ncr53c8xx.c +++ b/src/scsi/scsi_ncr53c8xx.c @@ -308,6 +308,8 @@ typedef struct { uint32_t bios_mask; + uint8_t bus; + pc_timer_t timer; #ifdef USE_WDTR @@ -440,7 +442,7 @@ ncr53c8xx_soft_reset(ncr53c8xx_t *dev) #ifdef USE_WDTR dev->tr_set[i] = 0; #endif - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[dev->bus][i]); } } else { /* This is *NOT* a wide SCSI controller, so do not touch @@ -449,7 +451,7 @@ ncr53c8xx_soft_reset(ncr53c8xx_t *dev) #ifdef USE_WDTR dev->tr_set[i] = 0; #endif - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[dev->bus][i]); } } } @@ -613,7 +615,7 @@ ncr53c8xx_disconnect(ncr53c8xx_t *dev) { scsi_device_t *sd; - sd = &scsi_devices[dev->sdid]; + sd = &scsi_devices[dev->bus][dev->sdid]; dev->scntl1 &= ~NCR_SCNTL1_CON; dev->sstat1 &= ~PHASE_MASK; @@ -659,7 +661,7 @@ ncr53c8xx_do_dma(ncr53c8xx_t *dev, int out, uint8_t id) uint32_t addr, tdbc; int count; - scsi_device_t *sd = &scsi_devices[id]; + scsi_device_t *sd = &scsi_devices[dev->bus][id]; if ((!scsi_device_present(sd))) { ncr53c8xx_log("(ID=%02i LUN=%02i) SCSI Command 0x%02x: Device not present when attempting to do DMA\n", id, dev->current_lun, dev->last_command); @@ -697,7 +699,7 @@ ncr53c8xx_do_dma(ncr53c8xx_t *dev, int out, uint8_t id) dev->buffer_pos += count; if (dev->temp_buf_len <= 0) { - scsi_device_command_phase1(&scsi_devices[id]); + scsi_device_command_phase1(&scsi_devices[dev->bus][id]); #ifdef ENABLE_NCR53C8XX_LOG if (out) ncr53c8xx_log("(ID=%02i LUN=%02i) SCSI Command 0x%02x: SCSI Command Phase 1 on PHASE_DO\n", id, dev->current_lun, dev->last_command); @@ -750,7 +752,7 @@ ncr53c8xx_do_command(ncr53c8xx_t *dev, uint8_t id) dev->sfbr = buf[0]; dev->command_complete = 0; - sd = &scsi_devices[id]; + sd = &scsi_devices[dev->bus][id]; if (!scsi_device_present(sd) || (dev->current_lun > 0)) { ncr53c8xx_log("(ID=%02i LUN=%02i) SCSI Command 0x%02x: Bad Selection\n", id, dev->current_lun, buf[0]); ncr53c8xx_bad_selection(dev, id); @@ -769,7 +771,7 @@ ncr53c8xx_do_command(ncr53c8xx_t *dev, uint8_t id) if ((buf[1] & 0xe0) != (dev->current_lun << 5)) buf[1] = (buf[1] & 0x1f) | (dev->current_lun << 5); - scsi_device_command_phase0(&scsi_devices[dev->current->tag], buf); + scsi_device_command_phase0(&scsi_devices[dev->bus][dev->current->tag], buf); dev->hba_private = (void *)dev->current; dev->waiting = 0; @@ -785,12 +787,12 @@ ncr53c8xx_do_command(ncr53c8xx_t *dev, uint8_t id) if ((sd->phase == SCSI_PHASE_DATA_IN) && (sd->buffer_length > 0)) { ncr53c8xx_log("(ID=%02i LUN=%02i) SCSI Command 0x%02x: PHASE_DI\n", id, dev->current_lun, buf[0]); ncr53c8xx_set_phase(dev, PHASE_DI); - ncr53c8xx_timer_on(dev, sd, scsi_device_get_callback(&scsi_devices[dev->current->tag])); + ncr53c8xx_timer_on(dev, sd, scsi_device_get_callback(&scsi_devices[dev->bus][dev->current->tag])); return 1; } else if ((sd->phase == SCSI_PHASE_DATA_OUT) && (sd->buffer_length > 0)) { ncr53c8xx_log("(ID=%02i LUN=%02i) SCSI Command 0x%02x: PHASE_DO\n", id, buf[0]); ncr53c8xx_set_phase(dev, PHASE_DO); - ncr53c8xx_timer_on(dev, sd, scsi_device_get_callback(&scsi_devices[dev->current->tag])); + ncr53c8xx_timer_on(dev, sd, scsi_device_get_callback(&scsi_devices[dev->bus][dev->current->tag])); return 1; } else { ncr53c8xx_command_complete(dev, sd->status); @@ -913,7 +915,7 @@ ncr53c8xx_do_msgout(ncr53c8xx_t *dev, uint8_t id) #endif scsi_device_t *sd; - sd = &scsi_devices[id]; + sd = &scsi_devices[dev->bus][id]; #ifdef ENABLE_NCR53C8XX_LOG current_tag = id; @@ -1169,7 +1171,7 @@ again: } dev->sstat0 |= NCR_SSTAT0_WOA; dev->scntl1 &= ~NCR_SCNTL1_IARB; - if (!scsi_device_present(&scsi_devices[id])) { + if (!scsi_device_present(&scsi_devices[dev->bus][id])) { ncr53c8xx_bad_selection(dev, id); break; } @@ -2513,6 +2515,8 @@ ncr53c8xx_init(const device_t *info) dev = malloc(sizeof(ncr53c8xx_t)); memset(dev, 0x00, sizeof(ncr53c8xx_t)); + dev->bus = scsi_get_bus(); + dev->chip_rev = 0; dev->chip = info->local & 0xff; diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index a4ec36f24..be5aec503 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -168,6 +168,7 @@ typedef struct { int deferred_complete; uint32_t dma; uint8_t ti_buf[TI_BUFSZ]; + uint8_t bus; uint8_t id, lun; uint8_t cmdbuf[ESP_CMDBUF_SZ]; uint32_t cmdlen; @@ -289,7 +290,7 @@ esp_get_cmd(esp_t *dev, uint8_t *buf, uint8_t buflen) dev->ti_rptr = 0; dev->ti_wptr = 0; - if (scsi_device_present(&scsi_devices[dev->id]) && (dev->lun > 0)) { + if (scsi_device_present(&scsi_devices[dev->bus][dev->id]) && (dev->lun > 0)) { /* We only support LUN 0 */ dev->rregs[ESP_RSTAT] = 0; dev->rregs[ESP_RINTR] = INTR_DC; @@ -298,7 +299,7 @@ esp_get_cmd(esp_t *dev, uint8_t *buf, uint8_t buflen) return 0; } - scsi_device_identify(&scsi_devices[dev->id], dev->lun); + scsi_device_identify(&scsi_devices[dev->bus][dev->id], dev->lun); return dmalen; } @@ -308,7 +309,7 @@ esp_do_busid_cmd(esp_t *dev, uint8_t *buf, uint8_t busid) { scsi_device_t *sd; - sd = &scsi_devices[busid]; + sd = &scsi_devices[dev->bus][busid]; sd->buffer_length = -1; @@ -388,7 +389,7 @@ esp_hard_reset(esp_t *dev) timer_stop(&dev->timer); for (int i = 0; i < 8; i++) - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[dev->bus][i]); } static void @@ -536,7 +537,7 @@ static void handle_ti(void *priv) { esp_t *dev = (esp_t *)priv; - scsi_device_t *sd = &scsi_devices[dev->id]; + scsi_device_t *sd = &scsi_devices[dev->bus][dev->id]; uint32_t dmalen; if (dev->dma) { @@ -1430,6 +1431,8 @@ dc390_init(const device_t *info) dev = malloc(sizeof(esp_t)); memset(dev, 0x00, sizeof(esp_t)); + dev->bus = scsi_get_bus(); + dev->PCIBase = 0; dev->MMIOBase = 0; diff --git a/src/scsi/scsi_spock.c b/src/scsi/scsi_spock.c index 270ad8c6c..5075d7f0a 100644 --- a/src/scsi/scsi_spock.c +++ b/src/scsi/scsi_spock.c @@ -143,7 +143,7 @@ typedef struct { int lun_id; } dev_id[SCSI_ID_MAX]; - uint8_t last_status; + uint8_t last_status, bus; uint8_t cdb[12]; int cdb_len; int cdb_id; @@ -488,7 +488,7 @@ spock_process_imm_cmd(spock_t *scsi) spock_log("Reset Command\n"); if ((scsi->attention & 0x0f) == 0x0f) { /*Adapter reset*/ for (i = 0; i < 8; i++) - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[scsi->bus][i]); spock_log("Adapter Reset\n"); if (!scsi->adapter_reset && scsi->bios_ver) /*The early 1990 bios must have its boot drive @@ -798,7 +798,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) break; case 2: /* Wait */ - if (scsi->scsi_state == SCSI_STATE_IDLE && scsi_device_present(&scsi_devices[scsi->cdb_id])) { + if (scsi->scsi_state == SCSI_STATE_IDLE && scsi_device_present(&scsi_devices[scsi->bus][scsi->cdb_id])) { if (scsi->last_status == SCSI_STATUS_OK) { scsi->scb_state = 3; spock_log("Status is Good on device ID %d, timer = %i\n", scsi->cdb_id, scsi->cmd_timer); @@ -816,7 +816,7 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) dma_bm_write(scb->term_status_block_addr + 0xb*2, (uint8_t *)&term_stat_block_addrb, 2, 2); dma_bm_write(scb->term_status_block_addr + 0xc*2, (uint8_t *)&term_stat_block_addrc, 2, 2); } - } else if (scsi->scsi_state == SCSI_STATE_IDLE && !scsi_device_present(&scsi_devices[scsi->cdb_id])) { + } else if (scsi->scsi_state == SCSI_STATE_IDLE && !scsi_device_present(&scsi_devices[scsi->bus][scsi->cdb_id])) { uint16_t term_stat_block_addr7 = (0xc << 8) | 2; uint16_t term_stat_block_addr8 = 0x10; spock_set_irq(scsi, scsi->scb_id, IRQ_TYPE_COMMAND_FAIL); @@ -854,7 +854,7 @@ spock_process_scsi(spock_t *scsi, scb_t *scb) case SCSI_STATE_SELECT: spock_log("Selecting ID %d\n", scsi->cdb_id); - if ((scsi->cdb_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[scsi->cdb_id])) { + if ((scsi->cdb_id != (uint8_t)-1) && scsi_device_present(&scsi_devices[scsi->bus][scsi->cdb_id])) { scsi->scsi_state = SCSI_STATE_SEND_COMMAND; spock_log("Device selected at ID %i\n", scsi->cdb_id); } else { @@ -869,7 +869,7 @@ spock_process_scsi(spock_t *scsi, scb_t *scb) break; case SCSI_STATE_SEND_COMMAND: - sd = &scsi_devices[scsi->cdb_id]; + sd = &scsi_devices[scsi->bus][scsi->cdb_id]; memset(scsi->temp_cdb, 0x00, 12); if (scsi->cdb_len < 12) { @@ -1086,7 +1086,7 @@ spock_mca_reset(void *priv) /* Reset all devices on controller reset. */ for (i = 0; i < 8; i++) - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[scsi->bus][i]); scsi->adapter_reset = 0; } @@ -1097,7 +1097,9 @@ spock_init(const device_t *info) int c; spock_t *scsi = malloc(sizeof(spock_t)); memset(scsi, 0x00, sizeof(spock_t)); - + + scsi->bus = scsi_get_bus(); + scsi->irq = 14; scsi->bios_ver = device_get_config_int("bios_ver"); diff --git a/src/scsi/scsi_x54x.c b/src/scsi/scsi_x54x.c index ea6f1b38b..c8dd945f5 100644 --- a/src/scsi/scsi_x54x.c +++ b/src/scsi/scsi_x54x.c @@ -85,7 +85,7 @@ x54x_irq(x54x_t *dev, int set) else irq = dev->Irq; - if (dev->bus & DEVICE_PCI) { + if (dev->card_bus & DEVICE_PCI) { x54x_log("PCI IRQ: %02X, PCI_INTA\n", dev->pci_slot); if (set) pci_set_irq(dev->pci_slot, PCI_INTA); @@ -155,9 +155,9 @@ clear_irq(x54x_t *dev) static void -target_check(uint8_t id) +target_check(x54x_t *dev, uint8_t id) { - if (! scsi_device_valid(&scsi_devices[id])) + if (! scsi_device_valid(&scsi_devices[dev->bus][id])) fatal("BIOS INT13 device on ID %02i has disappeared\n", id); } @@ -432,7 +432,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) if (!ret) { /* Get pointer to selected device. */ - dev = &scsi_devices[cmd->id]; + dev = &scsi_devices[x54x->bus][cmd->id]; dev->buffer_length = 0; if (! scsi_device_present(dev)) { @@ -459,7 +459,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) break; case 0x01: /* Read Status of Last Operation */ - target_check(cmd->id); + target_check(x54x, cmd->id); /* * Assuming 14 bytes because that is the default @@ -479,7 +479,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) case 0x03: /* Write Desired Sectors from Memory */ case 0x04: /* Verify Desired Sectors */ case 0x0c: /* Seek */ - target_check(cmd->id); + target_check(x54x, cmd->id); cdb[0] = bios_cmd_to_scsi[cmd->command]; cdb[1] = (cmd->lun & 7) << 5; @@ -519,7 +519,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) case 0x07: /* Format Unit */ case 0x10: /* Test Drive Ready */ case 0x11: /* Recalibrate */ - target_check(cmd->id); + target_check(x54x, cmd->id); cdb[0] = bios_cmd_to_scsi[cmd->command]; cdb[1] = (cmd->lun & 7) << 5; @@ -529,7 +529,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) case 0x08: /* Read Drive Parameters */ case 0x15: /* Read DASD Type */ - target_check(cmd->id); + target_check(x54x, cmd->id); dev->buffer_length = 6; @@ -758,7 +758,7 @@ x54x_set_residue(x54x_t *dev, Req_t *req, int32_t TransferLength) { uint32_t Residue = 0; addr24 Residue24; - int32_t BufLen = scsi_devices[req->TargetID].buffer_length; + int32_t BufLen = scsi_devices[dev->bus][req->TargetID].buffer_length; uint8_t bytes[4] = { 0, 0, 0, 0 }; if ((req->CmdBlock.common.Opcode == SCSI_INITIATOR_COMMAND_RES) || @@ -792,7 +792,7 @@ x54x_buf_dma_transfer(x54x_t *dev, Req_t *req, int Is24bit, int TransferLength, uint32_t DataPointer, DataLength; uint32_t SGEntryLength = (Is24bit ? sizeof(SGE) : sizeof(SGE32)); uint32_t Address, i; - int32_t BufLen = scsi_devices[req->TargetID].buffer_length; + int32_t BufLen = scsi_devices[dev->bus][req->TargetID].buffer_length; uint8_t read_from_host = (dir && ((req->CmdBlock.common.ControlByte == CCB_DATA_XFER_OUT) || (req->CmdBlock.common.ControlByte == 0x00))); uint8_t write_to_host = (!dir && ((req->CmdBlock.common.ControlByte == CCB_DATA_XFER_IN) || (req->CmdBlock.common.ControlByte == 0x00))); int sg_pos = 0; @@ -824,11 +824,11 @@ x54x_buf_dma_transfer(x54x_t *dev, Req_t *req, int Is24bit, int TransferLength, if (read_from_host && DataToTransfer) { x54x_log("Reading S/G segment %i: length %i, pointer %08X\n", i, DataToTransfer, Address); - dma_bm_read(Address, &(scsi_devices[req->TargetID].sc->temp_buffer[sg_pos]), DataToTransfer, dev->transfer_size); + dma_bm_read(Address, &(scsi_devices[dev->bus][req->TargetID].sc->temp_buffer[sg_pos]), DataToTransfer, dev->transfer_size); } else if (write_to_host && DataToTransfer) { x54x_log("Writing S/G segment %i: length %i, pointer %08X\n", i, DataToTransfer, Address); - dma_bm_write(Address, &(scsi_devices[req->TargetID].sc->temp_buffer[sg_pos]), DataToTransfer, dev->transfer_size); + dma_bm_write(Address, &(scsi_devices[dev->bus][req->TargetID].sc->temp_buffer[sg_pos]), DataToTransfer, dev->transfer_size); } else x54x_log("No action on S/G segment %i: length %i, pointer %08X\n", i, DataToTransfer, Address); @@ -848,9 +848,9 @@ x54x_buf_dma_transfer(x54x_t *dev, Req_t *req, int Is24bit, int TransferLength, if ((DataLength > 0) && (BufLen > 0) && (req->CmdBlock.common.ControlByte < 0x03)) { if (read_from_host) - dma_bm_read(Address, scsi_devices[req->TargetID].sc->temp_buffer, MIN(BufLen, (int) DataLength), dev->transfer_size); + dma_bm_read(Address, scsi_devices[dev->bus][req->TargetID].sc->temp_buffer, MIN(BufLen, (int) DataLength), dev->transfer_size); else if (write_to_host) - dma_bm_write(Address, scsi_devices[req->TargetID].sc->temp_buffer, MIN(BufLen, (int) DataLength), dev->transfer_size); + dma_bm_write(Address, scsi_devices[dev->bus][req->TargetID].sc->temp_buffer, MIN(BufLen, (int) DataLength), dev->transfer_size); } } } @@ -896,7 +896,7 @@ SenseBufferFree(x54x_t *dev, Req_t *req, int Copy) uint8_t temp_sense[256]; if (SenseLength && Copy) { - scsi_device_request_sense(&scsi_devices[req->TargetID], temp_sense, SenseLength); + scsi_device_request_sense(&scsi_devices[dev->bus][req->TargetID], temp_sense, SenseLength); /* * The sense address, in 32-bit mode, is located in the @@ -925,7 +925,7 @@ x54x_scsi_cmd(x54x_t *dev) uint32_t i, target_cdb_len = 12; scsi_device_t *sd; - sd = &scsi_devices[req->TargetID]; + sd = &scsi_devices[dev->bus][req->TargetID]; target_cdb_len = 12; dev->target_data_len = x54x_get_length(dev, req, bit24); @@ -965,7 +965,7 @@ x54x_scsi_cmd(x54x_t *dev) else dev->callback_sub_phase = 2; - x54x_log("scsi_devices[%02i].Status = %02X\n", req->TargetID, sd->status); + x54x_log("scsi_devices[%02i][%02i].Status = %02X\n", dev->bus, req->TargetID, sd->status); } @@ -977,7 +977,7 @@ x54x_scsi_cmd_phase1(x54x_t *dev) uint8_t bit24 = !!req->Is24bit; scsi_device_t *sd; - sd = &scsi_devices[req->TargetID]; + sd = &scsi_devices[dev->bus][req->TargetID]; if (dev->scsi_cmd_phase != SCSI_PHASE_STATUS) { if ((dev->temp_cdb[0] != 0x03) || (req->CmdBlock.common.ControlByte != 0x03)) { @@ -992,7 +992,7 @@ x54x_scsi_cmd_phase1(x54x_t *dev) } dev->callback_sub_phase = 3; - x54x_log("scsi_devices[%02i].Status = %02X\n", req->TargetID, sd->status); + x54x_log("scsi_devices[%02xi][%02i].Status = %02X\n", x54x->bus, req->TargetID, sd->status); } @@ -1003,7 +1003,7 @@ x54x_request_sense(x54x_t *dev) uint32_t SenseBufferAddress; scsi_device_t *sd; - sd = &scsi_devices[req->TargetID]; + sd = &scsi_devices[dev->bus][req->TargetID]; if (dev->scsi_cmd_phase != SCSI_PHASE_STATUS) { if ((dev->temp_cdb[0] == 0x03) && (req->CmdBlock.common.ControlByte == 0x03)) { @@ -1011,7 +1011,7 @@ x54x_request_sense(x54x_t *dev) sd->buffer_length = ConvertSenseLength(req->CmdBlock.common.RequestSenseLength); if ((sd->status != SCSI_STATUS_OK) && (sd->buffer_length > 0)) { SenseBufferAddress = SenseBufferPointer(req); - dma_bm_write(SenseBufferAddress, scsi_devices[req->TargetID].sc->temp_buffer, sd->buffer_length, dev->transfer_size); + dma_bm_write(SenseBufferAddress, scsi_devices[dev->bus][req->TargetID].sc->temp_buffer, sd->buffer_length, dev->transfer_size); x54x_add_to_period(dev, sd->buffer_length); } scsi_device_command_phase1(sd); @@ -1033,7 +1033,7 @@ x54x_request_sense(x54x_t *dev) } dev->callback_sub_phase = 4; - x54x_log("scsi_devices[%02i].Status = %02X\n", req->TargetID, sd->status); + x54x_log("scsi_devices[%02i][%02i].Status = %02X\n", dev->bus, req->TargetID, sd->status); } @@ -1056,7 +1056,7 @@ x54x_notify(x54x_t *dev) Req_t *req = &dev->Req; scsi_device_t *sd; - sd = &scsi_devices[req->TargetID]; + sd = &scsi_devices[dev->bus][req->TargetID]; x54x_mbo_free(dev); @@ -1088,7 +1088,7 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) req->LUN = req->Is24bit ? req->CmdBlock.old.Lun : req->CmdBlock.new.Lun; id = req->TargetID; - sd = &scsi_devices[id]; + sd = &scsi_devices[dev->bus][id]; lun = req->LUN; if ((id > dev->max_id) || (lun > 7)) { x54x_log("SCSI Target ID %i or LUN %i is not valid\n",id,lun); @@ -1466,7 +1466,7 @@ x54x_reset(x54x_t *dev) /* Reset all devices on controller reset. */ for (i = 0; i < 16; i++) - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[dev->bus][i]); if (dev->ven_reset) dev->ven_reset(dev); @@ -1522,7 +1522,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) if (val & CTRL_SCRST) { /* Reset all devices on SCSI bus reset. */ for (i = 0; i < 16; i++) - scsi_device_reset(&scsi_devices[i]); + scsi_device_reset(&scsi_devices[dev->bus][i]); } if (val & CTRL_IRST) { @@ -1699,7 +1699,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) if (i == host_id) continue; /* TODO: Query device for LUN's. */ - if (scsi_device_present(&scsi_devices[i])) + if (scsi_device_present(&scsi_devices[dev->bus][i])) dev->DataBuf[i] |= 1; } dev->DataReplyLeft = i; @@ -1846,9 +1846,9 @@ x54x_is_32bit(x54x_t *dev) { int bit32 = 0; - if (dev->bus & DEVICE_PCI) + if (dev->card_bus & DEVICE_PCI) bit32 = 1; - else if ((dev->bus & DEVICE_MCA) && (dev->flags & X54X_32BIT)) + else if ((dev->card_bus & DEVICE_MCA) && (dev->flags & X54X_32BIT)) bit32 = 1; return bit32; @@ -1939,7 +1939,7 @@ x54x_init(const device_t *info) memset(dev, 0x00, sizeof(x54x_t)); dev->type = info->local; - dev->bus = info->flags; + dev->card_bus = info->flags; dev->callback_phase = 0; timer_add(&dev->ResetCB, x54x_reset_poll, dev, 0); diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 8ba956285..4b059c533 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -549,32 +549,50 @@ BEGIN BS_AUTOCHECKBOX | WS_TABSTOP,7,118,94,10 END -DLG_CFG_STORAGE DIALOG DISCARDABLE 107, 0, 267, 111 +DLG_CFG_STORAGE DIALOG DISCARDABLE 107, 0, 267, 211 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN - LTEXT "SCSI Controller:",IDT_1717,7,9,64,10 - COMBOBOX IDC_COMBO_SCSI,64,7,155,120,CBS_DROPDOWNLIST | + LTEXT "HD Controller:",IDT_1718,7,9,64,10 + COMBOBOX IDC_COMBO_HDC,64,7,155,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI,222,7,38,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_HDC,222,7,38,12 - LTEXT "HD Controller:",IDT_1718,7,28,64,10 - COMBOBOX IDC_COMBO_HDC,64,26,155,120,CBS_DROPDOWNLIST | + LTEXT "FD Controller:",IDT_1768,7,28,64,10 + COMBOBOX IDC_COMBO_FDC,64,26,155,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_HDC,222,26,38,12 - - LTEXT "FD Controller:",IDT_1768,7,47,64,10 - COMBOBOX IDC_COMBO_FDC,64,45,155,120,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_FDC,222,45,38,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_FDC,222,26,38,12 CONTROL "Tertiary IDE Controller",IDC_CHECK_IDE_TER,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,66,199,10 - PUSHBUTTON "Configure",IDC_BUTTON_IDE_TER,222,64,38,12 + BS_AUTOCHECKBOX | WS_TABSTOP,7,47,199,10 + PUSHBUTTON "Configure",IDC_BUTTON_IDE_TER,222,45,38,12 CONTROL "Quaternary IDE Controller",IDC_CHECK_IDE_QUA,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,7,85,199,10 - PUSHBUTTON "Configure",IDC_BUTTON_IDE_QUA,222,83,38,12 + BS_AUTOCHECKBOX | WS_TABSTOP,7,66,199,10 + PUSHBUTTON "Configure",IDC_BUTTON_IDE_QUA,222,64,38,12 + + GROUPBOX "SCSI",IDC_GROUP_SCSI,7,85,253,93 + LTEXT "Controller 1:",IDT_1763,16,102,48,10 + COMBOBOX IDC_COMBO_SCSI_1,73,100,137,120, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI_1,213,100,38,12 + LTEXT "Controller 2:",IDT_1764,16,121,48,10 + COMBOBOX IDC_COMBO_SCSI_2,73,119,137,120, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI_2,213,119,38,12 + LTEXT "Controller 3:",IDT_1765,16,140,48,10 + COMBOBOX IDC_COMBO_SCSI_3,73,138,137,120, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI_3,213,138,38,12 + LTEXT "Controller 4:",IDT_1766,16,159,48,10 + COMBOBOX IDC_COMBO_SCSI_4,73,157,137,120, + CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI_4,213,157,38,12 + + LTEXT "SCSI Controller:",IDT_1717,7,185,64,10 + COMBOBOX IDC_COMBO_SCSI,64,183,155,120,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI,222,183,38,12 END DLG_CFG_HARD_DISKS DIALOG DISCARDABLE 107, 0, 267, 154 @@ -1114,7 +1132,7 @@ STRINGTABLE DISCARDABLE BEGIN IDS_4096 "Hard disk (%s)" IDS_4097 "%01i:%01i" - IDS_4098 "%i" + IDS_4098 "%01i" IDS_4099 "MFM/RLL or ESDI CD-ROM drives never existed" IDS_4100 "Custom..." IDS_4101 "Custom (large)..." @@ -1151,6 +1169,7 @@ BEGIN IDS_4132 "This could mean that the parent image was modified after the differencing image was created.\n\nIt can also happen if the image files were moved or copied, or by a bug in the program that created this disk.\n\nDo you want to fix the timestamps?" IDS_4133 "Parent and child disk timestamps do not match" IDS_4134 "Could not fix VHD timestamp." + IDS_4135 "%01i:%02i" IDS_4352 "MFM/RLL" IDS_4353 "XTA" @@ -1164,7 +1183,7 @@ BEGIN IDS_4610 "ESDI (%01i:%01i)" IDS_4611 "IDE (%01i:%01i)" IDS_4612 "ATAPI (%01i:%01i)" - IDS_4613 "SCSI (ID %02i)" + IDS_4613 "SCSI (%01i:%02i)" IDS_5120 "CD-ROM %i (%s): %s" @@ -1174,7 +1193,7 @@ BEGIN IDS_5632 "Disabled" IDS_5637 "ATAPI (%01i:%01i)" - IDS_5638 "SCSI (ID %02i)" + IDS_5638 "SCSI (%01i:%02i)" IDS_5888 "160 kB" IDS_5889 "180 kB" diff --git a/src/win/win_media_menu.c b/src/win/win_media_menu.c index 1908f1f7c..ff6c34557 100644 --- a/src/win/win_media_menu.c +++ b/src/win/win_media_menu.c @@ -295,7 +295,9 @@ 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 == 0)) + if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) return 0; return cdrom[i].bus_type != 0; } @@ -305,7 +307,9 @@ 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 == 0)) + if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) return 0; return zip_drives[i].bus_type != 0; } @@ -315,7 +319,9 @@ 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 == 0)) + if ((mo_drives[i].bus_type == MO_BUS_SCSI) && !MACHINE_HAS_SCSI && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) return 0; return mo_drives[i].bus_type != 0; } diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 067f7c9f9..31e33c587 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -103,7 +103,8 @@ 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, temp_ide_ter, temp_ide_qua; +static int temp_fdc_card, temp_hdc, temp_scsi_card_legacy, temp_ide_ter, temp_ide_qua; +static int temp_scsi_card[SCSI_BUS_MAX]; static int temp_bugger; static int temp_postcard; static int temp_isartc; @@ -136,7 +137,7 @@ static int settings_list_to_midi[20], settings_list_to_midi_in[20]; static int settings_list_to_hdc[20]; static int max_spt = 63, max_hpc = 255, max_tracks = 266305; -static uint64_t mfm_tracking, esdi_tracking, xta_tracking, ide_tracking, scsi_tracking[2]; +static uint64_t mfm_tracking, esdi_tracking, xta_tracking, ide_tracking, scsi_tracking[8]; static uint64_t size; static int hd_listview_items, hdc_id_to_listview_index[HDD_NUM]; static int no_update = 0, existing = 0, chs_enabled = 0; @@ -369,7 +370,9 @@ win_settings_init(void) temp_serial[i] = serial_enabled[i]; /* Other peripherals category */ - temp_scsi_card = scsi_card_current; + 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; temp_hdc = hdc_current; temp_ide_ter = ide_ter_enabled; @@ -485,7 +488,9 @@ win_settings_changed(void) i = i || (temp_serial[j] != serial_enabled[j]); /* Peripherals category */ - i = i || (scsi_card_current != temp_scsi_card); + 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); i = i || (hdc_current != temp_hdc); i = i || (temp_ide_ter != ide_ter_enabled); @@ -572,7 +577,9 @@ win_settings_save(void) serial_enabled[i] = temp_serial[i]; /* Peripherals category */ - scsi_card_current = temp_scsi_card; + 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; fdc_type = temp_fdc_card; ide_ter_enabled = temp_ide_ter; @@ -1530,7 +1537,7 @@ static BOOL CALLBACK win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { int c, d; - int is_at; + int e, is_at; LPTSTR lptsTemp; char *stransi; const device_t *scsi_dev, *fdc_dev; @@ -1626,9 +1633,21 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) settings_add_string(hdlg, IDC_COMBO_SCSI, win_get_string(IDS_2103)); else settings_add_string(hdlg, IDC_COMBO_SCSI, (LPARAM) device_name); - settings_list_to_device[0][d] = c; - if ((c == 0) || (c == temp_scsi_card)) + + 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)); + else + settings_add_string(hdlg, IDC_COMBO_SCSI_1 + e, (LPARAM) device_name); + + if ((c == 0) || (c == temp_scsi_card[e])) + settings_set_cur_sel(hdlg, IDC_COMBO_SCSI_1 + e, d); + } + + settings_list_to_device[0][d] = c; d++; } } @@ -1636,8 +1655,20 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) c++; } - settings_enable_window(hdlg, IDC_COMBO_SCSI, d); - settings_enable_window(hdlg, IDC_CONFIGURE_SCSI, scsi_card_has_config(temp_scsi_card)); + 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])); + } is_at = IS_AT(temp_machine); settings_enable_window(hdlg, IDC_CHECK_IDE_TER, is_at); settings_enable_window(hdlg, IDC_BUTTON_IDE_TER, is_at && temp_ide_ter); @@ -1674,13 +1705,25 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) break; case IDC_CONFIGURE_SCSI: - temp_scsi_card = 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)); + 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 = 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)); + 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)]; + temp_deviceconfig |= deviceconfig_inst_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card[c]), c + 1); + break; + + case IDC_COMBO_SCSI_1 ... IDC_COMBO_SCSI_4: + c = LOWORD(wParam) - IDC_COMBO_SCSI_1; + temp_scsi_card[c] = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI_1 + c)]; + settings_enable_window(hdlg, IDC_CONFIGURE_SCSI_1 + c, scsi_card_has_config(temp_scsi_card[c])); break; case IDC_CHECK_IDE_TER: @@ -1706,7 +1749,9 @@ 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 = settings_list_to_device[0][settings_get_cur_sel(hdlg, IDC_COMBO_SCSI)]; + 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); temp_ide_qua = settings_get_check(hdlg, IDC_CHECK_IDE_QUA); @@ -1896,8 +1941,8 @@ add_locations(HWND hdlg) settings_add_string(hdlg, IDC_COMBO_HD_CHANNEL, (LPARAM) lptsTemp); } - for (i = 0; i < 16; i++) { - wsprintf(lptsTemp, plat_get_string(IDS_4098), i); + for (i = 0; i < 64; i++) { + wsprintf(lptsTemp, plat_get_string(IDS_4135), i >> 4, i & 15); settings_add_string(hdlg, IDC_COMBO_HD_ID, (LPARAM) lptsTemp); } @@ -1943,7 +1988,7 @@ next_free_scsi_id(uint8_t *id) { int64_t i; - for (i = 0; i < 16; i++) { + for (i = 0; i < 64; i++) { if (!(scsi_tracking[i >> 3] & (0xffLL << ((i & 0x07) << 3LL)))) { *id = i; return; @@ -2126,7 +2171,7 @@ win_settings_hard_disks_update_item(HWND hdlg, int i, int column) wsprintf(szText, plat_get_string(IDS_4612), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); break; case HDD_BUS_SCSI: - wsprintf(szText, plat_get_string(IDS_4613), temp_hdd[i].scsi_id); + wsprintf(szText, plat_get_string(IDS_4613), temp_hdd[i].scsi_id >> 4, temp_hdd[i].scsi_id >> 4 & 15); break; } lvI.pszText = szText; @@ -2200,7 +2245,7 @@ win_settings_hard_disks_recalc_list(HWND hdlg) wsprintf(szText, plat_get_string(IDS_4612), temp_hdd[i].ide_channel >> 1, temp_hdd[i].ide_channel & 1); break; case HDD_BUS_SCSI: - wsprintf(szText, plat_get_string(IDS_4613), temp_hdd[i].scsi_id); + wsprintf(szText, plat_get_string(IDS_4613), temp_hdd[i].scsi_id >> 4, temp_hdd[i].scsi_id >> 4 & 15); break; } lvI.pszText = szText; @@ -3575,7 +3620,7 @@ win_settings_cdrom_drives_recalc_list(HWND hdlg) lvI.iImage = 1; break; case CDROM_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].scsi_device_id >> 4, temp_cdrom[i].scsi_device_id & 15); lvI.pszText = szText; lvI.iImage = 1; break; @@ -3632,7 +3677,7 @@ win_settings_mo_drives_recalc_list(HWND hdlg) lvI.iImage = 1; break; case MO_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_mo_drives[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_mo_drives[i].scsi_device_id >> 4, temp_mo_drives[i].scsi_device_id & 15); lvI.pszText = szText; lvI.iImage = 1; break; @@ -3695,7 +3740,7 @@ win_settings_zip_drives_recalc_list(HWND hdlg) lvI.iImage = 1; break; case ZIP_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_zip_drives[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_zip_drives[i].scsi_device_id >> 4, temp_zip_drives[i].scsi_device_id & 15); lvI.pszText = szText; lvI.iImage = 1; break; @@ -4006,7 +4051,7 @@ win_settings_cdrom_drives_update_item(HWND hdlg, int i) lvI.iImage = 1; break; case CDROM_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].scsi_device_id >> 4, temp_cdrom[i].scsi_device_id & 15); lvI.pszText = szText; lvI.iImage = 1; break; @@ -4059,7 +4104,7 @@ win_settings_mo_drives_update_item(HWND hdlg, int i) lvI.iImage = 1; break; case MO_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_mo_drives[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_mo_drives[i].scsi_device_id >> 4, temp_mo_drives[i].scsi_device_id & 15); lvI.pszText = szText; lvI.iImage = 1; break; @@ -4117,7 +4162,7 @@ win_settings_zip_drives_update_item(HWND hdlg, int i) lvI.iImage = 1; break; case ZIP_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_zip_drives[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_zip_drives[i].scsi_device_id >> 4, temp_zip_drives[i].scsi_device_id & 15); lvI.pszText = szText; lvI.iImage = 1; break; @@ -4154,8 +4199,8 @@ cdrom_add_locations(HWND hdlg) settings_add_string(hdlg, IDC_COMBO_CD_SPEED, (LPARAM) lptsTemp); } - for (i = 0; i < 16; i++) { - wsprintf(lptsTemp, plat_get_string(IDS_4098), i); + for (i = 0; i < 64; i++) { + wsprintf(lptsTemp, plat_get_string(IDS_4135), i >> 4, i & 15); settings_add_string(hdlg, IDC_COMBO_CD_ID, (LPARAM) lptsTemp); } @@ -4222,8 +4267,8 @@ mo_add_locations(HWND hdlg) settings_add_string(hdlg, IDC_COMBO_MO_BUS, win_get_string(combo_id_to_string_id(i))); } - for (i = 0; i < 16; i++) { - wsprintf(lptsTemp, plat_get_string(IDS_4098), i); + for (i = 0; i < 64; i++) { + wsprintf(lptsTemp, plat_get_string(IDS_4135), i >> 4, i & 15); settings_add_string(hdlg, IDC_COMBO_MO_ID, (LPARAM) lptsTemp); } @@ -4301,8 +4346,8 @@ zip_add_locations(HWND hdlg) settings_add_string(hdlg, IDC_COMBO_ZIP_BUS, win_get_string(combo_id_to_string_id(i))); } - for (i = 0; i < 16; i++) { - wsprintf(lptsTemp, plat_get_string(IDS_4098), i); + for (i = 0; i < 64; i++) { + wsprintf(lptsTemp, plat_get_string(IDS_4135), i >> 4, i & 15); settings_add_string(hdlg, IDC_COMBO_ZIP_ID, (LPARAM) lptsTemp); } diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index 505c4cb7b..f67c0881c 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -504,7 +504,9 @@ ui_sb_update_panes(void) continue; if ((cdrom[i].bus_type == CDROM_BUS_SCSI) && - !scsi_int && (scsi_card_current == 0)) + !scsi_int && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; if (cdrom[i].bus_type != 0) sb_parts++; @@ -516,7 +518,9 @@ ui_sb_update_panes(void) continue; if ((zip_drives[i].bus_type == ZIP_BUS_SCSI) && - !scsi_int && (scsi_card_current == 0)) + !scsi_int && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; if (zip_drives[i].bus_type != 0) sb_parts++; @@ -528,7 +532,9 @@ ui_sb_update_panes(void) continue; if ((mo_drives[i].bus_type == MO_BUS_SCSI) && - !scsi_int && (scsi_card_current == 0)) + !scsi_int && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; if (mo_drives[i].bus_type != 0) sb_parts++; @@ -545,7 +551,8 @@ 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 != 0))) + if (c_scsi && (scsi_int || (scsi_card_current_legacy != 0) || (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) sb_parts++; @@ -576,7 +583,9 @@ 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 == 0)) + !scsi_int && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; if (cdrom[i].bus_type != 0) { edge += icon_width; @@ -592,7 +601,9 @@ 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 == 0)) + !scsi_int && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; if (zip_drives[i].bus_type != 0) { edge += icon_width; @@ -608,7 +619,9 @@ 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 == 0)) + !scsi_int && (scsi_card_current_legacy == 0) && + (scsi_card_current[0] == 0) && (scsi_card_current[1] == 0) && + (scsi_card_current[2] == 0) && (scsi_card_current[3] == 0)) continue; if (mo_drives[i].bus_type != 0) { edge += icon_width; @@ -646,7 +659,8 @@ ui_sb_update_panes(void) sb_map[SB_HDD | HDD_BUS_IDE] = sb_parts; sb_parts++; } - if (c_scsi && (scsi_int || (scsi_card_current != 0))) { + if (c_scsi && (scsi_int || (scsi_card_current_legacy != 0) || (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; sb_part_meanings[sb_parts] = SB_HDD | HDD_BUS_SCSI; From c47e766bc40d15048d7e07a1cefa67710994ef28 Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 23 Jul 2021 01:20:14 +0200 Subject: [PATCH 2/4] 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; From ea65edb831448bb13a976f2828aaf5206be89d5d Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 23 Jul 2021 01:22:47 +0200 Subject: [PATCH 3/4] Did some changes I forgot to do before. --- src/include/86box/resource.h | 32 +++++++++++++++----------------- src/win/86Box.rc | 5 ----- src/win/win_settings.c | 3 ++- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/include/86box/resource.h b/src/include/86box/resource.h index 86215fdfc..0cd8d1423 100644 --- a/src/include/86box/resource.h +++ b/src/include/86box/resource.h @@ -180,23 +180,21 @@ #define IDC_CHECK_PARALLEL3 1079 #define IDC_OTHER_PERIPH 1080 /* storage controllers config */ -#define IDC_COMBO_SCSI 1081 -#define IDC_CONFIGURE_SCSI 1082 -#define IDC_COMBO_HDC 1083 -#define IDC_CONFIGURE_HDC 1084 -#define IDC_CHECK_IDE_TER 1085 -#define IDC_BUTTON_IDE_TER 1086 -#define IDC_CHECK_IDE_QUA 1087 -#define IDC_BUTTON_IDE_QUA 1088 -#define IDC_GROUP_SCSI 1089 -#define IDC_COMBO_SCSI_1 1090 -#define IDC_COMBO_SCSI_2 1091 -#define IDC_COMBO_SCSI_3 1092 -#define IDC_COMBO_SCSI_4 1093 -#define IDC_CONFIGURE_SCSI_1 1094 -#define IDC_CONFIGURE_SCSI_2 1095 -#define IDC_CONFIGURE_SCSI_3 1096 -#define IDC_CONFIGURE_SCSI_4 1097 +#define IDC_COMBO_HDC 1081 +#define IDC_CONFIGURE_HDC 1082 +#define IDC_CHECK_IDE_TER 1083 +#define IDC_BUTTON_IDE_TER 1084 +#define IDC_CHECK_IDE_QUA 1085 +#define IDC_BUTTON_IDE_QUA 1086 +#define IDC_GROUP_SCSI 1087 +#define IDC_COMBO_SCSI_1 1088 +#define IDC_COMBO_SCSI_2 1089 +#define IDC_COMBO_SCSI_3 1090 +#define IDC_COMBO_SCSI_4 1091 +#define IDC_CONFIGURE_SCSI_1 1092 +#define IDC_CONFIGURE_SCSI_2 1093 +#define IDC_CONFIGURE_SCSI_3 1094 +#define IDC_CONFIGURE_SCSI_4 1095 #define IDC_HARD_DISKS 1100 /* hard disks config */ #define IDC_LIST_HARD_DISKS 1101 diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 4b059c533..658b7868b 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -588,11 +588,6 @@ BEGIN COMBOBOX IDC_COMBO_SCSI_4,73,157,137,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI_4,213,157,38,12 - - LTEXT "SCSI Controller:",IDT_1717,7,185,64,10 - COMBOBOX IDC_COMBO_SCSI,64,183,155,120,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI,222,183,38,12 END DLG_CFG_HARD_DISKS DIALOG DISCARDABLE 107, 0, 267, 154 diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 90e2a00d4..f0a00c6c5 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -1615,7 +1615,8 @@ win_settings_storage_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) /*SCSI config*/ c = d = 0; - settings_reset_content(hdlg, IDC_COMBO_SCSI); + for (e = 0; e < SCSI_BUS_MAX; e++) + settings_reset_content(hdlg, IDC_COMBO_SCSI_1 + e); while (1) { generate_device_name(scsi_card_getdevice(c), scsi_card_get_internal_name(c), 1); From 7f85f6acdff1acc5ce4d80e6b283516f00b23033 Mon Sep 17 00:00:00 2001 From: OBattler Date: Fri, 23 Jul 2021 05:51:26 +0200 Subject: [PATCH 4/4] Some PCI IRQ changes to mitigate IRQ loss. --- src/pci.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pci.c b/src/pci.c index 5f1c48f50..746cad811 100644 --- a/src/pci.c +++ b/src/pci.c @@ -377,6 +377,7 @@ pci_set_mirq(uint8_t mirq, int level) if (level && (pci_irq_hold[irq_line] & (1ULL << irq_bit))) { /* IRQ already held, do nothing. */ pci_log("pci_set_mirq(%02X): MIRQ is already holding the IRQ\n", mirq); + picintlevel(1 << irq_line); return; } pci_log("pci_set_mirq(%02X): MIRQ not yet holding the IRQ\n", mirq); @@ -391,6 +392,7 @@ pci_set_mirq(uint8_t mirq, int level) picint(1 << irq_line); } else if (level && pci_irq_hold[irq_line]) { pci_log("pci_set_mirq(%02X): IRQ line already being held\n", mirq); + picintlevel(1 << irq_line); } /* If the IRQ is level-triggered, mark that this MIRQ is holding it. */ @@ -449,6 +451,7 @@ pci_set_irq(uint8_t card, uint8_t pci_int) if (level && (pci_irq_hold[irq_line] & (1ULL << slot))) { /* IRQ already held, do nothing. */ pci_log("pci_set_irq(%02X, %02X): Card is already holding the IRQ\n", card, pci_int); + picintlevel(1 << irq_line); return; } pci_log("pci_set_irq(%02X, %02X): Card not yet holding the IRQ\n", card, pci_int); @@ -463,6 +466,7 @@ pci_set_irq(uint8_t card, uint8_t pci_int) picint(1 << irq_line); } else if (level && pci_irq_hold[irq_line]) { pci_log("pci_set_irq(%02X, %02X): IRQ line already being held\n", card, pci_int); + picintlevel(1 << irq_line); } /* If the IRQ is level-triggered, mark that this card is holding it. */