system.pp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. unit system;
  2. interface
  3. {$ifdef FULL_RTL}
  4. {$define FPC_IS_SYSTEM}
  5. { The heap for ZX Spectrum is implemented
  6. in tinyheap.inc include file,
  7. but it uses default SysGetMem names }
  8. {$define HAS_MEMORYMANAGER}
  9. {$I systemh.inc}
  10. {$I tnyheaph.inc}
  11. {$ifndef FPUNONE}
  12. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  13. {$define fpc_softfpu_interface}
  14. {$i softfpu.pp}
  15. {$undef fpc_softfpu_interface}
  16. {$endif FPC_HAS_FEATURE_SOFTFPU}
  17. {$endif FPUNONE}
  18. {$else FULL_RTL}
  19. {$mode objfpc}
  20. Type
  21. dword = longword;
  22. integer = smallint;
  23. sizeint = smallint;
  24. sizeuint = word;
  25. ptrint = smallint;
  26. ptruint = word;
  27. jmp_buf = packed record
  28. f,a,b,c,e,d,l,h,ixlo,ixhi,iylo,iyhi,splo,sphi,pclo,pchi : byte;
  29. end;
  30. pjmp_buf = ^jmp_buf;
  31. PExceptAddr = ^TExceptAddr;
  32. TExceptAddr = record
  33. end;
  34. PGuid = ^TGuid;
  35. TGuid = packed record
  36. case integer of
  37. 1 : (
  38. Data1 : DWord;
  39. Data2 : word;
  40. Data3 : word;
  41. Data4 : array[0..7] of byte;
  42. );
  43. 2 : (
  44. D1 : DWord;
  45. D2 : word;
  46. D3 : word;
  47. D4 : array[0..7] of byte;
  48. );
  49. 3 : ( { uuid fields according to RFC4122 }
  50. time_low : dword; // The low field of the timestamp
  51. time_mid : word; // The middle field of the timestamp
  52. time_hi_and_version : word; // The high field of the timestamp multiplexed with the version number
  53. clock_seq_hi_and_reserved : byte; // The high field of the clock sequence multiplexed with the variant
  54. clock_seq_low : byte; // The low field of the clock sequence
  55. node : array[0..5] of byte; // The spatially unique node identifier
  56. );
  57. end;
  58. HRESULT = Byte;
  59. TTypeKind = (tkUnknown,tkInteger,tkChar,tkEnumeration,tkFloat,
  60. tkSet,tkMethod,tkSString,tkLString,tkAString,
  61. tkWString,tkVariant,tkArray,tkRecord,tkInterface,
  62. tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord,
  63. tkDynArray,tkInterfaceRaw,tkProcVar,tkUString,tkUChar,
  64. tkHelper,tkFile,tkClassRef,tkPointer);
  65. procedure fpc_InitializeUnits;compilerproc;
  66. Procedure fpc_do_exit;compilerproc;
  67. procedure Move(const source;var dest;count:SizeInt);
  68. Procedure FillChar(var x;count:SizeInt;value:byte);
  69. function get_frame:pointer;
  70. function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;
  71. function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;
  72. Function Sptr : pointer;
  73. {$endif FULL_RTL}
  74. { OpenChannel(2) opens the upper screen
  75. OpenChannel(1) opens the lower screen
  76. OpenChannel(3) opens the ZX Printer }
  77. procedure OpenChannel(Chan: Byte);
  78. procedure PrintChar(Ch: Char);
  79. procedure PrintLn;
  80. procedure PrintHexDigit(const d: byte);
  81. procedure PrintHexByte(const b: byte);
  82. procedure PrintHexWord(const w: word);
  83. procedure Ink(colour: Byte);
  84. procedure Paper(colour: Byte);
  85. procedure GotoXY(X, Y: Byte);
  86. function ReadKey: Char;
  87. function KeyPressed: Boolean;
  88. implementation
  89. {$ifdef FULL_RTL}
  90. const
  91. LineEnding = #13#10;
  92. { LFNSupport is a variable here, defined below!!! }
  93. DirectorySeparator = '\';
  94. DriveSeparator = ':';
  95. ExtensionSeparator = '.';
  96. PathSeparator = ';';
  97. AllowDirectorySeparators : set of char = ['\','/'];
  98. AllowDriveSeparators : set of char = [':'];
  99. { FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
  100. maxExitCode = 255;
  101. MaxPathLen = 256;
  102. {$I system.inc}
  103. {$I tinyheap.inc}
  104. {$ifndef FPUNONE}
  105. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  106. {$define fpc_softfpu_implementation}
  107. {$i softfpu.pp}
  108. {$undef fpc_softfpu_implementation}
  109. { we get these functions and types from the softfpu code }
  110. {$define FPC_SYSTEM_HAS_float64}
  111. {$define FPC_SYSTEM_HAS_float32}
  112. {$define FPC_SYSTEM_HAS_flag}
  113. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  114. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  115. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  116. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  117. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  118. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  119. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  120. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  121. {$endif FPC_HAS_FEATURE_SOFTFPU}
  122. {$endif FPUNONE}
  123. {$else FULL_RTL}
  124. {$I z80.inc}
  125. {$endif FULL_RTL}
  126. var
  127. save_iy: Word; public name 'FPC_SAVE_IY';
  128. LastKey: Char absolute 23560;
  129. function ReadKey: Char;
  130. begin
  131. repeat
  132. ReadKey:=LastKey;
  133. until ReadKey<>#0;
  134. LastKey:=#0;
  135. end;
  136. function KeyPressed: Boolean;
  137. begin
  138. KeyPressed:=LastKey<>#0;
  139. end;
  140. procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; compilerproc;
  141. begin
  142. end;
  143. Procedure fpc_do_exit;[Public,Alias:'FPC_DO_EXIT']; compilerproc;
  144. begin
  145. repeat
  146. until false;
  147. end;
  148. procedure OpenChannel(Chan: Byte);
  149. begin
  150. asm
  151. ld iy,(save_iy)
  152. ld a, (Chan)
  153. push ix
  154. call 5633
  155. pop ix
  156. ld (save_iy),iy
  157. end;
  158. end;
  159. procedure PrintChar(Ch: Char);
  160. begin
  161. asm
  162. ld iy,(save_iy)
  163. ld a, (Ch)
  164. push ix
  165. rst 16
  166. pop ix
  167. ld (save_iy),iy
  168. end;
  169. end;
  170. procedure PrintLn;
  171. begin
  172. PrintChar(#13);
  173. end;
  174. procedure PrintHexDigit(const d: byte);
  175. begin
  176. { the code generator is still to broken to compile this, so we do it in a stupid way }
  177. { if (d >= 0) or (d <= 9) then
  178. PrintChar(Char(d + Ord('0')))
  179. else if (d >= 10) and (d <= 15) then
  180. PrintChar(Char(d + (Ord('A') - 10)));}
  181. if d=0 then
  182. PrintChar('0')
  183. else if d=1 then
  184. PrintChar('1')
  185. else if d=2 then
  186. PrintChar('2')
  187. else if d=3 then
  188. PrintChar('3')
  189. else if d=4 then
  190. PrintChar('4')
  191. else if d=5 then
  192. PrintChar('5')
  193. else if d=6 then
  194. PrintChar('6')
  195. else if d=7 then
  196. PrintChar('7')
  197. else if d=8 then
  198. PrintChar('8')
  199. else if d=9 then
  200. PrintChar('9')
  201. else if d=10 then
  202. PrintChar('A')
  203. else if d=11 then
  204. PrintChar('B')
  205. else if d=12 then
  206. PrintChar('C')
  207. else if d=13 then
  208. PrintChar('D')
  209. else if d=14 then
  210. PrintChar('E')
  211. else if d=15 then
  212. PrintChar('F')
  213. else
  214. PrintChar('?');
  215. end;
  216. procedure PrintHexByte(const b: byte);
  217. begin
  218. PrintHexDigit(b shr 4);
  219. PrintHexDigit(b and $F);
  220. end;
  221. procedure PrintHexWord(const w: word);
  222. begin
  223. PrintHexByte(Byte(w shr 8));
  224. PrintHexByte(Byte(w));
  225. end;
  226. procedure Ink(colour: Byte);
  227. begin
  228. PrintChar(#16);
  229. PrintChar(Char(colour));
  230. end;
  231. procedure Paper(colour: Byte);
  232. begin
  233. PrintChar(#17);
  234. PrintChar(Char(colour));
  235. end;
  236. procedure GotoXY(X, Y: Byte);
  237. begin
  238. PrintChar(#22);
  239. PrintChar(Char(X-1));
  240. PrintChar(Char(Y-1));
  241. end;
  242. end.