Category : Assembly Language Source Code
Archive   : TSR.ZIP
Filename : TSR.ASM

 
Output of file : TSR.ASM contained in archive : TSR.ZIP
title tsr.asm

;
;A skeleton program for writing terminate but stay resident
;assembly programs
;
;Copyright, 1987, by Robert D. King, Springfield, Va.
;
;Placed in the public domain, 1987. This program may not be
;sold or used for profit without the permission of the author.
;A nominal charge, not to exceed $3.00 may be made to cover
;the expense of copying and distributing.
;
;

;
;generally useful equates and macros
;

false = 0
true = not false
bel = 07h
cr = 0dh
lf = 0ah

far_jump macro ;used to go directly to bios routines
db 0eah
endm

far_call macro ;used to call bios routines when control
db 09ah ;is to be assumed by this program after
endm ;bios does its work.


cs_override macro ;not smart enough to do this some other way
db 02eh
endm

;
;label definitions which access the interrupt vectors go here
;
abso segment at 0
org 00h*4 ;this example replaces interrupt 0
old_ivec label dword

abso ends


cseg segment para
assume cs:cseg,ds:cseg,es:cseg

begin:
jmp init ;initialize and exit

EVEN ;useful for 8086 & 80286 microprocessors
;puts the interrupt handler on an even
;boundary

new_ivec:

;
;the replaced interrupt vector will point to here
;new processing code should be inserted as appropriate.
;note that a jump and a call to the old interrupt vector
;are available below. The routine gobak may be jumped to
;in order to skip interrupt processing. Remember that if a
;hardware interrupt has been intercepted, a non-specific End-Of-Interrupt
;may need to be sent to the interrupt controller.


old_jump:
far_jump ;macro above will generate a far jump
old_ivec_jump dd 0 ;interrupt vector gets placed here by init


old_call:
pushf ;to call the old interrupt, must push flags
far_call ;macro above will generate a far call
old_ivec_call dd 0 ;interrupt vector gets placed here by init

;
;will return to here after the far call
;

gobak:
iret

;
;signature used to test for previous installation
;goes here
;
signature:
db "tsr tsr tsr"
sig_count: ;lets me get a count for comparison by init


init:
;
;
;get old interrupt address from old_ivec and save it
;at old_ivec_jump and old_ivec_call for dummy jump and call,
;respectively... then put pointer to output routine there
;then, exit with tsr data.

push es ;save registers... like all good programs
push ds ;should
push si
push di
push cx
xor ax,ax ;set ds to absolute segment
mov ds,ax
assume ds:abso

;
;get the segment address from the old interrupt vector
;
mov di,word ptr old_ivec+2
mov cs:word ptr old_ivec_call+2,di
mov cs:word ptr old_ivec_jump+2,di
mov es,di

;
;get the offset address from the old interrupt vector
;
mov di,word ptr old_ivec
mov cs:word ptr old_ivec_call,di
mov cs:word ptr old_ivec_jump,di

;
;test for previous installation
;


add di,offset signature-offset new_ivec
;es:di now point to
;signature if already
;installed

mov si,offset signature ;cs:si now point to
;local signature block

mov cx,offset sig_count - offset signature ;number to check
cld ;set direction

cs_override ;want relative to cs:
;don't know how to do this with
;the *&%$#@!-ing version of
;MASM that I use

repz cmpsb ;scan for all matching

jz no_tsr ;z-flag set means all of them
;matched

;
;z-flag wasn't set, so....
;now set the new interrupt vector pointer
;


cli ;critical section... interrupts off!
mov word ptr old_ivec+2,cs
mov word ptr old_ivec,offset new_ivec
sti ;end of critical section... back on!


pop cx ;restore registers
pop di
pop si
pop ds
pop es
mov ax,3100h ;code for terminate & stay resident
;al has 0 for error code

mov dx,(offset init-offset begin) shr 1 + 0010h
;length of code to keep
;don't know why this doesn't
;work without adding 10h, but
;it doesn't

int 21h


;
;was previously installed
;
no_tsr:
pop cx
pop di
pop si
pop ds
pop es
push ds
mov dx,seg dseg ;point ds to dseg segment
mov ds,dx
assume ds:dseg
mov dx,offset msg_dead ;set up for print
mov ah,9 ;command to print the message
int 21h
pop ds
mov ax,4c01h ;terminate process with error code
int 21h

cseg ends


dseg segment para ;align to paragraph

msg_dead label byte
db "Cannot Load... Already Resident",bel,cr,lf,'$'
dseg ends

end begin


  3 Responses to “Category : Assembly Language Source Code
Archive   : TSR.ZIP
Filename : TSR.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/