systemh.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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 FillByte(var x;count:longint;value:byte);
  127. Procedure FillWord(Var x;count:Longint;Value:Word);
  128. procedure FillDWord(var x;count:longint;value:DWord);
  129. function IndexChar(var buf;len:longint;b:char):longint;
  130. function IndexByte(var buf;len:longint;b:byte):longint;
  131. function Indexword(var buf;len:longint;b:word):longint;
  132. function IndexDWord(var buf;len:longint;b:DWord):longint;
  133. function CompareChar(var buf1,buf2;len:longint):longint;
  134. function CompareByte(var buf1,buf2;len:longint):longint;
  135. function CompareWord(var buf1,buf2;len:longint):longint;
  136. function CompareDWord(var buf1,buf2;len:longint):longint;
  137. procedure MoveChar0(var buf1,buf2;len:longint);
  138. function IndexChar0(var buf;len:longint;b:char):longint;
  139. function CompareChar0(var buf1,buf2;len:longint):longint;
  140. {$endif}
  141. {****************************************************************************
  142. Math Routines
  143. ****************************************************************************}
  144. {$ifndef RTLLITE}
  145. Function lo(w:Word):byte;
  146. Function lo(l:Longint):Word;
  147. Function lo(l:DWord):Word;
  148. Function lo(i:Integer):byte;
  149. Function lo(B: Byte):Byte;
  150. Function hi(w:Word):byte;
  151. Function hi(i:Integer):byte;
  152. Function hi(l:Longint):Word;
  153. Function hi(b : Byte) : Byte;
  154. Function hi(l: DWord): Word;
  155. Function Swap (X:Word):Word;
  156. Function Swap (X:Integer):Integer;
  157. Function Swap (X:Cardinal):Cardinal;
  158. Function Swap (X:LongInt):LongInt;
  159. {$ifdef INT64}
  160. Function lo(q : QWord) : DWord;
  161. Function lo(i : Int64) : DWord;
  162. Function hi(q : QWord) : DWord;
  163. Function hi(i : Int64) : DWord;
  164. Function Swap (X:QWord):QWord;
  165. Function Swap (X:Int64):Int64;
  166. {$endif}
  167. {$endif RTLLITE}
  168. Function Random(l:cardinal):cardinal;
  169. {$ifndef cardinalmulfixed}
  170. Function Random(l:longint):longint;
  171. {$endif cardinalmulfixed}
  172. Function Random: extended;
  173. Procedure Randomize;
  174. Function abs(l:Longint):Longint;
  175. Function sqr(l:Longint):Longint;
  176. Function odd(l:Longint):Boolean;
  177. { float math routines }
  178. {$I mathh.inc}
  179. {****************************************************************************
  180. Addr/Pointer Handling
  181. ****************************************************************************}
  182. {$ifndef RTLLITE}
  183. Function ptr(sel,off:Longint):pointer;
  184. Function Cseg:Word;
  185. Function Dseg:Word;
  186. Function Sseg:Word;
  187. {$endif RTLLITE}
  188. {****************************************************************************
  189. PChar and String Handling
  190. ****************************************************************************}
  191. function strpas(p:pchar):shortstring;
  192. function strlen(p:pchar):longint;
  193. { Shortstring functions }
  194. Function Copy(const s:shortstring;index:StrLenInt;count:StrLenInt):shortstring;
  195. Procedure Delete(Var s:shortstring;index:StrLenInt;count:StrLenInt);
  196. Procedure Insert(const source:shortstring;Var s:shortstring;index:StrLenInt);
  197. Procedure Insert(source:Char;Var s:shortstring;index:StrLenInt);
  198. Function Pos(const substr:shortstring;const s:shortstring):StrLenInt;
  199. Function Pos(C:Char;const s:shortstring):StrLenInt;
  200. Procedure SetLength(var s:shortstring;len:StrLenInt);
  201. Procedure SetString (Var S : Shortstring; Buf : PChar; Len : Longint);
  202. Procedure SetString (Var S : AnsiString; Buf : PChar; Len : Longint);
  203. Function Length(s:string):byte;
  204. Function upCase(const s:shortstring):shortstring;
  205. {$ifndef RTLLITE}
  206. Function lowerCase(const s:shortstring):shortstring;
  207. {$endif}
  208. Function Space(b:byte):shortstring;
  209. {$ifndef RTLLITE}
  210. Function hexStr(Val:Longint;cnt:byte):shortstring;
  211. Function binStr(Val:Longint;cnt:byte):shortstring;
  212. {$endif RTLLITE}
  213. { Char functions }
  214. Function Chr(b:byte):Char;
  215. Function upCase(c:Char):Char;
  216. {$ifndef RTLLITE}
  217. Function lowerCase(c:Char):Char;
  218. {$endif RTLLITE}
  219. function copy(c:char;index : StrLenInt;count : StrLenInt): shortstring;
  220. function pos(const substr : shortstring;c:char): StrLenInt;
  221. function length(c:char):byte;
  222. {****************************************************************************
  223. AnsiString Handling
  224. ****************************************************************************}
  225. Procedure SetLength (Var S : AnsiString; l : Longint);
  226. Procedure UniqueAnsiString (Var S : AnsiString);
  227. Function Length (Const S : AnsiString) : Longint;
  228. Function Copy (Const S : AnsiString; Index,Size : Longint) : AnsiString;
  229. Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
  230. Procedure Insert (Const Source : AnsiString; Var S : AnsiString; Index : Longint);
  231. Procedure Delete (Var S : AnsiString; Index,Size: Longint);
  232. Function StringOfChar(c : char;l : longint) : AnsiString;
  233. {****************************************************************************
  234. Untyped File Management
  235. ****************************************************************************}
  236. Procedure Assign(Var f:File;const Name:string);
  237. Procedure Assign(Var f:File;p:pchar);
  238. Procedure Assign(Var f:File;c:char);
  239. Procedure Rewrite(Var f:File;l:Longint);
  240. Procedure Rewrite(Var f:File);
  241. Procedure Reset(Var f:File;l:Longint);
  242. Procedure Reset(Var f:File);
  243. Procedure Close(Var f:File);
  244. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint;Var Result:Longint);
  245. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Word);
  246. Procedure BlockWrite(Var f:File;Var Buf;Count:Word;Var Result:Integer);
  247. Procedure BlockWrite(Var f:File;Var Buf;Count:Longint);
  248. Procedure BlockRead(Var f:File;Var Buf;count:Longint;Var Result:Longint);
  249. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Word);
  250. Procedure BlockRead(Var f:File;Var Buf;count:Word;Var Result:Integer);
  251. Procedure BlockRead(Var f:File;Var Buf;count:Longint);
  252. Function FilePos(Var f:File):Longint;
  253. Function FileSize(Var f:File):Longint;
  254. Procedure Seek(Var f:File;Pos:Longint);
  255. Function EOF(Var f:File):Boolean;
  256. Procedure Erase(Var f:File);
  257. Procedure Rename(Var f:File;const s:string);
  258. Procedure Rename(Var f:File;p:pchar);
  259. Procedure Rename(Var f:File;c:char);
  260. Procedure Truncate (Var F:File);
  261. {****************************************************************************
  262. Typed File Management
  263. ****************************************************************************}
  264. Procedure Assign(Var f:TypedFile;const Name:string);
  265. Procedure Assign(Var f:TypedFile;p:pchar);
  266. Procedure Assign(Var f:TypedFile;c:char);
  267. Procedure Rewrite(Var f:TypedFile);
  268. Procedure Reset(Var f:TypedFile);
  269. {****************************************************************************
  270. Text File Management
  271. ****************************************************************************}
  272. Procedure Assign(Var t:Text;const s:string);
  273. Procedure Assign(Var t:Text;p:pchar);
  274. Procedure Assign(Var t:Text;c:char);
  275. Procedure Close(Var t:Text);
  276. Procedure Rewrite(Var t:Text);
  277. Procedure Reset(Var t:Text);
  278. Procedure Append(Var t:Text);
  279. Procedure Flush(Var t:Text);
  280. Procedure Erase(Var t:Text);
  281. Procedure Rename(Var t:Text;const s:string);
  282. Procedure Rename(Var t:Text;p:pchar);
  283. Procedure Rename(Var t:Text;c:char);
  284. Function EOF(Var t:Text):Boolean;
  285. Function EOF:Boolean;
  286. Function EOLn(Var t:Text):Boolean;
  287. Function EOLn:Boolean;
  288. Function SeekEOLn (Var t:Text):Boolean;
  289. Function SeekEOF (Var t:Text):Boolean;
  290. Function SeekEOLn:Boolean;
  291. Function SeekEOF:Boolean;
  292. Procedure SetTextBuf(Var f:Text; Var Buf);
  293. Procedure SetTextBuf(Var f:Text; Var Buf; Size:Longint);
  294. {****************************************************************************
  295. Directory Management
  296. ****************************************************************************}
  297. Procedure chdir(const s:string);
  298. Procedure mkdir(const s:string);
  299. Procedure rmdir(const s:string);
  300. Procedure getdir(drivenr:byte;Var dir:shortstring);
  301. Procedure getdir(drivenr:byte;Var dir:ansistring);
  302. {*****************************************************************************
  303. Miscelleaous
  304. *****************************************************************************}
  305. { os independent calls to allow backtraces }
  306. function get_frame:longint;
  307. function get_caller_addr(framebp:longint):longint;
  308. function get_caller_frame(framebp:longint):longint;
  309. Function IOResult:Word;
  310. Function Sptr:Longint;
  311. {*****************************************************************************
  312. Init / Exit / ExitProc
  313. *****************************************************************************}
  314. Function Paramcount:Longint;
  315. Function ParamStr(l:Longint):string;
  316. {$ifndef RTLLITE}
  317. Procedure Dump_Stack(var f : text;bp:Longint);
  318. {$endif RTLLITE}
  319. Procedure RunError(w:Word);
  320. Procedure RunError;
  321. Procedure halt(errnum:byte);
  322. {$ifndef RTLLITE}
  323. Procedure AddExitProc(Proc:TProcedure);
  324. {$endif RTLLITE}
  325. Procedure halt;
  326. {*****************************************************************************
  327. Abstract/Assert/Error Handling
  328. *****************************************************************************}
  329. procedure AbstractError;
  330. Procedure SysAssert(Const Msg,FName:ShortString;LineNo,ErrorAddr:Longint);
  331. { Error handlers }
  332. Type
  333. TErrorProc = Procedure (ErrNo : Longint; Address : Pointer);
  334. TAbstractErrorProc = Procedure;
  335. TAssertErrorProc = Procedure(const msg,fname:ShortString;lineno,erroraddr:longint);
  336. const
  337. ErrorProc : TErrorProc = nil;
  338. AbstractErrorProc : TAbstractErrorProc = nil;
  339. AssertErrorProc : TAssertErrorProc = @SysAssert;
  340. {*****************************************************************************
  341. SetJmp/LongJmp
  342. *****************************************************************************}
  343. {$i setjumph.inc}
  344. {*****************************************************************************
  345. Object Pascal support
  346. *****************************************************************************}
  347. {$i objpash.inc}
  348. {
  349. $Log$
  350. Revision 1.75 2000-01-10 09:54:30 peter
  351. * primitives added
  352. Revision 1.74 2000/01/07 16:41:36 daniel
  353. * copyright 2000
  354. Revision 1.73 2000/01/07 16:32:25 daniel
  355. * copyright 2000 added
  356. Revision 1.72 1999/12/20 11:20:14 peter
  357. + smallint, maxsmallint
  358. * integer is redefined as smallint
  359. Revision 1.71 1999/12/18 14:55:05 florian
  360. * very basic widestring support
  361. Revision 1.70 1999/12/12 13:29:34 jonas
  362. * remove "random(longint): longint" if cardinalmulfixed is defined
  363. Revision 1.69 1999/12/01 12:37:13 jonas
  364. + function random(longint): longint
  365. Revision 1.68 1999/11/25 13:34:57 michael
  366. + Added Ansistring setstring call
  367. Revision 1.67 1999/11/20 12:48:09 jonas
  368. * reinstated old random generator, but modified it so the integer
  369. one now has a much longer period
  370. Revision 1.66 1999/11/09 20:14:12 daniel
  371. * Committed new random generator.
  372. Revision 1.65 1999/11/06 14:35:39 peter
  373. * truncated log
  374. Revision 1.64 1999/10/27 14:19:10 florian
  375. + StringOfChar
  376. Revision 1.63 1999/10/26 12:31:00 peter
  377. * *errorproc are not procvars instead of pointers which allows better
  378. error checking for the parameters (shortstring<->ansistring)
  379. Revision 1.62 1999/08/19 11:16:13 peter
  380. * settextbuf size is now longint
  381. Revision 1.61 1999/07/05 20:04:28 peter
  382. * removed temp defines
  383. Revision 1.60 1999/07/03 01:24:21 peter
  384. * $ifdef int64
  385. Revision 1.59 1999/07/02 18:06:43 florian
  386. + qword/int64: lo/hi/swap
  387. Revision 1.58 1999/06/30 22:17:22 florian
  388. + fpuint64 to system unit interface added: if it is true, the rtl
  389. uses the fpu to do int64 operations, if possible
  390. Revision 1.57 1999/05/17 21:52:40 florian
  391. * most of the Object Pascal stuff moved to the system unit
  392. Revision 1.56 1999/05/06 09:05:14 peter
  393. * generic write_float str_float
  394. Revision 1.55 1999/04/17 13:10:26 peter
  395. * addr() internal
  396. Revision 1.54 1999/04/08 15:57:56 peter
  397. + subrange checking for readln()
  398. Revision 1.53 1999/03/16 17:49:37 jonas
  399. * changes for internal Val code (do a "make cycle OPT=-dvalintern" to test)
  400. * in text.inc: changed RTE 106 when read integer values are out of bounds to RTE 201
  401. * in systemh.inc: disabled "support_fixed" for the i386 because it gave internal errors,
  402. Revision 1.52 1999/03/10 22:15:30 florian
  403. + system.cmdline variable for go32v2 and win32 added
  404. Revision 1.51 1999/03/03 15:23:58 michael
  405. + Added setstring for Delphi compatibility
  406. Revision 1.50 1999/02/01 00:05:16 florian
  407. + functions lo/hi for DWord type implemented
  408. Revision 1.49 1999/01/29 09:23:10 pierre
  409. * Fillchar(..,..,boolean) added
  410. Revision 1.48 1999/01/22 12:39:24 pierre
  411. + added text arg for dump_stack
  412. Revision 1.47 1999/01/11 19:26:53 jonas
  413. * made inster(string,string,index) a bit faster
  414. + overloaded insert(char,string,index)
  415. Revision 1.46 1998/12/28 15:50:48 peter
  416. + stdout, which is needed when you write something in the system unit
  417. to the screen. Like the runtime error
  418. Revision 1.45 1998/12/15 22:43:04 peter
  419. * removed temp symbols
  420. }