fvcommon.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. { $Id$ }
  2. {********************[ COMMON UNIT ]***********************}
  3. { }
  4. { System independent COMMON TYPES & DEFINITIONS }
  5. { }
  6. { Parts Copyright (c) 1997 by Balazs Scheidler }
  7. { [email protected] }
  8. { }
  9. { Parts Copyright (c) 1999, 2000 by Leon de Boer }
  10. { [email protected] - primary e-mail address }
  11. { [email protected] - backup e-mail address }
  12. { }
  13. {****************[ THIS CODE IS FREEWARE ]*****************}
  14. { }
  15. { This sourcecode is released for the purpose to }
  16. { promote the pascal language on all platforms. You may }
  17. { redistribute it and/or modify with the following }
  18. { DISCLAIMER. }
  19. { }
  20. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  21. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  22. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  23. { }
  24. {*****************[ SUPPORTED PLATFORMS ]******************}
  25. { 16 and 32 Bit compilers }
  26. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  27. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  28. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  29. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  30. { - Delphi 1.0+ (16 Bit) }
  31. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  32. { - Virtual Pascal 2.0+ (32 Bit) }
  33. { - Speedsoft Sybil 2.0+ (32 Bit) }
  34. { - FPC 0.9912+ (32 Bit) }
  35. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  36. { - Speed Pascal 1.0+ (32 Bit) }
  37. { - C'T patch to BP (16 Bit) }
  38. { }
  39. {******************[ REVISION HISTORY ]********************}
  40. { Version Date Who Fix }
  41. { ------- -------- --- ---------------------------- }
  42. { 0.1 12 Jul 97 Bazsi Initial implementation }
  43. { 0.2 18 Jul 97 Bazsi Linux specific error codes }
  44. { 0.2.2 28 Jul 97 Bazsi Base error code for Video }
  45. { 0.2.3 29 Jul 97 Bazsi Basic types added (PByte etc) }
  46. { 0.2.5 08 Aug 97 Bazsi Error handling code added }
  47. { 0.2.6 06 Sep 97 Bazsi Base code for keyboard }
  48. { 0.2.7 06 Nov 97 Bazsi Base error code for filectrl }
  49. { 0.2.8 21 Jan 99 LdB Max data sizes added. }
  50. { 0.2.9 22 Jan 99 LdB General array types added. }
  51. { 0.3.0 27 Oct 99 LdB Delphi3+ MaxAvail, MemAvail }
  52. { 0.4.0 14 Nov 00 LdB Revamp of whole unit }
  53. {**********************************************************}
  54. UNIT FVCommon;
  55. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  56. INTERFACE
  57. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  58. {====Include file to sort compiler platform out =====================}
  59. {$I Platform.inc}
  60. {====================================================================}
  61. {$ifdef win32}
  62. uses
  63. Windows;
  64. {$endif}
  65. {***************************************************************************}
  66. { PUBLIC CONSTANTS }
  67. {***************************************************************************}
  68. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  69. { SYSTEM ERROR BASE CONSTANTS }
  70. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  71. {---------------------------------------------------------------------------}
  72. { The following ranges have been defined for error codes: }
  73. {---------------------------------------------------------------------------}
  74. { 0 - 1000 OS dependant error codes }
  75. { 1000 - 10000 API reserved error codes }
  76. { 10000 - Add-On unit error codes }
  77. {---------------------------------------------------------------------------}
  78. {---------------------------------------------------------------------------}
  79. { DEFINED BASE ERROR CONSTANTS }
  80. {---------------------------------------------------------------------------}
  81. CONST
  82. errOk = 0; { No error }
  83. errVioBase = 1000; { Video base offset }
  84. errKbdBase = 1010; { Keyboard base offset }
  85. errFileCtrlBase = 1020; { File IO base offset }
  86. errMouseBase = 1030; { Mouse base offset }
  87. {---------------------------------------------------------------------------}
  88. { MAXIUM DATA SIZES }
  89. {---------------------------------------------------------------------------}
  90. CONST
  91. {$IFDEF BIT_16} { 16 BIT DEFINITION }
  92. MaxBytes = 65520; { Maximum data size }
  93. {$ENDIF}
  94. {$IFDEF BIT_32} { 32 BIT DEFINITION }
  95. MaxBytes = 128*1024*1024; { Maximum data size }
  96. {$ENDIF}
  97. MaxWords = MaxBytes DIV SizeOf(Word); { Max words }
  98. MaxInts = MaxBytes DIV SizeOf(Integer); { Max integers }
  99. MaxLongs = MaxBytes DIV SizeOf(LongInt); { Max longints }
  100. MaxPtrs = MaxBytes DIV SizeOf(Pointer); { Max pointers }
  101. MaxReals = MaxBytes DIV SizeOf(Real); { Max reals }
  102. MaxStr = MaxBytes DIV SizeOf(String); { Max strings }
  103. {***************************************************************************}
  104. { PUBLIC TYPE DEFINITIONS }
  105. {***************************************************************************}
  106. {---------------------------------------------------------------------------}
  107. { CPU TYPE DEFINITIONS }
  108. {---------------------------------------------------------------------------}
  109. TYPE
  110. {$IFDEF BIT_32} { 32 BIT CODE }
  111. CPUWord = Longint; { CPUWord is 32 bit }
  112. CPUInt = Longint; { CPUInt is 32 bit }
  113. {$ELSE} { 16 BIT CODE }
  114. CPUWord = Word; { CPUWord is 16 bit }
  115. CPUInt = Integer; { CPUInt is 16 bit }
  116. {$ENDIF}
  117. {---------------------------------------------------------------------------}
  118. { 16/32 BIT SWITCHED TYPE CONSTANTS }
  119. {---------------------------------------------------------------------------}
  120. TYPE
  121. {$IFDEF BIT_16} { 16 BIT DEFINITIONS }
  122. Sw_Word = Word; { Standard word }
  123. Sw_Integer = Integer; { Standard integer }
  124. {$ENDIF}
  125. {$IFDEF BIT_32} { 32 BIT DEFINITIONS }
  126. Sw_Word = Cardinal; { Long integer now }
  127. Sw_Integer = LongInt; { Long integer now }
  128. {$ENDIF}
  129. {---------------------------------------------------------------------------}
  130. { FILE HANDLE SIZE }
  131. {---------------------------------------------------------------------------}
  132. TYPE
  133. {$IFDEF OS_DOS} { DOS DEFINITION }
  134. THandle = Integer; { Handles are 16 bits }
  135. {$ENDIF}
  136. {$IFDEF OS_ATARI} { ATARI DEFINITION }
  137. THandle = Integer; { Handles are 16 bits }
  138. {$ENDIF}
  139. {$IFDEF OS_UNIX} { LINUX DEFINITIONS }
  140. { values are words, though the OS calls return 32-bit values }
  141. { to check (CEC) }
  142. THandle = LongInt; { Simulated 32 bits }
  143. {$ENDIF}
  144. {$IFDEF OS_AMIGA} { AMIGA DEFINITIONS }
  145. THandle = LongInt; { Handles are 32 bits }
  146. {$ENDIF}
  147. {$IFDEF OS_WINDOWS} { WIN/NT DEFINITIONS }
  148. THandle = Windows.THandle; { Can be either }
  149. {$ENDIF}
  150. {$IFDEF OS_OS2} { OS2 DEFINITIONS }
  151. THandle = sw_Integer; { Can be either }
  152. {$ENDIF}
  153. {$IFDEF OS_MAC} { MACINTOSH DEFINITIONS }
  154. THandle = LongInt; { Handles are 32 bits }
  155. {$ENDIF}
  156. {---------------------------------------------------------------------------}
  157. { POINTERS TO STANDARD DATA TYPES }
  158. {---------------------------------------------------------------------------}
  159. TYPE
  160. PByte = ^Byte; { Pointer to byte }
  161. PWord = ^Word; { Pointer to word }
  162. PLongint = ^Longint; { Pointer to longint }
  163. {---------------------------------------------------------------------------}
  164. { GENERAL ARRAYS }
  165. {---------------------------------------------------------------------------}
  166. TYPE
  167. TByteArray = ARRAY [0..MaxBytes-1] Of Byte; { Byte array }
  168. PByteArray = ^TByteArray; { Byte array pointer }
  169. TWordArray = ARRAY [0..MaxWords-1] Of Word; { Word array }
  170. PWordArray = ^TWordArray; { Word array pointer }
  171. TIntegerArray = ARRAY [0..MaxInts-1] Of Integer; { Integer array }
  172. PIntegerArray = ^TIntegerArray; { Integer array pointer }
  173. TLongIntArray = ARRAY [0..MaxLongs-1] Of LongInt; { LongInt array }
  174. PLongIntArray = ^TLongIntArray; { LongInt array pointer }
  175. TRealArray = Array [0..MaxReals-1] Of Real; { Real array }
  176. PRealarray = ^TRealArray; { Real array pointer }
  177. TPointerArray = Array [0..MaxPtrs-1] Of Pointer; { Pointer array }
  178. PPointerArray = ^TPointerArray; { Pointer array ptr }
  179. TStrArray = Array [0..MaxStr-1] Of String; { String array }
  180. PStrArray = ^TStrArray; { String array ptr }
  181. {***************************************************************************}
  182. { INTERFACE ROUTINES }
  183. {***************************************************************************}
  184. {-GetErrorCode-------------------------------------------------------
  185. Returns the last error code and resets ErrorCode to errOk.
  186. 07/12/97 Bazsi
  187. ---------------------------------------------------------------------}
  188. FUNCTION GetErrorCode: LongInt;
  189. {-GetErrorInfo-------------------------------------------------------
  190. Returns the info assigned to the previous error, doesn't reset the
  191. value to nil. Would usually only be called if ErrorCode <> errOk.
  192. 07/12/97 Bazsi
  193. ---------------------------------------------------------------------}
  194. FUNCTION GetErrorInfo: Pointer;
  195. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  196. { MINIMUM AND MAXIMUM ROUTINES }
  197. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  198. FUNCTION Min (I, J: Sw_Integer): Sw_Integer;
  199. FUNCTION Max (I, J: Sw_Integer): Sw_Integer;
  200. {-MinimumOf----------------------------------------------------------
  201. Given two real numbers returns the minimum real of the two.
  202. 04Oct99 LdB
  203. ---------------------------------------------------------------------}
  204. FUNCTION MinimumOf (A, B: Real): Real;
  205. {-MaximumOf----------------------------------------------------------
  206. Given two real numbers returns the maximum real of the two.
  207. 04Oct99 LdB
  208. ---------------------------------------------------------------------}
  209. FUNCTION MaximumOf (A, B: Real): Real;
  210. {-MinIntegerOf-------------------------------------------------------
  211. Given two integer values returns the lowest integer of the two.
  212. 04Oct99 LdB
  213. ---------------------------------------------------------------------}
  214. FUNCTION MinIntegerOf (A, B: Integer): Integer;
  215. {-MaxIntegerof-------------------------------------------------------
  216. Given two integer values returns the biggest integer of the two.
  217. 04Oct99 LdB
  218. ---------------------------------------------------------------------}
  219. FUNCTION MaxIntegerOf (A, B: Integer): Integer;
  220. {-MinLongIntOf-------------------------------------------------------
  221. Given two long integers returns the minimum longint of the two.
  222. 04Oct99 LdB
  223. ---------------------------------------------------------------------}
  224. FUNCTION MinLongIntOf (A, B: LongInt): LongInt;
  225. {-MaxLongIntOf-------------------------------------------------------
  226. Given two long integers returns the maximum longint of the two.
  227. 04Oct99 LdB
  228. ---------------------------------------------------------------------}
  229. FUNCTION MaxLongIntOf (A, B: LongInt): LongInt;
  230. {$IFDEF PPC_DELPHI3} { DELPHI 3+ CODE }
  231. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  232. { MISSING DELPHI3 ROUTINES }
  233. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  234. { ******************************* REMARK ****************************** }
  235. { Delphi 3+ does not define these standard routines so I have made }
  236. { some public functions here to complete compatability. }
  237. { ****************************** END REMARK *** Leon de Boer, 14Aug98 * }
  238. {-MemAvail-----------------------------------------------------------
  239. Returns the free memory available under Delphi 3+.
  240. 14Aug98 LdB
  241. ---------------------------------------------------------------------}
  242. FUNCTION MemAvail: LongInt;
  243. {-MaxAvail-----------------------------------------------------------
  244. Returns the max free memory block size available under Delphi 3+.
  245. 14Aug98 LdB
  246. ---------------------------------------------------------------------}
  247. FUNCTION MaxAvail: LongInt;
  248. {$ENDIF}
  249. {***************************************************************************}
  250. { INITIALIZED PUBLIC VARIABLES }
  251. {***************************************************************************}
  252. {---------------------------------------------------------------------------}
  253. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  254. {---------------------------------------------------------------------------}
  255. CONST
  256. ErrorCode: Longint = errOk; { Last error code }
  257. ErrorInfo: Pointer = Nil; { Last error info }
  258. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  259. IMPLEMENTATION
  260. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  261. {$IFDEF PPC_DELPHI3} { DELPHI 3+ COMPILER }
  262. USES WinTypes, WinProcs; { Stardard units }
  263. {$ENDIF}
  264. {***************************************************************************}
  265. { INTERFACE ROUTINES }
  266. {***************************************************************************}
  267. {---------------------------------------------------------------------------}
  268. { GetErrorCode -> Platforms ALL - Updated 12Jul97 Bazsi }
  269. {---------------------------------------------------------------------------}
  270. FUNCTION GetErrorCode: LongInt;
  271. BEGIN
  272. GetErrorCode := ErrorCode; { Return last error }
  273. ErrorCode := 0; { Now clear errorcode }
  274. END;
  275. {---------------------------------------------------------------------------}
  276. { GetErrorInfo -> Platforms ALL - Updated 12Jul97 Bazsi }
  277. {---------------------------------------------------------------------------}
  278. FUNCTION GetErrorInfo: Pointer;
  279. BEGIN
  280. GetErrorInfo := ErrorInfo; { Return errorinfo ptr }
  281. END;
  282. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  283. { MINIMUM AND MAXIMUM ROUTINES }
  284. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  285. FUNCTION Min (I, J: Sw_Integer): Sw_Integer;
  286. BEGIN
  287. If (I < J) Then Min := I Else Min := J; { Select minimum }
  288. END;
  289. FUNCTION Max (I, J: Sw_Integer): Sw_Integer;
  290. BEGIN
  291. If (I > J) Then Max := I Else Max := J; { Select maximum }
  292. END;
  293. {---------------------------------------------------------------------------}
  294. { MinimumOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  295. {---------------------------------------------------------------------------}
  296. FUNCTION MinimumOf (A, B: Real): Real;
  297. BEGIN
  298. If (B < A) Then MinimumOf := B { B smaller take it }
  299. Else MinimumOf := A; { Else take A }
  300. END;
  301. {---------------------------------------------------------------------------}
  302. { MaximumOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  303. {---------------------------------------------------------------------------}
  304. FUNCTION MaximumOf (A, B: Real): Real;
  305. BEGIN
  306. If (B > A) Then MaximumOf := B { B bigger take it }
  307. Else MaximumOf := A; { Else take A }
  308. END;
  309. {---------------------------------------------------------------------------}
  310. { MinIntegerOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  311. {---------------------------------------------------------------------------}
  312. FUNCTION MinIntegerOf (A, B: Integer): Integer;
  313. BEGIN
  314. If (B < A) Then MinIntegerOf := B { B smaller take it }
  315. Else MinIntegerOf := A; { Else take A }
  316. END;
  317. {---------------------------------------------------------------------------}
  318. { MaxIntegerOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  319. {---------------------------------------------------------------------------}
  320. FUNCTION MaxIntegerOf (A, B: Integer): Integer;
  321. BEGIN
  322. If (B > A) Then MaxIntegerOf := B { B bigger take it }
  323. Else MaxIntegerOf := A; { Else take A }
  324. END;
  325. {---------------------------------------------------------------------------}
  326. { MinLongIntOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  327. {---------------------------------------------------------------------------}
  328. FUNCTION MinLongIntOf (A, B: LongInt): LongInt;
  329. BEGIN
  330. If (B < A) Then MinLongIntOf := B { B smaller take it }
  331. Else MinLongIntOf := A; { Else take A }
  332. END;
  333. {---------------------------------------------------------------------------}
  334. { MaxLongIntOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  335. {---------------------------------------------------------------------------}
  336. FUNCTION MaxLongIntOf (A, B: LongInt): LongInt;
  337. BEGIN
  338. If (B > A) Then MaxLongIntOf := B { B bigger take it }
  339. Else MaxLongIntOf := A; { Else take A }
  340. END;
  341. {$IFDEF PPC_DELPHI3} { DELPHI 3+ CODE }
  342. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  343. { MISSING DELPHI3 ROUTINES }
  344. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  345. {---------------------------------------------------------------------------}
  346. { MemAvail -> Platforms WIN/NT - Updated 14Aug98 LdB }
  347. {---------------------------------------------------------------------------}
  348. FUNCTION MemAvail: LongInt;
  349. VAR Ms: TMemoryStatus;
  350. BEGIN
  351. GlobalMemoryStatus(Ms); { Get memory status }
  352. MemAvail := Ms.dwAvailPhys; { Avail physical memory }
  353. END;
  354. {---------------------------------------------------------------------------}
  355. { MaxAvail -> Platforms WIN/NT - Updated 14Aug98 LdB }
  356. {---------------------------------------------------------------------------}
  357. FUNCTION MaxAvail: LongInt;
  358. VAR Ms: TMemoryStatus;
  359. BEGIN
  360. GlobalMemoryStatus(Ms); { Get memory status }
  361. MaxAvail := Ms.dwTotalPhys; { Max physical memory }
  362. END;
  363. {$ENDIF}
  364. END.
  365. {
  366. $Log$
  367. Revision 1.5 2003-06-05 14:45:06 peter
  368. * use Windows THandle
  369. Revision 1.4 2002/09/07 15:06:36 peter
  370. * old logs removed and tabs fixed
  371. Revision 1.3 2002/06/04 11:12:41 marco
  372. * Renamefest
  373. }