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

  1.         TITLE    'Listing 5-5'
  2.         NAME    ReadPixel0F
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        ReadPixel0F
  7. ;
  8. ; Function:    Read the value of a pixel in 640x350 monochrome mode
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            int    ReadPixel0F(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    _ReadPixel0F
  27. _ReadPixel0F    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
  40.  
  41.         mov    ch,ah
  42.         shl    ch,cl        ; CH := bit mask in proper position
  43.         mov    si,bx        ; ES:SI -> regen buffer byte
  44.  
  45.         mov    dx,3CEh        ; DX := Graphics Controller port
  46.         mov    ax,204h        ; AH := initial bit plane number
  47.                     ; AL := Read Map Select register number
  48.  
  49.         xor    bl,bl        ; BL is used to accumulate the pixel value
  50.  
  51. L01:        out    dx,ax        ; (same as before)
  52.         mov    bh,es:[si]
  53.         and    bh,ch
  54.         neg    bh
  55.  
  56.         rol    bx,1
  57.         sub    ah,2
  58.         jge    L01
  59.  
  60.         mov    al,bl
  61.         xor    ah,ah
  62.  
  63.         pop    si
  64.         mov    sp,bp
  65.         pop    bp
  66.         ret
  67.  
  68. _ReadPixel0F    ENDP
  69.  
  70. _TEXT        ENDS
  71.  
  72.         END
  73.