TIP: Click on subject to list as thread! ANSI
echo: 80xxx
to: NIMA HODA
from: JAMES VAHN
date: 1997-02-13 06:20:00
subject: programming TSRs

 NH> Does anyone know how to program a TSR?
For a better skeleton, f'req TBONES07.ZIP from 1:346/15
;----------------------------------------
; TSR.ASM- Simple code skeleton for TSR programs.
; Public Domain by James Vahn
Hook    EQU     09h                ; Vector to hook into. 1Ch,09h,etc.
.286                               ; Uses 286 codes, PUSHA & POPA
cseg segment
assume cs:cseg, ds:cseg
org 100h                           ; COM format.
Begin:
        jmp Init                   ; Jump over the ISR code
                                   ; to the intitialization code.
Old_Int         dd      ?          ; Storage- points to the old ISR.
InDOS           dd      ?          ; DOS busy flag
New_ISR:
        pusha                      ; Save the registers
        push    ds
        push    es
 ; Optional code to check InDOS/CritErr flags..
        push    cs                 ; Might not be needed.
        pop     ds
        mov     es, word ptr InDOS ; Test if DOS is busy.
        mov     bx, word ptr InDOS+2
        mov     ax,es:[bx-1]
        cmp     ax,0
        jne     Exit
  ;---------------------
  ; The ISR routine.
  ;---------------------
  ; your code here.
  ;---------------------
Exit:
        pop     es
        pop     ds
        popa                       ; End of ISR- exit
        jmp    cs:[Old_Int]        ; to old vector.
;-----------------------------
; TSR Initialization code follows.
; This portion doesn't stay resident.
;-----------------------------
Init:
        mov     dx,offset Msg      ; Prints the hello message.
        mov     ah,09h
        int     21h
        mov     bx,02Ch            ; Release the environment memory.
        mov     es,[bx]
        mov     ah,49h
        int     21h
        mov     ah,35h             ; Get old vector and store it.
        mov     al,Hook
        int     21h
        mov     word ptr [Old_Int],bx
        mov     word ptr [Old_Int+2],es
        mov     ah,34h             ; Get address of DOS Busy flag.
        int     21h
        mov     word ptr [InDOS],es
        mov     word ptr [InDOS+2],bx
        mov     al,Hook            ; Change the target vector.
        mov     dx,offset New_ISR
        mov     ah,25h
        int     21h
        mov     dx,offset Init     ; Allocate TSR memory
        int     27h                ; and exit to DOS.
Msg  db 13,10
     db 'TSR shell installed.',13,10
     db 13,10,36
cseg ends
end Begin
--- timEd 1.01
---------------
* Origin: James Vahn (jvahn@short.circuit.com) (1:346/15.1)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.