4 // Compression algorithm: RDC
\r
5 // Algorithm developed by Ed Ross
\r
6 function RDC_decompress(var source,dest; size: Word): Word;
\r
8 // Compression algorithm: LZSS
\r
9 // Algorithm developed by Lempel-Ziv-Storer-Szymanski
\r
10 function LZSS_decompress(var source,dest; size: Word): Word;
\r
12 // Compression algorithm: LZW
\r
13 // Algorithm developed by Lempel-Ziv-Welch
\r
14 function LZW_decompress(var source,dest): Word;
\r
16 // Compression algorithm: SixPack
\r
17 // Algorithm developed by Philip G. Gage
\r
18 function SIXPACK_decompress(var source,dest; size: Word): Word;
\r
20 // Compression algorithm: aPack
\r
21 // Algorithm developed by Joergen Ibsen
\r
22 function APACK_decompress(var source,dest): Longint;
\r
27 WORKMEM_SIZE = 64*1024;
\r
30 work_mem: array[0..PRED(WORKMEM_SIZE)] of Byte;
\r
31 ibufCount,ibufSize: Word;
\r
32 input_size,output_size: Word;
\r
33 input_ptr,output_ptr,work_ptr: Pointer;
\r
36 ibuf_idx,ibuf_end,obuf_idx,obuf_src: Pointer;
\r
37 ctrl_bits,ctrl_mask,
\r
38 command,count,offs: Word;
\r
40 procedure RDC_decode; assembler;
\r
66 @@2: mov ax,ctrl_bits
\r
166 @@7: mov eax,obuf_idx
\r
171 function RDC_decompress(var source,dest; size: Word): Word;
\r
173 input_ptr := @source;
\r
174 output_ptr := @dest;
\r
175 input_size := size;
\r
177 RDC_decompress := output_size;
\r
185 procedure GetChar; assembler;
\r
194 mov al,byte ptr [edi+ebx]
\r
206 procedure PutChar; assembler;
\r
212 mov byte ptr [edi+ebx],al
\r
219 procedure LZSS_decode; assembler;
\r
242 mov byte ptr [esi],al
\r
264 mov al,byte ptr [esi+ebx]
\r
266 mov byte ptr [esi],al
\r
278 function LZSS_decompress(var source,dest; size: Word): Word;
\r
281 input_ptr := @source;
\r
282 output_ptr := @dest;
\r
283 work_ptr := @work_mem;
\r
284 input_size := size;
\r
285 FillChar(work_ptr^,WORKMEM_SIZE,0);
\r
287 LZSS_decompress := output_size;
\r
292 le6a,le6c,le6e,le70,le72,le74,le78,
\r
293 le7a_0,le7a_2,le7a_4,le7a_6,le7a_8,le82a,le82b: Word;
\r
295 procedure NextCode; assembler;
\r
322 and ax,[ebx+le7a_0]
\r
325 function LZW_decode: Word; assembler;
\r
363 mov byte ptr [edi],al
\r
396 mov byte ptr [edi],al
\r
421 @@9: mov output_size,ax
\r
424 function LZW_decompress(var source,dest): Word;
\r
426 input_ptr := @source;
\r
427 output_ptr := @dest;
\r
428 work_ptr := @work_mem;
\r
430 LZW_decompress := output_size;
\r
441 CODESPERRANGE = MAXCOPY-MINCOPY+1;
\r
442 MAXCHAR = FIRSTCODE+COPYRANGES*CODESPERRANGE-1;
\r
443 SUCCMAX = MAXCHAR+1;
\r
444 TWICEMAX = 2*MAXCHAR+1;
\r
445 MAXBUF = PRED(64*1024);
\r
446 MAXDISTANCE = 21389;
\r
447 MAXSIZE = 21389+MAXCOPY;
\r
450 BitValue: array[1..14] of Word = (1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192);
\r
451 CopyBits: array[0..PRED(COPYRANGES)] of Word = (4,6,8,10,12,14);
\r
452 CopyMin: array[0..PRED(COPYRANGES)] of Word = (0,16,80,336,1360,5456);
\r
455 leftC,rghtC: array[0..MAXCHAR] of Word;
\r
456 dad,freq: array[0..TWICEMAX] of Word;
\r
457 index,ibitCount,ibitBuffer,obufCount: Word;
\r
459 procedure InitTree; assembler;
\r
470 mov word ptr dad[edi],ax
\r
471 mov word ptr freq[edi],cx
\r
482 mov word ptr leftC[edi],ax
\r
484 mov word ptr rghtC[edi],ax
\r
491 procedure UpdateFreq(a,b: Word); assembler;
\r
497 mov bx,word ptr freq[edi]
\r
500 add bx,word ptr freq[edi]
\r
503 mov dx,word ptr dad[edi]
\r
506 mov word ptr freq[edi],bx
\r
512 mov di,word ptr dad[edi]
\r
515 mov bx,word ptr leftC[edi]
\r
520 mov bx,word ptr rghtC[edi]
\r
525 mov bx,word ptr leftC[edi]
\r
532 cmp word ptr freq[edi],bx
\r
545 procedure UpdateModel(code: Word); assembler;
\r
554 mov cx,word ptr freq[edi]
\r
556 mov word ptr freq[edi],cx
\r
559 cmp word ptr dad[edi],cx
\r
561 mov dx,word ptr dad[edi]
\r
567 mov si,word ptr [edi]
\r
573 mov si,word ptr rghtC[edi]
\r
584 mov ax,word ptr dad[edi]
\r
588 cmp word ptr leftC[edi],dx
\r
591 mov si,word ptr rghtC[edi]
\r
593 @@3: mov si,word ptr leftC[edi]
\r
598 mov ax,word ptr freq[edi]
\r
603 cmp cx,word ptr freq[edi]
\r
608 cmp word ptr leftC[edi],dx
\r
611 mov word ptr rghtC[edi],bx
\r
615 mov word ptr leftC[edi],bx
\r
616 @@6: lea edi,[leftC]
\r
621 cmp word ptr [edi],bx
\r
623 mov word ptr [edi],si
\r
626 mov cx,word ptr rghtC[edi]
\r
630 mov word ptr rghtC[edi],si
\r
631 mov cx,word ptr leftC[edi]
\r
635 mov word ptr dad[edi],dx
\r
638 mov word ptr dad[edi],ax
\r
647 mov bx,word ptr dad[edi]
\r
650 mov dx,word ptr dad[edi]
\r
656 function InputCode(bits: Word): Word; assembler;
\r
661 @@1: cmp ibitCount,0
\r
663 cmp ibufCount,MAXBUF
\r
667 @@2: mov edi,input_ptr
\r
678 @@4: cmp ibitBuffer,7fffh
\r
684 mov ax,word ptr BitValue[edi]
\r
686 @@5: shl ibitBuffer,1
\r
693 function Uncompress: Word; assembler;
\r
720 mov bx,word ptr rghtC[edi]
\r
724 mov bx,word ptr leftC[edi]
\r
738 procedure SIXPACK_decode; assembler;
\r
749 @@1: cmp ax,TERMINATE
\r
765 @@2: mov edi,work_ptr
\r
776 @@3: sub ax,FIRSTCODE
\r
779 mov bx,CODESPERRANGE
\r
791 mov bx,word ptr CopyBits[edi]
\r
798 add ax,word ptr CopyMin[edi]
\r
807 @@5: mov edi,work_ptr
\r
809 mov al,byte ptr [edi]
\r
815 mov byte ptr [edi],al
\r
822 @@6: mov edi,work_ptr
\r
825 mov al,byte ptr [edi]
\r
828 mov byte ptr [edi],al
\r
845 @@9: call Uncompress
\r
847 @@10: mov bx,obufCount
\r
851 function SIXPACK_decompress(var source,dest; size: Word): Word;
\r
853 input_ptr := @source;
\r
854 output_ptr := @dest;
\r
855 work_ptr := @work_mem;
\r
856 input_size := size;
\r
858 SIXPACK_decompress := output_size;
\r
861 function APACK_decompress(var source,dest): Longint; assembler;
\r
961 @@22: xchg eax,@dummy
\r
962 @@23: mov eax,@dummy
\r
969 @@25: sub edi,[dest]
\r