home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / teseract / source / tsutil.asm < prev   
Encoding:
Assembly Source File  |  1988-10-02  |  13.3 KB  |  501 lines

  1. IFNDEF TP4
  2.         PAGE 60,132
  3. ;----------------------------------------------------------------------------
  4. SUBTTL  TesSeRact Revision Level 1
  5. ;-----------------------------------------------------------------------------
  6. ;   TesSeRact(tm) -- A Library of Routines for Creating Ram-Resident (TSR)
  7. ;                    programs for the IBM PC and compatible Personal
  8. ;                    Computers.
  9. ;
  10. ;The software, documentation and source code are: 
  11. ;       Copyright (C) 1986, 1987, 1988 Tesseract Development Team
  12. ;       All Rights Reserved 
  13. ;       c/o Chip Rabinowitz
  14. ;       Innovative Data Concepts
  15. ;       2084 Woodlawn Avenue
  16. ;       Glenside, PA 19038
  17. ;       1-215-884-3373
  18. ;
  19. ;-----------------------------------------------------------------------------
  20. ;   This product supports the TesSeRact Standard for Ram-Resident Program 
  21. ;   Communication.  For information about TesSeRact, contact the TesSeRact 
  22. ;   Development Team at:
  23. ;       Compuserve:    70731,20
  24. ;       MCIMAIL:       315-5415
  25. ;   This MCIMAIL Account has been provided to the TesSeRact Development
  26. ;   Team by Borland International, Inc.  The TesSeRact Development Team
  27. ;   is in no way associated with Borland International, Inc.
  28. ;-----------------------------------------------------------------------------
  29.  
  30. INCLUDE MIXED.INC
  31. INCLUDE TESS.INC
  32. IFDEF   ALLPUBLIC
  33. INCLUDE tsutil.pub
  34. ENDIF
  35.  
  36. .MODEL small
  37.  
  38. EXTRN TSRCLEANUP:FAR
  39.  
  40. .CODE
  41.  
  42. EXTRN TESS_GLOBALS:byte
  43. EXTRN TESS_USERPARMS:byte
  44.  
  45. PUBLIC _TESSRESTOREINTS, _TESSSETUPINTS, _TESSSETPSP, _TESSGETPSP, _TESSRELEASETSR 
  46.  
  47. ENDIF
  48.  
  49. ;
  50. ; ***************************************************************************
  51. ;       Function to restore interrupts.
  52. ;
  53. ;       If AX=0, this function does popup-interrupts (1B, 23 and 24)
  54. ;       If AX=anything else, this function does initial interrupts
  55. ;
  56. _TESSRESTOREINTS proc near
  57.         ASSUMEDS
  58.  
  59.         push    ds
  60.         push    ax
  61.         push    dx
  62.         push    si
  63.         push    di
  64.         push    cx
  65.         mov     di,7                    ;7 bytes per structure
  66.  
  67.         or      ax,ax
  68.         jnz     restore1
  69.  
  70.         mov     cx,NUMINTS_2            ;three times through
  71.         mov     si,offset OLDINT1B      ;start at table beginning
  72.         jmp     short restore_loop
  73. restore1:
  74.         mov     cx,NUMINTS_1            ;eleven interrupts!
  75.         mov     si,offset OLDINT8       ;top of table
  76.  
  77. restore_loop:
  78.         push    di                      ;save structure size
  79.         push    ds
  80.         mov     al,4[si]                ;interrupt number
  81.         mov     dx,[si]                 ;IP of interrupt vector
  82.         mov     ds,2[si]                ;CS of interrupt vector
  83.         mov     ah,25h                  ;set interrupt vector function
  84.         int     21h
  85.         pop     ds
  86.         xor     ax,ax                   ;clear this entry from table
  87.         mov     [si],ax                 ;so it shows not used
  88.         mov     2[si],ax
  89.         pop     di                      ;get size back
  90.         add     si,di                   ;do it again
  91.         loop    restore_loop
  92.  
  93.         pop     cx
  94.         pop     di
  95.         pop     si
  96.         pop     dx
  97.         pop     ax
  98.         pop     ds
  99.         ret
  100. _TESSRESTOREINTS endp
  101. ;
  102. ; ***************************************************************************
  103. ;       Function to set interrupts.
  104. ;
  105. ;       If AX=0, this function does popup-interrupts (1B, 23 and 24)
  106. ;       If AX=anything else, this function does initial interrupts
  107. ;
  108. _TESSSETUPINTS proc near
  109.         ASSUMEDS
  110.         push    es
  111.         push    ax
  112.         push    bx
  113.         push    dx
  114.         push    di
  115.         push    si
  116.         push    cx
  117.         mov     di,7                    ;7 bytes per structure
  118.  
  119.         or      ax,ax
  120.         jnz     setup1
  121.  
  122.         mov     cx,NUMINTS_2            ;three times through
  123.         mov     si,offset OLDINT1B      ;start at table beginning
  124.         jmp     short setup_loop
  125. setup1:
  126.         mov     cx,NUMINTS_1            ;eleven interrupts!
  127.         mov     si,offset OLDINT8       ;top of table
  128.  
  129. setup_loop:
  130.         push    di                      ;save structure size
  131.  
  132.         mov     ax,[si]                 ;check for value
  133.         or      ax,ax                   ;if not zero, next one
  134.         jnz     setup2
  135.         mov     al,4[si]                ;interrupt number
  136.         mov     ah,35h                  ;get interrupt vector function
  137.  
  138.         int     21h
  139.         mov     [si],bx                 ;save IP
  140.         mov     2[si],es                ;save CS
  141.  
  142.         mov     al,4[si]                ;interrupt number
  143.                                         ;DS already contains correct segment
  144.         mov     dx,5[si]                ;IP of interrupt vector
  145.         mov     ah,25h                  ;set interrupt vector function
  146.         int     21h
  147.  
  148. setup2:
  149.         pop     di                      ;get size back
  150.         add     si,di                   ;do it again
  151.         loop    setup_loop
  152. ex_set:
  153.         pop     cx
  154.         pop     si
  155.         pop     di
  156.         pop     dx
  157.         pop     bx
  158.         pop     ax
  159.         pop     es
  160.         ret
  161. _TESSSETUPINTS endp
  162.  
  163. ;
  164. ; ***************************************************************************
  165. ;       Function to test interrupts.
  166. ;
  167. ;       This functionis called to see if all our interrupts are still at
  168. ;        the top of the interrupt chain.  If any of our interrupts are not
  169. ;        at the top of the interrupt chain, we return -1.  Zero (0) is 
  170. ;        returned if it safe to unload.
  171. ;
  172. test_restore proc near
  173.  
  174.         ASSUMEDS
  175.  
  176.         push    ds
  177.         push    es
  178.         push    dx
  179.         push    si
  180.         push    di
  181.         push    cx
  182.         push    bx
  183.         mov     di,7                    ;7 bytes per structure
  184.  
  185.  
  186. t_restore1:
  187.         mov     cx,NUMINTS_1            ;eleven interrupts!
  188.         mov     si,offset OLDINT8       ;top of table
  189.  
  190. restore_test:
  191.         mov     al,4[si]
  192.         mov     ah,35h
  193.         int     21h
  194.  
  195.         mov     ax,es
  196.         mov     bx,cs
  197.         cmp     ax,bx
  198.         jne     not_us
  199.  
  200.         add     si,di                   ;do it again
  201.         loop    restore_test
  202.  
  203.         xor     ax,ax
  204.         jmp     short test_out
  205.  
  206. not_us:
  207.         xor     ax,ax
  208.         dec     ax
  209.  
  210. test_out:
  211.         pop     bx
  212.         pop     cx
  213.         pop     di
  214.         pop     si
  215.         pop     dx
  216.         pop     es
  217.         pop     ds
  218.         ret
  219.  
  220. test_restore endp
  221.  
  222. ;
  223. ; ***************************************************************************
  224. ;       S E T   P S P
  225. ;
  226. ;       A bug in DOS 2.0, 2.1, causes DOS to clobber its standard stack
  227. ;       Then the PSP get/set functions are issued at the DOS prompt. The
  228. ;       following checks are made, forcing DOS to use the "critical"
  229. ;       stack when the TSR enters at the INDOS level.
  230. ;
  231. ;               BX contains the PSP segment to set
  232. ;
  233. _TESSSETPSP proc        near
  234.         ASSUMEDS
  235.         call    checkindos              ;If Version < 3, and INDOS,...
  236.         jz      do_set_psp
  237.         mov     BPTR es:[di],0ffh       ;set critical flag
  238.  
  239.  
  240. do_set_psp:
  241.         mov     ax,5000h                ;set PSP function
  242.                                         ;BX already holds segment
  243.         int 21h                         ;DOS function request
  244.  
  245.         call    checkindos              ;If Version < 3, and INDOS,...
  246.         jz      set_out
  247.         mov     BPTR es:[di],0h         ;set critical flag
  248.  
  249. set_out:
  250.         ret
  251.  
  252. _TESSSETPSP endp
  253.  
  254. ;
  255. ; ***************************************************************************
  256. ;       G E T   P S P
  257. ;
  258. ;       A bug in DOS 2.0, 2.1, causes DOS to clobber its standard stack
  259. ;       Then the PSP get/set functions are issued at the DOS prompt. The
  260. ;       following checks are made, forcing DOS to use the "critical"
  261. ;       stack when the TSR enters at the INDOS level.
  262. ;
  263. ;               The PSP Segment is returned in BX
  264. ;
  265. _TESSGETPSP proc        near
  266.         ASSUMEDS
  267.         call    checkindos              ;If Version < 3, and INDOS,...
  268.         jz      do_get_psp
  269.         mov     BPTR es:[di],0ffh       ;set critical flag
  270.  
  271. do_get_psp:
  272.         mov     ax,5100h                ;get PSP function
  273.         int 21h                         ;DOS function request
  274.                                         ;BX now holds PSP segment
  275.         call    checkindos              ;If Version < 3, and INDOS,...
  276.         jz      get_out
  277.         mov     BPTR es:[di],0h ;clear critical flag
  278.  
  279. get_out:
  280.         ret
  281.  
  282. _TESSGETPSP endp
  283.  
  284. ;
  285. ; ***************************************************************************
  286. ;       This routine checks the version of DOS in use, and returns the
  287. ;       ZF=0 (Not zero) if version < 3.0, and INDOS is set.  Internal function
  288. ;       is called ONLY by getpsp and setpsp.
  289. ;
  290. checkindos proc near
  291.         ASSUMEDS
  292.         mov     al,BPTR [DOSVERSION]
  293.         cmp     al,3                    ;If Version is less than 3.0 ...
  294.         jae     ok_ret
  295.  
  296.         les     di,DPTR [INDOSFLAG]
  297.  
  298.         mov     al,BPTR es:[di]
  299.         or      al,al                   ;INDOS is set ...
  300.         jz      ok_ret
  301.         les     di,DPTR [DOSCRITERR]
  302.         jmp     short fixit             ;exit with not zero
  303. ok_ret:
  304.         xor     al,al                   ;set zero flag
  305. fixit:
  306.         ret
  307.  
  308. checkindos endp
  309.  
  310. IFNDEF ASMCOM
  311.  
  312. hProc <TSRESTORE2F FAR>
  313.  
  314. ELSE
  315.  
  316. hProc <TSRESTORE2F NEAR>                ; This procedure is should be
  317.                                         ;   called by any program that
  318. ENDIF                                   ;   calls TSCHECKRESIDENT but
  319.         ASSUMENODS                      ;   that does not call
  320.                                         ;   TSDOINIT!!
  321.  
  322.     push    di
  323.         xor     ax,ax
  324.         mov     es,ax
  325.         mov     bx,2fh
  326.         shl     bx,1
  327.         shl     bx,1
  328.         mov     ax,es:[bx+2]
  329.     mov    di,cs
  330.     cmp    ax,di
  331.         jne     not_took
  332.  
  333.     xor    ax,ax
  334.         mov     es:[bx],ax
  335.         mov     es:[bx+2],ax
  336.  
  337. not_took:
  338.     pop    di
  339.  
  340.         hRet
  341. hEndp
  342.  
  343.  
  344. GotStack db     0
  345.  
  346. _TESSRELEASETSR proc near
  347.  
  348.         ASSUMENODS
  349.         push    ax
  350.         push    bx
  351.         push    es
  352.         push    ds
  353.  
  354.         push    cs
  355.         pop     ds
  356.  
  357.         ASSUMEDS
  358.  
  359. test_rel:
  360.         call    test_restore
  361.         or      ax,ax
  362.         jz      skip3
  363.  
  364. IFDEF   TP4
  365. IFNDEF  ASMCOM
  366.         jmp     no_release
  367. ELSE
  368.         jmp     no_release
  369. ENDIF
  370. ELSE
  371.         jmp     no_release
  372. ENDIF
  373.  
  374. skip3:
  375.  
  376.         mov     bx,WPTR [OURPSP]
  377.         mov     es,bx
  378.         push    es
  379.         mov     bx,es:[2ch]
  380.  
  381.         mov     es,bx
  382.         mov     ax,4900h
  383.         int     21h
  384.  
  385.         pop     es
  386.  
  387.         jc      no_release
  388.  
  389.         mov     ax,4900h
  390.         int     21h
  391.         jc      no_release
  392.  
  393.         mov     [GotStack],0
  394.  
  395.         push    ds
  396.         mov     ax,WPTR [OURDSEG]
  397.         mov     ds,ax
  398.  
  399.         ASSUMENODS
  400.  
  401.         mov     ax,ss
  402.         cmp     ax,WPTR [OURSSSP+2]
  403.         je      our_stack
  404.  
  405.         mov     [GotStack],1
  406.  
  407.         cli                             ;no interrupts now!!!
  408.  
  409.         mov     WPTR [USERSS],ss        ;save user's stack segment
  410.         mov     WPTR [USERSP],sp        ;... and stack pointer
  411.  
  412.         mov     ss,WPTR [OURSSSP+2]     ;load TSR stack segment ...
  413.         mov     sp,WPTR [OURSSSP]       ;... and stack pointer
  414.  
  415.         sti
  416.  
  417. our_stack:
  418.         xor     ax,ax
  419.         inc     ax                      ;AX=1 on stack, shutdown routine
  420. IFNDEF  ASMCOM                          ;don't push for ASMCOM
  421.         push    ax
  422. ENDIF
  423.  
  424. IFDEF   TP4
  425. IFNDEF  ASMCOM
  426.  
  427. extrn EXITPROC:dword                    ;TP4's storage variables...
  428.  
  429.         call    DPTR PCLEANUP           ;call user routine (TP4 version)
  430.  
  431. TP_cleanup:                             ;fake out TP4's Exit Procedure ptrs
  432.         les     bx,DS:[EXITPROC]        ;pick up pointer
  433.         mov     ax,es
  434.         or      ax,bx
  435.         jz      TP_cleanup_done         ;if NIL no more to process
  436.  
  437.         xor     ax,ax                   ;set to NIL each time around
  438.         mov     WPTR DS:[EXITPROC],ax
  439.         mov     WPTR DS:[EXITPROC+2],ax
  440.  
  441.         mov     ax,offset TP_cleanup    ;return adr after Exit Proc
  442.         push    cs
  443.         push    ax
  444.         push    es
  445.         push    bx
  446.  
  447.         retf                            ;go do Exit Proc
  448.  
  449. TP_cleanup_done:
  450. ELSE
  451.         call    TSRCLEANUP              ;call user routine
  452. ENDIF
  453. ELSE
  454.         call    TSRCLEANUP              ;call user routine
  455. ENDIF
  456.  
  457.         mov     al,[GotStack]
  458.         or      al,al
  459.         jz      our_stack_1
  460.  
  461.         cli
  462.  
  463.         mov     ss,WPTR [USERSS]        ;restore user's stack segment
  464.         mov     sp,WPTR [USERSP]        ;... and stack pointer
  465.  
  466.         sti
  467.  
  468. our_stack_1:
  469.  
  470.         pop     ds
  471.  
  472.         ASSUMEDS
  473.  
  474.         xor     ax,ax
  475.         inc     ax                      ;say all restore
  476.         call    _TESSRESTOREINTS
  477.  
  478.     call    TSRESTORE2F
  479.  
  480.         mov     WPTR [STATUS],0
  481.  
  482.         jmp     short no_release_end
  483.  
  484. no_release:
  485.                                         ;make sure we try again
  486.         or      WPTR [STATUS],HOTKEYON+TSRRELEASED+POPUPSET
  487.         and     WPTR [STATUS],NOT TSRENABLED
  488.  
  489. no_release_end:
  490.         ASSUMENODS
  491.         pop     ds
  492.         pop     es
  493.         pop     bx
  494.         pop     ax
  495.         ret
  496. _TESSRELEASETSR endp
  497.  
  498. ENDIT
  499.