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

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