kolibrios-fun/programs/fs/kfar/trunk/zlib/example1.asm

287 lines
6.2 KiB
NASM
Raw Normal View History

use32
org 0
db 'MENUET01'
dd 1,START,I_END,MEM,STACKTOP,0,cur_dir_path
include '../../../../proc32.inc'
include '../../../../macros.inc'
include '../../../../KOSfuncs.inc'
include '../../../../develop/libraries/box_lib/load_lib.mac'
include 'deflate.inc'
include 'debug.inc'
include 'zlib.inc'
@use_library
align 4
m0size dd 90 ;ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E3AFA0><EFBFBD><EFBFBD><EFBFBD>
m1size dd 1024 ;ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E3AFA0><EFBFBD><EFBFBD><EFBFBD>
m2size dd 0 ;ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD><E1AFA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
align 4
m0: ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E3AFA0><EFBFBD><EFBFBD><EFBFBD>
file 'zlib.txt'
align 4
m1 rb 1024 ;<3B><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E3AFA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
m2 dd 0 ;㪠<><E3AAA0><EFBFBD> <20><> <20><><EFBFBD><E1AFA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
buf rb 1024 ;<3B><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><EFBFBD><EBA2AE><><E1A6A0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>
strategy dd Z_DEFAULT_STRATEGY ;<3B><><EFBFBD><EFBFBD><EFBFBD><E2A5A3><><E1A6A0><EFBFBD>
align 4
START:
load_libraries l_libs_start,load_lib_end
mov ebp,lib0
.test_lib_open:
cmp dword [ebp+ll_struc_size-4],0
jz @f
mcall SF_TERMINATE_PROCESS ;exit not correct
@@:
add ebp,ll_struc_size
cmp ebp,load_lib_end
jl .test_lib_open
; mcall SF_SYS_MISC, SSF_HEAP_INIT
call test_code
align 4
red: ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1AEA2><EFBFBD> <20><><EFBFBD><EFBFBD>
call draw_window ; <20><><EFBFBD><EFBFBD><EBA2A0> <20><><EFBFBD><EFBFBD><E6A5A4><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><E1AEA2> <20><><EFBFBD><EFBFBD>
align 4
still:
mcall SF_WAIT_EVENT
cmp eax,1 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1AEA2><EFBFBD> <20><><EFBFBD><EFBFBD> ?
je red
cmp eax,2 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ?
je key
cmp eax,3 ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ?
je button
jmp still
align 4
key:
mcall SF_GET_KEY
cmp ah,178 ;Up
jne @f
cmp dword[strategy],0
jle @f
dec dword[strategy]
call test_code
call draw_window
@@:
cmp ah,177 ;Down
jne @f
cmp dword[strategy],4
jge @f
inc dword[strategy]
call test_code
call draw_window
@@:
cmp ah,176 ;Left
jne @f
cmp dword[m0size],8
jl @f
dec dword[m0size]
call test_code
call draw_window
@@:
cmp ah,179 ;Right
jne @f
inc dword[m0size]
call test_code
call draw_window
@@:
jmp still ; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><><E6A8AA>
;---------------------------------------------------------------------
align 4
button:
mcall SF_GET_BUTTON
cmp ah,1
jne still
.exit: ; <20><><EFBFBD><EFBFBD><EFBFBD> <20>ணࠬ<E0AEA3><E0A0AC>
mcall SF_SYS_MISC,SSF_MEM_FREE,[m2]
mcall SF_TERMINATE_PROCESS
align 4
draw_window:
mcall SF_REDRAW, SSF_BEGIN_DRAW
mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc,sizeof.system_colors
mov edx, [sc.work] ; 梥<><>
or edx, 0x33000000 ; <20> <20><><EFBFBD><EFBFBD> 3
mcall SF_CREATE_WINDOW, <50,600>, <50,180>, , ,title
cStr edx,'Strategy:'
mcall SF_DRAW_TEXT, <10,10>,0x40f0,,9
cStr edx,'Input size:'
mcall , <10,20>,,,11
cStr edx,'Compr. size:'
mcall , <10,30>,,,12
cStr edx,'Outp. size:'
mcall , <10,120>,,,11
mov edx,[strategy]
imul edx,12
add edx,capt_strateg
mcall , <90,10>,0,,12
mcall SF_DRAW_NUMBER, (5 shl 16)+1, m0size, <90,20>
mcall , (5 shl 16)+1, m1size, <90,30>
mcall , (5 shl 16)+1, m2size, <90,120>
;mov ecx,(1 shl 31)
mov esi,[m2size]
cmp esi,95
jle @f
mov esi,95
@@:
mcall SF_DRAW_TEXT, <10,130>, 0, [m2]
mov esi,7
mov ebx,(10 shl 16)+45 ;(x shl 16)+y
mov edx,buf
.cycle1: ;rows
mcall SF_DRAW_TEXT,, (1 shl 31)
add ebx,10
add edx,32*3
dec esi
jnz .cycle1
mcall SF_REDRAW, SSF_END_DRAW
ret
align 4
test_code:
stdcall [deflateInit2], my_strm,\
-1, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, [strategy]
;<3B><><EFBFBD><EFBFBD><EFBFBD><E2A5A3>:
; Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE, Z_FIXED
mov eax,my_strm
mov [eax+z_stream.next_in],m0 ;<3B><><EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E1A6A0><EFBFBD>
mov ecx,[m0size]
mov [eax+z_stream.avail_in],ecx ;ࠧ<><E0A0A7><EFBFBD><><E1A6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mov [eax+z_stream.next_out],m1 ;<3B><><EFBFBD><E2A0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E1A6A0><EFBFBD>
mov dword[eax+z_stream.avail_out],1024 ;ࠧ<><E0A0A7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><><E1A6A0><EFBFBD> (<28><><EFBFBD><EFBFBD><E1A8AC> 16 <20><>)
stdcall [deflate], my_strm, Z_FINISH
;ࠧ<><E0A0A7><EFBFBD><><E1A6A0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1024-[my_strm.avail_out]
mov ecx,1024
sub ecx,[my_strm.avail_out]
mov [m1size],ecx
;assert(ret != Z_STREAM_ERROR)
;while (strm.avail_out == 0)
;<3B><>ନ஢<E0ACA8><E0AEA2><EFBFBD><EFBFBD><><E2A5AA><EFBFBD> <20><><EFBFBD> <20>⮡ࠦ<E2AEA1><E0A0A6><EFBFBD><EFBFBD><><E1A6A0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
;<3B> 16-<2D><><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><EFBFBD> ⮫쪮 <20><><EFBFBD> <20><EFBFBD><E0A8AC><EFBFBD>
mov ebx,[m1size]
mov esi,m1
mov edi,buf
mov edx,7
align 4
.cycle1: ;rows
mov ecx,32
align 4
.cycle0: ;cols
stdcall hex_in_str, edi,[esi],2
add edi,2
inc esi
mov byte[edi],' ' ;format space
dec ebx
jz .cycle1end ;if end file
inc edi
loop .cycle0
mov byte[edi-1],0
dec edx
jnz .cycle1
.cycle1end:
mov byte[edi],0
;㤠<><E3A4A0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><E0A0AD> <20><><EFBFBD><E1AFA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD>
mcall SF_SYS_MISC,SSF_MEM_FREE,[m2]
mov eax,[m1size]
sub eax,2 ;;; 2? or 6?
mov [m2size],eax
mov eax,m1
add eax,2
stdcall [deflate_unpack],eax,m2size
mov [m2],eax ;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><E1AFA0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mov ecx,[m0size] ;;; ???
mov [m2size],ecx
ret
align 4
proc print_z_struct uses eax ebx
mov eax,my_strm
mov ebx,[eax+z_stream.state]
stdcall debug_fields,eax,sv_2
stdcall debug_fields,ebx,sv_3
ret
endp
align 4
sc system_colors
align 4
title db 'Zlib test, press on [Up], [Down], [Left], [Right]',0
align 4
capt_strateg db '0) Default ',0
db '1) Filtered',0
db '2) Huffman ',0
db '3) Rle ',0
db '4) Fixed ',0
align 4
import_archiver:
deflate_unpack dd sz_deflate_unpack
deflateInit dd sz_deflateInit
deflateInit2 dd sz_deflateInit2
deflateReset dd sz_deflateReset
deflate dd sz_deflate
deflateEnd dd sz_deflateEnd
calc_crc32 dd sz_calc_crc32
dd 0,0
sz_deflate_unpack db 'deflate_unpack',0
sz_deflateInit db 'deflateInit',0
sz_deflateInit2 db 'deflateInit2',0
sz_deflateReset db 'deflateReset',0
sz_deflate db 'deflate',0
sz_deflateEnd db 'deflateEnd',0
sz_calc_crc32 db 'calc_crc32',0
;--------------------------------------------------
system_dir_0 db '/sys/lib/'
lib_name_0 db 'archiver.obj',0
err_message_found_lib0 db 'Sorry I cannot load library archiver.obj',0
head_f_i:
head_f_l db 'System error',0
err_message_import0 db 'Error on load import library archiver.obj',0
l_libs_start:
lib0 l_libs lib_name_0, cur_dir_path, library_path, system_dir_0,\
err_message_found_lib0, head_f_l, import_archiver,err_message_import0, head_f_i
load_lib_end:
;---------------------------------------------------------------------
align 16
I_END:
my_strm z_stream
rd 4096
align 16
STACKTOP:
cur_dir_path:
rb 4096
library_path:
rb 4096
MEM: