home *** CD-ROM | disk | FTP | other *** search
- IFNDEF TP4
- PAGE 60,132
- ;----------------------------------------------------------------------------
- SUBTTL TesSeRact Revision Level 1
- ;-----------------------------------------------------------------------------
- ; TesSeRact(tm) -- A Library of Routines for Creating Ram-Resident (TSR)
- ; programs for the IBM PC and compatible Personal
- ; Computers.
- ;
- ;The software, documentation and source code are:
- ;
- ; Copyright (C) 1986, 1987, 1988 Tesseract Development Team
- ; All Rights Reserved
- ;
- ; c/o Chip Rabinowitz
- ; Innovative Data Concepts
- ; 2084 Woodlawn Avenue
- ; Glenside, PA 19038
- ; 1-215-884-3373
- ;
- ;-----------------------------------------------------------------------------
- ; This product supports the TesSeRact Standard for Ram-Resident Program
- ; Communication. For information about TesSeRact, contact the TesSeRact
- ; Development Team at:
- ; Compuserve: 70731,20
- ; MCIMAIL: 315-5415
- ; This MCIMAIL Account has been provided to the TesSeRact Development
- ; Team by Borland International, Inc. The TesSeRact Development Team
- ; is in no way associated with Borland International, Inc.
- ;-----------------------------------------------------------------------------
-
- INCLUDE MIXED.INC
- INCLUDE TESS.INC
- IFDEF ALLPUBLIC
- INCLUDE tsutil.pub
- ENDIF
-
- .MODEL small
-
- EXTRN TSRCLEANUP:FAR
-
- .CODE
-
- EXTRN TESS_GLOBALS:byte
- EXTRN TESS_USERPARMS:byte
-
- PUBLIC _TESSRESTOREINTS, _TESSSETUPINTS, _TESSSETPSP, _TESSGETPSP, _TESSRELEASETSR
-
- ENDIF
-
- ;
- ; ***************************************************************************
- ; Function to restore interrupts.
- ;
- ; If AX=0, this function does popup-interrupts (1B, 23 and 24)
- ; If AX=anything else, this function does initial interrupts
- ;
- _TESSRESTOREINTS proc near
- ASSUMEDS
-
- push ds
- push ax
- push dx
- push si
- push di
- push cx
- mov di,7 ;7 bytes per structure
-
- or ax,ax
- jnz restore1
-
- mov cx,NUMINTS_2 ;three times through
- mov si,offset OLDINT1B ;start at table beginning
- jmp short restore_loop
- restore1:
- mov cx,NUMINTS_1 ;eleven interrupts!
- mov si,offset OLDINT8 ;top of table
-
- restore_loop:
- push di ;save structure size
- push ds
- mov al,4[si] ;interrupt number
- mov dx,[si] ;IP of interrupt vector
- mov ds,2[si] ;CS of interrupt vector
- mov ah,25h ;set interrupt vector function
- int 21h
- pop ds
- xor ax,ax ;clear this entry from table
- mov [si],ax ;so it shows not used
- mov 2[si],ax
- pop di ;get size back
- add si,di ;do it again
- loop restore_loop
-
- pop cx
- pop di
- pop si
- pop dx
- pop ax
- pop ds
- ret
- _TESSRESTOREINTS endp
- ;
- ; ***************************************************************************
- ; Function to set interrupts.
- ;
- ; If AX=0, this function does popup-interrupts (1B, 23 and 24)
- ; If AX=anything else, this function does initial interrupts
- ;
- _TESSSETUPINTS proc near
- ASSUMEDS
- push es
- push ax
- push bx
- push dx
- push di
- push si
- push cx
- mov di,7 ;7 bytes per structure
-
- or ax,ax
- jnz setup1
-
- mov cx,NUMINTS_2 ;three times through
- mov si,offset OLDINT1B ;start at table beginning
- jmp short setup_loop
- setup1:
- mov cx,NUMINTS_1 ;eleven interrupts!
- mov si,offset OLDINT8 ;top of table
-
- setup_loop:
- push di ;save structure size
-
- mov ax,[si] ;check for value
- or ax,ax ;if not zero, next one
- jnz setup2
- mov al,4[si] ;interrupt number
- mov ah,35h ;get interrupt vector function
-
- int 21h
- mov [si],bx ;save IP
- mov 2[si],es ;save CS
-
- mov al,4[si] ;interrupt number
- ;DS already contains correct segment
- mov dx,5[si] ;IP of interrupt vector
- mov ah,25h ;set interrupt vector function
- int 21h
-
- setup2:
- pop di ;get size back
- add si,di ;do it again
- loop setup_loop
- ex_set:
- pop cx
- pop si
- pop di
- pop dx
- pop bx
- pop ax
- pop es
- ret
- _TESSSETUPINTS endp
-
- ;
- ; ***************************************************************************
- ; Function to test interrupts.
- ;
- ; This functionis called to see if all our interrupts are still at
- ; the top of the interrupt chain. If any of our interrupts are not
- ; at the top of the interrupt chain, we return -1. Zero (0) is
- ; returned if it safe to unload.
- ;
- test_restore proc near
-
- ASSUMEDS
-
- push ds
- push es
- push dx
- push si
- push di
- push cx
- push bx
- mov di,7 ;7 bytes per structure
-
-
- t_restore1:
- mov cx,NUMINTS_1 ;eleven interrupts!
- mov si,offset OLDINT8 ;top of table
-
- restore_test:
- mov al,4[si]
- mov ah,35h
- int 21h
-
- mov ax,es
- mov bx,cs
- cmp ax,bx
- jne not_us
-
- add si,di ;do it again
- loop restore_test
-
- xor ax,ax
- jmp short test_out
-
- not_us:
- xor ax,ax
- dec ax
-
- test_out:
- pop bx
- pop cx
- pop di
- pop si
- pop dx
- pop es
- pop ds
- ret
-
- test_restore endp
-
- ;
- ; ***************************************************************************
- ; S E T P S P
- ;
- ; A bug in DOS 2.0, 2.1, causes DOS to clobber its standard stack
- ; Then the PSP get/set functions are issued at the DOS prompt. The
- ; following checks are made, forcing DOS to use the "critical"
- ; stack when the TSR enters at the INDOS level.
- ;
- ; BX contains the PSP segment to set
- ;
- _TESSSETPSP proc near
- ASSUMEDS
- call checkindos ;If Version < 3, and INDOS,...
- jz do_set_psp
- mov BPTR es:[di],0ffh ;set critical flag
-
-
- do_set_psp:
- mov ax,5000h ;set PSP function
- ;BX already holds segment
- int 21h ;DOS function request
-
- call checkindos ;If Version < 3, and INDOS,...
- jz set_out
- mov BPTR es:[di],0h ;set critical flag
-
- set_out:
- ret
-
- _TESSSETPSP endp
-
- ;
- ; ***************************************************************************
- ; G E T P S P
- ;
- ; A bug in DOS 2.0, 2.1, causes DOS to clobber its standard stack
- ; Then the PSP get/set functions are issued at the DOS prompt. The
- ; following checks are made, forcing DOS to use the "critical"
- ; stack when the TSR enters at the INDOS level.
- ;
- ; The PSP Segment is returned in BX
- ;
- _TESSGETPSP proc near
- ASSUMEDS
- call checkindos ;If Version < 3, and INDOS,...
- jz do_get_psp
- mov BPTR es:[di],0ffh ;set critical flag
-
- do_get_psp:
- mov ax,5100h ;get PSP function
- int 21h ;DOS function request
- ;BX now holds PSP segment
- call checkindos ;If Version < 3, and INDOS,...
- jz get_out
- mov BPTR es:[di],0h ;clear critical flag
-
- get_out:
- ret
-
- _TESSGETPSP endp
-
- ;
- ; ***************************************************************************
- ; This routine checks the version of DOS in use, and returns the
- ; ZF=0 (Not zero) if version < 3.0, and INDOS is set. Internal function
- ; is called ONLY by getpsp and setpsp.
- ;
- checkindos proc near
- ASSUMEDS
- mov al,BPTR [DOSVERSION]
- cmp al,3 ;If Version is less than 3.0 ...
- jae ok_ret
-
- les di,DPTR [INDOSFLAG]
-
- mov al,BPTR es:[di]
- or al,al ;INDOS is set ...
- jz ok_ret
- les di,DPTR [DOSCRITERR]
- jmp short fixit ;exit with not zero
- ok_ret:
- xor al,al ;set zero flag
- fixit:
- ret
-
- checkindos endp
-
- IFNDEF ASMCOM
-
- hProc <TSRESTORE2F FAR>
-
- ELSE
-
- hProc <TSRESTORE2F NEAR> ; This procedure is should be
- ; called by any program that
- ENDIF ; calls TSCHECKRESIDENT but
- ASSUMENODS ; that does not call
- ; TSDOINIT!!
-
- push di
- xor ax,ax
- mov es,ax
- mov bx,2fh
- shl bx,1
- shl bx,1
- mov ax,es:[bx+2]
- mov di,cs
- cmp ax,di
- jne not_took
-
- xor ax,ax
- mov es:[bx],ax
- mov es:[bx+2],ax
-
- not_took:
- pop di
-
- hRet
- hEndp
-
-
- GotStack db 0
-
- _TESSRELEASETSR proc near
-
- ASSUMENODS
- push ax
- push bx
- push es
- push ds
-
- push cs
- pop ds
-
- ASSUMEDS
-
- test_rel:
- call test_restore
- or ax,ax
- jz skip3
-
- IFDEF TP4
- IFNDEF ASMCOM
- jmp no_release
- ELSE
- jmp no_release
- ENDIF
- ELSE
- jmp no_release
- ENDIF
-
- skip3:
-
- mov bx,WPTR [OURPSP]
- mov es,bx
- push es
- mov bx,es:[2ch]
-
- mov es,bx
- mov ax,4900h
- int 21h
-
- pop es
-
- jc no_release
-
- mov ax,4900h
- int 21h
- jc no_release
-
- mov [GotStack],0
-
- push ds
- mov ax,WPTR [OURDSEG]
- mov ds,ax
-
- ASSUMENODS
-
- mov ax,ss
- cmp ax,WPTR [OURSSSP+2]
- je our_stack
-
- mov [GotStack],1
-
- cli ;no interrupts now!!!
-
- mov WPTR [USERSS],ss ;save user's stack segment
- mov WPTR [USERSP],sp ;... and stack pointer
-
- mov ss,WPTR [OURSSSP+2] ;load TSR stack segment ...
- mov sp,WPTR [OURSSSP] ;... and stack pointer
-
- sti
-
- our_stack:
- xor ax,ax
- inc ax ;AX=1 on stack, shutdown routine
- IFNDEF ASMCOM ;don't push for ASMCOM
- push ax
- ENDIF
-
- IFDEF TP4
- IFNDEF ASMCOM
-
- extrn EXITPROC:dword ;TP4's storage variables...
-
- call DPTR PCLEANUP ;call user routine (TP4 version)
-
- TP_cleanup: ;fake out TP4's Exit Procedure ptrs
- les bx,DS:[EXITPROC] ;pick up pointer
- mov ax,es
- or ax,bx
- jz TP_cleanup_done ;if NIL no more to process
-
- xor ax,ax ;set to NIL each time around
- mov WPTR DS:[EXITPROC],ax
- mov WPTR DS:[EXITPROC+2],ax
-
- mov ax,offset TP_cleanup ;return adr after Exit Proc
- push cs
- push ax
- push es
- push bx
-
- retf ;go do Exit Proc
-
- TP_cleanup_done:
- ELSE
- call TSRCLEANUP ;call user routine
- ENDIF
- ELSE
- call TSRCLEANUP ;call user routine
- ENDIF
-
- mov al,[GotStack]
- or al,al
- jz our_stack_1
-
- cli
-
- mov ss,WPTR [USERSS] ;restore user's stack segment
- mov sp,WPTR [USERSP] ;... and stack pointer
-
- sti
-
- our_stack_1:
-
- pop ds
-
- ASSUMEDS
-
- xor ax,ax
- inc ax ;say all restore
- call _TESSRESTOREINTS
-
- call TSRESTORE2F
-
- mov WPTR [STATUS],0
-
- jmp short no_release_end
-
- no_release:
- ;make sure we try again
- or WPTR [STATUS],HOTKEYON+TSRRELEASED+POPUPSET
- and WPTR [STATUS],NOT TSRENABLED
-
- no_release_end:
- ASSUMENODS
- pop ds
- pop es
- pop bx
- pop ax
- ret
- _TESSRELEASETSR endp
-
- ENDIT
-