add 'zlib.obj'

git-svn-id: svn://kolibrios.org@6617 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2016-10-26 19:35:35 +00:00
parent aeead601fe
commit 87008e93c5
15 changed files with 9171 additions and 0 deletions

View File

@ -0,0 +1,309 @@
; adler32.asm -- compute the Adler-32 checksum of a data stream
; Copyright (C) 1995-2011 Mark Adler
; For conditions of distribution and use, see copyright notice in zlib.h
BASE equ 65521 ;largest prime smaller than 65536
NMAX equ 5552
; NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
macro DO1 buf,i
{
mov eax,buf
add eax,i
movzx eax,byte[eax]
add [adler],eax
mov eax,[adler]
add [sum2],eax
}
macro DO2 buf,i
{
DO1 buf,i
DO1 buf,i+1
}
macro DO4 buf,i
{
DO2 buf,i
DO2 buf,i+2
}
macro DO8 buf,i
{
DO4 buf,i
DO4 buf,i+4
}
macro DO16 buf
{
DO8 buf,0
DO8 buf,8
}
; use NO_DIVIDE if your processor does not do division in hardware --
; try it both ways to see which is faster
; note that this assumes BASE is 65521, where 65536 % 65521 == 15
; (thank you to John Reiser for pointing this out)
macro CHOP a
{
if NO_DIVIDE eq 1
mov eax,a
shr eax,16
and a,0xffff
shl eax,4
add a,eax
shr eax,4
sub a,eax
end if
}
macro MOD28 a
{
if NO_DIVIDE eq 1
local .end0
CHOP a
cmp a,BASE
jl .end0 ;if (..>=..)
sub a,BASE
.end0:
else
push eax ecx edx
mov eax,a
xor edx,edx
mov ecx,BASE
div ecx
mov a,edx
pop edx ecx eax
end if
}
macro MOD a
{
if NO_DIVIDE eq 1
CHOP a
MOD28 a
else
push eax ecx edx
mov eax,a
xor edx,edx
mov ecx,BASE
div ecx
mov a,edx
pop edx ecx eax
end if
}
macro MOD63 a
{
if NO_DIVIDE eq 1
;this assumes a is not negative
; z_off64_t tmp = a >> 32;
; a &= 0xffffffff;
; a += (tmp << 8) - (tmp << 5) + tmp;
; tmp = a >> 16;
; a &= 0xffff;
; a += (tmp << 4) - tmp;
; tmp = a >> 16;
; a &= 0xffff;
; a += (tmp << 4) - tmp;
; if (a >= BASE) a -= BASE;
else
push eax ecx edx
mov eax,a
xor edx,edx
mov ecx,BASE
div ecx
mov a,edx
pop edx ecx eax
end if
}
; =========================================================================
;uLong (adler, buf, len)
; uLong adler
; const Bytef *buf
; uInt len
align 4
proc adler32 uses ebx edx, adler:dword, buf:dword, len:dword
locals
sum2 dd ? ;uLong
endl
;zlib_debug 'adler32 adler = %d',[adler]
; split Adler-32 into component sums
mov eax,[adler]
shr eax,16
mov [sum2],eax
and [adler],0xffff
mov ebx,[buf]
; in case user likes doing a byte at a time, keep it fast
cmp dword[len],1
jne .end0 ;if (..==..)
movzx eax,byte[ebx]
add [adler],eax
cmp dword[adler],BASE
jl @f ;if (..>=..)
sub dword[adler],BASE
@@:
mov eax,[adler]
add [sum2],eax
cmp dword[sum2],BASE
jl @f ;if (..>=..)
sub dword[sum2],BASE
@@:
jmp .combine
align 4
.end0:
; initial Adler-32 value (deferred check for len == 1 speed)
cmp ebx,Z_NULL
jne @f ;if (..==0)
xor eax,eax
inc eax
jmp .end_f
align 4
@@:
; in case short lengths are provided, keep it somewhat fast
cmp dword[len],16
jge .end1 ;if (..<..)
.cycle0:
cmp dword[len],0
jne @f ;while (..)
movzx eax,byte[ebx]
inc ebx
add [adler],eax
mov eax,[adler]
add [sum2],eax
dec dword[len]
jmp .cycle0
align 4
@@:
cmp dword[adler],BASE
jl @f ;if (..>=..)
sub dword[adler],BASE
@@:
MOD28 dword[sum2] ;only added so many BASE's
jmp .combine
align 4
.end1:
; do length NMAX blocks -- requires just one modulo operation
.cycle3:
cmp dword[len],NMAX
jl .cycle3end ;while (..>=..)
sub dword[len],NMAX
mov edx,NMAX/16 ;NMAX is divisible by 16
.cycle1: ;do
DO16 ebx ;16 sums unrolled
add ebx,16
dec edx
cmp edx,0
jg .cycle1 ;while (..)
MOD [adler]
MOD [sum2]
jmp .cycle3
align 4
.cycle3end:
; do remaining bytes (less than NMAX, still just one modulo)
cmp dword[len],0
jne .end2 ;if (..) ;avoid modulos if none remaining
@@:
cmp dword[len],16
jl .cycle2 ;while (..>=..)
sub dword[len],16
DO16 ebx
add ebx,16
jmp @b
align 4
.cycle2:
cmp dword[len],0
jne @f ;while (..)
movzx eax,byte[ebx]
inc ebx
add [adler],eax
mov eax,[adler]
add [sum2],eax
dec dword[len]
jmp .cycle2
align 4
@@:
MOD [adler]
MOD [sum2]
.end2:
; return recombined sums
.combine:
mov eax,[sum2]
shl eax,16
or eax,[adler]
.end_f:
;zlib_debug ' adler32.ret = %d',eax
ret
endp
; =========================================================================
;uLong (adler1, adler2, len2)
; uLong adler1
; uLong adler2
; z_off64_t len2
align 4
proc adler32_combine_, adler1:dword, adler2:dword, len2:dword
locals
sum1 dd ? ;uLong
sum2 dd ? ;uLong
; unsigned rem;
endl
; for negative len, return invalid adler32 as a clue for debugging
cmp dword[len2],0
jge @f ;if (..<0)
mov eax,0xffffffff
jmp .end_f
@@:
; the derivation of this formula is left as an exercise for the reader
; MOD63(len2) ;assumes len2 >= 0
; rem = (unsigned)len2;
; sum1 = adler1 & 0xffff;
; sum2 = rem * sum1;
; MOD(sum2);
; sum1 += (adler2 & 0xffff) + BASE - 1;
; sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
cmp dword[sum1],BASE
jl @f ;if (..>=..)
sub dword[sum1],BASE
@@:
cmp dword[sum1],BASE
jl @f ;if (..>=..)
sub dword[sum1],BASE
@@:
cmp dword[sum2],BASE shl 1
jl @f ;if (..>=..)
sub dword[sum2],BASE shl 1
@@:
cmp dword[sum2],BASE
jl @f ;if (..>=..)
sub dword[sum2],BASE
@@:
mov eax,[sum2]
shl eax,16
or eax,[sum1]
.end_f:
ret
endp
; =========================================================================
;uLong (adler1, adler2, len2)
; uLong adler1
; uLong adler2
; z_off_t len2
align 4
proc adler32_combine, adler1:dword, adler2:dword, len2:dword
stdcall adler32_combine_, [adler1], [adler2], [len2]
ret
endp
;uLong (adler1, adler2, len2)
; uLong adler1
; uLong adler2
; z_off64_t len2
align 4
proc adler32_combine64, adler1:dword, adler2:dword, len2:dword
stdcall adler32_combine_, [adler1], [adler2], [len2]
ret
endp

View File

@ -0,0 +1,5 @@
@fasm.exe -m 32768 zlib.asm zlib.obj
@kpack zlib.obj
@fasm.exe -m 32768 example1.asm example1.kex
@kpack example1.kex
pause

View File

@ -0,0 +1,278 @@
; crc32.asm -- compute the CRC-32 of a data stream
; Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler
; For conditions of distribution and use, see copyright notice in zlib.inc
; Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
; CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
; tables for updating the shift register in one step with three exclusive-ors
; instead of four steps with four exclusive-ors. This results in about a
; factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
; Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
; protection on the static variables used to control the first-use generation
; of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
; first call get_crc_table() to initialize the tables before allowing more than
; one thread to use crc32().
; Definitions for doing the crc four data bytes at a time.
TBLS equ 1
if DYNAMIC_CRC_TABLE eq 1
align 4
crc_table_empty dd 1
align 4
crc_table rd TBLS*256
; Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
; x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
; Polynomials over GF(2) are represented in binary, one bit per coefficient,
; with the lowest powers in the most significant bit. Then adding polynomials
; is just exclusive-or, and multiplying a polynomial by x is a right shift by
; one. If we call the above polynomial p, and represent a byte as the
; polynomial q, also with the lowest power in the most significant bit (so the
; byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
; where a mod b means the remainder after dividing a by b.
; This calculation is done using the shift-register method of multiplying and
; taking the remainder. The register is initialized to zero, and for each
; incoming bit, x^32 is added mod p to the register if the bit is a one (where
; x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
; x (which is shifting right by one and adding x^32 mod p if the bit shifted
; out is a one). We start with the highest power (least significant bit) of
; q and repeat for all eight bits of q.
; The first table is simply the CRC of all possible eight bit values. This is
; all the information needed to generate CRCs on data a byte at a time for all
; combinations of CRC register values and incoming bytes. The remaining tables
; allow for word-at-a-time CRC calculation for both big-endian and little-
; endian machines, where a word is four bytes.
;void ()
align 4
proc make_crc_table uses ecx edx edi
zlib_debug 'make_crc_table'
; generate a crc for every 8-bit value
xor edx, edx
mov edi, crc_table
.1:
mov ecx, 8
mov eax, edx
.2:
shr eax, 1
jnc @f
xor eax, 0xEDB88320
@@:
loop .2
stosd
inc dl
jnz .1
mov dword[crc_table_empty],0
ret
endp
else ;!DYNAMIC_CRC_TABLE
; ========================================================================
; Tables of CRC-32s of all single-byte values, made by make_crc_table().
;include 'crc32.inc'
end if ;DYNAMIC_CRC_TABLE
; =========================================================================
; This function can be used by asm versions of crc32()
;const z_crc_t* ()
align 4
proc get_crc_table
if DYNAMIC_CRC_TABLE eq 1
cmp dword[crc_table_empty],0
je @f ;if (..)
call make_crc_table
@@:
end if ;DYNAMIC_CRC_TABLE
mov eax,crc_table
ret
endp
; =========================================================================
macro DO1
{
xor al,byte[esi]
xor al,ah
mov eax,[crc_table+eax*4]
inc esi
}
macro DO8
{
DO1
DO1
DO1
DO1
DO1
DO1
DO1
DO1
}
; =========================================================================
;unsigned long (crc, buf, len)
; unsigned long crc
; unsigned char *buf
; uInt len
align 4
proc calc_crc32 uses ecx esi, p1crc:dword, buf:dword, len:dword
xor eax,eax
mov esi,[buf]
zlib_debug 'calc_crc32 buf = %d',esi
cmp esi,Z_NULL
je .end_f ;if (..==0) return 0
if DYNAMIC_CRC_TABLE eq 1
cmp dword[crc_table_empty],0
je @f ;if (..)
call make_crc_table
@@:
end if
mov eax,[p1crc]
xor eax,0xffffffff
mov [p1crc],eax
mov ecx,[len]
align 4
.cycle0:
cmp ecx,8
jl @f
DO8
sub ecx,8
jmp .cycle0
align 4
@@:
cmp ecx,1
jl @f
DO1
dec ecx
jmp @b
@@:
mov eax,[p1crc]
xor eax,0xffffffff
.end_f:
ret
endp
GF2_DIM equ 32 ;dimension of GF(2) vectors (length of CRC)
; =========================================================================
;unsigned long (mat, vec)
; unsigned long *mat
; unsigned long vec
align 4
proc gf2_matrix_times, mat:dword, vec:dword
; unsigned long sum;
; sum = 0;
; while (vec) {
; if (vec & 1)
; sum ^= *mat;
; vec >>= 1;
; mat++;
; }
; return sum;
ret
endp
; =========================================================================
;local void (square, mat)
; unsigned long *square
; unsigned long *mat
align 4
proc gf2_matrix_square, square:dword, mat:dword
; int n;
; for (n = 0; n < GF2_DIM; n++)
; square[n] = gf2_matrix_times(mat, mat[n]);
ret
endp
; =========================================================================
;uLong (crc1, crc2, len2)
; uLong crc1
; uLong crc2
; z_off64_t len2
align 4
proc crc32_combine_, crc1:dword, crc2:dword, len2:dword
; int n;
; unsigned long row;
; unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
; unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
; degenerate case (also disallow negative lengths)
; if (len2 <= 0)
; return crc1;
; put operator for one zero bit in odd
; odd[0] = 0xedb88320UL; /* CRC-32 polynomial */
; row = 1;
; for (n = 1; n < GF2_DIM; n++) {
; odd[n] = row;
; row <<= 1;
; }
; put operator for two zero bits in even
; gf2_matrix_square(even, odd);
; put operator for four zero bits in odd
; gf2_matrix_square(odd, even);
; apply len2 zeros to crc1 (first square will put the operator for one
; zero byte, eight zero bits, in even)
; do {
; apply zeros operator for this bit of len2
; gf2_matrix_square(even, odd);
; if (len2 & 1)
; crc1 = gf2_matrix_times(even, crc1);
; len2 >>= 1;
; if no more bits set, then done
; if (len2 == 0)
; break;
; another iteration of the loop with odd and even swapped
; gf2_matrix_square(odd, even);
; if (len2 & 1)
; crc1 = gf2_matrix_times(odd, crc1);
; len2 >>= 1;
; if no more bits set, then done
; } while (len2 != 0);
; return combined crc
; crc1 ^= crc2;
; return crc1;
ret
endp
; =========================================================================
;uLong (crc1, crc2, len2)
; uLong crc1
; uLong crc2
; z_off_t len2
align 4
proc crc32_combine, crc1:dword, crc2:dword, len2:dword
stdcall crc32_combine_, [crc1], [crc2], [len2]
ret
endp
;uLong (crc1, crc2, len2)
; uLong crc1
; uLong crc2
; z_off64_t len2
align 4
proc crc32_combine64, crc1:dword, crc2:dword, len2:dword
stdcall crc32_combine_, [crc1], [crc2], [len2]
ret
endp

View File

@ -0,0 +1,440 @@
txt_zv db '*',0
txt_sp db ' ',0
txt_buf db '1234',0
rd 1
buf_param rb 80
macro cStr dest,txt
{
local .end_t
local .m_txt
jmp .end_t
align 4
.m_txt db txt,0
align 4
.end_t:
if dest eq
mov eax,.m_txt
else
mov dest,.m_txt
end if
}
;for debug
tz1 db 'next_in',13,10,0
tz2 db 'avail_in',13,10,0
tz3 db 'total_in',13,10,0
tz4 db 'next_out',13,10,0
tz5 db 'avail_out',13,10,0
tz6 db 'total_out',13,10,0
tz7 db 'msg',13,10,0
tz8 db 'state',13,10,0
tz9 db 'zalloc',13,10,0
tz10 db 'zfree',13,10,0
tz11 db 'opaque',13,10,0
tz12 db 'data_type',13,10,0
tz13 db 'adler',13,10,0
tz14 db 'reserved',13,10,0
sv_2:
dd z_stream.next_in,4,tz1
dd z_stream.avail_in,2,tz2
dd z_stream.total_in,4,tz3
dd z_stream.next_out,4,tz4
dd z_stream.avail_out,2,tz5
dd z_stream.total_out,4,tz6
dd z_stream.msg,4,tz7
dd z_stream.state,4,tz8
dd z_stream.zalloc,4,tz9
dd z_stream.zfree,4,tz10
dd z_stream.opaque,4,tz11
dd z_stream.data_type,2,tz12
dd z_stream.adler,4,tz13
dd z_stream.reserved,4,tz14
dd 0,0
ta1 db 'strm',13,10,0
ta2 db 'status',13,10,0
ta3 db 'pending_buf',13,10,0
ta4 db 'pending_buf_size',13,10,0
ta5 db 'pending_out',13,10,0
ta6 db 'pending',13,10,0
ta7 db 'wrap',13,10,0
ta8 db 'gzhead',13,10,0
ta9 db 'gzindex',13,10,0
ta10 db 'method',13,10,0
ta11 db 'last_flush',13,10,0
ta12 db 'w_size',13,10,0
ta13 db 'w_bits',13,10,0
ta14 db 'w_mask',13,10,0
ta15 db 'window',13,10,0
ta16 db 'window_size',13,10,0
ta17 db 'prev',13,10,0
ta18 db 'head',13,10,0
ta19 db 'ins_h',13,10,0
ta20 db 'hash_size',13,10,0
ta21 db 'hash_bits',13,10,0
ta22 db 'hash_mask',13,10,0
ta23 db 'hash_shift',13,10,0
ta24 db 'block_start',13,10,0
ta25 db 'match_length',13,10,0
ta26 db 'prev_match',13,10,0
ta27 db 'match_available',13,10,0
ta28 db 'strstart',13,10,0
ta29 db 'match_start',13,10,0
ta30 db 'lookahead',13,10,0
ta31 db 'prev_length',13,10,0
ta32 db 'max_chain_length',13,10,0
ta33 db 'max_lazy_match',13,10,0
ta34 db 'level',13,10,0
ta35 db 'strategy',13,10,0
ta36 db 'good_match',13,10,0
ta37 db 'nice_match',13,10,0
ta38 db 'dyn_ltree',13,10,0
ta39 db 'dyn_dtree',13,10,0
ta40 db 'bl_tree',13,10,0
ta41 db 'l_desc',13,10,0
ta42 db 'd_desc',13,10,0
ta43 db 'bl_desc',13,10,0
ta44 db 'bl_count',13,10,0
ta45 db 'heap',13,10,0
ta46 db 'heap_len',13,10,0
ta47 db 'heap_max',13,10,0
ta48 db 'depth',13,10,0
ta49 db 'l_buf',13,10,0
ta50 db 'lit_bufsize',13,10,0
ta51 db 'last_lit',13,10,0
ta52 db 'd_buf',13,10,0
ta53 db 'opt_len',13,10,0
ta54 db 'static_len',13,10,0
ta55 db 'matches',13,10,0
ta56 db 'insert',13,10,0
; db 'compressed_len',13,10,0
; db 'bits_sent',13,10,0
ta59 db 'bi_buf',13,10,0
ta60 db 'bi_valid',13,10,0
ta61 db 'high_water',13,10,0
sv_3:
dd deflate_state.strm,4,ta1
dd deflate_state.status,4,ta2
dd deflate_state.pending_buf,4,ta3
dd deflate_state.pending_buf_size,4,ta4
dd deflate_state.pending_out,4,ta5
dd deflate_state.pending,2,ta6
dd deflate_state.wrap,4,ta7
dd deflate_state.gzhead,4,ta8
dd deflate_state.gzindex,4,ta9
dd deflate_state.method,1,ta10
dd deflate_state.last_flush,4,ta11
dd deflate_state.w_size,4,ta12
dd deflate_state.w_bits,4,ta13
dd deflate_state.w_mask,4,ta14
dd deflate_state.window,4,ta15
dd deflate_state.window_size,4,ta16
dd deflate_state.prev,4,ta17
dd deflate_state.head,4,ta18
dd deflate_state.ins_h,4,ta19
dd deflate_state.hash_size,4,ta20
dd deflate_state.hash_bits,4,ta21
dd deflate_state.hash_mask,4,ta22
dd deflate_state.hash_shift,4,ta23
dd deflate_state.block_start,4,ta24
dd deflate_state.match_length,4,ta25
dd deflate_state.prev_match,4,ta26
dd deflate_state.match_available,4,ta27
dd deflate_state.strstart,4,ta28
dd deflate_state.match_start,4,ta29
dd deflate_state.lookahead,4,ta30
dd deflate_state.prev_length,4,ta31
dd deflate_state.max_chain_length,4,ta32
dd deflate_state.max_lazy_match,4,ta33
dd deflate_state.level,2,ta34
dd deflate_state.strategy,2,ta35
dd deflate_state.good_match,4,ta36
dd deflate_state.nice_match,4,ta37
dd deflate_state.dyn_ltree,((2*HEAP_SIZE) shl 16)+2,ta38
dd deflate_state.dyn_dtree,((2*(2*D_CODES+1)) shl 16)+2,ta39
dd deflate_state.bl_tree,((2*(2*BL_CODES+1)) shl 16)+2,ta40
dd deflate_state.l_desc,(3 shl 16)+4,ta41
dd deflate_state.d_desc,(3 shl 16)+4,ta42
dd deflate_state.bl_desc,(3 shl 16)+4,ta43
dd deflate_state.bl_count,((MAX_BITS+1) shl 16)+2,ta44
dd deflate_state.heap,((2*L_CODES+1) shl 16)+2,ta45
dd deflate_state.heap_len,4,ta46
dd deflate_state.heap_max,4,ta47
dd deflate_state.depth,((2*L_CODES+1) shl 16)+1,ta48
dd deflate_state.l_buf,4,ta49
dd deflate_state.lit_bufsize,4,ta50
dd deflate_state.last_lit,4,ta51
dd deflate_state.d_buf,4,ta52
dd deflate_state.opt_len,4,ta53
dd deflate_state.static_len,4,ta54
dd deflate_state.matches,4,ta55
dd deflate_state.insert,4,ta56
;if DEBUG eq 1
;dd deflate_state.compressed_len
;dd deflate_state.bits_sent
;end if
dd deflate_state.bi_buf,2,ta59
dd deflate_state.bi_valid,4,ta60
dd deflate_state.high_water,4,ta61
dd 0,0
align 4
proc dbg_print, fun:dword, mes:dword
pushad
mov eax,SF_BOARD
mov ebx,SSF_DEBUG_WRITE
mov esi,[fun]
cmp esi,0
je .end0
@@:
mov cl,byte[esi]
int 0x40
inc esi
cmp byte[esi],0
jne @b
mov cl,':'
int 0x40
mov cl,' '
int 0x40
.end0:
mov esi,[mes]
cmp esi,0
je .end_f
@@:
mov cl,byte[esi]
cmp cl,0
je .end_f
int 0x40
inc esi
jmp @b
.end_f:
popad
ret
endp
;input:
; zif - 1...8
align 4
proc hex_in_str, buf:dword,val:dword,zif:dword
pushad
mov edi,dword[buf]
mov ecx,dword[zif]
add edi,ecx
dec edi
mov ebx,dword[val]
.cycle:
mov al,bl
and al,0xf
cmp al,10
jl @f
add al,'a'-'0'-10
@@:
add al,'0'
mov byte[edi],al
dec edi
shr ebx,4
loop .cycle
popad
ret
endp
;output:
; eax = strlen
align 4
proc strlen, str1:dword
mov eax,[str1]
@@:
cmp byte[eax],0
je @f
inc eax
jmp @b
@@:
sub eax,[str1]
ret
endp
align 4
proc str_format_dbg, buf:dword, fmt:dword, p1:dword
pushad
mov esi,[fmt]
mov edi,[buf]
mov ecx,80-1
.cycle0:
lodsb
cmp al,'%'
jne .no_param
lodsb
dec ecx
cmp al,0
je .cycle0end
cmp al,'d'
je @f
cmp al,'u'
je @f
cmp al,'l'
je .end1
jmp .end0
.end1: ;%lu %lx
lodsb
dec ecx
cmp al,'u'
jne .end0
@@:
mov eax,[p1]
stdcall convert_int_to_str,ecx
xor al,al
repne scasb
dec edi
.end0:
loop .cycle0
.no_param:
stosb
cmp al,0
je .cycle0end
loop .cycle0
.cycle0end:
xor al,al
stosb
stdcall dbg_print,txt_sp,[buf]
popad
ret
endp
align 4
proc debug_fields, saddr:dword, form:dword
locals
nl_array dd ?
endl
pushad
mov edi,[saddr]
cmp edi,0
je .end_f
mcall SF_BOARD,SSF_DEBUG_WRITE,13
mcall ,,10
mov eax,[form]
align 4
.cycle0:
mov ebx,[eax+4]
mov ecx,ebx
and ebx,0xffff
cmp ebx,0
je .end_f
mov esi,ebx
shl ebx,1
shr ecx,16
cmp ecx,0
je .end0
;if array
stdcall dbg_print,0,[eax+8]
mov edx,61 ;size text line
mov dword[nl_array],0
.cycle2:
inc dword[nl_array]
sub edx,ebx
sub edx,2 ;': '
cmp edx,3
jg .cycle2
mov edx,edi
add edx,[eax]
push eax
.nl_i:
mov eax,[nl_array]
mov byte[ebx+txt_buf],0 ;конец числа
.cycle1:
stdcall hex_in_str,txt_buf,[edx],ebx
add edx,esi ;move next value
push edi
mov edi,txt_buf
cmp byte[edi],'0'
jne @f
inc edi
cmp byte[edi],'0'
jne @f
inc edi
cmp byte[edi],'0'
jne @f
inc edi
cmp byte[edi],'0'
jne @f
inc edi
@@:
cmp byte[edi],0
jne @f
dec edi
@@:
stdcall dbg_print,edi,0
pop edi
;stdcall dbg_print,txt_buf,0
dec eax
jz .nl
loop .cycle1
.nl:
push ebx ecx
mcall SF_BOARD,SSF_DEBUG_WRITE,13
mcall ,,10
pop ecx ebx
dec ecx
cmp ecx,0
jg .nl_i
pop eax
add eax,12
jmp .cycle0
.end0:
mov edx,edi
add edx,[eax]
stdcall hex_in_str,txt_buf,[edx],ebx
mov byte[ebx+txt_buf],0 ;конец числа
stdcall dbg_print,txt_buf,[eax+8]
add eax,12
jmp .cycle0
.end_f:
mcall SF_BOARD,SSF_DEBUG_WRITE,13
mcall ,,10
popad
ret
endp
;input:
; eax - число
; edi - буфер для строки
; len - длинна буфера
;output:
align 4
proc convert_int_to_str, len:dword
pushad
mov esi,[len]
add esi,edi
dec esi
call .str
popad
ret
endp
align 4
.str:
mov ecx,0x0a
cmp eax,ecx
jb @f
xor edx,edx
div ecx
push edx
call .str
pop eax
@@:
cmp edi,esi
jge @f
or al,0x30
stosb
mov byte[edi],0
@@:
ret

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,353 @@
; deflate.inc -- internal compression state
; Copyright (C) 1995-2012 Jean-loup Gailly
; For conditions of distribution and use, see copyright notice in zlib.inc
; WARNING: this file should *not* be used by applications. It is
; part of the implementation of the compression library and is
; subject to change. Applications should only use zlib.inc.
include 'zutil.inc'
; ===========================================================================
; Internal compression state.
LENGTH_CODES equ 29
; number of length codes, not counting the special END_BLOCK code
LITERALS equ 256
; number of literal bytes 0..255
L_CODES equ (LITERALS+1+LENGTH_CODES)
; number of Literal or Length codes, including the END_BLOCK code
D_CODES equ 30
; number of distance codes
BL_CODES equ 19
; number of codes used to transfer the bit lengths
HEAP_SIZE equ (2*L_CODES+1)
; maximum heap size
MAX_BITS equ 15
; All codes must not exceed MAX_BITS bits
Buf_size equ 16
; size of bit buffer in bi_buf
INIT_STATE equ 42
EXTRA_STATE equ 69
NAME_STATE equ 73
COMMENT_STATE equ 91
HCRC_STATE equ 103
BUSY_STATE equ 113
FINISH_STATE equ 800
; Stream status
; Data structure describing a single value and its code string.
struct ct_data ;ct_data_s
fc dw ? ;union
;uint_16 freq ;frequency count
;uint_16 code ;bit string
dale dw ? ;union
;uint_16 dad ;father node in Huffman tree
;uint_16 len ;length of bit string
ends
Freq equ ct_data.fc ;.freq
Code equ ct_data.fc ;.code
Dad equ ct_data.dale ;.dad
Len equ ct_data.dale ;.len
struct tree_desc ;tree_desc_s
dyn_tree dd ? ;ct_data * ;the dynamic tree
max_code dd ? ;int ;largest code with non zero frequency
stat_desc dd ? ;static_tree_desc * ;the corresponding static tree
ends
; A Pos is an index in the character window. We use short instead of int to
; save space in the various tables. IPos is used only for parameter passing.
struct deflate_state ;internal_state
strm dd ? ;z_streamp ;pointer back to this zlib stream
status dd ? ;int ;as the name implies
pending_buf dd ? ;Bytef *;output still pending
pending_buf_size dd ? ;ulg ;size of pending_buf
pending_out dd ? ;Bytef * ;next pending byte to output to the stream
pending dw ? ;uInt ;nb of bytes in the pending buffer
wrap dd ? ;int ;bit 0 true for zlib, bit 1 true for gzip
gzhead dd ? ;gz_headerp ;gzip header information to write
gzindex dd ? ;uInt ;where in extra, name, or comment
method db ? ;Byte ;can only be DEFLATED
last_flush dd ? ;int ;value of flush param for previous deflate call
; used by deflate.asm:
w_size dd ? ;uInt ;LZ77 window size (32K by default)
w_bits dd ? ;uInt ;log2(w_size) (8..16)
w_mask dd ? ;uInt ;w_size - 1
window dd ? ;Bytef *
; Sliding window. Input bytes are read into the second half of the window,
; and move to the first half later to keep a dictionary of at least wSize
; bytes. With this organization, matches are limited to a distance of
; wSize-MAX_MATCH bytes, but this ensures that IO is always
; performed with a length multiple of the block size. Also, it limits
; the window size to 64K, which is quite useful on MSDOS.
; To do: use the user input buffer as sliding window.
window_size dd ? ;ulg
; Actual size of window: 2*wSize, except when the user input buffer
; is directly used as sliding window.
prev dd ? ;Posf *
; Link to older string with same hash index. To limit the size of this
; array to 64K, this link is maintained only for the last 32K strings.
; An index in this array is thus a window index modulo 32K.
head dd ? ;Posf * ;Heads of the hash chains or NIL.
ins_h dd ? ;uInt ;hash index of string to be inserted
hash_size dd ? ;uInt ;number of elements in hash table
hash_bits dd ? ;uInt ;log2(hash_size)
hash_mask dd ? ;uInt ;hash_size-1
hash_shift dd ? ;uInt
; Number of bits by which ins_h must be shifted at each input
; step. It must be such that after MIN_MATCH steps, the oldest
; byte no longer takes part in the hash key, that is:
; hash_shift * MIN_MATCH >= hash_bits
block_start dd ? ;long
; Window position at the beginning of the current output block. Gets
; negative when the window is moved backwards.
match_length dd ? ;uInt ;length of best match
prev_match dd ? ;IPos ;previous match
match_available dd ? ;int ;set if previous match exists
strstart dd ? ;uInt ;start of string to insert
match_start dd ? ;uInt ;start of matching string
lookahead dd ? ;uInt ;number of valid bytes ahead in window
prev_length dd ? ;uInt
; Length of the best match at previous step. Matches not greater than this
; are discarded. This is used in the lazy match evaluation.
max_chain_length dd ? ;uInt
; To speed up deflation, hash chains are never searched beyond this
; length. A higher limit improves compression ratio but degrades the
; speed.
max_lazy_match dd ? ;uInt
; Attempt to find a better match only when the current match is strictly
; smaller than this value. This mechanism is used only for compression
; levels >= 4.
;# define max_insert_length max_lazy_match
; Insert new strings in the hash table only if the match length is not
; greater than this length. This saves time but degrades compression.
; max_insert_length is used only for compression levels <= 3.
level dw ? ;int ;compression level (1..9)
strategy dw ? ;int ;favor or force Huffman coding
good_match dd ? ;uInt
; Use a faster search when the previous match is longer than this
nice_match dd ? ;int ;Stop searching when current match exceeds this
; used by trees.asm:
; Didn't use ct_data typedef below to suppress compiler warning
dyn_ltree rb sizeof.ct_data * HEAP_SIZE ;literal and length tree
dyn_dtree rb sizeof.ct_data * (2*D_CODES+1) ;distance tree
bl_tree rb sizeof.ct_data * (2*BL_CODES+1) ;Huffman tree for bit lengths
l_desc tree_desc ;desc. for literal tree
d_desc tree_desc ;desc. for distance tree
bl_desc tree_desc ;desc. for bit length tree
bl_count rw MAX_BITS+1 ;uint_16[]
; number of codes at each bit length for an optimal tree
heap rw 2*L_CODES+1 ;int[] ;heap used to build the Huffman trees
heap_len dd ? ;int ;number of elements in the heap
heap_max dd ? ;int ;element of largest frequency
; The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
; The same heap array is used to build all trees.
depth rb 2*L_CODES+1 ;uch[]
; Depth of each subtree used as tie breaker for trees of equal frequency
l_buf dd ? ;uchf * ;buffer for literals or lengths
lit_bufsize dd ? ;uInt
; Size of match buffer for literals/lengths. There are 4 reasons for
; limiting lit_bufsize to 64K:
; - frequencies can be kept in 16 bit counters
; - if compression is not successful for the first block, all input
; data is still in the window so we can still emit a stored block even
; when input comes from standard input. (This can also be done for
; all blocks if lit_bufsize is not greater than 32K.)
; - if compression is not successful for a file smaller than 64K, we can
; even emit a stored file instead of a stored block (saving 5 bytes).
; This is applicable only for zip (not gzip or zlib).
; - creating new Huffman trees less frequently may not provide fast
; adaptation to changes in the input data statistics. (Take for
; example a binary file with poorly compressible code followed by
; a highly compressible string table.) Smaller buffer sizes give
; fast adaptation but have of course the overhead of transmitting
; trees more frequently.
; - I can't count above 4
last_lit dd ? ;uInt ;running index in l_buf
d_buf dd ? ;uint_16p
; Buffer for distances. To simplify the code, d_buf and l_buf have
; the same number of elements. To use different lengths, an extra flag
; array would be necessary.
opt_len dd ? ;ulg ;bit length of current block with optimal trees
static_len dd ? ;ulg ;bit length of current block with static trees
matches dd ? ;uInt ;number of string matches in current block
insert dd ? ;uInt ;bytes at end of window left to insert
if DEBUG eq 1
compressed_len dd ? ;ulg ;total bit length of compressed file mod 2^32
bits_sent dd ? ;ulg ;bit length of compressed data sent mod 2^32
end if
bi_buf dw ? ;uint_16
; Output buffer. bits are inserted starting at the bottom (least
; significant bits).
bi_valid dd ? ;int
; Number of valid bits in bi_buf. All bits above the last valid bit
; are always zero.
high_water dd ? ;ulg
; High water mark offset in window for initialized bytes -- bytes above
; this are set to zero in order to avoid memory check warnings when
; longest match routines access bytes past the input. This is then
; updated to the new high water mark.
ends
; Output a byte on the stream.
; IN assertion: there is enough room in pending_buf.
macro put_byte s, c
{
;xor eax,eax
;mov al,c
;zlib_debug '(%d)',eax
movzx eax,word[s+deflate_state.pending]
add eax,[s+deflate_state.pending_buf]
mov byte[eax],c
inc word[s+deflate_state.pending]
}
macro put_dword s, d
{
;mov eax,d
;zlib_debug '(%d)',eax
movzx eax,word[s+deflate_state.pending]
add eax,[s+deflate_state.pending_buf]
mov dword[eax],d
add word[s+deflate_state.pending],4
}
MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1)
; Minimum amount of lookahead, except at the end of the input file.
; See deflate.asm for comments about the MIN_MATCH+1.
macro MAX_DIST s
{
mov eax,[s+deflate_state.w_size]
sub eax,MIN_LOOKAHEAD
}
; In order to simplify the code, particularly on 16 bit machines, match
; distances are limited to MAX_DIST instead of WSIZE.
WIN_INIT equ MAX_MATCH
; Number of bytes after end of data in window to initialize in order to avoid
; memory checker errors from longest match routines
macro d_code dist
{
;if (dist < 256) _dist_code[dist]
;else _dist_code[ 256+(dist>>7) ]
local .end0
mov eax,dist
cmp eax,256
jl .end0
shr eax,7
add eax,256
.end0:
movzx eax,byte[eax+_dist_code]
}
; Mapping from a distance to a distance code. dist is the distance - 1 and
; must not have side effects. _dist_code[256] and _dist_code[257] are never
; used.
macro _tr_tally_lit s, c, flush
{
local .end0
if DEBUG eq 0
; Inline versions of _tr_tally for speed:
if c eq eax
else
mov eax,c
end if
push ecx
mov ecx,[s+deflate_state.last_lit]
shl ecx,1
add ecx,[s+deflate_state.d_buf]
mov word[ecx],0
mov ecx,[s+deflate_state.last_lit]
add ecx,[s+deflate_state.l_buf]
mov byte[ecx],al
inc dword[s+deflate_state.last_lit]
and eax,0xff
imul eax,sizeof.ct_data
add eax,s
inc word[eax+deflate_state.dyn_ltree+Freq]
xor eax,eax
mov ecx,[s+deflate_state.lit_bufsize]
dec ecx
cmp [s+deflate_state.last_lit],ecx
jne .end0
inc eax ;flush = (..==..)
.end0:
mov flush, eax
pop ecx
else
stdcall _tr_tally, s, 0, c
mov flush, eax
end if
}
macro _tr_tally_dist s, distance, length, flush
{
if 0 ;;;DEBUG eq 0
push ecx
; uch len = (length)
if distance eq eax
else
mov eax,distance
end if
mov ecx,[s+deflate_state.last_lit]
shl ecx,1
add ecx,[s+deflate_state.d_buf]
mov word[ecx],ax
mov ecx,[s+deflate_state.last_lit]
add ecx,[s+deflate_state.l_buf]
mov byte[ecx],length
inc dword[s+deflate_state.last_lit]
dec eax
; s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++;
; s->dyn_dtree[d_code(dist)].Freq++;
; flush = (s->last_lit == s->lit_bufsize-1);
pop ecx
else
stdcall _tr_tally, s, distance, length
mov flush, eax
end if
}

View File

@ -0,0 +1,287 @@
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 ; äã­ªæ¨ï 12: á®®¡é¨âì Ž‘ ® ­ ç «¥ ®âà¨á®¢ª¨
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
mcall SF_DRAW_NUMBER, (1 shl 16)+1, strategy, <90,10>, 0
mcall , (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 ; äã­ªæ¨ï 12.2, § ª®­ç¨«¨ à¨á®¢ âì
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 word[eax+z_stream.avail_in],cx ;à §¬¥à ᦨ¬ ¥¬ë¦ ¤ ­­ëå
mov [eax+z_stream.next_out],m1 ;ãáâ ­ ¢«¨¢ ¥¬ ¡ãä¥à ¤«ï ᦠâ¨ï
mov word[eax+z_stream.avail_out],1024 ;à §¬¥à ¡ãä¥à  ¤«ï ᦠâ¨ï
;call print_z_struct
stdcall [deflate], my_strm, Z_FINISH ;Z_NO_FLUSH
;call print_z_struct
;à §¬¥à ᦠâëå ¤ ­­ëå: 1024-word[eax+z_stream.avail_out]
mov eax,my_strm
mov ecx,1024
sub cx,word[eax+z_stream.avail_out]
mov [m1size],ecx
;assert(ret != Z_STREAM_ERROR)
;while (strm.avail_out == 0)
mov ebx,[m1size]
mov esi,m1
mov edi,buf
mov edx,7
.cycle1: ;rows
mov ecx,32
.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
sc system_colors
title db 'Zlib test, press on [Up], [Down], [Left], [Right]',0
align 4
import_archiver:
deflate_unpack dd sz_deflate_unpack
dd 0,0
sz_deflate_unpack db 'deflate_unpack',0
align 4
import_zlib:
; dd sz_lib_init
deflateInit dd sz_deflateInit
deflateInit2 dd sz_deflateInit2
deflateReset dd sz_deflateReset
deflate dd sz_deflate
deflateEnd dd sz_deflateEnd
dd 0,0
; sz_lib_init db 'lib_init',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
;--------------------------------------------------
system_dir_0 db '/sys/lib/'
lib_name_0 db 'archiver.obj',0
system_dir_1 db '/sys/lib/'
lib_name_1 db 'zlib.obj',0
err_message_found_lib0 db 'Sorry I cannot load library archiver.obj',0
err_message_found_lib1 db 'Sorry I cannot load library zlib.obj',0
head_f_i:
head_f_l db 'System error',0
err_message_import0 db 'Error on load import library archiver.obj',0
err_message_import1 db 'Error on load import library zlib.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
lib1 l_libs lib_name_1, cur_dir_path, library_path, system_dir_1,\
err_message_found_lib1, head_f_l, import_zlib, err_message_import1, 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:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,139 @@
;ct_data[L_CODES+2]
align 4
static_ltree dw \
12, 8, 140, 8, 76, 8, 204, 8, 44, 8,\
172, 8, 108, 8, 236, 8, 28, 8, 156, 8,\
92, 8, 220, 8, 60, 8, 188, 8, 124, 8,\
252, 8, 2, 8, 130, 8, 66, 8, 194, 8,\
34, 8, 162, 8, 98, 8, 226, 8, 18, 8,\
146, 8, 82, 8, 210, 8, 50, 8, 178, 8,\
114, 8, 242, 8, 10, 8, 138, 8, 74, 8,\
202, 8, 42, 8, 170, 8, 106, 8, 234, 8,\
26, 8, 154, 8, 90, 8, 218, 8, 58, 8,\
186, 8, 122, 8, 250, 8, 6, 8, 134, 8,\
70, 8, 198, 8, 38, 8, 166, 8, 102, 8,\
230, 8, 22, 8, 150, 8, 86, 8, 214, 8,\
54, 8, 182, 8, 118, 8, 246, 8, 14, 8,\
142, 8, 78, 8, 206, 8, 46, 8, 174, 8,\
110, 8, 238, 8, 30, 8, 158, 8, 94, 8,\
222, 8, 62, 8, 190, 8, 126, 8, 254, 8,\
1, 8, 129, 8, 65, 8, 193, 8, 33, 8,\
161, 8, 97, 8, 225, 8, 17, 8, 145, 8,\
81, 8, 209, 8, 49, 8, 177, 8, 113, 8,\
241, 8, 9, 8, 137, 8, 73, 8, 201, 8,\
41, 8, 169, 8, 105, 8, 233, 8, 25, 8,\
153, 8, 89, 8, 217, 8, 57, 8, 185, 8,\
121, 8, 249, 8, 5, 8, 133, 8, 69, 8,\
197, 8, 37, 8, 165, 8, 101, 8, 229, 8,\
21, 8, 149, 8, 85, 8, 213, 8, 53, 8,\
181, 8, 117, 8, 245, 8, 13, 8, 141, 8,\
77, 8, 205, 8, 45, 8, 173, 8, 109, 8,\
237, 8, 29, 8, 157, 8, 93, 8, 221, 8,\
61, 8, 189, 8, 125, 8, 253, 8, 19, 9,\
275, 9, 147, 9, 403, 9, 83, 9, 339, 9,\
211, 9, 467, 9, 51, 9, 307, 9, 179, 9,\
435, 9, 115, 9, 371, 9, 243, 9, 499, 9,\
11, 9, 267, 9, 139, 9, 395, 9, 75, 9,\
331, 9, 203, 9, 459, 9, 43, 9, 299, 9,\
171, 9, 427, 9, 107, 9, 363, 9, 235, 9,\
491, 9, 27, 9, 283, 9, 155, 9, 411, 9,\
91, 9, 347, 9, 219, 9, 475, 9, 59, 9,\
315, 9, 187, 9, 443, 9, 123, 9, 379, 9,\
251, 9, 507, 9, 7, 9, 263, 9, 135, 9,\
391, 9, 71, 9, 327, 9, 199, 9, 455, 9,\
39, 9, 295, 9, 167, 9, 423, 9, 103, 9,\
359, 9, 231, 9, 487, 9, 23, 9, 279, 9,\
151, 9, 407, 9, 87, 9, 343, 9, 215, 9,\
471, 9, 55, 9, 311, 9, 183, 9, 439, 9,\
119, 9, 375, 9, 247, 9, 503, 9, 15, 9,\
271, 9, 143, 9, 399, 9, 79, 9, 335, 9,\
207, 9, 463, 9, 47, 9, 303, 9, 175, 9,\
431, 9, 111, 9, 367, 9, 239, 9, 495, 9,\
31, 9, 287, 9, 159, 9, 415, 9, 95, 9,\
351, 9, 223, 9, 479, 9, 63, 9, 319, 9,\
191, 9, 447, 9, 127, 9, 383, 9, 255, 9,\
511, 9, 0, 7, 64, 7, 32, 7, 96, 7,\
16, 7, 80, 7, 48, 7, 112, 7, 8, 7,\
72, 7, 40, 7, 104, 7, 24, 7, 88, 7,\
56, 7, 120, 7, 4, 7, 68, 7, 36, 7,\
100, 7, 20, 7, 84, 7, 52, 7, 116, 7,\
3, 8, 131, 8, 67, 8, 195, 8, 35, 8,\
163, 8, 99, 8, 227, 8
;ct_data[D_CODES]
align 4
static_dtree dw \
0, 5, 16, 5, 8, 5, 24, 5, 4, 5,\
20, 5, 12, 5, 28, 5, 2, 5, 18, 5,\
10, 5, 26, 5, 6, 5, 22, 5, 14, 5,\
30, 5, 1, 5, 17, 5, 9, 5, 25, 5,\
5, 5, 21, 5, 13, 5, 29, 5, 3, 5,\
19, 5, 11, 5, 27, 5, 7, 5, 23, 5
;uch[DIST_CODE_LEN]
align 4
_dist_code db \
0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,\
8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,\
10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,\
11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,\
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,\
13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,\
13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,\
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,\
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,\
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,\
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,\
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,\
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,\
18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,\
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,\
24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,\
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,\
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,\
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,\
27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\
28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,\
28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,\
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,\
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,\
29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
;uch[MAX_MATCH-MIN_MATCH+1]
align 4
_length_code db \
0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,\
13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,\
17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,\
19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,\
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,\
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,\
23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,\
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,\
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,\
25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,\
26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,\
26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,\
27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
;int[LENGTH_CODES]
align 4
base_length dd \
0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,\
64, 80, 96, 112, 128, 160, 192, 224, 0
;int[D_CODES]
align 4
base_dist dd \
0, 1, 2, 3, 4, 6, 8, 12, 16, 24,\
32, 48, 64, 96, 128, 192, 256, 384, 512, 768,\
1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576

View File

@ -0,0 +1,165 @@
; zconf.inc -- configuration of the zlib compression library
; Copyright (C) 1995-2013 Jean-loup Gailly.
; For conditions of distribution and use, see copyright notice in zlib.inc
; Compile with -DMAXSEG_64K if the alloc function cannot allocate more
; than 64k bytes at a time (needed on systems with 16-bit int).
;if MSDOS
;# define UNALIGNED_OK
;end if
; Maximum value for memLevel in deflateInit2
MAX_MEM_LEVEL equ 9
; Maximum value for windowBits in deflateInit2 and inflateInit2.
; WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
; created by gzip. (Files created by minigzip can still be extracted by
; gzip.)
MAX_WBITS equ 15 ;32K LZ77 window
; The memory requirements for deflate are (in bytes):
; (1 << (windowBits+2)) + (1 << (memLevel+9))
; that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
; plus a few kilobytes for small objects. For example, if you want to reduce
; the default memory requirements from 256K to 128K, compile with
; make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
; Of course this will generally degrade compression (there's no free lunch).
; The memory requirements for inflate are (in bytes) 1 << windowBits
; that is, 32K for windowBits=15 (default value) plus a few kilobytes
; for small objects.
; /* Type declarations */
;#ifndef OF /* function prototypes */
;# ifdef STDC
;# define OF(args) args
;# else
;# define OF(args) ()
;# endif
;end if
;#ifndef Z_ARG /* function prototypes for stdarg */
;# if defined(STDC) || defined(Z_HAVE_STDARG_H)
;# define Z_ARG(args) args
;# else
;# define Z_ARG(args) ()
;# endif
;end if
; The following definitions for FAR are needed only for MSDOS mixed
; model programming (small or medium model with some far allocations).
; This was tested only with MSC; for other MSDOS compilers you may have
; to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
; just define FAR to be empty.
;#if defined(WINDOWS) || defined(WIN32)
; If building or using zlib as a DLL, define ZLIB_DLL.
; This is not mandatory, but it offers a little performance increase.
;# ifdef ZLIB_DLL
;# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
;# ifdef ZLIB_INTERNAL
;# define ZEXTERN extern __declspec(dllexport)
;# else
;# define ZEXTERN extern __declspec(dllimport)
;# endif
;# endif
;# endif /* ZLIB_DLL */
; If building or using zlib with the WINAPI/WINAPIV calling convention,
; define ZLIB_WINAPI.
; Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
;#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
;# include <limits.h>
;# if (UINT_MAX == 0xffffffffUL)
;# define Z_U4 unsigned
;# elif (ULONG_MAX == 0xffffffffUL)
;# define Z_U4 unsigned long
;# elif (USHRT_MAX == 0xffffffffUL)
;# define Z_U4 unsigned short
;# endif
;end if
;if Z_U4
; typedef Z_U4 z_crc_t;
;else
; typedef unsigned long z_crc_t;
;end if
;if HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
;# define Z_HAVE_UNISTD_H
;end if
;if HAVE_STDARG_H /* may be set to #if 1 by ./configure */
;# define Z_HAVE_STDARG_H
;end if
;if STDC
;# ifndef Z_SOLO
;# include <sys/types.h> /* for off_t */
;# endif
;end if
;#if defined(STDC) || defined(Z_HAVE_STDARG_H)
;# ifndef Z_SOLO
;# include <stdarg.h> /* for va_list */
;# endif
;end if
; a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
; "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
; though the former does not conform to the LFS document), but considering
; both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
; equivalently requesting no 64-bit operations
;#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
;# undef _LARGEFILE64_SOURCE
;end if
;#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
;# define Z_HAVE_UNISTD_H
;end if
;#ifndef Z_SOLO
;# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE)
;# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
;# ifdef VMS
;# include <unixio.h> /* for off_t */
;# endif
;# ifndef z_off_t
;# define z_off_t off_t
;# endif
;# endif
;end if
;#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
;# define Z_LFS64
;end if
;#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
;# define Z_LARGE64
;end if
;#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
;# define Z_WANT64
;end if
;#if !defined(SEEK_SET) && !defined(Z_SOLO)
;# define SEEK_SET 0 /* Seek from beginning of file. */
;# define SEEK_CUR 1 /* Seek from current position. */
;# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
;end if
;# define z_off_t long
;#if !defined(_WIN32) && defined(Z_LARGE64)
;# define z_off64_t off64_t
;else
;# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
;# define z_off64_t __int64
;# else
;# define z_off64_t z_off_t
;# endif
;end if

View File

@ -0,0 +1,179 @@
format MS COFF
public EXPORTS
section '.flat' code readable align 16
include '../../../../proc32.inc'
include '../../../../macros.inc'
include '../../../../KOSfuncs.inc'
FASTEST equ 1
GEN_TREES_H equ 0
DEBUG equ 0
DYNAMIC_CRC_TABLE equ 1
; define NO_GZIP when compiling if you want to disable gzip header and
; trailer creation by deflate(). NO_GZIP would be used to avoid linking in
; the crc code when it is not needed. For shared libraries, gzip encoding
; should be left enabled.
GZIP equ 1
macro zlib_debug fmt,p1
{
local .end_t
local .m_fmt
jmp .end_t
.m_fmt db fmt,13,10,0
align 4
.end_t:
if p1 eq
stdcall dbg_print,0,.m_fmt
else
stdcall str_format_dbg, buf_param,.m_fmt,p1
end if
}
include 'zlib.inc'
include 'deflate.inc'
include 'zutil.asm'
include 'crc32.asm'
include 'adler32.asm'
include 'trees.asm'
include 'deflate.asm'
align 4
buf_param rb 80
align 4
proc dbg_print, fun:dword, mes:dword
pushad
mov eax,SF_BOARD
mov ebx,SSF_DEBUG_WRITE
mov esi,[fun]
cmp esi,0
je .end0
@@:
mov cl,byte[esi]
int 0x40
inc esi
cmp byte[esi],0
jne @b
mov cl,':'
int 0x40
mov cl,' '
int 0x40
.end0:
mov esi,[mes]
cmp esi,0
je .end_f
@@:
mov cl,byte[esi]
cmp cl,0
je .end_f
int 0x40
inc esi
jmp @b
.end_f:
popad
ret
endp
align 4
proc str_format_dbg, buf:dword, fmt:dword, p1:dword
pushad
mov esi,[fmt]
mov edi,[buf]
mov ecx,80-1
.cycle0:
lodsb
cmp al,'%'
jne .no_param
lodsb
dec ecx
cmp al,0
je .cycle0end
cmp al,'d'
je @f
cmp al,'u'
je @f
cmp al,'l'
je .end1
jmp .end0
.end1: ;%lu %lx
lodsb
dec ecx
cmp al,'u'
jne .end0
@@:
mov eax,[p1]
stdcall convert_int_to_str,ecx
xor al,al
repne scasb
dec edi
.end0:
loop .cycle0
.no_param:
stosb
cmp al,0
je .cycle0end
loop .cycle0
.cycle0end:
xor al,al
stosb
stdcall dbg_print,0,[buf]
popad
ret
endp
;input:
; eax - число
; edi - буфер для строки
; len - длинна буфера
;output:
align 4
proc convert_int_to_str, len:dword
pushad
mov esi,[len]
add esi,edi
dec esi
call .str
popad
ret
endp
align 4
.str:
mov ecx,0x0a
cmp eax,ecx
jb @f
xor edx,edx
div ecx
push edx
call .str
pop eax
@@:
cmp edi,esi
jge @f
or al,0x30
stosb
mov byte[edi],0
@@:
ret
; export table
align 4
EXPORTS:
dd adeflateInit, deflateInit
dd adeflateInit2, deflateInit2
dd adeflateReset, deflateReset
dd adeflate, deflate
dd adeflateEnd, deflateEnd
dd 0
; exported names
adeflateInit db 'deflateInit',0
adeflateInit2 db 'deflateInit2',0
adeflateReset db 'deflateReset',0
adeflate db 'deflate',0
adeflateEnd db 'deflateEnd',0

View File

@ -0,0 +1,262 @@
; zlib.inc -- interface of the 'zlib' general purpose compression library
; version 1.2.8, April 28th, 2013
; Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions:
; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source distribution.
; Jean-loup Gailly Mark Adler
; jloup@gzip.org madler@alumni.caltech.edu
; The data format used by the zlib library is described by RFCs (Request for
; Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
; (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
include 'zconf.inc'
align 4
ZLIB_VERSION db '1.2.8',0
ZLIB_VERNUM equ 0x1280
ZLIB_VER_MAJOR equ 1
ZLIB_VER_MINOR equ 2
ZLIB_VER_REVISION equ 8
ZLIB_VER_SUBREVISION equ 0
; The 'zlib' compression library provides in-memory compression and
; decompression functions, including integrity checks of the uncompressed data.
; This version of the library supports only one compression method (deflation)
; but other algorithms will be added later and will have the same stream
; interface.
; Compression can be done in a single step if the buffers are large enough,
; or can be done by repeated calls of the compression function. In the latter
; case, the application must provide more input and/or consume the output
; (providing more output space) before each call.
; The compressed data format used by default by the in-memory functions is
; the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
; around a deflate stream, which is itself documented in RFC 1951.
; The library also supports reading and writing files in gzip (.gz) format
; with an interface similar to that of stdio using the functions that start
; with "gz". The gzip format is different from the zlib format. gzip is a
; gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
; This library can optionally read and write gzip streams in memory as well.
; The zlib format was designed to be compact and fast for use in memory
; and on communications channels. The gzip format was designed for single-
; file compression on file systems, has a larger header than zlib to maintain
; directory information, and uses a different, slower check method than zlib.
; The library does not install any signal handler. The decoder checks
; the consistency of the compressed data, so the library should never crash
; even in case of corrupted input.
struct z_stream ;z_stream_s
next_in dd ? ;z_const Bytef * ;next input byte
avail_in dw ? ;uInt ;number of bytes available at next_in
total_in dd ? ;uLong ;total number of input bytes read so far
next_out dd ? ;Bytef * ;next output byte should be put there
avail_out dw ? ;uInt ;remaining free space at next_out
total_out dd ? ;uLong ;total number of bytes output so far
msg dd ? ;z_const char * ;last error message, NULL if no error
state dd ? ;deflate_state* ;not visible by applications
zalloc dd ? ;alloc_func ;used to allocate the internal state
zfree dd ? ;free_func ;used to free the internal state
opaque dd ? ;voidpf ;private data object passed to zalloc and zfree
data_type dw ? ;int ;best guess about the data type: binary or text
adler dd ? ;uLong ;adler32 value of the uncompressed data
reserved dd ? ;uLong ;reserved for future use
ends
; gzip header information passed to and from zlib routines. See RFC 1952
; for more details on the meanings of these fields.
struct gz_header ;_s
text dd ? ;int ;true if compressed data believed to be text
time dd ? ;uLong ;modification time
xflags dd ? ;int ;extra flags (not used when writing a gzip file)
os dd ? ;int ;operating system
extra dd ? ;Bytef* ;pointer to extra field or Z_NULL if none
extra_len dd ? ;uInt ;extra field length (valid if extra != Z_NULL)
extra_max dd ? ;uInt ;space at extra (only when reading header)
name dd ? ;Bytef* ;pointer to zero-terminated file name or Z_NULL
name_max dd ? ;uInt ;space at name (only when reading header)
comment dd ? ;Bytef* ;pointer to zero-terminated comment or Z_NULL
comm_max dd ? ;uInt ;space at comment (only when reading header)
hcrc dd ? ;int ;true if there was or will be a header crc
done dd ? ;int ;true when done reading gzip header (not used
;when writing a gzip file)
ends
; The application must update next_in and avail_in when avail_in has dropped
; to zero. It must update next_out and avail_out when avail_out has dropped
; to zero. The application must initialize zalloc, zfree and opaque before
; calling the init function. All other fields are set by the compression
; library and must not be updated by the application.
; The opaque value provided by the application will be passed as the first
; parameter for calls of zalloc and zfree. This can be useful for custom
; memory management. The compression library attaches no meaning to the
; opaque value.
; zalloc must return Z_NULL if there is not enough memory for the object.
; If zlib is used in a multi-threaded application, zalloc and zfree must be
; thread safe.
; On 16-bit systems, the functions zalloc and zfree must be able to allocate
; exactly 65536 bytes, but will not be required to allocate more than this if
; the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
; returned by zalloc for objects of exactly 65536 bytes *must* have their
; offset normalized to zero. The default allocation function provided by this
; library ensures this (see zutil.c). To reduce memory requirements and avoid
; any allocation of 64K objects, at the expense of compression ratio, compile
; the library with -DMAX_WBITS=14 (see zconf.h).
; The fields total_in and total_out can be used for statistics or progress
; reports. After compression, total_in holds the total size of the
; uncompressed data and may be saved for use in the decompressor (particularly
; if the decompressor wants to decompress everything in a single step).
; constants
Z_NO_FLUSH equ 0
Z_PARTIAL_FLUSH equ 1
Z_SYNC_FLUSH equ 2
Z_FULL_FLUSH equ 3
Z_FINISH equ 4
Z_BLOCK equ 5
Z_TREES equ 6
; Allowed flush values; see deflate() and inflate() below for details
Z_OK equ 0
Z_STREAM_END equ 1
Z_NEED_DICT equ 2
Z_ERRNO equ (-1)
Z_STREAM_ERROR equ (-2)
Z_DATA_ERROR equ (-3)
Z_MEM_ERROR equ (-4)
Z_BUF_ERROR equ (-5)
Z_VERSION_ERROR equ (-6)
; Return codes for the compression/decompression functions. Negative values
; are errors, positive values are used for special but normal events.
Z_NO_COMPRESSION equ 0
Z_BEST_SPEED equ 1
Z_BEST_COMPRESSION equ 9
Z_DEFAULT_COMPRESSION equ (-1)
; compression levels
Z_FILTERED equ 1
Z_HUFFMAN_ONLY equ 2
Z_RLE equ 3
Z_FIXED equ 4
Z_DEFAULT_STRATEGY equ 0
; compression strategy; see deflateInit2() below for details
Z_BINARY equ 0
Z_TEXT equ 1
Z_ASCII equ Z_TEXT ;for compatibility with 1.2.2 and earlier
Z_UNKNOWN equ 2
; Possible values of the data_type field (though see inflate())
Z_DEFLATED equ 8
; The deflate compression method (the only one supported in this version)
Z_NULL equ 0 ;for initializing zalloc, zfree, opaque
zlib_version equ zlibVersion
; for compatibility with versions < 1.0.2
; various hacks, don't look :)
; deflateInit and inflateInit are macros to allow checking the zlib version
; and the compiler's view of z_stream:
;int inflateBackInit_ OF((z_streamp strm, int windowBits,
; unsigned char FAR *window,
; const char *version,
; int stream_size));
;#define inflateInit(strm) \
; inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
;#define inflateInit2(strm, windowBits) \
; inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
; (int)sizeof(z_stream))
;#define inflateBackInit(strm, windowBits, window) \
; inflateBackInit_((strm), (windowBits), (window), \
; ZLIB_VERSION, (int)sizeof(z_stream))
;#ifndef Z_SOLO
; gzgetc() macro and its supporting function and exposed data structure. Note
; that the real internal state is much larger than the exposed structure.
; This abbreviated structure exposes just enough for the gzgetc() macro. The
; user should not mess with these exposed elements, since their names or
; behavior could change in the future, perhaps even capriciously. They can
; only be used by the gzgetc() macro. You have been warned.
;struct gzFile_s {
; unsigned have;
; unsigned char *next;
; z_off64_t pos;
;};
;int gzgetc_ OF((gzFile file)); /* backward compatibility */
;if Z_PREFIX_SET
;# undef z_gzgetc
;# define z_gzgetc(g) \
; ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
;#else
;# define gzgetc(g) \
; ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
;end if
; provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
; change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
; both are true, the application gets the *64 functions, and the regular
; functions are changed to 64 bits) -- in case these are set on systems
; without large file support, _LFS64_LARGEFILE must also be true
; undocumented functions
;const char * zError OF((int));
;int inflateSyncPoint OF((z_streamp));
;const z_crc_t FAR * get_crc_table OF((void));
;int inflateUndermine OF((z_streamp, int));
;int inflateResetKeep OF((z_streamp));
;#if defined(_WIN32) && !defined(Z_SOLO)
;gzFile gzopen_w OF((const wchar_t *path,
; const char *mode));
;end if
;#if defined(STDC) || defined(Z_HAVE_STDARG_H)
;# ifndef Z_SOLO
;int ZEXPORTVA gzvprintf Z_ARG((gzFile file,
; const char *format,
; va_list va));
;# endif
;end if

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,203 @@
; zutil.asm -- target dependent utility functions for the compression library
; Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly.
; For conditions of distribution and use, see copyright notice in zlib.inc
align 4
z_errmsg dd ze0,ze1,ze2,ze3,ze4,ze5,ze6,ze7,ze8,ze9
ze0 db 'need dictionary',0 ;Z_NEED_DICT 2
ze1 db 'stream end',0 ;Z_STREAM_END 1
ze2 db '',0 ;Z_OK 0
ze3 db 'file error',0 ;Z_ERRNO (-1)
ze4 db 'stream error',0 ;Z_STREAM_ERROR (-2)
ze5 db 'data error',0 ;Z_DATA_ERROR (-3)
ze6 db 'insufficient memory',0 ;Z_MEM_ERROR (-4)
ze7 db 'buffer error',0 ;Z_BUF_ERROR (-5)
ze8 db 'incompatible version',0 ;Z_VERSION_ERROR (-6)
ze9 db '',0
;const char * ()
align 4
proc zlibVersion
mov eax,ZLIB_VERSION;
ret
endp
;uLong ()
align 4
proc zlibCompileFlags
; uLong flags;
; flags = 0;
; switch ((int)(sizeof(uInt))) {
; case 2: break;
; case 4: flags += 1; break;
; case 8: flags += 2; break;
; default: flags += 3;
; }
; switch ((int)(sizeof(uLong))) {
; case 2: break;
; case 4: flags += 1 << 2; break;
; case 8: flags += 2 << 2; break;
; default: flags += 3 << 2;
; }
; switch ((int)(sizeof(voidpf))) {
; case 2: break;
; case 4: flags += 1 << 4; break;
; case 8: flags += 2 << 4; break;
; default: flags += 3 << 4;
; }
; switch ((int)(sizeof(z_off_t))) {
; case 2: break;
; case 4: flags += 1 << 6; break;
; case 8: flags += 2 << 6; break;
; default: flags += 3 << 6;
; }
;if DEBUG
; flags += 1 << 8;
;end if
;#if defined(ASMV) || defined(ASMINF)
; flags += 1 << 9;
;end if
if ZLIB_WINAPI eq 1
; flags += 1 << 10;
end if
if BUILDFIXED eq 1
; flags += 1 << 12;
end if
if DYNAMIC_CRC_TABLE eq 1
; flags += 1 << 13;
end if
if NO_GZCOMPRESS eq 1
; flags += 1L << 16;
end if
if NO_GZIP eq 1
; flags += 1L << 17;
end if
if PKZIP_BUG_WORKAROUND eq 1
; flags += 1L << 20;
end if
if FASTEST eq 1
; flags += 1L << 21;
end if
;#if defined(STDC) || defined(Z_HAVE_STDARG_H)
;# ifdef NO_vsnprintf
; flags += 1L << 25;
;# ifdef HAS_vsprintf_void
; flags += 1L << 26;
;# endif
;# else
;# ifdef HAS_vsnprintf_void
; flags += 1L << 26;
;# endif
;# endif
;#else
; flags += 1L << 24;
;# ifdef NO_snprintf
; flags += 1L << 25;
;# ifdef HAS_sprintf_void
; flags += 1L << 26;
;# endif
;# else
;# ifdef HAS_snprintf_void
; flags += 1L << 26;
;# endif
;# endif
;end if
; return flags;
ret
endp
;if DEBUG
;# define verbose 0
;int z_verbose = verbose;
;void (m)
; char *m;
align 4
proc z_error, m:dword
; fprintf(stderr, "%s\n", m);
; exit(1);
ret
endp
;end if
; exported to allow conversion of error code to string for compress() and
; uncompress()
;const char * (err)
; int err;
align 4
proc zError, err:dword
; return ERR_MSG(err);
ret
endp
;#ifndef HAVE_MEMCPY
;void (dest, source, len)
; Bytef* dest;
; const Bytef* source;
; uInt len;
align 4
proc zmemcpy uses ecx edi esi, dest:dword, source:dword, len:dword
mov ecx,[len]
cmp ecx,0
jle @f
mov edi,[dest]
mov esi,[source]
rep movsb
jmp .end0
@@:
zlib_debug 'zmemcpy size = %d',ecx
.end0:
ret
endp
;int (s1, s2, len)
; const Bytef* s1;
; const Bytef* s2;
; uInt len;
align 4
proc zmemcmp, s1:dword, s2:dword, len:dword
; uInt j;
; for (j = 0; j < len; j++) {
; if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
; }
; return 0;
ret
endp
;void (dest, len)
; Bytef* dest;
; uInt len;
align 4
proc zmemzero, dest:dword, len:dword
; if (len == 0) return;
; do {
; *dest++ = 0; /* ??? to be unrolled */
; } while (--len != 0);
ret
endp
;end if
;#ifndef Z_SOLO
;voidpf (voidpf opaque, unsigned items, unsigned size)
align 4
proc zcalloc uses ebx ecx, opaque:dword, items:dword, size:dword
mov ecx,[size]
imul ecx,[items]
mcall SF_SYS_MISC, SSF_MEM_ALLOC
ret
endp
;void (voidpf opaque, voidpf ptr)
align 4
proc zcfree uses eax ebx ecx, opaque:dword, p2ptr:dword
mcall SF_SYS_MISC, SSF_MEM_FREE, [p2ptr]
ret
endp
;end if /* !Z_SOLO */

View File

@ -0,0 +1,88 @@
; zutil.inc -- internal interface and configuration of the compression library
; Copyright (C) 1995-2013 Jean-loup Gailly.
; For conditions of distribution and use, see copyright notice in zlib.inc
; WARNING: this file should *not* be used by applications. It is
; part of the implementation of the compression library and is
; subject to change. Applications should only use zlib.inc.
macro ERR_MSG err
{
mov ecx,Z_NEED_DICT-err
mov ecx,[4*ecx+z_errmsg]
}
macro ERR_RETURN strm,err
{
ERR_MSG err
mov [strm+z_stream.msg],ecx
mov eax,err
}
; To be used only when the state is known to be valid
; /* common constants */
;#ifndef DEF_WBITS
;# define DEF_WBITS MAX_WBITS
;end if
; default windowBits for decompression. MAX_WBITS is for compression only
;#if MAX_MEM_LEVEL >= 8
DEF_MEM_LEVEL equ 8
;#else
;# define DEF_MEM_LEVEL MAX_MEM_LEVEL
;end if
; default memLevel
STORED_BLOCK equ 0
STATIC_TREES equ 1
DYN_TREES equ 2
; The three kinds of block type
MIN_MATCH equ 3
MAX_MATCH equ 258
; The minimum and maximum match lengths
PRESET_DICT equ 0x20 ;preset dictionary flag in zlib header
; /* common defaults */
OS_CODE equ 0x03 ;assume Unix
; /* functions */
; Diagnostic functions
;if DEBUG eq 1
;# define Trace(x) {if (z_verbose>=0) fprintf x ;}
;# define Tracev(x) {if (z_verbose>0) fprintf x ;}
macro Tracevv mes1, mes2
{
;zlib_debug 'Tracevv = %d', mes1
}
;# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
;# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
;end if
macro ZALLOC strm, items, size
{
stdcall dword[strm+z_stream.zalloc], [strm+z_stream.opaque], items, size
}
macro ZFREE strm, p2addr
{
stdcall dword[strm+z_stream.zfree], dword[strm+z_stream.opaque], p2addr
}
macro TRY_FREE s, p
{
local .end0
cmp p,0
je .end0
ZFREE s, p
.end0:
}
; Reverse the bytes in a 32-bit value
macro ZSWAP32 q
{
bswap q
}