First post, by llm
now it runs and does not crash!!!
FIXES:
1. changed wlink.exe format dos ... to wlink.exe format dos com ...
2. removed mov ax,@data and mov ds,ax because ds=cs in tiny model
3. fixed the uinstall code to use the real tsr data
4. fixes missing use of es in uninstall tsr_info acccess
can anyone see were i made a error or anyone got an idea whats wrong with my code - i try to overwrite the int 21h/ah=9 functions to replace some chars on print
its not finished (no code in the ISR except calling the old handler) but already helps my dosbox DOS behaves strange after install - can't even run the Dosbox debugger after install
build with OpenWatcom V2 wasm+wlink (or JWasm, Uasm, Masm)
set WATCOM=f:\projects\fun\dos_games_rev\tools\open-watcom-2_0-c-win-x64
set WATCOM_BIN=%WATCOM%\binnt64
set INCLUDE=%WATCOM%\h
set PATH=%WATCOM_BIN%;%PATH%
wasm.exe tsr.asm
wlink.exe format dos com file tsr.obj name tsr.com
the TSR code
far_ptr_t struc
offs dw 0
segm dw 0
far_ptr_t ends
tsr_info_t struc
signature dw 0CAFEh
old_interrupt_21h far_ptr_t<0,0>
load_segment dw 0
tsr_info_t ends
.model tiny
.code
org 100h ; this is a COM program
start:
jmp setup ; jump to TSR installation
int21h_handler proc far
cmp ah,9 ; is it print
jne run_original
; copy string with $
; search for 'l' and replace with 'X'
; ds=cs,dx=offset buffer
; ...
run_original:
jmp far ptr cs:[tsr_info.old_interrupt_21h] ; jump to original int 21h
; local buffer
buffer db 16 dup(0)
int21h_handler endp
; tsr data
tsr_info TSR_info_t<>
resident_end: ; also contains PSP at start due to "org 100h"
TSR_INFO_OFFSET = offset tsr_info - offset int21h_handler;
current_load_seg dw 0
setup:
mov bx,ds
mov current_load_seg,bx
; ds == cs
mov ax,3521h ; get int 21h
int 21h
mov di,bx
add di,TSR_INFO_OFFSET
mov ax,es:[di+TSR_info_t.signature]
cmp ax,0CAFEh
je uinstall
; install
; save current int 21h handler
mov [tsr_info.old_interrupt_21h.offs],bx
mov [tsr_info.old_interrupt_21h.segm],es
; save load-segment for uninstall
mov ax,current_load_seg
mov [tsr_info.load_segment],ax
mov ax,2521h ; set interrupt vector
mov dx,offset int21h_handler
int 21h
mov ax,3100h
mov dx,offset resident_end
mov cl,4
shr dx,cl
inc dx
int 21h
uinstall:
push ds
mov ax,es:[di+TSR_info_t.old_interrupt_21h.segm]
mov ds,ax
mov dx,es:[di+TSR_info_t.old_interrupt_21h.offs]
mov ax,2521h
int 21h
pop ds
mov ax,es:[di+TSR_info_t.load_segment]
mov es,ax
mov ah,49h
int 21h
mov ax,4c00h
int 21h
END start
last time if was something simple like an overwritten ah,ah register - im doing way too much C++ and my brain isn't very good in pattern machting of stupid mistakes in 16bit assembler 🙁