home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
PASCAL
/
TPLZH026.ZIP
/
TPLZH.DOC
< prev
next >
Wrap
Text File
|
1993-08-05
|
12KB
|
332 lines
═══════════════════════════════════════════════════════════════════════
Requestable from : Joe Jared of 1:125/1212@Fidonet.ORG
BBS (510) 834-6906 V.32bis/HST 8n1
(European Guard tones enabled)
File request name : TPLZH (Magic names only please)
Discription : (V0.26) Huffman Compression Engine w/TP {$O+}
: interface. Atari ST/TT, and IBM.
Downloadable name : TPLZH@##.zip where @ is the major release number and
## the minor release.
Topics:
- What's new
- How to use this utility in your programs
- Legalities and distribution limitations
- Version history: Refer to TPLZH.HST
═══════════════════════════════════════════════════════════════════════
V0.26 (TPLZH026.Zip)
Bug fix for wild write in DS memory (IBM version)
Abandoned TP 5.5 compatibility
═══════════════════════════════════════════════════════════════════════
- Implementation: (IBM)
The following is a basic structure of how the engine operates:
( Your program ) ------------\
| \---( Your program )
| +-->(Your procedure for handling input buffer)
| | (These must be far procedures)
| |+->(Your procedure for handling output buffer)
v ||
(Huffman Compression Engine)
It's generally a good idea to have some sort of display related function
in each of your iobuffer routines, and especially during initial setup.
In the examples, position progress reports keep the user from being bored.
Memory requirements:
Memory requirements are as follows:
{$M Stack, Minheap, Maxheap}
{$M 1024, 56000, 56000}
(Lzhasm.obj)
Note: This does not include sample program space.
Codespace: 3693 bytes.
Dataspace: 12 bytes
The stack is probably higher than necessary, but heap memory
is definately accurate. (Some space is currently reserved for
updates so there are no hassles Approximately 700 bytes)
This unit is overlayable, and is designed to operate best when
overlayed. (With minimum usage of data seg, it makes sense to
overlay the engine, because its entire process can be contained
in an overlay.)
The following system variables are available for your interface to play
with:
Routines available in the engine:
Public Decode, Encode ; Encode for compression, Decode for decompression.
EXTERN LZHMemSeg : WORD ; Heap pointer to LZH Structure.
(Note: No offset, because the engine expects to have an Addr:0000h)
Note that both of these are FAR pointers to procedures.
EXTERN WriteFromBuffer : FAR PTR ; External buffer handling.
EXTERN ReadToBuffer : FAR PTR ; External buffer handling.
EXTERN LZHERROR : WORD ; Errorlevel return {Future use}
(Offset into LZHMem^. allocation)
Text_Buf equ 0 ; array[0..N + F - 2] of byte; 5155 bytes
; Text_buf is not a buffer you should care about. It's placed in the top
; of the segment because it's most used.
; The following are variables you should care about.
count Equ Text_Buf +N+F ;
textsize Equ Count+4 ; LongInt = 0;
textsize Equ count +4 ; LongInt = 0;
codesize equ textsize +4 ; LongInt = 0;
inptr equ codesize +4 ; Word
inend equ inptr+2 ; word
outptr equ inend+2 ; Word
outend equ outptr+2 ; Word
Ebytes equ outend+2 ; LongInt = 0;
Inbuf equ Ebytes+4 ; IObuf
Outbuf equ Inbuf +2800h ; IObuf
═══════════════════════════════════════════════════════════════════════
- Interfacing to Turbo Pascal:
Const
N = $1000 ; {Size of string buffer}
F = 60 ; {60 Size of look-ahead buffer}
These constants are actually hard coded, but used for one important
reason. In various flavors of this engine, various buffer sizes are used.
To provide multiple flavors means the N constant needs to be flexible
in both the high level language and the low level intel-relocatable object
file. That is why the distributed engine is called '4k'. The 8 bit
variant of this engine is called 256-byte huffman compression, and produces
about 9% less compression.
type
IObuf = array[0..$2800-1] of byte; {These buffers are now FIXED!}
LZHRec = Record {Segment:0 aligned}
WorkSpace1 : Array [0..N+F-1] of byte;
count : LongInt;
textsize : LongInt;
codesize : LongInt;
inptr,inend,outptr,outend : Word;
Ebytes : Longint;
inbuf,outbuf : IObuf;
{Buffersize and position are critical}
WorkSpace : Array [0..$76c3] of byte;
{LZHASM work space} {Some space reserved}
End;
{$L LZHASM}
var
StupidAlloc : Boolean;
StupidPtr : Pointer;
These variable is to provide Segment:0 alignment for versions
of turbo Pascal prior to 6.0. Refer to notes in InitLzh.
WriteFromBuffer,
ReadToBuffer: Procedure;
These variables should "point" to your procedures for reading and
writing of LZH compressed data. Before calling any LZH Functions,
you must have the following lines of code in your routine, or some
function thereof:
{$F+}
Myprocwrite
{$F-}
begin
(Your procedure for handling data from LZHMem^.Inbuff)
end;
Myprocread
{$F-}
begin
(Your procedure for handling data from LZHMem^.Outbuff)
end;
Your startup for your program should have:
WriteFromBuffer := Myprocwrite;
ReadToBuffer := Myprocread;
The actual procedure type MUST be a far Call, but the data within
the procedure may be near.
IObuf = array[0..$2800-1] of byte; {These buffers are now FIXED!}
For your reference, preceed all variables with "LZHMem^.".
LZHRec = Record
count : LongInt; {LZHMEM^.Count}
Current position of compression of input data. This counter
will continue to count, until encode or decode is called again.
textsize : LongInt;
Size of input text data
codesize : LongInt;
Size of output code data.
These variables are available to provide user interface for
ratios.
inptr,inend,outptr,outend : Word;
Inptr points to the position of valid data in your input bufferm
as does outptr for your output buffer. These are counters to
determine where in the appropriate buffer to place the next byte
of data, and how much of your buffer is valid data.
(See example LZ.PAS for details of implementation).
inend, Outend:
These variables point to the last valid byte in the appropriate
buffer. You MUST set these values to the pointer. You can
adjust the size that the engine thinks it has by adjusting these
values. (From 0..10239]
(Again see LZ.PAS for details)
Ebytes : Longint;
EBytes is a count of total bytes to compress. You MUST set this
variable to the total number of bytes you wish to compress.
inbuf,outbuf : IObuf;
These are input/output buffers for the compression engine.
In previous versions, these were seperate from LZHMem^, but it
seemed more practical to have one call to allocate memory. If
someone complains loud enough I'll "Put em back" to seperate
independent pointers.
WorkSpace : Array [0..$8657] of byte;
{LZHASM work space}
This variable array is work space for LZHASM.OBJ. Please do
not adjust it or change the data while encode or decode is
active. If you wish to keep the space active on your heap, you
can use it in between runs for other things.
End;
LZHMem: ^LZHRec;
LZHMemSeg : WORD;
Notice that there is no offset variable. This is intentional,
and the reason is simple: SPEED!
In LZH.PAS, there is a sample routine for allocating memory that
is segment:0 aligned. The difference in memory allocated using
this method is up to 32 bytes.
(For allocations of 55k, who cares!)
procedure Encode ; compresses data
procedure Decode; decompresses data
Procedure InitLZH; Segment:0 aligned memory allocation
Procedure DInitLZH; Memory de-allocation.
(Pay attention to this section in future versions)
The proper sequence is as follows:
Set writetobuffer and readfrombuffer to point to your procedures
for handling of buffer data. Make sure that at bare minimum,
that the procedure "call" is of far type. loops within the
procedure may be near type.
{$F+}
Procedure YourProc;
{$F-}
InitLzh
If compressing:
Set LZHMEM^.Ebytes to the size of the data you wish to compress.
(If compressing)
Call encode to compress, or decode to decompress.
The memory buffers will have the decompressed data, and your
procedures will then process the data as buffers are filled.
═══════════════════════════════════════════════════════════════════════
-Legalities:
-Compression of this archive:
As far as compression type is concerned, I could personally care
less, as long as the software used to re-compress is freely
available. Please to not re-compress this archive with
crippleware, and do not add useless banner files.
The contents of this archive should contain the following: +
means compatible with language v x.xx and higher.
.model small,pascal
LZHASM.OBJ -=> The huffman compression object file (MSC 5.1+)
TPLZH.HST -=> Version history
TPLZH.DOC -=> This document.
LZ.PAS -=> Sample TP 6.0+ version
LZH.PAS -=> Base unit for all pascal platforms
LZO.PAS -=> OOPS examples for TP 6.0+
TESTLZO.PAS -=> OOPS examples for TP 6.0+
LZ.exe -=> Compiled Lz.pas using Turbo Pascal 7.0
Anything additional shall be considered twit behavior.
If this object is used in any utility you write for public
or commercial use, please give credit to the following people
in your documentation or credits banner (as applicable):
(These people always)
Haruyasu YOSHIZAKI : Original lharc program.
Kenji RIKITAKE : English translation to C
Peter Sawatzki : Pascal interface(TP 5.0+}
Wayne Sullivan : Pascal interface(TP 5.0+)
Joe Jared : Assembler optimization {TP 5.0+}
: Assembler routines for 680x0 machines.
(These people as appropriate)
Andres Cvitkovich : Object Oriented version (TP 5.5+)
-Distribution
No fee may be charged for distribution of this package, and it
CANNOT be sold for any reason. All code is property of the
developers listed.
Exceptions: The disk this program is on, may be sold for the
cost of the disk. (Not to exceed $0.70)+exact mail costs if
mailed.
CD-ROM distribution.
Unrestricted, but please either download or freq the latest
prior to distribution.
If in a shareware or commercial package, no additional charges
may be added for the use of this "module".
This is a * militantly freeware * implementation of huffman
compression.
════════════════════════════════════════════════════════════════════════