| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TxLib filesystem functions, Critical-error handling |
|---|
| 34 | // |
|---|
| 35 | |
|---|
| 36 | #include <txlib.h> // TxLib interface |
|---|
| 37 | #include <txtpriv.h> // private interface |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | #if defined (DOS32) // DOS specific local stuff |
|---|
| 41 | |
|---|
| 42 | #define DOS_CRITERR_INT 0x24 // DOS critical error interrupt |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | typedef void (_interrupt _far * TXFSINT) // DOS std interrupt handler |
|---|
| 46 | ( |
|---|
| 47 | void |
|---|
| 48 | ); |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | typedef int (far * TXFS_CRITHAND) // crit-err handler |
|---|
| 52 | ( |
|---|
| 53 | unsigned deverr, // IN device code |
|---|
| 54 | unsigned doserr, // IN dos error code |
|---|
| 55 | unsigned far *hdr // IN device header |
|---|
| 56 | ); |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | // Handle critical errors using a TXWIN MsgBox popup or automatic-FAIL |
|---|
| 60 | int TxCriticalErrorHandler |
|---|
| 61 | ( |
|---|
| 62 | unsigned deverr, // IN device code |
|---|
| 63 | unsigned doserr, // IN dos error code |
|---|
| 64 | unsigned far *hdr // IN device header |
|---|
| 65 | ); |
|---|
| 66 | |
|---|
| 67 | static TXFSINT TxOldHandler = NULL; // old handler, crit errors |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | /*****************************************************************************/ |
|---|
| 72 | // Handle critical errors by presenting an Abort, Retry, Ignore MessageBox |
|---|
| 73 | /*****************************************************************************/ |
|---|
| 74 | int TxCriticalErrorHandler // Tx critical error handler |
|---|
| 75 | ( |
|---|
| 76 | unsigned deverr, // IN device code |
|---|
| 77 | unsigned doserr, // IN dos error code |
|---|
| 78 | unsigned far *hdr // IN device header |
|---|
| 79 | ) |
|---|
| 80 | { |
|---|
| 81 | #if defined (USEWINDOWING) |
|---|
| 82 | if ( (TxAutoFail != 0) // mode set to AutoFail |
|---|
| 83 | #if defined (DUMP) |
|---|
| 84 | || (TxTrLevel != 0) // or tracing is active |
|---|
| 85 | #endif |
|---|
| 86 | ) |
|---|
| 87 | { |
|---|
| 88 | _hardresume( (int) _HARDERR_FAIL); |
|---|
| 89 | } |
|---|
| 90 | else |
|---|
| 91 | { |
|---|
| 92 | TXTM text; |
|---|
| 93 | |
|---|
| 94 | if (deverr & 0x8000) // error on a device ? |
|---|
| 95 | { |
|---|
| 96 | sprintf( text, "Error on device %8.8s - ", ((char *) hdr) + 11); |
|---|
| 97 | } |
|---|
| 98 | else // error on a drive |
|---|
| 99 | { |
|---|
| 100 | sprintf( text, "Error %sing Drive %c: - ", |
|---|
| 101 | (deverr & 0x100) ? "writ" : "read", |
|---|
| 102 | (char) (deverr & 0xff) + 'A'); |
|---|
| 103 | } |
|---|
| 104 | switch (doserr) |
|---|
| 105 | { |
|---|
| 106 | case 0: strcat( text, "Disk is write protected" ); break; |
|---|
| 107 | case 1: strcat( text, "Unknown drive or unit" ); break; |
|---|
| 108 | case 2: strcat( text, "Drive is not ready" ); break; |
|---|
| 109 | case 3: strcat( text, "Unknown device command" ); break; |
|---|
| 110 | case 4: strcat( text, "CRC error" ); break; |
|---|
| 111 | case 5: strcat( text, "Bad request format" ); break; |
|---|
| 112 | case 6: strcat( text, "Seek error" ); break; |
|---|
| 113 | case 7: strcat( text, "Media not recognized" ); break; |
|---|
| 114 | case 8: strcat( text, "Sector not found" ); break; |
|---|
| 115 | case 9: strcat( text, "Printer out of paper" ); break; |
|---|
| 116 | case 10: strcat( text, "General write fault" ); break; |
|---|
| 117 | case 11: strcat( text, "General read fault" ); break; |
|---|
| 118 | default: strcat( text, "General failure" ); break; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | //- Note: handler is instable on FreeDOS (and perhaps others) |
|---|
| 122 | //- probably because it uses too much stack ... |
|---|
| 123 | |
|---|
| 124 | switch (txwMessageBox( TXHWND_DESKTOP, TXHWND_DESKTOP, |
|---|
| 125 | text, "DOS Critical error", |
|---|
| 126 | TXWD_HELPSMSG + TXWD_RETRYFAIL, |
|---|
| 127 | TXMB_RETRYFAIL | TXMB_HELP | |
|---|
| 128 | TXMB_MOVEABLE | TXMB_HCENTER | TXMB_VCENTER) ) |
|---|
| 129 | { |
|---|
| 130 | case TXMBID_RETRY: |
|---|
| 131 | _hardresume( (int) _HARDERR_RETRY); |
|---|
| 132 | break; |
|---|
| 133 | |
|---|
| 134 | case TXMBID_FAIL: // Fail selected, |
|---|
| 135 | default: // or <F4> or <Esc> |
|---|
| 136 | _hardresume( (int) _HARDERR_FAIL); |
|---|
| 137 | break; |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | #else |
|---|
| 141 | _hardresume( (int) _HARDERR_FAIL); |
|---|
| 142 | #endif |
|---|
| 143 | return 0; |
|---|
| 144 | } // end 'TxCriticalErrorHandler' |
|---|
| 145 | /*---------------------------------------------------------------------------*/ |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | /*****************************************************************************/ |
|---|
| 149 | // Get number of physical diskette drives from BIOS |
|---|
| 150 | /*****************************************************************************/ |
|---|
| 151 | USHORT TxPhysDisketteDrives // RET nr of diskette drives |
|---|
| 152 | ( |
|---|
| 153 | void |
|---|
| 154 | ) |
|---|
| 155 | { |
|---|
| 156 | USHORT rc = 0; // function return |
|---|
| 157 | USHORT eq; // equipment list |
|---|
| 158 | |
|---|
| 159 | ENTER(); |
|---|
| 160 | |
|---|
| 161 | eq = TxxBiosWord(TXX_EQUIPMENT); // get the equipment BIOS word |
|---|
| 162 | if (eq & 0x0001) // some drives present |
|---|
| 163 | { |
|---|
| 164 | rc = ((eq & 0x00c0) > 6) +1; |
|---|
| 165 | } |
|---|
| 166 | RETURN (rc); |
|---|
| 167 | } // end 'TxPhysDisketteDrives' |
|---|
| 168 | /*---------------------------------------------------------------------------*/ |
|---|
| 169 | #endif |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | /*****************************************************************************/ |
|---|
| 173 | // Set critical error handling to use an interactive MessageBox (for DOS only) |
|---|
| 174 | /*****************************************************************************/ |
|---|
| 175 | void TxFsSetCritErrHandler |
|---|
| 176 | ( |
|---|
| 177 | BOOL enable // IN MsgBox on CritErr |
|---|
| 178 | ) |
|---|
| 179 | { |
|---|
| 180 | ENTER(); |
|---|
| 181 | #if defined (WIN32) |
|---|
| 182 | //- Note: Windows provides its own popups |
|---|
| 183 | #elif defined (DOS32) |
|---|
| 184 | if (enable) |
|---|
| 185 | { |
|---|
| 186 | if (TxOldHandler == NULL) // not set yet ? |
|---|
| 187 | { |
|---|
| 188 | TxOldHandler = (TXFSINT) _dos_getvect( DOS_CRITERR_INT); |
|---|
| 189 | _harderr((TXFS_CRITHAND) TxCriticalErrorHandler); // install our own handler |
|---|
| 190 | } // using C-runtime stubs |
|---|
| 191 | } |
|---|
| 192 | else |
|---|
| 193 | { |
|---|
| 194 | if (TxOldHandler != NULL) // if set, re-install old handler |
|---|
| 195 | { |
|---|
| 196 | _dos_setvect( DOS_CRITERR_INT, TxOldHandler); |
|---|
| 197 | TxOldHandler = NULL; |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | TRACES(("Old handler:%8.8lx\n", TxOldHandler)); |
|---|
| 201 | #elif defined (LINUX) |
|---|
| 202 | //- to be refined |
|---|
| 203 | #else |
|---|
| 204 | //- Note: OS/2 provides its own popups in PM |
|---|
| 205 | //- Without PM, to be refined |
|---|
| 206 | |
|---|
| 207 | #endif |
|---|
| 208 | VRETURN(); |
|---|
| 209 | } // end 'TxFsSetCritErrHandler' |
|---|
| 210 | /*---------------------------------------------------------------------------*/ |
|---|