3dsheart src uploaded

git-svn-id: svn://kolibrios.org@2271 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2011-10-06 01:23:34 +00:00
parent 0e155e3784
commit 6dd203912d
14 changed files with 6430 additions and 4 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,134 @@
macro .comment
{
init_envmap: ; create 512x512 env map
.temp equ word [ebp-2]
push ebp
mov ebp,esp
sub esp,2
mov edi,envmap
fninit
mov dx,-256
.ie_ver:
mov cx,-256
.ie_hor:
mov .temp,cx
fild .temp
fmul st,st0
mov .temp,dx
fild .temp
fmul st,st0
faddp
fsqrt
mov .temp,254
fisubr .temp
fmul [env_const]
fistp .temp
mov ax,.temp
or ax,ax
jge .ie_ok1
xor ax,ax
jmp .ie_ok2
.ie_ok1:
cmp ax,254
jle .ie_ok2
mov ax,254
.ie_ok2:
push dx
mov bx,ax
mul [max_color_b]
shr ax,8
stosb
mov ax,bx
mul [max_color_g]
shr ax,8
stosb
mov ax,bx
mul [max_color_r]
shr ax,8
stosb
pop dx
inc cx
cmp cx,256
jne .ie_hor
inc dx
cmp dx,256
jne .ie_ver
mov esp,ebp
pop ebp
ret
}
calc_bumpmap: ; calculate random bumpmap
;--------------in edi _ pointer to TEX_X x TEX_Y bumpmap
push edi
mov ecx,TEXTURE_SIZE
@@:
push ecx
xor ecx,ecx
mov edx,255
call random
stosb
pop ecx
loop @b
pop edi
mov ecx,4
.blur:
xor esi,esi
mov edx,TEXTURE_SIZE
xor eax,eax
xor ebx,ebx
@@:
mov ebp,esi
dec ebp
and ebp,TEXTURE_SIZE
mov al,byte[ebp+edi]
mov ebp,esi
inc ebp
and ebp,TEXTURE_SIZE
mov bl,byte[ebp+edi]
add eax,ebx
mov ebp,esi
sub ebp,TEX_X
and ebp,TEXTURE_SIZE
mov bl,byte[ebp+edi]
add eax,ebx
mov ebp,esi
add ebp,TEX_X
and ebp,TEXTURE_SIZE
mov bl,byte[ebp+edi]
add eax,ebx
shr eax,2
mov byte[esi+edi],al
inc esi
dec edx
jnz @b
loop .blur
ret
random:
; in - ecx - min
; edx - max
; out - eax - random number
mov bx,[rand_seed]
add bx,0x9248
ror bx,3
mov [rand_seed],bx
mov ax,dx
sub ax,cx
mul bx
mov ax,dx
add ax,cx
cwde
ret
rand_seed dw ?

View File

@ -0,0 +1 @@
fasm 3dsheart.asm 3dsheart

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

View File

@ -0,0 +1,769 @@
;SIZE_X equ 350
;SIZE_Y equ 350
ROUND equ 8
;TEX_X equ 512
;TEX_Y equ 512
;TEXTURE_SIZE EQU (512*512)-1
;TEX_SHIFT EQU 9
CATMULL_SHIFT equ 8
;TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1
;------- Big thanks to Majuma (www.majuma.xt.pl) for absolutely great---
;------- DOS 13h mode demos --------------------------------------------
;------- Procedure draws bump triangle using Catmull Z-buffer algorithm-
;------- (Z coordinate interpolation)-----------------------------------
bump_triangle_z:
;------------------in - eax - x1 shl 16 + y1 -----------
;---------------------- ebx - x2 shl 16 + y2 -----------
;---------------------- ecx - x3 shl 16 + y3 -----------
;---------------------- edx - pointer to bump map ------
;---------------------- esi - pointer to environment map
;---------------------- edi - pointer to screen buffer--
;---------------------- stack : bump coordinates--------
;---------------------- environment coordinates-
;---------------------- Z position coordinates--
;---------------------- pointer io Z buffer-----
;-- Z-buffer - filled with coordinates as dword --------
;-- (Z coor. as word) shl CATMULL_SHIFT ----------------
.b_x1 equ ebp+4 ; procedure don't save registers !!!
.b_y1 equ ebp+6 ; each coordinate as word
.b_x2 equ ebp+8
.b_y2 equ ebp+10
.b_x3 equ ebp+12
.b_y3 equ ebp+14
.e_x1 equ ebp+16
.e_y1 equ ebp+18
.e_x2 equ ebp+20
.e_y2 equ ebp+22
.e_x3 equ ebp+24
.e_y3 equ ebp+26
.z1 equ word[ebp+28]
.z2 equ word[ebp+30]
.z3 equ word[ebp+32]
.z_buff equ dword[ebp+34] ; pointer to Z-buffer
.t_bmap equ dword[ebp-4] ; pointer to bump map
.t_emap equ dword[ebp-8] ; pointer to e. map
.x1 equ word[ebp-10]
.y1 equ word[ebp-12]
.x2 equ word[ebp-14]
.y2 equ word[ebp-16]
.x3 equ word[ebp-18]
.y3 equ word[ebp-20]
.dx12 equ dword[ebp-24]
.dbx12 equ dword[ebp-28]
.dby12 equ dword[ebp-32]
.dex12 equ dword[ebp-36]
.dey12 equ dword[ebp-40]
.dz12 equ dword[ebp-44]
.dx13 equ dword[ebp-48]
.dbx13 equ dword[ebp-52]
.dby13 equ dword[ebp-56]
.dex13 equ dword[ebp-60]
.dey13 equ dword[ebp-64]
.dz13 equ dword[ebp-68]
.dx23 equ dword[ebp-72]
.dbx23 equ dword[ebp-76]
.dby23 equ dword[ebp-80]
.dex23 equ dword[ebp-84]
.dey23 equ dword[ebp-88]
.dz23 equ dword[ebp-92]
.cx1 equ dword[ebp-96] ; current variables
.cx2 equ dword[ebp-100]
.cbx1 equ dword[ebp-104]
.cbx2 equ dword[ebp-108]
.cby1 equ dword[ebp-112]
.cby2 equ dword[ebp-116]
.cex1 equ dword[ebp-120]
.cex2 equ dword[ebp-124]
.cey1 equ dword[ebp-128]
.cey2 equ dword[ebp-132]
.cz1 equ dword[ebp-136]
.cz2 equ dword[ebp-140]
mov ebp,esp
push edx ; store bump map
push esi ; store e. map
; sub esp,120
.sort3: ; sort triangle coordinates...
cmp ax,bx
jle .sort1
xchg eax,ebx
mov edx,dword[.b_x1]
xchg edx,dword[.b_x2]
mov dword[.b_x1],edx
mov edx,dword[.e_x1]
xchg edx,dword[.e_x2]
mov dword[.e_x1],edx
mov dx,.z1
xchg dx,.z2
mov .z1,dx
.sort1:
cmp bx,cx
jle .sort2
xchg ebx,ecx
mov edx,dword[.b_x2]
xchg edx,dword[.b_x3]
mov dword[.b_x2],edx
mov edx,dword[.e_x2]
xchg edx,dword[.e_x3]
mov dword[.e_x2],edx
mov dx,.z2
xchg dx,.z3
mov .z2,dx
jmp .sort3
.sort2:
push eax ; store triangle coords in variables
push ebx
push ecx
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .loop23_done
; mov edx,eax ; eax,ebx,ecx are ORd together into edx which means that
; or edx,ebx ; if any *one* of them is negative a sign flag is raised
; or edx,ecx
; test edx,80000000h ; Check only X
; jne .loop23_done
; cmp .x1,SIZE_X ; {
; jg .loop23_done
; cmp .x2,SIZE_X ; This can be optimized with effort
; jg .loop23_done
; cmp .x3,SIZE_X
; jg .loop23_done ; {
mov bx,.y2 ; calc delta 12
sub bx,.y1
jnz .bt_dx12_make
mov ecx,6
xor edx,edx
@@:
push edx ;dword 0
loop @b
jmp .bt_dx12_done
.bt_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx12,eax
push eax
mov ax,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
mov ax,.z2
sub ax,.z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
.bt_dx12_done:
mov bx,.y3 ; calc delta13
sub bx,.y1
jnz .bt_dx13_make
mov ecx,6
xor edx,edx
@@:
push edx ;dword 0
loop @b
jmp .bt_dx13_done
.bt_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx13,eax
push eax
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
; nop here bug ????!!!
mov ax,.z3
sub ax,.z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
; mov .dz13,eax
push eax
.bt_dx13_done:
mov bx,.y3 ; calc delta23
sub bx,.y2
jnz .bt_dx23_make
mov ecx,6
xor edx,edx
@@:
push edx ;dword 0
loop @b
jmp .bt_dx23_done
.bt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx23,eax
push eax
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
mov ax,.z3
sub ax,.z2
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
; mov .dz23,eax
push eax
; sub esp,40
.bt_dx23_done:
movsx eax,.x1
shl eax,ROUND
; mov .cx1,eax
; mov .cx2,eax
push eax
push eax
movsx eax,word[.b_x1]
shl eax,ROUND
; mov .cbx1,eax
; mov .cbx2,eax
push eax
push eax
movsx eax,word[.b_y1]
shl eax,ROUND
; mov .cby1,eax
; mov .cby2,eax
push eax
push eax
movsx eax,word[.e_x1]
shl eax,ROUND
;mov .cex1,eax
;mov .cex2,eax
push eax
push eax
movsx eax,word[.e_y1]
shl eax,ROUND
;mov .cey1,eax
;mov .cey2,eax
push eax
push eax
movsx eax,.z1
shl eax,CATMULL_SHIFT
;mov .cz1,eax
;mov .cz2,eax
push eax
push eax
movsx ecx,.y1
cmp cx,.y2
jge .loop12_done
.loop12:
call .call_bump_line
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
mov eax,.dz13
add .cz1,eax
mov eax,.dz12
add .cz2,eax
inc ecx
cmp cx,.y2
jl .loop12
.loop12_done:
movsx ecx,.y2
cmp cx,.y3
jge .loop23_done
movsx eax,.z2
shl eax,CATMULL_SHIFT
mov .cz2,eax
movsx eax,.x2
shl eax,ROUND
mov .cx2,eax
movzx eax,word[.b_x2]
shl eax,ROUND
mov .cbx2,eax
movzx eax,word[.b_y2]
shl eax,ROUND
mov .cby2,eax
movzx eax,word[.e_x2]
shl eax,ROUND
mov .cex2,eax
movzx eax,word[.e_y2]
shl eax,ROUND
mov .cey2,eax
.loop23:
call .call_bump_line
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
mov eax,.dz13
add .cz1,eax
mov eax,.dz23
add .cz2,eax
inc ecx
cmp cx,.y3
jl .loop23
.loop23_done:
mov esp,ebp
ret 34
.call_bump_line:
; push ebp
; push ecx
pushad
push .cz1
push .cz2
push .z_buff
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_z
popad
ret
bump_line_z:
;--------------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]
.z_buff equ dword [ebp+48]
.z2 equ dword [ebp+52] ; -- |> z coords shifted
.z1 equ dword [ebp+56] ; -- shl CATMULL_SHIFT
.x1 equ dword [ebp-4]
.x2 equ dword [ebp-8]
.dbx equ dword [ebp-12]
.dby equ dword [ebp-16]
.dex equ dword [ebp-20]
.dey equ dword [ebp-24]
.dz equ dword [ebp-28]
.cbx equ dword [ebp-32]
.cby equ dword [ebp-36]
.cex equ dword [ebp-40]
.cey equ dword [ebp-44]
.cz equ dword [ebp-48]
.czbuff equ dword [ebp-52]
mov ebp,esp
mov ecx,.y
or ecx,ecx
jl .bl_end
cmp ecx,SIZE_Y
jge .bl_end
cmp eax,ebx
jl .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
mov edx,.z1
xchg edx,.z2
mov .z1,edx
.bl_ok:
push eax
push ebx ;store x1, x2
cmp .x1,SIZE_X
jge .bl_end
cmp .x2,0
jle .bl_end
mov ebx,.x2
sub ebx,.x1
mov eax,.bx2 ; calc .dbx
sub eax,.bx1
cdq
idiv ebx
push eax
mov eax,.by2 ; calc .dby
sub eax,.by1
cdq
idiv ebx
push eax
mov eax,.ex2 ; calc .dex
sub eax,.ex1
cdq
idiv ebx
push eax
mov eax,.ey2 ; calc .dey
sub eax,.ey1
cdq
idiv ebx
push eax
mov eax,.z2 ; calc .dz
sub eax,.z1
cdq
idiv ebx
push eax
cmp .x1,0 ; set correctly begin variable
jge @f ; CLIPPING ON FUNCTION
; cutting triangle exceedes screen
mov ebx,.x1
neg ebx
imul ebx ; eax = .dz * abs(.x1)
add .z1,eax
mov .x1,0
mov eax,.dbx
imul ebx
add .bx1,eax
mov eax,.dby
imul ebx
add .by1,eax
mov eax,.dex
imul ebx
add .ex1,eax
mov eax,.dey
imul ebx
add .ey1,eax
@@:
cmp .x2,SIZE_X
jl @f
mov .x2,SIZE_X
@@:
mov eax,SIZE_X ;calc memory begin in buffers
mov ebx,.y
mul ebx
mov ebx,.x1
add eax,ebx
mov ebx,eax
lea eax,[eax*3]
add edi,eax
mov esi,.z_buff ; z-buffer filled with dd variables
shl ebx,2
add esi,ebx
mov ecx,.x2
sub ecx,.x1
; init current variables
push .bx1
push .by1
push .ex1
push .ey1
push .z1 ; current z shl CATMULL_SHIFT
push esi
.draw:
; if TEX = SHIFTING ;bump drawing only in shifting mode
mov esi,.czbuff ; .czbuff current address in buffer
mov ebx,.cz ; .cz - cur z position
cmp ebx,dword[esi]
jge .skip
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 ebx,.cz
mov esi,.czbuff
mov dword[esi],ebx
jmp .no_skip
.skip:
add edi,3
.no_skip:
add .czbuff,4
mov eax,.dbx
add .cbx,eax
mov eax,.dby
add .cby,eax
mov eax,.dex
add .cex,eax
mov eax,.dey
add .cey,eax
mov eax,.dz
add .cz,eax
dec ecx
jnz .draw
; end if
.bl_end:
mov esp,ebp
ret 56

View File

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

View File

@ -0,0 +1,342 @@
CATMULL_SHIFT equ 16
fill_Z_buffer:
mov eax,0x70000000
mov edi,Z_buffer
mov ecx,SIZE_X*SIZE_Y
rep stosd
ret
flat_triangle_z:
; procedure drawing triangle with Z cordinate interpolation ------
; (Catmull alghoritm)--------------------------------------------
; ----------------in - eax - x1 shl 16 + y1 ----------------------
; -------------------- ebx - x2 shl 16 + y2 ----------------------
; -------------------- ecx - x3 shl 16 + y3 ----------------------
; -------------------- edx - color 0x00RRGGBB --------------------
; -------------------- esi - pointer to Z-buffer -----------------
; -------------------- edi - pointer to screen buffer-------------
; -------------------- stack : z coordinates
; -------------------- Z-buffer : each z variable as dword
; -------------------- (Z coor. as word) shl CATMULL_SHIFT
.z1 equ word[ebp+4]
.z2 equ word[ebp+6] ; each z coordinate as word integer
.z3 equ word[ebp+8]
.col equ dword[ebp-4]
.x1 equ word[ebp-6]
.y1 equ word[ebp-8]
.x2 equ word[ebp-10]
.y2 equ word[ebp-12]
.x3 equ word[ebp-14]
.y3 equ word[ebp-16]
.dx12 equ dword[ebp-20]
.dz12 equ dword[ebp-24]
.dx13 equ dword[ebp-28]
.dz13 equ dword[ebp-32]
.dx23 equ dword[ebp-36]
.dz23 equ dword[ebp-40]
.zz1 equ dword[ebp-44]
.zz2 equ dword[ebp-48]
mov ebp,esp
push edx ; store edx in variable .col
.sort2:
cmp ax,bx
jle .sort1
xchg eax,ebx
mov dx,.z1
xchg dx,.z2
mov .z1,dx
.sort1:
cmp bx,cx
jle .sort3
xchg ebx,ecx
mov dx,.z2
xchg dx,.z3
mov .z2,dx
jmp .sort2
.sort3:
push eax ; store triangle coordinates in user friendly variables
push ebx
push ecx
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .ft_loop2_end
; cmp ax,SIZE_Y
; jle @f
; cmp bx,SIZE_Y
; jle @f
; cmp cx,SIZE_Y
; jge @f
; ror eax,16
; ror ebx,16
; ror ecx,16
; cmp ax,SIZE_X
; jle @f
; cmp bx,SIZE_X
; jle @f
; cmp cx,SIZE_X
; jle @f
; jmp .ft_loop2_end
;@@:
sub esp,32
mov bx,.y2 ; calc delta 12
sub bx,.y1
jnz .ft_dx12_make
mov .dx12,0
mov .dz12,0
jmp .ft_dx12_done
.ft_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
mov .dx12,eax
mov ax,.z2
sub ax,.z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
mov .dz12,eax
.ft_dx12_done:
mov bx,.y3 ; calc delta 13
sub bx,.y1
jnz .ft_dx13_make
mov .dx13,0
mov .dz13,0
jmp .ft_dx13_done
.ft_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
mov .dx13,eax
mov ax,.z3
sub ax,.z1
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
mov .dz13,eax
.ft_dx13_done:
mov bx,.y3 ; calc delta 23
sub bx,.y2
jnz .gt_dx23_make
mov .dx23,0
mov .dz23,0
jmp .gt_dx23_done
.gt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
mov .dx23,eax
mov ax,.z3
sub ax,.z2
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
mov .dz23,eax
.gt_dx23_done:
movsx edx,.z1
shl edx,CATMULL_SHIFT
mov .zz1,edx
mov .zz2,edx
movsx eax,.x1
shl eax,ROUND ; eax - x1
mov ebx,eax ; ebx - x2
mov cx,.y1
cmp cx,.y2
jge .ft_loop1_end
.ft_loop1:
pushad
push .col
push cx ; y
sar ebx,ROUND
push bx ; x2
sar eax,ROUND
push ax ; x1
push .zz2 ; z2 shl CATMULL_SHIFT
push .zz1 ; z1 shl CATMULL_SHIFT
call flat_line_z
popad
add eax,.dx13
add ebx,.dx12
mov edx,.dz13
add .zz1,edx
mov edx,.dz12
add .zz2,edx
inc cx
cmp cx,.y2
jl .ft_loop1
.ft_loop1_end:
movsx edx,.z2
shl edx,CATMULL_SHIFT
mov .zz2,edx
movsx ebx,.x2
shl ebx,ROUND
mov cx,.y2
cmp cx,.y3
jge .ft_loop2_end
.ft_loop2:
pushad
push .col
push cx
sar ebx,ROUND
push bx
sar eax,ROUND
push ax ; x1
push .zz2 ; z2 shl CATMULL_SHIFT
push .zz1 ; z1 shl CATMULL_SHIFT
call flat_line_z
popad
add eax,.dx13
add ebx,.dx23
mov edx,.dz13
add .zz1,edx
mov edx,.dz23
add .zz2,edx
inc cx
cmp cx,.y3
jl .ft_loop2
.ft_loop2_end:
mov esp,ebp
ret 6
flat_line_z:
;----------------
;-------------in edi - pointer to screen buffer ----------------------------------
;--------------- esi - pointer to z-buffer (each Z varible dword)-----------------
;----------stack - (each z coordinate shifted shl CATMULL_SHIFT)------------------
.z1 equ dword [ebp+4]
.z2 equ dword [ebp+8]
.x1 equ word [ebp+12]
.x2 equ word [ebp+14]
.y equ word [ebp+16]
.col equ dword [ebp+18]
.dz equ dword [ebp-4]
mov ebp,esp
;; sub esp,4
mov ax,.y
or ax,ax
jl .fl_quit
cmp ax,SIZE_Y-1
jg .fl_quit
; cmp .x1,0
; jge .fl_ok1
; cmp .x2,0
; jl .fl_quit
; .fl_ok1:
; cmp .x1,SIZE_X
; jle .fl_ok2
; cmp .x2,SIZE_X
; jg .fl_quit
; .fl_ok2:
mov ax,.x1
cmp ax,.x2
je .fl_quit
jl .fl_ok
xchg ax,.x2
mov .x1,ax
mov edx,.z1
xchg edx,.z2
mov .z1,edx
.fl_ok:
cmp .x1,SIZE_X-1
jg .fl_quit
cmp .x2,0
jle .fl_quit
mov eax,.z2
sub eax,.z1
cdq
mov bx,.x2
sub bx,.x1
movsx ebx,bx
idiv ebx
;; mov .dz,eax ; calculated delta - shifted .dz
push eax
cmp .x1,0
jge @f
movsx ebx,.x1
neg ebx
imul ebx
add .z1,eax
mov .x1,0
@@:
cmp .x2,SIZE_X
jl @f
mov .x2,SIZE_X
@@:
mov edx,SIZE_X
movsx eax,.y
mul edx ; edi = edi + (SIZE_X * y + x1)*3
movsx edx,.x1
add eax,edx
push eax
lea eax,[eax*3]
add edi,eax ; esi = esi + (SIZE_X * y + x1)*4
pop eax
shl eax,2
add esi,eax
mov cx,.x2
sub cx,.x1
movzx ecx,cx
mov eax,.col
mov ebx,.z1 ; ebx : curr. z
mov edx,.dz
.ddraw:
;pushad
;show
;popad
cmp ebx,dword[esi]
jge .skip
stosd
dec edi
mov dword[esi],ebx
jmp .no_skip
.skip:
add edi,3
.no_skip:
add esi,4
add ebx,edx
loop .ddraw
.fl_quit:
mov esp,ebp
ret 18

View File

@ -0,0 +1,481 @@
gouraud_triangle:
;------------------in - eax - x1 shl 16 + y1 ---------
;---------------------- ebx - x2 shl 16 + y2 ---------
;---------------------- ecx - x3 shl 16 + y3 ---------
;---------------------- edi - pointer to screen buffer
;---------------------- stack : colors----------------
;----------------- procedure don't save registers !!--
.col1r equ ebp+4 ; each color as word
.col1g equ ebp+6
.col1b equ ebp+8
.col2r equ ebp+10
.col2g equ ebp+12
.col2b equ ebp+14
.col3r equ ebp+16
.col3g equ ebp+18
.col3b equ ebp+20
.x1 equ word[ebp-2]
.y1 equ word[ebp-4]
.x2 equ word[ebp-6]
.y2 equ word[ebp-8]
.x3 equ word[ebp-10]
.y3 equ word[ebp-12]
.dc12r equ dword[ebp-16]
.dc12g equ dword[ebp-20]
.dc12b equ dword[ebp-24]
.dc13r equ dword[ebp-28]
.dc13g equ dword[ebp-32]
.dc13b equ dword[ebp-36]
.dc23r equ dword[ebp-40]
.dc23g equ dword[ebp-44]
.dc23b equ dword[ebp-48]
.c1r equ dword[ebp-52]
.c1g equ dword[ebp-56]
.c1b equ dword[ebp-60]
.c2r equ dword[ebp-64]
.c2g equ dword[ebp-68]
.c2b equ dword[ebp-72]
.dx12 equ dword[ebp-76]
.dx13 equ dword[ebp-80]
.dx23 equ dword[ebp-84]
mov ebp,esp
; sub esp,72
.sort3: ; sort triangle coordinates...
cmp ax,bx
jle .sort1
xchg eax,ebx
mov edx,dword[.col1r]
xchg edx,dword[.col2r]
mov dword[.col1r],edx
mov dx,word[.col1b]
xchg dx,word[.col2b]
mov word[.col1b],dx
.sort1:
cmp bx,cx
jle .sort2
xchg ebx,ecx
mov edx,dword[.col2r]
xchg edx,dword[.col3r]
mov dword[.col2r],edx
mov dx,word[.col2b]
xchg dx,word[.col3b]
mov word[.col2b],dx
jmp .sort3
.sort2:
push eax ;store triangle coordinates in user friendly variables
push ebx
push ecx
sub esp,72 ; set correctly value of esp
mov edx,eax ; check only X triangle coordinate
or edx,ebx
or edx,ecx
test edx,80000000h
jne .gt_loop2_end
shr eax,16
cmp ax,SIZE_X-1
jg .gt_loop2_end
shr ebx,16
cmp bx,SIZE_X-1
jg .gt_loop2_end
shr ecx,16
cmp cx,SIZE_X-1
jg .gt_loop2_end
mov bx,.y2 ; calc deltas
sub bx,.y1
jnz .gt_dx12_make
mov .dx12,0
mov .dc12r,0
mov .dc12g,0
mov .dc12b,0
jmp .gt_dx12_done
.gt_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
mov .dx12,eax
mov ax,word[.col2r]
sub ax,word[.col1r]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc12r,eax
mov ax,word[.col2g]
sub ax,word[.col1g]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc12g,eax
mov ax,word[.col2b]
sub ax,word[.col1b]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc12b,eax
.gt_dx12_done:
mov bx,.y3
sub bx,.y1
jnz .gt_dx13_make
mov .dx13,0
mov .dc13r,0
mov .dc13g,0
mov .dc13b,0
jmp .gt_dx13_done
.gt_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
mov .dx13,eax
mov ax,word[.col3r]
sub ax,word[.col1r]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc13r,eax
mov ax,word[.col3g]
sub ax,word[.col1g]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc13g,eax
mov ax,word[.col3b]
sub ax,word[.col1b]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc13b,eax
.gt_dx13_done:
mov bx,.y3
sub bx,.y2
jnz .gt_dx23_make
mov .dx23,0
mov .dc23r,0
mov .dc23g,0
mov .dc23b,0
jmp .gt_dx23_done
.gt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
mov .dx23,eax
mov ax,word[.col3r]
sub ax,word[.col2r]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc23r,eax
mov ax,word[.col3g]
sub ax,word[.col2g]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc23g,eax
mov ax,word[.col3b]
sub ax,word[.col2b]
cwde
shl eax,ROUND
cdq
idiv ebx
mov .dc23b,eax
.gt_dx23_done:
movsx eax,.x1
shl eax,ROUND
mov ebx,eax
movsx edx,word[.col1r]
shl edx,ROUND
mov .c1r,edx
mov .c2r,edx
movsx edx,word[.col1g]
shl edx,ROUND
mov .c1g,edx
mov .c2g,edx
movsx edx,word[.col1b]
shl edx,ROUND
mov .c1b,edx
mov .c2b,edx
mov cx,.y1
cmp cx,.y2
jge .gt_loop1_end
.gt_loop1:
push eax ; eax - cur x1
push ebx ; ebx - cur x2
push cx ; cx - cur y
push edi
push ebp
mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors
sar edx,ROUND
push dx
mov edx,.c2g
sar edx,ROUND
push dx
mov edx,.c2b
sar edx,ROUND
push dx
mov edx,.c1r
sar edx,ROUND
push dx
mov edx,.c1g
sar edx,ROUND
push dx
mov edx,.c1b
sar edx,ROUND
push dx
push cx
sar ebx,ROUND
push bx
sar eax,ROUND
push ax
call gouraud_line
pop ebp
pop edi
pop cx
pop ebx
pop eax
mov edx,.dc13r
add .c1r,edx
mov edx,.dc13g
add .c1g,edx
mov edx,.dc13b
add .c1b,edx
mov edx,.dc12r
add .c2r,edx
mov edx,.dc12g
add .c2g,edx
mov edx,.dc12b
add .c2b,edx
add eax,.dx13
add ebx,.dx12
inc cx
cmp cx,.y2
jl .gt_loop1
.gt_loop1_end:
mov cx,.y2
cmp cx,.y3
jge .gt_loop2_end
movsx ebx,.x2
shl ebx,ROUND
movsx edx,word[.col2r]
shl edx,ROUND
mov .c2r,edx
movsx edx,word[.col2g]
shl edx,ROUND
mov .c2g,edx
movsx edx,word[.col2b]
shl edx,ROUND
mov .c2b,edx
.gt_loop2:
push eax ; eax - cur x1
push ebx ; ebx - cur x2
push cx
push edi
push ebp
mov edx,.c2r
sar edx,ROUND
push dx
mov edx,.c2g
sar edx,ROUND
push dx
mov edx,.c2b
sar edx,ROUND
push dx
mov edx,.c1r
sar edx,ROUND
push dx
mov edx,.c1g
sar edx,ROUND
push dx
mov edx,.c1b
sar edx,ROUND
push dx
push cx
sar ebx,ROUND
push bx
sar eax,ROUND
push ax
call gouraud_line
pop ebp
pop edi
pop cx
pop ebx
pop eax
mov edx,.dc13r
add .c1r,edx
mov edx,.dc13g
add .c1g,edx
mov edx,.dc13b
add .c1b,edx
mov edx,.dc23r
add .c2r,edx
mov edx,.dc23g
add .c2g,edx
mov edx,.dc23b
add .c2b,edx
add eax,.dx13
add ebx,.dx23
inc cx
cmp cx,.y3
jl .gt_loop2
.gt_loop2_end:
; add esp,84
mov esp,ebp
ret 18
gouraud_line:
;-------------in - edi - pointer to screen buffer
;----------------- stack - another parameters
.x1 equ word [ebp+4]
.x2 equ word [ebp+6]
.y equ word [ebp+8]
.col1b equ ebp+10
.col1g equ ebp+12
.col1r equ ebp+14
.col2b equ ebp+16
.col2g equ ebp+18
.col2r equ ebp+20
.dc_r equ dword[ebp-4]
.dc_g equ dword[ebp-8]
.dc_b equ dword[ebp-12]
mov ebp,esp
mov ax,.y
or ax,ax
jl .gl_quit
cmp ax,SIZE_Y-1
jg .gl_quit
mov ax,.x1
cmp ax,.x2
je .gl_quit
jl .gl_ok
xchg ax,.x2
mov .x1,ax
mov eax,dword[.col1b]
xchg eax,dword[.col2b]
mov dword[.col1b],eax
mov ax,word[.col1r]
xchg ax,word[.col2r]
mov word[.col1r],ax
.gl_ok:
; cmp .x1,SIZE_X-1 ;check
; jg .gl_quit
; cmp .x2,SIZE_X-1
; jl @f
; mov .x2,SIZE_X-1
; @@:
; cmp .x1,0
; jg @f
; mov .x1,0
; @@:
; cmp .x2,0
; jl .gl_quit
movsx ecx,.y
mov eax,SIZE_X*3
mul ecx
movsx ebx,.x1
lea ecx,[ebx*2+eax]
add edi,ecx
add edi,ebx
mov ax,word[.col2r]
sub ax,word[.col1r]
cwde
shl eax,ROUND
cdq
mov cx,.x2
sub cx,.x1
movsx ecx,cx
idiv ecx
;mov .dc_r,eax ;first delta
push eax
mov ax,word[.col2g]
sub ax,word[.col1g]
cwde
shl eax,ROUND
cdq
idiv ecx
;mov .dc_g,eax
push eax
mov ax,word[.col2b]
sub ax,word[.col1b]
cwde
shl eax,ROUND
cdq
idiv ecx
; mov .dc_b,eax
push eax
movsx ebx,word[.col1r]
shl ebx,ROUND
movsx edx,word[.col1g]
shl edx,ROUND
movsx esi,word[.col1b]
shl esi,ROUND
.gl_draw:
mov eax,ebx
sar eax,ROUND
stosb
mov eax,edx
sar eax,ROUND
stosb
mov eax,esi
sar eax,ROUND
stosb
add ebx,.dc_r
add edx,.dc_g
add esi,.dc_b
loop .gl_draw
.gl_quit:
; add esp,12
mov esp,ebp
ret 18

View File

@ -0,0 +1,598 @@
ROUND equ 8
CATMULL_SHIFT equ 8
gouraud_triangle_z:
;----procedure drawing gouraud triangle with z coordinate
;----interpolation ( Catmull alghoritm )-----------------
;------------------in - eax - x1 shl 16 + y1 ------------
;---------------------- ebx - x2 shl 16 + y2 ------------
;---------------------- ecx - x3 shl 16 + y3 ------------
;---------------------- esi - pointer to Z-buffer--------
;---------------------- Z-buffer filled with dd variables
;---------------------- shifted CATMULL_SHIFT------------
;---------------------- edi - pointer to screen buffer---
;---------------------- stack : colors-------------------
;----------------- procedure don't save registers !!-----
.col1r equ ebp+4 ; each color as word
.col1g equ ebp+6 ; each z coordinate as word
.col1b equ ebp+8
.z1 equ ebp+10
.col2r equ ebp+12
.col2g equ ebp+14
.col2b equ ebp+16
.z2 equ ebp+18
.col3r equ ebp+20
.col3g equ ebp+22
.col3b equ ebp+24
.z3 equ ebp+26
.x1 equ word[ebp-2]
.y1 equ word[ebp-4]
.x2 equ word[ebp-6]
.y2 equ word[ebp-8]
.x3 equ word[ebp-10]
.y3 equ word[ebp-12]
.dx12 equ dword[ebp-16]
.dz12 equ dword[ebp-20]
.dc12r equ dword[ebp-24]
.dc12g equ dword[ebp-28]
.dc12b equ dword[ebp-32]
.dx13 equ dword[ebp-36]
.dz13 equ dword[ebp-40]
.dc13r equ dword[ebp-44]
.dc13g equ dword[ebp-48]
.dc13b equ dword[ebp-52]
.dx23 equ dword[ebp-56]
.dz23 equ dword[ebp-60]
.dc23r equ dword[ebp-64]
.dc23g equ dword[ebp-68]
.dc23b equ dword[ebp-72]
.c1r equ dword[ebp-76]
.c1g equ dword[ebp-80]
.c1b equ dword[ebp-84]
.c2r equ dword[ebp-88]
.c2g equ dword[ebp-92]
.c2b equ dword[ebp-96]
.zz1 equ dword[ebp-100]
.zz2 equ dword[ebp-104]
mov ebp,esp
; sub esp,84
.sort3: ; sort triangle coordinates...
cmp ax,bx
jle .sort1
xchg eax,ebx
mov edx,dword[.col1r]
xchg edx,dword[.col2r]
mov dword[.col1r],edx
mov edx,dword[.col1b]
xchg edx,dword[.col2b]
mov dword[.col1b],edx
.sort1:
cmp bx,cx
jle .sort2
xchg ebx,ecx
mov edx,dword[.col2r]
xchg edx,dword[.col3r]
mov dword[.col2r],edx
mov edx,dword[.col2b]
xchg edx,dword[.col3b]
mov dword[.col2b],edx
jmp .sort3
.sort2:
push eax ; store in variables
push ebx
push ecx
mov edx,80008000h ; eax,ebx,ecx are ANDd together into edx which means that
and edx,ebx ; if *all* of them are negative a sign flag is raised
and edx,ecx
and edx,eax
test edx,80008000h ; Check both X&Y at once
jne .gt_loop2_end
mov bx,.y2 ; calc deltas
sub bx,.y1
jnz .gt_dx12_make
; mov .dx12,0
; mov .dz12,0
; mov .dc12r,0
; mov .dc12g,0
; mov .dc12b,0
mov ecx,5
@@:
push dword 0
loop @b
jmp .gt_dx12_done
.gt_dx12_make:
mov ax,.x2
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx12,eax
push eax
mov ax,word[.z2]
sub ax,word[.z1]
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
mov ax,word[.col2r]
sub ax,word[.col1r]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc12r,eax
push eax
mov ax,word[.col2g]
sub ax,word[.col1g]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc12g,eax
push eax
mov ax,word[.col2b] ;;---
sub ax,word[.col1b]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc12b,eax
push eax
.gt_dx12_done:
mov bx,.y3 ; calc deltas
sub bx,.y1
jnz .gt_dx13_make
; mov .dx13,0
; mov .dz13,0
; mov .dc13r,0
; mov .dc13g,0
; mov .dc13b,0
mov ecx,5
@@:
push dword 0
loop @b
jmp .gt_dx13_done
.gt_dx13_make:
mov ax,.x3
sub ax,.x1
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx13,eax
push eax
mov ax,word[.z3]
sub ax,word[.z1]
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
mov ax,word[.col3r]
sub ax,word[.col1r]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc13r,eax
push eax
mov ax,word[.col3g]
sub ax,word[.col1g]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc13g,eax
push eax
mov ax,word[.col3b]
sub ax,word[.col1b]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc13b,eax
push eax
.gt_dx13_done:
mov bx,.y3 ; calc deltas
sub bx,.y2
jnz .gt_dx23_make
; mov .dx23,0
; mov .dz23,0
; mov .dc23r,0
; mov .dc23g,0
; mov .dc23b,0
mov ecx,5
@@:
push dword 0
loop @b
jmp .gt_dx23_done
.gt_dx23_make:
mov ax,.x3
sub ax,.x2
cwde
movsx ebx,bx
shl eax,ROUND
cdq
idiv ebx
; mov .dx23,eax
push eax
mov ax,word[.z3]
sub ax,word[.z2]
cwde
shl eax,CATMULL_SHIFT
cdq
idiv ebx
push eax
mov ax,word[.col3r]
sub ax,word[.col2r]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc23r,eax
push eax
mov ax,word[.col3g]
sub ax,word[.col2g]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc23g,eax
push eax
mov ax,word[.col3b]
sub ax,word[.col2b]
cwde
shl eax,ROUND
cdq
idiv ebx
; mov .dc23b,eax
push eax
.gt_dx23_done:
sub esp,32
movsx eax,.x1 ; eax - cur x1
shl eax,ROUND ; ebx - cur x2
mov ebx,eax
movsx edx,word[.z1]
shl edx,CATMULL_SHIFT
mov .zz1,edx
mov .zz2,edx
movzx edx,word[.col1r]
shl edx,ROUND
mov .c1r,edx
mov .c2r,edx
movzx edx,word[.col1g]
shl edx,ROUND
mov .c1g,edx
mov .c2g,edx
movzx edx,word[.col1b]
shl edx,ROUND
mov .c1b,edx
mov .c2b,edx
mov cx,.y1
cmp cx,.y2
jge .gt_loop1_end
.gt_loop1:
pushad
; macro .debug
mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors
sar edx,ROUND
push dx
mov edx,.c2g
sar edx,ROUND
push dx
mov edx,.c2b
sar edx,ROUND
push dx
sar ebx,ROUND ; x2
push bx
mov edx,.c1r
sar edx,ROUND
push dx
mov edx,.c1g
sar edx,ROUND
push dx
mov edx,.c1b
sar edx,ROUND
push dx
sar eax,ROUND
push ax ; x1
push cx ; y
push .zz2
push .zz1
call gouraud_line_z
popad
mov edx,.dc13r
add .c1r,edx
mov edx,.dc13g
add .c1g,edx
mov edx,.dc13b
add .c1b,edx
mov edx,.dc12r
add .c2r,edx
mov edx,.dc12g
add .c2g,edx
mov edx,.dc12b
add .c2b,edx
mov edx,.dz13
add .zz1,edx
mov edx,.dz12
add .zz2,edx
add eax,.dx13
add ebx,.dx12
inc cx
cmp cx,.y2
jl .gt_loop1
.gt_loop1_end:
mov cx,.y2
cmp cx,.y3
jge .gt_loop2_end
movsx ebx,.x2 ; eax - cur x1
shl ebx,ROUND ; ebx - cur x2
movsx edx,word[.z2]
shl edx,CATMULL_SHIFT
mov .zz2,edx
movzx edx,word[.col2r]
shl edx,ROUND
mov .c2r,edx
movzx edx,word[.col2g]
shl edx,ROUND
mov .c2g,edx
movzx edx,word[.col2b]
shl edx,ROUND
mov .c2b,edx
.gt_loop2:
pushad
; macro .debug
mov edx,.c2r ; c2r,c2g,c2b,c1r,c1g,c1b - current colors
sar edx,ROUND
push dx
mov edx,.c2g
sar edx,ROUND
push dx
mov edx,.c2b
sar edx,ROUND
push dx
sar ebx,ROUND ; x2
push bx
mov edx,.c1r
sar edx,ROUND
push dx
mov edx,.c1g
sar edx,ROUND
push dx
mov edx,.c1b
sar edx,ROUND
push dx
sar eax,ROUND
push ax ; x1
push cx ; y
push .zz2
push .zz1
call gouraud_line_z
popad
mov edx,.dc13r
add .c1r,edx
mov edx,.dc13g
add .c1g,edx
mov edx,.dc13b
add .c1b,edx
mov edx,.dc23r
add .c2r,edx
mov edx,.dc23g
add .c2g,edx
mov edx,.dc23b
add .c2b,edx
mov edx,.dz13
add .zz1,edx
mov edx,.dz23
add .zz2,edx
add eax,.dx13
add ebx,.dx23
inc cx
cmp cx,.y3
jl .gt_loop2
.gt_loop2_end:
mov esp,ebp
ret 24
gouraud_line_z:
;----------------- procedure drawing gouraud line
;----------------- with z coordinate interpolation
;----------------- esi - pointer to Z_buffer
;----------------- edi - pointer to screen buffer
;----------------- stack:
.z1 equ dword[ebp+4] ; z coordiunate shifted left CATMULL_SHIFT
.z2 equ dword[ebp+8]
.y equ word[ebp+12]
.x1 equ ebp+14
.c1b equ ebp+16
.c1g equ ebp+18
.c1r equ ebp+20
.x2 equ ebp+22
.c2b equ ebp+24
.c2g equ ebp+26
.c2r equ ebp+28
.dz equ dword[ebp-4]
.dc_r equ dword[ebp-8]
.dc_g equ dword[ebp-12]
.dc_b equ dword[ebp-16]
.cr equ dword[ebp-20]
.cg equ dword[ebp-24]
.cb equ dword[ebp-28]
mov ebp,esp
mov ax,.y
or ax,ax
jl .gl_quit
cmp ax,SIZE_Y
jge .gl_quit
mov eax,dword[.x1]
cmp ax,word[.x2]
je .gl_quit
jl @f
xchg eax,dword[.x2]
mov dword[.x1],eax
mov eax,dword[.c1g]
xchg eax,dword[.c2g]
mov dword[.c1g],eax
mov eax,.z1
xchg eax,.z2
mov .z1,eax
@@:
cmp word[.x1],SIZE_X
jge .gl_quit
cmp word[.x2],0
jle .gl_quit
mov eax,.z2
sub eax,.z1
cdq
mov bx,word[.x2] ; dz = z2-z1/x2-x1
sub bx,word[.x1]
movsx ebx,bx
idiv ebx
push eax
mov ax,word[.c2r]
sub ax,word[.c1r]
cwde
shl eax,ROUND ; dc_r = c2r-c1r/x2-x1
cdq
idiv ebx
push eax
mov ax,word[.c2g]
sub ax,word[.c1g]
cwde
shl eax,ROUND
cdq
idiv ebx
push eax
mov ax,word[.c2b]
sub ax,word[.c1b]
cwde
shl eax,ROUND
cdq
idiv ebx
push eax
cmp word[.x1],0 ; clipping on function
jg @f
mov eax,.dz
movsx ebx,word[.x1]
neg ebx
imul ebx
add .z1,eax
mov word[.x1],0
mov eax,.dc_r
imul ebx
sar eax,ROUND
add word[.c1r],ax
mov eax,.dc_g
imul ebx
sar eax,ROUND
add word[.c1g],ax
mov eax,.dc_b
imul ebx
sar eax,ROUND
add word[.c1b],ax
@@:
cmp word[.x2],SIZE_X
jl @f
mov word[.x2],SIZE_X
@@:
sub esp,12 ; calculate memory begin
mov edx,SIZE_X ; in buffers
movzx eax,.y
mul edx
movzx edx,word[.x1]
add eax,edx
push eax
lea eax,[eax*3]
add edi,eax
pop eax
shl eax,2
add esi,eax
mov cx,word[.x2]
sub cx,word[.x1]
movzx ecx,cx
mov ebx,.z1 ; ebx - currrent z shl CATMULL_SIFT
mov edx,.dz ; edx - delta z
movzx eax,word[.c1r]
shl eax,ROUND
mov .cr,eax
movzx eax,word[.c1g]
shl eax,ROUND
mov .cg,eax
movzx eax,word[.c1b]
shl eax,ROUND
mov .cb,eax
.ddraw:
cmp ebx,dword[esi] ; esi - z_buffer
jge .skip ; edi - Screen buffer
mov eax,.cr
sar eax,ROUND
stosb
mov eax,.cg
sar eax,ROUND
stosb
mov eax,.cb
sar eax,ROUND
stosb
mov dword[esi],ebx
jmp .no_skip
.skip:
add edi,3
.no_skip:
add esi,4
add ebx,edx
mov eax,.dc_r
add .cr,eax
mov eax,.dc_g
add .cg,eax
mov eax,.dc_b
add .cb,eax
loop .ddraw
.gl_quit:
mov esp,ebp
ret 26

Binary file not shown.

View File

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

View File

@ -0,0 +1,585 @@
;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]
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
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 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
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 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+16
.tex_x2 equ ebp+18
.tex_y2 equ ebp+20
.z2 equ dword [ebp+22] ;z1, z2 coords shifted shl CATMULL_SHIFT
.z1 equ dword [ebp+26]
.z_ptr equ dword [ebp+30]
.tex_dx equ dword [ebp-4]
.tex_dy equ dword [ebp-8]
.dz equ dword [ebp-12]
.cz equ dword [ebp-16]
.c_tex_x equ dword [ebp-20] ; current tex x
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
mov eax,dword[.tex_x1]
xchg eax,dword[.tex_x2]
mov dword[.tex_x1],eax
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 ax,word[.tex_x2] ; calc .dtx
sub ax,word[.tex_x1]
cwde
shl eax,ROUND
cdq
idiv ebx
push eax
mov ax,word[.tex_y2] ; calc .dty
sub ax,word[.tex_y1]
cwde
shl eax,ROUND
cdq
idiv ebx
push eax
mov eax,.z2 ; calc .dz
sub eax,.z1
cdq
idiv ebx
push eax
cmp .x1,0 ; clipping
jge @f
movsx ebx,.x1
neg ebx
imul ebx ; eax = .dz * abs(.x1)
add .z1,eax
mov .x1,0
mov eax,.tex_dy
sar eax,ROUND
imul ebx
add word[.tex_y1],ax
mov eax,.tex_dx
sar eax,ROUND
imul ebx
add word[.tex_x1],ax
@@:
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
movzx eax,word[.tex_x1]
shl eax,ROUND
movzx ebx,word[.tex_y1]
shl ebx,ROUND
push .z1 ; .cz
push eax ;.c_tex_x
.tl_loop:
mov edx,.z_ptr ; eax - temp
mov eax,.cz ; ebx - cur tex y shl ROUND
cmp eax,[edx] ; ecx - l.lenght
jge .skip ; 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
and esi,TEXTURE_SIZE
lea esi,[esi*3]
add esi,.tex_ptr
movsd
dec edi
mov eax,.cz
mov esi,.z_ptr
mov dword[esi],eax ; renew z buffer
jmp .no_skip
.skip:
add edi,3
.no_skip:
add .z_ptr,4
mov eax,.dz
add .cz,eax
mov eax,.tex_dx
add .c_tex_x,eax
add ebx,.tex_dy
loop .tl_loop
.tl_quit:
mov esp,ebp
ret 30

View File

@ -7,6 +7,9 @@
; ;
; ;
TIMEOUT EQU 2 TIMEOUT EQU 2
IMG_X equ 512
IMG_Y equ 384
use32 use32
org 0x0 org 0x0
@ -96,7 +99,7 @@ still:
mov eax,7 ;put image mov eax,7 ;put image
mov ebx,the_mem mov ebx,the_mem
mov ecx,512*65536+384 mov ecx,IMG_X*65536+IMG_Y
mov edx,0 mov edx,0
int 0x40 int 0x40
@ -204,14 +207,14 @@ draw_window:
mov ebx,1 ; 1, start of draw mov ebx,1 ; 1, start of draw
int 0x40 int 0x40
mov eax,48 mov eax,48 ;get skin width
mov ebx,4 mov ebx,4
int 0x40 int 0x40
mov esi, eax mov esi, eax
; DRAW WINDOW ; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+512+9 ; [x start] *65536 + [x size] mov ebx,100*65536+IMG_X+9 ; [x start] *65536 + [x size]
mov ecx,100*65536+384+4 ; [y start] *65536 + [y size] mov ecx,100*65536+IMG_Y+4 ; [y start] *65536 + [y size]
add ecx, esi add ecx, esi
mov edx,0x74000000 ; color of work area RRGGBB,8->color gl mov edx,0x74000000 ; color of work area RRGGBB,8->color gl
mov edi,labelt mov edi,labelt