system.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 = $ffff;
  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. QCON: longint; // QDOS console
  53. QSCR: longint; // QDOS screen
  54. heapStart: pointer;
  55. {$if defined(FPUSOFT)}
  56. {$define fpc_softfpu_interface}
  57. {$i softfpu.pp}
  58. {$undef fpc_softfpu_interface}
  59. {$endif defined(FPUSOFT)}
  60. implementation
  61. {$if defined(FPUSOFT)}
  62. {$define fpc_softfpu_implementation}
  63. {$define softfpu_compiler_mul32to64}
  64. {$define softfpu_inline}
  65. {$i softfpu.pp}
  66. {$undef fpc_softfpu_implementation}
  67. { we get these functions and types from the softfpu code }
  68. {$define FPC_SYSTEM_HAS_float64}
  69. {$define FPC_SYSTEM_HAS_float32}
  70. {$define FPC_SYSTEM_HAS_flag}
  71. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  72. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  73. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  74. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  75. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  76. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  77. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  78. {$endif defined(FPUSOFT)}
  79. {$i system.inc}
  80. {$ifdef FPC_QL_USE_TINYHEAP}
  81. {$i tinyheap.inc}
  82. {$endif FPC_QL_USE_TINYHEAP}
  83. function GetProcessID:SizeUInt;
  84. begin
  85. GetProcessID := 1;
  86. end;
  87. procedure SysInitParamsAndEnv;
  88. begin
  89. end;
  90. procedure randomize;
  91. begin
  92. {$WARNING: randseed is uninitialized}
  93. randseed:=0;
  94. end;
  95. procedure PrintStr(ch: longint; const s: shortstring);
  96. begin
  97. io_sstrg(ch,-1,@s[1],ord(s[0]));
  98. end;
  99. procedure PrintStr2(ch: longint; const s: shortstring);
  100. var
  101. i: smallint;
  102. begin
  103. for i:=1 to ord(s[0]) do
  104. io_sbyte(ch,-1,s[i]);
  105. end;
  106. procedure DebugStr(const s: shortstring); public name '_dbgstr';
  107. var
  108. i: longint;
  109. begin
  110. PrintStr($00010001,s);
  111. for i:=0 to 10000 do begin end;
  112. end;
  113. {$ifdef FPC_QL_USE_TINYHEAP}
  114. procedure InitQLHeap;
  115. begin
  116. HeapOrg:=nil;
  117. HeapEnd:=nil;
  118. FreeList:=nil;
  119. HeapPtr:=nil;
  120. end;
  121. {$endif}
  122. {*****************************************************************************
  123. System Dependent Entry code
  124. *****************************************************************************}
  125. { QL/QDOS specific startup }
  126. procedure SysInitQDOS;
  127. var
  128. r: TQLRect;
  129. begin
  130. stdInputHandle:=io_open('con_',Q_OPEN);
  131. stdOutputHandle:=stdInputHandle;
  132. stdErrorHandle:=stdInputHandle;
  133. QCON:=stdInputHandle;
  134. r.q_width:=512;
  135. r.q_height:=256;
  136. r.q_x:=0;
  137. r.q_y:=0;
  138. sd_wdef(stdInputHandle,-1,0,16,@r);
  139. sd_clear(stdInputHandle,-1);
  140. // QSCR:=io_open('scr_',Q_OPEN);
  141. end;
  142. {*****************************************************************************
  143. System Dependent Exit code
  144. *****************************************************************************}
  145. procedure haltproc(e:longint); external name '_haltproc';
  146. procedure system_exit;
  147. begin
  148. // io_close(QCON);
  149. // io_close(QSCR);
  150. stdInputHandle:=UnusedHandle;
  151. stdOutputHandle:=UnusedHandle;
  152. stdErrorHandle:=UnusedHandle;
  153. haltproc(exitcode);
  154. end;
  155. {*****************************************************************************
  156. System Unit Initialization
  157. *****************************************************************************}
  158. procedure SysInitStdIO;
  159. begin
  160. OpenStdIO(Input,fmInput,StdInputHandle);
  161. OpenStdIO(Output,fmOutput,StdOutputHandle);
  162. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  163. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  164. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  165. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  166. {$endif FPC_STDOUT_TRUE_ALIAS}
  167. end;
  168. function CheckInitialStkLen (StkLen: SizeUInt): SizeUInt;
  169. begin
  170. CheckInitialStkLen := StkLen;
  171. end;
  172. begin
  173. StackLength := CheckInitialStkLen (InitialStkLen);
  174. { Initialize ExitProc }
  175. ExitProc:=Nil;
  176. SysInitQDOS;
  177. {$ifndef FPC_QL_USE_TINYHEAP}
  178. { Setup heap }
  179. InitHeap;
  180. {$else FPC_QL_USE_TINYHEAP}
  181. InitQLHeap;
  182. {$endif FPC_QL_USE_TINYHEAP}
  183. SysInitExceptions;
  184. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  185. InitUnicodeStringManager;
  186. {$endif FPC_HAS_FEATURE_UNICODESTRINGS}
  187. { Setup stdin, stdout and stderr }
  188. SysInitStdIO;
  189. { Reset IO Error }
  190. InOutRes:=0;
  191. { Setup command line arguments }
  192. SysInitParamsAndEnv;
  193. {$ifdef FPC_HAS_FEATURE_THREADING}
  194. InitSystemThreads;
  195. {$endif FPC_HAS_FEATURE_THREADING}
  196. end.