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

  1.         TITLE    'Listing 4-4'
  2.         NAME    PixelAddr10
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        PixelAddr10
  7. ;
  8. ; Function:    Determine buffer address of pixel in native EGA and VGA modes:
  9. ;            320x200 16-color
  10. ;            640x200 16-color
  11. ;            640x350 16-color
  12. ;            640x350 monochrome (4-color)
  13. ;            640x480 2-color
  14. ;            640x480 16-color
  15. ;
  16. ; Caller:    AX = y-coordinate
  17. ;        BX = x-coordinate
  18. ;
  19. ; Returns:    AH = bit mask
  20. ;        BX = byte offset in buffer
  21. ;        CL = number of bits to shift left
  22. ;        ES = video buffer segment
  23. ;
  24.  
  25.  
  26. BytesPerLine    EQU    80        ; bytes in one horizontal line
  27. OriginOffset    EQU    0        ; byte offset of (0,0)
  28. VideoBufferSeg    EQU    0A000h
  29.  
  30. _TEXT        SEGMENT    byte public 'CODE'
  31.         ASSUME    cs:_TEXT
  32.  
  33.         PUBLIC    PixelAddr10
  34. PixelAddr10    PROC    near
  35.  
  36.         mov    cl,bl        ; CL := low-order byte of x
  37.  
  38.         push    dx        ; preserve DX
  39.  
  40.         mov    dx,BytesPerLine    ; AX := y * BytesPerLine
  41.         mul    dx
  42.  
  43.         pop    dx
  44.         shr    bx,1
  45.         shr    bx,1
  46.         shr    bx,1        ; BX := x/8
  47.         add    bx,ax        ; BX := y*BytesPerLine + x/8
  48.         add    bx,OriginOffset    ; BX := byte offset in video buffer
  49.  
  50.         mov    ax,VideoBufferSeg
  51.         mov    es,ax        ; ES:BX := byte address of pixel
  52.  
  53.         and    cl,7        ; CL := x & 7
  54.         xor    cl,7        ; CL := number of bits to shift left
  55.         mov    ah,1        ; AH := unshifted bit mask
  56.         ret
  57.  
  58. PixelAddr10    ENDP
  59.  
  60. _TEXT        ENDS
  61.  
  62.         END
  63.