From f88fbd6fd27a29f7fe8e8190adf8386728d94737 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 6 Nov 2022 20:04:10 +0100 Subject: [PATCH] The later SCSI and ATAPI CD-ROM drives correctly identify as having tray loaders and not caddy loaders. --- src/scsi/scsi_cdrom.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index bee60bb5f..2a1e63c98 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -518,18 +518,29 @@ scsi_cdrom_mode_sense(scsi_cdrom_t *dev, uint8_t *buf, uint32_t pos, uint8_t pag buf[pos++] = msplen; scsi_cdrom_log("CD-ROM %i: MODE SENSE: Page [%02X] length %i\n", dev->id, i, msplen); for (j = 0; j < msplen; j++) { - if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && (j <= 7)) { - if (j & 1) - buf[pos++] = ((dev->drv->speed * 176) & 0xff); - else - buf[pos++] = ((dev->drv->speed * 176) >> 8); - } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && (j <= 13)) { - if (j & 1) - buf[pos++] = ((dev->drv->cur_speed * 176) & 0xff); - else - buf[pos++] = ((dev->drv->cur_speed * 176) >> 8); - } else + /* If we are returning changeable values, always return them from the page, + so they are all correctly. */ + if (page_control == 1) buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j); + else { + if ((i == GPMODE_CAPABILITIES_PAGE) && (j == 4)) { + buf[pos] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j) & 0x1f; + /* The early CD-ROM drives we emulate (NEC CDR-260 for ATAPI and Toshiba CDS-431) are + caddy drives, the later ones are tray drives. */ + buf[pos++] |= (dev->early ? 0x00 : 0x20); + } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && (j <= 7)) { + if (j & 1) + buf[pos++] = ((dev->drv->speed * 176) & 0xff); + else + buf[pos++] = ((dev->drv->speed * 176) >> 8); + } else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && (j <= 13)) { + if (j & 1) + buf[pos++] = ((dev->drv->cur_speed * 176) & 0xff); + else + buf[pos++] = ((dev->drv->cur_speed * 176) >> 8); + } else + buf[pos++] = scsi_cdrom_mode_sense_read(dev, page_control, i, 2 + j); + } } } }