home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / db3plsar.zip / TWENTY.ASM < prev    next >
Assembly Source File  |  1986-05-10  |  6KB  |  157 lines

  1.         PAGE  80,132
  2. TITLE   Twenty Files - A dBASE III Plus Callable Module
  3.  
  4.         ; by James Troutman (JT)
  5.         ; Version 1.00
  6.  
  7. COMMENT *
  8.    This is the assembly language source code for a module that can be
  9.    LOADed and CALLed in dBASE III Plus.  It requires DOS 3.xx or greater.
  10.    When assembled (with MASM) it should be LINKed and converted to a binary
  11.    (.BIN) file with EXE2BIN.  It uses what is currently an undocumented
  12.    feature of DOS -- namely the ability to move the file handle table and
  13.    increase its length to allow more than the default 20 open files.
  14.    However, since dBASE itself imposes a limit of 20 files, it does not
  15.    make sense to increase the handle table to more than 25 entries.  This
  16.    allows DOS to have its 5 (STDIN, STDOUT, STDERR, STDAUX, and STDPRN) and
  17.    still leave room for 20 active files in dBASE.
  18.  
  19.    [Actually, the dBASE programmers were clever enough to close the STDAUX
  20.    device (no one uses it, anyway) and use its freed handle for the dBASE
  21.    overlay file.]
  22.  
  23.    A problem with an earlier test version of this module has been fixed.
  24.    It no longer makes any difference how many times the module is LOADed or
  25.    CALLed -- the expanded handle table is no longer stored within the
  26.    module's memory, but in an unused (I hope!) area of dBASE's Program
  27.    Segment Prefix.  Although I have tested this, PLEASE use it
  28.    with caution, and please let me know of any problems (or successes!)
  29.    that you have with it.
  30.  
  31.    SYNTAX:
  32.            LOAD Twenty
  33.            CALL Twenty
  34.  
  35.    ... and get ready to open your 20 files!
  36.  
  37.    Good Luck!
  38.    James Troutman (JT)
  39.    CompuServe PPN 74746,1567
  40.  
  41.    P.S. See the May, 1986 issue of Dr. Dobbs Journal, pp 107-108 for more
  42.    information about how and why this program works.  If I get ambitious, I
  43.    will upload a version with a .DOC file that will explain some of the
  44.    theory of why it works.
  45.  
  46. *
  47.  
  48. DosInt        EQU  21h   ; the standard DOS interrupt number
  49. Unused        EQU  0FFh  ; used by DOD to mark a handle as unused
  50. OurLength     EQU  25    ; the length of OUR table
  51. DefLength     EQU  20    ; the length of THEIR table
  52.  
  53. ; Macro definitions
  54.  
  55. GetDosVersion Macro
  56.         MOV   AH,30h
  57.         INT   DosInt
  58.         EndM
  59.  
  60. ; found these next two macros on the IBM SIG; nifty!
  61.  
  62. Save    Macro   R1,R2,R3,R4,R5,R6,R7,R8,R9,R10
  63.         Irp     Rx,<R1,R2,R3,R4,R5,R6,R7,R8,R9,R10>
  64.         IfNb    <Rx>    ;If this parm not blank
  65.         PUSH    Rx      ;Save the register
  66.         EndIf           ;End IfNb
  67.         EndM            ;End Irp
  68.  
  69. Restore Macro
  70.         Irp     Rx,<R10,R9,R8,R7,R6,R5,R4,R3,R2,R1>
  71.         IfNb    <Rx>    ;If this parm not blank
  72.         POP     Rx      ;Pop the register
  73.         EndIf           ;End IfNb
  74.         EndM            ;End Irp
  75.         EndM            ;End of Restore macro
  76.         EndM            ;End of Save Macro
  77.  
  78. ; the actual code starts here
  79.  
  80. Cseg   SEGMENT PARA PUBLIC 'CODE'
  81.        ASSUME CS:Cseg,DS:Dseg,ES:Dseg,SS:Nothing
  82.  
  83. Twenty  PROC   FAR
  84.         ORG    0
  85.  
  86.         Save    AX,BX,CX,DI,SI,DS,ES   ; not necessary, but a good habit
  87.  
  88.         GetDosVersion     ; Twenty will ONLY work with DOS 3.xx
  89.  
  90.         CMP     AL,3
  91.         JB      Finished   ; return if it's not DOS 3 or greater
  92.         MOV     AH,62h  ; get the PSP of the active process (i.e., dBASE)
  93.         INT     DosInt
  94.         MOV     ES,BX   ; and point our DS and ES at it
  95.         MOV     DS,BX
  96.         CMP     HndlTblSize,20 ; see if the current handle table has
  97.         JNE     Finished       ; exactly 20 entries; if not, exit.
  98.                                ; The assumption is that, if there are
  99.                                ; not exactly 20 entries, someone (maybe us!)
  100.                                ; has already tinkered with the table
  101.  
  102.         CMP     HndlTblOffs,OFFSET DefHndlTbl ; if table is at a different
  103.         JNE     Finished       ; offset, let it be
  104.  
  105.         CMP     HndlTblSeg, BX ; and if the Handle Table has
  106.         JNE     Finished       ; already been moved to another segment,
  107.                                ; we don't want to tinker with it
  108.  
  109.         MOV     AL,Unused    ; fill our new handle table (at OurHndlTbl)
  110.         MOV     CX,OurLength ; with closed (0FFh) handles
  111.         LEA     DI,OurHndlTbl
  112.         CLD
  113. REP     STOSB
  114.  
  115.         MOV     CX,DefLength ; now move the contents of the old table into the new
  116.         LEA     DI,OurHndlTbl
  117.         LEA     SI,DefHndlTbl
  118. REP     MOVSB
  119.         MOV     AX,OurLength   ; now tell DOS that our new table can have 25 entries
  120.         MOV     HndlTblSize,AX
  121.         LEA     AX,OurHndlTbl  ; and what the offset of our new table is
  122.         MOV     HndlTblOffs,AX
  123.  
  124. Finished:
  125.         Restore
  126.         RET              ; return to dBASE
  127.  
  128. Twenty  EndP
  129. Cseg    EndS
  130.  
  131. COMMENT *
  132.   Our DS and ES registers will be set to point to the Program Segment Prefix
  133.   of dBASE.  All the locations that they will reference are defined below
  134. *
  135.  
  136. Dseg    Segment Para Public 'DATA'
  137.  
  138.         ORG   018h
  139. DefHndlTbl  Label  Byte     ; where the handle table is by default
  140.  
  141.         ORG   032h
  142. HndlTblSize  Label  Word    ; size of the handle table
  143.  
  144.         ORG   034h
  145. HndlTblOffs  Label  Word    ; offset of the handle table
  146.  
  147.         ORG   036h
  148. HndlTblSeg   Label  Word    ; segment of the handle table
  149.  
  150.         ORG   05Ch
  151. OurHndlTbl   Label Byte    ; normally the first File Control Block in dBASE's PSP
  152.                            ; currently unused by dBASE
  153. Dseg    EndS
  154.  
  155.         End     TWENTY
  156.  
  157.