fvcommon.inc 19 KB

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