From 184460aa4bae328eb85925ec2cc4d27dc33024d1 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sat, 31 Oct 2009 22:01:20 +0000 Subject: [PATCH] New View3ds demo from macgub git-svn-id: svn://kolibrios.org@1245 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/demos/3DS/3DMATH.ASM | 109 - programs/demos/3DS/3DMATH.INC | 411 +++ programs/demos/3DS/3DSHEART.ASM | 1984 ------------ programs/demos/3DS/3DSTPOT.ASM | 1991 ------------ programs/demos/3DS/3dspiral.asm | 440 --- programs/demos/3DS/A_PROCS.INC | 503 +++ programs/demos/3DS/BUMP3.INC | 609 ++++ programs/demos/3DS/BUMP_CAT.INC | 1095 +++++++ programs/demos/3DS/BUMP_TEX.INC | 1352 ++++++++ programs/demos/3DS/B_PROCS.INC | 1171 +++++++ programs/demos/3DS/FLAT3.ASM | 188 -- programs/demos/3DS/FLAT3.INC | 205 ++ programs/demos/3DS/FLATWAV.ASM | 762 ----- .../demos/3DS/{FLAT_CAT.ASM => FLAT_CAT.INC} | 92 +- programs/demos/3DS/{GRD3.ASM => GRD3.INC} | 0 .../demos/3DS/{GRD_CAT.ASM => GRD_CAT.INC} | 160 +- programs/demos/3DS/GRD_TEX.INC | 929 ++++++ programs/demos/3DS/TEX3.ASM | 507 --- programs/demos/3DS/TEX3.INC | 543 ++++ programs/demos/3DS/TEX_CAT.INC | 610 ++++ programs/demos/3DS/TWO_TEX.INC | 1080 +++++++ programs/demos/3DS/VIEW3DS.ASM | 2754 +++++++++++++++++ programs/demos/3DS/data.inc | 468 +++ programs/demos/3DS/readme.txt | 31 + 24 files changed, 11964 insertions(+), 6030 deletions(-) delete mode 100644 programs/demos/3DS/3DMATH.ASM create mode 100644 programs/demos/3DS/3DMATH.INC delete mode 100644 programs/demos/3DS/3DSHEART.ASM delete mode 100644 programs/demos/3DS/3DSTPOT.ASM delete mode 100644 programs/demos/3DS/3dspiral.asm create mode 100644 programs/demos/3DS/A_PROCS.INC create mode 100644 programs/demos/3DS/BUMP3.INC create mode 100644 programs/demos/3DS/BUMP_CAT.INC create mode 100644 programs/demos/3DS/BUMP_TEX.INC create mode 100644 programs/demos/3DS/B_PROCS.INC delete mode 100644 programs/demos/3DS/FLAT3.ASM create mode 100644 programs/demos/3DS/FLAT3.INC delete mode 100644 programs/demos/3DS/FLATWAV.ASM rename programs/demos/3DS/{FLAT_CAT.ASM => FLAT_CAT.INC} (78%) rename programs/demos/3DS/{GRD3.ASM => GRD3.INC} (100%) rename programs/demos/3DS/{GRD_CAT.ASM => GRD_CAT.INC} (79%) create mode 100644 programs/demos/3DS/GRD_TEX.INC delete mode 100644 programs/demos/3DS/TEX3.ASM create mode 100644 programs/demos/3DS/TEX3.INC create mode 100644 programs/demos/3DS/TEX_CAT.INC create mode 100644 programs/demos/3DS/TWO_TEX.INC create mode 100644 programs/demos/3DS/VIEW3DS.ASM create mode 100644 programs/demos/3DS/data.inc create mode 100644 programs/demos/3DS/readme.txt diff --git a/programs/demos/3DS/3DMATH.ASM b/programs/demos/3DS/3DMATH.ASM deleted file mode 100644 index dd022f13d9..0000000000 --- a/programs/demos/3DS/3DMATH.ASM +++ /dev/null @@ -1,109 +0,0 @@ -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 ------------------------ -make_vector: - fninit - fild word[edi+x3d] ;edi+x3d - fisub word[esi+x3d] ;esi+x3d - fstp dword[ebx+vec_x] - - fild word[edi+y3d] - fisub word[esi+y3d] - fstp dword[ebx+vec_y] - - fild word[edi+z3d] - fisub word[esi+z3d] - fstp dword[ebx+vec_z] - -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: - 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] -ret -;------------------in: ------------------------- -;------------------ esi - pointer to 1st vector -;------------------ edi - pointer to 2nd vector -;------------------out: ------------------------ -;------------------ st0 - dot-product -dot_product: - fninit - 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 -ret - - - diff --git a/programs/demos/3DS/3DMATH.INC b/programs/demos/3DS/3DMATH.INC new file mode 100644 index 0000000000..9b22fa6521 --- /dev/null +++ b/programs/demos/3DS/3DMATH.INC @@ -0,0 +1,411 @@ +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 ------------------------ +if 0 +make_vector: + fninit + fild word[edi+x3d] ;edi+x3d + fisub word[esi+x3d] ;esi+x3d + fstp dword[ebx+vec_x] + + fild word[edi+y3d] + fisub word[esi+y3d] + fstp dword[ebx+vec_y] + + fild word[edi+z3d] + fisub word[esi+z3d] + fstp dword[ebx+vec_z] + +ret +end if +make_vector_r: + 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] + +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: + 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] +ret +;------------------in: ------------------------- +;------------------ esi - pointer to 1st vector +;------------------ edi - pointer to 2nd vector +;------------------out: ------------------------ +;------------------ st0 - dot-product +dot_product: + fninit + 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 +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 .siny + 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 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,2 - 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 - mov esi,envmap - call tex_triangle - - .end_draw: - pop esi - add esi,6 - cmp dword[esi],-1 - jne .again_dts -ret -translate_points: -; fninit -; mov ebx,points_rotated -; again_trans: -; fild word[ebx+4] ;z1 -; fmul [sq] -; fld st -; fiadd word[ebx] ;x1 -; fistp word[ebx] -; fchs -; fiadd word[ebx+2] ;y1 -; fistp word[ebx+2] ;y1 - -; add ebx,6 -; cmp dword[ebx],-1 -; jne again_trans -;ret -translate_perspective_points: ;translate points from 3d to 2d using - fninit ;perspective equations - mov ebx,points_rotated - .again_trans: - fild word[ebx] - fisub [xobs] - fimul [zobs] - fild word[ebx+4] - fisub [zobs] - fdivp - fiadd [xobs] - fistp word[ebx] - fild word[ebx+2] - fisub [yobs] - fimul [zobs] - fild word[ebx+4] - fisub [zobs] - fdivp - fchs - fiadd [yobs] - fistp word[ebx+2] - add ebx,6 - cmp dword[ebx],-1 - jne .again_trans -ret - - -copy_points: - mov esi,points - mov edi,points_rotated - mov ecx,points_count*3+2 - rep movsw -ret - - - -read_from_file: - mov edi,triangles - xor ebx,ebx - xor ebp,ebp - mov esi,SourceFile - cmp [esi],word 4D4Dh - jne .exit ;Must be legal .3DS file - cmp dword[esi+2],EndFile-SourceFile - jne .exit ;This must tell the length - 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] - mov [points_count_var],cx - mov edx,ecx - add esi,8 - @@: - fld dword[esi+4] - fmul [sscale] - fadd [xoffset] - fld dword[esi+8] - fchs - fmul [sscale] - fadd [yoffset] - fld dword[esi+0] - fchs - fmul [sscale] - fistp word[points+ebx+4] - fistp word[points+ebx+2] - fistp word[points+ebx+0] - add ebx,6 - add esi,12 - dec ecx - jnz @b - @@: - mov dword[points+ebx],-1 - @@: - cmp [esi],word 4120h - je @f - add esi,[esi+2] - jmp @b - @@: - movzx ecx,word[esi+6] - mov [triangles_count_var],cx - add esi,8 - ;mov edi,triangles - @@: - movsd - movsw - add word[edi-6],bp - add word[edi-4],bp - add word[edi-2],bp - add esi,2 - dec ecx - jnz @b - add ebp,edx - jmp .find4k - - .exit: - mov dword[edi],-1 -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 ebx,100*65536+SIZE_X+80 ; [x start] *65536 + [x size] - mov ecx,100*65536+SIZE_Y+30 ; [y start] *65536 + [y size] - mov edx,0x04000000 ; color of work area RRGGBB,8->color gl - mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl - mov edi,0x005080d0 ; color of frames RRGGBB - int 0x40 - - ; WINDOW LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,8*65536+8 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelt ; pointer to text beginning - mov esi,labellen-labelt ; text length - int 0x40 - - ; CLOSE BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+80-19)*65536+12 ; [x start] *65536 + [x size] - mov ecx,5*65536+12 ; [y start] *65536 + [y size] - mov edx,1 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ; ROTARY BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,25*65536+12 ; [y start] *65536 + [y size] - mov edx,2 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; ROTARY LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+28 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelrot ; pointer to text beginning - mov esi,labelrotend-labelrot ; text length - int 0x40 - - ; DRAW MODE BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15)*65536+12 ; [y start] *65536 + [y size] - mov edx,3 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; DRAW MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+28+15 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labeldrmod ; pointer to text beginning - mov esi,labeldrmodend-labeldrmod ; text length - int 0x40 - - ; SPEED BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*2)*65536+12 ; [y start] *65536 + [y size] - mov edx,4 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; SPEED MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*2) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelspeedmod ; pointer to text beginning - mov esi,labelspeedmodend-labelspeedmod ; text length - int 0x40 - - ; SCALE- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*3)*65536+12 ; [y start] *65536 + [y size] - mov edx,5 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; SCALE- MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*3) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzoomout ; pointer to text beginning - mov esi,labelzoomoutend-labelzoomout ; text length - int 0x40 - - ; SCALE+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*4)*65536+12 ; [y start] *65536 + [y size] - mov edx,6 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; SCALE+ MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*4) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzoomin ; pointer to text beginning - mov esi,labelzoominend-labelzoomin ; text length - int 0x40 - ; ADD VECTOR LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*5) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelvector ; pointer to text beginning - mov esi,labelvectorend-labelvector ; text length - int 0x40 - ; VECTOR Y- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*6)*65536+12 ; [y start] *65536 + [y size] - mov edx,7 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Y- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*6) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelyminus ; pointer to text beginning - mov esi,labelyminusend-labelyminus ; text length - int 0x40 - ; VECTOR Z+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*6)*65536+12 ; [y start] *65536 + [y size] - mov edx,8 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Z+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*6) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzplus ; pointer to text beginning - mov esi,labelzplusend-labelzplus ; text length - int 0x40 - ; VECTOR x- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*7)*65536+12 ; [y start] *65536 + [y size] - mov edx,9 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR x- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*7) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelxminus ; pointer to text beginning - mov esi,labelxminusend-labelxminus ; text length - int 0x40 - ; VECTOR x+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*7)*65536+12 ; [y start] *65536 + [y size] - mov edx,10 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR x+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*7) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelxplus ; pointer to text beginning - mov esi,labelxplusend-labelxplus ; text length - int 0x40 - ; VECTOR z- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*8)*65536+12 ; [y start] *65536 + [y size] - mov edx,11 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR z- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*8) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzminus ; pointer to text beginning - mov esi,labelzminusend-labelzminus ; text length - int 0x40 - ;VECTOR Y+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*8)*65536+12 ; [y start] *65536 + [y size] - mov edx,12 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Y+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*8) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelyplus ; pointer to text beginning - mov esi,labelyplusend-labelyplus ; text length - int 0x40 - ; LEAD COLOR LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*9) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelmaincolor ; pointer to text beginning - mov esi,labelmaincolorend-labelmaincolor ; text length - int 0x40 - - ;RED+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*10)*65536+12 ; [y start] *65536 + [y size] - mov edx,13 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;RED+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*10) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelredplus ; pointer to text beginning - mov esi,labelredplusend-labelredplus ; text length - int 0x40 - ;GREEN+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*10)*65536+12 ; [y start] *65536 + [y size] - mov edx,14 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;GREEN+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*10) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelgreenplus ; pointer to text beginning - mov esi,labelgreenplusend-labelgreenplus ; text length - int 0x40 - ;BLUE+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*10)*65536+12 ; [y start] *65536 + [y size] - mov edx,15 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;BLUE+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*10) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelblueplus ; pointer to text beginning - mov esi,labelblueplusend-labelblueplus ; text length - int 0x40 - ;RED- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*11)*65536+12 ; [y start] *65536 + [y size] - mov edx,16 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;RED- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*11) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelredminus ; pointer to text beginning - mov esi,labelredminusend-labelredminus ; text length - int 0x40 - ;GREEN- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*11)*65536+12 ; [y start] *65536 + [y size] - mov edx,17 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;GREEN- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*11) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelgreenminus ; pointer to text beginning - mov esi,labelgreenminusend-labelgreenminus ; text length - int 0x40 - ;BLUE- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*11)*65536+12 ; [y start] *65536 + [y size] - mov edx,18 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;BLUE- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*11) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelblueminus ; pointer to text beginning - mov esi,labelblueminusend-labelblueminus ; text length - int 0x40 - ; Catmull LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*12) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelcatmullmod ; pointer to text beginning - mov esi,labelcatmullmodend-labelcatmullmod ; text length - int 0x40 - ; on/off BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*13)*65536+12 ; [y start] *65536 + [y size] - mov edx,19 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; on/off LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*13) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelonoff ; pointer to text beginning - mov esi,labelonoffend-labelonoff ; text length - int 0x40 - - - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw - int 0x40 - - ret - - - ; DATA AREA - i3 dw 3 - light_vector dd 0.0,0.0,-1.0 - ; debug_vector dd 0.0,2.0,2.0 ;--debug - ; debug_vector1 dd 0.0,0.0,0.0 - ; debug_points dw 1,1,1,3,4,20 - ; debug_dd dw ? - ; debug_dwd dd 65535 - ; debug_counter dw 0 - dot_max dd 1.0 - dot_min dd 0.0 - env_const dd 1.2 - correct_tex dw 255 - max_color_r dw 255 - max_color_g dw 25 - max_color_b dw 35 - xobs dw SIZE_X / 2 ;200 ;observer - yobs dw SIZE_Y / 2 ;200 ;coordinates - zobs dw -500 - - - angle_counter dw 0 - piD180 dd 0.017453292519943295769236907684886 - ; sq dd 0.70710678118654752440084436210485 - const6 dw 6,6,6,6 - xo dw 130;87 - zo dw 0 - yo dw 100 - xoffset dd 130.0 - yoffset dd 150.0 - sscale dd 6.0 ; real scale - vect_x dw 0 - vect_y dw 0 - vect_z dw 0 - - - r_flag db 0 - dr_flag db 2 - speed_flag db 0 - catmull_flag db 0 - SourceFile file 'hrt.3ds' - EndFile: - labelrot: - db 'rot. mode' - labelrotend: - labeldrmod: - db 'shd. mode' - labeldrmodend: - labelspeedmod: - db 'spd. mode' - labelspeedmodend: - labelzoomout: - db 'zoom out' - labelzoomoutend: - labelzoomin: - db 'zoom in' - labelzoominend: - 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: - labelmaincolor: - db 'main color' - labelmaincolorend: - labelredplus: - db 'r +' - labelredplusend: - labelgreenplus: - db 'g +' - labelgreenplusend: - labelblueplus: - db 'b +' - labelblueplusend: - labelredminus: - db 'r -' - labelredminusend: - labelgreenminus: - db 'g -' - labelgreenminusend: - labelblueminus: - db 'b -' - labelblueminusend: - labelcatmullmod: - db 'catmull' - labelcatmullmodend: - labelonoff: - db 'on/off' - labelonoffend: - labelt: - db 'DEUS CARITAS EST' - if Ext=MMX - db ' (MMX)' - end if - labellen: - STRdata db '-1 ' -align 8 - @col dd ? - @y1 dw ? - @x1 dw ?;+8 - @y2 dw ? - @x2 dw ? - @y3 dw ? - @x3 dw ?;+16 - - @dx12 dd ? - @dx13 dd ?;+24 - @dx23 dd ? - - sinbeta dd ?;+32 - cosbeta dd ? - - xsub dw ? - zsub dw ?;+40 - ysub dw ? - - xx1 dw ? - yy1 dw ? - zz1 dw ?;+48 - xx2 dw ? - yy2 dw ? - zz2 dw ? - xx3 dw ?;+56 - yy3 dw ? - zz3 dw ? - scale dd ? ; help scale variable - ;screen dd ? ;pointer to screen buffer - triangles_count_var dw ? - points_count_var dw ? - - - point_index1 dw ? ;-\ - point_index2 dw ? ; } don't change order - point_index3 dw ? ;-/ - temp_col dw ? - high dd ? -align 8 - buffer dq ? - - err dd ? - drr dd ? - xx dd ? - yy dd ? - xst dd ? - yst dd ? -align 16 - points: - rw (EndFile-SourceFile)/12*3 - points_count = ($-points)/6 - triangles: - rw (EndFile-SourceFile)/12*3 - triangles_count = ($-triangles)/6 - -align 16 - points_rotated rw points_count*3 + 2 -align 16 - label trizdd dword - label trizdq qword - triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position -align 16 - triangles_normals rb triangles_count * 12 ; - point_normals rb points_count * 12 ;one 3dvector - triple float dword x,y,z -align 16 - point_normals_rotated rb points_count * 12 -align 16 - vectors rb 24 - points_color rb 6*points_count ; each color as word -; sorted_triangles rw triangles_count*3 + 2 -;align 16 - screen rb SIZE_X * SIZE_Y * 3 ; screen buffer - Z_buffer rb SIZE_X * SIZE_Y * 4 - envmap rb 512*512*3 - memStack rb 1000 ;memory area for stack - I_END: \ No newline at end of file diff --git a/programs/demos/3DS/3DSTPOT.ASM b/programs/demos/3DS/3DSTPOT.ASM deleted file mode 100644 index c57fef8f44..0000000000 --- a/programs/demos/3DS/3DSTPOT.ASM +++ /dev/null @@ -1,1991 +0,0 @@ -; -; application : Cruce - app shows three models shading -; compiler : FASM 1.65.13 -; system : KolibriOS/MenuetOS -; author : macgub -; email : macgub3@wp.pl -; web : www.menuet.xt.pl -; Fell free to use this intro in your own distribution of KolibriOS/MenuetOS. -; Special greetings to all MenuetOS maniax in the world. -; I hope because my intros 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 the program uses window style Y=4 - 19.10.2007, by Ataualpa - -SIZE_X equ 250 -SIZE_Y equ 250 -TIMEOUT equ 4 -ROUND equ 10 -TEX_X equ 512 ; texture width -TEX_Y equ 512 ; height -TEX_SHIFT equ 9 ; texture widith shifting -TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} -FLUENTLY = 0 -SHIFTING = 1 -;CATMULL_SHIFT equ 8 -NON = 0 -MMX = 1 - -Ext = MMX ;Ext={ NON | MMX} - -use32 - org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd I_END ; size of image - dd I_END ; memory for app - dd I_END ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - -START: ; start of execution - cld - ; call alloc_buffer_mem - call read_from_file - call init_triangles_normals - call init_point_normals - call init_envmap - call draw_window - - -still: - mov eax,23 ; wait here for event with timeout - mov ebx,TIMEOUT - cmp [speed_flag],1 - jne .skip - mov eax,11 - .skip: - int 0x40 - - cmp eax,1 ; redraw request ? - je red - cmp eax,2 ; key in buffer ? - je key - cmp eax,3 ; button in buffer ? - je button - - jmp noclose - - red: ; redraw - call draw_window - jmp noclose - - key: ; key - mov eax,2 ; just read it and ignore - int 0x40 - jmp noclose - - button: ; button - mov eax,17 ; get id - int 0x40 - - cmp ah,1 ; button id=1 ? - jne .ch_another - - mov eax,-1 ; close this program - int 0x40 - .ch_another: - cmp ah,2 - jne .ch_another1 - inc [r_flag] - cmp [r_flag],3 - jne noclose - mov [r_flag],0 - .ch_another1: - cmp ah,3 - jne .ch_another2 - inc [dr_flag] - cmp [dr_flag],3 - jne noclose - mov [dr_flag],0 - .ch_another2: - cmp ah,4 ; toggle speed - jne @f - inc [speed_flag] - cmp [speed_flag],2 - jne noclose - mov [speed_flag],0 - @@: - cmp ah,5 - jne @f ;scale- - mov [scale],0.7 - fninit - fld [sscale] - fmul [scale] - fstp [sscale] - call read_from_file - mov ax,[vect_x] ;-- last change - mov bx,[vect_y] - mov cx,[vect_z] - call add_vector -; call do_scale - @@: - cmp ah,6 - jne @f ; scale+ - mov [scale],1.3 - fninit - fld [sscale] - fmul [scale] - fstp [sscale] - call read_from_file - mov ax,[vect_x] - mov bx,[vect_y] - mov cx,[vect_z] - call add_vector - call init_triangles_normals - call init_point_normals - @@: - cmp ah,7 - jne @f - xor ax,ax ;add vector to object and rotary point - mov bx,-10 - xor cx,cx - call add_vector - sub [vect_y],10 - sub [yo],10 - @@: - cmp ah,8 - jne @f - xor ax,ax - xor bx,bx - mov cx,10 - call add_vector - add [vect_z],10 - add [zo],10 - @@: - cmp ah,9 - jne @f - mov ax,-10 - xor bx,bx - xor cx,cx - call add_vector - sub [vect_x],10 - sub [xo],10 - @@: - cmp ah,10 - jne @f - mov ax,10 - xor bx,bx - xor cx,cx - call add_vector - add [vect_x],10 - add [xo],10 - @@: - cmp ah,11 - jne @f - xor ax,ax - xor bx,bx - mov cx,-10 - call add_vector - sub [vect_z],10 - sub [zo],10 - @@: - cmp ah,12 - jne @f - xor ax,ax - mov bx,10 - xor cx,cx - call add_vector - add [vect_y],10 - add [yo],10 - @@: - cmp ah,13 ; change main color - - jne @f ; - lead color setting - cmp [max_color_r],245 - jge @f - add [max_color_r],10 - call init_envmap - @@: - cmp ah,14 - jne @f - cmp [max_color_g],245 - jge @f - add [max_color_g],10 - call init_envmap - @@: - cmp ah,15 - jne @f - cmp [max_color_b],245 - jge @f - add [max_color_b],10 - call init_envmap - @@: - cmp ah,16 ; change main color - jne @f - cmp [max_color_r],10 - jle @f - sub [max_color_r],10 - call init_envmap - @@: - cmp ah,17 - jne @f - cmp [max_color_g],10 - jle @f - sub [max_color_g],10 - call init_envmap - @@: - cmp ah,18 - jne @f - cmp [max_color_b],10 - jle @f - sub [max_color_b],10 - call init_envmap - @@: - cmp ah,19 - jne @f - inc [catmull_flag] - cmp [catmull_flag],2 - jne @f - mov [catmull_flag],0 - @@: - noclose: - - call calculate_angle ; calculates sinus and cosinus - call copy_point_normals - ; copy normals and rotate the copy using sin/cosbeta - best way - call rotate_point_normals - call calculate_colors - call copy_points - call rotate_points - call translate_perspective_points; translate from 3d to 2d - call clrscr ; clear the screen - cmp [dr_flag],2 - je @f - cmp [catmull_flag],1 ;if env_mapping sort faces - je @f - @@: - call sort_triangles - @@: - call fill_Z_buffer - - RDTSC - push eax - call draw_triangles ; draw all triangles from the list - - RDTSC - sub eax,[esp] - sub eax,41 - ; lea esi,[debug_points] - ; lea edi,[debug_points+6] - ; lea ebx,[debug_vector1] - ; call make_vector - ; fninit - ; fld [sinbeta_one] - ; fimul [debug_dwd] - ; fistp [debug_dd] - ; movzx eax,[debug_dd] - - - mov ecx,10 - .dc: - xor edx,edx - mov edi,10 - div edi - add dl,30h - mov [STRdata+ecx-1],dl - loop .dc - pop eax -macro show -{ - mov eax,7 ; put image - mov ebx,screen - mov ecx,SIZE_X shl 16 + SIZE_Y - mov edx,5 shl 16 + 20 - int 0x40 -} - show - mov eax,4 ; function 4 : write text to window - mov ebx,5*65536+23 ; [x start] *65536 + [y start] - mov ecx,-1 - mov edx,STRdata ; pointer to text beginning - mov esi,10 ; text length - int 40h - - - - jmp still - -;-------------------------------------------------------------------------------- -;-------------------------PROCEDURES--------------------------------------------- -;-------------------------------------------------------------------------------- -include "tex3.asm" -include "flat_cat.asm" -include "grd_cat.asm" -include "3dmath.asm" -include "grd3.asm" -include "flat3.asm" - - -;alloc_buffer_mem: -; mov eax,68 -; mov ebx,5 -; mov ecx,SIZE_X*SIZE_Y*3 -; int 0x40 -; mov [screen],eax -;ret -init_envmap: - -.temp equ word [ebp-2] - push ebp - mov ebp,esp - sub esp,2 - mov edi,envmap - fninit - - mov dx,-256 - .ie_ver: - mov cx,-256 - .ie_hor: - mov .temp,cx - fild .temp - fmul st,st0 - mov .temp,dx - fild .temp - fmul st,st0 - faddp - fsqrt - mov .temp,254 - 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,254 - jle .ie_ok2 - mov ax,254 - .ie_ok2: - push dx - mov bx,ax - mul [max_color_b] - shr ax,8 - stosb - mov ax,bx - mul [max_color_g] - shr ax,8 - stosb - mov ax,bx - mul [max_color_r] - shr ax,8 - stosb - pop dx - - inc cx - cmp cx,256 - jne .ie_hor - - inc dx - cmp dx,256 - jne .ie_ver - - mov esp,ebp - pop ebp -macro debug -{ - mov edi,envmap - mov ecx,512*512*3/4 - mov eax,0xffffffff - rep stosd -} -ret -calculate_colors: - fninit - xor ebx,ebx - movzx ecx,[points_count_var] - lea ecx,[ecx*3] - add ecx,ecx - .cc_again: - mov esi,light_vector - lea edi,[point_normals_rotated+ebx*2] - call dot_product - fcom [dot_min] - fstsw ax - sahf - ja .cc_ok1 - ffree st - mov dword[points_color+ebx],0 - mov word[points_color+ebx+4],0 - add ebx,6 - cmp ebx,ecx - jne .cc_again - jmp .cc_done - .cc_ok1: - fcom [dot_max] - fstsw ax - sahf - jb .cc_ok2 - ffree st - mov dword[points_color+ebx],0 ; clear r,g,b - mov word[points_color+ebx+4],0 - add ebx,6 - cmp ebx,ecx - jne .cc_again - jmp .cc_done - .cc_ok2: - fld st - fld st - fimul [max_color_r] - fistp word[points_color+ebx] ;each color as word - fimul [max_color_g] - fistp word[points_color+ebx+2] - fimul [max_color_b] - fistp word[points_color+ebx+4] - add ebx,6 - cmp ebx,ecx - jne .cc_again - .cc_done: -ret -copy_point_normals: - movzx ecx,[points_count_var] - shl ecx,2 - inc ecx - mov esi,point_normals - mov edi,point_normals_rotated - rep movsd -ret -rotate_point_normals: - movzx ecx,[points_count_var] - mov ebx,point_normals_rotated - fninit ; for now only rotate around Z axle - .again_r: - cmp [r_flag],1 - je .z_rot - cmp [r_flag],2 - je .x_rot - - .y_rot: - fld dword[ebx] ; x - fld [sinbeta] - fmul dword[ebx+8] ; z * sinbeta - fchs - fld [cosbeta] - fmul dword[ebx] ; x * cosbeta - faddp - fstp dword[ebx] ; new x - fmul [sinbeta] ; old x * sinbeta - fld [cosbeta] - fmul dword[ebx+8] ; z * cosbeta - faddp - fstp dword[ebx+8] ; new z - add ebx,12 - loop .y_rot - jmp .end_rot - .z_rot: - fld dword[ebx] ;x - fld [sinbeta] - fmul dword[ebx+4] ;y - fld [cosbeta] - fmul dword[ebx] ;x - faddp - fstp dword[ebx] ;new x - fmul [sinbeta] ; sinbeta * old x - fchs - fld [cosbeta] - fmul dword[ebx+4] ; cosbeta * y - faddp - fstp dword[ebx+4] ; new y - add ebx,12 - loop .z_rot - jmp .end_rot - .x_rot: - fld dword[ebx+4] ;y - fld [sinbeta] - fmul dword[ebx+8] ;z - fld [cosbeta] - fmul dword[ebx+4] ;y - faddp - fstp dword[ebx+4] ; new y - fmul [sinbeta] ; sinbeta * old y - fchs - fld [cosbeta] - fmul dword[ebx+8] - faddp - fstp dword[ebx+8] - add ebx,12 - loop .x_rot - .end_rot: -ret -init_triangles_normals: - mov ebx,triangles_normals - mov ebp,triangles - @@: - push ebx - mov ebx,vectors - movzx esi,word[ebp] ; first point index - lea esi,[esi*3] - lea esi,[points+esi*2] ; esi - pointer to 1st 3d point - 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 - add ebx,12 - mov esi,edi - movzx edi,word[ebp+4] ; third point index - lea edi,[edi*3] - lea edi,[points+edi*2] - call make_vector - 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,6 - add ebx,12 - cmp dword[ebp],-1 - jne @b -ret - -init_point_normals: -.x equ dword [ebp-4] -.y equ dword [ebp-8] -.z equ dword [ebp-12] -.point_number equ word [ebp-26] -.hit_faces equ word [ebp-28] - - fninit - mov ebp,esp - sub esp,28 - mov edi,point_normals - mov .point_number,0 - .ipn_loop: - mov .hit_faces,0 - mov .x,0 - mov .y,0 - mov .z,0 - mov esi,triangles - xor ecx,ecx ; ecx - triangle number - .ipn_check_face: - xor ebx,ebx ; ebx - 'position' in one triangle - .ipn_check_vertex: - movzx eax,word[esi+ebx] ; eax - point_number - cmp ax,.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 - - fld .x - fadd dword[esi+vec_x] - fstp .x - 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,2 - cmp ebx,6 - jne .ipn_check_vertex - .ipn_next_face: - add esi,6 - inc ecx - cmp cx,[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 dx,.point_number - cmp dx,[points_count_var] - jne .ipn_loop - - mov esp,ebp -ret - -add_vector: - mov ebp,points - @@: - add word[ebp],ax - add word[ebp+2],bx - add word[ebp+4],cx - add ebp,6 - cmp dword[ebp],-1 - jne @b -ret -;do_scale: -; fninit -; mov ebp,points -; .next_sc: -; fld1 -; fsub [scale] -; fld st -; fimul [xo] -; fld [scale] -; fimul word[ebp] ;x -; faddp -; fistp word[ebp] -; fld st -; fimul [yo] -; fld [scale] -; fimul word[ebp+2] -; faddp -; fistp word[ebp+2] -; fimul [zo] -; fld [scale] -; fimul word[ebp+4] -; faddp -; fistp word[ebp+4] -; add ebp,6 -; cmp dword[ebp],-1 -; jne .next_sc -;ret -sort_triangles: - mov esi,triangles - mov edi,triangles_with_z - mov ebp,points_rotated - - make_triangle_with_z: ;makes list with triangles and z position - movzx eax,word[esi] - lea eax,[eax*3] - movzx ecx,word[ebp+eax*2+4] - - movzx eax,word[esi+2] - lea eax,[eax*3] - add cx,word[ebp+eax*2+4] - - movzx eax,word[esi+4] - lea eax,[eax*3] - add cx,word[ebp+eax*2+4] - - mov ax,cx - ; cwd - ; idiv word[i3] - movsd ; store vertex coordinates - movsw - stosw ; middle vertex coordinate 'z' in triangles_with_z list - cmp dword[esi],-1 - jne make_triangle_with_z - movsd ; copy end mark - mov eax,4 - lea edx,[edi-8-trizdd] - mov [high],edx - call quicksort - mov eax,4 - mov edx,[high] - call insertsort - jmp end_sort - - quicksort: - mov ecx,edx - sub ecx,eax - cmp ecx,32 - jc .exit - lea ecx,[eax+edx] - shr ecx,4 - lea ecx,[ecx*8-4]; i - mov ebx,[trizdd+eax]; trizdd[l] - mov esi,[trizdd+ecx]; trizdd[i] - mov edi,[trizdd+edx]; trizdd[h] - cmp ebx,esi - jg @f ; direction NB! you need to negate these to invert the order - if Ext=NON - mov [trizdd+eax],esi - mov [trizdd+ecx],ebx - mov ebx,[trizdd+eax-4] - mov esi,[trizdd+ecx-4] - mov [trizdd+eax-4],esi - mov [trizdd+ecx-4],ebx - mov ebx,[trizdd+eax] - mov esi,[trizdd+ecx] - else - movq mm0,[trizdq+eax-4] - movq mm1,[trizdq+ecx-4] - movq [trizdq+ecx-4],mm0 - movq [trizdq+eax-4],mm1 - xchg ebx,esi - end if - @@: - cmp ebx,edi - jg @f ; direction - if Ext=NON - mov [trizdd+eax],edi - mov [trizdd+edx],ebx - mov ebx,[trizdd+eax-4] - mov edi,[trizdd+edx-4] - mov [trizdd+eax-4],edi - mov [trizdd+edx-4],ebx - mov ebx,[trizdd+eax] - mov edi,[trizdd+edx] - else - movq mm0,[trizdq+eax-4] - movq mm1,[trizdq+edx-4] - movq [trizdq+edx-4],mm0 - movq [trizdq+eax-4],mm1 - xchg ebx,edi - end if - @@: - cmp esi,edi - jg @f ; direction - if Ext=NON - mov [trizdd+ecx],edi - mov [trizdd+edx],esi - mov esi,[trizdd+ecx-4] - mov edi,[trizdd+edx-4] - mov [trizdd+ecx-4],edi - mov [trizdd+edx-4],esi - else - movq mm0,[trizdq+ecx-4] - movq mm1,[trizdq+edx-4] - movq [trizdq+edx-4],mm0 - movq [trizdq+ecx-4],mm1 -; xchg ebx,esi - end if - @@: - mov ebp,eax ; direction - add ebp,8 ; j - if Ext=NON - mov esi,[trizdd+ebp] - mov edi,[trizdd+ecx] - mov [trizdd+ebp],edi - mov [trizdd+ecx],esi - mov esi,[trizdd+ebp-4] - mov edi,[trizdd+ecx-4] - mov [trizdd+ecx-4],esi - mov [trizdd+ebp-4],edi - else - movq mm0,[trizdq+ebp-4] - movq mm1,[trizdq+ecx-4] - movq [trizdq+ecx-4],mm0 - movq [trizdq+ebp-4],mm1 - end if - mov ecx,edx ; i; direction - mov ebx,[trizdd+ebp]; trizdd[j] - .loop: - sub ecx,8 ; direction - cmp [trizdd+ecx],ebx - jl .loop ; direction - @@: - add ebp,8 ; direction - cmp [trizdd+ebp],ebx - jg @b ; direction - cmp ebp,ecx - jge @f ; direction - if Ext=NON - mov esi,[trizdd+ecx] - mov edi,[trizdd+ebp] - mov [trizdd+ebp],esi - mov [trizdd+ecx],edi - mov edi,[trizdd+ecx-4] - mov esi,[trizdd+ebp-4] - mov [trizdd+ebp-4],edi - mov [trizdd+ecx-4],esi - else - movq mm0,[trizdq+ecx-4] - movq mm1,[trizdq+ebp-4] - movq [trizdq+ebp-4],mm0 - movq [trizdq+ecx-4],mm1 - end if - jmp .loop - @@: - if Ext=NON - mov esi,[trizdd+ecx] - mov edi,[trizdd+eax+8] - mov [trizdd+eax+8],esi - mov [trizdd+ecx],edi - mov edi,[trizdd+ecx-4] - mov esi,[trizdd+eax+4] - mov [trizdd+eax+4],edi - mov [trizdd+ecx-4],esi - else - movq mm0,[trizdq+ecx-4] - movq mm1,[trizdq+eax+4]; dir - movq [trizdq+eax+4],mm0; dir - movq [trizdq+ecx-4],mm1 - end if - add ecx,8 - push ecx edx - mov edx,ebp - call quicksort - pop edx eax - call quicksort - .exit: - ret - insertsort: - mov esi,eax - .start: - add esi,8 - cmp esi,edx - ja .exit - mov ebx,[trizdd+esi] - if Ext=NON - mov ecx,[trizdd+esi-4] - else - movq mm1,[trizdq+esi-4] - end if - mov edi,esi - @@: - cmp edi,eax - jna @f - cmp [trizdd+edi-8],ebx - jg @f ; direction - if Ext=NON - mov ebp,[trizdd+edi-8] - mov [trizdd+edi],ebp - mov ebp,[trizdd+edi-12] - mov [trizdd+edi-4],ebp - else - movq mm0,[trizdq+edi-12] - movq [trizdq+edi-4],mm0 - end if - sub edi,8 - jmp @b - @@: - if Ext=NON - mov [trizdd+edi],ebx - mov [trizdd+edi-4],ecx - else - movq [trizdq+edi-4],mm1 - end if - jmp .start - .exit: - ret - end_sort: - ; translate triangles_with_z to sorted_triangles - mov esi,triangles_with_z - ; mov edi,sorted_triangles - mov edi,triangles - again_copy: - if Ext=NON - movsd - movsw - add esi,2 - else - movq mm0,[esi] - movq [edi],mm0 - add esi,8 - add edi,6 - end if - cmp dword[esi],-1 - jne again_copy -; if Ext=MMX -; emms -; end if - movsd ; copy end mark too -ret - -clrscr: - mov edi,screen - mov ecx,SIZE_X*SIZE_Y*3/4 - xor eax,eax - if Ext=NON - rep stosd - else - 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 - end if -ret - -calculate_angle: - fninit -; fldpi -; fidiv [i180] - fld [piD180] - fimul [angle_counter] - fsincos - fstp [sinbeta] - fstp [cosbeta] - inc [angle_counter] - cmp [angle_counter],360 - jne end_calc_angle - mov [angle_counter],0 - end_calc_angle: -ret - -rotate_points: - fninit - mov ebx,points_rotated - again_r: - cmp [r_flag],1 - je .z_rot - cmp [r_flag],2 - je .x_rot - .y_rot: - mov eax,[ebx+2] ;z - mov ax,word[ebx] ;x - sub eax,dword[xo] - mov dword[xsub],eax - fld [sinbeta] - fimul [zsub] - fchs - fld [cosbeta] - fimul [xsub] - faddp - fiadd [xo] - fistp word[ebx] ;x - fld [sinbeta] - fimul [xsub] - fld [cosbeta] - fimul [zsub] - faddp - fiadd [zo] - fistp word[ebx+4] ;z - jmp .end_rot - .z_rot: - mov ax,word[ebx] - sub ax,word[xo] ;need optimization - mov [xsub],ax - mov ax,word[ebx+2] - sub ax,word[yo] - mov [ysub],ax - fld [sinbeta] - fimul [ysub] - fld [cosbeta] - fimul [xsub] - faddp - fiadd [xo] - fistp word[ebx] - fld [cosbeta] - fimul [ysub] - fld [sinbeta] - fimul [xsub] - fchs - faddp - fiadd [yo] - fistp word[ebx+2] - jmp .end_rot - .x_rot: - mov ax,word[ebx+2] - sub ax,[yo] - mov [ysub],ax - mov ax,word[ebx+4] - sub ax,word[zo] - mov [zsub],ax - fld [sinbeta] - fimul [zsub] - fld [cosbeta] - fimul [ysub] - faddp - fiadd [yo] - fistp word[ebx+2];y - fld [cosbeta] - fimul [zsub] - fld [sinbeta] - fimul [ysub] - fchs - faddp - fiadd [zo] - fistp word[ebx+4] - .end_rot: - add ebx,6 - cmp dword[ebx],-1 - jne again_r -ret - -draw_triangles: - mov esi,triangles - .again_dts: - mov ebp,points_rotated - if Ext=NON - movzx eax,word[esi] - mov [point_index1],ax - lea eax,[eax*3] - add eax,eax - push ebp - add ebp,eax - mov eax,[ebp] - mov dword[xx1],eax - mov eax,[ebp+4] - mov [zz1],ax - pop ebp - - - movzx eax,word[esi+2] - mov [point_index2],ax - 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 - - - movzx eax,word[esi+4] ; xyz3 = [ebp+[esi+4]*6] - mov [point_index3],ax - 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 - mov eax,dword[esi] ; don't know MMX - mov dword[point_index1],eax - ; shr eax,16 - ; mov [point_index2],ax - mov ax,word[esi+4] - mov [point_index3],ax - movq mm0,[esi] - pmullw mm0,qword[const6] - movd eax,mm0 - psrlq mm0,16 - movd ebx,mm0 - psrlq mm0,16 - movd ecx,mm0 - 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 - push esi - ; culling - fninit - mov esi,point_index1 - mov ecx,3 - @@: - movzx eax,word[esi] - lea eax,[eax*3] - shl eax,2 - lea eax,[eax+point_normals_rotated] - fld dword[eax+8] - ftst - fstsw ax - sahf - jb @f - ffree st - loop @b - jmp .end_draw - @@: - ffree st ;is visable - - cmp [dr_flag],0 ; draw type flag - je .flat_draw - cmp [dr_flag],2 - je .env_mapping - - movzx edi,[point_index3] - lea edi,[edi*3] - lea edi,[points_color+edi*2] - cmp [catmull_flag],0 - je @f - push [zz3] - @@: - push word[edi] - push word[edi+2] - push word[edi+4] - movzx edi,[point_index2] - lea edi,[edi*3] - lea edi,[points_color+edi*2] - cmp [catmull_flag],0 - je @f - push [zz2] - @@: - push word[edi] - push word[edi+2] - push word[edi+4] - movzx edi,[point_index1] - lea edi,[edi*3] - lea edi,[points_color+edi*2] - cmp [catmull_flag],0 - je @f - push [zz1] - @@: - push word[edi] - push word[edi+2] - push word[edi+4] - - ; 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 [max_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 [max_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 [max_color_r] - ; fistp [temp_col] - ; and [temp_col],0x00ff - ; push [temp_col] - ; push [temp_col] - ; push [temp_col] - -; xor edx,edx ; draw acording to position -; mov ax,[zz3] -; add ax,128 -; neg al -; and ax,0x00ff -; push ax -; neg al -; push ax -; mov dx,[yy3] -; and dx,0x00ff -; push dx -; mov ax,[zz2] -; add ax,128 -; neg al -; and ax,0x00ff -; push ax -; neg al -; push ax -; mov dx,[yy2] -; and dx,0x00ff -; push dx -; mov ax,[zz1] -; add ax,128 -; neg al -; and ax,0x00ff -; push ax -; neg al -; push ax -; mov dx,[yy1] -; and dx,0x00ff -; push dx - mov eax,dword[xx1] - ror eax,16 - mov ebx,dword[xx2] - ror ebx,16 - mov ecx,dword[xx3] - ror ecx,16 - lea edi,[screen] - cmp [catmull_flag],0 - je @f - lea esi,[Z_buffer] - call gouraud_triangle_z - jmp .end_draw - @@: - call gouraud_triangle - jmp .end_draw - .flat_draw: - - movzx edi,[point_index3] - lea edi,[edi*3] - lea edi,[points_color+edi*2] - movzx eax,word[edi] - movzx ebx,word[edi+2] - movzx ecx,word[edi+4] - movzx edi,[point_index2] - lea edi,[edi*3] - lea edi,[points_color+edi*2] - add ax,word[edi] - add bx,word[edi+2] - add cx,word[edi+4] - movzx edi,[point_index1] - lea edi,[edi*3] - lea edi,[points_color+edi*2] - add ax,word[edi] - add bx,word[edi+2] - add cx,word[edi+4] - cwd - idiv [i3] - mov di,ax - shl edi,16 - mov ax,bx - cwd - idiv [i3] - mov di,ax - shl di,8 - mov ax,cx - cwd - idiv [i3] - mov edx,edi - mov dl,al - and edx,0x00ffffff - - - ; 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 - lea edi,[screen] - cmp [catmull_flag],0 - je @f - lea esi,[Z_buffer] - push word[zz3] - push word[zz2] - push word[zz1] - call flat_triangle_z - jmp .end_draw - @@: - call draw_triangle - jmp .end_draw - .env_mapping: - ; fninit - mov esi,point_index1 - sub esp,12 - mov edi,esp - mov ecx,3 - @@: - movzx eax,word[esi] - lea eax,[eax*3] - shl eax,2 - add eax,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,2 - 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 - mov esi,envmap - call tex_triangle - - .end_draw: - pop esi - add esi,6 - cmp dword[esi],-1 - jne .again_dts -ret -translate_points: -; fninit -; mov ebx,points_rotated -; again_trans: -; fild word[ebx+4] ;z1 -; fmul [sq] -; fld st -; fiadd word[ebx] ;x1 -; fistp word[ebx] -; fchs -; fiadd word[ebx+2] ;y1 -; fistp word[ebx+2] ;y1 - -; add ebx,6 -; cmp dword[ebx],-1 -; jne again_trans -;ret -translate_perspective_points: ;translate points from 3d to 2d using - fninit ;perspective equations - mov ebx,points_rotated - .again_trans: - fild word[ebx] - fisub [xobs] - fimul [zobs] - fild word[ebx+4] - fisub [zobs] - fdivp - fiadd [xobs] - fistp word[ebx] - fild word[ebx+2] - fisub [yobs] - fimul [zobs] - fild word[ebx+4] - fisub [zobs] - fdivp - fchs - fiadd [yobs] - fistp word[ebx+2] - add ebx,6 - cmp dword[ebx],-1 - jne .again_trans -ret - - -copy_points: - mov esi,points - mov edi,points_rotated - mov ecx,points_count*3+2 - rep movsw -ret - - - -read_from_file: - mov edi,triangles - xor ebx,ebx - xor ebp,ebp - mov esi,SourceFile - cmp [esi],word 4D4Dh - jne .exit ;Must be legal .3DS file - cmp dword[esi+2],EndFile-SourceFile - jne .exit ;This must tell the length - 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] - mov [points_count_var],cx - mov edx,ecx - add esi,8 - @@: - fld dword[esi+4] - fmul [sscale] - fadd [xoffset] - fld dword[esi+8] - fchs - fmul [sscale] - fadd [yoffset] - fld dword[esi+0] - fchs - fmul [sscale] - fistp word[points+ebx+4] - fistp word[points+ebx+2] - fistp word[points+ebx+0] - add ebx,6 - add esi,12 - dec ecx - jnz @b - @@: - mov dword[points+ebx],-1 - @@: - cmp [esi],word 4120h - je @f - add esi,[esi+2] - jmp @b - @@: - movzx ecx,word[esi+6] - mov [triangles_count_var],cx - add esi,8 - ;mov edi,triangles - @@: - movsd - movsw - add word[edi-6],bp - add word[edi-4],bp - add word[edi-2],bp - add esi,2 - dec ecx - jnz @b - add ebp,edx - jmp .find4k - - .exit: - mov dword[edi],-1 -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 ebx,100*65536+SIZE_X+80 ; [x start] *65536 + [x size] - mov ecx,100*65536+SIZE_Y+30 ; [y start] *65536 + [y size] - mov edx,0x04000000 ; color of work area RRGGBB,8->color gl - mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl - mov edi,0x005080d0 ; color of frames RRGGBB - int 0x40 - - ; WINDOW LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,8*65536+8 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelt ; pointer to text beginning - mov esi,labellen-labelt ; text length - int 0x40 - - ; ROTARY BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,25*65536+12 ; [y start] *65536 + [y size] - mov edx,2 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ; ROTARY LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+28 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelrot ; pointer to text beginning - mov esi,labelrotend-labelrot ; text length - int 0x40 - - ; DRAW MODE BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15)*65536+12 ; [y start] *65536 + [y size] - mov edx,3 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ; DRAW MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+28+15 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labeldrmod ; pointer to text beginning - mov esi,labeldrmodend-labeldrmod ; text length - int 0x40 - - ; SPEED BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*2)*65536+12 ; [y start] *65536 + [y size] - mov edx,4 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ; SPEED MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*2) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelspeedmod ; pointer to text beginning - mov esi,labelspeedmodend-labelspeedmod ; text length - int 0x40 - - ; SCALE- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*3)*65536+12 ; [y start] *65536 + [y size] - mov edx,5 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ; SCALE- MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*3) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzoomout ; pointer to text beginning - mov esi,labelzoomoutend-labelzoomout ; text length - int 0x40 - - ; SCALE+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*4)*65536+12 ; [y start] *65536 + [y size] - mov edx,6 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ; SCALE+ MODE LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*4) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzoomin ; pointer to text beginning - mov esi,labelzoominend-labelzoomin ; text length - int 0x40 - - ; ADD VECTOR LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*5) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelvector ; pointer to text beginning - mov esi,labelvectorend-labelvector ; text length - int 0x40 - - ; VECTOR Y- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*6)*65536+12 ; [y start] *65536 + [y size] - mov edx,7 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ;VECTOR Y- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*6) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelyminus ; pointer to text beginning - mov esi,labelyminusend-labelyminus ; text length - int 0x40 - - ; VECTOR Z+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*6)*65536+12 ; [y start] *65536 + [y size] - mov edx,8 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ;VECTOR Z+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*6) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzplus ; pointer to text beginning - mov esi,labelzplusend-labelzplus ; text length - int 0x40 - - ; VECTOR x- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*7)*65536+12 ; [y start] *65536 + [y size] - mov edx,9 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - - ;VECTOR x- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*7) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelxminus ; pointer to text beginning - mov esi,labelxminusend-labelxminus ; text length - int 0x40 - ; VECTOR x+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*7)*65536+12 ; [y start] *65536 + [y size] - mov edx,10 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR x+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*7) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelxplus ; pointer to text beginning - mov esi,labelxplusend-labelxplus ; text length - int 0x40 - ; VECTOR z- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*8)*65536+12 ; [y start] *65536 + [y size] - mov edx,11 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR z- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*8) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelzminus ; pointer to text beginning - mov esi,labelzminusend-labelzminus ; text length - int 0x40 - ;VECTOR Y+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*8)*65536+12 ; [y start] *65536 + [y size] - mov edx,12 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;VECTOR Y+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*8) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelyplus ; pointer to text beginning - mov esi,labelyplusend-labelyplus ; text length - int 0x40 - ; LEAD COLOR LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*9) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelmaincolor ; pointer to text beginning - mov esi,labelmaincolorend-labelmaincolor ; text length - int 0x40 - - ;RED+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*10)*65536+12 ; [y start] *65536 + [y size] - mov edx,13 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;RED+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*10) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelredplus ; pointer to text beginning - mov esi,labelredplusend-labelredplus ; text length - int 0x40 - ;GREEN+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*10)*65536+12 ; [y start] *65536 + [y size] - mov edx,14 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;GREEN+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*10) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelgreenplus ; pointer to text beginning - mov esi,labelgreenplusend-labelgreenplus ; text length - int 0x40 - ;BLUE+ BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*10)*65536+12 ; [y start] *65536 + [y size] - mov edx,15 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;BLUE+ LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*10) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelblueplus ; pointer to text beginning - mov esi,labelblueplusend-labelblueplus ; text length - int 0x40 - ;RED- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*11)*65536+12 ; [y start] *65536 + [y size] - mov edx,16 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;RED- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*11) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelredminus ; pointer to text beginning - mov esi,labelredminusend-labelredminus ; text length - int 0x40 - ;GREEN- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+20)*65536+62-42 ; [x start] *65536 + [x size] - mov ecx,(25+15*11)*65536+12 ; [y start] *65536 + [y size] - mov edx,17 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;GREEN- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+20)*65536+(28+15*11) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelgreenminus ; pointer to text beginning - mov esi,labelgreenminusend-labelgreenminus ; text length - int 0x40 - ;BLUE- BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10+41)*65536+62-41 ; [x start] *65536 + [x size] - mov ecx,(25+15*11)*65536+12 ; [y start] *65536 + [y size] - mov edx,18 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ;BLUE- LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12+41)*65536+(28+15*11) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelblueminus ; pointer to text beginning - mov esi,labelblueminusend-labelblueminus ; text length - int 0x40 - ; Catmull LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*12) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelcatmullmod ; pointer to text beginning - mov esi,labelcatmullmodend-labelcatmullmod ; text length - int 0x40 - ; on/off BUTTON - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X+10)*65536+62 ; [x start] *65536 + [x size] - mov ecx,(25+15*13)*65536+12 ; [y start] *65536 + [y size] - mov edx,19 ; button id - mov esi,0x6688dd ; button color RRGGBB - int 0x40 - ; on/off LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,(SIZE_X+12)*65536+(28+15*13) ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelonoff ; pointer to text beginning - mov esi,labelonoffend-labelonoff ; text length - int 0x40 - - - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw - int 0x40 - - ret - - - ; DATA AREA - i3 dw 3 - light_vector dd 0.0,0.0,-1.0 - ; debug_vector dd 0.0,2.0,2.0 ;--debug - ; debug_vector1 dd 0.0,0.0,0.0 - ; debug_points dw 1,1,1,3,4,20 - ; debug_dd dw ? - ; debug_dwd dd 65535 - ; debug_counter dw 0 - dot_max dd 1.0 - dot_min dd 0.0 - env_const dd 1.2 - correct_tex dw 255 - max_color_r dw 33 - max_color_g dw 255 - max_color_b dw 110 - xobs dw SIZE_X / 2 ;200 ;observer - yobs dw SIZE_Y / 2 ;200 ;coordinates - zobs dw -500 - - - angle_counter dw 0 - piD180 dd 0.017453292519943295769236907684886 - ; sq dd 0.70710678118654752440084436210485 - const6 dw 6,6,6,6 - xo dw 130;87 - zo dw 0 - yo dw 100 - xoffset dd 130.0 - yoffset dd 150.0 - sscale dd 2.0 ; real scale - vect_x dw 0 - vect_y dw 0 - vect_z dw 0 - - - r_flag db 0 - dr_flag db 0 - speed_flag db 0 - catmull_flag db 0 - SourceFile file 'teapot.3ds' - EndFile: - labelrot: - db 'rot. mode' - labelrotend: - labeldrmod: - db 'shd. mode' - labeldrmodend: - labelspeedmod: - db 'spd. mode' - labelspeedmodend: - labelzoomout: - db 'zoom out' - labelzoomoutend: - labelzoomin: - db 'zoom in' - labelzoominend: - 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: - labelmaincolor: - db 'main color' - labelmaincolorend: - labelredplus: - db 'r +' - labelredplusend: - labelgreenplus: - db 'g +' - labelgreenplusend: - labelblueplus: - db 'b +' - labelblueplusend: - labelredminus: - db 'r -' - labelredminusend: - labelgreenminus: - db 'g -' - labelgreenminusend: - labelblueminus: - db 'b -' - labelblueminusend: - labelcatmullmod: - db 'catmull' - labelcatmullmodend: - labelonoff: - db 'on/off' - labelonoffend: - labelt: - db 'AVE CRUCE SALUS MEA' - if Ext=MMX - db ' (MMX)' - end if - labellen: - STRdata db '-1 ' -align 8 - @col dd ? - @y1 dw ? - @x1 dw ?;+8 - @y2 dw ? - @x2 dw ? - @y3 dw ? - @x3 dw ?;+16 - - @dx12 dd ? - @dx13 dd ?;+24 - @dx23 dd ? - - sinbeta dd ?;+32 - cosbeta dd ? - - xsub dw ? - zsub dw ?;+40 - ysub dw ? - - xx1 dw ? - yy1 dw ? - zz1 dw ?;+48 - xx2 dw ? - yy2 dw ? - zz2 dw ? - xx3 dw ?;+56 - yy3 dw ? - zz3 dw ? - scale dd ? ; help scale variable - ;screen dd ? ;pointer to screen buffer - triangles_count_var dw ? - points_count_var dw ? - - - point_index1 dw ? ;-\ - point_index2 dw ? ; } don't change order - point_index3 dw ? ;-/ - temp_col dw ? - high dd ? -align 8 - buffer dq ? - - err dd ? - drr dd ? - xx dd ? - yy dd ? - xst dd ? - yst dd ? -align 16 - points: - rw (EndFile-SourceFile)/12*3 - points_count = ($-points)/6 - triangles: - rw (EndFile-SourceFile)/12*3 - triangles_count = ($-triangles)/6 - -align 16 - points_rotated rw points_count*3 + 2 -align 16 - label trizdd dword - label trizdq qword - triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position -align 16 - triangles_normals rb triangles_count * 12 ; - point_normals rb points_count * 12 ;one 3dvector - triple float dword x,y,z -align 16 - point_normals_rotated rb points_count * 12 -align 16 - vectors rb 24 - points_color rb 6*points_count ; each color as word -; sorted_triangles rw triangles_count*3 + 2 -;align 16 - screen rb SIZE_X * SIZE_Y * 3 ; screen buffer - Z_buffer rb SIZE_X * SIZE_Y * 4 - envmap rb 512*512*3 - memStack rb 1000 ;memory area for stack - I_END: \ No newline at end of file diff --git a/programs/demos/3DS/3dspiral.asm b/programs/demos/3DS/3dspiral.asm deleted file mode 100644 index dae8a7f1ad..0000000000 --- a/programs/demos/3DS/3dspiral.asm +++ /dev/null @@ -1,440 +0,0 @@ -; -; application : 3d shaking waved spiral -; compilator : fasm -; system : MenuetOS -; author : macgub -; email : macgub3@wp - -timeout equ 3 -maxx equ 600 ; window size -maxy equ 420 -use32 - - org 0x0 - - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd I_END ; size of image - dd 0x100000 ; memory for app - dd 0xbffff ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - -START: ; start of execution - - call draw_window - -still: - -; mov eax,23 ; wait here for event -; mov ebx,timeout -; int 0x40 - mov eax,11 ; check for event no wait - int 0x40 - - cmp eax,1 ; redraw request ? - je red - cmp eax,2 ; key in buffer ? - je key - cmp eax,3 ; button in buffer ? - je button - - jmp noclose - - red: ; redraw - call draw_window - jmp still - - key: ; key - mov eax,2 ; just read it and ignore - int 0x40 - jmp still - - button: ; button - mov eax,17 ; get id - int 0x40 - - cmp ah,1 ; button id=1 ? - jne noclose - - mov eax,-1 ; close this program - int 0x40 - noclose: - -; mov eax,13 -; mov ebx,20*65536+maxx-25 -; mov ecx,20*65536+maxy-25 -; xor edx,edx -; int 0x40 - - mov edi,screen_buf - mov ecx,maxx*maxy*3/4 - xor eax,eax - cld - rep stosd - - - call calc_deg - mov [z],0 - mov [sin_counter],0 - finit -oopz: - mov [x],0 - push [z] - call calc_sin_variable -oop: - push [x] -; call getcol ;(x,z) - call fun ; calculates y and y1 -; call rotateY - mov eax,[sin_variable] - add eax,[vector_x] ; vector_x - add [x],eax - mov eax,[vector_y] - add [y],eax ; vector_y - add [y1],eax - call point_perspective - call draw_point_3d - pop [x] - inc [x] - mov eax,[x] - cmp eax,[loop_counter] - jne oop - inc [sin_counter] - pop [z] - inc [z] - cmp [z],200 - jne oopz - - mov eax,7 - mov ebx,screen_buf - mov ecx,maxx*65536+maxy - mov edx,20*65536+20 - int 0x40 - - call set_elipse_dim - call set_vectors - -jmp still -;-----------------++++++PROCEDURES -getcol: - mov eax,[x_resolution] - mul [z] - add eax,[x] - mov ebx,eax - mov eax,35 - int 0x40 - mov [col],eax -ret - -set_vectors: - cmp [vector_x],55 - jne vec1 - mov [vector_dir_x],1 - vec1: - cmp [vector_x],250 - jne vec2 - mov [vector_dir_x],0 - vec2: - cmp [vector_dir_x],1 - jne vec3 - inc [vector_x] - jmp end_x - vec3: - dec [vector_x] - end_x: - cmp [vector_y],195 - jne vec4 - mov [vector_dir_y],1 - vec4: - cmp [vector_y],205 - jne vec5 - mov [vector_dir_y],0 - vec5: - cmp [vector_dir_y],1 - jne vec6 - inc [vector_y] - ret - vec6: - dec [vector_y] -ret -set_elipse_dim: - cmp [b],60 - jne go11 - mov [elipse_dir],0 - go11: - cmp [b],10 - jne go12 - mov [elipse_dir],1 - go12: - cmp [elipse_dir],1 - jne go13 - inc [b] - dec [a] - mov eax,[a] - mov [xo],eax - shl eax,1 - inc eax - mov [loop_counter],eax - ret - go13: - dec [b] - inc [a] - mov eax,[a] - mov [xo],eax - shl eax,1 - inc eax - mov [loop_counter],eax -ret - -calc_deg: - cmp [deg_counter], 360 - jne go_deg - mov [deg_counter],0 - go_deg: - fldpi - fidiv [deg_div] - fimul [deg_counter] - fstp [current_deg] -; fsincos -; fstp [cosbeta] -; fstp [sinbeta] - inc [deg_counter] - ret - -;rotateY: -; mov eax,[z] -; sub eax,[zoo] -; mov [subz],eax -; mov eax,[x] -; sub eax,[xoo] -; mov [subx],eax -; -; fld [sinbeta] -; fimul [subz] -; fchs -; fld [cosbeta] -; fimul[subx] -; faddp -; fiadd [xoo] -; fistp [x] - -; fld [sinbeta] -; fimul [subx] -; fld [cosbeta] -; fimul [subz] -; faddp -; fiadd [zoo] -; fistp [z] -; finit - -; ret - -point_perspective: - mov eax,[x] - sub eax,[xobs] - mov [xobssub],eax - mov eax,[z] - sub eax,[zobs] - mov [zobssub],eax - - mov eax,[y] - sub eax,[yobs] - mov [yobssub],eax - mov eax,[y1] - sub eax,[yobs] - mov [y1obssub],eax - - finit - fild [xobssub] - fidiv [zobssub] - fimul [zobs] - fchs - fiadd [xobs] - fistp [x] - fild [yobssub] - fidiv [zobssub] - fimul [zobs] - fchs - fiadd [yobs] - fistp [y] - -; mov eax,[xobssub] -; idiv [zobssub] -;; mov eax,edx -; imul [zobs] -; neg eax -; add eax,[xobs] -; mov [x],eax -; mov eax,[yobssub] -; idiv [zobssub] -;; mov eax,edx -; imul [zobs] -; neg eax -; add eax,[yobs] -; mov [y],eax - - fild [y1obssub] - fidiv [zobssub] - fimul [zobs] - fchs - fiadd [yobs] - fistp [y1] -ret -calc_sin_variable: - ;calculate sinus variable - fldpi - fidiv [sin_gran] - fimul [sin_counter] - fadd [current_deg] - fsin - fimul [sin_mul] - fistp [sin_variable] -ret - -fun: -; finit - fild [x] - fisub [xo] -; fchs -; faddp - fild [a] - fdivp st1,st - fmul st,st0 - fchs - fld1 - faddp - fsqrt - fimul [b] - fld st - fchs - fiadd [yo] - fistp [y] - fiadd [yo] - fistp [y1] -ret -draw_point_3d: - mov eax,[z] - imul [sq] - shr eax,10 - mov ebx,eax - neg eax - push eax - add eax,[y] - mov [y],eax - pop eax - add eax,[y1] - mov [y1],eax - mov eax,ebx - add eax,[x] - mov [x],eax - ;mov eax,1 - ;mov ebx,[x] - ;mov ecx,[y] - ;mov edx,[col] - ;int 0x40 - ;mov ecx,[y1] - ;int 0x40 - mov eax,maxx - mul [y] - add eax,[x] - mov ebx,eax - shl ebx,1 - add eax,ebx - add eax,screen_buf - mov ebx,[col] - or [eax],ebx - mov eax,maxx - mul [y1] - add eax,[x] - mov ebx,eax - shl ebx,1 - add eax,ebx - add eax,screen_buf - mov ebx,[col] - or [eax],ebx -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 ebx,100*65536+maxx+25 ; [x start] *65536 + [x size] - mov ecx,100*65536+maxy+25 ; [y start] *65536 + [y size] - mov edx,0x04000000 ; color of work area RRGGBB,8->color gl - mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl - mov edi,0x005080d0 ; color of frames RRGGBB - int 0x40 - ; WINDOW LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,8*65536+8 ; [x start] *65536 + [y start] - mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelt ; pointer to text beginning - mov esi,labellen-labelt ; text length - int 0x40 - - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw - int 0x40 - - ret - -x_resolution dd 800 -vector_x dd 200 -vector_y dd 200 -vector_dir_x db 1 -vector_dir_y db 1 -elipse_dir db 1 - -deg_counter dd ? ; rotation variables -deg_div dd 20 -current_deg dd ? -;cosbeta dd ? -;sinbeta dd ? -;zoo dd 100 ; rotation axle -;xoo dd 40 -;yoo dd 20 -;subx dd ? -;suby dd ? -;subz dd ? - -xobs dd maxx/2 ; 320 observer variables -yobs dd maxy/2 ; 175 -zobs dd -200 -xobssub dd ? -yobssub dd ? -y1obssub dd ? -zobssub dd ? - -sin_variable dd ? -sin_mul dd 60 -sin_gran dd 30 -sin_counter dd 0 -sq dd 724 ; round( (sqrt2)/2*1024 ) -z dd ? -x dd ? -y dd ? -y1 dd ? -xo dd 70 ; center point , (loop counter-1)/2 -yo dd 20 -a dd 70 ; vertical half-axle -b dd 20 ; horizontal half-axle -loop_counter dd 141 ; axle granularity -col dd 0x00ffffff - -labelt: - db ' 3D SHAKING WAVED SPIRAL' -labellen: -screen_buf: - -I_END: - - - - diff --git a/programs/demos/3DS/A_PROCS.INC b/programs/demos/3DS/A_PROCS.INC new file mode 100644 index 0000000000..853bf2557d --- /dev/null +++ b/programs/demos/3DS/A_PROCS.INC @@ -0,0 +1,503 @@ +draw_dots: + mov esi,[points_translated_ptr] + movzx 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 + jge @f + cmp bx,SIZE_X + jge @f + mov edx,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: + ; 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 +;********************************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 ax,4 + mov bx,4+4 + mov [triangles_count_var],164*3 ;140 + + mov cx,80*3 ;68 + @@: + stosw ;---- + mov [edi],bx ; | + add edi,2 ; | + inc ax ; | + stosw ; |repeat 4 times + + mov [edi],bx ; | + inc bx + add edi,2 + stosw ; | + mov [edi],bx ; | + add edi,2 ;---- + 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 ax,5 + mov bx,5+5 + mov [triangles_count_var],204 + + mov cx,100 + @@: + stosw ;---- + mov [edi],bx ; | + add edi,2 ; | + inc ax ; | + stosw ; |repeat + + mov [edi],bx ; | + inc bx + add edi,2 + stosw ; | + mov [edi],bx ; | + add edi,2 ;---- + loop @b + + mov ax,5 + mov bx,[points_count_var] + sub bx,2 + mov dl,2 + .nx: + mov cx,5 + add [triangles_count_var],cx + @@: + stosw + add ax,5 + stosw + mov word[edi],bx + add edi,2 + loop @b + + cmp dl,1 + je @f + + inc bx + jmp .lab + @@: + dec bx + .lab: + mov cx,5 + add [triangles_count_var],cx + @@: + stosw + add ax,5 + stosw + mov word[edi],bx + add edi,2 + loop @b + + dec dl + or dl,dl + jnz .nx + + sub ax,25 + stosw + sub ax,50 + stosw + mov word[edi],bx + add edi,2 + + stosw + add ax,50 + stosw + inc bx + mov word[edi],bx + add edi,2 + 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/3DS/BUMP3.INC b/programs/demos/3DS/BUMP3.INC new file mode 100644 index 0000000000..4db1fed748 --- /dev/null +++ b/programs/demos/3DS/BUMP3.INC @@ -0,0 +1,609 @@ +;------- Big thanks to majuma (www.majuma.xt.pl) for absolutelly great-- +;------- 13h mode demos ------------------------------------------------ + +bump_triangle: +;------------------in - eax - x1 shl 16 + y1 ----------- +;---------------------- ebx - x2 shl 16 + y2 ----------- +;---------------------- ecx - x3 shl 16 + y3 ----------- +;---------------------- edx - pointer to bump map ------ +;---------------------- esi - pointer to environment map +;---------------------- edi - pointer to screen buffer-- +;---------------------- stack : bump coordinates-------- +;---------------------- environment coordinates- +.b_x1 equ ebp+4 ; procedure don't save registers !!! +.b_y1 equ ebp+6 ; each coordinate as word +.b_x2 equ ebp+8 +.b_y2 equ ebp+10 +.b_x3 equ ebp+12 +.b_y3 equ ebp+14 +.e_x1 equ ebp+16 +.e_y1 equ ebp+18 +.e_x2 equ ebp+20 +.e_y2 equ ebp+22 +.e_x3 equ ebp+24 +.e_y3 equ ebp+26 + +.t_bmap equ dword[ebp-4] +.t_emap equ dword[ebp-8] +.x1 equ word[ebp-10] +.y1 equ word[ebp-12] +.x2 equ word[ebp-14] +.y2 equ word[ebp-16] +.x3 equ word[ebp-18] +.y3 equ word[ebp-20] + +.dx12 equ dword[ebp-24] +.dbx12 equ dword[ebp-28] +.dby12 equ dword[ebp-32] +.dex12 equ dword[ebp-36] +.dey12 equ dword[ebp-40] + +.dx13 equ dword[ebp-44] +.dbx13 equ dword[ebp-48] +.dby13 equ dword[ebp-52] +.dex13 equ dword[ebp-56] +.dey13 equ dword[ebp-60] + +.dx23 equ dword[ebp-64] +.dbx23 equ dword[ebp-68] +.dby23 equ dword[ebp-72] +.dex23 equ dword[ebp-76] +.dey23 equ dword[ebp-80] + +.cx1 equ dword[ebp-84] ; current variables +.cx2 equ dword[ebp-88] +.cbx1 equ dword[ebp-92] +.cbx2 equ dword[ebp-96] +.cby1 equ dword[ebp-100] +.cby2 equ dword[ebp-104] +.cex1 equ dword[ebp-108] +.cex2 equ dword[ebp-112] +.cey1 equ dword[ebp-116] +.cey2 equ dword[ebp-120] + + mov ebp,esp + push edx ; store bump map + push esi ; store e. map + ; sub esp,120 + .sort3: ; sort triangle coordinates... + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov edx,dword[.b_x1] + xchg edx,dword[.b_x2] + mov dword[.b_x1],edx + mov edx,dword[.e_x1] + xchg edx,dword[.e_x2] + mov dword[.e_x1],edx + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + mov edx,dword[.b_x2] + xchg edx,dword[.b_x3] + mov dword[.b_x2],edx + mov edx,dword[.e_x2] + xchg edx,dword[.e_x3] + mov dword[.e_x2],edx + jmp .sort3 + .sort2: + push eax ; store triangle coords in variables + push ebx + push ecx + + mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that + or edx,ebx ; if any *one* of them is negative a sign flag is raised + or edx,ecx + test edx,80000000h ; Check only X + jne .loop23_done + + cmp .x1,SIZE_X ; { + jg .loop23_done + cmp .x2,SIZE_X ; This can be optimized with effort + jg .loop23_done + cmp .x3,SIZE_X + jg .loop23_done ; { + + + mov bx,.y2 ; calc delta 12 + sub bx,.y1 + jnz .bt_dx12_make + mov ecx,5 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx12_done + .bt_dx12_make: + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx12,eax + push eax + + mov ax,word[.b_x2] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx12,eax + push eax + + mov ax,word[.b_y2] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby12,eax + push eax + + mov ax,word[.e_x2] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex12,eax + push eax + + mov ax,word[.e_y2] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey12,eax + push eax + .bt_dx12_done: + + mov bx,.y3 ; calc delta13 + sub bx,.y1 + jnz .bt_dx13_make + mov ecx,5 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx13_done + .bt_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx13,eax + push eax + + mov ax,word[.b_x3] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx13,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby13,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex13,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey13,eax + push eax + .bt_dx13_done: + + mov bx,.y3 ; calc delta23 + sub bx,.y2 + jnz .bt_dx23_make + mov ecx,5 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx23_done + .bt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx23,eax + push eax + + mov ax,word[.b_x3] + sub ax,word[.b_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx23,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby23,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex23,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey23,eax + push eax + + ; sub esp,40 + .bt_dx23_done: + + movsx eax,.x1 + shl eax,ROUND + ; mov .cx1,eax + ; mov .cx2,eax + push eax + push eax + + movsx eax,word[.b_x1] + shl eax,ROUND + ; mov .cbx1,eax + ; mov .cbx2,eax + push eax + push eax + + movsx eax,word[.b_y1] + shl eax,ROUND + ; mov .cby1,eax + ; mov .cby2,eax + push eax + push eax + + movsx eax,word[.e_x1] + shl eax,ROUND + ;mov .cex1,eax + ;mov .cex2,eax + push eax + push eax + + movsx eax,word[.e_y1] + shl eax,ROUND + ;mov .cey1,eax + ;mov .cey2,eax + push eax + push eax + + movzx ecx,.y1 + cmp cx,.y2 + jge .loop12_done + .loop12: + call .call_bump_line + + mov eax,.dx13 + add .cx1,eax + mov eax,.dx12 + add .cx2,eax + + mov eax,.dbx13 + add .cbx1,eax + mov eax,.dbx12 + add .cbx2,eax + mov eax,.dby13 + add .cby1,eax + mov eax,.dby12 + add .cby2,eax + + mov eax,.dex13 + add .cex1,eax + mov eax,.dex12 + add .cex2,eax + mov eax,.dey13 + add .cey1,eax + mov eax,.dey12 + add .cey2,eax + + inc ecx + cmp cx,.y2 + jl .loop12 + .loop12_done: + movzx ecx,.y2 + cmp cx,.y3 + jge .loop23_done + + movzx eax,.x2 + shl eax,ROUND + mov .cx2,eax + + movzx eax,word[.b_x2] + shl eax,ROUND + mov .cbx2,eax + + movzx eax,word[.b_y2] + shl eax,ROUND + mov .cby2,eax + + movzx eax,word[.e_x2] + shl eax,ROUND + mov .cex2,eax + + movzx eax,word[.e_y2] + shl eax,ROUND + mov .cey2,eax + + .loop23: + call .call_bump_line + + mov eax,.dx13 + add .cx1,eax + mov eax,.dx23 + add .cx2,eax + + mov eax,.dbx13 + add .cbx1,eax + mov eax,.dbx23 + add .cbx2,eax + mov eax,.dby13 + add .cby1,eax + mov eax,.dby23 + add .cby2,eax + + mov eax,.dex13 + add .cex1,eax + mov eax,.dex23 + add .cex2,eax + mov eax,.dey13 + add .cey1,eax + mov eax,.dey23 + add .cey2,eax + + inc ecx + cmp cx,.y3 + jl .loop23 + .loop23_done: + mov esp,ebp +ret 24 + +.call_bump_line: + + ; push ebp + ; push ecx + pushad + + push .t_emap + push .t_bmap + push .cey2 + push .cex2 + push .cey1 + push .cex1 + push .cby2 + push .cbx2 + push .cby1 + push .cbx1 + push ecx + + mov eax,.cx1 + sar eax,ROUND + mov ebx,.cx2 + sar ebx,ROUND + + call bump_line + + popad +ret +bump_line: +;--------------in: eax - x1 +;-------------- ebx - x2 +;-------------- edi - pointer to screen buffer +;stack - another parameters : +.y equ dword [ebp+4] +.bx1 equ dword [ebp+8] ; --- +.by1 equ dword [ebp+12] ; | +.bx2 equ dword [ebp+16] ; | +.by2 equ dword [ebp+20] ; |> bump and env coords +.ex1 equ dword [ebp+24] ; |> shifted shl ROUND +.ey1 equ dword [ebp+28] ; | +.ex2 equ dword [ebp+32] ; | +.ey2 equ dword [ebp+36] ; --- +.bmap equ dword [ebp+40] +.emap equ dword [ebp+44] + +.x1 equ dword [ebp-4] +.x2 equ dword [ebp-8] +.dbx equ dword [ebp-12] +.dby equ dword [ebp-16] +.dex equ dword [ebp-20] +.dey equ dword [ebp-24] +.cbx equ dword [ebp-28] +.cby equ dword [ebp-32] +.cex equ dword [ebp-36] +.cey equ dword [ebp-40] + mov ebp,esp + + mov ecx,.y + or ecx,ecx + jl .bl_end + cmp ecx,SIZE_Y + jge .bl_end + + cmp eax,ebx + jl .bl_ok + je .bl_end + + xchg eax,ebx + + mov edx,.bx1 + xchg edx,.bx2 + mov .bx1,edx + mov edx,.by1 + xchg edx,.by2 + mov .by1,edx + + mov edx,.ex1 + xchg edx,.ex2 + mov .ex1,edx + mov edx,.ey1 + xchg edx,.ey2 + mov .ey1,edx + .bl_ok: + push eax + push ebx ;store x1, x2 + + mov eax,SIZE_X*3 + mov ebx,.y + mul ebx + mov ecx,.x1 + lea ecx,[ecx*3] + add eax,ecx + add edi,eax + + mov ecx,.x2 + sub ecx,.x1 + + mov eax,.bx2 ; calc .dbx + sub eax,.bx1 + cdq + idiv ecx + push eax + + mov eax,.by2 ; calc .dby + sub eax,.by1 + cdq + idiv ecx + push eax + + mov eax,.ex2 ; calc .dex + sub eax,.ex1 + cdq + idiv ecx + push eax + + mov eax,.ey2 ; calc .dey + sub eax,.ey1 + cdq + idiv ecx + push eax + + push .bx1 + push .by1 + push .ex1 + push .ey1 + .draw: + ; if TEX = SHIFTING ;bump drawing only in shifting mode + + mov eax,.cby + sar eax,ROUND + shl eax,TEX_SHIFT + mov esi,.cbx + sar esi,ROUND + add esi,eax + + mov ebx,esi + dec ebx + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx eax,byte [ebx] + + mov ebx,esi + inc ebx + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx ebx,byte [ebx] + sub eax,ebx + + mov ebx,esi + sub ebx,TEX_X + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx edx,byte [ebx] + + mov ebx,esi + add ebx,TEX_X + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx ebx,byte [ebx] + sub edx,ebx + + mov ebx,.cex ;.cex - current env map X + sar ebx,ROUND + add eax,ebx ; eax - modified x coord + + mov ebx,.cey ;.cey - current env map y + sar ebx,ROUND + add edx,ebx ; edx - modified y coord + + or eax,eax + jl .black + cmp eax,TEX_X + jg .black + or edx,edx + jl .black + cmp edx,TEX_Y + jg .black + + shl edx,TEX_SHIFT + add edx,eax + lea edx,[edx*3] + add edx,.emap + mov eax,dword[edx] + jmp .put_pixel + .black: + xor eax,eax + .put_pixel: + stosd + dec edi + + mov eax,.dbx + add .cbx,eax + mov eax,.dby + add .cby,eax + mov eax,.dex + add .cex,eax + mov eax,.dey + add .cey,eax + + dec ecx + jnz .draw + ; end if + .bl_end: + mov esp,ebp +ret 44 \ No newline at end of file diff --git a/programs/demos/3DS/BUMP_CAT.INC b/programs/demos/3DS/BUMP_CAT.INC new file mode 100644 index 0000000000..aa0eb34ce6 --- /dev/null +++ b/programs/demos/3DS/BUMP_CAT.INC @@ -0,0 +1,1095 @@ +;SIZE_X equ 350 +;SIZE_Y equ 350 +ROUND equ 8 +;TEX_X equ 512 +;TEX_Y equ 512 +;TEXTURE_SIZE EQU (512*512)-1 +;TEX_SHIFT EQU 9 +CATMULL_SHIFT equ 8 +;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 +;Ext = NON +;MMX = 1 +;NON = 0 +;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great--- +;------- DOS 13h mode demos -------------------------------------------- +;------- Procedure draws bump triangle using Catmull Z-buffer algorithm- +;------- (Z coordinate interpolation)----------------------------------- +bump_triangle_z: +;------------------in - eax - x1 shl 16 + y1 ----------- +;---------------------- ebx - x2 shl 16 + y2 ----------- +;---------------------- ecx - x3 shl 16 + y3 ----------- +;---------------------- edx - pointer to bump map ------ +;---------------------- esi - pointer to environment map +;---------------------- edi - pointer to screen buffer-- +;---------------------- stack : bump coordinates-------- +;---------------------- environment coordinates- +;---------------------- Z position coordinates-- +;---------------------- pointer io Z buffer----- +;-- Z-buffer - filled with coordinates as dword -------- +;-- (Z coor. as word) shl CATMULL_SHIFT ---------------- +.b_x1 equ ebp+4 ; procedure don't save registers !!! +.b_y1 equ ebp+6 ; each coordinate as word +.b_x2 equ ebp+8 +.b_y2 equ ebp+10 +.b_x3 equ ebp+12 +.b_y3 equ ebp+14 +.e_x1 equ ebp+16 +.e_y1 equ ebp+18 +.e_x2 equ ebp+20 +.e_y2 equ ebp+22 +.e_x3 equ ebp+24 +.e_y3 equ ebp+26 +.z1 equ word[ebp+28] +.z2 equ word[ebp+30] +.z3 equ word[ebp+32] +.z_buff equ dword[ebp+34] ; pointer to Z-buffer + + +.t_bmap equ dword[ebp-4] ; pointer to bump map +.t_emap equ dword[ebp-8] ; pointer to e. map +.x1 equ word[ebp-10] +.y1 equ word[ebp-12] +.x2 equ word[ebp-14] +.y2 equ word[ebp-16] +.x3 equ word[ebp-18] +.y3 equ word[ebp-20] + +.dx12 equ dword[ebp-24] +.dz12 equ [ebp-28] +.dbx12 equ dword[ebp-32] +.dby12 equ [ebp-36] +.dex12 equ dword[ebp-40] +.dey12 equ [ebp-44] + +.dx13 equ dword[ebp-48] +.dz13 equ [ebp-52] +.dbx13 equ dword[ebp-56] +.dby13 equ [ebp-60] +.dex13 equ dword[ebp-64] +.dey13 equ [ebp-68] + +.dx23 equ dword[ebp-72] +.dz23 equ [ebp-76] +.dbx23 equ dword[ebp-80] +.dby23 equ [ebp-84] +.dex23 equ dword[ebp-88] +.dey23 equ [ebp-92] + +.cx1 equ dword[ebp-96] ; current variables +.cz1 equ [ebp-100] +.cx2 equ dword[ebp-104] +.cz2 equ [ebp-108] +.cbx1 equ dword[ebp-112] +.cby1 equ [ebp-116] +.cbx2 equ dword[ebp-120] +.cby2 equ [ebp-124] +.cex1 equ dword[ebp-128] +.cey1 equ [ebp-132] +.cex2 equ dword[ebp-136] +.cey2 equ [ebp-140] + + mov ebp,esp + push edx ; store bump map + push esi ; store e. map + ; sub esp,120 + .sort3: ; sort triangle coordinates... + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov edx,dword[.b_x1] + xchg edx,dword[.b_x2] + mov dword[.b_x1],edx + mov edx,dword[.e_x1] + xchg edx,dword[.e_x2] + mov dword[.e_x1],edx + mov dx,.z1 + xchg dx,.z2 + mov .z1,dx + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + mov edx,dword[.b_x2] + xchg edx,dword[.b_x3] + mov dword[.b_x2],edx + mov edx,dword[.e_x2] + xchg edx,dword[.e_x3] + mov dword[.e_x2],edx + mov dx,.z2 + xchg dx,.z3 + mov .z2,dx + jmp .sort3 + .sort2: + push eax ; store triangle coords in variables + push ebx + push ecx + + 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 .loop23_done + ; mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that + ; or edx,ebx ; if any *one* of them is negative a sign flag is raised + ; or edx,ecx + ; test edx,80000000h ; Check only X + ; jne .loop23_done + + ; cmp .x1,SIZE_X ; { + ; jg .loop23_done + ; cmp .x2,SIZE_X ; This can be optimized with effort + ; jg .loop23_done + ; cmp .x3,SIZE_X + ; jg .loop23_done ; { + + + mov bx,.y2 ; calc delta 12 + sub bx,.y1 + jnz .bt_dx12_make + mov ecx,6 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx12_done + .bt_dx12_make: + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx12,eax + push eax + + mov ax,.z2 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax +if Ext>=SSE + + sub esp,16 + cvtsi2ss xmm3,ebx ;rcps + ; mov eax,255 + cvtsi2ss xmm4,[i255d] + divss xmm3,xmm4 + rcpss xmm3,xmm3 + ; mulss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x1] + movd mm1,[.b_x2] + movd mm2,[.e_x1] + movd mm3,[.e_x2] + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + psubd mm1,mm0 + psubd mm3,mm2 + + ; cvtpi2ps xmm0,mm0 + ; movlhps xmm0,xmm0 + ; cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + ; subps xmm1,xmm0 + + +; cvtpi2ps xmm0,mm3 + ; divps xmm1,xmm3 + mulps xmm1,xmm3 + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey12,mm0 + movq .dby12,mm1 + + +else + + mov ax,word[.b_x2] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx12,eax + push eax + + mov ax,word[.b_y2] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby12,eax + push eax + + mov ax,word[.e_x2] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex12,eax + push eax + + mov ax,word[.e_y2] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey12,eax + push eax + +end if + + .bt_dx12_done: + + mov bx,.y3 ; calc delta13 + sub bx,.y1 + jnz .bt_dx13_make + mov ecx,6 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx13_done + .bt_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx13,eax + push eax + + mov ax,.z3 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz13,eax + push eax + +if Ext>=SSE + + sub esp,16 + cvtsi2ss xmm3,ebx ;rcps + ; mov eax,255 + cvtsi2ss xmm4,[i255d] + divss xmm3,xmm4 + rcpss xmm3,xmm3 + ; mulss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x1] + movd mm1,[.b_x3] + movd mm2,[.e_x1] + movd mm3,[.e_x3] + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + psubd mm1,mm0 + psubd mm3,mm2 + + ; cvtpi2ps xmm0,mm0 + ; movlhps xmm0,xmm0 + ; cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + ; subps xmm1,xmm0 + + +; cvtpi2ps xmm0,mm3 + ; divps xmm1,xmm3 + mulps xmm1,xmm3 + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey13,mm0 + movq .dby13,mm1 + + +else + + mov ax,word[.b_x3] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx13,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby13,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex13,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey13,eax + push eax +end if + + .bt_dx13_done: + + mov bx,.y3 ; calc delta23 + sub bx,.y2 + jnz .bt_dx23_make + mov ecx,6 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx23_done + .bt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx23,eax + push eax + + mov ax,.z3 + sub ax,.z2 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz23,eax + push eax + ; sub esp,40 +if Ext>=SSE + + sub esp,16 + cvtsi2ss xmm3,ebx ;rcps + ; mov eax,255 + cvtsi2ss xmm4,[i255d] + divss xmm3,xmm4 + rcpss xmm3,xmm3 + ; mulss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x2] + movd mm1,[.b_x3] + movd mm2,[.e_x2] + movd mm3,[.e_x3] + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + psubd mm1,mm0 + psubd mm3,mm2 + +; cvtpi2ps xmm0,mm0 +; movlhps xmm0,xmm0 +; cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 +; subps xmm1,xmm0 + + +; cvtpi2ps xmm0,mm3 + ; divps xmm1,xmm3 + mulps xmm1,xmm3 + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey23,mm0 + movq .dby23,mm1 + +else + + mov ax,word[.b_x3] + sub ax,word[.b_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx23,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby23,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex23,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey23,eax + push eax + +end if + + .bt_dx23_done: + sub esp,48 + + movsx eax,.x1 + shl eax,ROUND + mov .cx1,eax + mov .cx2,eax + ; push eax + ; push eax + + movsx eax,word[.b_x1] + shl eax,ROUND + mov .cbx1,eax + mov .cbx2,eax + ; push eax + ; push eax + + movsx eax,word[.b_y1] + shl eax,ROUND + mov .cby1,eax + mov .cby2,eax + ; push eax + ; push eax + + movsx eax,word[.e_x1] + shl eax,ROUND + mov .cex1,eax + mov .cex2,eax + ; push eax + ; push eax + + movsx eax,word[.e_y1] + shl eax,ROUND + mov .cey1,eax + mov .cey2,eax + ; push eax + ; push eax + + movsx eax,.z1 + shl eax,CATMULL_SHIFT + mov .cz1,eax + mov .cz2,eax + ; push eax + ; push eax + + movsx ecx,.y1 + cmp cx,.y2 + jge .loop12_done + .loop12: + call .call_bump_line + +if Ext >= MMX + movq mm0,.cby2 + movq mm1,.cby1 + movq mm2,.cey2 + movq mm3,.cey1 + movq mm4,.cz1 + movq mm5,.cz2 + paddd mm0,.dby12 + paddd mm1,.dby13 + paddd mm2,.dey12 + paddd mm3,.dey13 + paddd mm4,.dz13 + paddd mm5,.dz12 + movq .cby2,mm0 + movq .cby1,mm1 + movq .cey1,mm3 + movq .cey2,mm2 + movq .cz1,mm4 + movq .cz2,mm5 +else + mov edx,.dbx13 + add .cbx1,edx + mov eax,.dbx12 + add .cbx2,eax + mov ebx,.dby13 + add .cby1,ebx + mov edx,.dby12 + add .cby2,edx + + mov eax,.dex13 + add .cex1,eax + mov ebx,.dex12 + add .cex2,ebx + mov edx,.dey13 + add .cey1,edx + mov eax,.dey12 + add .cey2,eax + + mov eax,.dx13 + add .cx1,eax + mov ebx,.dx12 + add .cx2,ebx + + mov ebx,.dz13 + add .cz1,ebx + mov edx,.dz12 + add .cz2,edx +end if + inc ecx + cmp cx,.y2 + jl .loop12 + .loop12_done: + + movsx ecx,.y2 + cmp cx,.y3 + jge .loop23_done + + movsx eax,.z2 + shl eax,CATMULL_SHIFT + mov .cz2,eax + + movsx eax,.x2 + shl eax,ROUND + mov .cx2,eax + + movzx eax,word[.b_x2] + shl eax,ROUND + mov .cbx2,eax + + movzx eax,word[.b_y2] + shl eax,ROUND + mov .cby2,eax + + movzx eax,word[.e_x2] + shl eax,ROUND + mov .cex2,eax + + movzx eax,word[.e_y2] + shl eax,ROUND + mov .cey2,eax + + .loop23: + call .call_bump_line + +if Ext >= MMX + movq mm0,.cby2 + movq mm1,.cby1 + movq mm2,.cey2 + movq mm3,.cey1 + movq mm4,.cz1 + movq mm5,.cz2 + paddd mm0,.dby23 + paddd mm1,.dby13 + paddd mm2,.dey23 + paddd mm3,.dey13 + paddd mm4,.dz13 + paddd mm5,.dz23 + movq .cby2,mm0 + movq .cby1,mm1 + movq .cey1,mm3 + movq .cey2,mm2 + movq .cz1,mm4 + movq .cz2,mm5 +else + mov eax,.dx13 + add .cx1,eax + mov ebx,.dx23 + add .cx2,ebx + + mov edx,.dbx13 + add .cbx1,edx + mov eax,.dbx23 + add .cbx2,eax + mov ebx,.dby13 + add .cby1,ebx + mov edx,.dby23 + add .cby2,edx + + mov eax,.dex13 + add .cex1,eax + mov ebx,.dex23 + add .cex2,ebx + mov edx,.dey13 + add .cey1,edx + mov eax,.dey23 + add .cey2,eax + + mov ebx,.dz13 + add .cz1,ebx + mov edx,.dz23 + add .cz2,edx +end if + inc ecx + cmp cx,.y3 + jl .loop23 + .loop23_done: + + mov esp,ebp +ret 34 + +.call_bump_line: + + ; push ebp + ; push ecx + pushad + + push dword .cz1 + push dword .cz2 + push .z_buff + push .t_emap + push .t_bmap + push dword .cey2 + push .cex2 + push dword .cey1 + push .cex1 + push dword .cby2 + push .cbx2 + push dword .cby1 + push .cbx1 + push ecx + + mov eax,.cx1 + sar eax,ROUND + mov ebx,.cx2 + sar ebx,ROUND + + call bump_line_z + + popad +ret +bump_line_z: +;--------------in: eax - x1 +;-------------- ebx - x2 +;-------------- edi - pointer to screen buffer +;stack - another parameters : +.y equ dword [ebp+4] +.bx1q equ [ebp+8] +.bx2q equ [ebp+16] +.ex1q equ [ebp+24] +.ex2q equ [ebp+32] +.bx1 equ dword [ebp+8] ; --- +.by1 equ dword [ebp+12] ; | +.bx2 equ dword [ebp+16] ; | +.by2 equ dword [ebp+20] ; |> bump and env coords +.ex1 equ dword [ebp+24] ; |> shifted shl ROUND +.ey1 equ dword [ebp+28] ; | +.ex2 equ dword [ebp+32] ; | +.ey2 equ dword [ebp+36] ; --- +;.bx1q equ qword [ebp+8] ; - new +;.ex1q equ qword [ebp+24] ; - new +.bmap equ dword [ebp+40] +.emap equ dword [ebp+44] +.z_buff equ dword [ebp+48] +.z2 equ dword [ebp+52] ; -- |> z coords shifted +.z1 equ dword [ebp+56] ; -- shl CATMULL_SHIFT + +.x1 equ dword [ebp-4] +.x2 equ dword [ebp-8] +.dbx equ dword [ebp-12] +.dby equ dword [ebp-16] +.dbyq equ qword [ebp-16] ; - new +.dex equ dword [ebp-20] +.dey equ dword [ebp-24] +.deyq equ qword [ebp-24] ; - new +.dz equ dword [ebp-28] +.cbx equ dword [ebp-32] +.cby equ dword [ebp-36] +.cbyq equ qword [ebp-36] ; - new +.cex equ dword [ebp-40] +.cey equ dword [ebp-44] +.ceyq equ qword [ebp-44] ; - new +.cz equ dword [ebp-48] +.czbuff equ dword [ebp-52] +.temp1 equ ebp-60 +.temp2 equ ebp-68 +.temp3 equ ebp-76 +.temp4 equ ebp-84 +.temp5 equ ebp-92 + + mov ebp,esp + + mov ecx,.y + or ecx,ecx + jl .bl_end + cmp ecx,SIZE_Y + jge .bl_end + + cmp eax,ebx + jl .bl_ok + je .bl_end + + xchg eax,ebx +if Ext=NON + mov edx,.bx1 + xchg edx,.bx2 + mov .bx1,edx + mov edx,.by1 + xchg edx,.by2 + mov .by1,edx + + mov edx,.ex1 + xchg edx,.ex2 + mov .ex1,edx + mov edx,.ey1 + xchg edx,.ey2 + mov .ey1,edx +else + + movq mm0,.bx1q + movq mm1,.ex1q + movq mm2,.bx2q + movq mm3,.ex2q + movq .bx2q,mm0 + movq .ex2q,mm1 + movq .bx1q,mm2 + movq .ex1q,mm3 + +end if + + mov edx,.z1 + xchg edx,.z2 + mov .z1,edx + + .bl_ok: + + push eax + push ebx ;store x1, x2 + + cmp .x1,SIZE_X + jge .bl_end + cmp .x2,0 + jle .bl_end + + mov ebx,.x2 + sub ebx,.x1 + +if Ext >= SSE + + sub esp,16 + cvtsi2ss xmm3,ebx ;rcps + shufps xmm3,xmm3,0 + + cvtpi2ps xmm0,.bx1q ;mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,.ex1q ;mm2 + cvtpi2ps xmm1,.bx2q ;mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,.ex2q ;mm3 + subps xmm1,xmm0 + + divps xmm1,xmm3 + + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .deyq,mm0 + movq .dbyq,mm1 + +else + + mov eax,.bx2 ; calc .dbx + sub eax,.bx1 + cdq + idiv ebx + push eax + + mov eax,.by2 ; calc .dby + sub eax,.by1 + cdq + idiv ebx + push eax + + mov eax,.ex2 ; calc .dex + sub eax,.ex1 + cdq + idiv ebx + push eax + + mov eax,.ey2 ; calc .dey + sub eax,.ey1 + cdq + idiv ebx + push eax + +end if + + mov eax,.z2 ; calc .dz + sub eax,.z1 + cdq + idiv ebx + push eax + + cmp .x1,0 ; set correctly begin variable + jge @f ; CLIPPING ON FUNCTION + ; cutting triangle exceedes screen + mov ebx,.x1 + neg ebx + imul ebx ; eax = .dz * abs(.x1) + add .z1,eax + mov .x1,0 + + mov eax,.dbx + imul ebx + add .bx1,eax + + mov eax,.dby + imul ebx + add .by1,eax + + mov eax,.dex + imul ebx + add .ex1,eax + + mov eax,.dey + imul ebx + add .ey1,eax + @@: + cmp .x2,SIZE_X + jl @f + mov .x2,SIZE_X + @@: + mov eax,SIZE_X ;calc memory begin in buffers + mov ebx,.y + mul ebx + mov ebx,.x1 + add eax,ebx + mov ebx,eax + lea eax,[eax*3] + add edi,eax + mov esi,.z_buff ; z-buffer filled with dd variables + shl ebx,2 + add esi,ebx + + mov ecx,.x2 + sub ecx,.x1 + ; init current variables + push .bx1 + push .by1 + push .ex1 + push .ey1 + + push .z1 ; current z shl CATMULL_SHIFT + push esi +; It's my first attempt at MMX :), have mercy - Macgub + +;; if Ext = MMX +; mov dword[.temp1],esi +; mov dword[.temp1+4],esi +;; movq mm0,.cbyq ; mm0 - current bump coords +;; movq mm1,.ceyq ; mm1 - current env coords +;; movq mm2,.dbyq ; mm2 - delta bump +;; movq mm3,.deyq ; mm3 - delta env +; movd mm6,.z1 ; mm6 - cur z +; movq mm7,qword.[temp1] ; mm7 = lo = hi dword = current z buff +;; mov dword [.temp2],1 +;; mov dword [.temp2+4],-1 +;; mov dword [.temp3],TEXTURE_SIZE +;; mov dword [.temp3+4],TEXTURE_SIZE +;; mov esi,.bmap +;; mov dword [.temp4],esi +;; mov dword [.temp4+4],esi +;; mov dword [.temp5],TEX_X +;; mov dword [.temp5+4],- TEX_X +; mov dword [.temp1],TEX_SHIFT +; mov dword [.temp1+4],0 +;; end if + + .draw: + ; if TEX = SHIFTING ;bump drawing only in shifting mode + mov esi,.czbuff ; .czbuff current address in buffer + mov ebx,.cz ; .cz - cur z position + cmp ebx,dword[esi] + jge .skip +;; if Ext=NON + mov eax,.cby + sar eax,ROUND + mov esi,.cbx + sar esi,ROUND +;; else +;; movq mm4,mm0 ; mm4 - copies of cur bump coords +;; psrad mm4,ROUND ; mm4 = lo dword = y b coord, hi dword = x b coord +;; movd eax,mm4 ; - +;; psrlq mm4,32 ; - +;; movd esi,mm4 ; - +;; +;;; punpckldq mm5,mm4 ; +;;; psllq mm5,TEX_SHIFT +;;; paddq mm4,mm5 ; mm4 - lo dword index to b. map +;; +;; ; packqd mm4,mm5 + ; movq mm5,mm4 ; mm5 ~~ current bump map index? + +;; end if + shl eax,TEX_SHIFT ;- + add esi,eax ;- ; esi - current bump map index +;; if Ext = NON + mov ebx,esi + dec ebx + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx eax,byte [ebx] + + mov ebx,esi + inc ebx + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx ebx,byte [ebx] +;; else ;------------------------------------------- +;; mov dword [.temp1],esi ;- +;; mov dword [.temp1+4],esi ;- +;; movq mm5, qword[.temp1] ;- +;; paddd mm5, qword[.temp2] ; .temp2 == low dword = 1, high dword = -1 +;; pand mm5, qword[.temp3] ; .temp3 == low = high dword = TEX_SIZE +;; paddd mm5, qword[.temp4] ; .temp4 == low = high dword = .bmap +;; movd ebx,mm5 +;; psrlq mm5,32 +;; movd eax,mm5 +;; movzx ebx,byte[ebx] +;; movzx eax,byte[eax] +;; end if + sub eax,ebx +;; if Ext=NON + mov ebx,esi + sub ebx,TEX_X + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx edx,byte [ebx] + + mov ebx,esi + add ebx,TEX_X + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx ebx,byte [ebx] +;; else +;; movq mm5, qword[.temp1] ;- +;; paddd mm5, qword[.temp5] ; .temp5 == low dword = TEX_X, high dword = -TEX_X +;; pand mm5, qword[.temp3] ; .temp3 == low = high dword = TEX_SIZE +;; paddd mm5, qword[.temp4] ; .temp4 == low = high dword = offset .bmap +;; movd ebx,mm5 +;; psrlq mm5,32 +;; movd edx,mm5 +;; movzx ebx,byte[ebx] +;; movzx edx,byte[edx] +;; end if + sub edx,ebx + ; eax - horizontal sub + ; edx - vertical sub +;; if Ext=NON + mov ebx,.cex ;.cex - current env map X + sar ebx,ROUND + add eax,ebx ; eax - modified x coord + + mov ebx,.cey ;.cey - current env map y + sar ebx,ROUND + add edx,ebx ; edx - modified y coord +;; else +;; movq mm5,mm1 ; mm5 - copy of cur env coords +;; psrad mm5,ROUND +;; movq qword[.temp1],mm5 +;; add eax,dword [.temp1] +;; add edx,dword [.temp1+4] +;; ; movd ebx,mm5 +;; ; add eax,ebx +;; ; psrlq mm5,32 +;; ; movd ebx,mm5 + ; add edx,ebx +;; end if + + or eax,eax + jl .black + cmp eax,TEX_X + jg .black + or edx,edx + jl .black + cmp edx,TEX_Y + jg .black + + shl edx,TEX_SHIFT + add edx,eax + lea edx,[edx*3] + add edx,.emap + mov eax,dword[edx] + jmp .put_pixel + .black: + xor eax,eax + .put_pixel: + stosd + dec edi + mov ebx,.cz + mov esi,.czbuff + mov dword[esi],ebx + jmp .no_skip + .skip: + add edi,3 + .no_skip: + add .czbuff,4 +;; if Ext = NON + mov eax,.dbx + add .cbx,eax + mov eax,.dby + add .cby,eax + mov eax,.dex + add .cex,eax + mov eax,.dey + add .cey,eax +;; else +;; paddd mm0,mm2 +;; paddd mm1,mm3 +;; end if + mov eax,.dz + add .cz,eax + + dec ecx + jnz .draw + ; end if + .bl_end: + mov esp,ebp +ret 56 diff --git a/programs/demos/3DS/BUMP_TEX.INC b/programs/demos/3DS/BUMP_TEX.INC new file mode 100644 index 0000000000..3d80ff5574 --- /dev/null +++ b/programs/demos/3DS/BUMP_TEX.INC @@ -0,0 +1,1352 @@ + +;CATMULL_SHIFT equ 8 +;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 +;ROUND equ 8 +;Ext = NON +;MMX = 1 +;NON = 0 +;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great--- +;------- DOS 13h mode demos -------------------------------------------- +;------- Procedure draws bump triangle with texture, I use ------------- +;--------Catmull Z-buffer algorithm- (Z coordinate interpolation)------- +;--------I calc texture pixel by this way: col1*col2/256 --------------- +bump_tex_triangle_z: +;------------------in - eax - x1 shl 16 + y1 ----------- +;---------------------- ebx - x2 shl 16 + y2 ----------- +;---------------------- ecx - x3 shl 16 + y3 ----------- +;---------------------- edx - pointer to bump map------- +;---------------------- esi - pointer to env map-------- +;---------------------- edi - pointer to screen buffer-- +;---------------------- stack : bump coordinates-------- +;---------------------- environment coordinates- +;---------------------- Z position coordinates-- +;---------------------- pointer to Z buffer----- +;---------------------- pointer to texture------ +;---------------------- texture coordinates----- +;-- Z-buffer - filled with coordinates as dword -------- +;-- (Z coor. as word) shl CATMULL_SHIFT ---------------- +.b_x1 equ ebp+4 ; procedure don't save registers !!! +.b_y1 equ ebp+6 ; each coordinate as word +.b_x2 equ ebp+8 +.b_y2 equ ebp+10 ; b - bump map coords +.b_x3 equ ebp+12 ; e - env map coords +.b_y3 equ ebp+14 +.e_x1 equ ebp+16 +.e_y1 equ ebp+18 +.e_x2 equ ebp+20 +.e_y2 equ ebp+22 +.e_x3 equ ebp+24 +.e_y3 equ ebp+26 +.z1 equ word[ebp+28] +.z2 equ word[ebp+30] +.z3 equ word[ebp+32] +.z_buff equ dword[ebp+34] ; pointer to Z-buffer +.tex_ptr equ dword[ebp+38] ; ptr to texture +.t_x1 equ ebp+42 ; texture coords +.t_y1 equ ebp+44 +.t_x2 equ ebp+46 +.t_y2 equ ebp+48 +.t_x3 equ ebp+50 +.t_y3 equ ebp+52 + + + +.t_bmap equ dword[ebp-4] ; pointer to bump map +.t_emap equ dword[ebp-8] ; pointer to env map +.x1 equ word[ebp-10] +.y1 equ word[ebp-12] +.x2 equ word[ebp-14] +.y2 equ word[ebp-16] +.x3 equ word[ebp-18] +.y3 equ word[ebp-20] + +.dx12 equ dword[ebp-24] +.dz12 equ [ebp-28] +.dbx12 equ dword[ebp-32] +.dby12 equ [ebp-36] +.dex12 equ dword[ebp-40] +.dey12 equ [ebp-44] +.dtx12 equ dword[ebp-48] +.dty12 equ [ebp-52] + +.dx13 equ dword[ebp-52-4*1] +.dz13 equ [ebp-52-4*2] +.dbx13 equ dword[ebp-52-4*3] +.dby13 equ [ebp-52-4*4] +.dex13 equ dword[ebp-52-4*5] +.dey13 equ [ebp-52-4*6] +.dtx13 equ dword[ebp-52-4*7] +.dty13 equ [ebp-52-4*8] + + +.dx23 equ dword[ebp-(52+4*9)] +.dz23 equ [ebp-(52+4*10)] +.dbx23 equ dword[ebp-(52+4*11)] +.dby23 equ [ebp-(52+4*12)] +.dex23 equ dword[ebp-(52+4*13)] +.dey23 equ [ebp-(52+4*14)] +.dtx23 equ dword[ebp-(52+4*15)] +.dty23 equ [ebp-(52+4*16)] + +.cx1 equ dword[ebp-(52+4*17)] ; current variables +.cz1 equ [ebp-(52+4*18)] +.cx2 equ dword[ebp-(52+4*19)] +.cz2 equ [ebp-(52+4*20)] +.cbx1 equ dword[ebp-(52+4*21)] +.cby1 equ [ebp-(52+4*22)] +.cbx2 equ dword[ebp-(52+4*23)] +.cby2 equ [ebp-(52+4*24)] +.cex1 equ dword[ebp-(52+4*25)] +.cey1 equ [ebp-(52+4*26)] +.cex2 equ dword[ebp-(52+4*27)] +.cey2 equ [ebp-(52+4*28)] + +.ctx1 equ dword[ebp-(52+4*29)] +.cty1 equ [ebp-(52+4*30)] +.ctx2 equ dword[ebp-(52+4*31)] +.cty2 equ [ebp-(52+4*32)] + + cld + mov ebp,esp + push edx ; store bump map + push esi ; store e. map + ; sub esp,120 + .sort3: ; sort triangle coordinates... + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov edx,dword[.b_x1] + xchg edx,dword[.b_x2] + mov dword[.b_x1],edx + mov edx,dword[.e_x1] + xchg edx,dword[.e_x2] + mov dword[.e_x1],edx + mov edx,dword[.t_x1] + xchg edx,dword[.t_x2] + mov dword[.t_x1],edx + mov dx,.z1 + xchg dx,.z2 + mov .z1,dx + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + mov edx,dword[.b_x2] + xchg edx,dword[.b_x3] + mov dword[.b_x2],edx + mov edx,dword[.e_x2] + xchg edx,dword[.e_x3] + mov dword[.e_x2],edx + mov edx,dword[.t_x2] + xchg edx,dword[.t_x3] + mov dword[.t_x2],edx + mov dx,.z2 + xchg dx,.z3 + mov .z2,dx + jmp .sort3 + .sort2: + push eax ; store triangle coords in variables + push ebx + push ecx + 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 .loop23_done + ; mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that + ; or edx,ebx ; if any *one* of them is negative a sign flag is raised + ; or edx,ecx + ; test edx,80000000h ; Check only X + ; jne .loop23_done + + ; cmp .x1,SIZE_X ; { + ; jg .loop23_done + ; cmp .x2,SIZE_X ; This can be optimized with effort + ; jg .loop23_done + ; cmp .x3,SIZE_X + ; jg .loop23_done ; { + + + mov bx,.y2 ; calc delta 12 + sub bx,.y1 + jnz .bt_dx12_make + mov ecx,8 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx12_done + .bt_dx12_make: + + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx12,eax + push eax + + mov ax,.z2 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + +if Ext>=SSE + + sub esp,16 + ; mov eax,256 + cvtsi2ss xmm4,[i255d] + cvtsi2ss xmm3,ebx ;rcps + divss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x1] + movd mm1,[.b_x2] + movd mm2,[.e_x1] + movd mm3,[.e_x2] + + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + psubd mm1,mm0 + psubd mm3,mm2 + + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + + divps xmm1,xmm3 ;xmm1--> | dby | dbx | dey | dex | + + shufps xmm1,xmm1,10110001b + ;xmm1--> | dbx | dby | dex | dey | + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey12,mm0 + movq .dby12,mm1 +;------------- +; mov ax,.z2 +; sub ax,.z1 +; cwde +; mov bx,.x2 +; sub bx,.x1 +; movsx ebx,bx +; movd mm1,eax +; psllq mm1,32 +; movd mm1,ebx +;; push ebx +;; push eax +;; movq mm1,[esp] +;; add esp,8 +;;; mov ax,.z1 +;;; mov bx,.z2 +;;; shl eax,16 +;;; shl ebx,16 +;;; mov ax,.x1 +;;; mov bx,.x2 +; movd mm2,[.t_x1] +; movd mm3,[.t_x2] +;; movd mm0,eax +;; movd mm1,ebx + +; pxor mm4,mm4 +;; punpcklwd mm0,mm4 +;; punpcklwd mm1,mm4 +; punpcklwd mm2,mm4 +; punpcklwd mm3,mm4 + +;; psubd mm1,mm0 +; psubd mm3,mm2 + + +; cvtpi2ps xmm1,mm1 +; movlhps xmm1,xmm1 +; cvtpi2ps xmm1,mm3 + +; divps xmm1,xmm3 ; xmm1--> | dz | dx | dty | dtx | + +; shufps xmm1,xmm1,10110001b + ; xmm1--> | dx | dz | dtx | dty | +; cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords | dtx | dty | +; movhlps xmm1,xmm1 +; cvtps2pi mm1,xmm1 ; mm1 --> 2 delta dwords | dx | dz | +; movq .dty12,mm0 +; movq .dz12,mm1 +else + + mov ax,word[.b_x2] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx12,eax + push eax + + mov ax,word[.b_y2] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby12,eax + push eax + + mov ax,word[.e_x2] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex12,eax + push eax + + mov ax,word[.e_y2] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey12,eax + push eax + +end if + + mov ax,word[.t_x2] + sub ax,word[.t_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dtx12,eax + push eax + + mov ax,word[.t_y2] + sub ax,word[.t_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dty12,eax + push eax + + .bt_dx12_done: + + mov bx,.y3 ; calc delta13 + sub bx,.y1 + jnz .bt_dx13_make + mov ecx,8 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx13_done + .bt_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx13,eax + push eax + + mov ax,.z3 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz13,eax + push eax + +if Ext>=SSE + + sub esp,16 + ; mov eax,255 + cvtsi2ss xmm4,[i255d] + cvtsi2ss xmm3,ebx ;rcps + divss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x1] + movd mm1,[.b_x3] + movd mm2,[.e_x1] + movd mm3,[.e_x3] + + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + psubd mm1,mm0 + psubd mm3,mm2 + + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + + divps xmm1,xmm3 ;xmm1--> | dby | dbx | dey | dex | + + shufps xmm1,xmm1,10110001b + ;xmm1--> | dbx | dby | dex | dey | + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey13,mm0 + movq .dby13,mm1 +else + mov ax,word[.b_x3] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx13,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby13,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex13,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey13,eax + push eax +end if + + mov ax,word[.t_x3] + sub ax,word[.t_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dtx13,eax + push eax + + mov ax,word[.t_y3] + sub ax,word[.t_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dty13,eax + push eax + + .bt_dx13_done: + + mov bx,.y3 ; calc delta23 + sub bx,.y2 + jnz .bt_dx23_make + mov ecx,8 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx23_done + .bt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx23,eax + push eax + + mov ax,.z3 + sub ax,.z2 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz23,eax + push eax + +if Ext>=SSE + + sub esp,16 + ; mov eax,255 + cvtsi2ss xmm4,[i255d] + cvtsi2ss xmm3,ebx ;rcps + divss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x2] + movd mm1,[.b_x3] + movd mm2,[.e_x2] + movd mm3,[.e_x3] + + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + psubd mm1,mm0 + psubd mm3,mm2 + + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + + divps xmm1,xmm3 ;xmm1--> | dby | dbx | dey | dex | + + shufps xmm1,xmm1,10110001b + ;xmm1--> | dbx | dby | dex | dey | + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey23,mm0 + movq .dby23,mm1 +else + mov ax,word[.b_x3] + sub ax,word[.b_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx23,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby23,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex23,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey23,eax + push eax +end if + + mov ax,word[.t_x3] + sub ax,word[.t_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dtx23,eax + push eax + + mov ax,word[.t_y3] + sub ax,word[.t_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dty23,eax + push eax + + ; sub esp,40 + .bt_dx23_done: + sub esp,64 + movsx eax,.x1 + shl eax,ROUND + mov .cx1,eax + mov .cx2,eax + ; push eax + ; push eax + + movsx ebx,word[.b_x1] + shl ebx,ROUND + mov .cbx1,ebx + mov .cbx2,ebx + ; push ebx + ; push ebx + + movsx ecx,word[.b_y1] + shl ecx,ROUND + mov .cby1,ecx + mov .cby2,ecx + ; push ecx + ; push ecx + + movsx edx,word[.e_x1] + shl edx,ROUND + mov .cex1,edx + mov .cex2,edx + ; push edx + ; push edx + + movsx eax,word[.e_y1] + shl eax,ROUND + mov .cey1,eax + mov .cey2,eax + ; push eax + ; push eax + + movsx ebx,.z1 + shl ebx,CATMULL_SHIFT + mov .cz1,ebx + mov .cz2,ebx + ; push ebx + ; push ebx + + ; sub esp,16 + movsx ecx,word[.t_x1] + shl ecx,ROUND + mov .ctx1,ecx + mov .ctx2,ecx + ;push ecx + ;push ecx + + movsx edx,word[.t_y1] + shl edx,ROUND + mov .cty1,edx + mov .cty2,edx + ; push edx + ; push edx + + + movsx ecx,.y1 + cmp cx,.y2 + jge .loop12_done + .loop12: + call .call_line + +if Ext >= MMX + movq mm0,.cby2 + movq mm1,.cby1 + movq mm2,.cey2 + movq mm3,.cey1 + movq mm4,.cty1 + movq mm5,.cty2 + movq mm6,.cz1 + movq mm7,.cz2 + paddd mm0,.dby12 + paddd mm1,.dby13 + paddd mm2,.dey12 + paddd mm3,.dey13 + paddd mm4,.dty13 + paddd mm5,.dty12 + paddd mm6,.dz13 + paddd mm7,.dz12 + movq .cby2,mm0 + movq .cby1,mm1 + movq .cey1,mm3 + movq .cey2,mm2 + movq .cty1,mm4 + movq .cty2,mm5 + movq .cz1,mm6 + movq .cz2,mm7 +else + mov edx,.dbx13 + add .cbx1,edx + mov eax,.dbx12 + add .cbx2,eax + mov ebx,.dby13 + add .cby1,ebx + mov edx,.dby12 + add .cby2,edx + + mov eax,.dex13 + add .cex1,eax + mov ebx,.dex12 + add .cex2,ebx + mov edx,.dey13 + add .cey1,edx + mov eax,.dey12 + add .cey2,eax + + mov eax,.dtx13 + add .ctx1,eax + mov ebx,.dtx12 + add .ctx2,ebx + mov edx,.dty13 + add .cty1,edx + mov eax,.dty12 + add .cty2,eax + + mov eax,.dx13 + add .cx1,eax + mov ebx,.dx12 + add .cx2,ebx + mov ebx,.dz13 + add .cz1,ebx + mov edx,.dz12 + add .cz2,edx +end if + inc ecx + cmp cx,.y2 + jl .loop12 + .loop12_done: + + movsx ecx,.y2 + cmp cx,.y3 + jge .loop23_done + + movsx eax,.z2 + shl eax,CATMULL_SHIFT + mov .cz2,eax + + movsx ebx,.x2 + shl ebx,ROUND + mov .cx2,ebx + + movzx edx,word[.b_x2] + shl edx,ROUND + mov .cbx2,edx + + movzx eax,word[.b_y2] + shl eax,ROUND + mov .cby2,eax + + movzx ebx,word[.e_x2] + shl ebx,ROUND + mov .cex2,ebx + + movzx edx,word[.e_y2] + shl edx,ROUND + mov .cey2,edx + + movzx eax,word[.t_x2] + shl eax,ROUND + mov .ctx2,eax + + movzx ebx,word[.t_y2] + shl ebx,ROUND + mov .cty2,ebx + + .loop23: + call .call_line + +if Ext >= MMX + movq mm0,.cby2 + movq mm1,.cby1 + movq mm2,.cey2 + movq mm3,.cey1 + movq mm4,.cty1 + movq mm5,.cty2 + movq mm6,.cz1 + movq mm7,.cz2 + paddd mm0,.dby23 + paddd mm1,.dby13 + paddd mm2,.dey23 + paddd mm3,.dey13 + paddd mm4,.dty13 + paddd mm5,.dty23 + paddd mm6,.dz13 + paddd mm7,.dz23 + movq .cby2,mm0 + movq .cby1,mm1 + movq .cey2,mm2 + movq .cey1,mm3 + movq .cty1,mm4 + movq .cty2,mm5 + movq .cz1,mm6 + movq .cz2,mm7 +else + mov edx,.dbx13 + add .cbx1,edx + mov eax,.dbx23 + add .cbx2,eax + mov ebx,.dby13 + add .cby1,ebx + mov edx,.dby23 + add .cby2,edx + + mov eax,.dex13 + add .cex1,eax + mov ebx,.dex23 + add .cex2,ebx + mov edx,.dey13 + add .cey1,edx + mov eax,.dey23 + add .cey2,eax + + mov eax,.dx13 + add .cx1,eax + mov ebx,.dx23 + add .cx2,ebx + mov ebx,.dz13 + add .cz1,ebx + mov edx,.dz23 + add .cz2,edx + + mov eax,.dtx13 + add .ctx1,eax + mov ebx,.dtx23 + add .ctx2,ebx + mov edx,.dty13 + add .cty1,edx + mov eax,.dty23 + add .cty2,eax + +end if + inc ecx + cmp cx,.y3 + jl .loop23 + .loop23_done: + + mov esp,ebp +ret 50 + +.call_line: + + pushad + push .tex_ptr + push dword .cty2 + push .ctx2 + push dword .cty1 + push .ctx1 + push dword .cz1 + push dword .cz2 + push .z_buff + push .t_emap + push .t_bmap + push dword .cey2 + push .cex2 + push dword .cey1 + push .cex1 + push dword .cby2 + push .cbx2 + push dword .cby1 + push .cbx1 + push ecx + + mov eax,.cx1 + sar eax,ROUND + mov ebx,.cx2 + sar ebx,ROUND + + call bump_tex_line_z + + popad +ret +bump_tex_line_z: +;--------------in: eax - x1 +;-------------- ebx - x2 +;-------------- edi - pointer to screen buffer +;stack - another parameters : +.y equ dword [ebp+4] +.bx1q equ [ebp+8] +.bx2q equ [ebp+16] +.ex1q equ [ebp+24] +.ex2q equ [ebp+32] +.tx1q equ [ebp+60] +.tx2q equ [ebp+68] +;.bx1q equ [ebp+8] +;.bx2q equ [ebp+16] +;.ex1q equ [ebp+24] +;.exyq equ [ebp+32] +.bx1 equ dword [ebp+8] ; --- +.by1 equ dword [ebp+12] ; | +.bx2 equ dword [ebp+16] ; | +.by2 equ dword [ebp+20] ; |> b. map and e. map coords +.ex1 equ dword [ebp+24] ; |> shifted shl ROUND +.ey1 equ dword [ebp+28] ; | +.ex2 equ dword [ebp+32] ; | +.ey2 equ dword [ebp+36] ; --- +.bmap equ dword [ebp+40] ; bump map offset +.emap equ dword [ebp+44] ; env map offset +.z_buff equ dword [ebp+48] +.z2 equ dword [ebp+52] ; -- |> z coords shifted +.z1 equ dword [ebp+56] ; -- shl CATMULL_SHIFT + +.tx1 equ dword [ebp+60] ; ----- +.ty1 equ dword [ebp+64] ; |> shifted shl ROUND +.tx2 equ dword [ebp+68] ; | +.ty2 equ dword [ebp+72] ; --- +.tex_map equ dword [ebp+76] ; texture offset ( pointer ) + + +.x1 equ dword [ebp-4] +.x2 equ dword [ebp-8] +.dbx equ dword [ebp-12] +.dby equ dword [ebp-16] +.dbyq equ qword [ebp-16] ; - new +.dex equ dword [ebp-20] +.dey equ dword [ebp-24] +.deyq equ qword [ebp-24] ; - new +.dz equ dword [ebp-28] +.dtx equ dword [ebp-32] +.dty equ dword [ebp-36] +.dtyq equ qword [ebp-36] + +.cbx equ dword [ebp-40] +.cby equ dword [ebp-44] +.cbyq equ qword [ebp-44] ; - new +.cex equ dword [ebp-48] +.cey equ dword [ebp-52] +.ceyq equ qword [ebp-52] ; - new +.cz equ dword [ebp-56] +.czbuff equ dword [ebp-60] +.ctx equ dword [ebp-64] +.cty equ dword [ebp-68] +.ctyq equ qword [ebp-68] +.c_scr equ dword [ebp-72] + +.temp1 equ ebp-80 +.temp2 equ ebp-88 +.temp3 equ ebp-76 +.temp4 equ ebp-84 +.temp5 equ ebp-92 + + mov ebp,esp + + + + mov ecx,.y + or ecx,ecx + jl .bl_end + cmp ecx,SIZE_Y + jge .bl_end + + cmp eax,ebx + jl .bl_ok + je .bl_end + + xchg eax,ebx +if Ext=NON + mov edx,.bx1 + xchg edx,.bx2 + mov .bx1,edx + mov edx,.by1 + xchg edx,.by2 + mov .by1,edx + + mov edx,.ex1 + xchg edx,.ex2 + mov .ex1,edx + mov edx,.ey1 + xchg edx,.ey2 + mov .ey1,edx + + mov edx,.tx1 + xchg edx,.tx2 + mov .tx1,edx + mov edx,.ty1 + xchg edx,.ty2 + mov .ty1,edx +else + movq mm0,.bx1q + movq mm1,.bx2q + movq mm2,.ex1q + movq mm3,.ex2q + movq mm4,.tx1q + movq mm5,.tx2q + movq .bx2q,mm0 + movq .bx1q,mm1 + movq .ex1q,mm3 + movq .ex2q,mm2 + movq .tx1q,mm5 + movq .tx2q,mm4 +end if + + mov edx,.z1 + xchg edx,.z2 + mov .z1,edx + .bl_ok: + push eax + push ebx ;store x1, x2 + cmp .x1,SIZE_X + jge .bl_end + cmp .x2,0 + jle .bl_end + + mov ebx,.x2 + sub ebx,.x1 + +if Ext>=SSE + + sub esp,28 + cvtsi2ss xmm3,ebx ;rcps + shufps xmm3,xmm3,0 + + cvtpi2ps xmm0,.bx1q ;mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,.ex1q ;mm2 + cvtpi2ps xmm1,.bx2q ;mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,.ex2q ;mm3 + subps xmm1,xmm0 + + divps xmm1,xmm3 + + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .deyq,mm0 + movq .dbyq,mm1 + + movd mm2,.z1 + movd mm3,.z2 + + cvtpi2ps xmm0,.tx1q ;mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,.tx2q ;mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + subps xmm1,xmm0 + + divps xmm1,xmm3 + + shufps xmm1,xmm1,10110100b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movd .dz,mm0 + movq .dtyq,mm1 + +else + + mov eax,.bx2 ; calc .dbx + sub eax,.bx1 + cdq + idiv ebx + push eax + + mov eax,.by2 ; calc .dby + sub eax,.by1 + cdq + idiv ebx + push eax + + mov eax,.ex2 ; calc .dex + sub eax,.ex1 + cdq + idiv ebx + push eax + + mov eax,.ey2 ; calc .dey + sub eax,.ey1 + cdq + idiv ebx + push eax + + + mov eax,.z2 ; calc .dz + sub eax,.z1 + cdq + idiv ebx + push eax + + mov eax,.tx2 ; calc .dtx + sub eax,.tx1 + cdq + idiv ebx + push eax + + mov eax,.ty2 ; calc .dty + sub eax,.ty1 + cdq + idiv ebx + push eax + +end if + cmp .x1,0 ; set correctly begin variable + jge @f ; CLIPPING ON FUNCTION + ; cutting triangle exceedes screen + mov ebx,.x1 + neg ebx + imul ebx ; eax = .dz * abs(.x1) + add .z1,eax + mov .x1,0 + + mov eax,.dbx + imul ebx + add .bx1,eax + + mov eax,.dby + imul ebx + add .by1,eax + + mov eax,.dex + imul ebx + add .ex1,eax + + mov eax,.dey + imul ebx + add .ey1,eax + + mov eax,.dtx + imul ebx + add .tx1,eax + + mov eax,.dty + imul ebx + add .ty1,eax + + @@: + cmp .x2,SIZE_X + jl @f + mov .x2,SIZE_X + @@: + mov eax,SIZE_X ;calc memory begin in buffers + mul .y + add eax,.x1 + lea esi,[4*eax] + add esi,.z_buff ; z-buffer filled with dd variables + lea eax,[eax*3] + add edi,eax + + + mov ecx,.x2 + sub ecx,.x1 + ; init current variables + push .bx1 ; current b, e and t shifted shl ROUND .cbx + push .by1 ; .cby + push .ex1 ; .cex + push .ey1 ; .cey + + push .z1 ; current z shl CATMULL_SHIFT ; .cz + push esi ; .czbuff + + push .tx1 ; .ctx + push .ty1 ; .cty + push edi ; .c_scr +if Ext>=MMX + movq mm7,.ctyq + movq mm6,.cbyq + movq mm5,.ceyq +; movq mm4,.dtyq +; movq mm3,.dbyq +end if + + .draw: + ; if TEX = SHIFTING ;bump drawing only in shifting mode + mov esi,.czbuff ; .czbuff current address in buffer + mov ebx,.cz ; .cz - cur z position + cmp ebx,dword[esi] + jge .skip +if Ext=NON + mov eax,.cby + shr eax,ROUND + mov esi,.cbx + shr esi,ROUND +else + movq mm1,mm6 + psrld mm1,ROUND + movd eax,mm1 + psrlq mm1,32 + movd esi,mm1 +end if + + + + shl eax,TEX_SHIFT + add esi,eax ;- ; esi - current bump map index + + mov ebx,esi + dec ebx + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx eax,byte [ebx] + + mov ebx,esi + inc ebx + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx ebx,byte [ebx] + sub eax,ebx + + mov ebx,esi + sub ebx,TEX_X + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx edx,byte [ebx] + + mov ebx,esi + add ebx,TEX_X + and ebx,TEXTURE_SIZE + add ebx,.bmap + movzx ebx,byte [ebx] + sub edx,ebx + + ; eax - horizontal sub modificated x coord + ; edx - vertical sub modificated y coord +if Ext=NON + mov ebx,.cex ;.cex - current env map X + shr ebx,ROUND + add eax,ebx + + + mov ebx,.cey ;.cey - current env map y + shr ebx,ROUND + add edx,ebx + +else + movq mm1,mm5 ; mm5 - copy of cur env coords + psrld mm1,ROUND + movd ebx,mm1 + psrlq mm1,32 + add eax,ebx + movd ebx,mm1 + add edx,ebx +; movq qword[.temp1],mm3 +; add eax,dword [.temp1] +; add edx,dword [.temp1+4] +end if + + or eax,eax + jl .black + cmp eax,TEX_X + jg .black + or edx,edx + jl .black + cmp edx,TEX_Y + jg .black + + shl edx,TEX_SHIFT ; zaburzenie w emapie = zaburzenie w teksturze + add edx,eax ; proponuje nie stawiac czarnego pixela tylko + lea esi,[edx*3] ; niezaburzony. + add esi,.emap ; + lodsd + +if Ext=NON + mov edx,.cty + shr edx,ROUND ; sar + + mov edi,.ctx + shr edi,ROUND ; sar +else + movq mm1,mm7 + psrld mm1,ROUND + movd edx,mm1 + psrlq mm1,32 + movd edi,mm1 + +end if + + shl edx,TEX_SHIFT + add edi,edx + and edi,TEXTURE_SIZE + lea esi,[edi*3] + add esi,.tex_map + +if Ext=NON + mov edx,eax + lodsd + push ax + mul dl + mov dl,ah + pop ax + shr ax,8 + mul dh + mov al,dl + mov edi,.c_scr + stosw + shr edx,16 + shr eax,16 + mul dl + shr ax,8 + stosb +else + movd mm0,eax + pxor mm1,mm1 + punpcklbw mm0,mm1 + movd mm2,[esi] + punpcklbw mm2,mm1 + pmullw mm0,mm2 + psrlw mm0,8 + packuswb mm0,mm1 + mov edi,.c_scr + movd [edi],mm0 + +end if + + jmp .actual_zbuff ; actualize z buffer + @@: + .black: + xor eax,eax + mov edi,.c_scr + stosd + .actual_zbuff: + mov eax,.cz + mov edi,.czbuff + stosd + + .skip: + add .czbuff,4 + add .c_scr,3 + +if Ext=NON + mov eax,.dbx + add .cbx,eax + mov ebx,.dby + add .cby,ebx + + mov edx,.dex + add .cex,edx + mov eax,.dey + add .cey,eax + + mov ebx,.dtx + add .ctx,ebx + mov edx,.dty + add .cty,edx + +else + paddd mm7,.dtyq + paddd mm6,.dbyq + paddd mm5,.deyq +end if + mov eax,.dz + add .cz,eax + + dec ecx + jnz .draw + + .bl_end: + mov esp,ebp +ret 76 +;Ext = MMX + +; else +; movq mm5, qword[.temp1] ;- +; paddd mm5, qword[.temp5] ; .temp5 == low dword = TEX_X, high dword = -TEX_X +; pand mm5, qword[.temp3] ; .temp3 == low = high dword = TEX_SIZE +; paddd mm5, qword[.temp4] ; .temp4 == low = high dword = offset .bmap +; movd ebx,mm5 +; psrlq mm5,32 +; end if diff --git a/programs/demos/3DS/B_PROCS.INC b/programs/demos/3DS/B_PROCS.INC new file mode 100644 index 0000000000..9bc0e8d83d --- /dev/null +++ b/programs/demos/3DS/B_PROCS.INC @@ -0,0 +1,1171 @@ +;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 dx,[points_count_var] + fld dword[edi+ebx] + fst .max + fstp .min + add edi,12 + dec dx + .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 dx + 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 dx,[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 dx + 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> + movzx 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 si,si + xor ax,ax + mov bx,.N+1 + mov cx,(.N*2)+2 ;-- + mov dx,(.N*3)+3 ;--- + mov [triangles_count_var],0 + .again_tri: + stosw ; main wave + mov word[edi],bx + inc ax + add edi,2 + stosw + stosw + mov word[edi],bx + inc bx + mov word[edi+2],bx + + + add edi,4 + + mov word[edi],cx ;---- ; n2+2 ; xor ax,ax + inc cx ; n2+3 ; mov bx,.N+1 + mov word[edi+2],dx ; ; mov cx,(.N*2)+2 ;-- + mov word[edi+4],cx ; n3+3 ; mov dx,(.N*3)+3 ;--- + mov word[edi+6],dx ; n3+3 ; + inc dx ; ; + mov word[edi+8],dx ; n2+3 ; + mov word[edi+10],cx ; n3+4 + add edi,12 ;---- + + dec ax ; border of wave + dec bx + dec cx + dec dx + + stosw ; first border + inc ax + stosw + mov word[edi],dx + add edi,2 + + mov word[edi],dx + add edi,2 + stosw + inc dx + mov word[edi],dx + + mov word[edi+2],bx ; second border + mov word[edi+4],cx + inc bx + mov word[edi+6],bx + + mov word[edi+8],bx + mov word[edi+10],cx + inc cx + mov word[edi+12],cx + add edi,14 + + add [triangles_count_var],8 ;10 + inc si + cmp si,.N + jne .again_tri + + add ax,((.N+1)*3)+1 + add bx,((.N+1)*3)+1 + add cx,((.N+1)*3)+1 + add dx,((.N+1)*3)+1 + xor si,si + cmp ax,(.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 + 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>=MMX + emms + push ebp + mov ebp,esp + push dword 0x0 + push dword 0x01010101 +.again_blur: + push ecx + mov edi,screen + 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 + movzx 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 + movzx 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/3DS/FLAT3.ASM b/programs/demos/3DS/FLAT3.ASM deleted file mode 100644 index a2253bcba9..0000000000 --- a/programs/demos/3DS/FLAT3.ASM +++ /dev/null @@ -1,188 +0,0 @@ -draw_triangle: - ;----------in - eax - x1 shl 16 + y1 - ;------------- -ebx - x2 shl 16 + y2 - ;---------------ecx - x3 shl 16 + y3 - ;---------------edx - color 0x00rrggbb - ;---------------edi - pointer to screen buffer - @ch3: - cmp ax,bx - jg @ch1 - @ch4: ; sort parameters - cmp bx,cx - jg @ch2 - jle @chEnd - @ch1: - xchg eax,ebx - jmp @ch4 - @ch2: - xchg ebx,ecx - jmp @ch3 - @chEnd: - mov dword[@y1],eax ; ....and store to user friendly variables - mov dword[@y2],ebx - mov dword[@y3],ecx - mov [@col],edx - mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that - or edx,ebx ; if any *one* of them is negative a sign flag is raised - or edx,ecx - test edx,80008000h ; Check both X&Y at once - jne @end_triangle - - cmp [@x1],SIZE_X ; { - jg @end_triangle - cmp [@x2],SIZE_X ; This can be optimized with effort - jg @end_triangle - cmp [@x3],SIZE_X - jg @end_triangle ; } - - shr eax,16 - shr ebx,16 - shr ecx,16 - - neg ax ; calculate delta 12 - add ax,bx - cwde - shl eax,ROUND - cdq - mov bx,[@y2] - mov cx,[@y1] - sub bx,cx - ;cmp ebx,0 - jne @noZero1 - mov [@dx12],0 - jmp @yesZero1 - @noZero1: - idiv ebx - mov [@dx12],eax - @yesZero1: - - mov ax,[@x3] ; calculate delta 13 - sub ax,[@x1] - cwde - shl eax,ROUND - cdq - mov bx,[@y3] - mov cx,[@y1] - sub bx,cx - ;cmp ebx,0 - jne @noZero2 - mov [@dx13],0 - jmp @yesZero2 - @noZero2: - idiv ebx - mov [@dx13],eax - @yesZero2: - - mov ax,[@x3] ; calculate delta 23 [dx23] - sub ax,[@x2] - cwde - shl eax,ROUND - cdq - mov bx,[@y3] - mov cx,[@y2] - sub bx,cx - ;cmp ebx,0 - jne @noZero3 - mov [@dx23],0 - jmp @yesZero3 - @noZero3: - idiv ebx - mov [@dx23],eax - @yesZero3: - - movzx eax,word[@x1] ; eax - xk1 - shl eax,ROUND - mov ebx,eax ; ebx - xk2 - movzx esi,word[@y1] ; esi - y - @next_line1: - mov ecx,eax ; ecx - x11 - sar ecx,ROUND - mov edx,ebx ; edx - x12 - sar edx,ROUND - cmp ecx,edx - jle @nochg - xchg ecx,edx - @nochg: - pusha - mov ebx,ecx - sub edx,ecx - mov ecx,edx - mov edx,esi - mov eax,[@col] - call @horizontal_line - popa - add eax,[@dx13] - add ebx,[@dx12] - inc esi - cmp si,[@y2] - jl @next_line1 - - movzx esi,word[@y2] - movzx ebx,word[@x2] - shl ebx,ROUND - @next_line2: - mov ecx,eax - sar ecx,ROUND - mov edx,ebx - sar edx,ROUND - cmp ecx,edx - jle @nochg1 - xchg ecx,edx - @nochg1: - pusha - mov ebx,ecx - sub edx,ecx - mov ecx,edx - mov edx,esi - mov eax,[@col] - call @horizontal_line - popa - add eax,[@dx13] - add ebx,[@dx23] - inc esi - cmp si,[@y3] - jl @next_line2 - @end_triangle: -ret - -@horizontal_line: - ;---------in - ;---------eax - color of line, 0x00RRGGBB - ;---------ebx - x1 - x position of line begin - ;---------ecx - lenght of line - ;---------edx - y position of line - ;---------edi - pointer to buffer - jcxz @end_hor_l -; or edx,edx -; jl @end_hor_l - cmp edx,SIZE_Y - jg @end_hor_l - push eax - mov eax,SIZE_X*3 - mul edx - add edi,eax ; calculate line begin adress - ;add edi,ebx - ;shl ebx,1 - lea edi,[edi+ebx*2] - add edi,ebx - pop eax - cld - ;mov dword[edi-3],0000FF00h - @ddraw: ; Drawing horizontally: - ;push eax - stosd ; 4 bytes at a time - dec edi ; point to the 4th - ;shr eax,16 - ;stosb - ;pop eax - ;pusha ; If you want to draw pixel-by-pixel - ; mov eax,7 ; put image - ; mov ebx,screen - ; mov ecx,SIZE_X shl 16 + SIZE_Y - ; mov edx,5 shl 16 + 20 - ; int 0x40 - ;popa - loop @ddraw - mov byte[edi],0 ; The last 4th will be reset - @end_hor_l: -ret diff --git a/programs/demos/3DS/FLAT3.INC b/programs/demos/3DS/FLAT3.INC new file mode 100644 index 0000000000..365f9b8155 --- /dev/null +++ b/programs/demos/3DS/FLAT3.INC @@ -0,0 +1,205 @@ +draw_triangle: + ;----------in - eax - x1 shl 16 + y1 + ;------------- -ebx - x2 shl 16 + y2 + ;---------------ecx - x3 shl 16 + y3 + ;---------------edx - color 0x00rrggbb + ;---------------edi - pointer to screen buffer + + .col equ ebp-4 ;dd ? + .x1 equ ebp-6 ;dw ? + .y1 equ ebp-8 ;dw ?;+8 + .x2 equ ebp-10 ;dw ? + .y2 equ ebp-12 ;dw ? + .x3 equ ebp-14 ;dw ? + .y3 equ ebp-16 ;dw ?;+16 + .dx12 equ ebp-20 ; dd ? + .dx13 equ ebp-24 ; dd ?;+24 + .dx23 equ ebp-28 ; dd ? + + mov ebp,esp + ; sub esp,28 + push edx + .ch3: + cmp ax,bx + jg .ch1 + .ch4: ; sort parameters + cmp bx,cx + jg .ch2 + jle .chEnd + .ch1: + xchg eax,ebx + jmp .ch4 + .ch2: + xchg ebx,ecx + jmp .ch3 + .chEnd: + ; mov dword[.y1],eax ; ..and store to user friendly variables + ; mov dword[.y2],ebx + ; mov dword[.y3],ecx + ; mov [.col],edx + push eax + push ebx + push ecx + sub esp,12 + mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that + or edx,ebx ; if any *one* of them is negative a sign flag is raised + or edx,ecx + test edx,80008000h ; Check both X&Y at once + jne .end_triangle + + cmp word[.x1],SIZE_X ; { + jg .end_triangle + cmp word[.x2],SIZE_X ; This can be optimized with effort + jg .end_triangle + cmp word[.x3],SIZE_X + jg .end_triangle ; } + + shr eax,16 + shr ebx,16 + shr ecx,16 + + neg ax ; calculate delta 12 + add ax,bx + cwde + shl eax,ROUND + cdq + mov bx,[.y2] + mov cx,[.y1] + sub bx,cx + ;cmp ebx,0 + jne .noZero1 + mov dword[.dx12],0 + jmp .yesZero1 + .noZero1: + idiv ebx + mov [.dx12],eax + .yesZero1: + + mov ax,[.x3] ; calculate delta 13 + sub ax,[.x1] + cwde + shl eax,ROUND + cdq + mov bx,[.y3] + mov cx,[.y1] + sub bx,cx + ;cmp ebx,0 + jne .noZero2 + mov dword[.dx13],0 + jmp .yesZero2 + .noZero2: + idiv ebx + mov [.dx13],eax + .yesZero2: + + mov ax,[.x3] ; calculate delta 23 [dx23] + sub ax,[.x2] + cwde + shl eax,ROUND + cdq + mov bx,[.y3] + mov cx,[.y2] + sub bx,cx + ;cmp ebx,0 + jne .noZero3 + mov dword[.dx23],0 + jmp .yesZero3 + .noZero3: + idiv ebx + mov [.dx23],eax + .yesZero3: + + movsx eax,word[.x1] ; eax - xk1 ;;; + shl eax,ROUND + mov ebx,eax ; ebx - xk2 ;;; + movsx esi,word[.y1] ; esi - y + .next_line1: + mov ecx,eax ; ecx - x11 + sar ecx,ROUND + mov edx,ebx ; edx - x12 + sar edx,ROUND + cmp ecx,edx + jle .nochg + xchg ecx,edx + .nochg: + pusha + mov ebx,ecx + sub edx,ecx + mov ecx,edx + mov edx,esi + mov eax,[.col] + call .horizontal_line + popa + add eax,[.dx13] + add ebx,[.dx12] + inc esi + cmp si,[.y2] + jl .next_line1 + + movzx esi,word[.y2] + movzx ebx,word[.x2] + shl ebx,ROUND + .next_line2: + mov ecx,eax + sar ecx,ROUND + mov edx,ebx + sar edx,ROUND + cmp ecx,edx + jle .nochg1 + xchg ecx,edx + .nochg1: + pusha + mov ebx,ecx + sub edx,ecx + mov ecx,edx + mov edx,esi + mov eax,[.col] + call .horizontal_line + popa + add eax,[.dx13] + add ebx,[.dx23] + inc esi + cmp si,[.y3] + jl .next_line2 + .end_triangle: + + mov esp,ebp +ret + +.horizontal_line: + ;---------in + ;---------eax - color of line, 0x00RRGGBB + ;---------ebx - x1 - x position of line begin + ;---------ecx - lenght of line + ;---------edx - y position of line + ;---------edi - pointer to buffer + jcxz .end_hor_l +; or edx,edx +; jl .end_hor_l + cmp edx,SIZE_Y + jg .end_hor_l + push eax + mov eax,SIZE_X*3 + mul edx + add edi,eax ; calculate line begin adress + ;add edi,ebx + ;shl ebx,1 + lea edi,[edi+ebx*2] + add edi,ebx + pop eax + cld + ;mov dword[edi-3],0000FF00h + dec ecx + jecxz .last_pix + .ddraw: ; Drawing horizontally: + ;push eax + stosd ; 4 bytes at a time + dec edi ; point to the 4th + loop .ddraw + .last_pix: + stosw + shr eax,16 + stosb +; mov byte[edi],0 ; The last 4th will be reset + .end_hor_l: +ret diff --git a/programs/demos/3DS/FLATWAV.ASM b/programs/demos/3DS/FLATWAV.ASM deleted file mode 100644 index 7ae0f76572..0000000000 --- a/programs/demos/3DS/FLATWAV.ASM +++ /dev/null @@ -1,762 +0,0 @@ -; -; application : Flag - Polonia in Tertio Millenium - wavy shading rotary area -; compiler : FASM -; system : MenuetOS -; author : macgub -; email : macgub3@wp.pl -; web : www.menuet.xt.pl -; Fell free to use this intro in your own distribution of MenuetOS. -SIZE_X equ 220 -SIZE_Y equ 260 -TIMEOUT equ 1 -ROUND equ 12 -points_count equ 50 -triangles_count equ 54 - -use32 - - org 0x0 - - db 'MENUET01' ; 8 byte id - dd 0x01 ; header version - dd START ; start of code - dd I_END ; size of image - dd I_END ; memory for app - dd I_END ; esp - dd 0x0 , 0x0 ; I_Param , I_Icon - -START: ; start of execution - - call draw_window - ; call generate_map - -still: - - mov eax,23 ; wait here for event with timeout - mov ebx,TIMEOUT - cmp [speed_flag],0xff - jne speed_skip - mov eax,11 - speed_skip: - int 0x40 - - cmp eax,1 ; redraw request ? - je red - cmp eax,2 ; key in buffer ? - je key - cmp eax,3 ; button in buffer ? - je button - - jmp noclose - - red: ; redraw - call draw_window - jmp noclose - - key: ; key - mov eax,2 ; just read it and ignore - int 0x40 - jmp noclose - - button: ; button - mov eax,17 ; get id - int 0x40 - - cmp ah,1 ; button id=1 ? - jne shad_button - mov eax,-1 ; close this program - int 0x40 - shad_button: - cmp ah,2 - jne speed_button - not [shad_flag] ; set shadow / flag mode - speed_button: - cmp ah,3 - jne noclose - not [speed_flag] - noclose: - - call calculate_angle ; calculates sinus and cosinus - call generate_map - call copy_points - call rotate_points - call translate_points ; translate from 3d to 2d - call clrscr ; clear the screen - call sort_triangles - call draw_triangles ; draw all triangles from the list - - mov eax,7 ; put image - mov ebx,screen - mov ecx,SIZE_X shl 16 + SIZE_Y - mov edx,5 shl 16 + 20 - int 0x40 - - jmp still -generate_map: - finit - mov edi,points - xor ebx,ebx ;z - again_gen1: - mov eax,70 ;x - again_gen: - mov word[edi],ax - mov word[edi+4],bx - fild word[edi] - fidiv [i20] - fadd [current_angle] - fsin - fimul [i20] - fiadd [i75] - fistp word [edi+2] -; fild word[edi] ;another map generation -; fisub [i100] -; fidiv [i75] -; fmul st,st0 -; fild word[edi+4] -; fisub [i50] -; fidiv [i20] -; fmul st,st0 -; faddp -; fsqrt -; fadd [current_angle] -; fsin -; fimul [i20] -; fiadd [i75] -; fistp word[edi+2] - - add ax,10 - add edi,6 - cmp ax,170 - jne again_gen - add bx,20 - cmp bx,100 - jne again_gen1 - mov dword[edi],0xffffffff -ret -i20 dw 20 -i50 dw 50 -i75 dw 75 -i100 dw 100 - -sort_triangles: - mov esi,triangles - mov edi,triangles_with_z - mov ebp,points_rotated - - make_triangle_with_z: ;makes list with triangles and z position - xor eax,eax - mov ax,word[esi] - shl eax,1 - mov ebx,eax - shl eax,1 - add eax,ebx - push ebp - add ebp,eax - xor ecx,ecx - mov cx,word[ebp+4] - pop ebp - - xor eax,eax - mov ax,word[esi+2] - shl eax,1 - mov ebx,eax - shl eax,1 - add eax,ebx - push ebp - add ebp,eax - add cx,word[ebp+4] - pop ebp - - xor eax,eax - mov ax,word[esi+4] - shl eax,1 - mov ebx,eax - shl eax,1 - add eax,ebx - push ebp - add ebp,eax - add cx,word[ebp+4] - pop ebp - - mov ax,cx - cwd - idiv [i3] - cld - movsd ; store vertex coordinates - movsw - stosw ; middle vertex coordinate 'z' in triangles_with_z list - cmp dword[esi],0xffffffff - jne make_triangle_with_z - movsd ; copy end mark - -;macro sort - - mov [sort_flag],1 - next_booble: - mov esi,triangles_with_z ;sort list triangles_with_z booble metod - cmp [sort_flag],0 - je end_sort - mov [sort_flag],0 - check_and_check: - ; cmp dword[esi],0xffffffff - ; je next_booble - cmp dword[esi+8],0xffffffff - je next_booble - mov ax,word[esi+6] - cmp ax,word[esi+14] - jge no_chg_pos - mov eax,dword[esi] - mov ebx,dword[esi+4] - xchg eax,dword[esi+8] - xchg ebx,dword[esi+12] - mov dword[esi],eax - mov dword[esi+4],ebx ; sort_flag=1 if change occured - mov [sort_flag],1 - no_chg_pos: - add esi,8 - jmp check_and_check ;check end mark end if greater - end_sort: - - ; translate triangles_with_z to sorted_triangles - mov esi,triangles_with_z - mov edi,sorted_triangles - again_copy: - movsd - movsw - add esi,2 - cmp dword[esi],0xffffffff - jne again_copy - movsd ; copy end mark too -ret -sort_flag db 0 -clrscr: - mov edi,screen - mov ecx,SIZE_X*SIZE_Y*3/4 - xor eax,eax - cld - rep stosd -ret -calculate_angle: - finit - fldpi - fidiv [i180] - fimul [angle_counter] - fst [current_angle] - fld st - fidiv [i2] - fsincos - fstp [singamma] - fstp [cosgamma] - fsincos - fstp [sinbeta] - fstp [cosbeta] - inc [angle_counter] - cmp [angle_counter],360 - jne end_calc_angle - mov [angle_counter],0 - end_calc_angle: -ret -i180 dw 90 -i2 dw 2 -rotate_points: - finit ; y axle rotate - mov ebx,points_rotated - again_r: - mov ax,word[ebx] ;x - sub ax,[xo] - mov [xsub],ax - mov ax,word[ebx+4] ;z - sub ax,[zo] - mov [zsub],ax - fld [sinbeta] - fimul [zsub] - fchs - fld [cosbeta] - fimul [xsub] - faddp - fiadd [xo] - fistp word[ebx] ;x - fld [sinbeta] - fimul [xsub] - ;fchs - fld [cosbeta] - fimul [zsub] - faddp - fiadd [zo] - fistp word[ebx+4] ;z - - mov ax,word[ebx+2] ;y ; z axle rotate - sub ax,[yo] - mov [ysub],ax - mov ax,word[ebx] ;x - sub ax,[xo] - mov [xsub],ax - fld [singamma] - fimul[ysub] - fld [cosgamma] - fimul [xsub] - faddp - fiadd [xo] - fistp word[ebx] ;x - fld [cosgamma] - fimul [ysub] - fld [singamma] - fimul [xsub] - fchs - faddp - fiadd [yo] - fistp word[ebx+2] ;y - - add ebx,6 - cmp dword[ebx],0xffffffff - jne again_r -ret -xsub dw ? -ysub dw ? -zsub dw ? -draw_triangles: - mov [tr_counter],1 - mov ebp,points_rotated -; mov esi,triangles - mov esi,sorted_triangles - again_dts: - xor eax,eax - mov ax,word[esi] - shl eax,1 - mov [dtpom],eax - shl eax,1 - add eax,[dtpom] - push ebp - add ebp,eax - mov ax,word[ebp] - mov [xx1],ax - mov ax,word[ebp+2] - mov [yy1],ax - mov ax,word[ebp+4] - mov [zz1],ax - pop ebp - - xor eax,eax - mov ax,word[esi+2] - shl eax,1 - mov [dtpom],eax - shl eax,1 - add eax,[dtpom] - push ebp - add ebp,eax - mov ax,word[ebp] - mov [xx2],ax - mov ax,word[ebp+2] - mov [yy2],ax - mov ax,word[ebp+4] - mov [zz2],ax - pop ebp - - xor eax,eax - mov ax,word[esi+4] - shl eax,1 - mov [dtpom],eax - shl eax,1 - add eax,[dtpom] - push ebp - add ebp,eax - mov ax,word[ebp] - mov [xx3],ax - mov ax,word[ebp+2] - mov [yy3],ax - mov ax,word[ebp+4] - mov [zz3],ax - pop ebp - push ebp - push esi - -macro set_flag -{ - mov edx,0x00ffffff - inc [tr_counter] - cmp [tr_counter],triangles_count/2 - jl skip_red - set_red: - mov edx,0x00ff0000 - skip_red: -} - - mov ax,[zz1] - add ax,[zz2] - add ax,[zz3] - cwd - idiv [i3] - sub ax,100 ;77 -; shl ax,1 - neg al - xor edx,edx - mov dh,al ;set color according to z position - mov dl,al -; push dx -; shl edx,8 -; pop dx - - cmp [shad_flag],0 - je skip_col - set_flag - skip_col: - mov ax,[xx1] - shl eax,16 - mov ax,[yy1] - mov bx,[xx2] - shl ebx,16 - mov bx,[yy2] - mov cx,[xx3] - shl ecx,16 - mov cx,[yy3] - mov edi,screen - call draw_triangle - pop esi - pop ebp - - add esi,6 - cmp dword[esi],0xffffffff - jne again_dts -ret -i3 dw 3 -tr_counter dw 0 -dtpom dd ? -xx1 dw ? -yy1 dw ? -zz1 dw ? -xx2 dw ? -yy2 dw ? -zz2 dw ? -xx3 dw ? -yy3 dw ? -zz3 dw ? -translate_points: - finit - mov ebx,points_rotated - again_trans: - fild word[ebx+4] ;z1 - fmul [sq] - fld st - fiadd word[ebx] ;x1 - fistp word[ebx] - fchs - fiadd word[ebx+2] ;y1 - fistp word[ebx+2] ;y1 - - add ebx,6 - cmp dword[ebx],0xffffffff - jne again_trans -ret -copy_points: - mov esi,points - mov edi,points_rotated - mov ecx,points_count*3+2 - cld - rep movsw -ret - -draw_triangle: -;----------in - eax - x1 shl 16 + y1 -;------------- -ebx - x2 shl 16 + y2 -;---------------ecx - x3 shl 16 + y3 -;---------------edx - color 0x00rrggbb -;---------------edi - pointer to screen buffer - @ch3: - cmp ax,bx - jg @ch1 - @ch4: ; sort parameters - cmp bx,cx - jg @ch2 - jle @chEnd - @ch1: - xchg eax,ebx - jmp @ch4 - @ch2: - xchg ebx,ecx - jmp @ch3 - @chEnd: - mov [@y1],ax ; ....and store to user friendly variables - mov [@y2],bx - mov [@y3],cx - shr eax,16 - shr ebx,16 - shr ecx,16 - mov [@x1],ax - mov [@x2],bx - mov [@x3],cx - mov [@col],edx - - cmp [@y1],0 - jl @end_triangle - cmp [@y2],0 - jl @end_triangle - cmp [@y3],0 - jl @end_triangle - cmp [@x1],0 - jl @end_triangle - cmp [@x2],0 - jl @end_triangle - cmp [@x3],0 - jl @end_triangle - cmp [@y1],SIZE_Y - jg @end_triangle - cmp [@y2],SIZE_Y - jg @end_triangle - cmp [@y3],SIZE_Y - jg @end_triangle - cmp [@x1],SIZE_X - jg @end_triangle - cmp [@x2],SIZE_X - jg @end_triangle - cmp [@x3],SIZE_X - jg @end_triangle - - neg ax ; calculate delta 12 - add ax,bx - cwde - shl eax,ROUND - cdq - mov bx,[@y2] - mov cx,[@y1] - sub ebx,ecx - cmp ebx,0 - jne @noZero1 - mov [@dx12],0 - jmp @yesZero1 - @noZero1: - idiv ebx - mov [@dx12],eax - @yesZero1: - - mov ax,[@x3] ; calculate delta 13 - sub ax,[@x1] - cwde - shl eax,ROUND - cdq - xor ebx,ebx - xor ecx,ecx - or bx,[@y3] - or cx,[@y1] - sub ebx,ecx - cmp ebx,0 - jne @noZero2 - mov [@dx13],0 - jmp @yesZero2 - @noZero2: - idiv ebx - mov [@dx13],eax - @yesZero2: - - mov ax,[@x3] ; calculate delta 23 [dx23] - sub ax,[@x2] - cwde - shl eax,ROUND - cdq - xor ebx,ebx - xor ecx,ecx - or bx,[@y3] - or cx,[@y2] - sub ebx,ecx - cmp ebx,0 - jne @noZero3 - mov [@dx23],0 - jmp @yesZero3 - @noZero3: - idiv ebx - mov [@dx23],eax - @yesZero3: - - - xor eax,eax ;eax - xk1 - or ax,[@x1] - shl eax,ROUND - mov ebx,eax ; ebx - xk2 - xor esi,esi ; esi - y - or si,[@y1] - @next_line1: - mov ecx,eax ; ecx - x11 - sar ecx,ROUND - mov edx,ebx ;edx - x12 - sar edx,ROUND - cmp ecx,edx - jle @nochg - xchg ecx,edx - @nochg: - pusha - mov ebx,ecx - sub edx,ecx - mov ecx,edx - mov edx,esi - mov eax,[@col] - call @horizontal_line - popa - add eax,[@dx13] - add ebx,[@dx12] - inc esi - cmp si,[@y2] - jl @next_line1 - - xor esi,esi - or si,[@y2] - xor ebx,ebx - mov bx,[@x2] - shl ebx,ROUND - @next_line2: - mov ecx,eax - sar ecx,ROUND - mov edx,ebx - sar edx,ROUND - cmp ecx,edx - jle @nochg1 - xchg ecx,edx - @nochg1: - pusha - mov eax,[@col] - mov ebx,ecx - sub edx,ecx - mov ecx,edx - mov edx,esi - call @horizontal_line - popa - add eax,[@dx13] - add ebx,[@dx23] - inc esi - cmp si,[@y3] - jl @next_line2 - @end_triangle: -ret -@col dd ? -@y1 dw ? -@x1 dw ? -@y2 dw ? -@x2 dw ? -@y3 dw ? -@x3 dw ? -@dx12 dd ? -@dx13 dd ? -@dx23 dd ? - -@horizontal_line: -;---------in -;---------eax - color of line, 0x00RRGGBB -;---------ebx - x1 - x position of line begin -;---------ecx - lenght of line -;---------edx - y position of line -;---------edi - pointer to buffer - jcxz @end_hor_l - push eax - mov eax,SIZE_X*3 - mul edx - add edi,eax ; calculate line begin adress - add edi,ebx - shl ebx,1 - add edi,ebx - pop eax - cld - @ddraw: - push eax - stosw - shr eax,16 - stosb - pop eax - loop @ddraw - @end_hor_l: -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 ebx,100*65536+SIZE_X+20 ; [x start] *65536 + [x size] - mov ecx,100*65536+SIZE_Y+30 ; [y start] *65536 + [y size] - mov edx,0x04000000 ; color of work area RRGGBB,8->color gl - mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl - mov edi,0x005080d0 ; color of frames RRGGBB - int 0x40 - - ; WINDOW LABEL - mov eax,4 ; function 4 : write text to window - mov ebx,8*65536+8 ; [x start] *65536 + [y start] - mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) - mov edx,labelt ; pointer to text beginning - mov esi,labellen-labelt ; text length - int 0x40 - - ; flag color button - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X-35)*65536+12 ; [x start] *65536 + [x size] - mov ecx,5*65536+12 ; [y start] *65536 + [y size] - mov edx,2 ; button id - mov esi,0x64504A ; button color RRGGBB - int 0x40 - - ; speed button - mov eax,8 ; function 8 : define and draw button - mov ebx,(SIZE_X-53)*65536+12 ; [x start] *65536 + [x size] - mov ecx,5*65536+12 ; [y start] *65536 + [y size] - mov edx,3 ; button id - mov esi,0x64504A ; button color RRGGBB - int 0x40 - - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw - int 0x40 - - ret - - -; DATA AREA -angle_counter dw 0 -sq dd 0.707 -xo dw 110 ;87 -zo dw 0 -yo dw 125 -shad_flag db 0 -speed_flag db 0 - -triangles: -dw 0,1,10, 10,11,1, 1,2,11, 11,12,2, 2,3,12, 12,13,3, 3,4,13, 13,14,4, 4,5,14 -dw 14,15,5, 5,6,15, 15,16,6, 6,7,16, 16,17,7, 7,8,17, 17,18,8, 8,9,18, 18,19,9 -dw 10,11,20, 20,21,11, 11,12,21, 21,22,12, 12,13,22, 22,23,13, 13,14,23 -dw 23,24,14, 14,15,24, 24,25,15, 15,16,25, 25,26,16, 16,17,26, 26,27,17 -dw 17,18,27, 27,28,18, 18,19,28, 28,29,19, 20,21,30, 30,31,21, 21,22,31 -dw 31,32,22, 22,23,32, 32,33,23, 23,24,33, 33,34,24, 24,25,34, 34,35,25 -dw 25,26,35, 35,36,26, 26,27,36, 36,37,27, 27,28,37, 37,38,28, 28,29,38 -dw 38,39,29 - dd 0xffffffff ;<- end marker - - - -labelt: - db '3d wavy rotaring area' -labellen: -sinbeta rd 1 -cosbeta rd 1 -singamma rd 1 -cosgamma rd 1 -current_angle rd 1 - -points rw points_count*3 + 2 -points_rotated rw points_count*3 + 2 -triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position -sorted_triangles rw triangles_count*3 + 2 -screen rb SIZE_X * SIZE_Y * 3 ; screen buffer -memStack rb 1000 ;memory area for stack -I_END: - - - - diff --git a/programs/demos/3DS/FLAT_CAT.ASM b/programs/demos/3DS/FLAT_CAT.INC similarity index 78% rename from programs/demos/3DS/FLAT_CAT.ASM rename to programs/demos/3DS/FLAT_CAT.INC index c07458ecc9..79dabae351 100644 --- a/programs/demos/3DS/FLAT_CAT.ASM +++ b/programs/demos/3DS/FLAT_CAT.INC @@ -1,10 +1,6 @@ CATMULL_SHIFT equ 16 -fill_Z_buffer: - mov eax,0x70000000 - mov edi,Z_buffer - mov ecx,SIZE_X*SIZE_Y - rep stosd -ret + + flat_triangle_z: ; procedure drawing triangle with Z cordinate interpolation ------ ; (Catmull alghoritm)-------------------------------------------- @@ -30,15 +26,24 @@ flat_triangle_z: .y3 equ word[ebp-16] .dx12 equ dword[ebp-20] -.dz12 equ dword[ebp-24] -.dx13 equ dword[ebp-28] -.dz13 equ dword[ebp-32] +;.dz12 equ dword[ebp-24] +.dx13 equ dword[ebp-24] +.dz13 equ dword[ebp-28] +.dz12 equ dword[ebp-32] +;.dz13 equ dword[ebp-32] .dx23 equ dword[ebp-36] -.dz23 equ dword[ebp-40] -.zz1 equ dword[ebp-44] -.zz2 equ dword[ebp-48] - +.dz13M equ [ebp-40] +.dz23 equ dword[ebp-44] +.zz1 equ dword[ebp-48] +.zz2 equ dword[ebp-52] +.zz2M equ qword[ebp-52] +.dz12M equ qword[ebp-32] +.dz23M equ qword[ebp-44] +;if Ext>=MMX +; emms +;end if mov ebp,esp + push edx ; store edx in variable .col .sort2: cmp ax,bx @@ -82,7 +87,7 @@ flat_triangle_z: ; jle @f ; jmp .ft_loop2_end ;@@: - sub esp,32 + sub esp,52-12 mov bx,.y2 ; calc delta 12 sub bx,.y1 @@ -113,6 +118,7 @@ flat_triangle_z: jnz .ft_dx13_make mov .dx13,0 mov .dz13,0 + mov dword .dz13M,0 jmp .ft_dx13_done .ft_dx13_make: mov ax,.x3 @@ -131,6 +137,7 @@ flat_triangle_z: cdq idiv ebx mov .dz13,eax + mov dword .dz13M,eax .ft_dx13_done: mov bx,.y3 ; calc delta 23 sub bx,.y2 @@ -164,6 +171,9 @@ flat_triangle_z: movsx eax,.x1 shl eax,ROUND ; eax - x1 mov ebx,eax ; ebx - x2 +;if Ext>=MMX +; movq mm0,.zz2M +;end if mov cx,.y1 cmp cx,.y2 jge .ft_loop1_end @@ -177,18 +187,28 @@ flat_triangle_z: push bx ; x2 sar eax,ROUND push ax ; x1 +;if Ext>=MMX +; sub esp,8 +; movq [esp],mm0 +;else push .zz2 ; z2 shl CATMULL_SHIFT push .zz1 ; z1 shl CATMULL_SHIFT +;end if call flat_line_z popad add eax,.dx13 add ebx,.dx12 +;if Ext>=MMX +; paddd mm0,.dz12M +;else + mov edx,.dz13 add .zz1,edx mov edx,.dz12 add .zz2,edx +;end if inc cx cmp cx,.y2 jl .ft_loop1 @@ -199,6 +219,13 @@ flat_triangle_z: mov .zz2,edx movsx ebx,.x2 shl ebx,ROUND +;if Ext>=MMX +; movq mm0,.zz2M +;; push .dz13 ; exchange +;; pop .dz12 +;; push .dz23 ; exchange +;; pop .dz13 +;end if mov cx,.y2 cmp cx,.y3 jge .ft_loop2_end @@ -211,18 +238,32 @@ flat_triangle_z: push bx sar eax,ROUND push ax ; x1 +;if Ext>=MMX +; sub esp,8 +; movq [esp],mm0 +;else push .zz2 ; z2 shl CATMULL_SHIFT push .zz1 ; z1 shl CATMULL_SHIFT +;end if call flat_line_z popad add eax,.dx13 add ebx,.dx23 +;if Ext>=MMX +; paddd mm0,.dz23M +;else mov edx,.dz13 add .zz1,edx mov edx,.dz23 add .zz2,edx + +; mov edx,.dz13 +; add .zz1,edx +; mov edx,.dz12 +; add .zz2,edx +;end if inc cx cmp cx,.y3 jl .ft_loop2 @@ -250,6 +291,9 @@ flat_line_z: mov ax,.y or ax,ax jl .fl_quit +;; mov bx,[size_y] +;; dec bx + cmp ax,[size_y] cmp ax,SIZE_Y-1 jg .fl_quit @@ -274,6 +318,8 @@ flat_line_z: xchg edx,.z2 mov .z1,edx .fl_ok: + ;; mov bx,[size_x] + ;; dec bx cmp .x1,SIZE_X-1 jg .fl_quit cmp .x2,0 @@ -320,23 +366,31 @@ flat_line_z: mov eax,.col mov ebx,.z1 ; ebx : curr. z mov edx,.dz + dec ecx + jecxz .draw_last .ddraw: - ;pushad - ;show - ;popad cmp ebx,dword[esi] - jge .skip + jge @f stosd dec edi mov dword[esi],ebx jmp .no_skip - .skip: + @@: add edi,3 .no_skip: add esi,4 add ebx,edx loop .ddraw + .draw_last: + cmp ebx,dword[esi] + jge .fl_quit + stosw + shr eax,16 + stosb + mov dword[esi],ebx + .fl_quit: + mov esp,ebp ret 18 diff --git a/programs/demos/3DS/GRD3.ASM b/programs/demos/3DS/GRD3.INC similarity index 100% rename from programs/demos/3DS/GRD3.ASM rename to programs/demos/3DS/GRD3.INC diff --git a/programs/demos/3DS/GRD_CAT.ASM b/programs/demos/3DS/GRD_CAT.INC similarity index 79% rename from programs/demos/3DS/GRD_CAT.ASM rename to programs/demos/3DS/GRD_CAT.INC index 26942aaddd..f5ea30e8bc 100644 --- a/programs/demos/3DS/GRD_CAT.ASM +++ b/programs/demos/3DS/GRD_CAT.INC @@ -1,6 +1,7 @@ ROUND equ 8 CATMULL_SHIFT equ 8 gouraud_triangle_z: + ;----procedure drawing gouraud triangle with z coordinate ;----interpolation ( Catmull alghoritm )----------------- ;------------------in - eax - x1 shl 16 + y1 ------------ @@ -50,14 +51,30 @@ gouraud_triangle_z: .dc23g equ dword[ebp-68] .dc23b equ dword[ebp-72] -.c1r equ dword[ebp-76] -.c1g equ dword[ebp-80] -.c1b equ dword[ebp-84] -.c2r equ dword[ebp-88] -.c2g equ dword[ebp-92] -.c2b equ dword[ebp-96] -.zz1 equ dword[ebp-100] -.zz2 equ dword[ebp-104] +.zz1 equ dword[ebp-76] +.c1r equ dword[ebp-80] +.c1g equ dword[ebp-84] +.c1b equ dword[ebp-88] +.zz2 equ dword[ebp-92] +.c2r equ dword[ebp-96] +.c2g equ dword[ebp-100] +.c2b equ dword[ebp-104] +;.zz1 equ dword[ebp-100] +;.zz2 equ dword[ebp-104] + +.c1bM equ [ebp-88] +.c2bM equ [ebp-104] +.c1rM equ [ebp-80] +.c2rM equ [ebp-96] +.dc23bM equ [ebp-72] +.dc13bM equ [ebp-52] +.dc12bM equ [ebp-32] +.dc12rM equ [ebp-24] +.dc13rM equ [ebp-44] +.dc23rM equ [ebp-64] +if Ext=MMX + emms +end if mov ebp,esp ; sub esp,84 @@ -141,7 +158,7 @@ gouraud_triangle_z: idiv ebx ; mov .dc12g,eax push eax - mov ax,word[.col2b] + mov ax,word[.col2b] ;;--- sub ax,word[.col1b] cwde shl eax,ROUND @@ -323,7 +340,21 @@ gouraud_triangle_z: call gouraud_line_z popad +if Ext >= MMX + movq mm0,.c1bM + paddd mm0,qword .dc13bM + movq .c1bM,mm0 + movq mm1,.c2bM + paddd mm1,qword .dc12bM + movq .c2bM,mm1 + movq mm0,.c1rM + paddd mm0,qword .dc13rM + movq .c1rM,mm0 + movq mm1,.c2rM + paddd mm1,qword .dc12rM + movq .c2rM,mm1 +else mov edx,.dc13r add .c1r,edx mov edx,.dc13g @@ -336,11 +367,12 @@ gouraud_triangle_z: add .c2g,edx mov edx,.dc12b add .c2b,edx + mov edx,.dz13 add .zz1,edx mov edx,.dz12 add .zz2,edx - +end if add eax,.dx13 add ebx,.dx12 inc cx @@ -400,6 +432,21 @@ gouraud_triangle_z: popad +if Ext >= MMX + movq mm0,.c1bM + paddd mm0,qword .dc13bM + movq .c1bM,mm0 + movq mm1,.c2bM + paddd mm1,qword .dc23bM + movq .c2bM,mm1 + + movq mm0,.c1rM + paddd mm0,qword .dc13rM + movq .c1rM,mm0 + movq mm1,.c2rM + paddd mm1,qword .dc23rM + movq .c2rM,mm1 +else mov edx,.dc13r add .c1r,edx mov edx,.dc13g @@ -416,7 +463,7 @@ gouraud_triangle_z: add .zz1,edx mov edx,.dz23 add .zz2,edx - +end if add eax,.dx13 add ebx,.dx23 inc cx @@ -443,13 +490,25 @@ gouraud_line_z: .c2b equ ebp+24 .c2g equ ebp+26 .c2r equ ebp+28 + .dz equ dword[ebp-4] -.dc_r equ dword[ebp-8] +.dc_b equ dword[ebp-8] .dc_g equ dword[ebp-12] -.dc_b equ dword[ebp-14] -.cr equ dword[ebp-18] -.cg equ dword[ebp-22] -.cb equ dword[ebp-26] +.dc_r equ dword[ebp-16] +.c_z equ dword[ebp-20] +.cb equ dword[ebp-24] +.cg equ dword[ebp-28] +.cr equ dword[ebp-32] +;.cg2 equ dword[ebp-36] + + +.crM equ ebp-32 +.cgM equ ebp-28 +.cbM equ ebp-24 + +.dc_rM equ ebp-16 +.dc_gM equ ebp-12 +.dc_bM equ ebp-8 mov ebp,esp mov ax,.y @@ -486,10 +545,10 @@ gouraud_line_z: idiv ebx push eax - mov ax,word[.c2r] - sub ax,word[.c1r] + mov ax,word[.c2b] + sub ax,word[.c1b] cwde - shl eax,ROUND ; dc_r = c2r-c1r/x2-x1 + shl eax,ROUND cdq idiv ebx push eax @@ -502,15 +561,15 @@ gouraud_line_z: idiv ebx push eax - mov ax,word[.c2b] - sub ax,word[.c1b] + mov ax,word[.c2r] + sub ax,word[.c1r] cwde - shl eax,ROUND + shl eax,ROUND ; dc_r = c2r-c1r/x2-x1 cdq idiv ebx push eax - cmp word[.x1],0 + cmp word[.x1],0 ; clipping on function jg @f mov eax,.dz movsx ebx,word[.x1] @@ -539,7 +598,7 @@ gouraud_line_z: jl @f mov word[.x2],SIZE_X @@: - sub esp,12 ; calculate memory begin + sub esp,16 ; calculate memory begin mov edx,SIZE_X ; in buffers movzx eax,.y mul edx @@ -556,6 +615,9 @@ gouraud_line_z: sub cx,word[.x1] movzx ecx,cx mov ebx,.z1 ; ebx - currrent z shl CATMULL_SIFT +;if Ext >= SSE +; mov .cz,edx +;end if mov edx,.dz ; edx - delta z movzx eax,word[.c1r] shl eax,ROUND @@ -566,9 +628,37 @@ gouraud_line_z: movzx eax,word[.c1b] shl eax,ROUND mov .cb,eax +if Ext = MMX +; mov .c_z,edx + movd mm2,[.dc_bM] ; delta color blue MMX + movd mm3,[.cbM] ; current blue MMX + movq mm5,[.dc_rM] + movq mm4,[.crM] + pxor mm6,mm6 +end if + + .ddraw: - cmp ebx,dword[esi] - jge .skip +;if Ext = MMX +; movq mm0,mm3 +; psrsq mm0,32 +; movd ebx,mm0 +;end if + cmp ebx,dword[esi] ; esi - z_buffer + jge @f ; edi - Screen buffer +if Ext = MMX + movq mm0,mm3 ; mm0, mm1 - temp registers + psrld mm0,ROUND + movq mm1,mm4 + psrld mm1,ROUND + packssdw mm1,mm0 + packuswb mm1,mm6 +; movd [edi],mm1 + movd eax,mm1 + stosw + shr eax,16 + stosb +else mov eax,.cr sar eax,ROUND stosb @@ -578,21 +668,31 @@ gouraud_line_z: mov eax,.cb sar eax,ROUND stosb +end if mov dword[esi],ebx +;if Ext = NON jmp .no_skip - .skip: +;end if + @@: add edi,3 .no_skip: add esi,4 +;if Ext=NON add ebx,edx - mov eax,.dc_r - add .cr,eax +;end if +if Ext=MMX + paddd mm3,mm2 + paddd mm4,mm5 +else mov eax,.dc_g add .cg,eax mov eax,.dc_b add .cb,eax + mov eax,.dc_r + add .cr,eax +end if loop .ddraw .gl_quit: mov esp,ebp -ret 26 \ No newline at end of file +ret 26 diff --git a/programs/demos/3DS/GRD_TEX.INC b/programs/demos/3DS/GRD_TEX.INC new file mode 100644 index 0000000000..191c2016b0 --- /dev/null +++ b/programs/demos/3DS/GRD_TEX.INC @@ -0,0 +1,929 @@ + + +CATMULL_SHIFT equ 8 +ROUND equ 8 +;NON=0 +;MMX=1 +;Ext=MMX +;TEX_SIZE=0x3fff +;SIZE_X equ 512 +;SIZE_Y equ 512 +;ROUND = 8 +;TEX_SHIFT equ 6 + +; procedure drawing textured triangle with Gouraud shading +; Z-buffer alghoritm included, Z coord interpolation ---- +; I set the color by this way -- (col1 * col2)/256 ------ +;------------------in - eax - x1 shl 16 + y1 ------------ +;---------------------- ebx - x2 shl 16 + y2 ------------ +;---------------------- ecx - x3 shl 16 + y3 ------------ +;---------------------- esi - pointer to Z-buffer-------- +;---------------------- edx - pointer to texture--------- +;---------------------- Z-buffer filled with dd variables +;---------------------- shifted CATMULL_SHIFT------------ +;---------------------- edi - pointer to screen buffer--- +;---------------------- stack : colors------------------- + + + +tex_plus_grd_triangle: +; parameters : + .tex_y3 equ [ebp+38] ; 36 bytes through stack + .tex_x3 equ [ebp+36] + .tex_y2 equ [ebp+34] + .tex_x2 equ [ebp+32] + .tex_y1 equ [ebp+30] + .tex_x1 equ [ebp+28] + + .z3 equ [ebp+26] + .col3b equ [ebp+24] + .col3g equ [ebp+22] + .col3r equ [ebp+20] + + .z2 equ [ebp+18] + .col2b equ [ebp+16] + .col2g equ [ebp+14] + .col2r equ [ebp+12] + + .z1 equ [ebp+10] + .col1b equ [ebp+8] + .col1g equ [ebp+6] + .col1r equ [ebp+4] + +; local variables: + + .tex_ptr equ dword[ebp-4] + .z_ptr equ dword[ebp-8] + .scr_buff equ dword[ebp-12] + + .x1 equ word[ebp-14] ;dw ? ;equ word[ebp-10] + .y1 equ word[ebp-16] ;dw ? ;equ word[ebp-12] + .x2 equ word[ebp-18] ;dw ? ;equ word[ebp-14] + .y2 equ word[ebp-20] ;dw ? ;equ word[ebp-16] + .x3 equ word[ebp-22] ;dw ? ;equ word[ebp-18] + .y3 equ word[ebp-24] ;dw ? ;equ word[ebp-20] + + .dx12 equ dword[ebp-28] ;dd ? + .tex_dx12 equ dword[ebp-32] ;dd ? + .tex_dy12 equ dword[ebp-36] ;dd ? + .dz12 equ dword[ebp-40] ;dd ? + .dc12r equ dword[ebp-44] ;dd ? + .dc12g equ dword[ebp-48] ;dd ? + .dc12b equ dword[ebp-52] ;dd ? + + .dx23 equ dword[ebp-56] ;dd ? + .tex_dx23 equ dword[ebp-60] ;dd ? + .tex_dy23 equ dword[ebp-64] ;dd ? + .dz23 equ dword[ebp-68] ;dd ? + .dc23r equ dword[ebp-72] ;dd ? + .dc23g equ dword[ebp-76] ;dd ? + .dc23b equ dword[ebp-80] ;dword[ebp-8]dd ? + + .dx13 equ dword[ebp-84] ;dd ? + .tex_dx13 equ dword[ebp-88] ;dd ? + .tex_dy13 equ dword[ebp-92] ;dd ? + .dz13 equ dword[ebp-96] ;dd ? + .dc13r equ dword[ebp-100] ;dd ? + .dc13g equ dword[ebp-104] ;dd ? + .dc13b equ dword[ebp-108] ;dd ? + + .zz1 equ dword[ebp-112] ;dw ? + .zz2 equ dword[ebp-116] ;dw ? + .cur1r equ dword[ebp-120] ;dw ? + .cur1g equ dword[ebp-124] ;dw ? + .cur1b equ dword[ebp-128] ;dw ? + .cur2r equ dword[ebp-132] ;dw ? + .cur2g equ dword[ebp-136] ;dw ? + .cur2b equ dword[ebp-140] ;dw ? + .scan_x1 equ dword[ebp-144] ;dd ? + .scan_x2 equ dword[ebp-148] ;dd ? + .scan_y1 equ dword[ebp-152] ;dd ? + .scan_y2 equ dword[ebp-156] ;dd ? + + + mov ebp,esp +if Ext>=MMX + emms +end if + + ; mov .tex_ptr,edx + ; mov .z_ptr,esi + ; mov .scr_buff,edi + push edx esi edi +; push esi +; push edi + 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 + + .sort3: + cmp ax,bx + jle .sort1 + xchg eax,ebx +if Ext>=MMX + movq mm0, .col1r ; exchange r, g, b, z + movq mm1, .col2r + movq .col1r ,mm1 + movq .col2r ,mm0 +else + mov edx,dword .col1r ; exchange both r and g + xchg edx,dword .col2r + mov dword .col1r ,edx + + mov edx,dword .col1b ; b and z + xchg edx,dword .col2b + mov dword .col1b ,edx +end if + + mov edx,dword .tex_x1 + xchg edx,dword .tex_x2 + mov dword .tex_x1 ,edx + + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + +if Ext>=MMX + movq mm0, .col2r ; exchange r, g, b, z + movq mm1, .col3r + movq .col3r ,mm0 + movq .col2r ,mm1 +else + + mov edx,dword .col2r ; r, g + xchg edx,dword .col3r + mov dword .col2r,edx + + mov edx,dword .col2b ; b, z + xchg edx,dword .col3b + mov dword .col2b,edx +end if + + mov edx,dword .tex_x2 + xchg edx,dword .tex_x3 + mov dword .tex_x2,edx + + jmp .sort3 + + .sort2: + + push eax ebx ecx ; store in variables + ; push ebx + ; push ecx + +;****************** delta computng zone ************** +;+++++++++ first zone + mov bx,.y2 ; calc delta12 + sub bx,.y1 + jnz .dx12_make + mov ecx,7 + @@: + push dword 0 + loop @b + jmp .dx12_done + .dx12_make: + + + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx12,eax + push eax + +if 0 ; Ext=SSE + movd mm0,.col1r ; 2 words r, g + pxor mm1,mm1 + punpcklwd mm0,mm1 + cvtpi2ps xmm0,mm0 + movlhps xmm0,xmm0 + movd mm0,.col1g ; 2 words b, z + punpcklwd mm0,mm1 + cvtpi2ps xmm0,mm0 + ; xmm0=four float double words + divss xmm0,.pack3 + ;convert and insert mm0 to lower xmm1 .. +end if + + mov ax,word .tex_x2 + sub ax,word .tex_x1 + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .tex_dx12r,eax + push eax + + mov ax,word .tex_y2 + sub ax,word .tex_y1 + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .tex_dx12,eax + push eax + + mov ax,word .z2 + sub ax,word .z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz12,eax + push eax ; .dza12 + + mov ax,word .col2r + sub ax,word .col1r + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dc12r,eax + push eax + + mov ax,word .col2g + sub ax,word .col1g + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dc12g,eax + push eax + + mov ax,word .col2b ;;--- + sub ax,word .col1b + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .dc12b,eax + push eax + +;+++++++++++++++++ second zone +++++++++++++ + .dx12_done: + + mov bx,.y3 ; calc delta23 + sub bx,.y2 + jnz .dx23_make + mov ecx,7 + @@: + push dword 0 + loop @b + jmp .dx23_done + + .dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx23,eax + push eax + + mov ax,word .tex_x3 + sub ax,word .tex_x2 + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .tex_dx23,eax + push eax + + mov ax,word .tex_y3 + sub ax,word .tex_y2 + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .tex_dy23,eax + push eax + + mov ax,word .z3 + sub ax,word .z2 + cwde ; + shl eax,CATMULL_SHIFT ; 2222222 + cdq ; 2 2 + idiv ebx ; 2 +; mov .dz23,eax ; 2 + push eax ; .dza12 ; 2 + ; 2 + mov ax,word .col3r ; 2 + sub ax,word .col2r ; 2222222 + cwde ; second delta + shl eax,ROUND ; + cdq ; + idiv ebx ; +; mov .dc23r,eax ; + push eax + + mov ax,word .col3g + sub ax,word .col2g + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .dc23g,eax + push eax + + mov ax,word .col3b ;;--- + sub ax,word .col2b + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .dc23b,eax + push eax + + .dx23_done: +;++++++++++++++++++third zone++++++++++++++++++++++++ + mov bx,.y3 ; calc delta13 + sub bx,.y1 + jnz .dx13_make + mov ecx,7 + @@: + push dword 0 + loop @b + jmp .dx13_done + .dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx +; mov .dx13,eax + push eax + + mov ax,word .tex_x3 ; triangle b + sub ax,word .tex_x1 + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .tex_dx13r,eax + push eax + + mov ax,word .tex_y3 + sub ax,word .tex_y1 + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .tex_dy13,eax + push eax + + mov ax,word .z3 + sub ax,word .z1 ; 333333333 + cwde ; 3 3 + shl eax,CATMULL_SHIFT ; 3 + cdq ; 3 + idiv ebx ; 3 +; mov .dz13,eax ; 3 + push eax ; .dza12 ; 3 + ; 3 + mov ax,word .col3r ; 3333333333 + sub ax,word .col1r ; 3 + cwde ; 3 + shl eax,ROUND ; 3 + cdq ; 3 + idiv ebx ; 3 + ; mov .dc13r,eax ; 3 3 + push eax ; 33333333 + + mov ax,word .col3g + sub ax,word .col1g + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dc13g,eax + push eax + + mov ax,word .col3b ;;--- + sub ax,word .col1b + cwde + shl eax,ROUND + cdq + idiv ebx +; mov .dc13b,eax + push eax + + .dx13_done: + +; <<<<<<< ::delta zone end+++++++++++++++++++++ >>>>>>>> + sub esp,55 ;(12*4) + + movsx eax,.x1 ; eax - cur x1 + shl eax,ROUND ; ebx - cur x2 + mov ebx,eax + movsx edx,word .z1 + shl edx,CATMULL_SHIFT + mov .zz1,edx + mov .zz2,edx + + movzx edi,word .col1r + shl edi,ROUND + mov .cur1r,edi + mov .cur2r,edi + movzx esi,word .col1g + shl esi,ROUND + mov .cur1g,esi + mov .cur2g,esi + movzx edx,word .col1b + shl edx,ROUND + mov .cur1b,edx + mov .cur2b,edx + + movzx edi,word .tex_x1 + shl edi,ROUND + mov .scan_x1,edi + mov .scan_x2,edi + movzx edx,word .tex_y1 + shl edx,ROUND + mov .scan_y1,edx + mov .scan_y2,edx + + mov cx,.y1 + cmp cx,.y2 + jge .loop1_end + .loop_1: + ; push eax ebx ebp + pushad + + push .tex_ptr + push .scr_buff + push .z_ptr + push cx + + push .zz2 + + push .scan_x2 + push .scan_y2 + push .cur2r + push .cur2g + push .cur2b + + push .zz1 + + push .scan_x1 + push .scan_y1 + push .cur1r + push .cur1g + push .cur1b + + sar eax,ROUND + sar ebx,ROUND + call horizontal_tex_grd_line + + ; pop ebp ebx eax + popad + mov edx,.dc13b + add .cur1b,edx + mov esi,.dc13g + add .cur1g,esi + mov edi,.dc13r + add .cur1r,edi + mov edx,.tex_dx13 + add .scan_x1,edx + mov esi,.tex_dy13 + add .scan_y1,esi + mov edx,.dz13 + add .zz1,edx + + mov edi,.dc12b + add .cur2b,edi + mov esi,.dc12g + add .cur2g,esi + mov edx,.dc12r + add .cur2r,edx + mov edi,.tex_dx12 + add .scan_x2,edi + mov esi,.tex_dy12 + add .scan_y2,esi + mov edx,.dz12 + add .zz2,edx + add eax,.dx13 + add ebx,.dx12 + inc cx + cmp cx,.y2 + jl .loop_1 + .loop1_end: + movzx ecx,.y2 + cmp cx,.y3 + jge .loop2_end + + movsx ebx,.x2 ; eax - cur x1 + shl ebx,ROUND ; ebx - cur x2 + + movsx edx,word .z2 + shl edx,CATMULL_SHIFT +; mov .zz1,edx + mov .zz2,edx + + movzx edi,word .col2r + shl edi,ROUND + ; mov .cur1r,edi + mov .cur2r,edi + movzx esi,word .col2g + shl esi,ROUND + ; mov .cur1g,esi + mov .cur2g,esi + movzx edx,word .col2b + shl edx,ROUND + ; mov .cur1b,edx + mov .cur2b,edx + + movzx edi,word .tex_x2 + shl edi,ROUND + ; mov .scan_x1,edi + mov .scan_x2,edi + movzx edx,word .tex_y2 + shl edx,ROUND + ; mov .scan_y1,edx + mov .scan_y2,edx + + .loop_2: + pushad + + push .tex_ptr + push .scr_buff + push .z_ptr + push cx + + push .zz2 + + push .scan_x2 + push .scan_y2 + push .cur2r + push .cur2g + push .cur2b + + push .zz1 + + push .scan_x1 + push .scan_y1 + push .cur1r + push .cur1g + push .cur1b + + sar eax,ROUND + sar ebx,ROUND + call horizontal_tex_grd_line + + popad + mov edx,.dc13b + add .cur1b,edx + mov esi,.dc13g + add .cur1g,esi + mov edi,.dc13r + add .cur1r,edi + mov edx,.tex_dx13 + add .scan_x1,edx + mov esi,.tex_dy13 + add .scan_y1,esi + mov edx,.dz13 + add .zz1,edx + + mov edi,.dc23b + add .cur2b,edi + mov esi,.dc23g + add .cur2g,esi + mov edx,.dc23r + add .cur2r,edx + mov edi,.tex_dx23 + add .scan_x2,edi + mov esi,.tex_dy23 + add .scan_y2,esi + mov edx,.dz23 + add .zz2,edx + add eax,.dx13 + add ebx,.dx23 + inc cx + cmp cx,.y3 + jl .loop_2 + +.loop2_end: + mov esp,ebp +ret 36 +horizontal_tex_grd_line: +;in: +; eax : x1, ebx : x2 + +.tex_ptr equ [ebp+62] +.screen equ [ebp+58] +.z_buffer equ [ebp+54] +.y equ [ebp+52] + +.z2 equ [ebp+48] +.tex_x2 equ [ebp+44] +.tex_y2 equ [ebp+40] +.r2 equ [ebp+36] +.g2 equ [ebp+32] +.b2 equ [ebp+28] + +.z1 equ [ebp+24] +.tex_x1 equ [ebp+20] +.tex_y1 equ [ebp+16] +.r1 equ [ebp+12] +.g1 equ [ebp+8] +.b1 equ [ebp+4] + +.x1 equ word[ebp-2] +.x2 equ word[ebp-4] +.dz equ dword[ebp-8] +.db equ dword[ebp-12] +.dg equ dword[ebp-16] +.dr equ dword[ebp-20] +.dtex_x equ dword[ebp-24] +.dtex_y equ dword[ebp-28] + +.c_ty equ [ebp-32] +.c_tx equ [ebp-36] +.cb equ [ebp-40] +.cg equ [ebp-44] +.cr equ [ebp-48] +.t_col equ [ebp-52] + +.dtex_yM equ qword[ebp-28] +.drM equ qword[ebp-20] +.dbM equ qword[ebp-12] + + mov ebp,esp + ; sub esp,30 + + mov cx,word .y + or cx,cx + jl .quit_l + + cmp cx,SIZE_Y + jge .quit_l + + cmp ax,bx + je .quit_l + jl @f + + xchg eax,ebx + +if Ext=NON + mov ecx,dword .r1 + xchg ecx, .r2 + mov dword .r1, ecx + + mov ecx,dword .g1 + xchg ecx, .g2 + mov dword .g1, ecx + + mov ecx,dword .b1 + xchg ecx, .b2 + mov dword .b1, ecx + + mov ecx,dword .tex_x1 + xchg ecx, .tex_x2 + mov dword .tex_x1, ecx + + mov ecx,dword .tex_y1 + xchg ecx, .tex_y2 + mov dword .tex_y1, ecx + + mov ecx,dword .z1 + xchg ecx, .z2 + mov dword .z1, ecx + +else + movq mm0,.b1 ; b, g + movq mm1,.b2 + movq .b1, mm1 + movq .b2, mm0 + movq mm2,.r1 ; r, y + movq mm3,.r2 + movq .r1,mm3 + movq .r2,mm2 + movq mm4,.tex_x1 ; x, z + movq mm5,.tex_x2 + movq .tex_x1,mm5 + movq .tex_x2,mm4 + +end if + + @@: + or bx,bx + jle .quit_l + cmp ax,SIZE_X + jge .quit_l + + push ax + push bx + + mov eax,.z2 ; delta zone************ + sub eax,.z1 + cdq + mov bx,.x2 + sub bx,.x1 + movsx ebx,bx + idiv ebx + push eax ; .dz + + mov eax,.b2 + sub eax,.b1 + cdq + idiv ebx + push eax ; .db + + mov eax,.g2 + sub eax,.g1 + cdq + idiv ebx + push eax ; .dg + + mov eax,.r2 + sub eax,.r1 + cdq + idiv ebx + push eax ; .dr + + mov eax,.tex_x2 + sub eax,.tex_x1 + cdq + idiv ebx + push eax ; .dtex_x + + mov eax,.tex_y2 + sub eax,.tex_y1 + cdq + idiv ebx + push eax ; .dtey_x + + cmp .x1,0 + jg @f + + mov eax,.dz ; clipping + movsx ebx,.x1 + neg ebx + imul ebx + add .z1,eax + mov .x1,0 + + mov eax,.dr + imul ebx + add .r1,eax +;if Ext=NON + mov eax,.dg + imul ebx + add .g1,eax + + mov eax,.db + imul ebx + add .b1,eax + + mov eax,.dtex_x + imul ebx + add .tex_x1,eax + + mov eax,.dtex_y + imul ebx + add .tex_y1,eax + @@: + mov edx,SIZE_X + cmp .x2,dx + jl @f + mov .x2,dx + @@: +; calc line addres begin in screen and Z buffer + movsx eax,word .y + mul edx + movsx edx,.x1 + add eax,edx + + mov esi,eax + shl esi,2 + add esi,.z_buffer + + lea eax,[eax*3] + mov edi,.screen + add edi,eax + + mov cx,.x2 + sub cx,.x1 + movzx ecx,cx + +; init current variables + push dword .tex_y1 +;if Ext=NON + push dword .tex_x1 + + push dword .b1 + push dword .g1 + push dword .r1 + +if Ext>=MMX + movq mm4,.cr ; lo -> r,g + movq mm6,.cb ; hi -> b, tex_x + pxor mm0,mm0 +end if + mov ebx,.z1 + .ddraw: + cmp ebx,dword[esi] + jge @f + mov eax,.c_ty +; if ROUNDTEX_SHIFT +; shr eax,ROUND-TEX_SHIFT +; end if + shr eax,ROUND + shl Eax,TEX_SHIFT + mov edx,.c_tx ; calc texture pixel mem addres + shr edx,ROUND + add eax,edx + and eax,TEXTURE_SIZE ; cutting + lea eax,[3*eax] + add eax,.tex_ptr + mov dword[esi],ebx +if Ext = NON + mov eax,dword[eax] + ; mov .tex_col,eax + push ax + shl eax,8 + pop ax + mov edx,.cr + sar edx,ROUND + mul dl ; al*dl + shr ax,8 + stosb + ror eax,16 + push ax + mov edx,.cg + sar edx,ROUND + mul dl + shr ax,8 + stosb + pop ax + shr ax,8 + mov edx,.cb + sar edx,ROUND + mul dl + shr ax,8 + stosb + jmp .no_skip +else + movd mm1,[eax] + punpcklbw mm1,mm0 + movq mm3,mm4 ;.cr ; lo -> r,g + movq mm5,mm6 ;.cb ; lo -> b,tex_x + psrld mm3,ROUND ; + psrld mm5,ROUND ; + packssdw mm3,mm5 + pmullw mm1,mm3 + psrlw mm1,8 + packuswb mm1,mm0 + movd [edi],mm1 +end if + mov dword[esi],ebx +if Ext = NON + jmp .no_skip +end if + @@: + add edi,3 + .no_skip: + add esi,4 + add ebx,.dz + + mov eax,.dtex_x + add .c_tx, eax + mov edx,.dtex_y + add .c_ty, edx +if Ext=NON + mov eax,.dr + add .cr,eax + mov edx,.dg + add .cg,edx + mov eax,.db + add .cb,eax + +else + paddd mm4,.drM + paddd mm6,.dbM +;; paddd mm7,.dtex_y ; mm4 - b, g +;; movq .c_tx,mm7 + ; mm6 - r, x +end if ; mm7 - y, x + + dec ecx + jnz .ddraw + + .quit_l: + + mov esp,ebp +ret 42+20 ; horizontal line + diff --git a/programs/demos/3DS/TEX3.ASM b/programs/demos/3DS/TEX3.ASM deleted file mode 100644 index afb0263ee9..0000000000 --- a/programs/demos/3DS/TEX3.ASM +++ /dev/null @@ -1,507 +0,0 @@ -;--------------------------------------------------------------------- -;--------------------textured triangle procedure---------------------- -;--------------------------------------------------------------------- -tex_triangle: -;----------in - eax - x1 shl 16 + y1 -;-------------- ebx - x2 shl 16 + y2 -;---------------ecx - x3 shl 16 + y3 -;---------------edx - nothing -;---------------esi - pointer to texture buffer -;---------------edi - pointer to screen buffer -;-------------stack - texture coordinates -.tex_x1 equ ebp+4 -.tex_y1 equ ebp+6 -.tex_x2 equ ebp+8 -.tex_y2 equ ebp+10 -.tex_x3 equ ebp+12 -.tex_y3 equ ebp+14 - mov ebp,esp - - mov edx,dword[.tex_x1] ; check all parameters - or dx,dx - jl .tt_end - cmp dx,TEX_X-1 - jg .tt_end - shr edx,16 - or dx,dx - jl .tt_end - cmp dx,TEX_Y-1 - jg .tt_end - - mov edx,dword[.tex_x2] - or dx,dx - jl .tt_end - cmp dx,TEX_X-1 - jg .tt_end - shr edx,16 - or dx,dx - jl .tt_end - cmp dx,TEX_Y-1 - jg .tt_end - - mov edx,dword[.tex_x3] - or dx,dx - jl .tt_end - cmp dx,TEX_X-1 - jg .tt_end - shr edx,16 - cmp dx,TEX_Y-1 - jg .tt_end - or dx,dx - jl .tt_end - - mov edx,eax ; check X&Y triangle coordinate - or edx,ebx - or edx,ecx - test edx,80008000h - jne .tt_end - - ; or ax,ax - ; jl .tt_end - cmp ax,SIZE_Y - jg .tt_end - ror eax,16 - ; or ax,ax - ; jl .tt_end - cmp ax,SIZE_X - jg .tt_end - rol eax,16 - - ; or bx,bx - ; jl .tt_end - cmp bx,SIZE_Y - jg .tt_end - ror ebx,16 - ; or bx,bx - ; jl .tt_end - cmp bx,SIZE_X - jg .tt_end - rol ebx,16 - - ; or cx,cx - ; jl .tt_end - cmp cx,SIZE_Y - jg .tt_end - ror ecx,16 - ; or cx,cx - ; jl .tt_end - cmp cx,SIZE_X - jg .tt_end - rol ecx,16 ; uff.. parameters was checked - - cmp ax,bx ;sort all parameters - jle .tt_sort1 - xchg eax,ebx - mov edx,dword [.tex_x1] - xchg edx,dword [.tex_x2] - mov dword[.tex_x1],edx -.tt_sort1: - cmp ax,cx - jle .tt_sort2 - xchg eax,ecx - mov edx,dword [.tex_x1] - xchg edx,dword [.tex_x3] - mov dword [.tex_x1],edx -.tt_sort2: - cmp bx,cx - jle .tt_sort3 - xchg ebx,ecx - mov edx,dword [.tex_x2] - xchg edx,dword [.tex_x3] - mov dword [.tex_x2],edx -.tt_sort3: - mov [.y1],ax ; and store to user friendly variables - shr eax,16 - mov [.x1],ax - mov [.y2],bx - shr ebx,16 - mov [.x2],bx - mov [.y3],cx - shr ecx,16 - mov [.x3],cx - mov [.tex_ptr],esi - - movsx ebx,word[.y2] - sub bx,[.y1] - jnz .tt_dx12_make - - mov [.dx12],0 - mov [.tex_dx12],0 - mov [.tex_dy12],0 - jmp .tt_dx12_done -.tt_dx12_make: - mov ax,[.x2] - sub ax,[.x1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.dx12],eax ; dx12 = (x2-x1)/(y2-y1) - - mov ax,word[.tex_x2] - sub ax,word[.tex_x1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) - - mov ax,word[.tex_y2] - sub ax,word[.tex_y1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) -.tt_dx12_done: - - movsx ebx,[.y3] - sub bx,[.y1] - jnz .tt_dx13_make - - mov [.dx13],0 - mov [.tex_dx13],0 - mov [.tex_dy13],0 - jmp .tt_dx13_done -.tt_dx13_make: - mov ax,[.x3] - sub ax,[.x1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.dx13],eax ; dx13 = (x3-x1)/(y3-y1) - - mov ax,word[.tex_x3] - sub ax,word[.tex_x1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.tex_dx13],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) - - mov ax,word[.tex_y3] - sub ax,word[.tex_y1] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.tex_dy13],eax ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1) -.tt_dx13_done: - - movsx ebx,[.y3] - sub bx,[.y2] - jnz .tt_dx23_make - - mov [.dx23],0 - mov [.tex_dx23],0 - mov [.tex_dy23],0 - jmp .tt_dx23_done -.tt_dx23_make: - mov ax,[.x3] - sub ax,[.x2] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.dx23],eax ; dx23 = (x3-x2)/(y3-y2) - - mov ax,word[.tex_x3] - sub ax,word[.tex_x2] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) - - mov ax,word[.tex_y3] - sub ax,word[.tex_y2] - cwde - shl eax,ROUND - cdq - idiv ebx - mov [.tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) -.tt_dx23_done: - - movsx eax,[.x1] - shl eax,ROUND - mov ebx,eax - - movsx edx, word[.tex_x1] - shl edx,ROUND - mov [.scan_x1],edx - mov [.scan_x2],edx - movsx edx, word[.tex_y1] - shl edx,ROUND - mov [.scan_y1],edx - mov [.scan_y2],edx - - mov cx,[.y1] - cmp cx, [.y2] - jge .tt_loop1_end -.tt_loop1: - push edi - push eax - push ebx - push cx - push ebp - - mov edx, [.scan_y2] - sar edx, ROUND - push dx - mov edx, [.scan_x2] - sar edx, ROUND - push dx - mov edx, [.scan_y1] - sar edx, ROUND - push dx - mov edx, [.scan_x1] - sar edx, ROUND - push dx - push [.tex_ptr] - - push cx - mov edx,ebx - sar edx,ROUND - push dx - mov edx,eax - sar edx,ROUND - push dx - call textured_line - - pop ebp - pop cx - pop ebx - pop eax - pop edi - - mov edx, [.tex_dx13] - add [.scan_x1], edx - mov edx, [.tex_dx12] - add [.scan_x2], edx - mov edx, [.tex_dy13] - add [.scan_y1], edx - mov edx, [.tex_dy12] - add [.scan_y2], edx - - add eax, [.dx13] - add ebx, [.dx12] - inc cx - cmp cx,[.y2] - jl .tt_loop1 -.tt_loop1_end: - - - mov cx,[.y2] - cmp cx, [.y3] - jge .tt_loop2_end - - movsx ebx,[.x2] - shl ebx,ROUND - - movsx edx, word[.tex_x2] - shl edx,ROUND - mov [.scan_x2],edx - movsx edx, word[.tex_y2] - shl edx,ROUND - mov [.scan_y2],edx - -.tt_loop2: - push edi - push eax - push ebx - push cx - push ebp - - mov edx, [.scan_y2] - sar edx, ROUND - push dx - mov edx, [.scan_x2] - sar edx, ROUND - push dx - mov edx, [.scan_y1] - sar edx, ROUND - push dx - mov edx, [.scan_x1] - sar edx, ROUND - push dx - push [.tex_ptr] - - push cx - mov edx,ebx - sar edx,ROUND - push dx - mov edx,eax - sar edx,ROUND - push dx - call textured_line - - pop ebp - pop cx - pop ebx - pop eax - pop edi - - mov edx, [.tex_dx13] - add [.scan_x1], edx - mov edx, [.tex_dx23] - add [.scan_x2], edx - mov edx, [.tex_dy13] - add [.scan_y1], edx - mov edx, [.tex_dy23] - add [.scan_y2], edx - - add eax, [.dx13] - add ebx, [.dx23] - inc cx - cmp cx,[.y3] - jl .tt_loop2 -.tt_loop2_end: - -.tt_end: - mov esp,ebp -ret 12 -.x1 dw ? -.y1 dw ? -.x2 dw ? -.y2 dw ? -.x3 dw ? -.y3 dw ? -.dx12 dd ? -.dx13 dd ? -.dx23 dd ? -.tex_dx12 dd ? -.tex_dy12 dd ? -.tex_dx13 dd ? -.tex_dy13 dd ? -.tex_dx23 dd ? -.tex_dy23 dd ? -.tex_ptr dd ? - -.scan_x1 dd ? -.scan_y1 dd ? -.scan_x2 dd ? -.scan_y2 dd ? - - -textured_line: -;-----in -edi screen buffer pointer -;------------ stack: - .x1 equ word [ebp+4] - .x2 equ word [ebp+6] - .y equ word [ebp+8] - - .tex_ptr equ dword [ebp+10] - .tex_x1 equ word [ebp+14] - .tex_y1 equ word [ebp+16] - .tex_x2 equ word [ebp+18] - .tex_y2 equ word [ebp+20] - - mov ebp,esp - - mov ax,.y - or ax,ax - jl .tl_quit - cmp ax,SIZE_Y - jg .tl_quit - - mov ax,.x1 - cmp ax,.x2 - je .tl_quit - jl .tl_ok - - xchg ax,.x2 - mov .x1,ax - - mov ax,.tex_x1 - xchg ax,.tex_x2 - mov .tex_x1,ax - - mov ax,.tex_y1 - xchg ax,.tex_y2 - mov .tex_y1,ax - - .tl_ok: - mov ebx,edi - movsx edi,.y - mov eax,SIZE_X*3 - mul edi - mov edi,eax - movsx eax,.x1 - add edi,eax - shl eax,1 - add edi,eax - add edi,ebx - - mov cx,.x2 - sub cx,.x1 - movsx ecx,cx - - mov ax,.tex_x2 - sub ax,.tex_x1 - cwde - shl eax,ROUND - cdq - idiv ecx - mov [.tex_dx],eax ; tex_dx=(tex_x2-tex_x1)/(x2-x1) - - mov ax,.tex_y2 - sub ax,.tex_y1 - cwde - shl eax,ROUND - cdq - idiv ecx - mov [.tex_dy],eax ; tex_dy = (tex_y2-tex_y1)/(x2-x1) - - movsx eax,.tex_x1 - shl eax,ROUND - movsx ebx,.tex_y1 - shl ebx,ROUND - cld - .tl_loop: - mov edx,eax - mov esi,ebx - sar edx,ROUND - sar esi,ROUND - macro .fluent - { - push eax - push edx - mov eax,TEX_X*3 - mul esi - mov esi,eax - pop edx - pop eax - } - macro .shift - { - shl esi,TEX_SHIFT - lea esi,[esi*3] - ;push edx - ;mov edx,esi - ;shl esi,1 - ;add esi,edx - ;pop edx - } - if TEX = FLUENTLY - .fluent - end if - if TEX = SHIFTING - .shift - end if - lea edx,[edx*3] - add esi,edx - ; shl edx,1 - ; add esi,edx - add esi,.tex_ptr - movsd - dec edi - add eax,[.tex_dx] - add ebx,[.tex_dy] - loop .tl_loop - - .tl_quit: - mov esp,ebp -ret 18 - .tex_dx dd ? - .tex_dy dd ? diff --git a/programs/demos/3DS/TEX3.INC b/programs/demos/3DS/TEX3.INC new file mode 100644 index 0000000000..111cf2bd20 --- /dev/null +++ b/programs/demos/3DS/TEX3.INC @@ -0,0 +1,543 @@ +;--------------------------------------------------------------------- +;--------------------textured triangle procedure---------------------- +;--------------------------------------------------------------------- + +tex_triangle: +;----------in - eax - x1 shl 16 + y1 +;-------------- ebx - x2 shl 16 + y2 +;---------------ecx - x3 shl 16 + y3 +;---------------edx - nothing +;---------------esi - pointer to texture buffer +;---------------edi - pointer to screen buffer +;-------------stack - texture coordinates +.tex_x1 equ ebp+4 +.tex_y1 equ ebp+6 +.tex_x2 equ ebp+8 +.tex_y2 equ ebp+10 +.tex_x3 equ ebp+12 +.tex_y3 equ ebp+14 + +.x1 equ ebp-2 ;dw ? +.y1 equ ebp-4 ;dw ? +.x2 equ ebp-6 ;dw ? +.y2 equ ebp-8 ;dw ? +.x3 equ ebp-10 ;dw ? +.y3 equ ebp-12 ;dw ? +.dx12 equ ebp-16 ;dd ? +.dx13 equ ebp-20 ;dd ? +.dx23 equ ebp-24 ;dd ? +.tex_dx12 equ ebp-28 ;dd ? +.tex_dy12 equ ebp-32 ;dd ? +.tex_dx13 equ ebp-36 ;dd ? +.tex_dy13 equ ebp-40 ;dd ? +.tex_dx23 equ ebp-44 ;dd ? +.tex_dy23 equ ebp-48 ;dd ? +.tex_ptr equ ebp-52 ;dd ? + +.scan_x2 equ ebp-56 ;dd ? +.scan_y2 equ ebp-60 ;dd ? +.scan_x1 equ ebp-64 ;dd ? +.scan_y1 equ ebp-68 ;dd ? + + mov ebp,esp + sub esp,68 +;if Ext = MMX +; emms +;end if + mov edx,dword[.tex_x1] ; check all parameters + or dx,dx + jl .tt_end + cmp dx,TEX_X-1 + jg .tt_end + shr edx,16 + or dx,dx + jl .tt_end + cmp dx,TEX_Y-1 + jg .tt_end + + mov edx,dword[.tex_x2] + or dx,dx + jl .tt_end + cmp dx,TEX_X-1 + jg .tt_end + shr edx,16 + or dx,dx + jl .tt_end + cmp dx,TEX_Y-1 + jg .tt_end + + mov edx,dword[.tex_x3] + or dx,dx + jl .tt_end + cmp dx,TEX_X-1 + jg .tt_end + shr edx,16 + cmp dx,TEX_Y-1 + jg .tt_end + or dx,dx + jl .tt_end + + mov edx,eax ; check X&Y triangle coordinate + or edx,ebx + or edx,ecx + test edx,80008000h + jne .tt_end + + ; or ax,ax + ; jl .tt_end + cmp ax,SIZE_Y + jg .tt_end + ror eax,16 + ; or ax,ax + ; jl .tt_end + cmp ax,SIZE_X + jg .tt_end + rol eax,16 + + ; or bx,bx + ; jl .tt_end + cmp bx,SIZE_Y + jg .tt_end + ror ebx,16 + ; or bx,bx + ; jl .tt_end + cmp bx,SIZE_X + jg .tt_end + rol ebx,16 + + ; or cx,cx + ; jl .tt_end + cmp cx,SIZE_Y + jg .tt_end + ror ecx,16 + ; or cx,cx + ; jl .tt_end + cmp cx,SIZE_X + jg .tt_end + rol ecx,16 ; uff.. parameters was checked + + cmp ax,bx ;sort all parameters + jle .tt_sort1 + xchg eax,ebx + mov edx,dword [.tex_x1] + xchg edx,dword [.tex_x2] + mov dword[.tex_x1],edx +.tt_sort1: + cmp ax,cx + jle .tt_sort2 + xchg eax,ecx + mov edx,dword [.tex_x1] + xchg edx,dword [.tex_x3] + mov dword [.tex_x1],edx +.tt_sort2: + cmp bx,cx + jle .tt_sort3 + xchg ebx,ecx + mov edx,dword [.tex_x2] + xchg edx,dword [.tex_x3] + mov dword [.tex_x2],edx +.tt_sort3: + mov [.y1],ax ; and store to user friendly variables + shr eax,16 + mov [.x1],ax + mov [.y2],bx + shr ebx,16 + mov [.x2],bx + mov [.y3],cx + shr ecx,16 + mov [.x3],cx + mov [.tex_ptr],esi + + movsx ebx,word[.y2] + sub bx,[.y1] + jnz .tt_dx12_make + + mov dword[.dx12],0 + mov dword[.tex_dx12],0 + mov dword[.tex_dy12],0 + jmp .tt_dx12_done +.tt_dx12_make: + mov ax,[.x2] + sub ax,[.x1] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.dx12],eax ; dx12 = (x2-x1)/(y2-y1) + + mov ax,word[.tex_x2] + sub ax,word[.tex_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) + + mov ax,word[.tex_y2] + sub ax,word[.tex_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) +.tt_dx12_done: + + movsx ebx,word[.y3] + sub bx,word[.y1] + jnz .tt_dx13_make + + mov dword [.dx13],0 + mov dword [.tex_dx13],0 + mov dword [.tex_dy13],0 + jmp .tt_dx13_done +.tt_dx13_make: + mov ax,[.x3] + sub ax,[.x1] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.dx13],eax ; dx13 = (x3-x1)/(y3-y1) + + mov ax,word[.tex_x3] + sub ax,word[.tex_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.tex_dx13],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) + + mov ax,word[.tex_y3] + sub ax,word[.tex_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.tex_dy13],eax ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1) +.tt_dx13_done: + + movsx ebx,word[.y3] + sub bx,word[.y2] + jnz .tt_dx23_make + + mov dword [.dx23],0 + mov dword [.tex_dx23],0 + mov dword [.tex_dy23],0 + jmp .tt_dx23_done +.tt_dx23_make: + mov ax,[.x3] + sub ax,[.x2] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.dx23],eax ; dx23 = (x3-x2)/(y3-y2) + + mov ax,word[.tex_x3] + sub ax,word[.tex_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) + + mov ax,word[.tex_y3] + sub ax,word[.tex_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + mov [.tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) +.tt_dx23_done: + + movsx eax,word[.x1] + shl eax,ROUND + mov ebx,eax + + movsx edx, word[.tex_x1] + shl edx,ROUND + mov [.scan_x1],edx + mov [.scan_x2],edx + movsx edx, word[.tex_y1] + shl edx,ROUND + mov [.scan_y1],edx + mov [.scan_y2],edx + + mov cx,[.y1] + cmp cx, [.y2] + jge .tt_loop1_end +.tt_loop1: + push edi + push eax + push ebx + push cx + push ebp +;; Madis +;if Ext=MMX ; With MMX enabled it reverse light vectors ???? +; mov dword[esp-8],ROUND +; mov dword[esp-4],0 ; Is this a bug? Explanation down 3 lines +; movq mm0,qword[.scan_y1] +; movq mm1,qword[.scan_y2] +; psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc. +; psrad mm1,[esp-8] ;It always defaults to QWORD +; packssdw mm0,mm1 +; movq [esp-8],mm0 +; sub esp,8 +;else + + push dword[.scan_y2] ; now I push variables on stack without shifting + push dword[.scan_x2] + push dword[.scan_y1] + push dword[.scan_x1] + +;end if + + + + push dword[.tex_ptr] + + push cx + mov edx,ebx + sar edx,ROUND + push dx + mov edx,eax + sar edx,ROUND + push dx + call textured_line + + pop ebp + pop cx + pop ebx + pop eax + pop edi + + mov edx, [.tex_dx13] + add [.scan_x1], edx + mov edx, [.tex_dx12] + add [.scan_x2], edx + mov edx, [.tex_dy13] + add [.scan_y1], edx + mov edx, [.tex_dy12] + add [.scan_y2], edx + + add eax, [.dx13] + add ebx, [.dx12] + inc cx + cmp cx,[.y2] + jl .tt_loop1 + +.tt_loop1_end: + + + mov cx, [.y2] + cmp cx, [.y3] + jge .tt_loop2_end + + movsx ebx,word[.x2] + shl ebx,ROUND + + movsx edx, word[.tex_x2] + shl edx,ROUND + mov [.scan_x2],edx + movsx edx, word[.tex_y2] + shl edx,ROUND + mov [.scan_y2],edx + +.tt_loop2: + push edi + push eax + push ebx + push cx + push ebp +;; Madis +;if Ext=MMX +; mov dword[esp-8],ROUND +; mov dword[esp-4],0 ; Is this a bug? Explanation down 3 lines +; movq mm0,qword[.scan_y1] +; movq mm1,qword[.scan_y2] +; psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc. +; psrad mm1,[esp-8] ;It always defaults to QWORD +; packssdw mm0,mm1 +; movq [esp-8],mm0 +; sub esp,8 +;else + +;end if + push dword[.scan_y2] + push dword[.scan_x2] + push dword[.scan_y1] + push dword[.scan_x1] + + + + push dword[.tex_ptr] + + push cx + mov edx,ebx + sar edx,ROUND + push dx + mov edx,eax + sar edx,ROUND + push dx + call textured_line + + pop ebp + pop cx + pop ebx + pop eax + pop edi + + mov edx, [.tex_dx13] + add [.scan_x1], edx + mov edx, [.tex_dx23] + add [.scan_x2], edx + mov edx, [.tex_dy13] + add [.scan_y1], edx + mov edx, [.tex_dy23] + add [.scan_y2], edx + + add eax, [.dx13] + add ebx, [.dx23] + inc cx + cmp cx,[.y3] + jl .tt_loop2 + +.tt_loop2_end: + +.tt_end: + mov esp,ebp + +ret 12 + + +textured_line: +;-----in -edi screen buffer pointer +;------------ stack: + .x1 equ word [ebp+4] + .x2 equ word [ebp+6] + .y equ word [ebp+8] + + .tex_ptr equ dword [ebp+10] + .tex_x1 equ [ebp+14] + .tex_y1 equ [ebp+18] + .tex_x2 equ [ebp+22] + .tex_y2 equ [ebp+26] + + .tex_dx equ ebp-4 ;dd ? + .tex_dy equ ebp-8 ;dd ? + + mov ebp,esp + sub esp,8 + + mov ax,.y + or ax,ax + jl .tl_quit + cmp ax,SIZE_Y + jg .tl_quit + + mov ax,.x1 + cmp ax,.x2 + je .tl_quit + jl .tl_ok + + xchg ax,.x2 + mov .x1,ax + +if Ext >= MMX + movq mm0,.tex_x1 + movq mm1,.tex_x2 + movq .tex_x2,mm0 + movq .tex_x1,mm1 + +else + + mov eax,.tex_x1 + xchg eax,.tex_x2 + mov .tex_x1,eax + + mov eax,.tex_y1 + xchg eax,.tex_y2 + mov .tex_y1,eax + +end if + + .tl_ok: + + mov ebx,edi + movsx edi,.y + mov eax,SIZE_X*3 + mul edi + mov edi,eax + movsx eax,.x1 + add edi,eax + shl eax,1 + add edi,eax + add edi,ebx + + mov cx,.x2 + sub cx,.x1 + movsx ecx,cx + + mov eax,.tex_x2 + sub eax,.tex_x1 + cdq + idiv ecx + mov [.tex_dx],eax ; tex_dx=(tex_x2-tex_x1)/(x2-x1) + + mov eax,.tex_y2 + sub eax,.tex_y1 + cdq + idiv ecx + mov [.tex_dy],eax ; tex_dy = (tex_y2-tex_y1)/(x2-x1) + + mov eax,.tex_x1 + mov ebx,.tex_y1 + cld + .tl_loop: + mov edx,eax ; eax - cur x + mov esi,ebx ; ebx - cur y + shr edx,ROUND + shr esi,ROUND + macro .fluent + { + push eax + push edx + mov eax,TEX_X*3 + mul esi + mov esi,eax + pop edx + pop eax + } + macro .shift + { + shl esi,TEX_SHIFT + lea esi,[esi*3] + ;push edx + ;mov edx,esi + ;shl esi,1 + ;add esi,edx + ;pop edx + } + if TEX = FLUENTLY + .fluent + end if + if TEX = SHIFTING + .shift + end if + lea edx,[edx*3] + add esi,edx + ; shl edx,1 + ; add esi,edx + add esi,.tex_ptr + movsd + dec edi + add eax,[.tex_dx] + add ebx,[.tex_dy] + loop .tl_loop + + .tl_quit: + mov esp,ebp + +ret 18+8 +; .tex_dx dd ? +; .tex_dy dd ? diff --git a/programs/demos/3DS/TEX_CAT.INC b/programs/demos/3DS/TEX_CAT.INC new file mode 100644 index 0000000000..68a3ee87d1 --- /dev/null +++ b/programs/demos/3DS/TEX_CAT.INC @@ -0,0 +1,610 @@ +;TEX_X = 512 +;TEX_Y = 512 +;ROUND equ 8 +;SIZE_X = 512 +;SIZE_Y = 512 +;TEX_SHIFT = 9 +CATMULL_SHIFT equ 8 + +;------------------------------------------------------------------------ +;- Procedure drawing textured triangle using Catmull Z-buffer algorithm - +;------------------------------------------------------------------------ +tex_triangle_z: +;----------in - eax - x1 shl 16 + y1 +;-------------- ebx - x2 shl 16 + y2 +;---------------ecx - x3 shl 16 + y3 +;---------------edx - pointer to Z-buffer +;---------------esi - pointer to texture buffer +;---------------edi - pointer to screen buffer +;-------------stack - texture coordinates +;------------------ - z coordinates +.tex_x1 equ ebp+4 +.tex_y1 equ ebp+6 +.tex_x2 equ ebp+8 +.tex_y2 equ ebp+10 +.tex_x3 equ ebp+12 +.tex_y3 equ ebp+14 +.z1 equ word[ebp+16] +.z2 equ word[ebp+18] +.z3 equ word[ebp+20] + +.tex_ptr equ dword[ebp-4] ; pointer to texture +.z_ptr equ dword[ebp-8] ; pointer to z-buffer +.x1 equ word[ebp-10] +.y1 equ word[ebp-12] +.x2 equ word[ebp-14] +.y2 equ word[ebp-16] +.x3 equ word[ebp-18] +.y3 equ word[ebp-20] + +.dx12 equ dword[ebp-24] +.tex_dx12 equ dword[ebp-28] +.tex_dy12 equ dword[ebp-32] +.dz12 equ dword[ebp-36] + +.dx13 equ dword[ebp-40] +.tex_dx13 equ dword[ebp-44] +.tex_dy13 equ dword[ebp-48] +.dz13 equ dword[ebp-52] + +.dx23 equ dword[ebp-56] +.tex_dx23 equ dword[ebp-60] +.tex_dy23 equ dword[ebp-64] +.dz23 equ dword[ebp-68] + +.scan_x1 equ dword[ebp-72] +.scan_x2 equ dword[ebp-76] +.scan_y1 equ dword[ebp-80] +.scan_y2 equ dword[ebp-84] +.cz1 equ dword[ebp-88] +.cz2 equ dword[ebp-92] + +if Ext >= MMX + emms +end if + mov ebp,esp + push esi ; store memory pointers + push edx +.tt_sort3: + cmp ax,bx ;sort all parameters + jle .tt_sort1 + xchg eax,ebx + mov edx,dword [.tex_x1] + xchg edx,dword [.tex_x2] + mov dword[.tex_x1],edx + mov dx,.z1 + xchg dx,.z2 + mov .z1,dx +.tt_sort1: + cmp bx,cx + jle .tt_sort2 + xchg ebx,ecx + mov edx,dword [.tex_x2] + xchg edx,dword [.tex_x3] + mov dword [.tex_x2],edx + mov dx,.z2 + xchg dx,.z3 + mov .z2,dx + jmp .tt_sort3 +.tt_sort2: + + push eax ; and store to user friendly variables + push ebx + push ecx + + 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 .tt_loop2_end + cmp ax,SIZE_Y + jl @f + cmp bx,SIZE_Y + jl @f + cmp cx,SIZE_Y + jl @f + ror eax,16 + ror ebx,16 + ror ecx,16 + cmp ax,SIZE_X + jl @f + cmp bx,SIZE_X + jl @f + cmp cx,SIZE_X + jl @f + jmp .tt_loop2_end + @@: + mov eax,dword[.tex_x1] ; texture coords must be in [0..TEX_X(Y)] + mov ebx,dword[.tex_x2] + mov ecx,dword[.tex_x3] + mov edx,eax + or edx,ebx + or edx,ecx + test edx,80008000h + jne .tt_loop2_end + cmp ax,TEX_X + jge .tt_loop2_end + cmp bx,TEX_X + jge .tt_loop2_end + cmp cx,TEX_X + jge .tt_loop2_end + ror eax,16 + ror ebx,16 + ror ecx,16 + cmp ax,TEX_Y + jge .tt_loop2_end + cmp bx,TEX_Y + jge .tt_loop2_end + cmp cx,TEX_Y + jge .tt_loop2_end + + + movsx ebx,.y2 ; calc delta + sub bx,.y1 + jnz .tt_dx12_make + xor edx,edx + mov ecx,4 + @@: + push edx + loop @b + jmp .tt_dx12_done + .tt_dx12_make: + mov ax,.x2 + sub ax,.x1 + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dx12,eax ; dx12 = (x2-x1)/(y2-y1) + push eax + + mov ax,word[.tex_x2] + sub ax,word[.tex_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov [.tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1) + push eax + + mov ax,word[.tex_y2] + sub ax,word[.tex_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov [.tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1) + push eax + + mov ax,.z2 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + .tt_dx12_done: + + movsx ebx,.y3 ; calc delta + sub bx,.y1 + jnz .tt_dx13_make + xor edx,edx + mov ecx,4 + @@: + push edx + loop @b + jmp .tt_dx13_done + .tt_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dx12,eax ; dx13 = (x3-x1)/(y3-y1) + push eax + + mov ax,word[.tex_x3] + sub ax,word[.tex_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov [.tex_dx12],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1) + push eax + + mov ax,word[.tex_y3] + sub ax,word[.tex_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov [.tex_dy12],eax ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1) + push eax + + mov ax,.z3 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + .tt_dx13_done: + + mov bx,.y3 ; calc delta + sub bx,.y2 + jnz .tt_dx23_make + xor edx,edx + mov ecx,4 + @@: + push edx + loop @b + jmp .tt_dx23_done + .tt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + shl eax,ROUND + cdq + movzx ebx,bx + idiv ebx + ; mov .dx23,eax ; dx23 = (x3-x2)/(y3-y2) + push eax + + mov ax,word[.tex_x3] + sub ax,word[.tex_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov [.tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2) + push eax + + mov ax,word[.tex_y3] + sub ax,word[.tex_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov [.tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2) + push eax + + mov ax,.z3 + sub ax,.z2 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + .tt_dx23_done: + + movsx eax,.x1 ;eax - cur x1 + shl eax,ROUND ;ebx - cur x2 + mov ebx,eax + + movsx edx, word[.tex_x1] + shl edx,ROUND + ; mov [.scan_x1],edx + ; mov [.scan_x2],edx + push edx + push edx + movsx edx, word[.tex_y1] + shl edx,ROUND + ; mov [.scan_y1],edx + ; mov [.scan_y2],edx + push edx + push edx + movsx edx,.z1 + shl edx,CATMULL_SHIFT + push edx + push edx + mov cx,.y1 + cmp cx,.y2 + jge .tt_loop1_end + + .tt_loop1: + pushad + + push .z_ptr + push .cz1 ; z coords shifted shl catmull_shift + push .cz2 + push .scan_y2 + push .scan_x2 + push .scan_y1 + push .scan_x1 + push esi ;[.tex_ptr] + + push cx + sar ebx,ROUND + push bx + sar eax,ROUND + push ax + call textured_line_z + + popad + mov edx,.dz13 + add .cz1,edx + mov edx,.dz12 + add .cz2,edx + + mov edx, .tex_dx13 + add .scan_x1, edx + mov edx, .tex_dx12 + add .scan_x2, edx + mov edx, .tex_dy13 + add .scan_y1, edx + mov edx, .tex_dy12 + add .scan_y2, edx + + add eax, .dx13 + add ebx, .dx12 + inc cx + cmp cx,.y2 + jl .tt_loop1 + + .tt_loop1_end: + + + mov cx,.y2 + cmp cx,.y3 + jge .tt_loop2_end + + movsx ebx,.x2 + shl ebx,ROUND + movsx edx,.z2 + shl edx,CATMULL_SHIFT + mov .cz2,edx + movzx edx, word [.tex_x2] + shl edx,ROUND + mov .scan_x2,edx + movzx edx, word[.tex_y2] + shl edx,ROUND + mov .scan_y2,edx + +.tt_loop2: + + pushad + + push .z_ptr + push .cz1 ; z coords shifted shl catmull_shift + push .cz2 + + push .scan_y2 + push .scan_x2 + push .scan_y1 + push .scan_x1 + push esi ;[.tex_ptr] + + push cx + sar ebx,ROUND + push bx + sar eax,ROUND + push ax + call textured_line_z + + popad + + + mov edx,.dz13 + add .cz1,edx + mov edx,.dz23 + add .cz2,edx + + mov edx, .tex_dx13 + add .scan_x1, edx + mov edx, .tex_dx23 + add .scan_x2, edx + mov edx, .tex_dy13 + add .scan_y1, edx + mov edx, .tex_dy23 + add .scan_y2, edx + + add eax, .dx13 + add ebx, .dx23 + inc cx + cmp cx,.y3 + jl .tt_loop2 + +.tt_loop2_end: + +.tt_end: + mov esp,ebp +ret 18 + +textured_line_z: +;-----in -edi screen buffer pointer +;------------ stack: + .x1 equ word [ebp+4] + .x2 equ word [ebp+6] + .y equ word [ebp+8] + + .tex_ptr equ dword [ebp+10] + .tex_x1 equ ebp+14 + .tex_y1 equ ebp+18 + .tex_x2 equ ebp+22 + .tex_y2 equ ebp+26 + .z2 equ dword [ebp+30] ;z1, z2 coords shifted shl CATMULL_SHIFT + .z1 equ dword [ebp+34] + .z_ptr equ dword [ebp+38] + + .tex_dy equ dword [ebp-4] + .tex_dx equ dword [ebp-8] + .dz equ dword [ebp-12] + .cz equ dword [ebp-16] + .c_tex_x equ dword [ebp-20] ; current tex x + .m_sft1 equ ebp-28 + .m_sft2 equ ebp-32 +; .c_tex_xM equ ebp+14 + .tex_dxM equ ebp-8 + + mov ebp,esp + + mov ax,.y + or ax,ax + jl .tl_quit + cmp ax,SIZE_Y + jge .tl_quit + + mov ax,.x1 + cmp ax,.x2 + je .tl_quit + jl .tl_ok + + xchg ax,.x2 ; sort params + mov .x1,ax +if Ext >= MMX + movq mm0,[.tex_x1] + movq mm1,[.tex_x2] + movq [.tex_x2],mm0 + movq [.tex_x1],mm1 + +else + mov eax,dword[.tex_x1] + xchg eax,dword[.tex_x2] + mov dword[.tex_x1],eax + + mov eax,dword[.tex_y1] + xchg eax,dword[.tex_y2] + mov dword[.tex_y1],eax + +end if + + mov eax,.z1 + xchg eax,.z2 + mov .z1,eax + + .tl_ok: + cmp .x1,SIZE_X + jge .tl_quit + cmp .x2,0 + jle .tl_quit + + mov bx,.x2 + sub bx,.x1 + movsx ebx,bx + + mov eax,dword[.tex_y2] ; calc .dty + sub eax,dword[.tex_y1] + cdq + idiv ebx + push eax + + mov eax,dword[.tex_x2] ; calc .dtx + sub eax,dword[.tex_x1] + cdq + idiv ebx + push eax + + mov eax,.z2 ; calc .dz + sub eax,.z1 + cdq + idiv ebx + push eax + + cmp .x1,0 ; clipping + jg @f + + movsx ebx,.x1 + neg ebx + imul ebx ; eax = .dz * abs(.x1) + add .z1,eax + mov .x1,0 + + mov eax,.tex_dy + imul ebx + add dword[.tex_y1],eax + + mov eax,.tex_dx + imul ebx + add dword[.tex_x1],eax + + @@: + cmp .x2,SIZE_X + jl @f + mov .x2,SIZE_X + @@: + + movsx ebx,.y ; calc mem begin in buffers + mov eax,SIZE_X + mul ebx + movsx ebx,.x1 + add eax,ebx + mov ebx,eax + + lea eax,[eax*3] + add edi,eax ; edi - scr buff + shl ebx,2 + add .z_ptr,ebx ; z buffer pointer + + mov cx,.x2 + sub cx,.x1 + movzx ecx,cx + +;if Ext >= MMX +; movq mm0,[.tex_x1] +; movq mm4,mm0 +; movq mm1,qword[.tex_dxM] +; mov ebx,.z1 +; mov eax,.dz +;else + mov eax,dword[.tex_x1] + mov ebx,dword[.tex_y1] + push .z1 ; .cz + push eax ;.c_tex_x +;end if + mov edx,.z_ptr + + .tl_loop: + +;if Ext >= MMX +; cmp ebx,[edx] ; ebx - current z +; jge @f +; movq mm2,mm0 +; psrad mm2,ROUND +; movq mm3,mm2 +; psrlq mm2,32-TEX_SHIFT +; paddd mm3,mm2 +; movd esi,mm3 +; mov dword[edx],ebx ; renew z buffer +;else + ; eax - temp + mov eax,.cz ; ebx - cur tex y shl ROUND + cmp eax,[edx] ; ecx - l.lenght + jge @f ; ebx - cur tex_y ; edx - temp + mov esi,ebx ; edi - scr buff + sar esi,ROUND ; esi - tex_ptr temp + shl esi,TEX_SHIFT ; .z_ptr - cur pointer to z buff + mov eax,.c_tex_x ; .cz - cur z coord shl CATMULL_SHIFT + sar eax,ROUND + add esi,eax + mov eax,.cz + mov dword[edx],eax ; renew z buffer +;end if + and esi,TEXTURE_SIZE + lea esi,[esi*3] + add esi,.tex_ptr + movsd + dec edi + jmp .no_skip + @@: + add edi,3 + .no_skip: + add edx,4 +;if Ext >= MMX +; add ebx,eax +; paddd mm0,mm1 +;else + mov eax,.dz + add .cz,eax + mov eax,.tex_dx + add .c_tex_x,eax + add ebx,.tex_dy +;end if + loop .tl_loop + .tl_quit: + + mov esp,ebp + +ret 30+8 + diff --git a/programs/demos/3DS/TWO_TEX.INC b/programs/demos/3DS/TWO_TEX.INC new file mode 100644 index 0000000000..f78ef719ca --- /dev/null +++ b/programs/demos/3DS/TWO_TEX.INC @@ -0,0 +1,1080 @@ + +;SIZE_X equ 350 +;SIZE_Y equ 350 +;ROUND equ 8 +;TEX_X equ 512 +;TEX_Y equ 512 +;TEXTURE_SIZE EQU (512*512)-1 +;TEX_SHIFT EQU 9 + +;CATMULL_SHIFT equ 8 +;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 +;Ext = SSE +;SSE = 3 +;MMX = 1 +;NON = 0 +;use32 +;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great--- +;------- DOS 13h mode demos -------------------------------------------- +;------- Procedure draws triangle with two overlapped textures, I use -- +;--------Catmull Z-buffer algorithm- (Z coordinate interpolation)------- +;--------I calc texture pixel by this way: col1*col2/256 --------------- +two_tex_triangle_z: +;------------------in - eax - x1 shl 16 + y1 ----------- +;---------------------- ebx - x2 shl 16 + y2 ----------- +;---------------------- ecx - x3 shl 16 + y3 ----------- +;---------------------- edx - pointer to b. texture----- +;---------------------- esi - pointer to e. texture----- +;---------------------- edi - pointer to screen buffer-- +;---------------------- stack : b. tex coordinates------ +;---------------------- e. tex coordinates------ +;---------------------- Z position coordinates-- +;---------------------- pointer io Z buffer----- +;-- Z-buffer - filled with coordinates as dword -------- +;-- (Z coor. as word) shl CATMULL_SHIFT ---------------- +.b_x1 equ ebp+4 ; procedure don't save registers !!! +.b_y1 equ ebp+6 ; each coordinate as word +.b_x2 equ ebp+8 +.b_y2 equ ebp+10 ; b - first texture +.b_x3 equ ebp+12 +.b_y3 equ ebp+14 ; e - second texture +.e_x1 equ ebp+16 +.e_y1 equ ebp+18 +.e_x2 equ ebp+20 +.e_y2 equ ebp+22 +.e_x3 equ ebp+24 +.e_y3 equ ebp+26 +.z1 equ word[ebp+28] +.z2 equ word[ebp+30] +.z3 equ word[ebp+32] +.z_buff equ dword[ebp+34] ; pointer to Z-buffer + + +.t_bmap equ dword[ebp-4] ; pointer to b. texture +.t_emap equ dword[ebp-8] ; pointer to e. texture +.x1 equ word[ebp-10] +.y1 equ word[ebp-12] +.x2 equ word[ebp-14] +.y2 equ word[ebp-16] +.x3 equ word[ebp-18] +.y3 equ word[ebp-20] + +.dx12 equ dword[ebp-24] +.dbx12 equ dword[ebp-28] +.dby12 equ dword[ebp-32] +.dby12q equ [ebp-32] +.dex12 equ dword[ebp-36] +.dey12 equ dword[ebp-40] +.dey12q equ [ebp-40] +.dz12 equ dword[ebp-44] + +.dx13 equ dword[ebp-48] +.dbx13 equ dword[ebp-52] +.dby13 equ dword[ebp-56] +.dby13q equ [ebp-56] +.dex13 equ dword[ebp-60] +.dey13 equ dword[ebp-64] +.dey13q equ [ebp-64] +.dz13 equ dword[ebp-68] + +.dx23 equ dword[ebp-72] +.dbx23 equ dword[ebp-76] +.dby23 equ dword[ebp-80] +.dby23q equ [ebp-80] +.dex23 equ dword[ebp-84] +.dey23 equ dword[ebp-88] +.dey23q equ [ebp-88] +.dz23 equ dword[ebp-92] + +.cx1 equ dword[ebp-96] ; current variables +.cx2 equ dword[ebp-100] +;.cbx1q equ [ebp-104] +.cbx1 equ dword[ebp-104] +.cby1 equ [ebp-108] +;.cbx2q [ebp-112] +.cbx2 equ dword[ebp-112] +.cby2 equ [ebp-116] +;.cex1q equ [ebp-120] +.cex1 equ dword[ebp-120] +.cey1 equ [ebp-124] +;.cex2q equ [ebp-128] +.cex2 equ dword[ebp-128] +.cey2 equ [ebp-132] + +.cz1 equ dword[ebp-136] +.cz2 equ dword[ebp-140] + + if Ext >= MMX + emms + else + cld + end if + mov ebp,esp + push edx esi ; store bump map +; push esi ; store e. map + ; sub esp,120 + .sort3: ; sort triangle coordinates... + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov edx,dword[.b_x1] + xchg edx,dword[.b_x2] + mov dword[.b_x1],edx + mov edx,dword[.e_x1] + xchg edx,dword[.e_x2] + mov dword[.e_x1],edx + mov dx,.z1 + xchg dx,.z2 + mov .z1,dx + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + mov edx,dword[.b_x2] + xchg edx,dword[.b_x3] + mov dword[.b_x2],edx + mov edx,dword[.e_x2] + xchg edx,dword[.e_x3] + mov dword[.e_x2],edx + mov dx,.z2 + xchg dx,.z3 + mov .z2,dx + jmp .sort3 + .sort2: + push eax ebx ecx ; store triangle coords in variables +; push ebx +; push ecx + + 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 .loop23_done + ; mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that + ; or edx,ebx ; if any *one* of them is negative a sign flag is raised + ; or edx,ecx + ; test edx,80000000h ; Check only X + ; jne .loop23_done + + ; cmp .x1,SIZE_X ; { + ; jg .loop23_done + ; cmp .x2,SIZE_X ; This can be optimized with effort + ; jg .loop23_done + ; cmp .x3,SIZE_X + ; jg .loop23_done ; { + + + mov bx,.y2 ; calc delta 12 + sub bx,.y1 + jnz .bt_dx12_make + mov ecx,6 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx12_done + .bt_dx12_make: + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx +; mov .dx12,eax + push eax + +if Ext=SSE + + sub esp,16 + cvtsi2ss xmm3,ebx ;rcps + ; mov eax,255 + cvtsi2ss xmm4,[i255d] ;eax + divss xmm3,xmm4 + rcpss xmm3,xmm3 + ; mulss xmm3,xmm4 + shufps xmm3,xmm3,0 + + movd mm0,[.b_x1] + movd mm1,[.b_x2] + movd mm2,[.e_x1] + movd mm3,[.e_x2] + ; psubsw mm3,mm2 + ; psubsw mm1,mm0 + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + ; pslld mm0,ROUND + ; pslld mm1,ROUND + ; pslld mm2,ROUND + ; pslld mm3,ROUND + cvtpi2ps xmm0,mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + subps xmm1,xmm0 + + ; pxor mm4,mm4 + ; movq mm5,mm1 + ; movq mm6,mm1 + ; pcmpeqb mm5,mm4 +; psubd mm1,mm0 +; psubd mm3,mm2 + + ; movq mm0,[.b_x1] ; bx1 by1 bx2 by2 + ; movq mm1,[.e_x1] ; ex1 ey1 ex2 ey2 + ; pxor + ; punpcklhd mm0,mm1 ; lwd ; + ; psubw mm1,mm0 ; mm1, mm0 + ; pxor mm2,mm2 + ; pmovmaskb eax,mm1 + ; and eax,10101010b + ; pcmpgtw mm2,mm1 + ; punpcklwd mm1,mm2 + ; psllw mm0,ROUND + ; psllw mm1,ROUND + ; movq mm2,mm0 + ; psrlq mm0,32 + +; cvtpi2ps xmm0,mm1 +; movlhps xmm0,xmm0 +; cvtpi2ps xmm0,mm3 + ; divps xmm1,xmm3 + mulps xmm1,xmm3 + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey12q,mm0 + movq .dby12q,mm1 + +; movd .dex12,mm0 +; psrlq mm0,32 +; movd .dey12,mm0 +; movhlps xmm1,xmm1 +; cvtps2pi mm0,xmm1 +; movd .dbx12,mm0 +; psrlq mm0,32 +; movd .dby12,mm0 + +else + mov ax,word[.b_x2] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx12,eax + push eax + + mov ax,word[.b_y2] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby12,eax + push eax + + ; mov eax,.dbx12 + ; mov ebx,.dby12 + ; int3 + + mov ax,word[.e_x2] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex12,eax + push eax + + mov ax,word[.e_y2] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey12,eax + push eax + +end if + mov ax,.z2 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + .bt_dx12_done: + + mov bx,.y3 ; calc delta13 + sub bx,.y1 + jnz .bt_dx13_make + mov ecx,6 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx13_done + .bt_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx13,eax + push eax + +if Ext=SSE + + cvtsi2ss xmm3,ebx + ; mov eax,255 + cvtsi2ss xmm4,[i255d] + divss xmm3,xmm4 + rcpss xmm3,xmm3 +; mulss xmm3,xmm4 + shufps xmm3,xmm3,0 + sub esp,16 + + movd mm0,[.b_x1] + movd mm1,[.b_x3] + movd mm2,[.e_x1] + movd mm3,[.e_x3] + + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + cvtpi2ps xmm0,mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + subps xmm1,xmm0 + + ; divps xmm1,xmm3 + mulps xmm1,xmm3 + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey13q,mm0 + movq .dby13q,mm1 + +else + + mov ax,word[.b_x3] + sub ax,word[.b_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx13,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby13,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex13,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y1] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey13,eax + push eax + +end if + + mov ax,.z3 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz13,eax + push eax + .bt_dx13_done: + + mov bx,.y3 ; calc delta23 + sub bx,.y2 + jnz .bt_dx23_make + mov ecx,6 + xor edx,edx + @@: + push edx ;dword 0 + loop @b + jmp .bt_dx23_done + .bt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + ; mov .dx23,eax + push eax + +if Ext=SSE + + cvtsi2ss xmm3,ebx + ; mov eax,255 + cvtsi2ss xmm4,[i255d] ;eax + divss xmm3,xmm4 + shufps xmm3,xmm3,0 + sub esp,16 + + movd mm0,[.b_x2] + movd mm1,[.b_x3] + movd mm2,[.e_x2] + movd mm3,[.e_x3] + + pxor mm4,mm4 + punpcklwd mm0,mm4 + punpcklwd mm1,mm4 + punpcklwd mm2,mm4 + punpcklwd mm3,mm4 + + cvtpi2ps xmm0,mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,mm2 + cvtpi2ps xmm1,mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,mm3 + subps xmm1,xmm0 + + divps xmm1,xmm3 + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .dey23q,mm0 + movq .dby23q,mm1 + +else + + mov ax,word[.b_x3] + sub ax,word[.b_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dbx23,eax + push eax + + mov ax,word[.b_y3] + sub ax,word[.b_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dby23,eax + push eax + + mov ax,word[.e_x3] + sub ax,word[.e_x2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dex23,eax + push eax + + mov ax,word[.e_y3] + sub ax,word[.e_y2] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dey23,eax + push eax +end if + mov ax,.z3 + sub ax,.z2 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + ; mov .dz23,eax + push eax + ; sub esp,40 + .bt_dx23_done: + movsx eax,.x1 + shl eax,ROUND + ; mov .cx1,eax + ; mov .cx2,eax + push eax eax + ; push eax + + movsx eax,word[.b_x1] + shl eax,ROUND + mov .cbx1,eax + mov .cbx2,eax + ; push eax eax + ; push eax + + movsx eax,word[.b_y1] + shl eax,ROUND + mov .cby1,eax + mov .cby2,eax + ; push eax eax + ; push eax + + movsx eax,word[.e_x1] + shl eax,ROUND + mov .cex1,eax + mov .cex2,eax + ; push eax eax + ;push eax + + movsx eax,word[.e_y1] + shl eax,ROUND + mov .cey1,eax + mov .cey2,eax + sub esp,32 + ; push eax eax + ;push eax + + movsx eax,.z1 + shl eax,CATMULL_SHIFT + ; mov .cz1,eax + ; mov .cz2,eax + push eax eax + ;push eax + + movsx ecx,.y1 + cmp cx,.y2 + jge .loop12_done + .loop12: + call .call_line + + mov eax,.dx13 + add .cx1,eax + mov ebx,.dx12 + add .cx2,ebx + +if Ext >= MMX + movq mm0,.cby2 ; with this optimization object + movq mm1,.cby1 ; looks bit annoying + movq mm2,.cey2 + movq mm3,.cey1 + paddd mm0,.dby12q + paddd mm1,.dby13q + paddd mm2,.dey12q + paddd mm3,.dey13q + movq .cby2,mm0 + movq .cby1,mm1 + movq .cey1,mm3 + movq .cey2,mm2 +else + mov edx,.dbx13 + add .cbx1,edx + mov eax,.dbx12 + add .cbx2,eax + mov ebx,.dby13 + add .cby1,ebx + mov edx,.dby12 + add .cby2,edx + + mov eax,.dex13 + add .cex1,eax + mov ebx,.dex12 + add .cex2,ebx + mov edx,.dey13 + add .cey1,edx + mov eax,.dey12 + add .cey2,eax + +end if + mov ebx,.dz13 + add .cz1,ebx + mov edx,.dz12 + add .cz2,edx + + inc ecx + cmp cx,.y2 + jl .loop12 + .loop12_done: + + movsx ecx,.y2 + cmp cx,.y3 + jge .loop23_done + + movsx eax,.z2 + shl eax,CATMULL_SHIFT + mov .cz2,eax + + movsx eax,.x2 + shl eax,ROUND + mov .cx2,eax + + movzx eax,word[.b_x2] + shl eax,ROUND + mov .cbx2,eax + + movzx eax,word[.b_y2] + shl eax,ROUND + mov .cby2,eax + + movzx eax,word[.e_x2] + shl eax,ROUND + mov .cex2,eax + + movzx eax,word[.e_y2] + shl eax,ROUND + mov .cey2,eax + + .loop23: + call .call_line +;if Ext = NON + mov eax,.dx13 + add .cx1,eax + mov ebx,.dx23 + add .cx2,ebx + +if Ext >= MMX + movq mm0,.cby2 ; with this mmx optimization object looks bit + movq mm1,.cby1 ; annoying + movq mm2,.cey2 + movq mm3,.cey1 + paddd mm0,.dby23q + paddd mm1,.dby13q + paddd mm2,.dey23q + paddd mm3,.dey13q + movq .cby2,mm0 + movq .cby1,mm1 + movq .cey2,mm2 + movq .cey1,mm3 + +else + mov edx,.dbx13 + add .cbx1,edx + mov eax,.dbx23 + add .cbx2,eax + mov ebx,.dby13 + add .cby1,ebx + mov edx,.dby23 + add .cby2,edx + + mov eax,.dex13 + add .cex1,eax + mov ebx,.dex23 + add .cex2,ebx + mov edx,.dey13 + add .cey1,edx + mov eax,.dey23 + add .cey2,eax +end if + + mov ebx,.dz13 + add .cz1,ebx + mov edx,.dz23 + add .cz2,edx +;else +; movq mm0,.db13q +; movq mm1,.cbx1q + + inc ecx + cmp cx,.y3 + jl .loop23 + .loop23_done: + + mov esp,ebp +ret 34 + +.call_line: + + pushad + + push .cz1 + push .cz2 + push .z_buff + push .t_emap + push .t_bmap + push dword .cey2 + push .cex2 + push dword .cey1 + push .cex1 + push dword .cby2 + push .cbx2 + push dword .cby1 + push .cbx1 + push ecx + + mov eax,.cx1 + sar eax,ROUND + mov ebx,.cx2 + sar ebx,ROUND + + call two_tex_line_z + + popad +ret +two_tex_line_z: +;--------------in: eax - x1 +;-------------- ebx - x2 +;-------------- edi - pointer to screen buffer +;stack - another parameters : +.y equ dword [ebp+4] +.bx1q equ [ebp+8] +.bx1 equ dword [ebp+8] ; --- +.by1 equ dword [ebp+12] ; | +.bx2q equ [ebp+16] +.bx2 equ dword [ebp+16] ; | +.by2 equ dword [ebp+20] ; |> b. texture and e. texture coords +.ex1q equ [ebp+24] +.ex1 equ dword [ebp+24] ; |> shifted shl ROUND +.ey1 equ dword [ebp+28] ; | +.ex2q equ [ebp+32] +.ex2 equ dword [ebp+32] ; | +.ey2 equ dword [ebp+36] ; --- +.bmap equ dword [ebp+40] ; b texture offset +.emap equ dword [ebp+44] ; e texture offset +.z_buff equ dword [ebp+48] +.z2 equ dword [ebp+52] ; -- |> z coords shifted +.z1 equ dword [ebp+56] ; -- shl CATMULL_SHIFT + +.x1 equ dword [ebp-4] +.x2 equ dword [ebp-8] +.dbx equ dword [ebp-12] +.dby equ dword [ebp-16] +.dbyq equ qword [ebp-16] ; - new +.dex equ dword [ebp-20] +.dey equ dword [ebp-24] +.deyq equ qword [ebp-24] ; - new +.dz equ dword [ebp-28] +.cbx equ dword [ebp-32] +.cby equ dword [ebp-36] +.cbyq equ qword [ebp-36] ; - new +.cex equ dword [ebp-40] +.cey equ dword [ebp-44] +.ceyq equ qword [ebp-44] ; - new +.cz equ dword [ebp-48] +.czbuff equ dword [ebp-52] + + mov ebp,esp + + mov ecx,.y + or ecx,ecx + jl .bl_end + cmp ecx,SIZE_Y + jge .bl_end + + cmp eax,ebx + jl @f + je .bl_end + + xchg eax,ebx +if Ext=NON + mov edx,.bx1 + xchg edx,.bx2 + mov .bx1,edx + mov edx,.by1 + xchg edx,.by2 + mov .by1,edx + + mov edx,.ex1 + xchg edx,.ex2 + mov .ex1,edx + mov edx,.ey1 + xchg edx,.ey2 + mov .ey1,edx +else + movq mm0,.bx1q + movq mm1,.ex1q + movq mm2,.bx2q + movq mm3,.ex2q + movq .bx2q,mm0 + movq .ex2q,mm1 + movq .bx1q,mm2 + movq .ex1q,mm3 +end if + mov edx,.z1 + xchg edx,.z2 + mov .z1,edx + @@: + push eax ebx +; push ebx ;store x1, x2 + + cmp .x1,SIZE_X + jge .bl_end + cmp .x2,0 + jle .bl_end + + mov ebx,.x2 + sub ebx,.x1 + +if Ext=SSE + + sub esp,16 + cvtsi2ss xmm3,ebx ;rcps + shufps xmm3,xmm3,0 + + ; movq mm0,.bx1q + ; movq mm1,.bx2q + ; movq mm2,.ex1q + ; movq mm3,.ex2q + ; psubd mm1,mm0 + ; psubd mm3,mm2 + ; cvtpi2ps xmm1,mm1 + ; movlhps xmm1,xmm1 + ; cvtpi2ps xmm1,mm3 + + cvtpi2ps xmm0,.bx1q ;mm0 + movlhps xmm0,xmm0 + cvtpi2ps xmm0,.ex1q ;mm2 + cvtpi2ps xmm1,.bx2q ;mm1 + movlhps xmm1,xmm1 + cvtpi2ps xmm1,.ex2q ;mm3 + subps xmm1,xmm0 + + divps xmm1,xmm3 + + shufps xmm1,xmm1,10110001b + cvtps2pi mm0,xmm1 ; mm0 -> 2 delta dwords + movhlps xmm1,xmm1 + cvtps2pi mm1,xmm1 + movq .deyq,mm0 + movq .dbyq,mm1 + +else + + mov eax,.bx2 ; calc .dbx + sub eax,.bx1 + cdq + idiv ebx + push eax + + mov eax,.by2 ; calc .dby + sub eax,.by1 + cdq + idiv ebx + push eax + + mov eax,.ex2 ; calc .dex + sub eax,.ex1 + cdq + idiv ebx + push eax + + mov eax,.ey2 ; calc .dey + sub eax,.ey1 + cdq + idiv ebx + push eax + +end if + + mov eax,.z2 ; calc .dz + sub eax,.z1 + cdq + idiv ebx + push eax + + cmp .x1,0 ; set correctly begin variable + jge @f ; CLIPPING ON FUNCTION + ; cutting triangle exceedes screen + mov ebx,.x1 + neg ebx + imul ebx ; eax = .dz * abs(.x1) + add .z1,eax + mov .x1,0 + + mov eax,.dbx + imul ebx + add .bx1,eax + + mov eax,.dby + imul ebx + add .by1,eax + + mov eax,.dex + imul ebx + add .ex1,eax + + mov eax,.dey + imul ebx + add .ey1,eax + @@: + cmp .x2,SIZE_X + jl @f + mov .x2,SIZE_X + @@: + mov eax,SIZE_X ;calc memory begin in buffers + mov ebx,.y + mul ebx + mov ebx,.x1 + add eax,ebx + mov ebx,eax + lea eax,[eax*3] + add edi,eax ; edi - screen + mov esi,.z_buff ; z-buffer filled with dd variables + shl ebx,2 + add esi,ebx ; esi - Z buffer + + mov ecx,.x2 + sub ecx,.x1 + ; init current variables + push .bx1 .by1 .ex1 .ey1 .z1 esi +; push .by1 +; push .ex1 +; push .ey1 + +; push .z1 ; current z shl CATMULL_SHIFT +; push esi + +if Ext >= MMX + pxor mm0,mm0 + movq mm3,.ceyq + movq mm4,.cbyq +; movq mm5,mm3 +; movq mm6,mm4 +; psrad mm5,ROUND +; psrad mm6,ROUND +; movq .ceyq,mm5 +; movq .cbyq,mm6 + mov edx,.czbuff +else + cld +end if + .draw: + ; if TEX = SHIFTING ;bump drawing only in shifting mode +if Ext=NON + mov esi,.czbuff ; .czbuff current address in buffer + mov ebx,.cz ; .cz - cur z position + cmp ebx,dword[esi] +else + mov ebx,.cz + cmp ebx,dword[edx] +end if + jge .skip + +;if Ext=NON + mov eax,.cby + mov esi,.cbx + sar eax,ROUND + sar esi,ROUND +;else +; movd eax,mm6 +; psrlq mm6,32 +; movd esi,mm6 +;end if + shl eax,TEX_SHIFT ;- + add esi,eax + lea esi,[esi*3] ;- ; esi - current b. texture addres + add esi,.bmap + +;if Ext=NON + mov ebx,.cex ;.cex - current env map X + mov eax,.cey ;.cey - current env map y + sar ebx,ROUND + sar eax,ROUND +;else +; movd eax,mm5 +; psrlq mm5,32 +; movd ebx,mm5 +;end if + shl eax,TEX_SHIFT + add ebx,eax + lea ebx,[ebx*3] + add ebx,.emap +if Ext>=MMX + movd mm1,[esi] + movd mm2,[ebx] + punpcklbw mm1,mm0 + punpcklbw mm2,mm0 + pmullw mm1,mm2 + psrlw mm1,8 + packuswb mm1,mm0 + movd [edi],mm1 + mov ebx,.cz + mov dword[edx],ebx +else + cld ; esi - tex e. + lodsb ; ebx - tex b. + mov dl,[ebx] + mul dl + shr ax,8 + stosb + inc ebx + lodsb + mov dl,[ebx] + mul dl + shr ax,8 + stosb + inc ebx + lodsb + mov dl,[ebx] + mul dl + shr ax,8 + stosb + mov ebx,.cz + mov esi,.czbuff + mov dword[esi],ebx + jmp .no_skip +end if + .skip: + add edi,3 + + if Ext = NON + .no_skip: + add .czbuff,4 + mov eax,.dbx + add .cbx,eax + mov eax,.dby + add .cby,eax + mov eax,.dex + add .cex,eax + mov eax,.dey + add .cey,eax + else + add edx,4 + paddd mm3,.deyq + paddd mm4,.dbyq + ; movq mm5,mm3 + ; movq mm6,mm4 + ; psrad mm5,ROUND + ; psrad mm6,ROUND + movq .ceyq,mm3 + movq .cbyq,mm4 + end if + mov eax,.dz + add .cz,eax + if Ext = NON + dec ecx + jnz .draw + else + loop .draw + end if + + .bl_end: + mov esp,ebp +ret 56 + diff --git a/programs/demos/3DS/VIEW3DS.ASM b/programs/demos/3DS/VIEW3DS.ASM new file mode 100644 index 0000000000..247a781140 --- /dev/null +++ b/programs/demos/3DS/VIEW3DS.ASM @@ -0,0 +1,2754 @@ + +; application : View3ds ver. 0.053 - tiny .3ds files viewer. +; compiler : FASM 1.65.13 +; system : KolibriOS/MenuetOS +; author : Macgub aka Maciej Guba +; email : macgub3@wp.pl +; web : www.menuet.xt.pl +; Fell free to use this intro in your own distribution of KolibriOS/MenuetOS. +; Special greetings to all MenuetOS maniax in the world. +; I hope because my intros 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) +;include 'proc32.inc' + +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 +Ext = MMX ;Ext={ NON | MMX | SSE} + +; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features) +USE_LFN = 1 + +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 + call alloc_buffer_mem + call read_param + call read_from_disk ; read, if all is ok eax = 0 + cmp eax,0 + jne .gen + call read_tp_variables ; init points and triangles count variables + cmp eax,0 + je .gen + jmp .malloc + .gen: + if USE_LFN + mov [triangles_count_var],1000 + mov [points_count_var],1000 + call alloc_mem_for_tp + end if + call generate_object + 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 + 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 + + +still: + + mov eax,23 ; wait here for event with timeout + mov ebx,TIMEOUT + cmp [speed_flag],1 + jne .skip + mov eax,11 + .skip: + int 0x40 + + cmp eax,1 ; redraw request ? + je red + cmp eax,2 ; key in buffer ? + je key + cmp eax,3 ; button in buffer ? + je button + + jmp noclose + + red: ; redraw + call draw_window + + jmp noclose + + key: ; key + mov eax,2 ; just read it and ignore + int 0x40 + 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 + ; call init_envmap_cub2 + @@: + cmp [dr_flag],4 + jne @f + call generate_texture2 + + @@: + .next_m6: + ; ah = 5 -> scale- + cmp ah,5 + jne @f + mov [scale],0.7 + fninit + fld [rsscale] + fmul [scale] + fstp [rsscale] + + @@: + cmp ah,6 ; ah = 6 -> scale+ + jne @f + mov [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 + 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 + @@: +; 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 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 ax,bl ; ax < - 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: + + 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],1 + je @f +; cmp [move_flag],2 +; je .set_light1 + sub [vect_y],10 + jmp .next + @@: + sub [yobs],10 ; observator = camera position + jmp .next + +;-------------------------------------------------- +; .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],1 + je @f + + sub [vect_x],10 + jmp .next2 + @@: + sub [xobs],10 ; observator = camera position + .next2: + cmp ah,32 + jne .next3 + cmp [move_flag],1 + je @f + + add [vect_x],10 + jmp .next3 + @@: + add [xobs],10 ; observator = camera position + .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],1 + je @f + + ; call add_vector + add [vect_y],10 + jmp .next5 + @@: + add [yobs],10 ; observator = camera position + .next5: + + + + noclose: + + 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 + movzx 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 + movzx ecx,[points_count_var] + call rotary + +; RDTSC +; pop ebx +; sub eax,ebx +; sub eax,41 +; push eax + + mov esi,[points_rotated_ptr] + mov edi,[points_translated_ptr] + movzx ecx,[points_count_var] + call translate_points + +; cmp [dr_flag],5 +; jne @f +; call calc_attenuation_light +; @@: + cmp [fire_flag],0 + jne @f + call clrscr ; clear the screen + @@: + cmp [catmull_flag],1 ;non sort if Catmull = on + je .no_sort + 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: + RDTSC + push eax + cmp [dr_flag],6 + jne @f + call draw_dots + jmp .blurrr + @@: + call draw_triangles ; draw all triangles from the list + .blurrr: + 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 + + @@: + + + 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 + mov ecx,SIZE_X shl 16 + SIZE_Y + mov edx,5 shl 16 + 20 + int 0x40 + + + mov eax,4 ; function 4 : write text to window + mov ebx,5*65536+23 ; [x start] *65536 + [y start] + mov ecx,-1 + mov edx,STRdata ; pointer to text beginning + mov esi,10 ; text length + int 40h + + + + jmp still + +;-------------------------------------------------------------------------------- +;-------------------------PROCEDURES--------------------------------------------- +;-------------------------------------------------------------------------------- +include "tex3.inc" +include "flat_cat.inc" +include "tex_cat.inc" +include "bump_cat.inc" +include "3dmath.inc" +include "grd3.inc" +include "flat3.inc" +include "bump3.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" + +alloc_buffer_mem: + movzx ecx,[size_x] + movzx eax,[size_y] + mul ecx + lea ecx,[eax*3] + push ecx + shl eax,2 + add ecx,eax + add ecx,MEM_END + mov ebx,1 + mov eax,64 ; allocate mem - resize app mem + int 0x40 + mov [screen_ptr],MEM_END + mov [Zbuffer_ptr],MEM_END + pop ecx + add [Zbuffer_ptr],ecx +ret + +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 + .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 ebx,(SIZE_X+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] + add ebx,(SIZE_X+12+70)*65536+28 ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 ; spherical mapping around y axle + fldpi + fadd st,st +; fstp .Pi2 + mov esi,[points_ptr] + mov edi,tex_points + movzx ecx,[points_count_var] + inc ecx + + @@: + 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 + +; mov esp,ebp +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 0 +init_triangles_normals: + mov ebx,triangles_normals + mov ebp,triangles + @@: + push ebx + mov ebx,vectors + movzx esi,word[ebp] ; first point index + lea esi,[esi*3] + lea esi,[points+esi*2] ; esi - pointer to 1st 3d point + 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 + add ebx,12 + mov esi,edi + movzx edi,word[ebp+4] ; third point index + lea edi,[edi*3] + lea edi,[points+edi*2] + call make_vector + 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,6 + add ebx,12 + cmp dword[ebp],-1 + jne @b +ret +end if +init_point_normals: +.x equ dword [ebp-4] +.y equ dword [ebp-8] +.z equ dword [ebp-12] +.point_number equ word [ebp-26] +.hit_faces equ word [ebp-28] + + fninit + mov ebp,esp + sub esp,28 + 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: + movzx eax,word[esi+ebx] ; eax - point_number + cmp ax,.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,2 + cmp ebx,6 + jne .ipn_check_vertex + .ipn_next_face: + add esi,6 + inc ecx + cmp cx,[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 dx,.point_number + cmp dx,[points_count_var] + jne .ipn_loop + + mov esp,ebp +ret +;=============================================================== + +init_triangles_normals2: + mov ebx,[triangles_normals_ptr] + mov ebp,[triangles_ptr] + @@: + push ebx + mov ebx,vectors + movzx esi,word[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] + movzx edi,word[ebp+2] ; 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 + movzx edi,word[ebp+4] ; 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,6 + add ebx,12 + cmp dword[ebp],-1 + jne @b +ret + + +;================================================================= +sort_triangles: + mov esi,[triangles_ptr] + mov edi,triangles_with_z + mov ebp,[points_translated_ptr] + + make_triangle_with_z: ;makes list with triangles and z position + movzx eax,word[esi] + lea eax,[eax*3] + movzx ecx,word[ebp+eax*2+4] + + movzx eax,word[esi+2] + lea eax,[eax*3] + add cx,word[ebp+eax*2+4] + + movzx eax,word[esi+4] + lea eax,[eax*3] + add cx,word[ebp+eax*2+4] + + mov ax,cx + ; cwd + ; idiv word[i3] + movsd ; store vertex coordinates + movsw + stosw ; middle vertex coordinate 'z' in triangles_with_z list + cmp dword[esi],-1 + jne make_triangle_with_z + movsd ; copy end mark + mov eax,4 + lea edx,[edi-8-trizdd] + ; lea edx, [edi-8] + ; sub edx,[triangles_w_z_ptr] + mov [high],edx + call quicksort + mov eax,4 + mov edx,[high] + call insertsort + jmp end_sort + + quicksort: + mov ecx,edx + sub ecx,eax + cmp ecx,32 + jc .exit + lea ecx,[eax+edx] + shr ecx,4 + lea ecx,[ecx*8-4]; +; mov edi,[triangles_w_z_ptr] +; mov ebx,[edi+eax] +; mov esi,[edi+ecx] +; mov edi,[edi+edx] + mov ebx,[trizdd+eax]; trizdd[l] + mov esi,[trizdd+ecx]; trizdd[i] + mov edi,[trizdd+edx]; trizdd[h] + cmp ebx,esi + jg @f ; direction NB! you need to negate these to invert the order + if Ext=NON + mov [trizdd+eax],esi + mov [trizdd+ecx],ebx + mov ebx,[trizdd+eax-4] + mov esi,[trizdd+ecx-4] + mov [trizdd+eax-4],esi + mov [trizdd+ecx-4],ebx + mov ebx,[trizdd+eax] + mov esi,[trizdd+ecx] + else +; push ebx +; mov ebx,[triangles_w_z_ptr] +; movq mm0,[ebx+eax-4] +; movq mm1,[ebx+ecx-4] +; movq [ebx+ecx-4],mm0 +; movq [ebx+eax-4],mm1 +; pop ebx + movq mm0,[trizdq+eax-4] + movq mm1,[trizdq+ecx-4] + movq [trizdq+ecx-4],mm0 + movq [trizdq+eax-4],mm1 + xchg ebx,esi + end if + @@: + cmp ebx,edi + jg @f ; direction + if Ext=NON + mov [trizdd+eax],edi + mov [trizdd+edx],ebx + mov ebx,[trizdd+eax-4] + mov edi,[trizdd+edx-4] + mov [trizdd+eax-4],edi + mov [trizdd+edx-4],ebx + mov ebx,[trizdd+eax] + mov edi,[trizdd+edx] + else +; push ebx +; mov ebx,[triangles_w_z_ptr] +; movq mm0,[ebx+eax-4] +; movq mm1,[ebx+edx-4] +; movq [ebx+edx-4],mm0 +; movq [ebx+eax-4],mm1 + movq mm0,[trizdq+eax-4] + movq mm1,[trizdq+edx-4] + movq [trizdq+edx-4],mm0 + movq [trizdq+eax-4],mm1 +; pop ebx + xchg ebx,edi + end if + @@: + cmp esi,edi + jg @f ; direction + if Ext=NON + mov [trizdd+ecx],edi + mov [trizdd+edx],esi + mov esi,[trizdd+ecx-4] + mov edi,[trizdd+edx-4] + mov [trizdd+ecx-4],edi + mov [trizdd+edx-4],esi + else +; push ebx +; mov ebx,[triangles_w_z_ptr] +; movq mm0,[ebx+ecx-4] +; movq mm1,[ebx+edx-4] +; movq [ebx+edx-4],mm0 +; movq [ebx+ecx-4],mm1 +; pop ebx + + movq mm0,[trizdq+ecx-4] + movq mm1,[trizdq+edx-4] + movq [trizdq+edx-4],mm0 + movq [trizdq+ecx-4],mm1 + xchg ebx,esi + end if + @@: + mov ebp,eax ; direction + add ebp,8 ; j + if Ext=NON + mov esi,[trizdd+ebp] + mov edi,[trizdd+ecx] + mov [trizdd+ebp],edi + mov [trizdd+ecx],esi + mov esi,[trizdd+ebp-4] + mov edi,[trizdd+ecx-4] + mov [trizdd+ecx-4],esi + mov [trizdd+ebp-4],edi + else +; push ebx +; mov ebx,[triangles_w_z_ptr] +; movq mm0,[ebx+ebp-4] +; movq mm1,[ebx+ecx-4] +; movq [ebx+ecx-4],mm0 +; movq [ebx+ebp-4],mm1 +; pop ebx + + movq mm0,[trizdq+ebp-4] + movq mm1,[trizdq+ecx-4] + movq [trizdq+ecx-4],mm0 + movq [trizdq+ebp-4],mm1 + end if + mov ecx,edx ; i; direction + mov ebx,[trizdd+ebp]; trizdd[j] +; mov ebx, [triangles_w_z_ptr] +; add ebx, ebp + + ; push eax + ; mov eax, [triangles_w_z_ptr] + .loop: + sub ecx,8 ; direction + cmp [trizdd+ecx],ebx +; cmp [eax+ecx],ebx + jl .loop ; direction + @@: + add ebp,8 ; direction + cmp [trizdd+ebp],ebx +; cmp [eax+ebp],ebx + jg @b ; direction + cmp ebp,ecx + jge @f ; direction + if Ext=NON + mov esi,[trizdd+ecx] + mov edi,[trizdd+ebp] + mov [trizdd+ebp],esi + mov [trizdd+ecx],edi + mov edi,[trizdd+ecx-4] + mov esi,[trizdd+ebp-4] + mov [trizdd+ebp-4],edi + mov [trizdd+ecx-4],esi + else +; movq mm0,[eax+ecx-4] +; movq mm1,[eax+ebp-4] +; movq [eax+ebp-4],mm0 +; movq [eax+ecx-4],mm1 + movq mm0,[trizdq+ecx-4] + movq mm1,[trizdq+ebp-4] + movq [trizdq+ebp-4],mm0 + movq [trizdq+ecx-4],mm1 + end if + jmp .loop +; pop eax + @@: + if Ext=NON + mov esi,[trizdd+ecx] + mov edi,[trizdd+eax+8] + mov [trizdd+eax+8],esi + mov [trizdd+ecx],edi + mov edi,[trizdd+ecx-4] + mov esi,[trizdd+eax+4] + mov [trizdd+eax+4],edi + mov [trizdd+ecx-4],esi + else +; push edx +; mov edx,[triangles_w_z_ptr] +; movq mm0,[edx+ecx-4] +; movq mm1,[edx+eax+4]; dir +; movq [edx+eax+4],mm0; dir +; movq [edx+ecx-4],mm1 +; pop edx + + movq mm0,[trizdq+ecx-4] + movq mm1,[trizdq+eax+4]; dir + movq [trizdq+eax+4],mm0; dir + movq [trizdq+ecx-4],mm1 + end if + add ecx,8 + push ecx edx + mov edx,ebp + call quicksort + pop edx eax + call quicksort + .exit: + ret + insertsort: + mov esi,eax + .start: + add esi,8 + cmp esi,edx + ja .exit + mov ebx,[trizdd+esi] +; mov ebx,[triangles_w_z_ptr] +; add ebx,esi + if Ext=NON + mov ecx,[trizdd+esi-4] + else +; push ebx +; mov ebx,[triangles_w_z_ptr] +; movq mm1,[ebx+esi-4] + movq mm1,[trizdq+esi-4] +; pop ebx + end if + mov edi,esi + @@: + cmp edi,eax + jna @f +; push eax +; mov eax,[triangles_w_z_ptr] +; cmp [eax+edi-8],ebx +; pop eax + cmp [trizdd+edi-8],ebx + jg @f ; direction + if Ext=NON + mov ebp,[trizdd+edi-8] + mov [trizdd+edi],ebp + mov ebp,[trizdd+edi-12] + mov [trizdd+edi-4],ebp + else +; push eax +; mov eax,[triangles_w_z_ptr] +; movq mm0,[eax+edi-12] +; movq [eax+edi-4],mm0 + movq mm0,[trizdq+edi-12] + movq [trizdq+edi-4],mm0 +; pop eax + end if + sub edi,8 + jmp @b + @@: + if Ext=NON + mov [trizdd+edi],ebx + mov [trizdd+edi-4],ecx + else +; push eax +; mov eax,[triangles_w_z_ptr] +; movq [eax+edi-4],mm1 + movq [trizdq+edi-4],mm1 +; pop eax + end if + jmp .start + .exit: + ret + end_sort: + ; translate triangles_with_z to sorted_triangles + mov esi,triangles_with_z +; mov esi,[triangles_w_z_ptr] + ; mov edi,sorted_triangles + mov edi,[triangles_ptr] + again_copy: + if Ext=NON + movsd + movsw + add esi,2 + else + movq mm0,[esi] + movq [edi],mm0 + add esi,8 + add edi,6 + end if + cmp dword[esi],-1 + jne again_copy +; if Ext=MMX +; emms +; end if + movsd ; copy end mark too +ret + +clrscr: + mov edi,screen + mov ecx,SIZE_X*SIZE_Y*3/4 + xor eax,eax + if Ext=NON + rep stosd + else + 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 + end if +ret + + +draw_triangles: + mov esi,[triangles_ptr] + .again_dts: + mov ebp,[points_translated_ptr] + if Ext=NON + movzx eax,word[esi] + mov [point_index1],ax + lea eax,[eax*3] + add eax,eax + push ebp + add ebp,eax + mov eax,[ebp] + mov dword[xx1],eax + mov eax,[ebp+4] + mov [zz1],ax + pop ebp + + + movzx eax,word[esi+2] + mov [point_index2],ax + 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 + + + movzx eax,word[esi+4] ; xyz3 = [ebp+[esi+4]*6] + mov [point_index3],ax + 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 + mov eax,dword[esi] ; don't know MMX + mov dword[point_index1],eax + ; shr eax,16 + ; mov [point_index2],ax + mov ax,word[esi+4] + mov [point_index3],ax + movq mm0,[esi] + pmullw mm0,qword[const6] + movd eax,mm0 + psrlq mm0,16 + movd ebx,mm0 + psrlq mm0,16 + movd ecx,mm0 + 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 ; ********************************* + 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 ; + @@: + movzx eax,word[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 + ; **************** + mov esi,point_index3 ; do Gouraud shading + mov ecx,3 + .again_grd_draw: + movzx eax,word[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 word[esp-2] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] ; y cooficient + fimul [correct_tex] + fiadd [correct_tex] + fistp word[esp-4] + + movzx eax,word[esp-4] + movzx ebx,word[esp-2] + 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,2 + 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 + cmp [catmull_flag],1 + jne @f + push [zz2] + @@: + mov eax,dword[yy2] + and eax,ebx + push eax + neg al + push ax + cmp [catmull_flag],1 + jne @f + 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 + lea edi,[screen] + cmp [catmull_flag],0 + je @f + ; lea esi,[Z_buffer] + mov esi,[Zbuffer_ptr] + call gouraud_triangle_z + jmp .end_draw + @@: + call gouraud_triangle + jmp .end_draw + + .flat_draw: ;************************** + ; FLAT DRAWING + movzx eax,[point_index1] + movzx ebx,[point_index2] + movzx 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 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 dword[esp-8] ; y + mov edx,dword[esp-8] + shl edx,TEX_SHIFT + add edx,dword[esp-4] + lea eax,[3*edx+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 + lea edi,[screen] + cmp [catmull_flag],0 + je @f + ; lea esi,[Z_buffer] + mov esi,[Zbuffer_ptr] + push word[zz3] + push word[zz2] + push word[zz1] + call flat_triangle_z + jmp .end_draw + @@: + call draw_triangle + jmp .end_draw + .env_mapping: + ; fninit + cmp [catmull_flag],0 + je @f + push [zz3] + push [zz2] + push [zz1] + @@: + mov esi,point_index1 + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + movzx eax,word[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] ;point_normals_rotated +; # +; 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,2 + 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 + mov esi,envmap + cmp [catmull_flag],0 + je @f + ; mov edx,Z_buffer + mov edx,[Zbuffer_ptr] + call tex_triangle_z + jmp .end_draw + @@: + call tex_triangle + jmp .end_draw +;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + .cubic_env_mapping: + ; fninit + cmp [catmull_flag],0 + je @f + push [zz3] + push [zz2] + push [zz1] + @@: + mov esi,point_index1 + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + movzx eax,word[esi] + lea eax,[eax*3] + shl eax,2 + add eax,[points_normals_rot_ptr] ;point_normals_rotated +; # + 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,2 + 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 + mov esi,envmap_cub + cmp [catmull_flag],0 + je @f + ; mov edx,Z_buffer + mov edx,[Zbuffer_ptr] + call tex_triangle_z + jmp .end_draw + @@: + call tex_triangle + jmp .end_draw + +;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + .bump_mapping: + ; fninit + cmp [catmull_flag],0 + je @f +; push Z_buffer + push [Zbuffer_ptr] + push [zz3] + push [zz2] + push [zz1] + @@: + mov esi,point_index1 + sub esp,12 + mov edi,esp + mov ecx,3 + @@: + movzx eax,word[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,2 + loop @b + + movzx esi,[point_index3] ; bump map coords + shl esi,2 + add esi,tex_points + push dword[esi] + movzx 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] + movzx 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 + mov esi,envmap + mov edx,bumpmap ;BUMP_MAPPING + + cmp [catmull_flag],0 + je @f + call bump_triangle_z + jmp .end_draw + @@: + call bump_triangle + jmp .end_draw + + .tex_mapping: + + ; fninit + cmp [catmull_flag],0 + je @f + push [zz3] + push [zz2] + push [zz1] + @@: + movzx esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + movzx esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + movzx 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 + mov esi,texmap + cmp [catmull_flag],0 + je @f + ; mov edx,Z_buffer + mov edx,[Zbuffer_ptr] + call tex_triangle_z + ; call tex_plus_grd_trianlgle + jmp .end_draw + @@: + call tex_triangle + 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 + + movzx esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] ; texture coords as first + movzx esi,[point_index2] ; group of parameters + shl esi,2 + add esi,tex_points + push dword[esi] + movzx 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 + + movzx eax,word[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 word[ebp-2] + ; texture y=(rotated point normal -> y * 255)+255 + fld dword[eax+4] ; y cooficient + fimul [correct_tex] + fiadd [correct_tex] + fistp word[ebp-4] + + movzx eax,word[ebp-4] + movzx ebx,word[ebp-2] + shl eax,TEX_SHIFT + add eax,ebx + lea eax,[eax*3+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,2 + 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 + 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] + + movzx esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + movzx esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + movzx 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 + @@: + movzx eax,word[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,2 + 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 + mov esi,texmap + mov edx,envmap + + call two_tex_triangle_z + jmp .end_draw + + .bump_tex: + movzx esi,[point_index3] ; tex map coords + shl esi,2 + add esi,tex_points + push dword[esi] + movzx esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + movzx 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 + @@: + movzx eax,word[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,2 + loop @b + +; push dword 1 shl 16 + 1 ; emap coords +; push dword 127 shl 16 + 1 +; push dword 127 shl 16 + 127 + + movzx esi,[point_index3] ; bump map coords + shl esi,2 + add esi,tex_points + push dword[esi] + movzx esi,[point_index2] + shl esi,2 + add esi,tex_points + push dword[esi] + + movzx 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 + mov esi,envmap + mov edx,bumpmap + + call bump_tex_triangle_z + + .end_draw: + pop esi + add esi,6 + cmp dword[esi],-1 + jne .again_dts +ret + + +fill_Z_buffer: + mov eax,0x70000000 + ; mov edi,Z_buffer + mov edi,[Zbuffer_ptr] + mov ecx,SIZE_X*SIZE_Y + rep stosd +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],cx + + mov edx,ecx + add esi,8 + @@: + push edi + mov edi,[points_ptr] + push dword[esi+4] + pop dword[edi+ebx*2+0] + push dword[esi+8] + pop dword[edi+ebx*2+4] + push dword[esi+0] + pop dword[edi+ebx*2+8] + pop edi +; fld dword[esi+4] +; fstp dword[real_points+ebx*2+0] ; x +; fld dword[esi+8] +; fstp dword[real_points+ebx*2+4] ; y +; fld dword[esi+0] +; fstp dword[real_points+ebx*2+8] ; z + + 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],cx + add esi,8 + ;mov edi,triangles + @@: + movsd + movsw + add word[edi-6],bp + add word[edi-4],bp + add word[edi-2],bp + add esi,2 + dec ecx + jnz @b + add ebp,edx + jmp .find4k + mov eax,-1 ;<---mark if OK + .exit: + mov dword[edi],-1 +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],bx + mov [triangles_count_var],bx + 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],cx + + 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],cx + 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 + +if USE_LFN +alloc_mem_for_tp: + mov eax, 68 + mov ebx, 12 + movzx ecx, [triangles_count_var] + inc ecx + lea ecx, [ecx*3] + add ecx, ecx + int 0x40 ; -> allocate memory to triangles + mov [triangles_ptr], eax ; -> eax = pointer to allocated mem + +; mov eax, 68 +; mov ebx, 12 +; movzx ecx, [triangles_count_var] +; shl ecx, 4 +; int 0x40 +; mov [triangles_w_z_ptr], eax ; for trainagles_with_z list + ; ststic memory + + mov eax, 68 + movzx ecx, [triangles_count_var] + lea ecx, [3+ecx*3] + shl ecx, 2 + int 0x40 ; -> allocate memory for triangles normals + mov [triangles_normals_ptr], eax ; -> eax = pointer to allocated mem + + mov eax, 68 + movzx ecx, [points_count_var] + lea ecx,[3+ecx*3] + shl ecx, 2 + int 0x40 + mov [points_normals_ptr], eax + + mov eax, 68 + mov ebx, 12 + movzx ecx, [points_count_var] + lea ecx,[3+ecx*3] + shl ecx, 2 + int 0x40 + mov [points_normals_rot_ptr], eax + + mov eax, 68 + int 0x40 + mov [points_ptr], eax + + mov eax, 68 + int 0x40 + mov [points_rotated_ptr], eax + + mov eax, 68 + movzx ecx, [points_count_var] + inc ecx + shl ecx, 3 + int 0x40 + mov [points_translated_ptr], eax +ret +end if + + +read_from_disk: +if USE_LFN +;- + mov eax, 70 + mov ebx, file_info + mov dword[ebx], 5 ; -> subfunction number + int 0x40 ; -> read file size + mov ebx, [fptr] + mov ebx, dword[ebx+32] + inc ebx + mov [fsize], ebx + + mov eax, 68 + mov ebx, 11 + int 0x40 ; -> create heap + + mov eax, 68 + mov ebx, 12 + mov ecx, [fsize] + int 0x40 ; -> allocate memory for file + mov [fptr], eax ; -> eax = pointer to allocated mem + + mov eax, 70 + mov ebx, file_info + mov dword[ebx],0 + int 0x40 ; -> read file + + mov [fsize],ebx + + cmp eax,6 + jnz @f + xor eax,eax ;;;;--- + @@: +else + mov eax,58 + mov ebx,file_info + int 0x40 + + mov eax,ebx + shr eax,9 + inc eax + mov [fsize],eax +; mov ecx,ebx +; add ecx,MEM_END +; mov ebx,1 +; mov eax,64 ; allocate mem - resize app mem + ; for points and triangles + int 0x40 + + mov eax,58 + mov ebx,file_info + int 0x40 +end if + ; 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 ebx,(SIZE_X+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] + add ebx,(SIZE_X+12)*65536+28 ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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,0x20ddeeff ; 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 ebx,100*65536;+SIZE_X;+80+30 ; [x start] *65536 + [x size] + mov ecx,100*65536;+SIZE_Y;+30 ; [y start] *65536 + [y size] + mov bx,[size_x] + add bx,110 + mov cx,[size_y] + add cx,30 + mov edx,0x02000000 ; color of work area RRGGBB,8->color gl + mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl + mov edi,0x005080d0 ; color of frames RRGGBB + int 0x40 + + ; WINDOW LABEL + mov eax,4 ; function 4 : write text to window + mov ebx,8*65536+8 ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB ) + mov edx,labelt ; pointer to text beginning + mov esi,labellen-labelt ; text length + int 0x40 + + ; CLOSE BUTTON + mov eax,8 ; function 8 : define and draw button + movzx ebx,[size_x] + shl ebx,16 + add ebx, 91 shl 16 + 12 +; mov ebx,(SIZE_X+80+30-19)*65536+12 ; [x start] *65536 + [x size] + mov ecx,5*65536+12 ; [y start] *65536 + [y size] + mov edx,1 ; button id + mov esi,0x6688dd ; button color RRGGBB + int 0x40 + + call buttons ; more buttons + + .Y_ADD equ 1 ;-> offset of 'add vector' buttons + + ; ADD VECTOR LABEL ; add vector buttons - 30 ++ + mov eax,4 ; function 4 : write text to window + mov ebx,(SIZE_X+12)*65536+(168+15*(13+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 + mov ebx,(SIZE_X+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 + mov ebx,(SIZE_X+32)*65536+(168+15*(14+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 + mov ebx,(SIZE_X+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 + mov ebx,(SIZE_X+53)*65536+(168+15*(14+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 + mov ebx,(SIZE_X+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 + mov ebx,(SIZE_X+12)*65536+(168+15*(15+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 + mov ebx,(SIZE_X+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 + mov ebx,(SIZE_X+53)*65536+(168+15*(15+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 + mov ebx,(SIZE_X+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 + mov ebx,(SIZE_X+12)*65536+(168+15*(16+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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 + mov ebx,(SIZE_X+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 + mov ebx,(SIZE_X+32)*65536+(168+15*(16+.Y_ADD)) ; [x start] *65536 + [y start] + mov ecx,0x20ddeeff ; 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' + +MEM_END: diff --git a/programs/demos/3DS/data.inc b/programs/demos/3DS/data.inc new file mode 100644 index 0000000000..0d1263e4d1 --- /dev/null +++ b/programs/demos/3DS/data.inc @@ -0,0 +1,468 @@ + ; DATA AREA ************************************ + + i3 dw 3 + 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 -500 + size_x dw SIZE_X + size_y dw SIZE_Y + + 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 + angle_x dw 0 + angle_y dw 0 + angle_z dw 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' + db 11 + dr_flag db 0 + 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 1 + 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 2 +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 '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' + spd_f: + db 'idle' + db 'full' + axl_f: + db ' y ' + db 'x+y ' + db ' x ' + onoff_f: + db 'off ' + db 'on ' +; light_component_f: +; db 'norm ' ; diffuse | +; db 'min' ; specular | or sth. like this +; db 'max ' ; emmisive | + +;; color_component_f: +;; db ' r ' +;; db ' g ' +;; db ' b ' + + 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 '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: + +;navigation_size = $ - labelvector +; db 'set color ' +; db 'r -' +; db 'g +' +; db 'b -' +; db 'b +' +; db 'g -' +; db 'r +' + + labelt: + db 'DEUS CARITAS EST' + if Ext=MMX + db ' (MMX)' + end if + if Ext=SSE + db ' (SSE)' + end if + db ' 0.053' + labellen: + STRdata db '-1 ' + + all_lights_size dw lightsend-lights + +if USE_LFN + + file_info: + dd 0 + dd 0 + dd 0 + fsize dd 0 ;180000 ; sizeof(workarea) + fptr dd 0 ;workarea + file_name: + db '/rd/1/3d/teapot.3ds',0 + +else + + file_info: + dd 0 + dd 0 + fsize dd 1 + dd workarea + dd hash_table + file_name: + db '/rd/1/teapot.3ds',0 +end if + +I_END: + + 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: + +if USE_LFN = 0 +hash_table rb 4096 +SourceFile: +workarea rb 180000 +else +SourceFile: +workarea rb 180 +end if +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 + scale dd ? ; help scale variable + ;== + triangles_count_var dw ? + points_count_var dw ? + triangles_ptr dd ? + triangles_w_z_ptr dd ? + triangles_normals_ptr dd ? + points_normals_ptr dd ? + points_normals_rot_ptr dd ? + points_ptr dd ? + points_rotated_ptr dd ? + points_translated_ptr dd ? + screen_ptr dd ? + Zbuffer_ptr dd ? + + ;=== + + point_index1 dw ? ;-\ + point_index2 dw ? ; } don't change order + point_index3 dw ? ;-/ + temp_col dw ? + high dd ? + rand_seed dw ? +align 8 + buffer dq ? + err 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 + +if USE_LFN = 0 + points: + rw (EndFile-SourceFile)/12*3 + points_count = ($-points)/6 + triangles: + rw (EndFile-SourceFile)/12*3 + triangles_count = ($-triangles)/6 +align 16 + real_points rd points_count*3 + 1 +align 16 + rotated_points_r rd points_count*3 + 1 +align 16 + points_rotated rw points_count*3 + 2 ;means translated +align 16 + triangles_normals rb triangles_count * 12 ; +align 16 + point_normals rb points_count * 12 ;one 3dvector - triple float dword x,y,z +align 16 + point_normals_rotated rb points_count * 12 +align 16 + triangles_normals_rotated rb triangles_count * 12 + +else + points_count = 180000/6*3 + triangles_count = 180000 / 6 ;($-triangles)/6 +end if +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 +; points_color rb 6*points_count ; each color as word +; sorted_triangles rw triangles_count*3 + 2 +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 +1) * 3 +align 16 + tex_points rb points_count * 4 ; bump_map and texture coords + ; each point word x, word y +align 16 + ; 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 + I_Param rb 256 + memStack rb 4000 ;memory area for stack +align 16 +screen: \ No newline at end of file diff --git a/programs/demos/3DS/readme.txt b/programs/demos/3DS/readme.txt new file mode 100644 index 0000000000..09818815f8 --- /dev/null +++ b/programs/demos/3DS/readme.txt @@ -0,0 +1,31 @@ +View3ds 0.053 - tiny viewer to .3ds files. + +What's new? +1. Optimizations. + + +Buttons description: +1. rotary: choosing rotary axle: x, y, x+y. +2. shd. model: choosing shading model: flat, grd (smooth), env (spherical + environment mapping, bump (bump mapping), tex (texture mapping), + pos (position shading depend), dots (app draws only points - nodes of object), + txgrd (texture mapping + smooth shading), 2tex (texture mapping + spherical + environment mapping), bmap (bump + texture mapping), cenv (cubic environment + mapping). +3. speed: idle, full. +4,5. zoom in, out: no comment. +6. catmull: on( use z buffer ( z coordinate interpolation), off( depth sorting, painters alghoritm). + txgrd and 2tex models only with catmull = on. +7. culling: backface culling on/ off. +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 blur to do edges more deep. + carefull with emboss + fire - it looks annoying. +13. fire: do movement blur ( looks like fire ). +14. move: changes meaning x,y,z +/- buttons -> obj: moving object, camr: moving camera. +15. generate: Generates some objects: node, Thorn Crown, heart... +16. bumps: random, according to texture. +15. bumps deep -> create bumps deeper or lighter. + + Macgub X 2009 \ No newline at end of file