home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 2 / 2_2.asm next >
Encoding:
Assembly Source File  |  1988-08-11  |  1.4 KB  |  74 lines

  1.         TITLE    'Listing 2-2'
  2.         NAME    HRTimeout
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        HRTimeout
  7. ;
  8. ; Function:     Determine a timeout value for the horizontal blanking interval
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            int HRTimeout();
  13. ;
  14.  
  15. _TEXT        SEGMENT    byte public 'CODE'
  16.         ASSUME    cs:_TEXT
  17.  
  18.         PUBLIC    _HRTimeout
  19. _HRTimeout    PROC    near
  20.  
  21.         push    bp        ; usual C prologue to establish
  22.         mov    bp,sp        ;  stack frame
  23.  
  24.         mov    ax,40h
  25.         mov    es,ax        ; ES := video BIOS data segment
  26.  
  27.         mov    dx,es:[63h]    ; DX := port for CRTC Address register
  28.         add    dl,6        ; DX := port for CRTC Status register
  29.  
  30. ; synchronize with start of refresh cycle
  31.  
  32. L01:        in    al,dx        ; AL := CRTC status
  33.         test    al,8        ; test bit 3
  34.         jz    L01        ; loop while NOT in vertical retrace
  35.  
  36. L02:        in    al,dx
  37.         test    al,8
  38.         jnz    L02        ; loop during vertical retrace
  39.  
  40. ; synchronize with a horizontal scan and time the horizontal blanking interval
  41.  
  42.         mov    cx,0FFFFh    ; CX := loop counter
  43.  
  44.         cli            ; disable interrupts
  45.  
  46. L03:        in    al,dx
  47.         test    al,1
  48.         jnz    L03        ; loop while Display Enable is inactive
  49.  
  50. L04:        in    al,dx
  51.         test    al,1
  52.         jz    L04        ; loop while Display Enable is active
  53.  
  54. L05:        in    al,dx
  55.         test    al,1
  56.         loopnz    L05        ; decrement CX and loop while Display
  57.                     ;  Enable is inactive
  58.  
  59.         sti            ; enable interrupts again
  60.  
  61.         mov    ax,cx        ; AX := loop counter
  62.         neg    ax
  63.         shl    ax,1        ; AX := timeout value
  64.  
  65.         mov    sp,bp        ; discard stack frame and return to C
  66.         pop    bp
  67.         ret
  68.  
  69. _HRTimeout    ENDP
  70.  
  71. _TEXT        ENDS
  72.  
  73.         END
  74.