home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 12 / tinybas.doc < prev    next >
Encoding:
Text File  |  1986-06-30  |  14.0 KB  |  423 lines

  1.  
  2.                         Documentation for
  3.              Gordo's MC68000 Tiny BASIC version 1.0
  4.  
  5.  
  6.      This  is  an adaptation of Li Chen Wang's  'Palo  Alto  Tiny 
  7. BASIC' for the Motorola MC68000 microprocessor.  It includes more 
  8. functions and program save and load. As distributed, it is set up 
  9. for  a Motorola MEX68KECB Educational Computer Board connected to 
  10. a  host  CP/M computer.  The source code should give  you  enough 
  11. details to allow you to install it on a different system.  If you 
  12. have any problems, you can write to me at:
  13.      Gordon Brandly
  14.      R.R. 2
  15.      Fort Sask., AB, Canada
  16.      T8L 2N8
  17.  
  18.  
  19.      This version for the Atari 520 ST translated by :
  20.      Kenneth L. Hurley
  21.      1230 W 7th #3
  22.      Eugene, OR  97402
  23.      (503) 343-7285
  24.  
  25.                           The Language
  26.  
  27. Numbers
  28.  
  29. In  this Tiny BASIC,  all numbers are integers and must be in the 
  30. range 2147483647 to -2147483648.
  31.  
  32.  
  33. Variables
  34.  
  35. There are 26 variables denoted by the letters A through Z.  There 
  36. is  also a single array @(I).  The dimension of this array (i.e., 
  37. the  range of value of the index I) is set automatically to  make 
  38. use  of all the memory space that is left unused by  the  program 
  39. (i.e.,  0 through SIZE/4, see SIZE function below). All variables 
  40. and array elements are 4 bytes long.
  41.  
  42.  
  43. Functions
  44.  
  45. There are 4 functions:
  46.      ABS(X) gives the absolute value of X.
  47.      RND(X) gives a random number between 1 and X (inclusive).
  48.      SIZE gives the number of bytes left unused by the program.
  49.      PEEK(X) gives the value of the byte at memory location X.
  50.  
  51. Arithmetic and Compare Operators
  52.  
  53.      /    Divide. (Note that since we have integers only, 2/3=0)
  54.      *    Multiply.
  55.      -    Subtract.
  56.      +    Add.
  57.      >    Greater than. (comparison)
  58.      <    Less than. (comparison)
  59.      =    Equal to.  (comparison)   Note that to certain versions 
  60.           of BASIC "LET A=B=0" means "set both A and B to 0".  To 
  61.           this  version  of Tiny BASIC,  it means "set A  to  the 
  62.           result of comparing B with 0".
  63.      <>   Not equal to. (comparison)
  64.      >=   Greater than or equal to. (comparison)
  65.      <=   Less than or equal to. (comparison)
  66.  
  67. +,  -,  *,  and / operations result in values between -2147483647 
  68. and 2147483647.  (-2147483648 is also allowed in some cases.) All 
  69. compare operators result in a 1 if true and a 0 if not true.
  70.  
  71.  
  72. Expressions
  73.  
  74. Expressions  are formed with numbers,  variables,  and  functions 
  75. with arithmetic and compare operators between them. + and - signs 
  76. can also be used at the beginning of an expression.  The value of 
  77. an expression is evaluated from left to right,  except that * and 
  78. /  are  always done first,  and then + and - ,  and then  compare 
  79. operators.  Parentheses  can also be used to alter the  order  of 
  80. evaluation.  Note  that  compare  operators can be  used  in  any 
  81. expression. For example:
  82.  
  83.      10 LET A=(X>Y)*123+(X=Y)*456+(X<Y)*789
  84.      20 IF (U=1)*(V<2)+(U>V)*(U<99)*(V>3) PRINT "Yes"
  85.      30 LET R=RND(100), A=(R>3)+(R>15)+(R>56)+(R>98)
  86.  
  87. In line 10,  A will be set to 123 if X>Y,  to 456 if X=Y,  and to 
  88. 789 if X<Y. In line 20, the "*" operator acts like a logical AND, 
  89. and the "+" operator acts like a logical OR.  In line 30,  A will 
  90. be a random number between 0 and 4 with a prescribed  probability 
  91. distribution of: 3% of being 0, 15-3=12% of being 1, 56-15=41% of 
  92. being 2, 98-56=42% of being 3, and 100-98=2% of being 4.
  93.  
  94.  
  95. Program Lines
  96.  
  97. A  Tiny BASIC line consists of a line number between 1 and  65534 
  98. followed  by one or more commands.  Commands in the same line are 
  99. separated by a colon ":".
  100.      "GOTO",  "STOP",  and  "RETURN"  commands must be  the  last 
  101. command on any given line.
  102.  
  103.  
  104. Program
  105.  
  106. A Tiny BASIC program consists of one or more lines. When a direct 
  107. command  "RUN"  is issued,  the line with the  lowest  number  is 
  108. executed  first,  then the one with the next lowest line  number, 
  109. etc.  However, the "GOTO", "GOSUB", "STOP", and "RETURN" commands 
  110. can  alter  this normal sequence.  Within a  line,  execution  of 
  111. commands  is from left to right.  The "IF" command can cause  the 
  112. remaining commands on the same line to be skipped over.
  113.  
  114.  
  115. Commands
  116.  
  117. Tiny BASIC commands are listed below with examples. Remember that 
  118. multiple commands can be put on one line if colons separate them. 
  119. In  order to store the line,  you must also have a line number at 
  120. the beginning of the line.  (The line number and multiple-command 
  121. lines aren't shown in the examples.
  122.  
  123.  
  124. REM or REMARK Command
  125.  
  126. REM anything goes
  127.  
  128. This line will be ignored by Tiny BASIC.
  129.  
  130.  
  131. LET Command
  132.  
  133. LET A=234-5*6, A=A/2, X=A-100, @(X+9)=A-1
  134.  
  135. Will  set  the variable A to the value of the expression  234-5*6 
  136. (i.e.  204),  set  the  variable A (again) to the  value  of  the 
  137. expression A/2 (i.e. 102), set the variable X to the value of the 
  138. expression A-100 (i.e. 2), and then set the variable @(11) to 101 
  139. (where 11 is the value of the expression X+9 and 101 is the value 
  140. of the expression A-1).
  141.  
  142. LET U=A<>B, V=(A>B)*X+(A<B)*Y
  143.  
  144. Will  set the variable U to either 1 or 0 depending on whether  A 
  145. is  not  equal  to or is equal to B;  and set the variable  V  to 
  146. either  X,  Y or 0 depending on whether A is greater  than,  less 
  147. than, or equal to B.
  148.  
  149.  
  150. Print Command
  151.  
  152. PRINT
  153.  
  154. Will  cause  a carriage-return (CR) and a line-feed (LF)  on  the 
  155. output device.
  156.  
  157. PRINT A*3+1, "abc 123 !@#", ' cba '
  158.  
  159. Will  print the value of the expression  A*3+1  (i.e.  307),  the 
  160. string  of  characters "abc 123 !@#" and the string" cba  ",  and 
  161. then  a CR-LF.  Note that either single or double quotes  can  be 
  162. used to quote strings, but pairs must be matched.
  163.  
  164. PRINT A*3+1, "abc 123 !@#", ' cba ',
  165.  
  166. Will produce the same output as before,  except that there is  no 
  167. CR-LF  after the last item printed.  This enables the program  to 
  168. continue printing on the same line with another "PRINT".
  169.  
  170. PRINT A, B, #3, C, D, E, #10, F, G
  171.  
  172. Will  print the values of A and B in 11 spaces,  the values of C, 
  173. D,  and E in 3 spaces, and the values of F and G in 10 spaces. If 
  174. there  aren't  enough  spaces specified for a given value  to  be 
  175. printed, the value will be printed in full anyway.
  176.  
  177. PRINT 'abc',_,'xxx'
  178.  
  179. Will  print the string "abc",  a CR without a LF,  and  then  the 
  180. string "xxx" (over the "abc") followed by a CR-LF.
  181.  
  182.  
  183. INPUT Command
  184.  
  185. INPUT A, B
  186.  
  187. When  this  command is executed,  Tiny BASIC will print "A:"  and 
  188. wait to read in an expression from the input device. The variable 
  189. A  will  be set to the value of this  expression,  then  "B:"  is 
  190. printed and variable B is set to the value of the next expression 
  191. read  from the input device.  Note that whole expressions as well 
  192. as numbers can be entered.
  193.  
  194. INPUT 'What is the weight'A, "and size"B
  195.  
  196. This is the same as the command above,  except the prompt "A:" is 
  197. replaced by "What is the weight:" and the prompt "B:" is replaced 
  198. with  "and size:".  Again,  both single and double quotes can  be 
  199. used as long as they are matched.
  200.  
  201. INPUT A, 'string',_, "another string", B
  202.  
  203. The strings and the "_" have the same effect as in "PRINT".
  204.  
  205.  
  206. POKE Command
  207.  
  208. POKE 4000+X,Y
  209.  
  210. This  command puts the value produced by expression "Y" into  the 
  211. byte memory location specified by the expression "4000+X".
  212.  
  213.  
  214. CALL Command
  215.  
  216. CALL X
  217.  
  218. This  command  will  call a machine language  subroutine  at  the 
  219. address  specified  by  the expression  "X".  All  of  the  CPU's 
  220. registers   (except  the  stack  pointer)  can  be  used  in  the 
  221. subroutine.
  222.  
  223.  
  224. IF Command
  225.  
  226. IF A<B LET X=3: PRINT 'this string'
  227.  
  228. This will test the value of the expression A<B.  If it isn't zero 
  229. (i.e.  if it is true), the rest of the commands on this line will 
  230. be executed.  If the value of the expression is zero (i.e.  if it 
  231. is  not  true),  the rest of this line will be skipped  over  and 
  232. execution continues on the next line.  Note that the word  "THEN" 
  233. is not used.
  234.  
  235.  
  236. GOTO Command
  237.  
  238. GOTO 120
  239.  
  240. Will  cause execution to jump to line 120.  Note that the  "GOTO" 
  241. command cannot be followed by a colon and other commands. It must 
  242. be ended with a CR.
  243.  
  244. GOTO A*10+B
  245.  
  246. Will  cause  the execution to jump to a different line number  as 
  247. computed from the value of the expression.
  248.  
  249.  
  250. GOSUB and RETURN Commands
  251.  
  252. GOSUB 120
  253.  
  254. Will cause execution to jump to line 120.
  255.  
  256. GOSUB A*10+B
  257.  
  258. Will cause execution to jump to different lines as computed  from 
  259. the value of the expression A*10+B.
  260.  
  261. RETURN
  262.  
  263. A  RETURN command must be the last command on a line and must  be 
  264. followed by a CR.  When a RETURN command is encountered,  it will 
  265. cause  execution  to jump back to the command following the  most 
  266. recent GOSUB command.
  267.      GOSUB's can be nested with a depth limited only by the stack 
  268. space.
  269.  
  270.  
  271. FOR and NEXT Commands
  272.  
  273. FOR X=A+1 TO 3*B STEP C-1
  274.  
  275. The  variable X is set to the value of the  expression  A+1.  The 
  276. values  of  the expressions (not the expressions themselves)  3*B 
  277. and  C-1 are remembered.  The name of the variable  X,  the  line 
  278. number  and the position of this command within the line are also 
  279. remembered.  Execution then continues the normal way until a NEXT 
  280. command is encountered.
  281.      The step can be positive,  negative or even zero.  The  word 
  282. STEP  and  the  expression  following it can be  omitted  if  the 
  283. desired step is +1.
  284.  
  285. NEXT X
  286.  
  287. The  name  of  the variable X is checked with that  of  the  most 
  288. recent  FOR  command.  If they do not agree,  then  that  FOR  is 
  289. terminated and the next recent FOR is checked,  etc. When a match 
  290. is found, this variable will be set to its current value plus the 
  291. value  of  the  step expression saved by  the  FOR  command.  The 
  292. updated  value  is  then  compared  with  the  value  of  the  TO 
  293. expression  also  saved by the FOR command.  If this  within  the 
  294. limit,  execution will jump back to the command following the FOR 
  295. command.  If  this  is  outside the  limit,  execution  continues 
  296. following the NEXT command itself.
  297.      FOR's  can also be nested with a depth limited only  by  the 
  298. stack space.  If a new FOR command with the same control variable 
  299. as that of an old FOR command is encountered, the old FOR will be 
  300. terminated automatically.
  301.  
  302.  
  303. STOP Command
  304.  
  305. STOP
  306.  
  307. This  command  stops  the execution of the  program  and  returns 
  308. control  to direct commands from the console.  It can appear many 
  309. times  in  a program but must be the last command  on  any  given 
  310. line, i.e. it cannot be followed by a colon and other commands.
  311.  
  312.  
  313. BYE Command
  314.  
  315. Will  return  you  to the resident monitor program  or  operating 
  316. system.  (Tutor in the case of the ECB.)
  317.  
  318.  
  319. Direct Commands
  320.  
  321. As defined earlier,  a line consists of a line number followed by 
  322. commands.  If  the  line number is missing,  or if it is  0,  the 
  323. commands  will be executed after you have typed the CR.  All  the 
  324. commands  described above can be used as direct  commands.  There 
  325. are  five  more commands that can be used as direct commands  but 
  326. not as part of a program line:
  327.  
  328. RUN
  329.  
  330. Will  start  to  execute  the  program  starting  at  the  lowest 
  331. line number.
  332.  
  333. LIST
  334.  
  335. Will print out all the lines in numerical order.
  336.  
  337. LIST 120
  338.  
  339. Will  print out all the lines in numerical order starting at line 
  340. 120.
  341.  
  342. NEW
  343.  
  344. Will delete the entire program.
  345.  
  346. SAVE
  347.  
  348. Will save the present program on the storage device you  provide. 
  349. Details  on installing this device are given in the source  code. 
  350. As  set  up for the MEX68KECB Educational  Computer  Board,  this 
  351. command  will  send  the program out to the host computer  in  an 
  352. easily-stored text form.  It isn't, however, pure program text as 
  353. the line numbers are stored in hexadecimal.
  354.  
  355. LOAD
  356.  
  357. Will  delete  the program in memory and load in a file from  your 
  358. storage device.
  359.  
  360.  
  361. Stopping Program Execution
  362.  
  363. The  execution  of the program or listing of the program  can  be 
  364. stopped   by   pressing  the  control-C  key  on   the   console. 
  365. Additionally,  a listing can be paused by pressing control-S, and 
  366. then pressing any key to continue.
  367.  
  368.  
  369. Abbreviations and Blanks
  370.  
  371. You  may use blanks freely within a program except that  numbers, 
  372. command  key  words,  and  function names  cannot  have  embedded 
  373. blanks.
  374.      You  may  truncate all command key words and function  names 
  375. and follow each by a period.   "P.",  "PR.",  "PRI.", and "PRIN." 
  376. all stand for "PRINT".  The word LET in LET commands may also  be 
  377. omitted.  The shortest abbreviations for all the key words are as 
  378. follows:
  379. A.=ABS    C.=CALL   F.=FOR    GOS.=GOSUB     G.=GOTO
  380. IF=IF     I.=INPUT  L.=LIST   LO.=LOAD       N.=NEW
  381. N.=NEXT   P.=PEEK   PO.=POKE  P.=PRINT       REM=REMARK
  382. R.=RETURN R.=RND    R.=RUN    S.=SAVE        S.=SIZE
  383. S.=STEP   S.=STOP   TO=TO
  384. no key word = LET
  385.  
  386.  
  387. Error Reports
  388.  
  389. There  are  only three error conditions in Tiny BASIC.  The  line 
  390. with  the error is printed out with a question mark  inserted  at 
  391. the point where the error is detected.
  392.  
  393. (1) "What?" means it doesn't understand you.  For example:
  394.  
  395. What?
  396. 260 LET A=B+3, C=(3+4?. X=4
  397.  
  398. (2) "How?" means it understands you but doesn't know how to do it.
  399.  
  400. How?
  401. 210 P?TINT "This"   <- where PRINT is misspelled
  402.  
  403. How?
  404. 310 LET A=B*C?+2    <- where B*C is larger than 2147483647
  405.  
  406. How?
  407. 380 GOTO 412?       <- where 412 does not exist
  408.  
  409. (3)  "Sorry." means it understands you and knows how to do it but 
  410.      there isn't enough memory to accomplish the task.
  411.  
  412.  
  413. Error Corrections
  414.  
  415. If you notice an error in your entry before you press the CR, you 
  416. can delete the last character with the backspace (control-H)  key 
  417. or delete the entire line with control-X.  To correct a line, you 
  418. can  retype the line number and the correct commands.  Tiny BASIC 
  419. will  replace the old line with the new one.  To delete  a  line, 
  420. type  the  line  number  and  a  CR  only.  You  can  verify  the 
  421. corrections to line 'nnnn' by typing "LIST nnnn" and pressing the 
  422. control-C key while the line is being printed.