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

  1.         TITLE    'Listing 5-6'
  2.         NAME    ReadPixel10
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        ReadPixel10
  7. ;
  8. ; Function:    Read the value of a pixel in 640x350 modes on 64K EGA
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            int    ReadPixel10(x,y);
  13. ;
  14. ;            int x,y;        /* pixel coordinates */
  15. ;
  16.  
  17. ARGx        EQU    word ptr [bp+4]    ; stack frame addressing
  18. ARGy        EQU    word ptr [bp+6]
  19.  
  20.  
  21. _TEXT        SEGMENT    byte public 'CODE'
  22.         ASSUME    cs:_TEXT
  23.  
  24.         EXTRN    PixelAddr10:near
  25.  
  26.         PUBLIC    _ReadPixel10
  27. _ReadPixel10    PROC    near
  28.  
  29.         push    bp        ; preserve caller registers
  30.         mov    bp,sp
  31.         push    si
  32.  
  33.         mov    ax,ARGy        ; AX := y
  34.         mov    bx,ARGx        ; BX := x
  35.         call    PixelAddr10    ; AH := bit mask
  36.                     ; ES:BX -> buffer
  37.                     ; CL := #bits to shift
  38.  
  39. ; concatenate bits from bit planes 2 and 0 (even byte address)
  40. ;  or 3 and 1 (odd byte address)
  41.  
  42.         mov    ch,ah
  43.         shl    ch,cl        ; CH := bit mask in proper position
  44.  
  45.         mov    si,bx        ; ES:SI -> regen buffer byte
  46.  
  47.         mov    ah,bl        ; AH := low-order byte of address
  48.         and    ax,100h        ; AH := low-order bit of address
  49.                     ; AL := 0
  50.         add    ax,204h        ; AH := initial bit plane number (2 or 3)
  51.                     ; AL := Read Map Select register number
  52.  
  53.         mov    dx,3CEh        ; DX := Graphics Controller port
  54.         xor    bl,bl        ; BL is used to accumulate the pixel value
  55.  
  56. L01:        out    dx,ax        ; (same as before)
  57.         mov    bh,es:[si]
  58.         and    bh,ch
  59.         neg    bh
  60.  
  61.         rol    bx,1
  62.         sub    ah,2
  63.         jge    L01
  64.  
  65.         mov    al,bl
  66.         xor    ah,ah
  67.  
  68.         pop    si
  69.         mov    sp,bp
  70.         pop    bp
  71.         ret
  72.  
  73. _ReadPixel10    ENDP
  74.  
  75. _TEXT        ENDS
  76.  
  77.         END
  78.