@SS - screensaver. Some optimisations and code refactoring.

git-svn-id: svn://kolibrios.org@2529 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov (Mario79) 2012-03-30 16:11:37 +00:00
parent 59bbcee373
commit 19ee52261b
3 changed files with 548 additions and 433 deletions

View File

@ -1,90 +1,119 @@
;------------------------------------------------------------------------------
; @SS - screensaver
;------------------------------------------------------------------------------
; last update: 30/03/2012
; changed by: Marat Zakiyanov aka Mario79, aka Mario
; changes: The program uses only 4 Kb memory is now.
; Code refactoring. Using transparent cursor.
; Fix bug - using lots of buttons from f.8.
;---------------------------------------------------------------------
; SCREENSAVER APPLICATION by lisovin@26.ru ; SCREENSAVER APPLICATION by lisovin@26.ru
; ;
; Compile with FASM for Menuet ; Compile with FASM for Menuet
; ;
;------------------------------------------------------------------------------
use32 use32
org 0x0 org 0x0
used_memory = 0x10000
db 'MENUET01' ; 8 byte id db 'MENUET01' ; 8 byte id
dd 0x01 ; header version dd 0x01 ; header version
dd START ; start of code dd START ; start of code
dd I_END ; size of image dd IM_END ; size of image
dd used_memory ; memory for app dd I_END ; memory for app
dd used_memory ; esp dd stack_top ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon dd 0x0 ; I_Param
dd 0x0 ; path
;------------------------------------------------------------------------------
include 'lang.inc' include 'lang.inc'
include '..\..\..\macros.inc' include '..\..\..\macros.inc'
purge mov ; decrease kpack'ed size
;include 'debug.inc' ;include 'debug.inc'
;------------------------------------------------------------------------------
align 4
START: START:
mov eax,40 ; ãáâ ­®¢¨âì ¬ áªã ᮡë⨩ mcall 68,11
mov ebx,110010b ; ॠ£¨à㥬 ­  ª« ¢¨ âãàã, ¬ëèì, ®âà¨á®¢ªã ä®­  mcall 40,110010b
mcall ;------------------------------------------------------------------------------
align 4
bgr_changed: bgr_changed:
mov eax,14 mcall 14
mcall mov [y_max],ax
mov [y_max], ax shr eax,16
shr eax, 16 mov [x_max],ax
mov [x_max], ax shl eax,16
shl eax, 16 mov [top_right_corner],eax
mov [top_right_corner], eax ;------------------------------------------------------------------------------
align 4
still: still:
movzx ebx, [time] movzx ebx,[time]
imul ebx, 60*100 imul ebx,60*100
mcall 23 ; ¦¤ñ¬ ᮡëâ¨ï ¢ â¥ç¥­¨¥ [time] ¬¨­ãâ mcall 23 ; ¦¤ñ¬ ᮡëâ¨ï ¢ â¥ç¥­¨¥ [time] ¬¨­ãâ
test eax, eax test eax,eax
jz create_ss_thread jz create_ss_thread
cmp al, 2 ; key in buffer?
cmp al,2 ; key in buffer?
jz key jz key
cmp al, 5 ; background redraw?
cmp al,5 ; background redraw?
jz bgr_changed jz bgr_changed
; mouse event ; mouse event
mcall 37,2 ; ¯à®¢¥à¨¬ ª­®¯ª¨ mcall 37,2 ; ¯à®¢¥à¨¬ ª­®¯ª¨
and al, 3 and al,3
cmp al, 3 ; ­ ¦ âë ®¡¥ ª­®¯ª¨ ¬ëè¨? cmp al,3 ; ­ ¦ âë ®¡¥ ª­®¯ª¨ ¬ëè¨?
jnz still jnz still
mcall 37,0 ; ¯à®¢¥à¨¬ ª®®à¤¨­ âë mcall 37,0 ; ¯à®¢¥à¨¬ ª®®à¤¨­ âë
cmp [top_right_corner], eax cmp [top_right_corner],eax
jnz still jnz still
;------------------------------------------------------------------------------
align 4
create_setup: create_setup:
test [params], 2 test [params],2
jnz still ; ®ª­® ­ áâ஥ª 㦥 ᮧ¤ ­® jnz still ; ®ª­® ­ áâ஥ª 㦥 ᮧ¤ ­®
mcall 51,1,sthread,used_memory-0x1000 mcall 51,1,sthread,sthread_stack_top
or [params], 2 or [params],2
jmp still jmp still
;------------------------------------------------------------------------------
align 4
key: key:
mcall ; eax = 2 mcall ; eax = 2
jmp still jmp still
;------------------------------------------------------------------------------
align 4
create_ss_thread: create_ss_thread:
test [params], 3 test [params],3
jnz still jnz still
call create_ss call create_ss
jmp still jmp still
;------------------------------------------------------------------------------
align 4
create_ss: create_ss:
mcall 51,1,thread,used_memory-0x2000 mcall 51,1,thread,thread_stack_top
or [params], 1 or [params],1
ret ret
;------------------------------------------------------------------------------
align 4
thread:
mcall 40,100010b
;set_new_cursor_skin - transparent cursor
mcall 68,12,32*32*4 ; get memory for own cursor area
thread: push eax
; mov eax,5 mov ecx,eax
; mov ebx,eax mcall 37,4,,2 ; load own cursor
; mcall
mov eax,40 mov ecx,eax
mov ebx,100010b mcall 37,5 ; set own cursor
mcall
cmp dword [type],0 pop ecx
mcall 68,13 ; free own cursor area
cmp [type],dword 0
je drawsswin je drawsswin
cmp dword [type],24
cmp [type],dword 24
je asminit je asminit
mov dword [delay],1 mov dword [delay],1
mov [lx1],10 ; for "draw line" mov [lx1],10 ; for "draw line"
mov [lx2],40 mov [lx2],40
@ -95,58 +124,106 @@ create_ss:
mov [addy1],1 mov [addy1],1
mov [addy2],1 mov [addy2],1
jmp drawsswin jmp drawsswin
asminit: ; for "assembler" ;--------------------------------------
mov dword [delay],25 align 4
mov eax,70 asminit: ; for "assembler" - assembler sources demo
mov ebx,fileinfo ; get size of file
mcall mov [fileinfo],dword 5
mov [filesize], ebx mov [fileinfo.point],dword fileinfo_buffer
asminit1: mcall 70,fileinfo
mov [stringstart],data_from_file test eax,eax
jnz .no_file
; get memory for file
mov ecx,[fileinfo_buffer+32]
mov [fileinfo.size],ecx
mcall 68,12
mov [fileinfo.point],eax
; load file
mov [fileinfo],dword 0
mcall 70,fileinfo
test eax,eax
jz @f
mcall 68,13,[fileinfo.point]
;--------------------------------------
align 4
.no_file:
mov [type],dword 0
jmp drawsswin
;--------------------------------------
align 4
@@:
mov dword [delay],1 ;25 - old value
;--------------------------------------
align 4
asminit1:
mov eax,[fileinfo.point]
mov [stringstart],eax
mov dword [stringlen],1 mov dword [stringlen],1
newpage: ;--------------------------------------
align 4
newpage:
mov word [stringpos],10 mov word [stringpos],10
;--------------------------------------
drawsswin: align 4
drawsswin:
xor eax,eax xor eax,eax
movzx ebx,[x_max] movzx ebx,[x_max]
movzx ecx,[y_max] movzx ecx,[y_max]
inc ebx inc ebx
inc ecx inc ecx
mov edx,0x01000000 mcall ,,,0x01000000
mcall
mov eax,13
xor edx,edx xor edx,edx
mcall mcall 13
tstill: ;--------------------------------------
mov eax,23 align 4
mov ebx,[delay] tstill:
mcall mcall 23,[delay]
test eax,eax test eax,eax
jnz thr_end jnz thr_end
cmp dword [type],0
cmp [type],dword 0
je tstill je tstill
cmp dword [type],24
cmp [type],dword 24
je drawssasm je drawssasm
call draw_line call draw_line
jmp tstill jmp tstill
thr_end: ;--------------------------------------
align 4
thr_end:
cmp [type],dword 24
jne @f
mcall 68,13,[fileinfo.point]
;--------------------------------------
align 4
@@:
and [params], not 1 and [params], not 1
or eax,-1 or eax,-1
mcall mcall
;------------------------------------------------------------------------------
drawssasm: align 4
drawssasm:
mov edi,[stringstart] mov edi,[stringstart]
add edi,[stringlen] add edi,[stringlen]
dec edi dec edi
lea eax,[edi-data_from_file]
cmp eax,[filesize] mov eax,edi
sub eax,[fileinfo.point]
cmp eax,[fileinfo.size]
ja asminit1 ja asminit1
cmp word [edi],0x0a0d cmp word [edi],0x0a0d
je addstring je addstring
cmp byte [edi],0x0a cmp byte [edi],0x0a
jne noaddstring jne noaddstring
dec edi dec edi
;--------------------------------------
align 4
addstring: addstring:
add word [stringpos],10 add word [stringpos],10
add edi,2 add edi,2
@ -156,19 +233,18 @@ addstring:
cmp ax,[y_max] cmp ax,[y_max]
jb tstill jb tstill
jmp newpage jmp newpage
noaddstring: ;--------------------------------------
mov eax,4 align 4
noaddstring:
mov ebx,10*65536 mov ebx,10*65536
mov bx,[stringpos] mov bx,[stringpos]
mov ecx,0x104ba010 mcall 4,,0x104ba010,[stringstart],[stringlen]
mov edx,[stringstart]
mov esi,[stringlen]
mcall
inc dword [stringlen] inc dword [stringlen]
cmp byte [edi],byte ' ' cmp [edi],byte ' '
je drawssasm je drawssasm
jmp tstill jmp tstill
;------------------------------------------------------------------------------
align 4
draw_line: draw_line:
movzx esi,[x_max] movzx esi,[x_max]
movzx edi,[y_max] movzx edi,[y_max]
@ -186,37 +262,57 @@ draw_line:
cmp [lx1],1 cmp [lx1],1
jge dl1 jge dl1
mov [addx1],1 mov [addx1],1
dl1: ;--------------------------------------
align 4
dl1:
cmp [lx2],1 cmp [lx2],1
jge dl2 jge dl2
mov [addx2],1 mov [addx2],1
dl2: ;--------------------------------------
align 4
dl2:
cmp [lx1],esi cmp [lx1],esi
jbe dl3 jbe dl3
mov [addx1],0xffffffff mov [addx1],0xffffffff
dl3: ;--------------------------------------
align 4
dl3:
cmp [lx2],esi cmp [lx2],esi
jbe dl4 jbe dl4
mov [addx2],0xffffffff
dl4:
mov [addx2],0xffffffff
;--------------------------------------
align 4
dl4:
cmp [ly1],1 cmp [ly1],1
jge dl5 jge dl5
mov [addy1],1 mov [addy1],1
dl5: ;--------------------------------------
align 4
dl5:
cmp [ly2],2 cmp [ly2],2
jge dl6 jge dl6
mov [addy2],1 mov [addy2],1
dl6: ;--------------------------------------
align 4
dl6:
cmp [ly1],edi cmp [ly1],edi
jbe dl7 jbe dl7
mov [addy1],-1 mov [addy1],-1
dl7: ;--------------------------------------
align 4
dl7:
cmp [ly2],edi cmp [ly2],edi
jbe dl8 jbe dl8
mov [addy2],-1
dl8:
mov [addy2],-1
;--------------------------------------
align 4
dl8:
mov eax,[lx2] mov eax,[lx2]
cmp [lx1],eax cmp [lx1],eax
jz dnol jz dnol
@ -229,229 +325,228 @@ draw_line:
shl ecx,16 shl ecx,16
mov cx,word [ly2] mov cx,word [ly2]
mov eax,38
mov edx,[lcolor] mov edx,[lcolor]
and edx,0xffffff and edx,0xffffff
mcall mcall 38
;--------------------------------------
dnol: align 4
dnol:
add [lcolor],0x010201 add [lcolor],0x010201
ret ret
;------------------------------------------------------------------------------
align 4
sthread: ; start of execution sthread: ; start of execution
call sdraw_window call sdraw_window
;--------------------------------------
align 4
sstill: sstill:
mcall 10 ; wait here for event
mov eax,10 ; wait here for event
mcall
dec eax ; redraw request ? dec eax ; redraw request ?
je sthread je sthread
dec eax ; key in buffer ? dec eax ; key in buffer ?
jne sbutton jne sbutton
mov al,2
mcall
jmp snoclose ;sstill
sbutton: ; button mcall 2
mov eax,17 ; get id jmp snoclose ;sstill
mcall ;------------------------------------------------------------------------------
align 4
sbutton: ; button
mcall 17 ; get id
cmp ah,1 ; button id=1 ? cmp ah,1 ; button id=1 ?
jne snoclose jne snoclose
and [params], not 2 and [params],not 2
mov eax,-1 ; close this program mov eax,-1 ; close this program
mcall mcall
snoclose: ;--------------------------------------
align 4
snoclose:
cmp ah,7 cmp ah,7
jne nosetfl jne nosetfl
xor [params], 1
xor [params],1
call drawflag call drawflag
call drawtype call drawtype
call drawtime call drawtime
jmp sstill jmp sstill
nosetfl: ;--------------------------------------
test [params], 1 align 4
nosetfl:
test [params],1
jnz sstill jnz sstill
cmp ah,2 cmp ah,2
jne notypedown jne notypedown
mov eax,[type] mov eax,[type]
test eax,eax test eax,eax
je sstill je sstill
sub eax,12 sub eax,12
jmp typeupdn jmp typeupdn
notypedown: ;--------------------------------------
align 4
notypedown:
cmp ah,3 cmp ah,3
jne notypeup jne notypeup
mov eax,[type] mov eax,[type]
cmp eax,24 cmp eax,24
jae sstill jae sstill
add eax,12 add eax,12
jmp typeupdn jmp typeupdn
notypeup: ;--------------------------------------
align 4
notypeup:
cmp ah,4 cmp ah,4
jne notimedown jne notimedown
mov al,[time] mov al,[time]
cmp al,1 cmp al,1
jbe sstill jbe sstill
dec eax dec eax
; das ; das
jmp timeupdn jmp timeupdn
notimedown: ;--------------------------------------
align 4
notimedown:
cmp ah,5 cmp ah,5
jne notimeup jne notimeup
mov al,[time] mov al,[time]
cmp al,59 ; 0x59 cmp al,59 ; 0x59
jae sstill jae sstill
inc eax inc eax
; daa ; daa
jmp timeupdn jmp timeupdn
notimeup: ;--------------------------------------
align 4
notimeup:
cmp ah,6 cmp ah,6
jne noshow jne noshow
mov eax,5
mov ebx,10;150
mcall
call create_ss
noshow:
jmp sstill
timeupdn: mcall 5,10
call create_ss
;--------------------------------------
align 4
noshow:
jmp sstill
;--------------------------------------
align 4
timeupdn:
mov [time],al mov [time],al
call drawtime call drawtime
jmp sstill jmp sstill
typeupdn: ;--------------------------------------
align 4
typeupdn:
mov [type],eax mov [type],eax
call drawtype call drawtype
jmp sstill jmp sstill
;------------------------------------------------------------------------------
; ********************************************* ; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ******** ; ******* WINDOW DEFINITIONS AND DRAW ********
; ********************************************* ; *********************************************
align 4
sdraw_window: sdraw_window:
mcall 12,1
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
mcall
; DRAW WINDOW
xor eax,eax ; function 0 : define and draw window xor eax,eax ; function 0 : define and draw window
mov ebx,100*65536+215 ; [x start] *65536 + [x size] xor esi,esi
mov ecx,100*65536+70 ; [y start] *65536 + [y size] mcall ,<100,215>,<100,70>,0x13400088,,title
mov edx,0x13400088 ; color of work area RRGGBB,8->color gl
mov edi,title mcall 8,<47,10>,<31,10>,2,0x702050
mcall
mov al,8
mov ebx,47*65536+10
mov ecx,31*65536+10
mov edx,2
mov esi,0x702050
mcall
push ebx push ebx
add ebx,13*65536 add ebx,13*65536
mov edi,ebx mov edi,ebx
inc edx inc edx
mcall mcall
pop ebx pop ebx
add ecx,15*65536 add ecx,15*65536
inc edx inc edx
mcall mcall
mov ebx,edi mov ebx,edi
inc edx inc edx
mcall mcall
mov ebx,160*65536+40
mov ecx,28*65536+14
inc edx
mcall
mov al,4 ; function 4 : write text to window inc edx
mov ebx,15*65536+33 ; [x start] *65536 + [y start] mcall ,<160,40>,<28,14>
mov ecx,0x80ffffff
mov edx,setuptext mcall 4,<15,33>,0x80ffffff,setuptext ; write text to window
mcall
add ebx,15 add ebx,15
add edx,10 add edx,10
mcall mcall
mov ebx,169*65536+32
mov edx,buttext mcall ,<169,32>,,buttext
mcall
call drawtype call drawtype
call drawtime call drawtime
call drawflag call drawflag
mov eax,12 ; function 12:tell os about windowdraw mcall 12,2
mov ebx,2 ; 2, end of draw
mcall
ret ret
;------------------------------------------------------------------------------
align 4
drawtype: drawtype:
mov eax,13
mov ebx,80*65536+75
mov ecx,30*65536+12
mov edx,0xffffff mov edx,0xffffff
test [params], 1 test [params], 1
jz noblue jz noblue
mov edx,0x4e00e7 mov edx,0x4e00e7
noblue: ;--------------------------------------
mcall align 4
mov al,4 noblue:
mov ebx,82*65536+32 mcall 13,<80,75>,<30,12>
xor ecx,ecx xor ecx,ecx
mov edx,typetext mov edx,typetext
add edx,[type] add edx,[type]
mov esi,12 mcall 4,<82,32>,,,12
mcall
ret ret
;------------------------------------------------------------------------------
align 4
drawtime: drawtime:
mov eax,13
mov ebx,80*65536+15
mov ecx,45*65536+12
mov edx,0xffffff mov edx,0xffffff
test [params], 1 test [params], 1
jz noblue1 jz noblue1
mov edx,0x4e00e7 mov edx,0x4e00e7
noblue1: ;--------------------------------------
mcall align 4
mov al,47 noblue1:
mov edx,82*65536+47 mcall 13,<80,15>,<45,12>
xor esi,esi xor esi,esi
movzx ecx,byte [time] movzx ecx,byte [time]
mov ebx,0x00020000 mcall 47,0x00020000,,<82,47>
mcall
ret ret
;------------------------------------------------------------------------------
align 4
drawflag: drawflag:
mov eax,8 mcall 8,,,0x80000007 ; before we need delete button
mov ebx,150*65536+10 ; otherwise, a few hours later the application will spend all buttons of system
mov ecx,45*65536+10 mcall ,<150,10>,<45,10>,7,0xe0e0e0 ; then create button
mov edx,7
mov esi,0xe0e0e0
mcall
mov al,4
mov ebx,153*65536+47
xor ecx,ecx
mov esi,1
mov edx,flag mov edx,flag
bt dword [params],0 bt dword [params],0
jc setf jc setf
inc edx
setf:
mcall
ret
inc edx
;--------------------------------------
align 4
setf:
xor ecx,ecx
mcall 4,<153,47>,,,1
ret
;------------------------------------------------------------------------------
align 4
; DATA AREA ; DATA AREA
buttext db 'SHOW',0 buttext db 'SHOW',0
flag db 'V ' flag db 'V '
@ -482,19 +577,37 @@ stringpos dw 10
params db 0 ;if bit 0 set-ssaver works if bit 1 set-setup works params db 0 ;if bit 0 set-ssaver works if bit 1 set-setup works
fileinfo: fileinfo:
; used_memory-0x3000-data_from_file = ~50 Kb with current settings dd 0
dd 0,0,0,used_memory-0x3000-data_from_file,data_from_file dd 0
db '/sys/NETWORK/PPP.ASM',0 dd 0
.size: dd 0
I_END: .point: dd 0
db '/sys/macros.inc',0
;------------------------------------------------------------------------------
align 4
IM_END:
; UNINITIALIZED DATA: ; UNINITIALIZED DATA:
lcolor dd ? lcolor dd ?
x_max dw ? ; à §¬¥àë íªà ­  x_max dw ? ; à §¬¥àë íªà ­ 
y_max dw ? y_max dw ?
top_right_corner dd ? top_right_corner rd 1
filesize dd ? ;------------------------------------------------------------------------------
data_from_file: align 4
fileinfo_buffer:
rb 40
;------------------------------------------------------------------------------
align 4
rb 512
sthread_stack_top:
;------------------------------------------------------------------------------
align 4
rb 512
thread_stack_top:
;------------------------------------------------------------------------------
align 4
rb 512
stack_top:
I_END:
;------------------------------------------------------------------------------

View File

@ -1,5 +1,6 @@
@erase lang.inc @erase lang.inc
@echo lang fix en >lang.inc @echo lang fix en >lang.inc
@fasm @ss.asm @ss @fasm -m 16384 @ss.asm @ss
@kpack @ss
@erase lang.inc @erase lang.inc
@pause @pause

View File

@ -1,5 +1,6 @@
@erase lang.inc @erase lang.inc
@echo lang fix ru >lang.inc @echo lang fix ru >lang.inc
@fasm @ss.asm @ss @fasm -m 16384 @ss.asm @ss
@kpack @ss
@erase lang.inc @erase lang.inc
@pause @pause