system.pp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 Ansi Char 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: Char);
  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: Char;
  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 char = ['\','/'];
  50. AllowDriveSeparators : set of char = [':'];
  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. __heapsize: Word;external name '__heapsize';
  66. __fpc_initialheap: array[0..0] of byte;external name '__fpc_initialheap';
  67. {$I system.inc}
  68. {$I tinyheap.inc}
  69. {$ifndef FPUNONE}
  70. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  71. {$define fpc_softfpu_implementation}
  72. {$i softfpu.pp}
  73. {$undef fpc_softfpu_implementation}
  74. { we get these functions and types from the softfpu code }
  75. {$define FPC_SYSTEM_HAS_float64}
  76. {$define FPC_SYSTEM_HAS_float32}
  77. {$define FPC_SYSTEM_HAS_flag}
  78. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  79. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  80. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  81. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  82. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  83. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  84. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  85. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  86. {$endif FPC_HAS_FEATURE_SOFTFPU}
  87. {$endif FPUNONE}
  88. procedure randomize;
  89. begin
  90. end;
  91. function GetProcessID: SizeUInt;
  92. begin
  93. GetProcessID:=0;
  94. end;
  95. function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
  96. begin
  97. result := stklen;
  98. end;
  99. procedure system_exit;
  100. begin
  101. repeat
  102. until false;
  103. end;
  104. var
  105. save_iy: Word; public name 'FPC_SAVE_IY';
  106. LastKey: Char absolute 23560;
  107. function ReadKey: Char;
  108. begin
  109. repeat
  110. ReadKey:=LastKey;
  111. until ReadKey<>#0;
  112. LastKey:=#0;
  113. end;
  114. function KeyPressed: Boolean;
  115. begin
  116. KeyPressed:=LastKey<>#0;
  117. end;
  118. procedure OpenChannel(Chan: Byte);assembler;
  119. asm
  120. ld iy,(save_iy)
  121. ld a, (Chan)
  122. push ix
  123. call 5633
  124. pop ix
  125. ld (save_iy),iy
  126. end;
  127. procedure PrintChar(Ch: Char);assembler;
  128. asm
  129. ld iy,(save_iy)
  130. ld a, (Ch)
  131. push ix
  132. rst 16
  133. pop ix
  134. ld (save_iy),iy
  135. end;
  136. procedure PrintLn;
  137. begin
  138. PrintChar(#13);
  139. end;
  140. procedure PrintHexDigit(const d: byte);
  141. begin
  142. { the code generator is still to broken to compile this, so we do it in a stupid way }
  143. { if (d >= 0) or (d <= 9) then
  144. PrintChar(Char(d + Ord('0')))
  145. else if (d >= 10) and (d <= 15) then
  146. PrintChar(Char(d + (Ord('A') - 10)));}
  147. if d=0 then
  148. PrintChar('0')
  149. else if d=1 then
  150. PrintChar('1')
  151. else if d=2 then
  152. PrintChar('2')
  153. else if d=3 then
  154. PrintChar('3')
  155. else if d=4 then
  156. PrintChar('4')
  157. else if d=5 then
  158. PrintChar('5')
  159. else if d=6 then
  160. PrintChar('6')
  161. else if d=7 then
  162. PrintChar('7')
  163. else if d=8 then
  164. PrintChar('8')
  165. else if d=9 then
  166. PrintChar('9')
  167. else if d=10 then
  168. PrintChar('A')
  169. else if d=11 then
  170. PrintChar('B')
  171. else if d=12 then
  172. PrintChar('C')
  173. else if d=13 then
  174. PrintChar('D')
  175. else if d=14 then
  176. PrintChar('E')
  177. else if d=15 then
  178. PrintChar('F')
  179. else
  180. PrintChar('?');
  181. end;
  182. procedure PrintHexByte(const b: byte);
  183. begin
  184. PrintHexDigit(b shr 4);
  185. PrintHexDigit(b and $F);
  186. end;
  187. procedure PrintHexWord(const w: word);
  188. begin
  189. PrintHexByte(Byte(w shr 8));
  190. PrintHexByte(Byte(w));
  191. end;
  192. procedure Ink(colour: Byte);
  193. begin
  194. PrintChar(#16);
  195. PrintChar(Char(colour));
  196. end;
  197. procedure Paper(colour: Byte);
  198. begin
  199. PrintChar(#17);
  200. PrintChar(Char(colour));
  201. end;
  202. procedure GotoXY(X, Y: Byte);
  203. begin
  204. PrintChar(#22);
  205. PrintChar(Char(Y-1));
  206. PrintChar(Char(X-1));
  207. end;
  208. procedure PrintShortString(const s: ShortString);
  209. var
  210. i: byte;
  211. begin
  212. for i:=1 to length(s) do
  213. PrintChar(s[i]);
  214. end;
  215. {*****************************************************************************
  216. SystemUnit Initialization
  217. *****************************************************************************}
  218. procedure InitZXHeap;
  219. begin
  220. RegisterTinyHeapBlock_Simple_Prealigned(@__fpc_initialheap,__heapsize);
  221. end;
  222. procedure SysInitStdIO;
  223. begin
  224. OpenStdIO(Input,fmInput,StdInputHandle);
  225. OpenStdIO(Output,fmOutput,StdOutputHandle);
  226. {$ifndef FPC_STDERR_IS_ALIAS_FOR_STDOUT}
  227. OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
  228. {$endif FPC_STDERR_IS_ALIAS_FOR_STDOUT}
  229. {$ifndef FPC_STDOUT_TRUE_ALIAS}
  230. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  231. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  232. {$endif FPC_STDOUT_TRUE_ALIAS}
  233. end;
  234. begin
  235. { StackBottom := __stkbottom;
  236. StackLength := __stktop - __stkbottom;}
  237. { To be set if this is a GUI or console application }
  238. IsConsole := TRUE;
  239. {$ifdef FPC_HAS_FEATURE_DYNLIBS}
  240. { If dynlibs feature is disabled,
  241. IsLibrary is a constant, which can thus not be set to a value }
  242. { To be set if this is a library and not a program }
  243. IsLibrary := FALSE;
  244. {$endif def FPC_HAS_FEATURE_DYNLIBS}
  245. { Setup heap }
  246. InitZXHeap;
  247. SysInitExceptions;
  248. {$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
  249. initunicodestringmanager;
  250. {$endif def FPC_HAS_FEATURE_UNICODESTRINGS}
  251. { Setup stdin, stdout and stderr }
  252. SysInitStdIO;
  253. { Reset IO Error }
  254. InOutRes:=0;
  255. {$ifdef FPC_HAS_FEATURE_THREADING}
  256. InitSystemThreads;
  257. {$endif}
  258. end.