kolibrios-fun/programs/fs/kfar/trunk/zlib/example1.asm
IgorA fb9e611d64 archiver.obj: fix function deflate_rle
kiv: clean code

git-svn-id: svn://kolibrios.org@6801 a494cfbc-eb01-0410-851d-a64ba20cac60
2016-12-20 12:12:55 +00:00

301 lines
6.5 KiB
NASM
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use32 ; ¢ª«îç¨âì 32-¡¨â­ë© ०¨¬  áᥬ¡«¥à 
org 0x0 ;  ¤à¥á æ¨ï á ­ã«ï
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 ;à §¬¥à ¤ ­­ëå ¤«ï 㯠ª®¢ª¨
m1size dd 1024 ;à §¬¥à ¡ãä¥à  ¤ ­­ëå ¤«ï 㯠ª®¢ª¨
m2size dd 0 ;à §¬¥à à á¯ ª®¢ ­­ëå ¤ ­­ëå
align 4
m0: ;¤ ­­ë¥ ¤«ï 㯠ª®¢ª¨
file 'zlib.txt'
align 4
m1 rb 1024 ;¡ãä¥à ¤«ï 㯠ª®¢ ­­ëå ¤ ­­ëå
m2 dd 0 ;㪠§ â¥«ì ­  à á¯ ª®¢ ­­ë¥ ¤ ­­ë¥
buf rb 1024 ;¡ãä¥à ¤«ï ¢ë¢®¤  ᦠâëå ¤ ­­ëå ¢ ®ª­®
strategy dd Z_DEFAULT_STRATEGY ;áâà â¥£¨ï ᦠâ¨ï
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: ; ¯¥à¥à¨á®¢ âì ®ª­®
call draw_window ; ¢ë§ë¢ ¥¬ ¯à®æ¥¤ãàã ®âà¨á®¢ª¨ ®ª­ 
align 4
still:
mcall SF_WAIT_EVENT
cmp eax,1 ; ¯¥à¥à¨á®¢ âì ®ª­® ?
je red
cmp eax,2 ; ­ ¦ â  ª« ¢¨è  ?
je key
cmp eax,3 ; ­ ¦ â  ª­®¯ª  ?
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 ; ¢¥à­ãâìáï ª ­ ç «ã 横« 
;---------------------------------------------------------------------
align 4
button:
mcall SF_GET_BUTTON
cmp ah,1
jne still
.exit: ; ª®­¥æ ¯à®£à ¬¬ë
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 ; ¨ ⨯ ®ª­  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]
;‘âà â¥£¨ï:
; Z_DEFAULT_STRATEGY, Z_FILTERED, Z_HUFFMAN_ONLY, Z_RLE, Z_FIXED
mov eax,my_strm
mov [eax+z_stream.next_in],m0 ;ãáâ ­ ¢«¨¢ ¥¬ ¯ ¬ïâì ¤«ï ᦠâ¨ï
mov ecx,[m0size]
mov [eax+z_stream.avail_in],ecx ;à §¬¥à ᦨ¬ ¥¬ë¦ ¤ ­­ëå
mov [eax+z_stream.next_out],m1 ;ãáâ ­ ¢«¨¢ ¥¬ ¡ãä¥à ¤«ï ᦠâ¨ï
mov dword[eax+z_stream.avail_out],1024 ;à §¬¥à ¡ãä¥à  ¤«ï ᦠâ¨ï (¬ ªá¨¬ã¬ 16 Š¡)
;¢ëç¨á«ï¥¬ crc ¤«ï ᦨ¬ ¥¬ë¦ ¤ ­­ëå
stdcall [calc_crc32], 0,m0,ecx
mov edx,eax
;call print_z_struct
stdcall [deflate], my_strm, Z_FINISH ;Z_NO_FLUSH
;call print_z_struct
;à §¬¥à ᦠâëå ¤ ­­ëå: 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)
;áâ ¢¨¬ crc ­  ᦠâë¥ ¤ ­­ë¥
mov ecx,[m1size]
sub ecx,4
add ecx,m1
mov [ecx],edx
;ä®à¬¨à®¢ ­¨¥ ⥪áâ  ¤«ï ®â®¡à ¦¥­¨ï ᦠâëå ¤ ­­ëå
;¢ 16-à¨ç­®¬ ¢¨¤¥, ­ã¦­® ⮫쪮 ¤«ï ¯à¨¬¥à 
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
;㤠«¥­¨¥ ¡ãä¥à  á à ­¥¥ à á¯ ª®¢ ­­ë¬¨ ¤ ­­ë¬¨
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 ;§ ¯¨áì ­®¢ëå à á¯ ª®¢ ­­ëå ¤ ­­ëå
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: