home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter41 / l41-5.asm < prev    next >
Assembly Source File  |  1997-06-18  |  2KB  |  54 lines

  1. ; Draws all pixels in the horizontal line segment passed in, from
  2. ;  (LeftX,Y) to (RightX,Y), in the specified color in mode 13h, the
  3. ;  VGA's 320x200 256-color mode. No drawing will take place if
  4. ;  LeftX > RightX.
  5. ; C near-callable as:
  6. ;       void DrawHorizontalLineSeg(Y, LeftX, RightX, Color);
  7. ;
  8. ; Link with L23-4.C and L23-1.C in small model.
  9. ; Tested with TASM 4.0 and Borland C++ 4.02 by Jim Mischel 12/16/94.
  10.  
  11. SCREEN_WIDTH    equ     320
  12. SCREEN_SEGMENT  equ     0a000h
  13.  
  14. Parms   struc
  15.         dw      2 dup(?) ;return address & pushed BP
  16. Y       dw      ?       ;Y coordinate of line segment to draw
  17. LeftX   dw      ?       ;left endpoint of the line segment
  18. RightX  dw      ?       ;right endpoint of the line segment
  19. Color   dw      ?       ;color in which to draw the line segment
  20. Parms   ends
  21.  
  22.         .model small
  23.         .code
  24.         public _DrawHorizontalLineSeg
  25.         align   2
  26. _DrawHorizontalLineSeg  proc
  27.         push    bp              ;preserve caller's stack frame
  28.         mov     bp,sp           ;point to our stack frame
  29.         push    di              ;preserve caller's register variable
  30.         cld                     ;make string instructions inc pointers
  31.         mov     ax,SCREEN_SEGMENT
  32.         mov     es,ax           ;point ES to display memory
  33.         mov     di,[bp+LeftX]
  34.         mov     cx,[bp+RightX]
  35.         sub     cx,di           ;width of line
  36.         jl      DrawDone        ;RightX < LeftX; no drawing to do
  37.         inc     cx              ;include both endpoints
  38.         mov     ax,SCREEN_WIDTH
  39.         mul     [bp+Y]          ;offset of scan line on which to draw
  40.         add     di,ax           ;ES:DI points to start of line seg
  41.         mov     al,byte ptr [bp+Color] ;color in which to draw
  42.         mov     ah,al           ;put color in AH for STOSW
  43.         shr     cx,1            ;# of words to fill
  44.         rep     stosw           ;fill a word at a time
  45.         adc     cx,cx
  46.         rep     stosb           ;draw the odd byte, if any
  47. DrawDone:
  48.         pop     di              ;restore caller's register variable
  49.         pop     bp              ;restore caller's stack frame
  50.         ret
  51. _DrawHorizontalLineSeg  endp
  52.         end
  53.  
  54.