DEADSOFTWARE

701b5a29032e3615a9152440d143e09ece209a2a
[d2df-sdl.git] / imzutil.pas
1 Unit imzutil;
3 {
4 Copyright (C) 1998 by Jacques Nomssi Nzali
5 For conditions of distribution and use, see copyright notice in readme.txt
6 }
8 interface
10 {$I imzconf.inc}
12 { Type declarations }
14 type
15 {Byte = usigned char; 8 bits}
16 Bytef = byte;
17 charf = byte;
19 int = longint;
20 intf = int;
21 uInt = cardinal; { 16 bits or more }
22 uIntf = uInt;
24 Long = longint;
25 uLong = Cardinal;
26 uLongf = uLong;
28 voidp = pointer;
29 voidpf = voidp;
30 pBytef = ^Bytef;
31 pIntf = ^intf;
32 puIntf = ^uIntf;
33 puLong = ^uLongf;
35 ptr2int = uInt;
36 { a pointer to integer casting is used to do pointer arithmetic.
37 ptr2int must be an integer type and sizeof(ptr2int) must be less
38 than sizeof(pointer) - Nomssi }
40 type
41 zByteArray = array[0..(MaxInt div SizeOf(Bytef))-1] of Bytef;
42 pzByteArray = ^zByteArray;
43 type
44 zIntfArray = array[0..(MaxInt div SizeOf(Intf))-1] of Intf;
45 pzIntfArray = ^zIntfArray;
46 type
47 zuIntArray = array[0..(MaxInt div SizeOf(uInt))-1] of uInt;
48 PuIntArray = ^zuIntArray;
50 { Type declarations - only for deflate }
52 type
53 uch = Byte;
54 uchf = uch; { FAR }
55 ush = Word;
56 ushf = ush;
57 ulg = LongInt;
59 unsigned = uInt;
61 pcharf = ^charf;
62 puchf = ^uchf;
63 pushf = ^ushf;
65 type
66 zuchfArray = zByteArray;
67 puchfArray = ^zuchfArray;
68 type
69 zushfArray = array[0..(MaxInt div SizeOf(ushf))-1] of ushf;
70 pushfArray = ^zushfArray;
72 procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
73 function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
74 procedure zmemzero(destp : pBytef; len : uInt);
75 procedure zcfree(opaque : voidpf; ptr : voidpf);
76 function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
78 implementation
80 procedure zmemcpy(destp : pBytef; sourcep : pBytef; len : uInt);
81 begin
82 Move(sourcep^, destp^, len);
83 end;
85 function zmemcmp(s1p, s2p : pBytef; len : uInt) : int;
86 var
87 j : uInt;
88 source,
89 dest : pBytef;
90 begin
91 source := s1p;
92 dest := s2p;
93 for j := 0 to pred(len) do
94 begin
95 if (source^ <> dest^) then
96 begin
97 zmemcmp := 2*Ord(source^ > dest^)-1;
98 exit;
99 end;
100 Inc(source);
101 Inc(dest);
102 end;
103 zmemcmp := 0;
104 end;
106 procedure zmemzero(destp : pBytef; len : uInt);
107 begin
108 FillChar(destp^, len, 0);
109 end;
111 procedure zcfree(opaque : voidpf; ptr : voidpf);
112 {$ifdef Delphi16}
113 var
114 Handle : THandle;
115 {$endif}
116 {$IFDEF FPC}
117 var
118 memsize : uint;
119 {$ENDIF}
120 begin
121 (*
122 {$IFDEF DPMI}
123 {h :=} GlobalFreePtr(ptr);
124 {$ELSE}
125 {$IFDEF CALL_DOS}
126 dosFree(ptr);
127 {$ELSE}
128 {$ifdef HugeMem}
129 FreeMemHuge(ptr);
130 {$else}
131 {$ifdef Delphi16}
132 Handle := GlobalHandle(LH(ptr).H); { HiWord(LongInt(ptr)) }
133 GlobalUnLock(Handle);
134 GlobalFree(Handle);
135 {$else}
136 {$IFDEF FPC}
137 Dec(puIntf(ptr));
138 memsize := puIntf(ptr)^;
139 FreeMem(ptr, memsize+SizeOf(uInt));
140 {$ELSE}
141 FreeMem(ptr); { Delphi 2,3,4 }
142 {$ENDIF}
143 {$endif}
144 {$endif}
145 {$ENDIF}
146 {$ENDIF}
147 *)
148 FreeMem(ptr);
149 end;
151 function zcalloc (opaque : voidpf; items : uInt; size : uInt) : voidpf;
152 var
153 p : voidpf;
154 memsize : uLong;
155 {$ifdef Delphi16}
156 handle : THandle;
157 {$endif}
158 begin
159 memsize := uLong(items) * size;
160 (*
161 { $IFDEF DPMI}
162 p := GlobalAllocPtr(gmem_moveable, memsize);
163 { $ELSE}
164 { $IFDEF CALLDOS}
165 p := dosAlloc(memsize);
166 { $ELSE}
167 {$ifdef HugeMem}
168 GetMemHuge(p, memsize);
169 { $else}
170 { $ifdef Delphi16}
171 Handle := GlobalAlloc(HeapAllocFlags, memsize);
172 p := GlobalLock(Handle);
173 { $else}
174 { $IFDEF FPC}
175 GetMem(p, memsize+SizeOf(uInt));
176 puIntf(p)^:= memsize;
177 Inc(puIntf(p));
178 { $ELSE}
179 GetMem(p, memsize); { Delphi: p := AllocMem(memsize); }
180 { $ENDIF}
181 { $endif}
182 { $endif}
183 { $ENDIF}
184 { $ENDIF}
185 *)
186 GetMem(p, memsize);
187 zcalloc := p;
188 end;
190 end.