home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / basic / timera.asm < prev    next >
Encoding:
Assembly Source File  |  1989-11-09  |  2.8 KB  |  62 lines

  1. ;*************************  TIMERA.ASM  ******************************
  2. ; This program, along with TIMER.BAS, makes use of the BASIC SetUEvent
  3. ; routine to print a message on the screen every 4.5 seconds.
  4. ; This file has three procedures.  SetInt sets up the new DOS interrupt
  5. ; vector.  EventHandler increments a counter 18 times a second and
  6. ; notifies BASIC when 4.5 seconds have elapsed.  RestInt restores the
  7. ; old interrupt vector.
  8.  
  9.             .model  medium, basic           ;Stay compatible with BASIC.
  10.             .code
  11. SetInt      proc    uses ds                 ;Get old interrupt vector
  12.             mov     ax, 351CH               ;and save it.
  13.             int    21h
  14.             mov     word ptr cs:OldVector, bx
  15.             mov     word ptr cs:OldVector + 2, es
  16.  
  17.             push    cs                      ;Set the new
  18.             pop ds                          ;interrupt vector
  19.             lea dx, EventHandler            ;to the address
  20.             mov ax, 251CH                   ;of our service
  21.             int 21H                         ;routine.
  22.             ret    
  23. SetInt      endp
  24.  
  25. public  EventHandler                        ;Make this routine
  26.                                             ;public for debugging--
  27. EventHandler    proc                        ;it will check to see if
  28.                 extrn   SetUEvent: proc     ;4.5 seconds have passed.
  29.  
  30.             push    bx
  31.             lea     bx, TimerTicks
  32.             inc     byte ptr cs:[bx]        ;Have 4.5 seconds elapsed?
  33.             cmp     byte ptr cs:[bx], 82
  34.             jnz     Continue
  35.             mov     byte ptr cs:[bx], 0     ;If true, reset counter,
  36.             push    ax                      ;save registers, and
  37.             push    cx                      ;have BASIC set the
  38.             push    dx                      ;user event flag.
  39.             push    es
  40.             call    SetUevent
  41.             pop     es
  42.             pop     dx                      ;Restore registers.
  43.             pop     cx
  44.             pop     ax
  45. Continue:
  46.             pop     bx
  47.             jmp     cs:OldVector            ;Continue on with the
  48.                                             ;old service routine.
  49.  
  50. TimerTicks  db      0                       ;Keep data in code segment
  51. OldVector   dd      0                       ;where it can be found no
  52.                                             ;matter where in memory the
  53. EventHandler    endp                        ;interrupt occurs.
  54.  
  55. RestInt     proc    uses ds                 ;Restore the old
  56.             lds     dx, cs:OldVector        ;interrupt vector
  57.             mov     ax, 251CH               ;so things will
  58.             int     21h                     ;keep working when
  59.             ret                             ;this BASIC program is
  60. RestInt     endp                            ;finished.
  61.             end
  62.