Subversion Repositories Kolibri OS

Rev

Rev 1245 | Go to most recent revision | 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.         mov     dx,[size_x_var]
  51.         cmp     word[.x1],dx  ;SIZE_X    ; {
  52.         jg      .end_triangle
  53.         cmp     word[.x2],dx  ;SIZE_X     ; This can be optimized with effort
  54.         jg      .end_triangle
  55.         cmp     word[.x3],dx  ;SIZE_X
  56.         jg      .end_triangle   ; }
  57.  
  58.         shr     eax,16
  59.         shr     ebx,16
  60.         shr     ecx,16
  61.  
  62.         neg     ax              ; calculate delta 12
  63.         add     ax,bx
  64.         cwde
  65.         shl     eax,ROUND
  66.         cdq
  67.         mov     bx,[.y2]
  68.         mov     cx,[.y1]
  69.         sub     bx,cx
  70.         ;cmp     ebx,0
  71.         jne     .noZero1
  72.         mov     dword[.dx12],0
  73.         jmp     .yesZero1
  74.     .noZero1:
  75.         idiv    ebx
  76.         mov     [.dx12],eax
  77.     .yesZero1:
  78.  
  79.         mov     ax,[.x3]        ; calculate delta 13
  80.         sub     ax,[.x1]
  81.         cwde
  82.         shl     eax,ROUND
  83.         cdq
  84.         mov     bx,[.y3]
  85.         mov     cx,[.y1]
  86.         sub     bx,cx
  87.         ;cmp     ebx,0
  88.         jne     .noZero2
  89.         mov     dword[.dx13],0
  90.         jmp     .yesZero2
  91.     .noZero2:
  92.         idiv    ebx
  93.         mov     [.dx13],eax
  94.     .yesZero2:
  95.  
  96.         mov     ax,[.x3]     ; calculate delta 23 [dx23]
  97.         sub     ax,[.x2]
  98.         cwde
  99.         shl     eax,ROUND
  100.         cdq
  101.         mov     bx,[.y3]
  102.         mov     cx,[.y2]
  103.         sub     bx,cx
  104.         ;cmp     ebx,0
  105.         jne     .noZero3
  106.         mov     dword[.dx23],0
  107.         jmp     .yesZero3
  108.     .noZero3:
  109.         idiv    ebx
  110.         mov     [.dx23],eax
  111.     .yesZero3:
  112.  
  113.         movsx   eax,word[.x1]   ; eax - xk1   ;;;
  114.         shl     eax,ROUND
  115.         mov     ebx,eax         ; ebx - xk2   ;;;
  116.         movsx   esi,word[.y1]   ; esi - y
  117.     .next_line1:
  118.         mov     ecx,eax         ; ecx - x11
  119.         sar     ecx,ROUND
  120.         mov     edx,ebx         ; edx - x12
  121.         sar     edx,ROUND
  122.         cmp     ecx,edx
  123.         jle     .nochg
  124.         xchg    ecx,edx
  125.     .nochg:
  126.         pusha
  127.         mov     ebx,ecx
  128.         sub     edx,ecx
  129.         mov     ecx,edx
  130.         mov     edx,esi
  131.         mov     eax,[.col]
  132.         call    .horizontal_line
  133.         popa
  134.         add     eax,[.dx13]
  135.         add     ebx,[.dx12]
  136.         inc     esi
  137.         cmp     si,[.y2]
  138.         jl      .next_line1
  139.  
  140.         movzx   esi,word[.y2]
  141.         movzx   ebx,word[.x2]
  142.         shl     ebx,ROUND
  143.     .next_line2:
  144.         mov     ecx,eax
  145.         sar     ecx,ROUND
  146.         mov     edx,ebx
  147.         sar     edx,ROUND
  148.         cmp     ecx,edx
  149.         jle     .nochg1
  150.         xchg    ecx,edx
  151.     .nochg1:
  152.         pusha
  153.         mov     ebx,ecx
  154.         sub     edx,ecx
  155.         mov     ecx,edx
  156.         mov     edx,esi
  157.         mov     eax,[.col]
  158.         call    .horizontal_line
  159.         popa
  160.         add     eax,[.dx13]
  161.         add     ebx,[.dx23]
  162.         inc     esi
  163.         cmp     si,[.y3]
  164.         jl      .next_line2
  165.     .end_triangle:
  166.  
  167.        mov     esp,ebp
  168. ret
  169.  
  170. .horizontal_line:
  171.     ;---------in
  172.     ;---------eax - color of line,  0x00RRGGBB
  173.     ;---------ebx - x1 - x position of line begin
  174.     ;---------ecx - lenght of line
  175.     ;---------edx - y position of line
  176.     ;---------edi - pointer to buffer
  177.         jcxz    .end_hor_l
  178. ;        or      edx,edx
  179. ;        jl      .end_hor_l
  180.         movzx   esi,word[size_y_var]
  181.         cmp     edx,esi  ;SIZE_Y
  182.         jg      .end_hor_l
  183.         push    eax
  184.         movzx   eax,word[size_x_var]
  185.         lea     eax,[eax*3]
  186.    ;     mov     eax,SIZE_X*3
  187.         mul     edx
  188.         add     edi,eax         ; calculate line begin adress
  189.         ;add     edi,ebx
  190.         ;shl     ebx,1
  191.         lea     edi,[edi+ebx*2]
  192.         add     edi,ebx
  193.         pop     eax
  194.         cld
  195.         ;mov dword[edi-3],0000FF00h
  196.         dec     ecx
  197.         jecxz   .last_pix
  198.     .ddraw:                     ; Drawing horizontally:
  199.         ;push    eax
  200.         stosd                   ; 4 bytes at a time
  201.         dec edi                 ; point to the 4th
  202.         loop    .ddraw
  203.     .last_pix:
  204.         stosw
  205.         shr     eax,16
  206.         stosb
  207. ;        mov     byte[edi],0     ; The last 4th will be reset
  208.     .end_hor_l:
  209. ret
  210.