blob: 951a8ad00d4703bd6ada8eb717a05f8c2874adbe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
{$MACRO ON}
(******************************************************************************
*
* Copyright (c) 1994-2001 Palm, Inc. or its subsidiaries.
* All rights reserved.
*
* File: Lz77Mgr.h
*
* Release: Palm OS SDK 4.0 (63220)
*
* History:
* 11/01/99 Created by Michel Turcotte
* Initial revision based on InetLib
*
*****************************************************************************)
unit lz77mgr;
interface
uses palmos, libtraps, errorbase, systemresources;
//
// Common PalmOS and Windows section
//
const
Lz77VerID = 1;
Lz77LastSupportedVerID = 1;
lz77Compress = True;
lz77Expand = False;
type
Lz77ErrorType = Err;
(********************************************************************
* Error codes
********************************************************************)
const
lz77Success = $00;
// Non Fatal Errors
lz77ErrNonFatalFirstErr = lz77ErrorClass or $00;
lz77ErrNonFatalInputBufferIncomplete = lz77ErrorClass or $01;
lz77ErrNonFatalOutputBufferFull = lz77ErrorClass or $02;
lz77ErrNonFatalLastErr = lz77ErrorClass or $7F;
// Fatal Errors
lz77ErrFatalFirstErr = lz77ErrorClass or $80;
lz77ErrFatalUnfinishedInputBuffer = lz77ErrorClass or $80;
lz77ErrFatalInputBufferIncomplete = lz77ErrorClass or $81;
lz77ErrFatalInputBufferInvalid = lz77ErrorClass or $82;
lz77ErrFatalMemAllocation = lz77ErrorClass or $83;
lz77ErrFatalHandleInvalid = lz77ErrorClass or $84;
lz77ErrFatalCantChangeToCompress = lz77ErrorClass or $85;
lz77ErrFatalUnknownVersion = lz77ErrorClass or $86;
lz77ErrFatalOutputBufferTooSmall = lz77ErrorClass or $87;
lz77ErrFatalInvalidArgument = lz77ErrorClass or $88;
lz77ErrFatalLastErr = lz77ErrorClass or $FF;
function lz77ErrIsFatal(err: Lz77ErrorType): Boolean;
//
// Specific PalmOS section
//
// Creator. Used for both the database that contains the LZ77 Library and
// it's features for the feature manager.
const
lz77Creator = sysFileCLz77Lib; // Lz77 Library creator
lz77LibName = 'Lz77.lib'; // pass in to SysLibFind()
(********************************************************************
* LZ77 Library functions.
********************************************************************)
const
lz77LibTrapChunk = sysLibTrapCustom;
lz77LibTrapMaxBufferSize = sysLibTrapCustom + 1;
lz77LibTrapBufferGetInfo = sysLibTrapCustom + 2;
lz77LibTrapBufferSetInfo = sysLibTrapCustom + 3;
//--------------------------------------------------
// Library initialization, shutdown, sleep and wake
//--------------------------------------------------
function Lz77LibOpen(
libRefnum: UInt16; // Palm OS reference calling number
var lz77HandleP: MemHandle; // <- Pointer to returning LZ77 handle (NULL for error)
compressFlag: Boolean; // -> TRUE = Compress; FALSE = Expand
sourceSize: UInt32; // -> Source size in bytes
var destHP: MemHandle; // <-> If (*destHP != NULL) => use pre allocated memory
// (*destHP and *destSizeP)
// If (*destHP == NULL) => allocate memory in *destHP
var destSizeP: UInt32; // <-> If (*destSizeP ==0) THEN *destP must be NULL
// => Lz77Open will calculate maximum buffer size
// based on compressFlag and sourceSize
// If (*destSizeP !=0) THEN it indicate
// the size in bytes of the destination buffer
useVerNum: UInt16; // -> if (useVerNum !=0) THEN Use Version numbering
// (Compress will write the value useVerNum in the
// output buffer Expand will verify if the Version
// in the source buffer is compatible)
var primerP: UInt8; // -> if (compressFlag ==lz77Compress)
// UncompressPrimer buffer pointer
// else CompressPrimer buffer pointer
// Must be valid compressed lz77 data
// compressed without a primer.
// NULL means no primer
primerL: UInt32; // -> Byte length of primer
processedPrimerL: UInt32 // -> Byte length of processed primer
): Err; syscall sysLibTrapOpen;
// Note: The output buffer must be large enough to include the emtire processed primer.
// When Expanding, the compressed primer is passed to the Open routine and
// the output buffer must be large enough to contain the expanded primer.
function Lz77LibClose(
libRefnum: UInt16; // Palm OS reference calling number
lz77Handle: MemHandle; // -> Lz77 Handle
var ResultingSizeP: UInt32 // <- Size in bytes of output generated buffer
// Output buffer will be resized to the resulting size
// if Lz77Open have allocated the output buffer.
// Output buffer must be free by the calling application
): Err; syscall sysLibTrapClose;
function Lz77LibSleep(libRefnum: UInt16): Err; syscall sysLibTrapSleep;
function Lz77LibWake(libRefnum: UInt16): Err; syscall sysLibTrapWake;
function Lz77LibChunk(
libRefnum: UInt16; // Palm OS reference calling number
lz77Handle: MemHandle; // -> Lz77 Handle
var sourceP: Int8; // -> Source buffer pointer
sourceSize: UInt32; // -> Source buffer Size (bytes)
var sourceBitReadOffset: UInt32 // <-> Next bit to read from source
): Err; syscall lz77LibTrapChunk;
function Lz77LibMaxBufferSize(
libRefnum: UInt16; // Palm OS reference calling number
compressFlag: Boolean; // -> TRUE = Compress; FALSE = Expand
sourceSize: UInt32; // -> Size of Source buffer
var maxBufferSizeP: UInt32 // <- result size pointer
): Err; syscall lz77LibTrapMaxBufferSize;
function Lz77LibBufferGetInfo(
libRefnum: UInt16; // Palm OS reference calling number
lz77Handle: MemHandle; // -> Lz77 Handle
var compressFlagP: Boolean; // <- Get compressFlag (true = compress mode; false = expand mode)
var bufferHP: MemHandle; // <- Get the Pointer to the accumulated destination buffer
var bufferByteSizeP: UInt32; // <- Get destination buffer size in bytes
var destBitOffsetP: UInt32 // <- Get destination bit offset
): Err; syscall lz77LibTrapBufferGetInfo;
function Lz77LibBufferSetInfo(
libRefnum: UInt16; // Palm OS reference calling number
lz77Handle: MemHandle; // -> Lz77 Handle
compressFlag: Boolean; // -> Set compressFlag (true = compress mode; false = expand mode)
destH: MemHandle; // -> Set a Pointer to the accumulated destination buffer
destByteSize: UInt32; // -> Set destination buffer size in bytes
destBitOffset: UInt32 // -> Set destination bit offset
): Err; syscall lz77LibTrapBufferSetInfo;
implementation
function lz77ErrIsFatal(err: Lz77ErrorType): Boolean;
begin
lz77ErrIsFatal := (err <> lz77Success) and ((err < lz77ErrNonFatalFirstErr) or (err > lz77ErrNonFatalLastErr));
end;
end.
|