home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_BAS / PBFIXES2.ZIP / CTRLC.BAS next >
BASIC Source File  |  1994-01-14  |  3KB  |  86 lines

  1. $COMPILE UNIT
  2. $DEBUG PATH OFF
  3. $DEBUG UNIT OFF
  4. DECLARE FUNCTION SetOnExit%(BYVAL CodePntr???)
  5. SHARED DOSadd???, DOSByte?, BIOSadd???, BIOSByte?
  6. SHARED Cbrk?, CEHSeg??
  7.  
  8. CbrkRestore:
  9. ! Mov  dl,Cbrk?           ;dl = original BREAK flag state
  10. ! Mov  ax,&h3301          ;tell dos to reset it
  11. ! Int  &h21
  12.  
  13. ! Les  bx,BIOSadd???      ;es:[bx] points to Ctrl-Break handler now
  14. ! Mov  al,BIOSByte?       ;put the original byte into al
  15. ! Cli                     ;shut off interrupts momentarily
  16. ! Mov  es:[bx],al         ;restore the byte to it's original value
  17. ! Sti                     ;allow interrupts again
  18.  
  19. ! Les  bx,DOSadd???       ;es:[bx] points to Ctrl-C handler now
  20. ! Mov  al,DOSByte?        ;put the original byte into al
  21. ! Cli                     ;shut off interrupts momentarily
  22. ! Mov  es:[bx],al         ;restore the byte to it's original value
  23. ! Sti                     ;allow interrupts again
  24. ! RetF
  25.  
  26. FUNCTION CbrkDisable% PUBLIC
  27.   LOCAL temp??, result%
  28.  
  29. ! Mov  ax,&h3523          ;Get the Ctrl-C vector
  30. ! Int  &h21
  31. ! Mov  DOSadd???[+2],es   ;Save the segment
  32. ! Mov  DOSadd???,bx       ;and the offset
  33. ! Mov  al,&hCF            ;we want al set to &hCF for the move
  34. ! Cli                     ;turn off interrupts while we do this
  35. ! Xchg es:[bx],al         ;poke &hCF (Iret) into the interrupt routine
  36.                           'and copy the current byte into al
  37. ! Mov  DOSByte?,al        ;now save it where we can find it later
  38. ! Sti                     ;turn interrupts back on
  39.  
  40. ! Mov  ax,&h351B          ;Repeat the procedure for Ctrl-Break
  41. ! Int  &h21
  42. ! Mov  BIOSadd???[+2],es  
  43. ! Mov  BIOSadd???,bx
  44. ! Mov  al,&hCF
  45. ! Cli
  46. ! Xchg es:[bx],al
  47. ! Mov  BIOSByte?,al
  48. ! Sti
  49.  
  50. ! Mov  ax,&h3300          ;Get the DOS BREAK flag state
  51. ! Int  &h21
  52. ! Mov  Cbrk?,dl           ;save it so we can restore it later
  53. ! Mov  ax,&h3301          ;al = 1 for set flag function
  54. ! Xor  dl,dl              ;dl = 0 tells DOS to stop checking during disk IO
  55. ! Int  &h21
  56.  
  57. ! Mov  ax,&h3524          ;Get the Critical error handler vector
  58. ! Int  &h21
  59. ! Mov  CEHSeg??,es        ;Save the segment for use with ClrErDev
  60.  
  61.                           'emulate PowerBASICs CALL
  62. ! Push cs                 ;push the segment address on the stack first
  63.   temp?? = CODEPTR(CbrkRestore)
  64. ! Push temp??             ;and then the offset
  65. ! Call SetOnExit          ;PowerBASIC takes care of the rest
  66. ! Mov  result%,ax
  67. CbrkDisable% = result%
  68. END FUNCTION
  69.  
  70. FUNCTION CritErr% PUBLIC
  71. LOCAL t%                  'PB sets t% = 0 for us
  72. ! Mov  ax,CEHSeg??        ;set es = PB's critical error segment
  73. ! Mov  es,ax              ;using ax
  74. ! Mov  bx,&h00AE          ;es:[bx] -> PB's critical error flag
  75. ! Mov  ax,es:[bx]         ;copy its value into ax
  76. ! Or   al,al
  77. ! Jz   L1                 ;if the flag = 0 we are done
  78. ! Add  al,&h12            ;else add 12h to match Int 21h function 59h
  79. ! Mov  es:[bx+02],ax      ;copy the value into PB's ERDEV location
  80. ! Xor  al,al              ;clear ax (ah already equals 0)
  81. ! Mov  es:[bx],ax         ;clear the flag word for next CALL INTERRUPT
  82. ! Dec  t%                 ;return t% = -1 (TRUE)
  83. L1:
  84. CritErr% = t%
  85. END FUNCTION
  86.