home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / EXTEND32.ZIP / EXTEND.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-10-05  |  7.0 KB  |  152 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, some semi-documented features under DOS 3.x prior to
  9.   DOS 3.3 and the DOS extend files call under DOS 3.3 or later.  This
  10.   unit USES the DOS unit and should be used before any other units other than
  11.   the DOS unit.  This code was based upon earlier work by Randy Forgaard, Bela
  12.   Lubkin and Kim Kokkonen.  See EXTEND.DOC for more information.
  13.  
  14.   Scott Bussinger
  15.   Professional Practice Systems
  16.   110 South 131st Street
  17.   Tacoma, WA  98444
  18.   (206)531-8944
  19.   Compuserve [72247,2671] }
  20.  
  21. { ** Revision History **
  22.   1 EXTEND.PAS 9-Mar-89,`SCOTT' First version using TLIB -- Based on 3.2
  23.   2 EXTEND.PAS 15-Sep-89,`SCOTT'
  24.            Added SwapVectorsExtend procedure
  25.            Put handle table into DOS memory
  26.            Use DOS 3.3 extended handles function when available
  27.   3 EXTEND.PAS 2-Oct-89,`SCOTT'
  28.            Fixed bug in determining the DOS version
  29.   4 EXTEND.PAS 5-Oct-89,`SCOTT'
  30.            Yet another bug in the DosVersion detection
  31.   ** Revision History ** }
  32.  
  33. { Version 3.2 --  9/25/1988 -- Added O- compiler directive to prevent overlaying
  34.                                Moved extended handle table off of heap to support overlay manager
  35.                                Used DosVersion from DOS unit
  36.                                Turned off Range and I/O checking directives
  37.                                Fix exit procedure to chain first rather than last
  38.                                Compiled EXTEND.ASM with TASM
  39.                                Moved USES statement to implementation section
  40.           3.1 --  4/21/1988 -- Removed compiler directives (just uses defaults)
  41.           3.0 -- 10/16/1987 -- Reworked as a UNIT for use with Turbo Pascal 4
  42.                                EXTEND.ASM reworked to be compatible with A86 assembler
  43.                                Added support for DOS 3.3
  44.           2.5 --  3/16/1987 -- EXTEND.ASM worked on by Kim Kokkonen and Brian Foley to work
  45.                                  with Turbo Extender and whittle off a few clock cycles
  46.           2.4 -- 12/16/1986 -- Fixed a problem with DUP under DOS 2.x
  47.                                Now allocates the new handle table on heap
  48.                                  under DOS 3.x (compatible with TDebug+)
  49.           2.3 -- 11/18/1986 -- EXTEND now only affects DOS calls made from
  50.                                  same code segment it was installed from (fixes
  51.                                  problems with EXEC and batch files and already
  52.                                  resident TSR programs
  53.           2.2 -- 10/04/1986 -- Fixed problem with EXEC function destroying all
  54.                                  registers including the stack
  55.                                Changed way that original handle number is kept
  56.                                Permit FORCEDUP to change a standard handle
  57.                                Improve some comments
  58.           2.1 -- 10/02/1986 -- Fixed problem of Turbo assuming the registers
  59.                                  valid after the DOS call
  60.           2.0 -- 10/01/1986 -- Initial release of interrupt handler version
  61.           1.5                  Last version of EXTEND.PAS using explicit
  62.                                  calls to extend files. }
  63.  
  64. interface
  65.  
  66. procedure SwapVectorsExtend;
  67.   { Swap interrupt vectors taken over by Extend unit with system vectors }
  68.  
  69. implementation
  70.  
  71. uses Dos,Shrink;
  72.  
  73. type HandleArray = array[0..254] of byte;        { Room for 255 handles }
  74.      HandleArrayPtr = ^HandleArray;
  75.  
  76. var DosMemory: pointer;                          { Pointer to memory gained from DOS }
  77.     ExitSave: pointer;                           { Previous exit procedure }
  78.     OldInt21: pointer;                           { Save old INT 21 }
  79.     OldHandleTable: HandleArrayPtr;              { Pointer to original table }
  80.     OldNumHandles: byte;                         { Original number of handles }
  81.  
  82. {$L EXTEND }
  83. procedure ExtendInit; external;                  { Initialize interrupt handler }
  84. procedure ExtendHandler; external;               { Replacement INT 21 handler }
  85.  
  86. procedure SwapVectorsExtend;
  87.   { Swap interrupt vectors taken over by Extend unit with system vectors }
  88.   var TempVector: pointer;
  89.   begin
  90.   if lo(DosVersion) = 2 then
  91.     begin
  92.     GetIntVec($21,TempVector);                   { Swap the INT 21 vectors }
  93.     SetIntVec($21,OldInt21);
  94.     OldInt21 := TempVector
  95.     end
  96.   end;
  97.  
  98. procedure ExtendHandles;
  99.   { Install the extended handles interrupt.  No files (other than
  100.     standard handles) should be open when unit starts up. }
  101.   var Regs: Registers;
  102.   begin
  103.   if lo(DosVersion) = 2
  104.    then
  105.     begin
  106.     GetIntVec($21,OldInt21);                     { Install interrupt handler under DOS 2.x }
  107.     ExtendInit;                                  { Initialize the interrupt handler }
  108.     SetIntVec($21,@ExtendHandler)
  109.     end
  110.    else
  111.     begin
  112.     DosNewShrink(DosMemory,sizeof(HandleArray));
  113.     if DosMemory <> nil then                     { There wasn't enough memory for a handle table, so just quit }
  114.       if (lo(DosVersion)>=4) or (hi(DosVersion)>=30) { Does this DOS version support the handles call? }
  115.        then
  116.         begin
  117.         DosDispose(DosMemory);                   { Free up the DOS memory block so that the next function will succeed }
  118.         with Regs do
  119.           begin
  120.           AH := $67;                             { Tell DOS to allow us 255 handles }
  121.           BX := 255;                             { KEEP THIS NUMBER ODD TO AVOID BUG IN SOME VERSIONS OF DOS 3.3!! }
  122.           MsDos(Regs)
  123.           end
  124.         end
  125.        else
  126.         begin
  127.         fillchar(DosMemory^,sizeof(HandleArray),$FF);     { Initialize new handles as unused }
  128.         OldNumHandles := mem[prefixseg:$0032];            { Get old table length }
  129.         OldHandleTable := pointer(ptr(prefixseg,$0034)^); { Save address of old table }
  130.         mem[prefixseg:$0032] := sizeof(HandleArray);      { Set new table length }
  131.         pointer(meml[prefixseg:$0034]) := DosMemory;      { Point to new handle table }
  132.         move(OldHandleTable^,DosMemory^,OldNumHandles)    { Copy the current handle table to the new handle table }
  133.         end
  134.     end
  135.   end;
  136.  
  137. {$F+}
  138. procedure ExitHandler;
  139. {$F-}
  140.   { Uninstall the extended handles interrupt.  All files (other
  141.     than standard handles) should be closed before unit exits. }
  142.   begin
  143.   ExitProc := ExitSave;                          { Chain to next exit routine }
  144.   SwapVectorsExtend                              { Restore original interrupt vectors }
  145.   end;
  146.  
  147. begin
  148. ExitSave := ExitProc;                            { Remember the previous exit routine }
  149. ExitProc := @ExitHandler;                        { Install our exit routine }
  150. ExtendHandles                                    { Enable the extra handles }
  151. end.
  152.