zxbasic.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. { IHX (Intel Hex format) to TZX (ZX Spectrum tape file format) convertor tool
  2. This file contains various definitions, constants and utility functions for
  3. dealing with BASIC programs on the ZX Spectrum.
  4. Copyright (C) 2020 Nikolay Nikolov <[email protected]>
  5. This source is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 2 of the License, or (at your option)
  8. any later version.
  9. This code is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. details.
  13. A copy of the GNU General Public License is available on the World Wide Web
  14. at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
  15. to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  16. Boston, MA 02110-1335, USA.
  17. }
  18. unit zxbasic;
  19. {$mode objfpc}{$H+}
  20. interface
  21. uses
  22. Classes, SysUtils;
  23. const
  24. { the ZX BASIC special keyword character set }
  25. BC_RND = #165; { RND }
  26. BC_INKEYS = #166; { INKEY$ }
  27. BC_PI = #167; { PI }
  28. BC_FN = #168; { FN }
  29. BC_POINT = #169; { POINT }
  30. BC_SCREENS = #170; { SCREEN$ }
  31. BC_ATTR = #171; { ATTR }
  32. BC_AT = #172; { AT }
  33. BC_TAB = #173; { TAB }
  34. BC_VALS = #174; { VAL$ }
  35. BC_CODE = #175; { CODE }
  36. BC_VAL = #176; { VAL }
  37. BC_LEN = #177; { LEN }
  38. BC_SIN = #178; { SIN }
  39. BC_COS = #179; { COS }
  40. BC_TAN = #180; { TAN }
  41. BC_ASN = #181; { ASN }
  42. BC_ACS = #182; { ACS }
  43. BC_ATN = #183; { ATN }
  44. BC_LN = #184; { LN }
  45. BC_EXP = #185; { EXP }
  46. BC_INT = #186; { INT }
  47. BC_SOR = #187; { SOR }
  48. BC_SGN = #188; { SGN }
  49. BC_ABS = #189; { ABS }
  50. BC_PEEK = #190; { PEEK }
  51. BC_IN = #191; { IN }
  52. BC_USR = #192; { USR }
  53. BC_STRS = #193; { STR$ }
  54. BC_CHRS = #194; { CHR$ }
  55. BC_NOT = #195; { NOT }
  56. BC_BIN = #196; { BIN }
  57. BC_OR = #197; { OR }
  58. BC_AND = #198; { AND }
  59. BC_LE = #199; { <= }
  60. BC_GE = #200; { >= }
  61. BC_NEQ = #201; { <> }
  62. BC_LINE = #202; { LINE }
  63. BC_THEN = #203; { THEN }
  64. BC_TO = #204; { TO }
  65. BC_STEP = #205; { STEP }
  66. BC_DEF_FN = #206; { DEF FN }
  67. BC_CAT = #207; { CAT }
  68. BC_FORMAT = #208; { FORMAT }
  69. BC_MOVE = #209; { MOVE }
  70. BC_ERASE = #210; { ERASE }
  71. BC_OPEN = #211; { OPEN }
  72. BC_CLOSE = #212; { CLOSE }
  73. BC_MERGE = #213; { MERGE }
  74. BC_VERIFY = #214; { VERIFY }
  75. BC_BEEP = #215; { BEEP }
  76. BC_CIRCLE = #216; { CIRCLE }
  77. BC_INK = #217; { INK }
  78. BC_PAPER = #218; { PAPER }
  79. BC_FLASH = #219; { FLASH }
  80. BC_BRIGHT = #220; { BRIGHT }
  81. BC_INVERSE = #221; { INVERSE }
  82. BC_OVER = #222; { OVER }
  83. BC_OUT = #223; { OUT }
  84. BC_LPRINT = #224; { LPRINT }
  85. BC_LLIST = #225; { LLIST }
  86. BC_STOP = #226; { STOP }
  87. BC_READ = #227; { READ }
  88. BC_DATA = #228; { DATA }
  89. BC_RESTORE = #229; { RESTORE }
  90. BC_NEW = #230; { NEW }
  91. BC_BORDER = #231; { BORDER }
  92. BC_CONTINUE = #232; { CONTINUE }
  93. BC_DIM = #233; { DIM }
  94. BC_REM = #234; { REM }
  95. BC_FOR = #235; { FOR }
  96. BC_GO_TO = #236; { GO TO }
  97. BC_GO_SUB = #237; { GO SUB }
  98. BC_INPUT = #238; { INPUT }
  99. BC_LOAD = #239; { LOAD }
  100. BC_LIST = #240; { LIST }
  101. BC_LET = #241; { LET }
  102. BC_PAUSE = #242; { PAUSE }
  103. BC_NEXT = #243; { NEXT }
  104. BC_POKE = #244; { POKE }
  105. BC_PRINT = #245; { PRINT }
  106. BC_PLOT = #246; { PLOT }
  107. BC_RUN = #247; { RUN }
  108. BC_SAVE = #248; { SAVE }
  109. BC_RANDOMIZE = #249; { RANDOMIZE }
  110. BC_IF = #250; { IF }
  111. BC_CLS = #251; { CLS }
  112. BC_DRAW = #252; { DRAW }
  113. BC_CLEAR = #253; { CLEAR }
  114. BC_RETURN = #254; { RETURN }
  115. BC_COPY = #255; { COPY }
  116. function BAS_EncodeNumber(N: Integer): ansistring;
  117. function BAS_EncodeNumber(N: Real): ansistring;
  118. implementation
  119. function BAS_EncodeNumber(N: Integer): ansistring;
  120. begin
  121. if (N >= -65535) and (N <= 65535) then
  122. begin
  123. Str(N, Result);
  124. if N >= 0 then
  125. Result := Result + #14#0#0 + Chr(Byte(N)) + Chr(Byte(N shr 8)) + #0
  126. else
  127. begin
  128. N := Word(N + 131072);
  129. Result := Result + #14#0#255 + Chr(Byte(N)) + Chr(Byte(N shr 8)) + #0;
  130. end;
  131. end
  132. else
  133. Result := BAS_EncodeNumber(Real(N));
  134. end;
  135. function BAS_EncodeNumber(N: Real): ansistring;
  136. begin
  137. raise ENotImplemented.Create('Real number support not yet implemented');
  138. end;
  139. end.