systemh.inc 15 KB

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