Subversion Repositories Kolibri OS

Compare Revisions

Ignore whitespace Rev 6648 → Rev 6769

/programs/demos/3DS/3DMATH.INC
28,6 → 28,137
 
ret
end if
reverse_mx_3x3:
; esi - source matrix
; edi - desired reversed matrix
 
push ebp
mov ebp,esp
sub esp,4
.det equ ebp-4
 
fninit
fld dword[esi]
fmul dword[esi+16]
fmul dword[esi+32]
fld dword[esi+12]
fmul dword[esi+28]
fmul dword[esi+8]
faddp
fld dword[esi+24]
fmul dword[esi+4]
fmul dword[esi+20]
faddp
fld dword[esi]
fmul dword[esi+28]
fmul dword[esi+20]
fchs
faddp
fld dword[esi+24]
fmul dword[esi+16]
fmul dword[esi+8]
fchs
faddp
fld dword[esi+12]
fmul dword[esi+4]
fmul dword[esi+32]
fchs
faddp
fstp dword[.det]
cmp dword[.det],0
jne @f
int3
@@:
; fld1
; fdiv dword[.det]
; fstp dword[.det]
 
fld dword[esi+16]
fmul dword[esi+32]
fld dword[esi+20]
fmul dword[esi+28]
fchs
faddp
fdiv dword[.det]
fstp dword[edi]
 
fld dword[esi+8]
fmul dword[esi+28]
fld dword[esi+4]
fmul dword[esi+32]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+4]
 
fld dword[esi+4]
fmul dword[esi+20]
fld dword[esi+8]
fmul dword[esi+16]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+8]
 
fld dword[esi+20]
fmul dword[esi+24]
fld dword[esi+12]
fmul dword[esi+32]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+12]
 
fld dword[esi]
fmul dword[esi+32]
fld dword[esi+8]
fmul dword[esi+24]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+16]
 
fld dword[esi+8]
fmul dword[esi+12]
fld dword[esi]
fmul dword[esi+20]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+20]
 
fld dword[esi+12]
fmul dword[esi+28]
fld dword[esi+16]
fmul dword[esi+24]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+24]
 
fld dword[esi+4]
fmul dword[esi+24]
fld dword[esi]
fmul dword[esi+28]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+28]
 
fld dword[esi]
fmul dword[esi+16]
fld dword[esi+4]
fmul dword[esi+12]
fchs
faddp
fdiv dword[.det]
fstp dword[edi+32]
 
 
mov esp,ebp
pop ebp
ret
 
make_vector_r:
fninit
fld dword[edi] ;edi+x3d
211,7 → 342,7
faddp
fstp dword[edi+24]
 
fld .siny
fld .cosy
fmul .sinz
fstp dword[edi+4]
 
377,6 → 508,7
translate_points: ; just convert into integer; z coord still needed
fninit
.again:
if 0
fld dword[esi+8]
; fmul [rsscale]
fist word[edi+4]
403,7 → 535,19
fiadd [yobs]
fiadd [vect_y]
fistp word[edi+2]
 
end if
; movups xmm0,[esi]
; cvtps2dq xmm0,xmm0
; packsdw xmm0,xmm0
; movq [edi]
fld dword[esi]
fiadd [vect_x]
fistp word[edi]
fld dword[esi+4]
fiadd [vect_y]
fistp word[edi+2]
fld dword[esi+8]
fistp word[edi+4]
add esi,12
add edi,6
dec ecx
/programs/demos/3DS/A_PROCS.INC
176,9 → 176,9
punpcklbw xmm3,xmm0
punpcklbw xmm4,xmm0
psubsw xmm1,xmm2
paddw xmm1,[.bias]
paddw xmm1,[emboss_bias]
psubsw xmm3,xmm4
paddw xmm3,[.bias]
paddw xmm3,[emboss_bias]
pmulhw xmm1,xmm3
movaps xmm7,xmm1
movaps xmm6,xmm1
228,9 → 228,9
end if
ret
 
align 16
.bias:
dw 128, 128, 128, 128, 128, 128, 128, 128
;align 16
; emboss_bias:
; dw 128, 128, 128, 128, 128, 128, 128, 128
 
if 0 ; old emb proc
 
/programs/demos/3DS/DATA.INC
11,7 → 11,7
tex_y_div2 dw TEX_Y / 2
xobs dw 0 ;SIZE_X / 2 ;200 ;observer = camera
yobs dw 0 ;SIZE_Y / 2 ;200 ;coordinates
zobs dw -500
zobs dw -1000
; size_x dw SIZE_X
; size_y dw SIZE_Y
 
38,8 → 38,32
XYZpartices:
db 'X','Y','Z'
i10 dw 10
draw_win_at_first db 1
offset_y:
i25 dw 25 ; screen buff offset
offset_x:
i5 dw 5
triangles_ptr dd 0
triangles_w_z_ptr dd 0
triangles_normals_ptr dd 0
points_normals_ptr dd 0
points_normals_rot_ptr dd 0
points_ptr dd 0
points_rotated_ptr dd 0
points_translated_ptr dd 0
screen_ptr dd 0
Zbuffer_ptr dd 0
vertices_index_ptr dd 0
 
 
; draw_win_at_first db 1
vertex_edit_no dw 0
edit_start_x:
dw 0
edit_start_y dw 0
edit_end_x:
dw 0
edit_end_y dw 0
mouse_state dd 0
menu:
db 2 ; button number = index
db 'rotary ' ; label
179,6 → 203,12
sinus_flag db 0
dd onoff_f
 
 
db 25
db 'editor '
db 2
edit_flag db 0
dd onoff_f
; db 24
; db 'max '
; db 2
314,7 → 344,7
if Ext=SSE2
db ' (SSE2)'
end if
db ' 0.067',0
db ' 0.068',0
labellen:
STRdata db '-1 '
 
343,7 → 373,7
db '/rd/1/teapot.3ds',0
end if
 
I_END:
;I_END:
 
rb 256
 
390,7 → 420,11
;===============================================
 
lightsend:
align 16
emboss_bias:
dw 128, 128, 128, 128, 128, 128, 128, 128
 
I_END:
if USE_LFN = 0
hash_table rb 4096
SourceFile:
425,16 → 459,20
;==
triangles_count_var dw ?
points_count_var dw ?
triangles_ptr dd ?
triangles_w_z_ptr dd ?
triangles_normals_ptr dd ?
points_normals_ptr dd ?
points_normals_rot_ptr dd ?
points_ptr dd ?
points_rotated_ptr dd ?
points_translated_ptr dd ?
screen_ptr dd ?
Zbuffer_ptr dd ?
; triangles_ptr dd ?
; triangles_w_z_ptr dd ?
; triangles_normals_ptr dd ?
; points_normals_ptr dd ?
; points_normals_rot_ptr dd ?
; points_ptr dd ?
; points_rotated_ptr dd ?
; points_translated_ptr dd ?
; screen_ptr dd ?
; Zbuffer_ptr dd ?
; vertices_index_ptr dd ?
; edit_start_x:
dw ? ; don't change order
; edit_start_y dw ?
; edges_ptr dd ?
size_y_var:
dw ?
535,4 → 573,4
I_Param rb 256
memStack rb 4000 ;memory area for stack
align 16
screen:
screen:
/programs/demos/3DS/GRD_LINE.INC
77,7 → 77,7
macro .draw_pixel
{
mov [esi],ebx ; actualize Z buffer
if Ext=SSE2
if Ext>=SSE2
movaps xmm7,xmm1 ;[.cb] ;;xmm1
shufps xmm7,xmm7,00111001b
psrld xmm7,ROUND
136,8 → 136,10
jne .end_line
movzx edx,word [size_x_var]
mov [.xres],edx
dec edx
movzx ecx,word [size_y_var]
mov [.yres],ecx
dec ecx
cmp word[.x1],dx ;SIZE_X
jg .end_line
cmp word[.x2],dx ;SIZE_X
209,7 → 211,7
 
call .calc_delta
 
movzx eax,word [size_x_var] ;SIZE_X
mov eax,[.xres] ;SIZE_X
movsx ebx,word[.y1]
mul ebx
add esi,eax
275,7 → 277,7
 
call .calc_delta
 
movzx eax,word[size_x_var] ;SIZE_X
mov eax,[.xres] ;SIZE_X
movsx ebx,word[.y1]
mul ebx
add esi,eax
/programs/demos/3DS/History.txt
1,5 → 1,8
View3ds 0.067 - XI 2016
1. Sizable app window.
-----------------------------------------------------------------------------------
 
View 3ds 0,066 - X 2016
View3ds 0,066 - X 2016
1. App window size according to current screen resolution.
2. New emboss procedure.
-----------------------------------------------------------------------------------
/programs/demos/3DS/README.TXT
1,26 → 1,26
View3ds 0.067 - tiny viewer to .3ds and .asc files with several graphics
View3ds 0.068 - tiny viewer to .3ds and .asc files with several graphics
effects implementation.
 
 
What's new?
1. Sizable app window.
1. Editing option - new 'editor' button.
2. For now I disable perspective correction, to make implemtation of editing option easier.
 
 
Buttons description:
1. rotary: choosing rotary axle: x, y, x+y.
2. shd. model: choosing shading model: flat, grd (smooth), env (spherical
environment mapping, bump (bump mapping), tex (texture mapping),
pos (position shading depend), dots (app draws only points - nodes of object),
txgrd (texture mapping + smooth shading), 2tex (texture mapping + spherical
environment mapping), bmap (bump + texture mapping), cenv (cubic environment
mapping), grdl (Gouraud lines - edges only).
3. speed: idle, full.
1. rotary: choosing rotary axle: x, y, x+y.
2. shd. model: choosing shading model: flat, grd (smooth), env (spherical
environment mapping, bump (bump mapping), tex (texture mapping),
pos (position shading depend), dots (app draws only points - nodes of object),
txgrd (texture mapping + smooth shading), 2tex (texture mapping + spherical
environment mapping), bmap (bump + texture mapping), cenv (cubic environment
mapping), grdl (Gouraud lines - edges only).
3. speed: idle, full.
4,5. zoom in, out: no comment.
6. catmull: on -> use z buffer ( z coordinate interpolation), off -> depth sorting, painters
alghoritm).Txgrd, 2tex and bumptex models only with catmull = on.
7. culling: backface culling on/ off.
8. rand. light: Randomize 3 unlinear lights( so called Phong's illumination).
9. Blur: blur N times; N=0,1,2,3,4,5
6. catmull: on -> use z buffer ( z coordinate interpolation), off -> depth sorting, painters
alghoritm).Txgrd, 2tex and bumptex models only with catmull = on.
7. culling: backface culling on/ off.
8. rand. light: Randomize 3 unlinear lights( so called Phong's illumination).
9. Blur: blur N times; N=0,1,2,3,4,5
10.11,12,13. loseless operations (rotary 90, 180 degrees).
12. emboss: Do emboss effect( flat bumps ), use 'bumps deep' button to do edges more deep.
13. fire: do motion blur ( looks like fire ).
34,5 → 34,9
19. bright + -> increase picture brightness.
20. bright - -> decrease picture brightness.
21. wav effect -> do effect based sine function.
22. editor -> setting editing option. If is "on" then red bars are draw according to each vertex, Pressing
and moving left mouse button (cursor must be on handler)- change vertex position. If left mouse button
is released apply current position. You may also decrease whole handlers count by enable culling (using
appropriate button) - some back handlers become hidden.
 
Maciej Guba XI 2016
/programs/demos/3DS/TWO_TEX.INC
788,7 → 788,9
mov ecx,.y
or ecx,ecx
jl .bl_end
cmp cx,word[size_y_var] ;SIZE_Y
mov dx,word[size_y_var]
dec dx
cmp cx,dx ;word[size_y_var] ;SIZE_Y
jge .bl_end
 
cmp eax,ebx
827,6 → 829,7
push eax ebx ;store x1, x2
mov ebx,.x1
movzx edx,word[size_x_var]
dec edx
cmp ebx,edx
; cmp bx,word[size_x_var] ;SIZE_X
jg .bl_end
836,7 → 839,7
mov ebx,.x2
sub ebx,.x1
 
if Ext>=SSE
if Ext >= SSE
 
sub esp,16
cvtsi2ss xmm3,ebx ;rcps
/programs/demos/3DS/VIEW3DS.ASM
1,14 → 1,14
 
; application : View3ds ver. 0.067 - tiny .3ds and .asc files viewer
; with a few graphics effects demonstration.
; application : View3ds ver. 0.068 - tiny .3ds and .asc files viewer
; with a few graphics effects demonstration.
; compiler : FASM
; system : KolibriOS
; author : Macgub aka Maciej Guba
; email : macgub3@wp.pl
; web : www.macgub.hekko.pl
; 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
20,19 → 20,19
 
 
SIZE_X equ 512
SIZE_Y equ 512 ; ///// I want definitely
TIMEOUT equ 10 ; ------ say:
ROUND equ 10 ; \ @ @/ keep smiling every
TEX_X equ 512 ; texture width ; \ ./ / day.
TEX_Y equ 512 ; height ; \/ /
TEX_SHIFT equ 9 ; texture width shifting ; __||__ /
TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 ; /| |
TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} ; / \ /
FLUENTLY = 0 ; / | |
SHIFTING = 1 ; ------
CATMULL_SHIFT equ 8 ; | |
LIGHT_SIZE equ 22 ; | |
NON = 0 ; -/ \-
SIZE_Y equ 512 ; ///// I want definitely
TIMEOUT equ 10 ; ------ say:
ROUND equ 10 ; \ @ @/ keep smiling every
TEX_X equ 512 ; texture width ; \ ./ / day.
TEX_Y equ 512 ; height ; \/ /
TEX_SHIFT equ 9 ; texture width shifting ; __||__ /
TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1 ; /| |
TEX equ SHIFTING ; TEX={SHIFTING | FLUENTLY} ; / \ /
FLUENTLY = 0 ; / | |
SHIFTING = 1 ; ------
CATMULL_SHIFT equ 8 ; | |
LIGHT_SIZE equ 22 ; | |
NON = 0 ; -/ \-
MMX = 1
SSE = 2
SSE2 = 3
54,10 → 54,10
 
START: ; start of execution
cld
; 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,14 ; window size according to cur res ...
; int 0x40
; sub eax,150 shl 16 + 150
mov eax, 500 shl 16 + 600 ; ... or set manually
mov [size_y_var],ax
shr ax,1
mov [vect_y],ax
115,7 → 115,7
.opt:
 
 
; call alloc_buffer_mem ; alloc memfor screnn and z buffer
; call alloc_buffer_mem ; alloc memfor screnn and z buffer
 
call optimize_object1 ; proc in file b_procs.asm
; set point(0,0,0) in center and calc all coords
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:
.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
203,9 → 229,9
jne .next_m6
cmp [dr_flag],2
jne @f
; call init_envmap2 ; <----! this don't works in env mode
; and more than ~18 kb objects
; call init_envmap_cub2
; call init_envmap2 ; <----! this don't works in env mode
; and more than ~18 kb objects
; call init_envmap_cub2
@@:
cmp [dr_flag],4
jne @f
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]
232,19 → 258,19
fstp [rsscale]
 
@@:
cmp ah,9 ; lights random ; 'flat' 0
cmp ah,9 ; lights random ; 'flat' 0
jne .next_m5 ; 'grd ' 1
call make_random_lights ; 'env ' 2
call normalize_all_light_vectors ; 'bump' 3
call do_color_buffer ; intit color_map ; 'tex ' 4
; cmp [emboss_flag],1 ; 'pos ' 5
; je @f ; 'dots' 6
; cmp [dr_flag],8
; jge @f
; cmp [dr_flag],2 ; 'txgr' 7
; jl .next_m5 ; '2tex' 8
; cmp [dr_flag],3 ; 'btex' 9
; jg .next_m5
call do_color_buffer ; intit color_map ; 'tex ' 4
; cmp [emboss_flag],1 ; 'pos ' 5
; je @f ; 'dots' 6
; cmp [dr_flag],8
; jge @f
; cmp [dr_flag],2 ; 'txgr' 7
; jl .next_m5 ; '2tex' 8
; cmp [dr_flag],3 ; 'btex' 9
; jg .next_m5
; @@:
call init_envmap2 ; update env map if shading model = environment or bump
.next_m5:
266,15 → 292,15
cmp [emboss_flag],1
call init_envmap2
@@:
; cmp ah,17
; jne .next_m
; cmp [move_flag],2
; jne @f
; call draw_window ; redraw other labels to navigation buttons
; cmp ah,17
; jne .next_m
; cmp [move_flag],2
; jne @f
; call draw_window ; redraw other labels to navigation buttons
; @@:
; cmp [move_flag],0
; jne .next_m
; call draw_window ; redraw other labels to navigation buttons
; cmp [move_flag],0
; jne .next_m
; call draw_window ; redraw other labels to navigation buttons
.next_m:
cmp ah,18
jne .next_m2
329,8 → 355,8
jne .next
cmp [move_flag],0
jne @f
; cmp [move_flag],2
; je .set_light1
; cmp [move_flag],2
; je .set_light1
sub [vect_y],10
jmp .next
@@:
341,19 → 367,19
@@:
sub [sin_amplitude],10
;--------------------------------------------------
; .set_light1: ; r -
; movzx ebx,[light_no_flag] ; * 22
; mov ecx,ebx
; shl ebx,4
; shl ecx,1
; add ebx,ecx
; shl ecx,1
; add ebx,ecx
; add ebx,lights+6 ; 6 -> light vector size
; .set_light1: ; r -
; movzx ebx,[light_no_flag] ; * 22
; mov ecx,ebx
; shl ebx,4
; shl ecx,1
; add ebx,ecx
; shl ecx,1
; add ebx,ecx
; add ebx,lights+6 ; 6 -> light vector size
;
; movzx ecx,[light_comp_flag]
; lea ecx,[ecx*3}
; add ebx,ecx ; ebx -> color to set
; movzx ecx,[light_comp_flag]
; lea ecx,[ecx*3}
; add ebx,ecx ; ebx -> color to set
 
;---------------------------------------------------
.next:
414,7 → 440,7
jne .next5
cmp [move_flag],0
jne @f
; call add_vector
; call add_vector
add [vect_y],10
jmp .next5
@@:
430,6 → 456,8
 
noclose:
 
cmp [edit_flag],1
jz .end_rot
cmp [r_flag],2
jne .no_x
inc [angle_x]
487,9 → 515,9
movzx ecx,[points_count_var]
call translate_points
 
; cmp [dr_flag],5
; jne @f
; call calc_attenuation_light
; cmp [dr_flag],5
; jne @f
; call calc_attenuation_light
; @@:
cmp [fire_flag],0
jne @f
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]
843,7 → 1002,7
add ecx,eax
add ecx,MEM_END
mov ebx,1
mov eax,64 ; allocate mem - resize app mem
mov eax,64 ; allocate mem - resize app mem
int 0x40
mov [screen_ptr],MEM_END
mov [Zbuffer_ptr],MEM_END
854,7 → 1013,7
 
update_flags:
; updates flags and writing flag description
; in ah - button number
; in ah - button number
push ax
mov edi,menu
.ch_another:
874,7 → 1033,7
jne .ch_another
.write:
; clreol {pascal never dies}
; * eax = 13 - function number
; * eax = 13 - function number
; * ebx = [coordinate on axis x]*65536 + [size on axis x]
; * ecx = [coordinate on axis y]*65536 + [size on axis y]
; * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill
916,7 → 1075,7
normalize_all_light_vectors:
mov edi,lights
@@:
call normalize_vector ; 3dmath.inc
call normalize_vector ; 3dmath.inc
add edi,LIGHT_SIZE
cmp edi,lightsend ;ecx
jl @b
924,14 → 1083,14
 
calc_bumpmap_coords: ; map texture, bump
;macro .comment222
; ; planar mapping
; mov esi,points
; mov edi,tex_points
; ; planar mapping
; mov esi,points
; mov edi,tex_points
; @@:
; add esi,2
; movsd
; cmp dword[esi],dword -1
; jne @b
; add esi,2
; movsd
; cmp dword[esi],dword -1
; jne @b
 
; .Pi2 equ dword[ebp-4]
 
945,8 → 1104,8
mov edi,tex_points
movzx ecx,[points_count_var]
inc ecx
; cmp [map_tex_flag],1
; jne .cylindric
; cmp [map_tex_flag],1
; jne .cylindric
; spherical mapping around y axle
 
@@:
953,7 → 1112,7
fld dword[esi] ; x coord
fld dword[esi+8] ; z coord
fpatan ; arctg(st1/st)
; fdiv .Pi2
; fdiv .Pi2
fdiv st0,st1
fimul [tex_x_div2]
fiadd [tex_x_div2]
980,26 → 1139,26
add edi,4
loop @b
ffree st0
; jmp .end_map
; jmp .end_map
; .cylindric:
; fld dword[esi] ; around y axle
; fld dword[esi+8]
; fpatan
; fdiv st0,st1
; fimul [tex_x_div2]
; fiadd [tex_x_div2]
; fistp word[edi]
; fld dword[esi] ; around y axle
; fld dword[esi+8]
; fpatan
; fdiv st0,st1
; fimul [tex_x_div2]
; fiadd [tex_x_div2]
; fistp word[edi]
 
; fld dword[esi+4]
; fimul [tex_y_div2]
; fiadd [tex_y_div2]
; fistp word[edi+2]
; fld dword[esi+4]
; fimul [tex_y_div2]
; fiadd [tex_y_div2]
; fistp word[edi+2]
 
; add esi,12
; add edi,4
; loop .cylindric
; ffree st0
;; mov esp,ebp
; add esi,12
; add edi,4
; loop .cylindric
; ffree st0
;; mov esp,ebp
; .end_map:
ret
 
1019,9 → 1178,9
mov edi,envmap
fninit
 
mov dx,- TEX_Y / 2 ;256 ; dx - vertical coordinate = y
mov dx,- TEX_Y / 2 ;256 ; dx - vertical coordinate = y
.ie_ver:
mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x
mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x
.ie_hor:
xor ebx,ebx
mov dword .col_b, 0
1093,8 → 1252,8
mov al,byte[esi+15] ; r
push ax
push eax ; earlier - dot pr
; fstp .dot_product
; push .dot_product
; fstp .dot_product
; push .dot_product
call calc_one_col
pop ebp
; eax-0x00rrggbb
1135,7 → 1294,7
 
 
do_color_buffer: ; do color buffer for Gouraud, flat shading
;env_map 512 x 512 x 3 bytes ; many lights using
;env_map 512 x 512 x 3 bytes ; many lights using
.temp equ word [ebp-2]
.nz equ dword [ebp-6] ; dword
.ny equ dword [ebp-10]
1150,9 → 1309,9
mov edi,color_map
fninit
 
mov dx,- TEX_Y / 2 ;-256 ; dx - vertical coordinate = y
mov dx,- TEX_Y / 2 ;-256 ; dx - vertical coordinate = y
.ie_ver:
mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x
mov cx,- TEX_X / 2 ;256 ; cx - horizontal coord = x
.ie_hor:
mov .temp,cx
fild .temp
1217,8 → 1376,8
mov al,byte[esi+15] ; r
push ax
push eax ; earlier - dot pr
; fstp .dot_product
; push .dot_product
; fstp .dot_product
; push .dot_product
call calc_one_col
pop ebp
; eax-0x00rrggbb
1317,7 → 1476,7
push esi
mov esi,ecx
lea esi,[esi*3]
; lea esi,[triangles_normals+esi*4]
; lea esi,[triangles_normals+esi*4]
shl esi,2
add esi,[triangles_normals_ptr]
 
1371,7 → 1530,7
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
; lea esi,[points+esi*2] ; esi - pointer to 1st 3d point
shl esi,2
add esi,[points_ptr]
movzx edi,word[ebp+2] ; first point index
1378,9 → 1537,9
lea edi,[edi*3]
shl edi,2
add edi,[points_ptr]
; movzx edi,word[ebp+2] ; second point index
; lea edi,[edi*3]
; lea edi,[points+edi*2] ; edi - pointer to 2nd 3d point
; movzx edi,word[ebp+2] ; second point index
; lea edi,[edi*3]
; lea edi,[points+edi*2] ; edi - pointer to 2nd 3d point
call make_vector_r
add ebx,12
mov esi,edi
1388,7 → 1547,7
lea edi,[edi*3]
shl edi,2
add edi,[points_ptr]
; lea edi,[points+edi*2]
; lea edi,[points+edi*2]
call make_vector_r
mov edi,ebx ; edi - pointer to 2nd vector
mov esi,ebx
1425,7 → 1584,7
 
mov ax,cx
; cwd
; idiv word[i3]
; idiv word[i3]
movsd ; store vertex coordinates
movsw
stosw ; middle vertex coordinate 'z' in triangles_with_z list
1434,8 → 1593,8
movsd ; copy end mark
mov eax,4
lea edx,[edi-8-trizdd]
; lea edx, [edi-8]
; sub edx,[triangles_w_z_ptr]
; lea edx, [edi-8]
; sub edx,[triangles_w_z_ptr]
mov [high],edx
call quicksort
mov eax,4
1451,10 → 1610,10
lea ecx,[eax+edx]
shr ecx,4
lea ecx,[ecx*8-4];
; mov edi,[triangles_w_z_ptr]
; mov ebx,[edi+eax]
; mov esi,[edi+ecx]
; mov edi,[edi+edx]
; mov edi,[triangles_w_z_ptr]
; mov ebx,[edi+eax]
; mov esi,[edi+ecx]
; mov edi,[edi+edx]
mov ebx,[trizdd+eax]; trizdd[l]
mov esi,[trizdd+ecx]; trizdd[i]
mov edi,[trizdd+edx]; trizdd[h]
1470,13 → 1629,13
mov ebx,[trizdd+eax]
mov esi,[trizdd+ecx]
else
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+eax-4]
; movq mm1,[ebx+ecx-4]
; movq [ebx+ecx-4],mm0
; movq [ebx+eax-4],mm1
; pop ebx
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+eax-4]
; movq mm1,[ebx+ecx-4]
; movq [ebx+ecx-4],mm0
; movq [ebx+eax-4],mm1
; pop ebx
movq mm0,[trizdq+eax-4]
movq mm1,[trizdq+ecx-4]
movq [trizdq+ecx-4],mm0
1496,17 → 1655,17
mov ebx,[trizdd+eax]
mov edi,[trizdd+edx]
else
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+eax-4]
; movq mm1,[ebx+edx-4]
; movq [ebx+edx-4],mm0
; movq [ebx+eax-4],mm1
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+eax-4]
; movq mm1,[ebx+edx-4]
; movq [ebx+edx-4],mm0
; movq [ebx+eax-4],mm1
movq mm0,[trizdq+eax-4]
movq mm1,[trizdq+edx-4]
movq [trizdq+edx-4],mm0
movq [trizdq+eax-4],mm1
; pop ebx
; pop ebx
xchg ebx,edi
end if
@@:
1520,13 → 1679,13
mov [trizdd+ecx-4],edi
mov [trizdd+edx-4],esi
else
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+ecx-4]
; movq mm1,[ebx+edx-4]
; movq [ebx+edx-4],mm0
; movq [ebx+ecx-4],mm1
; pop ebx
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+ecx-4]
; movq mm1,[ebx+edx-4]
; movq [ebx+edx-4],mm0
; movq [ebx+ecx-4],mm1
; pop ebx
 
movq mm0,[trizdq+ecx-4]
movq mm1,[trizdq+edx-4]
1547,13 → 1706,13
mov [trizdd+ecx-4],esi
mov [trizdd+ebp-4],edi
else
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+ebp-4]
; movq mm1,[ebx+ecx-4]
; movq [ebx+ecx-4],mm0
; movq [ebx+ebp-4],mm1
; pop ebx
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm0,[ebx+ebp-4]
; movq mm1,[ebx+ecx-4]
; movq [ebx+ecx-4],mm0
; movq [ebx+ebp-4],mm1
; pop ebx
 
movq mm0,[trizdq+ebp-4]
movq mm1,[trizdq+ecx-4]
1562,20 → 1721,20
end if
mov ecx,edx ; i; direction
mov ebx,[trizdd+ebp]; trizdd[j]
; mov ebx, [triangles_w_z_ptr]
; add ebx, ebp
; mov ebx, [triangles_w_z_ptr]
; add ebx, ebp
 
; push eax
; mov eax, [triangles_w_z_ptr]
; push eax
; mov eax, [triangles_w_z_ptr]
.loop:
sub ecx,8 ; direction
cmp [trizdd+ecx],ebx
; cmp [eax+ecx],ebx
; cmp [eax+ecx],ebx
jl .loop ; direction
@@:
add ebp,8 ; direction
cmp [trizdd+ebp],ebx
; cmp [eax+ebp],ebx
; cmp [eax+ebp],ebx
jg @b ; direction
cmp ebp,ecx
jge @f ; direction
1589,10 → 1748,10
mov [trizdd+ebp-4],edi
mov [trizdd+ecx-4],esi
else
; movq mm0,[eax+ecx-4]
; movq mm1,[eax+ebp-4]
; movq [eax+ebp-4],mm0
; movq [eax+ecx-4],mm1
; movq mm0,[eax+ecx-4]
; movq mm1,[eax+ebp-4]
; movq [eax+ebp-4],mm0
; movq [eax+ecx-4],mm1
movq mm0,[trizdq+ecx-4]
movq mm1,[trizdq+ebp-4]
movq [trizdq+ebp-4],mm0
1599,7 → 1758,7
movq [trizdq+ecx-4],mm1
end if
jmp .loop
; pop eax
; pop eax
@@:
if Ext=NON
mov esi,[trizdd+ecx]
1611,13 → 1770,13
mov [trizdd+eax+4],edi
mov [trizdd+ecx-4],esi
else
; push edx
; mov edx,[triangles_w_z_ptr]
; movq mm0,[edx+ecx-4]
; movq mm1,[edx+eax+4]; dir
; movq [edx+eax+4],mm0; dir
; movq [edx+ecx-4],mm1
; pop edx
; push edx
; mov edx,[triangles_w_z_ptr]
; movq mm0,[edx+ecx-4]
; movq mm1,[edx+eax+4]; dir
; movq [edx+eax+4],mm0; dir
; movq [edx+ecx-4],mm1
; pop edx
 
movq mm0,[trizdq+ecx-4]
movq mm1,[trizdq+eax+4]; dir
1639,25 → 1798,25
cmp esi,edx
ja .exit
mov ebx,[trizdd+esi]
; mov ebx,[triangles_w_z_ptr]
; add ebx,esi
; mov ebx,[triangles_w_z_ptr]
; add ebx,esi
if Ext=NON
mov ecx,[trizdd+esi-4]
else
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm1,[ebx+esi-4]
; push ebx
; mov ebx,[triangles_w_z_ptr]
; movq mm1,[ebx+esi-4]
movq mm1,[trizdq+esi-4]
; pop ebx
; pop ebx
end if
mov edi,esi
@@:
cmp edi,eax
jna @f
; push eax
; mov eax,[triangles_w_z_ptr]
; cmp [eax+edi-8],ebx
; pop eax
; push eax
; mov eax,[triangles_w_z_ptr]
; cmp [eax+edi-8],ebx
; pop eax
cmp [trizdd+edi-8],ebx
jg @f ; direction
if Ext=NON
1666,13 → 1825,13
mov ebp,[trizdd+edi-12]
mov [trizdd+edi-4],ebp
else
; push eax
; mov eax,[triangles_w_z_ptr]
; movq mm0,[eax+edi-12]
; movq [eax+edi-4],mm0
; push eax
; mov eax,[triangles_w_z_ptr]
; movq mm0,[eax+edi-12]
; movq [eax+edi-4],mm0
movq mm0,[trizdq+edi-12]
movq [trizdq+edi-4],mm0
; pop eax
; pop eax
end if
sub edi,8
jmp @b
1681,11 → 1840,11
mov [trizdd+edi],ebx
mov [trizdd+edi-4],ecx
else
; push eax
; mov eax,[triangles_w_z_ptr]
; movq [eax+edi-4],mm1
; push eax
; mov eax,[triangles_w_z_ptr]
; movq [eax+edi-4],mm1
movq [trizdq+edi-4],mm1
; pop eax
; pop eax
end if
jmp .start
.exit:
1693,8 → 1852,8
end_sort:
; translate triangles_with_z to sorted_triangles
mov esi,triangles_with_z
; mov esi,[triangles_w_z_ptr]
; mov edi,sorted_triangles
; mov esi,[triangles_w_z_ptr]
; mov edi,sorted_triangles
mov edi,[triangles_ptr]
again_copy:
if Ext=NON
1710,7 → 1869,7
cmp dword[esi],-1
jne again_copy
; if Ext=MMX
; emms
; emms
; end if
movsd ; copy end mark too
ret
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
1792,7 → 1974,7
mov [point_index3],ax
lea eax,[eax*3]
add eax,eax
; push ebp
; push ebp
add ebp,eax
mov eax,[ebp]
mov dword[xx3],eax
1801,8 → 1983,8
else
mov eax,dword[esi] ; don't know MMX
mov dword[point_index1],eax
; shr eax,16
; mov [point_index2],ax
; shr eax,16
; mov [point_index2],ax
mov ax,word[esi+4]
mov [point_index3],ax
movq mm0,[esi]
1821,8 → 2003,46
movq qword[xx1],mm0
movq qword[xx2],mm1
movq qword[xx3],mm2
; emms
end if ; *********************************
; 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)
1834,7 → 2054,7
lea eax,[eax*3]
shl eax,2
add eax,[points_normals_rot_ptr]
; lea eax,[eax+point_normals_rotated]
; lea eax,[eax+point_normals_rotated]
fld dword[eax+8] ; *****************************
ftst ; CHECKING OF Z COOFICIENT OF
fstsw ax ; NORMAL VECTOR
1910,44 → 2130,44
jnz .again_grd_draw
jmp .both_draw
 
; movzx edi,[point_index3] ;gouraud shading according to light vector
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
; movzx edi,[point_index3] ;gouraud shading according to light vector
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
 
; movzx edi,[point_index2]
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
; movzx edi,[point_index2]
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
 
; movzx edi,[point_index1]
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
; movzx edi,[point_index1]
; lea edi,[edi*3]
; lea edi,[4*edi+point_normals_rotated] ; edi - normal
; mov esi,light_vector
; call dot_product
; fabs
; fimul [orginal_color_r]
; fistp [temp_col]
; and [temp_col],0x00ff
; push [temp_col]
; push [temp_col]
; push [temp_col]
.rainbow:
cmp [catmull_flag],1 ; put on stack z coordinate if necessary
jne @f
1987,7 → 2207,7
mov edi,[screen_ptr]
cmp [catmull_flag],0
je @f
; lea esi,[Z_buffer]
; lea esi,[Z_buffer]
mov esi,[Zbuffer_ptr]
call gouraud_triangle_z
jmp .end_draw
2033,17 → 2253,17
 
 
 
; 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 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
2051,11 → 2271,11
ror ebx,16
mov ecx,dword[xx3]
ror ecx,16
; mov edi,screen
; mov edi,screen
mov edi,[screen_ptr]
cmp [catmull_flag],0
je @f
; lea esi,[Z_buffer]
; lea esi,[Z_buffer]
mov esi,[Zbuffer_ptr]
push word[zz3]
push word[zz2]
2083,17 → 2303,17
shl eax,2
add eax,[points_normals_rot_ptr] ;point_normals_rotated
; #
; fld dword[eax]
; fmul dword[eax+4]
; fld1
; fld1
; faddp
; fmulp
; fimul [correct_tex]
; fiadd [correct_tex]
; fistp word[edi]
; mov word[edi+2],0
;; fistp word[edi+2]
; fld dword[eax]
; fmul dword[eax+4]
; fld1
; fld1
; faddp
; fmulp
; fimul [correct_tex]
; fiadd [correct_tex]
; fistp word[edi]
; mov word[edi+2],0
;; fistp word[edi+2]
; # last change
; texture x=(rotated point normal -> x * 255)+255
fld dword[eax]
2120,7 → 2340,7
mov esi,envmap
cmp [catmull_flag],0
je @f
; mov edx,Z_buffer
; mov edx,Z_buffer
mov edx,[Zbuffer_ptr]
call tex_triangle_z
jmp .end_draw
2156,18 → 2376,18
fiadd [correct_tex]
fistp word[edi]
mov word[edi+2],0
; fistp word[edi+2]
; fistp word[edi+2]
; # last change
; ; texture x=(rotated point normal -> x * 255)+255
; fld dword[eax]
; fimul [correct_tex]
; fiadd [correct_tex]
; fistp word[edi]
; ; texture y=(rotated point normal -> y * 255)+255
; fld dword[eax+4]
; fimul [correct_tex]
; fiadd [correct_tex]
; fistp word[edi+2]
; ; texture x=(rotated point normal -> x * 255)+255
; fld dword[eax]
; fimul [correct_tex]
; fiadd [correct_tex]
; fistp word[edi]
; ; texture y=(rotated point normal -> y * 255)+255
; fld dword[eax+4]
; fimul [correct_tex]
; fiadd [correct_tex]
; fistp word[edi+2]
; # end of last ch.
add edi,4
add esi,2
2183,7 → 2403,7
mov esi,envmap_cub
cmp [catmull_flag],0
je @f
; mov edx,Z_buffer
; mov edx,Z_buffer
mov edx,[Zbuffer_ptr]
call tex_triangle_z
jmp .end_draw
2197,7 → 2417,7
; fninit
cmp [catmull_flag],0
je @f
; push Z_buffer
; push Z_buffer
push [Zbuffer_ptr]
push [zz3]
push [zz2]
2234,17 → 2454,17
movzx esi,[point_index2]
shl esi,2
add esi,tex_points
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
push dword[esi]
; push dword[xx2]
; push dword[xx2]
movzx esi,[point_index1]
shl esi,2
add esi,tex_points
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
; lea esi,[esi*3]
; lea esi,[points+2+esi*2]
push dword[esi]
; push dword[xx1]
; push dword[xx1]
 
mov eax,dword[xx1]
ror eax,16
2296,47 → 2516,47
mov esi,texmap
cmp [catmull_flag],0
je @f
; mov edx,Z_buffer
; mov edx,Z_buffer
mov edx,[Zbuffer_ptr]
call tex_triangle_z
; call tex_plus_grd_trianlgle
; call tex_plus_grd_trianlgle
jmp .end_draw
@@:
call tex_triangle
jmp .end_draw
; .ray:
; grd_triangle according to points index
; cmp [catmull_flag],0
; je @f
; push [zz3] ; spot light with attenuation
; grd_triangle according to points index
; cmp [catmull_flag],0
; je @f
; push [zz3] ; spot light with attenuation
; @@:
; movzx eax,[point_index3] ; env_map - points color list
; shl eax,1 ; each color as word, 0x00rr00gg00bb..
; lea eax,[3*eax+bumpmap]
; push word[eax]
; push word[eax+2]
; push word[eax+4]
; cmp [catmull_flag],0
; je @f
; push [zz2]
; movzx eax,[point_index3] ; env_map - points color list
; shl eax,1 ; each color as word, 0x00rr00gg00bb..
; lea eax,[3*eax+bumpmap]
; push word[eax]
; push word[eax+2]
; push word[eax+4]
; cmp [catmull_flag],0
; je @f
; push [zz2]
; @@:
; movzx eax,[point_index2] ; env_map - points color list
; shl eax,1 ; each color as word, 0x00rr00gg00bb..
; lea eax,[eax*3+bumpmap]
; push word[eax]
; push word[eax+2]
; push word[eax+4]
; cmp [catmull_flag],0
; je @f
; push [zz1]
; movzx eax,[point_index2] ; env_map - points color list
; shl eax,1 ; each color as word, 0x00rr00gg00bb..
; lea eax,[eax*3+bumpmap]
; push word[eax]
; push word[eax+2]
; push word[eax+4]
; cmp [catmull_flag],0
; je @f
; push [zz1]
; @@:
; movzx eax,[point_index1] ; env_map - points color list
; shl eax,1 ; each color as word, 0xrr00gg00bb00..
; lea eax,[eax*3+bumpmap]
; push word[eax]
; push word[eax+2]
; push word[eax+4]
; jmp .both_draw
; movzx eax,[point_index1] ; env_map - points color list
; shl eax,1 ; each color as word, 0xrr00gg00bb00..
; lea eax,[eax*3+bumpmap]
; push word[eax]
; push word[eax+2]
; push word[eax+4]
; jmp .both_draw
 
.grd_tex: ; smooth shading + texture
push ebp
2521,9 → 2741,9
add esi,2
loop @b
 
; push dword 1 shl 16 + 1 ; emap coords
; push dword 127 shl 16 + 1
; push dword 127 shl 16 + 127
; push dword 1 shl 16 + 1 ; emap coords
; push dword 127 shl 16 + 1
; push dword 127 shl 16 + 127
 
movzx esi,[point_index3] ; bump map coords
shl esi,2
2539,9 → 2759,9
add esi,tex_points
push dword[esi]
 
; push dword 1 shl 16 + 127
; push dword 127 shl 16 + 127
; push dword 1 shl 16 + 1 ; bump coords
; push dword 1 shl 16 + 127
; push dword 127 shl 16 + 127
; push dword 1 shl 16 + 1 ; bump coords
 
mov eax,dword[xx1]
ror eax,16
2590,11 → 2810,11
dec ecx
jnz .again_line_param
 
; mov eax,[edges_ptr] ; this not works correctly
; add eax,[edges_counter] ; I mean chosing overlapped edges.
; mov bl,[eax] ;
; test bl,00000001b ;
; jz @f ;
; mov eax,[edges_ptr] ; this not works correctly
; add eax,[edges_counter] ; I mean chosing overlapped edges.
; mov bl,[eax] ;
; test bl,00000001b ;
; jz @f ;
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
 
2624,11 → 2844,11
 
call smooth_line
@@:
; mov eax,[edges_ptr] ; this not works correctly
; add eax,[edges_counter]
; mov bl,[eax]
; test bl,00000010b
; jz @f
; mov eax,[edges_ptr] ; this not works correctly
; add eax,[edges_counter]
; mov bl,[eax]
; test bl,00000010b
; jz @f
 
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
2660,11 → 2880,11
call smooth_line
@@:
 
; mov eax,[edges_ptr] ; this not works correctly
; add eax,[edges_counter] ;
; mov bl,[eax] ;
; test bl,00000100b ;
; jz @f ;
; mov eax,[edges_ptr] ; this not works correctly
; add eax,[edges_counter] ;
; mov bl,[eax] ;
; test bl,00000100b ;
; jz @f ;
 
mov edi,[screen_ptr]
mov esi,[Zbuffer_ptr]
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]
2735,7 → 3060,7
end if
ret
 
read_tp_variables: ; read [triangles_count_var] and [points_count_var]
read_tp_variables: ; read [triangles_count_var] and [points_count_var]
; and allocate memory
xor ebx,ebx
xor ebp,ebp
2807,7 → 3132,7
 
add ebx,6
add esi,12
; dec ecx
; dec ecx
loop @b
@@:
 
2825,7 → 3150,7
add esi,8
dec ecx
jnz @b
; xor ecx,ecx
; xor ecx,ecx
add ebp,edx
jmp .find4k
mov eax,-1 ;<---mark if OK
2846,11 → 3171,11
end if
cmp [esi],word 4D4Dh
jne .exit ;Must be legal .3DS file
; cmp dword[esi+2],EndFile-SourceFile
; jne .exit ;This must tell the length
; cmp dword[esi+2],EndFile-SourceFile
; jne .exit ;This must tell the length
mov eax,dword[esi+2]
; cmp eax,[fsize]
; jne .exit
; cmp eax,[fsize]
; jne .exit
 
add eax,esi
mov [EndFile],eax ;
2900,19 → 3225,19
@@:
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]
; fstp dword[real_points+ebx*2+0] ; x
; fld dword[esi+8]
; fstp dword[real_points+ebx*2+4] ; y
; fld dword[esi+0]
; fstp dword[real_points+ebx*2+8] ; z
; fld dword[esi+4]
; fstp dword[real_points+ebx*2+0] ; x
; fld dword[esi+8]
; fstp dword[real_points+ebx*2+4] ; y
; fld dword[esi+0]
; fstp dword[real_points+ebx*2+8] ; z
 
add ebx,6
add esi,12
2919,7 → 3244,7
dec ecx
jnz @b
@@:
; mov dword[points+ebx],-1
; mov dword[points+ebx],-1
push edi
mov edi,[points_ptr]
mov dword[edi+ebx*2],-1 ; end mark (not always in use)
2933,7 → 3258,7
movzx ecx,word[esi+6]
add [triangles_count_var],cx
add esi,8
;mov edi,triangles
;mov edi,triangles
@@:
movsd
movsw
2969,28 → 3294,28
int 0x40 ; -> allocate memory to triangles
mov [triangles_ptr], eax ; -> eax = pointer to allocated mem
 
; mov eax, 68
; movzx ecx, [triangles_count_var]
; inc ecx
; mov edx,[edges_ptr]
; int 0x40 ; -> allocate memory to edges
; mov [edges_ptr], eax ; -> eax = pointer to allocated mem
; mov eax, 68
; movzx ecx, [triangles_count_var]
; inc ecx
; mov edx,[edges_ptr]
; int 0x40 ; -> allocate memory to edges
; mov [edges_ptr], eax ; -> eax = pointer to allocated mem
 
; mov eax,-1 ; fill edges list
; movzx ecx,[triangles_count_var] ; importand if object generated
; shr ecx,2
; inc ecx
; mov edi,[edges_ptr]
; cld
; rep stosd
; mov eax,-1 ; fill edges list
; movzx ecx,[triangles_count_var] ; importand if object generated
; shr ecx,2
; inc ecx
; mov edi,[edges_ptr]
; cld
; rep stosd
 
 
; mov eax, 68
; mov ebx, 12
; movzx ecx, [triangles_count_var]
; shl ecx, 4
; int 0x40
; mov [triangles_w_z_ptr], eax ; for trainagles_with_z list
; mov eax, 68
; mov ebx, 12
; movzx ecx, [triangles_count_var]
; shl ecx, 4
; int 0x40
; mov [triangles_w_z_ptr], eax ; for trainagles_with_z list
; ststic memory
 
mov eax, 68
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,9 → 3340,14
mov edx,[points_normals_ptr]
int 0x40
mov [points_normals_ptr], eax
; int3
 
 
; int3
 
 
mov eax, 68
; mov ebx, 12
; mov ebx, 12
movzx ecx, [points_count_var]
lea ecx,[3+ecx*3]
shl ecx, 2
3067,7 → 3404,6
int 0x40 ; -> read file
 
mov [fsize],ebx
 
cmp eax,6
jnz @f
xor eax,eax ;;;;---
3081,10 → 3417,13
shr eax,9
inc eax
mov [fsize],eax
 
 
 
; mov ecx,ebx
; add ecx,MEM_END
; mov ebx,1
; mov eax,64 ; allocate mem - resize app mem
; mov eax,64 ; allocate mem - resize app mem
; for points and triangles
int 0x40
 
3146,14 → 3485,14
cmp byte[edi+11],255 ; if max_flag=255
je @f ; skip
; flag description
; mov eax,4 ; function 4 : write text to window
; movzx ebx,byte[edi]
; sub bl,2
; lea ebx,[ebx*3]
; lea ebx,[ebx*5]
; add ebx,(SIZE_X+12+70)*65536+28 ; [x start] *65536 + [y start]
; mov eax,4 ; function 4 : write text to window
; movzx ebx,byte[edi]
; sub bl,2
; lea ebx,[ebx*3]
; lea ebx,[ebx*5]
; add ebx,(SIZE_X+12+70)*65536+28 ; [x start] *65536 + [y start]
add ebx,70*65536
; mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
; mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
movzx edx,byte[edi+12] ; current flag
shl edx,2 ; * 4 = text length
add edx,dword[edi+13] ; pointer to text beginning
3179,8 → 3518,8
shl ebx,16
mov cx,[y_start]
shl ecx,16
;ebx - [x start] *65536 + [x size]
;ecx - [y start] *65536 + [y size]
;ebx - [x start] *65536 + [x size]
;ecx - [y start] *65536 + [y size]
mov bx,[size_x_var]
add bx,115
mov cx,[size_y_var]
3192,9 → 3531,9
 
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 ++
; ADD VECTOR LABEL ; add vector buttons - 30 ++
mov eax,4 ; function 4 : write text to window
movzx ebx,word[size_x_var]
shl ebx,16
3202,9 → 3541,9
mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelvector ; pointer to text beginning
mov esi,labelvectorend-labelvector ; text length
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; @@:
int 0x40
; VECTOR Y- BUTTON
3225,8 → 3564,8
mov edx,labelyminus ; pointer to text beginning
mov esi,labelyminusend-labelyminus ; text length
cmp [move_flag],2
; jne @f
; add edx,navigation_size
; jne @f
; add edx,navigation_size
; @@:
int 0x40
; VECTOR Z+ BUTTON
3246,9 → 3585,9
mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelzplus ; pointer to text beginning
mov esi,labelzplusend-labelzplus ; text length
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; @@:
 
int 0x40
3269,9 → 3608,9
mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelxminus ; pointer to text beginning
mov esi,labelxminusend-labelxminus ; text length
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; @@:
int 0x40
; VECTOR x+ BUTTON
3291,9 → 3630,9
mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelxplus ; pointer to text beginning
mov esi,labelxplusend-labelxplus ; text length
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; @@:
int 0x40
; VECTOR z- BUTTON
3313,9 → 3652,9
mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelzminus ; pointer to text beginning
mov esi,labelzminusend-labelzminus ; text length
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; @@:
int 0x40
;VECTOR Y+ BUTTON
3335,9 → 3674,9
mov ecx,0x00ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelyplus ; pointer to text beginning
mov esi,labelyplusend-labelyplus ; text length
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; cmp [move_flag],2
; jne @f
; add edx,navigation_size
; @@:
int 0x40
 
3347,7 → 3686,7
ret
 
 
; DATA AREA ************************************
; DATA AREA ************************************
 
include 'DATA.INC'
align 16