home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_02 / timer.asm < prev    next >
Assembly Source File  |  1990-09-26  |  2KB  |  77 lines

  1.  
  2.  
  3. .model small
  4.  
  5. .code
  6.  
  7.  
  8. public _readtimer
  9. _readtimer proc
  10.    cli             ; Disable interrupts */
  11.    mov  dx,020h     ; Address PIC ocw3   */
  12.    mov  al,00Ah     ; Ask to read irr    */
  13.    out  dx,al
  14.    mov  al,00h     ; Latch timer 0 */
  15.    out  043h,al
  16.    in   al,dx      ; Read irr      */
  17.    mov  di,ax      ; Save it in DI */
  18.    in   al,040h     ; Counter --> bx*/
  19.    mov  bl,al      ; LSB in BL     */
  20.    in   al,040h
  21.    mov  bh,al      ; MSB in BH     */
  22.    not  bx         ; Need ascending counter */
  23.    in   al,021h     ; Read PIC imr  */
  24.    mov  si,ax      ; Save it in SI */
  25.    mov  al,00FFh    ; Mask all interrupts */
  26.    out  021h,al
  27.    mov  ax,040h     ; read low word of time */
  28.    mov  es,ax      ; from BIOS data area   */
  29.    mov  dx,es:[06Ch]
  30.    mov  ax,si      ; Restore imr from SI   */
  31.    out  021h,al
  32.    sti             ; Enable interrupts */
  33.    mov  ax,di      ; Retrieve old irr  */
  34.    test al,001h     ; Counter hit 0?    */
  35.    jz   done       ; Jump if not       */
  36.    cmp  bx,0FFh     ; Counter > 0x0FF?    */
  37.    ja   done       ; Done if so        */
  38.    inc  dx         ; Else count int req. */
  39. done:
  40.    mov ax,bx   ; set function result */
  41.         ret
  42. _readtimer endp
  43.  
  44.  
  45.  
  46. public _restoretimer
  47. _restoretimer proc
  48.         mov     al,36h
  49.         out     43h,al
  50.         jmp     short $+2
  51.         xor     al,al
  52.         out     40h,al
  53.         jmp     short $+2
  54.         xor     al,al
  55.         out     40h,al
  56.         ret
  57. _restoretimer endp
  58.  
  59.  
  60. public _initializetimer
  61. _initializetimer proc
  62.         mov     al,34h
  63.         out     43h, al
  64.         jmp     short $+2
  65.         xor     al,al
  66.         out     40h,al
  67.         jmp     short $+2
  68.         xor     al,al
  69.         out     40h, al
  70.         ret
  71. _initializetimer endp
  72.  
  73.  
  74.  
  75. end
  76.  
  77.