system.pp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2020 by Karoly Balogh
  4. System unit for the Sinclair QL
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit System;
  12. interface
  13. {$define FPC_IS_SYSTEM}
  14. {$define FPC_STDOUT_TRUE_ALIAS}
  15. {$define FPC_ANSI_TEXTFILEREC}
  16. {$define FPC_QL_USE_OSHEAP}
  17. {$ifdef FPC_QL_USE_OSHEAP}
  18. {$define HAS_MEMORYMANAGER}
  19. {$endif FPC_QL_USE_OSHEAP}
  20. {$i systemh.inc}
  21. {Platform specific information}
  22. const
  23. LineEnding = #10;
  24. LFNSupport = false;
  25. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  26. DirectorySeparator = '\';
  27. DriveSeparator = ':';
  28. ExtensionSeparator = '.';
  29. PathSeparator = ';';
  30. AllowDirectorySeparators : set of char = ['\','/'];
  31. AllowDriveSeparators : set of char = [':'];
  32. FileNameCaseSensitive = false;
  33. FileNameCasePreserving = false;
  34. maxExitCode = 255;
  35. MaxPathLen = 255;
  36. AllFilesMask = '*.*';
  37. sLineBreak = LineEnding;
  38. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  39. const
  40. UnusedHandle = -1;
  41. StdInputHandle: longint = UnusedHandle;
  42. StdOutputHandle: longint = UnusedHandle;
  43. StdErrorHandle: longint = UnusedHandle;
  44. var
  45. args: PChar;
  46. argc: LongInt;
  47. argv: PPChar;
  48. envp: PPChar;
  49. heapStart: pointer;
  50. {$if defined(FPUSOFT)}
  51. {$define fpc_softfpu_interface}
  52. {$i softfpu.pp}
  53. {$undef fpc_softfpu_interface}
  54. {$endif defined(FPUSOFT)}
  55. implementation
  56. {$if defined(FPUSOFT)}
  57. {$define fpc_softfpu_implementation}
  58. {$define softfpu_compiler_mul32to64}
  59. {$define softfpu_inline}
  60. {$i softfpu.pp}
  61. {$undef fpc_softfpu_implementation}
  62. { we get these functions and types from the softfpu code }
  63. {$define FPC_SYSTEM_HAS_float64}
  64. {$define FPC_SYSTEM_HAS_float32}
  65. {$define FPC_SYSTEM_HAS_flag}
  66. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  67. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  68. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  69. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  70. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  71. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  72. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  73. {$endif defined(FPUSOFT)}
  74. {$i system.inc}
  75. {$ifdef FPC_QL_USE_OSHEAP}
  76. {$i osheap.inc}
  77. {$endif FPC_QL_USE_OSHEAP}
  78. function GetProcessID:SizeUInt;
  79. begin
  80. GetProcessID := mt_inf(nil, nil);
  81. end;
  82. var
  83. CmdLine_len : word; external name '__CmdLine_len';
  84. pCmdLine : pchar; external name '__pCmdLine';
  85. procedure SysInitParamsAndEnv;
  86. var
  87. str_len, i : word;
  88. c : char;
  89. in_word : boolean;
  90. const
  91. word_separators=[' ',#0];
  92. begin
  93. str_len:=CmdLine_len;
  94. argc:=0;
  95. argv:=nil;
  96. args:=pCmdLine;
  97. if not assigned(args) then
  98. exit;
  99. { Parse command line }
  100. { Compute argc imply replace spaces by #0 }
  101. i:=0;
  102. in_word:=false;
  103. while (i < str_len) do
  104. begin
  105. c:=args[i];
  106. if (not in_word) then
  107. begin
  108. if not(c in word_separators) then
  109. begin
  110. inc(argc);
  111. argv[argc]:=@args[i];
  112. in_word:=true;
  113. end
  114. else
  115. begin
  116. args[i]:=#0;
  117. end;
  118. end
  119. else if (c in word_separators) then
  120. begin
  121. in_word:=false;
  122. args[i]:=#0;
  123. end;
  124. inc(i);
  125. end;
  126. end;
  127. procedure randomize;
  128. begin
  129. { Get the current date/time }
  130. randseed:=mt_rclck;
  131. end;
  132. procedure PrintStr(ch: longint; const s: shortstring);
  133. begin
  134. io_sstrg(ch,-1,@s[1],ord(s[0]));
  135. end;
  136. procedure DebugStr(const s: shortstring); public name '_dbgstr';
  137. var
  138. i: longint;
  139. begin
  140. PrintStr(stdOutputHandle,s);
  141. for i:=0 to 10000 do begin end;
  142. end;
  143. {*****************************************************************************
  144. System Dependent Entry code
  145. *****************************************************************************}
  146. { QL/QDOS specific startup }
  147. procedure SysInitQDOS;
  148. var
  149. r: TQLRect;
  150. begin
  151. stdInputHandle:=io_open('con_',Q_OPEN);
  152. stdOutputHandle:=stdInputHandle;
  153. stdErrorHandle:=stdInputHandle;
  154. r.q_width:=512;
  155. r.q_height:=256;
  156. r.q_x:=0;
  157. r.q_y:=0;
  158. sd_wdef(stdInputHandle,-1,2,1,@r);
  159. sd_clear(stdInputHandle,-1);
  160. end;
  161. {*****************************************************************************
  162. System Dependent Exit code
  163. *****************************************************************************}
  164. procedure haltproc(e:longint); external name '_haltproc';
  165. procedure system_exit;
  166. const
  167. anyKey: string = 'Press any key to exit';
  168. begin
  169. io_sstrg(stdOutputHandle, -1, @anyKey[1], ord(anyKey[0]));
  170. io_fbyte(stdInputHandle, -1);
  171. stdInputHandle:=UnusedHandle;
  172. stdOutputHandle:=UnusedHandle;
  173. stdErrorHandle:=UnusedHandle;
  174. haltproc(exitcode);
  175. end;
  176. {*****************************************************************************
  177. System Unit Initialization
  178. *****************************************************************************}
  179. procedure SysInitStdIO;
  180. begin
  181. OpenStdIO(Input,fmInput,StdInputHandle);
  182. OpenStdIO(Output,fmOutput,StdOutputHandle);
  183. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  184. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  185. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  186. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  187. {$endif FPC_STDOUT_TRUE_ALIAS}
  188. end;
  189. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  190. begin
  191. CheckInitialStkLen := StkLen;
  192. end;
  193. begin
  194. StackLength := CheckInitialStkLen (InitialStkLen);
  195. { Initialize ExitProc }
  196. ExitProc:=Nil;
  197. SysInitQDOS;
  198. {$ifndef FPC_QL_USE_OSHEAP}
  199. { Setup heap }
  200. InitHeap;
  201. {$else FPC_QL_USE_OSHEAP}
  202. // InitOSHeap;
  203. {$endif FPC_QL_USE_OSHEAP}
  204. SysInitExceptions;
  205. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  206. InitUnicodeStringManager;
  207. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  208. { Setup stdin, stdout and stderr }
  209. SysInitStdIO;
  210. { Reset IO Error }
  211. InOutRes:=0;
  212. { Setup command line arguments }
  213. SysInitParamsAndEnv;
  214. {$ifdef FPC_HAS_FEATURE_THREADING}
  215. InitSystemThreads;
  216. {$endif FPC_HAS_FEATURE_THREADING}
  217. end.