From a90cdf000f7cd2054d8bd8bca22ffd0576f86d04 Mon Sep 17 00:00:00 2001 From: Marcio T Date: Sun, 5 Dec 2021 20:57:34 -0700 Subject: [PATCH] Many bug fixes and improvements - Fixed incorrect reporting of soft errors as hard errors - Fixed disk change detection - Fixed Jaz handling - Improved status reporting - Improved screen refresh --- mac-cpp-source/macos/text_box.cpp | 4 +-- mac-cpp-source/macos/text_box.h | 2 +- mac-cpp-source/scsi/mac_scsi.cpp | 6 ++-- mac-cpp-source/tip/tip.h | 7 ++-- mac-cpp-source/tip/tip_aspi.cpp | 55 ++++++++++++++++++------------- mac-cpp-source/tip/tip_main.cpp | 3 +- mac-cpp-source/tip/tip_text.cpp | 10 ++++++ 7 files changed, 54 insertions(+), 33 deletions(-) diff --git a/mac-cpp-source/macos/text_box.cpp b/mac-cpp-source/macos/text_box.cpp index a5df93d..fe1eaee 100644 --- a/mac-cpp-source/macos/text_box.cpp +++ b/mac-cpp-source/macos/text_box.cpp @@ -192,7 +192,7 @@ void TBSetScroll( TBHandle tb, short scroll ) { my.lastV = scroll; } -OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec) { +OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec, bool redraw) { short fRefNum; TBSetScroll(tb, 0); @@ -239,7 +239,7 @@ OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec) { Handle hStyle = Get1Resource('styl', 128); if (hStyle) { HNoPurge(hStyle); - TEUseStyleScrap(0, dataSize, (StScrpHandle) hStyle, true, my.tbox); + TEUseStyleScrap(0, dataSize, (StScrpHandle) hStyle, redraw, my.tbox); TECalText(my.tbox); ReleaseResource(hStyle); } diff --git a/mac-cpp-source/macos/text_box.h b/mac-cpp-source/macos/text_box.h index 009d6cc..15aa94a 100644 --- a/mac-cpp-source/macos/text_box.h +++ b/mac-cpp-source/macos/text_box.h @@ -28,4 +28,4 @@ void TBUpdate( TBHandle html ); void TBResize( TBHandle html, const Rect *r ); void TBSetScroll( TBHandle html, short scroll ); bool TBMouseDown( TBHandle html, Point where, WindowPtr whichWindow ); -OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec); +OSErr TBReadSimpleText( TBHandle tb, const FSSpec *docSpec, bool redraw); diff --git a/mac-cpp-source/scsi/mac_scsi.cpp b/mac-cpp-source/scsi/mac_scsi.cpp index 9251e2b..9da94ae 100644 --- a/mac-cpp-source/scsi/mac_scsi.cpp +++ b/mac-cpp-source/scsi/mac_scsi.cpp @@ -5,7 +5,7 @@ #include #include -#define READ_TIMEOUT 60 /* 300 ticks = 5 seconds */ +#define READ_TIMEOUT 180 /* 300 ticks = 5 seconds */ OSErr scsi_reset() { return SCSIReset(); @@ -69,10 +69,10 @@ OSErr scsi_cmd(int id, void *cmd, size_t clen, void *buff, size_t siz, size_t cn } /* Complete the transaction and release the bus */ - short cstat, cmsg; + short cstat = 0, cmsg = 0; OSErr comperr = SCSIComplete( &cstat, &cmsg, READ_TIMEOUT ); if(status) *status = cstat; - if (comperr != noErr) {printf("SCSIComplete Error: %d (status: %d)\n", err, cstat); return err;} + if (comperr != noErr) {printf("SCSIComplete Error: %d (status: %d)\n", comperr, cstat); return err;} return err; } diff --git a/mac-cpp-source/tip/tip.h b/mac-cpp-source/tip/tip.h index 95358f8..4125b03 100644 --- a/mac-cpp-source/tip/tip.h +++ b/mac-cpp-source/tip/tip.h @@ -1,3 +1,4 @@ +#include #include "ctype.h" extern WindowPtr tipWindow; @@ -297,7 +298,7 @@ void TestButtonClicked(); int GetDriveEntryOffset(short Device); void GetCommandDetails(char command, char &cmd_flags, char &cmd_length); -long SCSICommand(short Device, char *lpCmdBlk, void *lpIoBuf, short IoBufLen); +long SCSICommand(short Device, char *lpCmdBlk, void *lpIoBuf, size_t IoBufLen); long EnumerateIomegaDevices(uint8_t *DrivesSkipped); long GetModePage(short Device, short PageToGet, void *pBuffer, short BufLen); long SetModePage(short Device, void *pBuffer); @@ -310,9 +311,9 @@ void UnlockAllMedia(); long SpinUpIomegaCartridge(short Device); void EjectAllMedia(); long GetSpareSectorCounts(char); -uint8_t GetCartridgeStatus(long Device); +uint8_t GetCartridgeStatus(long Device, uint8_t flags); void HandleDriveChanging(); -void SetCartridgeStatusToEAX(long eax); +void SetCartridgeStatusToEAX(long eax, uint8_t flags); void EjectIomegaCartridge(int Device); long PerformRegionTransfer(short XferCmd, void *pBuffer); void TestTheDisk(); diff --git a/mac-cpp-source/tip/tip_aspi.cpp b/mac-cpp-source/tip/tip_aspi.cpp index 217526a..10309d2 100644 --- a/mac-cpp-source/tip/tip_aspi.cpp +++ b/mac-cpp-source/tip/tip_aspi.cpp @@ -190,12 +190,14 @@ void GetCommandDetails(char command, char &cmd_flags, char &cmd_length) { * length to an IoBuffer for the command. It returns the complete * three-byte sense code from the command. *******************************************************************************/ -long SCSICommand(short Device, char *lpCmdBlk, void *lpIoBuf, short IoBufLen) { +long SCSICommand(short Device, char *lpCmdBlk, void *lpIoBuf, size_t IoBufLen) { char cmd_length, cmd_flags, cmd_status; GetCommandDetails(lpCmdBlk[0], cmd_flags, cmd_length); // call the SCSI interface to forward the command to the device OSErr err = scsi_cmd(Device, lpCmdBlk, cmd_length, lpIoBuf, IoBufLen, 0, cmd_flags, &cmd_status); if(err != noErr) { + // else, if it's *NOT* a "Sense Data" error (SS_ERR) + LastError = err | 0x00FFFF00; // [00 FF FF er] return SS_ERR; } if(cmd_status == 0) { @@ -209,7 +211,7 @@ long SCSICommand(short Device, char *lpCmdBlk, void *lpIoBuf, short IoBufLen) { printf("SCSI CHECK CONDITION (KEY %x, ASC %x, ASCQ %x)\n", sense_data.key, sense_data.asc, sense_data.ascq); // okay, we have an SS_ERR condition, let's check the SENSE DATA // assemble [00 ASC ASCQ SenseKey] - long res = (long(sense_data.asc) << 16) | + const long res = (long(sense_data.asc) << 16) | (long(sense_data.ascq) << 8) | (long(sense_data.key) ); if(res == MEDIA_CHANGE_CODE) { @@ -217,7 +219,7 @@ long SCSICommand(short Device, char *lpCmdBlk, void *lpIoBuf, short IoBufLen) { DriveArray[index].flags |= MEDIA_CHANGED; return 0; } - return 0; + return res; } else { // else, if it's *NOT* a "Sense Data" error (SS_ERR) @@ -276,8 +278,7 @@ long EnumerateIomegaDevices(uint8_t *DrivesSkipped) { // On the Mac, we want to ignore drives that have media in them at // program entry, as this means the volume is mounted in Mac OS - JazDrive = isJaz; - const bool driveEmpty = (GetCartridgeStatus(Device) == DISK_NOT_PRESENT); + const bool driveEmpty = (GetCartridgeStatus(Device, flags) == DISK_NOT_PRESENT); if(driveEmpty) { DriveArray[DriveCount].flags = flags; DriveArray[DriveCount].scsi_id = Device; @@ -573,10 +574,11 @@ Rescan: do { // clear media changed status DriveArray[i].flags &= ~MEDIA_CHANGED; - GetCartridgeStatus(scsi_id); + GetCartridgeStatus(scsi_id, DriveArray[i].flags); } while(DriveArray[i].flags & MEDIA_CHANGED); // do it until NO media change! //-------------------------------------------------------------------------- - status = GetCartridgeStatus(scsi_id); + status = GetCartridgeStatus(scsi_id, DriveArray[i].flags); + if (status == DISK_STATUS_UNKNOWN) continue; // added by MLT // if the device we have is NOT the currently selected one if(scsi_id != CurrentDevice) { // if the disk is ANYTHING other than not present ... @@ -592,6 +594,7 @@ Rescan: // then set the current drive ... else if ((DriveArray[i].flags & DISK_EJECTING) == 0) { CurrentDevice = scsi_id; + printf("Selected SCSI ID %ld\n", CurrentDevice); TestingPhase = 0; Selecting = true; //goto Rescan; @@ -607,13 +610,13 @@ Rescan: // it is *NOT* empty! If it *IS* empty, kill current if(status == DISK_NOT_PRESENT) { CurrentDevice = -1; - SetCartridgeStatusToEAX(status); + SetCartridgeStatusToEAX(status, DriveArray[i].flags); } // if it's not already set correctly *and* either // the cart status is one of the pre-test ones, or // the NEW status from the cart is NOT "at speed" ... if((status != CartridgeStatus) && ((CartridgeStatus <= DISK_STALLED) || (status != DISK_AT_SPEED))) { - SetCartridgeStatusToEAX(status); + SetCartridgeStatusToEAX(status, DriveArray[i].flags); } } } @@ -621,18 +624,18 @@ Rescan: if ((CurrentDevice == -1) && (status == DISK_NOT_PRESENT) && (CartridgeStatus != DISK_NOT_PRESENT)) { - SetCartridgeStatusToEAX(status); + SetCartridgeStatusToEAX(status, 0); } } //----------------------------------------------------------------------------- // GET CARTRIDGE STATUS //----------------------------------------------------------------------------- -uint8_t GetCartridgeStatus(long Device) { +uint8_t GetCartridgeStatus(long Device, uint8_t flags) { long eax; char DiskStat[72]; #ifdef NO_EXCESS_READS - eax = GetNonSenseData(Device, DISK_STATUS_PAGE, DiskStat, JazDrive ? sizeof(DiskStat) : 63); + eax = GetNonSenseData(Device, DISK_STATUS_PAGE, DiskStat, (flags & JAZ_DRIVE) ? sizeof(DiskStat) : 63); if (eax) return DISK_STATUS_UNKNOWN; #else eax = GetNonSenseData(Device, DISK_STATUS_PAGE, DiskStat, sizeof(DiskStat)); @@ -649,7 +652,9 @@ uint8_t GetCartridgeStatus(long Device) { // SetCartridgeStatusToEAX //----------------------------------------------------------------------------- -void SetCartridgeStatusToEAX(long eax) { +void SetCartridgeStatusToEAX(long eax, uint8_t flags) { + JazDrive = flags & JAZ_DRIVE; + long PriorStatus = CartridgeStatus; CartridgeStatus = eax; @@ -785,7 +790,7 @@ void BumpErrorCounts(long ErrorCode) { LastError = eax; if (eax == 0x320003 || eax == 0x328F03) CartridgeStatus = DISK_LOW_SPARES; - if (eax & 0xFF == 1) // recovered error + if ((eax & 0xFF) == 1) // recovered error SoftErrors++; else HardErrors++; @@ -953,12 +958,12 @@ void TestTheDisk() { InvalidateRect(hTestMonitor); LockCurrentDrive(); // prevent media removal - GetSpareSectorCounts(false); // update the Cart's Condition UpdateRunTimeDisplay(); // Standard Testing Operation StartingInstant = GetSystemTime(); + long eax; do { ProcessPendingMessages(); @@ -989,7 +994,7 @@ void TestTheDisk() { UpdateRunTimeDisplay(); - long eax = PerformRegionTransfer(SCSI_Cmd_ReadMany, pUserDataBuffer); + eax = PerformRegionTransfer(SCSI_Cmd_ReadMany, pUserDataBuffer); if(eax == 0) { // ------------------------------- @@ -1009,6 +1014,10 @@ void TestTheDisk() { // if we hit the end of the disk ... exit gracefully! goto GetOut; } + else if (eax == SS_ERR) { + // added by MLT, exit on controller errors + goto GetOut; + } if (CartridgeStatus != DISK_TEST_UNDERWAY) { break; } @@ -1028,24 +1037,24 @@ GetOut: AllowProgramExit(); // compute the number of serious troubles - const char *eax; + const char *result; long errors = FirmErrors + HardErrors; if (errors >= BADNESS_THRESHOLD) { - eax = szBadResult; + result = szBadResult; } - else if (UserInterrupt) { - eax = szInterrupted; + else if (UserInterrupt || (eax == SS_ERR)) { + result = szInterrupted; } else { // it wasn't interrupted, nor seriously bad, was it perfect? errors += SoftErrors; if(errors) { - eax = szExplainResult; + result = szExplainResult; } else { - eax = szPerfectResult; + result = szPerfectResult; } } - SetRichEditText(eax); + SetRichEditText(result); InvalidateRect(hTestMonitor); Exit: StartApplicationTimer(); diff --git a/mac-cpp-source/tip/tip_main.cpp b/mac-cpp-source/tip/tip_main.cpp index 8384205..599781e 100644 --- a/mac-cpp-source/tip/tip_main.cpp +++ b/mac-cpp-source/tip/tip_main.cpp @@ -83,6 +83,7 @@ void run_tip() { } } while (!gDone); + EjectAllMedia(); DisposeTipWindow(); DisposeRgn(cursorRgn); } @@ -540,7 +541,7 @@ void SetRichEditText(const char *name) { // Load the text from the file - TBReadSimpleText(richText, &docSpec); + TBReadSimpleText(richText, &docSpec, false); if (name != szRunning && name != szNotRunning) { SetPage(EXPLAIN_RESULTS); diff --git a/mac-cpp-source/tip/tip_text.cpp b/mac-cpp-source/tip/tip_text.cpp index 4d8a4e5..7b626da 100644 --- a/mac-cpp-source/tip/tip_text.cpp +++ b/mac-cpp-source/tip/tip_text.cpp @@ -123,6 +123,16 @@ ErrorTypeList errorTypeList[] = { 0x0088020B, "Side Switch Error", 0x00FFFFE6, "Buffer Too Big", + /***** Mac SCSI Manager Errors *****/ + 0x00FFFF02, "SCSI comm err, timeout", + 0x00FFFF03, "SCSI bus arb, timeout", + 0x00FFFF05, "SCSI phase error", + 0x00FFFF07, "SCSI Manager busy", + 0x00FFFF08, "SCSI sequence error", + 0x00FFFF09, "SCSI blind, timeout", + 0x00FFFF0A, "SCSI compl, phase err", + /***********************************/ + 0xFFFFFFFF, "-- Unknown Error --", 0, 0