Coder's Guild Mailing List

Show Time TSR

Posted by Ali Bhai on 1999-05-07

Hi,

I have written the following code to display time on the lower left corner
of screen (assemble it as a .com program). I want to make a tsr out of it.
Let me explain my code first. There is one general routine Setup_Int that
sets up interrupt using function 35h interrupt 21h. Then there is the main
program that sets up my interrupt at 1Ch. The timer calls this interrupt
18.2 times per second. So, my procedure is called 18.2 times per second
automatically by the timer.

Actually I got the main idea from a book by Ytha Yu. However, I can't make
my program tsr so that it should display time permanently and exit. Any
ideas?

.MODEL SMALL
.CODE
ORG 100h
START: jmp main

LOCATION        EQU     1845h
oldCursor       DW      ?
timeBuff        DB      "00:00:00$"     ; hr:min:sec
oldVec          DD      ?               ; old vector
newVec          DW      ?, ?            ; new vector



show_time proc
   ; store register
   push ax
   push bx
   push cx
   push dx
   push ds


   ; initialize data segment
   mov ax, cs
   mov ds, ax

   ; get time
   mov ah, 2Ch
   int 21h

   ; store it in timeBuff
   mov bx, offset timeBuff
   xor ax, ax
   mov dl, 10
   mov al, ch           ; hours
   div dl
   or  ax, 3030h
   mov [bx], ax
   xor ah, ah
   mov al, cl           ; min
   div dl
   or  ax, 3030h
   mov [bx+3], ax
   xor ah, ah
   mov al, dh           ; sec
   div dl
   or  ax, 3030h
   mov [bx+6], ax

   ; store cursor
   mov ah, 3h
   xor bh, bh
   int 10h
   mov oldCursor, dx


   ; show time
   mov dx, LOCATION     ; set cursor
   mov ah, 2h
   xor bh, bh
   int 10h
   mov ah, 9
   lea dx, timeBuff
   int 21h

   ; restore cursor
   mov ah, 2h
   xor bh, bh
   mov dx, oldCursor
   int 10h

   ; exit
   pop ds
   pop dx
   pop cx
   pop bx
   pop ax
   iret
show_time endp



main proc
   ; setup interrupt 1Ch
   mov newVec, offset show_time
   mov newVec+2, cs
   lea si, newVec
   lea di, oldVec
   mov al, 1Ch
   call setup_int

   ; wait for a key
   mov ah, 0
   int 16h

   ; restore old vector
   lea si, oldVec
   lea di, newVec
   mov al, 1Ch
   call setup_int

   ; exit to dos
   mov ah, 4Ch
   int 21h
main endp




setup_int proc
   ; save old vector
   mov ah, 35h
   int 21h
   mov [di], bx
   mov [di+2], es

   ; setup new vector
   mov dx, [si]
   push ds
   mov ds, [si+2]
   mov ah, 25h
   int 21h
   pop ds

   ; exit
   ret
setup_int endp

end start



Ali Bhai
BCS III - FAST Institute of Computer Science, Karachi
email: mashah@xxxxx.xxx.xx
web page: www.pak.org/mufta
<----------------------------------------->
[To err is human but to really mess up the things you need a computer.]