1,5 → 1,5 |
|
; application : View3ds ver. 0.067 - tiny .3ds and .asc files viewer |
; application : View3ds ver. 0.068 - tiny .3ds and .asc files viewer |
; with a few graphics effects demonstration. |
; compiler : FASM |
; system : KolibriOS |
8,7 → 8,7 |
; web : www.macgub.hekko.pl |
; Fell free to use this intro in your own distribution of KolibriOS. |
; Special greetings to KolibriOS team . |
; I hope because my intros Christian Belive will be near to each of You. |
; I hope because my demos Christian Belive will be near to each of You. |
|
|
; Some adjustments made by Madis Kalme |
57,7 → 57,7 |
; mov eax,14 ; window size according to cur res ... |
; int 0x40 |
; sub eax,150 shl 16 + 150 |
mov eax, 600 shl 16 + 600 ; ... or set manually |
mov eax, 500 shl 16 + 600 ; ... or set manually |
mov [size_y_var],ax |
shr ax,1 |
mov [vect_y],ax |
132,16 → 132,33 |
call calc_bumpmap |
call calc_bumpmap_coords ; bump and texture mapping |
call draw_window |
mov [draw_win_at_first],0 |
|
; mov [draw_win_at_first],0 |
; mov eax,40 ; set events mask |
; mov ebx,1100000000000000000000000100111b |
; int 0x40 |
still: |
cmp [edit_flag],1 |
jne @f |
mov eax,40 ; set events mask |
mov ebx,1100000000000000000000000100111b |
jmp .int |
@@: |
mov eax,40 ; set events mask |
mov ebx,111b |
.int: |
int 0x40 |
|
mov eax,23 ; wait here for event with timeout |
mov eax,23 |
mov ebx,TIMEOUT |
cmp [speed_flag],1 |
jne .skip |
cmp [speed_flag],0 |
je .skip |
mov eax,11 |
.skip: |
cmp [edit_flag],1 |
jne @f |
mov eax,10 |
|
@@: |
int 0x40 |
|
cmp eax,1 ; redraw request ? |
150,7 → 167,16 |
je key |
cmp eax,3 ; button in buffer ? |
je button |
|
cmp eax,6 |
jne @f |
cmp [edit_flag],1 |
jne @f |
mov eax,37 |
mov ebx,3 ;read mouse state |
int 0x40 |
mov [mouse_state],eax |
call edit |
@@: |
jmp noclose |
|
red: ; redraw |
216,7 → 242,7 |
; ah = 5 -> scale- |
cmp ah,5 |
jne @f |
mov [scale],0.7 |
mov dword[scale],0.7 |
fninit |
fld [rsscale] |
fmul [scale] |
225,7 → 251,7 |
@@: |
cmp ah,6 ; ah = 6 -> scale+ |
jne @f |
mov [scale],1.3 |
mov dword[scale],1.3 |
fninit |
fld [rsscale] |
fmul [scale] |
430,6 → 456,8 |
|
noclose: |
|
cmp [edit_flag],1 |
jz .end_rot |
cmp [r_flag],2 |
jne .no_x |
inc [angle_x] |
516,6 → 544,19 |
jmp .blurrr |
@@: |
call draw_triangles ; draw all triangles from the list |
cmp [edit_flag],0 |
jz .no_edit |
call clear_vertices_index |
call draw_handlers |
; call edit |
|
|
|
|
|
|
.no_edit: |
|
.blurrr: |
cmp [sinus_flag],0 |
je @f |
652,76 → 693,8 |
jnc .oop1 |
end if |
.no_dec_bright: |
;======================================commmented==================== |
if 0 |
if Ext >= SSE |
cmp [max_flag],0 |
je .no_max |
;movzx ebx,[max_flag] |
.again_max: |
; push ecx |
mov edi,screen |
mov ecx,SIZE_X*3/4 |
; ; pxor mm5,mm5 |
xor eax,eax |
rep stosd |
|
mov ecx,(SIZE_X*(SIZE_Y-3))*3/8 |
.calc_max: |
@@: |
movq mm0,[edi+SIZE_X*3] |
movq mm1,[edi-SIZE_X*3] |
movq mm2,[edi-3] |
movq mm3,[edi+3] |
|
pmaxub mm0,mm1 |
pmaxub mm2,mm3 |
pmaxub mm0,mm2 |
|
movq [edi],mm0 |
add edi,8 |
loop @b |
|
xor eax,eax |
mov ecx,SIZE_X*3/4 |
rep stosd |
end if |
|
.no_max: |
|
if Ext >= SSE |
cmp [min_flag],0 |
je .no_min |
; push ecx |
mov edi,screen |
mov ecx,SIZE_X*3/4 |
; ; pxor mm5,mm5 |
xor eax,eax |
rep stosd |
|
mov ecx,(SIZE_X*(SIZE_Y-3))*3/8 |
@@: |
movq mm0,[edi+SIZE_X*3] |
movq mm1,[edi-SIZE_X*3] |
movq mm2,[edi-3] |
movq mm3,[edi+3] |
|
pminub mm0,mm1 |
pminub mm2,mm3 |
pminub mm0,mm2 |
|
movq [edi],mm0 |
add edi,8 |
loop @b |
|
xor eax,eax |
|
mov ecx,SIZE_X*3/4 |
rep stosd |
end if |
.no_min: |
end if |
|
RDTSC |
sub eax,[esp] |
sub eax,41 |
741,7 → 714,7 |
mov ebx,[screen_ptr] |
mov ecx,[size_y_var] |
; mov ecx,SIZE_X shl 16 + SIZE_Y |
mov edx,5 shl 16 + 25 |
mov edx,[offset_y] ;5 shl 16 + 25 |
int 0x40 |
|
mov eax,13 |
792,10 → 765,184 |
include "GRD_TEX.INC" |
include "TWO_TEX.INC" |
include "ASC.INC" |
clear_vertices_index: |
mov edi,[vertices_index_ptr] |
movzx eax,word[size_x_var] |
movzx ecx,word[size_y_var] |
imul ecx,eax |
xor eax,eax |
shr ecx,1 |
rep stosd |
ret |
edit: ; mmx required, edit mesh by vertex |
push ebp |
mov ebp,esp |
sub esp,128 |
|
.y_coord equ ebp-2 |
.x_coord equ ebp-4 |
.points_translated equ ebp-10 |
.points equ ebp-22 |
.points_rotated equ ebp-34 |
.mx equ ebp-70 |
|
macro check_bar |
{ |
movzx ebx,word[.x_coord] |
movzx ecx,word[.y_coord] |
movzx edx,word[size_x_var] |
imul edx,ecx |
add ebx,edx |
|
lea ecx,[ebx*2] |
lea ebx,[ebx*3] |
add ebx,[screen_ptr] |
mov ebx,[ebx] |
and ebx,0x00ffffff |
cmp ebx,0x00ff0000 ; is handle bar ? |
} |
|
emms |
mov eax,37 ; get mouse state |
mov ebx,1 ; x = 5, y = 25 - offsets |
int 0x40 |
|
mov ebx,[offset_y] ;5 shl 16 + 25 |
movd mm0,ebx |
movd mm1,eax |
movd mm3,[size_y_var] |
pcmpgtw mm0,mm1 |
pcmpgtw mm3,mm1 |
pxor mm3,mm0 |
movd eax,mm3 |
mov cx,ax |
shr eax,16 |
and ax,cx |
or ax,ax |
jz .no_edit |
|
|
movd mm0,ebx |
psubw mm1,mm0 |
movd eax,mm1 |
|
; store both x and y coordinates |
ror eax,16 |
; push eax |
; sub esp,256 |
mov [.x_coord],eax |
test word[mouse_state],100000000b |
jz .not_press ; check if left mouse button press |
|
; left button pressed |
|
; macro check_bar |
; { |
; movzx ebx,word[.x_coord] |
; movzx ecx,word[.y_coord] |
; imul ebx,ecx |
; lea ecx,[ebx*2] |
; lea ebx,[ebx*3] |
; add ebx,[screen_ptr] |
; mov ebx,[ebx] |
; and ebx,0x00ffffff |
; cmp ebx,0x00ff0000 ; is handle bar ? |
; } |
|
check_bar |
jne .no_edit |
add ecx,[vertices_index_ptr] |
mov cx,word[ecx] |
inc cx |
|
|
mov [vertex_edit_no],cx ;if vert_edit_no = 0, no vertex selected |
|
mov eax,dword[.x_coord] |
mov dword[edit_end_x],eax |
mov dword[edit_start_x],eax |
jmp .end |
.not_press: |
test byte[mouse_state],1b ; check if left button is held |
jz .not_held |
; check_bar |
; jne .no_edit |
; add ecx,[vertices_index_ptr] |
; mov cx,[ecx] |
; inc cx |
cmp [vertex_edit_no],0 ; cx ; vertex number |
je .end |
push dword[.x_coord] |
pop dword[edit_end_x] |
jmp .end |
.not_held: |
shr [mouse_state],16 |
test byte[mouse_state],1b ; test if left button released |
jz .end |
check_bar |
jne .end |
|
movzx esi,[vertex_edit_no] |
dec esi |
lea esi,[esi*3] |
add esi,esi |
add esi,[points_translated_ptr] |
emms |
|
movd mm1,dword[esi] |
paddw mm1,mm0 |
psubw mm1,qword[vect_x] |
movd dword[esi],mm1 |
|
lea edi,[.points] |
; detranslate |
fninit |
fild word[esi+4] |
fstp dword[edi+8] |
fild word[esi+2] |
fisub word[offset_x] |
fstp dword[edi+4] |
fild word[esi] |
fisub word[offset_y] ; proteza |
fstp dword[edi] |
|
mov esi,matrix |
lea edi,[.mx] |
call reverse_mx_3x3 |
|
lea esi,[.points] |
lea edi,[.points_rotated] |
lea ebx,[.mx] |
mov ecx,1 |
call rotary |
|
; inject into vertex list |
movzx edi,[vertex_edit_no] |
dec edi |
lea edi,[edi*3] |
shl edi,2 |
add edi,[points_ptr] |
lea esi,[.points_rotated] |
mov ecx,3 |
cld |
rep movsd |
|
|
mov dword[edit_end_x],0 |
mov [vertex_edit_no],0 |
|
.no_edit: |
.end: |
mov esp,ebp |
pop ebp |
ret |
|
alloc_buffer_mem: |
push ebp |
mov ebp,esp |
.temp equ ebp-4 |
push dword 0 |
|
mov eax, 68 |
mov ebx, 11 |
int 0x40 ; -> create heap, to be sure |
804,31 → 951,43 |
movzx ecx,word[size_x_var] |
movzx eax,word[size_y_var] |
mul ecx |
; add eax,100 |
push eax |
|
mov [.temp],eax |
lea ecx,[eax*3] |
add ecx,256 |
mov eax,68 |
mov ebx,20 |
mov edx,[screen_ptr] |
cmp [draw_win_at_first],1 |
jne @f |
xor edx,edx |
@@: |
int 0x40 |
; and eax,0xfffffff0 |
mov [screen_ptr],eax |
|
pop ecx |
mov ecx,[.temp] |
shl ecx,2 |
add ecx,256 |
mov eax,68 |
mov ebx,20 |
mov edx,[Zbuffer_ptr] |
cmp [draw_win_at_first],1 |
jne @f |
xor edx,edx |
@@: |
int 0x40 |
; and eax,0xfffffff0 |
mov [Zbuffer_ptr],eax |
|
|
mov ecx,[.temp] |
add ecx,ecx |
add ecx,256 |
mov eax,68 |
mov ebx,20 |
mov edx,[vertices_index_ptr] |
int 0x40 |
; and eax,0xfffffff0 |
mov [vertices_index_ptr],eax |
|
mov esp,ebp |
pop ebp |
|
|
|
if 0 |
;old Menuet style alloc |
movzx ecx,word[size_x_var] |
1757,6 → 1916,25 |
|
|
draw_triangles: |
|
emms |
; update translated list MMX required |
cmp [vertex_edit_no],0 |
je @f |
movzx eax,[vertex_edit_no] |
dec eax |
movd mm0,[edit_end_x] |
psubw mm0,[edit_start_x] |
lea eax,[eax*3] |
add eax,eax |
add eax,[points_translated_ptr] |
movd mm1,dword[eax] |
paddw mm1,mm0 |
movd dword[eax],mm1 |
@@: |
|
|
|
mov esi,[triangles_ptr] |
mov [edges_counter],0 |
.again_dts: |
1769,6 → 1947,10 |
push ebp |
add ebp,eax |
mov eax,[ebp] |
cmp [vertex_edit_no],0 |
jne @f |
|
@@: |
mov dword[xx1],eax |
mov eax,[ebp+4] |
mov [zz1],ax |
1823,6 → 2005,44 |
movq qword[xx3],mm2 |
; emms |
end if ; ********************************* |
if 0 |
cmp [vertex_edit_no],0 |
jne .no_edit |
mov ax,[vertex_edit_no] |
dec ax |
cmp ax,[point_index1] |
jne @f |
movd mm0,[edit_start_x] |
psubw mm0,[edit_end_x] |
movd mm1,dword[xx1] |
paddw mm1,mm0 |
movd dword[xx1],mm1 |
jmp .no_edit |
@@: |
|
cmp ax,[point_index2] |
jne @f |
movd mm0,[edit_start_x] |
psubw mm0,[edit_end_x] |
movd mm1,dword[xx2] |
paddw mm1,mm0 |
movd dword[xx2],mm1 |
jmp .no_edit |
@@: |
|
cmp ax,[point_index3] |
jne @f |
movd mm0,[edit_start_x] |
psubw mm0,[edit_end_x] |
movd mm1,dword[xx3] |
paddw mm1,mm0 |
movd dword[xx3],mm1 |
jmp .no_edit |
@@: |
|
|
.no_edit: |
end if |
push esi ; |
fninit ; DO culling AT FIRST |
cmp [culling_flag],1 ; (if culling_flag = 1) |
2705,6 → 2925,111 |
ret |
|
|
|
|
|
|
|
draw_handlers: |
|
push ebp |
mov ebp,esp |
|
.counter equ ebp-16 |
.xres3m18 equ ebp-8 |
.xres2m12 equ ebp-12 |
|
|
; init counter |
sub esp,12 |
push dword 0 |
|
movzx eax,word[size_x_var] |
lea ebx,[eax*3] |
sub ebx,18 |
add eax,eax |
sub eax,12 |
mov [.xres3m18],ebx |
mov [.xres2m12],eax |
|
mov esi,[points_translated_ptr] |
.loop: |
push esi |
; DO culling AT FIRST |
cmp [culling_flag],1 ; (if culling_flag = 1) |
jne .no_culling |
mov edi,[.counter] ; ********************************* |
lea edi,[edi*3] |
shl edi,2 |
add edi,[points_normals_rot_ptr] |
mov eax,[edi+8] ; check sign of z coof |
shr eax,31 |
cmp eax,1 |
jnz .skip |
.no_culling: |
mov eax,[esi] |
movzx ebx,ax ; ebx - x |
shr eax,16 ; eax - y |
cmp eax,4 ; check if markers not exceedes screen |
jle .skip |
cmp ebx,4 |
jle .skip |
movzx edx,word[size_x_var] |
sub edx,4 |
movzx ecx,word[size_y_var] |
sub ecx,4 |
cmp ebx,edx |
jge .skip |
cmp eax,ecx |
jge .skip |
|
movzx edx,word[size_x_var] |
; sub ebx,3 |
; sub eax,3 |
imul eax,edx |
add eax,ebx |
lea edi,[eax*3] |
lea eax,[eax*2] |
; draw bar 6x6 |
add edi,[screen_ptr] |
add eax,dword[vertices_index_ptr] |
|
|
|
|
mov edx,[.counter] |
mov ecx,6 |
|
.oop: |
push ecx |
mov ecx,6 |
|
@@: |
mov word[edi],0x0000 ;ax |
mov byte[edi+2],0xff ;al |
mov word[eax],dx |
add eax,2 |
add edi,3 |
loop @b |
add edi,[.xres3m18] |
add eax,[.xres2m12] |
pop ecx |
loop .oop |
|
.skip: |
pop esi |
add esi,6 |
inc dword[.counter] |
mov ecx,[.counter] |
cmp cx,[points_count_var] |
jng .loop |
|
mov esp,ebp |
pop ebp |
|
ret |
|
|
fill_Z_buffer: |
mov eax,0x70000000 |
mov edi,[Zbuffer_ptr] |
2900,11 → 3225,11 |
@@: |
push edi |
mov edi,[points_ptr] |
push dword[esi+0] |
pop dword[edi+ebx*2+0] |
push dword[esi+4] |
pop dword[edi+ebx*2+0] |
pop dword[edi+ebx*2+4] |
push dword[esi+8] |
pop dword[edi+ebx*2+4] |
push dword[esi+0] |
pop dword[edi+ebx*2+8] |
pop edi |
; fld dword[esi+4] |
3001,6 → 3326,13 |
int 0x40 ; -> allocate memory for triangles normals |
mov [triangles_normals_ptr], eax ; -> eax = pointer to allocated mem |
|
; mov eax, 68 |
; movzx ecx,[points_count_var] |
; lea ecx,[2+ecx*2] |
; mov edx,dword [vertices_index_ptr] |
; int 0x40 |
; mov dword[vertices_index_ptr], eax |
|
mov eax, 68 |
movzx ecx, [points_count_var] |
lea ecx,[3+ecx*3] |
3008,7 → 3340,12 |
mov edx,[points_normals_ptr] |
int 0x40 |
mov [points_normals_ptr], eax |
; int3 |
|
|
; int3 |
|
|
mov eax, 68 |
; mov ebx, 12 |
movzx ecx, [points_count_var] |
3067,7 → 3404,6 |
int 0x40 ; -> read file |
|
mov [fsize],ebx |
|
cmp eax,6 |
jnz @f |
xor eax,eax ;;;;--- |
3081,6 → 3417,9 |
shr eax,9 |
inc eax |
mov [fsize],eax |
|
|
|
; mov ecx,ebx |
; add ecx,MEM_END |
; mov ebx,1 |
3192,7 → 3531,7 |
|
call buttons ; more buttons |
|
.Y_ADD equ 1 ;-> offset of 'add vector' buttons |
.Y_ADD equ 2 ;-> offset of 'add vector' buttons |
|
; ADD VECTOR LABEL ; add vector buttons - 30 ++ |
mov eax,4 ; function 4 : write text to window |