home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / turbopas / bonus507.arc / EXTEND.ARC / EXTEND.ASM next >
Assembly Source File  |  1988-09-24  |  9KB  |  225 lines

  1. ;   This is the source code for the replacement INT 21 handler EXTEND.PAS.
  2. ; This code is designed to be compiled by the TASM assembler and linked into
  3. ; the Pascal code.
  4. ;
  5. ;   This code was based upon earlier work by Randy Forgaard, Bela Lubkin and
  6. ; Kim Kokkonen.  The previous implementation was based on using the same
  7. ; technique only not using an interrupt handler.  See EXTEND.DOC for more
  8. ; information.
  9. ;
  10. ;   To compile with TASM:
  11. ;      TASM EXTEND
  12. ;
  13. ; Scott Bussinger
  14. ; Professional Practice Systems
  15. ; 110 South 131st
  16. ; Tacoma, WA  98444
  17. ; (206)531-8944
  18. ; Compuserve [72247,2671]
  19. ;
  20. ; Version 3.2 --  9/25/1988 -- Changed EXTEND.ASM to compile under TASM (needed a few detail changes)
  21. ;         3.0 -- 10/26/1987 -- Reworked as a UNIT for use with Turbo Pascal 4
  22. ;                              EXTEND.ASM reworked to be compatible with A86 assembler
  23. ;         2.5 --  3/16/1987 -- EXTEND.ASM worked on by Kim Kokkonen and Brian Foley to work
  24. ;                                with Turbo Extender and whittle off a few clock cycles
  25. ;         2.4 -- 12/16/1986 -- Fixes problem with DUP function
  26. ;         2.3 -- 11/18/1986 -- EXTEND now only affects DOS calls made from
  27. ;                                same code segment it was installed from (fixes
  28. ;                                problems with EXEC and batch files and already
  29. ;                                resident TSR programs
  30. ;         2.2 -- 10/04/1986 -- Fixed problem with EXEC function destroying all
  31. ;                                registers including the stack
  32. ;                              Changed way that original handle number is kept
  33. ;                              Permit FORCEDUP to change a standard handle
  34. ;                              Improve some comments
  35. ;         2.1 -- 10/02/1986 -- Fixed problem of Turbo assuming registers valid
  36. ;                                after a call to DOS
  37. ;         2.0 -- 10/01/1986 -- Initial release of this inline code
  38. ;
  39.  
  40.         PUBLIC  ExtendInit,ExtendHandler
  41.  
  42. DSEG    SEGMENT WORD PUBLIC
  43.  
  44.         EXTRN   OldInt21:DWORD         ; Address of old INT 21 handler
  45.         EXTRN   PrefixSeg:WORD         ; Segment address of Pascal program's PSP
  46.  
  47. DSEG    ENDS
  48.  
  49.  
  50. CSEG    SEGMENT WORD PUBLIC
  51.  
  52.         ASSUME  CS:CSEG, DS:DSEG
  53.  
  54. ; CS relative Data Storage
  55.  
  56. HandleTable    DD ?                    ; Pointer to standard handle table in PSP
  57. IntVector      DD ?                    ; Provide CS relative storage for old INT 21 vector
  58. SaveFunction   DB ?                    ; Save DOS function number
  59. SaveHandle     DB ?                    ; Save original handle
  60. SaveLastDCB    DB ?                    ; Save original handle slot
  61.  
  62. ; Initialize a few CS relative variables
  63.  
  64. ExtendInit PROC NEAR
  65.         LES   AX,[OldInt21]            ; Get the original INT 21 vector into CS relative storage
  66.         MOV   WORD PTR CS:[IntVector],AX
  67.         MOV   WORD PTR CS:[IntVector+2],ES
  68.  
  69.         MOV   WORD PTR CS:[HandleTable],0018H ; Create a pointer to handle table in PSP
  70.         MOV   AX,[PrefixSeg]
  71.         MOV   WORD PTR CS:[HandleTable+2],AX
  72.         RET
  73.  
  74. ExtendInit ENDP
  75.  
  76.  
  77. ; Main replacement for INT 21 handler
  78.  
  79. ExtendHandler PROC FAR
  80.  
  81.         PUSH  BP                       ; Save BP
  82.  
  83.         MOV   BP,SP                    ; Make sure this call is from our program
  84.         MOV   BP,[BP+4]                ; BP = caller's CS
  85.         CMP   BP,WORD PTR CS:[HandleTable+2] ; Is the caller's CS < our PSP address
  86.         JB    IgnoreExtend
  87.         CMP   BP,DSEG                  ; Is the caller's CS < our data segment
  88.         JAE   IgnoreExtend
  89.  
  90.         POP   BP                       ; Restore BP
  91.  
  92.         CMP   AH,4BH                   ; Skip the rest of this if an EXEC function
  93.         JNE   NotEXEC
  94.  
  95. IgnoreExtend:
  96.         POP   BP                       ; Restore BP
  97.         JMP   CS:[IntVector]           ; Go to original handler
  98.  
  99. NotEXEC:
  100.         CMP   AH,46H                   ; Function $46 is only partially supported
  101.         JNE   ValidFunction
  102.         CMP   CL,4                     ; Permit FORCEDUP if it's a standard handle
  103.         JBE   ValidFunction
  104.  
  105. NotSupported:
  106.         MOV   AX,6                     ; Tell the user it's an invalid handle
  107.         STC                            ; Signal an error
  108.         JMP   ReturnToTurbo
  109.  
  110. ValidFunction:
  111.         PUSH  DS                       ; Set up pointer to handle table
  112.         PUSH  CX
  113.         PUSH  DI
  114.         LDS   DI,CS:[HandleTable]
  115.         MOV   CL,[DI+19]               ; Remember contents of last handle slot
  116.         MOV   CS:[SaveLastDCB],CL
  117.         MOV   CS:[SaveFunction],AH     ; Save function code for later
  118.  
  119.         CMP   AH,3EH                   ; Check for DOS functions that pass a handle
  120.         JB    CallOldInt21
  121.  
  122.         CMP   AH,40H                   ; Convert functions $3E..$40 (Close,Read,Write)
  123.         JBE   ConvertDCB
  124.  
  125.         CMP   AH,42H                   ; Convert function $42 (Seek)
  126.         JE    ConvertDCB
  127.  
  128.         CMP   AH,44H                   ; Convert function $44..$46 (IOCTL,DUP,FORCEDUP)
  129.         JB    CallOldInt21
  130.  
  131.         CMP   AH,46H
  132.         JBE   ConvertDCB
  133.  
  134.         CMP   AH,57H                   ; Convert function $57 (File time/date)
  135.         JE    ConvertDCB
  136.  
  137.         CMP   AH,5CH                   ; Convert function $5C (Lock/Unlock)
  138.         JE    ConvertDCB
  139.  
  140.         CMP   AH,68H                   ; Convert function $68 (Commit File)
  141.         JNE   CallOldInt21
  142.  
  143. ConvertDCB:
  144.         MOV   CS:[SaveHandle],BL       ; Save the original handle
  145.         CMP   BL,4                     ; Check for output to standard handle
  146.         JBE   CallOldInt21             ; Let calls with standard handle pass through
  147.  
  148.         SUB   BL,5                     ; Account for an offset of 5 in DCB number
  149.         MOV   [DI+19],BL               ; Stuff DCB into last handle slot
  150.         MOV   BL,19                    ; Use number of last handle slot
  151.  
  152. CallOldInt21:
  153.         POP   DI                       ; Restore the registers
  154.         POP   CX
  155.         POP   DS
  156.         PUSHF
  157.         CALL  CS:[IntVector]           ; Fake an INT21 to original handler
  158.         STI                            ; Allow interrupts
  159.  
  160.         PUSH  DS                       ; Setup pointer to handle table
  161.         PUSH  DI
  162.         PUSH  BX
  163.         LDS   DI,CS:[HandleTable]      ; Check if INT handler returned an error
  164.         JC    Done                     ; Possibly needs to goto CheckForHandle??
  165.  
  166.         MOV   BL,CS:[SaveFunction]     ; Check for return handles
  167.         CMP   BL,3CH                   ; Convert function $3C (Create)
  168.         JE    ConvertHandle
  169.         CMP   BL,3DH                   ; Convert function $3D (Open)
  170.         JE    ConvertHandle
  171.         CMP   BL,45H                   ; Convert function $45 (Dup)
  172.         JE    ConvertHandle
  173.         CMP   BL,5AH                   ; Convert function $5A (Create unique)
  174.         JE    ConvertHandle
  175.         CMP   BL,5BH                   ; Convert function $5B (Create new)
  176.         JE    ConvertHandle
  177.         CMP   BL,68H                   ; Convert function $68 (Commit file)
  178.         JNE   CheckForHandle
  179.  
  180. ConvertHandle:
  181.         MOV   BX,AX                    ; Use handle as offset into handle table
  182.         MOV   AL,0FFH                  ; Show the handle as unused
  183.         XCHG  AL,[DI+BX]               ; Return DCB as handle number
  184.         ADD   AL,5                     ; Use offset of 5 to avoid standard handles
  185.  
  186. CheckForHandle:
  187.         MOV   BL,CS:[SaveFunction]     ; Check for handles left in registers
  188.         CMP   BL,3FH                   ; Convert function $3F (Read)
  189.         JE    RestoreHandle
  190.         CMP   BL,40H                   ; Convert function $40 (Write)
  191.         JE    RestoreHandle
  192.         CMP   BL,42H                   ; Convert function $42 (Seek)
  193.         JE    RestoreHandle
  194.         CMP   BL,44H                   ; Convert function $44..$46 (IOCTL,DUP,FORCEDUP)
  195.         JB    Success
  196.         CMP   BL,46H
  197.         JBE   RestoreHandle
  198.         CMP   BL,57H                   ; Convert function $57 (File time/date)
  199.         JE    RestoreHandle
  200.         CMP   BL,5CH                   ; Convert function $5C (Lock/Unlock)
  201.         JNE   Success
  202.  
  203. RestoreHandle:
  204.         POP   BX
  205.         MOV   BL,CS:[SaveHandle]       ; Restore original handle in case calling
  206.         PUSH  BX                       ; program assumes BX unchanged
  207.  
  208. Success:
  209.         CLC                            ; Everything is fine so clear error flag
  210.  
  211. Done:
  212.         MOV   BL,CS:[SaveLastDCB]      ; Restore contents of last handle slot
  213.         MOV   [DI+19],BL
  214.         POP   BX
  215.         POP   DI
  216.         POP   DS
  217. ReturnToTurbo:
  218.         RET   2                        ; Return to the calling program and cleanup stack
  219.  
  220. ExtendHandler ENDP
  221.  
  222. CSEG    ENDS
  223.  
  224.         END
  225.