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

  1.         TITLE    'Listing 4-2'
  2.         NAME    PixelAddr06
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        PixelAddr06
  7. ;
  8. ; Function:    Determine buffer address of pixel in 640x200 2-color mode
  9. ;
  10. ; Caller:    AX = y-coordinate (0-199)
  11. ;        BX = x-coordinate (0-639)
  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    PixelAddr06
  27. PixelAddr06    PROC    near
  28.  
  29.         mov    cl,bl        ; CL := low-order byte of x
  30.  
  31.         xchg    ah,al        ; AX := 100h * y
  32.         shr    bx,1        ; BX := x/2
  33.         shr    ax,1        ; AL := 80h*(y&1)
  34.         add    bh,al          ; BX := x/2 + 8000h*(y&1)
  35.         xor    al,al        ; AX := 100h*(y/2)
  36.         add    bx,ax          ; BX := x/2 + 8000h*(y&1) + 100h*(y/2)
  37.         shr    ax,1
  38.         shr    ax,1        ; AX := 40h*(y/2)
  39.         add    bx,ax          ; BX := x/2 + 8000h*(y&1) + 140h*(y/2)
  40.         shr    bx,1
  41.         shr    bx,1           ; BX := x/8 + 2000h*(y&1) + 50h*(y/2)
  42.         add    bx,OriginOffset    ; BX := byte offset in video buffer
  43.  
  44.         mov    ax,VideoBufferSeg
  45.         mov    es,ax        ; ES:BX := byte address of pixel
  46.  
  47.         and    cl,7        ; CL := x & 7
  48.         xor    cl,7        ; CL := number of bits to shift left
  49.         mov    ah,1        ; AH := unshifted bit mask
  50.  
  51.         ret
  52.  
  53. PixelAddr06    ENDP
  54.  
  55. _TEXT        ENDS
  56.  
  57.         END
  58.