home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / tipi / tipidoc.txt < prev    next >
Text File  |  1993-11-07  |  52KB  |  2,216 lines

  1.  
  2.        +--------------------------------------------------------------------+
  3.        |                                                                    |
  4.        |                          T I P I  version 1.0                      |
  5.        |           X                                             X          |
  6.        |          / \                                           / \         |
  7.        |         /   \             Copyright (c) 1993          /   \        |
  8.        |        /  +  \                    by                 /  +  \       |
  9.        |       /   +   \            Kent P. Peterson         /   +   \      |
  10.        |      /    O    \                                   /    O    \     |
  11.        |                          All Rights Reserved                       |
  12.        +--------------------------------------------------------------------+
  13.        |  TIPI 1.0 is provided as shareware.  Under the shareware           |
  14.        |  concept,  you can test a program before you buy it. If you find   |
  15.        |  it suitable for your needs and make use of this program, you are  |
  16.        |  expected to send a $25 registration fee.                          |
  17.        |                                                                    |
  18.        |  Feel free to distribute this software to others.  However, you    |
  19.        |  may not charge for the distribution of this software to others    |
  20.        |  nor may you alter the software or this documentation.             |
  21.        |                                                                    |
  22.        |  Registered users of any version of TIPI will receive a diskette   |
  23.        |  containing the current version of TIPI, plus may purchase future  |
  24.        |  updates at half of the normal registration price.  A printed      |
  25.        |  manual is available to registered users for an additional $10.00. |
  26.        |                                                                    |
  27.        |  For further ordering information, please see the file ORDER.FRM,  |
  28.        |  included with TIPI.                                               |
  29.        +--------------------------------------------------------------------+
  30.        |                                                                    |
  31.        |     Please send registration fees and suggestions to:              |
  32.        |                                                                    |
  33.        |                           Kent P. Peterson                         |
  34.        |                           360 NW Dogwood #A-201                    |
  35.        |                           Issaquah, WA  98027-3272                 |
  36.        |                                                                    |
  37.        |     Please mention the version of TIPI in any correspondence       |
  38.        |                       (This is TIPI Version 1.0)                   |
  39.        +--------------------------------------------------------------------+
  40.        |    You can also send questions/comments via Internet or Compuserve |
  41.        |                                                                    |
  42.        |                     Internet        tipi@prostar.com               |
  43.        |                                                                    |
  44.        |                     Compuserve      72310,2174                     |
  45.        |                                                                    |
  46.        +--------------------------------------------------------------------+
  47.        |                                                                    |
  48.        |  DISCLAIMER:  This software is provided "as is" without warranty   |
  49.        |  of any kind, either expressed or implied.                         |
  50.        |                                                                    |
  51.        |  Your registration fee entitles you to distribute TIPI.COM together|
  52.        |  with any TIPI programs you write. If you profit from working with |
  53.        |  TIPI, please register it. Thank you.                              |
  54.        +--------------------------------------------------------------------+
  55.                 
  56.                                 page 1
  57.  
  58.                 Contents
  59.  
  60.  
  61.     Introduction..................................................2
  62.  
  63.     History.......................................................2
  64.  
  65.     Installing TIPI...............................................2
  66.  
  67.     Running TIPI..................................................3
  68.  
  69.     The TIPI Programmer's Workbench...............................3
  70.  
  71.     TIPI Programming..............................................5
  72.  
  73.     Instruction Descriptions......................................7
  74.  
  75.     Errors and the TIPI Debugger..................................8
  76.  
  77.     Defining New Instructions....................................10
  78.  
  79.     Working with Stacks..........................................11
  80.  
  81.     Defining and Using Variables and Tables......................11
  82.  
  83.     Common mistakes of new TIPI Programmers......................13
  84.  
  85.     Notes and Limits.............................................13
  86.  
  87.     Math Instructions............................................14
  88.  
  89.     String Instructions..........................................16
  90.  
  91.     Stack Instructions...........................................20
  92.  
  93.     I/O Instructions.............................................23
  94.  
  95.     DOS Instructions.............................................30
  96.  
  97.     Defining Instructions........................................33
  98.  
  99.     Data Instructions............................................35
  100.  
  101.     Control Instructions.........................................36
  102.  
  103.     Debugging Instructions.......................................40
  104.  
  105.     Miscellaneous Instructions...................................41
  106.  
  107.  
  108.                 
  109.                                 page 2
  110.  
  111.                 Introduction
  112.  
  113.     TIPI is a small, structured programming language for MS-DOS
  114.     computers. The TIPI interpreter takes up less than 10K bytes
  115.     of disk space and TIPI programs are similarly small. TIPI
  116.     requires only 120K bytes of RAM and is thus well-suited for
  117.     palmtop computers such as the Atari Portfolio, the Poquet or
  118.     the HP-95LX.
  119.  
  120.     TIPI contains over 100 instructions and control structures
  121.     including Do..Loop, While..Wend and Begin..Until Loops. TIPI
  122.     also includes If..Then..Else and Case statements and an
  123.     integrated debugger. TIPI is an extensible language, so
  124.     programmers may add to the language as they see fit.
  125.  
  126.  
  127.                 History
  128.  
  129.     TIPI is a new language, but it incorporates elements from
  130.     various earlier languages. The languages Forth and BASIC most
  131.     stongly influenced the development of TIPI, but some of TIPI's
  132.     features may be traced back to C, Pascal or AWK. TIPI was
  133.     invented by Kent P. Peterson in 1993. The TIPI language and
  134.     the TIPI interpreter are copyright (c) 1993 by Kent P. Peterson.
  135.  
  136.     The name TIPI is an acronym standing for "Threaded Instruction
  137.     Processing Interpreter". While interpreted programs tend to run
  138.     slower than compiled programs, interpreters do not require a
  139.     seperate compile and link stage and thus programs can be quickly
  140.     tested and changed. Also, interpreters can be very small, as
  141.     evidenced by TIPI's tiny size.
  142.  
  143.     TIPI was written in ASIC, an excellent shareware compiler and
  144.     compacted using COMPACK, a shareware file compressor.
  145.  
  146.  
  147.                 Installing TIPI
  148.  
  149.     TIPI is distributed as a single compressed EXE file named
  150.     TIPIV1.EXE. Place this file in an empty DOS directory or
  151.     onto a floppy. When you run TIPIV1 from the DOS prompt, it
  152.     will extract the TIPI interpreter, various sample TIPI programs,
  153.     a few utilities and the TIPI documentation.
  154.  
  155.     To install TIPI on a palmtop computer, you really only need
  156.     TIPI.COM and whatever TIPI programs you care to run. To get the
  157.     full use of TIPI, however, I suggest that you install the TIPI
  158.     Programmer's Workbench, described on the next page. Also, if you
  159.     have an Atari Portfolio, you will need to set the FDISK to 8 to
  160.     allow TIPI to have the 120K of RAM it needs to run. See your
  161.     Portfolio manual for details.
  162.                 
  163.                                 page 3
  164.  
  165.                 Running TIPI
  166.  
  167.     TIPI programs are ASCII text files that are interpreted by the
  168.     TIPI interpreter. All of the sample TIPI programs included in
  169.     this release have the file extension .TPI
  170.  
  171.     The simplest way to run a tipi program is to type the word TIPI
  172.     followed by the name of the tipi program. Thus
  173.  
  174.         TIPI HANGMAN.TPI
  175.  
  176.     will run the hangman program.
  177.  
  178.     If you want to modify a TIPI program or create a new TIPI program,
  179.     you may edit the .TPI files with any ASCII text editor. A more
  180.     integrated approach is to use the TIPI Programmer's Workbench.
  181.  
  182.  
  183.             The TIPI Programmer's Workbench
  184.  
  185.     The TIPI Programmer's Workbench is a tiny integrated environment
  186.     for TIPI development. The files that make up the workbench are:
  187.  
  188.         T.BAT      The bat file that runs the whole show.
  189.         T.TPI      The TIPI menu file.
  190.         TIPI.COM   The TIPI interpreter.
  191.         TIPI.ADR   An alphabetic list of all the predefined
  192.                TIPI instructions.
  193.         SETAPP.COM (only needed for the Atari Portfolio)
  194.  
  195.     To get familiar with the workbench, start the workbench with
  196.     the sample program HANGMAN.TPI. You do this by typing:
  197.  
  198.         T HANGMAN.TPI
  199.  
  200.     You will see a screen that looks like this:
  201.  
  202.         +----------------------------------------+
  203.         | [E]dit, [L]ookup, [R]un or [Q]uit      |
  204.         |                                        |
  205.         | TIPI Programmer's Workbench    X       |
  206.         | Version 1.0                   / \      |
  207.         |                              /   \     |
  208.         | Current File: HANGMAN.TPI   /  +  \    |
  209.         |                            /   +   \   |
  210.         |                           /    O    \  |
  211.         +----------------------------------------+
  212.  
  213.     Now you may press E, L, R, or Q to select on of the functions.
  214.     Selecting [E]dit will let you edit the HANGMAN.TPI file. If
  215.     you are using an Atari Portfolio, the workbench will use the
  216.     Portfolio's editor. If you are on a PC or another palmtop, the
  217.     DOS editor will be used. (Please note, if you have a preference
  218.     for another editor, you can change the T.BAT file to use that
  219.     editor. If you don't know how to change a bat file, give up on
  220.     TIPI right now and learn the fundamentals of DOS!)
  221.                 
  222.                                 page 4
  223.  
  224.     TIPI programs are simple ASCII files that consists of INSTRUCTIONS
  225.     separated by WHITESPACE. The TIPI instructions are described in
  226.     detail later in this document. WHITESPACE characters are spaces,
  227.     tabs and carriage returns
  228.  
  229.     For starters, it is probably best to just look at the sample
  230.     programs and not change them. Once you have gotten familiar with
  231.     TIPI and written some small programs of your own, you can go back
  232.     and use the sample programs to give you ideas for kind of things
  233.     TIPI can do.
  234.  
  235.     [L]ookup will let you browse through the documentation for each
  236.     of the predefined TIPI instructions. On the Atari Portfolio,
  237.     the Porfolio's Address Book is used as the browser. On other
  238.     computers, the DOS editor is used. Again, you may edit the bat
  239.     file to make the workbench use you own favorite browser.
  240.  
  241.     [R]un will run your program and [Q]uit will quit the workbench.
  242.                 
  243.                                 page 5
  244.  
  245.                 TIPI Programming
  246.  
  247.     While many of the instructions in TIPI look very much like
  248.     BASIC statements, TIPI is in fact very different than BASIC.
  249.     Probably the greatest difference between TIPI and BASIC is
  250.     the fact that TIPI uses a syntax known as RPN. RPN stands for
  251.     Reverse Polish Notation (no, it's not an ethnic slur. It
  252.     refers to the nation of origin of the mathemeticians who
  253.     originated this notation.)
  254.  
  255.     RPN is used in many Hewlett-Packard calculators, in the display
  256.     language PostScript, in some CPUs, in Forth and now in TIPI.
  257.     To most people, RPN looks backwards, but RPN has many advantages.
  258.  
  259.     To add two plus two in BASIC and print out the result, your
  260.     program would look something like this:
  261.  
  262.         X=2+2
  263.         PRINT X
  264.  
  265.     To do the same thing in TIPI, your program would look like
  266.     this:
  267.  
  268.         2 2 + print
  269.  
  270.     It may seem weird, but once you get used to RPN, it really does
  271.     make things easier. For example, when you want to do more complex
  272.     math, you have to use parentheses in BASIC to make sure that
  273.     everything gets done in just the order you want, like this:
  274.  
  275.         X=(6+3)*4/3
  276.         PRINT X
  277.  
  278.     In TIPI you do it like this
  279.  
  280.         6 3 + 4 * 3 / print
  281.         ( parentheses mark comments in TIPI )
  282.         ( just like they do in English. )
  283.  
  284.     RPN works by using something called a STACK. The best way to think
  285.     of a stack is to think of a pile of data. TIPI has several of these
  286.     stacks and the most commonly used one of these is called simply
  287.     the stack or sometimes the data stack.
  288.  
  289.     Here is the key to TIPI programming:
  290.  
  291.     EVERY TIPI INSTRUCTION DOES SOMETHING TO ONE OR MORE OF TIPI'S
  292.     STACKS. TO PROGRAM IN TIPI, YOU MUST KNOW WHAT THE INSTRUCTIONS
  293.     DO TO THE STACKS.
  294.                 
  295.                                 page 6
  296.  
  297.     Let's return to our simple example to see what is going on in
  298.     TIPI. Here is our "two plus two" example expanded out and
  299.     explained. Once you understand this, you'll be well on your way
  300.     to understanding TIPI!
  301.  
  302.         2    # This places the number two on the stack.
  303.         2    # This also places a two on the the stack.
  304.         +    # This removes the top two numbers from the
  305.             # stack, adds them together and places the
  306.             # result on the stack.                
  307.         print    # This takes the top number from the stack
  308.             # and prints it out.                      
  309.  
  310.     Now is a good time to talk about program comments. Comments
  311.     are program instructions that are ignored by the computer
  312.     but are intended to be read by people. Even if you think
  313.     you are going to be the only person ever to look at your
  314.     program, it is almost always worth it to put some comments
  315.     in it. In TIPI you have your choice of two types of comments.
  316.     The following illustrates both comment methods.
  317.  
  318.         # Everything following a "pound" sign
  319.         # on a line in a TIPI program is taken
  320.         # to be a comment.
  321.         2 2 + ( add up two and two ) print ( and print the result )
  322.  
  323.     The "#" sign tells TIPI to ignore the rest of the line
  324.     and the "(" tells TIPI to ignore everything until it finds
  325.     a matching ")".
  326.  
  327.     TIPI does all it's math in integer values. That means you can
  328.     work with numbers like 6, -584, 47789329 and 0 but you can't
  329.     have 3.14159 or 6.02^23. Forth purists will tell you that you
  330.     don't need floating point math. I'll tell you that TIPI doesn't
  331.     have it because it would make TIPI too big and too slow for
  332.     what I wanted. And the Forth guys are basically right. I have
  333.     seen 3-D animation engines written using only integer math
  334.     and two friends of mine have coded an entire hockey game
  335.     (including player physics and AI) using only integer math.
  336.  
  337.     The TIPI data stack and all it's math instructions work with
  338.     long (32 bit) signed values. This means that TIPI can handle
  339.     integers from -2,147,483,648 to 2,147,483,647. This is a very
  340.     wide range and with some creative scaling, you should be able
  341.     to handle almost any problem that you might have thought would
  342.     require floating point math.
  343.  
  344.     In addition to the data stack, TIPI has a string stack and a
  345.     return stack. The string stack is used to store strings and
  346.     the return stack is used internally by TIPI. The return stack
  347.     may also be used as a temporary place to put a number that
  348.     you don't want to place on the regular data stack. See the
  349.     PUSH and POP instructions for more details.
  350.  
  351.                 
  352.                                 page 7
  353.  
  354.             Instruction Descriptions
  355.  
  356.     The bulk of this manual consists of descriptions of each of the
  357.     hundred-odd built-in TIPI instructions. These descriptions
  358.     consist of the name of the instruction, a STACK DIAGRAM which
  359.     explains what the instruction does to the Data and String stacks,
  360.     and a sentence or two describing what the instruction does. Here
  361.     is an example:
  362.  
  363.     MID$                <-- This is the name of the
  364.                         instruction.
  365.     Data   ( s l -- )        <-- These are the stack 
  366.     String ( a$ -- b$ )        <-- diagrams
  367.      
  368.     Returns b$, a string of l    <-- This is the description
  369.     characters starting at
  370.     position s from a$.
  371.  
  372.     What the stack diagrams do is describe what the data and string
  373.     stacks look like before the instruction executes and right after
  374.     the instruction executes. In these diagrams the "--" separates
  375.     the "before" from the "after" and the top of the stack is the
  376.     right most entry. Thus
  377.  
  378.     6 2 "TIPI is not BASIC" MID$
  379.  
  380.     would extract 2 characters starting at position 6 in "TIPI is
  381.     not BASIC". The result would be the string "is" left on the
  382.     string stack.
  383.  
  384.     TIPI has a wide range of instructions dealing with Math, Strings
  385.     Stacks, I/O, DOS, Definitions, Data, Control, Debugging and
  386.     Miscellanous functions. All of these instructions are detailed
  387.     in later sections of this manual.
  388.                 
  389.                                 page 8
  390.  
  391.             Errors and the TIPI Debugger
  392.  
  393.     It would be great if we all could write perfect programs and
  394.     never had programs bugs. Unfortunately, that's not the way
  395.     programming works. Because programs can have bugs, TIPI has
  396.     a built-in debugger. The debugger is actually a program tracer
  397.     and it will help you track down bugs and give you a view of what
  398.     is happening as TIPI runs your program.
  399.  
  400.     First off, let's run ERROR.TPI a sample program that contains
  401.     (gasp) a BUG. Start the TIPI Programmer's Workbench by typing:
  402.  
  403.         T ERROR.TPI
  404.  
  405.     and pick [R]un from the menu. 
  406.  
  407.     BAM! TIPI will display this error message:
  408.  
  409.         ERROR!        1
  410.         Too few stack values with
  411.         +
  412.  
  413.     Pressing any key will show you the debugger screen, which
  414.     looks like this:
  415.  
  416.         +- Data Depth  1 -+- String Depth  0-+
  417.         |                2|              ----|
  418.         |             ----|              ----|
  419.         |             ----|              ----|
  420.         |             ----|              ----|
  421.         |+                                   |
  422.         |3 =                                 |
  423.         +------------------------------------+
  424.  
  425.     This is what's known in the programming biz as a "post-mortem"
  426.     dump. This means that you program is dead and you can't really
  427.     do anything to fix it right now. This screen is just giving
  428.     you more info about what went wrong. In this case what went
  429.     wrong was the program tried to add with only one value on the
  430.     stack. The error message told you that, and the debugger came
  431.     up to show you just what you had on the stacks. The debugger
  432.     displays the data stack on the left, the string stack on the
  433.     right and the instruction just executed below the data stack.
  434.     Below that are the instructions it was about to execute. In a
  435.     post-mortem dump, pressing any key will return you to the
  436.     Workbench.
  437.  
  438.     Now let's use the editor to change the program to fix the bug.
  439.     Here is the program:
  440.  
  441.         # ERROR.TPI
  442.  
  443.         # This simple program has a
  444.         # bug in it to show you how
  445.         # to use the TIPI debugger
  446.  
  447.         3 + 2 =
  448.         "The sum is " print$ print
  449.                 
  450.                                 page 9
  451.  
  452.     The problem may be fixed by changing the program to read:
  453.  
  454.         # ERROR.TPI
  455.  
  456.         # This simple program had a
  457.         # bug in it to show you how
  458.         # to use the TIPI debugger
  459.  
  460.         3 2 +
  461.         "The sum is " print$ print
  462.  
  463.  
  464.     By moving the "+" after the 2 and getting rid of the unneeded
  465.     "=" the program is fixed. Running the program again will show
  466.     that all is well and our program can perform the amazing (well
  467.     maybe not amazing!) feat of adding two integers.
  468.  
  469.     But wait, what if we wanted to see more of what's going on?
  470.     You can do this by invoking the debugger at any point in your
  471.     code by simply adding the instruction "TRACEON". For example,
  472.     if you change our little program to look like this:
  473.  
  474.         # ERROR.TPI
  475.  
  476.         # This simple program had a
  477.         # bug in it to show you how
  478.         # to use the TIPI debugger
  479.         traceon
  480.         3 2 +
  481.         "The sum is " print$ print
  482.  
  483.     The debugger will be displayed from the start. You may step
  484.     through the program by pressing the [SPACEBAR]. You will see
  485.     each instuction execute and you can watch what it does to the
  486.     stacks. By watching a program in this way, you can usually
  487.     track down bugs in just a few minutes.
  488.  
  489.     While tracing a program, the following keys are active:
  490.  
  491.         [SPACEBAR]    Steps to the next instruction.
  492.         [ESC]        Quits the debugger until another
  493.                 TRACEON command is executed.
  494.         [END]        Ends the program.
  495.  
  496.     In addition to TRACEON there are instructions for turning
  497.     the trace window off, placing the trace window elsewhere on
  498.     the screen and for tracing the contents of variables. See the
  499.     section "Debugging Instructions" for more details.
  500.                 
  501.     `                            page 10
  502.  
  503.             Defining New Instructions
  504.  
  505.     For several pages now, I've been refering to TIPI's "built-in"
  506.     instructions. I use that phrase because TIPI lets you add your
  507.     own instructions to the language. This is a VERY powerful
  508.     concept. YOU CAN MAKE TIPI INTO WHAT YOU WANT. You can add
  509.     your own features to it. Once you get the hang of this, you are
  510.     playing with power. Most languages make you conform to the way
  511.     the language works. With TIPI, you mold the language to the
  512.     problem at hand and the way you work. The sample programs are
  513.     filled with examples of ways to extend the language, but
  514.     here is a simple sample:
  515.  
  516.  
  517.         # POWERS.TPI
  518.         # by Kent Peterson
  519.  
  520.         # This is a simple program to demonstrate
  521.         # how easy it is to add new instructions
  522.         # to TIPI.
  523.  
  524.         define square ( n -- n*n )
  525.         # Squares a number
  526.          dup *
  527.         enddef
  528.  
  529.         define cube ( n -- n*n*n )
  530.         # Cubes a number
  531.          dup square *
  532.         enddef
  533.  
  534.         define quad ( n -- n*n*n*n )
  535.         # raises a number to the fourth power
  536.          square dup *
  537.         enddef
  538.  
  539.         "Enter a number" print$
  540.         getnum
  541.         dup square print cr
  542.         dup cube   print cr
  543.              quad   print cr
  544.         begin key until
  545.  
  546.  
  547.     Notice that the definition "square" is used in the definitions
  548.     of "cube" and "quad". Once you define an instruction in your
  549.     program, you can use it just like a built-in TIPI instruction.
  550.     When your code executes, TIPI will jump back to where the
  551.     new instruction was defined. If you are running the debugger,
  552.     you can watch this happen.
  553.  
  554.     The main idea in TIPI programming is to break your problem up
  555.     into little chunks and create instructions to solve the sub
  556.     problems. In this way, you not only create a program to solve
  557.     this particular problem, but a language that is useful for
  558.     solving similar problems.
  559.                 
  560.                                 page 11
  561.  
  562.                 Working with Stacks
  563.  
  564.     Because stacks are such a vital part of TIPI programming, TIPI
  565.     has a wide range of instructions to manipulate the contents of
  566.     the stacks. The section titled, "Stack Instructions" later in
  567.     this manual details the use of these instructions.
  568.  
  569.  
  570.             Defining and Using Variables and Tables
  571.  
  572.     In addition to the data and string stacks, TIPI lets you create
  573.     integer variables, integer arrays and strings. To use a variable
  574.     in your program you must first define it. TIPI also has a data
  575.     structure called a TABLE. The proper use of variables and tables
  576.     are illustrated in the program VARSAMPLE listed below. More
  577.     information can be found in the manual sections describing
  578.     Defining Instructions and Data Instructions.
  579.  
  580.     # VARSAMPLE.TPI
  581.     # by Kent Peterson
  582.     # This program demonstrates the three
  583.     # types of variables in TIPI along with
  584.     # the table data structure.
  585.  
  586.     defvar price
  587.     3 defarray zipcode
  588.  
  589.     defstr Man$
  590.  
  591.     deftable kid$           # This sets the
  592.      "Bart" "Lisa" "Maggie" # table kid$ to
  593.     endtable                # to hold the names
  594.                             # of three kids.
  595.  
  596.     100 price store         # This stores 100 in
  597.                             # the variable price.
  598.  
  599.     10605 1 zipcode store   # This stores
  600.     60609 2 zipcode store   # different zipcodes
  601.     90210 3 zipcode store   # in each of the
  602.                             # three zipcode
  603.                             # slots.
  604.  
  605.     "Homer" Man$ store      # This stores the
  606.                             # word "Homer" in
  607.                             # the variable Man$.
  608.  
  609.     # Now let's use these variables
  610.     # and the table
  611.  
  612.     "Hi, I'm " print$
  613.     Man$ fetch print$       # You have to fetch
  614.                             # the contents of
  615.                             # a variable before
  616.                             # you can print it out.
  617.     "." print$ cr
  618.                 
  619.                                 page 12
  620.  
  621.     "My kids are named "
  622.     print$
  623.     1 kid$ print$           # Tables are initialized
  624.                             # when they are defined
  625.                             # and they auto-fetch.
  626.                             # DO NOT USE A FETCH
  627.                             # with a table.
  628.     ", " print$
  629.     2 kid$ print$
  630.     " and " print$
  631.     3 kid$ print$
  632.     "." print$ cr cr
  633.  
  634.     "My car cost $" print$
  635.     price fetch print
  636.     "." print$ cr cr
  637.  
  638.     "My zipcode is " print$
  639.     1 zipcode fetch print   # Array values
  640.                             # are fetched and
  641.                             # and stored using
  642.                             # their names and
  643.                             # their index values.
  644.     " but I wish it was "
  645.     print$
  646.     3 zipcode fetch print
  647.     "." print$ cr
  648.  
  649.  
  650.     begin key until     # This sequence of
  651.                         # instructions waits
  652.                         # until you press
  653.                         # a key.
  654.  
  655.                 
  656.                                 page 13
  657.  
  658.         Common mistakes of new TIPI Programmers
  659.  
  660.     The number one mistake would have to be stack errors. Study
  661.     the samples and learn RPN. IT IS WORTH IT. Your code won't
  662.     be cluttered with parentheses and the instructions will flow
  663.     in a logical order. The debugger will help a lot.
  664.  
  665.     Another common mistake is confusing the name of a variable
  666.     with the contents of a variable. If you have a variable
  667.     named FRED, FRED is just it's name. FRED FETCH is how you
  668.     fetch a value and FRED STORE is how you store a value.
  669.  
  670.     Forgetting to end a DEFINE. When TIPI sees a DEFINE, it looks
  671.     for the matching ENDDEF. If you don't have a match ENDDEF (or
  672.     you misspell it) TIPI gets very confused.
  673.  
  674.     Forgetting to leave white space around TIPI instructions. The
  675.     one that is most commonly screwed up is the "(". In TIPI make
  676.     your comments
  677.  
  678.         ( Look like this. )
  679.          (Not like this.)
  680.  
  681.  
  682.  
  683.                 Notes and Limits
  684.  
  685.     TIPI is case insensitive. This means that MAX, max and Max
  686.     all refer to the same instruction.
  687.  
  688.     TIPI uses vectored I/O. This means that all of the I/O commands
  689.     can be directed to/from files, the console, printers, etc.
  690.     See the commands ISINPUT and ISOUTPUT for details.
  691.  
  692.     Strings are limited to a maximum of 80 characters.
  693.  
  694.     The maximum depths for the data and return stacks are 80.
  695.  
  696.     The maximum depth of the string stack is 32.
  697.  
  698.     The maximum number of named variables is 100.
  699.  
  700.     The maximum number of array elements is a total of 1000.
  701.  
  702.     The maximum number of trace variables is 10.
  703.  
  704.     The maximum number of user-defined instructions is 100.
  705.  
  706.     TIPI always searches it's internal dictionary first, then
  707.     searches for new instructions in the order in which they
  708.     were defined.
  709.  
  710.     An instruction must be defined before it is used.
  711.  
  712.                 
  713.                                 page 14
  714.  
  715.             Math Instructions
  716.     
  717.                 ABS
  718.     ABS
  719.     Data   ( n -- abs(n) )
  720.     String ( -- )
  721.      
  722.     Replaces the top value on the data
  723.     stack with its absolute value.
  724.     
  725.     
  726.                 MAX
  727.     MAX
  728.     Data   ( A B -- MAX )
  729.     String ( -- )
  730.      
  731.     Places the greater of A or B
  732.     on the data stack.
  733.     
  734.     
  735.                 MIN
  736.     MIN
  737.     Data   ( A B -- MIN )
  738.     String ( -- )
  739.      
  740.     Places the lesser of A or B
  741.     on the data stack.
  742.     
  743.     
  744.                 MOD
  745.     MOD
  746.     Data   ( A B -- C )
  747.     String ( -- )
  748.      
  749.     Returns A modulo B.
  750.     
  751.     
  752.                 *
  753.     *
  754.     Data   ( A B -- C )
  755.     String ( -- )
  756.      
  757.     Multiplies A times B.
  758.     
  759.     
  760.                 +
  761.     +
  762.     Data   ( A B -- C )
  763.     String ( -- )
  764.      
  765.     Adds A and B.
  766.                      
  767.                                 page 15
  768.  
  769.                 -
  770.     -
  771.     Data   ( A B -- C )
  772.     String ( -- )
  773.      
  774.     Subtracts B from A.
  775.     
  776.     
  777.                 /
  778.     /
  779.     Data   ( A B -- C )
  780.     String ( -- )
  781.      
  782.     Divides A by B.
  783.     
  784.     
  785.                 <
  786.     <
  787.     Data   ( A B -- C )
  788.     String ( -- )
  789.      
  790.     C is TRUE if A is less than B,
  791.     FALSE otherwise.
  792.     
  793.     
  794.                 =
  795.     =
  796.     Data   ( A B -- C )
  797.     String ( -- )
  798.      
  799.     C is TRUE if A equals B, FALSE
  800.     otherwise.
  801.     
  802.     
  803.                 >
  804.     >
  805.     Data   ( A B  -- C )
  806.     String ( -- )
  807.      
  808.     C is TRUE if A is greater than B,
  809.     FALSE otherwise.
  810.                 
  811.                                 page 16
  812.  
  813.             String Instructions
  814.     
  815.                 ASC
  816.     ASC
  817.     Data   ( -- N )
  818.     String ( A$ -- A$ )
  819.      
  820.     Places a number N on the data
  821.     stack, where N is the ASCII value
  822.     of the first character of the
  823.     string on the top of the string
  824.     stack.
  825.     
  826.     
  827.                 CHR$
  828.     CHR$
  829.     Data   ( N -- )
  830.     String ( -- M$ )
  831.      
  832.     CHR$ converts an integer N from
  833.     the data stack to an ASCII
  834.     character and places the single
  835.     character string on the top of the
  836.     string stack.
  837.     
  838.     
  839.                 DATE$
  840.     DATE$
  841.     Data   ( -- )
  842.     String ( -- D$ )
  843.      
  844.     Places the current date on the
  845.     string stack in the form
  846.     "MM-DD-YYYY".
  847.     
  848.     
  849.                 INSTR
  850.     INSTR
  851.     Data   ( -- n )
  852.     String ( a$ b$ -- a$ b$ )
  853.      
  854.     Searches a$ for the first
  855.     occurrence of b$. If b$ is in a$,
  856.     n is the location where b$ starts
  857.     in a$. If b$ is not in a$, n is
  858.     zero.
  859.     
  860.     
  861.                 LCASE$
  862.     LCASE$
  863.     Data   ( -- )
  864.     String ( A$ -- a$ )
  865.      
  866.     Converts any uppercase characters
  867.     in A$ to lower case.
  868.                      
  869.                                 page 17
  870.  
  871.                 LEFT$
  872.     LEFT$
  873.     Data   ( n -- )
  874.     String ( a$ -- l$ )
  875.      
  876.     Returns a string consisting of the
  877.     n leftmost characters of a$. For
  878.     example, "This is a test" 7 LEFT$
  879.     would return "This is".
  880.     
  881.     
  882.                 LEN
  883.     LEN
  884.     Data   ( -- len )
  885.     String ( a$ -- a$ )
  886.      
  887.     Places the length of a$ on the
  888.     data stack.
  889.     
  890.     
  891.                 LTRIM$
  892.     LTRIM$
  893.     Data   ( -- )
  894.     String ( a$ -- b$ )
  895.      
  896.     Trims any leading blanks from a$.
  897.     
  898.     
  899.                 MID$
  900.     MID$
  901.     Data   ( s l -- )
  902.     String ( a$ -- b$ )
  903.      
  904.     Returns b$, a string of l
  905.     characters starting at position s
  906.     from a$.
  907.     
  908.     
  909.                 PARSE$
  910.     PARSE$
  911.     Data   ( -- )
  912.     String ( TEXT$ -- NEWTEXT$ WORD$ )
  913.      
  914.     Parses the first word from TEXT$.
  915.     
  916.     
  917.                 REPLACE$
  918.     REPLACE$
  919.     Data   ( -- )
  920.     String ( TEXT$ OLD$ NEW$ -- NEWTEXT$ )
  921.      
  922.     Replaces any occurences of OLD$ in
  923.     TEXT$ with NEW$.
  924.                      
  925.                                 page 18
  926.  
  927.                 RIGHT$
  928.     RIGHT$
  929.     Data   ( n -- )
  930.     String ( A$ -- B$ )
  931.      
  932.     Returns a string consisting of the
  933.     n rightmost characters of a$. For
  934.     example, "This is a test" 6 RIGHT$
  935.     would return "a test".
  936.     
  937.     
  938.                 RTRIM$
  939.     RTRIM$
  940.     Data   ( -- )
  941.     String ( A$ -- B$ )
  942.      
  943.     Removes any trailing blanks from
  944.     A$.
  945.     
  946.     
  947.                 STR$
  948.     STR$
  949.     Data   ( N -- )
  950.     String ( -- N$ )
  951.      
  952.     Converts an integer from the data
  953.     stack to a string. For example,
  954.     123 STR$ would place the string
  955.     "123" on the string stack.
  956.     
  957.     
  958.                 TIME$
  959.     TIME$
  960.     Data   ( -- )
  961.     String ( -- T$ )
  962.      
  963.     Places the current time (in the
  964.     form "HH:MM:SS") on the string
  965.     stack.
  966.     
  967.     
  968.                 UCASE$
  969.     UCASE$
  970.     Data   ( -- )
  971.     String ( a$ -- A$ )
  972.      
  973.     Converts all the characters in a
  974.     string to uppercase.
  975.     
  976.     
  977.                 VAL
  978.     VAL
  979.     Data   ( -- N )
  980.     String ( S$ -- )
  981.      
  982.     Converts a string to a number.
  983.                 
  984.                                 page 19
  985.  
  986.                 "
  987.     "
  988.     Data   ( -- )
  989.     String ( -- )
  990.      
  991.     Begins and ends a text string.
  992.     
  993.     
  994.                 +$
  995.     +$
  996.     Data   ( -- )
  997.     String ( A$ B$ -- C$ )
  998.      
  999.     Combines A$ and B$ into one
  1000.     string.
  1001.     
  1002.     
  1003.                 =$
  1004.     =$
  1005.     Data   ( -- C )
  1006.     String ( A$ B$ -- )
  1007.      
  1008.     C is TRUE if A$ equals B$, FALSE
  1009.     otherwise.
  1010.                 
  1011.                                 page 20
  1012.  
  1013.             Stack Instructions
  1014.     
  1015.                 DEPTH
  1016.     DEPTH
  1017.     Data   ( -- N )
  1018.     String ( -- )
  1019.      
  1020.     Places N on the data stack, where
  1021.     N is the depth of the data stack.
  1022.     
  1023.     
  1024.                 DEPTH$
  1025.     DEPTH$
  1026.     Data   ( -- N )
  1027.     String ( -- )
  1028.      
  1029.     Places N on the data stack, where
  1030.     N is the depth of the string stack.
  1031.     
  1032.     
  1033.                 DROP
  1034.     DROP
  1035.     Data   ( N -- )
  1036.     String ( -- )
  1037.      
  1038.     Removes the top value from the
  1039.     data stack.
  1040.     
  1041.     
  1042.                 DROP$
  1043.     DROP$
  1044.     Data   ( -- )
  1045.     String ( A$ -- )
  1046.      
  1047.     Removes the top value from the
  1048.     string stack.
  1049.     
  1050.     
  1051.                 DUP
  1052.     DUP
  1053.     Data   ( N -- N N )
  1054.     String ( -- )
  1055.      
  1056.     Duplicates the top value on the
  1057.     data stack.
  1058.     
  1059.     
  1060.                 DUP$
  1061.     DUP$
  1062.     Data   ( -- )
  1063.     String ( A$ -- A$ A$ )
  1064.      
  1065.     Duplicates the top value on the
  1066.     string stack.
  1067.                 
  1068.                                 page 21
  1069.  
  1070.                 OVER
  1071.     OVER
  1072.     Data   ( a b -- a b a )
  1073.     String ( -- )
  1074.      
  1075.     Copies the second item on the data
  1076.     stack to the top.
  1077.     
  1078.     
  1079.                 OVER$
  1080.     OVER$
  1081.     Data   ( -- )
  1082.     String ( a$ b$ -- a$ b$ a $ )
  1083.      
  1084.     Copies the second item on the data
  1085.     stack to the top.
  1086.     
  1087.     
  1088.                 PICK
  1089.     PICK
  1090.     Data   ( n -- m )
  1091.     String ( -- )
  1092.      
  1093.     Places a copy of the nth item on
  1094.     the top of the data stack.
  1095.     
  1096.     
  1097.                 PICK$
  1098.     PICK$
  1099.     Data   ( n --  )
  1100.     String ( -- m$ )
  1101.      
  1102.     Places a copy of the nth item on
  1103.     the top of the string stack.
  1104.     
  1105.     
  1106.                 POP
  1107.     POP
  1108.     Data   ( -- n )
  1109.     String ( -- )
  1110.      
  1111.     Pops a value off the return stack.
  1112.     
  1113.     
  1114.                 PUSH
  1115.     PUSH
  1116.     Data   ( n -- )
  1117.     String ( -- )
  1118.      
  1119.     Pushes a value to the return stack.
  1120.                 
  1121.                                 page 22
  1122.  
  1123.                 ROT
  1124.     ROT
  1125.     Data   ( A B C -- B C A )
  1126.     String ( -- )
  1127.      
  1128.     Rotates the top three values on
  1129.     the data stack.
  1130.     
  1131.     
  1132.                 ROT$
  1133.     ROT$
  1134.     Data   ( -- )
  1135.     String ( a$ b$ c$ -- b$ c$ a$ )
  1136.      
  1137.     Rotates the top three values on
  1138.     the string stack.
  1139.     
  1140.     
  1141.                 SWAP
  1142.     SWAP
  1143.     Data   ( A B -- B A )
  1144.     String ( -- )
  1145.      
  1146.     Swaps the top two values on the
  1147.     data stack.
  1148.     
  1149.     
  1150.                 SWAP$
  1151.     SWAP$
  1152.     Data   ( -- )
  1153.     String ( A$ B$ -- B$ A$ )
  1154.      
  1155.     Swaps the top two values on the
  1156.     string stack.
  1157.                 
  1158.                                 page 23
  1159.  
  1160.             I/O Instructions
  1161.     
  1162.                 BEEP
  1163.     BEEP
  1164.     Data   ( -- )
  1165.     String ( -- )
  1166.      
  1167.     Produces a short beep.
  1168.     
  1169.     
  1170.                 CLOSE
  1171.     CLOSE
  1172.     Data   ( N -- )
  1173.     String ( -- )
  1174.      
  1175.     Closes file N. N should be either
  1176.     a 1 or a 2.
  1177.     
  1178.     
  1179.                 CLS
  1180.     CLS
  1181.     Data   ( -- )
  1182.     String ( -- )
  1183.      
  1184.     Clears the screen and places the
  1185.     cursor in the upper left corner.
  1186.     
  1187.     
  1188.                 COLOR
  1189.     COLOR
  1190.     Data   ( Foreground Background -- )
  1191.     String ( -- )
  1192.      
  1193.     Sets the foreground and background
  1194.     colors of the screen for
  1195.     subsequent prints. Colors are as
  1196.     follows: 0 Black, 1 Blue, 2 Green,
  1197.     3 Cyan, 4 Red, 5 Magenta, 6 Brown,
  1198.     7 Gray, 8 Dark Gray, 9 Lt. Blue,
  1199.     10 Lt. Green, 11 Lt. Cyan,
  1200.     12 Lt. Red, 13 Lt. Magenta,
  1201.     14 Yellow, 15 White.
  1202.     Notes -- 
  1203.     1) Background colors 8 to 15
  1204.     result in blinking text.
  1205.     2) The COLOR command has no effect
  1206.     on the Atari Portfolio.
  1207.     
  1208.     
  1209.                 COLOR?
  1210.     COLOR?
  1211.     Data   ( -- flag )
  1212.     String ( -- )
  1213.      
  1214.     Returns TRUE if a color card is
  1215.     detected, FALSE if a monochrome
  1216.     card is detected
  1217.                 
  1218.                                 page 24
  1219.  
  1220.                 COLUMN
  1221.     COLUMN
  1222.     Data   ( -- col )
  1223.     String ( -- )
  1224.      
  1225.     Places the column of the current
  1226.     cursor position on the data stack.
  1227.     
  1228.     
  1229.                 CONSOLE
  1230.     CONSOLE
  1231.     Data   ( -- 0 )
  1232.     String ( -- )
  1233.      
  1234.     Places the constant 0 on the data
  1235.     stack. The CONSOLE instruction is
  1236.     used for clarity. For example, the
  1237.     sequence CONSOLE ISINPUT is much
  1238.     clearer than 0 ISINPUT.
  1239.     
  1240.     
  1241.                 CR
  1242.     CR
  1243.     Data   ( -- )
  1244.     String ( -- )
  1245.      
  1246.     Sends a carriage return to the
  1247.     current output device.
  1248.     
  1249.     
  1250.                 CURRENT
  1251.     CURRENT
  1252.     Data   ( -- -2 )
  1253.     String ( -- )
  1254.      
  1255.     Places the constant -2 on the data
  1256.     stack. CURRENT is used for
  1257.     clarity. For example,
  1258.     1 CURRENT FILEPOS is much clearer
  1259.     than 1 -2 FILEPOS.
  1260.     
  1261.     
  1262.                 CURSOR
  1263.     CURSOR
  1264.     Data   ( N -- )
  1265.     String ( -- )
  1266.      
  1267.     If N is zero, the cursor will be
  1268.     made invisible. If N is non-zero,
  1269.     the cursor will be made visible.
  1270.     WARNING! Don't execute a 1 CURSOR
  1271.     unless you have already executed
  1272.     at least one 0 CURSOR.
  1273.                 
  1274.                                 page 25
  1275.  
  1276.                 DEFSEG
  1277.     DEFSEG
  1278.     Data   ( N -- )
  1279.     String ( -- )
  1280.      
  1281.     DEFSEG is used to define the data
  1282.     segment used in subsequent PEEK
  1283.     and POKE instructions. If N is -1,
  1284.     the data segment will be set back
  1285.     to TIPI's default data segment
  1286.     address.
  1287.     
  1288.     
  1289.                 EOF
  1290.     EOF
  1291.     Data   ( -- -1 )
  1292.     String ( -- )
  1293.      
  1294.     Places the constant -1 on the data
  1295.     stack. EOF is used for clarity.
  1296.     For example, 1 EOF FILEPOS is much
  1297.     clearer than 1 -1 FILEPOS.
  1298.     
  1299.     
  1300.                 EXTENDED
  1301.     EXTENDED
  1302.     Data   ( -- n )
  1303.     String ( -- )
  1304.      
  1305.     Returns the contents of the system
  1306.     variable EXTENDED. This is used in
  1307.     conjuction with INKEY$. Extended
  1308.     will be 0 if a "normal" key is
  1309.     pressed, 1 if an "extended" key is
  1310.     pressed.
  1311.     
  1312.     
  1313.                 FILEPOS
  1314.     FILEPOS
  1315.     Data   ( filenum action -- loc )
  1316.     String ( -- )
  1317.      
  1318.     FILEPOS is used to position and
  1319.     read the value of a file pointer.
  1320.     The filenum is a previously opened
  1321.     file number (1 or 2) and the
  1322.     action is either EOF, CURRENT or a
  1323.     specific location. The number loc
  1324.     returned on the data stack is the
  1325.     location in the file where the
  1326.     next action will occur. EOF moves
  1327.     the pointer to the end of the
  1328.     file, CURRENT keeps it at its
  1329.     current position and any other
  1330.     number moves the pointer to that
  1331.     location in the file.
  1332.                 
  1333.                                 page 26
  1334.  
  1335.                 GETBYTE
  1336.     GETBYTE
  1337.     Data   ( filenum -- byte )
  1338.     String ( -- )
  1339.      
  1340.     Gets a single byte from a file
  1341.     whose filenumber is filenum. The
  1342.     file must have been previously
  1343.     opened and filenum must be either
  1344.     1 or 2.
  1345.     
  1346.     
  1347.                 GETNUM
  1348.     GETNUM
  1349.     Data   ( -- n )
  1350.     String ( -- )
  1351.      
  1352.     Gets a number from the current
  1353.     input device.
  1354.     
  1355.     
  1356.                 GET$
  1357.     GET$
  1358.     Data   ( -- )
  1359.     String ( -- string$ )
  1360.      
  1361.     Gets a string from the current
  1362.     input device.
  1363.     
  1364.     
  1365.                 INKEY$
  1366.     INKEY$
  1367.     Data   ( -- )
  1368.     String ( -- k$ )
  1369.      
  1370.     Scans the keyboard and returns a
  1371.     one character string. If no key is
  1372.     pressed, k$ is null (""),
  1373.     otherwise k$ is the character
  1374.     whose key was pressed. If an
  1375.     extended key was pressed, the
  1376.     system variable EXTENDED is set to
  1377.     TRUE.
  1378.     
  1379.     
  1380.                 ISINPUT
  1381.     ISINPUT
  1382.     Data   ( n -- )
  1383.     String ( -- )
  1384.      
  1385.     Sets the current input device to
  1386.     n, where n is either file number 1
  1387.     or 2 or the CONSOLE. The CONSOLE
  1388.     is device 0.
  1389.                 
  1390.                                 page 27
  1391.  
  1392.                 ISOUTPUT
  1393.     ISOUTPUT
  1394.     Data   ( n -- )
  1395.     String ( -- )
  1396.      
  1397.     Sets the current output device to
  1398.     n, where n is either file number 1
  1399.     or 2, the PRINTER or the CONSOLE.
  1400.     The CONSOLE is device 0 and the
  1401.     PRINTER is device 3.
  1402.     
  1403.     
  1404.                 KEY
  1405.     KEY
  1406.     Data   ( -- k )
  1407.     String (  --  )
  1408.      
  1409.     Scans the keyboard and returns a
  1410.     keycode. If no key is pressed, k
  1411.     is 0.
  1412.     
  1413.     
  1414.                 LF
  1415.     LF
  1416.     Data   ( -- )
  1417.     String ( -- )
  1418.      
  1419.     Sends a line feed to the current
  1420.     output device.
  1421.     
  1422.     
  1423.                 LOCATE
  1424.     LOCATE
  1425.     Data   ( row col -- )
  1426.     String ( -- )
  1427.      
  1428.     Places the cursor at row, col.
  1429.     
  1430.     
  1431.                 MOUSE
  1432.     MOUSE
  1433.     Data   ( AX BX CX DX -- AX BX CX DX )
  1434.     String ( -- )
  1435.      
  1436.     Calls the low-level mouse interupt.
  1437.     See MOUSE.TPI for examples.
  1438.     Note: This instruction has no effect
  1439.     on the Atari Portfolio.
  1440.                 
  1441.                                 page 28
  1442.  
  1443.                 OPEN
  1444.     OPEN
  1445.     Data   ( N -- )
  1446.     String ( T$ F$ -- )
  1447.      
  1448.     Opens a file. N is the file number
  1449.     and N may be either a 1 or a 2. T$
  1450.     is the type of open and T$ may be
  1451.     either "I", "O", "A" or "R" which
  1452.     stand for Input, Output, Append or
  1453.     Random respectively. F$ is the name
  1454.     of the file to open.
  1455.     
  1456.     
  1457.                 PEEK
  1458.     PEEK
  1459.     Data   ( Addr -- Byte )
  1460.     String ( -- )
  1461.      
  1462.     Places the contents of Addr on the
  1463.     stack. Addr is an address in the
  1464.     current segment. To change the
  1465.     current segment, use DEFSEG.
  1466.     
  1467.     
  1468.                 POKE
  1469.     POKE
  1470.     Data   ( Addr Byte -- )
  1471.     String ( -- )
  1472.      
  1473.     Pokes Byte into Addr. Addr is an
  1474.     address in the current segment. To
  1475.     change the current segment, use
  1476.     DEFSEG.
  1477.     
  1478.     
  1479.                 PRINT
  1480.     PRINT
  1481.     Data   ( n -- )
  1482.     String ( -- )
  1483.      
  1484.     Prints the number n on the current
  1485.     output device.
  1486.     
  1487.     
  1488.                 PRINTCHR
  1489.     PRINTCHR
  1490.     Data   ( c -- )
  1491.     String ( -- )
  1492.      
  1493.     Prints the character whose ASCII
  1494.     code is c on the current output
  1495.     device.
  1496.                 
  1497.                                 page 29
  1498.  
  1499.                 PRINTER
  1500.     PRINTER
  1501.     Data   ( -- 3 )
  1502.     String ( -- )
  1503.      
  1504.     Places the constant 3 on the data
  1505.     stack. The PRINTER instruction is
  1506.     used for clarity. For example, the
  1507.     sequence PRINTER ISOUTPUT is much
  1508.     clearer than 3 ISOUTPUT.
  1509.     
  1510.     
  1511.                 PRINT$
  1512.     PRINT$
  1513.     Data   ( -- )
  1514.     String ( a$ -- )
  1515.      
  1516.     Prints the string a$ on the
  1517.     current output device.
  1518.     
  1519.     
  1520.                 PUTBYTE
  1521.     PUTBYTE
  1522.     Data   ( B F -- )
  1523.     String ( -- )
  1524.      
  1525.     Outputs byte B to file F.
  1526.     
  1527.     
  1528.                 ROW
  1529.     ROW
  1530.     Data   ( -- row )
  1531.     String ( -- )
  1532.      
  1533.     Places the row of the current
  1534.     cursor position on the data stack.
  1535.     
  1536.     
  1537.                 SOUND
  1538.     SOUND
  1539.     Data   ( freq dur -- )
  1540.     String ( -- )
  1541.      
  1542.     Plays a sound of a given freq and
  1543.     dur. 0 is the highest freq and 
  1544.     32767 is the lowest.
  1545.     
  1546.     
  1547.                 VARPTR
  1548.     VARPTR
  1549.     Data   ( V -- A )
  1550.     String ( -- )
  1551.      
  1552.     Places the address of a variable
  1553.     onto the data stack. This may be
  1554.     used to PEEK and POKE values
  1555.     directly into a variable.
  1556.                 
  1557.                                 page 30
  1558.  
  1559.             DOS Instructions
  1560.     
  1561.                 CALL
  1562.     CALL
  1563.     Data   ( -- )
  1564.     String ( program$ param$ -- )
  1565.     Return ( -- )
  1566.     Calls a DOS program (program$) with
  1567.     parameters given in param$. Sets
  1568.     ERROR to 255 if the call is
  1569.     unsuccessful. Otherwise ERROR is
  1570.     set to zero unless the called DOS
  1571.     program returns it's own error
  1572.     code.
  1573.     
  1574.     
  1575.                 CHDIR
  1576.     CHDIR
  1577.     Data   ( -- )
  1578.     String ( dir$ -- )
  1579.      
  1580.     Changes the current DOS directory
  1581.     to the one specified by the top
  1582.     string on the string stack.
  1583.     
  1584.     
  1585.                 COMMAND$
  1586.     COMMAND$
  1587.     Data   ( -- )
  1588.     String ( -- Command$ )
  1589.      
  1590.     Places a string on the string
  1591.     stack consisting of what followed
  1592.     the word TIPI on the DOS command
  1593.     line when TIPI was invoked.
  1594.     
  1595.     
  1596.                 FIRSTFILE
  1597.     FIRSTFILE
  1598.     Data   ( -- )
  1599.     String ( filespec -- fname$ )
  1600.      
  1601.     Finds the first file that matches
  1602.     filespec. Filespec follows the
  1603.     standard DOS wildcard rules (ie
  1604.     the filespec can contain "*" or
  1605.     "?" characters).
  1606.                 
  1607.                                 page 31
  1608.  
  1609.                 GETDIR
  1610.     GETDIR
  1611.     Data   ( num -- )
  1612.     String ( -- dir$ )
  1613.      
  1614.     GETDIR is used to get the current
  1615.     directory. If num = 0 then GETDIR
  1616.     returns the directory of the
  1617.     current drive. If num is 1 GETDIR
  1618.     uses the A drive, 2 uses the B
  1619.     drive, etc. The directory returned
  1620.     does NOT contain the drive letter
  1621.     or the first "\". Thus, if the
  1622.     current directory is the root
  1623.     directory, 0 GETDIR will return
  1624.     a null string ("").
  1625.     
  1626.     
  1627.                 KILL
  1628.     KILL
  1629.     Data   ( -- )
  1630.     String ( filespec$ -- )
  1631.      
  1632.     Kills the specified file.
  1633.     
  1634.     
  1635.                 MAKEDIR
  1636.     MAKEDIR
  1637.     Data   ( -- )
  1638.     String ( dirspec$ -- )
  1639.      
  1640.     Makes the directory specified in
  1641.     dirspec$. If there is an error,
  1642.     the system variable ERROR will be
  1643.     set.
  1644.     
  1645.     
  1646.                 NEXTFILE
  1647.     NEXTFILE
  1648.     Data   ( -- )
  1649.     String ( -- file$ )
  1650.      
  1651.     Returns the next file that matches
  1652.     the filespec set by a previous
  1653.     FIRSTFILE command. If there are no
  1654.     more files matching the filespec,
  1655.     the null string ("") is returned.
  1656.                 
  1657.                                 page 32
  1658.  
  1659.                 REMDIR
  1660.     REMDIR
  1661.     Data   ( -- )
  1662.     String ( dir$ -- )
  1663.      
  1664.     Removes the directory dir$. The
  1665.     directory should be empty before
  1666.     you delete it. If REMDIR fails,
  1667.     the system variable ERROR will be
  1668.     set.
  1669.     
  1670.     
  1671.                 RENAME
  1672.     RENAME
  1673.     Data   ( -- )
  1674.     String ( oldname$ newname$ -- )
  1675.      
  1676.     Renames a file.
  1677.                 
  1678.                                 page 33
  1679.  
  1680.             Defining Instructions
  1681.     
  1682.                 DEFARRAY
  1683.     DEFARRAY
  1684.     Data   ( N -- )
  1685.     String ( -- )
  1686.      
  1687.     Creates an integer array of N 
  1688.     elements. The word after DEFARRAY
  1689.     is used as the name of the array.
  1690.     For example, 10 DEFARRAY BOB would
  1691.     create a 10 element array named
  1692.     BOB. When using STORE or FETCH
  1693.     with ARRAY variables, you must
  1694.     precede the ARRAY name with a
  1695.     number indicating the element to
  1696.     which you are refering. 
  1697.     For example, 3 BOB FETCH will
  1698.     fetch the contents of the third
  1699.     element of BOB, while 77 5 BOB
  1700.     STORE will store the number 77 in
  1701.     the fifth element of BOB. TIPI has
  1702.     enough array space for a total of
  1703.     up to 1000 array elements in a
  1704.     TIPI program. TIPI also has a
  1705.     limit of 100 distinct named
  1706.     variables per program.
  1707.     
  1708.     
  1709.                 DEFINE..ENDDEF
  1710.     DEFINE
  1711.     Data   ( -- )
  1712.     String ( -- )
  1713.      
  1714.     DEFINE is used to define new TIPI
  1715.     instructions. The word following
  1716.     DEFINE is the name of the new TIPI
  1717.     instruction. Following this will
  1718.     be a sequence of TIPI instructions
  1719.     followed by the word ENDDEF. Once
  1720.     a new TIPI instruction has been
  1721.     defined, it may be used just like
  1722.     any of the built-in TIPI
  1723.     instuctions. For example,
  1724.     DEFINE SQUARED DUP * ENDDEF
  1725.     DEFINE CUBED DUP SQUARED * ENDDEF
  1726.     will create two new TIPI 
  1727.     instructions, SQUARED and CUBED
  1728.     which will respectively square and
  1729.     cube a value on the stack. Up to
  1730.     100 new TIPI instuctions may be
  1731.     defined in a TIPI program.
  1732.     
  1733.     ENDDEF
  1734.     Data   ( -- )
  1735.     String ( -- )
  1736.      
  1737.     Ends an instruction definition.
  1738.                 
  1739.                                 page 34
  1740.  
  1741.                 DEFTABLE..ENDTABLE
  1742.     DEFTABLE
  1743.     Data   ( -- )
  1744.     String ( -- )
  1745.      
  1746.     Creates a new data table. The word
  1747.     after DEFTABLE is used as the
  1748.     name of the table. For example,
  1749.     DEFTABLE FRED will create a new
  1750.     table called FRED. Following the
  1751.     name will be a series of numbers or
  1752.     TIPI instructions followed by the
  1753.     instruction ENDTABLE. After a table
  1754.     has been defined, any instruction in
  1755.     the table may be executed by
  1756.     preceding the table name with the
  1757.     number of the instruction to
  1758.     execute. For example, 4 FRED would
  1759.     execute the fourth instruction in
  1760.     FRED.
  1761.     
  1762.     ENDTABLE
  1763.     Data   ( -- )
  1764.     String ( -- )
  1765.      
  1766.     Ends a table structure.
  1767.     
  1768.     
  1769.                 DEFSTR
  1770.     DEFSTR
  1771.     Data   ( -- )
  1772.     String ( -- )
  1773.      
  1774.     Creates a new string variable. The
  1775.     word after DEFSTR is used as the
  1776.     name of the string. For example,
  1777.     DEFSTR MARY will create a new
  1778.     string variable called MARY. STORE
  1779.     and FETCH are used to place values
  1780.     into variables and retrieve them
  1781.     respectively.
  1782.     
  1783.     
  1784.                 DEFVAR
  1785.     DEFVAR
  1786.     Data   ( -- )
  1787.     String ( -- )
  1788.      
  1789.     Creates a new numeric variable.
  1790.     The word after DEFVAR is used as
  1791.     the name of the variable. For
  1792.     example, DEFVAR HERB will create a
  1793.     new variable called HERB. STORE
  1794.     and FETCH are used to place values
  1795.     into variables and retrieve them
  1796.     respectively.
  1797.                 
  1798.                                 page 35
  1799.  
  1800.             Data Instructions
  1801.     
  1802.                 FETCH
  1803.     FETCH
  1804.     Data   ( v -- x )
  1805.               or
  1806.     String ( -- x$ )
  1807.      
  1808.     Returns the contents of variable
  1809.     v. The type of v (numeric or
  1810.     string) determines if the contents
  1811.     of the fetch is placed on the data
  1812.     or the string stack.
  1813.     
  1814.     
  1815.                 STORE
  1816.     STORE
  1817.     Data   ( n v -- )    ( v -- )
  1818.     String ( -- )     or ( s$ -- )
  1819.      
  1820.     Stores a value into a variable.
  1821.     The type of v (numeric or string)
  1822.     determines if the contents of the
  1823.     store is taken from the data or
  1824.     the string stack.
  1825.                 
  1826.                                 page 36
  1827.  
  1828.             Control Instructions
  1829.  
  1830.                 BEGIN..UNTIL
  1831.     BEGIN 
  1832.     Data   ( -- )
  1833.     String ( -- )
  1834.      
  1835.     Starts a BEGIN UNTIL loop.
  1836.     When TIPI encounters an UNTIL, it
  1837.     will branch back to the BEGIN
  1838.     if the value on the data stack is
  1839.     FALSE.
  1840.     
  1841.     UNTIL
  1842.     Data   ( N -- )
  1843.     String ( -- )
  1844.      
  1845.     Branches back to BEGIN if N is
  1846.     FALSE, otherwise continues.
  1847.     
  1848.     
  1849.                 DO..LOOP
  1850.     DO
  1851.     Data   ( N -- )
  1852.     String ( -- )
  1853.      
  1854.     Begins a DO loop. Processing 
  1855.     continues until a LOOP instruction is 
  1856.     encountered. The loop will be 
  1857.     executed N times.
  1858.     
  1859.     LOOP
  1860.     Data   ( -- )
  1861.     String ( -- )
  1862.      
  1863.     Closes a DO LOOP construct. 
  1864.     Decrements INDEX and loops back to
  1865.     the DO if INDEX > 0, otherwise exits
  1866.     the loop.
  1867.     
  1868.     
  1869.                     INDEX
  1870.     INDEX
  1871.     Data   ( -- INDEX )
  1872.     String ( -- )
  1873.      
  1874.     Copies the current DO LOOP index
  1875.     value to the data stack.
  1876.     
  1877.     
  1878.                     LEAVE
  1879.     LEAVE
  1880.     Data   ( -- )
  1881.     String ( -- )
  1882.      
  1883.     Sets the current INDEX value to
  1884.     one, thus ensuring the current DO
  1885.     LOOP will be ended on this
  1886.     itteration.
  1887.                 
  1888.                                 page 37
  1889.  
  1890.             CASE..OF..ENDOF..DEFAULT..ENDCASE
  1891.     CASE
  1892.     Data   ( -- )
  1893.     String ( -- )
  1894.      
  1895.     Begins a CASE structure.
  1896.     
  1897.     OF
  1898.     Data   ( m n -- )
  1899.     String ( -- )
  1900.      
  1901.     Must be used within a CASE
  1902.     structure. If m is equal to
  1903.     n, the instructions
  1904.     following the OF will be
  1905.     executed until an ENDOF is
  1906.     encountered.
  1907.     
  1908.     ENDOF
  1909.     Data   ( -- )
  1910.     String ( -- )
  1911.      
  1912.     Ends an OF clause in a CASE
  1913.     structure.
  1914.     
  1915.     DEFAULT
  1916.     Data   ( n -- )
  1917.     String ( -- )
  1918.      
  1919.     Used within a CASE structure to
  1920.     cover any cases not dealt with
  1921.     by previous OF clauses.
  1922.     
  1923.     ENDCASE
  1924.     Data   ( -- )
  1925.     String ( -- )
  1926.      
  1927.     Ends a CASE structure.
  1928.                 
  1929.                                 page 38
  1930.  
  1931.             CASE$..OF$..ENDOF$..DEFAULT$..ENDCASE$
  1932.     CASE$
  1933.     Data   ( -- )
  1934.     String ( -- )
  1935.      
  1936.     Begins a CASE$ structure.
  1937.     
  1938.     OF$
  1939.     Data   ( -- )
  1940.     String ( a$ b$ -- )
  1941.      
  1942.     Must be used within a CASE$
  1943.     structure. If a$ is equal to
  1944.     b$, the instructions
  1945.     following the OF$ will be
  1946.     executed until an ENDOF$ is
  1947.     encountered.
  1948.     
  1949.     ENDOF$
  1950.     Data   ( -- )
  1951.     String ( -- )
  1952.      
  1953.     Ends an OF$ clause in a CASE$
  1954.     structure.
  1955.     
  1956.     DEFAULT$
  1957.     Data   ( -- )
  1958.     String ( a$ -- )
  1959.      
  1960.     Used within a CASE$ structure to
  1961.     cover any cases not dealt with
  1962.     by previous OF$ clauses.
  1963.     
  1964.     ENDCASE$
  1965.     Data   ( -- )
  1966.     String ( -- )
  1967.      
  1968.     Ends a CASE$ structure.
  1969.                 
  1970.                                 page 39
  1971.  
  1972.                 IF..ELSE..ENDIF
  1973.     IF
  1974.     Data   ( n -- )
  1975.     String ( -- )
  1976.      
  1977.     If n is non-zero, statements up to
  1978.     the next ELSE or ENDIF will be
  1979.     executed. If N is zero, statements
  1980.     up to the next ELSE or ENDIF will
  1981.     be skipped.
  1982.     
  1983.     ELSE
  1984.     Data   ( -- )
  1985.     String ( -- )
  1986.      
  1987.     Used within IF ELSE ENDIF
  1988.     constructs.
  1989.     
  1990.     ENDIF
  1991.     Data   ( -- )
  1992.     String ( -- )
  1993.      
  1994.     Ends an IF ELSE ENDIF construct.
  1995.     
  1996.     
  1997.                 WHILE..WEND
  1998.     WHILE
  1999.     Data   ( N -- )
  2000.     String (  --  )
  2001.      
  2002.     If N is not equal to zero,
  2003.     instructions between the WHILE
  2004.     and WEND will be executed. WEND
  2005.     will branch back to the WHILE.
  2006.     If N is equal to zero, the
  2007.     instructions between the WHILE
  2008.     and the WEND will will be skipped.
  2009.     
  2010.     WEND
  2011.     Data   ( -- )
  2012.     String ( -- )
  2013.      
  2014.     WEND branches back to a previous
  2015.     WHILE.
  2016.                 
  2017.                                 page 40
  2018.  
  2019.             Debugging Instructions
  2020.     
  2021.                 TRACEON
  2022.     TRACEON
  2023.     Data   ( -- )
  2024.     String ( -- )
  2025.      
  2026.     Turns word tracing on. When
  2027.     instruction tracing is on, TIPI
  2028.     displays an informational window
  2029.     showing the stacks and the
  2030.     instructions being executed.
  2031.     
  2032.     
  2033.                 TRACEOFF
  2034.     TRACEOFF
  2035.     Data   ( -- )
  2036.     String ( -- )
  2037.      
  2038.     Turns instruction tracing off
  2039.     
  2040.     
  2041.                 TRACEVAR
  2042.     TRACEVAR
  2043.     Data   ( var -- )
  2044.     String ( -- )
  2045.      
  2046.     Adds a var to the trace window.
  2047.     
  2048.     
  2049.                 TRACEROW
  2050.     TRACEROW
  2051.     Data   ( row -- )
  2052.     String ( -- )
  2053.      
  2054.     Sets the row that the trace
  2055.     window will be shown on.
  2056.     
  2057.     
  2058.                 TRACECOL
  2059.     TRACECOL
  2060.     Data   ( col -- )
  2061.     String ( -- )
  2062.      
  2063.     Sets the column that the trace
  2064.     window will be shown on.
  2065.                 
  2066.                                 page 41
  2067.  
  2068.             Miscellaneous Instructions
  2069.     
  2070.                 BYE
  2071.     BYE
  2072.     Data   ( n -- )
  2073.     String ( -- )
  2074.      
  2075.     Exits a TIPI program and returns
  2076.     to DOS. BYE returns the top value
  2077.     from the data stack as an error
  2078.     level to DOS.
  2079.     
  2080.     
  2081.                 ERROR
  2082.     ERROR
  2083.     Data   ( -- n )
  2084.     String ( -- )
  2085.      
  2086.     Places the number of the current
  2087.     error on the data stack.
  2088.     
  2089.     
  2090.                 EVAL
  2091.     EVAL
  2092.     Data   ( -- ? )
  2093.     String ( I$ -- ? )
  2094.      
  2095.     Evaluates the instruction I$ from
  2096.     the string stack.
  2097.     
  2098.     
  2099.                 FALSE
  2100.     FALSE
  2101.     Data   ( -- 0 )
  2102.     String ( -- )
  2103.      
  2104.     Places the value of FALSE (0) on
  2105.     the top of the data stack.
  2106.     
  2107.     
  2108.                 NOT
  2109.     NOT
  2110.     Data   ( n -- m )
  2111.     String ( -- )
  2112.      
  2113.     Negates the truth value of a flag.
  2114.     If n is non-zero, m is zero. If n
  2115.     is zero, m is one.
  2116.     
  2117.     
  2118.                 OFF
  2119.     OFF
  2120.     Data   ( -- )
  2121.     String ( -- )
  2122.      
  2123.     Shuts off an Atari Portfolio. OFF
  2124.     has no effect on a PC.
  2125.                 
  2126.                                 page 42
  2127.  
  2128.                 PORT?
  2129.     PORT?
  2130.     Data   ( -- flag )
  2131.     String ( -- )
  2132.      
  2133.     Returns TRUE if TIPI is running on
  2134.     an Atari Portfolio, FALSE
  2135.     otherwise.
  2136.     
  2137.     
  2138.                 RANDOM
  2139.     RANDOM
  2140.     Data   ( N -- R )
  2141.     String ( -- )
  2142.      
  2143.     Replaces N on the data stack with
  2144.     R, a random integer selected from
  2145.     the range 1 to N (inclusive).
  2146.     
  2147.     
  2148.                 RANDOMIZE
  2149.     RANDOMIZE
  2150.     Data   ( -- )
  2151.     String ( -- )
  2152.      
  2153.     Initializes the random number
  2154.     generator.
  2155.     
  2156.     
  2157.                 TICKS
  2158.     TICKS
  2159.     Data   ( -- t )
  2160.     String ( -- )
  2161.      
  2162.     Places the current PC tick count
  2163.     on the data stack. A PC ticks
  2164.     18.2 times per second, while a
  2165.     Portfolio ticks either once
  2166.     every 128 seconds or once every
  2167.     second.
  2168.     
  2169.     
  2170.                 TRUE
  2171.     TRUE
  2172.     Data   ( -- 1 )
  2173.     String ( -- )
  2174.      
  2175.     Places the constant 1 on the top
  2176.     of the data stack.
  2177.                 
  2178.                                 page 43
  2179.  
  2180.                 VERSION
  2181.     VERSION
  2182.     Data   ( -- N )
  2183.     String ( -- )
  2184.      
  2185.     VERSION leaves an integer N on
  2186.     the data stack. N is equal to the
  2187.     version number times ten (ie if N
  2188.     is 23 then the TIPI version number
  2189.     is 2.3).
  2190.     
  2191.     
  2192.                 #
  2193.     #
  2194.     Data   ( -- )
  2195.     String ( -- )
  2196.      
  2197.     Identifies a comment. Anything
  2198.     after the # on a line is ignored.
  2199.     
  2200.     
  2201.                 (
  2202.     (
  2203.     Data   ( -- )
  2204.     String ( -- )
  2205.      
  2206.     Begins a comment.
  2207.     
  2208.     
  2209.                 )
  2210.     )
  2211.     Data   ( -- )
  2212.     String ( -- )
  2213.      
  2214.     Ends a comment.
  2215.  
  2216.