2
0

system.pp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. {$I system.inc}
  91. {$I tinyheap.inc}
  92. {$ifndef FPUNONE}
  93. {$ifdef FPC_HAS_FEATURE_SOFTFPU}
  94. {$define fpc_softfpu_implementation}
  95. {$i softfpu.pp}
  96. {$undef fpc_softfpu_implementation}
  97. { we get these functions and types from the softfpu code }
  98. {$define FPC_SYSTEM_HAS_float64}
  99. {$define FPC_SYSTEM_HAS_float32}
  100. {$define FPC_SYSTEM_HAS_flag}
  101. {$define FPC_SYSTEM_HAS_extractFloat64Frac0}
  102. {$define FPC_SYSTEM_HAS_extractFloat64Frac1}
  103. {$define FPC_SYSTEM_HAS_extractFloat64Exp}
  104. {$define FPC_SYSTEM_HAS_extractFloat64Frac}
  105. {$define FPC_SYSTEM_HAS_extractFloat64Sign}
  106. {$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
  107. {$define FPC_SYSTEM_HAS_extractFloat32Exp}
  108. {$define FPC_SYSTEM_HAS_extractFloat32Sign}
  109. {$endif FPC_HAS_FEATURE_SOFTFPU}
  110. {$endif FPUNONE}
  111. {$else FULL_RTL}
  112. {$I z80.inc}
  113. {$endif FULL_RTL}
  114. var
  115. save_iy: Word; public name 'FPC_SAVE_IY';
  116. LastKey: Char absolute 23560;
  117. function ReadKey: Char;
  118. begin
  119. repeat
  120. ReadKey:=LastKey;
  121. until ReadKey<>#0;
  122. LastKey:=#0;
  123. end;
  124. function KeyPressed: Boolean;
  125. begin
  126. KeyPressed:=LastKey<>#0;
  127. end;
  128. procedure fpc_InitializeUnits;[public,alias:'FPC_INITIALIZEUNITS']; compilerproc;
  129. begin
  130. end;
  131. Procedure fpc_do_exit;[Public,Alias:'FPC_DO_EXIT']; compilerproc;
  132. begin
  133. repeat
  134. until false;
  135. end;
  136. procedure OpenChannel(Chan: Byte);
  137. begin
  138. asm
  139. ld iy,(save_iy)
  140. ld a, (Chan)
  141. push ix
  142. call 5633
  143. pop ix
  144. ld (save_iy),iy
  145. end;
  146. end;
  147. procedure PrintChar(Ch: Char);
  148. begin
  149. asm
  150. ld iy,(save_iy)
  151. ld a, (Ch)
  152. push ix
  153. rst 16
  154. pop ix
  155. ld (save_iy),iy
  156. end;
  157. end;
  158. procedure PrintLn;
  159. begin
  160. PrintChar(#13);
  161. end;
  162. procedure PrintHexDigit(const d: byte);
  163. begin
  164. { the code generator is still to broken to compile this, so we do it in a stupid way }
  165. { if (d >= 0) or (d <= 9) then
  166. PrintChar(Char(d + Ord('0')))
  167. else if (d >= 10) and (d <= 15) then
  168. PrintChar(Char(d + (Ord('A') - 10)));}
  169. if d=0 then
  170. PrintChar('0')
  171. else if d=1 then
  172. PrintChar('1')
  173. else if d=2 then
  174. PrintChar('2')
  175. else if d=3 then
  176. PrintChar('3')
  177. else if d=4 then
  178. PrintChar('4')
  179. else if d=5 then
  180. PrintChar('5')
  181. else if d=6 then
  182. PrintChar('6')
  183. else if d=7 then
  184. PrintChar('7')
  185. else if d=8 then
  186. PrintChar('8')
  187. else if d=9 then
  188. PrintChar('9')
  189. else if d=10 then
  190. PrintChar('A')
  191. else if d=11 then
  192. PrintChar('B')
  193. else if d=12 then
  194. PrintChar('C')
  195. else if d=13 then
  196. PrintChar('D')
  197. else if d=14 then
  198. PrintChar('E')
  199. else if d=15 then
  200. PrintChar('F')
  201. else
  202. PrintChar('?');
  203. end;
  204. procedure PrintHexByte(const b: byte);
  205. begin
  206. PrintHexDigit(b shr 4);
  207. PrintHexDigit(b and $F);
  208. end;
  209. procedure PrintHexWord(const w: word);
  210. begin
  211. PrintHexByte(Byte(w shr 8));
  212. PrintHexByte(Byte(w));
  213. end;
  214. procedure Ink(colour: Byte);
  215. begin
  216. PrintChar(#16);
  217. PrintChar(Char(colour));
  218. end;
  219. procedure Paper(colour: Byte);
  220. begin
  221. PrintChar(#17);
  222. PrintChar(Char(colour));
  223. end;
  224. procedure GotoXY(X, Y: Byte);
  225. begin
  226. PrintChar(#22);
  227. PrintChar(Char(X-1));
  228. PrintChar(Char(Y-1));
  229. end;
  230. end.