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

  1.         TITLE    'Listing 5-7'
  2.         NAME    ReadPixelInC
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        ReadPixelInC
  7. ;
  8. ; Function:    Read the value of a pixel in InColor 720x348 16-color mode
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            int    ReadPixelInC(x,y);
  13. ;
  14. ;            int x,y;
  15. ;
  16.  
  17. ARGx        EQU    word ptr [bp+4]    ; stack frame addressing
  18. ARGy        EQU    word ptr [bp+6]
  19.  
  20. DefaultRWColor    EQU    0Fh        ; default value for R/W Color Register
  21.  
  22.  
  23. _TEXT        SEGMENT    byte public 'CODE'
  24.         ASSUME    cs:_TEXT
  25.  
  26.         EXTRN    PixelAddrHGC:near
  27.  
  28.         PUBLIC    _ReadPixelInC
  29. _ReadPixelInC    PROC    near
  30.  
  31.         push    bp        ; preserve caller registers
  32.         mov    bp,sp
  33.         push    si
  34.  
  35.         mov    ax,ARGy        ; AX := y
  36.         mov    bx,ARGx        ; BX := x
  37.         call    PixelAddrHGC    ; AH := bit mask
  38.                     ; ES:BX -> buffer
  39.                     ; CL := #bits to shift
  40.  
  41. ; set up to examine each bit plane separately
  42.  
  43.         mov    si,bx        ; ES:SI -> buffer
  44.  
  45.         shl    ah,cl
  46.         mov    cl,ah        ; CL := bit mask in proper position
  47.  
  48.         mov    dx,3B4h        ; DX := graphics control port
  49.  
  50.         mov    ax,0F01Ah    ; AH bits 4-7 := 1111b (background value)
  51.                     ; AL := 1Ah (R/W Color Register)
  52.         out    dx,ax        ; set background value
  53.  
  54.         mov    bx,800h        ; BH := 1000b (initial "don't care" bits)
  55.                     ; BL := 0 (initial value for result)
  56.  
  57.         dec    ax        ; AL := 19h (R/W Control Register number)
  58.  
  59. ; loop across bit planes by updating "don't care" bits
  60.  
  61. L01:        mov    ah,bh        ; AH bits 0-3 := next "don't care" bits
  62.                     ; AH bit 6 := 0 (Mask Polarity bit)
  63.         xor    ah,1111b    ; invert "don't care" bits
  64.         out    dx,ax        ; set R/W Control Register
  65.  
  66.         mov    ch,cl        ; CH := bit mask
  67.         and    ch,es:[si]    ; latch bit planes
  68.                     ; CH <> 0 if bit in latch is set
  69.  
  70.         neg    ch        ; cf set if CH <> 0
  71.         rcl    bl,1        ; accumulate result in BL
  72.  
  73.         shr    bh,1        ; BH := shifted "don't care" bits
  74.         jnz    L01        ; loop until shifted out of BH,
  75.                     ;  at which point BX = pixel value
  76. ; restore default state
  77.  
  78.         mov    ah,40h        ; AH := default R/W Control Register value
  79.         out    dx,ax
  80.  
  81.         inc    ax        ; AL := 1Ah (R/W Color Register number)
  82.         mov    ah,DefaultRWColor
  83.         out    dx,ax
  84.  
  85.         mov    ax,bx        ; AX := pixel value
  86.  
  87.         pop    si        ; restore caller registers and return
  88.         mov    sp,bp
  89.         pop    bp
  90.         ret
  91.  
  92. _ReadPixelInC    ENDP
  93.  
  94. _TEXT        ENDS
  95.  
  96.         END
  97.