Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.              I T T Y   B I T T Y   C O M P U T E R S
  13.  
  14.                       TINY BASIC User Manual
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.       Congratulations!  You have received the first of what we hope
  23. is a long line of low cost software for hobby computers.  We are
  24. operating on a low margin basis, and hope to make a profit on
  25. volume.  Please help us to stay in business by respecting the
  26. Copyright notices on the software and documentation.
  27.       If you are in a hurry to try TINY BASIC, Appendix C will tell
  28. you how to get on the air.  Then come back and read the rest of this
  29. manual --- most of it is useful information.
  30.  
  31.       The TINY BASIC interpreter program has been extensively tested
  32. for errors ("bugs"), but it would be foolish to claim of any program
  33. that it is guaranteed bug-free.  This program does come with a
  34. "Limited Warranty" in that any errors discovered will be corrected in
  35. the first 90 days.  Catastrophic bugs will be corrected by
  36. automatically mailing out corrected versions to all direct mail
  37. customers and local dealers.  Minor bugs will be corrected by
  38. request.  In any case this warranty is limited to replacement of the
  39. Program Tape and/or documentation, and no liability for consequential
  40. damages is implied.
  41.       If you think you have found a bug, make a listing of the
  42. program that demonstrates the bug, together with the run input and
  43. output.  Indicate on the listing what you think is wrong and what
  44. version number you are running and your serial number (on the tape
  45. leader).  Mail this to:
  46.  
  47.       ITTY BITTY COMPUTERS
  48.       P.0. Box 6539
  49.       San Jose, CA   95150
  50.  
  51. We will try to be responsive to your needs.
  52.  
  53.  
  54. ----------
  55. (C) Copyright 1976 by Tom Pittman.  All rights reserved.
  56.  
  57. "Itty Bitty" is a Trademark of the ITTY BITTY COMPUTERS Company.
  58.  
  59.  
  60.                                   1
  61.  
  62.       TINY BASIC was conceived by the dragons at the People's
  63. Computer Company (PCC), a non-profit corporation in Menlo Park CA.
  64. and its implementation defined by Dennis Allison and others in the
  65. PCC newspaper and an offshoot newsletter.  The implementation of this
  66. program follows the philosophy defined there.  The reader is referred
  67. to PCC v.4 Nos 1-3 for a discussion of the inner workings of this
  68. software.
  69.       In keeping with the "small is good" philosophy, TINY BASIC
  70. employs the two level interpreter approach (with its consequent speed
  71. cost) so that the whole system occupies only 2K of program memory
  72. (exclusive of user program; some versions are slightly larger).
  73. With 1K of additional RAM small but useful user programs (50 lines or
  74. less) may be accommodated. A system with 4K of RAM can contain the
  75. interpreter and about 100 lines of user program.
  76.  
  77.       TINY BASIC is offered in several versions for each processor.
  78. One is designed to be used with an arbitrary operating system, and
  79. executes out of low memory (e.g. 0100-08FF for the 6800). The other
  80. versions are configured for unusual memory requirements of particular
  81. operating systems. All are "clean" programs, in that they will
  82. execute properly from protected memory (such as PROM). Direct
  83. addressing is used for interpreter variables as much as possible, so
  84. memory Page 00 is largely dedicated. In all cases the user programs
  85. are placed at the end of that part of lower memory used by TINY, and
  86. they may occupy all the remaining contiguous memory. Appendix D is a
  87. a summary of the important low-memory addresses.
  88.       TINY BASIC is designed to be I/O independent, with all input
  89. and output funneled through three jumps placed near the beginning of
  90. the program.  In the non-standard versions these are preset for the
  91. particular operating system I/O, so the discussion to follow is
  92. primarily concerned with the standard versions.  For this
  93. discussion, it is assumed that the interpreter begins at hex address
  94. 0100, though the remarks may be applied to other versions with an
  95. appropriate offset.
  96.       Location 0106 is a JMP to a subroutine to read one ASCII
  97. character from the console/terminal.  Location 0109 is a JMP to a
  98. subroutine to type or display one ASCII character on the
  99. console/terminal.  In both cases the character is in the A
  100. accumulator, but the subroutine need not preserve the contents of the
  101. other registers.  It is assumed that the character input routine will
  102. simultaneously display each character as it is input; if this is not
  103. the case, the JMP instruction in location 0106 may be converted to a
  104. JSR, so that each character input flows through the output subroutine
  105. (which in this case must preserve A) before being fed to TINY.
  106. Users with terminals using Baudot or some other non-ASCII code should
  107. perform the character conversion in the Input and Output subroutines.
  108. If your console is a CRT and/or you have no need to output or
  109. display extra pad characters with each Carriage Return and Linefeed,
  110. you may intercept these in the output routine to bypass their
  111. display.  Each input prompt by TINY is followed by an "X-ON"
  112. character (ASCII DC1) with the sign bit set to 1 (all other
  113. characters except rubout are output with the sign bit set to 0) so
  114. these are also readily detected and deleted from the output stream.
  115. Appendix C shows how to perform these tests.
  116.       A third subroutine provided by you is optional, and gives TINY
  117.  
  118.  
  119.                                   2
  120.  
  121. a means to test for the BREAK condition in your system.  Appendix C
  122. shows how this subroutine may be implemented for different types of
  123. I/O devices.  If you choose to omit this subroutine, TINY will assume
  124. that a BREAK condition never happens; to include it, simply replace
  125. locations 010C-010E with a JMP to your subroutine, which returns with
  126. the break condition recorded in the Carry flag (1 = BREAK, 0 = no
  127. BREAK).  The Break condition is used to interrupt program execution,
  128. or to prematurely terminate a LIST operation.  Tiny responds to the
  129. Break condition any time in the LIST, or just before examining the
  130. next statement in program execution.  If a LIST statement included
  131. within a program is aborted by the Break condition, the Break
  132. condition must be held over to the next statement fetch (or repeated)
  133. to stop program execution also.
  134.       All input to Tiny is buffered in a 72 character line,
  135. terminated by a Carriage Return ("CR").  Excess characters are
  136. ignored, as signaled by ringing the console/terminal bell.  When the
  137. CR is typed in, Tiny will echo it with a Linefeed, then proceed to
  138. process the information in the line.  If a typing error occurs during
  139. the input of either a program line or data for an INPUT statement,
  140. the erroneous characters may be deleted by "backspacing" over them
  141. and retyping. If the entire line is in error, it may be canceled
  142. (and thus ignored) by typing the "Cancel" key.  The Backspace code is
  143. located near the beginning of the program (location 010F), and is
  144. set by default to "left-arrow" or ASCII Underline (shift-O on your
  145. Teletype).  To change this to the ASCII Standard Backspace code (or
  146. anything else you choose), the contents of location 010F may be
  147. changed to the desired code.  Similarly the Cancel code is located at
  148. memory address 0110, and is set by default to the ASCII Cancel code
  149. (Control-X).  Four characters which may not be used for line edits
  150. (Backspace or Cancel) are DC3 (hex 13), LF (0A), NUL (00), and DEL
  151. (FF).  These codes are trapped by the TINY BASIC input routines
  152. before line edits are tested.
  153.       When Tiny ends a line (either input or output), it types a CR,
  154. two pad characters, a Linefeed, and one more pad character.  The pad
  155. character used is defined by the sign bit in location 0111, and is
  156. set by default to the "Rubout" or Delete code (hex FF; Location 0111
  157. Bit 7 = 1) to minimize synchronization loss for bit-banger I/O
  158. routines.  The pad character may be changed to a Null (hex 00) by
  159. setting the sign of location 0111 to 0.  The remainder of this byte
  160. defines the number of Pad characters between the CR and linefeed.
  161. More than two pad characters may be required if large user programs
  162. are to be loaded from tape (see comments on Tape Mode, below).
  163.       TINY BASIC has a provision for suppressing output (in
  164. particular line prompts) when using paper tape for loading a program
  165. or inputting data.  This is activated by the occurrence of a Linefeed
  166. in the input stream (note that the user normally has no cause to type
  167. a Linefeed since it is echoed in response to each CR), and disables
  168. all output (including program output) until the tape mode is
  169. deactivated.  This is especially useful in half-duplex I/O systems
  170. such as that supported by Mikbug, since any output would interfere
  171. with incoming tape data.  The tape mode is turned off by the
  172. occurrence of an X-OFF character (ASCII DC3, or Control-S) in the
  173. input, by the termination of an executing program due to an error, or
  174. after the execution of any statement or command which leaves Tiny in
  175. the command mode.  The tape mode may be disabled completely by
  176. replacing the contents of memory location 0112 with a 00.
  177.  
  178.                                   3
  179.  
  180.       Memory location 0113 is of interest to those 6800 users with
  181. extensive operating systems.  Normally Tiny reserves 32 bytes of
  182. stack space for use by the interpreter and I/O routines (including
  183. interrupts).  Up to half of these may be used by Tiny in normal
  184. operation, leaving not more than 16 bytes on the stack for I/O.  If
  185. your system allows nested interrupts or uses much more than ten or
  186. twelve stack bytes for any purpose, additional space must be
  187. allocated on the stack.  Location 0113 contains the reserve stack
  188. space parameter used by Tiny, and is normally set to 32 (hex 20).  If
  189. your system requires more reserve, this value should be augmented
  190. accordingly before attempting to run the interpreter.
  191.       All of these memory locations are summarized in Appendix D.
  192. Note that there are no Input or Output instructions or interrupt
  193. disables in the interpreter itself; aside from the routines provided
  194. for your convenience (which you may connect or disconnect), your
  195. system has complete control over the I/O and interrupt structure of
  196. the TINY BASIC environment.
  197.  
  198.       TINY BASIC is designed to use all of the memory available to it
  199. for user programs.  This is done by scanning all the memory from the
  200. beginning of the user program space (e.g. 0900 for the standard 6800
  201. version) for the end of contiguous memory.  This then becomes the
  202. user program space, and any previous contents may be obliterated.
  203. If it is desired to preserve some part of this memory for machine
  204. language subroutines or I/O routines, it will be necessary to omit
  205. the memory scan initialization.  This is facilitated in TINY BASIC by
  206. the definition of two starting addresses.  Location 0100 (or the
  207. beginning of the interpreter) is the "Cold Start" entry point, and
  208. makes no assumptions about the contents of memory, except that it is
  209. available.  Location 0103 is the "Warm Start" entry point, and
  210. assumes that the upper and lower bounds of the user program memory
  211. have been defined, and that the program space is correctly
  212. formatted.  The Warm Start does not destroy any TINY BASIC programs
  213. in the program space, so it may be used to recover from catastrophic
  214. failures.  The lower bound is stored in locations 0020-0021 and the
  215. upper bound is in locations 0022-0023.  When using the Warm Start to
  216. preserve memory, you should be sure these locations contain the
  217. bounds of the user space.  Also when using the Warm Start instead of
  218. the Cold Start, the first command typed into TINY should be "CLEAR"
  219. to properly format the program space.
  220.  
  221.  
  222. STATEMENTS
  223.  
  224.       TINY BASIC is a subset of Dartmouth BASIC, with a few
  225. extensions to adapt it to the microcomputer environment.  Appendix B
  226. contains a BNF definition of the language; the discussion here is
  227. intended to enable you to use it.  When TINY issues a line prompt (a
  228. colon on the left margin) you may type in a statement with or without
  229. a line number.  If the line number is included, the entire line is
  230. inserted into the user program space in line number sequence, without
  231. further analysis.  Any previously existing line with the same line
  232. number is deleted or replaced by the new line.  If the new line
  233. consists of a line number only, it is considered a deletion, and
  234. nothing is inserted.  Blanks are not significant to TINY, so blanks
  235.  
  236.  
  237.                                   4
  238.  
  239. imbedded in the line number are ignored; however, after the first
  240. non-blank, non-numeric character in the line, all blanks are
  241. preserved in memory.
  242.       The following are valid lines with line numbers!
  243.  
  244.       123 PRINT "HELLO"
  245.       456    G O T O 1 2 3
  246.       7 8 9 PRINT "THIS IS LINE # 789"
  247.       123
  248.       32767 PRINT "THIS IS THE LARGEST LINE #"
  249.       1PRINT"THIS, IS THE SMALLEST LINE #"
  250.       10000 TINY BASIC DOES NOT CHECK
  251.       10001 FOR EXECUTABLE STATEMENTS ON INSERTION.
  252.  
  253.       0 Is not a valid line number.
  254.  
  255.       If the input line does not begin with a line number it is
  256. executed directly, and must consist of one of the following statement
  257. types:
  258.  
  259.       LET             GOTO            REM
  260.       IF...THEN       GOSUB           CLEAR
  261.       INPUT           RETURN          LIST
  262.       PRINT           END             RUN
  263.  
  264.       These statement types are discussed in more detail in the pages
  265. to follow.
  266.       Note that all twelve statement types may be used in either the
  267. Direct Execution mode (without a line number) or in a program
  268. sequence (with a line number).  Two of the statements (INPUT and RUN)
  269. behave slightly differently in these two operating modes, but
  270. otherwise each statement works the same in Direct Execution as within
  271. a program.  Obviously there is not much point in including such
  272. statements as RUN or CLEAR in a program, but they are valid.
  273. Similarly, a GOSUB statement executed directly, though valid, is
  274. likely to result in an error stop when the corresponding RETURN
  275. statement is executed.
  276.  
  277.  
  278. EXPRESSIONS
  279.  
  280.       Many of these statement types involve the use of EXPRESSIONS.
  281. An Expression is the combination of one or more NUMBERS or VARIABLES,
  282. joined by OPERATORS, and possibly grouped by Parentheses.  There are
  283. four Operators:
  284.       +   addition
  285.       -   subtraction
  286.       *   multiplication
  287.       /   division
  288. These are hierarchical, so that in an expression without parentheses,
  289. multiplication and division are performed before addition and
  290. subtraction.  Similarly, sub-expressions within parentheses are
  291. evaluated first.  Otherwise evaluation proceeds from left to right.
  292. Unary operators (+ and -) are allowed in front of an expression to
  293. denote its sign.
  294.  
  295.  
  296.                                   5
  297.  
  298.       A Number is any sequence of decimal digits (0, 1, 2, ... 9),
  299. denoting the decimal number so represented.  Blanks have no
  300. significance and may be imbedded within the number for readability if
  301. desired, but commas are not allowed.  All numbers are evaluated as
  302. 16-bit signed numbers, so numbers with five or more digits are
  303. truncated modulo 65536, with values greater than 32767 being
  304. considered negative.  The following are some valid numbers (note
  305. that the last two are equivalent to the first two in TINY):
  306.  
  307.       0
  308.       100
  309.       10 000
  310.       1 2 3 4
  311.       32767
  312.       65536
  313.       65 636
  314.  
  315.       A Variable is any Capital letter (A, B, ... Z). This variable
  316. is assigned a fixed location in memory (two bytes, the address of
  317. which is twice the ASCII representation of the variable name).  It
  318. may assume any value in the range, -32768 to +32767, as assigned to
  319. it by a LET or INPUT statement.
  320.       The following are some examples of valid expressions:
  321.       A
  322.       123
  323.       1+2-3
  324.       B-14*C
  325.       (A+B)/(C+D)
  326.       -128/(-32768+(I*1))
  327.       (((((Q)))))
  328.  
  329.       All expressions are evaluated as integers modulo 65536.  Thus
  330. an expression such as
  331.       N / P * P
  332. may not evaluate to the same value as (N), and in fact this may be
  333. put to use to determine if a variable is an exact multiple of some
  334. number.  TINY BASIC also makes no attempt to discover arithmetic
  335. overflow conditions, except in the case of an attempt to divide by
  336. zero (which results in an error stop).  Thus all of the following
  337. expressions evaluate to the same value:
  338.       -4096
  339.       15*4096
  340.       32768/8
  341.       30720+30720
  342.  
  343.       TINY BASIC allows two intrinsic functions.  These are:
  344.       RND (range)
  345.       USR (address,Xreg,Areg)
  346. Either of these functions may be used anywhere an (expression) is
  347. appropriate.
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.                                   6
  356.  
  357. FUNCTIONS
  358.  
  359.  
  360.       RND (range)
  361.  
  362.       This function has as its value, a positive pseudo-random number
  363. between zero and range-1, inclusive.  If the range argument is zero
  364. an error stop results.
  365.  
  366.  
  367.  
  368.       USR (address)
  369.       USR (address,Xreg)
  370.       USR (address,Xreg,Areg)
  371.  
  372.       This function is actually a machine-language subroutine call to
  373. the address in the first argument.  If the second argument is
  374. included the index registers contain that value on entry to the
  375. subroutine, with the most significant part in X.  If the third
  376. argument is included, the accumulators contain that value on entry to
  377. the subroutine, with the least significant part in A.  On exit, the
  378. value in the Accumulators (for the 6800; A and Y for the 6502)
  379. becomes the value of the function, with the least significant part in
  380. A.  All three arguments are evaluated as normal expressions.
  381.       It should be noted that machine language subroutine addresses
  382. are 16-bit Binary numbers.  TINY BASIC evaluates all expressions to
  383. 16-bit binary numbers, so any valid expression may be used to define
  384. a subroutine address.  However, most addresses are expressed in
  385. hexadecimal whereas TINY BASIC only accepts numerical constants in
  386. decimal.  Thus to jump to a subroutine at hex address 40AF, you must
  387. code USR(16559). Hex address FFB5 is similarly 65461 in decimal,
  388. though the equivalent (-75) may be easier to use.
  389.       For your convenience two subroutines have been included in the
  390. TINY BASIC interpreter to access memory.  If S contains the address
  391. of the beginning of the TINY BASIC interpreter (256 for standard
  392. 6800, 512 for standard 6502, etc.), then location S+20 (hex 0114) is
  393. the entry point of a subroutine to read one byte from the memory
  394. address in the index register, and location S+24 (hex 0118) is the
  395. entry point of a subroutine to store one byte into memory.
  396.       Appendix E gives examples of the USR function.
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413.  
  414.                                   7
  415.  
  416. STATEMENT TYPES
  417.  
  418.  
  419.       PRINT print-list
  420.       PR print-list
  421.  
  422.       This statement prints on the console/terminal the values of the
  423. expressions and/or the contents of the strings in the print-list.
  424. The print-list has the general form,
  425.       item,item...    or      item;item...
  426. The items may be expressions or alphanumeric strings enclosed in
  427. quotation marks (e.g. "STRING").  Expressions are evaluated and
  428. printed as signed numbers; strings are printed as they occur in the
  429. PRINT statement.  When the items are separated by commas the printed
  430. values are justified in columns of 8 characters wide; when semicolons
  431. are used there is no separation between the printed items. Thus,
  432.       PRINT 1,2,3
  433. prints as
  434.       1       2       3
  435. and
  436.       PRINT 1;2;3
  437. prints as
  438.       123
  439. Commas and semicolons, strings and expressions may be mixed in one
  440. PRINT statement at will.
  441.       If a PRINT statement ends with a comma or semicolon TINY BASIC
  442. will not terminate the output line so that several PRINT statements
  443. may print on the same output line, or an output message may be
  444. printed on the same line as an input request (see INPUT).  When the
  445. PRINT statement does not end with a comma or semicolon the output is
  446. terminated with a carriage return and linefeed (with their associated
  447. pad characters).  To aid in preparing data tapes for input to other
  448. programs, a colon at the end of a print-list will output an "X-OFF"
  449. control character just before the Carriage Return.
  450.  
  451.       Although the PRINT statement generates the output immediately
  452. while scanning the statement line, output lines are limited to 125
  453. characters, with excess suppressed.
  454.  
  455.       While the Break key will not interrupt a PRINT statement in
  456. progress, the Break condition will take effect at the end of the
  457. current PRINT statement.
  458.  
  459.       The following are some examples of valid PRINT statements:
  460.       PRINT "A=";A,"B+C=";B+C
  461.       PR                        (one blank line)
  462.       PRI                       (prints the value of I)
  463.       PRINT 1,","Q*P;",",R/42:
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.                                   8
  474.  
  475.       INPUT input-list
  476.  
  477.       This statement checks to see if the current input line is
  478. exhausted.  If it is, a question mark is prompted with an X-ON
  479. control character, and a new line is read in.  Then or otherwise, the
  480. input line is scanned for an expression which is evaluated.  The
  481. value thus derived is stored in the first variable in the input-list.
  482. If there are more variables in the input-list the process is
  483. repeated.  In an executing program, several values may be input on a
  484. single request by separating them with commas.  If these values are
  485. not used up in the current INPUT statement they are saved for
  486. subsequent INPUT statements.  The question mark is prompted only when
  487. a new line of input values is required.  Note that each line of input
  488. values must be terminated by a carriage return.  Since expressions
  489. may be used as input values, any letter in the input line will be
  490. interpreted as the value of that variable.  Thus if a program sets
  491. the value of A to 1, B to 2, and C to 3, and the following statement
  492. occurs during execution:
  493.       INPUT X,Y,Z
  494. and the user types in
  495.       A,C,B
  496. the values entered into X, Y, and Z will be 1, 3, and 2,
  497. respectively, just as if the numbers had been typed in.  Note also
  498. that blanks on the input line are ignored by TINY, and the commas are
  499. required only for separation in cases of ambiguity.  In the example
  500. above
  501.       ACB
  502. could have been typed in with the same results.  However an input,
  503. line typed in as
  504.       +1  -3  +6   0
  505. will be interpreted by TINY as a single value (=58) without commas
  506. for separators.  There is one anomaly in the expression input
  507. capability: if in response to this INPUT, the user types,
  508.       RND+3
  509. TINY will stop on a bad function syntax error (the RND function must
  510. be of the form, RND(x)); but if the user types,
  511.       RN,D+3
  512. the values in the variables R, N, and the expression (D+3) will be
  513. input.  This is because in the expression evaluator the intrinsic
  514. function names are recognized before variables, as long as they are
  515. correctly spelled.
  516.  
  517.       Due to the way TINY BASIC buffers its input lines, the INPUT
  518. statement cannot be directly executed for more than one variable at a
  519. time, and if the following statement is typed in without a line
  520. number,
  521.       INPUT A,B,C
  522. the value of B will be copied to A, and only one value (for C) will
  523. be requested from the console/terminal.  Similarly, the statement,
  524.       INPUT X,1,Y,2,Z,3
  525. will execute directly (loading X, Y, and Z with the values 1, 2, and
  526. 3), requesting no input, but with a line number in a program this
  527. statement will produce an error stop after requesting one value.
  528.  
  529.       If the number of expressions in the input line does not match
  530. the number of variables in the INPUT statement, the excess input is
  531.  
  532.                                   9
  533.  
  534. saved for the next INPUT statement, or another prompt is issued for
  535. more data. The user should note that misalignment in these
  536. circumstances may result in incorrect program execution (the wrong
  537. data to the wrong variables). If this is suspected, data entry may be
  538. typed in one value at a time to observe its synchronization with
  539. PRINT statements in the program.
  540.       There is no defined escape from an input request, but if an
  541. invalid expression is typed (such as a period or a pair of commas) an
  542. invalid expression error stop will occur.
  543.  
  544.       Because Tiny Basic does not allow arrays, about the only way to
  545. process large volumes of data is through paper tape files.  Each
  546. input request prompt consists of a question mark followed by an X-ON
  547. (ASCII DC1) control character to turn on an automatic paper tape
  548. reader on the Teletype (if it is ready).  A paper tape may be
  549. prepared in advance with data separated by commas, and an X-OFF
  550. (ASCII DC3 or Control-S) control character preceding the CR (a
  551. Teletype will generally read at least one more character after the
  552. X-OFF).  In this way the tape will feed one line at a time, as
  553. requested by the succession of INPUT statements.  This tape may also
  554. be prepared from a previous program output (see the PRINT
  555. statement).
  556.  
  557.  
  558.  
  559.  
  560.  
  561.       LET var = expression
  562.       var = expression
  563.  
  564.       This statement assigns the value of the expression to the
  565. variable (var).  The long form of this statement (i.e. with the
  566. keyword LET) executes slightly faster than the short form.  The
  567. following are valid LET statements:
  568.  
  569.       LET A = B+C
  570.       I = 0
  571.       LET Q = RND (RND(33)+5)
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                   10
  592.  
  593.       GOTO expression
  594.  
  595.       The GOTO statement permits changes in the sequence of program
  596. execution.  Normally programs are executed in the numerical sequence
  597. of the program line numbers, but the next statement to be executed
  598. after a GOTO has the line number derived by the evaluation of the
  599. expression in the GOTO statement.  Note that this permits you to
  600. compute the line number of the next statement on the basis of program
  601. parameters during program execution.  An error stop occurs if the
  602. evaluation of the expression results in a number for which there is
  603. no line.  If a GOTO statement is executed directly, it has the same
  604. effect as if it were the first line of a program, and the RUN
  605. statement were typed in, that is, program execution begins from that
  606. line number, even though it may not be the first in the program.
  607. Thus a program may be continued where it left off after correcting
  608. the cause of an error stop.  The following are valid GOTO
  609. statements:
  610.       GOTO 100
  611.       GO TO 200+I*10
  612.       G 0 T 0 X
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.       GOSUB expression
  620.  
  621.       The GOSUB statement is like the GOTO statement, except that TINY
  622. remembers the line number of the GOSUB statement, so that the next
  623. occurrence of a RETURN statement will result in execution proceeding
  624. from the statement following the GOSUB.  Subroutines called by GOSUB
  625. statements may be nested to any depth, limited only by the amount of
  626. user program memory remaining.  Note that a GOSUB directly executed
  627. may result in an error stop at the corresponding RETURN.  The
  628. following are some examples of valid GOSUB statements:
  629.       GOSUB 100
  630.       GO SUB 200+I*10
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637. RETURN
  638.  
  639.       The RETURN statement transfers execution control to the line
  640. following the most recent unRETURNed GOSUB.  If there is no matching
  641. GOSUB an error stop occurs.
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.                                   11
  651.  
  652.       IF expression rel expression THEN statement
  653.       IF expression rel expression statement
  654.  
  655.       The IF statement compares two expressions according to one of
  656. six relational operators.  If the relationship is True, the statement
  657. is executed; if False, the associated statement is skipped.  The six
  658. relational operators are:
  659.       =               equality
  660.       <               less than
  661.       >               greater than
  662.       <=              less or equal (not greater)
  663.       >=              greater or equal (not less)
  664.       <>, ><          not equal (greater or less)
  665.  
  666.       The statement may be any valid TINY BASIC statement (including
  667. another IF statement).  The following are valid IF statements:
  668.       IF I>25 THEN PRINT "ERROR"
  669.       IF N/P*P=N GOTO 100
  670.       IF 1=2 Then this is nonsense
  671.       IF RND (100) > 50 THEN IF I <> J INPUT Q,R
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.      END
  679.  
  680.      The END statement must be the last executable statement in a
  681. program.  Failure to include an END statement will result in an error
  682. stop after the last line of the program is executed.  The END
  683. statement may be used to terminate a program at any time, and there
  684. may be as many END statements in a program as needed.  The END
  685. statement also clears out any saved GOSUB line numbers remaining, and
  686. may be used for that purpose in the direct execution mode.
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.       REM comments
  694.  
  695.       The REM statement permits comments to be interspersed in the
  696. program.  Its execution has no effect on program operation, except
  697. for the time taken.
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.                                   12
  710.  
  711.       CLEAR
  712.  
  713.       The CLEAR statement formats the user program space, deleting
  714. any previous programs.  If included in a program (i.e. with a line
  715. number) the program becomes suicidal when the statement is executed,
  716. although no error results.  If the Warm Start is used to initialize
  717. the interpreter, this must be the first command given.
  718.  
  719.  
  720.  
  721.       RUN
  722.       RUN,expression-list
  723.  
  724.       The RUN statement is used to begin program execution at the
  725. first (lowest) line number.  If the RUN statement is directly
  726. executed, it may be followed by a comma, followed by values to be
  727. input when the program executes an INPUT statement.
  728.       If the RUN statement is included in a program with a line
  729. number, its execution works like a GO TO first statement of the
  730. program.
  731.  
  732.  
  733.  
  734.       LIST
  735.       LIST expression
  736.       LIST expression,expression
  737.  
  738.       The LIST statement causes part or all of the user program to be
  739. listed.  If no parameters are given, the whole program is listed.  A
  740. single expression parameter in evaluated to a line number which, if
  741. it exists, is listed.  If both expression parameters are given, all
  742. of the lines with line numbers between the two values (inclusive) are
  743. listed.  If the last expression in the LIST statement evaluates to a
  744. number for which there is no line, the next line above that number
  745. which does exist (if any) is listed as the last line.  Zero is not a
  746. valid line number, and an error stop will occur if one of the
  747. expressions evaluates to zero.  A LIST statement may be included as
  748. part of the program, which may be used for printing large text
  749. strings such as instructions to the operator.  A listing may be
  750. terminated by the Break key.
  751.       If the terminal punch (or cassette recorder) is turned on for a
  752. LIST operation, the tape may be saved to reload the program into TINY
  753. at a later time.
  754.       The following are valid LIST statements:
  755.       LIST
  756.       LIST 75+25            (lists line 100)
  757.       LIST 100,200
  758.       LIST 500,400          (lists nothing)
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.                                   13
  769.  
  770.                     A P P E N D I X   A
  771.  
  772.                    ERROR MESSAGE SUMMARY
  773.  
  774.  
  775. 0     Break during execution
  776. 8     Memory overflow; line not inserted
  777. 9     Line number 0 not allowed
  778. 13    RUN with no program in memory
  779. 18    LET is missing a variable name
  780. 20    LET is missing an =
  781. 23    Improper syntax in LET
  782. 25    LET is not followed by END
  783. 34    Improper syntax in GOTO
  784. 37    No line to GO TO
  785. 39    Misspelled GOTO
  786. 40,41 Misspelled GOSUB
  787. 46    GOSUB subroutine does not exist
  788. 59    PRINT not followed by END
  789. 62    Missing close quote in PRINT string
  790. 73    Colon in PRINT is not at end of statement
  791. 75    PRINT not followed by END
  792. 95    IF not followed by END
  793. 104   INPUT syntax bad - expects variable name
  794. 123   INPUT syntax bad - expects comma
  795. 124   INPUT not followed by END
  796. 132   RETURN syntax bad
  797. 133   RETURN has no matching GOSUB
  798. 134   GOSUB not followed by END
  799. 139   END syntax bad
  800. 154   Can't LIST line number 0
  801. 164   LIST syntax error - expects comma
  802. 183   REM not followed by END
  803. 184   Missing statement type keyword
  804. 186   Misspelled statement type keyword
  805. 188   Memory overflow: too many GOSUB's ...
  806. 211      ... or expression too complex
  807. 224   Divide by 0
  808. 226   Memory overflow
  809. 232   Expression too complex ...
  810. 233      ... using RND ...
  811. 234      ... in direct evaluation;
  812. 253      ... simplify the expression
  813. 259   RND (0) not allowed
  814. 266   Expression too complex ...
  815. 267      ... for RND
  816. 275   USR expects "(" before arguments
  817. 284   USR expects ")" after arguments
  818. 287   Expression too complex ...
  819. 288      ... for USR
  820. 290   Expression too complex
  821. 293   Syntax error in expression - expects value
  822. 296   Syntax error - expects ")"
  823. 298   Memory overflow (in USR)
  824. 303   Expression too complex (in USR)
  825.  
  826.  
  827.                                   14
  828.  
  829. 304   Memory overflow (in function evaluation)
  830. 306   Syntax error - expects "(" for function arguments
  831. 330   IF syntax error - expects relation operator
  832.  
  833.       Other error message numbers may possibly occur if the
  834. interpreter is malfunctioning.  If this happens, check the program in
  835. memory, or reload it, and try again.
  836.  
  837.       Error number 184 may also occur if TINY BASIC is incorrectly
  838. interfaced to the keyboard input routines.  A memory dump of the
  839. input line buffer may disclose this kind of irregularity.
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.                                   15
  887.  
  888.                      A P P E N D I X   B
  889.  
  890.                FORMAL DEFINITION OF TINY BASIC
  891.  
  892.  
  893. line ::= number statement CR
  894.          statement CR
  895. statement ::= PRINT printlist
  896.               PR printlist
  897.               INPUT varlist
  898.               LET var = expression
  899.               var = expression
  900.               GOTO expression
  901.               GOSUB expression
  902.               RETURN
  903.               IF expression relop expression THEN statement
  904.               IF expression relop expression statement
  905.               REM commentstring
  906.               CLEAR
  907.               RUN
  908.               RUN exprlist
  909.               LIST
  910.               LIST exprlist
  911. printlist ::=
  912.               printitem
  913.               printitem :
  914.               printitem separator printlist
  915. printitem ::= expression
  916.               "characterstring"
  917. varlist ::= var
  918.             var , varlist
  919. exprlist ::= expression
  920.              expression , exprlist
  921. expression ::= unsignedexpr
  922.                + unsignedexpr
  923.                - unsignedexpr
  924. unsignedexpr ::= term
  925.                  term + unsignedexpr
  926.                  term - unsignedexpr
  927. term ::= factor
  928.          factor * term
  929.          factor / term
  930. factor ::= var
  931.            number
  932.            ( expression )
  933.            function
  934. function ::= RND ( expression )
  935.              USR ( exprlist )
  936. number ::= digit
  937.            digit number
  938. separator ::= , ! ;
  939. var ::= A ! B ! ... ! Y ! Z
  940. digit ::= 0 ! 1 2 ! ... ! 9
  941. relop ::= < ! > ! = ! <= ! >= ! <> ! ><
  942.  
  943.  
  944.  
  945.                                   16
  946.  
  947.  
  948.                          A P P E N D I X   C
  949.  
  950.                       IMPLEMENTING I/O ROUTINES
  951.  
  952. COSMAC
  953.  
  954. COSMAC TINY occupies the same space as 6800 TINY -- 0100-08FF.
  955. Similarly, the general parameters occupy 0020-00B7, as defined in
  956. the manual.  However, COSMAC TINY also uses locations 0011-001F to
  957. contain copies of interpreter parameters and other run-time data; do
  958. not attempt to use these locations while running TINY.
  959.  
  960. Like all Itty Bitty Computer software, COSMAC TINY contains no I/O
  961. instructions (nor references to Q or EF1-4), no interrupt enables or
  962. disables, and no references to an operating system.  The three jumps
  963. (LBR instructions) at 0106, 0109, and 010C provide all necessary
  964. I/O, as defined in the manual.  If you are using UT3 or UT4, you may
  965. insert the following LBR instructions, which jump to the necessary
  966. interface routines:
  967.  
  968.                         ..  LINKS TO UT3/4
  969.         0106 C0076F             LBR UTIN
  970.         0109 C00776             LBR UTOUT
  971.         010C C00766             LBR UTBRK
  972.  
  973. If you are not using the RCA monitor, you must write your own I/O
  974. routines.  For this the standard subroutine call and return linkages
  975. are used, except that D is preserved through calls and returns by
  976. storing it in RF.1.  Registers R2-RB and RD contain essential
  977. interpreter data, and if the I/O routines make any use of any of
  978. them they should be saved and restored.  Note however, that R2-R6
  979. are defined in the customary way and may be used to nest subroutine
  980. calls if needed.  R0, R1, RC, RE and RF are available for use by the
  981. I/O routines, as is memory under R2.  Both the call and return
  982. linkages modify X and the I/O data character is passed in the
  983. accumulator ("D", not RD).
  984.  
  985. After connecting TINY to the I/O routines, start the processor at
  986. 0100 (the Cold Start).  Do not attempt to use the Warm Start without
  987. entering the Cold Start at least once to set up memory from
  988. 0011-0023.  Any register may be serving as program counter when
  989. entering either the Cold Start or the Warm Start.
  990.  
  991. The USR function works the same way as described in the manual,
  992. except that the second argument in the call is loaded into R8, and
  993. the third argument is loaded into RA with the least significant
  994. byte also in the Accumulator.  On return RA.1 and the accumulator
  995. contain the function value (RA.0 is ignored).  The machine language
  996. subroutine must exit by a SEP R5 instruction.  USR machine language
  997. subroutines may use R0, R1, R8, RA, RC-RF, so long as these do not
  998. conflict with I/O routine assignments.  TINY BASIC makes no internal
  999. use of R0, R1, RC, or RE.
  1000.  
  1001. RCA Corporation funded the development of COSMAC TINY BASIC, and it
  1002. is by RCA's permission that it is made available.
  1003.  
  1004.                                   17
  1005.      If you do not have access to a monitor in ROM with ASCII I/O
  1006. built in, you will have to write your own I/O routines.  Most likely
  1007. you have something connected to a parallel port for the keyboard
  1008. input; output may be some parallel port also, or you may want to
  1009. use the 1861 video display for a gross dot-matrix kind of text
  1010. display.  For the moment, let's assume you have parallel ports,
  1011. Port C (N=1100) for input, and port 4 (N=0100) for output.  Assume
  1012. also that EF4 controls both input and output.  This is the situation
  1013. you would have if you took an ordinary ELF and used the hex input
  1014. and display with the single "input" button to step through the
  1015. characters.  You need for this configuration, two routines, which
  1016. might look something like this:
  1017.      0106 C0 00E0    LBR KEYIN
  1018.      0109 C0 00E7    LBR DISPL
  1019.      ...
  1020.      00E0 3FE0 KEYIN BN4 *
  1021.      00E2 E2         SEX 2
  1022.      00E3 6C         INP 4
  1023.      00E4 37E4       B4  *
  1024.      00E6 68         LSKP
  1025.      00E7 3FE7 DISPL BN4 *
  1026.      00E9 E2         SEX 2
  1027.      00EA 73         STXD
  1028.      00EB 52         STR 2
  1029.      00EC 64         OUT 4
  1030.      00ED 37ED       B4  *
  1031.      00EF D5         SEP 5
  1032.      Of course if you have a keyboard on Port F you will change
  1033. the INP instruction to match; if the keyboard pulls EF3 down, then
  1034. you must change the first pair of BN4/B4 instructions to BN3/B3
  1035. instructions and change the LSKP to a NOP (C4 or E2).  If your
  1036. input comes from some device that already displayed the character
  1037. typed, then change the LSKP to a Return (D5).
  1038.      Similarly, if the output is to a different port you must
  1039. change the OUT instruction to fit it, and the second pair of BN4/B4
  1040. instructions to match the control line being used. Notice that
  1041. the LSKP instruction is only there to prevent your waiting on the
  1042. EF4 line twice for each keyin, and should be removed (changed to
  1043. a NOP) as soon as you connect up real input and output ports.
  1044.      Many 1802 systems come equipped with a video output using
  1045. the 1861 chip.  If you have this, you should get a copy of the
  1046. February and April 1979 issues of KILOBAUD MICROCOMPUTING (formerly
  1047. just KILOBAUD). I have a two-part article published in these two
  1048. issues which explains how to put text on the 1861 graphics display,
  1049. with particular emphasis on how to connect it to TINY BASIC.
  1050.      So far I have not mentioned the Break test. If you leave
  1051. that part unchanged, Tiny will work just fine, but you cannot stop
  1052. a listing or a program that is getting too long.  After you get
  1053. your keyboard and display connected up and working, you may want
  1054. to use EF4 (or some other flag) as a Break input. It is possible
  1055. to use the same flag for Break as for "input ready", if you want
  1056. Tiny to stop executing when you press a key on your keyboard (this
  1057. does not affect the INPUT instruction, which is obviously waiting
  1058. for that keyin). This code will do that:
  1059.      010C C000F0     LBR BRKT
  1060.      ...
  1061.      00F0 FC00  BRKT ADI 0
  1062.      00F2 3FF6       BN4 EXIT
  1063.      00F4 FF00       SMI 0
  1064.      00F6 D5    EXIT SEP R5
  1065.      Notice that the only function of this routine is to set the
  1066. Carry (DF) when EF4 is true (low) and clear it otherwise.
  1067.  
  1068.                                   18
  1069.  
  1070. KIM
  1071.  
  1072.       The Teletype I/O routines in the MOS Technology KIM system may
  1073. be used for the character input and output requirements of TINY BASIC
  1074. 6502.  The following break routine is included in Tiny to test the
  1075. serial data line at 1740;  Since TINY BASIC 6502 does not use the
  1076. lower part of memory page 01, the break test routine is ORG'ed to
  1077. execute in that space:
  1078.  
  1079.             ;  BREAK TEST FOR KIM
  1080. 0100 AD4017 KIMBT LDA KTTY      LOOK AT TTY
  1081. 0103 18           CLC           C=O IF IDLE
  1082. 0104 300E         BMI KIMX      IDLE
  1083. 0106 AD4017       LDA KTTY      WAIT FOR END
  1084. 0109 10FB         BPL *-3
  1085. 010B 200E01 KLDY  JSR *+3
  1086. 010E A9FF         LDA #255      DELAY 2 RUBOUT TIMES
  1087. 0110 20A01E       JSR OUTCH
  1088. 0113 38           SEC           C=1 IF BREAK
  1089. 0114 60     KIMX  RTS
  1090.  
  1091.       To run TINY BASIC 6502 load the paper tape into your Teletype
  1092. reader, type "L", and turn on the reader.  Then key in the following
  1093. Jumps:
  1094.  
  1095.             ;  JUMPS TO KIM
  1096. 0206 4C5A1E     JMP GETCH       CHARACTER INPUT
  1097. 0209 4CA01E     JMP OUTCH       CHARACTER OUTPUT
  1098. 020C 4C0001     JMP KIMBT       BREAK TEST
  1099.  
  1100.       It is recommended that you save a copy of memory on tape
  1101. (0100-0114 and 0200-0AFF) before going any further.  Or you may
  1102. prefer to save it on audio cassette.  Set up the starting address for
  1103. Tiny at 0200, and type "G".
  1104.       Because of the awkwardness of putting memory in the 4K gap left
  1105. in the KIM-1 system, an alternate version is available which executes
  1106. out of 2000-28FF.  For this version the Cold Start is at 2000 and
  1107. other addresses are at 200x instead of 020x (cf. 010x in Appendix D).
  1108.  
  1109.  
  1110. JOLT or TIM
  1111.  
  1112.       JOLT systems may not always have memory loaded in the space
  1113. from 0200 on up, so a special version has been prepared in which the
  1114. interpreter resides in the space 1000-18FF.  This is the only
  1115. difference between the JOLT version and the KIM version, so if your
  1116. JOLT or TIM system has contiguous memory from Page 00 you may prefer
  1117. to use the KIM version to gain the extra memory space.  Since the
  1118. serial data in the JOLT/TIM systems is not the same as KIM, a special
  1119. break test routine has also been provided for those systems:
  1120.  
  1121.             ; JOLT BREAK TEST
  1122. 0115 A901   JOLBT LDA #1        LOOK AT TTY
  1123. 0117 2C026E       BIT JTTY
  1124. 011A 18           CLC           C=0 IF IDLE
  1125.  
  1126.  
  1127.                                   19
  1128.  
  1129. 011B F00E         BEQ JOLTX     IDLE
  1130. 011D 2C026E       BIT JTTY      WAIT FOR END
  1131. 0120 D0FB         BNE *-3
  1132. 0122 202501       JSR *+3       DELAY TWO CH TIMES
  1133. 0125 A9FF         LDA #255
  1134. 0127 20C672       JSR WRT
  1135. 012A 38           SEC           C=1 = BREAK
  1136. 012B 60     JOLTX RTS
  1137.  
  1138.       To run, load the paper tape into your Teletype reader and type
  1139. "LH".  Then key in the following Jumps:
  1140.  
  1141.             ;  JUMPS TO JOLT/TIM
  1142. 1006 4CE972     JMP RDT         CHARACTER INPUT
  1143. 1009 4CC672     JMP WRT         CHARACTER OUTPUT
  1144. 100C 4C1501     JMP JOLBT       BREAK TEST
  1145.  
  1146.       As with other versions, the Cold start is the beginning of the
  1147. program (1000).
  1148.  
  1149.  
  1150.  
  1151. MIKBUG
  1152.  
  1153.       Systems that use MIKBUG (TM Motorola) for console I/O may use
  1154. the I/O routines in MIKBUG.  The following break routine is provided
  1155. in Tiny to test the PIA at 8004:
  1156.  
  1157.         *  BREAK TEST FOR MIKBUG
  1158.  
  1159. B68004  BREAK   LDA A PIAA      LOOK AT PIA
  1160. 0C              CLC             C=0 IF NONE
  1161. 2B0D            BMI EXIT
  1162. B68004          LDA A PIAA
  1163. 2AFB            BPL *-3         WAIT FOR END
  1164. 8D00            BSR *+2
  1165. 86FF            LDA A #$FF      DELAY ONE
  1166. BD0109          JSR TYPE        CHARACTER TIME
  1167. 0D              SEC             C=1 IF BREAK
  1168. 39      EXIT    RTS
  1169.  
  1170.       To run, load the paper tape into your Teletype reader and type
  1171. "L".  Then key in the following Jumps:
  1172.  
  1173.             *  JUMPS TO MIKBUG
  1174.                 ORG $0106
  1175. 0106 7EE1AC     JMP $E1AC       CHARACTER INPUT
  1176. 0109 7EE1D1     JMP $E1D1       CHARACTER OUTPUT
  1177. 010C 7E08FD     JMP $08FD       BREAK TEST
  1178.  
  1179.       It is recommended that you save a copy of memory on tape
  1180. (0100-08FF) before going any further.  Set the starting address in
  1181. A048-A049 to 0100 and type "G". For your convenience the Cold Start
  1182. entry leaves the Warm start entry set up in the Mikbug stack, so that
  1183. after a reset a simple "G" command will result in a Warm start and
  1184. preserve the user programs.
  1185.  
  1186.                                   20
  1187.  
  1188. OTHER
  1189.  
  1190.       For standard systems (and for special systems with I/O other
  1191. than that provided), subroutines must be supplied by the user to
  1192. interface TINY to the operator.  For ACIA input or output the
  1193. following routines may be used, or they may serve as examples for
  1194. your coding (6800 opcodes are shown).  They should be assembled for
  1195. your ACIA address, and in some memory location which is not
  1196. contiguous with the TINY BASIC user program memory (which may be
  1197. destroyed by the Cold Start).  If nothing else is available,
  1198. locations 00D8-00FF are not used by Tiny and may be used for this
  1199. purpose.
  1200.  
  1201.        *
  1202.        *  ACIA I/O
  1203.        *
  1204. B6XXXX BREAK   LDA A ACIA
  1205. 47             ASR A           CHECK FOR TYPEIN
  1206. 2406           BCC BRX         NO, NOT BREAK
  1207. B6XXXY         LDA A ACIA+1    GET IT
  1208. 2601           BNE BRX         NOT NULL IS BREAK
  1209. 0C             CLC             IGNORE NULLS
  1210. 39     BRX     RTS
  1211. B6XXXX INPUT   LDA A ACIA
  1212. 47             ASR A
  1213. 24FA           BCC INPUT       WAIT FOR A CHARACTER
  1214. B6XXXY         LDA A ACIA+1    GET IT
  1215. 36     OUTPUT  PSH A           SAVE CHARACTER
  1216. B6XXXX         LDA A ACIA
  1217. 8402           AND A #2        WAIT FOR READY
  1218. 27F9           BEQ OUTPUT+1
  1219. 32             PUL A
  1220. B7XXXY         STA A ACIA+1    OUTPUT CHARACTER
  1221. 39             RTS
  1222.  
  1223.       Note that this routine will accept any non-null character
  1224. typein as a break.  Alternatively we could look at the Framing Error
  1225. status, but if a character has been input this status will not show
  1226. up until that character is read in, rendering it ineffective in some
  1227. cases.  Nulls are excepted as break characters since one or more of
  1228. them may follow the carriage return in an input tape, and still be
  1229. pending.  Note that for this to work properly, the pad character
  1230. defined in location 0111 should be set to NULL (hex 00).
  1231.  
  1232.       The 6800 "R" version of TINY BASIC includes these routines in
  1233. the code, as shown here.  Locations 08FA-08FC contain a JMP to the
  1234. break test at the beginning of this block.  You should alter the ACIA
  1235. addresses to suit your system before using the subroutines.
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.                                   21
  1246.  
  1247. CRT OR TVT
  1248.  
  1249.       If a TV Typewriter is used for I/O it may be desirable to
  1250. remove excess control characters from the output stream.  All
  1251. controls except Carriage Return may be removed by the following
  1252. instructions at the beginning of the output subroutine (6800 opcodes
  1253. shown):
  1254.  
  1255. 39             RTS
  1256. 810A   OUTPUT  CMP A #0A
  1257. 2FFB           BLE OUTPUT-1
  1258.  
  1259. Only nulls, Rubouts, X-ON and X-OFF may be deleted by changing the
  1260. CMP to a TST A.  Nulls may be passed through by also changing the BLE
  1261. to a BMI.
  1262.  
  1263.       Some TV Typewriters do not scroll up when the cursor reaches
  1264. the bottom of the screen, but rather wrap the cursor around to the
  1265. top of the screen, writing over the previously displayed data.  With
  1266. this kind of display it is essential that the I/O routines (or the
  1267. hardware) clear to the end of the line whenever a CR-LF is output,
  1268. so that previous data does not interfere with the new.  If your I/O
  1269. routines are fixed in ROM, some sort of preprocessor may be required
  1270. to recognize output CR's and convert them to the appropriate sequence
  1271. of control functions.  It may also be necessary to trap input CR's
  1272. (suppressing their echo) since Tiny generally responds with both
  1273. another CR and a linefeed.
  1274.  
  1275.       Some users prefer to concatenate all output into one "line" of
  1276. print, using the terminal comma or semicolon to suppress the line
  1277. breaks.  Since TINY was designed to limit line lengths to less than
  1278. 128 characters, if this sort of concatenation is attempted it will
  1279. appear that TINY has quit running.  To eliminate the print
  1280. suppression the most significant two bits of the print control byte
  1281. (location 00BF in most versions) may be cleared to zero periodically
  1282. with the USR function or in the output driver routine.  The least
  1283. significant three bits of this same byte are used for the "comma
  1284. spacing" in the PRINT statement, and should be left unaltered.
  1285.  
  1286.  
  1287.  
  1288. CASSETTE I/O
  1289.  
  1290.       Officially, TINY only speaks to one peripheral--the console.
  1291. However a certain amount of file storage may be simulated by
  1292. attaching these peripherals (such as cassette systems) to the
  1293. character input and output routines.  If the same electrical and
  1294. software interface is used this is very easy.  Otherwise the I/O
  1295. drivers will require special routines to recognize control characters
  1296. in the input and output data for setting internal switches which
  1297. select one of several peripherals.  The USR function may also be
  1298. used either to directly call I/O routines or to alter switches in
  1299. memory.
  1300.  
  1301.  
  1302.  
  1303.  
  1304.                                   22
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.                          A P P E N D I X   D
  1311.  
  1312.                            LOW MEMORY MAP
  1313.  
  1314.  
  1315. LOCATION        SIGNIFICANCE
  1316. --------        ------------
  1317.  
  1318. 0000-000F       Not used by any version of TINY
  1319. 0011-001F       COSMAC version temporaries
  1320. 0020-0021       Lowest address of user program space
  1321. 0022-0023       Highest address of program space
  1322. 0024-0025       Program end + stack reserve
  1323. 0026-0027       Top of GOSUB stack
  1324. 0028-002F       Interpreter parameters
  1325. 0030-007F       Input line buffer & Computation stack
  1326. 0080-0081       Random Number Generator workspace
  1327. 0082-0083       Variable "A"
  1328. 0084-0085       Variable "B"
  1329. ...             ...
  1330. 00B4-00B5       Variable "Z"
  1331. 00B6-00C7       Interpreter temporaries
  1332. 00B8            Start of User program (PROTO)
  1333. 00C8-00D7       Sphere parameters (not 0020-002F)
  1334. 00D8-00FF       Unused by standard version
  1335.  
  1336. 0100            Cold Start entry point (6800)
  1337. 0103            Warm Start entry point
  1338. 0106-0108       JMP (or JSR) to character input
  1339. 0109-010B       JMP to character output
  1340. 010C-010E       JMP to Break test
  1341. 010F            Backspace code
  1342. 0110            Line Cancel code
  1343. 0111            Pad character
  1344. 0112            Tape Mode Enable flag (hex 80 = enabled)
  1345. 0113            Spare stack size
  1346. 0114            Subroutine to read one Byte
  1347.                   from RAM to A (address in X)
  1348. 0118            Subroutine to store A into RAM
  1349.                   at address in X
  1350.  
  1351. 0900            Beginning of User program (6800)
  1352.  
  1353. Note that some of these addresses apply to the standard 6800 version.
  1354. For other versions addresses above 0100 should be read as addresses
  1355. above their respective starting address.
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.                                   23
  1364.  
  1365.                          A P P E N D I X   E
  1366.  
  1367.                          AN EXAMPLE PROGRAM
  1368.  
  1369.  
  1370. 10 REM DISPLAY 64 RANDOM NUMBERS < 100 ON 8 LINES
  1371. 20 LET I=0
  1372. 30 PRINT RND (100),
  1373. 40 LET I=I+1
  1374. 50 IF I/8*8=I THEN PRINT
  1375. 60 IF I<64 THEN GOTO 30
  1376. 70 END
  1377.  
  1378.  
  1379. 100 REM PRINT HEX MEMORY DUMP
  1380. 109 REM INITIALIZE
  1381. 110 A=-10
  1382. 120 B=-11
  1383. 130 C=-12
  1384. 140 D=-13
  1385. 150 E=-14
  1386. 160 F=-15
  1387. 170 X = -1
  1388. 175 O = 0
  1389. 180 LET S = 256
  1390. 190 REMARK: S IS BEGINNING OF TINY (IN DECIMAL)
  1391. 200 REM GET (HEX) ADDRESSES
  1392. 210 PRINT "DUMP: L,U";
  1393. 215 REM INPUT STARTING ADDRESS IN HEX
  1394. 220 GOSUB 500
  1395. 230 L=N
  1396. 235 REM INPUT ENDING ADDRESS IN HEX
  1397. 240 GOSUB 500
  1398. 250 U=N
  1399. 275 REM TYPE OUT ADDRESS
  1400. 280 GOSUB 450
  1401. 290 REM GET MEMORY BYTE
  1402. 300 LET N = USR (S+20,L)
  1403. 305 REM CONVERT IT TO HEX
  1404. 310 LET M = N/16
  1405. 320 LET N = N-M*16
  1406. 330 PRINT " ";
  1407. 335 REM PRINT IT
  1408. 340 GOSUB 400+M+M
  1409. 350 GOSUB 400+N+N
  1410. 355 REM END?
  1411. 360 IF L=U GO TO 390
  1412. 365 L=L+1
  1413. 370 IF L/16*16 = L GOTO 280
  1414. 375 REM DO 16 BYTES PER LINE
  1415. 380 GO TO 300
  1416. 390 PRINT
  1417. 395 END
  1418. 399 PRINT ONE HEX DIGIT
  1419. 400 PRINT O;
  1420.  
  1421.  
  1422.                                   24
  1423.  
  1424. 401 RETURN
  1425. 402 PRINT 1;
  1426. 403 RETURN
  1427. 404 PRINT 2;
  1428. 405 RETURN
  1429. 406 PRINT 3;
  1430. 407 RETURN
  1431. 408 PRINT 4;
  1432. 409 RETURN
  1433. 410 PRINT 5;
  1434. 411 RETURN
  1435. 412 PRINT 6;
  1436. 413 RETURN
  1437. 414 PRINT 7;
  1438. 415 RETURN
  1439. 416 PRINT 8;
  1440. 417 RETURN
  1441. 418 PRINT 9;
  1442. 419 RETURN
  1443. 420 PRINT "A";
  1444. 421 RETURN
  1445. 422 PRINT "B";
  1446. 423 RETURN
  1447. 424 PRINT "C";
  1448. 425 RETURN
  1449. 426 PRINT "D";
  1450. 427 RETURN
  1451. 428 PRINT "E";
  1452. 429 RETURN
  1453. 430 PRINT "F";
  1454. 431 RETURN
  1455. 440 REM PRINT HEX ADDRESS
  1456. 450 PRINT
  1457. 455 REM CONVERT IT TO HEX
  1458. 460 N = L/4096
  1459. 470 IF L<0 N=(L-32768)/4096+8
  1460. 480 GOSUB 400+N+N
  1461. 483 LET N=(L-N*4096)
  1462. 486 GOSUB 400+N/256*2
  1463. 490 GOSUB 400+(N-N/256*256)/16*2
  1464. 495 GOTO 400+(N-N/16*16)*2
  1465. 496 GOTO=GOSUB,RETURN
  1466. 500 REM INPUT HEX NUMBER
  1467. 501 REM FORMAT IS NNNNX
  1468. 502 REM WHERE "N" IS ANY HEX DIGIT
  1469. 505 N=0
  1470. 509 REM INPUT LETTER OR STRING OF DIGITS
  1471. 510 INPUT R
  1472. 520 IF R=X RETURN
  1473. 525 REM CHECK FOR ERROR
  1474. 530 IF R>9999 THEN PRINT "BAD HEX ADDRESS
  1475. 531 REM NOTE ERROR STOP ON LINE 530 (ON PURPOSE!)
  1476. 535 REM CONVERT INPUT DECIMAL DIGITS TO HEX
  1477. 540 IF R>999 THEN N=N*16
  1478. 545 IF R>99 THEN N=N*16
  1479. 550 IF R>9 THEN N=N*16
  1480.  
  1481.                                   25
  1482.  
  1483. 555 IF R>0 THEN R=R+R/1000*1536+R/100*96+R/10*6
  1484. 559 REM PICK UP NON-DECIMAL DIGIT LETTERS
  1485. 560 IF R<0 THEN LET R=-R
  1486. 565 REM ADD NEW DIGIT TO PREVIOUS NUMBER
  1487. 570 LET N=N*16+R
  1488. 580 GOTO 510
  1489. 590 NOTE: DON'T NEED END HERE
  1490.  
  1491.  
  1492. 1000 TO RUN RANDOM NUMBER PROGRAM, TYPE "RUN"
  1493. 1010 IT WILL TYPE 8 LINES THEN STOP.
  1494. 1020 TO RUN HEX DUMP PROGRAM TYPE "GOTO 100"
  1495. 1030 IT WILL ASK FOR INPUT, TYPE 2 HEX ADDRESSES
  1496. 1040 EACH TERMINATED BY THE LETTER X,
  1497. 1050 AND SEPARATED BY A COMMA
  1498. 1055 (TYPE ALL ZEROS AS LETTER OH).
  1499. 1060 THE PROGRAM WILL DUMP MEMORY BETWEEN
  1500. 1070 THOSE TWO ADDRESSES, INCLUSIVE.
  1501. 1080 EXAMPLE:
  1502. 1090 :GOTO 100
  1503. 1100 DUMP: L,U? AO3EX,AO46X
  1504. 1110 A03E EE FF
  1505. 1120 A040 00 11 22 33 44 55 66
  1506. 1130 IF THE RANDOM NUMBER PROGRAM
  1507. 1140 IS REMOVED, OR IF YOU TYPE IN
  1508. 1150 :1 GOTO 100
  1509. 1160 THEN YOU CAN GET THE SAME DUMP BY TYPING
  1510. 1170 :RUN,AO3EX,AO46X
  1511. 1180 .
  1512. 1190 NOTE THAT THIS PROGRAM DEMONSTRATES NEARLY
  1513. 1200 EVERY FEATURE AVAILABLE IN TINY BASIC.
  1514.  
  1515.  
  1516.  
  1517. REMARK: TO FIND OUT HOW MUCH PROGRAM SPACE
  1518. REM... YOU HAVE LEFT, TYPE:
  1519. LET I=0
  1520. 1 LET I=I+2
  1521. 2 GOSUB 1
  1522. RUN
  1523. REMARK: AFTER A FEW SECONDS, THIS WILL STOP
  1524. REM... WITH AN ERROR; THEN TYPE:
  1525. END
  1526. PRINT "THERE ARE ";I;" BYTES LEFT"
  1527.  
  1528.  
  1529. REM: TO EXIT FROM TINY BASIC TO YOUR MONITOR/DEBUGGER,
  1530. LET S=256
  1531. REM (S AS IN LINE 180 ABOVE)
  1532. LET B=0
  1533. IF P=6800 THEN LET B=63
  1534. REM: B IS SWI OR BRK INSTRUCTION
  1535. LET A = USR (S+24,0,B) + USR (0)
  1536. REM: THE FIRST CALL STORES A BREAK IN 0000
  1537. REM... THE SECOND CALL JUMPS TO IT.
  1538.  
  1539.  
  1540.                                   26