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

  1.  
  2. ; this function draws a line from xs to xe using 32 bit data movement
  3.  
  4. .MODEL MEDIUM,                  ; use medium memory model C function names
  5.  
  6. .CODE                           ; begin the code segment
  7.  
  8. .386
  9.  
  10. PUBLIC _Triangle_32Line          ; export function name to linker
  11.  
  12.  
  13. _Triangle_32Line PROC
  14.  
  15. ARG dest:DWORD, xs:WORD, xe:WORD, color:WORD
  16.  
  17.  
  18.     push bp         ; create stack frame
  19.     mov bp,sp
  20.  
  21.     push di         ; save di
  22.  
  23.  
  24.     les di, dest    ; point es:di to start of line
  25.     add di,xs
  26.  
  27. ; process special cases first, i.e. lines of length 1,2,3 or 4
  28.  
  29. begin:
  30.  
  31.     mov ax,xe       ; ax=xs-xe;
  32.     sub ax,xs
  33.  
  34.     mov cx, color   ; cx = color | color << 8
  35.     mov ch,cl
  36.  
  37. test_0:
  38.  
  39.     cmp ax,0        ; if (ax==0)
  40.     jne test_1      ; else goto test_1
  41.  
  42.     mov es:[di],cl
  43.     ret
  44.  
  45.  
  46. test_1:
  47.  
  48.     cmp ax,1        ; if (ax==1)
  49.     jne test_2      ; else goto test_2
  50.  
  51.     mov es:[di],cx
  52.     ret
  53.  
  54.  
  55. test_2:
  56.  
  57.     cmp ax,2        ; if (ax==2)
  58.     jne test_3      ; else goto test_3
  59.  
  60.     mov es:[di],cx
  61.     add di,2
  62.     mov es:[di],cl
  63.     ret
  64.  
  65.  
  66. test_3:
  67.  
  68.     cmp ax,3                   ; if (ax==0)
  69.     jne process_left_end       ; else process left end
  70.  
  71.     mov es:[di],cx
  72.     add di,2
  73.     mov es:[di],cx
  74.     ret
  75.  
  76. process_left_end:
  77.  
  78.     mov ax,xs                  ; ax=xs & 0x03
  79.     and ax,03h
  80.  
  81. test_l1:
  82.  
  83.     cmp ax,1                   ; if (ax==1)
  84.     jne test_l2
  85.  
  86.     mov es:[di], cl
  87.     inc di
  88.     mov es:[di], cx
  89.  
  90.     add xs,3                   ; xs +=3
  91.  
  92.     jmp process_right_end
  93.  
  94. test_l2:                       ; if (ax==2)
  95.  
  96.     cmp ax,2
  97.     jne test_l3
  98.  
  99.     mov es:[di],cx
  100.  
  101.     add xs,2                   ; xs+=2
  102.  
  103.     jmp process_right_end
  104.  
  105.  
  106. test_l3:                       ; if (ax==3)
  107.  
  108.     cmp ax,3
  109.     jne process_right_end
  110.  
  111.     mov es:[di],cl
  112.  
  113.     inc xs                     ; xs+=1
  114.  
  115.  
  116. process_right_end:
  117.  
  118.     les di, dest               ; point es:di to start of line
  119.     add di,xe
  120.  
  121.     mov ax,xe                  ; ax=xs & 0x03
  122.     and ax,03h
  123.  
  124. test_r0:                       ; if (ax==0)
  125.  
  126.     cmp ax,0
  127.     jne test_r1
  128.  
  129.     mov es:[di],cl
  130.  
  131.     dec xe                     ; xe-=1
  132.  
  133.     jmp process_middle
  134.  
  135. test_r1:                       ; if (ax==1)
  136.  
  137.     cmp ax,1
  138.     jne test_r2
  139.  
  140.     dec di
  141.     mov es:[di],cx
  142.  
  143.     sub xe,2                   ; xe-=2
  144.  
  145.     jmp process_middle
  146.  
  147.  
  148. test_r2:                       ; if (ax==2)
  149.  
  150.     cmp ax,2
  151.     jne process_middle
  152.  
  153.     mov es:[di],cl
  154.     sub di,2
  155.     mov es:[di],cx
  156.  
  157.     sub xe,3                   ; xe-=3
  158.  
  159. process_middle:
  160.  
  161.  
  162.     les di,dest                ; point es:di to start of line
  163.     add di,xs
  164.  
  165.     cld                        ; clear the direction of movement
  166.  
  167.     mov eax, ecx               ; move the color data into eax
  168.     shl eax,16
  169.     or eax,ecx
  170.  
  171.     mov cx,xe                  ; compute number of words to move  (xe-xs+1)/2
  172.     sub cx,xs
  173.     inc cx
  174.     shr cx,2                   ; divide by 4
  175.  
  176.     rep stosd                  ; fill the region with data
  177.  
  178.     pop di                     ; restore di
  179.     pop bp                     ; fixup stack
  180.  
  181.     ret                        ; return to caller
  182.  
  183. Triangle_32Line ENDP
  184.  
  185. END
  186.  
  187.  
  188.  
  189.  
  190.  
  191.