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

  1.         TITLE    'Listing 4-3'
  2.         NAME    PixelAddrHGC
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        PixelAddrHGC
  7. ;
  8. ; Function:    Determine buffer address of pixel in 720x348 Hercules graphics
  9. ;
  10. ; Caller:    AX = y-coordinate (0-347)
  11. ;        BX = x-coordinate (0-719)
  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. BytesPerLine    EQU    90
  20. OriginOffset    EQU    0        ; byte offset of (0,0)
  21. VideoBufferSeg    EQU    0B000h
  22.  
  23. _TEXT        SEGMENT    byte public 'CODE'
  24.         ASSUME    cs:_TEXT
  25.  
  26.         PUBLIC    PixelAddrHGC
  27. PixelAddrHGC    PROC    near
  28.  
  29.         mov    cl,bl        ; CL := low-order byte of x
  30.  
  31.         shr    ax,1        ; AX := y/2
  32.         rcr    bx,1        ; BX := 8000h*(y&1) + x/2
  33.         shr    ax,1        ; AX := y/4
  34.         rcr    bx,1        ; BX := 4000h*(y&3) + x/4
  35.         shr    bx,1        ; BX := 2000h*(y&3) + x/8
  36.         mov    ah,BytesPerLine
  37.         mul    ah        ; AX := BytesPerLine*(y/4)
  38.         add    bx,ax        ; BX := 2000h*(y&3) + x/8 + BytesPerLine*(y/4)
  39.         add    bx,OriginOffset    ; BX := byte offset in video buffer
  40.  
  41.         mov    ax,VideoBufferSeg
  42.         mov    es,ax        ; ES:BX := byte address of pixel
  43.  
  44.         and    cl,7        ; CL := x & 7
  45.         xor    cl,7        ; CL := number of bits to shift left
  46.         mov    ah,1        ; AH := unshifted bit mask
  47.  
  48.         ret
  49.  
  50. PixelAddrHGC    ENDP
  51.  
  52. _TEXT        ENDS
  53.  
  54.         END
  55.