summaryrefslogtreecommitdiff
path: root/packages/fv/src/fvcommon.pas
blob: 4167559b4b9c11d3f176611d08cd6dabd54ef1c4 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
{********************[ COMMON UNIT ]***********************}
{                                                          }
{    System independent COMMON TYPES & DEFINITIONS         }
{                                                          }
{    Parts Copyright (c) 1997 by Balazs Scheidler          }
{    bazsi@balabit.hu                                      }
{                                                          }
{    Parts Copyright (c) 1999, 2000 by Leon de Boer        }
{    ldeboer@attglobal.net  - primary e-mail address       }
{    ldeboer@projectent.com.au - backup e-mail address     }
{                                                          }
{****************[ THIS CODE IS FREEWARE ]*****************}
{                                                          }
{     This sourcecode is released for the purpose to       }
{   promote the pascal language on all platforms. You may  }
{   redistribute it and/or modify with the following       }
{   DISCLAIMER.                                            }
{                                                          }
{     This SOURCE CODE is distributed "AS IS" WITHOUT      }
{   WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR     }
{   ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED.     }
{                                                          }
{*****************[ SUPPORTED PLATFORMS ]******************}
{     16 and 32 Bit compilers                              }
{        DOS      - Turbo Pascal 7.0 +      (16 Bit)       }
{        DPMI     - Turbo Pascal 7.0 +      (16 Bit)       }
{                 - FPC 0.9912+ (GO32V2)    (32 Bit)       }
{        WINDOWS  - Turbo Pascal 7.0 +      (16 Bit)       }
{                 - Delphi 1.0+             (16 Bit)       }
{        WIN95/NT - Delphi 2.0+             (32 Bit)       }
{                 - Virtual Pascal 2.0+     (32 Bit)       }
{                 - Speedsoft Sybil 2.0+    (32 Bit)       }
{                 - FPC 0.9912+             (32 Bit)       }
{        OS2      - Virtual Pascal 1.0+     (32 Bit)       }
{                 - Speed Pascal 1.0+       (32 Bit)       }
{                 - C'T patch to BP         (16 Bit)       }
{                                                          }
{******************[ REVISION HISTORY ]********************}
{  Version  Date      Who    Fix                           }
{  -------  --------  ---    ----------------------------  }
{  0.1     12 Jul 97  Bazsi  Initial implementation        }
{  0.2     18 Jul 97  Bazsi  Linux specific error codes    }
{  0.2.2   28 Jul 97  Bazsi  Base error code for Video     }
{  0.2.3   29 Jul 97  Bazsi  Basic types added (PByte etc) }
{  0.2.5   08 Aug 97  Bazsi  Error handling code added     }
{  0.2.6   06 Sep 97  Bazsi  Base code for keyboard        }
{  0.2.7   06 Nov 97  Bazsi  Base error code for filectrl  }
{  0.2.8   21 Jan 99  LdB    Max data sizes added.         }
{  0.2.9   22 Jan 99  LdB    General array types added.    }
{  0.3.0   27 Oct 99  LdB    Delphi3+ MaxAvail, MemAvail   }
{  0.4.0   14 Nov 00  LdB    Revamp of whole unit          }
{**********************************************************}

UNIT FVCommon;

{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
                                  INTERFACE
{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}

{====Include file to sort compiler platform out =====================}
{$I platform.inc}
{====================================================================}

{$ifdef win32}
  uses
    Windows;
{$endif}

{***************************************************************************}
{                              PUBLIC CONSTANTS                             }
{***************************************************************************}

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{                        SYSTEM ERROR BASE CONSTANTS                        }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}

{---------------------------------------------------------------------------}
{  The following ranges have been defined for error codes:                  }
{---------------------------------------------------------------------------}
{        0 -  1000    OS dependant error codes                              }
{     1000 - 10000    API reserved error codes                              }
{    10000 -          Add-On unit error codes                               }
{---------------------------------------------------------------------------}

{---------------------------------------------------------------------------}
{                         DEFINED BASE ERROR CONSTANTS                      }
{---------------------------------------------------------------------------}
CONST
   errOk                = 0;                          { No error }
   errVioBase           = 1000;                       { Video base offset }
   errKbdBase           = 1010;                       { Keyboard base offset }
   errFileCtrlBase      = 1020;                       { File IO base offset }
   errMouseBase         = 1030;                       { Mouse base offset }

{---------------------------------------------------------------------------}
{                            MAXIUM DATA SIZES                              }
{---------------------------------------------------------------------------}
CONST
{$IFDEF BIT_16}                                       { 16 BIT DEFINITION }
   MaxBytes = 65520;                                  { Maximum data size }
{$ENDIF}
{$IFDEF BIT_32}                                       { 32 BIT DEFINITION }
   MaxBytes = 128*1024*1024;                          { Maximum data size }
{$ENDIF}
   MaxWords = MaxBytes DIV SizeOf(Word);              { Max words }
   MaxInts  = MaxBytes DIV SizeOf(Integer);           { Max integers }
   MaxLongs = MaxBytes DIV SizeOf(LongInt);           { Max longints }
   MaxPtrs  = MaxBytes DIV SizeOf(Pointer);           { Max pointers }
   MaxReals = MaxBytes DIV SizeOf(Real);              { Max reals }
   MaxStr   = MaxBytes DIV SizeOf(String);            { Max strings }

{***************************************************************************}
{                          PUBLIC TYPE DEFINITIONS                          }
{***************************************************************************}

{---------------------------------------------------------------------------}
{                           CPU TYPE DEFINITIONS                            }
{---------------------------------------------------------------------------}
TYPE
{$IFDEF BIT_32}                                       { 32 BIT CODE }
   CPUWord = Longint;                                 { CPUWord is 32 bit }
   CPUInt = Longint;                                  { CPUInt is 32 bit }
{$ELSE}                                               { 16 BIT CODE }
   CPUWord = Word;                                    { CPUWord is 16 bit }
   CPUInt = Integer;                                  { CPUInt is 16 bit }
{$ENDIF}

{---------------------------------------------------------------------------}
{                     16/32 BIT SWITCHED TYPE CONSTANTS                     }
{---------------------------------------------------------------------------}
TYPE
{$IFDEF BIT_16}                                       { 16 BIT DEFINITIONS }
   Sw_Word    = Word;                                 { Standard word }
   Sw_Integer = Integer;                              { Standard integer }
{$ENDIF}
{$IFDEF BIT_32}                                       { 32 BIT DEFINITIONS }
   Sw_Word    = Cardinal;                             { Long integer now }
   Sw_Integer = LongInt;                              { Long integer now }
{$ENDIF}

{---------------------------------------------------------------------------}
{                               GENERAL ARRAYS                              }
{---------------------------------------------------------------------------}
TYPE
   TByteArray = ARRAY [0..MaxBytes-1] Of Byte;        { Byte array }
   PByteArray = ^TByteArray;                          { Byte array pointer }

   TWordArray = ARRAY [0..MaxWords-1] Of Word;        { Word array }
   PWordArray = ^TWordArray;                          { Word array pointer }

   TIntegerArray = ARRAY [0..MaxInts-1] Of Integer;   { Integer array }
   PIntegerArray = ^TIntegerArray;                    { Integer array pointer }

   TLongIntArray = ARRAY [0..MaxLongs-1] Of LongInt;  { LongInt array }
   PLongIntArray = ^TLongIntArray;                    { LongInt array pointer }

   TRealArray = Array [0..MaxReals-1] Of Real;        { Real array }
   PRealarray = ^TRealArray;                          { Real array pointer }

   TPointerArray = Array [0..MaxPtrs-1] Of Pointer;   { Pointer array }
   PPointerArray = ^TPointerArray;                    { Pointer array ptr }

   TStrArray = Array [0..MaxStr-1] Of String;         { String array }
   PStrArray = ^TStrArray;                            { String array ptr }

{***************************************************************************}
{                            INTERFACE ROUTINES                             }
{***************************************************************************}

{-GetErrorCode-------------------------------------------------------
Returns the last error code and resets ErrorCode to errOk.
07/12/97 Bazsi
---------------------------------------------------------------------}
FUNCTION GetErrorCode: LongInt;

{-GetErrorInfo-------------------------------------------------------
Returns the info assigned to the previous error, doesn't reset the
value to nil. Would usually only be called if ErrorCode <> errOk.
07/12/97 Bazsi
---------------------------------------------------------------------}
FUNCTION GetErrorInfo: Pointer;

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{                        MINIMUM AND MAXIMUM ROUTINES                       }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}

FUNCTION Min (I, J: Sw_Integer): Sw_Integer;
FUNCTION Max (I, J: Sw_Integer): Sw_Integer;

{-MinimumOf----------------------------------------------------------
Given two real numbers returns the minimum real of the two.
04Oct99 LdB
---------------------------------------------------------------------}
FUNCTION MinimumOf (A, B: Real): Real;

{-MaximumOf----------------------------------------------------------
Given two real numbers returns the maximum real of the two.
04Oct99 LdB
---------------------------------------------------------------------}
FUNCTION MaximumOf (A, B: Real): Real;

{-MinIntegerOf-------------------------------------------------------
Given two integer values returns the lowest integer of the two.
04Oct99 LdB
---------------------------------------------------------------------}
FUNCTION MinIntegerOf (A, B: Integer): Integer;

{-MaxIntegerof-------------------------------------------------------
Given two integer values returns the biggest integer of the two.
04Oct99 LdB
---------------------------------------------------------------------}
FUNCTION MaxIntegerOf (A, B: Integer): Integer;

{-MinLongIntOf-------------------------------------------------------
Given two long integers returns the minimum longint of the two.
04Oct99 LdB
---------------------------------------------------------------------}
FUNCTION MinLongIntOf (A, B: LongInt): LongInt;

{-MaxLongIntOf-------------------------------------------------------
Given two long integers returns the maximum longint of the two.
04Oct99 LdB
---------------------------------------------------------------------}
FUNCTION MaxLongIntOf (A, B: LongInt): LongInt;

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{                          MISSING DELPHI3 ROUTINES                         }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}

{ ******************************* REMARK ****************************** }
{  Delphi 3+ does not define these standard routines so I have made     }
{  some public functions here to complete compatability.                }
{ ****************************** END REMARK *** Leon de Boer, 14Aug98 * }

{-MemAvail-----------------------------------------------------------
Returns the free memory available under Delphi 3+.
14Aug98 LdB
---------------------------------------------------------------------}
FUNCTION MemAvail: LongInt;

{-MaxAvail-----------------------------------------------------------
Returns the max free memory block size available under Delphi 3+.
14Aug98 LdB
---------------------------------------------------------------------}
FUNCTION MaxAvail: LongInt;

{***************************************************************************}
{                        INITIALIZED PUBLIC VARIABLES                       }
{***************************************************************************}

{---------------------------------------------------------------------------}
{                INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES                  }
{---------------------------------------------------------------------------}
CONST
   ErrorCode: Longint = errOk;                        { Last error code }
   ErrorInfo: Pointer = Nil;                          { Last error info }

{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
                               IMPLEMENTATION
{<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}

{$IFDEF PPC_DELPHI3}                                  { DELPHI 3+ COMPILER }
USES WinTypes, WinProcs;                              { Stardard units }
{$ENDIF}

{***************************************************************************}
{                            INTERFACE ROUTINES                             }
{***************************************************************************}

{---------------------------------------------------------------------------}
{  GetErrorCode -> Platforms ALL - Updated 12Jul97 Bazsi                    }
{---------------------------------------------------------------------------}
FUNCTION GetErrorCode: LongInt;
BEGIN
   GetErrorCode := ErrorCode;                         { Return last error }
   ErrorCode := 0;                                    { Now clear errorcode }
END;

{---------------------------------------------------------------------------}
{  GetErrorInfo -> Platforms ALL - Updated 12Jul97 Bazsi                    }
{---------------------------------------------------------------------------}
FUNCTION GetErrorInfo: Pointer;
BEGIN
   GetErrorInfo := ErrorInfo;                         { Return errorinfo ptr }
END;

{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
{                        MINIMUM AND MAXIMUM ROUTINES                       }
{+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}

FUNCTION Min (I, J: Sw_Integer): Sw_Integer;
BEGIN
  If (I < J) Then Min := I Else Min := J;          { Select minimum }
END;

FUNCTION Max (I, J: Sw_Integer): Sw_Integer;
BEGIN
  If (I > J) Then Max := I Else Max := J;          { Select maximum }
END;


{---------------------------------------------------------------------------}
{  MinimumOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB         }
{---------------------------------------------------------------------------}
FUNCTION MinimumOf (A, B: Real): Real;
BEGIN
   If (B < A) Then MinimumOf := B                     { B smaller take it }
     Else MinimumOf := A;                             { Else take A }
END;

{---------------------------------------------------------------------------}
{  MaximumOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB         }
{---------------------------------------------------------------------------}
FUNCTION MaximumOf (A, B: Real): Real;
BEGIN
   If (B > A) Then MaximumOf := B                     { B bigger take it }
     Else MaximumOf := A;                             { Else take A }
END;

{---------------------------------------------------------------------------}
{  MinIntegerOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB      }
{---------------------------------------------------------------------------}
FUNCTION MinIntegerOf (A, B: Integer): Integer;
BEGIN
   If (B < A) Then MinIntegerOf := B                  { B smaller take it }
     Else MinIntegerOf := A;                          { Else take A }
END;

{---------------------------------------------------------------------------}
{  MaxIntegerOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB      }
{---------------------------------------------------------------------------}
FUNCTION MaxIntegerOf (A, B: Integer): Integer;
BEGIN
   If (B > A) Then MaxIntegerOf := B                  { B bigger take it }
     Else MaxIntegerOf := A;                          { Else take A }
END;

{---------------------------------------------------------------------------}
{  MinLongIntOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB      }
{---------------------------------------------------------------------------}
FUNCTION MinLongIntOf (A, B: LongInt): LongInt;
BEGIN
   If (B < A) Then MinLongIntOf := B                  { B smaller take it }
     Else MinLongIntOf := A;                          { Else take A }
END;

{---------------------------------------------------------------------------}
{  MaxLongIntOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB      }
{---------------------------------------------------------------------------}
FUNCTION MaxLongIntOf (A, B: LongInt): LongInt;
BEGIN
   If (B > A) Then MaxLongIntOf := B                  { B bigger take it }
     Else MaxLongIntOf := A;                          { Else take A }
END;

FUNCTION MemAvail: LongInt;
BEGIN
  { Unlimited }
  MemAvail:=high(longint);
END;

{---------------------------------------------------------------------------}
{  MaxAvail -> Platforms WIN/NT - Updated 14Aug98 LdB                       }
{---------------------------------------------------------------------------}
FUNCTION MaxAvail: LongInt;
BEGIN
  { Unlimited }
  MaxAvail:=high(longint);
END;

END.