home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST13-22.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  3KB  |  80 lines

  1. ;
  2. ; *** Listing 13-22 ***
  3. ;
  4. ; Replacement code for BlockDrawImage in Listing 11-34.
  5. ; This version uses in-line code to eliminate branching
  6. ; entirely during the drawing of each image (eliminates
  7. ; the branching between the drawing of each pair of lines.)
  8. ;----------------------------------------------------------
  9. ; Block-move draws the image of a 3-color square at the
  10. ; specified screen location. Assumes images start on
  11. ; even-numbered scan lines and are an even number of
  12. ; scan lines high. Always draws images byte-aligned in
  13. ; display memory.
  14. ;
  15. ; Input:
  16. ;    CX = X coordinate of upper left corner at which to
  17. ;        draw image (will be adjusted to nearest
  18. ;        less-than or equal-to multiple of 4 in order
  19. ;        to byte-align)
  20. ;    DX = Y coordinate of upper left corner at which to
  21. ;        draw image
  22. ;    ES = display memory segment
  23. ;
  24. ; Output: none
  25. ;
  26. ; Registers altered: AX, CX, DX, SI, DI, BP
  27. ;
  28. BlockDrawImage:
  29.     shr    dx,1    ;divide the row # by 2 to compensate
  30.             ; for the 2-bank nature of 320x200
  31.             ; 4-color mode
  32.     mov    ax,SCREEN_WIDTH
  33.     mul    dx    ;start offset of top row of image in
  34.             ; display memory
  35.     shr    cx,1    ;divide the X coordinate by 4
  36.     shr    cx,1    ; because there are 4 pixels per
  37.             ; byte
  38.     add    ax,cx    ;point to the offset at which the
  39.             ; upper left byte of the image will
  40.             ; go
  41.     mov    di,ax
  42.     mov    si,offset TheImage
  43.             ;point to the start of the one image
  44.             ; we always draw
  45.     mov    ax,BANK_OFFSET-SCREEN_WIDTH+IMAGE_WIDTH
  46.             ;offset from the end of an odd line
  47.             ; of the image in display memory to
  48.             ; the start of the next even line of
  49.             ; the image
  50.     mov    dx,BANK_OFFSET-IMAGE_WIDTH
  51.             ;offset from the end of an even line
  52.             ; of the image in display memory to
  53.             ; the start of the next odd line of
  54.             ; the image
  55.     mov    bp,IMAGE_WIDTH/2
  56.             ;# of words to draw per row of the
  57.             ; image. Note that IMAGE_WIDTH must
  58.             ; be an even number since we XOR
  59.             ; the image a word at a time
  60.     rept    IMAGE_HEIGHT/2
  61.     mov    cx,bp    ;# of words to draw per row of the
  62.             ; image
  63.     rep    movsw    ;draw a whole even row with this one
  64.             ; repeated instruction
  65.     add    di,dx    ;point to the start of the next
  66.             ; (odd) row of the image, which is
  67.             ; in the second bank of display
  68.             ; memory
  69.     mov    cx,bp    ;# of words to draw per row of the
  70.             ; image
  71.     rep    movsw    ;draw a whole odd row with this one
  72.             ; repeated instruction
  73.     sub    di,ax
  74.             ;point to the start of the next
  75.             ; (even) row of the image, which is
  76.             ; in the first bank of display
  77.             ; memory
  78.     endm
  79.     ret
  80.