system.pp 6.6 KB

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