2
0

system.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_TINYHEAP}
  17. {$ifdef FPC_QL_USE_TINYHEAP}
  18. {$define HAS_MEMORYMANAGER}
  19. {$endif FPC_QL_USE_TINYHEAP}
  20. {$i systemh.inc}
  21. {$ifdef FPC_QL_USE_TINYHEAP}
  22. {$i tnyheaph.inc}
  23. {$endif FPC_QL_USE_TINYHEAP}
  24. {Platform specific information}
  25. const
  26. LineEnding = #10;
  27. LFNSupport = false;
  28. CtrlZMarksEOF: boolean = false; (* #26 not considered as end of file *)
  29. DirectorySeparator = '\';
  30. DriveSeparator = ':';
  31. ExtensionSeparator = '.';
  32. PathSeparator = ';';
  33. AllowDirectorySeparators : set of char = ['\','/'];
  34. AllowDriveSeparators : set of char = [':'];
  35. FileNameCaseSensitive = false;
  36. FileNameCasePreserving = false;
  37. maxExitCode = 255;
  38. MaxPathLen = 255;
  39. AllFilesMask = '*.*';
  40. sLineBreak = LineEnding;
  41. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsLF;
  42. const
  43. UnusedHandle = -1;
  44. StdInputHandle: longint = UnusedHandle;
  45. StdOutputHandle: longint = UnusedHandle;
  46. StdErrorHandle: longint = UnusedHandle;
  47. var
  48. args: PChar;
  49. argc: LongInt;
  50. argv: PPChar;
  51. envp: PPChar;
  52. heapStart: pointer;
  53. {$if defined(FPUSOFT)}
  54. {$define fpc_softfpu_interface}
  55. {$i softfpu.pp}
  56. {$undef fpc_softfpu_interface}
  57. {$endif defined(FPUSOFT)}
  58. implementation
  59. {$if defined(FPUSOFT)}
  60. {$define fpc_softfpu_implementation}
  61. {$define softfpu_compiler_mul32to64}
  62. {$define softfpu_inline}
  63. {$i softfpu.pp}
  64. {$undef fpc_softfpu_implementation}
  65. { we get these functions and types from the softfpu code }
  66. {$define FPC_SYSTEM_HAS_float64}
  67. {$define FPC_SYSTEM_HAS_float32}
  68. {$define FPC_SYSTEM_HAS_flag}
  69. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  70. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  71. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  72. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  73. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  74. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  75. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  76. {$endif defined(FPUSOFT)}
  77. {$i system.inc}
  78. {$ifdef FPC_QL_USE_TINYHEAP}
  79. {$i tinyheap.inc}
  80. {$endif FPC_QL_USE_TINYHEAP}
  81. function GetProcessID:SizeUInt;
  82. begin
  83. GetProcessID := mt_inf(nil, nil);
  84. end;
  85. procedure SysInitParamsAndEnv;
  86. begin
  87. end;
  88. procedure randomize;
  89. begin
  90. {$WARNING: randseed is uninitialized}
  91. randseed:=0;
  92. end;
  93. procedure PrintStr(ch: longint; const s: shortstring);
  94. begin
  95. io_sstrg(ch,-1,@s[1],ord(s[0]));
  96. end;
  97. procedure DebugStr(const s: shortstring); public name '_dbgstr';
  98. var
  99. i: longint;
  100. begin
  101. PrintStr(stdOutputHandle,s);
  102. for i:=0 to 10000 do begin end;
  103. end;
  104. {$ifdef FPC_QL_USE_TINYHEAP}
  105. procedure InitQLHeap;
  106. begin
  107. HeapOrg:=nil;
  108. HeapEnd:=nil;
  109. FreeList:=nil;
  110. HeapPtr:=nil;
  111. end;
  112. {$endif}
  113. {*****************************************************************************
  114. System Dependent Entry code
  115. *****************************************************************************}
  116. { QL/QDOS specific startup }
  117. procedure SysInitQDOS;
  118. var
  119. r: TQLRect;
  120. begin
  121. stdInputHandle:=io_open('con_',Q_OPEN);
  122. stdOutputHandle:=stdInputHandle;
  123. stdErrorHandle:=stdInputHandle;
  124. r.q_width:=512;
  125. r.q_height:=256;
  126. r.q_x:=0;
  127. r.q_y:=0;
  128. sd_wdef(stdInputHandle,-1,2,1,@r);
  129. sd_clear(stdInputHandle,-1);
  130. end;
  131. {*****************************************************************************
  132. System Dependent Exit code
  133. *****************************************************************************}
  134. procedure haltproc(e:longint); external name '_haltproc';
  135. procedure system_exit;
  136. const
  137. anyKey: string = 'Press any key to exit';
  138. begin
  139. io_sstrg(stdOutputHandle, -1, @anyKey[1], ord(anyKey[0]));
  140. io_fbyte(stdInputHandle, -1);
  141. stdInputHandle:=UnusedHandle;
  142. stdOutputHandle:=UnusedHandle;
  143. stdErrorHandle:=UnusedHandle;
  144. haltproc(exitcode);
  145. end;
  146. {*****************************************************************************
  147. System Unit Initialization
  148. *****************************************************************************}
  149. procedure SysInitStdIO;
  150. begin
  151. OpenStdIO(Input,fmInput,StdInputHandle);
  152. OpenStdIO(Output,fmOutput,StdOutputHandle);
  153. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  154. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  155. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  156. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  157. {$endif FPC_STDOUT_TRUE_ALIAS}
  158. end;
  159. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  160. begin
  161. CheckInitialStkLen := StkLen;
  162. end;
  163. begin
  164. StackLength := CheckInitialStkLen (InitialStkLen);
  165. { Initialize ExitProc }
  166. ExitProc:=Nil;
  167. SysInitQDOS;
  168. {$ifndef FPC_QL_USE_TINYHEAP}
  169. { Setup heap }
  170. InitHeap;
  171. {$else FPC_QL_USE_TINYHEAP}
  172. InitQLHeap;
  173. {$endif FPC_QL_USE_TINYHEAP}
  174. SysInitExceptions;
  175. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  176. InitUnicodeStringManager;
  177. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  178. { Setup stdin, stdout and stderr }
  179. SysInitStdIO;
  180. { Reset IO Error }
  181. InOutRes:=0;
  182. { Setup command line arguments }
  183. SysInitParamsAndEnv;
  184. {$ifdef FPC_HAS_FEATURE_THREADING}
  185. InitSystemThreads;
  186. {$endif FPC_HAS_FEATURE_THREADING}
  187. end.