From 73122f1cb1e88544cf35140b11fa6f1d0bb54237 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 12 May 2021 00:26:00 +0000 Subject: [PATCH] view3ds 0073 by macgub git-svn-id: svn://kolibrios.org@8719 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/demos/view3ds/3dmath.inc | 1166 +++-- programs/demos/view3ds/3stencil.inc | 656 +-- programs/demos/view3ds/a_procs.inc | 1604 +++--- programs/demos/view3ds/b_procs.inc | 2639 +++++----- programs/demos/view3ds/data.inc | 1115 ++-- programs/demos/view3ds/grd_line.inc | 758 +-- programs/demos/view3ds/history.txt | 10 + programs/demos/view3ds/readme.txt | 29 +- programs/demos/view3ds/view3ds.asm | 7325 +++++++++++++-------------- 9 files changed, 7546 insertions(+), 7756 deletions(-) diff --git a/programs/demos/view3ds/3dmath.inc b/programs/demos/view3ds/3dmath.inc index 43b492b324..5a52eb5b0a 100644 --- a/programs/demos/view3ds/3dmath.inc +++ b/programs/demos/view3ds/3dmath.inc @@ -1,592 +1,574 @@ -x3d equ 0 -y3d equ 2 -z3d equ 4 -vec_x equ 0 -vec_y equ 4 -vec_z equ 8 -; 3d point - triple integer word coordinate -; vector - triple float dword coordinate -;----------------------in: -------------------------------- -;------------------------ esi - pointer to 1st 3d point --- -;------------------------ edi - pointer to 2nd 3d point --- -;------------------------ ebx - pointer to result vector -- -;---------------------- out : none ------------------------ -reverse_mx_3x3: -; esi - source matrix -; edi - desired reversed matrix - - push ebp - mov ebp,esp - sub esp,4 - .det equ ebp-4 - - fninit - fld dword[esi] - fmul dword[esi+16] - fmul dword[esi+32] - fld dword[esi+12] - fmul dword[esi+28] - fmul dword[esi+8] - faddp - fld dword[esi+24] - fmul dword[esi+4] - fmul dword[esi+20] - faddp - fld dword[esi] - fmul dword[esi+28] - fmul dword[esi+20] - fchs - faddp - fld dword[esi+24] - fmul dword[esi+16] - fmul dword[esi+8] - fchs - faddp - fld dword[esi+12] - fmul dword[esi+4] - fmul dword[esi+32] - fchs - faddp - fstp dword[.det] - cmp dword[.det],0 - jne @f - int3 - @@: - ; fld1 - ; fdiv dword[.det] - ; fstp dword[.det] - - fld dword[esi+16] - fmul dword[esi+32] - fld dword[esi+20] - fmul dword[esi+28] - fchs - faddp - fdiv dword[.det] - fstp dword[edi] - - fld dword[esi+8] - fmul dword[esi+28] - fld dword[esi+4] - fmul dword[esi+32] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+4] - - fld dword[esi+4] - fmul dword[esi+20] - fld dword[esi+8] - fmul dword[esi+16] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+8] - - fld dword[esi+20] - fmul dword[esi+24] - fld dword[esi+12] - fmul dword[esi+32] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+12] - - fld dword[esi] - fmul dword[esi+32] - fld dword[esi+8] - fmul dword[esi+24] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+16] - - fld dword[esi+8] - fmul dword[esi+12] - fld dword[esi] - fmul dword[esi+20] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+20] - - fld dword[esi+12] - fmul dword[esi+28] - fld dword[esi+16] - fmul dword[esi+24] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+24] - - fld dword[esi+4] - fmul dword[esi+24] - fld dword[esi] - fmul dword[esi+28] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+28] - - fld dword[esi] - fmul dword[esi+16] - fld dword[esi+4] - fmul dword[esi+12] - fchs - faddp - fdiv dword[.det] - fstp dword[edi+32] - - - mov esp,ebp - pop ebp -ret - -make_vector_r: - if Ext < SSE2 - fninit - fld dword[edi] ;edi+x3d - fsub dword[esi] ;esi+x3d - fstp dword[ebx+vec_x] - - fld dword[edi+4] - fsub dword[esi+4] - fstp dword[ebx+vec_y] - - fld dword[edi+8] - fsub dword[esi+8] - fstp dword[ebx+vec_z] - else - movups xmm0,[esi] - movups xmm1,[edi] - subps xmm1,xmm0 - movlps [ebx],xmm1 - movhlps xmm1,xmm1 - movss [ebx+8],xmm1 - end if - -ret -;---------------------- in: ------------------------------- -;--------------------------- esi - pointer to 1st vector -- -;--------------------------- edi - pointer to 2nd vector -- -;--------------------------- ebx - pointer to result vector -;---------------------- out : none -cross_product: - fninit - fld dword [esi+vec_y] - fmul dword [edi+vec_z] - fld dword [esi+vec_z] - fmul dword [edi+vec_y] - fsubp ;st1 ,st - fstp dword [ebx+vec_x] - - fld dword [esi+vec_z] - fmul dword [edi+vec_x] - fld dword [esi+vec_x] - fmul dword [edi+vec_z] - fsubp ;st1 ,st - fstp dword [ebx+vec_y] - - fld dword [esi+vec_x] - fmul dword [edi+vec_y] - fld dword [esi+vec_y] - fmul dword [edi+vec_x] - fsubp ;st1 ,st - fstp dword [ebx+vec_z] -ret -;----------------------- in: ------------------------------ -;---------------------------- edi - pointer to vector ----- -;----------------------- out : none -normalize_vector: -if Ext = SSE2 | Ext = SSE | Ext = SSE3 - movups xmm0,[edi] - andps xmm0,[zero_hgst_dd] - movups xmm1,xmm0 - mulps xmm0,xmm0 - movhlps xmm2,xmm0 - addps xmm0,xmm2 - movaps xmm2,xmm0 - shufps xmm2,xmm2,11100001b - addps xmm0,xmm2 - shufps xmm0,xmm0,0 - rsqrtps xmm0,xmm0 - mulps xmm0,xmm1 - movlps [edi],xmm0 - movhlps xmm0,xmm0 - movss [edi+8],xmm0 -end if -if 0 ; Ext >= SSE3 - movups xmm0,[edi] - andps xmm0,[zero_hgst_dd] - movups xmm1,xmm0 - mulps xmm0,xmm0 - haddps xmm0,xmm0 - haddps xmm0,xmm0 - rsqrtps xmm0,xmm0 - mulps xmm0,xmm1 - movlps [edi],xmm0 - movhlps xmm0,xmm0 - movss [edi+8],xmm0 -end if -if Ext < SSE - - fninit - fld dword [edi+vec_x] - fmul st, st - fld dword [edi+vec_y] - fmul st, st - fld dword [edi+vec_z] - fmul st, st - faddp st1, st - faddp st1, st - fsqrt - - ftst - fstsw ax - sahf - jnz @f - - fst dword [edi+vec_x] - fst dword [edi+vec_y] - fstp dword [edi+vec_z] - ret - @@: - fld st - fld st - fdivr dword [edi+vec_x] - fstp dword [edi+vec_x] - fdivr dword [edi+vec_y] - fstp dword [edi+vec_y] - fdivr dword [edi+vec_z] - fstp dword [edi+vec_z] -end if -ret -;------------------in: ------------------------- -;------------------ esi - pointer to 1st vector -;------------------ edi - pointer to 2nd vector -;------------------out: ------------------------ -;------------------ st0 - dot-product -dot_product: - fninit -;if Ext >=SSE3 -; movups xmm0,[esi] -; movups xmm1,[edi] -; andps xmm0,[zero_hgst_dd] -; mulps xmm0,xmm1 -; haddps xmm0,xmm0 -; haddps xmm0,xmm0 -; movss [esp-4],xmm0 -; fld dword[esp-4] -;else - fld dword [esi+vec_x] - fmul dword [edi+vec_x] - fld dword [esi+vec_y] - fmul dword [edi+vec_y] - fld dword [esi+vec_z] - fmul dword [edi+vec_z] - faddp - faddp -;end if -ret - -; DOS version Coded by Mikolaj Felix aka Majuma -; mfelix@polbox.com -; www.majuma.xt.pl -; into FASM translation by Macgub -init_sincos_tab: -.counter equ dword [ebp-4] ; cur angle - - push ebp - mov ebp,esp - - xor eax,eax - push eax ; init .counter - mov edi,cos_tab - mov esi,sin_tab - mov ecx,256 - fninit - - fld .counter - @@: - fld st - fsincos - fstp dword [edi] - fstp dword [esi] -; fadd [piD180] - fadd [piD128] - add esi,4 - add edi,4 - loop @b - ffree st - - mov esp,ebp - pop ebp -ret -;------ -; esi - offset (pointer) to angles, edi offset to 3x3 matrix -make_rotation_matrix: - .sinx equ dword[ebp-4] - .cosx equ dword[ebp-8] - .siny equ dword[ebp-12] - .cosy equ dword[ebp-16] - .sinz equ dword[ebp-20] - .cosz equ dword[ebp-24] - push ebp - mov ebp,esp - sub esp,24 - - movzx ebx,word[esi] - shl ebx,2 - mov eax,dword[sin_tab+ebx] - mov .sinx,eax - mov edx,dword[cos_tab+ebx] - mov .cosx,edx - - movzx ebx,word[esi+2] - shl ebx,2 - mov eax,dword[sin_tab+ebx] - mov .siny,eax - mov edx,dword[cos_tab+ebx] - mov .cosy,edx - - movzx ebx,word[esi+4] - shl ebx,2 - mov eax,dword[sin_tab+ebx] - mov .sinz,eax - mov edx,dword[cos_tab+ebx] - mov .cosz,edx - - fninit - fld .cosy - fmul .cosz - fstp dword[edi] - - fld .sinx - fmul .siny - fmul .cosz - fld .cosx - fmul .sinz - fchs - faddp - fstp dword[edi+12] - - fld .cosx - fmul .siny - fmul .cosz - fld .sinx - fmul .sinz - faddp - fstp dword[edi+24] - - fld .cosy - fmul .sinz - fstp dword[edi+4] - - fld .sinx - fmul .siny - fmul .sinz - fld .cosx - fmul .cosz - faddp - fstp dword[edi+16] - - fld .cosx - fmul .siny - fmul .sinz - fld .sinx - fchs - fmul .cosz - faddp - fstp dword[edi+28] - - fld .siny - fchs - fstp dword[edi+8] - - fld .cosy - fmul .sinx - fstp dword[edi+20] - - fld .cosx - fmul .cosy - fstp dword[edi+32] - - mov esp,ebp - pop ebp -ret -;--------------------- -; in: esi - ptr to points(normals], each point(normal) coeficient as dword -; edi - ptr to rotated points(normals) -; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix -; ecx - number of points(normals) -rotary: -if Ext= SSE3 + movups xmm0,[edi] + andps xmm0,[zero_hgst_dd] + movups xmm1,xmm0 + mulps xmm0,xmm0 + haddps xmm0,xmm0 + haddps xmm0,xmm0 + rsqrtps xmm0,xmm0 + mulps xmm0,xmm1 + movlps [edi],xmm0 + movhlps xmm0,xmm0 + movss [edi+8],xmm0 +else + + fninit + fld dword [edi+vec_x] + fmul st, st + fld dword [edi+vec_y] + fmul st, st + fld dword [edi+vec_z] + fmul st, st + faddp st1, st + faddp st1, st + fsqrt + + ftst + fstsw ax + sahf + jnz @f + + fst dword [edi+vec_x] + fst dword [edi+vec_y] + fstp dword [edi+vec_z] + ret + @@: + fld st + fld st + fdivr dword [edi+vec_x] + fstp dword [edi+vec_x] + fdivr dword [edi+vec_y] + fstp dword [edi+vec_y] + fdivr dword [edi+vec_z] + fstp dword [edi+vec_z] +end if +ret +;------------------in: ------------------------- +;------------------ esi - pointer to 1st vector +;------------------ edi - pointer to 2nd vector +;------------------out: ------------------------ +;------------------ st0 - dot-product +dot_product: + fninit +;if Ext >=SSE3 +; movups xmm0,[esi] +; movups xmm1,[edi] +; andps xmm0,[zero_hgst_dd] +; mulps xmm0,xmm1 +; haddps xmm0,xmm0 +; haddps xmm0,xmm0 +; movss [esp-4],xmm0 +; fld dword[esp-4] +;else + fld dword [esi+vec_x] + fmul dword [edi+vec_x] + fld dword [esi+vec_y] + fmul dword [edi+vec_y] + fld dword [esi+vec_z] + fmul dword [edi+vec_z] + faddp + faddp +;end if +ret + +; DOS version Coded by Mikolaj Felix aka Majuma +; mfelix@polbox.com +; www.majuma.xt.pl +; into FASM translation by Macgub +init_sincos_tab: +.counter equ dword [ebp-4] ; cur angle + + push ebp + mov ebp,esp + + xor eax,eax + push eax ; init .counter + mov edi,cos_tab + mov esi,sin_tab + mov ecx,256 + fninit + + fld .counter + @@: + fld st + fsincos + fstp dword [edi] + fstp dword [esi] +; fadd [piD180] + fadd [piD128] + add esi,4 + add edi,4 + loop @b + ffree st + + mov esp,ebp + pop ebp +ret +;------ +; esi - offset (pointer) to angles, edi offset to 3x3 matrix +make_rotation_matrix: + .sinx equ dword[ebp-4] + .cosx equ dword[ebp-8] + .siny equ dword[ebp-12] + .cosy equ dword[ebp-16] + .sinz equ dword[ebp-20] + .cosz equ dword[ebp-24] + push ebp + mov ebp,esp + sub esp,24 + + movzx ebx,word[esi] + shl ebx,2 + mov eax,dword[sin_tab+ebx] + mov .sinx,eax + mov edx,dword[cos_tab+ebx] + mov .cosx,edx + + movzx ebx,word[esi+2] + shl ebx,2 + mov eax,dword[sin_tab+ebx] + mov .siny,eax + mov edx,dword[cos_tab+ebx] + mov .cosy,edx + + movzx ebx,word[esi+4] + shl ebx,2 + mov eax,dword[sin_tab+ebx] + mov .sinz,eax + mov edx,dword[cos_tab+ebx] + mov .cosz,edx + + fninit + fld .cosy + fmul .cosz + fstp dword[edi] + + fld .sinx + fmul .siny + fmul .cosz + fld .cosx + fmul .sinz + fchs + faddp + fstp dword[edi+12] + + fld .cosx + fmul .siny + fmul .cosz + fld .sinx + fmul .sinz + faddp + fstp dword[edi+24] + + fld .cosy + fmul .sinz + fstp dword[edi+4] + + fld .sinx + fmul .siny + fmul .sinz + fld .cosx + fmul .cosz + faddp + fstp dword[edi+16] + + fld .cosx + fmul .siny + fmul .sinz + fld .sinx + fchs + fmul .cosz + faddp + fstp dword[edi+28] + + fld .siny + fchs + fstp dword[edi+8] + + fld .cosy + fmul .sinx + fstp dword[edi+20] + + fld .cosx + fmul .cosy + fstp dword[edi+32] + + mov esp,ebp + pop ebp +ret +;--------------------- +; in: esi - ptr to points(normals], each point(normal) coeficient as dword +; edi - ptr to rotated points(normals) +; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix +; ecx - number of points(normals) +rotary: +if Ext hi z1, z2, z3 as dword float - -.x1 equ [ebp-2] -.y1 equ [ebp-4] -.x2 equ [ebp-6] -.y2 equ [ebp-8] -.x3 equ [ebp-10] -.y3 equ [ebp-12] - -.dx12 equ dword[ebp-20] -.dx13 equ dword[ebp-24] -.dx23 equ dword[ebp-28] -.dz12 equ dword[ebp-32] -.dz13 equ dword[ebp-36] -.dz23 equ dword[ebp-40] -.zz2 equ [ebp-44] -.zz1 equ [ebp-48] -.z3 equ [ebp-56] -.z2 equ [ebp-60] -.z1 equ [ebp-64] -.s_buff equ [ebp-68] - - push ebp - mov ebp,esp - sub esp,128 - and ebp,0xfffffff0 - .sort2: - cmp ax,bx - jle .sort1 - xchg eax,ebx - shufps xmm0,xmm0,11100001b - .sort1: - cmp bx,cx - jle .sort3 - xchg ebx,ecx - shufps xmm0,xmm0,11011000b - jmp .sort2 - .sort3: - mov .y1,eax ; store triangle coordinates in user friendly variables - mov .y2,ebx - mov .y3,ecx - - ; mov edx,100.11 - ; movd xmm0,edx - ; shufps xmm0,xmm0,11100000b - - movaps .z1,xmm0 - ; mov dword .z1,edx - ; mov .z2,edx - ; mov .z3,edx - mov .s_buff,esi - - mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that - and edx,ebx ; if *all* of them are negative a sign flag is raised - and edx,ecx - and edx,eax - test edx,80008000h ; Check both X&Y at once - jne .loop2_end - - mov bx,.y2 ; calc delta 12 - sub bx,.y1 - jnz .dx12_make - mov .dx12,0 - mov .dz12,0 - jmp .dx12_done - .dx12_make: - mov ax,.x2 - sub ax,.x1 - cwde - movsx ebx,bx - shl eax,ROUND2 - cdq - idiv ebx - mov .dx12,eax - - movss xmm1,.z2 - cvtsi2ss xmm2,ebx - subss xmm1,.z1 - divss xmm1,xmm2 - movss .dz12,xmm1 - ; mov .dz12, dword 0.11 - - .dx12_done: - mov bx,.y3 ; calc delta 13 - sub bx,.y1 - jnz .dx13_make - mov .dx13,0 - mov .dz13,0 - jmp .dx13_done - .dx13_make: - mov ax,.x3 - sub ax,.x1 - cwde - movsx ebx,bx - shl eax,ROUND2 - cdq - idiv ebx - mov .dx13,eax - - movss xmm1,.z3 - cvtsi2ss xmm2,ebx - subss xmm1,.z1 - divss xmm1,xmm2 - movss .dz13,xmm1 - ; mov .dz13, dword 0.11 - - .dx13_done: - mov bx,.y3 ; calc delta 23 - sub bx,.y2 - jnz .dx23_make - mov .dx23,0 - mov .dz23,0 - jmp .dx23_done - .dx23_make: - mov ax,.x3 - sub ax,.x2 - cwde - movsx ebx,bx - shl eax,ROUND2 - cdq - idiv ebx - mov .dx23,eax - - movss xmm1,.z3 - cvtsi2ss xmm2,ebx - subss xmm1,.z2 - divss xmm1,xmm2 - movss .dz23,xmm1 - - .dx23_done: - mov edx,.z1 - - mov .zz1,edx - mov .zz2,edx - movsx eax,word .x1 - shl eax,ROUND2 ; eax - cur x1 - mov ebx,eax ; ebx - cur x2 - - mov cx,.y1 - cmp cx,.y2 - jge .loop1_end - .loop1: - - pushad - sar ebx,ROUND2 - sar eax,ROUND2 - ; movq xmm0,.zz1 - movlps xmm0,.zz1 - ; mov edx,0.11 - ; movd xmm0,edx - ; shufps xmm0,xmm0,11100000b - mov esi,.s_buff - - call stencil_line - - popad - add eax,.dx13 - add ebx,.dx12 - - movss xmm1,.zz1 - movss xmm2,.zz2 - addss xmm1,.dz13 - addss xmm2,.dz12 - movss .zz1,xmm1 - movss .zz2,xmm2 - - add cx,1 - cmp cx,.y2 - jl .loop1 - - .loop1_end: - - mov edx,.z2 - mov .zz2,edx - movsx ebx,word .x2 - shl ebx,ROUND2 - - mov cx,.y2 - cmp cx,.y3 - jge .loop2_end - .loop2: - pushad - - sar ebx,ROUND2 - sar eax,ROUND2 - movlps xmm0,.zz1 - mov esi,.s_buff - - - call stencil_line - - popad - - add eax,.dx13 - add ebx,.dx23 - - movss xmm1,.zz1 - movss xmm2,.zz2 - addss xmm1,.dz13 - addss xmm2,.dz23 - movss .zz1,xmm1 - movss .zz2,xmm2 - - - add cx,1 - cmp cx,.y3 - jl .loop2 - .loop2_end: - - add esp,128 - pop ebp - -ret - -stencil_line: -;---------------------------------------------------- -;-------------in xmm0 - lo -> hi z1, z2 -;--------------- eax - x1 --------------------------- -;--------------- ebx - x2 --------------------------- -;--------------- ecx - y----------------------------- -;--------------- esi - pointer to s-buffer - - -.dz equ [ebp-4] -.z2 equ [ebp-8] -.z1 equ [ebp-12] -.x2 equ [ebp-16] -.x1 equ [ebp-20] -.s_buf equ [ebp-24] -; cmp eax,ebx -; je @f -; int3 -; @@: - push ebp - mov ebp,esp - sub esp,64 - ; cmp eax,0 - ; jg @f - ; - ; @@: - or cx,cx - jle .l_quit - - cmp cx,[size_y_var] - jge .l_quit - - movzx ecx,cx - mov .s_buf,esi - cmp eax,ebx - je .l_quit - jl .l_ok - - xchg eax,ebx - shufps xmm0,xmm0,11100001b - .l_ok: - - cmp ax,[size_x_var] - jge .l_quit - cmp bx,0 - jle .l_quit - - movlps .z1,xmm0 - mov .x1,eax - mov .x2,ebx - - sub ebx,eax - movss xmm0,.z2 - cvtsi2ss xmm1,ebx - subss xmm0,.z1 - divss xmm0,xmm1 - movss .dz,xmm0 - - movzx edx,word[size_x_var] - cmp eax,1 - jge @f - mov eax,.x1 - neg eax - cvtsi2ss xmm2,eax - mulss xmm2,.dz - addss xmm2,.z1 - movss .z1,xmm2 - mov dword .x1,0 - movzx edx,word[size_x_var] - sub edx,1 - @@: - cmp .x2,edx - jl @f - mov .x2,edx - - @@: - ; mov eax,.x1 - ; cmp .x2,eax - ; je .l_quit - movzx edx,word[size_x_var] - mov esi,.s_buf - mov eax,ecx ; y - mul edx - add eax,.x1 - - shl eax,2 - add esi,eax - - mov ecx,.x2 - sub ecx,.x1 - movss xmm2,.z1 ; cz - .ccalc: - ; movss xmm1,xmm2 - comiss xmm2,dword[esi] - jg @f - movss dword[esi],xmm2 - @@: - add esi,4 - addss xmm2,.dz - sub ecx,1 - jnz .ccalc - .l_quit: - mov esp,ebp - pop ebp -ret +ROUND2 equ 10 + +stencil_tri: +; procedure calculate triangle in stencil buffer +; ----------------in - eax - x1 shl 16 + y1 ---------------------- +; -------------------- ebx - x2 shl 16 + y2 ---------------------- +; -------------------- ecx - x3 shl 16 + y3 ---------------------- +; -------------------- esi - pointer to s-buffer ----------------- +; -------------------- xmm0 - lo -> hi z1, z2, z3 as dword float + +.x1 equ [ebp-2] +.y1 equ [ebp-4] +.x2 equ [ebp-6] +.y2 equ [ebp-8] +.x3 equ [ebp-10] +.y3 equ [ebp-12] + +.dx12 equ dword[ebp-20] +.dx13 equ dword[ebp-24] +.dx23 equ dword[ebp-28] +.dz12 equ dword[ebp-32] +.dz13 equ dword[ebp-36] +.dz23 equ dword[ebp-40] +.zz2 equ [ebp-44] +.zz1 equ [ebp-48] +.z3 equ [ebp-56] +.z2 equ [ebp-60] +.z1 equ [ebp-64] +.s_buff equ [ebp-68] + + push ebp + mov ebp,esp + sub esp,128 + and ebp,0xfffffff0 + .sort2: + cmp ax,bx + jle .sort1 + xchg eax,ebx + shufps xmm0,xmm0,11100001b + .sort1: + cmp bx,cx + jle .sort3 + xchg ebx,ecx + shufps xmm0,xmm0,11011000b + jmp .sort2 + .sort3: + mov .y1,eax ; store triangle coordinates in user friendly variables + mov .y2,ebx + mov .y3,ecx + + ; mov edx,100.11 + ; movd xmm0,edx + ; shufps xmm0,xmm0,11100000b + + movaps .z1,xmm0 + ; mov dword .z1,edx + ; mov .z2,edx + ; mov .z3,edx + mov .s_buff,esi + + mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that + and edx,ebx ; if *all* of them are negative a sign flag is raised + and edx,ecx + and edx,eax + test edx,80008000h ; Check both X&Y at once + jne .loop2_end + + mov bx,.y2 ; calc delta 12 + sub bx,.y1 + jnz .dx12_make + mov .dx12,0 + mov .dz12,0 + jmp .dx12_done + .dx12_make: + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND2 + cdq + idiv ebx + mov .dx12,eax + + movss xmm1,.z2 + cvtsi2ss xmm2,ebx + subss xmm1,.z1 + divss xmm1,xmm2 + movss .dz12,xmm1 + ; mov .dz12, dword 0.11 + + .dx12_done: + mov bx,.y3 ; calc delta 13 + sub bx,.y1 + jnz .dx13_make + mov .dx13,0 + mov .dz13,0 + jmp .dx13_done + .dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND2 + cdq + idiv ebx + mov .dx13,eax + + movss xmm1,.z3 + cvtsi2ss xmm2,ebx + subss xmm1,.z1 + divss xmm1,xmm2 + movss .dz13,xmm1 + ; mov .dz13, dword 0.11 + + .dx13_done: + mov bx,.y3 ; calc delta 23 + sub bx,.y2 + jnz .dx23_make + mov .dx23,0 + mov .dz23,0 + jmp .dx23_done + .dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND2 + cdq + idiv ebx + mov .dx23,eax + + movss xmm1,.z3 + cvtsi2ss xmm2,ebx + subss xmm1,.z2 + divss xmm1,xmm2 + movss .dz23,xmm1 + + .dx23_done: + mov edx,.z1 + + mov .zz1,edx + mov .zz2,edx + movsx eax,word .x1 + shl eax,ROUND2 ; eax - cur x1 + mov ebx,eax ; ebx - cur x2 + + mov cx,.y1 + cmp cx,.y2 + jge .loop1_end + .loop1: + + pushad + sar ebx,ROUND2 + sar eax,ROUND2 + ; movq xmm0,.zz1 + movlps xmm0,.zz1 + ; mov edx,0.11 + ; movd xmm0,edx + ; shufps xmm0,xmm0,11100000b + mov esi,.s_buff + + call stencil_line + + popad + add eax,.dx13 + add ebx,.dx12 + + movss xmm1,.zz1 + movss xmm2,.zz2 + addss xmm1,.dz13 + addss xmm2,.dz12 + movss .zz1,xmm1 + movss .zz2,xmm2 + + add cx,1 + cmp cx,.y2 + jl .loop1 + + .loop1_end: + + mov edx,.z2 + mov .zz2,edx + movsx ebx,word .x2 + shl ebx,ROUND2 + + mov cx,.y2 + cmp cx,.y3 + jge .loop2_end + .loop2: + pushad + + sar ebx,ROUND2 + sar eax,ROUND2 + movlps xmm0,.zz1 + mov esi,.s_buff + + + call stencil_line + + popad + + add eax,.dx13 + add ebx,.dx23 + + movss xmm1,.zz1 + movss xmm2,.zz2 + addss xmm1,.dz13 + addss xmm2,.dz23 + movss .zz1,xmm1 + movss .zz2,xmm2 + + + add cx,1 + cmp cx,.y3 + jl .loop2 + .loop2_end: + + add esp,128 + pop ebp + +ret + +stencil_line: +;---------------------------------------------------- +;-------------in xmm0 - lo -> hi z1, z2 +;--------------- eax - x1 --------------------------- +;--------------- ebx - x2 --------------------------- +;--------------- ecx - y----------------------------- +;--------------- esi - pointer to s-buffer + + +.dz equ [ebp-4] +.z2 equ [ebp-8] +.z1 equ [ebp-12] +.x2 equ [ebp-16] +.x1 equ [ebp-20] +.s_buf equ [ebp-24] +; cmp eax,ebx +; je @f +; int3 +; @@: + push ebp + mov ebp,esp + sub esp,64 + ; cmp eax,0 + ; jg @f + ; + ; @@: + or cx,cx + jle .l_quit + + cmp cx,[size_y_var] + jge .l_quit + + movzx ecx,cx + mov .s_buf,esi + cmp eax,ebx + je .l_quit + jl .l_ok + + xchg eax,ebx + shufps xmm0,xmm0,11100001b + .l_ok: + + cmp ax,[size_x_var] + jge .l_quit + cmp bx,0 + jle .l_quit + + movlps .z1,xmm0 + mov .x1,eax + mov .x2,ebx + + sub ebx,eax + movss xmm0,.z2 + cvtsi2ss xmm1,ebx + subss xmm0,.z1 + divss xmm0,xmm1 + movss .dz,xmm0 + + movzx edx,word[size_x_var] + cmp eax,1 + jge @f + mov eax,.x1 + neg eax + cvtsi2ss xmm2,eax + mulss xmm2,.dz + addss xmm2,.z1 + movss .z1,xmm2 + mov dword .x1,0 + movzx edx,word[size_x_var] + sub edx,1 + @@: + cmp .x2,edx + jl @f + mov .x2,edx + + @@: + ; mov eax,.x1 + ; cmp .x2,eax + ; je .l_quit + movzx edx,word[size_x_var] + mov esi,.s_buf + mov eax,ecx ; y + mul edx + add eax,.x1 + + shl eax,2 + add esi,eax + + mov ecx,.x2 + sub ecx,.x1 + movss xmm2,.z1 ; cz + .ccalc: + movss xmm1,xmm2 + cmpltss xmm1,dword[esi] + movd eax,xmm1 + cmp eax,-1 + jnz @f + movss dword[esi],xmm2 + @@: + add esi,4 + addss xmm2,.dz + sub ecx,1 + jnz .ccalc + .l_quit: + mov esp,ebp + pop ebp +ret diff --git a/programs/demos/view3ds/a_procs.inc b/programs/demos/view3ds/a_procs.inc index 421feebfda..a68ad46dca 100644 --- a/programs/demos/view3ds/a_procs.inc +++ b/programs/demos/view3ds/a_procs.inc @@ -1,623 +1,981 @@ -do_sinus: - .x equ [ebp-8] - .y equ [ebp-12] - .new_y equ [ebp-16] - .temp equ [ebp-20] - push ebp - mov ebp,esp - sub esp,64 - mov dword .x,0 - mov dword .y,0 - mov esi,[screen_ptr] - mov edi,[Zbuffer_ptr] - push edi - ; clear Zbuffer temporally used as image buffer - movzx ecx,word[size_x_var] - movzx eax,word[size_y_var] - imul ecx,eax ;SIZE_X*SIZE_Y - xor eax,eax - cld - rep stosd - pop edi - fninit - .again: - fild dword .x - fmul [sin_frq] - fistp dword .temp - mov eax, .temp - - and eax, 0x000000ff - - - fld dword [sin_tab+eax*4] - fimul dword [sin_amplitude] - fiadd dword .y - fistp dword .new_y - - mov eax,.new_y - or eax,eax - jl .skip - movzx ebx,word[size_y_var] - cmp eax,ebx ;SIZE_Y - jg .skip - movzx edx,word[size_x_var] - mul edx -; shl eax,9 - add eax,dword .x - - lea ebx,[eax*3] - cmp [dr_flag],12 ; 32 bit col cause - jl @f - add ebx,eax - @@: - mov eax,[esi] - mov [edi+ebx],eax - .skip: - add esi,3 - cmp [dr_flag],12 - jl @f - inc esi - @@: - inc dword .x - movzx edx,word[size_x_var] - cmp dword .x,edx ;SIZE_X - jl .again - mov dword .x,0 - inc dword .y - movzx edx,word[size_y_var] - cmp dword .y,edx ;SIZE_Y - jl .again - - ; copy from temporary buffer -> Zbuffer to screen - mov esi,[Zbuffer_ptr] - mov edi,[screen_ptr] - movzx ecx,word[size_x_var] - movzx eax,word[size_y_var] - imul ecx,eax - cmp [dr_flag],12 - jge @f - lea ecx,[ecx*3] - shr ecx,2 - ; mov ecx,SIZE_X*SIZE_Y*3/4 - @@: - cld - rep movsd - - - mov esp,ebp - pop ebp -ret - - -draw_dots: - mov esi,[points_translated_ptr] - mov ecx,[points_count_var] - .drw: - @@: - lodsd - add esi,2 ; skip z - movzx ebx,ax - shr eax,16 ; bx = x , ax = y - or ax,ax - jl @f - or bx,bx - jl @f - cmp ax,[size_y_var] ;SIZE_Y - jge @f - cmp bx,[size_x_var] ;SIZE_X - jge @f - movzx edx,word[size_x_var] ;SIZE_X ; SIZE_X not only power of 2 -> 256,512,... - mul edx - add eax,ebx - mov edi,[screen_ptr] - lea eax,[eax*3] - add edi,eax - xor eax,eax - not eax - stosd - @@: - loop .drw - -ret - -do_emboss: ; sse2 version only -if Ext >= SSE2 - movzx ecx,[bumps_deep_flag] - inc ecx - call blur_screen ;blur n times - - mov eax,[size_y_var] ;load both x, y - mov ebx,eax - shr ebx,16 - cwde - mul ebx - mov ecx,eax - sub ecx,ebx - sub ecx,ebx - mov esi,[screen_ptr] - mov edi,[Zbuffer_ptr] - cmp [dr_flag],12 - jge @f - lea ebx,[ebx*3] - jmp .f -@@: - shl ebx,2 -.f: - mov edx,esi - add esi,ebx - lea ebx,[ebx+esi] - pxor xmm0,xmm0 - push eax -.emb: - cmp [dr_flag],12 - jge @f - movlps xmm1,[esi+3] - movhps xmm1,[esi+6] - movlps xmm2,[esi-3] - movhps xmm2,[esi] - movlps xmm3,[ebx] - movhps xmm3,[ebx+3] - movlps xmm4,[edx] - movhps xmm4,[edx+3] - jmp .ff -@@: - movlps xmm1,[esi+4] - movhps xmm1,[esi+8] - movlps xmm2,[esi-4] - movhps xmm2,[esi] - movlps xmm3,[ebx] - movhps xmm3,[ebx+4] - movlps xmm4,[edx] - movhps xmm4,[edx+4] -.ff: - punpcklbw xmm1,xmm0 - punpcklbw xmm2,xmm0 - punpcklbw xmm3,xmm0 - punpcklbw xmm4,xmm0 - psubsw xmm1,xmm2 - paddw xmm1,[emboss_bias] - psubsw xmm3,xmm4 - paddw xmm3,[emboss_bias] - pmulhw xmm1,xmm3 - movaps xmm7,xmm1 - movaps xmm6,xmm1 - psrlq xmm7,2*8 - psrlq xmm6,4*8 - pmaxsw xmm1,xmm7 - pmaxsw xmm1,xmm6 - -if 0 - movaps xmm7,xmm3 - movaps xmm6,xmm3 - psrlq xmm7,2*8 - psrlq xmm6,4*8 - pmaxsw xmm3,xmm7 - pmaxsw xmm3,xmm6 -end if - pmaxsw xmm1,xmm3 - - movd eax,xmm1 - movzx eax,al -; cmp [dr_flag],12 -; je @f - lea eax,[eax*3+envmap_cub] -; jmp .fff -;@@: - - mov eax,[eax] - mov [edi],eax ;xmm1 - psrldq xmm1,8 - movd eax,xmm1 - movzx eax,al - lea eax,[eax*3+envmap_cub] - mov eax,[eax] - mov [edi+4],eax - - cmp [dr_flag],12 - jl @f - add esi,2 - add ebx,2 - add edx,2 -@@: - - add edi,8 - add esi,6 - add ebx,6 - add edx,6 - sub ecx,2 - jnc .emb - - - pop ecx ;,eax - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - cmp [dr_flag],12 - jge .e -@@: - movsd - dec edi - loop @b -.e: - rep movsd - -end if - -ret - - -;********************************EMBOSS DONE******************************* - - -generate_object2: ; torus -;in ax - figure number 2=torus, 3=loop, 4=loop -;locals -; counter dw ? -; sin dd ? -; cos dd ? -;endl -.counter equ word[ebp-2] -.sin equ dword[ebp-6] -.cos equ dword[ebp-10] -.sin2 equ dword[ebp-14] -.cos2 equ dword[ebp-18] -.piD180m3 equ dword[ebp-22] -.cD2 equ word[ebp-24] - push ebp - mov ebp,esp - sub esp,24 - - push ax - - fninit - mov edi,[points_ptr] - xor eax,eax - ; init seed -> 4 3d points - mov dword[edi],-1.0 ; x - add edi,4 - stosd ; y - stosd ; z - mov dword[edi],-0.9 ; x1 - mov dword[edi+4],0.1 ; y1 - add edi,8 - stosd ; z1 - mov dword[edi],-0.8 - add edi,4 - stosd - stosd - mov dword[edi],-0.9 ; x3 - mov dword[edi+4],-0.1 ; y3 - add edi,8 - stosd ; z3 - mov [points_count_var],4 - - fld [piD180] - fidiv [i3] - fstp .piD180m3 - mov .cD2,5 - - pop ax - mov ecx,1 - mov edx,9 - .next: ; calc angle and rotate seed 4 points - mov .counter,cx - mov ebx,[points_ptr] - fld .piD180m3 - fimul .counter - fld st - fsincos - fstp .sin - fstp .cos - fadd st,st0 - fsincos - fstp .sin2 - fstp .cos2 - - .rotor: ; next 4 - ; rotary y - fld dword[ebx] ; x - fld .sin - fmul dword[ebx+8] ; z * sinbeta - fchs - fld .cos - fmul dword[ebx] ; x * cosbeta - faddp - fstp dword[edi] ; new x - fmul .sin ; old x * sinbeta - fld .cos - fmul dword[ebx+8] ; z * cosbeta - faddp - dec dx - or dx,dx - jnz @f -; mov .counter,dx - fld st - fidiv [i3] - faddp - @@: - fstp dword[edi+8] ; new z - fld dword[ebx+4] - or dx,dx - jnz @f - ; fld1 - ; faddp -; fld st - fadd st,st0 - fadd st,st0 -; fxch -; fimul [i3] -; fsin -; faddp - mov dx,9 - @@: - fstp dword[edi+4] - ; rotary x - cmp al,3 - jl .end_rot - fld dword[edi+4] ;y - fld .sin2 - fmul dword[edi+8] ;z - fld .cos2 - fmul dword[edi+4] ;y - faddp - fstp dword[edi+4] ; new y - fmul .sin2 ; sinbeta * old y - fchs - fld .cos2 - fmul dword[edi+8] - faddp - fstp dword[edi+8] - ; rotary z - cmp al,4 - jl .end_rot - fld dword[edi] ;x - fld .sin - fmul dword[edi+4] ;y - fld .cos - fmul dword[edi] ;x - faddp - fstp dword[edi] ;new x - fmul .sin ; sinbeta * old x - fchs - fld .cos - fmul dword[edi+4] ; cosbeta * y - faddp - fstp dword[edi+4] ; new y - - - - .end_rot: - - add edi,12 - add ebx,12 - mov esi,[points_ptr] - add esi,12*4 - cmp ebx,esi - jl .rotor - - add [points_count_var],4 - add cx,18 - cmp cx,(18*21*3)+1 - jle .next - - mov edi,[triangles_ptr] - mov eax,4 - mov ebx,4+4 - mov [triangles_count_var],160*3 ;164*3 ;140 - - mov ecx,80*3 ;68 - @@: - stosd ;---- - mov [edi],ebx ; | - add edi,4 ; | - inc eax ; | - stosd ; |repeat 4 times - - mov [edi],ebx ; | - inc ebx - add edi,4 - stosd ; | - mov [edi],ebx ; | - add edi,4 ;---- - loop @b - - - mov dword[edi],-1 ; < - end mark - mov [culling_flag],0 - - mov esp,ebp - pop ebp - -ret -generate_object3: ; heart -;locals -; counter dw ? -; sin dd ? -; cos dd ? -;endl -.counter equ word[ebp-2] -.sin equ dword[ebp-6] -.cos equ dword[ebp-10] -.sin2 equ dword[ebp-14] -.cos2 equ dword[ebp-18] -.piD180m3 equ dword[ebp-22] -.cD2 equ word[ebp-24] - push ebp - mov ebp,esp - sub esp,24 - - fninit - mov edi,[points_ptr] - xor eax,eax - ; init seed -> eight 3d points - mov dword[edi],2.0 - add edi,4 - stosd - stosd - - mov dword[edi],2.0 - mov dword[edi+4],-0.5 - add edi,8 - stosd - - mov dword[edi],1.5 - mov dword[edi+4],-1.5 - add edi,8 - stosd - mov dword[edi],1.0 - mov dword[edi+4],-2.0 - add edi,8 - stosd - - stosd - mov dword[edi],-2.5 - add edi,4 - stosd - - mov [points_count_var],5 - - mov ecx,1 - .next: ; calc angle and rotate seed 4 points - mov .counter,cx - mov ebx,[points_ptr] - fld [piD180] - fimul .counter - fsincos - fstp .sin - fstp .cos - - .rotor: ; next 4 - ; rotary y - fld dword[ebx] ; x - fld .sin - fmul dword[ebx+8] ; z * sinbeta - fchs - fld .cos - fmul dword[ebx] ; x * cosbeta - faddp - fidiv [i3] - fstp dword[edi] ; new x - fmul .sin ; old x * sinbeta - fld .cos - fmul dword[ebx+8] ; z * cosbeta - faddp - fstp dword[edi+8] ; new z - - fld dword[ebx+4] ;y - fstp dword[edi+4] - - - .end_rot: - - add edi,12 - add ebx,12 - mov esi,[points_ptr] - add esi,12*5 - cmp ebx,esi ;real_points + (12*5) - jl .rotor - - add [points_count_var],5 - add cx,18 - cmp cx,(18*21)+1 - jle .next -;last points - - xor eax,eax - - mov dword[edi],0.22 - mov dword[edi+4],0.77 - mov dword[edi+8],1.25 - add edi,12 - - mov dword[edi],0.22 - mov dword[edi+4],0.77 - mov dword[edi+8],-1.25 - add edi,12 - stosd - - add [points_count_var],2 - -; init triangles list - - mov edi,[triangles_ptr] - mov eax,5 - mov ebx,5+5 - mov [triangles_count_var],200 ;204 - - mov ecx,100 - @@: - stosd ;---- - mov [edi],ebx ; | - add edi,4 ; | - inc eax ; | - stosd ; |repeat - - mov [edi],ebx ; | - inc ebx - add edi,4 - stosd ; | - mov [edi],ebx ; | - add edi,4 ;---- - loop @b - - mov eax,5 - mov ebx,[points_count_var] - sub ebx,2 - mov dl,2 - .nx: - mov ecx,5 - add [triangles_count_var],ecx - @@: - stosd - add eax,5 - stosd - mov dword[edi],ebx - add edi,4 - loop @b - - cmp dl,1 - je @f - - inc ebx - jmp .lab - @@: - dec ebx - .lab: - mov ecx,5 - add [triangles_count_var],ecx - @@: - stosd - add eax,5 - stosd - mov dword[edi],ebx - add edi,4 - loop @b - - dec dl - or dl,dl - jnz .nx - - sub eax,25 - stosd - sub eax,50 - stosd - mov dword[edi],ebx - add edi,4 - - stosd - add eax,50 - stosd - inc ebx - mov dword[edi],ebx - add edi,4 - add [triangles_count_var],2 - - mov dword[edi],-1 ; < - end mark - mov [culling_flag],0 - - mov esp,ebp - pop ebp - -ret - - - +;=============================================================== +do_edges_list: + push ebp + mov ebp,esp + sub esp,32 + + .ed_cnt equ [ebp-4] + .edd_ptr equ [ebp-8] + .counter equ [ebp-12] + + + mov ebx,[edges_ptr] + mov eax,[triangles_ptr] + mov ecx,[triangles_count_var] + @@: + movdqu xmm0,[eax] + movq [ebx],xmm0 + pshufd xmm0,xmm0,11001001b + movq [ebx+8],xmm0 + pshufd xmm0,xmm0,11001001b + movq [ebx+16],xmm0 + add ebx,24 + add eax,12 + loop @b + + + mov ebx,[edges_ptr] + mov ecx,[triangles_count_var] + lea ecx,[ecx*3] + .mxd: + mov eax,[ebx] + cmp eax,[ebx+4] + jl @f + movq xmm0,[ebx] + pshufd xmm0,xmm0,11100001b + movq [ebx],xmm0 + @@: + add ebx,8 + loop .mxd + + + ; insert sort + mov ebx,[edges_ptr] + mov ecx,[triangles_count_var] + lea ecx,[ecx*3] + + mov esi,ecx + shl esi,3 + add esi,ebx + + .ccc: + mov eax,[ebx+8] + cmp eax,[ebx] + jge .g + movq xmm0,[ebx+8] + push ebx + .c: + cmp ebx,esi + jge .done + cmp ebx,[edges_ptr] + jl .done + cmp eax,[ebx] + jge .done + movq xmm7,[ebx] + movq [ebx+8],xmm7 + sub ebx,8 + jnz .c + add ebx,8 + .done: + movq [ebx+8],xmm0 + .p: + pop ebx + .g: + add ebx,8 + dec ecx + cmp ecx,1 + jnz .ccc + + + ; insert sort again + mov ebx,[edges_ptr] + mov ecx,[triangles_count_var] + lea ecx,[ecx*3] + mov esi,ecx + shl esi,3 + add esi,ebx + + .count: + push ecx + push ebx + xor ecx,ecx + mov eax,[ebx] ; count + .aa: + inc ecx + add ebx,8 + cmp ebx,esi + jge .br ; break + cmp eax,[ebx] + je .aa + mov .counter,ecx + pop ebx + mov edi,ebx + sub edi,8 + mov edx,[ebx+8] + .ccc2: + + cmp ebx,esi + jbe @f + add esp,4 + jmp .ff + @@: + mov eax,[ebx+12] + mov edx,[ebx+8] + cmp eax,[ebx+4] + jge .gg2 + movq xmm0,[ebx+8] + push ebx + .c2: + cmp eax,[ebx+4] + jge .done2 + movq xmm7,[ebx] + movq [ebx+8],xmm7 + + sub ebx,8 + cmp ebx,edi + jz @f + cmp [ebx+8],edx + jz .c2 + @@: + .done2: + add ebx,8 + movq [ebx],xmm0 + + .p2: + pop ebx + .gg2: + add ebx,8 + dec ecx + cmp ecx,1 + jnz .ccc2 + + pop ecx + sub ecx,.counter + add ebx,8 + ja .count + + jmp .ff + .br: ;break + add esp,8 + .ff: + + ; count edges + mov ecx,0 + mov edx,[triangles_count_var] + lea edx,[edx*3] + mov ebx,[edges_ptr] +; mov esi,edx +; shl esi,3 +; add esi,[edges_ptr] + .nx: + movq xmm0,[ebx] + add ebx,8 +; cmp ebx,esi +; jae @f + movq xmm1,[ebx] +; @@: + pcmpeqd xmm0,xmm1 + pmovmskb eax,xmm0 + and eax,0xff + cmp eax,0xff + jz @f + inc ecx + @@: + dec edx + jnz .nx + + + mov .ed_cnt,ecx + lea ecx,[ecx*3] + shl ecx,2 + add ecx,65536 + mov ebx,12 + mov eax,68 + mov edx,.edd_ptr + int 0x40 ; -> allocate memory to triangles + mov .edd_ptr, eax ; -> eax = pointer to allocated mem + + + + mov ebx,[edges_ptr] + mov ecx,[triangles_count_var] + lea ecx,[ecx*3] + .seek: + movq xmm0,[ebx] + movq xmm1,[ebx+8] + pcmpeqd xmm1,xmm0 + pmovmskb edx,xmm1 + and edx,0xff + cmp edx,0xff + je @f + movq [eax],xmm0 + add eax,8 + @@: + add ebx,8 + loop .seek + + mov eax,68 + mov ebx,13 + mov ecx,[edges_ptr] + int 0x40 ; release old edges ptr + + + mov eax,.edd_ptr + mov ecx,.ed_cnt + mov [edges_ptr],eax + mov [edges_count],ecx + + mov esp,ebp + pop ebp +ret + +;======================= + + +do_sinus: + .x equ [ebp-8] + .y equ [ebp-12] + .new_y equ [ebp-16] + .temp equ [ebp-20] + push ebp + mov ebp,esp + sub esp,64 + mov dword .x,0 + mov dword .y,0 + mov esi,[screen_ptr] + mov edi,[Zbuffer_ptr] + push edi + ; clear Zbuffer temporally used as image buffer + movzx ecx,word[size_x_var] + movzx eax,word[size_y_var] + imul ecx,eax ;SIZE_X*SIZE_Y + xor eax,eax + cld + rep stosd + pop edi +; movzx eax,[sinus_flag] +; mov edx,10 +; mul edx +; mov [sin_amplitude],eax +; mov [sin_frq],eax + fninit +;if Ext = SSE2 +; movups xmm1,[const0123] ; xmm1 - init values +; mov eax,0x000000ff +; movd xmm2,eax +; shufps xmm2,xmm2,0 ; xmm2 - mask value +; mov eax,4 +; movd xmm3,eax +; shufps xmm3,xmm3,0 + .again: +if 0 + fild dword .x + fidiv [sin_frq] + fsin + fimul [sin_amplitude] + fiadd dword .y + fistp dword .new_y +else + fild dword .x + fmul [sin_frq] + fistp dword .temp + mov eax, .temp +; mov bx, [angle_x] +; add bx, [angle_y] +; movzx ebx,bx +; shr ebx,1 ; change phase +; add eax,ebx + + + and eax, 0x000000ff + +; cdq + ; mul [sin_frq] +; and eax,0x000000ff +; and ax,0x00ff +; cwde + + fld dword [sin_tab+eax*4] + fimul dword [sin_amplitude] + fiadd dword .y + fistp dword .new_y +end if + mov eax,.new_y + or eax,eax + jl .skip + movzx ebx,word[size_y_var] + cmp eax,ebx ;SIZE_Y + jg .skip + movzx edx,word[size_x_var] + mul edx +; shl eax,9 + add eax,dword .x + + lea ebx,[eax*3] + cmp [dr_flag],12 ; 32 bit col cause + jl @f + add ebx,eax + @@: + mov eax,[esi] + mov [edi+ebx],eax + .skip: + add esi,3 + cmp [dr_flag],12 + jl @f + inc esi + @@: + inc dword .x + movzx edx,word[size_x_var] + cmp dword .x,edx ;SIZE_X + jl .again + mov dword .x,0 + inc dword .y + movzx edx,word[size_y_var] + cmp dword .y,edx ;SIZE_Y + jl .again + + ; copy from temporary buffer -> Zbuffer to screen + mov esi,[Zbuffer_ptr] + mov edi,[screen_ptr] + movzx ecx,word[size_x_var] + movzx eax,word[size_y_var] + imul ecx,eax + cmp [dr_flag],12 + jge @f + lea ecx,[ecx*3] + shr ecx,2 + ; mov ecx,SIZE_X*SIZE_Y*3/4 + @@: + cld + rep movsd + + + mov esp,ebp + pop ebp +ret + + +draw_dots: + mov esi,[points_translated_ptr] + mov ecx,[points_count_var] + .drw: + @@: + lodsd + add esi,2 ; skip z + movzx ebx,ax + shr eax,16 ; bx = x , ax = y + or ax,ax + jl @f + or bx,bx + jl @f + cmp ax,[size_y_var] ;SIZE_Y + jge @f + cmp bx,[size_x_var] ;SIZE_X + jge @f + movzx edx,word[size_x_var] ;SIZE_X ; SIZE_X not only power of 2 -> 256,512,... + mul edx + add eax,ebx + mov edi,[screen_ptr] + lea eax,[eax*3] + add edi,eax + xor eax,eax + not eax + stosd + @@: + loop .drw + +ret + +do_emboss: ; sse2 version only +if Ext >= SSE2 + movzx ecx,[bumps_deep_flag] + inc ecx + call blur_screen ;blur n times + + mov eax,[size_y_var] ;load both x, y + mov ebx,eax + shr ebx,16 + cwde + mul ebx + mov ecx,eax + sub ecx,ebx + sub ecx,ebx + mov esi,[screen_ptr] + mov edi,[Zbuffer_ptr] + cmp [dr_flag],12 + jge @f + lea ebx,[ebx*3] + jmp .f +@@: + shl ebx,2 +.f: + mov edx,esi + add esi,ebx + lea ebx,[ebx+esi] + pxor xmm0,xmm0 + push eax +.emb: + cmp [dr_flag],12 + jge @f + movlps xmm1,[esi+3] + movhps xmm1,[esi+6] + movlps xmm2,[esi-3] + movhps xmm2,[esi] + movlps xmm3,[ebx] + movhps xmm3,[ebx+3] + movlps xmm4,[edx] + movhps xmm4,[edx+3] + jmp .ff +@@: + movlps xmm1,[esi+4] + movhps xmm1,[esi+8] + movlps xmm2,[esi-4] + movhps xmm2,[esi] + movlps xmm3,[ebx] + movhps xmm3,[ebx+4] + movlps xmm4,[edx] + movhps xmm4,[edx+4] +.ff: + punpcklbw xmm1,xmm0 + punpcklbw xmm2,xmm0 + punpcklbw xmm3,xmm0 + punpcklbw xmm4,xmm0 + psubsw xmm1,xmm2 + paddw xmm1,[emboss_bias] + psubsw xmm3,xmm4 + paddw xmm3,[emboss_bias] + pmulhw xmm1,xmm3 + movaps xmm7,xmm1 + movaps xmm6,xmm1 + psrlq xmm7,2*8 + psrlq xmm6,4*8 + pmaxsw xmm1,xmm7 + pmaxsw xmm1,xmm6 + +if 0 + movaps xmm7,xmm3 + movaps xmm6,xmm3 + psrlq xmm7,2*8 + psrlq xmm6,4*8 + pmaxsw xmm3,xmm7 + pmaxsw xmm3,xmm6 +end if + pmaxsw xmm1,xmm3 + + movd eax,xmm1 + movzx eax,al +; cmp [dr_flag],12 +; je @f + lea eax,[eax*3+envmap_cub] +; jmp .fff +;@@: + + mov eax,[eax] + mov [edi],eax ;xmm1 + psrldq xmm1,8 + movd eax,xmm1 + movzx eax,al + lea eax,[eax*3+envmap_cub] + mov eax,[eax] + mov [edi+4],eax + + cmp [dr_flag],12 + jl @f + add esi,2 + add ebx,2 + add edx,2 +@@: + + add edi,8 + add esi,6 + add ebx,6 + add edx,6 + sub ecx,2 + jnc .emb + + + pop ecx ;,eax + mov edi,[screen_ptr] + mov esi,[Zbuffer_ptr] + cmp [dr_flag],12 + jge .e +@@: + movsd + dec edi + loop @b +.e: + rep movsd + +end if + +ret + +;align 16 +; emboss_bias: +; dw 128, 128, 128, 128, 128, 128, 128, 128 + +if 0 ; old emb proc + + ; emboss - after drawing all, + ; transfer screen buffer into bump map + ; and draw two bump triangles + ; ************************************* + mov esi,screen + mov edi,bumpmap2 + mov ecx,TEXTURE_SIZE/3 + cld +if Ext=NON + xor eax,eax + xor bh,bh + xor dh,dh + @@: + lodsb + movzx bx,al + lodsb + movzx dx,al + lodsb + add ax,bx + add ax,dx + ; cwd + ; div [i3] + ;; push ax + ;; pop bx + ;; shr bx,3 + ;; shr ax,2 + ;; add ax,bx + + lea eax,[eax*5] + shr ax,4 + + stosb + loop @b +else + emms + pxor mm1,mm1 + mov ebx,0x0000ffff + @@: + movd mm0,[esi] + punpcklbw mm0,mm1 + movq mm2,mm0 + psrlq mm2,16 + movq mm3,mm0 + psrlq mm3,32 + paddw mm0,mm2 + paddw mm0,mm3 + + + movd eax,mm0 + and eax,ebx + lea eax,[eax*5] + shr ax,4 + stosb + add esi,3 + loop @b + +end if + push ebp + + push dword 0 ; env coords + push word 0 + push word SIZE_X + push word SIZE_Y + push dword 0 + push dword 0 ; bump coords + push word SIZE_X + push word SIZE_Y + push word 0 + mov eax,SIZE_Y + mov ebx,SIZE_X*65536+0 + xor ecx,ecx + mov edx,bumpmap2 + mov esi,envmap + mov edi,screen + call bump_triangle + + push dword SIZE_X shl 16 + SIZE_Y ; env coords + push word 0 + push word SIZE_X + push word SIZE_Y + push word 0 + push dword SIZE_X shl 16 + SIZE_Y ; bump coords + push word 0 + push word SIZE_X + push word SIZE_Y + push word 0 + mov eax,SIZE_Y + mov ebx,SIZE_X * 65536+0 + mov ecx,SIZE_X shl 16 + SIZE_Y + mov edx,bumpmap2 + mov esi,envmap + mov edi,screen + call bump_triangle + + pop ebp +ret +end if +;********************************EMBOSS DONE******************************* + + +generate_object2: ; torus +;in ax - figure number 2=torus, 3=loop, 4=loop +;locals +; counter dw ? +; sin dd ? +; cos dd ? +;endl +.counter equ word[ebp-2] +.sin equ dword[ebp-6] +.cos equ dword[ebp-10] +.sin2 equ dword[ebp-14] +.cos2 equ dword[ebp-18] +.piD180m3 equ dword[ebp-22] +.cD2 equ word[ebp-24] + push ebp + mov ebp,esp + sub esp,24 + + push ax + + fninit + mov edi,[points_ptr] + xor eax,eax + ; init seed -> 4 3d points + mov dword[edi],-1.0 ; x + add edi,4 + stosd ; y + stosd ; z + mov dword[edi],-0.9 ; x1 + mov dword[edi+4],0.1 ; y1 + add edi,8 + stosd ; z1 + mov dword[edi],-0.8 + add edi,4 + stosd + stosd + mov dword[edi],-0.9 ; x3 + mov dword[edi+4],-0.1 ; y3 + add edi,8 + stosd ; z3 + mov [points_count_var],4 + + fld [piD180] + fidiv [i3] + fstp .piD180m3 + mov .cD2,5 + + pop ax + mov ecx,1 + mov edx,9 + .next: ; calc angle and rotate seed 4 points + mov .counter,cx + mov ebx,[points_ptr] + fld .piD180m3 + fimul .counter + fld st + fsincos + fstp .sin + fstp .cos + fadd st,st0 + fsincos + fstp .sin2 + fstp .cos2 + + .rotor: ; next 4 + ; rotary y + fld dword[ebx] ; x + fld .sin + fmul dword[ebx+8] ; z * sinbeta + fchs + fld .cos + fmul dword[ebx] ; x * cosbeta + faddp + fstp dword[edi] ; new x + fmul .sin ; old x * sinbeta + fld .cos + fmul dword[ebx+8] ; z * cosbeta + faddp + dec dx + or dx,dx + jnz @f +; mov .counter,dx + fld st + fidiv [i3] + faddp + @@: + fstp dword[edi+8] ; new z + fld dword[ebx+4] + or dx,dx + jnz @f + ; fld1 + ; faddp +; fld st + fadd st,st0 + fadd st,st0 +; fxch +; fimul [i3] +; fsin +; faddp + mov dx,9 + @@: + fstp dword[edi+4] + ; rotary x + cmp al,3 + jl .end_rot + fld dword[edi+4] ;y + fld .sin2 + fmul dword[edi+8] ;z + fld .cos2 + fmul dword[edi+4] ;y + faddp + fstp dword[edi+4] ; new y + fmul .sin2 ; sinbeta * old y + fchs + fld .cos2 + fmul dword[edi+8] + faddp + fstp dword[edi+8] + ; rotary z + cmp al,4 + jl .end_rot + fld dword[edi] ;x + fld .sin + fmul dword[edi+4] ;y + fld .cos + fmul dword[edi] ;x + faddp + fstp dword[edi] ;new x + fmul .sin ; sinbeta * old x + fchs + fld .cos + fmul dword[edi+4] ; cosbeta * y + faddp + fstp dword[edi+4] ; new y + + + + .end_rot: + + add edi,12 + add ebx,12 + mov esi,[points_ptr] + add esi,12*4 + cmp ebx,esi + jl .rotor + + add [points_count_var],4 + add cx,18 + cmp cx,(18*21*3)+1 + jle .next + + mov edi,[triangles_ptr] + mov eax,4 + mov ebx,4+4 + mov [triangles_count_var],160*3 ;164*3 ;140 + + mov ecx,80*3 ;68 + @@: + stosd ;---- + mov [edi],ebx ; | + add edi,4 ; | + inc eax ; | + stosd ; |repeat 4 times + + mov [edi],ebx ; | + inc ebx + add edi,4 + stosd ; | + mov [edi],ebx ; | + add edi,4 ;---- + loop @b + + + mov dword[edi],-1 ; < - end mark + mov [culling_flag],0 + + mov esp,ebp + pop ebp + +ret +generate_object3: ; heart +;locals +; counter dw ? +; sin dd ? +; cos dd ? +;endl +.counter equ word[ebp-2] +.sin equ dword[ebp-6] +.cos equ dword[ebp-10] +.sin2 equ dword[ebp-14] +.cos2 equ dword[ebp-18] +.piD180m3 equ dword[ebp-22] +.cD2 equ word[ebp-24] + push ebp + mov ebp,esp + sub esp,24 + + fninit + mov edi,[points_ptr] + xor eax,eax + ; init seed -> eight 3d points + mov dword[edi],2.0 + add edi,4 + stosd + stosd + + mov dword[edi],2.0 + mov dword[edi+4],-0.5 + add edi,8 + stosd + + mov dword[edi],1.5 + mov dword[edi+4],-1.5 + add edi,8 + stosd + mov dword[edi],1.0 + mov dword[edi+4],-2.0 + add edi,8 + stosd + + stosd + mov dword[edi],-2.5 + add edi,4 + stosd + + mov [points_count_var],5 + + mov ecx,1 + .next: ; calc angle and rotate seed 4 points + mov .counter,cx + mov ebx,[points_ptr] + fld [piD180] + fimul .counter + fsincos + fstp .sin + fstp .cos + + .rotor: ; next 4 + ; rotary y + fld dword[ebx] ; x + fld .sin + fmul dword[ebx+8] ; z * sinbeta + fchs + fld .cos + fmul dword[ebx] ; x * cosbeta + faddp + fidiv [i3] + fstp dword[edi] ; new x + fmul .sin ; old x * sinbeta + fld .cos + fmul dword[ebx+8] ; z * cosbeta + faddp + fstp dword[edi+8] ; new z + + fld dword[ebx+4] ;y + fstp dword[edi+4] + + + .end_rot: + + add edi,12 + add ebx,12 + mov esi,[points_ptr] + add esi,12*5 + cmp ebx,esi ;real_points + (12*5) + jl .rotor + + add [points_count_var],5 + add cx,18 + cmp cx,(18*21)+1 + jle .next +;last points + + xor eax,eax + + mov dword[edi],0.22 + mov dword[edi+4],0.77 + mov dword[edi+8],1.25 + add edi,12 + + mov dword[edi],0.22 + mov dword[edi+4],0.77 + mov dword[edi+8],-1.25 + add edi,12 + stosd + + add [points_count_var],2 + +; init triangles list + + mov edi,[triangles_ptr] + mov eax,5 + mov ebx,5+5 + mov [triangles_count_var],200 ;204 + + mov ecx,100 + @@: + stosd ;---- + mov [edi],ebx ; | + add edi,4 ; | + inc eax ; | + stosd ; |repeat + + mov [edi],ebx ; | + inc ebx + add edi,4 + stosd ; | + mov [edi],ebx ; | + add edi,4 ;---- + loop @b + + mov eax,5 + mov ebx,[points_count_var] + sub ebx,2 + mov dl,2 + .nx: + mov ecx,5 + add [triangles_count_var],ecx + @@: + stosd + add eax,5 + stosd + mov dword[edi],ebx + add edi,4 + loop @b + + cmp dl,1 + je @f + + inc ebx + jmp .lab + @@: + dec ebx + .lab: + mov ecx,5 + add [triangles_count_var],ecx + @@: + stosd + add eax,5 + stosd + mov dword[edi],ebx + add edi,4 + loop @b + + dec dl + or dl,dl + jnz .nx + + sub eax,25 + stosd + sub eax,50 + stosd + mov dword[edi],ebx + add edi,4 + + stosd + add eax,50 + stosd + inc ebx + mov dword[edi],ebx + add edi,4 + add [triangles_count_var],2 + + mov dword[edi],-1 ; < - end mark + mov [culling_flag],0 + + mov esp,ebp + pop ebp + +ret + + + diff --git a/programs/demos/view3ds/b_procs.inc b/programs/demos/view3ds/b_procs.inc index 9bd613cae0..c79774c834 100644 --- a/programs/demos/view3ds/b_procs.inc +++ b/programs/demos/view3ds/b_procs.inc @@ -1,1336 +1,1305 @@ -;init_envmap_cub2: -; mov esi,envmap -; mov edi,envmap_cub ;take cubic env. map from -; xor eax,eax ;spherical env. map -; @@: -; add esi,eax -; movsd -; dec edi -; dec esi -; add esi,511*3 -; add eax,3 -; cmp eax,511*3 -; jl @b -;ret -init_envmap_cub: ; create 512x512 env map -.temp equ word [ebp-2] - push ebp - mov ebp,esp - sub esp,2 - mov edi,envmap_cub - fninit - - mov cx,-256 - .ie_hor: - mov .temp,cx - fild .temp - fabs - ; fmul st,st0 - ; fsqrt - mov .temp,255 - fisubr .temp - fmul [env_const] - fistp .temp - mov ax,.temp - - or ax,ax - jge .ie_ok1 - xor ax,ax - jmp .ie_ok2 - .ie_ok1: - cmp ax,255 - jle .ie_ok2 - mov ax,255 - .ie_ok2: - stosb - stosb - stosb - - inc cx - cmp cx,256 - jne .ie_hor - - mov esp,ebp - pop ebp -ret - -calc_one_col: -; procedure don't save registers !!! -; in - st - dot_product -; stack - other parameters -; out - eax - 0x00rrggbb -.dot_prd equ dword[ebp+4] ; dot product - cos x - not now -.min_col_r equ [ebp+8] ; minimum color - ambient -.min_col_g equ word[ebp+10] -.min_col_b equ word[ebp+12] -.max_col_r equ [ebp+14] ; maximum color - specular -.max_col_g equ word[ebp+16] -.max_col_b equ word[ebp+18] -.org_col_r equ [ebp+20] ; orginal color - diffuse -.org_col_g equ word[ebp+22] -.org_col_b equ word[ebp+24] -.n equ word[ebp+26] ; shines - not implemented -.temp equ word[ebp-2] -.color_sum_r equ [ebp-6] -.color_sum_g equ [ebp-10] -.color_sum_b equ [ebp-14] -; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular - mov ebp,esp - sub esp,14 - - - mov ax,.min_col_r - add ax,.max_col_r - add ax,.org_col_r - cwde - mov .color_sum_r,eax - - mov ax,.min_col_g - add ax,.max_col_g - add ax,.org_col_g - cwde - mov .color_sum_g,eax - - mov ax,.min_col_b - add ax,.max_col_b - add ax,.org_col_b - cwde - mov .color_sum_b,eax -if 0 - - - movq xmm0,.min_col_r - movq xmm1,.max_col_r - movq xmm2,.org_col_r - packuswb xmm0,[the_zero] - packuswb xmm1,[the_zero] - packuswb xmm2,[the_zero] - punpcklbw xmm0,xmm1 - punpcklbw xmm2,[the_zero] - packusdw xmm2,[the_zero] - cvtdq2ps xmm0,xmm0 - cvtdq2ps xmm1,xmm1 - cvtdq2ps xmm2,xmm2 - haddps xmm0,xmm0 - haddps xmm1,xmm1 - haddps xmm2,xmm2 - haddps xmm0,xmm0 - haddps xmm1,xmm1 - haddps xmm2,xmm2 - - cvtss2si eax,xmm0 - cvtss2si ebx,xmm1 - cvtss2si ecx,xmm2 - mov .color_sum_r,eax - mov .color_sum_g,ebx - mov .color_sum_b,ecx - - -end if - -; fld .dot_prd - ; fild .n - ; fxch st1 - ; fabs - ; fyl2x ; - ; f2xm1 - ; fld1 - ; faddp ; st = dot_product ^ n - - fld st ; copy dot pr - fmul st,st0 - fmul st,st0 - fmul st,st0 - cmp .n,255 ; .n = 255 -> spot light - jne @f - fmul st,st0 - fmul st,st0 - fmul st,st0 - @@: - fld st ; st0=st1=dot_pr^n, st2=dot_pr - fimul .max_col_b - fild .org_col_b - fmul st,st3 - faddp ; st0=first piece of col, st1=dot_pr^n.. - fiadd .min_col_b - fimul .max_col_b - fidiv dword .color_sum_b - fistp .temp - movzx eax,.temp - shl eax,16 - - fld st - fimul .max_col_g - fild .org_col_g - fmul st,st3 - faddp - fiadd .min_col_g - fimul .max_col_g - fidiv dword .color_sum_g - fistp .temp - mov ax,.temp - mov ah,al - shl eax,8 - - fimul word .max_col_r - fild word .org_col_r - fmulp st2,st - faddp - fiadd word .min_col_r - fimul word .max_col_r - fidiv dword .color_sum_r - fistp .temp - mov ax,.temp ;eax - 0xbbgg00rr - ; mov ah,al - ror eax,16 - xchg al,ah ; eax - 0x00rrggbb - mov esp,ebp -ret 24 - -calc_bumpmap: ; calculate random bumpmap -;--------------in edi _ pointer to TEX_X x TEX_Y bumpmap - - push edi - - cmp [bumps_flag],0 - je .random_bump_map - ; else bumps according to texture - mov esi,texmap - mov ecx,TEXTURE_SIZE - @@: - movzx ax,byte[esi] - movzx bx,byte[esi+1] - movzx dx,byte[esi+2] - add ax,bx - add ax,dx - cwd - div [i3] - stosb - add esi,3 - loop @b - jmp .blur_map -; push ecx -; mov eax,0x88888888 -; mov ecx,16/4 -; rep stosd -; mov eax,0xffffffff -; mov ecx,16/4 -; rep stosd -; pop ecx -; loop @b - .random_bump_map: - - mov ecx,TEXTURE_SIZE - @@: - push ecx - xor ecx,ecx - mov edx,255 - call random - stosb - pop ecx - loop @b - - .blur_map: - pop edi - movzx ecx,[bumps_deep_flag] - inc cx - .blur: - xor esi,esi - mov edx,TEXTURE_SIZE - xor eax,eax - xor ebx,ebx - @@: - mov ebp,esi - dec ebp - and ebp,TEXTURE_SIZE - mov al,byte[ebp+edi] - - mov ebp,esi - inc ebp - and ebp,TEXTURE_SIZE - mov bl,byte[ebp+edi] - add eax,ebx - - mov ebp,esi - sub ebp,TEX_X - and ebp,TEXTURE_SIZE - mov bl,byte[ebp+edi] - add eax,ebx - - mov ebp,esi - add ebp,TEX_X - and ebp,TEXTURE_SIZE - mov bl,byte[ebp+edi] - add eax,ebx - - shr eax,2 - mov byte[esi+edi],al - - inc esi - dec edx - jnz @b - - loop .blur -ret -random: -; in - ecx - min -; edx - max -; out - eax - random number - mov bx,[rand_seed] - add bx,0x9248 - ror bx,3 - mov [rand_seed],bx - - mov ax,dx - sub ax,cx - mul bx - mov ax,dx - add ax,cx - cwde -ret - -optimize_object1: ; setting point (0,0,0) in center of object - ; recalculate all coords , scale object, - ;the coords in <-1.0,1.0> -;in : real_points - table filled of real float dd coordinates (x,y,z), end mark dd -1 -; _ global variable -; points_count_var - dw integer variable with exactly points count -; - global variable -; SIZE_X, SIZE_Y must be defined - -.max equ dword[ebp-4] -.min equ dword[ebp-8] -.maxxx equ dword[ebp-12] -.center equ dword[ebp-16] - - mov ebp,esp - sub esp,16 - fninit - mov .maxxx,0 - mov ecx,3 - xor ebx,ebx ; ebx - x,y,z coord in real_points list - .next_c: ; max/min/center x,y,z - mov edi,[points_ptr] ; in real_point list minimum two points - mov edx,[points_count_var] - fld dword[edi+ebx] - fst .max - fstp .min - add edi,12 - dec edx - .next_coord: ; next coord from real_points list - fld dword [edi+ebx] ; real_points -> x,y,z - fcom .max ; max_x,y,z - fstsw ax - sahf - jbe @f ; jmp less equal - fstp .max ; new max_x,y,z - jmp .end_coords - @@: - fcom .min ; min_x,y,z - fstsw ax - sahf - jnbe @f ; jmp greater - fst .min ; new min_x - @@: - ffree st - .end_coords: - add edi,12 - ; cmp dword[edi],-1 ; cmp with end mark - dec edx - jnz .next_coord - ; ok after this we found max_coord and min_coord - fld .max ; find center point - fadd .min - fld1 - fld1 - faddp - fdivp st1,st ; st0 - center coord - fstp .center - - fld .max - fsub .center ; st = .max - .center - fcom .maxxx ; maximum of all .max - fstsw ax - sahf - jbe @f ; jmp lower - fst .maxxx ; new maxx - @@: - ffree st - mov edi,[points_ptr] - mov edx,[points_count_var] ; substraction all coords - center point - @@: - fld dword[edi+ebx] - fsub .center - fstp dword[edi+ebx] - add edi,12 -; cmp dword[edi],-1 -; jne @b - dec edx - jnz @b - - add ebx,4 ; ebx - x,y,z cooficientes in list real_points - dec ecx - jnz .next_c - - fld .maxxx - mov edi,[points_ptr] ; create all coords in <-1.0,1.0> - mov ecx,[points_count_var] - @@: - fld dword[edi] - fdiv .maxxx - fstp dword[edi] - fld dword[edi+4] - fdiv .maxxx - fstp dword[edi+4] - fld dword[edi+8] - fdiv .maxxx - fstp dword[edi+8] - add edi,12 - loop @b - ; cmp dword[edi],-1 - - ; jne @b - - mov esp,ebp -ret - -generate_object: ; generate node -.N equ 32 -.x equ word[ebp-2] -.Ndiv2 equ word[ebp-10] -.MthickSqr equ dword[ebp-14] ; diameter^2 -.temp equ dword[ebp-18] ; variable for x <-1;1> -.Hthick equ dword[ebp-22] -.cos_temp equ dword[ebp-26] -.next_const equ dword[ebp-30] -.a equ dword[ebp-34] -.Pi2 equ ebp-38 - - - - mov ebp,esp - sub esp,42 - - mov .Ndiv2,.N/2 - fninit - fldpi - fadd st,st - fst dword[.Pi2] - fidiv .Ndiv2 - fst .a ; .Ndiv2*.a=2Pi => .a=2pi/.Ndiv2 - - fld [.Mthick] ; inside diameter, (outside daiameter = 1) - fmul st,st0 - fstp .MthickSqr - fld1 - - fsub [.Mthick] - - fst .Hthick ; Hthick = 1 - Mthick - fld st - fadd st,st - faddp - fstp .next_const ; next_const = Hthick * 3 - - - ;init triangles list - mov edi,[triangles_ptr] - - xor esi,esi - xor eax,eax - mov ebx,.N+1 - mov ecx,(.N*2)+2 ;-- - mov edx,(.N*3)+3 ;--- - mov [triangles_count_var],0 - .again_tri: - stosd ; main wave - mov dword[edi],ebx - inc eax - add edi,4 - stosd - stosd - mov dword[edi],ebx - inc ebx - mov dword[edi+4],ebx - - - add edi,8 - - mov dword[edi],ecx ;---- ; n2+2 ; xor ax,ax - inc ecx ; n2+3 ; mov bx,.N+1 - mov dword[edi+4],edx ; ; mov cx,(.N*2)+2 ;-- - mov dword[edi+8],ecx ; n3+3 ; mov dx,(.N*3)+3 ;--- - mov dword[edi+12],edx ; n3+3 ; - inc edx ; ; - mov dword[edi+16],edx ; n2+3 ; - mov dword[edi+20],ecx ; n3+4 - add edi,24 ;---- - - dec eax ; border of wave - dec ebx - dec ecx - dec edx - - stosd ; first border - inc eax - stosd - mov dword[edi],edx - add edi,4 - - mov dword[edi],edx - add edi,4 - stosd - inc edx - mov dword[edi],edx - - mov dword[edi+4],ebx ; second border - mov dword[edi+8],ecx - inc ebx - mov dword[edi+12],ebx - - mov dword[edi+16],ebx - mov dword[edi+20],ecx - inc ecx - mov dword[edi+24],ecx - add edi,28 - - add [triangles_count_var],8 ;10 - inc esi - cmp esi,.N - jne .again_tri - - add eax,((.N+1)*3)+1 - add ebx,((.N+1)*3)+1 - add ecx,((.N+1)*3)+1 - add edx,((.N+1)*3)+1 - xor esi,esi - cmp eax,(.N*13)+13 ;;;(.N*23)+23 ; ax,(.N*13)+13 - jl .again_tri - - ; mov dword[edi],-1 ; <--- end mark not always in use - - ; init real points list - mov .x,-(.N/2) - mov edi,[points_ptr] - lea esi,[edi+(12*(.N+1))] - mov eax,[points_ptr] - mov ebx,eax - add eax,2*12*(.N+1) ;--- - add ebx,3*12*(.N+1) ;--- - mov [points_count_var],0 - - - .R_P4 equ edi+(4*12*(.N+1)) - .R_P5 equ edi+(5*12*(.N+1)) - .R_P6 equ edi+(6*12*(.N+1)) - .R_P7 equ edi+(7*12*(.N+1)) - - .R_P8 equ edi+(8*12*(.N+1)) - .R_P9 equ edi+(9*12*(.N+1)) - .R_P10 equ edi+(10*12*(.N+1)) - .R_P11 equ edi+(11*12*(.N+1)) - - .R_P12 equ edi+(12*12*(.N+1)) - .R_P13 equ edi+(13*12*(.N+1)) - .R_P14 equ edi+(14*12*(.N+1)) - .R_P15 equ edi+(15*12*(.N+1)) - - @@: - ; x coordinate - fild .x - fld st -;; fmul .a ; st = <-2pi;2pi> when mul .a - fidiv .Ndiv2 - fst .temp ; temporary x in <-1.0;1.0> - - fst dword[edi] ;x coordinate of point - fst dword[esi] - fst dword[eax] ;-- - - - fst dword[.R_P4] - fst dword[.R_P5] - fst dword[.R_P6] - fst dword[.R_P7] - - fst dword[.R_P8] - fst dword[.R_P9] - fst dword[.R_P10] - fst dword[.R_P11] - - fst dword[.R_P12] - fst dword[.R_P13] - fst dword[.R_P14] - fst dword[.R_P15] - - fstp dword[ebx] ;pop - ;*******y coord dword[offset + 4] - fmul .a ; st = <-2pi;2pi> - fsincos - fmul .next_const - fst dword[edi+4] ; y coordinate of point - fst dword[esi+4] - fst dword[.R_P4+4] - fst dword[.R_P5+4] - fld .Hthick - faddp - fst dword[.R_P6+4] - fst dword[.R_P7+4] - fst dword[eax+4] - fst dword[ebx+4] - - fchs - fst dword[.R_P10+4] - fst dword[.R_P11+4] - fst dword[.R_P14+4] - fst dword[.R_P15+4] - fadd .Hthick - fadd .Hthick - fst dword[.R_P8+4] - fst dword[.R_P9+4] - fst dword[.R_P12+4] - fstp dword[.R_P13+4] - - - fmul .Hthick - fmul .next_const - fstp .cos_temp ; cos_temp = Hthick^2 * 3 - - ;***************z coord - fld .temp - fld st - fmul st,st0 ; z coords - fchs - fld1 - faddp - fabs - fsqrt -; fld st -; fsub - fld st - fsub .cos_temp - fst dword[esi+8] - fstp dword[eax+8] ;-- - fld st - fadd .cos_temp - fst dword[.R_P9+8] - fstp dword[.R_P10+8] - fchs - fld st - fsub .cos_temp - fst dword[.R_P6+8] - fstp dword[.R_P5+8] - fadd .cos_temp - fst dword[.R_P13+8] - fstp dword[.R_P14+8] - - fmul [.Mthick] - fmul st,st0 - fchs - fld .MthickSqr - faddp - fabs - fsqrt - fld st - fsub .cos_temp - fst dword[edi+8] ; z coordinate - fstp dword[ebx+8] ;-- - fld st - fadd .cos_temp - fst dword[.R_P8+8] - fstp dword[.R_P11+8] - fchs - fld st - fsub .cos_temp - fst dword[.R_P7+8] - fstp dword[.R_P4+8] - fadd .cos_temp - fst dword[.R_P12+8] - fstp dword[.R_P15+8] - - add edi,12 - add esi,12 - add eax,12 ;-- - add ebx,12 ;--- - add [points_count_var],24 ;16 - inc .x - cmp .x,.N/2 - jng @b -; mov dword[esi],-1 ; <-- end mark - mov [culling_flag],0 - mov esp,ebp -ret -.Mthick dd 0.85 ; size-thickness - -make_random_lights: - .temp1 equ ebp-4 - .temp2 equ ebp-8 ; - light vector generate variables - .temp3 equ ebp-12 - .max equ 800 - RDTSC - mov [rand_seed],ax - push ebp - mov ebp,esp - sub esp,12 - mov edi,lights - fninit - mov dword[.temp2],.max - mov dword[.temp3],.max/2 - - .again: - xor esi,esi - @@: - mov edx,.max - xor ecx,ecx - call random - sub eax,.max/2 - mov dword[.temp1],eax - fild dword[.temp1] - fidiv dword[.temp3] - fstp dword[edi+esi*4] - inc esi - cmp esi,2 - jne @b - - .max1 equ 1000 - mov dword[.temp2],.max1/2 - mov edx,.max1 - xor ecx,ecx - call random - mov dword[.temp1],eax - fild dword[.temp1] - fchs - fidiv dword[.temp2] - fstp dword[edi+8] - - xor esi,esi - @@: - mov ecx,220 ; max colors and shine , ecx = 200 - more bright shading - mov edx,255 - call random - mov byte[edi+18+esi],al - inc esi - cmp esi,4 - jne @b - - - xor esi,esi - @@: - mov ecx,100 ; orginal colors - movzx edx,byte[edi+18+esi] - call random - mov byte[edi+12+esi],al - inc esi - cmp esi,3 - jne @b - - xor esi,esi - @@: - mov ecx,1 ; min cols - movzx edx,byte[edi+12+esi] - call random - mov byte[edi+15+esi],al - inc esi - cmp esi,3 - jne @b - - add edi,LIGHT_SIZE ;22 - cmp edi,lightsend ; see file View3ds,asm - jne .again - - mov esp,ebp - pop ebp -ret - -generate_texture2: -.const equ 32 - mov edi,texmap - xor bx,bx - .next_line: - xor dx,dx - .next2stripes: - mov eax,-1 - mov ecx,(TEX_X/.const)*3/4 - rep stosd - mov eax,0x00ff0000 - mov ecx,(TEX_X/.const) - @@: - stosd - dec edi - loop @b - inc dx - cmp dx,.const/2 - jl .next2stripes - inc bx - cmp bx,TEX_Y - jl .next_line -ret - -blur_screen: ;blur n times ; blur or fire -;in - ecx times count -;.counter equ dword[esp-4] -.counter1 equ dword[esp-8] -if Ext>=SSE2 - push ebp - mov ebp,esp - push dword 0x01010101 - movss xmm5,[esp] - shufps xmm5,xmm5,0 - .again_blur: - push ecx - mov edi,[screen_ptr] - movzx ecx,word[size_x_var] ;SIZE_X*3/4 - - cmp [dr_flag],12 - jge @f - lea ecx,[ecx*3+1] - shr ecx,2 - @@: - - xor eax,eax - rep stosd - if 1 - movzx ebx,word[size_x_var] - movzx ecx,word[size_y_var] - sub ecx,3 - imul ecx,ebx - cmp [dr_flag],12 ; 32 bit per pix cause - jge @f - lea ecx,[ecx*3] - shr ecx,4 - lea ebx,[ebx *3] - jmp .blr - @@: - - shr ecx,2 - shl ebx,2 - ; mov ecx,(SIZE_X*(SIZE_Y-3))*3/16 - .blr: - @@: - push ecx - movups xmm0,[edi+ebx] - mov ecx,edi - sub ecx,ebx - movups xmm1,[ecx] - cmp [dr_flag],12 - jge @f - movups xmm2,[edi-3] - movups xmm3,[edi+3] - jmp .f - @@: - movups xmm2,[edi-4] - movups xmm3,[edi+4] - .f: - pavgb xmm0,xmm1 - pavgb xmm2,xmm3 - pavgb xmm0,xmm2 - psubusb xmm0,xmm5 ; importand if fire - movups [edi],xmm0 - add edi,16 - add esi,16 - pop ecx - loop .blr - end if - xor eax,eax - movzx ecx,word[size_x_var] - cmp [dr_flag],12 - jge @f - lea ecx,[ecx*3] - shr ecx,2 - @@: - ; mov ecx,SIZE_X*3/4 - rep stosd - pop ecx - dec ecx - jnz .again_blur - mov esp,ebp - pop ebp -end if - -if Ext=SSE - emms - push ebp - mov ebp,esp - push dword 0x01010101 - push dword 0x01010101 - movq mm4,[esp] - .again_blur: - push ecx - mov edi,[screen_ptr] - movzx ecx,word[size_x_var] ;SIZE_X*3/4 - lea ecx,[ecx*3] - shr ecx,2 - ; pxor mm5,mm5 - xor eax,eax - rep stosd - movzx ebx,word[size_x_var] - movzx ecx,word[size_y_var] - sub ecx,3 - imul ecx,ebx - lea ecx,[ecx*3] - shr ecx,3 - lea ebx,[ebx*3] - ; mov ecx,(SIZE_X*(SIZE_Y-3))*3/8 - .blr: - @@: - movq mm0,[edi+ebx] - movq mm1,[edi-ebx] - movq mm2,[edi-3] - movq mm3,[edi+3] - - pavgb mm0,mm1 - pavgb mm2,mm3 - pavgb mm0,mm2 - - psubusb mm0,mm4 ; importand if fire - - movq [edi],mm0 - add edi,8 - add esi,8 - - loop .blr - - xor eax,eax - mov ecx,[size_x_var] - lea ecx,[ecx*3] - shr ecx,2 - ; SIZE_X*3/4 - rep stosd - pop ecx - loop .again_blur - mov esp,ebp - pop ebp -end if - -if Ext=MMX - emms - push ebp - mov ebp,esp - push dword 0x0 - push dword 0x01010101 -.again_blur: - push ecx - mov edi,[screen_ptr] - mov ecx,SIZE_X*3/4 - pxor mm5,mm5 - xor eax,eax - rep stosd - - mov ecx,(SIZE_X*(SIZE_Y-3))*3/4 - .blr: - @@: - - movd mm0,[edi+SIZE_X*3] - movd mm1,[edi-SIZE_X*3] - movd mm2,[edi-3] - movd mm3,[edi+3] - - punpcklbw mm0,mm5 - punpcklbw mm1,mm5 - punpcklbw mm2,mm5 - punpcklbw mm3,mm5 - paddw mm0,mm1 - paddw mm0,mm2 - paddw mm0,mm3 - psrlw mm0,2 - - packuswb mm0,mm5 - psubusb mm0,qword[esp] ; importand if fire - movd eax,mm0 - stosd - - loop .blr - - xor eax,eax - mov ecx,SIZE_X*3/4 - rep stosd - pop ecx - loop .again_blur - mov esp,ebp - pop ebp -end if -if Ext=NON - .blur: - push ecx - xor ecx,ecx - .next_col_coof: - xor esi,esi - xor eax,eax - xor ebx,ebx - mov edi,SIZE_X*SIZE_Y - .next: - mov ebp,esi - dec ebp - - cmp ebp,SIZE_X*SIZE_Y-1 ; clipping - jl @f - mov ebp,SIZE_X*SIZE_Y-1 - @@: - or ebp,ebp - jg @f - xor ebp,ebp - @@: - lea edx,[ebp*3+screen] - mov al,byte[edx+ecx] - - mov ebp,esi - inc ebp - cmp ebp,SIZE_X*SIZE_Y-1 ; clipping - jl @f - mov ebp,SIZE_X*SIZE_Y-1 - @@: - or ebp,ebp - jg @f - xor ebp,ebp - @@: - lea edx,[ebp*3+screen] - mov bl,byte[edx+ecx] - add eax,ebx - - mov ebp,esi - sub ebp,SIZE_X - cmp ebp,SIZE_X*SIZE_Y-1 ; clipping - jl @f - mov ebp,SIZE_X*SIZE_Y-1 - @@: - or ebp,ebp - jg @f - xor ebp,ebp - @@: - lea edx,[ebp*3+screen] - mov bl,byte[edx+ecx] - add eax,ebx - - mov ebp,esi - add ebp,SIZE_X - cmp ebp,SIZE_X*SIZE_Y-1 ; clipping - jl @f - mov ebp,SIZE_X*SIZE_Y-1 - @@: - or ebp,ebp - jg @f - xor ebp,ebp - @@: - lea edx,[ebp*3+screen] - mov bl,byte[edx+ecx] - add eax,ebx - - shr eax,2 - lea edx,[esi*3+screen] - or al,al - jz @f - dec al ; not importand if fire - mov byte[edx+ecx],al - @@: - - inc esi - dec edi - jnz .next - - inc ecx - cmp ecx,3 - jne .next_col_coof - pop ecx - dec ecx - jnz .blur -end if -ret - -mirror: ; mirror effect - loseless operation -; in ah - button id = 11, 12, 13 - mov edi,[points_ptr] ; one real point - triple float - mov esi,[points_normals_ptr] ; one 3dvector - triple float dword x,y,z - fninit - mov ecx,[points_count_var] - - cmp ah,11 - je @f - cmp ah,12 - je .yn - cmp ah,13 - je .zn - - @@: ; neg x - fld dword[edi] ;x - fchs - fstp dword[edi] ;x - fld dword[esi] - fchs - fstp dword[esi] - add edi,12 - add esi,12 - loop @b - ret - .yn: - fld dword[edi+4] ;y - fchs - fstp dword[edi+4] ;y - fld dword[esi+4] - fchs - fstp dword[esi+4] - - add edi,12 - add esi,12 - loop .yn - ret - .zn: - fld dword[edi+8] ;z - fchs - fstp dword[edi+8] ;z - fld dword[esi+8] - fchs - fstp dword[esi+8] - - add edi,12 - add esi,12 - loop .zn -ret - -exchange: ; exchange some coords - loseless operation - mov edi,[points_ptr] ; one real point - triple float - mov esi,[points_normals_ptr] ; one 3dvector - triple float dword x,y,z - fninit ; exchange both points and normal vactors coords/coofics - mov ecx,[points_count_var] - - cmp [xchg_flag],1 - je @f - cmp [xchg_flag],2 - je .zx - cmp [xchg_flag],3 - je .yz - @@: - fld dword[edi] ;x - fld dword[edi+4] ;y - fstp dword[edi] ;x - fstp dword[edi+4] ;y - fld dword[esi] ;x - fld dword[esi+4] ;y - fstp dword[esi] ;x - fstp dword[esi+4] ;y - - add esi,12 - add edi,12 - loop @b - ret - .zx: - fld dword[edi] ;x - fld dword[edi+8] ;z - fstp dword[edi] ;x - fstp dword[edi+8] ;z - fld dword[esi] ;x - fld dword[esi+8] ;y - fstp dword[esi] ;x - fstp dword[esi+8] ;y - - add esi,12 - add edi,12 - loop .zx - ret - .yz: - fld dword[edi+8] ;z - fld dword[edi+4] ;y - fstp dword[edi+8] ;z - fstp dword[edi+4] ;y - fld dword[esi+8] ;x - fld dword[esi+4] ;y - fstp dword[esi+8] ;x - fstp dword[esi+4] ;y - - add edi,12 - add esi,12 - loop .yz -ret - -;#\\\\\\\\\\\\\\\\\\\\\\\\\comented/////////////////////////////// -if 0 -calc_attenuation_light: ;; calculate point to spot_light distance -; spot light with attenuation ;; and vector, normalize vector, - ;; calc dot_pr and unlinear color according - ;; to dot_product, write to color buff -.distance equ dword[ebp-4] ;; color buff in bumpmap for save the mem -.temp_col equ word[ebp-6] -.vector equ [ebp-20] -.spot_light_ptr equ dword [ebp-24] - mov ebp,esp - sub esp,24 - mov edi,rotated_points_r ;points_rotated - mov edx,point_normals_rotated - mov ecx,bumpmap ; mem area with temp points color list - xor ax,ax ; counter - mov esi,spot_light_params - mov .spot_light_ptr,esi - .again_color: - push eax - lea ebx,.vector - mov esi,.spot_light_ptr ; calc vector fom light to every point - call make_vector_r - ; ebx - ptr to result vector - fld dword [ebx] - fmul st, st - fld dword [ebx+4] - fmul st, st - fld dword [ebx+8] - fmul st, st - faddp st1, st - faddp st1, st - fsqrt - fstp .distance - push edi - mov edi,ebx - call normalize_vector - ; edi - normalized distance vector - mov esi,edx - call dot_product ; esi first vector, edi second vector - ; st0 - dot product - fabs ; why not ? - think about it - pop edi - fldz - fcomip st1 - jbe @f ; st1>0 - mov dword[ecx],0 - mov word[ecx+4],0 - add ecx,6 - ffree st0 - jmp .update_counters - @@: - ; pop edi - - ; calc color(with atenuation), write to buff - ; buff - color of points list - ; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular - - push edx - push edi - - push ecx - push ebp - -; mov eax,spot_light_params - mov eax,.spot_light_ptr - movzx dx,byte[eax+15] - push dx ; shines - movzx dx,byte[eax+8] ; b - push dx ; orginal col - movzx dx,byte[eax+7] ; g - push dx - movzx dx,byte[eax+6] ; r - push dx - movzx dx,byte[eax+14] ; max col - push dx - movzx dx,byte[eax+13] - push dx - movzx dx,byte[eax+12] - push dx - movzx dx,byte[eax+11] ; min col - push dx - movzx dx,byte[eax+10] - push dx - movzx dx,byte[eax+9] - push dx - push eax ; dot pr. (in st0) - call calc_one_col - ; eax - 0x00rrggbb - ; brightness = 1 - (distance/light.fadezero)^fogness - ; if brightness < 0, then brightness = 0 - ; attenuetion equation taken from 3dica tutorial - 1/d^2 isn't perfect - ; color = color * brightness ; fogness = <0.5,2.0> - pop ebp - pop ecx - - fld .distance - mov esi,.spot_light_ptr -; fidiv word[spot_light_params+16] ; fadezero - fidiv word[esi+16] ; fadezero - ; fmul st,st0 ; fogness = 2 - fabs ; to be sure - fchs - fld1 - faddp - fld1 - fcomip st1 - jnbe @f - ffree st0 - fld1 - @@: - fld st ; st - brightness - ror eax,16 - movzx bx,al ; al - r - mov .temp_col,bx - fimul .temp_col - fistp word[ecx] - cmp word[ecx],0 - jge @f - mov word[ecx],0 - @@: - ; mov edx,dword[spot_light_params+12] ; max colors - mov edx,dword[esi+12] ; max colors - movzx bx,dl ; r max - cmp word[ecx],bx ; choose the brightest for r, g, b - jl @f - mov word[ecx],bx - @@: - - add ecx,2 - fld st - ror eax,16 - movzx bx,ah ; g - mov .temp_col,bx - fimul .temp_col - fistp word[ecx] - cmp word[ecx],0 - jg @f - mov word[ecx],0 - @@: - movzx bx,dh ; g max - cmp word[ecx],bx - jle @f - mov word[ecx],bx - @@: - - add ecx,2 - movzx bx,al ; b - mov .temp_col,bx - fimul .temp_col - fistp word[ecx] - cmp word[ecx],0 - jg @f - mov word[ecx],0 - @@: - shr edx,16 - movzx bx,dl ; b max - cmp word[ecx],bx - jle @f - mov word[ecx],bx - @@: - add ecx,2 -;end if -; ror eax,16 -; movzx bx,al -; mov word[ecx],bx -; ror eax,16 -; movzx bx,ah -; mov word[ecx+2],bx -; xor ah,ah -; mov word[ecx+4],ax -; add ecx,6 - - pop edi - pop edx - - .update_counters: - add edx,12 ; normal_size - add edi,12 ;6 ; 3d point_coord_size - - pop eax - inc ax - cmp ax,[points_count_var] - jne .again_color - - add .spot_light_ptr,18 - cmp .spot_light_ptr,spot_l_end - jl .again_color - - mov esp,ebp -ret -end if +;init_envmap_cub2: +; mov esi,envmap +; mov edi,envmap_cub ;take cubic env. map from +; xor eax,eax ;spherical env. map +; @@: +; add esi,eax +; movsd +; dec edi +; dec esi +; add esi,511*3 +; add eax,3 +; cmp eax,511*3 +; jl @b +;ret +init_envmap_cub: ; create 512x512 env map +.temp equ word [ebp-2] + push ebp + mov ebp,esp + sub esp,2 + mov edi,envmap_cub + fninit + + mov cx,-256 + .ie_hor: + mov .temp,cx + fild .temp + fabs + ; fmul st,st0 + ; fsqrt + mov .temp,255 + fisubr .temp + fmul [env_const] + fistp .temp + mov ax,.temp + + or ax,ax + jge .ie_ok1 + xor ax,ax + jmp .ie_ok2 + .ie_ok1: + cmp ax,255 + jle .ie_ok2 + mov ax,255 + .ie_ok2: + stosb + stosb + stosb + + inc cx + cmp cx,256 + jne .ie_hor + + mov esp,ebp + pop ebp +ret + +calc_one_col: +; procedure don't save registers !!! +; in - st - dot_product +; stack - other parameters +; out - eax - 0x00rrggbb +.dot_prd equ dword[ebp+4] ; dot product - cos x - not now +.min_col_r equ word[ebp+8] ; minimum color - ambient +.min_col_g equ word[ebp+10] +.min_col_b equ word[ebp+12] +.max_col_r equ word[ebp+14] ; maximum color - specular +.max_col_g equ word[ebp+16] +.max_col_b equ word[ebp+18] +.org_col_r equ word[ebp+20] ; orginal color - diffuse +.org_col_g equ word[ebp+22] +.org_col_b equ word[ebp+24] +.n equ word[ebp+26] ; shines - not implemented +.temp equ word[ebp-2] +.color_sum_r equ dword[ebp-6] +.color_sum_g equ dword[ebp-10] +.color_sum_b equ dword[ebp-14] +; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular + mov ebp,esp + sub esp,14 + + mov ax,.min_col_r + add ax,.max_col_r + add ax,.org_col_r + cwde + mov .color_sum_r,eax + + mov ax,.min_col_g + add ax,.max_col_g + add ax,.org_col_g + cwde + mov .color_sum_g,eax + + mov ax,.min_col_b + add ax,.max_col_b + add ax,.org_col_b + cwde + mov .color_sum_b,eax + + +; fld .dot_prd + ; fild .n + ; fxch st1 + ; fabs + ; fyl2x ; + ; f2xm1 + ; fld1 + ; faddp ; st = dot_product ^ n + + fld st ; copy dot pr + fmul st,st0 + fmul st,st0 + fmul st,st0 + cmp .n,255 ; .n = 255 -> spot light + jne @f + fmul st,st0 + fmul st,st0 + fmul st,st0 + @@: + fld st ; st0=st1=dot_pr^n, st2=dot_pr + fimul .max_col_b + fild .org_col_b + fmul st,st3 + faddp ; st0=first piece of col, st1=dot_pr^n.. + fiadd .min_col_b + fimul .max_col_b + fidiv .color_sum_b + fistp .temp + movzx eax,.temp + shl eax,16 + + fld st + fimul .max_col_g + fild .org_col_g + fmul st,st3 + faddp + fiadd .min_col_g + fimul .max_col_g + fidiv .color_sum_g + fistp .temp + mov ax,.temp + mov ah,al + shl eax,8 + + fimul .max_col_r + fild .org_col_r + fmulp st2,st + faddp + fiadd .min_col_r + fimul .max_col_r + fidiv .color_sum_r + fistp .temp + mov ax,.temp ;eax - 0xbbgg00rr + ; mov ah,al + ror eax,16 + xchg al,ah ; eax - 0x00rrggbb + mov esp,ebp +ret 24 + +calc_bumpmap: ; calculate random bumpmap +;--------------in edi _ pointer to TEX_X x TEX_Y bumpmap + + push edi + + cmp [bumps_flag],0 + je .random_bump_map + ; else bumps according to texture + mov esi,texmap + mov ecx,TEXTURE_SIZE + @@: + movzx ax,byte[esi] + movzx bx,byte[esi+1] + movzx dx,byte[esi+2] + add ax,bx + add ax,dx + cwd + div [i3] + stosb + add esi,3 + loop @b + jmp .blur_map +; push ecx +; mov eax,0x88888888 +; mov ecx,16/4 +; rep stosd +; mov eax,0xffffffff +; mov ecx,16/4 +; rep stosd +; pop ecx +; loop @b + .random_bump_map: + + mov ecx,TEXTURE_SIZE + @@: + push ecx + xor ecx,ecx + mov edx,255 + call random + stosb + pop ecx + loop @b + + .blur_map: + pop edi + movzx ecx,[bumps_deep_flag] + inc cx + .blur: + xor esi,esi + mov edx,TEXTURE_SIZE + xor eax,eax + xor ebx,ebx + @@: + mov ebp,esi + dec ebp + and ebp,TEXTURE_SIZE + mov al,byte[ebp+edi] + + mov ebp,esi + inc ebp + and ebp,TEXTURE_SIZE + mov bl,byte[ebp+edi] + add eax,ebx + + mov ebp,esi + sub ebp,TEX_X + and ebp,TEXTURE_SIZE + mov bl,byte[ebp+edi] + add eax,ebx + + mov ebp,esi + add ebp,TEX_X + and ebp,TEXTURE_SIZE + mov bl,byte[ebp+edi] + add eax,ebx + + shr eax,2 + mov byte[esi+edi],al + + inc esi + dec edx + jnz @b + + loop .blur +ret +random: +; in - ecx - min +; edx - max +; out - eax - random number + mov bx,[rand_seed] + add bx,0x9248 + ror bx,3 + mov [rand_seed],bx + + mov ax,dx + sub ax,cx + mul bx + mov ax,dx + add ax,cx + cwde +ret + +optimize_object1: ; setting point (0,0,0) in center of object + ; recalculate all coords , scale object, + ;the coords in <-1.0,1.0> +;in : real_points - table filled of real float dd coordinates (x,y,z), end mark dd -1 +; _ global variable +; points_count_var - dw integer variable with exactly points count +; - global variable +; SIZE_X, SIZE_Y must be defined + +.max equ dword[ebp-4] +.min equ dword[ebp-8] +.maxxx equ dword[ebp-12] +.center equ dword[ebp-16] + + mov ebp,esp + sub esp,16 + fninit + mov .maxxx,0 + mov ecx,3 + xor ebx,ebx ; ebx - x,y,z coord in real_points list + .next_c: ; max/min/center x,y,z + mov edi,[points_ptr] ; in real_point list minimum two points + mov edx,[points_count_var] + fld dword[edi+ebx] + fst .max + fstp .min + add edi,12 + dec edx + .next_coord: ; next coord from real_points list + fld dword [edi+ebx] ; real_points -> x,y,z + fcom .max ; max_x,y,z + fstsw ax + sahf + jbe @f ; jmp less equal + fstp .max ; new max_x,y,z + jmp .end_coords + @@: + fcom .min ; min_x,y,z + fstsw ax + sahf + jnbe @f ; jmp greater + fst .min ; new min_x + @@: + ffree st + .end_coords: + add edi,12 + ; cmp dword[edi],-1 ; cmp with end mark + dec edx + jnz .next_coord + ; ok after this we found max_coord and min_coord + fld .max ; find center point + fadd .min + fld1 + fld1 + faddp + fdivp st1,st ; st0 - center coord + fstp .center + + fld .max + fsub .center ; st = .max - .center + fcom .maxxx ; maximum of all .max + fstsw ax + sahf + jbe @f ; jmp lower + fst .maxxx ; new maxx + @@: + ffree st + mov edi,[points_ptr] + mov edx,[points_count_var] ; substraction all coords - center point + @@: + fld dword[edi+ebx] + fsub .center + fstp dword[edi+ebx] + add edi,12 +; cmp dword[edi],-1 +; jne @b + dec edx + jnz @b + + add ebx,4 ; ebx - x,y,z cooficientes in list real_points + dec ecx + jnz .next_c + + fld .maxxx + mov edi,[points_ptr] ; create all coords in <-1.0,1.0> + mov ecx,[points_count_var] + @@: + fld dword[edi] + fdiv .maxxx + fstp dword[edi] + fld dword[edi+4] + fdiv .maxxx + fstp dword[edi+4] + fld dword[edi+8] + fdiv .maxxx + fstp dword[edi+8] + add edi,12 + loop @b + ; cmp dword[edi],-1 + + ; jne @b + + mov esp,ebp +ret + +generate_object: ; generate node +.N equ 32 +.x equ word[ebp-2] +.Ndiv2 equ word[ebp-10] +.MthickSqr equ dword[ebp-14] ; diameter^2 +.temp equ dword[ebp-18] ; variable for x <-1;1> +.Hthick equ dword[ebp-22] +.cos_temp equ dword[ebp-26] +.next_const equ dword[ebp-30] +.a equ dword[ebp-34] +.Pi2 equ ebp-38 + + + + mov ebp,esp + sub esp,42 + + mov .Ndiv2,.N/2 + fninit + fldpi + fadd st,st + fst dword[.Pi2] + fidiv .Ndiv2 + fst .a ; .Ndiv2*.a=2Pi => .a=2pi/.Ndiv2 + + fld [.Mthick] ; inside diameter, (outside daiameter = 1) + fmul st,st0 + fstp .MthickSqr + fld1 + + fsub [.Mthick] + + fst .Hthick ; Hthick = 1 - Mthick + fld st + fadd st,st + faddp + fstp .next_const ; next_const = Hthick * 3 + + + ;init triangles list + mov edi,[triangles_ptr] + + xor esi,esi + xor eax,eax + mov ebx,.N+1 + mov ecx,(.N*2)+2 ;-- + mov edx,(.N*3)+3 ;--- + mov [triangles_count_var],0 + .again_tri: + stosd ; main wave + mov dword[edi],ebx + inc eax + add edi,4 + stosd + stosd + mov dword[edi],ebx + inc ebx + mov dword[edi+4],ebx + + + add edi,8 + + mov dword[edi],ecx ;---- ; n2+2 ; xor ax,ax + inc ecx ; n2+3 ; mov bx,.N+1 + mov dword[edi+4],edx ; ; mov cx,(.N*2)+2 ;-- + mov dword[edi+8],ecx ; n3+3 ; mov dx,(.N*3)+3 ;--- + mov dword[edi+12],edx ; n3+3 ; + inc edx ; ; + mov dword[edi+16],edx ; n2+3 ; + mov dword[edi+20],ecx ; n3+4 + add edi,24 ;---- + + dec eax ; border of wave + dec ebx + dec ecx + dec edx + + stosd ; first border + inc eax + stosd + mov dword[edi],edx + add edi,4 + + mov dword[edi],edx + add edi,4 + stosd + inc edx + mov dword[edi],edx + + mov dword[edi+4],ebx ; second border + mov dword[edi+8],ecx + inc ebx + mov dword[edi+12],ebx + + mov dword[edi+16],ebx + mov dword[edi+20],ecx + inc ecx + mov dword[edi+24],ecx + add edi,28 + + add [triangles_count_var],8 ;10 + inc esi + cmp esi,.N + jne .again_tri + + add eax,((.N+1)*3)+1 + add ebx,((.N+1)*3)+1 + add ecx,((.N+1)*3)+1 + add edx,((.N+1)*3)+1 + xor esi,esi + cmp eax,(.N*13)+13 ;;;(.N*23)+23 ; ax,(.N*13)+13 + jl .again_tri + + ; mov dword[edi],-1 ; <--- end mark not always in use + + ; init real points list + mov .x,-(.N/2) + mov edi,[points_ptr] + lea esi,[edi+(12*(.N+1))] + mov eax,[points_ptr] + mov ebx,eax + add eax,2*12*(.N+1) ;--- + add ebx,3*12*(.N+1) ;--- + mov [points_count_var],0 + + + .R_P4 equ edi+(4*12*(.N+1)) + .R_P5 equ edi+(5*12*(.N+1)) + .R_P6 equ edi+(6*12*(.N+1)) + .R_P7 equ edi+(7*12*(.N+1)) + + .R_P8 equ edi+(8*12*(.N+1)) + .R_P9 equ edi+(9*12*(.N+1)) + .R_P10 equ edi+(10*12*(.N+1)) + .R_P11 equ edi+(11*12*(.N+1)) + + .R_P12 equ edi+(12*12*(.N+1)) + .R_P13 equ edi+(13*12*(.N+1)) + .R_P14 equ edi+(14*12*(.N+1)) + .R_P15 equ edi+(15*12*(.N+1)) + + @@: + ; x coordinate + fild .x + fld st +;; fmul .a ; st = <-2pi;2pi> when mul .a + fidiv .Ndiv2 + fst .temp ; temporary x in <-1.0;1.0> + + fst dword[edi] ;x coordinate of point + fst dword[esi] + fst dword[eax] ;-- + + + fst dword[.R_P4] + fst dword[.R_P5] + fst dword[.R_P6] + fst dword[.R_P7] + + fst dword[.R_P8] + fst dword[.R_P9] + fst dword[.R_P10] + fst dword[.R_P11] + + fst dword[.R_P12] + fst dword[.R_P13] + fst dword[.R_P14] + fst dword[.R_P15] + + fstp dword[ebx] ;pop + ;*******y coord dword[offset + 4] + fmul .a ; st = <-2pi;2pi> + fsincos + fmul .next_const + fst dword[edi+4] ; y coordinate of point + fst dword[esi+4] + fst dword[.R_P4+4] + fst dword[.R_P5+4] + fld .Hthick + faddp + fst dword[.R_P6+4] + fst dword[.R_P7+4] + fst dword[eax+4] + fst dword[ebx+4] + + fchs + fst dword[.R_P10+4] + fst dword[.R_P11+4] + fst dword[.R_P14+4] + fst dword[.R_P15+4] + fadd .Hthick + fadd .Hthick + fst dword[.R_P8+4] + fst dword[.R_P9+4] + fst dword[.R_P12+4] + fstp dword[.R_P13+4] + + + fmul .Hthick + fmul .next_const + fstp .cos_temp ; cos_temp = Hthick^2 * 3 + + ;***************z coord + fld .temp + fld st + fmul st,st0 ; z coords + fchs + fld1 + faddp + fabs + fsqrt +; fld st +; fsub + fld st + fsub .cos_temp + fst dword[esi+8] + fstp dword[eax+8] ;-- + fld st + fadd .cos_temp + fst dword[.R_P9+8] + fstp dword[.R_P10+8] + fchs + fld st + fsub .cos_temp + fst dword[.R_P6+8] + fstp dword[.R_P5+8] + fadd .cos_temp + fst dword[.R_P13+8] + fstp dword[.R_P14+8] + + fmul [.Mthick] + fmul st,st0 + fchs + fld .MthickSqr + faddp + fabs + fsqrt + fld st + fsub .cos_temp + fst dword[edi+8] ; z coordinate + fstp dword[ebx+8] ;-- + fld st + fadd .cos_temp + fst dword[.R_P8+8] + fstp dword[.R_P11+8] + fchs + fld st + fsub .cos_temp + fst dword[.R_P7+8] + fstp dword[.R_P4+8] + fadd .cos_temp + fst dword[.R_P12+8] + fstp dword[.R_P15+8] + + add edi,12 + add esi,12 + add eax,12 ;-- + add ebx,12 ;--- + add [points_count_var],24 ;16 + inc .x + cmp .x,.N/2 + jng @b +; mov dword[esi],-1 ; <-- end mark + mov [culling_flag],0 + mov esp,ebp +ret +.Mthick dd 0.85 ; size-thickness + +make_random_lights: + .temp1 equ ebp-4 + .temp2 equ ebp-8 ; - light vector generate variables + .temp3 equ ebp-12 + .max equ 800 + RDTSC + mov [rand_seed],ax + push ebp + mov ebp,esp + sub esp,12 + mov edi,lights + fninit + mov dword[.temp2],.max + mov dword[.temp3],.max/2 + + .again: + xor esi,esi + @@: + mov edx,.max + xor ecx,ecx + call random + sub eax,.max/2 + mov dword[.temp1],eax + fild dword[.temp1] + fidiv dword[.temp3] + fstp dword[edi+esi*4] + inc esi + cmp esi,2 + jne @b + + .max1 equ 1000 + mov dword[.temp2],.max1/2 + mov edx,.max1 + xor ecx,ecx + call random + mov dword[.temp1],eax + fild dword[.temp1] + fchs + fidiv dword[.temp2] + fstp dword[edi+8] + + xor esi,esi + @@: + mov ecx,220 ; max colors and shine , ecx = 200 - more bright shading + mov edx,255 + call random + mov byte[edi+18+esi],al + inc esi + cmp esi,4 + jne @b + + + xor esi,esi + @@: + mov ecx,100 ; orginal colors + movzx edx,byte[edi+18+esi] + call random + mov byte[edi+12+esi],al + inc esi + cmp esi,3 + jne @b + + xor esi,esi + @@: + mov ecx,1 ; min cols + movzx edx,byte[edi+12+esi] + call random + mov byte[edi+15+esi],al + inc esi + cmp esi,3 + jne @b + + add edi,LIGHT_SIZE ;22 + cmp edi,lightsend ; see file View3ds,asm + jne .again + + mov esp,ebp + pop ebp +ret + +generate_texture2: +.const equ 32 + mov edi,texmap + xor bx,bx + .next_line: + xor dx,dx + .next2stripes: + mov eax,-1 + mov ecx,(TEX_X/.const)*3/4 + rep stosd + mov eax,0x00ff0000 + mov ecx,(TEX_X/.const) + @@: + stosd + dec edi + loop @b + inc dx + cmp dx,.const/2 + jl .next2stripes + inc bx + cmp bx,TEX_Y + jl .next_line +ret + +blur_screen: ;blur n times ; blur or fire +;in - ecx times count +;.counter equ dword[esp-4] +.counter1 equ dword[esp-8] +if Ext>=SSE2 + push ebp + mov ebp,esp + push dword 0x01010101 + movss xmm5,[esp] + shufps xmm5,xmm5,0 + .again_blur: + push ecx + mov edi,[screen_ptr] + movzx ecx,word[size_x_var] ;SIZE_X*3/4 + + cmp [dr_flag],12 + jge @f + lea ecx,[ecx*3+1] + shr ecx,2 + @@: + + xor eax,eax + rep stosd + if 1 + movzx ebx,word[size_x_var] + movzx ecx,word[size_y_var] + sub ecx,3 + imul ecx,ebx + cmp [dr_flag],12 ; 32 bit per pix cause + jge @f + lea ecx,[ecx*3] + shr ecx,4 + lea ebx,[ebx *3] + jmp .blr + @@: + + shr ecx,2 + shl ebx,2 + ; mov ecx,(SIZE_X*(SIZE_Y-3))*3/16 + .blr: + @@: + push ecx + movups xmm0,[edi+ebx] + mov ecx,edi + sub ecx,ebx + movups xmm1,[ecx] + cmp [dr_flag],12 + jge @f + movups xmm2,[edi-3] + movups xmm3,[edi+3] + jmp .f + @@: + movups xmm2,[edi-4] + movups xmm3,[edi+4] + .f: + pavgb xmm0,xmm1 + pavgb xmm2,xmm3 + pavgb xmm0,xmm2 + psubusb xmm0,xmm5 ; importand if fire + movups [edi],xmm0 + add edi,16 + add esi,16 + pop ecx + loop .blr + end if + xor eax,eax + movzx ecx,word[size_x_var] + cmp [dr_flag],12 + jge @f + lea ecx,[ecx*3] + shr ecx,2 + @@: + ; mov ecx,SIZE_X*3/4 + rep stosd + pop ecx + dec ecx + jnz .again_blur + mov esp,ebp + pop ebp +end if + +if Ext=SSE + emms + push ebp + mov ebp,esp + push dword 0x01010101 + push dword 0x01010101 + movq mm4,[esp] + .again_blur: + push ecx + mov edi,[screen_ptr] + movzx ecx,word[size_x_var] ;SIZE_X*3/4 + lea ecx,[ecx*3] + shr ecx,2 + ; pxor mm5,mm5 + xor eax,eax + rep stosd + movzx ebx,word[size_x_var] + movzx ecx,word[size_y_var] + sub ecx,3 + imul ecx,ebx + lea ecx,[ecx*3] + shr ecx,3 + lea ebx,[ebx*3] + ; mov ecx,(SIZE_X*(SIZE_Y-3))*3/8 + .blr: + @@: + movq mm0,[edi+ebx] + movq mm1,[edi-ebx] + movq mm2,[edi-3] + movq mm3,[edi+3] + + pavgb mm0,mm1 + pavgb mm2,mm3 + pavgb mm0,mm2 + + psubusb mm0,mm4 ; importand if fire + + movq [edi],mm0 + add edi,8 + add esi,8 + + loop .blr + + xor eax,eax + mov ecx,[size_x_var] + lea ecx,[ecx*3] + shr ecx,2 + ; SIZE_X*3/4 + rep stosd + pop ecx + loop .again_blur + mov esp,ebp + pop ebp +end if + +if Ext=MMX + emms + push ebp + mov ebp,esp + push dword 0x0 + push dword 0x01010101 +.again_blur: + push ecx + mov edi,[screen_ptr] + mov ecx,SIZE_X*3/4 + pxor mm5,mm5 + xor eax,eax + rep stosd + + mov ecx,(SIZE_X*(SIZE_Y-3))*3/4 + .blr: + @@: + + movd mm0,[edi+SIZE_X*3] + movd mm1,[edi-SIZE_X*3] + movd mm2,[edi-3] + movd mm3,[edi+3] + + punpcklbw mm0,mm5 + punpcklbw mm1,mm5 + punpcklbw mm2,mm5 + punpcklbw mm3,mm5 + paddw mm0,mm1 + paddw mm0,mm2 + paddw mm0,mm3 + psrlw mm0,2 + + packuswb mm0,mm5 + psubusb mm0,qword[esp] ; importand if fire + movd eax,mm0 + stosd + + loop .blr + + xor eax,eax + mov ecx,SIZE_X*3/4 + rep stosd + pop ecx + loop .again_blur + mov esp,ebp + pop ebp +end if +if Ext=NON + .blur: + push ecx + xor ecx,ecx + .next_col_coof: + xor esi,esi + xor eax,eax + xor ebx,ebx + mov edi,SIZE_X*SIZE_Y + .next: + mov ebp,esi + dec ebp + + cmp ebp,SIZE_X*SIZE_Y-1 ; clipping + jl @f + mov ebp,SIZE_X*SIZE_Y-1 + @@: + or ebp,ebp + jg @f + xor ebp,ebp + @@: + lea edx,[ebp*3+screen] + mov al,byte[edx+ecx] + + mov ebp,esi + inc ebp + cmp ebp,SIZE_X*SIZE_Y-1 ; clipping + jl @f + mov ebp,SIZE_X*SIZE_Y-1 + @@: + or ebp,ebp + jg @f + xor ebp,ebp + @@: + lea edx,[ebp*3+screen] + mov bl,byte[edx+ecx] + add eax,ebx + + mov ebp,esi + sub ebp,SIZE_X + cmp ebp,SIZE_X*SIZE_Y-1 ; clipping + jl @f + mov ebp,SIZE_X*SIZE_Y-1 + @@: + or ebp,ebp + jg @f + xor ebp,ebp + @@: + lea edx,[ebp*3+screen] + mov bl,byte[edx+ecx] + add eax,ebx + + mov ebp,esi + add ebp,SIZE_X + cmp ebp,SIZE_X*SIZE_Y-1 ; clipping + jl @f + mov ebp,SIZE_X*SIZE_Y-1 + @@: + or ebp,ebp + jg @f + xor ebp,ebp + @@: + lea edx,[ebp*3+screen] + mov bl,byte[edx+ecx] + add eax,ebx + + shr eax,2 + lea edx,[esi*3+screen] + or al,al + jz @f + dec al ; not importand if fire + mov byte[edx+ecx],al + @@: + + inc esi + dec edi + jnz .next + + inc ecx + cmp ecx,3 + jne .next_col_coof + pop ecx + dec ecx + jnz .blur +end if +ret + +mirror: ; mirror effect - loseless operation +; in ah - button id = 11, 12, 13 + mov edi,[points_ptr] ; one real point - triple float + mov esi,[points_normals_ptr] ; one 3dvector - triple float dword x,y,z + fninit + mov ecx,[points_count_var] + + cmp ah,11 + je @f + cmp ah,12 + je .yn + cmp ah,13 + je .zn + + @@: ; neg x + fld dword[edi] ;x + fchs + fstp dword[edi] ;x + fld dword[esi] + fchs + fstp dword[esi] + add edi,12 + add esi,12 + loop @b + ret + .yn: + fld dword[edi+4] ;y + fchs + fstp dword[edi+4] ;y + fld dword[esi+4] + fchs + fstp dword[esi+4] + + add edi,12 + add esi,12 + loop .yn + ret + .zn: + fld dword[edi+8] ;z + fchs + fstp dword[edi+8] ;z + fld dword[esi+8] + fchs + fstp dword[esi+8] + + add edi,12 + add esi,12 + loop .zn +ret + +exchange: ; exchange some coords - loseless operation + mov edi,[points_ptr] ; one real point - triple float + mov esi,[points_normals_ptr] ; one 3dvector - triple float dword x,y,z + fninit ; exchange both points and normal vactors coords/coofics + mov ecx,[points_count_var] + + cmp [xchg_flag],1 + je @f + cmp [xchg_flag],2 + je .zx + cmp [xchg_flag],3 + je .yz + @@: + fld dword[edi] ;x + fld dword[edi+4] ;y + fstp dword[edi] ;x + fstp dword[edi+4] ;y + fld dword[esi] ;x + fld dword[esi+4] ;y + fstp dword[esi] ;x + fstp dword[esi+4] ;y + + add esi,12 + add edi,12 + loop @b + ret + .zx: + fld dword[edi] ;x + fld dword[edi+8] ;z + fstp dword[edi] ;x + fstp dword[edi+8] ;z + fld dword[esi] ;x + fld dword[esi+8] ;y + fstp dword[esi] ;x + fstp dword[esi+8] ;y + + add esi,12 + add edi,12 + loop .zx + ret + .yz: + fld dword[edi+8] ;z + fld dword[edi+4] ;y + fstp dword[edi+8] ;z + fstp dword[edi+4] ;y + fld dword[esi+8] ;x + fld dword[esi+4] ;y + fstp dword[esi+8] ;x + fstp dword[esi+4] ;y + + add edi,12 + add esi,12 + loop .yz +ret + +;#\\\\\\\\\\\\\\\\\\\\\\\\\comented/////////////////////////////// +if 0 +calc_attenuation_light: ;; calculate point to spot_light distance +; spot light with attenuation ;; and vector, normalize vector, + ;; calc dot_pr and unlinear color according + ;; to dot_product, write to color buff +.distance equ dword[ebp-4] ;; color buff in bumpmap for save the mem +.temp_col equ word[ebp-6] +.vector equ [ebp-20] +.spot_light_ptr equ dword [ebp-24] + mov ebp,esp + sub esp,24 + mov edi,rotated_points_r ;points_rotated + mov edx,point_normals_rotated + mov ecx,bumpmap ; mem area with temp points color list + xor ax,ax ; counter + mov esi,spot_light_params + mov .spot_light_ptr,esi + .again_color: + push eax + lea ebx,.vector + mov esi,.spot_light_ptr ; calc vector fom light to every point + call make_vector_r + ; ebx - ptr to result vector + fld dword [ebx] + fmul st, st + fld dword [ebx+4] + fmul st, st + fld dword [ebx+8] + fmul st, st + faddp st1, st + faddp st1, st + fsqrt + fstp .distance + push edi + mov edi,ebx + call normalize_vector + ; edi - normalized distance vector + mov esi,edx + call dot_product ; esi first vector, edi second vector + ; st0 - dot product + fabs ; why not ? - think about it + pop edi + fldz + fcomip st1 + jbe @f ; st1>0 + mov dword[ecx],0 + mov word[ecx+4],0 + add ecx,6 + ffree st0 + jmp .update_counters + @@: + ; pop edi + + ; calc color(with atenuation), write to buff + ; buff - color of points list + ; color = ambient+cos(x)*diffuse+(cos(x)^n)*specular + + push edx + push edi + + push ecx + push ebp + +; mov eax,spot_light_params + mov eax,.spot_light_ptr + movzx dx,byte[eax+15] + push dx ; shines + movzx dx,byte[eax+8] ; b + push dx ; orginal col + movzx dx,byte[eax+7] ; g + push dx + movzx dx,byte[eax+6] ; r + push dx + movzx dx,byte[eax+14] ; max col + push dx + movzx dx,byte[eax+13] + push dx + movzx dx,byte[eax+12] + push dx + movzx dx,byte[eax+11] ; min col + push dx + movzx dx,byte[eax+10] + push dx + movzx dx,byte[eax+9] + push dx + push eax ; dot pr. (in st0) + call calc_one_col + ; eax - 0x00rrggbb + ; brightness = 1 - (distance/light.fadezero)^fogness + ; if brightness < 0, then brightness = 0 + ; attenuetion equation taken from 3dica tutorial - 1/d^2 isn't perfect + ; color = color * brightness ; fogness = <0.5,2.0> + pop ebp + pop ecx + + fld .distance + mov esi,.spot_light_ptr +; fidiv word[spot_light_params+16] ; fadezero + fidiv word[esi+16] ; fadezero + ; fmul st,st0 ; fogness = 2 + fabs ; to be sure + fchs + fld1 + faddp + fld1 + fcomip st1 + jnbe @f + ffree st0 + fld1 + @@: + fld st ; st - brightness + ror eax,16 + movzx bx,al ; al - r + mov .temp_col,bx + fimul .temp_col + fistp word[ecx] + cmp word[ecx],0 + jge @f + mov word[ecx],0 + @@: + ; mov edx,dword[spot_light_params+12] ; max colors + mov edx,dword[esi+12] ; max colors + movzx bx,dl ; r max + cmp word[ecx],bx ; choose the brightest for r, g, b + jl @f + mov word[ecx],bx + @@: + + add ecx,2 + fld st + ror eax,16 + movzx bx,ah ; g + mov .temp_col,bx + fimul .temp_col + fistp word[ecx] + cmp word[ecx],0 + jg @f + mov word[ecx],0 + @@: + movzx bx,dh ; g max + cmp word[ecx],bx + jle @f + mov word[ecx],bx + @@: + + add ecx,2 + movzx bx,al ; b + mov .temp_col,bx + fimul .temp_col + fistp word[ecx] + cmp word[ecx],0 + jg @f + mov word[ecx],0 + @@: + shr edx,16 + movzx bx,dl ; b max + cmp word[ecx],bx + jle @f + mov word[ecx],bx + @@: + add ecx,2 +;end if +; ror eax,16 +; movzx bx,al +; mov word[ecx],bx +; ror eax,16 +; movzx bx,ah +; mov word[ecx+2],bx +; xor ah,ah +; mov word[ecx+4],ax +; add ecx,6 + + pop edi + pop edx + + .update_counters: + add edx,12 ; normal_size + add edi,12 ;6 ; 3d point_coord_size + + pop eax + inc ax + cmp ax,[points_count_var] + jne .again_color + + add .spot_light_ptr,18 + cmp .spot_light_ptr,spot_l_end + jl .again_color + + mov esp,ebp +ret +end if ;#\\\\\\\\\\\\\\\\\\\\\\\\\comented//////////////////////////////////// \ No newline at end of file diff --git a/programs/demos/view3ds/data.inc b/programs/demos/view3ds/data.inc index 2a93693e76..117ebe3449 100644 --- a/programs/demos/view3ds/data.inc +++ b/programs/demos/view3ds/data.inc @@ -1,554 +1,561 @@ - ; DATA AREA ************************************ - - i3 dw 3 - i12 dd 12 - i256 dw 256 - i255d dd 255 - dot_max dd 1.0 ; dot product max and min - dot_min dd 0.0 - env_const dd 1.05 - tex_x_div2 dw TEX_X / 2 - tex_y_div2 dw TEX_Y / 2 - xobs dw 0 ;SIZE_X / 2 ;200 ;observer = camera - yobs dw 0 ;SIZE_Y / 2 ;200 ;coordinates - zobs dw -1000 - - re_alloc_flag db 0 - angle_counter dw 0 - piD180 dd 0.017453292519943295769236907684886 - piD128 dd 0.024544 - const6 dw 6,6,6,6 - x_offset dw SIZE_X / 2 - y_offset dw SIZE_Y / 2 - z_offset dw 0 - rsscale dd 175.0 ; next real scale - vect_x dw SIZE_X / 2 - vect_y dw SIZE_Y / 2 - vect_z dw 0 - size_y_var: - yres_var dw SIZE_Y - - size_x_var: - xres_var dw SIZE_X - - angle_x dw 0 - angle_y dw 0 - angle_z dw 0 - sin_amplitude dd 50 - sin_frq dd 0.7 - sin_delta dd 0.07 ; wave frequency granularity - convert_muler: - dd 1, 10, 100, 1000, 10000 - XYZpartices: - db 'X','Y','Z' - i10 dw 10 - offset_y: - i25 dw 25 ; screen buff offset - offset_x: - i5 dw 5 - triangles_ptr dd 0 - triangles_w_z_ptr dd 0 - triangles_normals_ptr dd 0 - points_normals_ptr dd 0 - points_normals_rot_ptr dd 0 - points_ptr dd 0 - points_rotated_ptr dd 0 - points_translated_ptr dd 0 - screen_ptr dd 0 - Zbuffer_ptr dd 0 - vertices_index_ptr dd 0 - vertex_edit_no dw 0 - edit_start_x: - dw 0 - edit_start_y dw 0 - edit_end_x: - dw 0 - edit_end_y dw 0 - mouse_state dd 0 - - - menu: - db 2 ; button number = index - db 'rotary ' ; label - db 3 ; max flag + 1 , if = 255, no flag - r_flag db 1 ; flag - dd axl_f ; offset to flags description - - db 3 - db 'shd. model' - if Ext >= SSE3 - max_dr_flg db 15 - else - db 12 - end if - dr_flag db 0 ; 6 - dots - dd shd_f - - db 4 - db 'speed ' - db 2 - speed_flag db 0 - dd spd_f - - db 5 - db 'zoom out ' - db 255 - db ? - dd ? - - db 6 - db 'zoom in ' - db 255 - db ? - dd ? - - db 7 - db 'catmull ' - db 2 -catmull_flag db 1 - dd onoff_f - - db 8 - db 'culling ' - db 2 -culling_flag db 0 - dd onoff_f - - db 9 - db 'rand.light' - db 255 - db ? - dd ? - - db 10 - db 'blur ' - db 6 -blur_flag db 0 - dd blur_f - - db 11 - db 'mirror x ' - db 2 -mirr_x_flag db 0 - dd onoff_f - - db 12 - db 'mirror y ' - db 2 -mirr_y_flag db 0 - dd onoff_f - - db 13 - db 'mirror z ' - db 2 -mirr_z_flag db 0 - dd onoff_f - - db 14 - db 'xchg ' - db 4 -xchg_flag db 0 - dd xchg_f - - db 15 - db 'emboss ' - db 2 -emboss_flag db 0 - dd onoff_f - - db 16 - db 'fire ' - db 3 -fire_flag db 0 - dd blur_f - - db 17 - db 'move ' - db 3 -move_flag db 0 - dd move_f - - db 18 - db 'generate ' - db 6 -generator_flag db 0 - dd blur_f - - db 19 - db 'bumps ' - db 2 -bumps_flag db 0 - dd bumps_f - - db 20 - db 'bumps deep' - db 4 -bumps_deep_flag db 3 - dd bumps_d_f - - db 21 - db 're-map tex' - db 255 -map_tex_flag db ? ;1 - dd ? ;bumps_d_f - - db 22 - db 'bright + ' - db 6 -inc_bright_flag db 0 ;1 - dd blur_f - - db 23 - db 'bright - ' - db 6 -dec_bright_flag db 0 ;1 - dd blur_f - - db 24 - db 'wav effect' - db 2 -sinus_flag db 0 - dd onoff_f - - - db 25 - db 'editor ' - db 2 - edit_flag db 0 - dd onoff_f -; db 24 -; db 'max ' -; db 2 -;max_flag db 0 ;1 -; dd blur_f -; -; db 25 -; db 'min ' -; db 2 -;min_flag db 0 ;1 -; dd blur_f - - - -; db 21 -; db 'light No. ' -; db 3 -;light_no_flag db 0 -; dd bumps_d_f - -; db 22 -; db 'light comp' -; db 3 -;light_comp_flag db 0 -; dd light_component_f - -;; db 23 -;; db 'col. comp' -;; db 3 -;;color_comp_flag db 0 -;; dd color_component_f - - - - - - db -1 ; end mark - - -flags: ; flags description - shd_f: - db 'flat' - db 'grd ' - db 'env ' - db 'bump' - db 'tex ' - db 'pos ' - db 'dots' - db 'txgr' - db '2tex' - db 'btex' - db 'cenv' - db 'grdl' - db 'rphg' - db 'glas' - db 'ptex' - spd_f: - db 'idle' - db 'full' - axl_f: - db ' y ' - db 'x+y ' - db ' x ' - onoff_f: - db 'off ' - db 'on ' - - blur_f: ; blur, fire - db 'off ' -bumps_d_f: db ' 1 ' - db ' 2 ' - db ' 3 ' - db ' 4 ' - db ' 5 ' - - xchg_f: - db 'no ' - db 'x<>y' - db 'z<>x' - db 'y<>z' - move_f: - db 'obj ' - db 'camr' - db 'wave' -; db 'lght' - bumps_f: - db 'rand' - db 'tex ' -; db 'cscl' -base_vector: - labelvector: - db 'add vector' - labelvectorend: - labelyminus: - db 'y -' - labelyminusend: - labelzplus: - db 'z +' - labelzplusend: - labelxminus: - db 'x -' - labelxminusend: - labelxplus: - db 'x +' - labelxplusend: - labelzminus: - db 'z -' - labelzminusend: - labelyplus: - db 'y +' - labelyplusend: - - - labelt: - db 'DEUS CARITAS EST' - if Ext=MMX - db ' (MMX)' - end if - if Ext=SSE - db ' (SSE)' - end if - if Ext=SSE2 - db ' (SSE2)' - end if - if Ext=SSE3 - db ' (SSE3)' - end if - db ' 0.072',0 - labellen: - STRdata db '-1 ' - - all_lights_size dw lightsend-lights - - -; file_info: -; dd 0 -; dd 0 -; dd 0 -; fsize dd 0 ;180000 ; sizeof(workarea) -; fptr dd 0 ;workarea -; file_name: -; db '/rd/1/3d/house.3ds',0 -; ; db '/tmp0/1/ant.3ds',0 -; -; rb 256 - -;============================================= -lights: - .light_vector dd 0.0,0.0,-1.0 ; x,y,z Z cooficient of vector must be negative - .orginal_color_r db 1 ; +12 - .orginal_color_g db 255 ; - .orginal_color_b db 1 ; +14 - .min_color_r db 1 ; - .min_color_g db 1 ; +16 - .min_color_b db 1 ; - .max_color_r db 255 ; - .max_color_g db 255 ; - .max_color_b db 255 ; - .shine db 24 ; +21 - ; LIGHT_SIZE equ ($-lights) - - dd -0.5,-0.5,-1.0 ; x,y,z ; .light_vector - db 5 ; .orginal_color_r - db 1 ; .orginal_color_g - db 135 ; .orginal_color_b - db 19 ; .min_color_r - db 19 ; .min_color_g - db 19 ; .min_color_b - db 255 ; .max_color_r - db 255 ; .max_color_g - db 255 ; .max_color_b - db 16 ; .shine - - dd 0.5,0.5,-1.0 ; x,y,z ; .light_vector - db 135 ; .orginal_color_r - db 1 ; .orginal_color_g - db 1 ; .orginal_color_b - db 19 ; .min_color_r - db 19 ; .min_color_g - db 19 ; .min_color_b - db 255 ; .max_color_r - db 255 ; .max_color_g - db 20 ; .max_color_b - db 16 ; .shine -; ALL_LIGHTS_SIZE equ ($ - lights) -;#all_lights_size dw ($ - lights) ;ALL_LIGHTS_SIZE -;=============================================== - -lightsend: - - - - -align 16 - emboss_bias: - dw 128, 128, 128, 128, 128, 128, 128, 128 - zero_hgst_dd: - dd -1, -1, -1, 0 - mask_255f: - correct_texf: - times 4 dd 255.0 - the_zero: - times 4 dd 0.0 - tex_m2: - times 4 dd 510.0 - the_one: - times 4 dd 1.0 - aprox dd 0.0001 - - - file_info: - dd 0 - dd 0 - dd 0 - fsize dd 0 ;180000 ; sizeof(workarea) - fptr dd 0 ;workarea - file_name: - db '/rd/1/3d/house.3ds',0 - ; db '/tmp0/1/ant.3ds',0 - - rb 256 - - -I_END: -SourceFile: -workarea rb 180 -EndFile dd ? -align 8 - sinbeta dd ?;+32 - cosbeta dd ? - - xsub dw ? - zsub dw ?;+40 - ysub dw ? - - xx1 dw ? - yy1 dw ? - zz1 dw ?;+48 xx1 + 4 - xx2 dw ? - yy2 dw ? - zz2 dw ? ; xx1 + 10 - xx3 dw ?;+56 - yy3 dw ? - zz3 dw ? ; xx1 + 16 - col1 dd ? - col2 dd ? - col3 dd ? - scale dd ? ; help scale variable - - ;== - triangles_count_var dd ? - points_count_var dd ? - -; size_y_var: -; yres_var dw ? - -; size_x_var: -; xres_var dw ? - x_start: - dw ? - y_start: - dw ? - - ;=== - - point_index1 dd ? ;-\ - point_index2 dd ? ; } don't change order - point_index3 dd ? ;-/ - temp_col dw ? - temp1 dd ? ; > dont change - temp2 dd ? ; > order - high dd ? - rand_seed dw ? -align 8 - buffer dq ? - errr dd ? - drr dd ? - xx dd ? - yy dd ? - xst dd ? - yst dd ? -; screen_ptr dd ? -; Zbuffer_ptr dd ? - - matrix rb 36 - cos_tab rd 360 - sin_tab rd 360 - -align 16 - - - points_count = 180000/6*3 - triangles_count = 180000 / 6 ;($-triangles)/6 -align 16 - label trizdd dword - label trizdq qword - triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position -align 16 - vectors rb 24 -align 16 - bumpmap rb TEXTURE_SIZE + 1 -align 16 - bumpmap2 rb TEXTURE_SIZE + 1 -align 16 - envmap rb (TEXTURE_SIZE +1) * 3 -align 16 - envmap_cub rb TEX_X * 3 -align 16 - texmap rb (TEXTURE_SIZE +1) * 3 -align 16 - color_map rb (TEXTURE_SIZE +100) * 3 -align 16 - tex_points rb points_count * 4 ; bump_map and texture coords - ; each point word x, word y -align 16 - lights_aligned: - lights_aligned_end = $ + 16 * 12 - rb 16 * 12 - - -if Ext >= SSE2 - sse_repository rb 1024 -end if - ; SourceFile: ; source file temporally in screen area - ; workarea dd ? - - ; screen rb SIZE_X * SIZE_Y * 3 ; screen buffer -;align 16 - ; Z_buffer rb SIZE_X * SIZE_Y * 4 - procinfo: - rb 1024 ; process info - I_Param rb 256 - memStack: - rb 2000 -align 16 -screen: + ; DATA AREA ************************************ + + i3 dw 3 + i6 dd 6 + i12 dd 12 + i36 dd 36 + i256 dw 256 + i255d dd 255 + dot_max dd 1.0 ; dot product max and min + dot_min dd 0.0 + env_const dd 1.05 + correct_tex dw 255 + tex_x_div2 dw TEX_X / 2 + tex_y_div2 dw TEX_Y / 2 + xobs dw 0 ;SIZE_X / 2 ;200 ;observer = camera + yobs dw 0 ;SIZE_Y / 2 ;200 ;coordinates + zobs dw -1000 + + re_alloc_flag db 0 + angle_counter dw 0 + piD180 dd 0.017453292519943295769236907684886 + piD128 dd 0.024544 + const6 dw 6,6,6,6 + x_offset dw SIZE_X / 2 + y_offset dw SIZE_Y / 2 + z_offset dw 0 + rsscale dd 175.0 ; next real scale + vect_x dw SIZE_X / 2 + vect_y dw SIZE_Y / 2 + vect_z dw 0 + size_y_var: + yres_var dw SIZE_Y + + size_x_var: + xres_var dw SIZE_X + + angle_x dw 0 + angle_y dw 0 + angle_z dw 0 + sin_amplitude dd 50 + sin_frq dd 0.7 + sin_delta dd 0.07 ; wave frequency granularity + convert_muler: + dd 1, 10, 100, 1000, 10000 + XYZpartices: + db 'X','Y','Z' + i10 dw 10 + offset_y: + i25 dw 25 ; screen buff offset + offset_x: + i5 dw 5 + triangles_ptr dd 0 + triangles_w_z_ptr dd 0 + triangles_normals_ptr dd 0 + points_normals_ptr dd 0 + points_normals_rot_ptr dd 0 + points_ptr dd 0 + points_rotated_ptr dd 0 + points_translated_ptr dd 0 + edges_ptr dd 0 + screen_ptr dd 0 + Zbuffer_ptr dd 0 + vertices_index_ptr dd 0 + vertex_edit_no dw 0 + edit_start_x: + dw 0 + edit_start_y dw 0 + edit_end_x: + dw 0 + edit_end_y dw 0 + x_start: dw 20 + y_start: dw 20 + + mouse_state dd 0 + + + menu: + db 2 ; button number = index + db 'rotary ' ; label + db 3 ; max flag + 1 , if = 255, no flag + r_flag db 1 ; flag + dd axl_f ; offset to flags description + + db 3 + db 'shd. model' + if Ext >= SSE3 + max_dr_flg db 15 + else + db 12 + end if + dr_flag db 0 ; 6 - dots + dd shd_f + + db 4 + db 'speed ' + db 2 + speed_flag db 0 + dd spd_f + + db 5 + db 'zoom out ' + db 255 + db ? + dd ? + + db 6 + db 'zoom in ' + db 255 + db ? + dd ? + + db 7 + db 'catmull ' + db 2 +catmull_flag db 1 + dd onoff_f + + db 8 + db 'culling ' + db 2 +culling_flag db 0 + dd onoff_f + + db 9 + db 'rand.light' + db 255 + db ? + dd ? + + db 10 + db 'blur ' + db 6 +blur_flag db 0 + dd blur_f + + db 11 + db 'mirror x ' + db 2 +mirr_x_flag db 0 + dd onoff_f + + db 12 + db 'mirror y ' + db 2 +mirr_y_flag db 0 + dd onoff_f + + db 13 + db 'mirror z ' + db 2 +mirr_z_flag db 0 + dd onoff_f + + db 14 + db 'xchg ' + db 4 +xchg_flag db 0 + dd xchg_f + + db 15 + db 'emboss ' + db 2 +emboss_flag db 0 + dd onoff_f + + db 16 + db 'fire ' + db 3 +fire_flag db 0 + dd blur_f + + db 17 + db 'move ' + db 3 +move_flag db 0 + dd move_f + + db 18 + db 'generate ' + db 6 +generator_flag db 0 + dd blur_f + + db 19 + db 'bumps ' + db 2 +bumps_flag db 0 + dd bumps_f + + db 20 + db 'bumps deep' + db 4 +bumps_deep_flag db 3 + dd bumps_d_f + + db 21 + db 're-map tex' + db 255 +map_tex_flag db ? ;1 + dd ? ;bumps_d_f + + db 22 + db 'bright + ' + db 6 +inc_bright_flag db 0 ;1 + dd blur_f + + db 23 + db 'bright - ' + db 6 +dec_bright_flag db 0 ;1 + dd blur_f + + db 24 + db 'wav effect' + db 2 +sinus_flag db 0 + dd onoff_f + + + db 25 + db 'editor ' + db 2 + edit_flag db 0 + dd onoff_f +; db 24 +; db 'max ' +; db 2 +;max_flag db 0 ;1 +; dd blur_f +; +; db 25 +; db 'min ' +; db 2 +;min_flag db 0 ;1 +; dd blur_f + + + +; db 21 +; db 'light No. ' +; db 3 +;light_no_flag db 0 +; dd bumps_d_f + +; db 22 +; db 'light comp' +; db 3 +;light_comp_flag db 0 +; dd light_component_f + +;; db 23 +;; db 'col. comp' +;; db 3 +;;color_comp_flag db 0 +;; dd color_component_f + + + + + + db -1 ; end mark + + +flags: ; flags description + shd_f: + db 'flat' + db 'grd ' + db 'env ' + db 'bump' + db 'tex ' + db 'pos ' + db 'dots' + db 'txgr' + db '2tex' + db 'btex' + db 'cenv' + db 'grdl' + db 'rphg' + db 'glas' + db 'ptex' + spd_f: + db 'idle' + db 'full' + axl_f: + db ' y ' + db 'x+y ' + db ' x ' + onoff_f: + db 'off ' + db 'on ' + + blur_f: ; blur, fire + db 'off ' +bumps_d_f: db ' 1 ' + db ' 2 ' + db ' 3 ' + db ' 4 ' + db ' 5 ' + + xchg_f: + db 'no ' + db 'x<>y' + db 'z<>x' + db 'y<>z' + move_f: + db 'obj ' + db 'camr' + db 'wave' +; db 'lght' + bumps_f: + db 'rand' + db 'tex ' +; db 'cscl' +base_vector: + labelvector: + db 'add vector' + labelvectorend: + labelyminus: + db 'y -' + labelyminusend: + labelzplus: + db 'z +' + labelzplusend: + labelxminus: + db 'x -' + labelxminusend: + labelxplus: + db 'x +' + labelxplusend: + labelzminus: + db 'z -' + labelzminusend: + labelyplus: + db 'y +' + labelyplusend: + + + labelt: + db 'DEUS CARITAS EST' + if Ext=MMX + db ' (MMX)' + end if + if Ext=SSE + db ' (SSE)' + end if + if Ext=SSE2 + db ' (SSE2)' + end if + if Ext=SSE3 + db ' (SSE3)' + end if + db ' 0.073',0 + labellen: + STRdata db '-1 ' + lab_vert: + db 'Vertices count: ' + lab_vert_end: + lab_tr: + db 'Faces count: ' + lab_tr_end: + lab_ed: + db 'Edges count: ' + lab_ed_end: + + + all_lights_size dw lightsend-lights + + +; file_info: +; dd 0 +; dd 0 +; dd 0 +; fsize dd 0 ;180000 ; sizeof(workarea) +; fptr dd 0 ;workarea +; file_name: +; db '/rd/1/3d/house.3ds',0 +; ; db '/tmp0/1/ant.3ds',0 +; +; rb 256 + +;============================================= +lights: + .light_vector dd 0.0,0.0,-1.0 ; x,y,z Z cooficient of vector must be negative + .orginal_color_r db 1 ; +12 + .orginal_color_g db 255 ; + .orginal_color_b db 1 ; +14 + .min_color_r db 1 ; + .min_color_g db 1 ; +16 + .min_color_b db 1 ; + .max_color_r db 255 ; + .max_color_g db 255 ; + .max_color_b db 255 ; + .shine db 24 ; +21 + ; LIGHT_SIZE equ ($-lights) + + dd -0.5,-0.5,-1.0 ; x,y,z ; .light_vector + db 5 ; .orginal_color_r + db 1 ; .orginal_color_g + db 135 ; .orginal_color_b + db 19 ; .min_color_r + db 19 ; .min_color_g + db 19 ; .min_color_b + db 255 ; .max_color_r + db 255 ; .max_color_g + db 255 ; .max_color_b + db 16 ; .shine + + dd 0.5,0.5,-1.0 ; x,y,z ; .light_vector + db 135 ; .orginal_color_r + db 1 ; .orginal_color_g + db 1 ; .orginal_color_b + db 19 ; .min_color_r + db 19 ; .min_color_g + db 19 ; .min_color_b + db 255 ; .max_color_r + db 255 ; .max_color_g + db 20 ; .max_color_b + db 16 ; .shine +; ALL_LIGHTS_SIZE equ ($ - lights) +;#all_lights_size dw ($ - lights) ;ALL_LIGHTS_SIZE +;=============================================== + +lightsend: + + + + +align 16 + abs_mask: + dd 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff + emboss_bias: + dw 128, 128, 128, 128, 128, 128, 128, 128 + zero_hgst_dd: + dd -1, -1, -1, 0 + mask_255f: + correct_texf: + times 4 dd 255.0 + the_zero: + times 4 dd 0.0 + tex_m2: + times 4 dd 510.0 + the_one: + times 4 dd 1.0 + aprox dd 0.0001 + + + file_info: + dd 0 + dd 0 + dd 0 + fsize dd 0 ;180000 ; sizeof(workarea) + fptr dd 0 ;workarea + file_name: + db '/rd/1/3d/house.3ds',0 + ; db '/tmp0/1/ant.3ds',0 + + rb 256 + + +I_END: +SourceFile: +workarea rb 180 +EndFile dd ? +align 8 + sinbeta dd ?;+32 + cosbeta dd ? + + xsub dw ? + zsub dw ?;+40 + ysub dw ? + + xx1 dw ? + yy1 dw ? + zz1 dw ?;+48 xx1 + 4 + xx2 dw ? + yy2 dw ? + zz2 dw ? ; xx1 + 10 + xx3 dw ?;+56 + yy3 dw ? + zz3 dw ? ; xx1 + 16 + col1 dd ? + col2 dd ? + col3 dd ? + scale dd ? ; help scale variable + + points_count_var dd ? ; + triangles_count_var dd ? ; dont change order + edges_count dd ? ; + + point_index1 dd ? ;-\ + point_index2 dd ? ; } don't change order + point_index3 dd ? ;-/ + temp_col dw ? + temp1 dd ? ; > dont change + temp2 dd ? ; > order + high dd ? + rand_seed dw ? +align 8 + buffer dq ? + errr dd ? + drr dd ? + xx dd ? + yy dd ? + xst dd ? + yst dd ? +; screen_ptr dd ? +; Zbuffer_ptr dd ? + + matrix rb 36 + cos_tab rd 360 + sin_tab rd 360 + +align 16 + + + points_count = 180000/6*3 + triangles_count = 180000 / 6 ;($-triangles)/6 +align 16 + label trizdd dword + label trizdq qword + triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position +align 16 + vectors rb 24 +align 16 + bumpmap rb TEXTURE_SIZE + 1 +align 16 + bumpmap2 rb TEXTURE_SIZE + 1 +align 16 + envmap rb (TEXTURE_SIZE +1) * 3 +align 16 + envmap_cub rb TEX_X * 3 +align 16 + texmap rb (TEXTURE_SIZE +1) * 3 +align 16 + color_map rb (TEXTURE_SIZE +100) * 3 +align 16 + tex_points rb points_count * 4 ; bump_map and texture coords + ; each point word x, word y +align 16 + lights_aligned: + lights_aligned_end = $ + 16 * 12 + rb 16 * 12 + + +if Ext >= SSE2 + sse_repository rb 1024 +end if + ; SourceFile: ; source file temporally in screen area + ; workarea dd ? + + ; screen rb SIZE_X * SIZE_Y * 3 ; screen buffer +;align 16 + ; Z_buffer rb SIZE_X * SIZE_Y * 4 + procinfo: + rb 1024 ; process info + I_Param rb 256 + memStack: + rb 2000 +align 16 +screen: diff --git a/programs/demos/view3ds/grd_line.inc b/programs/demos/view3ds/grd_line.inc index d7b26055ed..b48afb1aba 100644 --- a/programs/demos/view3ds/grd_line.inc +++ b/programs/demos/view3ds/grd_line.inc @@ -1,643 +1,115 @@ -;-procedure draws smooth shaded lines (I mean interpolation 24 bit-- -;-color), with z coord interpolation-------------------------------- -;-author: Maciej Guba (www.macgub.hekko.pl)------------------------- -;-in : ------------------------------------------------------------- -;----- edi - pointer to screen buffer ------------------------------ -;----- esi - pointer to Z buffer ----------------------------------- -;------ constans : SIZE_X, SIZE_Y - screen width and height--------- -;----------------- ROUND - fixed point shift------------------------ -;------ other parameters via stack---------------------------------- -smooth_line: -.x1 equ ebp+4 -.y1 equ ebp+6 -.z1 equ ebp+8 -.r1 equ ebp+10 -.g1 equ ebp+12 -.b1 equ ebp+14 -.x2 equ ebp+16 -.y2 equ ebp+18 -.z2 equ ebp+20 -.r2 equ ebp+22 -.g2 equ ebp+24 -.b2 equ ebp+26 - - -.line_lenght equ ebp-2 -.delta equ ebp-6 -.delta_x equ ebp-10 -.delta_y equ ebp-14 -.dr equ ebp-18 -.dg equ ebp-22 -.db equ ebp-26 -.dz equ ebp-30 -.cr equ ebp-34 -.cg equ ebp-38 -.cb equ ebp-42 -.cz equ ebp-46 - -;.line_lenght equ ebp-48 -.screen equ ebp-52 -.zbuffer equ ebp-56 -.ccoord equ ebp-60 ;current coordinate -.czbuf equ ebp-64 -.cscr equ ebp-68 -.xres equ ebp-72 -.yres equ ebp-76 -.xresm1 equ ebp-80 -.yresm1 equ ebp-84 -.xresp1 equ ebp-88 -.yresp1 equ ebp-92 -.xres3 equ ebp-96 -.xres4 equ ebp-100 - -macro .update_cur_var -{ -if Ext=NON - mov ebx,[.dz] - add [.cz],ebx - mov ebx,[.dr] - add [.cr],ebx - mov ebx,[.dg] - add [.cg],ebx - mov ebx,[.db] - add [.cb],ebx -elseif Ext=MMX - movq mm0,[.cz] - movq mm1,[.cg] - paddd mm0,mm2 ;[.dz] - paddd mm1,mm3 ;[.dg] - movq [.cz],mm0 - movq [.cg],mm1 -elseif Ext >= SSE2 -; movups xmm1,[.cz] - paddd xmm1,xmm0 -; movups [.cz],xmm1 -end if -} -macro .draw_pixel -{ - mov [esi],ebx ; actualize Z buffer -if Ext>=SSE2 - movaps xmm7,xmm1 ;[.cb] ;;xmm1 - shufps xmm7,xmm7,00111001b - psrld xmm7,ROUND - packssdw xmm7,xmm7 - packuswb xmm7,xmm7 - pand xmm7,xmm6 ;[.mask] - movd [edi],xmm7 -else - - mov eax,[.cb] - sar eax,ROUND - mov [edi],al -; and eax,0x000000ff ; clean unused bits - mov ebx,[.cg] - sar ebx,ROUND - mov [edi+1],bl -; mov ah,bl - mov edx,[.cr] - sar edx,ROUND - mov [edi+2],dl -end if -; shl ebx,16 -; or eax,ebx -; mov [edi],eax -} -macro .sort -{ - -if Ext >= MMX - movq mm0,[.x1] - movq mm1,[.x2] - movq [.x1],mm1 - movq [.x2],mm0 -else - mov edx,[.x1] - xchg edx,[.x2] - mov [.x1],edx - mov edx,[.z1] - xchg edx,[.z2] - mov [.z1],edx -end if - mov edx,[.g1] - xchg edx,[.g2] - mov [.g1],edx -} - - - - emms - mov ebp,esp - sub esp,128 - mov eax,[.x1] ; check if parameters exceedes screen area - mov ebx,[.x2] - or eax,ebx - test eax,80008000h - jne .end_line - movzx edx,word [size_x_var] - mov [.xres],edx - dec edx - movzx ecx,word [size_y_var] - mov [.yres],ecx - dec ecx - cmp word[.x1],dx ;SIZE_X - jg .end_line - cmp word[.x2],dx ;SIZE_X - jg .end_line - cmp word[.y1],cx ;SIZE_Y - jg .end_line - cmp word[.y2],cx ;SIZE_Y - jg .end_line - - mov edx,[.xres] - shl edx,2 - mov [.xres4],edx - shr edx,2 - lea edx,[edx*3] - mov [.xres3],edx - mov edx,[.xres] - mov ecx,[.yres] - dec edx - dec ecx - mov [.xresm1],edx - mov [.yresm1],ecx - add edx,2 - add ecx,2 - mov [.xresp1],edx - mov [.yresp1],ecx - - mov [.screen],edi - mov cx,[.x1] - cmp cx,[.x2] - je .vertical_l - mov cx,[.y1] - cmp cx,[.y2] - je .horizontal_l - mov ax,[.x1] - sub ax,[.x2] - cmp ax,0 - jg @f - neg ax ; calc absolute value - @@: - mov [.delta_x],ax - mov bx,[.y1] - sub bx,[.y2] - cmp bx,0 - jg @f - neg bx - @@: - mov [.delta_y],bx - cmp ax,bx - je .deg45_l - jl .more_vertical_l - jg .more_horizon_l - jmp .end_line - ; -.horizontal_l: - mov ax,[.x1] - mov bx,[.x2] - cmp bx,ax - jge @f - - .sort -@@: - - mov bx,[.x2] - sub bx,[.x1] - movsx ebx,bx - cmp ebx,0 ;line lenght equql 0 - je .end_line - mov [.delta_x],ebx - - call .calc_delta - - mov eax,[.xres] ;SIZE_X - movsx ebx,word[.y1] - mul ebx - add esi,eax - lea eax,[eax*3] - add esi,eax - add edi,eax - movsx eax,word[.x1] - add esi,eax - lea eax,[eax*3] - add edi,eax - add esi,eax - - mov ecx,[.delta_x] - - movsx ebx,word[.r1] - shl ebx,ROUND - mov [.cr],ebx - movsx ebx,word[.g1] - shl ebx,ROUND - mov [.cg],ebx - movsx ebx,word[.b1] - shl ebx,ROUND - mov [.cb],ebx - movsx ebx,word[.z1] - shl ebx,ROUND - mov [.cz],ebx -if Ext >= SSE2 - movups xmm1,[.cz] -end if -.hdraw: -if Ext >= SSE2 - movd ebx,xmm1 -else - mov ebx,[.cz] -end if - cmp [esi],ebx - jle .skip - - .draw_pixel - -.skip: - add edi,3 - add esi,4 - - .update_cur_var - - loop .hdraw - jmp .end_line - -.vertical_l: - mov ax,[.y1] - cmp [.y2],ax - jge @f - - .sort -@@: - mov bx,[.y2] - sub bx,[.y1] - movsx ebx,bx - cmp ebx,0 - je .end_line - mov [.delta_y],ebx - - call .calc_delta - - mov eax,[.xres] ;SIZE_X - movsx ebx,word[.y1] - mul ebx - add esi,eax - lea eax,[eax*3] - add edi,eax - add esi,eax - movsx eax,word[.x1] - add esi,eax - lea eax,[eax*3] - add esi,eax - add edi,eax - - mov ecx,[.delta_y] - - movsx ebx,word[.r1] - shl ebx,ROUND - mov [.cr],ebx - movsx ebx,word[.g1] - shl ebx,ROUND - mov [.cg],ebx - movsx ebx,word[.b1] - shl ebx,ROUND - mov [.cb],ebx - movsx ebx,word[.z1] - shl ebx,ROUND - mov [.cz],ebx -if Ext >= SSE2 - movups xmm1,[.cz] -end if - -.v_draw: -if Ext >= SSE2 - movd ebx,xmm1 -else - mov ebx,[.cz] -end if - cmp [esi],ebx - jle @f - - .draw_pixel - -@@: - add edi,[.xres3] - add esi,[.xres4] - - .update_cur_var - - loop .v_draw - jmp .end_line -.deg45_l: - mov word[.line_lenght],ax - mov ax,[.x1] - cmp [.x2],ax - jge @f - - .sort -@@: - mov bx,[.y2] - sub bx,[.y1] - movsx ebx,bx - cmp ebx,0 - je .end_line - mov [.delta_y],ebx - mov bx,[.x2] - sub bx,[.x1] - movsx ebx,bx - mov [.delta_x],ebx - - call .calc_delta - - mov eax,[.xres] - movsx ebx,word[.y1] ;calc begin values in screen and Z buffers - mul ebx - lea ebx,[3*eax] - add edi,ebx - shl eax,2 - add esi,eax - movsx eax,word[.x1] - lea ebx,[eax*3] - add edi,ebx - shl eax,2 - add esi,eax - - movzx ecx,word[.line_lenght] - - movsx ebx,word[.r1] - shl ebx,ROUND - mov [.cr],ebx - movsx ebx,word[.g1] - shl ebx,ROUND - mov [.cg],ebx - movsx ebx,word[.b1] - shl ebx,ROUND - mov [.cb],ebx - movsx ebx,word[.z1] - shl ebx,ROUND - mov [.cz],ebx -.d45_draw: -if Ext >= SSE2 - movd ebx,xmm1 -else - mov ebx,[.cz] -end if - cmp [esi],ebx - jle @f - - .draw_pixel - -@@: - cmp dword[.delta_y],0 - jl @f - add edi,[.xres3] ;SIZE_X*3+3 - add edi,3 - add esi,[.xres4] ;SIZE_X*4+4 - add esi,4 - jmp .d45_1 -@@: - sub edi,[.xres3] ;(SIZE_X*3)-3 - sub edi,3 - sub esi,[.xres4] ;(SIZE_X*4)-4 - sub esi,4 -.d45_1: - .update_cur_var - - loop .d45_draw - jmp .end_line - -.more_vertical_l: - mov word[.line_lenght],bx - mov ax,[.y1] - cmp [.y2],ax - jge @f - .sort -@@: - mov bx,[.y2] - sub bx,[.y1] - movsx ebx,bx - cmp ebx,0 - je .end_line ;======================= - mov [.delta_y],ebx - - mov ax,[.x2] - sub ax,[.x1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.delta],eax - - call .calc_delta - - mov eax,[.xres] ;SIZE_X - movsx ebx,word[.y1] ;calc begin values in screen and Z buffers - mul ebx - lea ebx,[3*eax] - add esi,ebx - add esi,eax - add edi,ebx - mov [.cscr],edi - mov [.czbuf],esi - - movzx ecx,word[.line_lenght] - - movsx ebx,word[.r1] - shl ebx,ROUND - mov [.cr],ebx - movsx ebx,word[.g1] - shl ebx,ROUND - mov [.cg],ebx - movsx ebx,word[.b1] - shl ebx,ROUND - mov [.cb],ebx - movsx ebx,word[.z1] - shl ebx,ROUND - mov [.cz],ebx -if Ext >= SSE2 - movups xmm1,[.cz] -end if - movsx ebx,word[.x1] - shl ebx,ROUND - mov [.ccoord],ebx ; .ccoord -> x coordinate -.draw_m_v: - mov edi,[.cscr] - mov esi,[.czbuf] - mov eax,[.ccoord] - sar eax,ROUND - lea ebx,[eax*3] - add edi,ebx - add esi,ebx - add esi,eax -if Ext >= SSE2 - movd ebx,xmm1 -else - mov ebx,[.cz] -end if - cmp [esi],ebx - jle @f - - .draw_pixel - -@@: - mov eax,[.delta] - mov ebx,[.xres3] - add [.ccoord],eax - mov eax,[.xres4] - add dword[.cscr],ebx ;SIZE_X*3 ; - add dword[.czbuf],eax ;SIZE_X*4 -.d_m_v1: - - .update_cur_var - - dec ecx - jnz .draw_m_v - jmp .end_line - -.more_horizon_l: - mov word[.line_lenght],ax - mov ax,[.x1] - cmp [.x2],ax - jge @f - - .sort -@@: - mov bx,[.x2] - sub bx,[.x1] - movsx ebx,bx - cmp ebx,0;======================= - je .end_line - mov [.delta_x],ebx - - mov ax,[.y2] - sub ax,[.y1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.delta],eax - - call .calc_delta - - ;calc begin values in screen and Z buffers - movsx ebx,word[.x1] - mov eax,ebx - add esi,ebx - lea ebx,[3*ebx] - add esi,ebx - add edi,ebx - mov [.cscr],edi - mov [.czbuf],esi - - movzx ecx,word[.line_lenght] - - movsx ebx,word[.r1] - shl ebx,ROUND - mov [.cr],ebx - movsx ebx,word[.g1] - shl ebx,ROUND - mov [.cg],ebx - movsx ebx,word[.b1] - shl ebx,ROUND - mov [.cb],ebx - movsx ebx,word[.z1] - shl ebx,ROUND - mov [.cz],ebx -if Ext >= SSE2 - movups xmm1,[.cz] -end if - movsx ebx,word[.y1] - shl ebx,ROUND - mov [.ccoord],ebx ; .ccoord -> y coordinate - -.draw_m_h: - mov edi,[.cscr] - mov esi,[.czbuf] - mov eax,[.ccoord] ; ccoord - cur y coordinate - sar eax,ROUND - mov ebx,[.xres] ;SIZE_X - mul ebx - add esi,eax - lea eax,[eax*3] - add esi,eax - add edi,eax -if Ext >= SSE2 - movd ebx,xmm1 -else - mov ebx,[.cz] -end if - cmp [esi],ebx - jle @f - - .draw_pixel - -@@: - mov eax,[.delta] - add [.ccoord],eax - add dword[.cscr],3 ; - add dword[.czbuf],4 - - .update_cur_var - - dec ecx - jnz .draw_m_h - -.end_line: - mov esp,ebp - ret 24 - -.calc_delta: - mov ax,[.z2] - sub ax,[.z1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.dz],eax - - mov ax,[.r2] - sub ax,[.r1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.dr],eax - - mov ax,[.g2] - sub ax,[.g1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.dg],eax - - mov ax,[.b2] - sub ax,[.b1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.db],eax -if Ext=MMX | Ext = SSE - movq mm2,[.dz] - movq mm3,[.dg] -else if Ext >= SSE2 - movups xmm0,[.dz] - movups xmm6,[.mask] -end if -ret -.mask: - dq 0xffffffff00ffffff - dq 0xffffffffffffffff - - - - - - - - - - - - - +; Line drawing procedure by Pablo Reda. +; Gouraud extension by Maciej Guba. +;**************************************************** +line_grd: ; eax=x1 ebx=y1 ecx=x2 edx=y2 + ; xmm0 - color1 argb as 4 dword float + ; xmm1 - color2 argb as 4 dword float + ; xmm2 - z1 as dword float + ; xmm3 - z2 as dword float + ; mm0 - Z buffer + ; mm1 - screen buffer + ; mm2 - screen width + + + cmp ebx,edx + ; je horizontal_grd + jg .noswap + xchg eax,ecx + xchg ebx,edx + movaps xmm7,xmm0 + movaps xmm0,xmm1 + movaps xmm1,xmm7 + movaps xmm7,xmm2 + movaps xmm2,xmm3 + movaps xmm3,xmm7 +.noswap: + + cvtsi2ss xmm7,eax + cvtsi2ss xmm6,ebx + cvtsi2ss xmm5,ecx + cvtsi2ss xmm4,edx + subss xmm7,xmm5 + subss xmm6,xmm4 + andps xmm7,[abs_mask] ; 0x7fff + andps xmm6,[abs_mask] ; 0x7fff + maxss xmm7,xmm6 ; xmm7 - delta + shufps xmm7,xmm7,0 + movaps xmm6,xmm3 + rcpps xmm7,xmm7 + subss xmm6,xmm2 + mulss xmm6,xmm7 ; xmm6 - delta z + movaps xmm5,xmm1 + subps xmm5,xmm0 + mulps xmm5,xmm7 ; xmm5 - delta col argb + + + shl eax,16 + shl ecx,16 + sub eax,ecx + push ebx + push edx + sub ebx,edx + add ebx,1 + cdq + idiv ebx + mov esi,eax + add ecx,$7fff + pop ebx + pop edx +.lineas: + mov eax,ecx + add eax,esi + push ebx + push eax + push edx + shr ecx,16 + shr eax,16 + call horizontal_grd + pop edx + pop ecx + pop ebx + add ebx,1 + cmp ebx,edx + jle .lineas + ret + +horizontal_grd: ; eax=x1 ebx=y1 ecx=x2 + cmp ecx,eax + jg .m + xchg ecx,eax +.m: + sub ecx,eax + jnz .nn + add ecx,1 +.nn: + movd edx,mm2 + imul ebx,edx + add eax,ebx + movd edi,mm1 + lea edi,[edi+eax*4] + push eax + push ebx + movd ebx,mm0 + lea ebx,[ebx+eax*4] +.l: + ; movss xmm4,xmm2 ; xmm2 - cur z + ; cmpnltss xmm4,[ebx] + ; movd eax,xmm4 + ; or eax,eax + ; jnz @f + comiss xmm2,[ebx] + jng @f + movaps xmm4,xmm0 ; xmm0 - cur col + cvtps2dq xmm4,xmm4 + packssdw xmm4,xmm4 + packuswb xmm4,xmm4 + movd [edi],xmm4 + @@: + addss xmm2,xmm6 + addps xmm0,xmm5 + add edi,4 + sub ecx,1 + jnz .l + pop ebx + pop eax + ret diff --git a/programs/demos/view3ds/history.txt b/programs/demos/view3ds/history.txt index 2c84fd9eaa..a264ebbe7f 100644 --- a/programs/demos/view3ds/history.txt +++ b/programs/demos/view3ds/history.txt @@ -1,4 +1,14 @@ +View3ds 0.072 - march 2021 +1. New displaying model - texturing with bilinear filtering and transparency + simultanusly. Note that filtering is done only inside polygon. To better + quality of image there is a need to use floats coordinates of texture to pass + as arguments to single triangle rendering proc. +2. Optimizations. +3. SSE3 version runs correct on SSE2 cpus, but real phong, glass and + transparented texturing with filtering rendering models are disabled. +----------------------------------------------------------------------------------- + View3ds 0.071 - VIII 2020 1. New displaying model - glass - it's two pass rendering. First pass calculates Z position of all front pixels, second render image with adding reflective diff --git a/programs/demos/view3ds/readme.txt b/programs/demos/view3ds/readme.txt index 4978561dec..b4279a8f63 100644 --- a/programs/demos/view3ds/readme.txt +++ b/programs/demos/view3ds/readme.txt @@ -1,7 +1,12 @@ -View3ds 0.072 - tiny viewer to .3ds and .asc files with several graphics +View3ds 0.073 - tiny viewer to .3ds and .asc files with several graphics effects implementation. What's new? +1. I introduced procedure for searching nonredundand edges. +2. Writing some info about object: vertices, triangles unique edges + count. + + 1. New displaying model - texturing with bilinear filtering and transparency simultanusly. Note that filtering is done only inside polygon. To better quality of image there is a need to use floats coordinates of texture to pass @@ -26,21 +31,23 @@ Buttons description: 8. rand. light: Randomize 3 unlinear lights( so called Phong's illumination). 9. Blur: blur N times; N=0,1,2,3,4,5 10.11,12,13. loseless operations (rotary 90, 180 degrees). -12. emboss: Do emboss effect( flat bumps ), use 'bumps deep' button to do edges more deep. +12. emboss: Do emboss effect( flat bumps ), use 'bumps deep' button to do edges + more deep. 13. fire: do motion blur ( looks like fire ). -14. move: changes meaning x,y,z +/- buttons -> obj: moving object, camr: moving camera, wave: x,y +/- increase, - decrease wave effect frequency and amplitude. +14. move: changes meaning x,y,z +/- buttons -> obj: moving object, camr: moving + camera, wave: x,y +/- increase, decrease wave effect frequency and amplitude. 15. generate: Generates some objects: node, Thorn Crown, heart... 16. bumps: random, according to texture. 17. bumps deep -> create bumps deeper or lighter. -18. re-map tex -> re-map texture and bump map coordinates, to change spherical mapping - around axle use 'xchg' and 'mirror' buttons, then press 're-map tex' button. +18. re-map tex -> re-map texture and bump map coordinates, to change spherical + mapping around axle use 'xchg' and 'mirror' buttons, then press 're-map tex' button. 19. bright + -> increase picture brightness. 20. bright - -> decrease picture brightness. 21. wav effect -> do effect based sine function. -22. editor -> setting editing option. If is "on" then red bars are draw according to each vertex, Pressing - and moving left mouse button (cursor must be on handler)- change vertex position. If left mouse button - is released apply current position. You may also decrease whole handlers count by enable culling (using - appropriate button) - some back handlers become hidden. +22. editor -> setting editing option. If is "on" then red bars are draw according to each + vertex, Pressing and moving left mouse button (cursor must be on handler)- change + vertex position. If left mouse button is released apply current position. You may also + decrease whole handlers count by enable culling (using appropriate button) - some + back handlers become hidden. - Maciej Guba III 2021 + Maciej Guba V 2021 diff --git a/programs/demos/view3ds/view3ds.asm b/programs/demos/view3ds/view3ds.asm index c426b5e5b2..98ae5bc568 100644 --- a/programs/demos/view3ds/view3ds.asm +++ b/programs/demos/view3ds/view3ds.asm @@ -1,3671 +1,3654 @@ - -; application : View3ds ver. 0.072 - tiny .3ds and .asc files viewer -; with a few graphics effects demonstration. -; compiler : FASM -; system : KolibriOS -; author : Macgub aka Maciej Guba -; email : macgub3@wp.pl -; web : http://macgub.j.pl, http://macgub.co.pl -; Fell free to use this intro in your own distribution of KolibriOS. -; Special greetings to KolibriOS team . -; I hope because my demos Christian Belive will be near to each of You. - - -; Some adjustments made by Madis Kalme -; madis.kalme@mail.ee -; I tried optimizing it a bit, but don't know if it was successful. The objects -; can be: -; 1) Read from a file (*.3DS standard) -; 2) Written in manually (at the end of the code) ; now not exist - - -SIZE_X equ 500 -SIZE_Y equ 600 ; ///// I want definitely -TIMEOUT equ 10 ; ------ say: -ROUND equ 10 ; \ @ @/ keep smiling every -TEX_X equ 512 ; texture width ; \ ./ / day. -TEX_Y equ 512 ; height ; \/ / -TEX_SHIFT equ 9 ; texture width shifting ; __||__ / -TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 ; /| | -TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} ; / \ / -FLUENTLY = 0 ; / | | -SHIFTING = 1 ; ------ -CATMULL_SHIFT equ 8 ; | | -LIGHT_SIZE equ 22 ; | | -NON = 0 ; -/ \- -MMX = 1 -SSE = 2 -SSE2 = 3 -SSE3 = 4 -Ext = SSE3 ;Ext={ NON | MMX | SSE | SSE2 | SSE3 } - -; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features) -USE_LFN = 1 ; App is Kolibri only now. - -use32 - org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd I_END ; size of image - dd MEM_END ; memory for app - dd MEM_END ; esp - dd I_Param ; I_Param - dd 0x0 ; I_Icon - -START: ; start of execution - cld - push dword (SIZE_Y shr 3) * 3 - fninit - fild dword[esp] - fstp [rsscale] - pop ebx - - mov [x_start],dword 20 shl 16 + 20 ;eax - - - call alloc_buffer_mem - call read_param - call read_from_disk ; read, if all is ok eax = 0 - cmp eax,0 - jne .gen - mov esi,[fptr] - cmp [esi],word 4D4Dh - jne .asc - call read_tp_variables ; init points and triangles count variables - cmp eax,0 - je .gen - jmp .malloc - .gen: - call generate_object - jmp .opt - .asc: - mov [triangles_count_var],10000 ; to do: read asc header - mov [points_count_var],10000 - call alloc_mem_for_tp - call read_asc - jmp .opt - .malloc: - if USE_LFN - call alloc_mem_for_tp - end if - call read_from_file - .opt: - - - - call optimize_object1 ; proc in file b_procs.asm - ; set point(0,0,0) in center and calc all coords - ; to be in <-1.0,1.0> - call normalize_all_light_vectors - if Ext >= SSE3 - call copy_lights ; to aligned float - end if - call init_triangles_normals2 - call init_point_normals - call init_envmap2 - call init_envmap_cub - call generate_texture2 - call init_sincos_tab - call do_color_buffer ; intit color_map - mov edi,bumpmap - call calc_bumpmap - call calc_bumpmap_coords ; bump and texture mapping - call draw_window - ;mov [draw_win_at_first],0 - ;mov eax,40 ; set events mask - ;mov ebx,1100000000000000000000000100111b - ;int 0x40 - if Ext >= SSE3 - mov eax,1 - cpuid - bt ecx,0 ; is sse3 on board? - jc @f - mov [max_dr_flg],12 - @@: - end if - -still: - cmp [edit_flag],1 - jne @f - mov eax,40 ; set events mask - mov ebx,1100000000000000000000000100111b - jmp .int - @@: - mov eax,40 ; set events mask - mov ebx,111b - .int: - int 0x40 - - mov eax,23 - mov ebx,TIMEOUT - cmp [speed_flag],0 - je .skip - mov eax,11 - .skip: - cmp [edit_flag],1 - jne @f - mov eax,10 - - @@: - int 0x40 - - cmp eax,1 ; redraw event ? - je red - cmp eax,2 ; key event ? - je key - cmp eax,3 ; button event ? - je button - cmp eax,6 ; mouse event ? - jne @f - cmp [edit_flag],1 ; handle mouse only when edit is active - jne @f - - mov eax,37 - mov ebx,7 ; get mouse scroll - int 0x40 - and eax, 0xFFFF ; check only vertial - cmp eax, 65535 - je button.zoom_in - cmp eax, 1 - je button.zoom_out - - mov eax,37 - mov ebx,3 ;read mouse state - int 0x40 - mov [mouse_state],eax - call edit - @@: - jmp noclose - - red: ; redraw - mov eax,9 ; get process info - mov ebx,procinfo - mov ecx,-1 - int 0x40 - mov eax,[procinfo+42] ; read params of window - sub eax,115 - mov [size_x_var],ax - shr ax,1 - mov [vect_x],ax -; - mov eax,[procinfo+46] - sub eax,30 - mov [size_y_var],ax - shr ax,1 - mov [vect_y],ax - - mov eax,[procinfo+34] - mov [x_start],ax - mov eax,[procinfo+38] - mov [y_start],ax - call alloc_buffer_mem ;realloc mem for scr & z buffs - call draw_window - - jmp noclose - - key: ; key - mov eax,2 ; just read it and ignore - int 0x40 - - cmp ah, '+' - je button.zoom_in - cmp ah, '=' - je button.zoom_in - cmp ah, '-' - je button.zoom_out - cmp ah, 176 ;left - je add_vec_buttons.x_minus - cmp ah, 179 ;right - je add_vec_buttons.x_plus - cmp ah, 178 ;up - je add_vec_buttons.y_minus - cmp ah, 177 ;down - je add_vec_buttons.y_plus - - jmp noclose - - button: ; button - mov eax,17 ; get id - int 0x40 - - cmp ah,1 ; button id=1 ? - jne @f - - mov eax,-1 ; close this program - int 0x40 - @@: - cmp ah,30 - jge add_vec_buttons - call update_flags ; update flags and write labels of flags - - ; do other operations according to flag - cmp ah,3 ; ah = 3 -> shading model - jne .next_m6 - cmp [dr_flag],2 - jne @f - ; call init_envmap2 ; <----! this don't works in env mode - ; and more than ~18 kb objects - ; call init_envmap_cub2 - @@: - cmp [dr_flag],4 - jne @f - call generate_texture2 - - @@: - .next_m6: - ; ah = 5 -> scale- - cmp ah,5 - jne @f - .zoom_out: - mov dword[scale],0.7 - movss xmm0,[rsscale] - mulss xmm0,[scale] - movss [rsscale],xmm0 - ; fninit - ; fld [rsscale] - ; fmul [scale] - ; fstp [rsscale] - - - @@: - cmp ah,6 ; ah = 6 -> scale+ - jne @f - .zoom_in: - mov dword[scale],1.3 - movss xmm0,[rsscale] - mulss xmm0,[scale] - movss [rsscale],xmm0 - - ; fninit - ; fld [rsscale] - ; fmul [scale] - ; fstp [rsscale] - - @@: - cmp ah,9 ; lights random ; 'flat' 0 - jne .next_m5 ; 'grd ' 1 - call make_random_lights ; 'env ' 2 - call normalize_all_light_vectors ; 'bump' 3 - if Ext >= SSE3 - call copy_lights - end if - call do_color_buffer ; intit color_map ; 'tex ' 4 - ; cmp [emboss_flag],1 ; 'pos ' 5 - ; je @f ; 'dots' 6 - ; cmp [dr_flag],8 - ; jge @f - ; cmp [dr_flag],2 ; 'txgr' 7 - ; jl .next_m5 ; '2tex' 8 - ; cmp [dr_flag],3 ; 'btex' 9 - ; jg .next_m5 - ; @@: - call init_envmap2 ; update env map if shading model = environment or bump - .next_m5: - cmp ah,11 - je @f - cmp ah,12 - je @f - cmp ah,13 - jne .next_m4 - @@: - call mirror - .next_m4: - cmp ah,14 - jne @f - call exchange - @@: - cmp ah,15 - jne @f - cmp [emboss_flag],1 - ; call init_envmap2 - call do_emboss - @@: -; cmp ah,17 -; jne .next_m -; cmp [move_flag],2 -; jne @f -; call draw_window ; redraw other labels to navigation buttons -; @@: -; cmp [move_flag],0 -; jne .next_m -; call draw_window ; redraw other labels to navigation buttons - .next_m: - cmp ah,18 - jne .next_m2 - - mov [re_alloc_flag],1 ; reallocate memory - mov [triangles_count_var],20000 - mov [points_count_var],20000 - call alloc_mem_for_tp - mov [re_alloc_flag],0 - - mov bl,[generator_flag] - ; or bl,bl - ; jz .next_m2 - cmp bl,1 - jne @f - call generate_object - jmp .calc_norm - @@: - cmp bl,4 - jg @f - movzx eax,bl ; eax < - object number - call generate_object2 - jmp .calc_norm - @@: - call generate_object3 - .calc_norm: - call optimize_object1 - call init_triangles_normals2 - call init_point_normals - call calc_bumpmap_coords ; bump and texture mapping - - .next_m2: - cmp ah,19 - je @f - cmp ah,20 - jne .next_m3 - @@: - mov edi,bumpmap - call calc_bumpmap - .next_m3: - cmp ah,21 ; re map bumps, texture coordinates - jne @f - call calc_bumpmap_coords - @@: - jmp noclose - - - ; there are 6 navigation buttons each - add_vec_buttons: ; can move: object, camera,.. list is open - ; - cmp ah,30 - jne .next - cmp [move_flag],0 - jne @f -; cmp [move_flag],2 -; je .set_light1 - .y_minus: - sub [vect_y],10 - jmp .next - @@: - cmp [move_flag],1 - jne @f - sub [yobs],10 ; observator = camera position - jmp .next - @@: - sub [sin_amplitude],10 -;-------------------------------------------------- -; .set_light1: ; r - -; movzx ebx,[light_no_flag] ; * 22 -; mov ecx,ebx -; shl ebx,4 -; shl ecx,1 -; add ebx,ecx -; shl ecx,1 -; add ebx,ecx -; add ebx,lights+6 ; 6 -> light vector size -; -; movzx ecx,[light_comp_flag] -; lea ecx,[ecx*3} -; add ebx,ecx ; ebx -> color to set - -;--------------------------------------------------- - .next: - cmp ah,31 - jne .next1 - cmp [move_flag],1 - je @f - add [vect_z],10 - jmp .next1 - @@: - add [zobs],10 ; observator = camera position - .next1: - cmp ah,33 - jne .next2 - cmp [move_flag],0 - jne @f - .x_minus: - sub [vect_x],10 - jmp .next2 - @@: - cmp [move_flag],1 - jne @f - sub [xobs],10 ; observator = camera position - jmp .next2 - @@: - fninit - fld [sin_frq] - fsub [sin_delta] - fstp [sin_frq] - .next2: - cmp ah,32 - jne .next3 - cmp [move_flag],0 - jne @f - .x_plus: - add [vect_x],10 - jmp .next3 - @@: - cmp [move_flag],1 - jne @f - add [xobs],10 ; observator = camera position - jmp .next3 - @@: - fninit - fld [sin_frq] ; change wave effect frequency - fadd [sin_delta] - fstp [sin_frq] - .next3: - cmp ah,34 - jne .next4 - cmp [move_flag],1 - je @f - - sub [vect_z],10 - jmp .next4 - @@: - sub [zobs],10 ; observator = camera position - .next4: - cmp ah,35 - jne .next5 - cmp [move_flag],0 - jne @f - ; call add_vector - .y_plus: - add [vect_y],10 - jmp .next5 - @@: - cmp [move_flag],1 - jne @f - add [yobs],10 ; observator = camera position - jmp .next5 - @@: - add [sin_amplitude],10 - .next5: - - - - noclose: - - cmp [edit_flag],1 - jz .end_rot - cmp [r_flag],2 - jne .no_x - inc [angle_x] - and [angle_x],0xff - mov [angle_z],0 - jmp .end_rot - - .no_x: - cmp [r_flag],0 - jne .no_y - inc [angle_y] - and [angle_y],0xff - mov [angle_z],0 - jmp .end_rot - - .no_y: - cmp [r_flag],1 - jne .end_rot - mov cx,[angle_x] - inc cx - and cx,0xff - mov [angle_z],0 - mov [angle_y],cx - mov [angle_x],cx - .end_rot: - - mov esi,angle_x - mov edi,matrix - call make_rotation_matrix - RDTSC - push eax - mov esi,[points_normals_ptr] - mov edi,[points_normals_rot_ptr] - mov ebx,matrix - mov ecx,[points_count_var] - call rotary - - mov esi,matrix - call add_scale_to_matrix - - mov esi,[points_ptr] - mov edi,[points_rotated_ptr] - mov ebx,matrix - mov ecx,[points_count_var] - call rotary - - - mov esi,[points_rotated_ptr] - mov edi,[points_translated_ptr] - mov ecx,[points_count_var] - call translate_points - - cmp [fire_flag],0 - jne @f - call clrscr ; clear the screen - @@: - cmp [dr_flag],7 ; fill if 2tex and texgrd - jge @f - cmp [catmull_flag],0 ;non fill if Catmull = off - je .non_f - cmp [dr_flag],6 ; non fill if dots - je .non_f - @@: - call fill_Z_buffer ; make background - .non_f: - cmp [dr_flag],6 - jne @f - call draw_dots - jmp .blurrr - @@: - call draw_triangles ; draw all triangles from the list - cmp [edit_flag],0 - jz .no_edit - call clear_vertices_index - call draw_handlers - ; call edit - - .no_edit: - - .blurrr: - cmp [sinus_flag],0 - je @f - call do_sinus - @@: - cmp [fire_flag],0 - jne @f - cmp [blur_flag],0 - je .no_blur ; no blur, no fire - movzx ecx,[blur_flag] - call blur_screen ; blur and fire - jmp .no_blur - @@: - cmp [emboss_flag],0 - jne .emb ; if emboss=true -> no fire - movzx ecx,[fire_flag] - call blur_screen ; blur and fire - .no_blur: ; no blur, no fire - cmp [emboss_flag],0 - je @f - .emb: - call do_emboss - - @@: - - cmp [inc_bright_flag],0 ; increase brightness - je .no_inc_bright - movzx ebx,[inc_bright_flag] - shl ebx,4 - mov esi,[screen_ptr] - movzx ecx,word[size_y_var] - movzx eax,word[size_x_var] - mul ecx - lea ecx,[eax*4] - -if (Ext = MMX)|(Ext = SSE) - mov bh,bl - push bx - shl ebx,16 - pop bx - push ebx - push ebx - movq mm0,[esp] - add esp,8 -else if Ext >= SSE2 - mov bh,bl - push bx - shl ebx,16 - pop bx - movd xmm0,ebx - shufps xmm0,xmm0,0 -end if - .oop: -if Ext=NON - lodsb - add al,bl - jnc @f - mov byte[esi-1],255 - loop .oop - @@: - mov [esi-1],al - loop .oop -else if (Ext=MMX)|(Ext=SSE) - movq mm1,[esi] - movq mm2,[esi+8] - paddusb mm1,mm0 - paddusb mm2,mm0 - movq [esi],mm1 - movq [esi+8],mm2 - add esi,16 - sub ecx,16 - jnz .oop -else - movaps xmm1,[esi] - paddusb xmm1,xmm0 - movaps [esi],xmm1 - add esi,16 - sub ecx,16 - jnc .oop -end if - -.no_inc_bright: - - - cmp [dec_bright_flag],0 - je .no_dec_bright - movzx ebx,[dec_bright_flag] - shl ebx,4 - mov esi,[screen_ptr] - movzx eax,word[size_x_var] - movzx ecx,word[size_y_var] - mul ecx - lea ecx,[eax*4] - if (Ext = MMX)|(Ext = SSE) - mov bh,bl - push bx - shl ebx,16 - pop bx - push ebx - push ebx - movq mm0,[esp] - add esp,8 -else if Ext >=SSE2 - mov bh,bl - push bx - shl ebx,16 - pop bx - movd xmm0,ebx - shufps xmm0,xmm0,0 -end if - .oop1: -if Ext=NON - lodsb - sub al,bl - jb @f - mov [esi-1],al - loop .oop1 - @@: - mov byte[esi-1],0 - loop .oop1 -else if (Ext = MMX)|(Ext=SSE) - movq mm1,[esi] - psubusb mm1,mm0 - movq [esi],mm1 - add esi,8 - sub ecx,8 - jnz .oop1 -else - movaps xmm1,[esi] - psubusb xmm1,xmm0 - movaps [esi],xmm1 - add esi,16 - sub ecx,16 - jnc .oop1 -end if - .no_dec_bright: - - - RDTSC - sub eax,[esp] - sub eax,41 -; pop eax - - mov ecx,10 - .dc: - xor edx,edx - mov edi,10 - div edi - add dl,30h - mov [STRdata+ecx-1],dl - loop .dc - pop eax - - - mov eax,7 ; put image - mov ebx,[screen_ptr] - mov ecx,[size_y_var] - ; mov ecx,SIZE_X shl 16 + SIZE_Y - mov edx,[offset_y] ;5 shl 16 + 25 - cmp [dr_flag],12 - jge .ff - int 0x40 - jmp .f - .ff: - mov eax,65 - mov esi,32 - xor ebp,ebp - int 0x40 - .f: - mov eax,13 - mov bx,[size_x_var] - add ebx,18 - shl ebx,16 - mov bx,60 - mov cx,[size_y_var] - sub cx,2 - shl ecx,16 - mov cx,9 - xor edx,edx - int 40h - - mov eax,4 ; function 4 : write text to window - mov bx,[size_x_var] - add ebx,18 - shl ebx,16 - mov bx,[size_y_var] - sub bx,2 ; [x start] *65536 + [y start] - mov ecx,0x00888888 - mov edx,STRdata ; pointer to text beginning - mov esi,10 ; text length - int 40h - - - - jmp still - -;-------------------------------------------------------------------------------- -;-------------------------PROCEDURES--------------------------------------------- -;-------------------------------------------------------------------------------- -include "flat_cat.inc" -include "tex_cat.inc" -include "bump_cat.inc" -include "3dmath.inc" -include "grd_line.inc" -include "b_procs.inc" -include "a_procs.inc" -include "grd_cat.inc" -include "bump_tex.inc" -include "grd_tex.inc" -include "two_tex.inc" -include "asc.inc" -if Ext >= SSE3 -include "3r_phg.inc" -include '3stencil.inc' -include '3glass.inc' -include '3glass_tex.inc' -end if -clear_vertices_index: - mov edi,[vertices_index_ptr] - movzx eax,word[size_x_var] - movzx ecx,word[size_y_var] - imul ecx,eax - xor eax,eax - shr ecx,1 - rep stosd -ret -edit: ; mmx required, edit mesh by vertex - push ebp - mov ebp,esp - sub esp,128 - - .y_coord equ ebp-2 - .x_coord equ ebp-4 - .points_translated equ ebp-10 - .points equ ebp-22 - .points_rotated equ ebp-34 - .mx equ ebp-70 - - macro check_bar - { - movzx ebx,word[.x_coord] - movzx ecx,word[.y_coord] - movzx edx,word[size_x_var] - imul edx,ecx - add ebx,edx - push ebx - lea ecx,[ebx*2] - lea ebx,[ebx*3] - - cmp [dr_flag],12 - jl @f - add ebx,[esp] - @@: - add esp,4 - add ebx,[screen_ptr] - mov ebx,[ebx] - and ebx,0x00ffffff - cmp ebx,0x00ff0000 ; is handle bar ? - } - - emms - mov eax,37 ; get mouse state - mov ebx,1 ; x = 5, y = 25 - offsets - int 0x40 - - mov ebx,[offset_y] ;5 shl 16 + 25 - movd mm0,ebx - movd mm1,eax - movd mm3,[size_y_var] - pcmpgtw mm0,mm1 - pcmpgtw mm3,mm1 - pxor mm3,mm0 - movd eax,mm3 - mov cx,ax - shr eax,16 - and ax,cx - or ax,ax - jz .no_edit - - - movd mm0,ebx - psubw mm1,mm0 - movd eax,mm1 - - ; store both x and y coordinates - ror eax,16 - ; push eax - ; sub esp,256 - mov [.x_coord],eax - test word[mouse_state],100000000b - jz .not_press ; check if left mouse button press - - ; left button pressed - - - check_bar - jne .no_edit - add ecx,[vertices_index_ptr] - mov cx,word[ecx] - inc cx - - - mov [vertex_edit_no],cx ;if vert_edit_no = 0, no vertex selected - - mov eax,dword[.x_coord] - mov dword[edit_end_x],eax - mov dword[edit_start_x],eax - jmp .end - .not_press: - test byte[mouse_state],1b ; check if left button is held - jz .not_held - ; check_bar - ; jne .no_edit - ; add ecx,[vertices_index_ptr] - ; mov cx,[ecx] - ; inc cx - cmp [vertex_edit_no],0 ; cx ; vertex number - je .end - push dword[.x_coord] - pop dword[edit_end_x] - jmp .end - .not_held: - shr [mouse_state],16 - test byte[mouse_state],1b ; test if left button released - jz .end - check_bar - jne .end - - movzx esi,[vertex_edit_no] - dec esi - lea esi,[esi*3] - add esi,esi - add esi,[points_translated_ptr] - emms - - movd mm1,dword[esi] - paddw mm1,mm0 - psubw mm1,qword[vect_x] - movd dword[esi],mm1 - - lea edi,[.points] - ; detranslate - fninit - fild word[esi+4] - fstp dword[edi+8] - fild word[esi+2] - fisub word[offset_x] - fstp dword[edi+4] - fild word[esi] - fisub word[offset_y] ; proteza - fstp dword[edi] - - mov esi,matrix - lea edi,[.mx] - call reverse_mx_3x3 - - lea esi,[.points] - lea edi,[.points_rotated] - lea ebx,[.mx] - mov ecx,1 - call rotary - - ; inject into vertex list - movzx edi,[vertex_edit_no] - dec edi - lea edi,[edi*3] - shl edi,2 - add edi,[points_ptr] - lea esi,[.points_rotated] - cld - movsd - movsd - movsd - ; mov ecx,3 - ; cld - ; rep movsd - - - mov dword[edit_end_x],0 - mov [vertex_edit_no],0 - - .no_edit: - .end: - mov esp,ebp - pop ebp -ret - -alloc_buffer_mem: - push ebp - mov ebp,esp - .temp equ ebp-4 - push dword 0 - - mov eax, 68 - mov ebx, 11 - int 0x40 ; -> create heap, to be sure - - - movzx ecx,word[size_x_var] - movzx eax,word[size_y_var] - mul ecx - - mov [.temp],eax - lea ecx,[eax*4] ; more mem for r_phg cause - add ecx,256 - mov eax,68 - mov ebx,20 - mov edx,[screen_ptr] - int 0x40 - mov [screen_ptr],eax - - mov ecx,[.temp] - shl ecx,2 - add ecx,256 - mov eax,68 - mov ebx,20 - mov edx,[Zbuffer_ptr] - int 0x40 - mov [Zbuffer_ptr],eax - - - mov ecx,[.temp] - add ecx,ecx - add ecx,256 - mov eax,68 - mov ebx,20 - mov edx,[vertices_index_ptr] - int 0x40 - mov [vertices_index_ptr],eax - - mov esp,ebp - pop ebp - - - - -update_flags: -; updates flags and writing flag description -; in ah - button number - push ax - mov edi,menu - .ch_another: - cmp ah,byte[edi] ; ah = button id - jne @f - mov bl,byte[edi+11] ; max_flag + 1 - cmp bl,255 - je .no_write - inc byte[edi+12] ; flag - cmp byte[edi+12],bl - jne .write - mov byte[edi+12],0 - jmp .write - @@: - add edi,17 - cmp byte[edi],-1 - jne .ch_another - jmp .no_write - .write: -; clreol {pascal never dies} -; * eax = 13 - function number -; * ebx = [coordinate on axis x]*65536 + [size on axis x] -; * ecx = [coordinate on axis y]*65536 + [size on axis y] -; * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill - - mov eax,13 ; function 13 write rectangle - movzx ecx,byte[edi] - sub cl,2 - lea ecx,[ecx*3] - lea ecx,[ecx*5] - add ecx,28 - shl ecx,16 - add ecx,14 ; ecx = [coord y]*65536 + [size y] - mov bx,[size_x_var] - shl ebx,16 - add ebx,(12+70)*65536+25 ; [x start] *65536 + [size x] - mov edx,0x00000000 ; color 0x00RRGGBB - int 0x40 - - mov eax,4 ; function 4 : write text to window - movzx ebx,byte[edi] - sub bl,2 - lea ebx,[ebx*3] - lea ebx,[ebx*5] - mov cx,[size_x_var] - shl ecx,16 - add ebx,ecx - add ebx,(12+70)*65536+28 ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - movzx edx,byte[edi+12] ; current flag - shl edx,2 ; * 4 = text length - add edx,dword[edi+13] ; pointer to text beginning - mov esi,4 ; text length - - ; flag description 4 characters - int 0x40 - - .no_write: - pop ax -ret -normalize_all_light_vectors: - mov edi,lights - @@: - call normalize_vector ; 3dmath.inc - add edi,LIGHT_SIZE - cmp edi,lightsend ;ecx - jl @b -ret - -calc_bumpmap_coords: ; map texture, bump -;macro .comment222 -; ; planar mapping -; mov esi,points -; mov edi,tex_points -; @@: -; add esi,2 -; movsd -; cmp dword[esi],dword -1 -; jne @b - -; .Pi2 equ dword[ebp-4] - -; mov ebp,esp -; sub esp,4 - - fninit - fldpi - fadd st,st - mov esi,[points_ptr] - mov edi,tex_points - mov ecx,[points_count_var] - inc ecx -; cmp [map_tex_flag],1 -; jne .cylindric - ; spherical mapping around y axle - - @@: - fld dword[esi] ; x coord - fld dword[esi+8] ; z coord - fpatan ; arctg(st1/st) -; fdiv .Pi2 - fdiv st0,st1 - fimul [tex_x_div2] - fiadd [tex_x_div2] - fistp word[edi] ; x - - fld dword[esi+4] ; y coord - fld dword[esi] ; x - fmul st,st0 - fld dword[esi+4] ; y - fmul st,st0 - fld dword[esi+8] ; z - fmul st,st0 - faddp - faddp - fsqrt - fpatan - fldpi - fdivp - fimul [tex_y_div2] - fiadd [tex_y_div2] - fistp word[edi+2] ; y - - add esi,12 - add edi,4 - loop @b - ffree st0 -; jmp .end_map -; .cylindric: -; fld dword[esi] ; around y axle -; fld dword[esi+8] -; fpatan -; fdiv st0,st1 -; fimul [tex_x_div2] -; fiadd [tex_x_div2] -; fistp word[edi] - -; fld dword[esi+4] -; fimul [tex_y_div2] -; fiadd [tex_y_div2] -; fistp word[edi+2] - -; add esi,12 -; add edi,4 -; loop .cylindric -; ffree st0 -;; mov esp,ebp -; .end_map: -ret - - -init_envmap2: ; do env_map using many light sources -;env_map 512 x 512 x 3 bytes -.temp equ word [ebp-2] -.nEy equ word [ebp-4] -.nEx equ word [ebp-6] -.col_r equ [ebp-8] -.col_g equ [ebp-9] -.col_b equ [ebp-10] - - push ebp - mov ebp,esp - sub esp,20 - mov edi,envmap - fninit - - mov dx,- TEX_Y / 2 ;256 ; dx - vertical coordinate = y - .ie_ver: - mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x - .ie_hor: - xor ebx,ebx - mov dword .col_b, 0 - .light: - lea esi,[lights+ebx] - fld dword[esi] ; light vector x cooficient - fimul [tex_x_div2] ;[i256] - mov .temp,cx - fisubr .temp - fistp .nEx - fld dword[esi+4] ; light vector y cooficient - fimul [tex_y_div2] ;[i256] - mov .temp,dx - fisubr .temp - fistp .nEy - - cmp .nEx,- TEX_X / 2 ;256 - jl .update_counters - cmp .nEy,- TEX_Y / 2 ;256 - jl .update_counters - cmp .nEx,TEX_X / 2 ;256 - jg .update_counters - cmp .nEy,TEX_Y / 2 ;256 - jg .update_counters - - fild .nEx - fmul st,st0 - fild .nEy - fmul st,st0 - faddp - fsqrt - fisubr [i256] - fmul [env_const] - fidiv [i256] ; st - 'virtual' dot product - - fcom [dot_max] - fstsw ax - sahf - jb @f - ffree st - fld1 ;[dot_max] - @@: - fcom [dot_min] - fstsw ax - sahf - ja @f - ffree st - fldz ;[dot_min] - @@: - push ebp - movzx ax,byte[esi+21] - push ax ;- shines - mov al,byte[esi+14] ; b orginal color - push ax - mov al,byte[esi+13] ; g - push ax - mov al,byte[esi+12] ; r - push ax - ; pxor xmm1,xmm1 - ; movd xmm0,[esi+12] - ; punpckhbw xmm0,xmm1 - ; sub esp,8 - ; movq [esp],xmm0 - - - mov al,byte[esi+20] ; b max color - push ax - mov al,byte[esi+19] ; g - push ax - mov al,byte[esi+18] ; r - push ax - mov al,byte[esi+17] ; b min col - push ax - mov al,byte[esi+16] ; g - push ax - mov al,byte[esi+15] ; r - push ax - push eax ; earlier - dot pr - ; fstp .dot_product - ; push .dot_product - call calc_one_col - pop ebp - ; eax-0x00rrggbb - cmp al,.col_b - jbe @f - mov .col_b,al - @@: ; eax - ggbb00rr - shr ax,8 - cmp al,.col_g - jbe @f - mov .col_g,al - @@: ; eax - bb0000gg - shr eax,16 - cmp al,.col_r - jbe @f - mov .col_r,al - @@: - .update_counters: ; update and jump when neccesery - add ebx,LIGHT_SIZE - cmp bx,[all_lights_size] - jl .light ; next_light - mov eax,dword .col_b - stosd - dec edi - - inc cx - cmp cx,TEX_X / 2 ;256 - jne .ie_hor - - inc dx - cmp dx,TEX_Y / 2 ;256 - jne .ie_ver - - mov esp,ebp - pop ebp -ret - - - -do_color_buffer: ; do color buffer for Gouraud, flat shading -;env_map 512 x 512 x 3 bytes ; many lights using -.temp equ word [ebp-2] -.nz equ dword [ebp-6] ; dword -.ny equ dword [ebp-10] -.nx equ dword [ebp-14] -.col_r equ [ebp-16] -.col_g equ [ebp-17] -.col_b equ [ebp-18] - - push ebp - mov ebp,esp - sub esp,20 - mov edi,color_map - fninit - - mov dx,- TEX_Y / 2 ;-256 ; dx - vertical coordinate = y - .ie_ver: - mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x - .ie_hor: - mov .temp,cx - fild .temp - fidiv [i256] ;st = Nx - vector normal x cooficient - fst .nx - fmul st,st0 - mov .temp,dx - fild .temp - fidiv [i256] ; st = Ny - vector normal y coeficient - fst .ny - fmul st,st0 - faddp - fld1 - fchs - faddp - fabs - fsqrt - fchs - fstp .nz ; st - Nz - vect normal z coeficient - xor ebx,ebx - mov dword .col_b, 0 - .light: - push edi ;env_map - lea esi,[lights+ebx] - lea edi,.nx - call dot_product - pop edi - fcom [dot_min] - fstsw ax - sahf - ja .env_ok1 ;compare with dot_max - ffree st - - jmp .update_counters - .env_ok1: - fcom [dot_max] - fstsw ax - sahf - jb .env_ok2 ; calc col - ffree st - jmp .update_counters - .env_ok2: ;calc col - push ebp - movzx ax,byte[esi+21] - push ax ;- shines - mov al,byte[esi+14] ; b orginal color - push ax - mov al,byte[esi+13] ; g - push ax - mov al,byte[esi+12] ; r - push ax - mov al,byte[esi+20] ; b max color - push ax - mov al,byte[esi+19] ; g - push ax - mov al,byte[esi+18] ; r - push ax - mov al,byte[esi+17] ; b min col - push ax - mov al,byte[esi+16] ; g - push ax - mov al,byte[esi+15] ; r - push ax - push eax ; earlier - dot pr - ; fstp .dot_product - ; push .dot_product - call calc_one_col - pop ebp - ; eax-0x00rrggbb - cmp al,.col_b - jbe @f - mov .col_b,al - @@: - shr ax,8 - cmp al,.col_g - jbe @f - mov .col_g,al - @@: - shr eax,16 - cmp al,.col_r - jbe @f - mov .col_r,al - @@: - .update_counters: ; update and jump when neccesery - add ebx,LIGHT_SIZE - cmp bx,[all_lights_size] - jl .light ; next_light - mov eax,dword .col_b - stosd - dec edi - - inc cx - cmp cx,TEX_X / 2 ;256 - jne .ie_hor - - inc dx - cmp dx,TEX_X / 2 ;256 - jne .ie_ver - - .env_done: - mov esp,ebp - pop ebp -ret -if Ext >= SSE2 -init_point_normals: -.z equ dword [ebp-8] -.y equ dword [ebp-12] -.x equ [ebp-16] -.point_number equ dword [ebp-28] -.hit_faces equ dword [ebp-32] - - push ebp - mov ebp,esp - sub esp,64 - and ebp,-16 - mov edi,[points_normals_ptr] - mov .point_number,0 - .ipn_loop: - movd xmm0,.point_number - pshufd xmm0,xmm0,0 - mov .hit_faces,0 - mov .x,dword 0 - mov .y,0 - mov .z,0 - mov esi,[triangles_ptr] - xor ecx,ecx ; ecx - triangle number - .ipn_check_face: - movdqu xmm1,[esi] - pcmpeqd xmm1,xmm0 - pmovmskb eax,xmm1 - and eax,0xfff - or eax,eax - jz .ipn_next_face - push esi - mov esi,ecx - lea esi,[esi*3] - shl esi,2 - add esi,[triangles_normals_ptr] - movups xmm7,[esi] - addps xmm7,.x - movaps .x,xmm7 - pop esi - inc .hit_faces - - .ipn_next_face: - add esi,12 - inc ecx - cmp ecx,[triangles_count_var] - jne .ipn_check_face - cvtsi2ss xmm6,.hit_faces - movaps xmm7,.x - - rcpss xmm6,xmm6 - shufps xmm6,xmm6,11000000b - mulps xmm7,xmm6 - movlps [edi],xmm7 - movhlps xmm7,xmm7 - movss [edi+8],xmm7 - call normalize_vector - ; movaps xmm6,xmm7 - ; mulps xmm6,xmm6 - ; andps xmm6,[zero_hgst_dd] - ; haddps xmm6,xmm6 - ; haddps xmm6,xmm6 - ; rsqrtps xmm6,xmm6 - ; mulps xmm7,xmm6 - ; movlps [edi],xmm7 - ; movhlps xmm7,xmm7 - ; movss [edi+8],xmm7 - - add edi,12 - inc .point_number - mov edx,.point_number - cmp edx,[points_count_var] - jne .ipn_loop - - add esp,64 - pop ebp -ret -else -init_point_normals: -.x equ dword [ebp-4] -.y equ dword [ebp-8] -.z equ dword [ebp-12] -.point_number equ dword [ebp-28] -.hit_faces equ dword [ebp-32] - - fninit - mov ebp,esp - sub esp,32 - mov edi,[points_normals_ptr] - mov .point_number,0 - .ipn_loop: - mov .hit_faces,0 - mov .x,0 - mov .y,0 - mov .z,0 - mov esi,[triangles_ptr] - xor ecx,ecx ; ecx - triangle number - .ipn_check_face: - xor ebx,ebx ; ebx - 'position' in one triangle - .ipn_check_vertex: - mov eax,dword[esi+ebx] ; eax - point_number - cmp eax,.point_number - jne .ipn_next_vertex - push esi - mov esi,ecx - lea esi,[esi*3] - ; lea esi,[triangles_normals+esi*4] - shl esi,2 - add esi,[triangles_normals_ptr] - - fld .x - fadd dword[esi+vec_x] ; vec_x this defined in 3dmath.asm - x cooficient - fstp .x ; of normal vactor - fld .y - fadd dword[esi+vec_y] - fstp .y - fld .z - fadd dword[esi+vec_z] - fstp .z - pop esi - inc .hit_faces - jmp .ipn_next_face - .ipn_next_vertex: - add ebx,4 - cmp ebx,12 - jne .ipn_check_vertex - .ipn_next_face: - add esi,12 - inc ecx - cmp ecx,[triangles_count_var] - jne .ipn_check_face - - fld .x - fidiv .hit_faces - fstp dword[edi+vec_x] - fld .y - fidiv .hit_faces - fstp dword[edi+vec_y] - fld .z - fidiv .hit_faces - fstp dword[edi+vec_z] - call normalize_vector - add edi,12 ;type vector 3d - inc .point_number - mov edx,.point_number - cmp edx,[points_count_var] - jne .ipn_loop - - mov esp,ebp -ret -;=============================================================== -end if -init_triangles_normals2: - mov ebx,[triangles_normals_ptr] - mov ebp,[triangles_ptr] - mov ecx,[triangles_count_var] - @@: - push ecx - push ebx - mov ebx,vectors - mov esi,dword[ebp] ; first point index - lea esi,[esi*3] -; lea esi,[points+esi*2] ; esi - pointer to 1st 3d point - shl esi,2 - add esi,[points_ptr] - mov edi,dword[ebp+4] ; first point index - lea edi,[edi*3] - shl edi,2 - add edi,[points_ptr] -; movzx edi,word[ebp+2] ; second point index -; lea edi,[edi*3] -; lea edi,[points+edi*2] ; edi - pointer to 2nd 3d point - call make_vector_r - add ebx,12 - mov esi,edi - mov edi,dword[ebp+8] ; third point index - lea edi,[edi*3] - shl edi,2 - add edi,[points_ptr] -; lea edi,[points+edi*2] - call make_vector_r - mov edi,ebx ; edi - pointer to 2nd vector - mov esi,ebx - sub esi,12 ; esi - pointer to 1st vector - pop ebx - call cross_product - mov edi,ebx - call normalize_vector - add ebp,12 - add ebx,12 - pop ecx - sub ecx,1 - jnz @b - ; cmp dword[ebp],-1 - ; jne @b -ret - -if Ext >= SSE3 -copy_lights: ; after normalising ! - mov esi,lights - mov edi,lights_aligned - mov ecx,3 - .again: - push ecx - mov ecx,3 - cld - rep movsd - xor eax,eax - stosd - mov ecx,3 - .b: - push ecx - mov ecx,3 - @@: - movzx ebx,byte[esi] - cvtsi2ss xmm0,ebx - movss [edi],xmm0 - inc esi - add edi,4 - loop @b - stosd - pop ecx - loop .b - inc esi ; skip shiness - pop ecx - loop .again -ret -end if - -clrscr: - mov edi,[screen_ptr] - movzx ecx,word[size_x_var] - movzx eax,word[size_y_var] - imul ecx,eax - - - xor eax,eax - if Ext=NON - rep stosd - else if Ext = MMX - pxor mm0,mm0 - @@: - movq [edi+00],mm0 - movq [edi+08],mm0 - movq [edi+16],mm0 - movq [edi+24],mm0 - add edi,32 - sub ecx,8 - jnc @b - else - push ecx - mov ecx,edi - and ecx,0x0000000f - rep stosb - pop ecx - and ecx,0xfffffff0 - xorps xmm0,xmm0 - @@: - movaps [edi],xmm0 - movaps [edi+16],xmm0 - movaps [edi+32],xmm0 - movaps [edi+48],xmm0 - add edi,64 - sub ecx,16 - jnz @b - end if - -ret - - -draw_triangles: - - emms - ; update translated list MMX required - cmp [vertex_edit_no],0 - je @f - movzx eax,[vertex_edit_no] - dec eax - movd mm0,[edit_end_x] - psubw mm0,[edit_start_x] - lea eax,[eax*3] - add eax,eax - add eax,[points_translated_ptr] - movd mm1,dword[eax] - paddw mm1,mm0 - movd dword[eax],mm1 - @@: - if Ext >= SSE3 - cmp [dr_flag],13 - jnge .no_stencil - mov esi,[triangles_ptr] - mov ecx,[triangles_count_var] - @@: - push esi - push ecx - - mov eax,[esi] - mov ebx,[esi+4] - mov ecx,[esi+8] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_rotated_ptr] - add ebx,[points_rotated_ptr] - add ecx,[points_rotated_ptr] - push dword[ecx+8] - push dword[ebx+8] - push dword[eax+8] - movups xmm0,[esp] - add esp,12 - andps xmm0,[zero_hgst_dd] - - - mov eax,[esi] - mov ebx,[esi+4] - mov ecx,[esi+8] - shl eax,1 - shl ebx,1 - shl ecx,1 - lea eax,[eax*3] - lea ebx,[ebx*3] - lea ecx,[ecx*3] - add eax,[points_translated_ptr] - add ebx,[points_translated_ptr] - add ecx,[points_translated_ptr] - mov eax,[eax] - mov ebx,[ebx] - mov ecx,[ecx] - ror eax,16 - ror ebx,16 - ror ecx,16 - - - mov esi,[Zbuffer_ptr] - - call stencil_tri - - pop ecx - pop esi - add esi,12 - dec ecx - jnz @b - - .no_stencil: - end if - - - - mov esi,[triangles_ptr] - mov ecx,[triangles_count_var] - .again_dts: - push ecx - mov ebp,[points_translated_ptr] - if Ext = NON - mov eax,dword[esi] - mov [point_index1],eax - lea eax,[eax*3] - add eax,eax - push ebp - add ebp,eax - mov eax,[ebp] - ; cmp [vertex_edit_no],0 - ; jne @f - ; - ; @@: - mov dword[xx1],eax - mov eax,[ebp+4] - mov [zz1],ax - - pop ebp - - - mov eax,dword[esi+4] - mov [point_index2],eax - lea eax,[eax*3] - add eax,eax - push ebp - add ebp,eax - mov eax,[ebp] - mov dword[xx2],eax - mov eax,[ebp+4] - mov [zz2],ax - pop ebp - - - mov eax,dword[esi+8] ; xyz3 = [ebp+[esi+4]*6] - mov [point_index3],eax - lea eax,[eax*3] - add eax,eax - ; push ebp - add ebp,eax - mov eax,[ebp] - mov dword[xx3],eax - mov eax,[ebp+4] - mov [zz3],ax - else - movq mm0,[esi] ; don't know MMX - movq qword[point_index1],mm0 - ; shr eax,16 - ; mov [point_index2],ax - mov eax,dword[esi+8] - mov [point_index3],eax - movdqu xmm0,[esi] - paddd xmm0,xmm0 - movdqa xmm1,xmm0 - paddd xmm0,xmm0 - paddd xmm0,xmm1 - movd eax,xmm0 - psrldq xmm0,4 - movd ebx,xmm0 - psrldq xmm0,4 - movd ecx,xmm0 - and eax,0FFFFh - and ebx,0FFFFh - and ecx,0FFFFh - movq mm0,[ebp+eax] - movq mm1,[ebp+ebx] - movq mm2,[ebp+ecx] - movq qword[xx1],mm0 - movq qword[xx2],mm1 - movq qword[xx3],mm2 -; emms - end if ; ********************************* - if 0 - cmp [vertex_edit_no],0 - jne .no_edit - mov ax,[vertex_edit_no] - dec ax - cmp ax,[point_index1] - jne @f - movd mm0,[edit_start_x] - psubw mm0,[edit_end_x] - movd mm1,dword[xx1] - paddw mm1,mm0 - movd dword[xx1],mm1 - jmp .no_edit - @@: - - cmp ax,[point_index2] - jne @f - movd mm0,[edit_start_x] - psubw mm0,[edit_end_x] - movd mm1,dword[xx2] - paddw mm1,mm0 - movd dword[xx2],mm1 - jmp .no_edit - @@: - - cmp ax,[point_index3] - jne @f - movd mm0,[edit_start_x] - psubw mm0,[edit_end_x] - movd mm1,dword[xx3] - paddw mm1,mm0 - movd dword[xx3],mm1 - jmp .no_edit - @@: - - - .no_edit: -end if - - push esi ; - fninit ; DO culling AT FIRST - cmp [culling_flag],1 ; (if culling_flag = 1) - jne .no_culling - mov esi,point_index1 ; ********************************* - mov ecx,3 ; - @@: - mov eax,dword[esi] - lea eax,[eax*3] - shl eax,2 - add eax,[points_normals_rot_ptr] - bt dword[eax+8],+31 - jc .no_culling -; lea eax,[eax+point_normals_rotated] - ; fld dword[eax+8] ; ***************************** - ; ftst ; CHECKING OF Z COOFICIENT OF - ; fstsw ax ; NORMAL VECTOR - ; sahf - ; jb @f - ; ffree st - loop @b - jmp .end_draw ; non visable - ; @@: - ; ffree st ;is visable - .no_culling: - cmp [dr_flag],0 ; draw type flag - je .flat_draw - cmp [dr_flag],2 - je .env_mapping - cmp [dr_flag],3 - je .bump_mapping - cmp [dr_flag],4 - je .tex_mapping - cmp [dr_flag],5 - je .rainbow - cmp [dr_flag],7 - je .grd_tex - cmp [dr_flag],8 - je .two_tex - cmp [dr_flag],9 - je .bump_tex - cmp [dr_flag],10 - je .cubic_env_mapping - cmp [dr_flag],11 - je .draw_smooth_line - if Ext >= SSE3 - cmp [dr_flag],12 - je .r_phg - cmp [dr_flag],13 - je .glass - cmp [dr_flag],14 - je .glass_tex - - end if ; **************** - mov esi,point_index3 ; do Gouraud shading - mov ecx,3 - .again_grd_draw: - mov eax,dword[esi] - shl eax,2 - lea eax,[eax*3] - add eax,[points_normals_rot_ptr] - if Ext < SSE - ; texture x=(rotated point normal -> x * 255)+255 - fld dword[eax] ; x cooficient of normal vector - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp1] - ; texture y=(rotated point normal -> y * 255)+255 - fld dword[eax+4] ; y cooficient - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp2] - mov eax,[temp2] - mov ebx,[temp1] - else - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - movd eax,xmm0 - psrldq xmm0,4 - movd ebx,xmm0 - end if - and ebx,0xfffffff - shl eax,TEX_SHIFT - add eax,ebx - lea eax,[eax*3+color_map] - mov eax,dword[eax] - ; cmp [catmull_flag],1 ; put on stack z coordinate if necessary - ; jne @f - lea edx,[ecx*3] - push word[edx*2+xx1-2] ; zz1 ,2 ,3 - ; @@: - ror eax,16 ; eax -0xxxrrggbb -> 0xggbbxxrr - xor ah,ah - push ax ;r - rol eax,8 ; eax-0xggbb00rr -> 0xbb00rrgg - xor ah,ah - push ax ;g - shr eax,24 - push ax ;b - - sub esi,4 - dec cx - jnz .again_grd_draw - jmp .both_draw - - ; movzx edi,[point_index3] ;gouraud shading according to light vector - ; lea edi,[edi*3] - ; lea edi,[4*edi+point_normals_rotated] ; edi - normal - ; mov esi,light_vector - ; call dot_product - ; fabs - ; fimul [orginal_color_r] - ; fistp [temp_col] - ; and [temp_col],0x00ff - ; push [temp_col] - ; push [temp_col] - ; push [temp_col] - - ; movzx edi,[point_index2] - ; lea edi,[edi*3] - ; lea edi,[4*edi+point_normals_rotated] ; edi - normal - ; mov esi,light_vector - ; call dot_product - ; fabs - ; fimul [orginal_color_r] - ; fistp [temp_col] - ; and [temp_col],0x00ff - ; push [temp_col] - ; push [temp_col] - ; push [temp_col] - - ; movzx edi,[point_index1] - ; lea edi,[edi*3] - ; lea edi,[4*edi+point_normals_rotated] ; edi - normal - ; mov esi,light_vector - ; call dot_product - ; fabs - ; fimul [orginal_color_r] - ; fistp [temp_col] - ; and [temp_col],0x00ff - ; push [temp_col] - ; push [temp_col] - ; push [temp_col] - .rainbow: - ; cmp [catmull_flag],1 ; put on stack z coordinate if necessary - ; jne @f - push [zz3] - @@: - mov eax,dword[yy3] - mov ebx,0x00ff00ff - and eax,ebx - push eax - neg al - push ax - push [zz2] - - mov eax,dword[yy2] - and eax,ebx - push eax - neg al - push ax - push [zz1] - - mov eax,dword[yy1] - and eax,ebx - push eax - neg al - push ax - .both_draw: - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - call gouraud_triangle_z - jmp .end_draw - - .flat_draw: ;************************** - fninit ; FLAT DRAWING - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - ; shl eax,2 - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - ; shl ebx,2 - ; shl ecx,2 - ; lea eax,[eax*3] ;+point_normals_rotated] - add eax,[points_normals_rot_ptr] - ; lea ebx,[ebx*3] ;+point_normals_rotated] - add ebx,[points_normals_rot_ptr] - ; lea ecx,[ecx*3] ;+point_normals_rotated] - add ecx,[points_normals_rot_ptr] - fld dword[eax] ; x cooficient of normal vector - fadd dword[ebx] - fadd dword[ecx] - fidiv [i3] - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp1] ;dword[esp-4] ; x temp variables - fld dword[eax+4] ; y cooficient of normal vector - fadd dword[ebx+4] - fadd dword[ecx+4] - fidiv [i3] - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp2] ;dword[esp-8] ; y - mov edx,[temp2] ;dword[esp-8] - and edx,0xfffffff - and [temp1],0xfffffff - shl edx,TEX_SHIFT - add edx,[temp1] ;dword[esp-4] - - lea eax,[3*edx] - add eax,color_map - mov edx,dword[eax] - - and edx,0x00ffffff ; edx = 0x00rrggbb - - - - ; mov ax,[zz1] ; z position depend draw - ; add ax,[zz2] - ; add ax,[zz3] - ; cwd - ; idiv [i3] ; = -((a+b+c)/3+130) - ; add ax,130 - ; neg al - ; xor edx,edx - ; mov ah,al ;set color according to z position - ; shl eax,8 - ; mov edx,eax - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - - mov esi,[Zbuffer_ptr] - push word[zz3] - push word[zz2] - push word[zz1] - call flat_triangle_z - jmp .end_draw - - .env_mapping: - push [zz3] - push [zz2] - push [zz1] - - mov esi,point_index1 - sub esp,12 - mov edi,esp - mov ecx,3 - @@: - mov eax,dword[esi] - lea eax,[eax*3] - shl eax,2 - add eax,[points_normals_rot_ptr] ;point_normals_rotated - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - packssdw xmm0,xmm0 - movd [edi],xmm0 - add edi,4 - add esi,4 - loop @b - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,envmap - - mov edx,[Zbuffer_ptr] - call tex_triangle_z - - jmp .end_draw -;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - .cubic_env_mapping: - push [zz3] - push [zz2] - push [zz1] - - mov esi,point_index1 - sub esp,12 - mov edi,esp - mov ecx,3 - @@: - mov eax,dword[esi] - lea eax,[eax*3] - shl eax,2 - add eax,[points_normals_rot_ptr] - - fld dword[eax] - fmul dword[eax+4] - fld1 - fld1 - faddp - fmulp - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp word[edi] - mov word[edi+2],0 -; fistp word[edi+2] -; # last change -; ; texture x=(rotated point normal -> x * 255)+255 -; fld dword[eax] -; fimul [correct_tex] -; fiadd [correct_tex] -; fistp word[edi] -; ; texture y=(rotated point normal -> y * 255)+255 -; fld dword[eax+4] -; fimul [correct_tex] -; fiadd [correct_tex] -; fistp word[edi+2] -; # end of last ch. - add edi,4 - add esi,4 - loop @b - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,envmap_cub - mov edx,[Zbuffer_ptr] - - call tex_triangle_z - - jmp .end_draw - -;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - .bump_mapping: - - push [Zbuffer_ptr] - push [zz3] - push [zz2] - push [zz1] - - mov esi,point_index1 - sub esp,12 - mov edi,esp - mov ecx,3 - @@: - mov eax,dword[esi] - lea eax,[eax*3] - shl eax,2 - ; imul eax,[i12] - add eax,[points_normals_rot_ptr] ;point_normals_rotated - ; texture x=(rotated point normal -> x * 255)+255 - - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - packssdw xmm0,xmm0 - movd [edi],xmm0 - add edi,4 - add esi,4 - loop @b - - mov esi,[point_index3] ; bump map coords - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index2] - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,envmap - mov edx,bumpmap ;BUMP_MAPPING - - call bump_triangle_z - - jmp .end_draw - - .tex_mapping: - - push [zz3] - push [zz2] - push [zz1] - ; @@: - mov esi,[point_index3] ; tex map coords - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index2] - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,texmap - mov edx,[Zbuffer_ptr] - - call tex_triangle_z - - jmp .end_draw -; .ray: -; grd_triangle according to points index -; cmp [catmull_flag],0 -; je @f -; push [zz3] ; spot light with attenuation -; @@: -; movzx eax,[point_index3] ; env_map - points color list -; shl eax,1 ; each color as word, 0x00rr00gg00bb.. -; lea eax,[3*eax+bumpmap] -; push word[eax] -; push word[eax+2] -; push word[eax+4] -; cmp [catmull_flag],0 -; je @f -; push [zz2] -; @@: -; movzx eax,[point_index2] ; env_map - points color list -; shl eax,1 ; each color as word, 0x00rr00gg00bb.. -; lea eax,[eax*3+bumpmap] -; push word[eax] -; push word[eax+2] -; push word[eax+4] -; cmp [catmull_flag],0 -; je @f -; push [zz1] -; @@: -; movzx eax,[point_index1] ; env_map - points color list -; shl eax,1 ; each color as word, 0xrr00gg00bb00.. -; lea eax,[eax*3+bumpmap] -; push word[eax] -; push word[eax+2] -; push word[eax+4] -; jmp .both_draw - - .grd_tex: ; smooth shading + texture - push ebp - mov ebp,esp - sub esp,4 - push ebp - - mov esi,[point_index3] ; tex map coords - shl esi,2 - add esi,tex_points - push dword[esi] ; texture coords as first - mov esi,[point_index2] ; group of parameters - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - - mov esi,point_index3 - mov ecx,3 - - .aagain_grd_draw: - - lea edx,[ecx*3] - push word[edx*2+xx1-2] ; zz1 ,2 ,3 - ; fninit - mov eax,dword[esi] - shl eax,2 - lea eax,[eax*3] ;+point_normals_rotated] - add eax,[points_normals_rot_ptr] - if Ext < SSE - ; texture x=(rotated point normal -> x * 255)+255 - fld dword[eax] ; x cooficient of normal vector - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp1] ;word[ebp-2] - ; texture y=(rotated point normal -> y * 255)+255 - fld dword[eax+4] ; y cooficient - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp2] ;word[ebp-4] - mov eax,[temp2] - mov ebx,[temp1] - else - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - movd eax,xmm0 - psrldq xmm0,4 - movd ebx,xmm0 - end if - and ebx,0xfffffff ; some onjects need thid 'and' - shl eax,TEX_SHIFT - add eax,ebx - lea eax,[eax*3] - add eax,color_map - mov eax,dword[eax] - - ror eax,16 ; eax -0xxxrrggbb -> 0xggbbxxrr - xor ah,ah - push ax ;r - rol eax,8 ; eax-0xggbb00rr -> 0xbb00rrgg - xor ah,ah - push ax ;g - shr eax,24 - push ax ;b - - sub esi,4 - dec cx - jnz .aagain_grd_draw - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov edx,texmap - mov esi,[Zbuffer_ptr] - - call tex_plus_grd_triangle - - pop ebp - mov esp,ebp - pop ebp - jmp .end_draw - - .two_tex: - push [Zbuffer_ptr] - - push word[zz3] - push word[zz2] - push word[zz1] - - mov esi,[point_index3] ; tex map coords - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index2] - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - - mov esi,point_index1 ; env coords - sub esp,12 - mov edi,esp - mov ecx,3 - @@: - mov eax,dword[esi] - lea eax,[eax*3] - shl eax,2 - add eax,[points_normals_rot_ptr] - ; texture x=(rotated point normal -> x * 255)+255 - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - packssdw xmm0,xmm0 - movd [edi],xmm0 - ; fld dword[eax] - ; fmul dword[correct_texf] - ; fadd dword[correct_texf] - ; fistp word[edi] - - ; texture y=(rotated point normal -> y * 255)+255 - ; fld dword[eax+4] - ; fmul dword[correct_texf] - ; fadd dword[correct_texf] - ; fistp word[edi+2] - and word[edi+2],0x7fff ; some objects need it - add edi,4 - add esi,4 - loop @b - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,texmap - mov edx,envmap - - call two_tex_triangle_z - jmp .end_draw - - .bump_tex: - mov esi,[point_index3] ; tex map coords - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index2] - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - - push dword texmap - - push [Zbuffer_ptr] - xor edi,edi - - push word[zz3] - push word[zz2] - push word[zz1] - - mov esi,point_index1 ; env coords - sub esp,12 - mov edi,esp - mov ecx,3 - @@: - mov eax,dword[esi] - lea eax,[eax*3] - shl eax,2 - add eax,[points_normals_rot_ptr] - if Ext >= SSE - ; texture x=(rotated point normal -> x * 255)+255 - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - packssdw xmm0,xmm0 - movd [edi],xmm0 - else - fld dword[eax] - fimul [correct_tex] - fiadd [correct_tex] - fistp word[edi] - ; texture y=(rotated point normal -> y * 255)+255 - fld dword[eax+4] - fimul [correct_tex] - fiadd [correct_tex] - fistp word[edi+2] - end if - add edi,4 - add esi,4 - loop @b - -; push dword 1 shl 16 + 1 ; emap coords -; push dword 127 shl 16 + 1 -; push dword 127 shl 16 + 127 - - mov esi,[point_index3] ; bump map coords - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index2] - shl esi,2 - add esi,tex_points - push dword[esi] - - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - -; push dword 1 shl 16 + 127 -; push dword 127 shl 16 + 127 -; push dword 1 shl 16 + 1 ; bump coords - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,envmap - mov edx,bumpmap - - call bump_tex_triangle_z - - jmp .end_draw - - .draw_smooth_line: - mov esi,point_index3 - mov ecx,3 - .again_line_param: - mov eax,dword[esi] - shl eax,2 - lea eax,[eax*3] - add eax,[points_normals_rot_ptr] - if Ext>=SSE2 - movlps xmm0,[eax] - mulps xmm0,[correct_texf] - addps xmm0,[correct_texf] - cvtps2dq xmm0,xmm0 - movd eax,xmm0 - psrldq xmm0,4 - movd ebx,xmm0 - else if - ; texture ;x=(rotated point normal -> x * 255)+255 - fld dword[eax] ; x cooficient of normal vector - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp1] ;word[esp-2] - ; texture y=(rotated point normal -> y * 255)+255 - fld dword[eax+4] ; y cooficient - fmul dword[correct_texf] - fadd dword[correct_texf] - fistp [temp2] ;word[esp-4] - mov eax,[temp2] ;word[esp-4] - mov ebx,[temp1] ;word[esp-2] - end if - and ebx,0xfffffff - shl eax,TEX_SHIFT - add eax,ebx - lea eax,[eax*3+color_map] - mov eax,dword[eax] - lea ebx,[ecx-1] - shl ebx,2 - mov [ebx+col1],eax - - sub esi,4 - dec ecx - jnz .again_line_param - - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - - mov eax,[col1] - movzx bx,al - push bx ; b - movzx bx,ah - push bx - rol eax,16 - xor ah,ah - push ax - push [zz1] - push [yy1] - push [xx1] - - mov eax,[col2] - movzx bx,al - push bx ; b - movzx bx,ah - push bx - rol eax,16 - xor ah,ah - push ax - push [zz2] - push [yy2] - push [xx2] - - call smooth_line - @@: - - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - - mov eax,[col1] - movzx bx,al - push bx ; b - movzx bx,ah - push bx - rol eax,16 - xor ah,ah - push ax - push [zz1] - push [yy1] - push [xx1] - - mov eax,[col3] - movzx bx,al - push bx ; b - movzx bx,ah - push bx - rol eax,16 - xor ah,ah - push ax - push [zz3] - push [yy3] - push [xx3] - - call smooth_line - @@: - - - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - - mov eax,[col3] - movzx bx,al - push bx ; b - movzx bx,ah - push bx - rol eax,16 - xor ah,ah - push ax - push [zz3] - push [yy3] - push [xx3] - - mov eax,[col2] - movzx bx,al - push bx ; b - movzx bx,ah - push bx - rol eax,16 - xor ah,ah - push ax - push [zz2] - push [yy2] - push [xx2] - - call smooth_line - jmp .end_draw - @@: - -if Ext >= SSE3 - .r_phg: - - - movd xmm5,[size_y_var] - punpcklwd xmm5,[the_zero] - pshufd xmm5,xmm5,01110011b - - - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_normals_rot_ptr] - add ebx,[points_normals_rot_ptr] - add ecx,[points_normals_rot_ptr] - movups xmm0,[eax] - movups xmm1,[ebx] - movups xmm2,[ecx] - andps xmm0,[zero_hgst_dd] - andps xmm1,[zero_hgst_dd] - andps xmm2,[zero_hgst_dd] - xorps xmm3,xmm3 - - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_rotated_ptr] - add ebx,[points_rotated_ptr] - add ecx,[points_rotated_ptr] - push dword[ecx+8] - push dword[ebx+8] - push dword[eax+8] - movups xmm4,[esp] - add esp,12 - andps xmm4,[zero_hgst_dd] - - - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - - call real_phong_tri_z - - jmp .end_draw - - .glass: - - movd xmm5,[size_y_var] - punpcklwd xmm5,[the_zero] - pshufd xmm5,xmm5,01110011b - - - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_normals_rot_ptr] - add ebx,[points_normals_rot_ptr] - add ecx,[points_normals_rot_ptr] - movups xmm0,[eax] - movups xmm1,[ebx] - movups xmm2,[ecx] - andps xmm0,[zero_hgst_dd] - andps xmm1,[zero_hgst_dd] - andps xmm2,[zero_hgst_dd] - xorps xmm3,xmm3 - - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_rotated_ptr] - add ebx,[points_rotated_ptr] - add ecx,[points_rotated_ptr] - push dword[ecx+8] - push dword[ebx+8] - push dword[eax+8] - movups xmm4,[esp] - add esp,12 - andps xmm4,[zero_hgst_dd] - - - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edi,[screen_ptr] - mov edx,[Zbuffer_ptr] - mov esi,[Zbuffer_ptr] - - call glass_tri - jmp .end_draw - - .glass_tex: - movd xmm5,[size_y_var] - punpcklwd xmm5,[the_zero] - pshufd xmm5,xmm5,01110011b - - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_normals_rot_ptr] - add ebx,[points_normals_rot_ptr] - add ecx,[points_normals_rot_ptr] - movups xmm0,[eax] - movups xmm1,[ebx] - movups xmm2,[ecx] - andps xmm0,[zero_hgst_dd] - andps xmm1,[zero_hgst_dd] - andps xmm2,[zero_hgst_dd] - xorps xmm3,xmm3 - - mov eax,[point_index1] - mov ebx,[point_index2] - mov ecx,[point_index3] - imul eax,[i12] - imul ebx,[i12] - imul ecx,[i12] - add eax,[points_rotated_ptr] - add ebx,[points_rotated_ptr] - add ecx,[points_rotated_ptr] - push dword[ecx+8] - push dword[ebx+8] - push dword[eax+8] - movups xmm4,[esp] - add esp,12 - andps xmm4,[zero_hgst_dd] - - mov esi,[point_index3] ; tex map coords - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index2] - shl esi,2 - add esi,tex_points - push dword[esi] - mov esi,[point_index1] - shl esi,2 - add esi,tex_points - push dword[esi] - movups xmm6,[esp] - add esp,12 - ; pshuflw xmm6,xmm6,10110001b - ; pshufhw xmm6,xmm6,10110001b - - movzx eax,word[size_x_var] - andps xmm6,[zero_hgst_dd] - movd xmm7,eax - pslldq xmm7,12 - por xmm6,xmm7 - - - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - mov edx,texmap - mov edi,[screen_ptr] - mov esi,[Zbuffer_ptr] - - call glass_tex_tri - - jmp .end_draw -end if - - - - - .end_draw: - pop esi - add esi,12 - - pop ecx - sub ecx,1 - - jnz .again_dts -ret - - - - - - - - - - - -draw_handlers: - - push ebp - mov ebp,esp - - .counter equ ebp-16 - .xres3m18 equ ebp-8 - .xres2m12 equ ebp-12 - - - ; init counter - sub esp,12 - push dword 0 - - movzx eax,word[size_x_var] - cmp [dr_flag],12 - jge @f - lea ebx,[eax*3] - sub ebx,18 - add eax,eax - sub eax,12 - mov [.xres3m18],ebx - mov [.xres2m12],eax - jmp .f - @@: - lea ebx,[eax*4] - sub ebx,4*6 - add eax,eax - sub eax,3*4 - mov [.xres3m18],ebx - mov [.xres2m12],eax - .f: - - - - mov esi,[points_translated_ptr] - .loop: - push esi - ; DO culling AT FIRST - cmp [culling_flag],1 ; (if culling_flag = 1) - jne .no_culling - mov edi,[.counter] ; ********************************* - lea edi,[edi*3] - shl edi,2 - add edi,[points_normals_rot_ptr] - mov eax,[edi+8] ; check sign of z coof - shr eax,31 - cmp eax,1 - jnz .skip - .no_culling: - mov eax,[esi] - movzx ebx,ax ; ebx - x - shr eax,16 ; eax - y - cmp eax,4 ; check if markers not exceedes screen - jle .skip - cmp ebx,4 - jle .skip - movzx edx,word[size_x_var] - sub edx,4 - movzx ecx,word[size_y_var] - sub ecx,4 - cmp ebx,edx - jge .skip - cmp eax,ecx - jge .skip - - movzx edx,word[size_x_var] - ; sub ebx,3 - ; sub eax,3 - imul eax,edx - add eax,ebx - push eax - lea edi,[eax*3] - cmp [dr_flag],12 - jl @f - add edi,[esp] - @@: - add esp,4 - lea eax,[eax*2] - ; draw bar 6x6 - add edi,[screen_ptr] - add eax,dword[vertices_index_ptr] - - - - - mov edx,[.counter] - mov ecx,6 - - .oop: - push ecx - mov ecx,6 - - .do: - mov word[edi],0x0000 ;ax - mov byte[edi+2],0xff ;al - mov word[eax],dx - add eax,2 - cmp [dr_flag],12 - jl @f - add edi,4 - loop .do - jmp .ad - @@: - add edi,3 - loop .do - .ad: - add edi,[.xres3m18] - add eax,[.xres2m12] - pop ecx - loop .oop - - .skip: - pop esi - add esi,6 - inc dword[.counter] - mov ecx,[.counter] - cmp ecx,[points_count_var] - jng .loop - - mov esp,ebp - pop ebp - -ret - - -fill_Z_buffer: - mov eax,0x70000000 - cmp [dr_flag],12 - jne @f - mov eax,60000.1 - @@: - mov edi,[Zbuffer_ptr] - movzx ecx,word[size_x_var] - movzx ebx,word[size_y_var] - imul ecx,ebx - if Ext>=SSE2 - movd xmm0,eax - shufps xmm0,xmm0,0 - push ecx - mov ecx,edi - and edi,0xffffff00 - and ecx,0x000000ff - mov edx,ecx - rep stosd - pop ecx - sub ecx,edx - @@: - movaps [edi],xmm0 - movaps [edi+16],xmm0 - movaps [edi+32],xmm0 - movaps [edi+48],xmm0 - add edi,64 - sub ecx,16 - jnc @b - else - rep stosd - end if -ret - -read_tp_variables: ; read [triangles_count_var] and [points_count_var] - ; and allocate memory - xor ebx,ebx - xor ebp,ebp - mov [points_count_var],ebx - mov [triangles_count_var],ebx - if USE_LFN = 0 - mov esi,SourceFile - else - mov esi,[fptr] - end if - - cmp [esi],word 4D4Dh - je @f ;Must be legal .3DS file - xor eax,eax - ret - @@: - mov eax,dword[esi+2] - cmp eax,[fsize] ;This must tell the length - je @f - xor eax,eax - ret - @@: - add eax,esi - mov [EndFile],eax ; - - add esi,6 - @@: - cmp [esi],word 3D3Dh - je @f - add esi,[esi+2] - jmp @b - @@: - add esi,6 - .find4k: - cmp [esi],word 4000h - je @f - add esi,[esi+2] - cmp esi,[EndFile] - jc .find4k - jmp .exit - @@: - add esi,6 - @@: - cmp [esi],byte 0 - je @f - inc esi - jmp @b - @@: - inc esi - @@: - cmp [esi],word 4100h - je @f - add esi,[esi+2] - jmp @b - @@: - add esi,6 - @@: - cmp [esi],word 4110h - je @f - add esi,[esi+2] - jmp @b - @@: - movzx ecx,word[esi+6] - add [points_count_var],ecx - - mov edx,ecx - add esi,8 - @@: - - add ebx,6 - add esi,12 - ; dec ecx - loop @b - @@: - - @@: - cmp [esi],word 4120h - je @f - add esi,[esi+2] - jmp @b - @@: - movzx ecx,word[esi+6] - add [triangles_count_var],ecx - add esi,8 - - @@: - add esi,8 - dec ecx - jnz @b -; xor ecx,ecx - add ebp,edx - jmp .find4k - mov eax,-1 ;<---mark if OK - .exit: -ret - -read_from_file: - fninit - mov edi,[triangles_ptr] - xor ebx,ebx - xor ebp,ebp - mov [points_count_var],0 - mov [triangles_count_var],0 - if USE_LFN = 0 - mov esi,SourceFile - else - mov esi,[fptr] - end if - cmp [esi],word 4D4Dh - jne .exit ;Must be legal .3DS file -; cmp dword[esi+2],EndFile-SourceFile -; jne .exit ;This must tell the length - mov eax,dword[esi+2] - ; cmp eax,[fsize] - ; jne .exit - - add eax,esi - mov [EndFile],eax ; - - add esi,6 - @@: - cmp [esi],word 3D3Dh - je @f - add esi,[esi+2] - jmp @b - @@: - add esi,6 - .find4k: - cmp [esi],word 4000h - je @f - add esi,[esi+2] - cmp esi,[EndFile] - jc .find4k - jmp .exit - @@: - add esi,6 - @@: - cmp [esi],byte 0 - je @f - inc esi - jmp @b - @@: - inc esi - @@: - cmp [esi],word 4100h - je @f - add esi,[esi+2] - jmp @b - @@: - add esi,6 - @@: - cmp [esi],word 4110h - je @f - add esi,[esi+2] - jmp @b - @@: - movzx ecx,word[esi+6] - add [points_count_var],ecx - - mov edx,ecx - add esi,8 - @@: - push edi - mov edi,[points_ptr] - push dword[esi+0] - pop dword[edi+ebx*2+0] - push dword[esi+4] - pop dword[edi+ebx*2+4] - push dword[esi+8] - pop dword[edi+ebx*2+8] - pop edi - - add ebx,6 - add esi,12 - dec ecx - jnz @b - @@: - ; mov dword[points+ebx],-1 - push edi - mov edi,[points_ptr] - mov dword[edi+ebx*2],-1 ; end mark (not always in use) - pop edi - @@: - cmp [esi],word 4120h - je @f - add esi,[esi+2] - jmp @b - @@: - movzx ecx,word[esi+6] - add [triangles_count_var],ecx - add esi,8 - ;mov edi,triangles - @@: - movzx eax,word[esi] - add eax,ebp - stosd - movzx eax,word[esi+2] - add eax,ebp - stosd - movzx eax,word[esi+4] - add eax,ebp - stosd - ; add dword[edi-12],ebp - ; add dword[edi-8],ebp - ; add dword[edi-4],ebp - add esi,8 - dec ecx - jnz @b - add ebp,edx - jmp .find4k - mov eax,-1 ;<---mark if OK - .exit: - mov dword[edi],-1 -ret - -alloc_mem_for_tp: - mov eax, 68 - cmp [re_alloc_flag],1 - jz @f - mov ebx, 12 - jmp .alloc - @@: - mov ebx,20 - .alloc: - - mov ecx,[triangles_count_var] - add ecx,20 - lea ecx, [ecx*3] - shl ecx,2 - mov edx,[triangles_ptr] - int 0x40 ; -> allocate memory to triangles - mov [triangles_ptr], eax ; -> eax = pointer to allocated mem - - ; ststic memory - - mov eax, 68 - mov ecx, [triangles_count_var] - lea ecx, [3+ecx*3] - shl ecx, 2 - mov edx,[triangles_normals_ptr] - int 0x40 ; -> allocate memory for triangles normals - mov [triangles_normals_ptr], eax ; -> eax = pointer to allocated mem - - - mov eax, 68 - mov ecx, [points_count_var] - lea ecx,[3+ecx*3] - shl ecx, 2 - mov edx,[points_normals_ptr] - int 0x40 - mov [points_normals_ptr], eax - - - mov eax, 68 - ; mov ebx, 12 - mov ecx, [points_count_var] - lea ecx,[3+ecx*3] - shl ecx, 2 - mov edx,[points_normals_rot_ptr] - int 0x40 - mov [points_normals_rot_ptr], eax - - mov eax, 68 - mov edx,[points_ptr] - int 0x40 - mov [points_ptr], eax - - mov eax, 68 - mov edx,[points_rotated_ptr] - int 0x40 - mov [points_rotated_ptr], eax - - mov eax, 68 - mov ecx, [points_count_var] - inc ecx - shl ecx, 3 - mov edx,[points_translated_ptr] - int 0x40 - mov [points_translated_ptr], eax -ret - - - -read_from_disk: - mov eax, 68 - mov ebx, 11 - int 0x40 ; -> create heap - - ;load kpacked files by Leency - mov eax,68 - mov ebx,27 - mov ecx,file_name - int 0x40 - - mov [fsize],edx - mov [file_info+16],eax - - test eax,eax - jnz .open_opened_well - mov eax,6 ;otherwise => failed - jmp @f - .open_opened_well: - xor eax,eax - @@: - ; eax = 0 -> ok file loaded -ret - -read_param: - mov esi,I_Param - cmp dword[esi],0 - je .end - cmp byte[esi],'/' - je .copy - mov edi,esi - mov ecx,25 ; 25 - would be enought - repe scasb - jne .end - dec edi - mov esi,edi - .copy: - mov edi,file_name - mov ecx,50 - rep movsd - .end: -ret -buttons: ; draw some buttons (all but navigation and close ) - mov edi,menu - .again: - mov eax,8 ; function 8 : define and draw button - mov bx,[size_x_var] - shl ebx,16 - add ebx,(10)*65536+62 ; [x start] *65536 + [x size] - movzx ecx,byte[edi] ; button id = position+2 - sub cl,2 - lea ecx,[ecx*5] - lea ecx,[ecx*3] - add ecx,25 - shl ecx,16 - add ecx,12 - movzx edx,byte[edi] ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; BUTTON LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,byte[edi] - sub bl,2 ; button id, according to position - lea ebx,[ebx*3] - lea ebx,[ebx*5] - mov cx,[size_x_var] - shl ecx,16 - add ebx,ecx - add ebx,(12)*65536+28 ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - lea edx,[edi+1] ; pointer to text beginning - mov esi,10 ; text length - int 0x40 - cmp byte[edi+11],255 ; if max_flag=255 - je @f ; skip - ; flag description -; mov eax,4 ; function 4 : write text to window -; movzx ebx,byte[edi] -; sub bl,2 -; lea ebx,[ebx*3] -; lea ebx,[ebx*5] -; add ebx,(SIZE_X+12+70)*65536+28 ; [x start] *65536 + [y start] - add ebx,70*65536 -; mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - movzx edx,byte[edi+12] ; current flag - shl edx,2 ; * 4 = text length - add edx,dword[edi+13] ; pointer to text beginning - mov esi,4 ; text length - int 0x40 - - @@: - add edi,17 - cmp byte[edi],-1 - jnz .again -ret -; ********************************************* -; ******* WINDOW DEFINITIONS AND DRAW ******** -; ********************************************* - draw_window: - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,1 ; 1, start of draw - int 0x40 - - ; DRAW WINDOW - mov eax,0 ; function 0 : define and draw window - mov bx,[x_start] - shl ebx,16 - mov cx,[y_start] - shl ecx,16 -;ebx - [x start] *65536 + [x size] -;ecx - [y start] *65536 + [y size] - mov bx,[size_x_var] - add bx,115 - mov cx,[size_y_var] - add cx,30 - ; @@: - mov edx,0x13000000 ; color of work area RRGGBB,8->color gl - mov edi,labelt ; WINDOW LABEL - int 0x40 - - call buttons ; more buttons - - .Y_ADD equ 2 ;-> offset of 'add vector' buttons - - ; ADD VECTOR LABEL ; add vector buttons - 30 ++ - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(12)*65536+(168+15*(13+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelvector ; pointer to text beginning - mov esi,labelvectorend-labelvector ; text length - ; cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - int 0x40 - ; VECTOR Y- BUTTON - mov eax,8 ; function 8 : define and draw button - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,30*65536+20 ; [x start] *65536 + [x size] - mov ecx,(165+15*(14+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] - mov edx,30 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Y- LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(32)*65536+(168+15*(14+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelyminus ; pointer to text beginning - mov esi,labelyminusend-labelyminus ; text length - cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - int 0x40 - ; VECTOR Z+ BUTTON - mov eax,8 ; function 8 : define and draw button - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(51)*65536+21 ; [x start] *65536 + [x size] - mov ecx,(165+15*(14+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] - mov edx,31 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Z+ LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(53)*65536+(168+15*(14+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzplus ; pointer to text beginning - mov esi,labelzplusend-labelzplus ; text length - ; cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - - int 0x40 - ; VECTOR x- BUTTON - mov eax,8 ; function 8 : define and draw button - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(10)*65536+21 ; [x start] *65536 + [x size] - mov ecx,(165+15*(15+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] - mov edx,32 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR x- LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(12)*65536+(168+15*(15+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelxminus ; pointer to text beginning - mov esi,labelxminusend-labelxminus ; text length - ; cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - int 0x40 - ; VECTOR x+ BUTTON - mov eax,8 ; function 8 : define and draw button - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(51)*65536+21 ; [x start] *65536 + [x size] - mov ecx,(165+15*(15+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] - mov edx,33 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR x+ LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(53)*65536+(168+15*(15+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelxplus ; pointer to text beginning - mov esi,labelxplusend-labelxplus ; text length - ; cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - int 0x40 - ; VECTOR z- BUTTON - mov eax,8 ; function 8 : define and draw button - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+140+15*(16+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] - mov edx,34 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR z- LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(12)*65536+(168+15*(16+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzminus ; pointer to text beginning - mov esi,labelzminusend-labelzminus ; text length - ; cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - int 0x40 - ;VECTOR Y+ BUTTON - mov eax,8 ; function 8 : define and draw button - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(10+20)*65536+20 ; [x start] *65536 + [x size] - mov ecx,(165+15*(16+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] - mov edx,35 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Y+ LABEL - mov eax,4 ; function 4 : write text to window - movzx ebx,word[size_x_var] - shl ebx,16 - add ebx,(32)*65536+(168+15*(16+.Y_ADD)) ; [x start] *65536 + [y start] - mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelyplus ; pointer to text beginning - mov esi,labelyplusend-labelyplus ; text length - ; cmp [move_flag],2 - ; jne @f - ; add edx,navigation_size - ; @@: - int 0x40 - - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw - int 0x40 - ret - - - ; DATA AREA ************************************ - - include 'data.inc' - align 16 -MEM_END: + +; application : View3ds ver. 0.071 - tiny .3ds and .asc files viewer +; with a few graphics effects demonstration. +; compiler : FASM +; system : KolibriOS +; author : Macgub aka Maciej Guba +; email : macgub3@wp.pl +; web : http://macgub.co.pl, http://macgub.j.pl +; Fell free to use this intro in your own distribution of KolibriOS. +; Special greetings to KolibriOS team . +; I hope because my demos Christian Belive will be near to each of You. + + +; Some adjustments made by Madis Kalme +; madis.kalme@mail.ee +; I tried optimizing it a bit, but don't know if it was successful. The objects +; can be: +; 1) Read from a file (*.3DS standard) +; 2) Written in manually (at the end of the code) ; now not exist + + +SIZE_X equ 512 +SIZE_Y equ 512 ; ///// I want definitely +TIMEOUT equ 10 ; ------ say: +ROUND equ 10 ; \ @ @/ keep smiling every +TEX_X equ 512 ; texture width ; \ ./ / day. +TEX_Y equ 512 ; height ; \/ / +TEX_SHIFT equ 9 ; texture width shifting ; __||__ / +TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 ; /| | +TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} ; / \ / +FLUENTLY = 0 ; / | | +SHIFTING = 1 ; ------ +CATMULL_SHIFT equ 8 ; | | +LIGHT_SIZE equ 22 ; | | +NON = 0 ; -/ \- +MMX = 1 +SSE = 2 +SSE2 = 3 +SSE3 = 4 +Ext = SSE3 ;Ext={ NON | MMX | SSE | SSE2 | SSE3 } + +; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features) +USE_LFN = 1 ; App is Kolibri only now. + +use32 + org 0x0 + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd START ; start of code + dd I_END ; size of image + dd MEM_END ; memory for app + dd MEM_END ; esp + dd I_Param ; I_Param + dd 0x0 ; I_Icon + +START: ; start of execution + cld + push dword (SIZE_Y shr 3) * 3 + fninit + fild dword[esp] + fstp [rsscale] + pop ebx + + call alloc_buffer_mem + call read_param + call read_from_disk ; read, if all is ok eax = 0 + cmp eax,0 + jne .gen + mov esi,[fptr] + cmp [esi],word 4D4Dh + jne .asc + call read_tp_variables ; init points and triangles count variables + cmp eax,0 + je .gen + jmp .malloc + .gen: + call generate_object + jmp .opt + .asc: + mov [triangles_count_var],10000 ; to do: read asc header + mov [points_count_var],10000 + call alloc_mem_for_tp + call read_asc + jmp .opt + .malloc: + call alloc_mem_for_tp + call read_from_file + .opt: + call optimize_object1 ; proc in file b_procs.asm + ; set point(0,0,0) in center and calc all coords + ; to be in <-1.0,1.0> + call normalize_all_light_vectors + if Ext >= SSE3 + call copy_lights ; to aligned float + end if + call init_triangles_normals2 + call init_point_normals + call init_envmap2 + call init_envmap_cub + call generate_texture2 + call init_sincos_tab + call do_color_buffer ; intit color_map + mov edi,bumpmap + call calc_bumpmap + call calc_bumpmap_coords ; bump and texture mapping + call do_edges_list + call draw_window + ;mov [draw_win_at_first],0 + ;mov eax,40 ; set events mask + ;mov ebx,1100000000000000000000000100111b + ;int 0x40 + + +still: + cmp [edit_flag],1 + jne @f + mov eax,40 ; set events mask + mov ebx,1100000000000000000000000100111b + jmp .int + @@: + mov eax,40 ; set events mask + mov ebx,111b + .int: + int 0x40 + + mov eax,23 + mov ebx,TIMEOUT + cmp [speed_flag],0 + je .skip + mov eax,11 + .skip: + cmp [edit_flag],1 + jne @f + mov eax,10 + + @@: + int 0x40 + + cmp eax,1 ; redraw event ? + je red + cmp eax,2 ; key event ? + je key + cmp eax,3 ; button event ? + je button + cmp eax,6 ; mouse event ? + jne @f + cmp [edit_flag],1 ; handle mouse only when edit is active + jne @f + + mov eax,37 + mov ebx,7 ; get mouse scroll + int 0x40 + and eax, 0xFFFF ; check only vertial + cmp eax, 65535 + je button.zoom_in + cmp eax, 1 + je button.zoom_out + + mov eax,37 + mov ebx,3 ;read mouse state + int 0x40 + mov [mouse_state],eax + call edit + @@: + jmp noclose + + red: ; redraw + mov eax,9 ; get process info + mov ebx,procinfo + mov ecx,-1 + int 0x40 + mov eax,[procinfo+42] ; read params of window + sub eax,225 + mov [size_x_var],ax + shr ax,1 + mov [vect_x],ax +; + mov eax,[procinfo+46] + sub eax,30 + mov [size_y_var],ax + shr ax,1 + mov [vect_y],ax + + mov eax,[procinfo+34] + mov [x_start],ax + mov eax,[procinfo+38] + mov [y_start],ax + call alloc_buffer_mem ;realloc mem for scr & z buffs + call draw_window + + jmp noclose + + key: ; key + mov eax,2 ; just read it and ignore + int 0x40 + + cmp ah, '+' + je button.zoom_in + cmp ah, '=' + je button.zoom_in + cmp ah, '-' + je button.zoom_out + cmp ah, 176 ;left + je add_vec_buttons.x_minus + cmp ah, 179 ;right + je add_vec_buttons.x_plus + cmp ah, 178 ;up + je add_vec_buttons.y_minus + cmp ah, 177 ;down + je add_vec_buttons.y_plus + + jmp noclose + + button: ; button + mov eax,17 ; get id + int 0x40 + + cmp ah,1 ; button id=1 ? + jne @f + + mov eax,-1 ; close this program + int 0x40 + @@: + cmp ah,30 + jge add_vec_buttons + call update_flags ; update flags and write labels of flags + + ; do other operations according to flag + cmp ah,3 ; ah = 3 -> shading model + jne .next_m6 + cmp [dr_flag],2 + jne @f + ; call init_envmap2 ; <----! this don't works in env mode + ; and more than ~18 kb objects + ; call init_envmap_cub2 + @@: + cmp [dr_flag],4 + jne @f + call generate_texture2 + + @@: + .next_m6: + ; ah = 5 -> scale- + cmp ah,5 + jne @f + .zoom_out: + mov dword[scale],0.7 + fninit + fld [rsscale] + fmul [scale] + fstp [rsscale] + @@: + cmp ah,6 ; ah = 6 -> scale+ + jne @f + .zoom_in: + mov dword[scale],1.3 + fninit + fld [rsscale] + fmul [scale] + fstp [rsscale] + @@: + cmp ah,9 ; lights random ; 'flat' 0 + jne .next_m5 ; 'grd ' 1 + call make_random_lights ; 'env ' 2 + call normalize_all_light_vectors ; 'bump' 3 + if Ext >= SSE3 + call copy_lights + end if + call do_color_buffer ; intit color_map ; 'tex ' 4 + + call init_envmap2 ; update env map if shading model = environment or bump + .next_m5: + cmp ah,11 + je @f + cmp ah,12 + je @f + cmp ah,13 + jne .next_m4 + @@: + call mirror + .next_m4: + cmp ah,14 + jne @f + call exchange + @@: + cmp ah,15 + jne @f + cmp [emboss_flag],1 + ; call init_envmap2 + call do_emboss + @@: +; cmp ah,17 +; jne .next_m +; cmp [move_flag],2 +; jne @f +; call draw_window ; redraw other labels to navigation buttons +; @@: +; cmp [move_flag],0 +; jne .next_m +; call draw_window ; redraw other labels to navigation buttons + .next_m: + cmp ah,18 + jne .next_m2 + + mov [re_alloc_flag],1 ; reallocate memory + mov [triangles_count_var],20000 + mov [points_count_var],20000 + call alloc_mem_for_tp + mov [re_alloc_flag],0 + + mov bl,[generator_flag] + ; or bl,bl + ; jz .next_m2 + cmp bl,1 + jne @f + call generate_object + jmp .calc_norm + @@: + cmp bl,4 + jg @f + movzx eax,bl ; eax < - object number + call generate_object2 + jmp .calc_norm + @@: + call generate_object3 + .calc_norm: + call optimize_object1 + call init_triangles_normals2 + call init_point_normals + call calc_bumpmap_coords ; bump and texture mapping + call do_edges_list + call write_info + .next_m2: + cmp ah,19 + je @f + cmp ah,20 + jne .next_m3 + @@: + mov edi,bumpmap + call calc_bumpmap + .next_m3: + cmp ah,21 ; re map bumps, texture coordinates + jne @f + call calc_bumpmap_coords + @@: + jmp noclose + + + ; there are 6 navigation buttons each + add_vec_buttons: ; can move: object, camera,.. list is open + ; + cmp ah,30 + jne .next + cmp [move_flag],0 + jne @f +; cmp [move_flag],2 +; je .set_light1 + .y_minus: + sub [vect_y],10 + jmp .next + @@: + cmp [move_flag],1 + jne @f + sub [yobs],10 ; observator = camera position + jmp .next + @@: + sub [sin_amplitude],10 +;-------------------------------------------------- +; .set_light1: ; r - +; movzx ebx,[light_no_flag] ; * 22 +; mov ecx,ebx +; shl ebx,4 +; shl ecx,1 +; add ebx,ecx +; shl ecx,1 +; add ebx,ecx +; add ebx,lights+6 ; 6 -> light vector size +; +; movzx ecx,[light_comp_flag] +; lea ecx,[ecx*3} +; add ebx,ecx ; ebx -> color to set + +;--------------------------------------------------- + .next: + cmp ah,31 + jne .next1 + cmp [move_flag],1 + je @f + add [vect_z],10 + jmp .next1 + @@: + add [zobs],10 ; observator = camera position + .next1: + cmp ah,33 + jne .next2 + cmp [move_flag],0 + jne @f + .x_minus: + sub [vect_x],10 + jmp .next2 + @@: + cmp [move_flag],1 + jne @f + sub [xobs],10 ; observator = camera position + jmp .next2 + @@: + fninit + fld [sin_frq] + fsub [sin_delta] + fstp [sin_frq] + .next2: + cmp ah,32 + jne .next3 + cmp [move_flag],0 + jne @f + .x_plus: + add [vect_x],10 + jmp .next3 + @@: + cmp [move_flag],1 + jne @f + add [xobs],10 ; observator = camera position + jmp .next3 + @@: + fninit + fld [sin_frq] ; change wave effect frequency + fadd [sin_delta] + fstp [sin_frq] + .next3: + cmp ah,34 + jne .next4 + cmp [move_flag],1 + je @f + + sub [vect_z],10 + jmp .next4 + @@: + sub [zobs],10 ; observator = camera position + .next4: + cmp ah,35 + jne .next5 + cmp [move_flag],0 + jne @f + ; call add_vector + .y_plus: + add [vect_y],10 + jmp .next5 + @@: + cmp [move_flag],1 + jne @f + add [yobs],10 ; observator = camera position + jmp .next5 + @@: + add [sin_amplitude],10 + .next5: + + + + noclose: + + cmp [edit_flag],1 + jz .end_rot + cmp [r_flag],2 + jne .no_x + inc [angle_x] + and [angle_x],0xff + mov [angle_z],0 + jmp .end_rot + + .no_x: + cmp [r_flag],0 + jne .no_y + inc [angle_y] + and [angle_y],0xff + mov [angle_z],0 + jmp .end_rot + + .no_y: + cmp [r_flag],1 + jne .end_rot + mov cx,[angle_x] + inc cx + and cx,0xff + mov [angle_z],0 + mov [angle_y],cx + mov [angle_x],cx + .end_rot: + + mov esi,angle_x + mov edi,matrix + call make_rotation_matrix + RDTSC + push eax + mov esi,[points_normals_ptr] + mov edi,[points_normals_rot_ptr] + mov ebx,matrix + mov ecx,[points_count_var] + call rotary + + mov esi,matrix + call add_scale_to_matrix + + mov esi,[points_ptr] + mov edi,[points_rotated_ptr] + mov ebx,matrix + mov ecx,[points_count_var] + call rotary + + + mov esi,[points_rotated_ptr] + mov edi,[points_translated_ptr] + mov ecx,[points_count_var] + call translate_points + + cmp [fire_flag],0 + jne @f + call clrscr ; clear the screen + @@: + ; cmp [catmull_flag],1 ;non sort if Catmull = on + ; je .no_sort + ; 64 indexes call sort_triangles + .no_sort: + cmp [dr_flag],7 ; fill if 2tex and texgrd + jge @f + cmp [catmull_flag],0 ;non fill if Catmull = off + je .non_f + cmp [dr_flag],6 ; non fill if dots + je .non_f + @@: + call fill_Z_buffer ; make background + .non_f: + cmp [dr_flag],6 + jne @f + call draw_dots + jmp .blurrr + @@: + call draw_triangles ; draw all triangles from the list + cmp [edit_flag],0 + jz .no_edit + call clear_vertices_index + call draw_handlers + ; call edit + + + + + + + .no_edit: + + .blurrr: + cmp [sinus_flag],0 + je @f + call do_sinus + @@: + cmp [fire_flag],0 + jne @f + cmp [blur_flag],0 + je .no_blur ; no blur, no fire + movzx ecx,[blur_flag] + call blur_screen ; blur and fire + jmp .no_blur + @@: + cmp [emboss_flag],0 + jne .emb ; if emboss=true -> no fire + movzx ecx,[fire_flag] + call blur_screen ; blur and fire + .no_blur: ; no blur, no fire + cmp [emboss_flag],0 + je @f + .emb: + call do_emboss + + @@: + + + cmp [inc_bright_flag],0 ; increase brightness + je .no_inc_bright + movzx ebx,[inc_bright_flag] + shl ebx,4 + mov esi,[screen_ptr] + movzx ecx,word[size_y_var] + movzx eax,word[size_x_var] + mul ecx + lea ecx,[eax*4] + +if (Ext = MMX)|(Ext = SSE) + mov bh,bl + push bx + shl ebx,16 + pop bx + push ebx + push ebx + movq mm0,[esp] + add esp,8 +else if Ext >= SSE2 + mov bh,bl + push bx + shl ebx,16 + pop bx + movd xmm0,ebx + shufps xmm0,xmm0,0 +end if + .oop: +if Ext=NON + lodsb + add al,bl + jnc @f + mov byte[esi-1],255 + loop .oop + @@: + mov [esi-1],al + loop .oop +else if (Ext=MMX)|(Ext=SSE) + movq mm1,[esi] + movq mm2,[esi+8] + paddusb mm1,mm0 + paddusb mm2,mm0 + movq [esi],mm1 + movq [esi+8],mm2 + add esi,16 + sub ecx,16 + jnz .oop +else + movaps xmm1,[esi] + paddusb xmm1,xmm0 + movaps [esi],xmm1 + add esi,16 + sub ecx,16 + jnc .oop +end if + +.no_inc_bright: + + + cmp [dec_bright_flag],0 + je .no_dec_bright + movzx ebx,[dec_bright_flag] + shl ebx,4 + mov esi,[screen_ptr] + movzx eax,word[size_x_var] + movzx ecx,word[size_y_var] + mul ecx + lea ecx,[eax*4] + if (Ext = MMX)|(Ext = SSE) + mov bh,bl + push bx + shl ebx,16 + pop bx + push ebx + push ebx + movq mm0,[esp] + add esp,8 +else if Ext >=SSE2 + mov bh,bl + push bx + shl ebx,16 + pop bx + movd xmm0,ebx + shufps xmm0,xmm0,0 +end if + .oop1: +if Ext=NON + lodsb + sub al,bl + jb @f + mov [esi-1],al + loop .oop1 + @@: + mov byte[esi-1],0 + loop .oop1 +else if (Ext = MMX)|(Ext=SSE) + movq mm1,[esi] + psubusb mm1,mm0 + movq [esi],mm1 + add esi,8 + sub ecx,8 + jnz .oop1 +else + movaps xmm1,[esi] + psubusb xmm1,xmm0 + movaps [esi],xmm1 + add esi,16 + sub ecx,16 + jnc .oop1 +end if + .no_dec_bright: + + + RDTSC + sub eax,[esp] + sub eax,41 +; pop eax + + mov ecx,10 + .dc: + xor edx,edx + mov edi,10 + div edi + add dl,30h + mov [STRdata+ecx-1],dl + loop .dc + pop eax + + + mov eax,7 ; put image + mov ebx,[screen_ptr] + mov ecx,[size_y_var] + mov edx,[offset_y] + cmp [dr_flag],11 + jge .ff + int 0x40 + jmp .f + .ff: + mov eax,65 + mov esi,32 + xor ebp,ebp + int 0x40 + .f: + mov eax,13 + mov bx,[size_x_var] + add ebx,18 + shl ebx,16 + mov bx,60 + mov cx,[size_y_var] + sub cx,2 + shl ecx,16 + mov cx,9 + xor edx,edx + int 40h + + mov eax,4 ; function 4 : write text to window + mov bx,[size_x_var] + add ebx,18 + shl ebx,16 + mov bx,[size_y_var] + sub bx,2 ; [x start] *65536 + [y start] + mov ecx,0x00888888 + mov edx,STRdata ; pointer to text beginning + mov esi,10 ; text length + int 40h + + + + jmp still + +;-------------------------------------------------------------------------------- +;-------------------------PROCEDURES--------------------------------------------- +;-------------------------------------------------------------------------------- +include "flat_cat.inc" +include "tex_cat.inc" +include "bump_cat.inc" +include "3dmath.inc" +include "grd_line.inc" +include "b_procs.inc" +include "a_procs.inc" +include "grd_cat.inc" +include "bump_tex.inc" +include "grd_tex.inc" +include "two_tex.inc" +include "asc.inc" +if Ext >= SSE3 +include "3r_phg.inc" +include '3stencil.inc' +include '3glass.inc' +include '3glass_tex.inc' +end if +clear_vertices_index: + mov edi,[vertices_index_ptr] + movzx eax,word[size_x_var] + movzx ecx,word[size_y_var] + imul ecx,eax + xor eax,eax + shr ecx,1 + rep stosd +ret +edit: ; mmx required, edit mesh by vertex + push ebp + mov ebp,esp + sub esp,128 + + .y_coord equ ebp-2 + .x_coord equ ebp-4 + .points_translated equ ebp-10 + .points equ ebp-22 + .points_rotated equ ebp-34 + .mx equ ebp-70 + + macro check_bar + { + movzx ebx,word[.x_coord] + movzx ecx,word[.y_coord] + movzx edx,word[size_x_var] + imul edx,ecx + add ebx,edx + push ebx + lea ecx,[ebx*2] + lea ebx,[ebx*3] + + cmp [dr_flag],12 + jl @f + add ebx,[esp] + @@: + add esp,4 + add ebx,[screen_ptr] + mov ebx,[ebx] + and ebx,0x00ffffff + cmp ebx,0x00ff0000 ; is handle bar ? + } + + emms + mov eax,37 ; get mouse state + mov ebx,1 ; x = 5, y = 25 - offsets + int 0x40 + + mov ebx,[offset_y] ;5 shl 16 + 25 + movd mm0,ebx + movd mm1,eax + movd mm3,[size_y_var] + pcmpgtw mm0,mm1 + pcmpgtw mm3,mm1 + pxor mm3,mm0 + movd eax,mm3 + mov cx,ax + shr eax,16 + and ax,cx + or ax,ax + jz .no_edit + + + movd mm0,ebx + psubw mm1,mm0 + movd eax,mm1 + + ; store both x and y coordinates + ror eax,16 + ; push eax + ; sub esp,256 + mov [.x_coord],eax + test word[mouse_state],100000000b + jz .not_press ; check if left mouse button press + + ; left button pressed + + + check_bar + jne .no_edit + add ecx,[vertices_index_ptr] + mov cx,word[ecx] + inc cx + + + mov [vertex_edit_no],cx ;if vert_edit_no = 0, no vertex selected + + mov eax,dword[.x_coord] + mov dword[edit_end_x],eax + mov dword[edit_start_x],eax + jmp .end + .not_press: + test byte[mouse_state],1b ; check if left button is held + jz .not_held + ; check_bar + ; jne .no_edit + ; add ecx,[vertices_index_ptr] + ; mov cx,[ecx] + ; inc cx + cmp [vertex_edit_no],0 ; cx ; vertex number + je .end + push dword[.x_coord] + pop dword[edit_end_x] + jmp .end + .not_held: + shr [mouse_state],16 + test byte[mouse_state],1b ; test if left button released + jz .end + check_bar + jne .end + + movzx esi,[vertex_edit_no] + dec esi + lea esi,[esi*3] + add esi,esi + add esi,[points_translated_ptr] + emms + + movd mm1,dword[esi] + paddw mm1,mm0 + psubw mm1,qword[vect_x] + movd dword[esi],mm1 + + lea edi,[.points] + ; detranslate + fninit + fild word[esi+4] + fstp dword[edi+8] + fild word[esi+2] + fisub word[offset_x] + fstp dword[edi+4] + fild word[esi] + fisub word[offset_y] ; proteza + fstp dword[edi] + + mov esi,matrix + lea edi,[.mx] + call reverse_mx_3x3 + + lea esi,[.points] + lea edi,[.points_rotated] + lea ebx,[.mx] + mov ecx,1 + call rotary + + ; inject into vertex list + movzx edi,[vertex_edit_no] + dec edi + lea edi,[edi*3] + shl edi,2 + add edi,[points_ptr] + lea esi,[.points_rotated] + cld + movsd + movsd + movsd + ; mov ecx,3 + ; cld + ; rep movsd + + + mov dword[edit_end_x],0 + mov [vertex_edit_no],0 + + .no_edit: + .end: + mov esp,ebp + pop ebp +ret + +alloc_buffer_mem: + push ebp + mov ebp,esp + .temp equ ebp-4 + push dword 0 + + mov eax, 68 + mov ebx, 11 + int 0x40 ; -> create heap, to be sure + + + movzx ecx,word[size_x_var] + movzx eax,word[size_y_var] + mul ecx + + mov [.temp],eax + lea ecx,[eax*4] ; more mem for r_phg cause + add ecx,256 + mov eax,68 + mov ebx,20 + mov edx,[screen_ptr] + int 0x40 + mov [screen_ptr],eax + + mov ecx,[.temp] + shl ecx,2 + add ecx,256 + mov eax,68 + mov ebx,20 + mov edx,[Zbuffer_ptr] + int 0x40 + mov [Zbuffer_ptr],eax + + + mov ecx,[.temp] + add ecx,ecx + add ecx,256 + mov eax,68 + mov ebx,20 + mov edx,[vertices_index_ptr] + int 0x40 + mov [vertices_index_ptr],eax + + mov esp,ebp + pop ebp + + + + +update_flags: +; updates flags and writing flag description +; in ah - button number + push ax + mov edi,menu + .ch_another: + cmp ah,byte[edi] ; ah = button id + jne @f + mov bl,byte[edi+11] ; max_flag + 1 + cmp bl,255 + je .no_write + inc byte[edi+12] ; flag + cmp byte[edi+12],bl + jne .write + mov byte[edi+12],0 + jmp .write + @@: + add edi,17 + cmp byte[edi],-1 + jne .ch_another + jmp .no_write + .write: +; clreol {pascal never dies} +; * eax = 13 - function number +; * ebx = [coordinate on axis x]*65536 + [size on axis x] +; * ecx = [coordinate on axis y]*65536 + [size on axis y] +; * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill + + mov eax,13 ; function 13 write rectangle + movzx ecx,byte[edi] + sub cl,2 + lea ecx,[ecx*3] + lea ecx,[ecx*5] + add ecx,28 + shl ecx,16 + add ecx,14 ; ecx = [coord y]*65536 + [size y] + mov bx,[size_x_var] + shl ebx,16 + add ebx,(12+70)*65536+25 ; [x start] *65536 + [size x] + mov edx,0x00000000 ; color 0x00RRGGBB + int 0x40 + + mov eax,4 ; function 4 : write text to window + movzx ebx,byte[edi] + sub bl,2 + lea ebx,[ebx*3] + lea ebx,[ebx*5] + mov cx,[size_x_var] + shl ecx,16 + add ebx,ecx + add ebx,(12+70)*65536+28 ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + movzx edx,byte[edi+12] ; current flag + shl edx,2 ; * 4 = text length + add edx,dword[edi+13] ; pointer to text beginning + mov esi,4 ; text length - + ; flag description 4 characters + int 0x40 + + .no_write: + pop ax +ret +normalize_all_light_vectors: + mov edi,lights + @@: + call normalize_vector ; 3dmath.inc + add edi,LIGHT_SIZE + cmp edi,lightsend ;ecx + jl @b +ret + +calc_bumpmap_coords: ; map texture, bump +;macro .comment222 +; ; planar mapping +; mov esi,points +; mov edi,tex_points +; @@: +; add esi,2 +; movsd +; cmp dword[esi],dword -1 +; jne @b + +; .Pi2 equ dword[ebp-4] + +; mov ebp,esp +; sub esp,4 + + fninit + fldpi + fadd st,st + mov esi,[points_ptr] + mov edi,tex_points + mov ecx,[points_count_var] + inc ecx +; cmp [map_tex_flag],1 +; jne .cylindric + ; spherical mapping around y axle + + @@: + fld dword[esi] ; x coord + fld dword[esi+8] ; z coord + fpatan ; arctg(st1/st) +; fdiv .Pi2 + fdiv st0,st1 + fimul [tex_x_div2] + fiadd [tex_x_div2] + fistp word[edi] ; x + + fld dword[esi+4] ; y coord + fld dword[esi] ; x + fmul st,st0 + fld dword[esi+4] ; y + fmul st,st0 + fld dword[esi+8] ; z + fmul st,st0 + faddp + faddp + fsqrt + fpatan + fldpi + fdivp + fimul [tex_y_div2] + fiadd [tex_y_div2] + fistp word[edi+2] ; y + + add esi,12 + add edi,4 + loop @b + ffree st0 +; jmp .end_map +; .cylindric: +; fld dword[esi] ; around y axle +; fld dword[esi+8] +; fpatan +; fdiv st0,st1 +; fimul [tex_x_div2] +; fiadd [tex_x_div2] +; fistp word[edi] + +; fld dword[esi+4] +; fimul [tex_y_div2] +; fiadd [tex_y_div2] +; fistp word[edi+2] + +; add esi,12 +; add edi,4 +; loop .cylindric +; ffree st0 +;; mov esp,ebp +; .end_map: +ret + + +init_envmap2: ; do env_map using many light sources +;env_map 512 x 512 x 3 bytes +.temp equ word [ebp-2] +.nEy equ word [ebp-4] +.nEx equ word [ebp-6] +.col_r equ [ebp-8] +.col_g equ [ebp-9] +.col_b equ [ebp-10] + + push ebp + mov ebp,esp + sub esp,20 + mov edi,envmap + fninit + + mov dx,- TEX_Y / 2 ;256 ; dx - vertical coordinate = y + .ie_ver: + mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x + .ie_hor: + xor ebx,ebx + mov dword .col_b, 0 + .light: + lea esi,[lights+ebx] + fld dword[esi] ; light vector x cooficient + fimul [tex_x_div2] ;[i256] + mov .temp,cx + fisubr .temp + fistp .nEx + fld dword[esi+4] ; light vector y cooficient + fimul [tex_y_div2] ;[i256] + mov .temp,dx + fisubr .temp + fistp .nEy + + cmp .nEx,- TEX_X / 2 ;256 + jl .update_counters + cmp .nEy,- TEX_Y / 2 ;256 + jl .update_counters + cmp .nEx,TEX_X / 2 ;256 + jg .update_counters + cmp .nEy,TEX_Y / 2 ;256 + jg .update_counters + + fild .nEx + fmul st,st0 + fild .nEy + fmul st,st0 + faddp + fsqrt + fisubr [i256] + fmul [env_const] + fidiv [i256] ; st - 'virtual' dot product + + fcom [dot_max] + fstsw ax + sahf + jb @f + ffree st + fld1 ;[dot_max] + @@: + fcom [dot_min] + fstsw ax + sahf + ja @f + ffree st + fldz ;[dot_min] + @@: + push ebp + movzx ax,byte[esi+21] + push ax ;- shines + mov al,byte[esi+14] ; b orginal color + push ax + mov al,byte[esi+13] ; g + push ax + mov al,byte[esi+12] ; r + push ax + mov al,byte[esi+20] ; b max color + push ax + mov al,byte[esi+19] ; g + push ax + mov al,byte[esi+18] ; r + push ax + mov al,byte[esi+17] ; b min col + push ax + mov al,byte[esi+16] ; g + push ax + mov al,byte[esi+15] ; r + push ax + push eax ; earlier - dot pr + ; fstp .dot_product + ; push .dot_product + call calc_one_col + pop ebp + ; eax-0x00rrggbb + cmp al,.col_b + jbe @f + mov .col_b,al + @@: ; eax - ggbb00rr + shr ax,8 + cmp al,.col_g + jbe @f + mov .col_g,al + @@: ; eax - bb0000gg + shr eax,16 + cmp al,.col_r + jbe @f + mov .col_r,al + @@: + .update_counters: ; update and jump when neccesery + add ebx,LIGHT_SIZE + cmp bx,[all_lights_size] + jl .light ; next_light + mov eax,dword .col_b + stosd + dec edi + + inc cx + cmp cx,TEX_X / 2 ;256 + jne .ie_hor + + inc dx + cmp dx,TEX_Y / 2 ;256 + jne .ie_ver + + mov esp,ebp + pop ebp +ret + + + +do_color_buffer: ; do color buffer for Gouraud, flat shading +;env_map 512 x 512 x 3 bytes ; many lights using +.temp equ word [ebp-2] +.nz equ dword [ebp-6] ; dword +.ny equ dword [ebp-10] +.nx equ dword [ebp-14] +.col_r equ [ebp-16] +.col_g equ [ebp-17] +.col_b equ [ebp-18] + + push ebp + mov ebp,esp + sub esp,20 + mov edi,color_map + fninit + + mov dx,- TEX_Y / 2 ;-256 ; dx - vertical coordinate = y + .ie_ver: + mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x + .ie_hor: + mov .temp,cx + fild .temp + fidiv [i256] ;st = Nx - vector normal x cooficient + fst .nx + fmul st,st0 + mov .temp,dx + fild .temp + fidiv [i256] ; st = Ny - vector normal y coeficient + fst .ny + fmul st,st0 + faddp + fld1 + fchs + faddp + fabs + fsqrt + fchs + fstp .nz ; st - Nz - vect normal z coeficient + xor ebx,ebx + mov dword .col_b, 0 + .light: + push edi ;env_map + lea esi,[lights+ebx] + lea edi,.nx + call dot_product + pop edi + fcom [dot_min] + fstsw ax + sahf + ja .env_ok1 ;compare with dot_max + ffree st + + jmp .update_counters + .env_ok1: + fcom [dot_max] + fstsw ax + sahf + jb .env_ok2 ; calc col + ffree st + jmp .update_counters + .env_ok2: ;calc col + push ebp + movzx ax,byte[esi+21] + push ax ;- shines + mov al,byte[esi+14] ; b orginal color + push ax + mov al,byte[esi+13] ; g + push ax + mov al,byte[esi+12] ; r + push ax + mov al,byte[esi+20] ; b max color + push ax + mov al,byte[esi+19] ; g + push ax + mov al,byte[esi+18] ; r + push ax + mov al,byte[esi+17] ; b min col + push ax + mov al,byte[esi+16] ; g + push ax + mov al,byte[esi+15] ; r + push ax + push eax ; earlier - dot pr + ; fstp .dot_product + ; push .dot_product + call calc_one_col + pop ebp + ; eax-0x00rrggbb + cmp al,.col_b + jbe @f + mov .col_b,al + @@: + shr ax,8 + cmp al,.col_g + jbe @f + mov .col_g,al + @@: + shr eax,16 + cmp al,.col_r + jbe @f + mov .col_r,al + @@: + .update_counters: ; update and jump when neccesery + add ebx,LIGHT_SIZE + cmp bx,[all_lights_size] + jl .light ; next_light + mov eax,dword .col_b + stosd + dec edi + + inc cx + cmp cx,TEX_X / 2 ;256 + jne .ie_hor + + inc dx + cmp dx,TEX_X / 2 ;256 + jne .ie_ver + + .env_done: + mov esp,ebp + pop ebp +ret +if Ext >= SSE3 +init_point_normals: +.z equ dword [ebp-8] +.y equ dword [ebp-12] +.x equ [ebp-16] +.point_number equ dword [ebp-28] +.hit_faces equ dword [ebp-32] + + fninit + push ebp + mov ebp,esp + sub esp,64 + and ebp,-16 + mov edi,[points_normals_ptr] + mov .point_number,0 + .ipn_loop: + movd xmm0,.point_number + pshufd xmm0,xmm0,0 + mov .hit_faces,0 + mov .x,dword 0 + mov .y,0 + mov .z,0 + mov esi,[triangles_ptr] + xor ecx,ecx ; ecx - triangle number + .ipn_check_face: + movdqu xmm1,[esi] + pcmpeqd xmm1,xmm0 + pmovmskb eax,xmm1 + and eax,0xfff + or eax,eax + jz .ipn_next_face + push esi + mov esi,ecx + lea esi,[esi*3] + shl esi,2 + add esi,[triangles_normals_ptr] + movups xmm7,[esi] + addps xmm7,.x + movaps .x,xmm7 + pop esi + inc .hit_faces + + .ipn_next_face: + add esi,12 + inc ecx + cmp ecx,[triangles_count_var] + jne .ipn_check_face + cvtsi2ss xmm6,.hit_faces + movaps xmm7,.x + rcpss xmm6,xmm6 + shufps xmm6,xmm6,11000000b + mulps xmm7,xmm6 + movaps xmm6,xmm7 + mulps xmm6,xmm6 + andps xmm6,[zero_hgst_dd] + haddps xmm6,xmm6 + haddps xmm6,xmm6 + rsqrtps xmm6,xmm6 + mulps xmm7,xmm6 + movlps [edi],xmm7 + movhlps xmm7,xmm7 + movss [edi+8],xmm7 + add edi,12 + inc .point_number + mov edx,.point_number + cmp edx,[points_count_var] + jne .ipn_loop + + add esp,64 + pop ebp +ret +else +init_point_normals: +.x equ dword [ebp-4] +.y equ dword [ebp-8] +.z equ dword [ebp-12] +.point_number equ dword [ebp-28] +.hit_faces equ dword [ebp-32] + + fninit + mov ebp,esp + sub esp,32 + mov edi,[points_normals_ptr] + mov .point_number,0 + .ipn_loop: + mov .hit_faces,0 + mov .x,0 + mov .y,0 + mov .z,0 + mov esi,[triangles_ptr] + xor ecx,ecx ; ecx - triangle number + .ipn_check_face: + xor ebx,ebx ; ebx - 'position' in one triangle + .ipn_check_vertex: + mov eax,dword[esi+ebx] ; eax - point_number + cmp eax,.point_number + jne .ipn_next_vertex + push esi + mov esi,ecx + lea esi,[esi*3] + ; lea esi,[triangles_normals+esi*4] + shl esi,2 + add esi,[triangles_normals_ptr] + + fld .x + fadd dword[esi+vec_x] ; vec_x this defined in 3dmath.asm - x cooficient + fstp .x ; of normal vactor + fld .y + fadd dword[esi+vec_y] + fstp .y + fld .z + fadd dword[esi+vec_z] + fstp .z + pop esi + inc .hit_faces + jmp .ipn_next_face + .ipn_next_vertex: + add ebx,4 + cmp ebx,12 + jne .ipn_check_vertex + .ipn_next_face: + add esi,12 + inc ecx + cmp ecx,[triangles_count_var] + jne .ipn_check_face + + fld .x + fidiv .hit_faces + fstp dword[edi+vec_x] + fld .y + fidiv .hit_faces + fstp dword[edi+vec_y] + fld .z + fidiv .hit_faces + fstp dword[edi+vec_z] + call normalize_vector + add edi,12 ;type vector 3d + inc .point_number + mov edx,.point_number + cmp edx,[points_count_var] + jne .ipn_loop + + mov esp,ebp +ret +;=============================================================== +end if +init_triangles_normals2: + mov ebx,[triangles_normals_ptr] + mov ebp,[triangles_ptr] + mov ecx,[triangles_count_var] + @@: + push ecx + push ebx + mov ebx,vectors + mov esi,dword[ebp] ; first point index + lea esi,[esi*3] +; lea esi,[points+esi*2] ; esi - pointer to 1st 3d point + shl esi,2 + add esi,[points_ptr] + mov edi,dword[ebp+4] ; first point index + lea edi,[edi*3] + shl edi,2 + add edi,[points_ptr] +; movzx edi,word[ebp+2] ; second point index +; lea edi,[edi*3] +; lea edi,[points+edi*2] ; edi - pointer to 2nd 3d point + call make_vector_r + add ebx,12 + mov esi,edi + mov edi,dword[ebp+8] ; third point index + lea edi,[edi*3] + shl edi,2 + add edi,[points_ptr] +; lea edi,[points+edi*2] + call make_vector_r + mov edi,ebx ; edi - pointer to 2nd vector + mov esi,ebx + sub esi,12 ; esi - pointer to 1st vector + pop ebx + call cross_product + mov edi,ebx + call normalize_vector + add ebp,12 + add ebx,12 + pop ecx + sub ecx,1 + jnz @b + ; cmp dword[ebp],-1 + ; jne @b +ret + +if Ext >= SSE3 +copy_lights: ; after normalising ! + mov esi,lights + mov edi,lights_aligned + mov ecx,3 + .again: + push ecx + mov ecx,3 + cld + rep movsd + xor eax,eax + stosd + mov ecx,3 + .b: + push ecx + mov ecx,3 + @@: + movzx ebx,byte[esi] + cvtsi2ss xmm0,ebx + movss [edi],xmm0 + inc esi + add edi,4 + loop @b + stosd + pop ecx + loop .b + inc esi ; skip shiness + pop ecx + loop .again +ret +end if + +clrscr: + mov edi,[screen_ptr] + movzx ecx,word[size_x_var] + movzx eax,word[size_y_var] + imul ecx,eax + + + xor eax,eax + if Ext=NON + rep stosd + else if Ext = MMX + pxor mm0,mm0 + @@: + movq [edi+00],mm0 + movq [edi+08],mm0 + movq [edi+16],mm0 + movq [edi+24],mm0 + add edi,32 + sub ecx,8 + jnc @b + else + push ecx + mov ecx,edi + and ecx,0x0000000f + rep stosb + pop ecx + and ecx,0xfffffff0 + xorps xmm0,xmm0 + @@: + movaps [edi],xmm0 + movaps [edi+16],xmm0 + movaps [edi+32],xmm0 + movaps [edi+48],xmm0 + add edi,64 + sub ecx,16 + jnz @b + end if + +ret + + +draw_triangles: + + emms + ; update translated list MMX required + cmp [vertex_edit_no],0 + je @f + movzx eax,[vertex_edit_no] + dec eax + movd mm0,[edit_end_x] + psubw mm0,[edit_start_x] + lea eax,[eax*3] + add eax,eax + add eax,[points_translated_ptr] + movd mm1,dword[eax] + paddw mm1,mm0 + movd dword[eax],mm1 + @@: + if Ext >= SSE3 + cmp [dr_flag],13 + jnge .no_stencil + mov esi,[triangles_ptr] + mov ecx,[triangles_count_var] + @@: + push esi + push ecx + + mov eax,[esi] + mov ebx,[esi+4] + mov ecx,[esi+8] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_rotated_ptr] + add ebx,[points_rotated_ptr] + add ecx,[points_rotated_ptr] + push dword[ecx+8] + push dword[ebx+8] + push dword[eax+8] + movups xmm0,[esp] + add esp,12 + andps xmm0,[zero_hgst_dd] + + + mov eax,[esi] + mov ebx,[esi+4] + mov ecx,[esi+8] + shl eax,1 + shl ebx,1 + shl ecx,1 + lea eax,[eax*3] + lea ebx,[ebx*3] + lea ecx,[ecx*3] + add eax,[points_translated_ptr] + add ebx,[points_translated_ptr] + add ecx,[points_translated_ptr] + mov eax,[eax] + mov ebx,[ebx] + mov ecx,[ecx] + ror eax,16 + ror ebx,16 + ror ecx,16 + + + mov esi,[Zbuffer_ptr] + + call stencil_tri + + pop ecx + pop esi + add esi,12 + dec ecx + jnz @b + + .no_stencil: + end if + + + cmp [dr_flag],11 + je .draw_smooth_line + + mov esi,[triangles_ptr] + mov ecx,[triangles_count_var] + .again_dts: + push ecx + mov ebp,[points_translated_ptr] + if Ext >= SSE2 + mov eax,dword[esi] + mov [point_index1],eax + lea eax,[eax*3] + add eax,eax + push ebp + add ebp,eax + mov eax,[ebp] + ; cmp [vertex_edit_no],0 + ; jne @f + ; + ; @@: + mov dword[xx1],eax + mov eax,[ebp+4] + mov [zz1],ax + + pop ebp + + + mov eax,dword[esi+4] + mov [point_index2],eax + lea eax,[eax*3] + add eax,eax + push ebp + add ebp,eax + mov eax,[ebp] + mov dword[xx2],eax + mov eax,[ebp+4] + mov [zz2],ax + pop ebp + + + mov eax,dword[esi+8] ; xyz3 = [ebp+[esi+4]*6] + mov [point_index3],eax + lea eax,[eax*3] + add eax,eax + ; push ebp + add ebp,eax + mov eax,[ebp] + mov dword[xx3],eax + mov eax,[ebp+4] + mov [zz3],ax + else + movq mm0,[esi] ; don't know MMX + mov qword[point_index1],mm0 + ; shr eax,16 + ; mov [point_index2],ax + mov eax,dword[esi+8] + mov [point_index3],eax + movdqu xmm0,[esi] + paddd xmm0,xmm0 + movdqa xmm1,xmm0 + paddd xmm0,xmm0 + paddd xmm0,xmm1 + movd eax,xmm0 + psrldq xmm0,4 + movd ebx,xmm0 + psrldq xmm0,4 + movd ecx,xmm0 + and eax,0FFFFh + and ebx,0FFFFh + and ecx,0FFFFh + movq mm0,[ebp+eax] + movq mm1,[ebp+ebx] + movq mm2,[ebp+ecx] + movq qword[xx1],mm0 + movq qword[xx2],mm1 + movq qword[xx3],mm2 +; emms + end if ; ********************************* + if 0 + cmp [vertex_edit_no],0 + jne .no_edit + mov ax,[vertex_edit_no] + dec ax + cmp ax,[point_index1] + jne @f + movd mm0,[edit_start_x] + psubw mm0,[edit_end_x] + movd mm1,dword[xx1] + paddw mm1,mm0 + movd dword[xx1],mm1 + jmp .no_edit + @@: + + cmp ax,[point_index2] + jne @f + movd mm0,[edit_start_x] + psubw mm0,[edit_end_x] + movd mm1,dword[xx2] + paddw mm1,mm0 + movd dword[xx2],mm1 + jmp .no_edit + @@: + + cmp ax,[point_index3] + jne @f + movd mm0,[edit_start_x] + psubw mm0,[edit_end_x] + movd mm1,dword[xx3] + paddw mm1,mm0 + movd dword[xx3],mm1 + jmp .no_edit + @@: + + + .no_edit: +end if + + push esi ; + fninit ; DO culling AT FIRST + cmp [culling_flag],1 ; (if culling_flag = 1) + jne .no_culling + mov esi,point_index1 ; ********************************* + mov ecx,3 ; + @@: + mov eax,dword[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] +; lea eax,[eax+point_normals_rotated] + fld dword[eax+8] ; ***************************** + ftst ; CHECKING OF Z COOFICIENT OF + fstsw ax ; NORMAL VECTOR + sahf + jb @f + ffree st + loop @b + jmp .end_draw ; non visable + @@: + ffree st ;is visable + .no_culling: + cmp [dr_flag],0 ; draw type flag + je .flat_draw + cmp [dr_flag],2 + je .env_mapping + cmp [dr_flag],3 + je .bump_mapping + cmp [dr_flag],4 + je .tex_mapping + cmp [dr_flag],5 + je .rainbow + cmp [dr_flag],7 + je .grd_tex + cmp [dr_flag],8 + je .two_tex + cmp [dr_flag],9 + je .bump_tex + cmp [dr_flag],10 + je .cubic_env_mapping + cmp [dr_flag],11 + je .draw_smooth_line + if Ext >= SSE3 + cmp [dr_flag],12 + je .r_phg + cmp [dr_flag],13 + je .glass + cmp [dr_flag],14 + je .glass_tex + end if ; **************** + mov esi,point_index3 ; do Gouraud shading + mov ecx,3 + .again_grd_draw: + mov eax,dword[esi] + shl eax,2 + lea eax,[eax*3] + add eax,[points_normals_rot_ptr] + ; texture x=(rotated point normal -> x * 255)+255 + fld dword[eax] ; x cooficient of normal vector + fimul [correct_tex] + fiadd [correct_tex] + fistp [temp1] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] ; y cooficient + fimul [correct_tex] + fiadd [correct_tex] + fistp [temp2] + + mov eax,[temp2] + mov ebx,[temp1] + and ebx,0xfffffff + shl eax,TEX_SHIFT + add eax,ebx + lea eax,[eax*3+color_map] + mov eax,dword[eax] + ; cmp [catmull_flag],1 ; put on stack z coordinate if necessary + ; jne @f + lea edx,[ecx*3] + push word[edx*2+xx1-2] ; zz1 ,2 ,3 + ; @@: + ror eax,16 ; eax -0xxxrrggbb -> 0xggbbxxrr + xor ah,ah + push ax ;r + rol eax,8 ; eax-0xggbb00rr -> 0xbb00rrgg + xor ah,ah + push ax ;g + shr eax,24 + push ax ;b + + sub esi,4 + dec cx + jnz .again_grd_draw + jmp .both_draw + + ; movzx edi,[point_index3] ;gouraud shading according to light vector + ; lea edi,[edi*3] + ; lea edi,[4*edi+point_normals_rotated] ; edi - normal + ; mov esi,light_vector + ; call dot_product + ; fabs + ; fimul [orginal_color_r] + ; fistp [temp_col] + ; and [temp_col],0x00ff + ; push [temp_col] + ; push [temp_col] + ; push [temp_col] + + ; movzx edi,[point_index2] + ; lea edi,[edi*3] + ; lea edi,[4*edi+point_normals_rotated] ; edi - normal + ; mov esi,light_vector + ; call dot_product + ; fabs + ; fimul [orginal_color_r] + ; fistp [temp_col] + ; and [temp_col],0x00ff + ; push [temp_col] + ; push [temp_col] + ; push [temp_col] + + ; movzx edi,[point_index1] + ; lea edi,[edi*3] + ; lea edi,[4*edi+point_normals_rotated] ; edi - normal + ; mov esi,light_vector + ; call dot_product + ; fabs + ; fimul [orginal_color_r] + ; fistp [temp_col] + ; and [temp_col],0x00ff + ; push [temp_col] + ; push [temp_col] + ; push [temp_col] + .rainbow: + ; cmp [catmull_flag],1 ; put on stack z coordinate if necessary + ; jne @f + push [zz3] + @@: + mov eax,dword[yy3] + mov ebx,0x00ff00ff + and eax,ebx + push eax + neg al + push ax + push [zz2] + + mov eax,dword[yy2] + and eax,ebx + push eax + neg al + push ax + push [zz1] + + mov eax,dword[yy1] + and eax,ebx + push eax + neg al + push ax + .both_draw: + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,[Zbuffer_ptr] + call gouraud_triangle_z + jmp .end_draw + + .flat_draw: ;************************** + fninit ; FLAT DRAWING + mov eax,[point_index1] + mov ebx,[point_index2] + mov ecx,[point_index3] + shl eax,2 + shl ebx,2 + shl ecx,2 + lea eax,[eax*3] ;+point_normals_rotated] + add eax,[points_normals_rot_ptr] + lea ebx,[ebx*3] ;+point_normals_rotated] + add ebx,[points_normals_rot_ptr] + lea ecx,[ecx*3] ;+point_normals_rotated] + add ecx,[points_normals_rot_ptr] + fld dword[eax] ; x cooficient of normal vector + fadd dword[ebx] + fadd dword[ecx] + fidiv [i3] + fimul [correct_tex] + fiadd [correct_tex] + fistp [temp1] ;dword[esp-4] ; x temp variables + fld dword[eax+4] ; y cooficient of normal vector + fadd dword[ebx+4] + fadd dword[ecx+4] + fidiv [i3] + fimul [correct_tex] + fiadd [correct_tex] + fistp [temp2] ;dword[esp-8] ; y + mov edx,[temp2] ;dword[esp-8] + and edx,0xfffffff + and [temp1],0xfffffff + shl edx,TEX_SHIFT + add edx,[temp1] ;dword[esp-4] + + lea eax,[3*edx] + add eax,color_map + mov edx,dword[eax] + + and edx,0x00ffffff ; edx = 0x00rrggbb + + + + ; mov ax,[zz1] ; z position depend draw + ; add ax,[zz2] + ; add ax,[zz3] + ; cwd + ; idiv [i3] ; = -((a+b+c)/3+130) + ; add ax,130 + ; neg al + ; xor edx,edx + ; mov ah,al ;set color according to z position + ; shl eax,8 + ; mov edx,eax + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + + mov esi,[Zbuffer_ptr] + push word[zz3] + push word[zz2] + push word[zz1] + call flat_triangle_z + jmp .end_draw + + .env_mapping: + push [zz3] + push [zz2] + push [zz1] + + mov esi,point_index1 + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + mov eax,dword[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] ;point_normals_rotated + ; texture x=(rotated point normal -> x * 255)+255 + fld dword[eax] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi+2] + + add edi,4 + add esi,4 + loop @b + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,envmap + + mov edx,[Zbuffer_ptr] + call tex_triangle_z + + jmp .end_draw +;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + .cubic_env_mapping: + push [zz3] + push [zz2] + push [zz1] + + mov esi,point_index1 + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + mov eax,dword[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] + + fld dword[eax] + fmul dword[eax+4] + fld1 + fld1 + faddp + fmulp + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi] + mov word[edi+2],0 +; fistp word[edi+2] +; # last change +; ; texture x=(rotated point normal -> x * 255)+255 +; fld dword[eax] +; fimul [correct_tex] +; fiadd [correct_tex] +; fistp word[edi] +; ; texture y=(rotated point normal -> y * 255)+255 +; fld dword[eax+4] +; fimul [correct_tex] +; fiadd [correct_tex] +; fistp word[edi+2] +; # end of last ch. + add edi,4 + add esi,4 + loop @b + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,envmap_cub + mov edx,[Zbuffer_ptr] + + call tex_triangle_z + + jmp .end_draw + +;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + .bump_mapping: + + push [Zbuffer_ptr] + push [zz3] + push [zz2] + push [zz1] + + mov esi,point_index1 + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + mov eax,dword[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] ;point_normals_rotated + ; texture x=(rotated point normal -> x * 255)+255 + fld dword[eax] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi+2] + + add edi,4 + add esi,4 + loop @b + + mov esi,[point_index3] ; bump map coords + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index2] + shl esi,2 + add esi,tex_points +; lea esi,[esi*3] +; lea esi,[points+2+esi*2] + push dword[esi] + ; push dword[xx2] + mov esi,[point_index1] + shl esi,2 + add esi,tex_points +; lea esi,[esi*3] +; lea esi,[points+2+esi*2] + push dword[esi] + ; push dword[xx1] + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,envmap + mov edx,bumpmap ;BUMP_MAPPING + + call bump_triangle_z + + jmp .end_draw + + .tex_mapping: + + push [zz3] + push [zz2] + push [zz1] + ; @@: + mov esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index1] + shl esi,2 + add esi,tex_points + push dword[esi] + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,texmap + mov edx,[Zbuffer_ptr] + + call tex_triangle_z + + jmp .end_draw +; .ray: +; grd_triangle according to points index +; cmp [catmull_flag],0 +; je @f +; push [zz3] ; spot light with attenuation +; @@: +; movzx eax,[point_index3] ; env_map - points color list +; shl eax,1 ; each color as word, 0x00rr00gg00bb.. +; lea eax,[3*eax+bumpmap] +; push word[eax] +; push word[eax+2] +; push word[eax+4] +; cmp [catmull_flag],0 +; je @f +; push [zz2] +; @@: +; movzx eax,[point_index2] ; env_map - points color list +; shl eax,1 ; each color as word, 0x00rr00gg00bb.. +; lea eax,[eax*3+bumpmap] +; push word[eax] +; push word[eax+2] +; push word[eax+4] +; cmp [catmull_flag],0 +; je @f +; push [zz1] +; @@: +; movzx eax,[point_index1] ; env_map - points color list +; shl eax,1 ; each color as word, 0xrr00gg00bb00.. +; lea eax,[eax*3+bumpmap] +; push word[eax] +; push word[eax+2] +; push word[eax+4] +; jmp .both_draw + + .grd_tex: ; smooth shading + texture + push ebp + mov ebp,esp + sub esp,4 + push ebp + + mov esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] ; texture coords as first + mov esi,[point_index2] ; group of parameters + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index1] + shl esi,2 + add esi,tex_points + push dword[esi] + + mov esi,point_index3 + mov ecx,3 + + .aagain_grd_draw: + + lea edx,[ecx*3] + push word[edx*2+xx1-2] ; zz1 ,2 ,3 + fninit + mov eax,dword[esi] + shl eax,2 + lea eax,[eax*3] ;+point_normals_rotated] + add eax,[points_normals_rot_ptr] + ; texture x=(rotated point normal -> x * 255)+255 + fld dword[eax] ; x cooficient of normal vector + fimul [correct_tex] + fiadd [correct_tex] + fistp [temp1] ;word[ebp-2] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] ; y cooficient + fimul [correct_tex] + fiadd [correct_tex] + fistp [temp2] ;word[ebp-4] + + mov eax,[temp2] ;word[ebp-4] + mov ebx,[temp1] ;word[ebp-2] + and ebx,0xfffffff ; some onjects need thid 'and' + shl eax,TEX_SHIFT + add eax,ebx + lea eax,[eax*3] + add eax,color_map + mov eax,dword[eax] + + ror eax,16 ; eax -0xxxrrggbb -> 0xggbbxxrr + xor ah,ah + push ax ;r + rol eax,8 ; eax-0xggbb00rr -> 0xbb00rrgg + xor ah,ah + push ax ;g + shr eax,24 + push ax ;b + + sub esi,4 + dec cx + jnz .aagain_grd_draw + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov edx,texmap + mov esi,[Zbuffer_ptr] + + call tex_plus_grd_triangle + + pop ebp + mov esp,ebp + pop ebp + jmp .end_draw + + .two_tex: + push [Zbuffer_ptr] + + push word[zz3] + push word[zz2] + push word[zz1] + + mov esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index1] + shl esi,2 + add esi,tex_points + push dword[esi] + + mov esi,point_index1 ; env coords + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + mov eax,dword[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] + ; texture x=(rotated point normal -> x * 255)+255 + fld dword[eax] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi] + + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi+2] + and word[edi+2],0x7fff ; some objects need it + add edi,4 + add esi,4 + loop @b + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,texmap + mov edx,envmap + + call two_tex_triangle_z + jmp .end_draw + + .bump_tex: + mov esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index1] + shl esi,2 + add esi,tex_points + push dword[esi] + + push dword texmap + + push [Zbuffer_ptr] + xor edi,edi + + push word[zz3] + push word[zz2] + push word[zz1] + + mov esi,point_index1 ; env coords + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + mov eax,dword[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] + ; texture x=(rotated point normal -> x * 255)+255 + fld dword[eax] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] + fimul [correct_tex] + fiadd [correct_tex] + fistp word[edi+2] + + add edi,4 + add esi,4 + loop @b + +; push dword 1 shl 16 + 1 ; emap coords +; push dword 127 shl 16 + 1 +; push dword 127 shl 16 + 127 + + mov esi,[point_index3] ; bump map coords + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + + mov esi,[point_index1] + shl esi,2 + add esi,tex_points + push dword[esi] + +; push dword 1 shl 16 + 127 +; push dword 127 shl 16 + 127 +; push dword 1 shl 16 + 1 ; bump coords + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,envmap + mov edx,bumpmap + + call bump_tex_triangle_z + + jmp .end_draw + + +if Ext >= SSE3 + .r_phg: + + + movd xmm5,[size_y_var] + punpcklwd xmm5,[the_zero] + pshufd xmm5,xmm5,01110011b + + + mov eax,[point_index1] + mov ebx,[point_index2] + mov ecx,[point_index3] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_normals_rot_ptr] + add ebx,[points_normals_rot_ptr] + add ecx,[points_normals_rot_ptr] + movups xmm0,[eax] + movups xmm1,[ebx] + movups xmm2,[ecx] + andps xmm0,[zero_hgst_dd] + andps xmm1,[zero_hgst_dd] + andps xmm2,[zero_hgst_dd] + xorps xmm3,xmm3 + + mov eax,[point_index1] + mov ebx,[point_index2] + mov ecx,[point_index3] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_rotated_ptr] + add ebx,[points_rotated_ptr] + add ecx,[points_rotated_ptr] + push dword[ecx+8] + push dword[ebx+8] + push dword[eax+8] + movups xmm4,[esp] + add esp,12 + andps xmm4,[zero_hgst_dd] + + + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov esi,[Zbuffer_ptr] + + call real_phong_tri_z + + jmp .end_draw + + .glass: + movd xmm5,[size_y_var] + punpcklwd xmm5,[the_zero] + pshufd xmm5,xmm5,01110011b + + + mov eax,[point_index1] + mov ebx ,[point_index2] + mov ecx,[point_index3] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_normals_rot_ptr] + add ebx,[points_normals_rot_ptr] + add ecx,[points_normals_rot_ptr] + movups xmm0,[eax] + movups xmm1,[ebx] + movups xmm2,[ecx] + andps xmm0,[zero_hgst_dd] + andps xmm1,[zero_hgst_dd] + andps xmm2,[zero_hgst_dd] + xorps xmm3,xmm3 + + mov eax,[point_index1] + mov ebx,[point_index2] + mov ecx,[point_index3] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_rotated_ptr] + add ebx,[points_rotated_ptr] + add ecx,[points_rotated_ptr] + push dword[ecx+8] + push dword[ebx+8] + push dword[eax+8] + movups xmm4,[esp] + add esp,12 + andps xmm4,[zero_hgst_dd] + + + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edi,[screen_ptr] + mov edx,[Zbuffer_ptr] + mov esi,[Zbuffer_ptr] + + call glass_tri + jmp .end_draw + + + .glass_tex: + movd xmm5,[size_y_var] + punpcklwd xmm5,[the_zero] + pshufd xmm5,xmm5,01110011b + + mov eax,[point_index1] + mov ebx,[point_index2] + mov ecx,[point_index3] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_normals_rot_ptr] + add ebx,[points_normals_rot_ptr] + add ecx,[points_normals_rot_ptr] + movups xmm0,[eax] + movups xmm1,[ebx] + movups xmm2,[ecx] + andps xmm0,[zero_hgst_dd] + andps xmm1,[zero_hgst_dd] + andps xmm2,[zero_hgst_dd] + xorps xmm3,xmm3 + + mov eax,[point_index1] + mov ebx,[point_index2] + mov ecx,[point_index3] + imul eax,[i12] + imul ebx,[i12] + imul ecx,[i12] + add eax,[points_rotated_ptr] + add ebx,[points_rotated_ptr] + add ecx,[points_rotated_ptr] + push dword[ecx+8] + push dword[ebx+8] + push dword[eax+8] + movups xmm4,[esp] + add esp,12 + andps xmm4,[zero_hgst_dd] + + mov esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + mov esi,[point_index1] + shl esi,2 + add esi,tex_points + push dword[esi] + movups xmm6,[esp] + add esp,12 + ; pshuflw xmm6,xmm6,10110001b + ; pshufhw xmm6,xmm6,10110001b + + movzx eax,word[size_x_var] + andps xmm6,[zero_hgst_dd] + movd xmm7,eax + pslldq xmm7,12 + por xmm6,xmm7 + + + mov eax,dword[xx1] + ror eax,16 + mov ebx,dword[xx2] + ror ebx,16 + mov ecx,dword[xx3] + ror ecx,16 + mov edx,texmap + mov edi,[screen_ptr] + mov esi,[Zbuffer_ptr] + + call glass_tex_tri + + + +end if + + .end_draw: + pop esi + add esi,12 + + pop ecx + dec ecx + + jnz .again_dts +ret + + + .draw_smooth_line: + mov esi,[edges_ptr] + xor ecx,ecx + .again_s_line: + push ecx + push esi + + mov ecx,2 + .aga_n: + mov eax,[esi] + shl eax,2 + lea eax,[eax*3] + add eax,[points_normals_rot_ptr] + movups xmm0,[eax] + xorps xmm1,xmm1 + mov edx,lights_aligned + .again_cc: + movaps xmm3,xmm0 ;.cnv + mulps xmm3,[edx] + andps xmm3,[zero_hgst_dd] + ; haddps xmm3,xmm3 + ; haddps xmm3,xmm3 ; xmm3 - dot pr + movhlps xmm2,xmm3 + addps xmm3,xmm2 + movdqa xmm2,xmm3 + shufps xmm2,xmm2,01010101b + addps xmm3,xmm2 + shufps xmm3,xmm3,0 + movaps xmm6,xmm3 ;xmm7 + mulps xmm6,xmm6 + mulps xmm6,xmm6 + mulps xmm6,xmm6 + mulps xmm6,xmm6 + mulps xmm6,xmm6 + mulps xmm6,[edx+48] + movaps xmm7,xmm3 + mulps xmm7,[edx+16] + addps xmm7,xmm6 + addps xmm7,[edx+32] + minps xmm7,[mask_255f] ; global + + maxps xmm1,xmm7 + add edx,64 ; size of one light in aligned list + cmp edx,lights_aligned_end + jl .again_cc + sub esp,16 + movups [esp],xmm1 + add esi,4 + loop .aga_n + + movups xmm0,[esp] + movups xmm1,[esp+16] + add esp,32 + sub esi,8 + + mov ecx,[esi] + mov edx,[esi+4] + imul ecx,[i6] + imul edx,[i6] + add ecx,[points_translated_ptr] + add edx,[points_translated_ptr] + + movd xmm7,[ecx] + movhps xmm7,[edx] + pshufd xmm7,xmm7,11101000b + movdqa xmm6,xmm7 + movd xmm5,[size_y_var] + pshuflw xmm5,xmm5,00010001b + pcmpgtw xmm7,xmm5 + pcmpgtw xmm6,[the_zero] + pxor xmm7,xmm6 + pmovmskb eax,xmm7 + cmp al,-1 + jnz .skp + + + + + mov eax,[esi] + mov ebx,[esi+4] + imul eax,[i12] + imul ebx,[i12] + add eax,[points_rotated_ptr] + add ebx,[points_rotated_ptr] + movss xmm2,[eax+8] + movss xmm3,[ebx+8] + + + movzx eax,word[ecx] + movzx ebx,word[ecx+2] + movzx ecx,word[edx] + movzx edx,word[edx+2] + + emms + movd mm1,[screen_ptr] + movd mm0,[Zbuffer_ptr] + movzx esi,word[size_x_var] + movd mm2,esi + + push ebp + call line_grd + pop ebp + .skp: + pop esi + pop ecx + add esi,8 + inc ecx + cmp ecx,[edges_count] + jnz .again_s_line + + ret + + + + + + +draw_handlers: + + push ebp + mov ebp,esp + + .counter equ ebp-16 + .xres3m18 equ ebp-8 + .xres2m12 equ ebp-12 + + + ; init counter + sub esp,12 + push dword 0 + + movzx eax,word[size_x_var] + cmp [dr_flag],12 + jge @f + lea ebx,[eax*3] + sub ebx,18 + add eax,eax + sub eax,12 + mov [.xres3m18],ebx + mov [.xres2m12],eax + jmp .f + @@: + lea ebx,[eax*4] + sub ebx,4*6 + add eax,eax + sub eax,3*4 + mov [.xres3m18],ebx + mov [.xres2m12],eax + .f: + + + + mov esi,[points_translated_ptr] + .loop: + push esi + ; DO culling AT FIRST + cmp [culling_flag],1 ; (if culling_flag = 1) + jne .no_culling + mov edi,[.counter] ; ********************************* + lea edi,[edi*3] + shl edi,2 + add edi,[points_normals_rot_ptr] + mov eax,[edi+8] ; check sign of z coof + shr eax,31 + cmp eax,1 + jnz .skip + .no_culling: + mov eax,[esi] + movzx ebx,ax ; ebx - x + shr eax,16 ; eax - y + cmp eax,4 ; check if markers not exceedes screen + jle .skip + cmp ebx,4 + jle .skip + movzx edx,word[size_x_var] + sub edx,4 + movzx ecx,word[size_y_var] + sub ecx,4 + cmp ebx,edx + jge .skip + cmp eax,ecx + jge .skip + + movzx edx,word[size_x_var] + ; sub ebx,3 + ; sub eax,3 + imul eax,edx + add eax,ebx + push eax + lea edi,[eax*3] + cmp [dr_flag],12 + jl @f + add edi,[esp] + @@: + add esp,4 + lea eax,[eax*2] + ; draw bar 6x6 + add edi,[screen_ptr] + add eax,dword[vertices_index_ptr] + + + + + mov edx,[.counter] + mov ecx,6 + + .oop: + push ecx + mov ecx,6 + + .do: + mov word[edi],0x0000 ;ax + mov byte[edi+2],0xff ;al + mov word[eax],dx + add eax,2 + cmp [dr_flag],12 + jl @f + add edi,4 + loop .do + jmp .ad + @@: + add edi,3 + loop .do + .ad: + add edi,[.xres3m18] + add eax,[.xres2m12] + pop ecx + loop .oop + + .skip: + pop esi + add esi,6 + inc dword[.counter] + mov ecx,[.counter] + cmp ecx,[points_count_var] + jng .loop + + mov esp,ebp + pop ebp + +ret + + +fill_Z_buffer: + mov eax,0x70000000 + cmp [dr_flag],11 + jl @f + mov eax,60000.1 + @@: + mov edi,[Zbuffer_ptr] + movzx ecx,word[size_x_var] + movzx ebx,word[size_y_var] + imul ecx,ebx + if Ext>=SSE2 + movd xmm0,eax + shufps xmm0,xmm0,0 + push ecx + mov ecx,edi + and edi,0xffffff00 + and ecx,0x000000ff + mov edx,ecx + rep stosd + pop ecx + sub ecx,edx + @@: + movaps [edi],xmm0 + movaps [edi+16],xmm0 + movaps [edi+32],xmm0 + movaps [edi+48],xmm0 + add edi,64 + sub ecx,16 + jnc @b + else + rep stosd + end if +ret + +read_tp_variables: ; read [triangles_count_var] and [points_count_var] + ; and allocate memory + xor ebx,ebx + xor ebp,ebp + mov [points_count_var],ebx + mov [triangles_count_var],ebx + if USE_LFN = 0 + mov esi,SourceFile + else + mov esi,[fptr] + end if + + cmp [esi],word 4D4Dh + je @f ;Must be legal .3DS file + xor eax,eax + ret + @@: + mov eax,dword[esi+2] + cmp eax,[fsize] ;This must tell the length + je @f + xor eax,eax + ret + @@: + add eax,esi + mov [EndFile],eax ; + + add esi,6 + @@: + cmp [esi],word 3D3Dh + je @f + add esi,[esi+2] + jmp @b + @@: + add esi,6 + .find4k: + cmp [esi],word 4000h + je @f + add esi,[esi+2] + cmp esi,[EndFile] + jc .find4k + jmp .exit + @@: + add esi,6 + @@: + cmp [esi],byte 0 + je @f + inc esi + jmp @b + @@: + inc esi + @@: + cmp [esi],word 4100h + je @f + add esi,[esi+2] + jmp @b + @@: + add esi,6 + @@: + cmp [esi],word 4110h + je @f + add esi,[esi+2] + jmp @b + @@: + movzx ecx,word[esi+6] + add [points_count_var],ecx + + mov edx,ecx + add esi,8 + @@: + + add ebx,6 + add esi,12 + ; dec ecx + loop @b + @@: + + @@: + cmp [esi],word 4120h + je @f + add esi,[esi+2] + jmp @b + @@: + movzx ecx,word[esi+6] + add [triangles_count_var],ecx + add esi,8 + + @@: + add esi,8 + dec ecx + jnz @b +; xor ecx,ecx + add ebp,edx + jmp .find4k + mov eax,-1 ;<---mark if OK + .exit: +ret + +read_from_file: + fninit + mov edi,[triangles_ptr] + xor ebx,ebx + xor ebp,ebp + mov [points_count_var],0 + mov [triangles_count_var],0 + mov esi,[fptr] + cmp [esi],word 4D4Dh + jne .exit ;Must be legal .3DS file +; cmp dword[esi+2],EndFile-SourceFile +; jne .exit ;This must tell the length + mov eax,dword[esi+2] + ; cmp eax,[fsize] + ; jne .exit + + add eax,esi + mov [EndFile],eax ; + + add esi,6 + @@: + cmp [esi],word 3D3Dh + je @f + add esi,[esi+2] + jmp @b + @@: + add esi,6 + .find4k: + cmp [esi],word 4000h + je @f + add esi,[esi+2] + cmp esi,[EndFile] + jc .find4k + jmp .exit + @@: + add esi,6 + @@: + cmp [esi],byte 0 + je @f + inc esi + jmp @b + @@: + inc esi + @@: + cmp [esi],word 4100h + je @f + add esi,[esi+2] + jmp @b + @@: + add esi,6 + @@: + cmp [esi],word 4110h + je @f + add esi,[esi+2] + jmp @b + @@: + movzx ecx,word[esi+6] + add [points_count_var],ecx + + mov edx,ecx + add esi,8 + @@: + push edi + mov edi,[points_ptr] + push dword[esi+0] + pop dword[edi+ebx*2+0] + push dword[esi+4] + pop dword[edi+ebx*2+4] + push dword[esi+8] + pop dword[edi+ebx*2+8] + pop edi + + add ebx,6 + add esi,12 + dec ecx + jnz @b + @@: + ; mov dword[points+ebx],-1 + push edi + mov edi,[points_ptr] + mov dword[edi+ebx*2],-1 ; end mark (not always in use) + pop edi + @@: + cmp [esi],word 4120h + je @f + add esi,[esi+2] + jmp @b + @@: + movzx ecx,word[esi+6] + add [triangles_count_var],ecx + add esi,8 + ;mov edi,triangles + @@: + movzx eax,word[esi] + stosd + movzx eax,word[esi+2] + stosd + movzx eax,word[esi+4] + stosd + add dword[edi-12],ebp + add dword[edi-8],ebp + add dword[edi-4],ebp + add esi,8 + dec ecx + jnz @b + add ebp,edx + jmp .find4k + mov eax,-1 ;<---mark if OK + .exit: + mov dword[edi],-1 +ret + +alloc_mem_for_tp: + mov eax, 68 + cmp [re_alloc_flag],1 + jz @f + mov ebx, 12 + jmp .alloc + @@: + mov ebx,20 + .alloc: + + mov ecx,[triangles_count_var] + add ecx,20 + lea ecx, [ecx*3] + shl ecx,2 + mov edx,[triangles_ptr] + int 0x40 ; -> allocate memory to triangles + mov [triangles_ptr], eax ; -> eax = pointer to allocated mem + + mov eax, 68 + mov ecx,[triangles_count_var] + imul ecx,[i36] + mov edx,[edges_ptr] + int 0x40 ; -> allocate memory to triangles + mov [edges_ptr], eax ; -> eax = pointer to allocated mem + + + ; ststic memory + + mov eax, 68 + mov ecx, [triangles_count_var] + lea ecx, [3+ecx*3] + shl ecx, 2 + mov edx,[triangles_normals_ptr] + int 0x40 ; -> allocate memory for triangles normals + mov [triangles_normals_ptr], eax ; -> eax = pointer to allocated mem + + + mov eax, 68 + mov ecx, [points_count_var] + lea ecx,[3+ecx*3] + shl ecx, 2 + mov edx,[points_normals_ptr] + int 0x40 + mov [points_normals_ptr], eax + + + mov eax, 68 + ; mov ebx, 12 + mov ecx, [points_count_var] + lea ecx,[3+ecx*3] + shl ecx, 2 + mov edx,[points_normals_rot_ptr] + int 0x40 + mov [points_normals_rot_ptr], eax + + mov eax, 68 + mov edx,[points_ptr] + int 0x40 + mov [points_ptr], eax + + mov eax, 68 + mov edx,[points_rotated_ptr] + int 0x40 + mov [points_rotated_ptr], eax + + mov eax, 68 + mov ecx, [points_count_var] + inc ecx + shl ecx, 3 + mov edx,[points_translated_ptr] + int 0x40 + mov [points_translated_ptr], eax +ret + + + +read_from_disk: + mov eax, 68 + mov ebx, 11 + int 0x40 ; -> create heap + + ;load kpacked files by Leency + mov eax,68 + mov ebx,27 + mov ecx,file_name + int 0x40 + + mov [fsize],edx + mov [file_info+16],eax + + test eax,eax + jnz .open_opened_well + mov eax,6 ;otherwise => failed + jmp @f + .open_opened_well: + xor eax,eax + @@: + ; eax = 0 -> ok file loaded +ret +read_param: + mov esi,I_Param + cmp dword[esi],0 + je .end + cmp byte[esi],'/' + je .copy + mov edi,esi + mov ecx,25 ; 25 - would be enought + repe scasb + jne .end + dec edi + mov esi,edi + .copy: + mov edi,file_name + mov ecx,50 + rep movsd + .end: +ret +buttons: ; draw some buttons (all but navigation and close ) + mov edi,menu + .again: + mov eax,8 ; function 8 : define and draw button + mov bx,[size_x_var] + shl ebx,16 + add ebx,(10)*65536+62 ; [x start] *65536 + [x size] + movzx ecx,byte[edi] ; button id = position+2 + sub cl,2 + lea ecx,[ecx*5] + lea ecx,[ecx*3] + add ecx,25 + shl ecx,16 + add ecx,12 + movzx edx,byte[edi] ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ; BUTTON LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,byte[edi] + sub bl,2 ; button id, according to position + lea ebx,[ebx*3] + lea ebx,[ebx*5] + mov cx,[size_x_var] + shl ecx,16 + add ebx,ecx + add ebx,(12)*65536+28 ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + lea edx,[edi+1] ; pointer to text beginning + mov esi,10 ; text length + int 0x40 + cmp byte[edi+11],255 ; if max_flag=255 + je @f ; skip + ; flag description +; mov eax,4 ; function 4 : write text to window +; movzx ebx,byte[edi] +; sub bl,2 +; lea ebx,[ebx*3] +; lea ebx,[ebx*5] +; add ebx,(SIZE_X+12+70)*65536+28 ; [x start] *65536 + [y start] + add ebx,70*65536 +; mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + movzx edx,byte[edi+12] ; current flag + shl edx,2 ; * 4 = text length + add edx,dword[edi+13] ; pointer to text beginning + mov esi,4 ; text length + int 0x40 + + @@: + add edi,17 + cmp byte[edi],-1 + jnz .again +ret +write_info: + mov eax,13 + mov bx,[size_x_var] + shl ebx,16 + add ebx,120*65536+70 ; [x start] *65536 + [y start] + mov ecx,30 shl 16 + 100 + xor edx,edx + int 0x40 + + + xor esi,esi + emms + movd mm7,esi + .nxxx: + push esi + movd mm7,esi + + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,120*65536 ; [x start] *65536 + [y start] + mov bx,si + shl bx,3 + add ebx,30 + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + movd edx,mm7 + shl edx,2 + add edx,lab_vert ; pointer to text beginning + mov esi,lab_vert_end-lab_vert ; text length + int 0x40 + + movd esi,mm7 + mov eax,[points_count_var+esi] + mov ecx,10 + .dc: + xor edx,edx + mov edi,10 + div edi + add dl,30h + mov [STRdata+ecx-1],dl + loop .dc + + mov eax,4 ; function 4 : write text to window + mov bx,[size_x_var] + add ebx,120 + shl ebx,16 + mov bx,si ; [x start] *65536 + [y start] + shl bx,3 + add bx,45 + mov ecx,0x00ddeeff + mov edx,STRdata ; pointer to text beginning + mov esi,10 ; text length + int 40h + pop esi + add esi,4 + cmp esi,12 + jnz .nxxx +ret +; ********************************************* +; ******* WINDOW DEFINITIONS AND DRAW ******** +; ********************************************* + draw_window: + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,1 ; 1, start of draw + int 0x40 + + ; DRAW WINDOW + mov eax,0 ; function 0 : define and draw window + mov bx,[x_start] + shl ebx,16 + mov cx,[y_start] + shl ecx,16 +;ebx - [x start] *65536 + [x size] +;ecx - [y start] *65536 + [y size] + mov bx,[size_x_var] + add bx,225 + mov cx,[size_y_var] + add cx,30 + ; @@: + mov edx,0x13000000 ; color of work area RRGGBB,8->color gl + mov edi,labelt ; WINDOW LABEL + int 0x40 + + call buttons ; more buttons + + .Y_ADD equ 2 ;-> offset of 'add vector' buttons + + ; mov eax,47 + ; mov ebx,0000000000111000000000000000b + ; mov ecx,[points_count_var] + ; movzx edx,word[size_x_var] + ; shl edx,16 + ; add edx,130*65536+60 ; [x start] *65536 + [y start] + ; mov esi,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + ; int 0x40 + call write_info + + ; ADD VECTOR LABEL ; add vector buttons - 30 ++ + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(12)*65536+(168+15*(13+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelvector ; pointer to text beginning + mov esi,labelvectorend-labelvector ; text length + ; cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + int 0x40 + ; VECTOR Y- BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,30*65536+20 ; [x start] *65536 + [x size] + mov ecx,(165+15*(14+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] + mov edx,30 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ;VECTOR Y- LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(32)*65536+(168+15*(14+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelyminus ; pointer to text beginning + mov esi,labelyminusend-labelyminus ; text length + cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + int 0x40 + ; VECTOR Z+ BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(51)*65536+21 ; [x start] *65536 + [x size] + mov ecx,(165+15*(14+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] + mov edx,31 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ;VECTOR Z+ LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(53)*65536+(168+15*(14+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelzplus ; pointer to text beginning + mov esi,labelzplusend-labelzplus ; text length + ; cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + + int 0x40 + ; VECTOR x- BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(10)*65536+21 ; [x start] *65536 + [x size] + mov ecx,(165+15*(15+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] + mov edx,32 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ;VECTOR x- LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(12)*65536+(168+15*(15+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelxminus ; pointer to text beginning + mov esi,labelxminusend-labelxminus ; text length + ; cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + int 0x40 + ; VECTOR x+ BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(51)*65536+21 ; [x start] *65536 + [x size] + mov ecx,(165+15*(15+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] + mov edx,33 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ;VECTOR x+ LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(53)*65536+(168+15*(15+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelxplus ; pointer to text beginning + mov esi,labelxplusend-labelxplus ; text length + ; cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + int 0x40 + ; VECTOR z- BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(10)*65536+62-41 ; [x start] *65536 + [x size] + mov ecx,(25+140+15*(16+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] + mov edx,34 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ;VECTOR z- LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(12)*65536+(168+15*(16+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelzminus ; pointer to text beginning + mov esi,labelzminusend-labelzminus ; text length + ; cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + int 0x40 + ;VECTOR Y+ BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(10+20)*65536+20 ; [x start] *65536 + [x size] + mov ecx,(165+15*(16+.Y_ADD))*65536+12 ; [y start] *65536 + [y size] + mov edx,35 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + ;VECTOR Y+ LABEL + mov eax,4 ; function 4 : write text to window + movzx ebx,word[size_x_var] + shl ebx,16 + add ebx,(32)*65536+(168+15*(16+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelyplus ; pointer to text beginning + mov esi,labelyplusend-labelyplus ; text length + ; cmp [move_flag],2 + ; jne @f + ; add edx,navigation_size + ; @@: + int 0x40 + + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,2 ; 2, end of draw + int 0x40 + ret + + + ; DATA AREA ************************************ + + include 'data.inc' + align 16 +MEM_END: