fvcommon.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. UNIT FVCommon;
  54. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  55. INTERFACE
  56. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  57. {====Include file to sort compiler platform out =====================}
  58. {$I Platform.inc}
  59. {====================================================================}
  60. {$ifdef win32}
  61. uses
  62. Windows;
  63. {$endif}
  64. {***************************************************************************}
  65. { PUBLIC CONSTANTS }
  66. {***************************************************************************}
  67. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  68. { SYSTEM ERROR BASE CONSTANTS }
  69. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  70. {---------------------------------------------------------------------------}
  71. { The following ranges have been defined for error codes: }
  72. {---------------------------------------------------------------------------}
  73. { 0 - 1000 OS dependant error codes }
  74. { 1000 - 10000 API reserved error codes }
  75. { 10000 - Add-On unit error codes }
  76. {---------------------------------------------------------------------------}
  77. {---------------------------------------------------------------------------}
  78. { DEFINED BASE ERROR CONSTANTS }
  79. {---------------------------------------------------------------------------}
  80. CONST
  81. errOk = 0; { No error }
  82. errVioBase = 1000; { Video base offset }
  83. errKbdBase = 1010; { Keyboard base offset }
  84. errFileCtrlBase = 1020; { File IO base offset }
  85. errMouseBase = 1030; { Mouse base offset }
  86. {---------------------------------------------------------------------------}
  87. { MAXIUM DATA SIZES }
  88. {---------------------------------------------------------------------------}
  89. CONST
  90. {$IFDEF BIT_16} { 16 BIT DEFINITION }
  91. MaxBytes = 65520; { Maximum data size }
  92. {$ENDIF}
  93. {$IFDEF BIT_32} { 32 BIT DEFINITION }
  94. MaxBytes = 128*1024*1024; { Maximum data size }
  95. {$ENDIF}
  96. MaxWords = MaxBytes DIV SizeOf(Word); { Max words }
  97. MaxInts = MaxBytes DIV SizeOf(Integer); { Max integers }
  98. MaxLongs = MaxBytes DIV SizeOf(LongInt); { Max longints }
  99. MaxPtrs = MaxBytes DIV SizeOf(Pointer); { Max pointers }
  100. MaxReals = MaxBytes DIV SizeOf(Real); { Max reals }
  101. MaxStr = MaxBytes DIV SizeOf(String); { Max strings }
  102. {***************************************************************************}
  103. { PUBLIC TYPE DEFINITIONS }
  104. {***************************************************************************}
  105. {---------------------------------------------------------------------------}
  106. { CPU TYPE DEFINITIONS }
  107. {---------------------------------------------------------------------------}
  108. TYPE
  109. {$IFDEF BIT_32} { 32 BIT CODE }
  110. CPUWord = Longint; { CPUWord is 32 bit }
  111. CPUInt = Longint; { CPUInt is 32 bit }
  112. {$ELSE} { 16 BIT CODE }
  113. CPUWord = Word; { CPUWord is 16 bit }
  114. CPUInt = Integer; { CPUInt is 16 bit }
  115. {$ENDIF}
  116. {---------------------------------------------------------------------------}
  117. { 16/32 BIT SWITCHED TYPE CONSTANTS }
  118. {---------------------------------------------------------------------------}
  119. TYPE
  120. {$IFDEF BIT_16} { 16 BIT DEFINITIONS }
  121. Sw_Word = Word; { Standard word }
  122. Sw_Integer = Integer; { Standard integer }
  123. {$ENDIF}
  124. {$IFDEF BIT_32} { 32 BIT DEFINITIONS }
  125. Sw_Word = Cardinal; { Long integer now }
  126. Sw_Integer = LongInt; { Long integer now }
  127. {$ENDIF}
  128. {---------------------------------------------------------------------------}
  129. { GENERAL ARRAYS }
  130. {---------------------------------------------------------------------------}
  131. TYPE
  132. TByteArray = ARRAY [0..MaxBytes-1] Of Byte; { Byte array }
  133. PByteArray = ^TByteArray; { Byte array pointer }
  134. TWordArray = ARRAY [0..MaxWords-1] Of Word; { Word array }
  135. PWordArray = ^TWordArray; { Word array pointer }
  136. TIntegerArray = ARRAY [0..MaxInts-1] Of Integer; { Integer array }
  137. PIntegerArray = ^TIntegerArray; { Integer array pointer }
  138. TLongIntArray = ARRAY [0..MaxLongs-1] Of LongInt; { LongInt array }
  139. PLongIntArray = ^TLongIntArray; { LongInt array pointer }
  140. TRealArray = Array [0..MaxReals-1] Of Real; { Real array }
  141. PRealarray = ^TRealArray; { Real array pointer }
  142. TPointerArray = Array [0..MaxPtrs-1] Of Pointer; { Pointer array }
  143. PPointerArray = ^TPointerArray; { Pointer array ptr }
  144. TStrArray = Array [0..MaxStr-1] Of String; { String array }
  145. PStrArray = ^TStrArray; { String array ptr }
  146. {***************************************************************************}
  147. { INTERFACE ROUTINES }
  148. {***************************************************************************}
  149. {-GetErrorCode-------------------------------------------------------
  150. Returns the last error code and resets ErrorCode to errOk.
  151. 07/12/97 Bazsi
  152. ---------------------------------------------------------------------}
  153. FUNCTION GetErrorCode: LongInt;
  154. {-GetErrorInfo-------------------------------------------------------
  155. Returns the info assigned to the previous error, doesn't reset the
  156. value to nil. Would usually only be called if ErrorCode <> errOk.
  157. 07/12/97 Bazsi
  158. ---------------------------------------------------------------------}
  159. FUNCTION GetErrorInfo: Pointer;
  160. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  161. { MINIMUM AND MAXIMUM ROUTINES }
  162. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  163. FUNCTION Min (I, J: Sw_Integer): Sw_Integer;
  164. FUNCTION Max (I, J: Sw_Integer): Sw_Integer;
  165. {-MinimumOf----------------------------------------------------------
  166. Given two real numbers returns the minimum real of the two.
  167. 04Oct99 LdB
  168. ---------------------------------------------------------------------}
  169. FUNCTION MinimumOf (A, B: Real): Real;
  170. {-MaximumOf----------------------------------------------------------
  171. Given two real numbers returns the maximum real of the two.
  172. 04Oct99 LdB
  173. ---------------------------------------------------------------------}
  174. FUNCTION MaximumOf (A, B: Real): Real;
  175. {-MinIntegerOf-------------------------------------------------------
  176. Given two integer values returns the lowest integer of the two.
  177. 04Oct99 LdB
  178. ---------------------------------------------------------------------}
  179. FUNCTION MinIntegerOf (A, B: Integer): Integer;
  180. {-MaxIntegerof-------------------------------------------------------
  181. Given two integer values returns the biggest integer of the two.
  182. 04Oct99 LdB
  183. ---------------------------------------------------------------------}
  184. FUNCTION MaxIntegerOf (A, B: Integer): Integer;
  185. {-MinLongIntOf-------------------------------------------------------
  186. Given two long integers returns the minimum longint of the two.
  187. 04Oct99 LdB
  188. ---------------------------------------------------------------------}
  189. FUNCTION MinLongIntOf (A, B: LongInt): LongInt;
  190. {-MaxLongIntOf-------------------------------------------------------
  191. Given two long integers returns the maximum longint of the two.
  192. 04Oct99 LdB
  193. ---------------------------------------------------------------------}
  194. FUNCTION MaxLongIntOf (A, B: LongInt): LongInt;
  195. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  196. { MISSING DELPHI3 ROUTINES }
  197. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  198. { ******************************* REMARK ****************************** }
  199. { Delphi 3+ does not define these standard routines so I have made }
  200. { some public functions here to complete compatability. }
  201. { ****************************** END REMARK *** Leon de Boer, 14Aug98 * }
  202. {-MemAvail-----------------------------------------------------------
  203. Returns the free memory available under Delphi 3+.
  204. 14Aug98 LdB
  205. ---------------------------------------------------------------------}
  206. FUNCTION MemAvail: LongInt;
  207. {-MaxAvail-----------------------------------------------------------
  208. Returns the max free memory block size available under Delphi 3+.
  209. 14Aug98 LdB
  210. ---------------------------------------------------------------------}
  211. FUNCTION MaxAvail: LongInt;
  212. {***************************************************************************}
  213. { INITIALIZED PUBLIC VARIABLES }
  214. {***************************************************************************}
  215. {---------------------------------------------------------------------------}
  216. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  217. {---------------------------------------------------------------------------}
  218. CONST
  219. ErrorCode: Longint = errOk; { Last error code }
  220. ErrorInfo: Pointer = Nil; { Last error info }
  221. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  222. IMPLEMENTATION
  223. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  224. {$IFDEF PPC_DELPHI3} { DELPHI 3+ COMPILER }
  225. USES WinTypes, WinProcs; { Stardard units }
  226. {$ENDIF}
  227. {***************************************************************************}
  228. { INTERFACE ROUTINES }
  229. {***************************************************************************}
  230. {---------------------------------------------------------------------------}
  231. { GetErrorCode -> Platforms ALL - Updated 12Jul97 Bazsi }
  232. {---------------------------------------------------------------------------}
  233. FUNCTION GetErrorCode: LongInt;
  234. BEGIN
  235. GetErrorCode := ErrorCode; { Return last error }
  236. ErrorCode := 0; { Now clear errorcode }
  237. END;
  238. {---------------------------------------------------------------------------}
  239. { GetErrorInfo -> Platforms ALL - Updated 12Jul97 Bazsi }
  240. {---------------------------------------------------------------------------}
  241. FUNCTION GetErrorInfo: Pointer;
  242. BEGIN
  243. GetErrorInfo := ErrorInfo; { Return errorinfo ptr }
  244. END;
  245. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  246. { MINIMUM AND MAXIMUM ROUTINES }
  247. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  248. FUNCTION Min (I, J: Sw_Integer): Sw_Integer;
  249. BEGIN
  250. If (I < J) Then Min := I Else Min := J; { Select minimum }
  251. END;
  252. FUNCTION Max (I, J: Sw_Integer): Sw_Integer;
  253. BEGIN
  254. If (I > J) Then Max := I Else Max := J; { Select maximum }
  255. END;
  256. {---------------------------------------------------------------------------}
  257. { MinimumOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  258. {---------------------------------------------------------------------------}
  259. FUNCTION MinimumOf (A, B: Real): Real;
  260. BEGIN
  261. If (B < A) Then MinimumOf := B { B smaller take it }
  262. Else MinimumOf := A; { Else take A }
  263. END;
  264. {---------------------------------------------------------------------------}
  265. { MaximumOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  266. {---------------------------------------------------------------------------}
  267. FUNCTION MaximumOf (A, B: Real): Real;
  268. BEGIN
  269. If (B > A) Then MaximumOf := B { B bigger take it }
  270. Else MaximumOf := A; { Else take A }
  271. END;
  272. {---------------------------------------------------------------------------}
  273. { MinIntegerOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  274. {---------------------------------------------------------------------------}
  275. FUNCTION MinIntegerOf (A, B: Integer): Integer;
  276. BEGIN
  277. If (B < A) Then MinIntegerOf := B { B smaller take it }
  278. Else MinIntegerOf := A; { Else take A }
  279. END;
  280. {---------------------------------------------------------------------------}
  281. { MaxIntegerOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  282. {---------------------------------------------------------------------------}
  283. FUNCTION MaxIntegerOf (A, B: Integer): Integer;
  284. BEGIN
  285. If (B > A) Then MaxIntegerOf := B { B bigger take it }
  286. Else MaxIntegerOf := A; { Else take A }
  287. END;
  288. {---------------------------------------------------------------------------}
  289. { MinLongIntOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  290. {---------------------------------------------------------------------------}
  291. FUNCTION MinLongIntOf (A, B: LongInt): LongInt;
  292. BEGIN
  293. If (B < A) Then MinLongIntOf := B { B smaller take it }
  294. Else MinLongIntOf := A; { Else take A }
  295. END;
  296. {---------------------------------------------------------------------------}
  297. { MaxLongIntOf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Oct99 LdB }
  298. {---------------------------------------------------------------------------}
  299. FUNCTION MaxLongIntOf (A, B: LongInt): LongInt;
  300. BEGIN
  301. If (B > A) Then MaxLongIntOf := B { B bigger take it }
  302. Else MaxLongIntOf := A; { Else take A }
  303. END;
  304. FUNCTION MemAvail: LongInt;
  305. BEGIN
  306. { Unlimited }
  307. MemAvail:=high(longint);
  308. END;
  309. {---------------------------------------------------------------------------}
  310. { MaxAvail -> Platforms WIN/NT - Updated 14Aug98 LdB }
  311. {---------------------------------------------------------------------------}
  312. FUNCTION MaxAvail: LongInt;
  313. BEGIN
  314. { Unlimited }
  315. MaxAvail:=high(longint);
  316. END;
  317. END.