system.pp 5.9 KB

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