home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / msc / chap_17 / wline.asm < prev    next >
Assembly Source File  |  1995-03-29  |  2KB  |  81 lines

  1.  
  2. ; this function draws a line from from xs to xe using 16 bit dat movement
  3.  
  4.  
  5. .MODEL MEDIUM,C                 ; use medium memory model C function names
  6.  
  7. .CODE                           ; begin the code segment
  8.  
  9. PUBLIC Triangle_16Line          ; export function name to linker
  10.  
  11.  
  12. Triangle_16Line PROC FAR C dest:DWORD, xs:WORD, xe:WORD, color:WORD
  13.  
  14. .386
  15.  
  16. begin:
  17.  
  18.     les di,dest               ; point es:di to start of line
  19.     add di,xs
  20.  
  21.     mov cx, color             ; cx = color | color << 8
  22.     mov ch,cl
  23.  
  24. process_left_end:
  25.  
  26.     mov ax,xs                 ; ax=xs & 0x01
  27.     and ax,01h
  28.  
  29. test_l1:
  30.  
  31.     cmp ax,1                  ; if (ax==1)
  32.     jne process_right_end
  33.  
  34.     mov es:[di], cl           ; plot pixel
  35.     inc xs                    ; xs++
  36.  
  37. process_right_end:
  38.  
  39.     les di,dest               ; point es:di to start of line
  40.     add di,xe
  41.  
  42.     mov ax,xe                 ; ax=xs & 0x01
  43.     and ax,01h
  44.  
  45. test_r0:                      ; if (ax==0)
  46.  
  47.     cmp ax,0
  48.     jne process_middle
  49.  
  50.     mov es:[di],cl            ; plot pixel
  51.  
  52.     dec xe                    ; xe-=1
  53.  
  54. process_middle:
  55.  
  56.  
  57.     les di,dest               ; point es:di to start of line
  58.     add di,xs
  59.  
  60.     cld                       ; clear the direction of movement
  61.  
  62.     mov ax, cx                ; move the color data into eax
  63.  
  64.     mov cx,xe                 ; compute number of words to move  (xe-xs+1)/2
  65.     sub cx,xs
  66.     inc cx
  67.     shr cx,1                  ; divide by 2
  68.  
  69.     rep stosw                 ; fill the region with data
  70.  
  71.     ret                       ; return to caller
  72.  
  73. Triangle_16Line ENDP
  74.  
  75. END
  76.  
  77.  
  78.  
  79.  
  80.  
  81.