Maybe OT (wrong forum, wrong board and probably a stupidly wrong idea as well)... sorry.

To keep it short i need to make a dos app available from the network and because of bandwith limitation i cannot use vnc or similar crap.
The very 1st idea was redirecting standard i/o to a network pipe (e.g. nc.exe -e 16bit_dos_proggie.exe)... but this didnt work because 16bit_dos_proggie.exe directly writes to video memory. To get what i mean just try piping output from command.com and edit.com to a file.

So i wrote a very small tsr to poll video memory changes and transmit them to stdout...
What it basically do is:
- hooking int 1c to install the polling routine
- launching the proggie
- waiting for it to quit
- unhooking int 1c

This now somewhat works: invoking "launcher > FILE" fills FILE with the position, char and color of every character modified since last poll. Only problem is the whole thingy crashes as soon as 16bit_dos_proggie.exe calls int21 ah=4c... :(

Well i spent half a day trying to figure whats wrong but my asm16 knoweledge is somewhat rusty... and i got nowhere...
So here is the code... id be glad if someone could either point me to the mistake or suggest a better/cleaner way to do what i need... Cheers!!!



.model tiny
.code
.486
TsrBase:
org 100h
Proggie:
jmp Loader

; This is the int 1c hook
MyIntHanlder:

; Call real int 1c
cli
pushf
call dword ptr cs:oldintl

; Save some regs
push ds
push es

pusha
pushf

;Monitor Video Ram for changes (1st page starts @c000:b800)
mov ax, 0b800h
push ax
pop ds
xor si, si
push cs
pop es
mov di, offset buffer
cld
mov cx, 80*24
PollLoop:
repe
cmpsw
test cx, cx
je NothingNew

; If im here some memory changed
dec si
dec si
dec di
dec di

; Save segment+offset
mov cs:[send], si
lodsw
stosw
mov cs:[thiscrap], ax

; Output lo-offset to stdout using int 21 ah=2
mov ah, 2
mov dl, byte ptr cs:[send]
cli
pushf
call dword ptr cs:oldint21l

; Output hi-offset to stdout using int 21 ah=2
mov ah, 2
mov dl, byte ptr cs:[send+1]
cli
pushf
call dword ptr cs:oldint21l

; Output char to stdout using int 21 ah=2
mov ah, 2
mov dl, byte ptr cs:[thiscrap]
cli
pushf
call dword ptr cs:oldint21l

; Output color to stdout using int 21 ah=2
mov ah, 2
mov dl, byte ptr cs:[thiscrap+1]
cli
pushf
call dword ptr cs:oldint21l

jmp PollLoop

NothingNew:
; Restore all the registries
popf
popa

pop es
pop ds

; Return to the caller
sti
iret


; Various data
oldintl dw 0acabh
oldinth dw 0acabh

oldint21l dw 0acabh
oldint21h dw 0acabh

send dw 0
thiscrap dw 0

buffer dw (80*24) dup (0)
dummy db 20 dup (0)
tail db 0,0dh

child db 'C:\WINDOWS\COMMAND\EDIT.COM',0
;child db 'C:\WINDOWS\SYSTEM32\EDIT.COM',0

block dw 0
dw tail
segc dw 0
dw offset dummy
sega dw 0
dw offset dummy
segb dw 0


ThatsAll db 'END_$'


; Loader code

Loader:
;int 3
; Fill the buffer w/ current data
mov ax, 0b800h
push ax
pop ds
push cs
pop es
xor si, si
cld
mov di, offset buffer
mov cx, 80*24
repe
movsw

; Get int21 vector
mov ax, 3521h
int 21h
mov word ptr cs:[oldint21h], es
mov word ptr cs:[oldint21l], bx

; Get int1c vector
mov ax, 351ch
int 21h
mov word ptr cs:[oldinth], es
mov word ptr cs:[oldintl], bx

; Hook int1c
push cs
pop ds
mov dx, offset MyIntHanlder
mov ax, 251ch
int 21h


; Shrink allocated mem
mov bx, (offset top_mem)
shr bx, 4
inc bx
push cs
pop es
mov ah, 4ah
int 21h

; Setup the struct...
push cs
pop ds
push cs
pop es
push cs
pop word ptr [sega]
push cs
pop word ptr [segb]
push cs
pop word ptr [segc]

; ...and fire the proggie
mov dx, offset child
mov bx, offset block
mov ax, 4b00h
int 21h

; Revert old int1c vector
push word ptr cs:[oldinth]
pop ds
mov dx, word ptr cs:[oldintl]
mov ax, 251ch
int 21h

; This is the end
push cs
pop ds
mov dx, offset ThatsAll
mov ah, 09
int 21h

; Quit
mov ax, 4c00h
int 21h

end Proggie
Posted on 2003-12-15 09:30:26 by acab
Hi,

if I remember correctly Int 1C is called by int 08, a irq routine. in such a routine you must be careful to call dos interrupt 21h because it isnt reentrant.
You should possibly check indosflag and if it is set, save SDA before your calls and restore them later.

Japheth
Posted on 2003-12-16 12:33:11 by japheth
Ty a lot japheth!
i really forgot bout that....
I also figured out what made it crash: resizing the memory leaving ss:sp pointing outside the allocated memory is defently a stupid idea :(
Now it works... but still not as expected!
Under win9x, in fact, piped stdout gets buffered and actually only flushed on program termination.
But i guess that's a live with...
Everything works decently enough under NT-like's

Cheers!
Posted on 2003-12-17 13:40:12 by acab