system.pp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. unit system;
  2. interface
  3. {$define FPC_IS_SYSTEM}
  4. { The heap for ZX Spectrum is implemented
  5. in tinyheap.inc include file,
  6. but it uses default SysGetMem names }
  7. {$define HAS_MEMORYMANAGER}
  8. { Use AnsiChar for files }
  9. {$define FPC_ANSI_TEXTFILEREC}
  10. {$define FPC_STDOUT_TRUE_ALIAS}
  11. {$define FPC_STDERR_IS_ALIAS_FOR_STDOUT}
  12. {$I systemh.inc}
  13. {$I tnyheaph.inc}
  14. {$ifndef FPUNONE}
  15. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  16. {$define fpc_softfpu_interface}
  17. {$i softfpu.pp}
  18. {$undef fpc_softfpu_interface}
  19. {$endif FPC_HAS_FEATURE_SOFTFPU}
  20. {$endif FPUNONE}
  21. var
  22. { Mem[] support }
  23. mem : array[0..$7fff-1] of byte absolute $0;
  24. { memw : array[0..($7fff div sizeof(word))-1] of word absolute $0:$0;
  25. meml : array[0..($7fff div sizeof(longint))-1] of longint absolute $0:$0;}
  26. { OpenChannel(2) opens the upper screen
  27. OpenChannel(1) opens the lower screen
  28. OpenChannel(3) opens the ZX Printer }
  29. procedure OpenChannel(Chan: Byte);
  30. procedure PrintChar(Ch: AnsiChar);
  31. procedure PrintLn;
  32. procedure PrintShortString(const s: ShortString);
  33. procedure PrintHexDigit(const d: byte);
  34. procedure PrintHexByte(const b: byte);
  35. procedure PrintHexWord(const w: word);
  36. procedure Ink(colour: Byte);
  37. procedure Paper(colour: Byte);
  38. procedure GotoXY(X, Y: Byte);
  39. function ReadKey: AnsiChar;
  40. function KeyPressed: Boolean;
  41. implementation
  42. const
  43. LineEnding = #13;
  44. { LFNSupport is a variable here, defined below!!! }
  45. DirectorySeparator = '\';
  46. DriveSeparator = ':';
  47. ExtensionSeparator = '.';
  48. PathSeparator = ';';
  49. AllowDirectorySeparators : set of AnsiChar = ['\','/'];
  50. AllowDriveSeparators : set of AnsiChar = [':'];
  51. { FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
  52. maxExitCode = 255;
  53. MaxPathLen = 256;
  54. { Default filehandles }
  55. UnusedHandle = $ffff;{ instead of -1, as it is a word value}
  56. StdInputHandle = 0;
  57. StdOutputHandle = 1;
  58. StdErrorHandle = 2;
  59. FileNameCaseSensitive : boolean = false;
  60. FileNameCasePreserving: boolean = false;
  61. CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
  62. sLineBreak = LineEnding;
  63. DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCR;
  64. var
  65. fpc_stackarea_start: word; external name '__fpc_stackarea_start';
  66. fpc_stackarea_end: word; external name '__fpc_stackarea_end';
  67. __heapsize: Word;external name '__heapsize';
  68. __fpc_initialheap: array[0..0] of byte;external name '__fpc_initialheap';
  69. {$I system.inc}
  70. {$I tinyheap.inc}
  71. {$ifndef FPUNONE}
  72. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  73. {$define fpc_softfpu_implementation}
  74. {$i softfpu.pp}
  75. {$undef fpc_softfpu_implementation}
  76. { we get these functions and types from the softfpu code }
  77. {$define FPC_SYSTEM_HAS_float64}
  78. {$define FPC_SYSTEM_HAS_float32}
  79. {$define FPC_SYSTEM_HAS_flag}
  80. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  81. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  82. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  83. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  84. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  85. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  86. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  87. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  88. {$endif FPC_HAS_FEATURE_SOFTFPU}
  89. {$endif FPUNONE}
  90. procedure randomize;
  91. begin
  92. end;
  93. function GetProcessID: SizeUInt;
  94. begin
  95. GetProcessID:=0;
  96. end;
  97. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  98. begin
  99. result := stklen;
  100. end;
  101. procedure system_exit;
  102. begin
  103. repeat
  104. until false;
  105. end;
  106. var
  107. save_iy: Word; public name 'FPC_SAVE_IY';
  108. LastKey: AnsiChar absolute 23560;
  109. function ReadKey: AnsiChar;
  110. begin
  111. repeat
  112. ReadKey:=LastKey;
  113. until ReadKey<>#0;
  114. LastKey:=#0;
  115. end;
  116. function KeyPressed: Boolean;
  117. begin
  118. KeyPressed:=LastKey<>#0;
  119. end;
  120. procedure OpenChannel(Chan: Byte);assembler;
  121. asm
  122. ld iy,(save_iy)
  123. ld a, (Chan)
  124. push ix
  125. call 5633
  126. pop ix
  127. ld (save_iy),iy
  128. end;
  129. procedure PrintChar(Ch: AnsiChar);assembler;
  130. asm
  131. ld iy,(save_iy)
  132. ld a, (Ch)
  133. push ix
  134. rst 16
  135. pop ix
  136. ld (save_iy),iy
  137. end;
  138. procedure PrintLn;
  139. begin
  140. PrintChar(#13);
  141. end;
  142. procedure PrintHexDigit(const d: byte);
  143. begin
  144. { the code generator is still to broken to compile this, so we do it in a stupid way }
  145. { if (d >= 0) or (d <= 9) then
  146. PrintChar(AnsiChar(d + Ord('0')))
  147. else if (d >= 10) and (d <= 15) then
  148. PrintChar(AnsiChar(d + (Ord('A') - 10)));}
  149. if d=0 then
  150. PrintChar('0')
  151. else if d=1 then
  152. PrintChar('1')
  153. else if d=2 then
  154. PrintChar('2')
  155. else if d=3 then
  156. PrintChar('3')
  157. else if d=4 then
  158. PrintChar('4')
  159. else if d=5 then
  160. PrintChar('5')
  161. else if d=6 then
  162. PrintChar('6')
  163. else if d=7 then
  164. PrintChar('7')
  165. else if d=8 then
  166. PrintChar('8')
  167. else if d=9 then
  168. PrintChar('9')
  169. else if d=10 then
  170. PrintChar('A')
  171. else if d=11 then
  172. PrintChar('B')
  173. else if d=12 then
  174. PrintChar('C')
  175. else if d=13 then
  176. PrintChar('D')
  177. else if d=14 then
  178. PrintChar('E')
  179. else if d=15 then
  180. PrintChar('F')
  181. else
  182. PrintChar('?');
  183. end;
  184. procedure PrintHexByte(const b: byte);
  185. begin
  186. PrintHexDigit(b shr 4);
  187. PrintHexDigit(b and $F);
  188. end;
  189. procedure PrintHexWord(const w: word);
  190. begin
  191. PrintHexByte(Byte(w shr 8));
  192. PrintHexByte(Byte(w));
  193. end;
  194. procedure Ink(colour: Byte);
  195. begin
  196. PrintChar(#16);
  197. PrintChar(AnsiChar(colour));
  198. end;
  199. procedure Paper(colour: Byte);
  200. begin
  201. PrintChar(#17);
  202. PrintChar(AnsiChar(colour));
  203. end;
  204. procedure GotoXY(X, Y: Byte);
  205. begin
  206. PrintChar(#22);
  207. PrintChar(AnsiChar(Y-1));
  208. PrintChar(AnsiChar(X-1));
  209. end;
  210. procedure PrintShortString(const s: ShortString);
  211. var
  212. i: byte;
  213. begin
  214. for i:=1 to length(s) do
  215. PrintChar(s[i]);
  216. end;
  217. {*****************************************************************************
  218. SystemUnit Initialization
  219. *****************************************************************************}
  220. procedure InitZXHeap;
  221. begin
  222. RegisterTinyHeapBlock_Simple_Prealigned(@__fpc_initialheap,__heapsize);
  223. end;
  224. procedure SysInitStdIO;
  225. begin
  226. OpenStdIO(Input,fmInput,StdInputHandle);
  227. OpenStdIO(Output,fmOutput,StdOutputHandle);
  228. {$ifndef FPC_STDERR_IS_ALIAS_FOR_STDOUT}
  229. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  230. {$endif FPC_STDERR_IS_ALIAS_FOR_STDOUT}
  231. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  232. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  233. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  234. {$endif FPC_STDOUT_TRUE_ALIAS}
  235. end;
  236. begin
  237. StackBottom:=@fpc_stackarea_start;
  238. StackLength:=(@fpc_stackarea_end-@fpc_stackarea_start)+1;
  239. { To be set if this is a GUI or console application }
  240. IsConsole := TRUE;
  241. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  242. { If dynlibs feature is disabled,
  243. IsLibrary is a constant, which can thus not be set to a value }
  244. { To be set if this is a library and not a program }
  245. IsLibrary := FALSE;
  246. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  247. { Setup heap }
  248. InitZXHeap;
  249. SysInitExceptions;
  250. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  251. initunicodestringmanager;
  252. {$endif def FPC_HAS_FEATURE_UNICODESTRINGS}
  253. { Setup stdin, stdout and stderr }
  254. SysInitStdIO;
  255. { Reset IO Error }
  256. InOutRes:=0;
  257. {$ifdef FPC_HAS_FEATURE_THREADING}
  258. InitSystemThreads;
  259. {$endif}
  260. end.