From 734d7a5a5ac046c8fea3759cc940fd426a6d9cc5 Mon Sep 17 00:00:00 2001 From: OBattler Date: Sat, 2 Sep 2017 05:41:19 +0200 Subject: [PATCH] Various SCSI and CD-ROM bugfixes. --- src/cdrom.c | 7 +++++++ src/cdrom_image.cc | 9 +++++++-- src/scsi/scsi_aha154x.c | 30 +++++++++++++++++++++++++----- src/scsi/scsi_disk.c | 4 ++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/cdrom.c b/src/cdrom.c index bdee7a516..6310cb6e4 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -2389,6 +2389,13 @@ void cdrom_command(uint8_t id, uint8_t *cdb) case GPCMD_REQUEST_SENSE: /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE should forget about the not ready, and report unit attention straight away. */ + if (cdrom_drives[id].bus_type == CDROM_BUS_SCSI) + { + if (SCSIDevices[cdrom_drives[id].scsi_device_id][cdrom_drives[id].scsi_device_lun].InitLength < cdb[4]) + { + cdb[4] = SCSIDevices[cdrom_drives[id].scsi_device_id][cdrom_drives[id].scsi_device_lun].InitLength; + } + } cdrom_request_sense(id, cdbufferb, cdb[4]); cdrom_data_command_finish(id, 18, 18, cdb[4], 0); break; diff --git a/src/cdrom_image.cc b/src/cdrom_image.cc index ba538b066..13ac2cb73 100644 --- a/src/cdrom_image.cc +++ b/src/cdrom_image.cc @@ -780,6 +780,7 @@ static int image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int number; unsigned char attr; TMSF tmsf; + cdimg[id]->GetAudioTracks(first_track, last_track, tmsf); b[2] = first_track; @@ -795,8 +796,12 @@ static int image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, break; } } - cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr); - b[2] = number; + + if (starttrack != 0xAA) + { + cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr); + b[2] = number; + } for (c = d; c <= last_track; c++) { diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index 09261b3cd..80ea1cf21 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -781,6 +781,10 @@ aha_mbi(aha_t *dev) dev->MailboxInPosCur = 0; RaiseIntr(dev, 0, INTR_MBIF | INTR_ANY); + + while (dev->Interrupt) { + thread_wait_event(dev->evt, 10); + } } @@ -1230,13 +1234,24 @@ aha_do_mail(aha_t *dev) CodeOffset = dev->Mbx24bit ? 0 : 7; +#if 0 if (dev->Interrupt || dev->PendingInterrupt) { aha_log("%s: Interrupt set, waiting...\n", dev->name); return 1; } +#endif - Outgoing = aha_mbo(dev, &mb32); + uint8_t MailboxCur = dev->MailboxOutPosCur; + + /* Search for a filled mailbox - stop if we have scanned all mailboxes. */ + do { + /* Fetch mailbox from guest memory. */ + Outgoing = aha_mbo(dev, &mb32); + + /* Check the next mailbox. */ + aha_mbo_adv(dev); + } while ((mb32.u.out.ActionCode == MBO_FREE) && (MailboxCur != dev->MailboxOutPosCur)); if (mb32.u.out.ActionCode != MBO_FREE) { /* We got the mailbox, mark it as free in the guest. */ @@ -1247,9 +1262,14 @@ aha_do_mail(aha_t *dev) return 0; } - if (dev->MailboxOutInterrupts) + if (dev->MailboxOutInterrupts) { RaiseIntr(dev, 0, INTR_MBOA | INTR_ANY); + while (dev->Interrupt) { + thread_wait_event(dev->evt, 10); + } + } + if (mb32.u.out.ActionCode == MBO_START) { aha_log("Start Mailbox Command\n"); aha_req_setup(dev, mb32.CCBPointer, &mb32); @@ -1260,9 +1280,6 @@ aha_do_mail(aha_t *dev) aha_log("Invalid action code: %02X\n", mb32.u.out.ActionCode); } - /* Advance to the next mailbox. */ - aha_mbo_adv(dev); - return 1; } @@ -1279,6 +1296,7 @@ aha_event_restart: aha_scan_restart: while (aha_do_mail(dev) != 0) { + thread_wait_event(dev->evt, 10); } if (dev->scan_restart) @@ -1331,9 +1349,11 @@ aha_read(uint16_t port, void *priv) break; } +#if 0 #ifndef WALTJE aha_log("%s: Read Port 0x%02X, Returned Value %02X\n", dev->name, port, ret); +#endif #endif return(ret); diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index 1bc92e3c2..258d8c9ee 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -813,6 +813,10 @@ void scsi_hd_command(uint8_t id, uint8_t *cdb) case GPCMD_REQUEST_SENSE: /* If there's a unit attention condition and there's a buffered not ready, a standalone REQUEST SENSE should forget about the not ready, and report unit attention straight away. */ + if (SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength < cdb[4]) + { + cdb[4] = SCSIDevices[hdc[id].scsi_id][hdc[id].scsi_lun].InitLength; + } scsi_hd_request_sense(id, hdbufferb, cdb[4]); scsi_hd_data_command_finish(id, 18, 18, cdb[4], 0); break;