home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 10.ddi / TVSRC.ZIP / SYSERR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.6 KB  |  156 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       syserr.cpp                                */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*          TSystemError member functions                     */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #pragma inline
  19.  
  20. #define Uses_TDrawBuffer
  21. #define Uses_TSystemError
  22. #define Uses_TScreen
  23. #include <tv.h>
  24.  
  25. #if !defined( __DOS_H )
  26. #include <Dos.h>
  27. #endif  // __DOS_H
  28.  
  29. #if !defined( __CONIO_H )
  30. #include <conio.h>
  31. #endif  // __CONIO_H
  32.  
  33. #if !defined( __STDIO_H )
  34. #include <stdio.h>
  35. #endif  // __STDIO_H
  36.  
  37. #if !defined( __STRING_H )
  38. #include <String.h>
  39. #endif  // __STRING_H
  40.  
  41. #if !defined( __MATH_H )
  42. #include <Math.h>
  43. #endif  // __MATH_H
  44.  
  45. Boolean near TSystemError::ctrlBreakHit = False;
  46. short ( far * near TSystemError::sysErrorFunc )( short, uchar ) = &TSystemError::sysErr;
  47. ushort near TSystemError::sysColorAttr = 0x4E4F;
  48. ushort near TSystemError::sysMonoAttr = 0x7070;
  49. Boolean near TSystemError::saveCtrlBreak = False;
  50. Boolean near TSystemError::sysErrActive = False;
  51. Boolean near TSystemError::inIDE = False;
  52.  
  53. const SecretWord = 1495;
  54. const productID  =  136;
  55.  
  56. static void checkIDE()
  57. {
  58.     Int11trap trap;
  59.     _BX = SecretWord;
  60.     _AX = SecretWord;
  61.     geninterrupt( 0x12 );
  62. }
  63.  
  64. TSystemError::TSystemError()
  65. {
  66.     inIDE = False;
  67.     checkIDE();
  68.     resume();
  69. }
  70.  
  71. TSystemError::~TSystemError()
  72. {
  73.     suspend();
  74. }
  75.  
  76. #pragma warn -wasc
  77.  
  78. static int getakey()
  79. {
  80.     asm {
  81.         MOV AH,1;
  82.         INT 16h;
  83.         JNZ keyWaiting;
  84.         };
  85.     return 0;
  86.  
  87. keyWaiting:
  88.  
  89.     asm {
  90.         MOV AH,0;
  91.         INT 16h;
  92.         };
  93.     return _AX;
  94. }
  95.  
  96. #pragma warn .wasc
  97.  
  98. ushort TSystemError::selectKey()
  99. {
  100.     ushort crsrType = TScreen::getCursorType();
  101.  
  102.     TScreen::setCursorType( 0x2000 );
  103.  
  104.     while( getakey() )
  105.         ;
  106.     
  107.     int ch = getakey() & 0xFF;
  108.     while( ch != 13 && ch != 27 )
  109.         ch = getakey() & 0xFF;
  110.  
  111.     TScreen::setCursorType( crsrType );
  112.     return ch == 27;
  113. }
  114.  
  115. short TSystemError::sysErr( short errorCode, uchar drive )
  116. {
  117.     ushort c = ( (TScreen::screenMode & 0x00fF) != TDisplay::smMono  ) ?
  118.                                         sysColorAttr : sysMonoAttr;
  119.     char s[ 63 ];
  120.     TDrawBuffer b;
  121.  
  122.     sprintf( s, errorString[ errorCode ], drive + 'a' );
  123.  
  124.     b.moveChar( 0, ' ', c, 80);
  125.     b.moveCStr( 1, s, c);
  126.     b.moveCStr( 79-cstrlen(sRetryOrCancel), sRetryOrCancel, c);
  127.     swapStatusLine(b);
  128.     int res = selectKey();
  129.     swapStatusLine(b);
  130.     return res;
  131. }
  132.  
  133. Int11trap::Int11trap()
  134. {
  135.     oldHandler = getvect( 0x11 );
  136.     setvect( 0x11, &Int11trap::handler );
  137. }
  138.  
  139. Int11trap::~Int11trap()
  140. {
  141.     setvect( 0x11, oldHandler );
  142. }
  143.  
  144. void interrupt (far * near Int11trap::oldHandler)(...) = 0;
  145.  
  146. #pragma warn -eas
  147.  
  148. void interrupt Int11trap::handler(...)
  149. {
  150.     if( _AX == SecretWord && _BX == productID )
  151.         TSystemError::inIDE++;
  152.     oldHandler();
  153. }
  154.  
  155. #pragma warn .eas
  156.