home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Pascal / Samples / VFORMAT.ARJ / AUXDOS.PAS next >
Encoding:
Pascal/Delphi Source File  |  1991-11-04  |  3.0 KB  |  109 lines

  1. {$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,R-,S-,V-,X+}
  2.  
  3. UNIT AuxDos;
  4.  
  5. {Auxiliary DOS-Interface-Routines}
  6. {Written by Christoph H. Hochstätter}
  7. {FixDisk added by Alexander V. Sessa}
  8. {Written in Turbo-Pascal 6.0}
  9.  
  10. INTERFACE
  11.  
  12. USES dos;
  13.  
  14. {File open mode and sharing constants}
  15.  
  16. CONST OReadOnly = 0;
  17.   OWriteOnly    = 1;
  18.   OReadWrite    = 2;
  19.   OCompatibility= $00;
  20.   ODenyAll      = $10;
  21.   ODenyWrite    = $20;
  22.   ODenyRead     = $30;
  23.   ODenyNone     = $40;
  24.   ONoInheritance= $80;
  25.  
  26. {DOS-File-Handles}
  27.  
  28. CONST StdNulHandle = 0;
  29.   StdOutHandle     = 1;
  30.   StdErrHandle     = 2;
  31.  
  32. VAR StdErr        : Text;                       {Define a file variable for standard error output}
  33.     old1B         : Pointer;                                       {Save old Ctrl-Break-Interrupt}
  34.     old23         : Pointer;                                     {Save Old abnormal End Procedure}
  35.  
  36. CONST ExitRequest : Boolean   = FALSE;                                       {Ctrl-Break pressed?}
  37.  
  38. PROCEDURE CtrlBreak;
  39. PROCEDURE EndProgram(x: Byte;s: String);
  40. PROCEDURE DefExitProc;
  41. PROCEDURE IgnoreInt;
  42.  
  43. IMPLEMENTATION
  44.  
  45.   PROCEDURE CtrlBreak; Assembler;                     {Don't invoke directly (or go to neverland)}
  46.   ASM
  47.     push    ds                 {Save DS}
  48.     push    ax                 {Save AX, because it is interrupt}
  49.     mov     ax,seg @data       {Get data segment in AX}
  50.     mov     ds,ax              {Put it in DS}
  51.     pop     ax                 {Restore AX}
  52.     mov     ExitRequest,True   {Set ExitRequest}
  53.     pop     ds                 {Restore DS}
  54.     iret                       {Exit}
  55.   END;
  56.  
  57.   PROCEDURE IgnoreInt; Assembler;
  58.   ASM
  59.     iret
  60.   END;
  61.  
  62.   PROCEDURE FixDisk; Assembler;
  63.   ASM
  64.     push    ds
  65.     xor     ax,ax
  66.     mov     ds,ax
  67.     mov     si,1
  68.   @1:
  69.     mov     al,ds:[$490+si]
  70.     and     al,$C0
  71.     cmp     al,$40
  72.     jne     @2
  73.     mov     byte ptr ds:[$490+si],$61
  74.   @2:
  75.      dec     si
  76.      jz      @1
  77.      pop     ds
  78.   END;
  79.  
  80.   PROCEDURE EndProgram;
  81.   BEGIN
  82.     IF ExitRequest THEN BEGIN
  83.       WriteLn(stderr,#13#10,s);
  84.       Halt(x);
  85.     END;
  86.   END;
  87.  
  88.   PROCEDURE DefExitProc;                                                  {Default Exit-Procedure}
  89.   BEGIN
  90.     SetIntVec($1B,old1B);                                       {Restore old Ctrl-Break-Procedure}
  91.     SetIntVec($23,old23);                                   {Restore old abnormal abort Procedure}
  92.     FixDisk;
  93.     ExitProc:=NIL;
  94.   END;
  95.  
  96. BEGIN
  97.   move(Output,stderr,SizeOf(stderr));           {Copy Standard-Output File to Standard-Error File}
  98.   TextRec(stderr).Handle:=StdErrHandle;                      {Standard-Error is DOS-File-Handle 2}
  99.   TextRec(stderr).BufPtr:=@TextRec(stderr).Buffer;                            {set our own Buffer}
  100.   GetIntVec($1B,old1B);                                            {Save old Ctrl-Break interrupt}
  101.   GetIntVec($13,old23);
  102.   ExitProc:=@DefExitProc;                             {Restore Ctrl-Break-Interrupt, when exiting}
  103. END.
  104.  
  105.  
  106.  
  107.  
  108.  
  109.