(7219)  Thu 29 Jul 93  6:07a
By: Paul White
To: Sunil Puri
Re: RE: Interrupt Handling
St:
---------------------------------------------------------------------------
In a message to everyone written on Tuesday, July 27, 1993 at 8:02:38 PM,
Sunil Puri writes:

SP> Does anyone have general suggestions about writing int handlers? I have
SP> written a TSR that displays the time in the corner of the screen. It
SP> hooks int 1Ch (the timer-tick int). It displays the time once and is
SP> correct, however, my system hangs. Could it be that is executes too
SP> slowly (since it chains the

Here is an example of a little routine I use in the 18.2 Hz DOS timer
tick interrupt chain, to keep track of time-outs, etc.  You could
easily modify this for your on-screen clock program.  The InsertWedge
routine installs the new interrupt handler, and the RemoveWedge routine
is used to remove the handler.

; Include file WEDGE.INC
; Interrupt chain insert and delete routines

TimeLimit    dw    ?
oldIRQ       dd    ?        ; save address of normal IRQ 8

;---------------------------------------;
InsertWedge    proc    near
;---------------------------------------;
; Insert process in DOS timer tick interrupt (8) chain
;
    push   es

    mov    ax,3508h        ; Get interrupt vector (#8)
    int    21h            ; returns es:bx pointing to IRQ
                    ; routine
    mov    word ptr [OldIRQ],bx
    mov    word ptr [OldIRQ+2],es    ; save original address

    mov    dx,offset IntWedge    ; ds:dx = new vector
    mov    ax,2508h        ; Set interrupt vector (#8)
    int    21h

    pop    es
    ret

InsertWedge    endp

;---------------------------------------;
RemoveWedge    proc    near
;---------------------------------------;

    push   ds
    mov    dx,word ptr [OldIRQ]    ; get offset in DX
    mov    ax,word ptr [OldIRQ+2]    ; get segment in DS
    mov    ds,ax            ; ds:dx = new vector
    mov    ax,2508h        ; Set interrupt vector (#8)
    int    21h

    pop    ds
    ret

RemoveWedge    endp

;---------------------------------------;
IntWedge    proc    near
;---------------------------------------;
; This is the routine inserted in the DOS timer tick interrupt chain
;
    pushf                ; save flags and register(s)
    push    ax

    mov    ax,cs:TimeLimit        ; If TimeLimit <> 0, decrement it
    or     ax,ax
    jz     no_update        ; (jump if already 0)

    sub    ax,1
    mov    cs:TimeLimit,ax        ; Update counter

no_update:
    pop    ax            ; restore register and flags
    popf

    jmp    dword ptr cs:[OldIRQ]   ; go on to the next event in chain

IntWedge   endp

--- Tabby 3.0
 * Origin: The Mountain Air BBS, Cedar Glen, CA  909/336-6080 (1:207/226)

@PATH: 207/226 8/8 13/13 260/1
