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

  1.         TITLE    'Listing 5-4'
  2.         NAME    ReadPixel10
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        ReadPixel10
  7. ;
  8. ; Function:    Read the value of a pixel in EGA native graphics modes
  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.         mov    ch,ah
  40.         shl    ch,cl        ; CH := bit mask in proper position
  41.  
  42.         mov    si,bx        ; ES:SI -> regen buffer byte
  43.         xor    bl,bl        ; BL is used to accumulate the pixel value
  44.  
  45.         mov    dx,3CEh        ; DX := Graphics Controller port
  46.         mov    ax,304h        ; AH := initial bit plane number
  47.                     ; AL := Read Map Select register number
  48.  
  49. L01:        out    dx,ax        ; select bit plane
  50.         mov    bh,es:[si]    ; BH := byte from current bit plane
  51.         and    bh,ch        ; mask one bit
  52.         neg    bh        ; bit 7 of BH := 1 (if masked bit = 1)
  53.                     ; bit 7 of BH := 0 (if masked bit = 0)
  54.         rol    bx,1        ; bit 0 of BL := next bit from pixel value
  55.         dec    ah        ; AH := next bit plane number
  56.         jge    L01
  57.  
  58.         mov    al,bl        ; AL := pixel value
  59.         xor    ah,ah        ; AX := pixel value
  60.  
  61.         pop    si        ; restore caller registers and return
  62.         mov    sp,bp
  63.         pop    bp
  64.         ret
  65.  
  66. _ReadPixel10    ENDP
  67.  
  68. _TEXT        ENDS
  69.  
  70.         END
  71.