diff --git a/programs/demos/3DS/3DMATH.ASM b/programs/demos/3DS/3DMATH.ASM new file mode 100644 index 0000000000..dd022f13d9 --- /dev/null +++ b/programs/demos/3DS/3DMATH.ASM @@ -0,0 +1,109 @@ +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/3DSHEART.ASM b/programs/demos/3DS/3DSHEART.ASM new file mode 100644 index 0000000000..333f1620a5 --- /dev/null +++ b/programs/demos/3DS/3DSHEART.ASM @@ -0,0 +1,1984 @@ +; +; application : Deus Caritas Est - 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) +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 + + ; 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 new file mode 100644 index 0000000000..c57fef8f44 --- /dev/null +++ b/programs/demos/3DS/3DSTPOT.ASM @@ -0,0 +1,1991 @@ +; +; 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 new file mode 100644 index 0000000000..dae8a7f1ad --- /dev/null +++ b/programs/demos/3DS/3dspiral.asm @@ -0,0 +1,440 @@ +; +; 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/FLAT3.ASM b/programs/demos/3DS/FLAT3.ASM new file mode 100644 index 0000000000..a2253bcba9 --- /dev/null +++ b/programs/demos/3DS/FLAT3.ASM @@ -0,0 +1,188 @@ +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/FLATWAV.ASM b/programs/demos/3DS/FLATWAV.ASM new file mode 100644 index 0000000000..7ae0f76572 --- /dev/null +++ b/programs/demos/3DS/FLATWAV.ASM @@ -0,0 +1,762 @@ +; +; 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.ASM new file mode 100644 index 0000000000..c07458ecc9 --- /dev/null +++ b/programs/demos/3DS/FLAT_CAT.ASM @@ -0,0 +1,342 @@ +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)-------------------------------------------- +; ----------------in - eax - x1 shl 16 + y1 ---------------------- +; -------------------- ebx - x2 shl 16 + y2 ---------------------- +; -------------------- ecx - x3 shl 16 + y3 ---------------------- +; -------------------- edx - color 0x00RRGGBB -------------------- +; -------------------- esi - pointer to Z-buffer ----------------- +; -------------------- edi - pointer to screen buffer------------- +; -------------------- stack : z coordinates +; -------------------- Z-buffer : each z variable as dword +; -------------------- (Z coor. as word) shl CATMULL_SHIFT +.z1 equ word[ebp+4] +.z2 equ word[ebp+6] ; each z coordinate as word integer +.z3 equ word[ebp+8] + +.col equ dword[ebp-4] +.x1 equ word[ebp-6] +.y1 equ word[ebp-8] +.x2 equ word[ebp-10] +.y2 equ word[ebp-12] +.x3 equ word[ebp-14] +.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] +.dx23 equ dword[ebp-36] +.dz23 equ dword[ebp-40] +.zz1 equ dword[ebp-44] +.zz2 equ dword[ebp-48] + + mov ebp,esp + push edx ; store edx in variable .col + .sort2: + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov dx,.z1 + xchg dx,.z2 + mov .z1,dx + .sort1: + cmp bx,cx + jle .sort3 + xchg ebx,ecx + mov dx,.z2 + xchg dx,.z3 + mov .z2,dx + jmp .sort2 + .sort3: + push eax ; store triangle coordinates in 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 .ft_loop2_end + ; cmp ax,SIZE_Y + ; jle @f + ; cmp bx,SIZE_Y + ; jle @f + ; cmp cx,SIZE_Y + ; jge @f + ; ror eax,16 + ; ror ebx,16 + ; ror ecx,16 + ; cmp ax,SIZE_X + ; jle @f + ; cmp bx,SIZE_X + ; jle @f + ; cmp cx,SIZE_X + ; jle @f + ; jmp .ft_loop2_end + ;@@: + sub esp,32 + + mov bx,.y2 ; calc delta 12 + sub bx,.y1 + jnz .ft_dx12_make + mov .dx12,0 + mov .dz12,0 + jmp .ft_dx12_done + .ft_dx12_make: + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + mov .dx12,eax + + mov ax,.z2 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + mov .dz12,eax + .ft_dx12_done: + mov bx,.y3 ; calc delta 13 + sub bx,.y1 + jnz .ft_dx13_make + mov .dx13,0 + mov .dz13,0 + jmp .ft_dx13_done + .ft_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + mov .dx13,eax + + mov ax,.z3 + sub ax,.z1 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + mov .dz13,eax + .ft_dx13_done: + mov bx,.y3 ; calc delta 23 + sub bx,.y2 + jnz .gt_dx23_make + mov .dx23,0 + mov .dz23,0 + jmp .gt_dx23_done + .gt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + mov .dx23,eax + + mov ax,.z3 + sub ax,.z2 + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + mov .dz23,eax + .gt_dx23_done: + + movsx edx,.z1 + shl edx,CATMULL_SHIFT + mov .zz1,edx + mov .zz2,edx + movsx eax,.x1 + shl eax,ROUND ; eax - x1 + mov ebx,eax ; ebx - x2 + mov cx,.y1 + cmp cx,.y2 + jge .ft_loop1_end + .ft_loop1: + + pushad + + push .col + push cx ; y + sar ebx,ROUND + push bx ; x2 + sar eax,ROUND + push ax ; x1 + push .zz2 ; z2 shl CATMULL_SHIFT + push .zz1 ; z1 shl CATMULL_SHIFT + call flat_line_z + + popad + + add eax,.dx13 + add ebx,.dx12 + mov edx,.dz13 + add .zz1,edx + mov edx,.dz12 + add .zz2,edx + inc cx + cmp cx,.y2 + jl .ft_loop1 + .ft_loop1_end: + + movsx edx,.z2 + shl edx,CATMULL_SHIFT + mov .zz2,edx + movsx ebx,.x2 + shl ebx,ROUND + mov cx,.y2 + cmp cx,.y3 + jge .ft_loop2_end + .ft_loop2: + pushad + + push .col + push cx + sar ebx,ROUND + push bx + sar eax,ROUND + push ax ; x1 + push .zz2 ; z2 shl CATMULL_SHIFT + push .zz1 ; z1 shl CATMULL_SHIFT + call flat_line_z + + popad + + add eax,.dx13 + add ebx,.dx23 + mov edx,.dz13 + add .zz1,edx + mov edx,.dz23 + add .zz2,edx + inc cx + cmp cx,.y3 + jl .ft_loop2 + .ft_loop2_end: + + mov esp,ebp +ret 6 + +flat_line_z: +;---------------- +;-------------in edi - pointer to screen buffer ---------------------------------- +;--------------- esi - pointer to z-buffer (each Z varible dword)----------------- +;----------stack - (each z coordinate shifted shl CATMULL_SHIFT)------------------ +.z1 equ dword [ebp+4] +.z2 equ dword [ebp+8] +.x1 equ word [ebp+12] +.x2 equ word [ebp+14] +.y equ word [ebp+16] +.col equ dword [ebp+18] + +.dz equ dword [ebp-4] + + mov ebp,esp +;; sub esp,4 + mov ax,.y + or ax,ax + jl .fl_quit + cmp ax,SIZE_Y-1 + jg .fl_quit + + ; cmp .x1,0 + ; jge .fl_ok1 + ; cmp .x2,0 + ; jl .fl_quit + ; .fl_ok1: + ; cmp .x1,SIZE_X + ; jle .fl_ok2 + ; cmp .x2,SIZE_X + ; jg .fl_quit + ; .fl_ok2: + mov ax,.x1 + cmp ax,.x2 + je .fl_quit + jl .fl_ok + + xchg ax,.x2 + mov .x1,ax + mov edx,.z1 + xchg edx,.z2 + mov .z1,edx + .fl_ok: + cmp .x1,SIZE_X-1 + jg .fl_quit + cmp .x2,0 + jle .fl_quit + + mov eax,.z2 + sub eax,.z1 + cdq + mov bx,.x2 + sub bx,.x1 + movsx ebx,bx + idiv ebx +;; mov .dz,eax ; calculated delta - shifted .dz + push eax + + cmp .x1,0 + jge @f + movsx ebx,.x1 + neg ebx + imul ebx + add .z1,eax + mov .x1,0 + @@: + cmp .x2,SIZE_X + jl @f + mov .x2,SIZE_X + @@: + mov edx,SIZE_X + movsx eax,.y + mul edx ; edi = edi + (SIZE_X * y + x1)*3 + movsx edx,.x1 + add eax,edx + push eax + lea eax,[eax*3] + add edi,eax ; esi = esi + (SIZE_X * y + x1)*4 + pop eax + shl eax,2 + add esi,eax + + mov cx,.x2 + sub cx,.x1 + movzx ecx,cx + + mov eax,.col + mov ebx,.z1 ; ebx : curr. z + mov edx,.dz + .ddraw: + ;pushad + ;show + ;popad + cmp ebx,dword[esi] + jge .skip + stosd + dec edi + mov dword[esi],ebx + jmp .no_skip + .skip: + add edi,3 + .no_skip: + add esi,4 + add ebx,edx + loop .ddraw + + .fl_quit: + mov esp,ebp +ret 18 diff --git a/programs/demos/3DS/GRD3.ASM b/programs/demos/3DS/GRD3.ASM new file mode 100644 index 0000000000..ade6e1be47 --- /dev/null +++ b/programs/demos/3DS/GRD3.ASM @@ -0,0 +1,481 @@ +gouraud_triangle: +;------------------in - eax - x1 shl 16 + y1 --------- +;---------------------- ebx - x2 shl 16 + y2 --------- +;---------------------- ecx - x3 shl 16 + y3 --------- +;---------------------- edi - pointer to screen buffer +;---------------------- stack : colors---------------- +;----------------- procedure don't save registers !!-- +.col1r equ ebp+4 ; each color as word +.col1g equ ebp+6 +.col1b equ ebp+8 +.col2r equ ebp+10 +.col2g equ ebp+12 +.col2b equ ebp+14 +.col3r equ ebp+16 +.col3g equ ebp+18 +.col3b equ ebp+20 + +.x1 equ word[ebp-2] +.y1 equ word[ebp-4] +.x2 equ word[ebp-6] +.y2 equ word[ebp-8] +.x3 equ word[ebp-10] +.y3 equ word[ebp-12] + +.dc12r equ dword[ebp-16] +.dc12g equ dword[ebp-20] +.dc12b equ dword[ebp-24] +.dc13r equ dword[ebp-28] +.dc13g equ dword[ebp-32] +.dc13b equ dword[ebp-36] +.dc23r equ dword[ebp-40] +.dc23g equ dword[ebp-44] +.dc23b equ dword[ebp-48] + +.c1r equ dword[ebp-52] +.c1g equ dword[ebp-56] +.c1b equ dword[ebp-60] +.c2r equ dword[ebp-64] +.c2g equ dword[ebp-68] +.c2b equ dword[ebp-72] + +.dx12 equ dword[ebp-76] +.dx13 equ dword[ebp-80] +.dx23 equ dword[ebp-84] + + + + mov ebp,esp +; sub esp,72 + + .sort3: ; sort triangle coordinates... + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov edx,dword[.col1r] + xchg edx,dword[.col2r] + mov dword[.col1r],edx + mov dx,word[.col1b] + xchg dx,word[.col2b] + mov word[.col1b],dx + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + mov edx,dword[.col2r] + xchg edx,dword[.col3r] + mov dword[.col2r],edx + mov dx,word[.col2b] + xchg dx,word[.col3b] + mov word[.col2b],dx + jmp .sort3 + .sort2: + push eax ;store triangle coordinates in user friendly variables + push ebx + push ecx + sub esp,72 ; set correctly value of esp + + mov edx,eax ; check only X triangle coordinate + or edx,ebx + or edx,ecx + test edx,80000000h + jne .gt_loop2_end + shr eax,16 + cmp ax,SIZE_X-1 + jg .gt_loop2_end + shr ebx,16 + cmp bx,SIZE_X-1 + jg .gt_loop2_end + shr ecx,16 + cmp cx,SIZE_X-1 + jg .gt_loop2_end + + + mov bx,.y2 ; calc deltas + sub bx,.y1 + jnz .gt_dx12_make + mov .dx12,0 + mov .dc12r,0 + mov .dc12g,0 + mov .dc12b,0 + jmp .gt_dx12_done + .gt_dx12_make: + + mov ax,.x2 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + mov .dx12,eax + + mov ax,word[.col2r] + sub ax,word[.col1r] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc12r,eax + mov ax,word[.col2g] + sub ax,word[.col1g] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc12g,eax + mov ax,word[.col2b] + sub ax,word[.col1b] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc12b,eax +.gt_dx12_done: + + mov bx,.y3 + sub bx,.y1 + jnz .gt_dx13_make + mov .dx13,0 + mov .dc13r,0 + mov .dc13g,0 + mov .dc13b,0 + jmp .gt_dx13_done +.gt_dx13_make: + mov ax,.x3 + sub ax,.x1 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + mov .dx13,eax + + mov ax,word[.col3r] + sub ax,word[.col1r] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc13r,eax + mov ax,word[.col3g] + sub ax,word[.col1g] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc13g,eax + mov ax,word[.col3b] + sub ax,word[.col1b] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc13b,eax +.gt_dx13_done: + + mov bx,.y3 + sub bx,.y2 + jnz .gt_dx23_make + mov .dx23,0 + mov .dc23r,0 + mov .dc23g,0 + mov .dc23b,0 + jmp .gt_dx23_done +.gt_dx23_make: + mov ax,.x3 + sub ax,.x2 + cwde + movsx ebx,bx + shl eax,ROUND + cdq + idiv ebx + mov .dx23,eax + + mov ax,word[.col3r] + sub ax,word[.col2r] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc23r,eax + mov ax,word[.col3g] + sub ax,word[.col2g] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc23g,eax + mov ax,word[.col3b] + sub ax,word[.col2b] + cwde + shl eax,ROUND + cdq + idiv ebx + mov .dc23b,eax +.gt_dx23_done: + + movsx eax,.x1 + shl eax,ROUND + mov ebx,eax + movsx edx,word[.col1r] + shl edx,ROUND + mov .c1r,edx + mov .c2r,edx + movsx edx,word[.col1g] + shl edx,ROUND + mov .c1g,edx + mov .c2g,edx + movsx edx,word[.col1b] + shl edx,ROUND + mov .c1b,edx + mov .c2b,edx + mov cx,.y1 + cmp cx,.y2 + jge .gt_loop1_end +.gt_loop1: + push eax ; eax - cur x1 + push ebx ; ebx - cur x2 + push cx ; cx - cur y + push edi + push ebp + + mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors + sar edx,ROUND + push dx + mov edx,.c2g + sar edx,ROUND + push dx + mov edx,.c2b + sar edx,ROUND + push dx + mov edx,.c1r + sar edx,ROUND + push dx + mov edx,.c1g + sar edx,ROUND + push dx + mov edx,.c1b + sar edx,ROUND + push dx + push cx + sar ebx,ROUND + push bx + sar eax,ROUND + push ax + call gouraud_line + + pop ebp + pop edi + pop cx + pop ebx + pop eax + + mov edx,.dc13r + add .c1r,edx + mov edx,.dc13g + add .c1g,edx + mov edx,.dc13b + add .c1b,edx + mov edx,.dc12r + add .c2r,edx + mov edx,.dc12g + add .c2g,edx + mov edx,.dc12b + add .c2b,edx + + add eax,.dx13 + add ebx,.dx12 + inc cx + cmp cx,.y2 + jl .gt_loop1 +.gt_loop1_end: + + mov cx,.y2 + cmp cx,.y3 + jge .gt_loop2_end + movsx ebx,.x2 + shl ebx,ROUND + + movsx edx,word[.col2r] + shl edx,ROUND + mov .c2r,edx + movsx edx,word[.col2g] + shl edx,ROUND + mov .c2g,edx + movsx edx,word[.col2b] + shl edx,ROUND + mov .c2b,edx +.gt_loop2: + push eax ; eax - cur x1 + push ebx ; ebx - cur x2 + push cx + push edi + push ebp + + mov edx,.c2r + sar edx,ROUND + push dx + mov edx,.c2g + sar edx,ROUND + push dx + mov edx,.c2b + sar edx,ROUND + push dx + mov edx,.c1r + sar edx,ROUND + push dx + mov edx,.c1g + sar edx,ROUND + push dx + mov edx,.c1b + sar edx,ROUND + push dx + push cx + sar ebx,ROUND + push bx + sar eax,ROUND + push ax + call gouraud_line + + pop ebp + pop edi + pop cx + pop ebx + pop eax + + mov edx,.dc13r + add .c1r,edx + mov edx,.dc13g + add .c1g,edx + mov edx,.dc13b + add .c1b,edx + mov edx,.dc23r + add .c2r,edx + mov edx,.dc23g + add .c2g,edx + mov edx,.dc23b + add .c2b,edx + + add eax,.dx13 + add ebx,.dx23 + inc cx + cmp cx,.y3 + jl .gt_loop2 +.gt_loop2_end: + + ; add esp,84 + mov esp,ebp +ret 18 +gouraud_line: +;-------------in - edi - pointer to screen buffer +;----------------- stack - another parameters +.x1 equ word [ebp+4] +.x2 equ word [ebp+6] +.y equ word [ebp+8] +.col1b equ ebp+10 +.col1g equ ebp+12 +.col1r equ ebp+14 +.col2b equ ebp+16 +.col2g equ ebp+18 +.col2r equ ebp+20 +.dc_r equ dword[ebp-4] +.dc_g equ dword[ebp-8] +.dc_b equ dword[ebp-12] + mov ebp,esp + + mov ax,.y + or ax,ax + jl .gl_quit + cmp ax,SIZE_Y-1 + jg .gl_quit + + mov ax,.x1 + cmp ax,.x2 + je .gl_quit + jl .gl_ok + + xchg ax,.x2 + mov .x1,ax + mov eax,dword[.col1b] + xchg eax,dword[.col2b] + mov dword[.col1b],eax + mov ax,word[.col1r] + xchg ax,word[.col2r] + mov word[.col1r],ax +.gl_ok: + ; cmp .x1,SIZE_X-1 ;check + ; jg .gl_quit + ; cmp .x2,SIZE_X-1 + ; jl @f + ; mov .x2,SIZE_X-1 + ; @@: + ; cmp .x1,0 + ; jg @f + ; mov .x1,0 + ; @@: + ; cmp .x2,0 + ; jl .gl_quit + + movsx ecx,.y + mov eax,SIZE_X*3 + mul ecx + movsx ebx,.x1 + lea ecx,[ebx*2+eax] + add edi,ecx + add edi,ebx + + mov ax,word[.col2r] + sub ax,word[.col1r] + cwde + shl eax,ROUND + cdq + mov cx,.x2 + sub cx,.x1 + movsx ecx,cx + idiv ecx + ;mov .dc_r,eax ;first delta + push eax + + mov ax,word[.col2g] + sub ax,word[.col1g] + cwde + shl eax,ROUND + cdq + idiv ecx + ;mov .dc_g,eax + push eax + + mov ax,word[.col2b] + sub ax,word[.col1b] + cwde + shl eax,ROUND + cdq + idiv ecx + ; mov .dc_b,eax + push eax + + movsx ebx,word[.col1r] + shl ebx,ROUND + movsx edx,word[.col1g] + shl edx,ROUND + movsx esi,word[.col1b] + shl esi,ROUND +.gl_draw: + mov eax,ebx + sar eax,ROUND + stosb + mov eax,edx + sar eax,ROUND + stosb + mov eax,esi + sar eax,ROUND + stosb + add ebx,.dc_r + add edx,.dc_g + add esi,.dc_b + loop .gl_draw +.gl_quit: + ; add esp,12 + mov esp,ebp +ret 18 \ No newline at end of file diff --git a/programs/demos/3DS/GRD_CAT.ASM b/programs/demos/3DS/GRD_CAT.ASM new file mode 100644 index 0000000000..26942aaddd --- /dev/null +++ b/programs/demos/3DS/GRD_CAT.ASM @@ -0,0 +1,598 @@ +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 ------------ +;---------------------- ebx - x2 shl 16 + y2 ------------ +;---------------------- ecx - x3 shl 16 + y3 ------------ +;---------------------- esi - pointer to Z-buffer-------- +;---------------------- Z-buffer filled with dd variables +;---------------------- shifted CATMULL_SHIFT------------ +;---------------------- edi - pointer to screen buffer--- +;---------------------- stack : colors------------------- +;----------------- procedure don't save registers !!----- +.col1r equ ebp+4 ; each color as word +.col1g equ ebp+6 ; each z coordinate as word +.col1b equ ebp+8 +.z1 equ ebp+10 +.col2r equ ebp+12 +.col2g equ ebp+14 +.col2b equ ebp+16 +.z2 equ ebp+18 +.col3r equ ebp+20 +.col3g equ ebp+22 +.col3b equ ebp+24 +.z3 equ ebp+26 + +.x1 equ word[ebp-2] +.y1 equ word[ebp-4] +.x2 equ word[ebp-6] +.y2 equ word[ebp-8] +.x3 equ word[ebp-10] +.y3 equ word[ebp-12] + +.dx12 equ dword[ebp-16] +.dz12 equ dword[ebp-20] +.dc12r equ dword[ebp-24] +.dc12g equ dword[ebp-28] +.dc12b equ dword[ebp-32] + +.dx13 equ dword[ebp-36] +.dz13 equ dword[ebp-40] +.dc13r equ dword[ebp-44] +.dc13g equ dword[ebp-48] +.dc13b equ dword[ebp-52] + +.dx23 equ dword[ebp-56] +.dz23 equ dword[ebp-60] +.dc23r equ dword[ebp-64] +.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] + + mov ebp,esp + ; sub esp,84 + .sort3: ; sort triangle coordinates... + cmp ax,bx + jle .sort1 + xchg eax,ebx + mov edx,dword[.col1r] + xchg edx,dword[.col2r] + mov dword[.col1r],edx + mov edx,dword[.col1b] + xchg edx,dword[.col2b] + mov dword[.col1b],edx + .sort1: + cmp bx,cx + jle .sort2 + xchg ebx,ecx + mov edx,dword[.col2r] + xchg edx,dword[.col3r] + mov dword[.col2r],edx + mov edx,dword[.col2b] + xchg edx,dword[.col3b] + mov dword[.col2b],edx + jmp .sort3 + .sort2: + push eax ; store 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 .gt_loop2_end + + mov bx,.y2 ; calc deltas + sub bx,.y1 + jnz .gt_dx12_make + ; mov .dx12,0 + ; mov .dz12,0 + ; mov .dc12r,0 + ; mov .dc12g,0 + ; mov .dc12b,0 + mov ecx,5 + @@: + push dword 0 + loop @b + jmp .gt_dx12_done + .gt_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[.z2] + sub ax,word[.z1] + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + + 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 + .gt_dx12_done: + + mov bx,.y3 ; calc deltas + sub bx,.y1 + jnz .gt_dx13_make + ; mov .dx13,0 + ; mov .dz13,0 + ; mov .dc13r,0 + ; mov .dc13g,0 + ; mov .dc13b,0 + mov ecx,5 + @@: + push dword 0 + loop @b + jmp .gt_dx13_done + .gt_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[.z3] + sub ax,word[.z1] + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + + mov ax,word[.col3r] + sub ax,word[.col1r] + cwde + shl eax,ROUND + cdq + idiv ebx + ; mov .dc13r,eax + push eax + 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 + .gt_dx13_done: + + mov bx,.y3 ; calc deltas + sub bx,.y2 + jnz .gt_dx23_make + ; mov .dx23,0 + ; mov .dz23,0 + ; mov .dc23r,0 + ; mov .dc23g,0 + ; mov .dc23b,0 + mov ecx,5 + @@: + push dword 0 + loop @b + jmp .gt_dx23_done + .gt_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[.z3] + sub ax,word[.z2] + cwde + shl eax,CATMULL_SHIFT + cdq + idiv ebx + push eax + + mov ax,word[.col3r] + sub ax,word[.col2r] + cwde + 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 + .gt_dx23_done: + sub esp,32 + + 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 edx,word[.col1r] + shl edx,ROUND + mov .c1r,edx + mov .c2r,edx + movzx edx,word[.col1g] + shl edx,ROUND + mov .c1g,edx + mov .c2g,edx + movzx edx,word[.col1b] + shl edx,ROUND + mov .c1b,edx + mov .c2b,edx + mov cx,.y1 + cmp cx,.y2 + jge .gt_loop1_end + + .gt_loop1: + pushad + ; macro .debug + + mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors + sar edx,ROUND + push dx + mov edx,.c2g + sar edx,ROUND + push dx + mov edx,.c2b + sar edx,ROUND + push dx + sar ebx,ROUND ; x2 + push bx + mov edx,.c1r + sar edx,ROUND + push dx + mov edx,.c1g + sar edx,ROUND + push dx + mov edx,.c1b + sar edx,ROUND + push dx + sar eax,ROUND + push ax ; x1 + push cx ; y + push .zz2 + push .zz1 + call gouraud_line_z + + popad + + mov edx,.dc13r + add .c1r,edx + mov edx,.dc13g + add .c1g,edx + mov edx,.dc13b + add .c1b,edx + mov edx,.dc12r + add .c2r,edx + mov edx,.dc12g + add .c2g,edx + mov edx,.dc12b + add .c2b,edx + mov edx,.dz13 + add .zz1,edx + mov edx,.dz12 + add .zz2,edx + + add eax,.dx13 + add ebx,.dx12 + inc cx + cmp cx,.y2 + jl .gt_loop1 + + .gt_loop1_end: + mov cx,.y2 + cmp cx,.y3 + jge .gt_loop2_end + + movsx ebx,.x2 ; eax - cur x1 + shl ebx,ROUND ; ebx - cur x2 + movsx edx,word[.z2] + shl edx,CATMULL_SHIFT + mov .zz2,edx + movzx edx,word[.col2r] + shl edx,ROUND + mov .c2r,edx + movzx edx,word[.col2g] + shl edx,ROUND + mov .c2g,edx + movzx edx,word[.col2b] + shl edx,ROUND + mov .c2b,edx + + .gt_loop2: + pushad + ; macro .debug + + mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors + sar edx,ROUND + push dx + mov edx,.c2g + sar edx,ROUND + push dx + mov edx,.c2b + sar edx,ROUND + push dx + sar ebx,ROUND ; x2 + push bx + mov edx,.c1r + sar edx,ROUND + push dx + mov edx,.c1g + sar edx,ROUND + push dx + mov edx,.c1b + sar edx,ROUND + push dx + sar eax,ROUND + push ax ; x1 + push cx ; y + push .zz2 + push .zz1 + call gouraud_line_z + + popad + + mov edx,.dc13r + add .c1r,edx + mov edx,.dc13g + add .c1g,edx + mov edx,.dc13b + add .c1b,edx + mov edx,.dc23r + add .c2r,edx + mov edx,.dc23g + add .c2g,edx + mov edx,.dc23b + add .c2b,edx + mov edx,.dz13 + add .zz1,edx + mov edx,.dz23 + add .zz2,edx + + add eax,.dx13 + add ebx,.dx23 + inc cx + cmp cx,.y3 + jl .gt_loop2 + .gt_loop2_end: + + mov esp,ebp +ret 24 +gouraud_line_z: +;----------------- procedure drawing gouraud line +;----------------- with z coordinate interpolation +;----------------- esi - pointer to Z_buffer +;----------------- edi - pointer to screen buffer +;----------------- stack: +.z1 equ dword[ebp+4] ; z coordiunate shifted left CATMULL_SHIFT +.z2 equ dword[ebp+8] +.y equ word[ebp+12] +.x1 equ ebp+14 +.c1b equ ebp+16 +.c1g equ ebp+18 +.c1r equ ebp+20 +.x2 equ ebp+22 +.c2b equ ebp+24 +.c2g equ ebp+26 +.c2r equ ebp+28 +.dz equ dword[ebp-4] +.dc_r 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] + mov ebp,esp + + mov ax,.y + or ax,ax + jl .gl_quit + cmp ax,SIZE_Y + jge .gl_quit + + mov eax,dword[.x1] + cmp ax,word[.x2] + je .gl_quit + jl @f + + xchg eax,dword[.x2] + mov dword[.x1],eax + mov eax,dword[.c1g] + xchg eax,dword[.c2g] + mov dword[.c1g],eax + mov eax,.z1 + xchg eax,.z2 + mov .z1,eax + @@: + cmp word[.x1],SIZE_X + jge .gl_quit + cmp word[.x2],0 + jle .gl_quit + + mov eax,.z2 + sub eax,.z1 + cdq + mov bx,word[.x2] ; dz = z2-z1/x2-x1 + sub bx,word[.x1] + movsx ebx,bx + idiv ebx + push eax + + mov ax,word[.c2r] + sub ax,word[.c1r] + cwde + shl eax,ROUND ; dc_r = c2r-c1r/x2-x1 + cdq + idiv ebx + push eax + + mov ax,word[.c2g] + sub ax,word[.c1g] + cwde + shl eax,ROUND + cdq + idiv ebx + push eax + + mov ax,word[.c2b] + sub ax,word[.c1b] + cwde + shl eax,ROUND + cdq + idiv ebx + push eax + + cmp word[.x1],0 + jg @f + mov eax,.dz + movsx ebx,word[.x1] + neg ebx + imul ebx + add .z1,eax + mov word[.x1],0 + + mov eax,.dc_r + imul ebx + sar eax,ROUND + add word[.c1r],ax + + mov eax,.dc_g + imul ebx + sar eax,ROUND + add word[.c1g],ax + + mov eax,.dc_b + imul ebx + sar eax,ROUND + add word[.c1b],ax + + @@: + cmp word[.x2],SIZE_X + jl @f + mov word[.x2],SIZE_X + @@: + sub esp,12 ; calculate memory begin + mov edx,SIZE_X ; in buffers + movzx eax,.y + mul edx + movzx edx,word[.x1] + add eax,edx + push eax + lea eax,[eax*3] + add edi,eax + pop eax + shl eax,2 + add esi,eax + + mov cx,word[.x2] + sub cx,word[.x1] + movzx ecx,cx + mov ebx,.z1 ; ebx - currrent z shl CATMULL_SIFT + mov edx,.dz ; edx - delta z + movzx eax,word[.c1r] + shl eax,ROUND + mov .cr,eax + movzx eax,word[.c1g] + shl eax,ROUND + mov .cg,eax + movzx eax,word[.c1b] + shl eax,ROUND + mov .cb,eax + .ddraw: + cmp ebx,dword[esi] + jge .skip + mov eax,.cr + sar eax,ROUND + stosb + mov eax,.cg + sar eax,ROUND + stosb + mov eax,.cb + sar eax,ROUND + stosb + mov dword[esi],ebx + jmp .no_skip + .skip: + add edi,3 + .no_skip: + add esi,4 + add ebx,edx + mov eax,.dc_r + add .cr,eax + mov eax,.dc_g + add .cg,eax + mov eax,.dc_b + add .cb,eax + loop .ddraw + + .gl_quit: + mov esp,ebp +ret 26 \ No newline at end of file diff --git a/programs/demos/3DS/HRT.3DS b/programs/demos/3DS/HRT.3DS new file mode 100644 index 0000000000..a21f9d98be Binary files /dev/null and b/programs/demos/3DS/HRT.3DS differ diff --git a/programs/demos/3DS/TEAPOT.3DS b/programs/demos/3DS/TEAPOT.3DS new file mode 100644 index 0000000000..a48099d710 Binary files /dev/null and b/programs/demos/3DS/TEAPOT.3DS differ diff --git a/programs/demos/3DS/TEX3.ASM b/programs/demos/3DS/TEX3.ASM new file mode 100644 index 0000000000..afb0263ee9 --- /dev/null +++ b/programs/demos/3DS/TEX3.ASM @@ -0,0 +1,507 @@ +;--------------------------------------------------------------------- +;--------------------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/develop/fasm/trunk/build_ru.bat b/programs/develop/fasm/trunk/build_ru.bat index 8b14218bdd..69a5437498 100644 --- a/programs/develop/fasm/trunk/build_ru.bat +++ b/programs/develop/fasm/trunk/build_ru.bat @@ -2,4 +2,5 @@ @echo lang fix ru >lang.inc @fasm fasm.asm fasm @erase lang.inc +@kpack fasm @pause \ No newline at end of file diff --git a/programs/fs/kfar/trunk/build_ru.bat b/programs/fs/kfar/trunk/build_ru.bat index b0ca73ff89..c5ffa6ecd9 100644 --- a/programs/fs/kfar/trunk/build_ru.bat +++ b/programs/fs/kfar/trunk/build_ru.bat @@ -2,4 +2,5 @@ @echo lang fix ru >lang.inc @fasm kfar.asm kfar @erase lang.inc +@kpack kfar @pause \ No newline at end of file diff --git a/programs/games/rsquare/trunk/build_ru.bat b/programs/games/rsquare/trunk/build_ru.bat index 5c9f6f6923..32c91aaf7d 100644 --- a/programs/games/rsquare/trunk/build_ru.bat +++ b/programs/games/rsquare/trunk/build_ru.bat @@ -1,4 +1,5 @@ @echo lang fix ru >lang.inc @fasm rsquare.asm rsquare @erase lang.inc +kpack rsquare @pause \ No newline at end of file diff --git a/programs/media/jpegview/trunk/build_ru.bat b/programs/media/jpegview/trunk/build_ru.bat index d2a7da4349..2cf6968185 100644 --- a/programs/media/jpegview/trunk/build_ru.bat +++ b/programs/media/jpegview/trunk/build_ru.bat @@ -2,4 +2,5 @@ @echo lang fix ru >lang.inc @fasm jpegview.asm jpegview @erase lang.inc +@kpack jpegview @pause \ No newline at end of file diff --git a/programs/network/ftps/trunk/FTPS.ASM b/programs/network/ftps/trunk/FTPS.ASM index 2a4cb4f931..a1dd089428 100644 --- a/programs/network/ftps/trunk/FTPS.ASM +++ b/programs/network/ftps/trunk/FTPS.ASM @@ -20,7 +20,7 @@ use32 dd 0x7FFF0 ; esp = 0x7FFF0 dd 0, 0 ; no params, no path -include '..\..\..\macros.inc' +include 'macros.inc' ; Various states of client connection USER_NONE equ 0 ; Awaiting a connection USER_CONNECTED equ 1 ; User just connected, prompt given @@ -66,7 +66,7 @@ still: ; If the socket closed by remote host, open it again. cmp eax, 7 je con - + ; If socket closed by Reset, open it again cmp eax, 11 je con @@ -180,7 +180,7 @@ draw_window: xor eax,eax ; DRAW WINDOW mov ebx,100*65536+491 + 8 +15 mov ecx,100*65536+270 + 20 ; 20 for status bar - mov edx,0x13000000 + mov edx,0x14000000 mov edi,labelt mcall @@ -434,17 +434,17 @@ outputStr: mcall pop edx pop esi - + cmp eax, 0 je os_exit - - ; The TCP/IP transmit queue is full; Wait a bit, then retry + + ; The TCP/IP transmit queue is full; Wait a bit, then retry pusha mov eax,5 mov ebx,1 ; Delay for up 100ms mcall popa - jmp outputStr + jmp outputStr os_exit: ret @@ -475,13 +475,13 @@ outputDataStr: cmp eax, 0 je ods_exit - ; The TCP/IP transmit queue is full; Wait a bit, then retry + ; The TCP/IP transmit queue is full; Wait a bit, then retry pusha mov eax,5 mov ebx,20 ; Delay for upto 200ms mcall popa - jmp outputDataStr + jmp outputDataStr ods_exit: ret @@ -582,7 +582,7 @@ disconnect: mov ecx,[CmdSocket] mcall ret - + ;*************************************************************************** @@ -841,7 +841,7 @@ pps002: ; The data connection is already open. ; ; Inputs -; None +; None ; ; Outputs ; None @@ -1002,7 +1002,7 @@ sd_exit: ; file descriptor ; ; Inputs -; None +; None ; ; Outputs ; None @@ -1010,32 +1010,32 @@ sd_exit: ;*************************************************************************** setupFilePath: mov esi, buff + 4 ; Point to (1 before) first character of file - + ; Skip any trailing spaces or / character -sfp001: +sfp001: inc esi cmp [esi], byte ' ' je sfp001 cmp [esi], byte '/' je sfp001 - + ; esi points to start of filename. - - + + ; Copy across the directory path '/' ; into the fileinfoblock mov edi, filename mov dword [edi], '/RD/' mov word [edi+4], '1/' add edi, 6 - + ; Copy across the filename sfp002: cld movsb cmp [esi], byte 0x0d jne sfp002 - mov [edi], byte 0 + mov [edi], byte 0 ret @@ -1050,7 +1050,7 @@ sfp002: ; The file to send is named in the buff string ; ; Inputs -; None +; None ; ; Outputs ; None @@ -1065,7 +1065,7 @@ sendFile: and dword [ebx+4], 0 ; first block sf002a: - ; now read the file.. + ; now read the file.. mov eax,70 mcall test eax, eax @@ -1088,9 +1088,9 @@ sf002a: add dword [ebx+4], edx jmp sf002a -sf_exit: +sf_exit: ret - + ;*************************************************************************** ; Function @@ -1101,7 +1101,7 @@ sf_exit: ; The file to receive is named in the buff string ; ; Inputs -; None +; None ; ; Outputs ; None @@ -1109,7 +1109,7 @@ sf_exit: ;*************************************************************************** getFile: call setupFilePath - + ; init fileblock descriptor, for file write xor eax, eax mov [fsize], eax ; Start filelength at 0 @@ -1117,7 +1117,7 @@ getFile: inc eax inc eax mov [fileinfoblock], eax ; write cmd - + ; Read data from the socket until the socket closes ; loop ; loop @@ -1127,7 +1127,7 @@ getFile: ; sleep 100ms ; until socket no longer connected ; write file to ram - + gf000: mov eax, 53 mov ebx, 2 ; Get # of bytes in input queue @@ -1135,20 +1135,20 @@ gf000: mcall test eax, eax je gf_sleep - + mov eax, 53 mov ebx, 3 ; Get a byte from socket in bl mov ecx, [DataSocket] mcall ; returned data in bl - + mov esi, text + 0x1300 add esi, dword [fsize] mov [esi], bl inc dword [fsize] - + ; dummy, write to screen - ;call printChar - + ;call printChar + jmp gf000 gf_sleep: @@ -1176,8 +1176,8 @@ gf001: mov ebx,10 ; Delay for up 100ms mcall jmp gf000 ; try for more data - - + + @@ -1203,12 +1203,12 @@ cmdCWD: ; Only / is valid for the ramdisk cmp [buff+5], byte 0x0d jne ccwd_000 - + ; OK, show the directory name text mov esi, chdir mov edx, chdir_end - chdir jmp ccwd_001 - + ccwd_000: ; Tell user there is no such directory mov esi, noFileStr @@ -1292,22 +1292,22 @@ cmdDELE: mcall pop dword [ebx+16] pop dword [ebx+12] - + test eax, eax jne cmdDele_err mov esi, delokStr mov edx, delokStr_end - delokStr call outputStr - + jmp cmdDele_exit - -cmdDele_err: + +cmdDele_err: mov esi, noFileStr mov edx, noFileStr_end - noFileStr call outputStr - - + + cmdDele_exit: ret @@ -1340,7 +1340,7 @@ cl001: ; send directory listing call sendDir - + ; Close port call disconnectData @@ -1376,7 +1376,7 @@ cr001: ; send data to remote user call sendFile - + ; Close port call disconnectData @@ -1418,7 +1418,7 @@ cs001: ; get data file from remote user call getFile - + mov esi, endStr mov edx, endStr_end - endStr call outputStr @@ -1612,7 +1612,7 @@ dirinfoblock: dirpath db '/sys',0 fsize: dd 0 - + state db 0 buffptr dd 0 buff: times 256 db 0 ; Could put this after iend diff --git a/programs/network/httpc/trunk/httpc.asm b/programs/network/httpc/trunk/httpc.asm index 41c64f19fb..9e0d3c7f4c 100644 --- a/programs/network/httpc/trunk/httpc.asm +++ b/programs/network/httpc/trunk/httpc.asm @@ -23,17 +23,17 @@ DEBUGGING_DISABLED equ 0 DEBUGGING_STATE equ DEBUGGING_DISABLED use32 - org 0x0 - db 'MENUET01' ; header - dd 0x01 ; header version - dd START ; entry point - dd I_END ; image size - dd 0x100000 ; required memory - dd 0x100000 ; esp - dd 0x0 , 0x0 ; I_Param , I_Path + org 0x0 + db 'MENUET01' ; header + dd 0x01 ; header version + dd START ; entry point + dd I_END ; image size + dd 0x100000 ; required memory + dd 0x100000 ; esp + dd 0x0 , 0x0 ; I_Param , I_Path include 'lang.inc' -include '..\..\..\macros.inc' +include 'macros.inc' ;include "DEBUG.INC" URLMAXLEN equ 50 ; maximum length of url string @@ -1392,11 +1392,11 @@ draw_window: mov eax,0 ; function 0 : define and draw window mov ebx,50*65536+550 ; [x start] *65536 + [x size] mov ecx,50*65536+400 ; [y start] *65536 + [y size] - mov edx,0x13ffffff ; color of work area RRGGBB,8->color gl + mov edx,0x14ffffff ; color of work area RRGGBB,8->color gl mov edi,title ; WINDOW LABEL mcall - + mov esi, URLMAXLEN ; URL mov eax,4 ; function 4 : write text to window mov ebx,30*65536+38 ; [x start] *65536 + [y start] diff --git a/programs/network/https/trunk/https.asm b/programs/network/https/trunk/https.asm index b69b97b3f7..6045af826a 100644 --- a/programs/network/https/trunk/https.asm +++ b/programs/network/https/trunk/https.asm @@ -19,17 +19,17 @@ version equ '0.6' use32 - org 0x0 + org 0x0 - db 'MENUET01' ; 8 byte id - dd 0x01 ; required os - dd START ; program start - dd I_END ; program image size - dd 0x400000 ; required amount of memory - dd 0x20000 - dd 0,0 ; reserved=no extended header + db 'MENUET01' ; 8 byte id + dd 0x01 ; required os + dd START ; program start + dd I_END ; program image size + dd 0x400000 ; required amount of memory + dd 0x20000 + dd 0,0 ; reserved=no extended header -include "..\..\..\MACROS.INC" +include "MACROS.INC" ; 0x0+ - program image ; 0x1ffff - stack @@ -42,7 +42,7 @@ filel: dd 0 dd 50000 dd 0x20000 - db '/sys/board.htm',0 + db '/sys/board.htm',0 files: dd 2 @@ -53,7 +53,7 @@ files: db '/sys/board.htm',0 -START: ; start of execution +START: ; start of execution mov eax,70 mov ebx,filel @@ -81,7 +81,7 @@ START: ; start of execution mov [last_status],-2 call clear_input red: - call draw_window ; at first, draw the window + call draw_window ; at first, draw the window still: @@ -110,26 +110,26 @@ last_status dd 0x0 check_events: - cmp eax,1 ; redraw request ? + cmp eax,1 ; redraw request ? jz red - cmp eax,2 ; key in buffer ? + cmp eax,2 ; key in buffer ? jz key - cmp eax,3 ; button in buffer ? + cmp eax,3 ; button in buffer ? jz button ret -key: ; Keys are not valid at this part of the - mov al,2 ; loop. Just read it and ignore +key: ; Keys are not valid at this part of the + mov al,2 ; loop. Just read it and ignore mcall ret -button: ; button +button: ; button - mov al,17 ; get id + mov al,17 ; get id mcall - cmp ah,1 ; close + cmp ah,1 ; close jnz tst2 mov eax,53 mov ebx,8 @@ -146,9 +146,9 @@ button: ; button mov eax,53 mov ebx,5 mov ecx,80 ; local port # - http - mov edx,0 ; no remote port specified - mov esi,0 ; no remote ip specified - mov edi,0 ; PASSIVE open + mov edx,0 ; no remote port specified + mov esi,0 ; no remote ip specified + mov edi,0 ; PASSIVE open mcall mov [socket], eax mov [posy],1 @@ -160,7 +160,7 @@ button: ; button call check_status ret tst3: - cmp ah,4 ; button id=4 ? + cmp ah,4 ; button id=4 ? jnz no4 mov [server_active],0 close_socket: @@ -181,9 +181,9 @@ button: ; button mov eax,53 mov ebx,5 mov ecx,80 ; local port # - http - mov edx,0 ; no remote port specified - mov esi,0 ; no remote ip specified - mov edi,0 ; PASSIVE open + mov edx,0 ; no remote port specified + mov esi,0 ; no remote ip specified + mov edi,0 ; PASSIVE open mcall mov [socket], eax no_re_open: @@ -211,8 +211,8 @@ button: ; button jmp still no4: - cmp ah,6 ; read directory - je read_string + cmp ah,6 ; read directory + je read_string ret @@ -240,9 +240,9 @@ start_transmission: wait_for_data: call check_for_incoming_data cmp [input_text+256+1],dword 'GET ' - je data_received + je data_received cmp [input_text+256+1],dword 'POST' - je data_received + je data_received mov eax,5 mov ebx,1 mcall @@ -291,7 +291,7 @@ start_transmission: add [filepos],edx cmp [file_left],0 - jg newblock + jg newblock no_http_request: @@ -363,14 +363,14 @@ send_header: pusha - mov eax,53 ; send response and file length + mov eax,53 ; send response and file length mov ebx,7 mov ecx,[socket] mov edx,h_len-html_header mov esi,html_header mcall - mov eax,53 ; send file type + mov eax,53 ; send file type mov ebx,7 mov ecx,[socket] mov edx,[type_len] @@ -380,13 +380,13 @@ send_header: popa ret -fileinfo dd 0 - dd 0 - dd 0 - dd 512 - dd 0x100000 -getf db '/sys/' - times 50 db 0 +fileinfo dd 0 + dd 0 + dd 0 + dd 512 + dd 0x100000 +getf db '/sys/' + times 50 db 0 wanted_file: times 100 db 0 getflen dd 6 @@ -395,30 +395,30 @@ make_room: pusha - mov edx,ecx + mov edx,ecx - mov esi,0x20000 - add esi,[board_size] - mov edi,esi - add edi,edx - mov ecx,[board_size] - sub ecx,board1-board - inc ecx + mov esi,0x20000 + add esi,[board_size] + mov edi,esi + add edi,edx + mov ecx,[board_size] + sub ecx,board1-board + inc ecx std - rep movsb + rep movsb cld popa ret -from_i dd 0x0 +from_i dd 0x0 from_len dd 0x0 message dd 0x0 message_len dd 0x0 -read_file: ; start of execution +read_file: ; start of execution mov [fileinfo+16],eax shl ebx, 9 @@ -428,7 +428,7 @@ read_file: ; start of execution mov [filename+40*2+6],dword 'UNK ' cmp [input_text+256+1],dword 'POST' - je yes_new_message + je yes_new_message cmp [input_text+256+11],dword 'oard' ; server board message jne no_server_message_2 @@ -454,7 +454,7 @@ read_file: ; start of execution newfroms: inc esi cmp esi,input_text+256*20 - je no_server_message_2 + je no_server_message_2 cmp [esi],dword 'from' jne newfroms @@ -464,11 +464,11 @@ read_file: ; start of execution mov edx,0 name_new_len: cmp [esi+edx],byte 13 - je name_found_len + je name_found_len cmp [esi+edx],byte '&' - je name_found_len + je name_found_len cmp edx,1000 - je name_found_len + je name_found_len inc edx jmp name_new_len @@ -480,7 +480,7 @@ read_file: ; start of execution newmessages: inc esi cmp esi,input_text+256*20 - je no_server_message_2 + je no_server_message_2 cmp [esi],dword 'sage' jne newmessages @@ -491,11 +491,11 @@ read_file: ; start of execution new_len: inc edx cmp [esi+edx],byte ' ' - je found_len + je found_len cmp [esi+edx],byte 13 jbe found_len cmp edx,input_text+5000 - je found_len + je found_len jmp new_len found_len: mov [message_len],edx @@ -552,14 +552,14 @@ read_file: ; start of execution call make_room - mov esi,board1 ; first part + mov esi,board1 ; first part mov edi,0x20000 add edi,board1-board mov ecx,edx cld rep movsb - mov esi,[from_i] ; name + mov esi,[from_i] ; name mov edi,0x20000 add edi,board1-board add edi,board1e-board1 @@ -567,7 +567,7 @@ read_file: ; start of execution cld rep movsb - mov esi,board2 ; middle part + mov esi,board2 ; middle part mov edi,0x20000 add edi,board1-board + board1e-board1 add edi,[from_len] @@ -575,7 +575,7 @@ read_file: ; start of execution cld rep movsb - mov esi,[message] ; message + mov esi,[message] ; message mov edi,0x20000 add edi,board1-board + board1e-board1 + board2e-board2 add edi,[from_len] @@ -659,7 +659,7 @@ read_file: ; start of execution cld new_let: cmp [esi],byte ' ' - je no_new_let + je no_new_let cmp edi,wanted_file+30 jge no_new_let movsb @@ -672,10 +672,10 @@ read_file: ; start of execution cmp esi,input_text+256+6 jne no_index mov edi,wanted_file - mov [edi+0],dword 'inde' - mov [edi+4],dword 'x.ht' - mov [edi+8],byte 'm' - mov [edi+9],byte 0 + mov [edi+0],dword 'inde' + mov [edi+4],dword 'x.ht' + mov [edi+8],byte 'm' + mov [edi+9],byte 0 add edi,9 mov [file_type],htm @@ -686,9 +686,9 @@ read_file: ; start of execution no_index: cmp [edi-3],dword 'htm'+0 - je htm_header + je htm_header cmp [edi-3],dword 'HTM'+0 - je htm_header + je htm_header jmp no_htm_header htm_header: mov [file_type],htm @@ -698,9 +698,9 @@ read_file: ; start of execution no_htm_header: cmp [edi-3],dword 'png'+0 - je png_header + je png_header cmp [edi-3],dword 'PNG'+0 - je png_header + je png_header jmp no_png_header png_header: mov [file_type],png @@ -710,9 +710,9 @@ read_file: ; start of execution no_png_header: cmp [edi-3],dword 'gif'+0 - je gif_header + je gif_header cmp [edi-3],dword 'GIF'+0 - je gif_header + je gif_header jmp no_gif_header gif_header: mov [file_type],gif @@ -722,9 +722,9 @@ read_file: ; start of execution no_gif_header: cmp [edi-3],dword 'jpg'+0 - je jpg_header + je jpg_header cmp [edi-3],dword 'JPG'+0 - je jpg_header + je jpg_header jmp no_jpg_header jpg_header: mov [file_type],jpg @@ -734,13 +734,13 @@ read_file: ; start of execution no_jpg_header: cmp [edi-3],dword 'asm'+0 - je txt_header + je txt_header cmp [edi-3],dword 'ASM'+0 - je txt_header + je txt_header cmp [edi-3],dword 'txt'+0 - je txt_header + je txt_header cmp [edi-3],dword 'TXT'+0 - je txt_header + je txt_header jmp no_txt_header txt_header: mov [file_type],txt @@ -766,13 +766,13 @@ read_file: ; start of execution cld rep movsb - mov [fileinfo+12],dword 1 ; file exists ? + mov [fileinfo+12],dword 1 ; file exists ? mov eax,70 mov ebx,fileinfo mcall - cmp eax,0 ; file not found - message - je file_found + cmp eax,0 ; file not found - message + je file_found mov edi,et call set_time mov edi,ed @@ -988,7 +988,7 @@ check_status: mcall cmp eax,[status] - je c_ret + je c_ret mov [status],eax add al,48 mov [text+12],al @@ -999,8 +999,8 @@ check_status: ret -addr dd 0x0 -ya dd 0x0 +addr dd 0x0 +ya dd 0x0 filename2: times 100 db 32 @@ -1028,11 +1028,11 @@ read_string: mcall shr eax,8 cmp eax,13 - je read_done + je read_done cmp eax,8 jnz nobsl cmp edi,[addr] - jz f11 + jz f11 sub edi,1 mov [edi],byte 32 call print_text @@ -1096,33 +1096,33 @@ print_text: draw_window: - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,1 ; 1, start of draw + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,1 ; 1, start of draw mcall - ; DRAW WINDOW - mov eax,0 ; function 0 : define and draw window - mov ebx,100*65536+480 ; [x start] *65536 + [x size] - mov ecx,100*65536+215 ; [y start] *65536 + [y size] - mov edx,0x13ffffff ; color of work area RRGGBB - mov edi,title ; WINDOW LABEL + ; DRAW WINDOW + mov eax,0 ; function 0 : define and draw window + mov ebx,100*65536+480 ; [x start] *65536 + [x size] + mov ecx,100*65536+215 ; [y start] *65536 + [y size] + mov edx,0x14ffffff ; color of work area RRGGBB + mov edi,title ; WINDOW LABEL mcall - mov eax,8 ; function 8 : define and draw button - mov ebx,(40)*65536+20 ; [x start] *65536 + [x size] - mov ecx,59*65536+9 ; [y start] *65536 + [y size] - mov edx,2 ; button id - mov esi,0x66aa66 ; button color RRGGBB + mov eax,8 ; function 8 : define and draw button + mov ebx,(40)*65536+20 ; [x start] *65536 + [x size] + mov ecx,59*65536+9 ; [y start] *65536 + [y size] + mov edx,2 ; button id + mov esi,0x66aa66 ; button color RRGGBB mcall - ; function 8 : define and draw button - mov ebx,(40)*65536+20 ; [x start] *65536 + [x size] + ; function 8 : define and draw button + mov ebx,(40)*65536+20 ; [x start] *65536 + [x size] mov ecx,72*65536+9 ; [y start] *65536 + [y size] - mov edx,4 ; button id - mov esi,0xaa6666 ; button color RRGGBB + mov edx,4 ; button id + mov esi,0xaa6666 ; button color RRGGBB mcall - ; Enter directory + ; Enter directory mov ebx,(25)*65536+66 mov ecx,135*65536+15 mov edx,6 @@ -1143,8 +1143,8 @@ draw_window: call draw_data - mov eax,12 ; function 12:tell os about windowdraw - mov ebx,2 ; 2, end of draw + mov eax,12 ; function 12:tell os about windowdraw + mov ebx,2 ; 2, end of draw mcall ret @@ -1154,7 +1154,7 @@ draw_data: pusha - mov ebx,25*65536+35 ; draw info text with function 4 + mov ebx,25*65536+35 ; draw info text with function 4 mov ecx,0x000000 mov edx,text mov esi,35 @@ -1186,7 +1186,7 @@ draw_data: mov [input_text+4],dword 'IVED' mov [input_text+8],dword ': ' - mov ebx,255*65536+35 ; draw info text with function 4 + mov ebx,255*65536+35 ; draw info text with function 4 mov ecx,0x000000 mov edx,input_text mov esi,35 @@ -1215,7 +1215,7 @@ draw_data: ; DATA AREA -status dd 0x0 +status dd 0x0 text: db 'TCB status: x ' @@ -1296,8 +1296,8 @@ unkl: title db appname,version,0 -socket dd 0x0 -server_active db 0x0 +socket dd 0x0 +server_active db 0x0 board: @@ -1354,8 +1354,8 @@ db "",13,10 board_end: -board_size dd 0x0 -board_messages dd 0x0 +board_size dd 0x0 +board_messages dd 0x0 input_text: diff --git a/programs/network/netsendc/trunk/netsendc.asm b/programs/network/netsendc/trunk/netsendc.asm index ab65fd3de9..298972d66c 100644 --- a/programs/network/netsendc/trunk/netsendc.asm +++ b/programs/network/netsendc/trunk/netsendc.asm @@ -1,21 +1,21 @@ ; ; NetSend(Client) -; +; ; Автор: Hex ; Сайт: www.mestack.narod.ru -; +; ; Описание: ; Программа для обмена сообщениями в сети.Клиентская часть. ; ; Compile with FASM for Menuet ; Компилируется FASM'ом для Менуэт ОС ; - - + + use32 - + org 0x0 - + db 'MENUET01' ; 8 byte id dd 1 ; header version dd START ; program start @@ -23,26 +23,26 @@ use32 dd mem ; required amount of memory dd mem ; stack pointer dd 0, 0 ; param, icon - + include 'lang.inc' -include '..\..\..\macros.inc' - +include 'macros.inc' + START: ; start of execution - + mov eax,53 ; open socket mov ebx,0 mov ecx,0x4000 ; local port mov edx,0x5000 ; remote port mov esi,dword [remote_ip] ; node IP mcall - + mov [socketNum], eax -red: +red: call draw_window ; at first, draw the window - + still: - + mov eax,10 ; wait here for event mcall @@ -55,11 +55,11 @@ key: mov al,2 mcall jmp still - + button: mov al,17 mcall - + dec ah ; button id=1 ? jnz noclose mov eax, 53 @@ -76,7 +76,7 @@ button: ;; SEND CODE TO REMOTE ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - + send_xcode: mov eax,53 ; SEND CODE TO REMOTE @@ -87,35 +87,35 @@ send_xcode: mcall jmp still - - + + ; ********************************************* ; ******* WINDOW DEFINITIONS AND DRAW ******** ; ********************************************* - - + + draw_window: - + mov eax,12 ; function 12:tell os about windowdraw mov ebx,1 ; 1, start of draw mcall - + ; DRAW WINDOW mov eax,0 ; function 0 : define and draw window mov ebx,100*65536+250 ; [x start] *65536 + [x size] mov ecx,60*65536+150 ; [y start] *65536 + [y size] - mov edx,0x13ffffff ; color of work area RRGGBB + mov edx,0x14ffffff ; color of work area RRGGBB mov edi,title ; WINDOW LABEL mcall - - + + mov eax,8 ; SEND MESSAGE mov ebx,50*65536+145 mov ecx,47*65536+13 mov edx,2 mov esi,0x667788 mcall - + mov eax,4 mov ebx,25*65536+50 ; draw info text with function 4 mov ecx,0x000000 @@ -127,17 +127,17 @@ draw_window: add edx,esi cmp [edx],byte 'x' jnz newline - + mov eax,12 ; function 12:tell os about windowdraw mov ebx,2 ; 2, end of draw mcall - + ret - - + + ; DATA AREA - -if lang eq ru + +if lang eq ru text: db ' Послать сообщение ' db ' ' @@ -153,16 +153,16 @@ text: db ' Remote address : 192.168.0.2 ' db 'Text and address in end of source ' db 'x' ; <- END MARKER, DONT DELETE -end if - +end if + title db 'NetSend(Client)',0 - + remote_ip db 192,168,1,2 - + send_data db 'Привет,это тест!Hello,this is a test!' end_message: - + I_END: align 4 socketNum dd ? diff --git a/programs/network/netsends/trunk/netsends.asm b/programs/network/netsends/trunk/netsends.asm index 9d42363f53..0084849718 100644 --- a/programs/network/netsends/trunk/netsends.asm +++ b/programs/network/netsends/trunk/netsends.asm @@ -1,33 +1,33 @@ ; ; NetSend(Server) -; +; ; Автор: Hex ; Сайт: www.mestack.narod.ru -; +; ; Описание: ; Программа для обмена сообщениями в сети.Серверная часть. ; ; Compile with FASM for Menuet ; Компилируется FASM'ом для Менуэт ОС ; - + use32 - org 0x0 - db 'MENUET01' ; header - dd 0x01 ; header version - dd START ; entry point - dd I_END ; image size - dd I_END+0x10000 ; required memory - dd I_END+0x10000 ; esp - dd 0x0 , 0x0 ; I_Param , I_Path - + org 0x0 + db 'MENUET01' ; header + dd 0x01 ; header version + dd START ; entry point + dd I_END ; image size + dd I_END+0x10000 ; required memory + dd I_END+0x10000 ; esp + dd 0x0 , 0x0 ; I_Param , I_Path + include 'lang.inc' -include '..\..\..\macros.inc' +include 'macros.inc' remote_ip db 192,168,0,1 - - + + START: ; start of execution - + mov eax, 53 ; open receiver socket mov ebx, 0 mov ecx, 0x5000 ; local port @@ -37,73 +37,73 @@ START: ; start of execution mov [socketNum],eax mov [0],eax ; save for remote code -red: +red: call draw_window ; at first, draw the window - + still: - + mov eax,23 ; wait here for event mov ebx,1 mcall - + cmp eax,1 ; redraw request ? jz red cmp eax,2 ; key in buffer ? jz key cmp eax,3 ; button in buffer ? jz button - + mov eax,53 ; data from cluster terminal ? mov ebx,2 mov ecx,[socketNum] mcall - + cmp eax,0 jne data_arrived - + jmp still - + key: mov eax,2 mcall jmp still - + button: - + mov eax,53 mov ebx,1 mov ecx,[socketNum] mcall or eax,-1 mcall - - + + data_arrived: - + mov eax,5 ; wait a second for everything to arrive mov ebx,10 mcall - + mov edi,I_END - + get_data: - + mov eax,53 mov ebx,3 mov ecx,[socketNum] mcall - + mov [edi],bl inc edi - + mov eax,53 mov ebx,2 mov ecx,[socketNum] mcall - + cmp eax,0 jne get_data - + mov eax,4 mov ebx,10*65536+60 add ebx,[y] @@ -111,35 +111,35 @@ data_arrived: mov edx,I_END mov esi,100 mcall - + add [y],10 - + jmp still - + y dd 0x10 - - - + + + ; ********************************************* ; ******* WINDOW DEFINITIONS AND DRAW ******** ; ********************************************* - - + + draw_window: - + mov eax,12 ; function 12:tell os about windowdraw mov ebx,1 ; 1, start of draw mcall - + ; DRAW WINDOW mov eax,0 ; function 0 : define and draw window mov ebx,100*65536+300 ; [x start] *65536 + [x size] mov ecx,100*65536+330 ; [y start] *65536 + [y size] - mov edx,0x13ffffff ; color of work area RRGGBB + mov edx,0x14ffffff ; color of work area RRGGBB mov edi,title ; WINDOW LABEL mcall - - + + ; Re-draw the screen text cld mov eax,4 @@ -153,18 +153,18 @@ draw_window: add edx,40 cmp [edx],byte 'x' jnz newline - - + + mov eax,12 ; function 12:tell os about windowdraw mov ebx,2 ; 2, end of draw mcall - + ret - - + + ; DATA AREA - -if lang eq ru + +if lang eq ru text: db 'Данный адрес : 192.168.0.2 ' db 'Прослушиваемый порт : 0x5000 ' @@ -177,10 +177,10 @@ text: db 'Received messages: ' db 'x' ; <- END MARKER, DONT DELETE end if - + title db 'NetSend(Server)',0 - + socketNum dd 0x0 - + I_END: diff --git a/programs/network/popc/trunk/popc.asm b/programs/network/popc/trunk/popc.asm index 26a5440fa0..37e7c92920 100644 --- a/programs/network/popc/trunk/popc.asm +++ b/programs/network/popc/trunk/popc.asm @@ -9,7 +9,7 @@ ;; Compile with FASM for Menuet ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -include '..\..\..\macros.inc' +include 'macros.inc' version equ '0.1' use32 @@ -811,7 +811,7 @@ draw_window: mov eax,0 ; draw window mov ebx,5*65536+435 mov ecx,5*65536+232 - mov edx,0x13ffffff + mov edx,0x14ffffff mov edi,labelt mcall diff --git a/programs/network/telnet/trunk/telnet.asm b/programs/network/telnet/trunk/telnet.asm index 109eecbbdb..d507265802 100644 --- a/programs/network/telnet/trunk/telnet.asm +++ b/programs/network/telnet/trunk/telnet.asm @@ -6,20 +6,20 @@ ; use32 - org 0x0 - db 'MENUET01' ; header - dd 0x01 ; header version - dd START ; entry point - dd I_END ; image size - dd I_END+0x10000 ; required memory - dd I_END+0x10000 ; esp - dd 0x0 , 0x0 ; I_Param , I_Path + org 0x0 + db 'MENUET01' ; header + dd 0x01 ; header version + dd START ; entry point + dd I_END ; image size + dd I_END+0x10000 ; required memory + dd I_END+0x10000 ; esp + dd 0x0 , 0x0 ; I_Param , I_Path include 'lang.inc' -include '..\..\..\macros.inc' +include 'macros.inc' -START: ; start of execution +START: ; start of execution ; Clear the screen memory mov eax, ' ' @@ -43,22 +43,22 @@ still: mov [socket_status], eax cmp eax, ebx - je waitev + je waitev red: call draw_window waitev: - mov eax,23 ; wait here for event + mov eax,23 ; wait here for event mov ebx,20 mcall - cmp eax,1 ; redraw request ? - je red - cmp eax,2 ; key in buffer ? - je key - cmp eax,3 ; button in buffer ? - je button + cmp eax,1 ; redraw request ? + je red + cmp eax,2 ; key in buffer ? + je key + cmp eax,3 ; button in buffer ? + je button ; any data from the socket? @@ -105,11 +105,11 @@ handle_data: mov al, [telnetstate] cmp al, 0 - je state0 + je state0 cmp al, 1 - je state1 + je state1 cmp al, 2 - je state2 + je state2 jmp hd001 state0: @@ -138,7 +138,7 @@ state2: ret hd001: - cmp bl,13 ; BEGINNING OF LINE + cmp bl,13 ; BEGINNING OF LINE jne nobol mov ecx,[pos] add ecx,1 @@ -154,7 +154,7 @@ hd001: jmp newdata nobol: - cmp bl,10 ; LINE DOWN + cmp bl,10 ; LINE DOWN jne nolf addx1: add [pos],dword 1 @@ -168,7 +168,7 @@ hd001: jmp cm1 nolf: - cmp bl,8 ; BACKSPACE + cmp bl,8 ; BACKSPACE jne nobasp mov eax,[pos] dec eax @@ -178,7 +178,7 @@ hd001: jmp newdata nobasp: - cmp bl,15 ; CHARACTER + cmp bl,15 ; CHARACTER jbe newdata mov eax,[pos] mov [eax+text],bl @@ -188,7 +188,7 @@ hd001: mov ebx,[scroll+4] imul ebx,80 cmp eax,ebx - jb noeaxz + jb noeaxz mov esi,text+80 mov edi,text mov ecx,ebx @@ -201,16 +201,16 @@ hd001: newdata: ret - key: ; KEY - mov eax,2 ; send to modem + key: ; KEY + mov eax,2 ; send to modem mcall mov ebx, [socket_status] - cmp ebx, 4 ; connection open? - jne still ; no, so ignore key + cmp ebx, 4 ; connection open? + jne still ; no, so ignore key shr eax,8 - cmp eax,178 ; ARROW KEYS + cmp eax,178 ; ARROW KEYS jne noaup mov al,'A' call arrow @@ -240,10 +240,10 @@ hd001: jmp still - button: ; BUTTON + button: ; BUTTON mov eax,17 mcall - cmp ah,1 ; CLOSE PROGRAM + cmp ah,1 ; CLOSE PROGRAM jne noclose mov eax,53 @@ -254,7 +254,7 @@ hd001: or eax,-1 mcall noclose: - cmp ah, 2 ; Set IP + cmp ah, 2 ; Set IP jne notip mov [string_x], dword 78 @@ -267,9 +267,9 @@ hd001: ip1: inc esi cmp [esi],byte '0' - jb ip2 + jb ip2 cmp [esi],byte '9' - jg ip2 + jg ip2 imul eax,10 movzx ebx,byte [esi] sub ebx,48 @@ -287,7 +287,7 @@ hd001: jmp still notip: - cmp ah, 3 ; set port + cmp ah, 3 ; set port jne notport mov [string_x], dword 215 @@ -300,9 +300,9 @@ notip: ip11: inc esi cmp [esi],byte '0' - jb ip21 + jb ip21 cmp [esi],byte '9' - jg ip21 + jg ip21 imul eax,10 movzx ebx,byte [esi] sub ebx,48 @@ -318,24 +318,24 @@ notip: jmp still notport: - cmp ah, 4 ; connect + cmp ah, 4 ; connect jne notcon mov eax, [socket_status] cmp eax, 4 - je still + je still call connect jmp still notcon: - cmp ah,5 ; disconnect + cmp ah,5 ; disconnect jne notdiscon call disconnect jmp still -notdiscon: ; Echo Toggle +notdiscon: ; Echo Toggle cmp ah, 6 jne still @@ -376,7 +376,7 @@ tm_000: pop bx mov al, [echo] cmp al, 0 - je tm_001 + je tm_001 push bx call handle_data @@ -409,17 +409,17 @@ disconnect: connect: pusha - mov ecx, 1000 ; local port starting at 1000 + mov ecx, 1000 ; local port starting at 1000 getlp: - inc ecx + inc ecx push ecx - mov eax, 53 - mov ebx, 9 + mov eax, 53 + mov ebx, 9 mcall - pop ecx - cmp eax, 0 ; is this local port in use? - jz getlp ; yes - so try next + pop ecx + cmp eax, 0 ; is this local port in use? + jz getlp ; yes - so try next mov eax,53 mov ebx,5 @@ -431,7 +431,7 @@ getlp: shl edx, 8 mov dl, [ip_address] mov esi, edx - movzx edx, word [port] ; telnet port id + movzx edx, word [port] ; telnet port id mov edi,1 ; active open mcall mov [socket], eax @@ -455,10 +455,10 @@ draw_window: mov ebx,1 mcall - xor eax,eax ; DRAW WINDOW + xor eax,eax ; DRAW WINDOW mov ebx,100*65536+491 + 8 +15 mov ecx,100*65536+270 + 20 ; 20 for status bar - mov edx,0x13000000 + mov edx,0x14000000 mov edi,title mcall @@ -469,14 +469,14 @@ draw_window: mov edx, 0x00557799 mcall - mov eax,8 ; BUTTON 2: SET IP + mov eax,8 ; BUTTON 2: SET IP mov ebx,4*65536+70 mov ecx,273*65536+12 mov esi, 0x00557799 mov edx,2 mcall - mov eax,4 ; Button text + mov eax,4 ; Button text mov ebx,6*65536+276 mov ecx,0x00ffffff mov edx,setipt @@ -485,7 +485,7 @@ draw_window: mov eax,47 - mov edi,ip_address ; display IP address + mov edi,ip_address ; display IP address mov edx,78*65536+276 mov esi,0x00ffffff mov ebx,3*65536 @@ -495,16 +495,16 @@ draw_window: add edx,6*4*65536 inc edi cmp edi,ip_address+4 - jb ipdisplay + jb ipdisplay - mov eax,8 ; BUTTON 3: SET PORT + mov eax,8 ; BUTTON 3: SET PORT mov ebx,173*65536+38 mov ecx,273*65536+12 mov edx,3 mov esi, 0x00557799 mcall - mov eax,4 ; Button text + mov eax,4 ; Button text mov ebx,178*65536+276 mov ecx,0x00ffffff mov edx,setportt @@ -512,21 +512,21 @@ draw_window: mcall - mov edx,216*65536+276 ; display port + mov edx,216*65536+276 ; display port mov esi,0x00ffffff mov ebx,4*65536 mov eax,47 movzx ecx,word [port] mcall - mov eax,8 ; BUTTON 4: Connect + mov eax,8 ; BUTTON 4: Connect mov ebx,250*65536+50 mov ecx,273*65536+12 mov esi, 0x00557799 mov edx,4 mcall - mov eax,4 ; Button text + mov eax,4 ; Button text mov ebx,255*65536+276 mov ecx,0x00ffffff mov edx,cont @@ -534,7 +534,7 @@ draw_window: mcall - mov eax,8 ; BUTTON 5: disconnect + mov eax,8 ; BUTTON 5: disconnect mov ebx,303*65536+70 mov ecx,273*65536+12 mov edx,5 @@ -542,7 +542,7 @@ draw_window: mcall - mov eax,4 ; Button text + mov eax,4 ; Button text mov ebx,307*65536+276 mov ecx,0x00ffffff mov edx,dist @@ -550,22 +550,22 @@ draw_window: mcall - mov esi,contlen-contt ; display connected status + mov esi,contlen-contt ; display connected status mov edx, contt mov eax, [socket_status] - cmp eax, 4 ; 4 is connected - je pcon + cmp eax, 4 ; 4 is connected + je pcon mov esi,discontlen-discontt mov edx, discontt pcon: - mov eax,4 ; status text + mov eax,4 ; status text mov ebx,380*65536+276 mov ecx,0x00ffffff mcall - mov eax,8 ; BUTTON 6: echo + mov eax,8 ; BUTTON 6: echo mov ebx,460*65536+50 mov ecx,273*65536+12 mov edx,6 @@ -581,7 +581,7 @@ pcon: mov esi,echoolen-echoot peo: - mov eax,4 ; Button text + mov eax,4 ; Button text mov ebx,463*65536+276 mov ecx,0x00ffffff mcall @@ -622,7 +622,7 @@ draw_text: ; erase character pusha - mov edx, 0 ; bg colour + mov edx, 0 ; bg colour mov ecx, ebx add ecx, 26 shl ecx, 16 @@ -656,11 +656,11 @@ draw_text: add esi,1 add eax,6 cmp eax,80*6 - jb newletter + jb newletter mov eax,0 add ebx,10 cmp ebx,24*10 - jb newletter + jb newletter popa ret @@ -686,11 +686,11 @@ read_string: mcall shr eax,8 cmp eax,13 - je read_done + je read_done cmp eax,8 jnz nobsl cmp edi,string - jz f11 + jz f11 sub edi,1 mov [edi],byte '_' call print_text @@ -699,7 +699,7 @@ read_string: cmp eax,dword 31 jbe f11 cmp eax,dword 95 - jb keyok + jb keyok sub eax,32 keyok: mov [edi],al @@ -750,41 +750,41 @@ print_text: ; DATA AREA -telnetrep db 0xff,0xfc,0x00 -telnetstate db 0 +telnetrep db 0xff,0xfc,0x00 +telnetstate db 0 string_length dd 16 string_x dd 200 string_y dd 60 -string db '________________' +string db '________________' -tx_buff db 0, 10 -ip_address db 001,002,003,004 -port db 0,0 -echo db 0 -socket dd 0x0 -socket_status dd 0x0 -pos dd 80 * 1 -scroll dd 1 - dd 24 -wcolor dd 0x000000 -title db 'Telnet v0.1',0 -setipt db 'IP Address: . . .' +tx_buff db 0, 10 +ip_address db 001,002,003,004 +port db 0,0 +echo db 0 +socket dd 0x0 +socket_status dd 0x0 +pos dd 80 * 1 +scroll dd 1 + dd 24 +wcolor dd 0x000000 +title db 'Telnet v0.1',0 +setipt db 'IP Address: . . .' setiplen: -setportt db 'Port:' +setportt db 'Port:' setportlen: -cont db 'Connect' +cont db 'Connect' conlen: -dist db 'Disconnect' +dist db 'Disconnect' dislen: -contt db 'Connected' +contt db 'Connected' contlen: -discontt db 'Disconnected' +discontt db 'Disconnected' discontlen: -echot db 'Echo On' +echot db 'Echo On' echolen: -echoot db 'Echo Off' +echoot db 'Echo Off' echoolen: diff --git a/programs/other/period/trunk/build.bat b/programs/other/period/trunk/build.bat index 9108319564..4222b8e757 100644 --- a/programs/other/period/trunk/build.bat +++ b/programs/other/period/trunk/build.bat @@ -1,2 +1,3 @@ @fasm period.asm period +@kpack period @pause \ No newline at end of file diff --git a/programs/system/icon_new/trunk/build_icon.bat b/programs/system/icon_new/trunk/build_icon.bat index 6331f98afa..2d6e8558cf 100644 --- a/programs/system/icon_new/trunk/build_icon.bat +++ b/programs/system/icon_new/trunk/build_icon.bat @@ -2,4 +2,5 @@ @echo lang fix ru >lang.inc @fasm icon.asm @icon @erase lang.inc +@kpack @icon @pause \ No newline at end of file diff --git a/programs/system/icon_new/trunk/build_iconmngr.bat b/programs/system/icon_new/trunk/build_iconmngr.bat index b3f854f933..4c2116626a 100644 --- a/programs/system/icon_new/trunk/build_iconmngr.bat +++ b/programs/system/icon_new/trunk/build_iconmngr.bat @@ -2,4 +2,5 @@ @echo lang fix ru >lang.inc @fasm iconmngr.asm iconmngr @erase lang.inc +@kpack iconmngr @pause \ No newline at end of file diff --git a/programs/system/panel/trunk/build_ru.bat b/programs/system/panel/trunk/build_ru.bat index d3170f094a..412b60cbd1 100644 --- a/programs/system/panel/trunk/build_ru.bat +++ b/programs/system/panel/trunk/build_ru.bat @@ -2,4 +2,5 @@ @echo lang fix ru >lang.inc @fasm @panel.asm @panel @erase lang.inc +@kpack @panel @pause \ No newline at end of file diff --git a/programs/system/rb/trunk/@RB.ASM b/programs/system/rb/trunk/@RB.ASM index a71f6eeb4c..cbb47bfe57 100644 --- a/programs/system/rb/trunk/@RB.ASM +++ b/programs/system/rb/trunk/@RB.ASM @@ -346,7 +346,7 @@ DATA strtbl startapps ,\ <"/sys/PIC4",0> ,\ <"/sys/DESKTOP",0> ,\ - <"/sys/ICON",0>,\ + <"/sys/ICONMNGR",0>,\ <"/sys/SETUP",0> ,\ <"/sys/VRR",0> ,\ <"/sys/CPU",0>