system.pp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 the Free Pascal development team
  4. Portions based on the Atari RTL for FPC 1.x
  5. Copyright (c) 1999-2000 by Carl Eric Codere
  6. member of the Free Pascal development team
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit System;
  14. interface
  15. {$define FPC_IS_SYSTEM}
  16. {$define FPC_STDOUT_TRUE_ALIAS}
  17. {$define FPC_ANSI_TEXTFILEREC}
  18. {$define FPC_SYSTEM_NO_VERBOSE_UNICODEERROR}
  19. {.$define FPC_ATARI_USE_TINYHEAP}
  20. {$ifdef FPC_ATARI_USE_TINYHEAP}
  21. {$define HAS_MEMORYMANAGER}
  22. {$endif FPC_ATARI_USE_TINYHEAP}
  23. {$i systemh.inc}
  24. {$ifdef FPC_ATARI_USE_TINYHEAP}
  25. {$i tnyheaph.inc}
  26. {$endif FPC_ATARI_USE_TINYHEAP}
  27. {Platform specific information}
  28. const
  29. LineEnding = #13#10;
  30. LFNSupport = false;
  31. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  32. DirectorySeparator = '\';
  33. DriveSeparator = ':';
  34. ExtensionSeparator = '.';
  35. PathSeparator = ';';
  36. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  37. AllowDriveSeparators : set of AnsiChar = [':'];
  38. FileNameCaseSensitive = false;
  39. FileNameCasePreserving = false;
  40. maxExitCode = 255;
  41. MaxPathLen = 255;
  42. AllFilesMask = '*.*';
  43. sLineBreak = LineEnding;
  44. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
  45. const
  46. UnusedHandle = $ffff;
  47. StdInputHandle = 0;
  48. StdOutputHandle = 1;
  49. StdErrorHandle = 2;
  50. var
  51. args: PAnsiChar;
  52. argc: LongInt;
  53. argv: PPAnsiChar;
  54. envp: PPAnsiChar;
  55. AppFlag: Boolean; { Application or Accessory }
  56. {$if defined(FPUSOFT)}
  57. {$define fpc_softfpu_interface}
  58. {$i softfpu.pp}
  59. {$undef fpc_softfpu_interface}
  60. {$endif defined(FPUSOFT)}
  61. implementation
  62. {$define FPC_SYSTEM_HAS_STACKTOP}
  63. {$define FPC_SYSTEM_HAS_BACKTRACESTR}
  64. {$if defined(FPUSOFT)}
  65. {$define fpc_softfpu_implementation}
  66. {$define softfpu_compiler_mul32to64}
  67. {$define softfpu_inline}
  68. {$i softfpu.pp}
  69. {$undef fpc_softfpu_implementation}
  70. { we get these functions and types from the softfpu code }
  71. {$define FPC_SYSTEM_HAS_float64}
  72. {$define FPC_SYSTEM_HAS_float32}
  73. {$define FPC_SYSTEM_HAS_flag}
  74. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  75. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  76. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  77. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  78. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  79. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  80. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  81. {$endif defined(FPUSOFT)}
  82. {$i system.inc}
  83. {$ifdef FPC_ATARI_USE_TINYHEAP}
  84. {$i tinyheap.inc}
  85. {$endif FPC_ATARI_USE_TINYHEAP}
  86. {$i syspara.inc}
  87. function GetProcessID:SizeUInt;
  88. begin
  89. {$WARNING To be checked by platform maintainer}
  90. GetProcessID := 1;
  91. end;
  92. procedure SysInitParamsAndEnv;
  93. begin
  94. // [0] index contains the args length...
  95. args:=@basepage^.p_cmdlin[0];
  96. GenerateArgs;
  97. end;
  98. procedure randomize;
  99. begin
  100. {$WARNING: randseed initial value is 24bit}
  101. randseed:=xbios_random;
  102. end;
  103. function fpGetEnv(const envvar : ShortString): RawByteString; public name '_fpc_atari_getenv';
  104. var
  105. hp : PAnsiChar;
  106. i : longint;
  107. upperenv, str : RawByteString;
  108. begin
  109. fpGetEnv:='';
  110. hp:=basepage^.p_env;
  111. if (hp=nil) then
  112. exit;
  113. upperenv:=upcase(envvar);
  114. while hp^<>#0 do
  115. begin
  116. str:=hp;
  117. i:=pos('=',str);
  118. if upcase(copy(str,1,i-1))=upperenv then
  119. begin
  120. fpGetEnv:=copy(str,i+1,length(str)-i);
  121. break;
  122. end;
  123. { next string entry}
  124. hp:=hp+strlen(hp)+1;
  125. end;
  126. end;
  127. {*****************************************************************************
  128. System Dependent Exit code
  129. *****************************************************************************}
  130. procedure haltproc(e:longint); cdecl; external name 'haltproc';
  131. Procedure system_exit;
  132. begin
  133. haltproc(ExitCode);
  134. end;
  135. {*****************************************************************************
  136. SystemUnit Initialization
  137. *****************************************************************************}
  138. Procedure ConsoleRead(var t:TextRec);
  139. var
  140. dosResult: longint;
  141. Begin
  142. dosResult:=gemdos_fread(t.Handle,t.BufSize,t.Bufptr);
  143. t.BufPos:=0;
  144. { Reading from console on TOS does not include the terminating CR/LF }
  145. if (dosResult >= 0) then
  146. begin
  147. t.BufEnd := dosResult;
  148. if (dosResult>=1) and (t.Bufptr^[dosResult-1] = #10) then
  149. begin end
  150. else
  151. if (t.BufEnd < t.BufSize) then
  152. begin
  153. t.BufPtr^[t.BufEnd] := #13;
  154. inc(t.BufEnd);
  155. end;
  156. if (t.BufEnd < t.BufSize) then
  157. begin
  158. t.BufPtr^[t.BufEnd] := #10;
  159. inc(t.BufEnd);
  160. end;
  161. end
  162. else
  163. Error2InOutRes(dosResult);
  164. End;
  165. procedure myOpenStdIO(var f:text;mode:longint;hdl:thandle);
  166. begin
  167. OpenStdIO(f, mode, hdl);
  168. if (InOutRes=0) and (Mode=fmInput) and Do_Isdevice(hdl) then
  169. begin
  170. TextRec(f).InOutFunc:=@ConsoleRead;
  171. end;
  172. end;
  173. procedure SysInitStdIO;
  174. begin
  175. myOpenStdIO(Input,fmInput,StdInputHandle);
  176. myOpenStdIO(Output,fmOutput,StdOutputHandle);
  177. myOpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  178. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  179. myOpenStdIO(StdOut,fmOutput,StdOutputHandle);
  180. myOpenStdIO(StdErr,fmOutput,StdErrorHandle);
  181. {$endif FPC_STDOUT_TRUE_ALIAS}
  182. end;
  183. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  184. begin
  185. CheckInitialStkLen := StkLen;
  186. end;
  187. begin
  188. StackLength := CheckInitialStkLen (InitialStkLen);
  189. StackBottom := StackTop - StackLength;
  190. StackMargin := min(align(StackLength div 20,2),STACK_MARGIN_MAX);
  191. { Initialize ExitProc }
  192. ExitProc:=Nil;
  193. {$ifndef FPC_ATARI_USE_TINYHEAP}
  194. { Setup heap }
  195. InitHeap;
  196. {$endif FPC_ATARI_USE_TINYHEAP}
  197. SysInitExceptions;
  198. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  199. InitUnicodeStringManager;
  200. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  201. { Setup stdin, stdout and stderr }
  202. SysInitStdIO;
  203. { Reset IO Error }
  204. InOutRes:=0;
  205. { Setup command line arguments }
  206. SysInitParamsAndEnv;
  207. {$ifdef FPC_HAS_FEATURE_THREADING}
  208. InitSystemThreads;
  209. {$endif FPC_HAS_FEATURE_THREADING}
  210. end.