system.pp 4.7 KB

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