some optimized variants from K0700

git-svn-id: svn://kolibrios.org@625 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2007-09-13 13:29:59 +00:00
parent 48a2a652db
commit b8fa8489d3
6 changed files with 248 additions and 333 deletions

View File

@ -25,12 +25,31 @@ SCREEN_Y equ 200
include 'lang.inc'
include '..\..\..\macros.inc'
;purge mov
include 'ascl.inc'
include 'ascgl.inc'
START:
init_sin_cos:
finit
fldz
xor edi,edi
mov ecx,512
isc_make:
fld st0
fsincos
fmul [fixed_point_const]
fistp word [cos_table+edi]
fmul [fixed_point_const]
fistp word [sin_table+edi]
fadd [inc_angle]
add edi,2
loop isc_make
fstp st0
red:
call draw_window
call init_sin_cos
still:
mov eax,11
@ -76,9 +95,6 @@ main_loop:
jmp still
red:
call draw_window
jmp still
key:
mov eax,2
mcall
@ -124,46 +140,37 @@ df_draw:
mov ecx,3
mov edi,@@tx1 ;bp
df_get_point:
xor bh,bh
mov bl,byte [esi]
shl bx,2
mov ax,word [object_translated+bx]
mov word [edi],ax
mov ax,word [object_translated+bx+2]
mov word [edi+2],ax
movzx ebx, byte [esi]
movzx eax, word [object_translated + ebx*4]
stosd
movzx eax, word [object_translated + ebx*4 + 2]
stosd
inc esi
add edi,4
dec ecx
jnz df_get_point
mov ax,[@@ty1]
sub ax,[@@ty3]
mov bx,[@@tx2]
sub bx,[@@tx1]
imul bx
shl edx,16
mov dx,ax
push edx
mov ax,[@@tx1]
sub ax,[@@tx3]
mov bx,[@@ty2]
sub bx,[@@ty1]
imul bx
shl edx,16
mov dx,ax
mov eax,[@@ty1]
sub eax,[@@ty3]
mov ebx,[@@tx2]
sub ebx,[@@tx1]
imul ebx
push eax
mov eax,[@@tx1]
sub eax,[@@tx3]
mov ebx,[@@ty2]
sub ebx,[@@ty1]
imul ebx
pop ebx
sub ebx,edx
or ebx,ebx
sub ebx,eax
jge df_next
xor ah,ah
mov al,byte [si]
movzx eax, byte [esi]
mov [@@xcol],ax
mov [@@xcol], eax
call filled_triangle
df_next:
inc si
inc esi
pop ecx
dec ecx
jnz df_draw
@ -178,7 +185,7 @@ clear_screen_buffer:
mov ebx,scrbuf
mov ecx,SCREEN_X*65536+SCREEN_Y
mov edx,5*65536+22
mov ax,7
mov eax,7
mcall
;White background
@ -196,21 +203,22 @@ clear_screen_buffer:
;filled trangle procedure
@@tx1 dw 0
@@ty1 dw 0
@@tx2 dw 0
@@ty2 dw 0
@@tx3 dw 0
@@ty3 dw 0
@@xcol dw 0
align 4
@@tx1 dd 0
@@ty1 dd 0
@@tx2 dd 0
@@ty2 dd 0
@@tx3 dd 0
@@ty3 dd 0
@@xcol dd 0
@@dx12 dw 0
@@dx13 dw 0
@@dx23 dw 0
@@dx12 dd 0
@@dx13 dd 0
@@dx23 dd 0
filled_triangle:
mov ax,[@@xcol] ;trnsforming color
mov eax,[@@xcol] ;trnsforming color
mov bl,al ;byte bbbggrrx
mov dl,al ;to 3 byte
mov dh,al ;bbbxxxxx ggxxxxxx rrxxxxxx
@ -234,185 +242,175 @@ no_bitup:
shl eax,8
mov al,dl
mov dword [@@rgb],eax
mov eax,0 ; for 16 bit instructions
mov ax,[@@ty1]
cmp ax,[@@ty3]
mov eax,[@@ty1]
cmp eax,[@@ty3]
jb ft_check1
xchg ax,[@@ty3]
mov [@@ty1],ax
xchg eax,[@@ty3]
mov [@@ty1],eax
mov ax,[@@tx1]
xchg ax,[@@tx3]
mov [@@tx1],ax
mov eax,[@@tx1]
xchg eax,[@@tx3]
mov [@@tx1],eax
ft_check1:
mov ax,[@@ty2]
cmp ax,[@@ty3]
mov eax,[@@ty2]
cmp eax,[@@ty3]
jb ft_check2
xchg ax,[@@ty3]
mov [@@ty2],ax
xchg eax,[@@ty3]
mov [@@ty2],eax
mov ax,[@@tx2]
xchg ax,[@@tx3]
mov [@@tx2],ax
mov eax,[@@tx2]
xchg eax,[@@tx3]
mov [@@tx2],eax
ft_check2:
mov ax,[@@ty1]
cmp ax,[@@ty2]
mov eax,[@@ty1]
cmp eax,[@@ty2]
jb ft_check3
xchg ax,[@@ty2]
mov [@@ty1],ax
xchg eax,[@@ty2]
mov [@@ty1],eax
mov ax,[@@tx1]
xchg ax,[@@tx2]
mov [@@tx1],ax
mov eax,[@@tx1]
xchg eax,[@@tx2]
mov [@@tx1],eax
ft_check3:
mov bx,[@@ty2]
sub bx,[@@ty1]
mov ebx,[@@ty2]
sub ebx,[@@ty1]
jnz ft_dx12_make
mov [@@dx12],word 0
mov [@@dx12],dword 0
jmp ft_dx12_done
ft_dx12_make:
mov ax,[@@tx2]
sub ax,[@@tx1]
shl ax,7
cwd
idiv bx
mov [@@dx12],ax ; dx12 = (x2-x1)/(y2-y1)
mov eax,[@@tx2]
sub eax,[@@tx1]
shl eax,7
cdq
idiv ebx
mov [@@dx12],eax ; dx12 = (x2-x1)/(y2-y1)
ft_dx12_done:
mov bx,[@@ty3]
sub bx,[@@ty1]
mov ebx,[@@ty3]
sub ebx,[@@ty1]
jnz ft_dx13_make
mov [@@dx13],word 0
mov [@@dx13],dword 0
jmp ft_dx13_done
ft_dx13_make:
mov ax,[@@tx3]
sub ax,[@@tx1]
shl ax,7
cwd
idiv bx
mov [@@dx13],ax ; dx13 = (x3-x1)/(y3-y1)
mov eax,[@@tx3]
sub eax,[@@tx1]
shl eax,7
cdq
idiv ebx
mov [@@dx13],eax ; dx13 = (x3-x1)/(y3-y1)
ft_dx13_done:
mov bx,[@@ty3]
sub bx,[@@ty2]
mov ebx,[@@ty3]
sub ebx,[@@ty2]
jnz ft_dx23_make
mov [@@dx23],word 0
mov [@@dx23],dword 0
jmp ft_dx23_done
ft_dx23_make:
mov ax,[@@tx3]
sub ax,[@@tx2]
shl ax,7
cwd
idiv bx
mov [@@dx23],ax ; dx23 = (x3-x2)/(y3-y2)
mov eax,[@@tx3]
sub eax,[@@tx2]
shl eax,7
cdq
idiv ebx
mov [@@dx23],eax ; dx23 = (x3-x2)/(y3-y2)
ft_dx23_done:
mov ax,[@@tx1]
shl ax,7
mov bx,ax
mov eax,[@@tx1]
shl eax,7
mov ebx,eax
mov cx,[@@ty1]
mov ecx,[@@ty1]
ft_loop1:
pushad
mov [@@ly],cx
mov dx,bx
shr dx,7
mov [@@lx2],dx
mov dx,ax
shr dx,7
mov [@@lx1],dx
mov ax,[@@xcol]
mov [@@lcol],ax
mov [@@ly],ecx
mov edx,ebx
shr edx,7
mov [@@lx2],edx
mov edx,eax
shr edx,7
mov [@@lx1],edx
mov eax,[@@xcol]
mov [@@lcol],eax
call horizontal_line
popad
add ax,[@@dx13]
add bx,[@@dx12]
inc cx
cmp cx,[@@ty2]
add eax,[@@dx13]
add ebx,[@@dx12]
inc ecx
cmp ecx,[@@ty2]
jb ft_loop1
mov bx,[@@tx2]
shl bx,7
mov cx,[@@ty2]
mov ebx,[@@tx2]
shl ebx,7
mov ecx,[@@ty2]
ft_loop2:
pushad
mov [@@ly],cx
mov dx,bx
shr dx,7
mov [@@lx2],dx
mov dx,ax
shr dx,7
mov [@@lx1],dx
mov ax,[@@xcol]
mov [@@lcol],ax
mov [@@ly],ecx
mov edx,ebx
shr edx,7
mov [@@lx2],edx
mov edx,eax
shr edx,7
mov [@@lx1],edx
mov eax,[@@xcol]
mov [@@lcol],eax
call horizontal_line
popad
add ax,[@@dx13]
add bx,[@@dx23]
add eax,[@@dx13]
add ebx,[@@dx23]
inc ecx
cmp cx,[@@ty3]
cmp ecx,[@@ty3]
jb ft_loop2
ret
;horizontal line subproc
@@lx1 dw 0
@@lx2 dw 0
@@ly dw 0
@@lcol dw 0
align 4
@@lx1 dd 0
@@lx2 dd 0
@@ly dd 0
@@lcol dd 0
@@rgb dd 0
horizontal_line:
mov ecx,0
mov cx,[@@lx1]
cmp cx,[@@lx2]
mov ecx,[@@lx1]
sub ecx,[@@lx2]
ja x12
je ext
; ret
mov cx,[@@lx2]
sub cx,[@@lx1]
neg ecx
mov edi,3
jmp xx
x12:
mov cx,[@@lx1]
sub cx,[@@lx2]
mov edi,-3
jmp xx
ext:
mov ecx,-1 ;1
; sub ebp,3
xx:
mov eax,0
mov ax,[@@ly]
mov eax,[@@ly]
mov ebx,SCREEN_X ;320
mul ebx
mov ebp,0
mov bp,[@@lx1] ;for correct 16 bit size
add eax,ebp
mov ebx,3
mul ebx
mov ebp,eax
sub ebp,3 ;for delete white dots
add eax,[@@lx1]
lea ebp,[eax*3-3] ; for delete white dots
add ecx,2
loo:
@ -456,12 +454,11 @@ rotate_points:
mov edi,@@sin_x
mov edx,3
rp_sin_cos:
mov bx,word [esi]
and bx,511
shl bx,1
mov ax,word [sin_table+bx]
mov ebx, [esi]
and ebx,511
mov ax,word [sin_table+ebx*2]
mov word [edi],ax
mov ax,word [cos_table+bx]
mov ax,word [cos_table+ebx*2]
mov word [edi+2],ax
add esi,2
@ -591,8 +588,7 @@ y_n:
mov [my],bx
popad
mov ebx,0 ;?
mov bx,word [esi+4]
movzx ebx,word [esi+4]
mov ax,[my]
cmp ax,0
jng no_m
@ -601,20 +597,18 @@ y_n:
no_m:
add bx,256 ; Z factor (zoom)
mov eax,0 ;?
mov ax,word [esi]
shl ax,8
cwd
idiv bx; bx
add ax,(SCREEN_X/2) ;160 ;X factor (center X)
movsx eax,word [esi]
shl eax,8
cdq
idiv ebx
add eax,(SCREEN_X/2) ;160 ;X factor (center X)
stosw
mov eax,0 ;?
mov ax,word [esi+2]
shl ax,8
cwd
idiv bx
add ax,(SCREEN_Y/2) ;100 ;Y factor (center Y)
movsx eax,word [esi+2]
shl eax,8
cdq
idiv ebx
add eax,(SCREEN_Y/2) ;100 ;Y factor (center Y)
stosw
add esi,6
@ -622,32 +616,6 @@ no_m:
jnz translate_points
ret
init_sin_cos:
finit
fldz
fstp [temp]
xor edi,edi
mov ecx,512
isc_make:
fld [temp]
fld st0
fld st0
fsin
fmul [fixed_point_const]
fistp word [sin_table+edi]
fcos
fmul [fixed_point_const]
fistp word [cos_table+edi]
fadd [inc_angle]
fstp [temp]
add edi,2
loop isc_make
ret
temp dd 0
fixed_point_const dd 16384.0
inc_angle dd 0.01227184630309 ; pi/256

View File

@ -1,4 +1,4 @@
@echo lang fix en >lang.inc
@fasm 3dcube2.asm 3dcube2
@fasm rsquare.asm rsquare
@erase lang.inc
@pause

View File

@ -1,4 +1,4 @@
@echo lang fix ru >lang.inc
@fasm 3dcube2.asm 3dcube2
@fasm rsquare.asm rsquare
@erase lang.inc
@pause

View File

@ -17,6 +17,7 @@ use32
dd 0x00000000 ; reserved=no extended header
include 'lang.inc'
include '..\..\..\macros.inc'
purge mov ; decrease kpack'ed size
START: ; start of execution
call draw_window ; at first, draw the window
@ -54,15 +55,13 @@ still:
; Fill the table with blanks
mov edx, text + 160
mov edi, text + 160
doBlank:
mov esi, blank
mov edi, edx
mov ecx, 40
rep movsb
add edx, 40
cmp edx, text + 560
cmp edi, text + 560
jne doBlank
pop ecx ; The number of entries
@ -302,30 +301,21 @@ button: ; button
mov eax,0xffffffff ; close this program
mcall
jmp still
writeDecimal:
pusha
and eax, 0xff
mov ecx, eax
mov dl, 100
div dl
mov cl, ah
movzx ecx, ah
add al, '0'
mov [ebx], al
inc ebx
mov eax, ecx
mov dl, 10
div dl
mov cl, ah
add al, '0'
mov [ebx], al
inc ebx
mov al, ah
add al, '0'
mov [ebx], al
add ax, '00'
mov [ebx], ax
popa
ret
@ -360,7 +350,7 @@ draw_window:
newline:
mcall
add ebx,16
add edx,40
add edx,esi
cmp [edx],byte 'x'
jnz newline
@ -411,7 +401,7 @@ text:
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db 'x <- END MARKER, DONT DELETE '
db 'x' ; <- END MARKER, DONT DELETE
blank:
@ -424,9 +414,3 @@ hextable db '0123456789ABCDEF'
I_END:

View File

@ -26,8 +26,8 @@ include '..\..\..\macros.inc'
START: ; start of execution
cmp [PARAMS], byte 0
jne check_parameters
cmp [PARAMS], dword 'BOOT'
jz boot_set_settings
no_params:
@ -45,7 +45,7 @@ still:
jnz button
key: ; key
mov al,2 ; just read it and ignore
; mov al,2 ; just read it and ignore
mcall
jmp still
@ -55,74 +55,23 @@ still:
shr eax,8
cmp eax,1 ; button id=1 ?
dec eax ; button id=1 ?
jne noclose
or eax,-1 ; close this program
mcall
noclose:
cmp eax,2
dec eax
je read_stack_setup
cmp eax,3
dec eax
jne no_apply_stack_setup
call apply_stack_setup
jmp still
no_apply_stack_setup:
cmp eax,11
jb no_set_interface
cmp eax,14
jg no_set_interface
sub eax,11
mov [interface],eax
call draw_window
jmp still
no_set_interface:
cmp eax,21
jb no_ip_sf
cmp eax,22
jg no_ip_sf
sub eax,21
not eax
and eax,1
mov [assigned],eax
call draw_window
jmp still
no_ip_sf:
cmp eax,7 ; GET IP
jne no_read_ip
mov [string_x],205
mov [string_y],80
mov [string_length],15
call read_string
mov esi,string-1
mov edi,ip_address
xor eax,eax
ip1:
inc esi
cmp [esi],byte '0'
jb ip2
cmp [esi],byte '9'
jg ip2
imul eax,10
movzx ebx,byte [esi]
sub ebx,48
add eax,ebx
jmp ip1
ip2:
mov [edi],al
xor eax,eax
inc edi
cmp edi,ip_address+3
jbe ip1
call draw_window
jmp still
no_read_ip:
cmp eax,5 ; GET COM PORT
dec eax ; GET COM PORT
dec eax
jne no_read_comport
mov [string_x],272
mov [string_y],40
@ -152,11 +101,10 @@ no_apply_stack_setup:
sub eax,48
add ebx,eax
mov [com_add],ebx
call draw_window
jmp still
jmp red
no_read_comport:
cmp eax,6 ; GET COM IRQ
dec eax ; GET COM IRQ
jne no_read_comirq
mov [string_x],284
mov [string_y],50
@ -169,11 +117,38 @@ no_apply_stack_setup:
gci1:
sub eax,48
mov [com_irq],eax
call draw_window
jmp still
jmp red
no_read_comirq:
cmp eax, 8 ; set gateway ip
dec eax ; GET IP
jne no_read_ip
mov [string_x],205
mov [string_y],80
mov [string_length],15
call read_string
mov esi,string-1
mov edi,ip_address
ip0:
xor eax,eax
ip1:
inc esi
cmp [esi],byte '0'
jb ip2
cmp [esi],byte '9'
jg ip2
imul eax,10
movzx ebx,byte [esi]
sub ebx,48
add eax,ebx
jmp ip1
ip2:
stosb
cmp edi,ip_address+3
jbe ip0
jmp red
no_read_ip:
dec eax ; set gateway ip
jne no_set_gateway
mov [string_x],205
@ -182,6 +157,7 @@ no_apply_stack_setup:
call read_string
mov esi,string-1
mov edi,gateway_ip
gip0:
xor eax,eax
gip1:
inc esi
@ -195,17 +171,14 @@ no_apply_stack_setup:
add eax,ebx
jmp gip1
gip2:
mov [edi],al
xor eax,eax
inc edi
stosb
cmp edi,gateway_ip+3
jbe gip1
call draw_window
jmp still
jbe gip0
jmp red
no_set_gateway:
cmp eax, 9
dec eax
jne no_set_subnet
mov [string_x],205
@ -214,6 +187,7 @@ no_apply_stack_setup:
call read_string
mov esi,string-1
mov edi,subnet_mask
sip0:
xor eax,eax
sip1:
inc esi
@ -227,17 +201,13 @@ no_apply_stack_setup:
add eax,ebx
jmp sip1
sip2:
mov [edi],al
xor eax,eax
inc edi
stosb
cmp edi,subnet_mask+3
jbe sip1
call draw_window
jmp still
jbe sip0
jmp red
no_set_subnet:
cmp eax, 10
dec eax
jne no_set_dns
mov [string_x],205
@ -246,6 +216,7 @@ no_apply_stack_setup:
call read_string
mov esi,string-1
mov edi,dns_ip
dip0:
xor eax,eax
dip1:
inc esi
@ -259,20 +230,31 @@ no_apply_stack_setup:
add eax,ebx
jmp dip1
dip2:
mov [edi],al
xor eax,eax
inc edi
stosb
cmp edi,dns_ip+3
jbe dip1
call draw_window
jmp still
jbe dip0
jmp red
no_set_dns:
dec eax
jb no_set_interface
cmp eax,14-11
ja no_set_interface
mov [interface],eax
jmp red
no_set_interface:
sub eax,21-11
jb no_ip_sf
cmp eax,22-21
ja no_ip_sf
xor eax,1
mov [assigned],eax
jmp red
no_ip_sf:
jmp still
read_stack_setup:
mov eax,52
@ -318,11 +300,7 @@ read_stack_setup:
shr eax,7
and eax,1
mov [assigned],eax
call draw_window
jmp still
jmp red
apply_stack_setup:
@ -363,7 +341,6 @@ apply_stack_setup:
mcall
ret
jmp still
string_length dd 16
@ -388,7 +365,7 @@ read_string:
mcall
cmp eax,2
jne read_done
mov eax,2
; mov eax,2
mcall
shr eax,8
cmp eax,13
@ -419,11 +396,6 @@ read_string:
read_done:
call print_text
ret
print_text:
pusha
@ -607,27 +579,27 @@ draw_window:
mcall
;mov eax,8 ; BUTTON 6 : SET IRQ
mov ecx,49*65536+8
mov edx,6
inc edx
mcall
;mov eax,8 ; BUTTON 7 : SET IP
mov ecx,79*65536+8
mov edx,7
inc edx
mcall
;mov eax,8 ; BUTTON 8 : SET gateway IP
mov ebx,299*65536+8
mov ecx,89*65536+8
mov edx,8
inc edx
mcall
;mov eax,8 ; BUTTON 9 : SET subnet
mov ecx,99*65536+8
mov edx,9
inc edx
mcall
;mov eax,8 ; BUTTON 10 : SET dns ip
mov ecx,109*65536+8
mov edx,10
inc edx
mcall
mov ebx,31*65536+40 ; draw info text with function 4
@ -655,13 +627,6 @@ draw_window:
;******************************************************************************
check_parameters:
cmp [PARAMS], dword "BOOT" ; received BOOT parameter -> goto handler
je boot_set_settings
jmp no_params
;******************************************************************************
boot_set_settings:
mov eax,52
@ -723,5 +688,3 @@ assigned dd 0 ; get ip from server
config dd 0
I_END: