home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / turbopas / bonus507.arc / EXTEND.ARC / EXTEND.PAS < prev   
Pascal/Delphi Source File  |  1988-09-24  |  6KB  |  117 lines

  1. {$I-,O-,R-}
  2.  
  3. unit Extend;
  4.  
  5. { This unit allows a program to open more than the standard DOS maximum of 20
  6.   open files at one time.  You must also be sure to set a FILES=XX statement
  7.   in your CONFIG.SYS file.  This program installs a special interrupt handler
  8.   under DOS 2.x and uses some semi-documented features under DOS 3.x.  This
  9.   unit USES the DOS unit and should be used before any other units other than
  10.   the DOS unit.  This code was based upon earlier work by Randy Forgaard, Bela
  11.   Lubkin and Kim Kokkonen.  See EXTEND.DOC for more information.
  12.  
  13.   Scott Bussinger
  14.   Professional Practice Systems
  15.   110 South 131st Street
  16.   Tacoma, WA  98444
  17.   (206)531-8944
  18.   Compuserve [72247,2671]
  19.  
  20.   Version 3.2 --  9/25/1988 -- Added O- compiler directive to prevent overlaying
  21.                                Moved extended handle table off of heap to support overlay manager
  22.                                Used DosVersion from DOS unit
  23.                                Turned off Range and I/O checking directives
  24.                                Fix exit procedure to chain first rather than last
  25.                                Compiled EXTEND.ASM with TASM
  26.                                Moved USES statement to implementation section
  27.           3.1 --  4/21/1988 -- Removed compiler directives (just uses defaults)
  28.           3.0 -- 10/16/1987 -- Reworked as a UNIT for use with Turbo Pascal 4
  29.                                EXTEND.ASM reworked to be compatible with A86 assembler
  30.                                Added support for DOS 3.3
  31.           2.5 --  3/16/1987 -- EXTEND.ASM worked on by Kim Kokkonen and Brian Foley to work
  32.                                  with Turbo Extender and whittle off a few clock cycles
  33.           2.4 -- 12/16/1986 -- Fixed a problem with DUP under DOS 2.x
  34.                                Now allocates the new handle table on heap
  35.                                  under DOS 3.x (compatible with TDebug+)
  36.           2.3 -- 11/18/1986 -- EXTEND now only affects DOS calls made from
  37.                                  same code segment it was installed from (fixes
  38.                                  problems with EXEC and batch files and already
  39.                                  resident TSR programs
  40.           2.2 -- 10/04/1986 -- Fixed problem with EXEC function destroying all
  41.                                  registers including the stack
  42.                                Changed way that original handle number is kept
  43.                                Permit FORCEDUP to change a standard handle
  44.                                Improve some comments
  45.           2.1 -- 10/02/1986 -- Fixed problem of Turbo assuming the registers
  46.                                  valid after the DOS call
  47.           2.0 -- 10/01/1986 -- Initial release of interrupt handler version
  48.           1.5                  Last version of EXTEND.PAS using explicit
  49.                                  calls to extend files. }
  50.  
  51. interface
  52.  
  53. implementation
  54.  
  55. uses Dos;
  56.  
  57. type HandleArray = array[0..254] of byte;
  58.      HandleArrayPtr = ^HandleArray;
  59.  
  60. var ExitSave: pointer;                           { Previous exit procedure }
  61.     NewHandleTable: array[0..254] of byte;       { New table for handles }
  62.     OldInt21: pointer;                           { Save old INT 21 }
  63.     OldHandleTable: pointer;                     { Pointer to original table }
  64.     OldNumHandles: byte;                         { Original number of handles }
  65.  
  66.  
  67. {$L EXTEND }
  68. procedure ExtendInit; external;                  { Initialize interrupt handler }
  69. procedure ExtendHandler; external;               { Replacement INT 21 handler }
  70.  
  71.  
  72. procedure ExtendHandles;
  73.   { Install the extended handles interrupt.  No files (other than
  74.     standard handles) should be open when unit starts up. }
  75.   begin
  76.   if lo(DosVersion) = 2
  77.    then
  78.     begin
  79.     GetIntVec($21,OldInt21);                     { Install interrupt handler under DOS 2.x }
  80.     SetIntVec($21,@ExtendHandler);
  81.     ExtendInit                                   { Initialize the interrupt handler }
  82.     end
  83.    else
  84.     begin
  85.     fillchar(NewHandleTable,sizeof(NewHandleTable),$FF); { Initialize new handles as unused }
  86.     OldNumHandles := mem[prefixseg:$0032];               { Get old table length }
  87.     OldHandleTable := pointer(ptr(prefixseg,$0034)^);    { Save address of old table }
  88.     mem[prefixseg:$0032] := sizeof(NewHandleTable);      { Set new table length }
  89.     pointer(meml[prefixseg:$0034]) := @NewHandleTable;   { Point to new handle table }
  90.     move(OldHandleTable^,NewHandleTable,OldNumHandles)   { Copy the current handle table to the new handle table }
  91.     end
  92.   end;
  93.  
  94. {$F+}
  95. procedure UnExtendHandles;
  96.   { Uninstall the extended handles interrupt.  All files (other
  97.     than standard handles) should be closed before unit exits. }
  98.   begin
  99.   ExitProc := ExitSave;                          { Chain to next exit routine }
  100.   if lo(DosVersion) = 2
  101.    then
  102.     SetIntVec($21,OldInt21)                      { Restore old INT21 handler }
  103.    else
  104.     begin
  105.     mem[prefixseg:$0032] := OldNumHandles;             { Restore old table length }
  106.     pointer(meml[prefixseg:$0034]) := OldHandleTable;  { Restore original handle table }
  107.     move(NewHandleTable,OldHandleTable^,OldNumHandles) { Now copy the current handle table back }
  108.     end
  109.   end;
  110. {$F-}
  111.  
  112. begin
  113. ExitSave := ExitProc;                            { Remember the previous exit routine }
  114. ExitProc := @UnExtendHandles;                    { Install our exit routine }
  115. ExtendHandles                                    { Install the extended handles }
  116. end.
  117.