some fixes and optimize

git-svn-id: svn://kolibrios.org@6639 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2016-10-31 09:19:36 +00:00
parent 33fb425969
commit 830c466a98
10 changed files with 190 additions and 389 deletions

View File

@ -94,31 +94,11 @@ if DYNAMIC_CRC_TABLE eq 1
je @f ;if (..)
call make_crc_table
@@:
end if ;DYNAMIC_CRC_TABLE
end if
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
@ -140,26 +120,8 @@ if DYNAMIC_CRC_TABLE eq 1
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
call crc
.end_f:
ret
endp

View File

@ -198,10 +198,10 @@ endp
; =========================================================================
;int (strm, level, version, stream_size)
; z_streamp strm;
; int level;
; const char *version;
; int stream_size;
; z_streamp strm
; int level
; const char *version
; int stream_size
align 4
proc deflateInit_, strm:dword, level:dword, version:dword, stream_size:dword
stdcall deflateInit2_, [strm], [level], Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,\
@ -220,14 +220,14 @@ endp
; =========================================================================
;int (strm, level, method, windowBits, memLevel, strategy,
; version, stream_size)
; z_streamp strm;
; int level;
; int method;
; int windowBits;
; int memLevel;
; int strategy;
; const char *version;
; int stream_size;
; z_streamp strm
; int level
; int method
; int windowBits
; int memLevel
; int strategy
; const char *version
; int stream_size
align 4
proc deflateInit2_ uses ebx ecx edx edi, strm:dword, level:dword, method:dword,\
windowBits:dword, memLevel:dword, strategy:dword, version:dword, stream_size:dword
@ -433,9 +433,9 @@ endp
; =========================================================================
;int (strm, dictionary, dictLength)
; z_streamp strm;
; const Bytef *dictionary;
; uInt dictLength;
; z_streamp strm
; const Bytef *dictionary
; uInt dictLength
align 4
proc deflateSetDictionary uses ebx edi, strm:dword, dictionary:dword, dictLength:dword
locals
@ -518,7 +518,7 @@ endp
; =========================================================================
;int (strm)
; z_streamp strm;
; z_streamp strm
align 4
proc deflateResetKeep uses ebx edi, strm:dword
; deflate_state *s;
@ -563,7 +563,7 @@ proc deflateResetKeep uses ebx edi, strm:dword
if GZIP eq 1
cmp dword[edi+deflate_state.wrap],2
jne @f
stdcall calc_crc32, 0, Z_NULL, 0
xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
@@:
end if
mov dword[ebx+z_stream.adler],eax
@ -578,11 +578,11 @@ endp
; =========================================================================
;int (strm)
; z_streamp strm;
; z_streamp strm
align 4
proc deflateReset uses ebx, strm:dword
mov ebx,[strm]
;zlib_debug 'deflateReset'
zlib_debug 'deflateReset'
stdcall deflateResetKeep, ebx
cmp eax,0
jne @f ;if (..==Z_OK)
@ -593,8 +593,8 @@ endp
; =========================================================================
;int (strm, head)
; z_streamp strm;
; gz_headerp head;
; z_streamp strm
; gz_headerp head
align 4
proc deflateSetHeader uses ebx, strm:dword, head:dword
mov ebx,[strm]
@ -621,9 +621,9 @@ endp
; =========================================================================
;int (strm, pending, bits)
; unsigned *pending;
; int *bits;
; z_streamp strm;
; unsigned *pending
; int *bits
; z_streamp strm
align 4
proc deflatePending uses ebx edi, strm:dword, pending:dword, bits:dword
mov ebx,[strm]
@ -655,9 +655,9 @@ endp
; =========================================================================
;int (strm, bits, value)
; z_streamp strm;
; int bits;
; int value;
; z_streamp strm
; int bits
; int value
align 4
proc deflatePrime uses ebx edi, strm:dword, bits:dword, value:dword
; int put;
@ -691,9 +691,9 @@ endp
; =========================================================================
;int (strm, level, strategy)
; z_streamp strm;
; int level;
; int strategy;
; z_streamp strm
; int level
; int strategy
align 4
proc deflateParams uses ebx edi, strm:dword, level:dword, strategy:dword
; compress_func func;
@ -748,11 +748,11 @@ endp
; =========================================================================
;int (strm, good_length, max_lazy, nice_length, max_chain)
; z_streamp strm;
; int good_length;
; int max_lazy;
; int nice_length;
; int max_chain;
; z_streamp strm
; int good_length
; int max_lazy
; int nice_length
; int max_chain
align 4
proc deflateTune uses ebx, strm:dword, good_length:dword, max_lazy:dword,\
nice_length:dword, max_chain:dword
@ -797,14 +797,14 @@ endp
; allocation.
;uLong (strm, sourceLen)
; z_streamp strm;
; uLong sourceLen;
; z_streamp strm
; uLong sourceLen
align 4
proc deflateBound, strm:dword, sourceLen:dword
; deflate_state *s;
; uLong complen, wraplen;
; Bytef *str;
;zlib_debug 'deflateBound'
zlib_debug 'deflateBound'
; conservative upper bound for compressed data
; complen = sourceLen +
@ -863,8 +863,8 @@ endp
; pending_buf.
;void (s, b)
; deflate_state *s;
; uInt b;
; deflate_state *s
; uInt b
align 4
proc putShortMSB uses ebx ecx, s:dword, b:dword
mov ebx,[s]
@ -881,13 +881,13 @@ endp
; (See also read_buf()).
;void (strm)
; z_streamp strm;
; z_streamp strm
align 4
proc flush_pending uses eax ebx ecx edx, strm:dword
;ecx - len
;edx - deflate_state *s
;ebx - strm
;zlib_debug 'flush_pending'
zlib_debug 'flush_pending'
mov ebx,[strm]
mov edx,[ebx+z_stream.state]
@ -916,8 +916,8 @@ endp
; =========================================================================
;int (strm, flush)
; z_streamp strm;
; int flush;
; z_streamp strm
; int flush
align 4
proc deflate uses ebx ecx edx edi esi, strm:dword, flush:dword
locals
@ -973,7 +973,7 @@ zlib_debug 'deflate strm = %d',ebx
if GZIP eq 1
cmp dword[edi+deflate_state.wrap],2
jne .end1 ;if (..==..)
stdcall calc_crc32, 0, Z_NULL, 0
xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
mov [ebx+z_stream.adler],eax
put_byte edi, 31
put_byte edi, 139
@ -1107,7 +1107,7 @@ end if
bswap ecx
put_dword edi, ecx
@@:
stdcall calc_crc32, 0, Z_NULL, 0
xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
mov [ebx+z_stream.adler],eax
.end2:
if GZIP eq 1
@ -1307,7 +1307,7 @@ if GZIP eq 1
mov ecx,[ebx+z_stream.adler]
put_byte edi, cl
put_byte edi, ch
stdcall calc_crc32, 0, Z_NULL, 0
xor eax,eax ;stdcall calc_crc32, 0, Z_NULL, 0
mov [ebx+z_stream.adler],eax
mov dword[edi+deflate_state.status],BUSY_STATE
@@:
@ -1447,7 +1447,7 @@ end if
.end11:
cmp word[ebx+z_stream.avail_out],0
jg @f
zlib_debug 'bug2' ;Assert(..>0)
zlib_assert 'bug2' ;Assert(..>0)
@@:
cmp dword[flush],Z_FINISH
@ -1496,7 +1496,7 @@ endp
; =========================================================================
;int (strm)
; z_streamp strm;
; z_streamp strm
align 4
proc deflateEnd uses ebx ecx edx, strm:dword
mov ebx,[strm]
@ -1553,15 +1553,13 @@ endp
; doesn't have enough memory anyway to duplicate compression states).
;int (dest, source)
; z_streamp dest;
; z_streamp source;
; z_streamp dest
; z_streamp source
align 4
proc deflateCopy uses edx edi esi, dest:dword, source:dword
locals
overlay dd ? ;uint_16p
endl
;edi = ds; deflate_state*
;esi = ss; deflate_state*
proc deflateCopy uses ebx edx edi esi, dest:dword, source:dword
;ebx = overlay ;uint_16p
;edi = ds ;deflate_state*
;esi = ss ;deflate_state*
mov esi,[source]
cmp esi,Z_NULL
@ -1597,7 +1595,7 @@ endl
ZALLOC edx, [edi+deflate_state.hash_size], 4 ;sizeof.dd
mov dword[edi+deflate_state.head],eax
ZALLOC edx, [edi+deflate_state.lit_bufsize], 4 ;sizeof.dw+2
mov [overlay],eax
mov ebx,eax
mov dword[edi+deflate_state.pending_buf],eax
cmp dword[edi+deflate_state.window],Z_NULL
@ -1618,13 +1616,26 @@ endl
mov eax,[edi+deflate_state.w_size]
shl eax,1 ;*= 2*sizeof.db
stdcall zmemcpy, [edi+deflate_state.window], [esi+deflate_state.window], eax
; zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos));
; zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos));
; zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
mov eax,[edi+deflate_state.w_size]
shl eax,2 ;*= sizeof.dd
stdcall zmemcpy, [edi+deflate_state.prev], [esi+deflate_state.prev], eax
mov eax,[edi+deflate_state.hash_size]
shl eax,2 ;*= sizeof.dd
stdcall zmemcpy, [edi+deflate_state.head], [esi+deflate_state.head], eax
stdcall zmemcpy, [edi+deflate_state.pending_buf], [esi+deflate_state.pending_buf], [edi+deflate_state.pending_buf_size]
; ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
; ds->d_buf = overlay + ds->lit_bufsize/sizeof(uint_16);
; ds->l_buf = ds->pending_buf + (1+sizeof(uint_16))*ds->lit_bufsize;
mov eax,[edi+deflate_state.pending_buf]
add eax,[esi+deflate_state.pending_out]
sub eax,[esi+deflate_state.pending_buf]
mov [edi+deflate_state.pending_out],eax
mov eax,[edi+deflate_state.lit_bufsize]
shr eax,1 ;/=sizeof.uint_16
add eax,ebx
mov [edi+deflate_state.d_buf],eax
mov eax,[edi+deflate_state.lit_bufsize]
imul eax,3 ;*=1+sizeof.uint_16
add eax,[edi+deflate_state.pending_buf]
mov [edi+deflate_state.l_buf],eax
mov eax,edi
add eax,deflate_state.dyn_ltree
@ -1647,9 +1658,9 @@ endp
; (See also flush_pending()).
;int (strm, buf, size)
; z_streamp strm;
; Bytef *buf;
; unsigned size;
; z_streamp strm
; Bytef *buf
; unsigned size
align 4
proc read_buf uses ebx ecx, strm:dword, buf:dword, size:dword
mov ebx,[strm]
@ -1739,8 +1750,8 @@ end if
endp
;uInt (s, cur_match)
; deflate_state *s;
; IPos cur_match; /* current match */
; deflate_state *s
; IPos cur_match ;current match
align 4
proc longest_match uses ebx ecx edx edi esi, s:dword, cur_match:dword
if FASTEST eq 0
@ -1771,18 +1782,9 @@ if FASTEST eq 0
; Posf *prev = s->prev;
; uInt wmask = s->w_mask;
if UNALIGNED_OK eq 1
; Compare two bytes at a time. Note: this is not always beneficial.
; Try with and without -DUNALIGNED_OK to check.
; register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
; register uint_16 scan_start = *(uint_16p*)scan;
; register uint_16 scan_end = *(uint_16p*)(scan+best_len-1);
else
; register Bytef *strend = s->window + s->strstart + MAX_MATCH;
; register Byte scan_end1 = scan[best_len-1];
; register Byte scan_end = scan[best_len];
end if
; The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
; It is easy to get rid of this optimization if necessary.
@ -1812,41 +1814,6 @@ end if
; However the length of the match is limited to the lookahead, so
; the output of deflate is not affected by the uninitialized values.
if ((UNALIGNED_OK eq 1) & MAX_MATCH == 258)
; This code assumes sizeof(unsigned short) == 2. Do not use
; UNALIGNED_OK if your compiler uses a different size.
; if (*(uint_16p*)(match+best_len-1) != scan_end ||
; *(uint_16p*)match != scan_start) continue;
; It is not necessary to compare scan[2] and match[2] since they are
; always equal when the other bytes match, given that the hash keys
; are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
; strstart+3, +5, ... up to strstart+257. We check for insufficient
; lookahead only every 4th comparison; the 128th check will be made
; at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
; necessary to put more guard bytes at the end of the window, or
; to check more often for insufficient lookahead.
; Assert(scan[2] == match[2], "scan[2]?");
; scan++, match++;
; do {
; } while (*(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
; *(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
; *(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
; *(uint_16p*)(scan+=2) == *(uint_16p*)(match+=2) &&
; scan < strend);
; The funny "do {}" generates better code on most compilers
; Here, scan <= window+strstart+257
; Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
; if (*scan == *match) scan++;
; len = (MAX_MATCH - 1) - (int)(strend-scan);
; scan = strend - (MAX_MATCH-1);
else ;UNALIGNED_OK
; if (match[best_len] != scan_end ||
; match[best_len-1] != scan_end1 ||
; *match != *scan ||
@ -1876,18 +1843,12 @@ else ;UNALIGNED_OK
; len = MAX_MATCH - (int)(strend - scan);
; scan = strend - MAX_MATCH;
end if ;UNALIGNED_OK
; if (len > best_len) {
; s->match_start = cur_match;
; best_len = len;
; if (len >= nice_match) break;
if UNALIGNED_OK eq 1
; scan_end = *(uint_16p*)(scan+best_len-1);
else
; scan_end1 = scan[best_len-1];
; scan_end = scan[best_len];
end if
; }
; } while ((cur_match = prev[cur_match & wmask]) > limit
; && --chain_length != 0);
@ -1901,7 +1862,7 @@ else ;FASTEST
; ---------------------------------------------------------------------------
; Optimized version for FASTEST only
mov edx,[s]
;zlib_debug 'longest_match'
zlib_debug 'longest_match'
; The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
; It is easy to get rid of this optimization if necessary.
@ -1909,19 +1870,19 @@ else ;FASTEST
if MAX_MATCH <> 258
cmp dword[edx+deflate_state.hash_bits],8
jge @f
zlib_debug 'Code too clever' ;Assert(..>=.. && ..==..)
zlib_assert 'Code too clever' ;Assert(..>=.. && ..==..)
@@:
end if
mov eax,[edx+deflate_state.window_size]
sub eax,MIN_LOOKAHEAD
cmp [edx+deflate_state.strstart],eax
jle @f
zlib_debug 'need lookahead' ;Assert(..<=..)
zlib_assert 'need lookahead' ;Assert(..<=..)
@@:
mov eax,[edx+deflate_state.strstart]
cmp [cur_match],eax
jl @f
zlib_debug 'no future' ;Assert(..<..)
zlib_assert 'no future' ;Assert(..<..)
@@:
mov esi,[edx+deflate_state.window]
@ -1950,7 +1911,7 @@ end if
mov al,byte[edi]
cmp al,byte[esi]
je @f
zlib_debug 'match[2]?' ;Assert(..==..)
zlib_assert 'match[2]?' ;Assert(..==..)
@@:
; We check for insufficient lookahead only every 8th comparison;
@ -1969,7 +1930,7 @@ align 4
add eax,[edx+deflate_state.window]
cmp edi,eax
jle @f
zlib_debug 'wild scan' ;Assert(..<=..)
zlib_assert 'wild scan' ;Assert(..<=..)
@@:
sub edi,ebx
;edi = len
@ -1997,9 +1958,9 @@ endp
; Check that the match at match_start is indeed a match.
;void (s, start, match, length)
; deflate_state *s;
; IPos start, match;
; int length;
; deflate_state *s
; IPos start, match
; int length
align 4
proc check_match, s:dword, start:dword, p3match:dword, length:dword
if DEBUG eq 1
@ -2042,17 +2003,17 @@ pushad
;Объем свободного пространства в конце окна.
;ecx = wsize ;uInt
;edx = s.strm
;zlib_debug 'fill_window'
zlib_debug 'fill_window'
mov edi,[s]
cmp dword[edi+deflate_state.lookahead],MIN_LOOKAHEAD
jl @f
zlib_debug 'already enough lookahead' ;Assert(..<..)
zlib_assert 'already enough lookahead' ;Assert(..<..)
@@:
mov ecx,[edi+deflate_state.w_size]
mov edx,[edi+deflate_state.strm]
.cycle0: ;do
;zlib_debug 'do'
zlib_debug 'do'
mov ebx,[edi+deflate_state.window_size]
sub ebx,[edi+deflate_state.lookahead]
sub ebx,[edi+deflate_state.strstart]
@ -2135,7 +2096,7 @@ end if
cmp ebx,2
jge @f
zlib_debug 'more < 2' ;Assert(..>=..)
zlib_assert 'more < 2' ;Assert(..>=..)
@@:
mov eax,[edi+deflate_state.window]
add eax,[edi+deflate_state.strstart]
@ -2260,7 +2221,7 @@ end if
sub eax,MIN_LOOKAHEAD
cmp [edi+deflate_state.strstart],eax
jle @f
zlib_debug 'not enough room for search' ;Assert(..<=..)
zlib_assert 'not enough room for search' ;Assert(..<=..)
@@:
popad
ret
@ -2317,8 +2278,8 @@ end if
; window to pending_buf.
;block_state (s, flush)
; deflate_state *s;
; int flush;
; deflate_state *s
; int flush
align 4
proc deflate_stored uses ebx ecx edi, s:dword, flush:dword
; Stored blocks are limited to 0xffff bytes, pending_buf is limited
@ -2741,7 +2702,7 @@ align 4
.cycle0end:
cmp dword[flush],Z_NO_FLUSH
jne @f
zlib_debug 'no flush?' ;Assert (..!=..)
zlib_assert 'no flush?' ;Assert (..!=..)
@@:
cmp dword[edi+deflate_state.match_available],0
je @f ;if (..)
@ -2780,8 +2741,8 @@ endp
; deflate switches away from Z_RLE.)
;block_state (s, flush)
; deflate_state *s;
; int flush;
; deflate_state *s
; int flush
align 4
proc deflate_rle uses ecx edx edi esi, s:dword, flush:dword
locals
@ -2846,7 +2807,7 @@ align 4
add eax,[edx+deflate_state.window]
cmp edi,eax
jle .end1
zlib_debug 'wild scan' ;Assert(..<=..)
zlib_assert 'wild scan' ;Assert(..<=..)
.end1:
; Emit match if have run of MIN_MATCH or longer, else emit literal
@ -2903,8 +2864,8 @@ endp
; (It will be regenerated if this run of deflate switches away from Huffman.)
;block_state (s, flush)
; deflate_state *s;
; int flush;
; deflate_state *s
; int flush
align 4
proc deflate_huff uses ebx edi, s:dword, flush:dword
locals

View File

@ -247,8 +247,7 @@ macro put_byte s, c
}
macro put_dword s, d
{
;mov eax,d
;zlib_debug '(%d)',eax
zlib_debug '(%d)',d
movzx eax,word[s+deflate_state.pending]
add eax,[s+deflate_state.pending_buf]
mov dword[eax],d

View File

@ -106,9 +106,9 @@ button:
cmp ah,1
jne still
.exit:
.exit: ; ª®­¥æ ¯à®£à ¬¬ë
mcall SF_SYS_MISC,SSF_MEM_FREE,[m2]
mcall SF_TERMINATE_PROCESS ; ¨­ ç¥ ª®­¥æ ¯à®£à ¬¬ë
mcall SF_TERMINATE_PROCESS
align 4
draw_window:
@ -164,7 +164,11 @@ test_code:
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 ;à §¬¥à ¡ãä¥à  ¤«ï ᦠâ¨ï
mov word[eax+z_stream.avail_out],1024 ;à §¬¥à ¡ãä¥à  ¤«ï ᦠâ¨ï (¬ ªá¨¬ã¬ 16 Š¡)
;¢ëç¨á«ï¥¬ crc ¤«ï ᦨ¬ ¥¬ë¦ ¤ ­­ëå
stdcall [calc_crc32], 0,m0,ecx
mov edx,eax
;call print_z_struct
@ -172,21 +176,30 @@ test_code:
;call print_z_struct
;à §¬¥à ᦠâëå ¤ ­­ëå: 1024-word[eax+z_stream.avail_out]
mov eax,my_strm
;à §¬¥à ᦠâëå ¤ ­­ëå: 1024-word[my_strm.avail_out]
mov ecx,1024
sub cx,word[eax+z_stream.avail_out]
sub cx,word[my_strm.avail_out]
mov [m1size],ecx
;assert(ret != Z_STREAM_ERROR)
;while (strm.avail_out == 0)
;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
@ -199,10 +212,10 @@ test_code:
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]
@ -211,7 +224,7 @@ test_code:
mov eax,m1
add eax,2
stdcall [deflate_unpack],eax,m2size
mov [m2],eax
mov [m2],eax ;§ ¯¨áì ­®¢ëå à á¯ ª®¢ ­­ëå ¤ ­­ëå
mov ecx,[m0size] ;;; ???
mov [m2size],ecx
ret
@ -243,6 +256,7 @@ import_zlib:
deflateReset dd sz_deflateReset
deflate dd sz_deflate
deflateEnd dd sz_deflateEnd
calc_crc32 dd sz_calc_crc32
dd 0,0
@ -252,6 +266,8 @@ import_zlib:
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

View File

@ -172,7 +172,7 @@ macro put_short s, w
align 4
proc send_bits uses eax ecx edi, s:dword, value:dword, length:dword
; Tracevv((stderr," l %2d v %4x ", length, value));
;zlib_debug 'send_bits value = %d',[value]
zlib_debug 'send_bits value = %d',[value]
;if DEBUG eq 1
mov eax,[length]
cmp eax,0
@ -180,7 +180,7 @@ proc send_bits uses eax ecx edi, s:dword, value:dword, length:dword
cmp eax,15
jle .end1
@@:
zlib_debug 'invalid length' ;Assert(..>0 && ..<=15)
zlib_assert 'invalid length' ;Assert(..>0 && ..<=15)
.end1:
mov edi,[s]
add [edi+deflate_state.bits_sent],eax
@ -390,7 +390,7 @@ endp
align 4
proc _tr_init uses eax edi, s:dword
mov edi,[s]
;zlib_debug '_tr_init'
zlib_debug '_tr_init'
call tr_static_init
mov eax,edi
@ -530,7 +530,7 @@ endl
pushad
mov edi,[s]
mov eax,[k]
;zlib_debug 'pqdownheap k = %d',eax
zlib_debug 'pqdownheap k = %d',eax
mov esi,eax
shl esi,1
mov ax,[edi+deflate_state.heap+2*eax]
@ -604,7 +604,7 @@ locals
overflow dd 0 ;int ;number of elements with bit length too large
endl
pushad
;zlib_debug 'gen_bitlen'
zlib_debug 'gen_bitlen'
mov edi,[s]
mov edx,[desc]
mov eax,[edx+tree_desc.dyn_tree]
@ -817,7 +817,7 @@ locals
endl
; The distribution counts are first used to generate the code values
; without bit reversal.
;zlib_debug 'gen_codes'
zlib_debug 'gen_codes'
mov ebx,ebp
sub ebx,2*(MAX_BITS+1)
@ -846,7 +846,7 @@ endl
dec ax
cmp ax,(1 shl MAX_BITS)-1
je @f
zlib_debug 'inconsistent bit counts' ;Assert(..==..)
zlib_assert 'inconsistent bit counts' ;Assert(..==..)
@@:
; Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
@ -910,7 +910,7 @@ endl
mov ecx,[ecx+static_tree_desc.elems]
mov [elems],ecx
mov edi,[s]
;zlib_debug 'build_tree cycle0 ecx = %d',ecx
zlib_debug 'build_tree cycle0 ecx = %d',ecx
mov dword[edi+deflate_state.heap_len],0
mov dword[edi+deflate_state.heap_max],HEAP_SIZE
@ -1103,7 +1103,7 @@ locals
min_count dd 4 ;int ;min repeat count
endl
mov edi,[s]
;zlib_debug 'scan_tree'
zlib_debug 'scan_tree'
mov eax,[tree]
movzx eax,word[eax+Len]
mov [nextlen],eax
@ -1227,7 +1227,7 @@ locals
min_count dd 4 ;int ;min repeat count
endl
mov edi,[s]
;zlib_debug 'send_tree'
zlib_debug 'send_tree'
; *** tree[max_code+1].Len = -1 ;guard already set
mov eax,[tree]
movzx eax,word[eax+Len]
@ -1287,7 +1287,7 @@ align 4
cmp dword[count],6
jle .end8
@@:
zlib_debug ' 3_6?' ;Assert(..>=.. && ..<=..)
zlib_assert ' 3_6?' ;Assert(..>=.. && ..<=..)
.end8:
mov ebx,edi
add ebx,deflate_state.bl_tree
@ -1410,7 +1410,7 @@ endp
align 4
proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, blcodes:dword
;ecx = index in bl_order
;zlib_debug 'send_all_trees'
zlib_debug 'send_all_trees'
cmp dword[lcodes],257
jl @f
cmp dword[dcodes],1
@ -1418,7 +1418,7 @@ proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, b
cmp dword[blcodes],4
jge .end0
@@:
zlib_debug 'not enough codes' ;Assert(..>=.. && ..>=.. && ..>=..)
zlib_assert 'not enough codes' ;Assert(..>=.. && ..>=.. && ..>=..)
.end0:
cmp dword[lcodes],L_CODES
jg @f
@ -1427,7 +1427,7 @@ proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, b
cmp dword[blcodes],BL_CODES
jle .end1
@@:
zlib_debug 'too many codes' ;Assert(..<=.. && ..<=.. && ..<=..)
zlib_assert 'too many codes' ;Assert(..<=.. && ..<=.. && ..<=..)
.end1:
; Tracev((stderr, "\nbl counts: "));
mov edi,[s]
@ -1549,7 +1549,7 @@ locals
endl
; Build the Huffman trees unless a stored block is forced
mov edi,[s]
;zlib_debug '_tr_flush_block'
zlib_debug '_tr_flush_block'
cmp word[edi+deflate_state.level],0
jle .end0 ;if (..>0)
@ -1601,7 +1601,7 @@ endl
.end0: ;else
cmp dword[buf],0
jne @f
zlib_debug 'lost buf' ;Assert(..!=0)
zlib_assert 'lost buf' ;Assert(..!=0)
@@:
mov eax,[stored_len]
add eax,5
@ -1705,7 +1705,7 @@ endp
align 4
proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword
mov edi,[s]
;zlib_debug '_tr_tally'
zlib_debug '_tr_tally'
mov eax,[edi+deflate_state.last_lit]
shl eax,1
add eax,[edi+deflate_state.d_buf]
@ -1737,7 +1737,7 @@ proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword
cmp ax,D_CODES
jl .end2
@@:
zlib_debug '_tr_tally: bad match' ;Assert(..<.. && ..<=.. && ..<..)
zlib_assert '_tr_tally: bad match' ;Assert(..<.. && ..<=.. && ..<..)
.end2:
mov eax,[lc]
add eax,_length_code
@ -1853,7 +1853,7 @@ endl
mov [u_code],eax
cmp eax,D_CODES
jl @f
zlib_debug 'bad d_code' ;Assert(..<..)
zlib_assert 'bad d_code' ;Assert(..<..)
@@:
send_code edi, [u_code], [dtree] ;send the distance code
mov eax,[u_code]
@ -1877,7 +1877,7 @@ endl
add eax,[edi+deflate_state.lit_bufsize]
cmp word[edi+deflate_state.pending],ax
jl @f
zlib_debug 'pendingBuf overflow' ;Assert(..<..)
zlib_assert 'pendingBuf overflow' ;Assert(..<..)
@@:
mov eax,[edi+deflate_state.last_lit]
cmp [lx],eax
@ -1911,10 +1911,9 @@ proc detect_data_type uses ebx ecx edi, s:dword
; 0xf3ffc07f = binary 11110011111111111100000001111111
locals
black_mask dd 0xf3ffc07f
; int n;
endl
mov edi,[s]
;zlib_debug 'detect_data_type'
zlib_debug 'detect_data_type'
; Check for non-textual ("black-listed") bytes.
xor ecx,ecx
@ -1985,7 +1984,7 @@ endp
; int len ;its bit length
align 4
proc bi_reverse uses ebx, p1code:dword, len:dword
;zlib_debug 'bi_reverse'
zlib_debug 'bi_reverse'
xor eax,eax
@@: ;do
mov ebx,[p1code]

View File

@ -5,10 +5,6 @@
; 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
@ -30,136 +26,3 @@ MAX_WBITS equ 15 ;32K LZ77 window
; 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

@ -11,6 +11,7 @@ FASTEST equ 1
GEN_TREES_H equ 0
DEBUG equ 0
DYNAMIC_CRC_TABLE equ 1
Z_SOLO equ 0
; 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
@ -20,12 +21,19 @@ GZIP equ 1
macro zlib_debug fmt,p1
{
local .end_t
local .m_fmt
jmp .end_t
if DEBUG eq 1
zlib_assert fmt,p1
end if
}
macro zlib_assert fmt,p1
{
local .end_t
local .m_fmt
jmp .end_t
.m_fmt db fmt,13,10,0
align 4
.end_t:
.end_t:
if p1 eq
stdcall dbg_print,0,.m_fmt
else
@ -36,6 +44,7 @@ end if
include 'zlib.inc'
include 'deflate.inc'
include 'zutil.asm'
include '../kfar_arc/crc.inc'
include 'crc32.asm'
include 'adler32.asm'
include 'trees.asm'
@ -169,6 +178,9 @@ EXPORTS:
dd adeflateReset, deflateReset
dd adeflate, deflate
dd adeflateEnd, deflateEnd
dd adeflateCopy, deflateCopy
dd azError, zError
dd acalc_crc32, calc_crc32
dd 0
; exported names
@ -177,3 +189,6 @@ adeflateInit2 db 'deflateInit2',0
adeflateReset db 'deflateReset',0
adeflate db 'deflate',0
adeflateEnd db 'deflateEnd',0
adeflateCopy db 'deflateCopy',0
azError db 'zError',0
acalc_crc32 db 'calc_crc32',0

View File

@ -212,7 +212,7 @@ zlib_version equ zlibVersion
; inflateBackInit_((strm), (windowBits), (window), \
; ZLIB_VERSION, (int)sizeof(z_stream))
;#ifndef Z_SOLO
if Z_SOLO eq 0
; gzgetc() macro and its supporting function and exposed data structure. Note
; that the real internal state is much larger than the exposed structure.
@ -234,7 +234,7 @@ zlib_version equ zlibVersion
;#else
;# define gzgetc(g) \
; ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
;end if
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
@ -252,11 +252,4 @@ zlib_version equ zlibVersion
;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

View File

@ -107,38 +107,33 @@ end if
ret
endp
;if DEBUG
;# define verbose 0
;int z_verbose = verbose;
;void (m)
; char *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;
; int err
align 4
proc zError, err:dword
; return ERR_MSG(err);
proc zError uses ecx, err:dword
ERR_MSG [err]
mov eax,ecx
ret
endp
;#ifndef HAVE_MEMCPY
;void (dest, source, len)
; Bytef* dest;
; const Bytef* source;
; uInt 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]
@ -155,9 +150,9 @@ zlib_debug 'zmemcpy size = %d',ecx
endp
;int (s1, s2, len)
; const Bytef* s1;
; const Bytef* s2;
; uInt len;
; const Bytef* s1
; const Bytef* s2
; uInt len
align 4
proc zmemcmp, s1:dword, s2:dword, len:dword
; uInt j;
@ -170,8 +165,8 @@ proc zmemcmp, s1:dword, s2:dword, len:dword
endp
;void (dest, len)
; Bytef* dest;
; uInt len;
; Bytef* dest
; uInt len
align 4
proc zmemzero, dest:dword, len:dword
; if (len == 0) return;
@ -182,8 +177,6 @@ proc zmemzero, dest:dword, len:dword
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
@ -200,4 +193,3 @@ proc zcfree uses eax ebx ecx, opaque:dword, p2ptr:dword
ret
endp
;end if /* !Z_SOLO */

View File

@ -9,7 +9,8 @@
macro ERR_MSG err
{
mov ecx,Z_NEED_DICT-err
mov ecx,Z_NEED_DICT
sub ecx,err
mov ecx,[4*ecx+z_errmsg]
}