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

  1.                 TITLE   'Listing 4-1'
  2.         NAME    PixelAddr04
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        PixelAddr04
  7. ;
  8. ; Function:    Determine buffer address of pixel in 320x200 4-color mode
  9. ;
  10. ; Caller:    AX = y-coordinate (0-199)
  11. ;        BX = x-coordinate (0-319)
  12. ;
  13. ; Returns:    AH = bit mask
  14. ;        BX = byte offset in buffer
  15. ;        CL = number of bits to shift left
  16. ;        ES = video buffer segment
  17. ;
  18.  
  19.  
  20. OriginOffset    EQU    0        ; byte offset of (0,0)
  21. VideoBufferSeg    EQU    0B800h
  22.  
  23. _TEXT        SEGMENT    byte public 'CODE'
  24.         ASSUME    cs:_TEXT
  25.  
  26.         PUBLIC    PixelAddr04
  27. PixelAddr04    PROC    near
  28.  
  29.         mov    cl,bl        ; CL := low-order byte of x
  30.  
  31.         xchg    ah,al        ; AX := 100h * y
  32.         shr    ax,1        ; AL := 80h * (y&1)
  33.         add    bh,al          ; BX := x + 8000h*(y&1)
  34.         xor    al,al        ; AX := 100h*(y/2)
  35.         add    bx,ax          ; BX := x + 8000h*(y&1) + 100h*(y/2)
  36.         shr    ax,1
  37.         shr    ax,1        ; AX := 40h*(y/2)
  38.         add    bx,ax          ; BX := x + 8000h*(y&1) + 140h*(y/2)
  39.         shr    bx,1
  40.         shr    bx,1           ; BX := x/4 + 2000h*(y&1) + 50h*(y/2)
  41.         add    bx,OriginOffset    ; BX := byte offset in video buffer
  42.  
  43.         mov    ax,VideoBufferSeg
  44.         mov    es,ax        ; ES:BX := byte address of pixel
  45.  
  46.         mov    ah,3        ; AH := unshifted bit mask
  47.         and    cl,ah        ; CL := x & 3
  48.         xor    cl,ah        ; CL := 3 - (x & 3)
  49.         shl    cl,1        ; CL := # bits to shift left
  50.  
  51.         ret
  52.  
  53. PixelAddr04    ENDP
  54.  
  55. _TEXT        ENDS
  56.  
  57.         END
  58.