; ; tsrtest.asm - Terminate and Stay Resident Test App ; by Napalm ; [bits 16] [org 0x100] [segment .data] vector dd 0 tsrerror db "Error creating TSR", 0x0A, 0x0D, 0x24 strbuf db 10,0,0,0,0,0,0,0,0,0,0,0,0 [segment .bss] [segment .text] start: ; get old vector handler mov ax, 0x09 mov di, vector call getvector ; set new vector handler mov ax, 0x09 mov si, handler call setvector ; get string to test new handler mov dx, strbuf ; storage for inputted string mov ah, 0x0A ; ah = get string int 0x21 ; call dos dispatch handler ; calculate end of required memory mov dx, tsrend ; the address already has psp base of 0x100 mov cl, 4 ; keep dos debug happy with disassembly shr dx, cl ; divide by 16 (paragraph size) inc dx ; add 1 page for saftey ; exit but stay resident mov ax, 0x3100 ; ah = TSR, al = return code 0 int 0x21 ; call dos dispatch handler ; failed so print message and exit mov dx, tsrerror ; address of string mov ah, 0x09 ; ah = print string terminated by $ int 0x21 ; call dos dispatch handler exit: mov ax, 0x4C01 ; exit with return code 1 int 0x21 ; call dos dispatch handler ; assumes ax = int#, ds:si = function address setvector: push es push bx push cx xor cx, cx mov es, cx inc cx inc cx shl ax, cl mov bx, ax add cx, bx mov di, cs mov [es:bx], si ; 0000:(ax*4+0) = ds:si mov bx, cx mov [es:bx], di ; 0000:(ax*4+2) = cs pop cx pop bx pop es ret ; assumes ax = int#, es:di = address of dword getvector: push ds push cx xor cx, cx mov ds, cx inc cx inc cx shl ax, cl mov si, ax rep movsw ; [es:di+0] = 0000:(ax*4+0) ; [es:di+2] = 0000:(ax*4+2) pop cx pop ds ret ; play nice and align to paragraph boundry align 16 ; new interrupt 9 vector handler handler: push es ; backup seg pusha ; backup regs ; play with screen to test TSR is resident OK mov ax, 0xB800 mov es, ax mov bx, (79 * 2) ; top right inc word [es:bx] popa ; restore regs pop es ; restore seg jmp far [cs:vector] ; call old handler to complete interrupt ; this segment is needed to force the tsrend location to the end of the program ; so that everything in the program is reserved in memory [segment .bss] tsrend: