New View3ds demo from macgub

git-svn-id: svn://kolibrios.org@1245 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2009-10-31 22:01:20 +00:00
parent 38098ecc9f
commit 184460aa4b
24 changed files with 11964 additions and 6030 deletions

View File

@ -1,109 +0,0 @@
x3d equ 0
y3d equ 2
z3d equ 4
vec_x equ 0
vec_y equ 4
vec_z equ 8
; 3d point - triple integer word coordinate
; vector - triple float dword coordinate
;----------------------in: --------------------------------
;------------------------ esi - pointer to 1st 3d point ---
;------------------------ edi - pointer to 2nd 3d point ---
;------------------------ ebx - pointer to result vector --
;---------------------- out : none ------------------------
make_vector:
fninit
fild word[edi+x3d] ;edi+x3d
fisub word[esi+x3d] ;esi+x3d
fstp dword[ebx+vec_x]
fild word[edi+y3d]
fisub word[esi+y3d]
fstp dword[ebx+vec_y]
fild word[edi+z3d]
fisub word[esi+z3d]
fstp dword[ebx+vec_z]
ret
;---------------------- in: -------------------------------
;--------------------------- esi - pointer to 1st vector --
;--------------------------- edi - pointer to 2nd vector --
;--------------------------- ebx - pointer to result vector
;---------------------- out : none
cross_product:
fninit
fld dword [esi+vec_y]
fmul dword [edi+vec_z]
fld dword [esi+vec_z]
fmul dword [edi+vec_y]
fsubp ;st1 ,st
fstp dword [ebx+vec_x]
fld dword [esi+vec_z]
fmul dword [edi+vec_x]
fld dword [esi+vec_x]
fmul dword [edi+vec_z]
fsubp ;st1 ,st
fstp dword [ebx+vec_y]
fld dword [esi+vec_x]
fmul dword [edi+vec_y]
fld dword [esi+vec_y]
fmul dword [edi+vec_x]
fsubp ;st1 ,st
fstp dword [ebx+vec_z]
ret
;----------------------- in: ------------------------------
;---------------------------- edi - pointer to vector -----
;----------------------- out : none
normalize_vector:
fninit
fld dword [edi+vec_x]
fmul st, st
fld dword [edi+vec_y]
fmul st, st
fld dword [edi+vec_z]
fmul st, st
faddp st1, st
faddp st1, st
fsqrt
ftst
fstsw ax
sahf
jnz @f
fst dword [edi+vec_x]
fst dword [edi+vec_y]
fstp dword [edi+vec_z]
ret
@@:
fld st
fld st
fdivr dword [edi+vec_x]
fstp dword [edi+vec_x]
fdivr dword [edi+vec_y]
fstp dword [edi+vec_y]
fdivr dword [edi+vec_z]
fstp dword [edi+vec_z]
ret
;------------------in: -------------------------
;------------------ esi - pointer to 1st vector
;------------------ edi - pointer to 2nd vector
;------------------out: ------------------------
;------------------ st0 - dot-product
dot_product:
fninit
fld dword [esi+vec_x]
fmul dword [edi+vec_x]
fld dword [esi+vec_y]
fmul dword [edi+vec_y]
fld dword [esi+vec_z]
fmul dword [edi+vec_z]
faddp
faddp
ret

View File

@ -0,0 +1,411 @@
x3d equ 0
y3d equ 2
z3d equ 4
vec_x equ 0
vec_y equ 4
vec_z equ 8
; 3d point - triple integer word coordinate
; vector - triple float dword coordinate
;----------------------in: --------------------------------
;------------------------ esi - pointer to 1st 3d point ---
;------------------------ edi - pointer to 2nd 3d point ---
;------------------------ ebx - pointer to result vector --
;---------------------- out : none ------------------------
if 0
make_vector:
fninit
fild word[edi+x3d] ;edi+x3d
fisub word[esi+x3d] ;esi+x3d
fstp dword[ebx+vec_x]
fild word[edi+y3d]
fisub word[esi+y3d]
fstp dword[ebx+vec_y]
fild word[edi+z3d]
fisub word[esi+z3d]
fstp dword[ebx+vec_z]
ret
end if
make_vector_r:
fninit
fld dword[edi] ;edi+x3d
fsub dword[esi] ;esi+x3d
fstp dword[ebx+vec_x]
fld dword[edi+4]
fsub dword[esi+4]
fstp dword[ebx+vec_y]
fld dword[edi+8]
fsub dword[esi+8]
fstp dword[ebx+vec_z]
ret
;---------------------- in: -------------------------------
;--------------------------- esi - pointer to 1st vector --
;--------------------------- edi - pointer to 2nd vector --
;--------------------------- ebx - pointer to result vector
;---------------------- out : none
cross_product:
fninit
fld dword [esi+vec_y]
fmul dword [edi+vec_z]
fld dword [esi+vec_z]
fmul dword [edi+vec_y]
fsubp ;st1 ,st
fstp dword [ebx+vec_x]
fld dword [esi+vec_z]
fmul dword [edi+vec_x]
fld dword [esi+vec_x]
fmul dword [edi+vec_z]
fsubp ;st1 ,st
fstp dword [ebx+vec_y]
fld dword [esi+vec_x]
fmul dword [edi+vec_y]
fld dword [esi+vec_y]
fmul dword [edi+vec_x]
fsubp ;st1 ,st
fstp dword [ebx+vec_z]
ret
;----------------------- in: ------------------------------
;---------------------------- edi - pointer to vector -----
;----------------------- out : none
normalize_vector:
fninit
fld dword [edi+vec_x]
fmul st, st
fld dword [edi+vec_y]
fmul st, st
fld dword [edi+vec_z]
fmul st, st
faddp st1, st
faddp st1, st
fsqrt
ftst
fstsw ax
sahf
jnz @f
fst dword [edi+vec_x]
fst dword [edi+vec_y]
fstp dword [edi+vec_z]
ret
@@:
fld st
fld st
fdivr dword [edi+vec_x]
fstp dword [edi+vec_x]
fdivr dword [edi+vec_y]
fstp dword [edi+vec_y]
fdivr dword [edi+vec_z]
fstp dword [edi+vec_z]
ret
;------------------in: -------------------------
;------------------ esi - pointer to 1st vector
;------------------ edi - pointer to 2nd vector
;------------------out: ------------------------
;------------------ st0 - dot-product
dot_product:
fninit
fld dword [esi+vec_x]
fmul dword [edi+vec_x]
fld dword [esi+vec_y]
fmul dword [edi+vec_y]
fld dword [esi+vec_z]
fmul dword [edi+vec_z]
faddp
faddp
ret
; DOS version Coded by Mikolaj Felix aka Majuma
; mfelix@polbox.com
; www.majuma.xt.pl
; into FASM translation by Macgub
init_sincos_tab:
.counter equ dword [ebp-4] ; cur angle
push ebp
mov ebp,esp
xor eax,eax
push eax ; init .counter
mov edi,cos_tab
mov esi,sin_tab
mov ecx,256
fninit
fld .counter
@@:
fld st
fsincos
fstp dword [edi]
fstp dword [esi]
; fadd [piD180]
fadd [piD128]
add esi,4
add edi,4
loop @b
ffree st
mov esp,ebp
pop ebp
ret
;------
; esi - offset (pointer) to angles, edi offset to 3x3 matrix
make_rotation_matrix:
.sinx equ dword[ebp-4]
.cosx equ dword[ebp-8]
.siny equ dword[ebp-12]
.cosy equ dword[ebp-16]
.sinz equ dword[ebp-20]
.cosz equ dword[ebp-24]
push ebp
mov ebp,esp
sub esp,24
movzx ebx,word[esi]
shl ebx,2
mov eax,dword[sin_tab+ebx]
mov .sinx,eax
mov edx,dword[cos_tab+ebx]
mov .cosx,edx
movzx ebx,word[esi+2]
shl ebx,2
mov eax,dword[sin_tab+ebx]
mov .siny,eax
mov edx,dword[cos_tab+ebx]
mov .cosy,edx
movzx ebx,word[esi+4]
shl ebx,2
mov eax,dword[sin_tab+ebx]
mov .sinz,eax
mov edx,dword[cos_tab+ebx]
mov .cosz,edx
fninit
fld .cosy
fmul .cosz
fstp dword[edi]
fld .sinx
fmul .siny
fmul .cosz
fld .cosx
fmul .sinz
fchs
faddp
fstp dword[edi+12]
fld .cosx
fmul .siny
fmul .cosz
fld .sinx
fmul .sinz
faddp
fstp dword[edi+24]
fld .siny
fmul .sinz
fstp dword[edi+4]
fld .sinx
fmul .siny
fmul .sinz
fld .cosx
fmul .cosz
faddp
fstp dword[edi+16]
fld .cosx
fmul .siny
fmul .sinz
fld .sinx
fchs
fmul .cosz
faddp
fstp dword[edi+28]
fld .siny
fchs
fstp dword[edi+8]
fld .cosy
fmul .sinx
fstp dword[edi+20]
fld .cosx
fmul .cosy
fstp dword[edi+32]
mov esp,ebp
pop ebp
ret
;---------------------
; in: esi - ptr to points(normals], each point(normal) coeficient as dword
; edi - ptr to rotated points(normals)
; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix
; ecx - number of points(normals)
rotary:
if Ext<SSE
fninit
.again:
fld dword[esi]
fmul dword[ebx]
fld dword[esi+4]
fmul dword[ebx+12]
faddp
fld dword[esi+8]
fmul dword[ebx+24]
faddp
fstp dword[edi]
fld dword[esi+4]
fmul dword[ebx+16]
fld dword[esi]
fmul dword[ebx+4]
faddp
fld dword[esi+8]
fmul dword[ebx+28]
faddp
fstp dword[edi+4]
fld dword[esi+8]
fmul dword[ebx+32]
fld dword[esi]
fmul dword[ebx+8]
fld dword[esi+4]
fmul dword[ebx+20]
faddp
faddp
fstp dword[edi+8]
add esi,12
add edi,12
loop .again
mov [edi],dword -1
else
; Copyright (C) 1999-2001 Brian Paul
; Copyright (C) Maciej Guba
;---------------------
; in: esi - ptr to points(normals], each point(normal) coeficient as dword
; edi - ptr to rotated points(normals)
; ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix
; ecx - number of points(normals)
;align 32
movups xmm4,[ebx]
movups xmm5,[ebx+12]
movups xmm6,[ebx+24]
;align 32
.again:
movss xmm0,dword[esi]
shufps xmm0,xmm0,0
mulps xmm0,xmm4
movss xmm1,dword[esi+4]
shufps xmm1,xmm1,0
mulps xmm1,xmm5
movss xmm2,dword[esi+8]
shufps xmm2,xmm2,0
mulps xmm2,xmm6
addps xmm0,xmm1
addps xmm0,xmm2
movups [edi],xmm0
add esi,12
add edi,12
dec ecx
jne .again
mov [edi],dword -1
end if
ret
;----------------------------------------------
; esi - pointer to 3x3 matrix
add_scale_to_matrix:
fninit
fld [rsscale]
fld dword[esi] ;-----
fmul st,st1
fstp dword[esi]
fld dword[esi+12] ; x scale
fmul st,st1
fstp dword[esi+12]
fld dword[esi+24]
fmul st,st1
fstp dword[esi+24] ;------
fld dword[esi+4] ;-----
fmul st,st1
fstp dword[esi+4]
fld dword[esi+16] ; y scale
fmul st,st1
fstp dword[esi+16]
fld dword[esi+28]
fmul st,st1
fstp dword[esi+28] ;------
fld dword[esi+8] ;-----
fmul st,st1
fstp dword[esi+8]
fld dword[esi+20] ; z scale
fmul st,st1
fstp dword[esi+20]
fld dword[esi+32]
fmulp st1,st
fstp dword[esi+32] ;------
ret
;in esi - offset to 3d points (point as 3 dwords float)
; edi - offset to 2d points ( as 3 words integer)
; ecx - number of points
translate_points: ; just convert into integer; z coord still needed
fninit
.again:
fld dword[esi+8]
; fmul [rsscale]
fist word[edi+4]
fisub [zobs]
fchs
fld dword[esi]
; fmul [rsscale]
fisub [xobs]
fimul [zobs]
fdiv st0,st1
fiadd [xobs]
fiadd [vect_x]
fistp word[edi]
fld dword[esi+4]
; fmul [rsscale]
fisub [yobs]
fimul [zobs]
fdivrp ; st0,st1
fiadd [yobs]
fiadd [vect_y]
fistp word[edi+2]
add esi,12
add edi,6
dec ecx
jnz .again
ret

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,440 +0,0 @@
;
; application : 3d shaking waved spiral
; compilator : fasm
; system : MenuetOS
; author : macgub
; email : macgub3@wp
timeout equ 3
maxx equ 600 ; window size
maxy equ 420
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x100000 ; memory for app
dd 0xbffff ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
START: ; start of execution
call draw_window
still:
; mov eax,23 ; wait here for event
; mov ebx,timeout
; int 0x40
mov eax,11 ; check for event no wait
int 0x40
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
jmp noclose
red: ; redraw
call draw_window
jmp still
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp still
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; close this program
int 0x40
noclose:
; mov eax,13
; mov ebx,20*65536+maxx-25
; mov ecx,20*65536+maxy-25
; xor edx,edx
; int 0x40
mov edi,screen_buf
mov ecx,maxx*maxy*3/4
xor eax,eax
cld
rep stosd
call calc_deg
mov [z],0
mov [sin_counter],0
finit
oopz:
mov [x],0
push [z]
call calc_sin_variable
oop:
push [x]
; call getcol ;(x,z)
call fun ; calculates y and y1
; call rotateY
mov eax,[sin_variable]
add eax,[vector_x] ; vector_x
add [x],eax
mov eax,[vector_y]
add [y],eax ; vector_y
add [y1],eax
call point_perspective
call draw_point_3d
pop [x]
inc [x]
mov eax,[x]
cmp eax,[loop_counter]
jne oop
inc [sin_counter]
pop [z]
inc [z]
cmp [z],200
jne oopz
mov eax,7
mov ebx,screen_buf
mov ecx,maxx*65536+maxy
mov edx,20*65536+20
int 0x40
call set_elipse_dim
call set_vectors
jmp still
;-----------------++++++PROCEDURES
getcol:
mov eax,[x_resolution]
mul [z]
add eax,[x]
mov ebx,eax
mov eax,35
int 0x40
mov [col],eax
ret
set_vectors:
cmp [vector_x],55
jne vec1
mov [vector_dir_x],1
vec1:
cmp [vector_x],250
jne vec2
mov [vector_dir_x],0
vec2:
cmp [vector_dir_x],1
jne vec3
inc [vector_x]
jmp end_x
vec3:
dec [vector_x]
end_x:
cmp [vector_y],195
jne vec4
mov [vector_dir_y],1
vec4:
cmp [vector_y],205
jne vec5
mov [vector_dir_y],0
vec5:
cmp [vector_dir_y],1
jne vec6
inc [vector_y]
ret
vec6:
dec [vector_y]
ret
set_elipse_dim:
cmp [b],60
jne go11
mov [elipse_dir],0
go11:
cmp [b],10
jne go12
mov [elipse_dir],1
go12:
cmp [elipse_dir],1
jne go13
inc [b]
dec [a]
mov eax,[a]
mov [xo],eax
shl eax,1
inc eax
mov [loop_counter],eax
ret
go13:
dec [b]
inc [a]
mov eax,[a]
mov [xo],eax
shl eax,1
inc eax
mov [loop_counter],eax
ret
calc_deg:
cmp [deg_counter], 360
jne go_deg
mov [deg_counter],0
go_deg:
fldpi
fidiv [deg_div]
fimul [deg_counter]
fstp [current_deg]
; fsincos
; fstp [cosbeta]
; fstp [sinbeta]
inc [deg_counter]
ret
;rotateY:
; mov eax,[z]
; sub eax,[zoo]
; mov [subz],eax
; mov eax,[x]
; sub eax,[xoo]
; mov [subx],eax
;
; fld [sinbeta]
; fimul [subz]
; fchs
; fld [cosbeta]
; fimul[subx]
; faddp
; fiadd [xoo]
; fistp [x]
; fld [sinbeta]
; fimul [subx]
; fld [cosbeta]
; fimul [subz]
; faddp
; fiadd [zoo]
; fistp [z]
; finit
; ret
point_perspective:
mov eax,[x]
sub eax,[xobs]
mov [xobssub],eax
mov eax,[z]
sub eax,[zobs]
mov [zobssub],eax
mov eax,[y]
sub eax,[yobs]
mov [yobssub],eax
mov eax,[y1]
sub eax,[yobs]
mov [y1obssub],eax
finit
fild [xobssub]
fidiv [zobssub]
fimul [zobs]
fchs
fiadd [xobs]
fistp [x]
fild [yobssub]
fidiv [zobssub]
fimul [zobs]
fchs
fiadd [yobs]
fistp [y]
; mov eax,[xobssub]
; idiv [zobssub]
;; mov eax,edx
; imul [zobs]
; neg eax
; add eax,[xobs]
; mov [x],eax
; mov eax,[yobssub]
; idiv [zobssub]
;; mov eax,edx
; imul [zobs]
; neg eax
; add eax,[yobs]
; mov [y],eax
fild [y1obssub]
fidiv [zobssub]
fimul [zobs]
fchs
fiadd [yobs]
fistp [y1]
ret
calc_sin_variable:
;calculate sinus variable
fldpi
fidiv [sin_gran]
fimul [sin_counter]
fadd [current_deg]
fsin
fimul [sin_mul]
fistp [sin_variable]
ret
fun:
; finit
fild [x]
fisub [xo]
; fchs
; faddp
fild [a]
fdivp st1,st
fmul st,st0
fchs
fld1
faddp
fsqrt
fimul [b]
fld st
fchs
fiadd [yo]
fistp [y]
fiadd [yo]
fistp [y1]
ret
draw_point_3d:
mov eax,[z]
imul [sq]
shr eax,10
mov ebx,eax
neg eax
push eax
add eax,[y]
mov [y],eax
pop eax
add eax,[y1]
mov [y1],eax
mov eax,ebx
add eax,[x]
mov [x],eax
;mov eax,1
;mov ebx,[x]
;mov ecx,[y]
;mov edx,[col]
;int 0x40
;mov ecx,[y1]
;int 0x40
mov eax,maxx
mul [y]
add eax,[x]
mov ebx,eax
shl ebx,1
add eax,ebx
add eax,screen_buf
mov ebx,[col]
or [eax],ebx
mov eax,maxx
mul [y1]
add eax,[x]
mov ebx,eax
shl ebx,1
add eax,ebx
add eax,screen_buf
mov ebx,[col]
or [eax],ebx
ret
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+maxx+25 ; [x start] *65536 + [x size]
mov ecx,100*65536+maxy+25 ; [y start] *65536 + [y size]
mov edx,0x04000000 ; color of work area RRGGBB,8->color gl
mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x005080d0 ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
x_resolution dd 800
vector_x dd 200
vector_y dd 200
vector_dir_x db 1
vector_dir_y db 1
elipse_dir db 1
deg_counter dd ? ; rotation variables
deg_div dd 20
current_deg dd ?
;cosbeta dd ?
;sinbeta dd ?
;zoo dd 100 ; rotation axle
;xoo dd 40
;yoo dd 20
;subx dd ?
;suby dd ?
;subz dd ?
xobs dd maxx/2 ; 320 observer variables
yobs dd maxy/2 ; 175
zobs dd -200
xobssub dd ?
yobssub dd ?
y1obssub dd ?
zobssub dd ?
sin_variable dd ?
sin_mul dd 60
sin_gran dd 30
sin_counter dd 0
sq dd 724 ; round( (sqrt2)/2*1024 )
z dd ?
x dd ?
y dd ?
y1 dd ?
xo dd 70 ; center point , (loop counter-1)/2
yo dd 20
a dd 70 ; vertical half-axle
b dd 20 ; horizontal half-axle
loop_counter dd 141 ; axle granularity
col dd 0x00ffffff
labelt:
db ' 3D SHAKING WAVED SPIRAL'
labellen:
screen_buf:
I_END:

View File

@ -0,0 +1,503 @@
draw_dots:
mov esi,[points_translated_ptr]
movzx ecx,[points_count_var]
.drw:
@@:
lodsd
add esi,2 ; skip z
movzx ebx,ax
shr eax,16 ; bx = x , ax = y
or ax,ax
jl @f
or bx,bx
jl @f
cmp ax,SIZE_Y
jge @f
cmp bx,SIZE_X
jge @f
mov edx,SIZE_X ; SIZE_X not only power of 2 -> 256,512,...
mul edx
add eax,ebx
mov edi,[screen_ptr]
lea eax,[eax*3]
add edi,eax
xor eax,eax
not eax
stosd
@@:
loop .drw
ret
do_emboss:
; emboss - after drawing all,
; transfer screen buffer into bump map
; and draw two bump triangles
; *************************************
mov esi,screen
mov edi,bumpmap2
mov ecx,TEXTURE_SIZE/3
cld
if Ext=NON
xor eax,eax
xor bh,bh
xor dh,dh
@@:
lodsb
movzx bx,al
lodsb
movzx dx,al
lodsb
add ax,bx
add ax,dx
; cwd
; div [i3]
;; push ax
;; pop bx
;; shr bx,3
;; shr ax,2
;; add ax,bx
lea eax,[eax*5]
shr ax,4
stosb
loop @b
else
emms
pxor mm1,mm1
mov ebx,0x0000ffff
@@:
movd mm0,[esi]
punpcklbw mm0,mm1
movq mm2,mm0
psrlq mm2,16
movq mm3,mm0
psrlq mm3,32
paddw mm0,mm2
paddw mm0,mm3
movd eax,mm0
and eax,ebx
lea eax,[eax*5]
shr ax,4
stosb
add esi,3
loop @b
end if
push ebp
push dword 0 ; env coords
push word 0
push word SIZE_X
push word SIZE_Y
push dword 0
push dword 0 ; bump coords
push word SIZE_X
push word SIZE_Y
push word 0
mov eax,SIZE_Y
mov ebx,SIZE_X*65536+0
xor ecx,ecx
mov edx,bumpmap2
mov esi,envmap
mov edi,screen
call bump_triangle
push dword SIZE_X shl 16 + SIZE_Y ; env coords
push word 0
push word SIZE_X
push word SIZE_Y
push word 0
push dword SIZE_X shl 16 + SIZE_Y ; bump coords
push word 0
push word SIZE_X
push word SIZE_Y
push word 0
mov eax,SIZE_Y
mov ebx,SIZE_X * 65536+0
mov ecx,SIZE_X shl 16 + SIZE_Y
mov edx,bumpmap2
mov esi,envmap
mov edi,screen
call bump_triangle
pop ebp
ret
;********************************EMBOSS DONE*******************************
generate_object2: ; torus
;in ax - figure number 2=torus, 3=loop, 4=loop
;locals
; counter dw ?
; sin dd ?
; cos dd ?
;endl
.counter equ word[ebp-2]
.sin equ dword[ebp-6]
.cos equ dword[ebp-10]
.sin2 equ dword[ebp-14]
.cos2 equ dword[ebp-18]
.piD180m3 equ dword[ebp-22]
.cD2 equ word[ebp-24]
push ebp
mov ebp,esp
sub esp,24
push ax
fninit
mov edi,[points_ptr]
xor eax,eax
; init seed -> 4 3d points
mov dword[edi],-1.0 ; x
add edi,4
stosd ; y
stosd ; z
mov dword[edi],-0.9 ; x1
mov dword[edi+4],0.1 ; y1
add edi,8
stosd ; z1
mov dword[edi],-0.8
add edi,4
stosd
stosd
mov dword[edi],-0.9 ; x3
mov dword[edi+4],-0.1 ; y3
add edi,8
stosd ; z3
mov [points_count_var],4
fld [piD180]
fidiv [i3]
fstp .piD180m3
mov .cD2,5
pop ax
mov ecx,1
mov edx,9
.next: ; calc angle and rotate seed 4 points
mov .counter,cx
mov ebx,[points_ptr]
fld .piD180m3
fimul .counter
fld st
fsincos
fstp .sin
fstp .cos
fadd st,st0
fsincos
fstp .sin2
fstp .cos2
.rotor: ; next 4
; rotary y
fld dword[ebx] ; x
fld .sin
fmul dword[ebx+8] ; z * sinbeta
fchs
fld .cos
fmul dword[ebx] ; x * cosbeta
faddp
fstp dword[edi] ; new x
fmul .sin ; old x * sinbeta
fld .cos
fmul dword[ebx+8] ; z * cosbeta
faddp
dec dx
or dx,dx
jnz @f
; mov .counter,dx
fld st
fidiv [i3]
faddp
@@:
fstp dword[edi+8] ; new z
fld dword[ebx+4]
or dx,dx
jnz @f
; fld1
; faddp
; fld st
fadd st,st0
fadd st,st0
; fxch
; fimul [i3]
; fsin
; faddp
mov dx,9
@@:
fstp dword[edi+4]
; rotary x
cmp al,3
jl .end_rot
fld dword[edi+4] ;y
fld .sin2
fmul dword[edi+8] ;z
fld .cos2
fmul dword[edi+4] ;y
faddp
fstp dword[edi+4] ; new y
fmul .sin2 ; sinbeta * old y
fchs
fld .cos2
fmul dword[edi+8]
faddp
fstp dword[edi+8]
; rotary z
cmp al,4
jl .end_rot
fld dword[edi] ;x
fld .sin
fmul dword[edi+4] ;y
fld .cos
fmul dword[edi] ;x
faddp
fstp dword[edi] ;new x
fmul .sin ; sinbeta * old x
fchs
fld .cos
fmul dword[edi+4] ; cosbeta * y
faddp
fstp dword[edi+4] ; new y
.end_rot:
add edi,12
add ebx,12
mov esi,[points_ptr]
add esi,12*4
cmp ebx,esi
jl .rotor
add [points_count_var],4
add cx,18
cmp cx,(18*21*3)+1
jle .next
mov edi,[triangles_ptr]
mov ax,4
mov bx,4+4
mov [triangles_count_var],164*3 ;140
mov cx,80*3 ;68
@@:
stosw ;----
mov [edi],bx ; |
add edi,2 ; |
inc ax ; |
stosw ; |repeat 4 times
mov [edi],bx ; |
inc bx
add edi,2
stosw ; |
mov [edi],bx ; |
add edi,2 ;----
loop @b
mov dword[edi],-1 ; < - end mark
mov [culling_flag],0
mov esp,ebp
pop ebp
ret
generate_object3: ; heart
;locals
; counter dw ?
; sin dd ?
; cos dd ?
;endl
.counter equ word[ebp-2]
.sin equ dword[ebp-6]
.cos equ dword[ebp-10]
.sin2 equ dword[ebp-14]
.cos2 equ dword[ebp-18]
.piD180m3 equ dword[ebp-22]
.cD2 equ word[ebp-24]
push ebp
mov ebp,esp
sub esp,24
fninit
mov edi,[points_ptr]
xor eax,eax
; init seed -> eight 3d points
mov dword[edi],2.0
add edi,4
stosd
stosd
mov dword[edi],2.0
mov dword[edi+4],-0.5
add edi,8
stosd
mov dword[edi],1.5
mov dword[edi+4],-1.5
add edi,8
stosd
mov dword[edi],1.0
mov dword[edi+4],-2.0
add edi,8
stosd
stosd
mov dword[edi],-2.5
add edi,4
stosd
mov [points_count_var],5
mov ecx,1
.next: ; calc angle and rotate seed 4 points
mov .counter,cx
mov ebx,[points_ptr]
fld [piD180]
fimul .counter
fsincos
fstp .sin
fstp .cos
.rotor: ; next 4
; rotary y
fld dword[ebx] ; x
fld .sin
fmul dword[ebx+8] ; z * sinbeta
fchs
fld .cos
fmul dword[ebx] ; x * cosbeta
faddp
fidiv [i3]
fstp dword[edi] ; new x
fmul .sin ; old x * sinbeta
fld .cos
fmul dword[ebx+8] ; z * cosbeta
faddp
fstp dword[edi+8] ; new z
fld dword[ebx+4] ;y
fstp dword[edi+4]
.end_rot:
add edi,12
add ebx,12
mov esi,[points_ptr]
add esi,12*5
cmp ebx,esi ;real_points + (12*5)
jl .rotor
add [points_count_var],5
add cx,18
cmp cx,(18*21)+1
jle .next
;last points
xor eax,eax
mov dword[edi],0.22
mov dword[edi+4],0.77
mov dword[edi+8],1.25
add edi,12
mov dword[edi],0.22
mov dword[edi+4],0.77
mov dword[edi+8],-1.25
add edi,12
stosd
add [points_count_var],2
; init triangles list
mov edi,[triangles_ptr]
mov ax,5
mov bx,5+5
mov [triangles_count_var],204
mov cx,100
@@:
stosw ;----
mov [edi],bx ; |
add edi,2 ; |
inc ax ; |
stosw ; |repeat
mov [edi],bx ; |
inc bx
add edi,2
stosw ; |
mov [edi],bx ; |
add edi,2 ;----
loop @b
mov ax,5
mov bx,[points_count_var]
sub bx,2
mov dl,2
.nx:
mov cx,5
add [triangles_count_var],cx
@@:
stosw
add ax,5
stosw
mov word[edi],bx
add edi,2
loop @b
cmp dl,1
je @f
inc bx
jmp .lab
@@:
dec bx
.lab:
mov cx,5
add [triangles_count_var],cx
@@:
stosw
add ax,5
stosw
mov word[edi],bx
add edi,2
loop @b
dec dl
or dl,dl
jnz .nx
sub ax,25
stosw
sub ax,50
stosw
mov word[edi],bx
add edi,2
stosw
add ax,50
stosw
inc bx
mov word[edi],bx
add edi,2
add [triangles_count_var],2
mov dword[edi],-1 ; < - end mark
mov [culling_flag],0
mov esp,ebp
pop ebp
ret

View File

@ -0,0 +1,609 @@
;------- Big thanks to majuma (www.majuma.xt.pl) for absolutelly great--
;------- 13h mode demos ------------------------------------------------
bump_triangle:
;------------------in - eax - x1 shl 16 + y1 -----------
;---------------------- ebx - x2 shl 16 + y2 -----------
;---------------------- ecx - x3 shl 16 + y3 -----------
;---------------------- edx - pointer to bump map ------
;---------------------- esi - pointer to environment map
;---------------------- edi - pointer to screen buffer--
;---------------------- stack : bump coordinates--------
;---------------------- environment coordinates-
.b_x1 equ ebp+4 ; procedure don't save registers !!!
.b_y1 equ ebp+6 ; each coordinate as word
.b_x2 equ ebp+8
.b_y2 equ ebp+10
.b_x3 equ ebp+12
.b_y3 equ ebp+14
.e_x1 equ ebp+16
.e_y1 equ ebp+18
.e_x2 equ ebp+20
.e_y2 equ ebp+22
.e_x3 equ ebp+24
.e_y3 equ ebp+26
.t_bmap equ dword[ebp-4]
.t_emap equ dword[ebp-8]
.x1 equ word[ebp-10]
.y1 equ word[ebp-12]
.x2 equ word[ebp-14]
.y2 equ word[ebp-16]
.x3 equ word[ebp-18]
.y3 equ word[ebp-20]
.dx12 equ dword[ebp-24]
.dbx12 equ dword[ebp-28]
.dby12 equ dword[ebp-32]
.dex12 equ dword[ebp-36]
.dey12 equ dword[ebp-40]
.dx13 equ dword[ebp-44]
.dbx13 equ dword[ebp-48]
.dby13 equ dword[ebp-52]
.dex13 equ dword[ebp-56]
.dey13 equ dword[ebp-60]
.dx23 equ dword[ebp-64]
.dbx23 equ dword[ebp-68]
.dby23 equ dword[ebp-72]
.dex23 equ dword[ebp-76]
.dey23 equ dword[ebp-80]
.cx1 equ dword[ebp-84] ; current variables
.cx2 equ dword[ebp-88]
.cbx1 equ dword[ebp-92]
.cbx2 equ dword[ebp-96]
.cby1 equ dword[ebp-100]
.cby2 equ dword[ebp-104]
.cex1 equ dword[ebp-108]
.cex2 equ dword[ebp-112]
.cey1 equ dword[ebp-116]
.cey2 equ dword[ebp-120]
mov ebp,esp
push edx ; store bump map
push esi ; store e. map
; sub esp,120
.sort3: ; sort triangle coordinates...
cmp ax,bx
jle .sort1
xchg eax,ebx
mov edx,dword[.b_x1]
xchg edx,dword[.b_x2]
mov dword[.b_x1],edx
mov edx,dword[.e_x1]
xchg edx,dword[.e_x2]
mov dword[.e_x1],edx
.sort1:
cmp bx,cx
jle .sort2
xchg ebx,ecx
mov edx,dword[.b_x2]
xchg edx,dword[.b_x3]
mov dword[.b_x2],edx
mov edx,dword[.e_x2]
xchg edx,dword[.e_x3]
mov dword[.e_x2],edx
jmp .sort3
.sort2:
push eax ; store triangle coords in variables
push ebx
push ecx
mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that
or edx,ebx ; if any *one* of them is negative a sign flag is raised
or edx,ecx
test edx,80000000h ; Check only X
jne .loop23_done
cmp .x1,SIZE_X ; {
jg .loop23_done
cmp .x2,SIZE_X ; This can be optimized with effort
jg .loop23_done
cmp .x3,SIZE_X
jg .loop23_done ; {
mov bx,.y2 ; calc delta 12
sub bx,.y1
jnz .bt_dx12_make
mov ecx,5
xor edx,edx
@@:
push edx ;dword 0
loop @b
jmp .bt_dx12_done
.bt_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx12,eax
push eax
mov ax,word[.b_x2]
sub ax,word[.b_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dbx12,eax
push eax
mov ax,word[.b_y2]
sub ax,word[.b_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dby12,eax
push eax
mov ax,word[.e_x2]
sub ax,word[.e_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dex12,eax
push eax
mov ax,word[.e_y2]
sub ax,word[.e_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dey12,eax
push eax
.bt_dx12_done:
mov bx,.y3 ; calc delta13
sub bx,.y1
jnz .bt_dx13_make
mov ecx,5
xor edx,edx
@@:
push edx ;dword 0
loop @b
jmp .bt_dx13_done
.bt_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx13,eax
push eax
mov ax,word[.b_x3]
sub ax,word[.b_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dbx13,eax
push eax
mov ax,word[.b_y3]
sub ax,word[.b_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dby13,eax
push eax
mov ax,word[.e_x3]
sub ax,word[.e_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dex13,eax
push eax
mov ax,word[.e_y3]
sub ax,word[.e_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dey13,eax
push eax
.bt_dx13_done:
mov bx,.y3 ; calc delta23
sub bx,.y2
jnz .bt_dx23_make
mov ecx,5
xor edx,edx
@@:
push edx ;dword 0
loop @b
jmp .bt_dx23_done
.bt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx23,eax
push eax
mov ax,word[.b_x3]
sub ax,word[.b_x2]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dbx23,eax
push eax
mov ax,word[.b_y3]
sub ax,word[.b_y2]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dby23,eax
push eax
mov ax,word[.e_x3]
sub ax,word[.e_x2]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dex23,eax
push eax
mov ax,word[.e_y3]
sub ax,word[.e_y2]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dey23,eax
push eax
; sub esp,40
.bt_dx23_done:
movsx eax,.x1
shl eax,ROUND
; mov .cx1,eax
; mov .cx2,eax
push eax
push eax
movsx eax,word[.b_x1]
shl eax,ROUND
; mov .cbx1,eax
; mov .cbx2,eax
push eax
push eax
movsx eax,word[.b_y1]
shl eax,ROUND
; mov .cby1,eax
; mov .cby2,eax
push eax
push eax
movsx eax,word[.e_x1]
shl eax,ROUND
;mov .cex1,eax
;mov .cex2,eax
push eax
push eax
movsx eax,word[.e_y1]
shl eax,ROUND
;mov .cey1,eax
;mov .cey2,eax
push eax
push eax
movzx ecx,.y1
cmp cx,.y2
jge .loop12_done
.loop12:
call .call_bump_line
mov eax,.dx13
add .cx1,eax
mov eax,.dx12
add .cx2,eax
mov eax,.dbx13
add .cbx1,eax
mov eax,.dbx12
add .cbx2,eax
mov eax,.dby13
add .cby1,eax
mov eax,.dby12
add .cby2,eax
mov eax,.dex13
add .cex1,eax
mov eax,.dex12
add .cex2,eax
mov eax,.dey13
add .cey1,eax
mov eax,.dey12
add .cey2,eax
inc ecx
cmp cx,.y2
jl .loop12
.loop12_done:
movzx ecx,.y2
cmp cx,.y3
jge .loop23_done
movzx eax,.x2
shl eax,ROUND
mov .cx2,eax
movzx eax,word[.b_x2]
shl eax,ROUND
mov .cbx2,eax
movzx eax,word[.b_y2]
shl eax,ROUND
mov .cby2,eax
movzx eax,word[.e_x2]
shl eax,ROUND
mov .cex2,eax
movzx eax,word[.e_y2]
shl eax,ROUND
mov .cey2,eax
.loop23:
call .call_bump_line
mov eax,.dx13
add .cx1,eax
mov eax,.dx23
add .cx2,eax
mov eax,.dbx13
add .cbx1,eax
mov eax,.dbx23
add .cbx2,eax
mov eax,.dby13
add .cby1,eax
mov eax,.dby23
add .cby2,eax
mov eax,.dex13
add .cex1,eax
mov eax,.dex23
add .cex2,eax
mov eax,.dey13
add .cey1,eax
mov eax,.dey23
add .cey2,eax
inc ecx
cmp cx,.y3
jl .loop23
.loop23_done:
mov esp,ebp
ret 24
.call_bump_line:
; push ebp
; push ecx
pushad
push .t_emap
push .t_bmap
push .cey2
push .cex2
push .cey1
push .cex1
push .cby2
push .cbx2
push .cby1
push .cbx1
push ecx
mov eax,.cx1
sar eax,ROUND
mov ebx,.cx2
sar ebx,ROUND
call bump_line
popad
ret
bump_line:
;--------------in: eax - x1
;-------------- ebx - x2
;-------------- edi - pointer to screen buffer
;stack - another parameters :
.y equ dword [ebp+4]
.bx1 equ dword [ebp+8] ; ---
.by1 equ dword [ebp+12] ; |
.bx2 equ dword [ebp+16] ; |
.by2 equ dword [ebp+20] ; |> bump and env coords
.ex1 equ dword [ebp+24] ; |> shifted shl ROUND
.ey1 equ dword [ebp+28] ; |
.ex2 equ dword [ebp+32] ; |
.ey2 equ dword [ebp+36] ; ---
.bmap equ dword [ebp+40]
.emap equ dword [ebp+44]
.x1 equ dword [ebp-4]
.x2 equ dword [ebp-8]
.dbx equ dword [ebp-12]
.dby equ dword [ebp-16]
.dex equ dword [ebp-20]
.dey equ dword [ebp-24]
.cbx equ dword [ebp-28]
.cby equ dword [ebp-32]
.cex equ dword [ebp-36]
.cey equ dword [ebp-40]
mov ebp,esp
mov ecx,.y
or ecx,ecx
jl .bl_end
cmp ecx,SIZE_Y
jge .bl_end
cmp eax,ebx
jl .bl_ok
je .bl_end
xchg eax,ebx
mov edx,.bx1
xchg edx,.bx2
mov .bx1,edx
mov edx,.by1
xchg edx,.by2
mov .by1,edx
mov edx,.ex1
xchg edx,.ex2
mov .ex1,edx
mov edx,.ey1
xchg edx,.ey2
mov .ey1,edx
.bl_ok:
push eax
push ebx ;store x1, x2
mov eax,SIZE_X*3
mov ebx,.y
mul ebx
mov ecx,.x1
lea ecx,[ecx*3]
add eax,ecx
add edi,eax
mov ecx,.x2
sub ecx,.x1
mov eax,.bx2 ; calc .dbx
sub eax,.bx1
cdq
idiv ecx
push eax
mov eax,.by2 ; calc .dby
sub eax,.by1
cdq
idiv ecx
push eax
mov eax,.ex2 ; calc .dex
sub eax,.ex1
cdq
idiv ecx
push eax
mov eax,.ey2 ; calc .dey
sub eax,.ey1
cdq
idiv ecx
push eax
push .bx1
push .by1
push .ex1
push .ey1
.draw:
; if TEX = SHIFTING ;bump drawing only in shifting mode
mov eax,.cby
sar eax,ROUND
shl eax,TEX_SHIFT
mov esi,.cbx
sar esi,ROUND
add esi,eax
mov ebx,esi
dec ebx
and ebx,TEXTURE_SIZE
add ebx,.bmap
movzx eax,byte [ebx]
mov ebx,esi
inc ebx
and ebx,TEXTURE_SIZE
add ebx,.bmap
movzx ebx,byte [ebx]
sub eax,ebx
mov ebx,esi
sub ebx,TEX_X
and ebx,TEXTURE_SIZE
add ebx,.bmap
movzx edx,byte [ebx]
mov ebx,esi
add ebx,TEX_X
and ebx,TEXTURE_SIZE
add ebx,.bmap
movzx ebx,byte [ebx]
sub edx,ebx
mov ebx,.cex ;.cex - current env map X
sar ebx,ROUND
add eax,ebx ; eax - modified x coord
mov ebx,.cey ;.cey - current env map y
sar ebx,ROUND
add edx,ebx ; edx - modified y coord
or eax,eax
jl .black
cmp eax,TEX_X
jg .black
or edx,edx
jl .black
cmp edx,TEX_Y
jg .black
shl edx,TEX_SHIFT
add edx,eax
lea edx,[edx*3]
add edx,.emap
mov eax,dword[edx]
jmp .put_pixel
.black:
xor eax,eax
.put_pixel:
stosd
dec edi
mov eax,.dbx
add .cbx,eax
mov eax,.dby
add .cby,eax
mov eax,.dex
add .cex,eax
mov eax,.dey
add .cey,eax
dec ecx
jnz .draw
; end if
.bl_end:
mov esp,ebp
ret 44

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,188 +0,0 @@
draw_triangle:
;----------in - eax - x1 shl 16 + y1
;------------- -ebx - x2 shl 16 + y2
;---------------ecx - x3 shl 16 + y3
;---------------edx - color 0x00rrggbb
;---------------edi - pointer to screen buffer
@ch3:
cmp ax,bx
jg @ch1
@ch4: ; sort parameters
cmp bx,cx
jg @ch2
jle @chEnd
@ch1:
xchg eax,ebx
jmp @ch4
@ch2:
xchg ebx,ecx
jmp @ch3
@chEnd:
mov dword[@y1],eax ; ....and store to user friendly variables
mov dword[@y2],ebx
mov dword[@y3],ecx
mov [@col],edx
mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that
or edx,ebx ; if any *one* of them is negative a sign flag is raised
or edx,ecx
test edx,80008000h ; Check both X&Y at once
jne @end_triangle
cmp [@x1],SIZE_X ; {
jg @end_triangle
cmp [@x2],SIZE_X ; This can be optimized with effort
jg @end_triangle
cmp [@x3],SIZE_X
jg @end_triangle ; }
shr eax,16
shr ebx,16
shr ecx,16
neg ax ; calculate delta 12
add ax,bx
cwde
shl eax,ROUND
cdq
mov bx,[@y2]
mov cx,[@y1]
sub bx,cx
;cmp ebx,0
jne @noZero1
mov [@dx12],0
jmp @yesZero1
@noZero1:
idiv ebx
mov [@dx12],eax
@yesZero1:
mov ax,[@x3] ; calculate delta 13
sub ax,[@x1]
cwde
shl eax,ROUND
cdq
mov bx,[@y3]
mov cx,[@y1]
sub bx,cx
;cmp ebx,0
jne @noZero2
mov [@dx13],0
jmp @yesZero2
@noZero2:
idiv ebx
mov [@dx13],eax
@yesZero2:
mov ax,[@x3] ; calculate delta 23 [dx23]
sub ax,[@x2]
cwde
shl eax,ROUND
cdq
mov bx,[@y3]
mov cx,[@y2]
sub bx,cx
;cmp ebx,0
jne @noZero3
mov [@dx23],0
jmp @yesZero3
@noZero3:
idiv ebx
mov [@dx23],eax
@yesZero3:
movzx eax,word[@x1] ; eax - xk1
shl eax,ROUND
mov ebx,eax ; ebx - xk2
movzx esi,word[@y1] ; esi - y
@next_line1:
mov ecx,eax ; ecx - x11
sar ecx,ROUND
mov edx,ebx ; edx - x12
sar edx,ROUND
cmp ecx,edx
jle @nochg
xchg ecx,edx
@nochg:
pusha
mov ebx,ecx
sub edx,ecx
mov ecx,edx
mov edx,esi
mov eax,[@col]
call @horizontal_line
popa
add eax,[@dx13]
add ebx,[@dx12]
inc esi
cmp si,[@y2]
jl @next_line1
movzx esi,word[@y2]
movzx ebx,word[@x2]
shl ebx,ROUND
@next_line2:
mov ecx,eax
sar ecx,ROUND
mov edx,ebx
sar edx,ROUND
cmp ecx,edx
jle @nochg1
xchg ecx,edx
@nochg1:
pusha
mov ebx,ecx
sub edx,ecx
mov ecx,edx
mov edx,esi
mov eax,[@col]
call @horizontal_line
popa
add eax,[@dx13]
add ebx,[@dx23]
inc esi
cmp si,[@y3]
jl @next_line2
@end_triangle:
ret
@horizontal_line:
;---------in
;---------eax - color of line, 0x00RRGGBB
;---------ebx - x1 - x position of line begin
;---------ecx - lenght of line
;---------edx - y position of line
;---------edi - pointer to buffer
jcxz @end_hor_l
; or edx,edx
; jl @end_hor_l
cmp edx,SIZE_Y
jg @end_hor_l
push eax
mov eax,SIZE_X*3
mul edx
add edi,eax ; calculate line begin adress
;add edi,ebx
;shl ebx,1
lea edi,[edi+ebx*2]
add edi,ebx
pop eax
cld
;mov dword[edi-3],0000FF00h
@ddraw: ; Drawing horizontally:
;push eax
stosd ; 4 bytes at a time
dec edi ; point to the 4th
;shr eax,16
;stosb
;pop eax
;pusha ; If you want to draw pixel-by-pixel
; mov eax,7 ; put image
; mov ebx,screen
; mov ecx,SIZE_X shl 16 + SIZE_Y
; mov edx,5 shl 16 + 20
; int 0x40
;popa
loop @ddraw
mov byte[edi],0 ; The last 4th will be reset
@end_hor_l:
ret

View File

@ -0,0 +1,205 @@
draw_triangle:
;----------in - eax - x1 shl 16 + y1
;------------- -ebx - x2 shl 16 + y2
;---------------ecx - x3 shl 16 + y3
;---------------edx - color 0x00rrggbb
;---------------edi - pointer to screen buffer
.col equ ebp-4 ;dd ?
.x1 equ ebp-6 ;dw ?
.y1 equ ebp-8 ;dw ?;+8
.x2 equ ebp-10 ;dw ?
.y2 equ ebp-12 ;dw ?
.x3 equ ebp-14 ;dw ?
.y3 equ ebp-16 ;dw ?;+16
.dx12 equ ebp-20 ; dd ?
.dx13 equ ebp-24 ; dd ?;+24
.dx23 equ ebp-28 ; dd ?
mov ebp,esp
; sub esp,28
push edx
.ch3:
cmp ax,bx
jg .ch1
.ch4: ; sort parameters
cmp bx,cx
jg .ch2
jle .chEnd
.ch1:
xchg eax,ebx
jmp .ch4
.ch2:
xchg ebx,ecx
jmp .ch3
.chEnd:
; mov dword[.y1],eax ; ..and store to user friendly variables
; mov dword[.y2],ebx
; mov dword[.y3],ecx
; mov [.col],edx
push eax
push ebx
push ecx
sub esp,12
mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that
or edx,ebx ; if any *one* of them is negative a sign flag is raised
or edx,ecx
test edx,80008000h ; Check both X&Y at once
jne .end_triangle
cmp word[.x1],SIZE_X ; {
jg .end_triangle
cmp word[.x2],SIZE_X ; This can be optimized with effort
jg .end_triangle
cmp word[.x3],SIZE_X
jg .end_triangle ; }
shr eax,16
shr ebx,16
shr ecx,16
neg ax ; calculate delta 12
add ax,bx
cwde
shl eax,ROUND
cdq
mov bx,[.y2]
mov cx,[.y1]
sub bx,cx
;cmp ebx,0
jne .noZero1
mov dword[.dx12],0
jmp .yesZero1
.noZero1:
idiv ebx
mov [.dx12],eax
.yesZero1:
mov ax,[.x3] ; calculate delta 13
sub ax,[.x1]
cwde
shl eax,ROUND
cdq
mov bx,[.y3]
mov cx,[.y1]
sub bx,cx
;cmp ebx,0
jne .noZero2
mov dword[.dx13],0
jmp .yesZero2
.noZero2:
idiv ebx
mov [.dx13],eax
.yesZero2:
mov ax,[.x3] ; calculate delta 23 [dx23]
sub ax,[.x2]
cwde
shl eax,ROUND
cdq
mov bx,[.y3]
mov cx,[.y2]
sub bx,cx
;cmp ebx,0
jne .noZero3
mov dword[.dx23],0
jmp .yesZero3
.noZero3:
idiv ebx
mov [.dx23],eax
.yesZero3:
movsx eax,word[.x1] ; eax - xk1 ;;;
shl eax,ROUND
mov ebx,eax ; ebx - xk2 ;;;
movsx esi,word[.y1] ; esi - y
.next_line1:
mov ecx,eax ; ecx - x11
sar ecx,ROUND
mov edx,ebx ; edx - x12
sar edx,ROUND
cmp ecx,edx
jle .nochg
xchg ecx,edx
.nochg:
pusha
mov ebx,ecx
sub edx,ecx
mov ecx,edx
mov edx,esi
mov eax,[.col]
call .horizontal_line
popa
add eax,[.dx13]
add ebx,[.dx12]
inc esi
cmp si,[.y2]
jl .next_line1
movzx esi,word[.y2]
movzx ebx,word[.x2]
shl ebx,ROUND
.next_line2:
mov ecx,eax
sar ecx,ROUND
mov edx,ebx
sar edx,ROUND
cmp ecx,edx
jle .nochg1
xchg ecx,edx
.nochg1:
pusha
mov ebx,ecx
sub edx,ecx
mov ecx,edx
mov edx,esi
mov eax,[.col]
call .horizontal_line
popa
add eax,[.dx13]
add ebx,[.dx23]
inc esi
cmp si,[.y3]
jl .next_line2
.end_triangle:
mov esp,ebp
ret
.horizontal_line:
;---------in
;---------eax - color of line, 0x00RRGGBB
;---------ebx - x1 - x position of line begin
;---------ecx - lenght of line
;---------edx - y position of line
;---------edi - pointer to buffer
jcxz .end_hor_l
; or edx,edx
; jl .end_hor_l
cmp edx,SIZE_Y
jg .end_hor_l
push eax
mov eax,SIZE_X*3
mul edx
add edi,eax ; calculate line begin adress
;add edi,ebx
;shl ebx,1
lea edi,[edi+ebx*2]
add edi,ebx
pop eax
cld
;mov dword[edi-3],0000FF00h
dec ecx
jecxz .last_pix
.ddraw: ; Drawing horizontally:
;push eax
stosd ; 4 bytes at a time
dec edi ; point to the 4th
loop .ddraw
.last_pix:
stosw
shr eax,16
stosb
; mov byte[edi],0 ; The last 4th will be reset
.end_hor_l:
ret

View File

@ -1,762 +0,0 @@
;
; application : Flag - Polonia in Tertio Millenium - wavy shading rotary area
; compiler : FASM
; system : MenuetOS
; author : macgub
; email : macgub3@wp.pl
; web : www.menuet.xt.pl
; Fell free to use this intro in your own distribution of MenuetOS.
SIZE_X equ 220
SIZE_Y equ 260
TIMEOUT equ 1
ROUND equ 12
points_count equ 50
triangles_count equ 54
use32
org 0x0
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd I_END ; memory for app
dd I_END ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
START: ; start of execution
call draw_window
; call generate_map
still:
mov eax,23 ; wait here for event with timeout
mov ebx,TIMEOUT
cmp [speed_flag],0xff
jne speed_skip
mov eax,11
speed_skip:
int 0x40
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
jmp noclose
red: ; redraw
call draw_window
jmp noclose
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp noclose
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne shad_button
mov eax,-1 ; close this program
int 0x40
shad_button:
cmp ah,2
jne speed_button
not [shad_flag] ; set shadow / flag mode
speed_button:
cmp ah,3
jne noclose
not [speed_flag]
noclose:
call calculate_angle ; calculates sinus and cosinus
call generate_map
call copy_points
call rotate_points
call translate_points ; translate from 3d to 2d
call clrscr ; clear the screen
call sort_triangles
call draw_triangles ; draw all triangles from the list
mov eax,7 ; put image
mov ebx,screen
mov ecx,SIZE_X shl 16 + SIZE_Y
mov edx,5 shl 16 + 20
int 0x40
jmp still
generate_map:
finit
mov edi,points
xor ebx,ebx ;z
again_gen1:
mov eax,70 ;x
again_gen:
mov word[edi],ax
mov word[edi+4],bx
fild word[edi]
fidiv [i20]
fadd [current_angle]
fsin
fimul [i20]
fiadd [i75]
fistp word [edi+2]
; fild word[edi] ;another map generation
; fisub [i100]
; fidiv [i75]
; fmul st,st0
; fild word[edi+4]
; fisub [i50]
; fidiv [i20]
; fmul st,st0
; faddp
; fsqrt
; fadd [current_angle]
; fsin
; fimul [i20]
; fiadd [i75]
; fistp word[edi+2]
add ax,10
add edi,6
cmp ax,170
jne again_gen
add bx,20
cmp bx,100
jne again_gen1
mov dword[edi],0xffffffff
ret
i20 dw 20
i50 dw 50
i75 dw 75
i100 dw 100
sort_triangles:
mov esi,triangles
mov edi,triangles_with_z
mov ebp,points_rotated
make_triangle_with_z: ;makes list with triangles and z position
xor eax,eax
mov ax,word[esi]
shl eax,1
mov ebx,eax
shl eax,1
add eax,ebx
push ebp
add ebp,eax
xor ecx,ecx
mov cx,word[ebp+4]
pop ebp
xor eax,eax
mov ax,word[esi+2]
shl eax,1
mov ebx,eax
shl eax,1
add eax,ebx
push ebp
add ebp,eax
add cx,word[ebp+4]
pop ebp
xor eax,eax
mov ax,word[esi+4]
shl eax,1
mov ebx,eax
shl eax,1
add eax,ebx
push ebp
add ebp,eax
add cx,word[ebp+4]
pop ebp
mov ax,cx
cwd
idiv [i3]
cld
movsd ; store vertex coordinates
movsw
stosw ; middle vertex coordinate 'z' in triangles_with_z list
cmp dword[esi],0xffffffff
jne make_triangle_with_z
movsd ; copy end mark
;macro sort
mov [sort_flag],1
next_booble:
mov esi,triangles_with_z ;sort list triangles_with_z booble metod
cmp [sort_flag],0
je end_sort
mov [sort_flag],0
check_and_check:
; cmp dword[esi],0xffffffff
; je next_booble
cmp dword[esi+8],0xffffffff
je next_booble
mov ax,word[esi+6]
cmp ax,word[esi+14]
jge no_chg_pos
mov eax,dword[esi]
mov ebx,dword[esi+4]
xchg eax,dword[esi+8]
xchg ebx,dword[esi+12]
mov dword[esi],eax
mov dword[esi+4],ebx ; sort_flag=1 if change occured
mov [sort_flag],1
no_chg_pos:
add esi,8
jmp check_and_check ;check end mark end if greater
end_sort:
; translate triangles_with_z to sorted_triangles
mov esi,triangles_with_z
mov edi,sorted_triangles
again_copy:
movsd
movsw
add esi,2
cmp dword[esi],0xffffffff
jne again_copy
movsd ; copy end mark too
ret
sort_flag db 0
clrscr:
mov edi,screen
mov ecx,SIZE_X*SIZE_Y*3/4
xor eax,eax
cld
rep stosd
ret
calculate_angle:
finit
fldpi
fidiv [i180]
fimul [angle_counter]
fst [current_angle]
fld st
fidiv [i2]
fsincos
fstp [singamma]
fstp [cosgamma]
fsincos
fstp [sinbeta]
fstp [cosbeta]
inc [angle_counter]
cmp [angle_counter],360
jne end_calc_angle
mov [angle_counter],0
end_calc_angle:
ret
i180 dw 90
i2 dw 2
rotate_points:
finit ; y axle rotate
mov ebx,points_rotated
again_r:
mov ax,word[ebx] ;x
sub ax,[xo]
mov [xsub],ax
mov ax,word[ebx+4] ;z
sub ax,[zo]
mov [zsub],ax
fld [sinbeta]
fimul [zsub]
fchs
fld [cosbeta]
fimul [xsub]
faddp
fiadd [xo]
fistp word[ebx] ;x
fld [sinbeta]
fimul [xsub]
;fchs
fld [cosbeta]
fimul [zsub]
faddp
fiadd [zo]
fistp word[ebx+4] ;z
mov ax,word[ebx+2] ;y ; z axle rotate
sub ax,[yo]
mov [ysub],ax
mov ax,word[ebx] ;x
sub ax,[xo]
mov [xsub],ax
fld [singamma]
fimul[ysub]
fld [cosgamma]
fimul [xsub]
faddp
fiadd [xo]
fistp word[ebx] ;x
fld [cosgamma]
fimul [ysub]
fld [singamma]
fimul [xsub]
fchs
faddp
fiadd [yo]
fistp word[ebx+2] ;y
add ebx,6
cmp dword[ebx],0xffffffff
jne again_r
ret
xsub dw ?
ysub dw ?
zsub dw ?
draw_triangles:
mov [tr_counter],1
mov ebp,points_rotated
; mov esi,triangles
mov esi,sorted_triangles
again_dts:
xor eax,eax
mov ax,word[esi]
shl eax,1
mov [dtpom],eax
shl eax,1
add eax,[dtpom]
push ebp
add ebp,eax
mov ax,word[ebp]
mov [xx1],ax
mov ax,word[ebp+2]
mov [yy1],ax
mov ax,word[ebp+4]
mov [zz1],ax
pop ebp
xor eax,eax
mov ax,word[esi+2]
shl eax,1
mov [dtpom],eax
shl eax,1
add eax,[dtpom]
push ebp
add ebp,eax
mov ax,word[ebp]
mov [xx2],ax
mov ax,word[ebp+2]
mov [yy2],ax
mov ax,word[ebp+4]
mov [zz2],ax
pop ebp
xor eax,eax
mov ax,word[esi+4]
shl eax,1
mov [dtpom],eax
shl eax,1
add eax,[dtpom]
push ebp
add ebp,eax
mov ax,word[ebp]
mov [xx3],ax
mov ax,word[ebp+2]
mov [yy3],ax
mov ax,word[ebp+4]
mov [zz3],ax
pop ebp
push ebp
push esi
macro set_flag
{
mov edx,0x00ffffff
inc [tr_counter]
cmp [tr_counter],triangles_count/2
jl skip_red
set_red:
mov edx,0x00ff0000
skip_red:
}
mov ax,[zz1]
add ax,[zz2]
add ax,[zz3]
cwd
idiv [i3]
sub ax,100 ;77
; shl ax,1
neg al
xor edx,edx
mov dh,al ;set color according to z position
mov dl,al
; push dx
; shl edx,8
; pop dx
cmp [shad_flag],0
je skip_col
set_flag
skip_col:
mov ax,[xx1]
shl eax,16
mov ax,[yy1]
mov bx,[xx2]
shl ebx,16
mov bx,[yy2]
mov cx,[xx3]
shl ecx,16
mov cx,[yy3]
mov edi,screen
call draw_triangle
pop esi
pop ebp
add esi,6
cmp dword[esi],0xffffffff
jne again_dts
ret
i3 dw 3
tr_counter dw 0
dtpom dd ?
xx1 dw ?
yy1 dw ?
zz1 dw ?
xx2 dw ?
yy2 dw ?
zz2 dw ?
xx3 dw ?
yy3 dw ?
zz3 dw ?
translate_points:
finit
mov ebx,points_rotated
again_trans:
fild word[ebx+4] ;z1
fmul [sq]
fld st
fiadd word[ebx] ;x1
fistp word[ebx]
fchs
fiadd word[ebx+2] ;y1
fistp word[ebx+2] ;y1
add ebx,6
cmp dword[ebx],0xffffffff
jne again_trans
ret
copy_points:
mov esi,points
mov edi,points_rotated
mov ecx,points_count*3+2
cld
rep movsw
ret
draw_triangle:
;----------in - eax - x1 shl 16 + y1
;------------- -ebx - x2 shl 16 + y2
;---------------ecx - x3 shl 16 + y3
;---------------edx - color 0x00rrggbb
;---------------edi - pointer to screen buffer
@ch3:
cmp ax,bx
jg @ch1
@ch4: ; sort parameters
cmp bx,cx
jg @ch2
jle @chEnd
@ch1:
xchg eax,ebx
jmp @ch4
@ch2:
xchg ebx,ecx
jmp @ch3
@chEnd:
mov [@y1],ax ; ....and store to user friendly variables
mov [@y2],bx
mov [@y3],cx
shr eax,16
shr ebx,16
shr ecx,16
mov [@x1],ax
mov [@x2],bx
mov [@x3],cx
mov [@col],edx
cmp [@y1],0
jl @end_triangle
cmp [@y2],0
jl @end_triangle
cmp [@y3],0
jl @end_triangle
cmp [@x1],0
jl @end_triangle
cmp [@x2],0
jl @end_triangle
cmp [@x3],0
jl @end_triangle
cmp [@y1],SIZE_Y
jg @end_triangle
cmp [@y2],SIZE_Y
jg @end_triangle
cmp [@y3],SIZE_Y
jg @end_triangle
cmp [@x1],SIZE_X
jg @end_triangle
cmp [@x2],SIZE_X
jg @end_triangle
cmp [@x3],SIZE_X
jg @end_triangle
neg ax ; calculate delta 12
add ax,bx
cwde
shl eax,ROUND
cdq
mov bx,[@y2]
mov cx,[@y1]
sub ebx,ecx
cmp ebx,0
jne @noZero1
mov [@dx12],0
jmp @yesZero1
@noZero1:
idiv ebx
mov [@dx12],eax
@yesZero1:
mov ax,[@x3] ; calculate delta 13
sub ax,[@x1]
cwde
shl eax,ROUND
cdq
xor ebx,ebx
xor ecx,ecx
or bx,[@y3]
or cx,[@y1]
sub ebx,ecx
cmp ebx,0
jne @noZero2
mov [@dx13],0
jmp @yesZero2
@noZero2:
idiv ebx
mov [@dx13],eax
@yesZero2:
mov ax,[@x3] ; calculate delta 23 [dx23]
sub ax,[@x2]
cwde
shl eax,ROUND
cdq
xor ebx,ebx
xor ecx,ecx
or bx,[@y3]
or cx,[@y2]
sub ebx,ecx
cmp ebx,0
jne @noZero3
mov [@dx23],0
jmp @yesZero3
@noZero3:
idiv ebx
mov [@dx23],eax
@yesZero3:
xor eax,eax ;eax - xk1
or ax,[@x1]
shl eax,ROUND
mov ebx,eax ; ebx - xk2
xor esi,esi ; esi - y
or si,[@y1]
@next_line1:
mov ecx,eax ; ecx - x11
sar ecx,ROUND
mov edx,ebx ;edx - x12
sar edx,ROUND
cmp ecx,edx
jle @nochg
xchg ecx,edx
@nochg:
pusha
mov ebx,ecx
sub edx,ecx
mov ecx,edx
mov edx,esi
mov eax,[@col]
call @horizontal_line
popa
add eax,[@dx13]
add ebx,[@dx12]
inc esi
cmp si,[@y2]
jl @next_line1
xor esi,esi
or si,[@y2]
xor ebx,ebx
mov bx,[@x2]
shl ebx,ROUND
@next_line2:
mov ecx,eax
sar ecx,ROUND
mov edx,ebx
sar edx,ROUND
cmp ecx,edx
jle @nochg1
xchg ecx,edx
@nochg1:
pusha
mov eax,[@col]
mov ebx,ecx
sub edx,ecx
mov ecx,edx
mov edx,esi
call @horizontal_line
popa
add eax,[@dx13]
add ebx,[@dx23]
inc esi
cmp si,[@y3]
jl @next_line2
@end_triangle:
ret
@col dd ?
@y1 dw ?
@x1 dw ?
@y2 dw ?
@x2 dw ?
@y3 dw ?
@x3 dw ?
@dx12 dd ?
@dx13 dd ?
@dx23 dd ?
@horizontal_line:
;---------in
;---------eax - color of line, 0x00RRGGBB
;---------ebx - x1 - x position of line begin
;---------ecx - lenght of line
;---------edx - y position of line
;---------edi - pointer to buffer
jcxz @end_hor_l
push eax
mov eax,SIZE_X*3
mul edx
add edi,eax ; calculate line begin adress
add edi,ebx
shl ebx,1
add edi,ebx
pop eax
cld
@ddraw:
push eax
stosw
shr eax,16
stosb
pop eax
loop @ddraw
@end_hor_l:
ret
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+SIZE_X+20 ; [x start] *65536 + [x size]
mov ecx,100*65536+SIZE_Y+30 ; [y start] *65536 + [y size]
mov edx,0x04000000 ; color of work area RRGGBB,8->color gl
mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x005080d0 ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x20ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
; flag color button
mov eax,8 ; function 8 : define and draw button
mov ebx,(SIZE_X-35)*65536+12 ; [x start] *65536 + [x size]
mov ecx,5*65536+12 ; [y start] *65536 + [y size]
mov edx,2 ; button id
mov esi,0x64504A ; button color RRGGBB
int 0x40
; speed button
mov eax,8 ; function 8 : define and draw button
mov ebx,(SIZE_X-53)*65536+12 ; [x start] *65536 + [x size]
mov ecx,5*65536+12 ; [y start] *65536 + [y size]
mov edx,3 ; button id
mov esi,0x64504A ; button color RRGGBB
int 0x40
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA AREA
angle_counter dw 0
sq dd 0.707
xo dw 110 ;87
zo dw 0
yo dw 125
shad_flag db 0
speed_flag db 0
triangles:
dw 0,1,10, 10,11,1, 1,2,11, 11,12,2, 2,3,12, 12,13,3, 3,4,13, 13,14,4, 4,5,14
dw 14,15,5, 5,6,15, 15,16,6, 6,7,16, 16,17,7, 7,8,17, 17,18,8, 8,9,18, 18,19,9
dw 10,11,20, 20,21,11, 11,12,21, 21,22,12, 12,13,22, 22,23,13, 13,14,23
dw 23,24,14, 14,15,24, 24,25,15, 15,16,25, 25,26,16, 16,17,26, 26,27,17
dw 17,18,27, 27,28,18, 18,19,28, 28,29,19, 20,21,30, 30,31,21, 21,22,31
dw 31,32,22, 22,23,32, 32,33,23, 23,24,33, 33,34,24, 24,25,34, 34,35,25
dw 25,26,35, 35,36,26, 26,27,36, 36,37,27, 27,28,37, 37,38,28, 28,29,38
dw 38,39,29
dd 0xffffffff ;<- end marker
labelt:
db '3d wavy rotaring area'
labellen:
sinbeta rd 1
cosbeta rd 1
singamma rd 1
cosgamma rd 1
current_angle rd 1
points rw points_count*3 + 2
points_rotated rw points_count*3 + 2
triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position
sorted_triangles rw triangles_count*3 + 2
screen rb SIZE_X * SIZE_Y * 3 ; screen buffer
memStack rb 1000 ;memory area for stack
I_END:

View File

@ -1,10 +1,6 @@
CATMULL_SHIFT equ 16
fill_Z_buffer:
mov eax,0x70000000
mov edi,Z_buffer
mov ecx,SIZE_X*SIZE_Y
rep stosd
ret
flat_triangle_z:
; procedure drawing triangle with Z cordinate interpolation ------
; (Catmull alghoritm)--------------------------------------------
@ -30,15 +26,24 @@ flat_triangle_z:
.y3 equ word[ebp-16]
.dx12 equ dword[ebp-20]
.dz12 equ dword[ebp-24]
.dx13 equ dword[ebp-28]
.dz13 equ dword[ebp-32]
;.dz12 equ dword[ebp-24]
.dx13 equ dword[ebp-24]
.dz13 equ dword[ebp-28]
.dz12 equ dword[ebp-32]
;.dz13 equ dword[ebp-32]
.dx23 equ dword[ebp-36]
.dz23 equ dword[ebp-40]
.zz1 equ dword[ebp-44]
.zz2 equ dword[ebp-48]
.dz13M equ [ebp-40]
.dz23 equ dword[ebp-44]
.zz1 equ dword[ebp-48]
.zz2 equ dword[ebp-52]
.zz2M equ qword[ebp-52]
.dz12M equ qword[ebp-32]
.dz23M equ qword[ebp-44]
;if Ext>=MMX
; emms
;end if
mov ebp,esp
push edx ; store edx in variable .col
.sort2:
cmp ax,bx
@ -82,7 +87,7 @@ flat_triangle_z:
; jle @f
; jmp .ft_loop2_end
;@@:
sub esp,32
sub esp,52-12
mov bx,.y2 ; calc delta 12
sub bx,.y1
@ -113,6 +118,7 @@ flat_triangle_z:
jnz .ft_dx13_make
mov .dx13,0
mov .dz13,0
mov dword .dz13M,0
jmp .ft_dx13_done
.ft_dx13_make:
mov ax,.x3
@ -131,6 +137,7 @@ flat_triangle_z:
cdq
idiv ebx
mov .dz13,eax
mov dword .dz13M,eax
.ft_dx13_done:
mov bx,.y3 ; calc delta 23
sub bx,.y2
@ -164,6 +171,9 @@ flat_triangle_z:
movsx eax,.x1
shl eax,ROUND ; eax - x1
mov ebx,eax ; ebx - x2
;if Ext>=MMX
; movq mm0,.zz2M
;end if
mov cx,.y1
cmp cx,.y2
jge .ft_loop1_end
@ -177,18 +187,28 @@ flat_triangle_z:
push bx ; x2
sar eax,ROUND
push ax ; x1
;if Ext>=MMX
; sub esp,8
; movq [esp],mm0
;else
push .zz2 ; z2 shl CATMULL_SHIFT
push .zz1 ; z1 shl CATMULL_SHIFT
;end if
call flat_line_z
popad
add eax,.dx13
add ebx,.dx12
;if Ext>=MMX
; paddd mm0,.dz12M
;else
mov edx,.dz13
add .zz1,edx
mov edx,.dz12
add .zz2,edx
;end if
inc cx
cmp cx,.y2
jl .ft_loop1
@ -199,6 +219,13 @@ flat_triangle_z:
mov .zz2,edx
movsx ebx,.x2
shl ebx,ROUND
;if Ext>=MMX
; movq mm0,.zz2M
;; push .dz13 ; exchange
;; pop .dz12
;; push .dz23 ; exchange
;; pop .dz13
;end if
mov cx,.y2
cmp cx,.y3
jge .ft_loop2_end
@ -211,18 +238,32 @@ flat_triangle_z:
push bx
sar eax,ROUND
push ax ; x1
;if Ext>=MMX
; sub esp,8
; movq [esp],mm0
;else
push .zz2 ; z2 shl CATMULL_SHIFT
push .zz1 ; z1 shl CATMULL_SHIFT
;end if
call flat_line_z
popad
add eax,.dx13
add ebx,.dx23
;if Ext>=MMX
; paddd mm0,.dz23M
;else
mov edx,.dz13
add .zz1,edx
mov edx,.dz23
add .zz2,edx
; mov edx,.dz13
; add .zz1,edx
; mov edx,.dz12
; add .zz2,edx
;end if
inc cx
cmp cx,.y3
jl .ft_loop2
@ -250,6 +291,9 @@ flat_line_z:
mov ax,.y
or ax,ax
jl .fl_quit
;; mov bx,[size_y]
;; dec bx
cmp ax,[size_y]
cmp ax,SIZE_Y-1
jg .fl_quit
@ -274,6 +318,8 @@ flat_line_z:
xchg edx,.z2
mov .z1,edx
.fl_ok:
;; mov bx,[size_x]
;; dec bx
cmp .x1,SIZE_X-1
jg .fl_quit
cmp .x2,0
@ -320,23 +366,31 @@ flat_line_z:
mov eax,.col
mov ebx,.z1 ; ebx : curr. z
mov edx,.dz
dec ecx
jecxz .draw_last
.ddraw:
;pushad
;show
;popad
cmp ebx,dword[esi]
jge .skip
jge @f
stosd
dec edi
mov dword[esi],ebx
jmp .no_skip
.skip:
@@:
add edi,3
.no_skip:
add esi,4
add ebx,edx
loop .ddraw
.draw_last:
cmp ebx,dword[esi]
jge .fl_quit
stosw
shr eax,16
stosb
mov dword[esi],ebx
.fl_quit:
mov esp,ebp
ret 18

View File

@ -1,6 +1,7 @@
ROUND equ 8
CATMULL_SHIFT equ 8
gouraud_triangle_z:
;----procedure drawing gouraud triangle with z coordinate
;----interpolation ( Catmull alghoritm )-----------------
;------------------in - eax - x1 shl 16 + y1 ------------
@ -50,14 +51,30 @@ gouraud_triangle_z:
.dc23g equ dword[ebp-68]
.dc23b equ dword[ebp-72]
.c1r equ dword[ebp-76]
.c1g equ dword[ebp-80]
.c1b equ dword[ebp-84]
.c2r equ dword[ebp-88]
.c2g equ dword[ebp-92]
.c2b equ dword[ebp-96]
.zz1 equ dword[ebp-100]
.zz2 equ dword[ebp-104]
.zz1 equ dword[ebp-76]
.c1r equ dword[ebp-80]
.c1g equ dword[ebp-84]
.c1b equ dword[ebp-88]
.zz2 equ dword[ebp-92]
.c2r equ dword[ebp-96]
.c2g equ dword[ebp-100]
.c2b equ dword[ebp-104]
;.zz1 equ dword[ebp-100]
;.zz2 equ dword[ebp-104]
.c1bM equ [ebp-88]
.c2bM equ [ebp-104]
.c1rM equ [ebp-80]
.c2rM equ [ebp-96]
.dc23bM equ [ebp-72]
.dc13bM equ [ebp-52]
.dc12bM equ [ebp-32]
.dc12rM equ [ebp-24]
.dc13rM equ [ebp-44]
.dc23rM equ [ebp-64]
if Ext=MMX
emms
end if
mov ebp,esp
; sub esp,84
@ -141,7 +158,7 @@ gouraud_triangle_z:
idiv ebx
; mov .dc12g,eax
push eax
mov ax,word[.col2b]
mov ax,word[.col2b] ;;---
sub ax,word[.col1b]
cwde
shl eax,ROUND
@ -323,7 +340,21 @@ gouraud_triangle_z:
call gouraud_line_z
popad
if Ext >= MMX
movq mm0,.c1bM
paddd mm0,qword .dc13bM
movq .c1bM,mm0
movq mm1,.c2bM
paddd mm1,qword .dc12bM
movq .c2bM,mm1
movq mm0,.c1rM
paddd mm0,qword .dc13rM
movq .c1rM,mm0
movq mm1,.c2rM
paddd mm1,qword .dc12rM
movq .c2rM,mm1
else
mov edx,.dc13r
add .c1r,edx
mov edx,.dc13g
@ -336,11 +367,12 @@ gouraud_triangle_z:
add .c2g,edx
mov edx,.dc12b
add .c2b,edx
mov edx,.dz13
add .zz1,edx
mov edx,.dz12
add .zz2,edx
end if
add eax,.dx13
add ebx,.dx12
inc cx
@ -400,6 +432,21 @@ gouraud_triangle_z:
popad
if Ext >= MMX
movq mm0,.c1bM
paddd mm0,qword .dc13bM
movq .c1bM,mm0
movq mm1,.c2bM
paddd mm1,qword .dc23bM
movq .c2bM,mm1
movq mm0,.c1rM
paddd mm0,qword .dc13rM
movq .c1rM,mm0
movq mm1,.c2rM
paddd mm1,qword .dc23rM
movq .c2rM,mm1
else
mov edx,.dc13r
add .c1r,edx
mov edx,.dc13g
@ -416,7 +463,7 @@ gouraud_triangle_z:
add .zz1,edx
mov edx,.dz23
add .zz2,edx
end if
add eax,.dx13
add ebx,.dx23
inc cx
@ -443,13 +490,25 @@ gouraud_line_z:
.c2b equ ebp+24
.c2g equ ebp+26
.c2r equ ebp+28
.dz equ dword[ebp-4]
.dc_r equ dword[ebp-8]
.dc_b equ dword[ebp-8]
.dc_g equ dword[ebp-12]
.dc_b equ dword[ebp-14]
.cr equ dword[ebp-18]
.cg equ dword[ebp-22]
.cb equ dword[ebp-26]
.dc_r equ dword[ebp-16]
.c_z equ dword[ebp-20]
.cb equ dword[ebp-24]
.cg equ dword[ebp-28]
.cr equ dword[ebp-32]
;.cg2 equ dword[ebp-36]
.crM equ ebp-32
.cgM equ ebp-28
.cbM equ ebp-24
.dc_rM equ ebp-16
.dc_gM equ ebp-12
.dc_bM equ ebp-8
mov ebp,esp
mov ax,.y
@ -486,10 +545,10 @@ gouraud_line_z:
idiv ebx
push eax
mov ax,word[.c2r]
sub ax,word[.c1r]
mov ax,word[.c2b]
sub ax,word[.c1b]
cwde
shl eax,ROUND ; dc_r = c2r-c1r/x2-x1
shl eax,ROUND
cdq
idiv ebx
push eax
@ -502,15 +561,15 @@ gouraud_line_z:
idiv ebx
push eax
mov ax,word[.c2b]
sub ax,word[.c1b]
mov ax,word[.c2r]
sub ax,word[.c1r]
cwde
shl eax,ROUND
shl eax,ROUND ; dc_r = c2r-c1r/x2-x1
cdq
idiv ebx
push eax
cmp word[.x1],0
cmp word[.x1],0 ; clipping on function
jg @f
mov eax,.dz
movsx ebx,word[.x1]
@ -539,7 +598,7 @@ gouraud_line_z:
jl @f
mov word[.x2],SIZE_X
@@:
sub esp,12 ; calculate memory begin
sub esp,16 ; calculate memory begin
mov edx,SIZE_X ; in buffers
movzx eax,.y
mul edx
@ -556,6 +615,9 @@ gouraud_line_z:
sub cx,word[.x1]
movzx ecx,cx
mov ebx,.z1 ; ebx - currrent z shl CATMULL_SIFT
;if Ext >= SSE
; mov .cz,edx
;end if
mov edx,.dz ; edx - delta z
movzx eax,word[.c1r]
shl eax,ROUND
@ -566,9 +628,37 @@ gouraud_line_z:
movzx eax,word[.c1b]
shl eax,ROUND
mov .cb,eax
if Ext = MMX
; mov .c_z,edx
movd mm2,[.dc_bM] ; delta color blue MMX
movd mm3,[.cbM] ; current blue MMX
movq mm5,[.dc_rM]
movq mm4,[.crM]
pxor mm6,mm6
end if
.ddraw:
cmp ebx,dword[esi]
jge .skip
;if Ext = MMX
; movq mm0,mm3
; psrsq mm0,32
; movd ebx,mm0
;end if
cmp ebx,dword[esi] ; esi - z_buffer
jge @f ; edi - Screen buffer
if Ext = MMX
movq mm0,mm3 ; mm0, mm1 - temp registers
psrld mm0,ROUND
movq mm1,mm4
psrld mm1,ROUND
packssdw mm1,mm0
packuswb mm1,mm6
; movd [edi],mm1
movd eax,mm1
stosw
shr eax,16
stosb
else
mov eax,.cr
sar eax,ROUND
stosb
@ -578,21 +668,31 @@ gouraud_line_z:
mov eax,.cb
sar eax,ROUND
stosb
end if
mov dword[esi],ebx
;if Ext = NON
jmp .no_skip
.skip:
;end if
@@:
add edi,3
.no_skip:
add esi,4
;if Ext=NON
add ebx,edx
mov eax,.dc_r
add .cr,eax
;end if
if Ext=MMX
paddd mm3,mm2
paddd mm4,mm5
else
mov eax,.dc_g
add .cg,eax
mov eax,.dc_b
add .cb,eax
mov eax,.dc_r
add .cr,eax
end if
loop .ddraw
.gl_quit:
mov esp,ebp
ret 26
ret 26

View File

@ -0,0 +1,929 @@
CATMULL_SHIFT equ 8
ROUND equ 8
;NON=0
;MMX=1
;Ext=MMX
;TEX_SIZE=0x3fff
;SIZE_X equ 512
;SIZE_Y equ 512
;ROUND = 8
;TEX_SHIFT equ 6
; procedure drawing textured triangle with Gouraud shading
; Z-buffer alghoritm included, Z coord interpolation ----
; I set the color by this way -- (col1 * col2)/256 ------
;------------------in - eax - x1 shl 16 + y1 ------------
;---------------------- ebx - x2 shl 16 + y2 ------------
;---------------------- ecx - x3 shl 16 + y3 ------------
;---------------------- esi - pointer to Z-buffer--------
;---------------------- edx - pointer to texture---------
;---------------------- Z-buffer filled with dd variables
;---------------------- shifted CATMULL_SHIFT------------
;---------------------- edi - pointer to screen buffer---
;---------------------- stack : colors-------------------
tex_plus_grd_triangle:
; parameters :
.tex_y3 equ [ebp+38] ; 36 bytes through stack
.tex_x3 equ [ebp+36]
.tex_y2 equ [ebp+34]
.tex_x2 equ [ebp+32]
.tex_y1 equ [ebp+30]
.tex_x1 equ [ebp+28]
.z3 equ [ebp+26]
.col3b equ [ebp+24]
.col3g equ [ebp+22]
.col3r equ [ebp+20]
.z2 equ [ebp+18]
.col2b equ [ebp+16]
.col2g equ [ebp+14]
.col2r equ [ebp+12]
.z1 equ [ebp+10]
.col1b equ [ebp+8]
.col1g equ [ebp+6]
.col1r equ [ebp+4]
; local variables:
.tex_ptr equ dword[ebp-4]
.z_ptr equ dword[ebp-8]
.scr_buff equ dword[ebp-12]
.x1 equ word[ebp-14] ;dw ? ;equ word[ebp-10]
.y1 equ word[ebp-16] ;dw ? ;equ word[ebp-12]
.x2 equ word[ebp-18] ;dw ? ;equ word[ebp-14]
.y2 equ word[ebp-20] ;dw ? ;equ word[ebp-16]
.x3 equ word[ebp-22] ;dw ? ;equ word[ebp-18]
.y3 equ word[ebp-24] ;dw ? ;equ word[ebp-20]
.dx12 equ dword[ebp-28] ;dd ?
.tex_dx12 equ dword[ebp-32] ;dd ?
.tex_dy12 equ dword[ebp-36] ;dd ?
.dz12 equ dword[ebp-40] ;dd ?
.dc12r equ dword[ebp-44] ;dd ?
.dc12g equ dword[ebp-48] ;dd ?
.dc12b equ dword[ebp-52] ;dd ?
.dx23 equ dword[ebp-56] ;dd ?
.tex_dx23 equ dword[ebp-60] ;dd ?
.tex_dy23 equ dword[ebp-64] ;dd ?
.dz23 equ dword[ebp-68] ;dd ?
.dc23r equ dword[ebp-72] ;dd ?
.dc23g equ dword[ebp-76] ;dd ?
.dc23b equ dword[ebp-80] ;dword[ebp-8]dd ?
.dx13 equ dword[ebp-84] ;dd ?
.tex_dx13 equ dword[ebp-88] ;dd ?
.tex_dy13 equ dword[ebp-92] ;dd ?
.dz13 equ dword[ebp-96] ;dd ?
.dc13r equ dword[ebp-100] ;dd ?
.dc13g equ dword[ebp-104] ;dd ?
.dc13b equ dword[ebp-108] ;dd ?
.zz1 equ dword[ebp-112] ;dw ?
.zz2 equ dword[ebp-116] ;dw ?
.cur1r equ dword[ebp-120] ;dw ?
.cur1g equ dword[ebp-124] ;dw ?
.cur1b equ dword[ebp-128] ;dw ?
.cur2r equ dword[ebp-132] ;dw ?
.cur2g equ dword[ebp-136] ;dw ?
.cur2b equ dword[ebp-140] ;dw ?
.scan_x1 equ dword[ebp-144] ;dd ?
.scan_x2 equ dword[ebp-148] ;dd ?
.scan_y1 equ dword[ebp-152] ;dd ?
.scan_y2 equ dword[ebp-156] ;dd ?
mov ebp,esp
if Ext>=MMX
emms
end if
; mov .tex_ptr,edx
; mov .z_ptr,esi
; mov .scr_buff,edi
push edx esi edi
; push esi
; push edi
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .loop2_end
.sort3:
cmp ax,bx
jle .sort1
xchg eax,ebx
if Ext>=MMX
movq mm0, .col1r ; exchange r, g, b, z
movq mm1, .col2r
movq .col1r ,mm1
movq .col2r ,mm0
else
mov edx,dword .col1r ; exchange both r and g
xchg edx,dword .col2r
mov dword .col1r ,edx
mov edx,dword .col1b ; b and z
xchg edx,dword .col2b
mov dword .col1b ,edx
end if
mov edx,dword .tex_x1
xchg edx,dword .tex_x2
mov dword .tex_x1 ,edx
.sort1:
cmp bx,cx
jle .sort2
xchg ebx,ecx
if Ext>=MMX
movq mm0, .col2r ; exchange r, g, b, z
movq mm1, .col3r
movq .col3r ,mm0
movq .col2r ,mm1
else
mov edx,dword .col2r ; r, g
xchg edx,dword .col3r
mov dword .col2r,edx
mov edx,dword .col2b ; b, z
xchg edx,dword .col3b
mov dword .col2b,edx
end if
mov edx,dword .tex_x2
xchg edx,dword .tex_x3
mov dword .tex_x2,edx
jmp .sort3
.sort2:
push eax ebx ecx ; store in variables
; push ebx
; push ecx
;****************** delta computng zone **************
;+++++++++ first zone
mov bx,.y2 ; calc delta12
sub bx,.y1
jnz .dx12_make
mov ecx,7
@@:
push dword 0
loop @b
jmp .dx12_done
.dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx12,eax
push eax
if 0 ; Ext=SSE
movd mm0,.col1r ; 2 words r, g
pxor mm1,mm1
punpcklwd mm0,mm1
cvtpi2ps xmm0,mm0
movlhps xmm0,xmm0
movd mm0,.col1g ; 2 words b, z
punpcklwd mm0,mm1
cvtpi2ps xmm0,mm0
; xmm0=four float double words
divss xmm0,.pack3
;convert and insert mm0 to lower xmm1 ..
end if
mov ax,word .tex_x2
sub ax,word .tex_x1
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .tex_dx12r,eax
push eax
mov ax,word .tex_y2
sub ax,word .tex_y1
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .tex_dx12,eax
push eax
mov ax,word .z2
sub ax,word .z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
; mov .dz12,eax
push eax ; .dza12
mov ax,word .col2r
sub ax,word .col1r
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc12r,eax
push eax
mov ax,word .col2g
sub ax,word .col1g
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc12g,eax
push eax
mov ax,word .col2b ;;---
sub ax,word .col1b
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc12b,eax
push eax
;+++++++++++++++++ second zone +++++++++++++
.dx12_done:
mov bx,.y3 ; calc delta23
sub bx,.y2
jnz .dx23_make
mov ecx,7
@@:
push dword 0
loop @b
jmp .dx23_done
.dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx23,eax
push eax
mov ax,word .tex_x3
sub ax,word .tex_x2
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .tex_dx23,eax
push eax
mov ax,word .tex_y3
sub ax,word .tex_y2
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .tex_dy23,eax
push eax
mov ax,word .z3
sub ax,word .z2
cwde ;
shl eax,CATMULL_SHIFT ; 2222222
cdq ; 2 2
idiv ebx ; 2
; mov .dz23,eax ; 2
push eax ; .dza12 ; 2
; 2
mov ax,word .col3r ; 2
sub ax,word .col2r ; 2222222
cwde ; second delta
shl eax,ROUND ;
cdq ;
idiv ebx ;
; mov .dc23r,eax ;
push eax
mov ax,word .col3g
sub ax,word .col2g
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc23g,eax
push eax
mov ax,word .col3b ;;---
sub ax,word .col2b
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc23b,eax
push eax
.dx23_done:
;++++++++++++++++++third zone++++++++++++++++++++++++
mov bx,.y3 ; calc delta13
sub bx,.y1
jnz .dx13_make
mov ecx,7
@@:
push dword 0
loop @b
jmp .dx13_done
.dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx13,eax
push eax
mov ax,word .tex_x3 ; triangle b
sub ax,word .tex_x1
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .tex_dx13r,eax
push eax
mov ax,word .tex_y3
sub ax,word .tex_y1
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .tex_dy13,eax
push eax
mov ax,word .z3
sub ax,word .z1 ; 333333333
cwde ; 3 3
shl eax,CATMULL_SHIFT ; 3
cdq ; 3
idiv ebx ; 3
; mov .dz13,eax ; 3
push eax ; .dza12 ; 3
; 3
mov ax,word .col3r ; 3333333333
sub ax,word .col1r ; 3
cwde ; 3
shl eax,ROUND ; 3
cdq ; 3
idiv ebx ; 3
; mov .dc13r,eax ; 3 3
push eax ; 33333333
mov ax,word .col3g
sub ax,word .col1g
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc13g,eax
push eax
mov ax,word .col3b ;;---
sub ax,word .col1b
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc13b,eax
push eax
.dx13_done:
; <<<<<<< ::delta zone end+++++++++++++++++++++ >>>>>>>>
sub esp,55 ;(12*4)
movsx eax,.x1 ; eax - cur x1
shl eax,ROUND ; ebx - cur x2
mov ebx,eax
movsx edx,word .z1
shl edx,CATMULL_SHIFT
mov .zz1,edx
mov .zz2,edx
movzx edi,word .col1r
shl edi,ROUND
mov .cur1r,edi
mov .cur2r,edi
movzx esi,word .col1g
shl esi,ROUND
mov .cur1g,esi
mov .cur2g,esi
movzx edx,word .col1b
shl edx,ROUND
mov .cur1b,edx
mov .cur2b,edx
movzx edi,word .tex_x1
shl edi,ROUND
mov .scan_x1,edi
mov .scan_x2,edi
movzx edx,word .tex_y1
shl edx,ROUND
mov .scan_y1,edx
mov .scan_y2,edx
mov cx,.y1
cmp cx,.y2
jge .loop1_end
.loop_1:
; push eax ebx ebp
pushad
push .tex_ptr
push .scr_buff
push .z_ptr
push cx
push .zz2
push .scan_x2
push .scan_y2
push .cur2r
push .cur2g
push .cur2b
push .zz1
push .scan_x1
push .scan_y1
push .cur1r
push .cur1g
push .cur1b
sar eax,ROUND
sar ebx,ROUND
call horizontal_tex_grd_line
; pop ebp ebx eax
popad
mov edx,.dc13b
add .cur1b,edx
mov esi,.dc13g
add .cur1g,esi
mov edi,.dc13r
add .cur1r,edi
mov edx,.tex_dx13
add .scan_x1,edx
mov esi,.tex_dy13
add .scan_y1,esi
mov edx,.dz13
add .zz1,edx
mov edi,.dc12b
add .cur2b,edi
mov esi,.dc12g
add .cur2g,esi
mov edx,.dc12r
add .cur2r,edx
mov edi,.tex_dx12
add .scan_x2,edi
mov esi,.tex_dy12
add .scan_y2,esi
mov edx,.dz12
add .zz2,edx
add eax,.dx13
add ebx,.dx12
inc cx
cmp cx,.y2
jl .loop_1
.loop1_end:
movzx ecx,.y2
cmp cx,.y3
jge .loop2_end
movsx ebx,.x2 ; eax - cur x1
shl ebx,ROUND ; ebx - cur x2
movsx edx,word .z2
shl edx,CATMULL_SHIFT
; mov .zz1,edx
mov .zz2,edx
movzx edi,word .col2r
shl edi,ROUND
; mov .cur1r,edi
mov .cur2r,edi
movzx esi,word .col2g
shl esi,ROUND
; mov .cur1g,esi
mov .cur2g,esi
movzx edx,word .col2b
shl edx,ROUND
; mov .cur1b,edx
mov .cur2b,edx
movzx edi,word .tex_x2
shl edi,ROUND
; mov .scan_x1,edi
mov .scan_x2,edi
movzx edx,word .tex_y2
shl edx,ROUND
; mov .scan_y1,edx
mov .scan_y2,edx
.loop_2:
pushad
push .tex_ptr
push .scr_buff
push .z_ptr
push cx
push .zz2
push .scan_x2
push .scan_y2
push .cur2r
push .cur2g
push .cur2b
push .zz1
push .scan_x1
push .scan_y1
push .cur1r
push .cur1g
push .cur1b
sar eax,ROUND
sar ebx,ROUND
call horizontal_tex_grd_line
popad
mov edx,.dc13b
add .cur1b,edx
mov esi,.dc13g
add .cur1g,esi
mov edi,.dc13r
add .cur1r,edi
mov edx,.tex_dx13
add .scan_x1,edx
mov esi,.tex_dy13
add .scan_y1,esi
mov edx,.dz13
add .zz1,edx
mov edi,.dc23b
add .cur2b,edi
mov esi,.dc23g
add .cur2g,esi
mov edx,.dc23r
add .cur2r,edx
mov edi,.tex_dx23
add .scan_x2,edi
mov esi,.tex_dy23
add .scan_y2,esi
mov edx,.dz23
add .zz2,edx
add eax,.dx13
add ebx,.dx23
inc cx
cmp cx,.y3
jl .loop_2
.loop2_end:
mov esp,ebp
ret 36
horizontal_tex_grd_line:
;in:
; eax : x1, ebx : x2
.tex_ptr equ [ebp+62]
.screen equ [ebp+58]
.z_buffer equ [ebp+54]
.y equ [ebp+52]
.z2 equ [ebp+48]
.tex_x2 equ [ebp+44]
.tex_y2 equ [ebp+40]
.r2 equ [ebp+36]
.g2 equ [ebp+32]
.b2 equ [ebp+28]
.z1 equ [ebp+24]
.tex_x1 equ [ebp+20]
.tex_y1 equ [ebp+16]
.r1 equ [ebp+12]
.g1 equ [ebp+8]
.b1 equ [ebp+4]
.x1 equ word[ebp-2]
.x2 equ word[ebp-4]
.dz equ dword[ebp-8]
.db equ dword[ebp-12]
.dg equ dword[ebp-16]
.dr equ dword[ebp-20]
.dtex_x equ dword[ebp-24]
.dtex_y equ dword[ebp-28]
.c_ty equ [ebp-32]
.c_tx equ [ebp-36]
.cb equ [ebp-40]
.cg equ [ebp-44]
.cr equ [ebp-48]
.t_col equ [ebp-52]
.dtex_yM equ qword[ebp-28]
.drM equ qword[ebp-20]
.dbM equ qword[ebp-12]
mov ebp,esp
; sub esp,30
mov cx,word .y
or cx,cx
jl .quit_l
cmp cx,SIZE_Y
jge .quit_l
cmp ax,bx
je .quit_l
jl @f
xchg eax,ebx
if Ext=NON
mov ecx,dword .r1
xchg ecx, .r2
mov dword .r1, ecx
mov ecx,dword .g1
xchg ecx, .g2
mov dword .g1, ecx
mov ecx,dword .b1
xchg ecx, .b2
mov dword .b1, ecx
mov ecx,dword .tex_x1
xchg ecx, .tex_x2
mov dword .tex_x1, ecx
mov ecx,dword .tex_y1
xchg ecx, .tex_y2
mov dword .tex_y1, ecx
mov ecx,dword .z1
xchg ecx, .z2
mov dword .z1, ecx
else
movq mm0,.b1 ; b, g
movq mm1,.b2
movq .b1, mm1
movq .b2, mm0
movq mm2,.r1 ; r, y
movq mm3,.r2
movq .r1,mm3
movq .r2,mm2
movq mm4,.tex_x1 ; x, z
movq mm5,.tex_x2
movq .tex_x1,mm5
movq .tex_x2,mm4
end if
@@:
or bx,bx
jle .quit_l
cmp ax,SIZE_X
jge .quit_l
push ax
push bx
mov eax,.z2 ; delta zone************
sub eax,.z1
cdq
mov bx,.x2
sub bx,.x1
movsx ebx,bx
idiv ebx
push eax ; .dz
mov eax,.b2
sub eax,.b1
cdq
idiv ebx
push eax ; .db
mov eax,.g2
sub eax,.g1
cdq
idiv ebx
push eax ; .dg
mov eax,.r2
sub eax,.r1
cdq
idiv ebx
push eax ; .dr
mov eax,.tex_x2
sub eax,.tex_x1
cdq
idiv ebx
push eax ; .dtex_x
mov eax,.tex_y2
sub eax,.tex_y1
cdq
idiv ebx
push eax ; .dtey_x
cmp .x1,0
jg @f
mov eax,.dz ; clipping
movsx ebx,.x1
neg ebx
imul ebx
add .z1,eax
mov .x1,0
mov eax,.dr
imul ebx
add .r1,eax
;if Ext=NON
mov eax,.dg
imul ebx
add .g1,eax
mov eax,.db
imul ebx
add .b1,eax
mov eax,.dtex_x
imul ebx
add .tex_x1,eax
mov eax,.dtex_y
imul ebx
add .tex_y1,eax
@@:
mov edx,SIZE_X
cmp .x2,dx
jl @f
mov .x2,dx
@@:
; calc line addres begin in screen and Z buffer
movsx eax,word .y
mul edx
movsx edx,.x1
add eax,edx
mov esi,eax
shl esi,2
add esi,.z_buffer
lea eax,[eax*3]
mov edi,.screen
add edi,eax
mov cx,.x2
sub cx,.x1
movzx ecx,cx
; init current variables
push dword .tex_y1
;if Ext=NON
push dword .tex_x1
push dword .b1
push dword .g1
push dword .r1
if Ext>=MMX
movq mm4,.cr ; lo -> r,g
movq mm6,.cb ; hi -> b, tex_x
pxor mm0,mm0
end if
mov ebx,.z1
.ddraw:
cmp ebx,dword[esi]
jge @f
mov eax,.c_ty
; if ROUND<TEX_SHIFT
; shl eax,TEX_SHIFT-ROUND
; end if
; if ROUND>TEX_SHIFT
; shr eax,ROUND-TEX_SHIFT
; end if
shr eax,ROUND
shl Eax,TEX_SHIFT
mov edx,.c_tx ; calc texture pixel mem addres
shr edx,ROUND
add eax,edx
and eax,TEXTURE_SIZE ; cutting
lea eax,[3*eax]
add eax,.tex_ptr
mov dword[esi],ebx
if Ext = NON
mov eax,dword[eax]
; mov .tex_col,eax
push ax
shl eax,8
pop ax
mov edx,.cr
sar edx,ROUND
mul dl ; al*dl
shr ax,8
stosb
ror eax,16
push ax
mov edx,.cg
sar edx,ROUND
mul dl
shr ax,8
stosb
pop ax
shr ax,8
mov edx,.cb
sar edx,ROUND
mul dl
shr ax,8
stosb
jmp .no_skip
else
movd mm1,[eax]
punpcklbw mm1,mm0
movq mm3,mm4 ;.cr ; lo -> r,g
movq mm5,mm6 ;.cb ; lo -> b,tex_x
psrld mm3,ROUND ;
psrld mm5,ROUND ;
packssdw mm3,mm5
pmullw mm1,mm3
psrlw mm1,8
packuswb mm1,mm0
movd [edi],mm1
end if
mov dword[esi],ebx
if Ext = NON
jmp .no_skip
end if
@@:
add edi,3
.no_skip:
add esi,4
add ebx,.dz
mov eax,.dtex_x
add .c_tx, eax
mov edx,.dtex_y
add .c_ty, edx
if Ext=NON
mov eax,.dr
add .cr,eax
mov edx,.dg
add .cg,edx
mov eax,.db
add .cb,eax
else
paddd mm4,.drM
paddd mm6,.dbM
;; paddd mm7,.dtex_y ; mm4 - b, g
;; movq .c_tx,mm7
; mm6 - r, x
end if ; mm7 - y, x
dec ecx
jnz .ddraw
.quit_l:
mov esp,ebp
ret 42+20 ; horizontal line

View File

@ -1,507 +0,0 @@
;---------------------------------------------------------------------
;--------------------textured triangle procedure----------------------
;---------------------------------------------------------------------
tex_triangle:
;----------in - eax - x1 shl 16 + y1
;-------------- ebx - x2 shl 16 + y2
;---------------ecx - x3 shl 16 + y3
;---------------edx - nothing
;---------------esi - pointer to texture buffer
;---------------edi - pointer to screen buffer
;-------------stack - texture coordinates
.tex_x1 equ ebp+4
.tex_y1 equ ebp+6
.tex_x2 equ ebp+8
.tex_y2 equ ebp+10
.tex_x3 equ ebp+12
.tex_y3 equ ebp+14
mov ebp,esp
mov edx,dword[.tex_x1] ; check all parameters
or dx,dx
jl .tt_end
cmp dx,TEX_X-1
jg .tt_end
shr edx,16
or dx,dx
jl .tt_end
cmp dx,TEX_Y-1
jg .tt_end
mov edx,dword[.tex_x2]
or dx,dx
jl .tt_end
cmp dx,TEX_X-1
jg .tt_end
shr edx,16
or dx,dx
jl .tt_end
cmp dx,TEX_Y-1
jg .tt_end
mov edx,dword[.tex_x3]
or dx,dx
jl .tt_end
cmp dx,TEX_X-1
jg .tt_end
shr edx,16
cmp dx,TEX_Y-1
jg .tt_end
or dx,dx
jl .tt_end
mov edx,eax ; check X&Y triangle coordinate
or edx,ebx
or edx,ecx
test edx,80008000h
jne .tt_end
; or ax,ax
; jl .tt_end
cmp ax,SIZE_Y
jg .tt_end
ror eax,16
; or ax,ax
; jl .tt_end
cmp ax,SIZE_X
jg .tt_end
rol eax,16
; or bx,bx
; jl .tt_end
cmp bx,SIZE_Y
jg .tt_end
ror ebx,16
; or bx,bx
; jl .tt_end
cmp bx,SIZE_X
jg .tt_end
rol ebx,16
; or cx,cx
; jl .tt_end
cmp cx,SIZE_Y
jg .tt_end
ror ecx,16
; or cx,cx
; jl .tt_end
cmp cx,SIZE_X
jg .tt_end
rol ecx,16 ; uff.. parameters was checked
cmp ax,bx ;sort all parameters
jle .tt_sort1
xchg eax,ebx
mov edx,dword [.tex_x1]
xchg edx,dword [.tex_x2]
mov dword[.tex_x1],edx
.tt_sort1:
cmp ax,cx
jle .tt_sort2
xchg eax,ecx
mov edx,dword [.tex_x1]
xchg edx,dword [.tex_x3]
mov dword [.tex_x1],edx
.tt_sort2:
cmp bx,cx
jle .tt_sort3
xchg ebx,ecx
mov edx,dword [.tex_x2]
xchg edx,dword [.tex_x3]
mov dword [.tex_x2],edx
.tt_sort3:
mov [.y1],ax ; and store to user friendly variables
shr eax,16
mov [.x1],ax
mov [.y2],bx
shr ebx,16
mov [.x2],bx
mov [.y3],cx
shr ecx,16
mov [.x3],cx
mov [.tex_ptr],esi
movsx ebx,word[.y2]
sub bx,[.y1]
jnz .tt_dx12_make
mov [.dx12],0
mov [.tex_dx12],0
mov [.tex_dy12],0
jmp .tt_dx12_done
.tt_dx12_make:
mov ax,[.x2]
sub ax,[.x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dx12],eax ; dx12 = (x2-x1)/(y2-y1)
mov ax,word[.tex_x2]
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
mov ax,word[.tex_y2]
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
.tt_dx12_done:
movsx ebx,[.y3]
sub bx,[.y1]
jnz .tt_dx13_make
mov [.dx13],0
mov [.tex_dx13],0
mov [.tex_dy13],0
jmp .tt_dx13_done
.tt_dx13_make:
mov ax,[.x3]
sub ax,[.x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dx13],eax ; dx13 = (x3-x1)/(y3-y1)
mov ax,word[.tex_x3]
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dx13],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
mov ax,word[.tex_y3]
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dy13],eax ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
.tt_dx13_done:
movsx ebx,[.y3]
sub bx,[.y2]
jnz .tt_dx23_make
mov [.dx23],0
mov [.tex_dx23],0
mov [.tex_dy23],0
jmp .tt_dx23_done
.tt_dx23_make:
mov ax,[.x3]
sub ax,[.x2]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dx23],eax ; dx23 = (x3-x2)/(y3-y2)
mov ax,word[.tex_x3]
sub ax,word[.tex_x2]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
mov ax,word[.tex_y3]
sub ax,word[.tex_y2]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
.tt_dx23_done:
movsx eax,[.x1]
shl eax,ROUND
mov ebx,eax
movsx edx, word[.tex_x1]
shl edx,ROUND
mov [.scan_x1],edx
mov [.scan_x2],edx
movsx edx, word[.tex_y1]
shl edx,ROUND
mov [.scan_y1],edx
mov [.scan_y2],edx
mov cx,[.y1]
cmp cx, [.y2]
jge .tt_loop1_end
.tt_loop1:
push edi
push eax
push ebx
push cx
push ebp
mov edx, [.scan_y2]
sar edx, ROUND
push dx
mov edx, [.scan_x2]
sar edx, ROUND
push dx
mov edx, [.scan_y1]
sar edx, ROUND
push dx
mov edx, [.scan_x1]
sar edx, ROUND
push dx
push [.tex_ptr]
push cx
mov edx,ebx
sar edx,ROUND
push dx
mov edx,eax
sar edx,ROUND
push dx
call textured_line
pop ebp
pop cx
pop ebx
pop eax
pop edi
mov edx, [.tex_dx13]
add [.scan_x1], edx
mov edx, [.tex_dx12]
add [.scan_x2], edx
mov edx, [.tex_dy13]
add [.scan_y1], edx
mov edx, [.tex_dy12]
add [.scan_y2], edx
add eax, [.dx13]
add ebx, [.dx12]
inc cx
cmp cx,[.y2]
jl .tt_loop1
.tt_loop1_end:
mov cx,[.y2]
cmp cx, [.y3]
jge .tt_loop2_end
movsx ebx,[.x2]
shl ebx,ROUND
movsx edx, word[.tex_x2]
shl edx,ROUND
mov [.scan_x2],edx
movsx edx, word[.tex_y2]
shl edx,ROUND
mov [.scan_y2],edx
.tt_loop2:
push edi
push eax
push ebx
push cx
push ebp
mov edx, [.scan_y2]
sar edx, ROUND
push dx
mov edx, [.scan_x2]
sar edx, ROUND
push dx
mov edx, [.scan_y1]
sar edx, ROUND
push dx
mov edx, [.scan_x1]
sar edx, ROUND
push dx
push [.tex_ptr]
push cx
mov edx,ebx
sar edx,ROUND
push dx
mov edx,eax
sar edx,ROUND
push dx
call textured_line
pop ebp
pop cx
pop ebx
pop eax
pop edi
mov edx, [.tex_dx13]
add [.scan_x1], edx
mov edx, [.tex_dx23]
add [.scan_x2], edx
mov edx, [.tex_dy13]
add [.scan_y1], edx
mov edx, [.tex_dy23]
add [.scan_y2], edx
add eax, [.dx13]
add ebx, [.dx23]
inc cx
cmp cx,[.y3]
jl .tt_loop2
.tt_loop2_end:
.tt_end:
mov esp,ebp
ret 12
.x1 dw ?
.y1 dw ?
.x2 dw ?
.y2 dw ?
.x3 dw ?
.y3 dw ?
.dx12 dd ?
.dx13 dd ?
.dx23 dd ?
.tex_dx12 dd ?
.tex_dy12 dd ?
.tex_dx13 dd ?
.tex_dy13 dd ?
.tex_dx23 dd ?
.tex_dy23 dd ?
.tex_ptr dd ?
.scan_x1 dd ?
.scan_y1 dd ?
.scan_x2 dd ?
.scan_y2 dd ?
textured_line:
;-----in -edi screen buffer pointer
;------------ stack:
.x1 equ word [ebp+4]
.x2 equ word [ebp+6]
.y equ word [ebp+8]
.tex_ptr equ dword [ebp+10]
.tex_x1 equ word [ebp+14]
.tex_y1 equ word [ebp+16]
.tex_x2 equ word [ebp+18]
.tex_y2 equ word [ebp+20]
mov ebp,esp
mov ax,.y
or ax,ax
jl .tl_quit
cmp ax,SIZE_Y
jg .tl_quit
mov ax,.x1
cmp ax,.x2
je .tl_quit
jl .tl_ok
xchg ax,.x2
mov .x1,ax
mov ax,.tex_x1
xchg ax,.tex_x2
mov .tex_x1,ax
mov ax,.tex_y1
xchg ax,.tex_y2
mov .tex_y1,ax
.tl_ok:
mov ebx,edi
movsx edi,.y
mov eax,SIZE_X*3
mul edi
mov edi,eax
movsx eax,.x1
add edi,eax
shl eax,1
add edi,eax
add edi,ebx
mov cx,.x2
sub cx,.x1
movsx ecx,cx
mov ax,.tex_x2
sub ax,.tex_x1
cwde
shl eax,ROUND
cdq
idiv ecx
mov [.tex_dx],eax ; tex_dx=(tex_x2-tex_x1)/(x2-x1)
mov ax,.tex_y2
sub ax,.tex_y1
cwde
shl eax,ROUND
cdq
idiv ecx
mov [.tex_dy],eax ; tex_dy = (tex_y2-tex_y1)/(x2-x1)
movsx eax,.tex_x1
shl eax,ROUND
movsx ebx,.tex_y1
shl ebx,ROUND
cld
.tl_loop:
mov edx,eax
mov esi,ebx
sar edx,ROUND
sar esi,ROUND
macro .fluent
{
push eax
push edx
mov eax,TEX_X*3
mul esi
mov esi,eax
pop edx
pop eax
}
macro .shift
{
shl esi,TEX_SHIFT
lea esi,[esi*3]
;push edx
;mov edx,esi
;shl esi,1
;add esi,edx
;pop edx
}
if TEX = FLUENTLY
.fluent
end if
if TEX = SHIFTING
.shift
end if
lea edx,[edx*3]
add esi,edx
; shl edx,1
; add esi,edx
add esi,.tex_ptr
movsd
dec edi
add eax,[.tex_dx]
add ebx,[.tex_dy]
loop .tl_loop
.tl_quit:
mov esp,ebp
ret 18
.tex_dx dd ?
.tex_dy dd ?

543
programs/demos/3DS/TEX3.INC Normal file
View File

@ -0,0 +1,543 @@
;---------------------------------------------------------------------
;--------------------textured triangle procedure----------------------
;---------------------------------------------------------------------
tex_triangle:
;----------in - eax - x1 shl 16 + y1
;-------------- ebx - x2 shl 16 + y2
;---------------ecx - x3 shl 16 + y3
;---------------edx - nothing
;---------------esi - pointer to texture buffer
;---------------edi - pointer to screen buffer
;-------------stack - texture coordinates
.tex_x1 equ ebp+4
.tex_y1 equ ebp+6
.tex_x2 equ ebp+8
.tex_y2 equ ebp+10
.tex_x3 equ ebp+12
.tex_y3 equ ebp+14
.x1 equ ebp-2 ;dw ?
.y1 equ ebp-4 ;dw ?
.x2 equ ebp-6 ;dw ?
.y2 equ ebp-8 ;dw ?
.x3 equ ebp-10 ;dw ?
.y3 equ ebp-12 ;dw ?
.dx12 equ ebp-16 ;dd ?
.dx13 equ ebp-20 ;dd ?
.dx23 equ ebp-24 ;dd ?
.tex_dx12 equ ebp-28 ;dd ?
.tex_dy12 equ ebp-32 ;dd ?
.tex_dx13 equ ebp-36 ;dd ?
.tex_dy13 equ ebp-40 ;dd ?
.tex_dx23 equ ebp-44 ;dd ?
.tex_dy23 equ ebp-48 ;dd ?
.tex_ptr equ ebp-52 ;dd ?
.scan_x2 equ ebp-56 ;dd ?
.scan_y2 equ ebp-60 ;dd ?
.scan_x1 equ ebp-64 ;dd ?
.scan_y1 equ ebp-68 ;dd ?
mov ebp,esp
sub esp,68
;if Ext = MMX
; emms
;end if
mov edx,dword[.tex_x1] ; check all parameters
or dx,dx
jl .tt_end
cmp dx,TEX_X-1
jg .tt_end
shr edx,16
or dx,dx
jl .tt_end
cmp dx,TEX_Y-1
jg .tt_end
mov edx,dword[.tex_x2]
or dx,dx
jl .tt_end
cmp dx,TEX_X-1
jg .tt_end
shr edx,16
or dx,dx
jl .tt_end
cmp dx,TEX_Y-1
jg .tt_end
mov edx,dword[.tex_x3]
or dx,dx
jl .tt_end
cmp dx,TEX_X-1
jg .tt_end
shr edx,16
cmp dx,TEX_Y-1
jg .tt_end
or dx,dx
jl .tt_end
mov edx,eax ; check X&Y triangle coordinate
or edx,ebx
or edx,ecx
test edx,80008000h
jne .tt_end
; or ax,ax
; jl .tt_end
cmp ax,SIZE_Y
jg .tt_end
ror eax,16
; or ax,ax
; jl .tt_end
cmp ax,SIZE_X
jg .tt_end
rol eax,16
; or bx,bx
; jl .tt_end
cmp bx,SIZE_Y
jg .tt_end
ror ebx,16
; or bx,bx
; jl .tt_end
cmp bx,SIZE_X
jg .tt_end
rol ebx,16
; or cx,cx
; jl .tt_end
cmp cx,SIZE_Y
jg .tt_end
ror ecx,16
; or cx,cx
; jl .tt_end
cmp cx,SIZE_X
jg .tt_end
rol ecx,16 ; uff.. parameters was checked
cmp ax,bx ;sort all parameters
jle .tt_sort1
xchg eax,ebx
mov edx,dword [.tex_x1]
xchg edx,dword [.tex_x2]
mov dword[.tex_x1],edx
.tt_sort1:
cmp ax,cx
jle .tt_sort2
xchg eax,ecx
mov edx,dword [.tex_x1]
xchg edx,dword [.tex_x3]
mov dword [.tex_x1],edx
.tt_sort2:
cmp bx,cx
jle .tt_sort3
xchg ebx,ecx
mov edx,dword [.tex_x2]
xchg edx,dword [.tex_x3]
mov dword [.tex_x2],edx
.tt_sort3:
mov [.y1],ax ; and store to user friendly variables
shr eax,16
mov [.x1],ax
mov [.y2],bx
shr ebx,16
mov [.x2],bx
mov [.y3],cx
shr ecx,16
mov [.x3],cx
mov [.tex_ptr],esi
movsx ebx,word[.y2]
sub bx,[.y1]
jnz .tt_dx12_make
mov dword[.dx12],0
mov dword[.tex_dx12],0
mov dword[.tex_dy12],0
jmp .tt_dx12_done
.tt_dx12_make:
mov ax,[.x2]
sub ax,[.x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dx12],eax ; dx12 = (x2-x1)/(y2-y1)
mov ax,word[.tex_x2]
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
mov ax,word[.tex_y2]
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
.tt_dx12_done:
movsx ebx,word[.y3]
sub bx,word[.y1]
jnz .tt_dx13_make
mov dword [.dx13],0
mov dword [.tex_dx13],0
mov dword [.tex_dy13],0
jmp .tt_dx13_done
.tt_dx13_make:
mov ax,[.x3]
sub ax,[.x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dx13],eax ; dx13 = (x3-x1)/(y3-y1)
mov ax,word[.tex_x3]
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dx13],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
mov ax,word[.tex_y3]
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dy13],eax ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
.tt_dx13_done:
movsx ebx,word[.y3]
sub bx,word[.y2]
jnz .tt_dx23_make
mov dword [.dx23],0
mov dword [.tex_dx23],0
mov dword [.tex_dy23],0
jmp .tt_dx23_done
.tt_dx23_make:
mov ax,[.x3]
sub ax,[.x2]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.dx23],eax ; dx23 = (x3-x2)/(y3-y2)
mov ax,word[.tex_x3]
sub ax,word[.tex_x2]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
mov ax,word[.tex_y3]
sub ax,word[.tex_y2]
cwde
shl eax,ROUND
cdq
idiv ebx
mov [.tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
.tt_dx23_done:
movsx eax,word[.x1]
shl eax,ROUND
mov ebx,eax
movsx edx, word[.tex_x1]
shl edx,ROUND
mov [.scan_x1],edx
mov [.scan_x2],edx
movsx edx, word[.tex_y1]
shl edx,ROUND
mov [.scan_y1],edx
mov [.scan_y2],edx
mov cx,[.y1]
cmp cx, [.y2]
jge .tt_loop1_end
.tt_loop1:
push edi
push eax
push ebx
push cx
push ebp
;; Madis
;if Ext=MMX ; With MMX enabled it reverse light vectors ????
; mov dword[esp-8],ROUND
; mov dword[esp-4],0 ; Is this a bug? Explanation down 3 lines
; movq mm0,qword[.scan_y1]
; movq mm1,qword[.scan_y2]
; psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc.
; psrad mm1,[esp-8] ;It always defaults to QWORD
; packssdw mm0,mm1
; movq [esp-8],mm0
; sub esp,8
;else
push dword[.scan_y2] ; now I push variables on stack without shifting
push dword[.scan_x2]
push dword[.scan_y1]
push dword[.scan_x1]
;end if
push dword[.tex_ptr]
push cx
mov edx,ebx
sar edx,ROUND
push dx
mov edx,eax
sar edx,ROUND
push dx
call textured_line
pop ebp
pop cx
pop ebx
pop eax
pop edi
mov edx, [.tex_dx13]
add [.scan_x1], edx
mov edx, [.tex_dx12]
add [.scan_x2], edx
mov edx, [.tex_dy13]
add [.scan_y1], edx
mov edx, [.tex_dy12]
add [.scan_y2], edx
add eax, [.dx13]
add ebx, [.dx12]
inc cx
cmp cx,[.y2]
jl .tt_loop1
.tt_loop1_end:
mov cx, [.y2]
cmp cx, [.y3]
jge .tt_loop2_end
movsx ebx,word[.x2]
shl ebx,ROUND
movsx edx, word[.tex_x2]
shl edx,ROUND
mov [.scan_x2],edx
movsx edx, word[.tex_y2]
shl edx,ROUND
mov [.scan_y2],edx
.tt_loop2:
push edi
push eax
push ebx
push cx
push ebp
;; Madis
;if Ext=MMX
; mov dword[esp-8],ROUND
; mov dword[esp-4],0 ; Is this a bug? Explanation down 3 lines
; movq mm0,qword[.scan_y1]
; movq mm1,qword[.scan_y2]
; psrad mm0,[esp-8] ;This instr. won't allow modifiers BYTE, WORD, etc.
; psrad mm1,[esp-8] ;It always defaults to QWORD
; packssdw mm0,mm1
; movq [esp-8],mm0
; sub esp,8
;else
;end if
push dword[.scan_y2]
push dword[.scan_x2]
push dword[.scan_y1]
push dword[.scan_x1]
push dword[.tex_ptr]
push cx
mov edx,ebx
sar edx,ROUND
push dx
mov edx,eax
sar edx,ROUND
push dx
call textured_line
pop ebp
pop cx
pop ebx
pop eax
pop edi
mov edx, [.tex_dx13]
add [.scan_x1], edx
mov edx, [.tex_dx23]
add [.scan_x2], edx
mov edx, [.tex_dy13]
add [.scan_y1], edx
mov edx, [.tex_dy23]
add [.scan_y2], edx
add eax, [.dx13]
add ebx, [.dx23]
inc cx
cmp cx,[.y3]
jl .tt_loop2
.tt_loop2_end:
.tt_end:
mov esp,ebp
ret 12
textured_line:
;-----in -edi screen buffer pointer
;------------ stack:
.x1 equ word [ebp+4]
.x2 equ word [ebp+6]
.y equ word [ebp+8]
.tex_ptr equ dword [ebp+10]
.tex_x1 equ [ebp+14]
.tex_y1 equ [ebp+18]
.tex_x2 equ [ebp+22]
.tex_y2 equ [ebp+26]
.tex_dx equ ebp-4 ;dd ?
.tex_dy equ ebp-8 ;dd ?
mov ebp,esp
sub esp,8
mov ax,.y
or ax,ax
jl .tl_quit
cmp ax,SIZE_Y
jg .tl_quit
mov ax,.x1
cmp ax,.x2
je .tl_quit
jl .tl_ok
xchg ax,.x2
mov .x1,ax
if Ext >= MMX
movq mm0,.tex_x1
movq mm1,.tex_x2
movq .tex_x2,mm0
movq .tex_x1,mm1
else
mov eax,.tex_x1
xchg eax,.tex_x2
mov .tex_x1,eax
mov eax,.tex_y1
xchg eax,.tex_y2
mov .tex_y1,eax
end if
.tl_ok:
mov ebx,edi
movsx edi,.y
mov eax,SIZE_X*3
mul edi
mov edi,eax
movsx eax,.x1
add edi,eax
shl eax,1
add edi,eax
add edi,ebx
mov cx,.x2
sub cx,.x1
movsx ecx,cx
mov eax,.tex_x2
sub eax,.tex_x1
cdq
idiv ecx
mov [.tex_dx],eax ; tex_dx=(tex_x2-tex_x1)/(x2-x1)
mov eax,.tex_y2
sub eax,.tex_y1
cdq
idiv ecx
mov [.tex_dy],eax ; tex_dy = (tex_y2-tex_y1)/(x2-x1)
mov eax,.tex_x1
mov ebx,.tex_y1
cld
.tl_loop:
mov edx,eax ; eax - cur x
mov esi,ebx ; ebx - cur y
shr edx,ROUND
shr esi,ROUND
macro .fluent
{
push eax
push edx
mov eax,TEX_X*3
mul esi
mov esi,eax
pop edx
pop eax
}
macro .shift
{
shl esi,TEX_SHIFT
lea esi,[esi*3]
;push edx
;mov edx,esi
;shl esi,1
;add esi,edx
;pop edx
}
if TEX = FLUENTLY
.fluent
end if
if TEX = SHIFTING
.shift
end if
lea edx,[edx*3]
add esi,edx
; shl edx,1
; add esi,edx
add esi,.tex_ptr
movsd
dec edi
add eax,[.tex_dx]
add ebx,[.tex_dy]
loop .tl_loop
.tl_quit:
mov esp,ebp
ret 18+8
; .tex_dx dd ?
; .tex_dy dd ?

View File

@ -0,0 +1,610 @@
;TEX_X = 512
;TEX_Y = 512
;ROUND equ 8
;SIZE_X = 512
;SIZE_Y = 512
;TEX_SHIFT = 9
CATMULL_SHIFT equ 8
;------------------------------------------------------------------------
;- Procedure drawing textured triangle using Catmull Z-buffer algorithm -
;------------------------------------------------------------------------
tex_triangle_z:
;----------in - eax - x1 shl 16 + y1
;-------------- ebx - x2 shl 16 + y2
;---------------ecx - x3 shl 16 + y3
;---------------edx - pointer to Z-buffer
;---------------esi - pointer to texture buffer
;---------------edi - pointer to screen buffer
;-------------stack - texture coordinates
;------------------ - z coordinates
.tex_x1 equ ebp+4
.tex_y1 equ ebp+6
.tex_x2 equ ebp+8
.tex_y2 equ ebp+10
.tex_x3 equ ebp+12
.tex_y3 equ ebp+14
.z1 equ word[ebp+16]
.z2 equ word[ebp+18]
.z3 equ word[ebp+20]
.tex_ptr equ dword[ebp-4] ; pointer to texture
.z_ptr equ dword[ebp-8] ; pointer to z-buffer
.x1 equ word[ebp-10]
.y1 equ word[ebp-12]
.x2 equ word[ebp-14]
.y2 equ word[ebp-16]
.x3 equ word[ebp-18]
.y3 equ word[ebp-20]
.dx12 equ dword[ebp-24]
.tex_dx12 equ dword[ebp-28]
.tex_dy12 equ dword[ebp-32]
.dz12 equ dword[ebp-36]
.dx13 equ dword[ebp-40]
.tex_dx13 equ dword[ebp-44]
.tex_dy13 equ dword[ebp-48]
.dz13 equ dword[ebp-52]
.dx23 equ dword[ebp-56]
.tex_dx23 equ dword[ebp-60]
.tex_dy23 equ dword[ebp-64]
.dz23 equ dword[ebp-68]
.scan_x1 equ dword[ebp-72]
.scan_x2 equ dword[ebp-76]
.scan_y1 equ dword[ebp-80]
.scan_y2 equ dword[ebp-84]
.cz1 equ dword[ebp-88]
.cz2 equ dword[ebp-92]
if Ext >= MMX
emms
end if
mov ebp,esp
push esi ; store memory pointers
push edx
.tt_sort3:
cmp ax,bx ;sort all parameters
jle .tt_sort1
xchg eax,ebx
mov edx,dword [.tex_x1]
xchg edx,dword [.tex_x2]
mov dword[.tex_x1],edx
mov dx,.z1
xchg dx,.z2
mov .z1,dx
.tt_sort1:
cmp bx,cx
jle .tt_sort2
xchg ebx,ecx
mov edx,dword [.tex_x2]
xchg edx,dword [.tex_x3]
mov dword [.tex_x2],edx
mov dx,.z2
xchg dx,.z3
mov .z2,dx
jmp .tt_sort3
.tt_sort2:
push eax ; and store to user friendly variables
push ebx
push ecx
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .tt_loop2_end
cmp ax,SIZE_Y
jl @f
cmp bx,SIZE_Y
jl @f
cmp cx,SIZE_Y
jl @f
ror eax,16
ror ebx,16
ror ecx,16
cmp ax,SIZE_X
jl @f
cmp bx,SIZE_X
jl @f
cmp cx,SIZE_X
jl @f
jmp .tt_loop2_end
@@:
mov eax,dword[.tex_x1] ; texture coords must be in [0..TEX_X(Y)]
mov ebx,dword[.tex_x2]
mov ecx,dword[.tex_x3]
mov edx,eax
or edx,ebx
or edx,ecx
test edx,80008000h
jne .tt_loop2_end
cmp ax,TEX_X
jge .tt_loop2_end
cmp bx,TEX_X
jge .tt_loop2_end
cmp cx,TEX_X
jge .tt_loop2_end
ror eax,16
ror ebx,16
ror ecx,16
cmp ax,TEX_Y
jge .tt_loop2_end
cmp bx,TEX_Y
jge .tt_loop2_end
cmp cx,TEX_Y
jge .tt_loop2_end
movsx ebx,.y2 ; calc delta
sub bx,.y1
jnz .tt_dx12_make
xor edx,edx
mov ecx,4
@@:
push edx
loop @b
jmp .tt_dx12_done
.tt_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dx12,eax ; dx12 = (x2-x1)/(y2-y1)
push eax
mov ax,word[.tex_x2]
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov [.tex_dx12],eax ; tex_dx12 = (tex_x2-tex_x1)/(y2-y1)
push eax
mov ax,word[.tex_y2]
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov [.tex_dy12],eax ; tex_dy12 = (tex_y2-tex_y1)/(y2-y1)
push eax
mov ax,.z2
sub ax,.z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
.tt_dx12_done:
movsx ebx,.y3 ; calc delta
sub bx,.y1
jnz .tt_dx13_make
xor edx,edx
mov ecx,4
@@:
push edx
loop @b
jmp .tt_dx13_done
.tt_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dx12,eax ; dx13 = (x3-x1)/(y3-y1)
push eax
mov ax,word[.tex_x3]
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov [.tex_dx12],eax ; tex_dx13 = (tex_x3-tex_x1)/(y3-y1)
push eax
mov ax,word[.tex_y3]
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov [.tex_dy12],eax ; tex_dy13 = (tex_y3-tex_y1)/(y3-y1)
push eax
mov ax,.z3
sub ax,.z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
.tt_dx13_done:
mov bx,.y3 ; calc delta
sub bx,.y2
jnz .tt_dx23_make
xor edx,edx
mov ecx,4
@@:
push edx
loop @b
jmp .tt_dx23_done
.tt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
shl eax,ROUND
cdq
movzx ebx,bx
idiv ebx
; mov .dx23,eax ; dx23 = (x3-x2)/(y3-y2)
push eax
mov ax,word[.tex_x3]
sub ax,word[.tex_x2]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov [.tex_dx23],eax ; tex_dx23 = (tex_x3-tex_x2)/(y3-y2)
push eax
mov ax,word[.tex_y3]
sub ax,word[.tex_y2]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov [.tex_dy23],eax ; tex_dy23 = (tex_y3-tex_y2)/(y3-y2)
push eax
mov ax,.z3
sub ax,.z2
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
.tt_dx23_done:
movsx eax,.x1 ;eax - cur x1
shl eax,ROUND ;ebx - cur x2
mov ebx,eax
movsx edx, word[.tex_x1]
shl edx,ROUND
; mov [.scan_x1],edx
; mov [.scan_x2],edx
push edx
push edx
movsx edx, word[.tex_y1]
shl edx,ROUND
; mov [.scan_y1],edx
; mov [.scan_y2],edx
push edx
push edx
movsx edx,.z1
shl edx,CATMULL_SHIFT
push edx
push edx
mov cx,.y1
cmp cx,.y2
jge .tt_loop1_end
.tt_loop1:
pushad
push .z_ptr
push .cz1 ; z coords shifted shl catmull_shift
push .cz2
push .scan_y2
push .scan_x2
push .scan_y1
push .scan_x1
push esi ;[.tex_ptr]
push cx
sar ebx,ROUND
push bx
sar eax,ROUND
push ax
call textured_line_z
popad
mov edx,.dz13
add .cz1,edx
mov edx,.dz12
add .cz2,edx
mov edx, .tex_dx13
add .scan_x1, edx
mov edx, .tex_dx12
add .scan_x2, edx
mov edx, .tex_dy13
add .scan_y1, edx
mov edx, .tex_dy12
add .scan_y2, edx
add eax, .dx13
add ebx, .dx12
inc cx
cmp cx,.y2
jl .tt_loop1
.tt_loop1_end:
mov cx,.y2
cmp cx,.y3
jge .tt_loop2_end
movsx ebx,.x2
shl ebx,ROUND
movsx edx,.z2
shl edx,CATMULL_SHIFT
mov .cz2,edx
movzx edx, word [.tex_x2]
shl edx,ROUND
mov .scan_x2,edx
movzx edx, word[.tex_y2]
shl edx,ROUND
mov .scan_y2,edx
.tt_loop2:
pushad
push .z_ptr
push .cz1 ; z coords shifted shl catmull_shift
push .cz2
push .scan_y2
push .scan_x2
push .scan_y1
push .scan_x1
push esi ;[.tex_ptr]
push cx
sar ebx,ROUND
push bx
sar eax,ROUND
push ax
call textured_line_z
popad
mov edx,.dz13
add .cz1,edx
mov edx,.dz23
add .cz2,edx
mov edx, .tex_dx13
add .scan_x1, edx
mov edx, .tex_dx23
add .scan_x2, edx
mov edx, .tex_dy13
add .scan_y1, edx
mov edx, .tex_dy23
add .scan_y2, edx
add eax, .dx13
add ebx, .dx23
inc cx
cmp cx,.y3
jl .tt_loop2
.tt_loop2_end:
.tt_end:
mov esp,ebp
ret 18
textured_line_z:
;-----in -edi screen buffer pointer
;------------ stack:
.x1 equ word [ebp+4]
.x2 equ word [ebp+6]
.y equ word [ebp+8]
.tex_ptr equ dword [ebp+10]
.tex_x1 equ ebp+14
.tex_y1 equ ebp+18
.tex_x2 equ ebp+22
.tex_y2 equ ebp+26
.z2 equ dword [ebp+30] ;z1, z2 coords shifted shl CATMULL_SHIFT
.z1 equ dword [ebp+34]
.z_ptr equ dword [ebp+38]
.tex_dy equ dword [ebp-4]
.tex_dx equ dword [ebp-8]
.dz equ dword [ebp-12]
.cz equ dword [ebp-16]
.c_tex_x equ dword [ebp-20] ; current tex x
.m_sft1 equ ebp-28
.m_sft2 equ ebp-32
; .c_tex_xM equ ebp+14
.tex_dxM equ ebp-8
mov ebp,esp
mov ax,.y
or ax,ax
jl .tl_quit
cmp ax,SIZE_Y
jge .tl_quit
mov ax,.x1
cmp ax,.x2
je .tl_quit
jl .tl_ok
xchg ax,.x2 ; sort params
mov .x1,ax
if Ext >= MMX
movq mm0,[.tex_x1]
movq mm1,[.tex_x2]
movq [.tex_x2],mm0
movq [.tex_x1],mm1
else
mov eax,dword[.tex_x1]
xchg eax,dword[.tex_x2]
mov dword[.tex_x1],eax
mov eax,dword[.tex_y1]
xchg eax,dword[.tex_y2]
mov dword[.tex_y1],eax
end if
mov eax,.z1
xchg eax,.z2
mov .z1,eax
.tl_ok:
cmp .x1,SIZE_X
jge .tl_quit
cmp .x2,0
jle .tl_quit
mov bx,.x2
sub bx,.x1
movsx ebx,bx
mov eax,dword[.tex_y2] ; calc .dty
sub eax,dword[.tex_y1]
cdq
idiv ebx
push eax
mov eax,dword[.tex_x2] ; calc .dtx
sub eax,dword[.tex_x1]
cdq
idiv ebx
push eax
mov eax,.z2 ; calc .dz
sub eax,.z1
cdq
idiv ebx
push eax
cmp .x1,0 ; clipping
jg @f
movsx ebx,.x1
neg ebx
imul ebx ; eax = .dz * abs(.x1)
add .z1,eax
mov .x1,0
mov eax,.tex_dy
imul ebx
add dword[.tex_y1],eax
mov eax,.tex_dx
imul ebx
add dword[.tex_x1],eax
@@:
cmp .x2,SIZE_X
jl @f
mov .x2,SIZE_X
@@:
movsx ebx,.y ; calc mem begin in buffers
mov eax,SIZE_X
mul ebx
movsx ebx,.x1
add eax,ebx
mov ebx,eax
lea eax,[eax*3]
add edi,eax ; edi - scr buff
shl ebx,2
add .z_ptr,ebx ; z buffer pointer
mov cx,.x2
sub cx,.x1
movzx ecx,cx
;if Ext >= MMX
; movq mm0,[.tex_x1]
; movq mm4,mm0
; movq mm1,qword[.tex_dxM]
; mov ebx,.z1
; mov eax,.dz
;else
mov eax,dword[.tex_x1]
mov ebx,dword[.tex_y1]
push .z1 ; .cz
push eax ;.c_tex_x
;end if
mov edx,.z_ptr
.tl_loop:
;if Ext >= MMX
; cmp ebx,[edx] ; ebx - current z
; jge @f
; movq mm2,mm0
; psrad mm2,ROUND
; movq mm3,mm2
; psrlq mm2,32-TEX_SHIFT
; paddd mm3,mm2
; movd esi,mm3
; mov dword[edx],ebx ; renew z buffer
;else
; eax - temp
mov eax,.cz ; ebx - cur tex y shl ROUND
cmp eax,[edx] ; ecx - l.lenght
jge @f ; ebx - cur tex_y ; edx - temp
mov esi,ebx ; edi - scr buff
sar esi,ROUND ; esi - tex_ptr temp
shl esi,TEX_SHIFT ; .z_ptr - cur pointer to z buff
mov eax,.c_tex_x ; .cz - cur z coord shl CATMULL_SHIFT
sar eax,ROUND
add esi,eax
mov eax,.cz
mov dword[edx],eax ; renew z buffer
;end if
and esi,TEXTURE_SIZE
lea esi,[esi*3]
add esi,.tex_ptr
movsd
dec edi
jmp .no_skip
@@:
add edi,3
.no_skip:
add edx,4
;if Ext >= MMX
; add ebx,eax
; paddd mm0,mm1
;else
mov eax,.dz
add .cz,eax
mov eax,.tex_dx
add .c_tex_x,eax
add ebx,.tex_dy
;end if
loop .tl_loop
.tl_quit:
mov esp,ebp
ret 30+8

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

468
programs/demos/3DS/data.inc Normal file
View File

@ -0,0 +1,468 @@
; DATA AREA ************************************
i3 dw 3
i256 dw 256
i255d dd 255
dot_max dd 1.0 ; dot product max and min
dot_min dd 0.0
env_const dd 1.05
correct_tex dw 255
tex_x_div2 dw TEX_X / 2
tex_y_div2 dw TEX_Y / 2
xobs dw 0 ;SIZE_X / 2 ;200 ;observer = camera
yobs dw 0 ;SIZE_Y / 2 ;200 ;coordinates
zobs dw -500
size_x dw SIZE_X
size_y dw SIZE_Y
angle_counter dw 0
piD180 dd 0.017453292519943295769236907684886
piD128 dd 0.024544
const6 dw 6,6,6,6
x_offset dw SIZE_X / 2
y_offset dw SIZE_Y / 2
z_offset dw 0
rsscale dd 175.0 ; next real scale
vect_x dw SIZE_X / 2
vect_y dw SIZE_Y / 2
vect_z dw 0
angle_x dw 0
angle_y dw 0
angle_z dw 0
menu:
db 2 ; button number = index
db 'rotary ' ; label
db 3 ; max flag + 1 , if = 255, no flag
r_flag db 1 ; flag
dd axl_f ; offset to flags description
db 3
db 'shd. model'
db 11
dr_flag db 0
dd shd_f
db 4
db 'speed '
db 2
speed_flag db 0
dd spd_f
db 5
db 'zoom out '
db 255
db ?
dd ?
db 6
db 'zoom in '
db 255
db ?
dd ?
db 7
db 'catmull '
db 2
catmull_flag db 1
dd onoff_f
db 8
db 'culling '
db 2
culling_flag db 1
dd onoff_f
db 9
db 'rand.light'
db 255
db ?
dd ?
db 10
db 'blur '
db 6
blur_flag db 0
dd blur_f
db 11
db 'mirror x '
db 2
mirr_x_flag db 0
dd onoff_f
db 12
db 'mirror y '
db 2
mirr_y_flag db 0
dd onoff_f
db 13
db 'mirror z '
db 2
mirr_z_flag db 0
dd onoff_f
db 14
db 'xchg '
db 4
xchg_flag db 0
dd xchg_f
db 15
db 'emboss '
db 2
emboss_flag db 0
dd onoff_f
db 16
db 'fire '
db 3
fire_flag db 0
dd blur_f
db 17
db 'move '
db 2
move_flag db 0
dd move_f
db 18
db 'generate '
db 6
generator_flag db 0
dd blur_f
db 19
db 'bumps '
db 2
bumps_flag db 0
dd bumps_f
db 20
db 'bumps deep'
db 4
bumps_deep_flag db 3
dd bumps_d_f
; db 21
; db 'light No. '
; db 3
;light_no_flag db 0
; dd bumps_d_f
; db 22
; db 'light comp'
; db 3
;light_comp_flag db 0
; dd light_component_f
;; db 23
;; db 'col. comp'
;; db 3
;;color_comp_flag db 0
;; dd color_component_f
db -1 ; end mark
flags: ; flags description
shd_f:
db 'flat'
db 'grd '
db 'env '
db 'bump'
db 'tex '
db 'pos '
db 'dots'
db 'txgr'
db '2tex'
db 'btex'
db 'cenv'
spd_f:
db 'idle'
db 'full'
axl_f:
db ' y '
db 'x+y '
db ' x '
onoff_f:
db 'off '
db 'on '
; light_component_f:
; db 'norm ' ; diffuse |
; db 'min' ; specular | or sth. like this
; db 'max ' ; emmisive |
;; color_component_f:
;; db ' r '
;; db ' g '
;; db ' b '
blur_f: ; blur, fire
db 'off '
bumps_d_f: db ' 1 '
db ' 2 '
db ' 3 '
db ' 4 '
db ' 5 '
xchg_f:
db 'no '
db 'x<>y'
db 'z<>x'
db 'y<>z'
move_f:
db 'obj '
db 'camr'
; db 'lght'
bumps_f:
db 'rand'
db 'tex '
; db 'cscl'
base_vector:
labelvector:
db 'add vector'
labelvectorend:
labelyminus:
db 'y -'
labelyminusend:
labelzplus:
db 'z +'
labelzplusend:
labelxminus:
db 'x -'
labelxminusend:
labelxplus:
db 'x +'
labelxplusend:
labelzminus:
db 'z -'
labelzminusend:
labelyplus:
db 'y +'
labelyplusend:
;navigation_size = $ - labelvector
; db 'set color '
; db 'r -'
; db 'g +'
; db 'b -'
; db 'b +'
; db 'g -'
; db 'r +'
labelt:
db 'DEUS CARITAS EST'
if Ext=MMX
db ' (MMX)'
end if
if Ext=SSE
db ' (SSE)'
end if
db ' 0.053'
labellen:
STRdata db '-1 '
all_lights_size dw lightsend-lights
if USE_LFN
file_info:
dd 0
dd 0
dd 0
fsize dd 0 ;180000 ; sizeof(workarea)
fptr dd 0 ;workarea
file_name:
db '/rd/1/3d/teapot.3ds',0
else
file_info:
dd 0
dd 0
fsize dd 1
dd workarea
dd hash_table
file_name:
db '/rd/1/teapot.3ds',0
end if
I_END:
rb 256
;=============================================
lights:
.light_vector dd 0.0,0.0,-1.0 ; x,y,z Z cooficient of vector must be negative
.orginal_color_r db 1 ; +12
.orginal_color_g db 255 ;
.orginal_color_b db 1 ; +14
.min_color_r db 1 ;
.min_color_g db 1 ; +16
.min_color_b db 1 ;
.max_color_r db 255 ;
.max_color_g db 255 ;
.max_color_b db 255 ;
.shine db 24 ; +21
; LIGHT_SIZE equ ($-lights)
dd -0.5,-0.5,-1.0 ; x,y,z ; .light_vector
db 5 ; .orginal_color_r
db 1 ; .orginal_color_g
db 135 ; .orginal_color_b
db 19 ; .min_color_r
db 19 ; .min_color_g
db 19 ; .min_color_b
db 255 ; .max_color_r
db 255 ; .max_color_g
db 255 ; .max_color_b
db 16 ; .shine
dd 0.5,0.5,-1.0 ; x,y,z ; .light_vector
db 135 ; .orginal_color_r
db 1 ; .orginal_color_g
db 1 ; .orginal_color_b
db 19 ; .min_color_r
db 19 ; .min_color_g
db 19 ; .min_color_b
db 255 ; .max_color_r
db 255 ; .max_color_g
db 20 ; .max_color_b
db 16 ; .shine
; ALL_LIGHTS_SIZE equ ($ - lights)
;#all_lights_size dw ($ - lights) ;ALL_LIGHTS_SIZE
;===============================================
lightsend:
if USE_LFN = 0
hash_table rb 4096
SourceFile:
workarea rb 180000
else
SourceFile:
workarea rb 180
end if
EndFile dd ?
align 8
sinbeta dd ?;+32
cosbeta dd ?
xsub dw ?
zsub dw ?;+40
ysub dw ?
xx1 dw ?
yy1 dw ?
zz1 dw ?;+48 xx1 + 4
xx2 dw ?
yy2 dw ?
zz2 dw ? ; xx1 + 10
xx3 dw ?;+56
yy3 dw ?
zz3 dw ? ; xx1 + 16
scale dd ? ; help scale variable
;==
triangles_count_var dw ?
points_count_var dw ?
triangles_ptr dd ?
triangles_w_z_ptr dd ?
triangles_normals_ptr dd ?
points_normals_ptr dd ?
points_normals_rot_ptr dd ?
points_ptr dd ?
points_rotated_ptr dd ?
points_translated_ptr dd ?
screen_ptr dd ?
Zbuffer_ptr dd ?
;===
point_index1 dw ? ;-\
point_index2 dw ? ; } don't change order
point_index3 dw ? ;-/
temp_col dw ?
high dd ?
rand_seed dw ?
align 8
buffer dq ?
err dd ?
drr dd ?
xx dd ?
yy dd ?
xst dd ?
yst dd ?
; screen_ptr dd ?
; Zbuffer_ptr dd ?
matrix rb 36
cos_tab rd 360
sin_tab rd 360
align 16
if USE_LFN = 0
points:
rw (EndFile-SourceFile)/12*3
points_count = ($-points)/6
triangles:
rw (EndFile-SourceFile)/12*3
triangles_count = ($-triangles)/6
align 16
real_points rd points_count*3 + 1
align 16
rotated_points_r rd points_count*3 + 1
align 16
points_rotated rw points_count*3 + 2 ;means translated
align 16
triangles_normals rb triangles_count * 12 ;
align 16
point_normals rb points_count * 12 ;one 3dvector - triple float dword x,y,z
align 16
point_normals_rotated rb points_count * 12
align 16
triangles_normals_rotated rb triangles_count * 12
else
points_count = 180000/6*3
triangles_count = 180000 / 6 ;($-triangles)/6
end if
align 16
label trizdd dword
label trizdq qword
triangles_with_z rw triangles_count*4 + 2 ; triangles triple dw + z position
align 16
vectors rb 24
;align 16
; points_color rb 6*points_count ; each color as word
; sorted_triangles rw triangles_count*3 + 2
align 16
bumpmap rb TEXTURE_SIZE + 1
align 16
bumpmap2 rb TEXTURE_SIZE + 1
align 16
envmap rb (TEXTURE_SIZE +1) * 3
align 16
envmap_cub rb TEX_X * 3
align 16
texmap rb (TEXTURE_SIZE +1) * 3
align 16
color_map rb (TEXTURE_SIZE +1) * 3
align 16
tex_points rb points_count * 4 ; bump_map and texture coords
; each point word x, word y
align 16
; SourceFile: ; source file temporally in screen area
; workarea dd ?
; screen rb SIZE_X * SIZE_Y * 3 ; screen buffer
;align 16
; Z_buffer rb SIZE_X * SIZE_Y * 4
I_Param rb 256
memStack rb 4000 ;memory area for stack
align 16
screen:

View File

@ -0,0 +1,31 @@
View3ds 0.053 - tiny viewer to .3ds files.
What's new?
1. Optimizations.
Buttons description:
1. rotary: choosing rotary axle: x, y, x+y.
2. shd. model: choosing shading model: flat, grd (smooth), env (spherical
environment mapping, bump (bump mapping), tex (texture mapping),
pos (position shading depend), dots (app draws only points - nodes of object),
txgrd (texture mapping + smooth shading), 2tex (texture mapping + spherical
environment mapping), bmap (bump + texture mapping), cenv (cubic environment
mapping).
3. speed: idle, full.
4,5. zoom in, out: no comment.
6. catmull: on( use z buffer ( z coordinate interpolation), off( depth sorting, painters alghoritm).
txgrd and 2tex models only with catmull = on.
7. culling: backface culling on/ off.
8. rand. light: Randomize 3 unlinear lights( so called Phong's illumination).
9. Blur: blur N times; N=0,1,2,3,4,5
10.11,12,13. loseless operations (rotary 90, 180 degrees).
12. emboss: Do emboss effect( flat bumps ), use blur to do edges more deep.
carefull with emboss + fire - it looks annoying.
13. fire: do movement blur ( looks like fire ).
14. move: changes meaning x,y,z +/- buttons -> obj: moving object, camr: moving camera.
15. generate: Generates some objects: node, Thorn Crown, heart...
16. bumps: random, according to texture.
15. bumps deep -> create bumps deeper or lighter.
Macgub X 2009