Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. draw_triangle:
  2.     ;----------in - eax - x1 shl 16 + y1
  3.     ;------------- -ebx - x2 shl 16 + y2
  4.     ;---------------ecx - x3 shl 16 + y3
  5.     ;---------------edx - color 0x00rrggbb
  6.     ;---------------edi - pointer to screen buffer
  7.  
  8.         .col equ ebp-4  ;dd      ?
  9.         .x1  equ ebp-6  ;dw      ?
  10.         .y1  equ  ebp-8  ;dw      ?;+8
  11.         .x2  equ  ebp-10 ;dw      ?
  12.         .y2  equ  ebp-12 ;dw      ?
  13.         .x3  equ  ebp-14  ;dw      ?
  14.         .y3  equ  ebp-16  ;dw      ?;+16
  15.         .dx12 equ  ebp-20  ;  dd      ?
  16.         .dx13 equ  ebp-24  ;  dd      ?;+24
  17.         .dx23 equ  ebp-28  ;  dd      ?
  18.  
  19.         mov     ebp,esp
  20.       ;  sub     esp,28
  21.         push    edx
  22.     .ch3:
  23.         cmp     ax,bx
  24.         jg      .ch1
  25.     .ch4:                       ; sort parameters
  26.         cmp     bx,cx
  27.         jg      .ch2
  28.         jle     .chEnd
  29.     .ch1:
  30.         xchg    eax,ebx
  31.         jmp     .ch4
  32.     .ch2:
  33.         xchg    ebx,ecx
  34.         jmp     .ch3
  35.     .chEnd:
  36.      ;   mov     dword[.y1],eax  ; ..and store to user friendly  variables
  37.      ;   mov     dword[.y2],ebx
  38.      ;   mov     dword[.y3],ecx
  39.      ;   mov     [.col],edx
  40.         push    eax
  41.         push    ebx
  42.         push    ecx
  43.         sub     esp,12
  44.         mov     edx,eax         ; eax,ebx,ecx are ORd together into edx which means that
  45.         or      edx,ebx         ; if any *one* of them is negative a sign flag is raised
  46.         or      edx,ecx
  47.         test    edx,80008000h   ; Check both X&Y at once
  48.         jne     .end_triangle
  49.  
  50.         cmp     word[.x1],SIZE_X    ; {
  51.         jg      .end_triangle
  52.         cmp     word[.x2],SIZE_X     ; This can be optimized with effort
  53.         jg      .end_triangle
  54.         cmp     word[.x3],SIZE_X
  55.         jg      .end_triangle   ; }
  56.  
  57.         shr     eax,16
  58.         shr     ebx,16
  59.         shr     ecx,16
  60.  
  61.         neg     ax              ; calculate delta 12
  62.         add     ax,bx
  63.         cwde
  64.         shl     eax,ROUND
  65.         cdq
  66.         mov     bx,[.y2]
  67.         mov     cx,[.y1]
  68.         sub     bx,cx
  69.         ;cmp     ebx,0
  70.         jne     .noZero1
  71.         mov     dword[.dx12],0
  72.         jmp     .yesZero1
  73.     .noZero1:
  74.         idiv    ebx
  75.         mov     [.dx12],eax
  76.     .yesZero1:
  77.  
  78.         mov     ax,[.x3]        ; calculate delta 13
  79.         sub     ax,[.x1]
  80.         cwde
  81.         shl     eax,ROUND
  82.         cdq
  83.         mov     bx,[.y3]
  84.         mov     cx,[.y1]
  85.         sub     bx,cx
  86.         ;cmp     ebx,0
  87.         jne     .noZero2
  88.         mov     dword[.dx13],0
  89.         jmp     .yesZero2
  90.     .noZero2:
  91.         idiv    ebx
  92.         mov     [.dx13],eax
  93.     .yesZero2:
  94.  
  95.         mov     ax,[.x3]     ; calculate delta 23 [dx23]
  96.         sub     ax,[.x2]
  97.         cwde
  98.         shl     eax,ROUND
  99.         cdq
  100.         mov     bx,[.y3]
  101.         mov     cx,[.y2]
  102.         sub     bx,cx
  103.         ;cmp     ebx,0
  104.         jne     .noZero3
  105.         mov     dword[.dx23],0
  106.         jmp     .yesZero3
  107.     .noZero3:
  108.         idiv    ebx
  109.         mov     [.dx23],eax
  110.     .yesZero3:
  111.  
  112.         movsx   eax,word[.x1]   ; eax - xk1   ;;;
  113.         shl     eax,ROUND
  114.         mov     ebx,eax         ; ebx - xk2   ;;;
  115.         movsx   esi,word[.y1]   ; esi - y
  116.     .next_line1:
  117.         mov     ecx,eax         ; ecx - x11
  118.         sar     ecx,ROUND
  119.         mov     edx,ebx         ; edx - x12
  120.         sar     edx,ROUND
  121.         cmp     ecx,edx
  122.         jle     .nochg
  123.         xchg    ecx,edx
  124.     .nochg:
  125.         pusha
  126.         mov     ebx,ecx
  127.         sub     edx,ecx
  128.         mov     ecx,edx
  129.         mov     edx,esi
  130.         mov     eax,[.col]
  131.         call    .horizontal_line
  132.         popa
  133.         add     eax,[.dx13]
  134.         add     ebx,[.dx12]
  135.         inc     esi
  136.         cmp     si,[.y2]
  137.         jl      .next_line1
  138.  
  139.         movzx   esi,word[.y2]
  140.         movzx   ebx,word[.x2]
  141.         shl     ebx,ROUND
  142.     .next_line2:
  143.         mov     ecx,eax
  144.         sar     ecx,ROUND
  145.         mov     edx,ebx
  146.         sar     edx,ROUND
  147.         cmp     ecx,edx
  148.         jle     .nochg1
  149.         xchg    ecx,edx
  150.     .nochg1:
  151.         pusha
  152.         mov     ebx,ecx
  153.         sub     edx,ecx
  154.         mov     ecx,edx
  155.         mov     edx,esi
  156.         mov     eax,[.col]
  157.         call    .horizontal_line
  158.         popa
  159.         add     eax,[.dx13]
  160.         add     ebx,[.dx23]
  161.         inc     esi
  162.         cmp     si,[.y3]
  163.         jl      .next_line2
  164.     .end_triangle:
  165.  
  166.        mov     esp,ebp
  167. ret
  168.  
  169. .horizontal_line:
  170.     ;---------in
  171.     ;---------eax - color of line,  0x00RRGGBB
  172.     ;---------ebx - x1 - x position of line begin
  173.     ;---------ecx - lenght of line
  174.     ;---------edx - y position of line
  175.     ;---------edi - pointer to buffer
  176.         jcxz    .end_hor_l
  177. ;        or      edx,edx
  178. ;        jl      .end_hor_l
  179.         cmp     edx,SIZE_Y
  180.         jg      .end_hor_l
  181.         push    eax
  182.         mov     eax,SIZE_X*3
  183.         mul     edx
  184.         add     edi,eax         ; calculate line begin adress
  185.         ;add     edi,ebx
  186.         ;shl     ebx,1
  187.         lea     edi,[edi+ebx*2]
  188.         add     edi,ebx
  189.         pop     eax
  190.         cld
  191.         ;mov dword[edi-3],0000FF00h
  192.         dec     ecx
  193.         jecxz   .last_pix
  194.     .ddraw:                     ; Drawing horizontally:
  195.         ;push    eax
  196.         stosd                   ; 4 bytes at a time
  197.         dec edi                 ; point to the 4th
  198.         loop    .ddraw
  199.     .last_pix:
  200.         stosw
  201.         shr     eax,16
  202.         stosb
  203. ;        mov     byte[edi],0     ; The last 4th will be reset
  204.     .end_hor_l:
  205. ret
  206.