VOGONS


First post, by llm

User metadata
Rank Member
Rank
Member

FYI: this is my very first DOS TSR after >30Years
its a reduced example of my NoUniVBE project that just contains my TSR install/uninstall

the program installs a TSR that hooks Interrupt 10h (doing nothing currently) and
uses some Interrupt 10h relative Data to finde itself for uninstalling (UniVBE does is alike and the detection Data will be much larger in the end)

i detect if the TSR is installed, recover the original int 10h vector entry and
free the memory with int 21h/49h

tsr.png
Filename
tsr.png
File size
15.01 KiB
Views
593 views
File comment
image of the TSR run
File license
Public domain

the problem is that after calling int 21h/49h dosbox waits for a kexpress (i think there is something very wrong in my code that produces this effect)
and the original int 10h seems to be not recovered after the uninstall because my install detection matches again

any idea?

; USAM or MASM
; uasm.exe tsrint10.asm

; ulink.exe -T16 -Tdc tsrint10.obj, tsrint10.com,tsrint10.map
; or 16bit link.exe from microsoft

.MODEL TINY

PSP_BYTES = 100h

Far_pointer struc
offs dw 0
segm dw 0
Far_pointer ends

TSR_ID_STR EQU <"MyID">

TSR_info_t struc
signature db TSR_ID_STR
load_segment dw 0
old_int10h Far_pointer<>
TSR_info_t ends

.CODE

org PSP_BYTES

start:

jmp configure

;====================================================
; resident part
;====================================================

tsr_info TSR_info_t<>

; resident code

detoured_int10h:
pushf
call cs:tsr_info.old_int10h
iret

end_of_resident:

;====================================================
; configure part (not resident)
;====================================================

PARAGRAPH_BYTES = 16

RESIDENT_BYTES = end_of_resident - start
RESIDENT_PARAGRAPHS = (PSP_BYTES + RESIDENT_BYTES + (PARAGRAPH_BYTES-1))/PARAGRAPH_BYTES

TSR_INFO_DISTANCE = detoured_int10h - tsr_info

VIDEO_BIOS_INT = 10h ; 5h for testing


Show last 103 lines
; configure data

installed_msg db 'installed!',10,13,'$'
uninstalled_msg db 'uninstalled!',10,13,'$'

; configure code

configure:

; is TSR installed
mov ah,35h
mov al,VIDEO_BIOS_INT
cli
int 21h
sti

mov di,bx
sub di,TSR_INFO_DISTANCE
; es:di = tsr_info

; exists TSR info signature?
cld
mov cx, sizeof(TSR_info_t.signature)
mov si, offset(tsr_info.signature)
repe cmpsb
jne install

jmp uninstall

install:
; safe old VIDEO BIOS interrupt handler ptr
mov ah,35h
mov al,VIDEO_BIOS_INT
cli
int 21h
sti
mov [tsr_info.old_int10h.segm],es
mov [tsr_info.old_int10h.offs],bx

; install new handler
mov ah,25h
mov al,VIDEO_BIOS_INT
push ds
push cs
pop ds
mov dx,offset(detoured_int10h)
cli
int 21h
sti
pop ds

; safe load segment of TSR
mov [tsr_info.load_segment],cs

mov dx,offset(installed_msg)
mov ah,9h
int 21h

; stay resident
mov dx,RESIDENT_PARAGRAPHS
mov ah,31h
mov al,0
int 21h

uninstall:
mov ah,35h
mov al,VIDEO_BIOS_INT
cli
int 21h
sti

; es:di = tsr_info
mov di,bx
sub di,TSR_INFO_DISTANCE

; install old handler
mov ah,25h
mov al,VIDEO_BIOS_INT
push ds
mov ax,es:[di+TSR_info_t.old_int10h.segm]
mov ds,ax
mov dx,es:[di+TSR_info_t.old_int10h.offs]
cli
int 21h
sti
pop ds

mov ah,49h
mov ax,es:[di+TSR_info_t.load_segment]
mov es,ax
int 21h
; <<<<<<<<<<<<<<<<<< Dosbox waits here for a keypress?
;<<<<<<<<<<<<<<<<<< and the recover of the old int 10h seems to not happen

mov dx,offset(uninstalled_msg)
mov ah,9h
int 21h

mov ax,4c00h
int 21h

end start

Attachments

  • Filename
    tsrint10.zip
    File size
    322 Bytes
    Downloads
    28 downloads
    File comment
    the COM executable
    File license
    Public domain

Reply 2 of 8, by llm

User metadata
Rank Member
Rank
Member
retardware wrote on 2021-11-16, 18:27:

I have no idea why you call INT 21h with random AH contents.

no 16 bit dos assembler work in the last 30 years - my spider sense wasn't tingling at all looking at that lines

retardware wrote on 2021-11-16, 18:27:

And, you might want to use Soft-ICE with its convenient breakpoints to debug.

im now using the dosbox debugger

thanks for the finding:

changed the code to

  
mov ax,es:[di+TSR_info_t.load_segment]
mov es,ax
mov ah,49h
int 21h

it still needs sometimes a keypress before uninstall
but maybe there is another bug like the one you've found

tsr.png
Filename
tsr.png
File size
27.04 KiB
Views
538 views
File comment
Some start of tsrint10.com
File license
Public domain

attached is the current version source+com file

Attachments

  • Filename
    tsrint10.zip
    File size
    1.29 KiB
    Downloads
    28 downloads
    File comment
    COM executable + source
    File license
    Public domain

Reply 3 of 8, by llm

User metadata
Rank Member
Rank
Member

found it! thanks @retardware

  ; install old handler
mov ah,25h
mov al,VIDEO_BIOS_INT
push ds
mov ax,es:[di+TSR_info_t.old_int10h.segm]
mov ds,ax
mov dx,es:[di+TSR_info_t.old_int10h.offs]
cli
int 21h
sti
pop ds

second time trashing ah/al before int 21h call

Reply 4 of 8, by jakethompson1

User metadata
Rank Oldbie
Rank
Oldbie

Might want to free your environment segment from the initial launch before going resident to save a little memory? I don't remember off-hand if you might be leaking it.
Don't think you need the wrapping cli/sti when asking DOS to replace int10h. I think that is the reason to let DOS do it rather than messing with the IVT yourself.
I wouldn't personally use all the structs and such but that's just me, instead use equ for things like .-tsr_info
Should be able to use les bx,[tsr_info.old_int10h] if you want to try that, too

Reply 5 of 8, by retardware

User metadata
Rank Oldbie
Rank
Oldbie

One of the projects I want to do when I got time is updating my DOS screensaver for Win95/98.
I'll upload the source when I backed up my old backups onto my new computer. Lots of CDs and HDDs.
I have forgotten how I exactly did the resident test, but it was using the code itself as signature. No need for signature strings.
It also captured the video interrupt, as optionally output turns on screen again.
But the most funny thing was the battle with the MS mouse driver, as that one always stole the mouse interrupt so my TSR had to put itself back into the mouse interrupt chain again and again.
Like two cats alternately pulling the food bowl to them 😀

Anyway, does anybody know how to check whether Windows 9x is running in the graphics mode?
This might also be of interest for llm, as some video-handling TSRs should not activate when Windows is running.

Reply 6 of 8, by jakethompson1

User metadata
Rank Oldbie
Rank
Oldbie
retardware wrote on 2021-11-16, 21:24:

Anyway, does anybody know how to check whether Windows 9x is running in the graphics mode?
This might also be of interest for llm, as some video-handling TSRs should not activate when Windows is running.

Windows will make INT 2F calls that you can hook to know when it loads and exits. http://mirror.cs.msu.ru/oldlinux.org/Linux.ol … tml/rb-4498.htm
It's more thoroughly documented in Unauthorized Windows 95

Reply 7 of 8, by llm

User metadata
Rank Member
Rank
Member
jakethompson1 wrote on 2021-11-16, 20:38:

Might want to free your environment segment from the initial launch before going resident to save a little memory? I don't remember off-hand if you might be leaking it.

added that - there are some document around that telling the PSP:2Ch should be freed before getting resident

jakethompson1 wrote on 2021-11-16, 20:38:

Don't think you need the wrapping cli/sti when asking DOS to replace int10h.
I think that is the reason to let DOS do it rather than messing with the IVT yourself.

removed the cli/sti

jakethompson1 wrote on 2021-11-16, 20:38:

I wouldn't personally use all the structs and such but that's just me, instead use equ for things like .-tsr_info

i've got some include files around (in my real project) that contains even the PSP as a struct 😀

jakethompson1 wrote on 2021-11-16, 20:38:

Should be able to use les bx,[tsr_info.old_int10h] if you want to try that, too

yepp

lds dx,es:[di+TSR_info_t.old_int10h]

is much better to read

Reply 8 of 8, by llm

User metadata
Rank Member
Rank
Member
retardware wrote on 2021-11-16, 21:24:

I have forgotten how I exactly did the resident test, but it was using the code itself as signature. No need for signature strings.

nice idea - will try to adapt that

retardware wrote on 2021-11-16, 21:24:

Anyway, does anybody know how to check whether Windows 9x is running in the graphics mode?
This might also be of interest for llm, as some video-handling TSRs should not activate when Windows is running.

i don't need that currently (i hope) im just overloading the oem-string that the VESA info returns