diff --git a/mac-cpp-source/tip/tip.cpp b/mac-cpp-source/tip/tip.cpp index 61ec7be..96f7c95 100644 --- a/mac-cpp-source/tip/tip.cpp +++ b/mac-cpp-source/tip/tip.cpp @@ -344,6 +344,13 @@ void TestMonitorWndProc() { // TODO: paint the little speaker icon } +/******************************************************************************* + * APPLICATION TIMER PROC + *******************************************************************************/ +void ApplicationTimerProc() { + HandleDriveChanging(); +} + /******************************************************************************* * UPDATE RUN TIME DISPLAY *******************************************************************************/ @@ -379,6 +386,20 @@ void UpdateRunPhaseDisplay() { ReleaseDC(hTestMonitor); } +/******************************************************************************* + * PREVENT PROGRAM EXIT + *******************************************************************************/ +void PreventProgramExit() { + EnableWindow(hExitButton, false); +} + +/******************************************************************************* + * ALLOW PROGRAM EXIT + *******************************************************************************/ +void AllowProgramExit() { + EnableWindow(hExitButton, true); +} + /******************************************************************************* * ERROR SOUND *******************************************************************************/ diff --git a/mac-cpp-source/tip/tip.h b/mac-cpp-source/tip/tip.h index 56049f1..3eadbc9 100644 --- a/mac-cpp-source/tip/tip.h +++ b/mac-cpp-source/tip/tip.h @@ -60,19 +60,21 @@ long GetTextExtent(const char *str, unsigned long len); void TextOut(int x, int y, Str255 str); void TextOut(int x, int y, const char *str); void TextOutCentered(int x, int y, int w, int h, const char *str); -void SetButtonText(const char *str); +void SetWindowText(int id, const char *str); +void EnableWindow(int id, bool enabled); +void InvalidateRect(int id); void Rectangle(int left, int top, int right, int bottom); void DrawEdge(Rect *qrc, int edge, int grfFlags); +void StartApplicationTimer(); +void StopApplicationTimer(); void PostQuitMessage(); unsigned long GetSystemTime(); -#define hTestMonitor -20, -10 -#define hMainWnd 0, 40 - #define GetDC(h) {GrafPtr oldPort; \ GetPort(&oldPort); \ SetPort(tipWindow); \ - SetOrigin(h); + if(h == hTestMonitor) SetOrigin(-20, -10); \ + if(h == hMainWnd) SetOrigin(0, 40); #define ReleaseDC(h) SetOrigin(0,0); \ SetPort(oldPort);} @@ -162,6 +164,13 @@ extern const char *szBack; extern const char *szNext; extern const char *szQuit; +enum { + hMainWnd, + hTestMonitor, + hTestButton, + hExitButton +}; + #define IDB_BACK 0xFF00 #define IDB_NEXT 0xFF01 #define IDB_QUIT 0xFF02 @@ -189,10 +198,13 @@ void CvrtSecondsToHMSstring(char *szString, long seconds); void UpdateCurrentSector(); void UpdateRunTimeDisplay(); void UpdateRunPhaseDisplay(); +void PreventProgramExit(); +void AllowProgramExit(); void ErrorSound(); void ProcessPendingMessages(); void WndProc(long iMessage, long wParam); void TestMonitorWndProc(); +void ApplicationTimerProc(); void TestButtonClicked(); void GetCommandDetails(char command, char &cmd_flags, char &cmd_length); @@ -205,7 +217,9 @@ long GetNonSenseData(short Device, short DataPage, void *Buffer, short BufLen); long LockCurrentDrive(); long UnlockCurrentDrive(); long SpinUpIomegaCartridge(short Device); -void GetSpareSectorCounts(bool); +long GetSpareSectorCounts(bool); +void HandleDriveChanging(); +void SetCartridgeStatusToEAX(long eax); long PerformRegionTransfer(short XferCmd, void *pBuffer); long TestTheDisk(); long GetElapsedTimeInSeconds(); diff --git a/mac-cpp-source/tip/tip_aspi.cpp b/mac-cpp-source/tip/tip_aspi.cpp index 72fa07b..066b264 100644 --- a/mac-cpp-source/tip/tip_aspi.cpp +++ b/mac-cpp-source/tip/tip_aspi.cpp @@ -78,7 +78,9 @@ enum { szBadResult, szInterrupted, szExplainResult, - szPerfectResult + szPerfectResult, + szNoSpares, + szOutOfSpares }; long CurrentDevice = 0; @@ -331,7 +333,7 @@ long SpinUpIomegaCartridge(short Device) { * into the RichText control, else it sets the number of spares available *******************************************************************************/ -void GetSpareSectorCounts(bool) { +long GetSpareSectorCounts(bool) { DEFECT_LIST_HEADER DefectHeader; long eax = 0, ebx, edx; short ch, cl; @@ -351,10 +353,10 @@ void GetSpareSectorCounts(bool) { char DiskStat[72]; #ifdef NO_EXCESS_READS eax = GetNonSenseData(CurrentDevice, DISK_STATUS_PAGE, DiskStat, 63); - if (eax) return; + if (eax) return eax; #else eax = GetNonSenseData(CurrentDevice, DISK_STATUS_PAGE, DiskStat, sizeof(DiskStat)); - if (!eax) /*goto ListChk;*/ return; + if (!eax) /*goto ListChk;*/ return eax; #endif // -------------------------------------------------------------------------- ch = 0; // clear the DRIVE_A_SUPPORT @@ -378,8 +380,7 @@ void GetSpareSectorCounts(bool) { edx = DWORD_AT(DiskStat[OLD_ZIP_LAST_LBA_OFFSET]); } if(ebx == 0) { - CartridgeStatus = DISK_TEST_FAILURE; - return; + goto NoSpares; } } //--------------------------- @@ -399,24 +400,151 @@ void GetSpareSectorCounts(bool) { FirmErrors += Initial_Side_1_Spares - Side_1_SparesCount; // check to see whether we have ANY spare sectors remaining if(!Side_0_SparesCount && !Side_1_SparesCount) { + NoSpares: CartridgeStatus = DISK_TEST_FAILURE; - return; + eax = szNoSpares; + // if were running give them a different error message + if(TestingPhase) { + eax = szOutOfSpares; + } + goto ErrorExit; } // MLT: The code for removing the ZIP protection has been omitted - return; // return zero since no error + return 0; // return zero since no error } else { // trouble of some sort ... so suppress controls and // show the richedit control for the trouble if (eax == DEFECT_LIST_READ_ERROR) { CartridgeStatus = DISK_Z_TRACK_FAILURE; - return; + ErrorExit: + return -1; } else if (eax == MEDIA_NOT_PRESENT) { CartridgeStatus = MEDIA_NOT_PRESENT; } } + return eax; +} + +/******************************************************************************* + * HANDLE DRIVE CHANGING + *******************************************************************************/ +void HandleDriveChanging() { + // MLT: At the moment, we only handle one drive. + long eax; + char DiskStat[72]; + #ifdef NO_EXCESS_READS + eax = GetNonSenseData(CurrentDevice, DISK_STATUS_PAGE, DiskStat, 63); + if (eax) return; + #else + eax = GetNonSenseData(CurrentDevice, DISK_STATUS_PAGE, DiskStat, sizeof(DiskStat)); + if (!eax) return; + #endif + char status; + if (DiskStat[0] == DISK_STATUS_PAGE) { + status = DiskStat[NEW_DISK_STATUS_OFFSET]; + } else { + status = DiskStat[OLD_DISK_STATUS_OFFSET]; + } + // we're checking the current drive ... make SURE that + // it is *NOT* empty! If it *IS* empty, kill current + if(status == DISK_NOT_PRESENT) { + SetCartridgeStatusToEAX(status); + } + // 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 +//----------------------------------------------------------------------------- + +void SetCartridgeStatusToEAX(long eax) { + long PriorStatus = CartridgeStatus; + CartridgeStatus = eax; + + // Set the text of the "action initiate button" + const char *esi; + switch (CartridgeStatus) { + case DISK_SPUN_DOWN: + // set the button to "Start Disk Spinning" + esi = szPressToSpin; + break; + case DISK_TEST_UNDERWAY: + // set the button to "Stop Testing" + esi = szPressToStop; + break; + case DISK_NOT_PRESENT: + goto DisableActions; + case DISK_AT_SPEED: + eax = GetSpareSectorCounts(true); // update the Cart Condition + if(eax == MEDIA_NOT_PRESENT) { + goto DisableActions; + } + //TroubleFlag = eax; // decide whether we're in trouble + esi = szPressToEject; // presume trouble + if(!eax) { + Initial_Side_0_Spares = Side_0_SparesCount; + Initial_Side_1_Spares = Side_1_SparesCount; + FirmErrors = 0; + // check to see if we have enough spares to start + if(JazDrive) { + if(Side_0_SparesCount < MINIMUM_JAZ_SPARES) + goto InsufficientSpares; + } + else { + if(Side_0_SparesCount < MINIMUM_ZIP_SPARES) { + goto InsufficientSpares; + } + if(Side_1_SparesCount < MINIMUM_ZIP_SPARES) { + InsufficientSpares: + CartridgeStatus = DISK_LOW_SPARES; + esi = szPressToProceed; + goto EnableTestBtn; + } + } + // if no trouble, get ready to start testing... + PrepareToBeginTesting(); + esi = szPressToStart; + } + // The disk *IS* at speed so enable the action button! + EnableTestBtn: + EnableWindow(hTestButton, true); + break; + default: + // set the button to "One Moment Please" + DisableActions: + EnableWindow(hTestButton, false); + esi = szOneMoment; + } + // set the Window's text based upon setting of esi + SetWindowText(hTestButton, esi); + // based upon the TroubleFlag, show them the proper page set + // SetTabErrorMode(TroubleFlag) + // and if CartridgeStatus has changed, refresh the entire panel! + bool ecx = false; + if((PriorStatus == DISK_AT_SPEED) || + (PriorStatus == DISK_SPUN_DOWN)|| + (PriorStatus >= DISK_LOW_SPARES)) { + ecx = !ecx; + } + if((CartridgeStatus == DISK_AT_SPEED) || + (CartridgeStatus >= DISK_LOW_SPARES)) { + ecx = !ecx; + } + if (ecx) { // update the entire panel's data + InvalidateRect(hTestMonitor); + } else { // only paint the new cartridge status + GetDC(hTestMonitor); + PaintCartStatus(); + ReleaseDC(hTestMonitor); + } } /******************************************************************************* @@ -603,9 +731,13 @@ long TestTheDisk() { return -1; } + StopApplicationTimer(); + + PreventProgramExit(); CartridgeStatus = DISK_TEST_UNDERWAY; TestingPhase = TESTING_STARTUP; // inhibit stopping now - SetButtonText(szPressToStop); + SetWindowText(hTestButton, szPressToStop); + InvalidateRect(hTestMonitor); LockCurrentDrive(); // prevent media removal @@ -679,25 +811,29 @@ GetOut: TestingPhase = UNTESTED; UnlockCurrentDrive(); SetErrorRecovery(true, true, false); // reenable Retries & ECC - SetButtonText(szPressToStart); + SetWindowText(hTestButton, szPressToStart); CartridgeStatus = DISK_AT_SPEED; - UpdateRunTimeDisplay(); // added by mlt + AllowProgramExit(); // compute the number of serious troubles - long errors = FirmErrors + HardErrors; + long eax, errors = FirmErrors + HardErrors; if (errors >= BADNESS_THRESHOLD) { - return szBadResult; + eax = szBadResult; } else if (UserInterrupt) { - return szInterrupted; + eax = szInterrupted; } else { // it wasn't interrupted, nor seriously bad, was it perfect? errors += SoftErrors; if(errors) { - return szExplainResult; + eax = szExplainResult; } else { - return szPerfectResult; + eax = szPerfectResult; } } + + InvalidateRect(hTestMonitor); + StartApplicationTimer(); + return eax; } diff --git a/mac-cpp-source/tip/tip_main.cpp b/mac-cpp-source/tip/tip_main.cpp index 6177275..74892a0 100644 --- a/mac-cpp-source/tip/tip_main.cpp +++ b/mac-cpp-source/tip/tip_main.cpp @@ -13,7 +13,9 @@ WindowPtr tipWindow; static int gDone; static bool AllowColor; -static ControlHandle actionBtn = 0; +static bool timerEnabled = true; +static ControlHandle testBtn = 0; +static ControlHandle exitBtn = 0; void NewTipWindow(); void DestroyTipWindow(); @@ -33,6 +35,9 @@ void run_tip(int id) { if (WaitNextEvent(everyEvent, &event, GetCaretTime(), cursorRgn)) { DoEvent(event, &cursorRgn); } + if(timerEnabled) { + ApplicationTimerProc(); + } } while (!gDone); DestroyTipWindow(); @@ -79,17 +84,14 @@ void NewTipWindow() { StrToPascal(title, tipBtns[i].name); ControlHandle h = NewControl(tipWindow, &rect, title, true, 0, 0, 0, 0, tipBtns[i].id); if(tipBtns[i].id == IDB_TEST) { - actionBtn = h; + testBtn = h; + } + if(tipBtns[i].id == IDB_QUIT) { + exitBtn = h; } } ReleaseDC(hMainWnd); - - // Initialize tip - PrepareToBeginTesting(); - GetSpareSectorCounts(false); - FirmErrors = 0; - UpdateRunTimeDisplay(); } void DestroyTipWindow() { @@ -347,18 +349,41 @@ unsigned long GetSystemTime() { } /******************************************************************************* - * SET BUTTON TEXT + * SET WINDOW TEXT *******************************************************************************/ -void SetButtonText(const char *str) { +void SetWindowText(int id, const char *str) { Str255 pStr; StrToPascal(pStr, str); - if(actionBtn) { + if(testBtn && id == hTestButton) { GetDC(hMainWnd); - SetCTitle(actionBtn, pStr); + SetCTitle(testBtn, pStr); ReleaseDC(hMainWnd); } } +/******************************************************************************* + * ENABLE WINDOW + *******************************************************************************/ +void EnableWindow(int id, bool enabled) { + ControlHandle hCntl; + if(id == hTestButton) hCntl = testBtn; + if(id == hExitButton) hCntl = exitBtn; + if(hCntl) { + GetDC(hMainWnd); + HiliteControl(hCntl, enabled ? 0 : 255); + ReleaseDC(hMainWnd); + } +} + +/******************************************************************************* + * INVALIDATE RECT + *******************************************************************************/ +void InvalidateRect(int id) { + GetDC(id); + InvalRect(&qd.thePort->portRect); + ReleaseDC(id); +} + /******************************************************************************* * POST QUIT MESSAGE *******************************************************************************/ @@ -366,6 +391,20 @@ void PostQuitMessage() { gDone = true; } +/******************************************************************************* + * START APPLICATION TIMER + *******************************************************************************/ +void StartApplicationTimer() { + timerEnabled = true; +} + +/******************************************************************************* + * STOP APPLICATION TIMER + *******************************************************************************/ +void StopApplicationTimer() { + timerEnabled = false; +} + /******************************************************************************* * PROCESS PENDING MESSAGES *******************************************************************************/