Rev 6617 | Rev 6741 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6617 | Rev 6639 | ||
---|---|---|---|
Line 170... | Line 170... | ||
170 | ; int value ;value to send |
170 | ; int value ;value to send |
171 | ; int length ;number of bits |
171 | ; int length ;number of bits |
172 | align 4 |
172 | align 4 |
173 | proc send_bits uses eax ecx edi, s:dword, value:dword, length:dword |
173 | proc send_bits uses eax ecx edi, s:dword, value:dword, length:dword |
174 | ; Tracevv((stderr," l %2d v %4x ", length, value)); |
174 | ; Tracevv((stderr," l %2d v %4x ", length, value)); |
175 | ;zlib_debug 'send_bits value = %d',[value] |
175 | zlib_debug 'send_bits value = %d',[value] |
176 | ;if DEBUG eq 1 |
176 | ;if DEBUG eq 1 |
177 | mov eax,[length] |
177 | mov eax,[length] |
178 | cmp eax,0 |
178 | cmp eax,0 |
179 | jle @f |
179 | jle @f |
180 | cmp eax,15 |
180 | cmp eax,15 |
181 | jle .end1 |
181 | jle .end1 |
182 | @@: |
182 | @@: |
183 | zlib_debug 'invalid length' ;Assert(..>0 && ..<=15) |
183 | zlib_assert 'invalid length' ;Assert(..>0 && ..<=15) |
184 | .end1: |
184 | .end1: |
185 | mov edi,[s] |
185 | mov edi,[s] |
186 | add [edi+deflate_state.bits_sent],eax |
186 | add [edi+deflate_state.bits_sent],eax |
Line 187... | Line 187... | ||
187 | 187 | ||
Line 388... | Line 388... | ||
388 | ;void (s) |
388 | ;void (s) |
389 | ; deflate_state* s; |
389 | ; deflate_state* s; |
390 | align 4 |
390 | align 4 |
391 | proc _tr_init uses eax edi, s:dword |
391 | proc _tr_init uses eax edi, s:dword |
392 | mov edi,[s] |
392 | mov edi,[s] |
393 | ;zlib_debug '_tr_init' |
393 | zlib_debug '_tr_init' |
394 | call tr_static_init |
394 | call tr_static_init |
Line 395... | Line 395... | ||
395 | 395 | ||
396 | mov eax,edi |
396 | mov eax,edi |
397 | add eax,deflate_state.dyn_ltree |
397 | add eax,deflate_state.dyn_ltree |
Line 528... | Line 528... | ||
528 | v dw ? |
528 | v dw ? |
529 | endl |
529 | endl |
530 | pushad |
530 | pushad |
531 | mov edi,[s] |
531 | mov edi,[s] |
532 | mov eax,[k] |
532 | mov eax,[k] |
533 | ;zlib_debug 'pqdownheap k = %d',eax |
533 | zlib_debug 'pqdownheap k = %d',eax |
534 | mov esi,eax |
534 | mov esi,eax |
535 | shl esi,1 |
535 | shl esi,1 |
536 | mov ax,[edi+deflate_state.heap+2*eax] |
536 | mov ax,[edi+deflate_state.heap+2*eax] |
537 | mov [v],ax |
537 | mov [v],ax |
538 | ;esi = j ;left son of k |
538 | ;esi = j ;left son of k |
Line 602... | Line 602... | ||
602 | xbits dd ? ;int ;extra bits |
602 | xbits dd ? ;int ;extra bits |
603 | f dw ? ;uint_16 ;frequency |
603 | f dw ? ;uint_16 ;frequency |
604 | overflow dd 0 ;int ;number of elements with bit length too large |
604 | overflow dd 0 ;int ;number of elements with bit length too large |
605 | endl |
605 | endl |
606 | pushad |
606 | pushad |
607 | ;zlib_debug 'gen_bitlen' |
607 | zlib_debug 'gen_bitlen' |
608 | mov edi,[s] |
608 | mov edi,[s] |
609 | mov edx,[desc] |
609 | mov edx,[desc] |
610 | mov eax,[edx+tree_desc.dyn_tree] |
610 | mov eax,[edx+tree_desc.dyn_tree] |
611 | mov [tree],eax |
611 | mov [tree],eax |
612 | mov eax,[edx+tree_desc.max_code] |
612 | mov eax,[edx+tree_desc.max_code] |
Line 815... | Line 815... | ||
815 | bits dd 1 ;int ;bit index |
815 | bits dd 1 ;int ;bit index |
816 | next_code rw MAX_BITS+1 ;uint_16[] ;next code value for each bit length |
816 | next_code rw MAX_BITS+1 ;uint_16[] ;next code value for each bit length |
817 | endl |
817 | endl |
818 | ; The distribution counts are first used to generate the code values |
818 | ; The distribution counts are first used to generate the code values |
819 | ; without bit reversal. |
819 | ; without bit reversal. |
820 | ;zlib_debug 'gen_codes' |
820 | zlib_debug 'gen_codes' |
821 | mov ebx,ebp |
821 | mov ebx,ebp |
822 | sub ebx,2*(MAX_BITS+1) |
822 | sub ebx,2*(MAX_BITS+1) |
Line 823... | Line 823... | ||
823 | 823 | ||
824 | .cycle0: ;for (..;..<=..;..) |
824 | .cycle0: ;for (..;..<=..;..) |
Line 844... | Line 844... | ||
844 | mov ax,word[eax+2*MAX_BITS] |
844 | mov ax,word[eax+2*MAX_BITS] |
845 | add ax,[u_code] |
845 | add ax,[u_code] |
846 | dec ax |
846 | dec ax |
847 | cmp ax,(1 shl MAX_BITS)-1 |
847 | cmp ax,(1 shl MAX_BITS)-1 |
848 | je @f |
848 | je @f |
849 | zlib_debug 'inconsistent bit counts' ;Assert(..==..) |
849 | zlib_assert 'inconsistent bit counts' ;Assert(..==..) |
850 | @@: |
850 | @@: |
851 | ; Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); |
851 | ; Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); |
Line 852... | Line 852... | ||
852 | 852 | ||
853 | xor ecx,ecx ;n = 0 |
853 | xor ecx,ecx ;n = 0 |
Line 908... | Line 908... | ||
908 | mov eax,[ecx+static_tree_desc.static_tree] |
908 | mov eax,[ecx+static_tree_desc.static_tree] |
909 | mov [stree],eax |
909 | mov [stree],eax |
910 | mov ecx,[ecx+static_tree_desc.elems] |
910 | mov ecx,[ecx+static_tree_desc.elems] |
911 | mov [elems],ecx |
911 | mov [elems],ecx |
912 | mov edi,[s] |
912 | mov edi,[s] |
913 | ;zlib_debug 'build_tree cycle0 ecx = %d',ecx |
913 | zlib_debug 'build_tree cycle0 ecx = %d',ecx |
Line 914... | Line 914... | ||
914 | 914 | ||
915 | mov dword[edi+deflate_state.heap_len],0 |
915 | mov dword[edi+deflate_state.heap_len],0 |
Line 916... | Line 916... | ||
916 | mov dword[edi+deflate_state.heap_max],HEAP_SIZE |
916 | mov dword[edi+deflate_state.heap_max],HEAP_SIZE |
Line 1101... | Line 1101... | ||
1101 | count dd 0 ;int ;repeat count of the current code |
1101 | count dd 0 ;int ;repeat count of the current code |
1102 | max_count dd 7 ;int ;max repeat count |
1102 | max_count dd 7 ;int ;max repeat count |
1103 | min_count dd 4 ;int ;min repeat count |
1103 | min_count dd 4 ;int ;min repeat count |
1104 | endl |
1104 | endl |
1105 | mov edi,[s] |
1105 | mov edi,[s] |
1106 | ;zlib_debug 'scan_tree' |
1106 | zlib_debug 'scan_tree' |
1107 | mov eax,[tree] |
1107 | mov eax,[tree] |
1108 | movzx eax,word[eax+Len] |
1108 | movzx eax,word[eax+Len] |
1109 | mov [nextlen],eax |
1109 | mov [nextlen],eax |
1110 | cmp eax,0 |
1110 | cmp eax,0 |
1111 | jne @f ;if (..==0) |
1111 | jne @f ;if (..==0) |
Line 1225... | Line 1225... | ||
1225 | count dd 0 ;int ;repeat count of the current code |
1225 | count dd 0 ;int ;repeat count of the current code |
1226 | max_count dd 7 ;int ;max repeat count |
1226 | max_count dd 7 ;int ;max repeat count |
1227 | min_count dd 4 ;int ;min repeat count |
1227 | min_count dd 4 ;int ;min repeat count |
1228 | endl |
1228 | endl |
1229 | mov edi,[s] |
1229 | mov edi,[s] |
1230 | ;zlib_debug 'send_tree' |
1230 | zlib_debug 'send_tree' |
1231 | ; *** tree[max_code+1].Len = -1 ;guard already set |
1231 | ; *** tree[max_code+1].Len = -1 ;guard already set |
1232 | mov eax,[tree] |
1232 | mov eax,[tree] |
1233 | movzx eax,word[eax+Len] |
1233 | movzx eax,word[eax+Len] |
1234 | mov [nextlen],eax |
1234 | mov [nextlen],eax |
1235 | cmp eax,0 |
1235 | cmp eax,0 |
Line 1285... | Line 1285... | ||
1285 | cmp dword[count],3 |
1285 | cmp dword[count],3 |
1286 | jl @f |
1286 | jl @f |
1287 | cmp dword[count],6 |
1287 | cmp dword[count],6 |
1288 | jle .end8 |
1288 | jle .end8 |
1289 | @@: |
1289 | @@: |
1290 | zlib_debug ' 3_6?' ;Assert(..>=.. && ..<=..) |
1290 | zlib_assert ' 3_6?' ;Assert(..>=.. && ..<=..) |
1291 | .end8: |
1291 | .end8: |
1292 | mov ebx,edi |
1292 | mov ebx,edi |
1293 | add ebx,deflate_state.bl_tree |
1293 | add ebx,deflate_state.bl_tree |
1294 | send_code edi, REP_3_6, ebx |
1294 | send_code edi, REP_3_6, ebx |
1295 | mov ebx,[count] |
1295 | mov ebx,[count] |
Line 1408... | Line 1408... | ||
1408 | ; deflate_state* s |
1408 | ; deflate_state* s |
1409 | ; int lcodes, dcodes, blcodes ;number of codes for each tree |
1409 | ; int lcodes, dcodes, blcodes ;number of codes for each tree |
1410 | align 4 |
1410 | align 4 |
1411 | proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, blcodes:dword |
1411 | proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, blcodes:dword |
1412 | ;ecx = index in bl_order |
1412 | ;ecx = index in bl_order |
1413 | ;zlib_debug 'send_all_trees' |
1413 | zlib_debug 'send_all_trees' |
1414 | cmp dword[lcodes],257 |
1414 | cmp dword[lcodes],257 |
1415 | jl @f |
1415 | jl @f |
1416 | cmp dword[dcodes],1 |
1416 | cmp dword[dcodes],1 |
1417 | jl @f |
1417 | jl @f |
1418 | cmp dword[blcodes],4 |
1418 | cmp dword[blcodes],4 |
1419 | jge .end0 |
1419 | jge .end0 |
1420 | @@: |
1420 | @@: |
1421 | zlib_debug 'not enough codes' ;Assert(..>=.. && ..>=.. && ..>=..) |
1421 | zlib_assert 'not enough codes' ;Assert(..>=.. && ..>=.. && ..>=..) |
1422 | .end0: |
1422 | .end0: |
1423 | cmp dword[lcodes],L_CODES |
1423 | cmp dword[lcodes],L_CODES |
1424 | jg @f |
1424 | jg @f |
1425 | cmp dword[dcodes],D_CODES |
1425 | cmp dword[dcodes],D_CODES |
1426 | jg @f |
1426 | jg @f |
1427 | cmp dword[blcodes],BL_CODES |
1427 | cmp dword[blcodes],BL_CODES |
1428 | jle .end1 |
1428 | jle .end1 |
1429 | @@: |
1429 | @@: |
1430 | zlib_debug 'too many codes' ;Assert(..<=.. && ..<=.. && ..<=..) |
1430 | zlib_assert 'too many codes' ;Assert(..<=.. && ..<=.. && ..<=..) |
1431 | .end1: |
1431 | .end1: |
1432 | ; Tracev((stderr, "\nbl counts: ")); |
1432 | ; Tracev((stderr, "\nbl counts: ")); |
1433 | mov edi,[s] |
1433 | mov edi,[s] |
1434 | mov eax,[lcodes] |
1434 | mov eax,[lcodes] |
1435 | sub eax,257 |
1435 | sub eax,257 |
Line 1547... | Line 1547... | ||
1547 | static_lenb dd ? ;opt_len and static_len in bytes |
1547 | static_lenb dd ? ;opt_len and static_len in bytes |
1548 | max_blindex dd 0 ;int ;index of last bit length code of non zero freq |
1548 | max_blindex dd 0 ;int ;index of last bit length code of non zero freq |
1549 | endl |
1549 | endl |
1550 | ; Build the Huffman trees unless a stored block is forced |
1550 | ; Build the Huffman trees unless a stored block is forced |
1551 | mov edi,[s] |
1551 | mov edi,[s] |
1552 | ;zlib_debug '_tr_flush_block' |
1552 | zlib_debug '_tr_flush_block' |
1553 | cmp word[edi+deflate_state.level],0 |
1553 | cmp word[edi+deflate_state.level],0 |
1554 | jle .end0 ;if (..>0) |
1554 | jle .end0 ;if (..>0) |
Line 1555... | Line 1555... | ||
1555 | 1555 | ||
1556 | ; Check if the file is binary or text |
1556 | ; Check if the file is binary or text |
Line 1599... | Line 1599... | ||
1599 | mov [opt_lenb],eax |
1599 | mov [opt_lenb],eax |
1600 | jmp .end1 |
1600 | jmp .end1 |
1601 | .end0: ;else |
1601 | .end0: ;else |
1602 | cmp dword[buf],0 |
1602 | cmp dword[buf],0 |
1603 | jne @f |
1603 | jne @f |
1604 | zlib_debug 'lost buf' ;Assert(..!=0) |
1604 | zlib_assert 'lost buf' ;Assert(..!=0) |
1605 | @@: |
1605 | @@: |
1606 | mov eax,[stored_len] |
1606 | mov eax,[stored_len] |
1607 | add eax,5 |
1607 | add eax,5 |
1608 | mov [static_lenb],eax |
1608 | mov [static_lenb],eax |
1609 | mov [opt_lenb],eax ;force a stored block |
1609 | mov [opt_lenb],eax ;force a stored block |
Line 1703... | Line 1703... | ||
1703 | ; unsigned dist ;distance of matched string |
1703 | ; unsigned dist ;distance of matched string |
1704 | ; unsigned lc ;match length-MIN_MATCH or unmatched char (if dist==0) |
1704 | ; unsigned lc ;match length-MIN_MATCH or unmatched char (if dist==0) |
1705 | align 4 |
1705 | align 4 |
1706 | proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword |
1706 | proc _tr_tally uses ebx edi, s:dword, dist:dword, lc:dword |
1707 | mov edi,[s] |
1707 | mov edi,[s] |
1708 | ;zlib_debug '_tr_tally' |
1708 | zlib_debug '_tr_tally' |
1709 | mov eax,[edi+deflate_state.last_lit] |
1709 | mov eax,[edi+deflate_state.last_lit] |
1710 | shl eax,1 |
1710 | shl eax,1 |
1711 | add eax,[edi+deflate_state.d_buf] |
1711 | add eax,[edi+deflate_state.d_buf] |
1712 | mov ebx,[dist] |
1712 | mov ebx,[dist] |
1713 | mov word[eax],bx |
1713 | mov word[eax],bx |
Line 1735... | Line 1735... | ||
1735 | jg @f |
1735 | jg @f |
1736 | d_code [dist] |
1736 | d_code [dist] |
1737 | cmp ax,D_CODES |
1737 | cmp ax,D_CODES |
1738 | jl .end2 |
1738 | jl .end2 |
1739 | @@: |
1739 | @@: |
1740 | zlib_debug '_tr_tally: bad match' ;Assert(..<.. && ..<=.. && ..<..) |
1740 | zlib_assert '_tr_tally: bad match' ;Assert(..<.. && ..<=.. && ..<..) |
1741 | .end2: |
1741 | .end2: |
1742 | mov eax,[lc] |
1742 | mov eax,[lc] |
1743 | add eax,_length_code |
1743 | add eax,_length_code |
1744 | movzx eax,byte[eax] |
1744 | movzx eax,byte[eax] |
1745 | add eax,LITERALS+1 |
1745 | add eax,LITERALS+1 |
Line 1851... | Line 1851... | ||
1851 | dec dword[dist] ;dist is now the match distance - 1 |
1851 | dec dword[dist] ;dist is now the match distance - 1 |
1852 | d_code [dist] |
1852 | d_code [dist] |
1853 | mov [u_code],eax |
1853 | mov [u_code],eax |
1854 | cmp eax,D_CODES |
1854 | cmp eax,D_CODES |
1855 | jl @f |
1855 | jl @f |
1856 | zlib_debug 'bad d_code' ;Assert(..<..) |
1856 | zlib_assert 'bad d_code' ;Assert(..<..) |
1857 | @@: |
1857 | @@: |
1858 | send_code edi, [u_code], [dtree] ;send the distance code |
1858 | send_code edi, [u_code], [dtree] ;send the distance code |
1859 | mov eax,[u_code] |
1859 | mov eax,[u_code] |
1860 | shl eax,2 |
1860 | shl eax,2 |
1861 | add eax,extra_dbits |
1861 | add eax,extra_dbits |
Line 1875... | Line 1875... | ||
1875 | mov eax,[lx] |
1875 | mov eax,[lx] |
1876 | shl eax,1 |
1876 | shl eax,1 |
1877 | add eax,[edi+deflate_state.lit_bufsize] |
1877 | add eax,[edi+deflate_state.lit_bufsize] |
1878 | cmp word[edi+deflate_state.pending],ax |
1878 | cmp word[edi+deflate_state.pending],ax |
1879 | jl @f |
1879 | jl @f |
1880 | zlib_debug 'pendingBuf overflow' ;Assert(..<..) |
1880 | zlib_assert 'pendingBuf overflow' ;Assert(..<..) |
1881 | @@: |
1881 | @@: |
1882 | mov eax,[edi+deflate_state.last_lit] |
1882 | mov eax,[edi+deflate_state.last_lit] |
1883 | cmp [lx],eax |
1883 | cmp [lx],eax |
1884 | jl .cycle0 ;while (..<..) |
1884 | jl .cycle0 ;while (..<..) |
1885 | align 4 |
1885 | align 4 |
Line 1909... | Line 1909... | ||
1909 | ; black_mask is the bit mask of black-listed bytes |
1909 | ; black_mask is the bit mask of black-listed bytes |
1910 | ; set bits 0..6, 14..25, and 28..31 |
1910 | ; set bits 0..6, 14..25, and 28..31 |
1911 | ; 0xf3ffc07f = binary 11110011111111111100000001111111 |
1911 | ; 0xf3ffc07f = binary 11110011111111111100000001111111 |
1912 | locals |
1912 | locals |
1913 | black_mask dd 0xf3ffc07f |
1913 | black_mask dd 0xf3ffc07f |
1914 | ; int n; |
- | |
1915 | endl |
1914 | endl |
1916 | mov edi,[s] |
1915 | mov edi,[s] |
1917 | ;zlib_debug 'detect_data_type' |
1916 | zlib_debug 'detect_data_type' |
Line 1918... | Line 1917... | ||
1918 | 1917 | ||
1919 | ; Check for non-textual ("black-listed") bytes. |
1918 | ; Check for non-textual ("black-listed") bytes. |
1920 | xor ecx,ecx |
1919 | xor ecx,ecx |
1921 | mov ebx,edi |
1920 | mov ebx,edi |
Line 1983... | Line 1982... | ||
1983 | ;unsigned (code, len) |
1982 | ;unsigned (code, len) |
1984 | ; unsigned code ;the value to invert |
1983 | ; unsigned code ;the value to invert |
1985 | ; int len ;its bit length |
1984 | ; int len ;its bit length |
1986 | align 4 |
1985 | align 4 |
1987 | proc bi_reverse uses ebx, p1code:dword, len:dword |
1986 | proc bi_reverse uses ebx, p1code:dword, len:dword |
1988 | ;zlib_debug 'bi_reverse' |
1987 | zlib_debug 'bi_reverse' |
1989 | xor eax,eax |
1988 | xor eax,eax |
1990 | @@: ;do |
1989 | @@: ;do |
1991 | mov ebx,[p1code] |
1990 | mov ebx,[p1code] |
1992 | and ebx,1 |
1991 | and ebx,1 |
1993 | or eax,ebx |
1992 | or eax,ebx |