I am trying to create an active TSR which prints an 'A'
when the ESC key is pressed, it doesn't work.
Can anyone tell me what's wrong?

bits 16
org 100h

jmp init.tsr

int1c:
push ds
push ax
push cs
pop ds
call checkdos2
jc int1c_e
cmp byte [hotkey_found], 1
jnz int1c_e
call tsrapp
int1c_e:
pop ax
pop ds
iret

int28:
push ds
push ax
push cs
pop ds
call checkdos
jc int28_e
cmp byte [hotkey_found], 1
jnz int28_e
call tsrapp
int28_e:
pop ax
pop ds
iret

checkdos2:
push bx
push es
les bx, [InDOS]
mov al, 0
cmp al, byte [es:bx]
jb checkdos2_e
cmp al, byte [es:bx-1]
checkdos2_e:
pop es
pop bx
ret

checkdos:
push bx
push es
les bx, [InDOS]
mov al, 1
cmp al, byte [es:bx]
jb checkdos_e
xor al, al
cmp al, byte [es:bx-1]
checkdos_e:
pop es
pop bx
ret

InDOS      dd 0
Orig_isr9  dd 0
in_isr9    db 0
hotkey_found db 0
hotkey_idx dw 0
hotseq     db 0x1b

isr9:
push ds
push bx
push ax
push cs
pop ds
in al, 0x60
pushf
cli
call word far [Orig_isr9]
mov ah, [in_isr9]
or ah, [hotkey_found]
jnz isr9_e
inc byte [in_isr9]
cmp al, byte [hotseq]
jz isr9_foundkey
jmp isr9_exit
isr9_foundkey:
mov byte [hotkey_found], 1
isr9_exit:
dec byte [in_isr9]
isr9_e:
pop ax
pop bx
pop ds
iret

tsrapp:
push dx
mov ah, 0x2
mov dl, 0x41
int 0x21
pop dx
ret

pre equ $

init.tsr:
mov ax, 0x3509
int 0x21
mov [Orig_isr9], bx
mov [Orig_isr9+2], es
mov dx, isr9
mov ax, 0x2509
int 0x21
mov dx, int28
mov ax, 0x2528
int 0x21
mov dx, int1c
mov ax, 0x251c
int 0x21
mov ax, 0x3400
int 0x21
mov [InDOS], bx
mov [InDOS+2], es
mov dx, pre
add dx, 0xf
shr dx, 4
mov ax, 0x3100
int 0x21

int 28h is called from within DOS, so the indos byte will always be greater than 0 when it is called. You should check that it is not greater than one.

Also, it was normal to hook int 8 as well as int 28h. When checking indos from within int 8 you should make sure that it is not greater than zero.

If you were writing a full scale TSR you would also need to hook int 10h and int 13h, and set a flag every time they were invoked. You should then check those flags, in the same way that you check indos, before popping up a TSR.

commented: Thanks on this... +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.