home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 12 / 12_10.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-11  |  1.7 KB  |  79 lines

  1.         TITLE    'Listing 12-10'
  2.         NAME    GetHercMode
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        GetHercMode
  7. ;
  8. ; Function:    Determine video mode on Hercules adapters by estimating the size
  9. ;        of the displayed portion of the video buffer.
  10. ;
  11. ; Caller:    Microsoft C:
  12. ;
  13. ;            int GetHercMode(n);    /* returns approximate size */
  14. ;                        /*  of displayed portion of */
  15. ;                        /*  video buffer in words   */
  16. ;
  17.  
  18. _TEXT        SEGMENT    byte public 'CODE'
  19.         ASSUME    cs:_TEXT
  20.  
  21.         PUBLIC    _GetHercMode
  22. _GetHercMode    PROC    near
  23.  
  24.         push    bp        ; preserve BP
  25.         mov    bp,sp
  26.  
  27. ; reset CRTC light pen latch
  28.  
  29.         mov    dx,3BBh        ; DX := light pen reset port
  30.         out    dx,al        ; OUT to this port clears the latch
  31.                     ;  (the value in AL doesn't matter)
  32.  
  33. ; wait for start of next vertical retrace
  34.  
  35.         dec    dx        ; DX := 3BAH (CRT status port)
  36. L01:        in    al,dx        ; wait for start of vertical retrace
  37.         test    al,80h
  38.         jnz    L01
  39.  
  40. L02:        in    al,dx        ; wait for end of vertical retrace
  41.         test    al,80h
  42.         jz    L02
  43.  
  44.         cli            ; disable interrupts
  45. L03:        in    al,dx        ; wait for start of vertical retrace
  46.         test    al,80h
  47.         jnz    L03
  48.  
  49. ; latch the current CRTC address counter in the Light Pen registers
  50.  
  51.         dec    dx        ; DX := 3B9H
  52.         out    dx,al        ; OUT to this port loads the latch
  53.         sti            ; re-enable interrupts
  54.  
  55. ; return the value in the Light Pen registers
  56.  
  57.         mov    dl,0B4h        ; DX := 3B4H (CRTC address port)
  58.         mov    al,10h        ; AL := Light Pen High register number
  59.         out    dx,al
  60.         inc    dx
  61.         in    al,dx        ; read this register
  62.         dec    dx
  63.         mov    ah,al        ; AH := current Light Pen High value
  64.  
  65.         mov    al,11h        ; AL := Light Pen Low register number
  66.         out    dx,al
  67.         inc    dx
  68.         in    al,dx        ; AX := current light pen latch value
  69.                     ;  (i.e., value of CRTC address counter
  70.                     ;   at start of vertical retrace)
  71.         pop    bp
  72.         ret        
  73.  
  74. _GetHercMode    ENDP
  75.  
  76. _TEXT        ENDS
  77.  
  78.         END
  79.