systemh.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. This File contains the OS independent declarations of the system unit
  6. See the File COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. Supported conditionnals:
  14. ------------------------
  15. RTLLITE Create a somewhat smaller RTL
  16. }
  17. {****************************************************************************
  18. Needed switches
  19. ****************************************************************************}
  20. {$I-,Q-,H-,R-,V-}
  21. {$mode objfpc}
  22. { needed for insert,delete,readln }
  23. {$P+}
  24. { Stack check gives a note under linux }
  25. {$ifndef linux}
  26. {$S-}
  27. {$endif}
  28. {****************************************************************************
  29. Global Types and Constants
  30. ****************************************************************************}
  31. Type
  32. shortint = -128..127;
  33. SmallInt = -32768..32767;
  34. Longint = $80000000..$7fffffff; { $8000000 creates a longint overfow !! }
  35. byte = 0..255;
  36. Word = 0..65535;
  37. dword = cardinal;
  38. longword = cardinal;
  39. { at least declare Turbo Pascal real types }
  40. {$ifdef i386}
  41. StrLenInt = LongInt;
  42. {$define DEFAULT_EXTENDED}
  43. {$define SUPPORT_SINGLE}
  44. {$define SUPPORT_DOUBLE}
  45. {$define SUPPORT_EXTENDED}
  46. {$define SUPPORT_COMP}
  47. { define SUPPORT_FIXED}
  48. ValSInt = Longint;
  49. ValUInt = Cardinal;
  50. ValReal = Extended;
  51. {$endif}
  52. {$ifdef m68k}
  53. StrLenInt = Longint;
  54. ValSInt = Longint;
  55. ValUInt = Cardinal;
  56. ValReal = Real;
  57. {$define SUPPORT_SINGLE}
  58. {$endif}
  59. { Zero - terminated strings }
  60. PChar = ^Char;
  61. PPChar = ^PChar;
  62. {$ifdef HASWIDECHAR}
  63. PWideChar = ^WideChar;
  64. {$endif HASWIDECHAR}
  65. { procedure type }
  66. TProcedure = Procedure;
  67. const
  68. { Maximum value of the biggest signed and unsigned integer type available}
  69. MaxSIntValue = High(ValSInt);
  70. MaxUIntValue = High(ValUInt);
  71. { max. values for longint and int}
  72. maxLongint = $7fffffff;
  73. maxSmallint = 32767;
  74. { Integer type definition }
  75. type
  76. Integer = smallint;
  77. const
  78. maxint = maxsmallint;
  79. { Compatibility With TP }
  80. const
  81. {$ifdef i386}
  82. Test8086 : byte = 2; { Always i386 or newer }
  83. Test8087 : byte = 3; { Always 387 or newer. Emulated if needed. }
  84. FPUInt64 : boolean = true; { set this to false if you don't want that }
  85. { the fpu does int64*int64 and }
  86. { int64 div int64, if the * is overflow }
  87. { checked, it is done in software }
  88. {$endif i386}
  89. {$ifdef m68k}
  90. Test68000 : byte = 0; { Must be determined at startup for both }
  91. Test68881 : byte = 0;
  92. {$endif}
  93. { max level in dumping on error }
  94. Max_Frame_Dump : Word = 8;
  95. { Exit Procedure handling consts and types }
  96. ExitProc : pointer = nil;
  97. Erroraddr: pointer = nil;
  98. Errorcode: Word = 0;
  99. { file input modes }
  100. fmClosed = $D7B0;
  101. fmInput = $D7B1;
  102. fmOutput = $D7B2;
  103. fmInOut = $D7B3;
  104. fmAppend = $D7B4;
  105. Filemode : byte = 2;
  106. CmdLine : PChar = nil;
  107. var
  108. { Standard In- and Output }
  109. Output,
  110. Input,
  111. StdOut,
  112. StdErr : Text;
  113. ExitCode,
  114. InOutRes : Word;
  115. StackBottom,
  116. LowestStack,
  117. RandSeed : Cardinal;
  118. {****************************************************************************
  119. Processor specific routines
  120. ****************************************************************************}
  121. Procedure Move(Var source,dest;count:Longint);
  122. Procedure FillChar(Var x;count:Longint;Value:Boolean);
  123. Procedure FillChar(Var x;count:Longint;Value:Char);
  124. Procedure FillChar(Var x;count:Longint;Value:Byte);
  125. {$ifndef RTLLITE}
  126. Procedure FillWord(Var x;count:Longint;Value:Word);
  127. {$endif RTLLITE}
  128. {****************************************************************************
  129. Math Routines
  130. ****************************************************************************}
  131. {$ifndef RTLLITE}
  132. Function lo(w:Word):byte;
  133. Function lo(l:Longint):Word;
  134. Function lo(l:DWord):Word;
  135. Function lo(i:Integer):byte;
  136. Function lo(B: Byte):Byte;
  137. Function hi(w:Word):byte;
  138. Function hi(i:Integer):byte;
  139. Function hi(l:Longint):Word;
  140. Function hi(b : Byte) : Byte;
  141. Function hi(l: DWord): Word;
  142. Function Swap (X:Word):Word;
  143. Function Swap (X:Integer):Integer;
  144. Function Swap (X:Cardinal):Cardinal;
  145. Function Swap (X:LongInt):LongInt;
  146. {$ifdef INT64}
  147. Function lo(q : QWord) : DWord;
  148. Function lo(i : Int64) : DWord;
  149. Function hi(q : QWord) : DWord;
  150. Function hi(i : Int64) : DWord;
  151. Function Swap (X:QWord):QWord;
  152. Function Swap (X:Int64):Int64;
  153. {$endif}
  154. {$endif RTLLITE}
  155. Function Random(l:cardinal):cardinal;
  156. {$ifndef cardinalmulfixed}
  157. Function Random(l:longint):longint;
  158. {$endif cardinalmulfixed}
  159. Function Random: extended;
  160. Procedure Randomize;
  161. Function abs(l:Longint):Longint;
  162. Function sqr(l:Longint):Longint;
  163. Function odd(l:Longint):Boolean;
  164. { float math routines }
  165. {$I mathh.inc}
  166. {****************************************************************************
  167. Addr/Pointer Handling
  168. ****************************************************************************}
  169. {$ifndef RTLLITE}
  170. Function ptr(sel,off:Longint):pointer;
  171. Function Cseg:Word;
  172. Function Dseg:Word;
  173. Function Sseg:Word;
  174. {$endif RTLLITE}
  175. {****************************************************************************
  176. PChar and String Handling
  177. ****************************************************************************}
  178. function strpas(p:pchar):shortstring;
  179. function strlen(p:pchar):longint;
  180. { Shortstring functions }
  181. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  182. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  183. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  184. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  185. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  186. Function Pos(C:Char;const s:shortstring):StrLenInt;
  187. Procedure SetLength(var s:shortstring;len:StrLenInt);
  188. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  189. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  190. Function Length(s:string):byte;
  191. Function upCase(const s:shortstring):shortstring;
  192. {$ifndef RTLLITE}
  193. Function lowerCase(const s:shortstring):shortstring;
  194. {$endif}
  195. Function Space(b:byte):shortstring;
  196. {$ifndef RTLLITE}
  197. Function hexStr(Val:Longint;cnt:byte):shortstring;
  198. Function binStr(Val:Longint;cnt:byte):shortstring;
  199. {$endif RTLLITE}
  200. { Char functions }
  201. Function Chr(b:byte):Char;
  202. Function upCase(c:Char):Char;
  203. {$ifndef RTLLITE}
  204. Function lowerCase(c:Char):Char;
  205. {$endif RTLLITE}
  206. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  207. function pos(const substr : shortstring;c:char): StrLenInt;
  208. function length(c:char):byte;
  209. {****************************************************************************
  210. AnsiString Handling
  211. ****************************************************************************}
  212. Procedure SetLength (Var S : AnsiString; l : Longint);
  213. Procedure UniqueAnsiString (Var S : AnsiString);
  214. Function Length (Const S : AnsiString) : Longint;
  215. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  216. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  217. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  218. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  219. Function StringOfChar(c : char;l : longint) : AnsiString;
  220. {****************************************************************************
  221. Untyped File Management
  222. ****************************************************************************}
  223. Procedure Assign(Var f:File;const Name:string);
  224. Procedure Assign(Var f:File;p:pchar);
  225. Procedure Assign(Var f:File;c:char);
  226. Procedure Rewrite(Var f:File;l:Longint);
  227. Procedure Rewrite(Var f:File);
  228. Procedure Reset(Var f:File;l:Longint);
  229. Procedure Reset(Var f:File);
  230. Procedure Close(Var f:File);
  231. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  232. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  233. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  234. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  235. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  236. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  237. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  238. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  239. Function FilePos(Var f:File):Longint;
  240. Function FileSize(Var f:File):Longint;
  241. Procedure Seek(Var f:File;Pos:Longint);
  242. Function EOF(Var f:File):Boolean;
  243. Procedure Erase(Var f:File);
  244. Procedure Rename(Var f:File;const s:string);
  245. Procedure Rename(Var f:File;p:pchar);
  246. Procedure Rename(Var f:File;c:char);
  247. Procedure Truncate (Var F:File);
  248. {****************************************************************************
  249. Typed File Management
  250. ****************************************************************************}
  251. Procedure Assign(Var f:TypedFile;const Name:string);
  252. Procedure Assign(Var f:TypedFile;p:pchar);
  253. Procedure Assign(Var f:TypedFile;c:char);
  254. Procedure Rewrite(Var f:TypedFile);
  255. Procedure Reset(Var f:TypedFile);
  256. {****************************************************************************
  257. Text File Management
  258. ****************************************************************************}
  259. Procedure Assign(Var t:Text;const s:string);
  260. Procedure Assign(Var t:Text;p:pchar);
  261. Procedure Assign(Var t:Text;c:char);
  262. Procedure Close(Var t:Text);
  263. Procedure Rewrite(Var t:Text);
  264. Procedure Reset(Var t:Text);
  265. Procedure Append(Var t:Text);
  266. Procedure Flush(Var t:Text);
  267. Procedure Erase(Var t:Text);
  268. Procedure Rename(Var t:Text;const s:string);
  269. Procedure Rename(Var t:Text;p:pchar);
  270. Procedure Rename(Var t:Text;c:char);
  271. Function EOF(Var t:Text):Boolean;
  272. Function EOF:Boolean;
  273. Function EOLn(Var t:Text):Boolean;
  274. Function EOLn:Boolean;
  275. Function SeekEOLn (Var t:Text):Boolean;
  276. Function SeekEOF (Var t:Text):Boolean;
  277. Function SeekEOLn:Boolean;
  278. Function SeekEOF:Boolean;
  279. Procedure SetTextBuf(Var f:Text; Var Buf);
  280. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  281. {****************************************************************************
  282. Directory Management
  283. ****************************************************************************}
  284. Procedure chdir(const s:string);
  285. Procedure mkdir(const s:string);
  286. Procedure rmdir(const s:string);
  287. Procedure getdir(drivenr:byte;Var dir:shortstring);
  288. Procedure getdir(drivenr:byte;Var dir:ansistring);
  289. {*****************************************************************************
  290. Miscelleaous
  291. *****************************************************************************}
  292. { os independent calls to allow backtraces }
  293. function get_frame:longint;
  294. function get_caller_addr(framebp:longint):longint;
  295. function get_caller_frame(framebp:longint):longint;
  296. Function IOResult:Word;
  297. Function Sptr:Longint;
  298. {*****************************************************************************
  299. Init / Exit / ExitProc
  300. *****************************************************************************}
  301. Function Paramcount:Longint;
  302. Function ParamStr(l:Longint):string;
  303. {$ifndef RTLLITE}
  304. Procedure Dump_Stack(var f : text;bp:Longint);
  305. {$endif RTLLITE}
  306. Procedure RunError(w:Word);
  307. Procedure RunError;
  308. Procedure halt(errnum:byte);
  309. {$ifndef RTLLITE}
  310. Procedure AddExitProc(Proc:TProcedure);
  311. {$endif RTLLITE}
  312. Procedure halt;
  313. {*****************************************************************************
  314. Abstract/Assert/Error Handling
  315. *****************************************************************************}
  316. procedure AbstractError;
  317. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  318. { Error handlers }
  319. Type
  320. TErrorProc = Procedure (ErrNo : Longint; Address : Pointer);
  321. TAbstractErrorProc = Procedure;
  322. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  323. const
  324. ErrorProc : TErrorProc = nil;
  325. AbstractErrorProc : TAbstractErrorProc = nil;
  326. AssertErrorProc : TAssertErrorProc = @SysAssert;
  327. {*****************************************************************************
  328. SetJmp/LongJmp
  329. *****************************************************************************}
  330. {$i setjumph.inc}
  331. {*****************************************************************************
  332. Object Pascal support
  333. *****************************************************************************}
  334. {$i objpash.inc}
  335. {
  336. $Log$
  337. Revision 1.74 2000-01-07 16:41:36 daniel
  338. * copyright 2000
  339. Revision 1.73 2000/01/07 16:32:25 daniel
  340. * copyright 2000 added
  341. Revision 1.72 1999/12/20 11:20:14 peter
  342. + smallint, maxsmallint
  343. * integer is redefined as smallint
  344. Revision 1.71 1999/12/18 14:55:05 florian
  345. * very basic widestring support
  346. Revision 1.70 1999/12/12 13:29:34 jonas
  347. * remove "random(longint): longint" if cardinalmulfixed is defined
  348. Revision 1.69 1999/12/01 12:37:13 jonas
  349. + function random(longint): longint
  350. Revision 1.68 1999/11/25 13:34:57 michael
  351. + Added Ansistring setstring call
  352. Revision 1.67 1999/11/20 12:48:09 jonas
  353. * reinstated old random generator, but modified it so the integer
  354. one now has a much longer period
  355. Revision 1.66 1999/11/09 20:14:12 daniel
  356. * Committed new random generator.
  357. Revision 1.65 1999/11/06 14:35:39 peter
  358. * truncated log
  359. Revision 1.64 1999/10/27 14:19:10 florian
  360. + StringOfChar
  361. Revision 1.63 1999/10/26 12:31:00 peter
  362. * *errorproc are not procvars instead of pointers which allows better
  363. error checking for the parameters (shortstring<->ansistring)
  364. Revision 1.62 1999/08/19 11:16:13 peter
  365. * settextbuf size is now longint
  366. Revision 1.61 1999/07/05 20:04:28 peter
  367. * removed temp defines
  368. Revision 1.60 1999/07/03 01:24:21 peter
  369. * $ifdef int64
  370. Revision 1.59 1999/07/02 18:06:43 florian
  371. + qword/int64: lo/hi/swap
  372. Revision 1.58 1999/06/30 22:17:22 florian
  373. + fpuint64 to system unit interface added: if it is true, the rtl
  374. uses the fpu to do int64 operations, if possible
  375. Revision 1.57 1999/05/17 21:52:40 florian
  376. * most of the Object Pascal stuff moved to the system unit
  377. Revision 1.56 1999/05/06 09:05:14 peter
  378. * generic write_float str_float
  379. Revision 1.55 1999/04/17 13:10:26 peter
  380. * addr() internal
  381. Revision 1.54 1999/04/08 15:57:56 peter
  382. + subrange checking for readln()
  383. Revision 1.53 1999/03/16 17:49:37 jonas
  384. * changes for internal Val code (do a "make cycle OPT=-dvalintern" to test)
  385. * in text.inc: changed RTE 106 when read integer values are out of bounds to RTE 201
  386. * in systemh.inc: disabled "support_fixed" for the i386 because it gave internal errors,
  387. Revision 1.52 1999/03/10 22:15:30 florian
  388. + system.cmdline variable for go32v2 and win32 added
  389. Revision 1.51 1999/03/03 15:23:58 michael
  390. + Added setstring for Delphi compatibility
  391. Revision 1.50 1999/02/01 00:05:16 florian
  392. + functions lo/hi for DWord type implemented
  393. Revision 1.49 1999/01/29 09:23:10 pierre
  394. * Fillchar(..,..,boolean) added
  395. Revision 1.48 1999/01/22 12:39:24 pierre
  396. + added text arg for dump_stack
  397. Revision 1.47 1999/01/11 19:26:53 jonas
  398. * made inster(string,string,index) a bit faster
  399. + overloaded insert(char,string,index)
  400. Revision 1.46 1998/12/28 15:50:48 peter
  401. + stdout, which is needed when you write something in the system unit
  402. to the screen. Like the runtime error
  403. Revision 1.45 1998/12/15 22:43:04 peter
  404. * removed temp symbols
  405. }