home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / borland / chap_17 / wline.asm < prev    next >
Encoding:
Assembly Source File  |  1995-05-25  |  1.8 KB  |  94 lines

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