Author Topic: Converting MASM TSR in DOS and NASM  (Read 545 times)

Offline tysonprogrammer

  • Jr. Member
  • *
  • Posts: 25
  • Country: us
  • C# application developer attempting assembly.
Converting MASM TSR in DOS and NASM
« on: January 02, 2025, 11:29:39 PM »
So I have this book that has an example TSR written in MASM, al it doe sit look at the keyboard flags and if the user presses CTRL+ALT+DEL is if change turns off the CTRL bit. If the user pressss CTRL_ALT_Rgt Shift+DEL is will original handler.

I pretty much have it  working except after it installs I can no longer type anything so I am guessing it's not calling the old handler. I am pretty sure I have the jump addresses incorrect but not sure how to get that working.

I had originally pasted int the MASM source but was concerned that it might be copyrighted so I removed it and I removed unrelated code from my version as I believe the issue is either setting the interrupt vector or the jumping to the original one. Perhaps I am not jumping correctly.

Code: [Select]
org 100h

main:
jmp setup

int9_handler:
sti                                 ; enable hardware interupts
pushf                               ; save regs and flags
push es
push ax
push di

pop di
pop ax
pop es
popf
jmp [cs:old_interupt9]

old_interupt9 dw 2 dup (?)
end_isr: db 1 dup (?)
; ----------------------------------------------
; Save copy of original interrupt 9 vector, and setup
; the address of the program as the new vector, terminate
; this program and leave int9_handler procedure in memory.
setup:
mov ax, 0x3509                      ; get int9 vector
int 0x21

mov word [old_interupt9], bx        ; save int9 vector
mov word [old_interupt9+2], es

mov ax, 0x2509                      ; set int9 vector
mov dx, int9_handler
int 0x21

mov ax, 0x3100                      ; terminate and stay resident
mov dx, end_isr                     ; point to end of resident code
shr dx, 4                           ; divide by 16
inc dx                              ; round forward one paragraph
int 0x21


What am I missing?


thanks,
Tyson

« Last Edit: January 03, 2025, 10:51:33 PM by tysonprogrammer »

Offline tysonprogrammer

  • Jr. Member
  • *
  • Posts: 25
  • Country: us
  • C# application developer attempting assembly.
Re: Converting MASM TSR in DOS and NASM
« Reply #1 on: January 04, 2025, 12:00:21 AM »
I found the error of my ways, I needed to use jmp far [cs:old_interupt9]

Now to see why it's not detecting the keys and disabling the normal CTRL+ALT+DEL

So I have this book that has an example TSR written in MASM, al it doe sit look at the keyboard flags and if the user presses CTRL+ALT+DEL is if change turns off the CTRL bit. If the user pressss CTRL_ALT_Rgt Shift+DEL is will original handler.

I pretty much have it  working except after it installs I can no longer type anything so I am guessing it's not calling the old handler. I am pretty sure I have the jump addresses incorrect but not sure how to get that working.

I had originally pasted int the MASM source but was concerned that it might be copyrighted so I removed it and I removed unrelated code from my version as I believe the issue is either setting the interrupt vector or the jumping to the original one. Perhaps I am not jumping correctly.

Code: [Select]
org 100h

main:
jmp setup

int9_handler:
sti                                 ; enable hardware interupts
pushf                               ; save regs and flags
push es
push ax
push di

pop di
pop ax
pop es
popf
jmp [cs:old_interupt9]

old_interupt9 dw 2 dup (?)
end_isr: db 1 dup (?)
; ----------------------------------------------
; Save copy of original interrupt 9 vector, and setup
; the address of the program as the new vector, terminate
; this program and leave int9_handler procedure in memory.
setup:
mov ax, 0x3509                      ; get int9 vector
int 0x21

mov word [old_interupt9], bx        ; save int9 vector
mov word [old_interupt9+2], es

mov ax, 0x2509                      ; set int9 vector
mov dx, int9_handler
int 0x21

mov ax, 0x3100                      ; terminate and stay resident
mov dx, end_isr                     ; point to end of resident code
shr dx, 4                           ; divide by 16
inc dx                              ; round forward one paragraph
int 0x21


What am I missing?


thanks,
Tyson