Subversion Repositories Kolibri OS

Rev

Rev 6815 | Rev 6851 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6815 Rev 6847
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]
-
 
176
;if DEBUG eq 1
175
;if DEBUG eq 1
177
	mov eax,[length]
176
	mov eax,[length]
178
	cmp eax,0
177
	cmp eax,0
179
	jle @f
178
	jle @f
180
	cmp eax,15
179
	cmp eax,15
181
	jle .end1
180
	jle .end1
182
	@@:
181
	@@:
183
		zlib_assert 'invalid length' ;Assert(..>0 && ..<=15)
182
		zlib_assert 'invalid length' ;Assert(..>0 && ..<=15)
184
	.end1:
183
	.end1:
185
	mov edi,[s]
184
	mov edi,[s]
186
	add [edi+deflate_state.bits_sent],eax
185
	;;add [edi+deflate_state.bits_sent],eax
Line 187... Line 186...
187
 
186
 
188
	; If not enough room in bi_buf, use (valid) bits from bi_buf and
187
	; If not enough room in bi_buf, use (valid) bits from bi_buf and
189
	; (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
188
	; (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
Line 383... Line 382...
383
endp
382
endp
Line 384... Line 383...
384
 
383
 
385
; ===========================================================================
384
; ===========================================================================
Line 386... Line -...
386
; Initialize the tree data structures for a new zlib stream.
-
 
387
 
385
; Initialize the tree data structures for a new zlib stream.
388
;void (s)
386
 
389
;    deflate_state* s
387
;void (deflate_state* s)
390
align 4
388
align 4
391
proc _tr_init uses eax edi, s:dword
-
 
392
	mov edi,[s]
389
proc _tr_init uses eax edi, s:dword
Line 393... Line 390...
393
	zlib_debug '_tr_init'
390
	mov edi,[s]
394
	call tr_static_init
391
	call tr_static_init
395
 
392
 
Line 419... Line 416...
419
endp
416
endp
Line 420... Line 417...
420
 
417
 
421
; ===========================================================================
418
; ===========================================================================
Line 422... Line -...
422
; Initialize a new block.
-
 
423
 
419
; Initialize a new block.
424
;void (s)
420
 
425
;    deflate_state* s
421
;void (deflate_state* s)
426
align 4
422
align 4
Line 427... Line 423...
427
proc init_block uses eax ecx edi, s:dword
423
proc init_block uses eax ecx edi, s:dword
Line 467... Line 463...
467
; one less element. Updates heap and heap_len.
463
; one less element. Updates heap and heap_len.
Line 468... Line 464...
468
 
464
 
469
macro pqremove s, tree, top
465
macro pqremove s, tree, top
470
{
466
{
471
	mov eax,s
467
	mov eax,s
472
	add eax,deflate_state.heap+2*SMALLEST
468
	add eax,deflate_state.heap+4*SMALLEST
473
	movzx top,word[eax]
469
	movzx top,word[eax]
474
push ebx
470
push ebx
475
	mov ebx,[s+deflate_state.heap_len]
471
	mov ebx,[s+deflate_state.heap_len]
476
	mov bx,[s+deflate_state.heap+2*ebx]
472
	mov ebx,[s+deflate_state.heap+4*ebx]
477
	mov word[eax],bx
473
	mov [eax],ebx
478
	dec dword[s+deflate_state.heap_len]
474
	dec dword[s+deflate_state.heap_len]
479
pop ebx
475
pop ebx
480
	stdcall pqdownheap, s, tree, SMALLEST
476
	stdcall pqdownheap, s, tree, SMALLEST
Line 486... Line 482...
486
 
482
 
487
macro smaller tree, n, m, depth, m_end
483
macro smaller tree, n, m, depth, m_end
488
{
484
{
489
;if (..<.. || (..==.. && depth[n] <= depth[m]))
485
;if (..<.. || (..==.. && depth[n] <= depth[m]))
490
local .end0
486
local .end0
491
	movzx eax,n
487
	mov eax,n
492
	imul eax,sizeof.ct_data
488
	imul eax,sizeof.ct_data
493
	add eax,tree
489
	add eax,tree
494
	mov ax,word[eax+Freq]
490
	mov ax,word[eax+Freq]
495
	movzx ebx,m
491
	mov ebx,m
496
	imul ebx,sizeof.ct_data
492
	imul ebx,sizeof.ct_data
497
	add ebx,tree
493
	add ebx,tree
498
	mov bx,word[ebx+Freq]
494
	mov bx,word[ebx+Freq]
499
	cmp ax,bx
495
	cmp ax,bx
500
	jl .end0
496
	jl .end0
501
	jne m_end
497
	jne m_end
502
	movzx eax,n
498
	mov eax,n
503
	mov al,byte[eax+depth]
499
	mov al,byte[eax+depth]
504
	movzx ebx,m
500
	mov ebx,m
505
	cmp al,byte[ebx+depth]
501
	cmp al,byte[ebx+depth]
506
	jg m_end
502
	jg m_end
507
	.end0:
503
	.end0:
Line 521... Line 517...
521
proc pqdownheap, s:dword, tree:dword, k:dword
517
proc pqdownheap, s:dword, tree:dword, k:dword
522
pushad
518
pushad
523
	;ecx - v dw
519
	;ecx - v dw
524
	mov edi,[s]
520
	mov edi,[s]
525
	mov esi,[k]
521
	mov esi,[k]
526
	zlib_debug 'pqdownheap k = %d',esi
-
 
527
	mov cx,[edi+deflate_state.heap+2*esi]
522
	mov ecx,[edi+deflate_state.heap+4*esi]
528
	shl esi,1
523
	shl esi,1
529
	;esi = j ;left son of k
524
	;esi = j ;left son of k
530
	.cycle0: ;while (..<=..)
525
	.cycle0: ;while (..<=..)
531
		cmp esi,[edi+deflate_state.heap_len]
526
		cmp esi,[edi+deflate_state.heap_len]
532
		jg .cycle0end
527
		jg .cycle0end
533
		; Set j to the smallest of the two sons:
528
		; Set j to the smallest of the two sons:
534
		;;cmp esi,[edi+deflate_state.heap_len]
529
		;;cmp esi,[edi+deflate_state.heap_len]
535
		jge .end1 ;if (..<.. &&
530
		jge .end1 ;if (..<.. &&
536
		mov edx,esi
531
		mov edx,esi
537
		shl edx,1
532
		shl edx,2
538
		add edx,edi
533
		add edx,edi
539
		add edx,deflate_state.heap
534
		add edx,deflate_state.heap
540
		smaller [tree], word[edx+2], word[edx], edi+deflate_state.depth, .end1
535
		smaller [tree], dword[edx+4], dword[edx], edi+deflate_state.depth, .end1
541
			inc esi
536
			inc esi
542
		.end1:
537
		.end1:
543
		; Exit if v is smaller than both sons
538
		; Exit if v is smaller than both sons
544
		mov dx,[edi+deflate_state.heap+2*esi]
539
		mov edx,[edi+deflate_state.heap+4*esi]
545
		smaller [tree], cx, dx, edi+deflate_state.depth, .end2
540
		smaller [tree], ecx, edx, edi+deflate_state.depth, .end2
546
			jmp .cycle0end ;break
541
			jmp .cycle0end ;break
547
		.end2:
542
		.end2:
548
		; Exchange v with the smallest son
543
		; Exchange v with the smallest son
549
		;;mov dx,[edi+deflate_state.heap+2*esi]
544
		;;mov dx,[edi+deflate_state.heap+2*esi]
550
		mov eax,[k]
545
		mov eax,[k]
551
		mov [edi+deflate_state.heap+2*eax],dx
546
		mov [edi+deflate_state.heap+4*eax],edx
552
		mov [k],esi
547
		mov [k],esi
553
		; And continue down the tree, setting j to the left son of k
548
		; And continue down the tree, setting j to the left son of k
554
		shl esi,1
549
		shl esi,1
555
		jmp .cycle0
550
		jmp .cycle0
556
align 4
551
align 4
557
	.cycle0end:
552
	.cycle0end:
558
	mov eax,[k]
553
	mov eax,[k]
559
	mov [edi+deflate_state.heap+2*eax],cx
554
	mov [edi+deflate_state.heap+4*eax],ecx
560
popad
555
popad
561
	ret
556
	ret
562
endp
557
endp
Line 563... Line 558...
563
 
558
 
Line 589... Line 584...
589
	xbits dd ? ;int ;extra bits
584
	xbits dd ? ;int ;extra bits
590
	f     dw ? ;uint_16 ;frequency
585
	f     dw ? ;uint_16 ;frequency
591
	overflow dd 0 ;int ;number of elements with bit length too large
586
	overflow dd 0 ;int ;number of elements with bit length too large
592
endl
587
endl
593
pushad
588
pushad
594
	zlib_debug 'gen_bitlen'
-
 
595
	mov edi,[s]
589
	mov edi,[s]
596
	mov edx,[desc]
590
	mov edx,[desc]
597
	mov eax,[edx+tree_desc.dyn_tree]
591
	mov eax,[edx+tree_desc.dyn_tree]
598
	mov [tree],eax
592
	mov [tree],eax
599
	mov eax,[edx+tree_desc.max_code]
593
	mov eax,[edx+tree_desc.max_code]
Line 620... Line 614...
620
 
614
 
621
	; In a first pass, compute the optimal bit lengths (which may
615
	; In a first pass, compute the optimal bit lengths (which may
Line 622... Line 616...
622
	; overflow in the case of the bit length tree).
616
	; overflow in the case of the bit length tree).
623
 
617
 
624
	mov eax,[edi+deflate_state.heap_max]
618
	mov eax,[edi+deflate_state.heap_max]
625
	movzx eax,word[edi+deflate_state.heap+2*eax]
619
	mov eax,[edi+deflate_state.heap+4*eax]
626
	imul eax,sizeof.ct_data
620
	imul eax,sizeof.ct_data
Line 627... Line 621...
627
	add eax,[tree]
621
	add eax,[tree]
Line 632... Line 626...
632
	mov [h],eax
626
	mov [h],eax
633
	.cycle1:
627
	.cycle1:
634
	cmp dword[h],HEAP_SIZE
628
	cmp dword[h],HEAP_SIZE
635
	jge .cycle1end ;for (..;..<..;..)
629
	jge .cycle1end ;for (..;..<..;..)
636
		mov eax,[h]
630
		mov eax,[h]
637
		movzx ecx,word[edi+deflate_state.heap+2*eax]
631
		mov ecx,[edi+deflate_state.heap+4*eax]
638
		;ecx = n
632
		;ecx = n
639
		mov eax,sizeof.ct_data
633
		mov eax,sizeof.ct_data
640
		imul eax,ecx
634
		imul eax,ecx
641
		add eax,[tree]
635
		add eax,[tree]
642
		movzx eax,word[eax+Dad]
636
		movzx eax,word[eax+Dad]
Line 750... Line 744...
750
		.cycle4: ;while (..!=0)
744
		.cycle4: ;while (..!=0)
751
		cmp ecx,0
745
		cmp ecx,0
752
		je .cycle4end
746
		je .cycle4end
753
			dec dword[h]
747
			dec dword[h]
754
			mov eax,[h]
748
			mov eax,[h]
755
			movzx eax,word[edi+deflate_state.heap+2*eax]
749
			mov eax,[edi+deflate_state.heap+4*eax]
756
			mov [m],eax ;m = s.heap[--h]
750
			mov [m],eax ;m = s.heap[--h]
757
			cmp eax,[max_code]
751
			cmp eax,[max_code]
758
			jg .cycle4 ;if (..>..) continue
752
			jg .cycle4 ;if (..>..) continue
759
			mov esi,[m]
753
			mov esi,[m]
760
			imul esi,sizeof.ct_data
754
			imul esi,sizeof.ct_data
Line 802... Line 796...
802
	bits   dd 1 ;int ;bit index
796
	bits   dd 1 ;int ;bit index
803
	next_code rw MAX_BITS+1 ;uint_16[] ;next code value for each bit length
797
	next_code rw MAX_BITS+1 ;uint_16[] ;next code value for each bit length
804
endl
798
endl
805
	; The distribution counts are first used to generate the code values
799
	; The distribution counts are first used to generate the code values
806
	; without bit reversal.
800
	; without bit reversal.
807
	zlib_debug 'gen_codes'
-
 
808
	mov ebx,ebp
801
	mov ebx,ebp
809
	sub ebx,2*(MAX_BITS+1)
802
	sub ebx,2*(MAX_BITS+1)
Line 810... Line 803...
810
 
803
 
811
	.cycle0: ;for (..;..<=..;..)
804
	.cycle0: ;for (..;..<=..;..)
Line 910... Line 903...
910
		cmp word[edx+Freq],0
903
		cmp word[edx+Freq],0
911
		je @f ;if (..!=0)
904
		je @f ;if (..!=0)
912
			inc dword[edi+deflate_state.heap_len]
905
			inc dword[edi+deflate_state.heap_len]
913
			mov eax,[edi+deflate_state.heap_len]
906
			mov eax,[edi+deflate_state.heap_len]
914
			mov [max_code],ecx
907
			mov [max_code],ecx
915
			mov [edi+deflate_state.heap+2*eax],cx
908
			mov dword[edi+deflate_state.heap+4*eax],ecx
916
			mov byte[edi+deflate_state.depth+ecx],0
909
			mov byte[edi+deflate_state.depth+ecx],0
917
			jmp .end0
910
			jmp .end0
918
align 4
911
align 4
919
		@@: ;else
912
		@@: ;else
920
			mov word[edx+Len],0
913
			mov word[edx+Len],0
Line 939... Line 932...
939
		jge @f
932
		jge @f
940
			inc dword[max_code]
933
			inc dword[max_code]
941
			mov eax,[max_code]
934
			mov eax,[max_code]
942
		@@:
935
		@@:
943
		mov ecx,[edi+deflate_state.heap_len]
936
		mov ecx,[edi+deflate_state.heap_len]
944
		mov [edi+deflate_state.heap+2*ecx],ax
937
		mov [edi+deflate_state.heap+4*ecx],eax
945
		mov [node],eax
938
		mov [node],eax
946
		imul eax,sizeof.ct_data
939
		imul eax,sizeof.ct_data
947
		add eax,[tree]
940
		add eax,[tree]
948
		mov word[eax+Freq],1
941
		mov word[eax+Freq],1
949
		mov eax,[node]
942
		mov eax,[node]
Line 987... Line 980...
987
		movzx edx,word[eax]
980
		movzx edx,word[eax]
988
		mov [m],edx ;m = node of next least frequency
981
		mov [m],edx ;m = node of next least frequency
Line 989... Line 982...
989
 
982
 
990
		mov eax,[edi+deflate_state.heap_max]
983
		mov eax,[edi+deflate_state.heap_max]
991
		dec eax
984
		dec eax
992
		mov [edi+deflate_state.heap+2*eax],cx ;keep the nodes sorted by frequency
985
		mov [edi+deflate_state.heap+4*eax],ecx ;keep the nodes sorted by frequency
993
		dec eax
986
		dec eax
994
		mov [edi+deflate_state.heap_max],eax
987
		mov [edi+deflate_state.heap_max],eax
Line 995... Line 988...
995
		mov [edi+deflate_state.heap+2*eax],dx
988
		mov [edi+deflate_state.heap+4*eax],edx
996
 
989
 
997
		; Create a new node father of n and m
990
		; Create a new node father of n and m
998
		;;mov edx,[m]
991
		;;mov edx,[m]
Line 1038... Line 1031...
1038
;                    node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
1031
;                    node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
1039
;        }
1032
;        }
1040
;end if
1033
;end if
1041
		; and insert the new node in the heap
1034
		; and insert the new node in the heap
1042
		mov ecx,[node]
1035
		mov ecx,[node]
1043
		mov [edi+deflate_state.heap+2*SMALLEST],cx
1036
		mov [edi+deflate_state.heap+4*SMALLEST],ecx
1044
		inc dword[node]
1037
		inc dword[node]
1045
		stdcall pqdownheap, edi, [tree], SMALLEST
1038
		stdcall pqdownheap, edi, [tree], SMALLEST
1046
		cmp dword[edi+deflate_state.heap_len],2
1039
		cmp dword[edi+deflate_state.heap_len],2
1047
		jge .cycle3 ;while (..>=..)
1040
		jge .cycle3 ;while (..>=..)
Line 1048... Line 1041...
1048
 
1041
 
1049
	mov cx,[edi+deflate_state.heap+2*SMALLEST]
1042
	mov ecx,[edi+deflate_state.heap+4*SMALLEST]
1050
	dec dword[edi+deflate_state.heap_max]
1043
	dec dword[edi+deflate_state.heap_max]
1051
	mov eax,[edi+deflate_state.heap_max]
1044
	mov eax,[edi+deflate_state.heap_max]
Line 1052... Line 1045...
1052
	mov [edi+deflate_state.heap+2*eax],cx
1045
	mov [edi+deflate_state.heap+4*eax],ecx
1053
 
1046
 
Line 1054... Line 1047...
1054
	; At this point, the fields freq and dad are set. We can now
1047
	; At this point, the fields freq and dad are set. We can now
Line 1081... Line 1074...
1081
	count     dd 0 ;int ;repeat count of the current code
1074
	count     dd 0 ;int ;repeat count of the current code
1082
	max_count dd 7 ;int ;max repeat count
1075
	max_count dd 7 ;int ;max repeat count
1083
	min_count dd 4 ;int ;min repeat count
1076
	min_count dd 4 ;int ;min repeat count
1084
endl
1077
endl
1085
	mov edi,[s]
1078
	mov edi,[s]
1086
	zlib_debug 'scan_tree'
-
 
1087
	mov eax,[tree]
1079
	mov eax,[tree]
1088
	movzx eax,word[eax+Len]
1080
	movzx eax,word[eax+Len]
1089
	mov [nextlen],eax
1081
	mov [nextlen],eax
1090
	test eax,eax
1082
	test eax,eax
1091
	jnz @f ;if (..==0)
1083
	jnz @f ;if (..==0)
Line 1202... Line 1194...
1202
	count     dd 0 ;int ;repeat count of the current code
1194
	count     dd 0 ;int ;repeat count of the current code
1203
	max_count dd 7 ;int ;max repeat count
1195
	max_count dd 7 ;int ;max repeat count
1204
	min_count dd 4 ;int ;min repeat count
1196
	min_count dd 4 ;int ;min repeat count
1205
endl
1197
endl
1206
	mov edi,[s]
1198
	mov edi,[s]
1207
	zlib_debug 'send_tree'
-
 
1208
	; *** tree[max_code+1].Len = -1 ;guard already set
1199
	; *** tree[max_code+1].Len = -1 ;guard already set
1209
	mov eax,[tree]
1200
	mov eax,[tree]
1210
	movzx eax,word[eax+Len]
1201
	movzx eax,word[eax+Len]
1211
	mov [nextlen],eax
1202
	mov [nextlen],eax
1212
	xor ecx,ecx
1203
	xor ecx,ecx
1213
	test eax,eax
1204
	test eax,eax
1214
	jnz .cycle0 ;if (..==0)
1205
	jnz .cycle0 ;if (..==0)
1215
		mov dword[max_count],138
1206
		mov dword[max_count],138
1216
		mov dword[min_count],3
1207
		mov dword[min_count],3
1217
 
-
 
1218
align 4
1208
align 4
1219
	.cycle0: ;for (..;..<=..;..)
1209
	.cycle0: ;for (..;..<=..;..)
1220
	cmp ecx,[max_code]
1210
	cmp ecx,[max_code]
1221
	jg .cycle0end
1211
	jg .cycle0end
1222
		mov eax,[nextlen]
1212
		mov eax,[nextlen]
Line 1320... Line 1310...
1320
 
1310
 
1321
; ===========================================================================
1311
; ===========================================================================
1322
; Construct the Huffman tree for the bit lengths and return the index in
1312
; Construct the Huffman tree for the bit lengths and return the index in
Line 1323... Line -...
1323
; bl_order of the last bit length code to send.
-
 
1324
 
1313
; bl_order of the last bit length code to send.
1325
;int (s)
1314
 
1326
;    deflate_state* s
1315
;int (deflate_state* s)
1327
align 4
1316
align 4
1328
proc build_bl_tree uses edi, s:dword
1317
proc build_bl_tree uses edi, s:dword
1329
locals
1318
locals
Line 1383... Line 1372...
1383
;    deflate_state* s
1372
;    deflate_state* s
1384
;    int lcodes, dcodes, blcodes ;number of codes for each tree
1373
;    int lcodes, dcodes, blcodes ;number of codes for each tree
1385
align 4
1374
align 4
1386
proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, blcodes:dword
1375
proc send_all_trees uses eax ebx ecx edi, s:dword, lcodes:dword, dcodes:dword, blcodes:dword
1387
;ecx = index in bl_order
1376
;ecx = index in bl_order
1388
	zlib_debug 'send_all_trees'
-
 
1389
	cmp dword[lcodes],257
1377
	cmp dword[lcodes],257
1390
	jl @f
1378
	jl @f
1391
	cmp dword[dcodes],1
1379
	cmp dword[dcodes],1
1392
	jl @f
1380
	jl @f
1393
	cmp dword[blcodes],4
1381
	cmp dword[blcodes],4
Line 1477... Line 1465...
1477
endp
1465
endp
Line 1478... Line 1466...
1478
 
1466
 
1479
; ===========================================================================
1467
; ===========================================================================
Line 1480... Line -...
1480
; Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
-
 
1481
 
1468
; Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
1482
;void (s)
1469
 
1483
;    deflate_state* s
1470
;void (deflate_state* s)
1484
align 4
1471
;align 4
1485
proc _tr_flush_bits, s:dword
1472
;proc _tr_flush_bits, s:dword
1486
	stdcall bi_flush, [s]
1473
;	stdcall bi_flush, [s]
-
 
1474
;	ret
-
 
1475
;endp
Line 1487... Line 1476...
1487
	ret
1476
 
1488
endp
1477
_tr_flush_bits equ bi_flush
1489
 
1478
 
Line 1490... Line -...
1490
; ===========================================================================
-
 
1491
; Send one empty static block to give enough lookahead for inflate.
1479
; ===========================================================================
1492
; This takes 10 bits, of which 7 may remain in the bit buffer.
1480
; Send one empty static block to give enough lookahead for inflate.
1493
 
1481
; This takes 10 bits, of which 7 may remain in the bit buffer.
1494
;void (s)
1482
 
1495
;    deflate_state* s
1483
;void (deflate_state* s)
1496
align 4
1484
align 4
Line 1521... Line 1509...
1521
	static_lenb dd ? ;opt_len and static_len in bytes
1509
	static_lenb dd ? ;opt_len and static_len in bytes
1522
	max_blindex dd 0 ;int ;index of last bit length code of non zero freq
1510
	max_blindex dd 0 ;int ;index of last bit length code of non zero freq
1523
endl
1511
endl
1524
	; Build the Huffman trees unless a stored block is forced
1512
	; Build the Huffman trees unless a stored block is forced
1525
	mov edi,[s]
1513
	mov edi,[s]
1526
	zlib_debug '_tr_flush_block'
-
 
1527
	cmp word[edi+deflate_state.level],0
1514
	cmp word[edi+deflate_state.level],0
1528
	jle .end0 ;if (..>0)
1515
	jle .end0 ;if (..>0)
Line 1529... Line 1516...
1529
 
1516
 
1530
		; Check if the file is binary or text
1517
		; Check if the file is binary or text
Line 1726... Line 1713...
1726
 
1713
 
1727
if TRUNCATE_BLOCK eq 1
1714
if TRUNCATE_BLOCK eq 1
1728
	; Try to guess if it is profitable to stop the current block here
1715
	; Try to guess if it is profitable to stop the current block here
1729
	mov eax,[edi+deflate_state.last_lit]
1716
	mov eax,[edi+deflate_state.last_lit]
1730
	and eax,0x1fff
-
 
1731
	cmp eax,0
1717
	and eax,0x1fff
1732
	jne .end1
1718
	jnz .end1
1733
	cmp word[edi+deflate_state.level],2
1719
	cmp word[edi+deflate_state.level],2
1734
	jle .end1 ;if (..==.. && ..>..)
1720
	jle .end1 ;if (..==0 && ..>..)
1735
	; Compute an upper bound for the compressed length
1721
	; Compute an upper bound for the compressed length
1736
;        ulg out_length = (ulg)s->last_lit*8L;
1722
;        ulg out_length = (ulg)s->last_lit*8L;
1737
;        ulg in_length = (ulg)((long)s->strstart - s->block_start);
1723
;        ulg in_length = (ulg)((long)s->strstart - s->block_start);
1738
;        int dcode;
1724
;        int dcode;
Line 1773... Line 1759...
1773
locals
1759
locals
1774
	dist  dd ? ;unsigned ;distance of matched string
1760
	dist  dd ? ;unsigned ;distance of matched string
1775
	lc    dd ? ;int      ;match length or unmatched char (if dist == 0)
1761
	lc    dd ? ;int      ;match length or unmatched char (if dist == 0)
1776
	lx    dd 0 ;unsigned ;running index in l_buf
1762
	lx    dd 0 ;unsigned ;running index in l_buf
1777
	u_code dd ? ;unsigned ;the code to send
1763
	u_code dd ? ;unsigned ;the code to send
1778
	extra  dd ? ;int      ;number of extra bits to send
-
 
1779
endl
1764
endl
1780
	mov edi,[s]
1765
	mov edi,[s]
1781
	cmp dword[edi+deflate_state.last_lit],0
1766
	cmp dword[edi+deflate_state.last_lit],0
1782
	je .end0 ;if (..!=0)
1767
	je .end0 ;if (..!=0)
1783
	.cycle0: ; do
1768
	.cycle0: ; do
Line 1803... Line 1788...
1803
			movzx eax,byte[eax]
1788
			movzx eax,byte[eax]
1804
			mov [u_code],eax
1789
			mov [u_code],eax
1805
			add eax,LITERALS+1
1790
			add eax,LITERALS+1
1806
			send_code edi, eax, [ltree] ;send the length code
1791
			send_code edi, eax, [ltree] ;send the length code
1807
			mov eax,[u_code]
1792
			mov eax,[u_code]
1808
			shl eax,2
-
 
1809
			add eax,extra_lbits
1793
			mov eax,[4*eax+extra_lbits]
1810
			mov eax,[eax]
1794
			test eax,eax
1811
			mov [extra],eax
1795
			jz @f ;if (..!=0)
1812
			cmp eax,0
1796
				push eax ;extra
1813
			je @f ;if (..!=0)
-
 
1814
				mov eax,[u_code]
1797
				mov eax,[u_code]
1815
				shl eax,2
-
 
1816
				add eax,base_length
1798
				mov eax,[4*eax+base_length]
1817
				mov eax,[eax]
-
 
1818
				sub [lc],eax
1799
				sub [lc],eax
1819
				stdcall send_bits, edi, [lc], [extra] ;send the extra length bits
1800
				stdcall send_bits, edi, [lc] ;, ... ;send the extra length bits
1820
			@@:
1801
			@@:
1821
			dec dword[dist] ;dist is now the match distance - 1
1802
			dec dword[dist] ;dist is now the match distance - 1
1822
			d_code [dist]
1803
			d_code [dist]
1823
			mov [u_code],eax
1804
			mov [u_code],eax
1824
			cmp eax,D_CODES
1805
			cmp eax,D_CODES
1825
			jl @f
1806
			jl @f
1826
				zlib_assert 'bad d_code' ;Assert(..<..)
1807
				zlib_assert 'bad d_code' ;Assert(..<..)
1827
			@@:
1808
			@@:
1828
			send_code edi, [u_code], [dtree] ;send the distance code
1809
			send_code edi, [u_code], [dtree] ;send the distance code
1829
			mov eax,[u_code]
1810
			mov eax,[u_code]
1830
			shl eax,2
-
 
1831
			add eax,extra_dbits
1811
			mov eax,[4*eax+extra_dbits]
1832
			mov eax,[eax]
1812
			test eax,eax
1833
			mov [extra],eax
1813
			jz .end1 ;if (..!=0)
1834
			cmp eax,0
1814
				push eax ;extra
1835
			je .end1 ;if (..!=0)
-
 
1836
				mov eax,[u_code]
1815
				mov eax,[u_code]
1837
				shl eax,2
-
 
1838
				add eax,base_dist
1816
				mov eax,[4*eax+base_dist]
1839
				mov eax,[eax]
-
 
1840
				sub [dist],eax
1817
				sub [dist],eax
1841
				stdcall send_bits, edi, [dist], [extra] ;send the extra distance bits
1818
				stdcall send_bits, edi, [dist] ;, ... ;send the extra distance bits
1842
		.end1: ;literal or match pair ?
1819
		.end1: ;literal or match pair ?
Line 1843... Line 1820...
1843
 
1820
 
1844
		; Check that the overlay between pending_buf and d_buf+l_buf is ok:
1821
		; Check that the overlay between pending_buf and d_buf+l_buf is ok:
1845
		mov eax,[lx]
1822
		mov eax,[lx]
Line 1952... Line 1929...
1952
;unsigned (code, len)
1929
;unsigned (code, len)
1953
;    unsigned code ;the value to invert
1930
;    unsigned code ;the value to invert
1954
;    int len       ;its bit length
1931
;    int len       ;its bit length
1955
align 4
1932
align 4
1956
proc bi_reverse uses ebx, p1code:dword, len:dword
1933
proc bi_reverse uses ebx, p1code:dword, len:dword
1957
	zlib_debug 'bi_reverse'
-
 
1958
	xor eax,eax
1934
	xor eax,eax
1959
	@@: ;do
1935
	@@: ;do
1960
		mov ebx,[p1code]
1936
		mov ebx,[p1code]
1961
		and ebx,1
1937
		and ebx,1
1962
		or eax,ebx
1938
		or eax,ebx
Line 1996... Line 1972...
1996
endp
1972
endp
Line 1997... Line 1973...
1997
 
1973
 
1998
; ===========================================================================
1974
; ===========================================================================
Line 1999... Line -...
1999
; Flush the bit buffer and align the output on a byte boundary
-
 
2000
 
1975
; Flush the bit buffer and align the output on a byte boundary
2001
;void (s)
1976
 
2002
;    deflate_state* s
1977
;void (deflate_state* s)
2003
align 4
1978
align 4
2004
proc bi_windup uses eax ecx edi, s:dword
1979
proc bi_windup uses eax ecx edi, s:dword
2005
	mov edi,[s]
1980
	mov edi,[s]