home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / basic / tsrbas20.zip / TSRBASIC.DOC < prev    next >
Text File  |  1991-04-03  |  76KB  |  2,245 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.           TsrBasic, a Terminate and Stay Resident BASIC Interpreter
  7.           Version 2.0, Copyright 1990-1991 Anthony F. Stuart
  8.  
  9.  
  10.           1.   Introduction
  11.  
  12.           TsrBasic lets you write Terminate and Stay Resident (TSR)
  13.           programs in BASIC. It supports:
  14.  
  15.                1) Pop up applications that are recalled with a
  16.                user defined hotkey sequence.
  17.  
  18.                2) Background tasks that are recalled after a
  19.                specified period of time has elapsed.
  20.  
  21.                3) Screen savers that are recalled after a specified
  22.                period of keyboard inactivity.
  23.  
  24.           The entire interpreter can be recalled as well, giving you a
  25.           powerful programmable calculator at your fingertips.
  26.  
  27.           TsrBasic simplifies BASIC programming by relaxing data type
  28.           checking restrictions. This means you do not have to use special
  29.           suffixes like $ and # to specify the type of data a variable will
  30.           hold. Any variable can hold any type of data, either textual or
  31.           numeric. Conversions are performed when necessary.
  32.  
  33.           Structured programming is a snap with TsrBasic's IF/THEN/ELSE/
  34.           END IF statement, which supports multiline THEN and ELSE clauses
  35.           and nested IF's. The conventional form of the IF/THEN/ELSE
  36.           statement is supported as well.
  37.  
  38.           TsrBasic's powerful screen handling functions let you select
  39.           video attributes, define text windows for input and output, and
  40.           save and restore portions of the screen. TsrBasic supports direct
  41.           video access for speed or ROM-BIOS/DOS mode for compatibility
  42.           with nonstandard video adapters.
  43.  
  44.           TsrBasic lets you execute the contents of a character string so
  45.           that you can evaluate arithmetic expressions on the fly. You can
  46.           also use this feature to construct powerful user defined
  47.           functions.
  48.  
  49.           TsrBasic compiles your program into intermediate code and
  50.           interprets the intermediate code. This results in fast and
  51.           efficient program execution. You can display the intermediate
  52.           code if you wish. TsrBasic also lets you convert your BASIC
  53.           program into an executable (.exe) file that can be invoked from
  54.           DOS.
  55.  
  56.           Version 2.0 of TsrBasic features even better video support,
  57.           including graphics, as well as many new and improved functions
  58.  
  59.  
  60.           TsrBasic Reference Manual                                  Page 1
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.           and statements. If you are familiar with TsrBasic, version 1.0,
  72.           see the file named changes.doc on the distribution disk for more
  73.           information on the new features and bug fixes for version 2.0.
  74.  
  75.  
  76.           2.   About this Document...
  77.  
  78.           The remainder of this document provides you with the information
  79.           you need to know to take advantage of the special features of
  80.           TsrBasic. It is intended for people who have some experience with
  81.           the BASIC programming language. If you do not have any experience
  82.           with BASIC, you may wish to consult a more detailed book on
  83.           programming in BASIC before reading this document.
  84.  
  85.  
  86.           3.   Variables and Arrays
  87.  
  88.           TsrBasic variables consist of a letter followed by zero or more
  89.           letters, digits, underscores, periods, dollar signs, number
  90.           signs, percent signs or exclamation marks. Variable names are
  91.           case sensitive, e.g. LastName and lastname are two separate
  92.           variables.
  93.  
  94.           Arrays must be declared using the DIM statement before they are
  95.           referenced. Arrays may have an arbitrary number of dimensions.
  96.           The extent of each dimension is from zero to the value(s)
  97.           specified in the DIM statement.
  98.  
  99.           The TsrBasic SORT and SHIFT statements make working with arrays
  100.           easier and more efficient. The SORT statement sorts a one
  101.           dimensional array into ascending or descending order. The SHIFT
  102.           statement shifts the elements of an array up or down one or more
  103.           positions.
  104.  
  105.           Arrays and variables must be initialized before they are used,
  106.           i.e. a value must be stored in the variable or array element
  107.           before it is read. Failure to do so will generate an
  108.           uninitialized variable error message. Note that PARSE,
  109.           SCREENSAVE, SCREENRESTORE and SUSPEND do not support storing into
  110.           an array.
  111.  
  112.  
  113.           4.   Constants
  114.  
  115.           Numeric constants may be written using any of the following
  116.           formats:
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.           Page 2                                  TsrBasic Reference Manual
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.                Format         Example
  139.                ------         -------
  140.  
  141.                integer        42
  142.                decimal        3.14
  143.                exponential    314e-2
  144.                hexadecimal    0x1b
  145.                octal          033
  146.  
  147.           TsrBasic boolean logical operations use zero for false and
  148.           nonzero (usually 1) for true.
  149.  
  150.           String constants are written as sequences of characters enclosed
  151.           by double quotes. The closing double quote is required. A double
  152.           quote may be included in a character string by concatenating the
  153.           double quote character, chr(34), to it.
  154.  
  155.  
  156.           5.   Operators
  157.  
  158.           TsrBasic supports the standard set of BASIC operators, plus some
  159.           operators for doing bitwise operations on 16 bit quantities. The
  160.           following list of operators is organized from lowest precedence
  161.           to highest precedence. Operators of the same precedence are
  162.           evaluated from left to right.
  163.  
  164.                Operator       Precedence     Description
  165.  
  166.                and            1              logical and
  167.                or             1              logical or
  168.  
  169.                =              2              equal
  170.                <>             2              not equal
  171.                <              2              less than
  172.                <=             2              less than or equal
  173.                >              2              greater than
  174.                >=             2              greater than or equal
  175.  
  176.                -              3              subtract
  177.                +              3              add (or concatenate
  178.                                                   if strings)
  179.  
  180.                *              4              multiply
  181.                /              4              divide
  182.                mod            4              modulo
  183.                \              4              integer divide
  184.  
  185.                |              5              bitwise or     (16 bits)
  186.                &              5              bitwise and    (16 bits)
  187.                `              5              bitwise xor    (16 bits)
  188.  
  189.  
  190.  
  191.  
  192.           TsrBasic Reference Manual                                  Page 3
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.                ~              6              bitwise negate (16 bits)
  205.                -              6              arithmetic negate
  206.                not            6              logical negate
  207.  
  208.                ^              7              power
  209.  
  210.           The plus operator (+) performs addition if both operands are
  211.           numeric or concatenation if either operand is a string. This
  212.           means that you cannot use the plus operator to concatenate two
  213.           numbers. Use the CAT function for this purpose.
  214.  
  215.  
  216.           6.   Editor and Environment
  217.  
  218.           TsrBasic provides a simple interactive command mode that allows
  219.           you to enter and execute statements and commands. Program
  220.           statements are entered with line numbers, which must be in the
  221.           range 1-32767. Commands and immediate mode statements are entered
  222.           without line numbers. The backspace key can be used to delete the
  223.           last character entered. The escape key can be used to delete the
  224.           entire line.
  225.  
  226.           Note: Type control-c to terminate a runaway TsrBasic program.
  227.  
  228.           For more complex editing needs, the TsrBasic EDIT command can be
  229.           used to invoke an editor of your choice. The syntax of the EDIT
  230.           command is as follows:
  231.  
  232.                edit [line-number-spec]
  233.  
  234.           The EDIT command lets you use your favorite DOS editor to edit
  235.           the current program. Here's how it works:
  236.  
  237.           TsrBasic writes the current file, or the part specified by
  238.           line-number-spec to a temporary file. It then invokes the editor
  239.           specified by the EDITOR environment variable on the temporary
  240.           file. After you exit the editor, TsrBasic loads (if no
  241.           line-number-spec was used) or merges (if a line-number-spec was
  242.           used) the temporary file. See your DOS reference manual for more
  243.           information on environment variables.
  244.  
  245.           Because DOS is not reentrant, the EDIT command will not work when
  246.           you have recalled a suspended TsrBasic from the DOS shell. In
  247.           this case it will return a "DOS is busy" error. You can, however,
  248.           use the EDIT command when you have recalled TsrBasic from most
  249.           other applications, provided there is sufficient memory.
  250.  
  251.           Note that no default editor is supplied with TsrBasic.
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.           Page 4                                  TsrBasic Reference Manual
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.           7.   Suspend Statement
  271.  
  272.           The SUSPEND statement provides access to TsrBasic's terminate and
  273.           stay resident capabilities. Executing the SUSPEND statement will
  274.           cause TsrBasic to return to the environment from which it was
  275.           invoked. TsrBasic can be recalled by hotkey sequence, timer
  276.           expiration, or a period of keyboard inactivity, depending on
  277.           parameters specified in the SUSPEND statement. After recall,
  278.           TsrBasic executes the statement following the SUSPEND statement,
  279.           if one exists, or returns to command level.
  280.  
  281.           The syntax for SUSPEND is:
  282.  
  283.           suspend screen, key-code, key-flags, interval, inactivity, status
  284.  
  285.           All parameters are optional. Parameters to the right of the one
  286.           you wish to specify may be omitted. The parameters have the
  287.           following functions and defaults:
  288.  
  289.                screen - boolean, if true (1) save the contents of the
  290.                screen when the hotkey sequence is entered or the timer
  291.                interval expires so that the screen may be restored by
  292.                the next SUSPEND statement. The default is true.
  293.  
  294.                key-code - keyboard scan code that, when combined with
  295.                the key-flags parameter, will recall the interpreter.
  296.                This key-code should be selected from the list of
  297.                keyboard scan codes in Appendix D. The default is 0x30
  298.                (the b key).
  299.  
  300.                key-flags - keyboard flags for control, shift and alt
  301.                keys that, when combined with the key-code parameter,
  302.                will recall the interpreter. Possible values for the
  303.                keyboard flags are:
  304.  
  305.                     0x80 = insert on
  306.                     0x40 = caps lock on
  307.                     0x20 = num lock on
  308.                     0x10 = scroll lock on
  309.                     0x08 = alt key down
  310.                     0x04 = control key down
  311.                     0x02 = left shift down
  312.                     0x01 = right shift down
  313.  
  314.                These flags may be OR'd together, i.e. 0x02 | 0x04
  315.                represents shift+control, so that shift and control and
  316.                the key-code specified above must be held down 
  317.                simultaneously to recall the interpreter. The default 
  318.                is 0x06 (shift+control).
  319.  
  320.                interval - amount of time, in clock ticks, to wait 
  321.                before recalling the interpreter. This is used for 
  322.  
  323.  
  324.           TsrBasic Reference Manual                                  Page 5
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.                background tasks. Since there are approximately 18 
  336.                clock ticks per second, multiply the number of seconds
  337.                you want to wait by 18 to get the interval. A value of
  338.                0 disables the interval timer and the interpreter is 
  339.                recalled using the hotkey sequence (or keyboard timer,
  340.                if specified). The default is zero (disabled).
  341.  
  342.                inactivity - amount of time, in clock ticks, to wait
  343.                after last keystroke is entered before recalling the 
  344.                interpreter. This is used for screen savers. The 
  345.                default is zero (disabled).
  346.  
  347.                status - a variable which is used to hold an integer
  348.                value returned by SUSPEND. This variable is set to 0 
  349.                if the program was recalled by the hotkey sequence, 1 
  350.                if recalled by the interval timer and 2 if recalled by 
  351.                the keyboard inactivity timer.
  352.  
  353.           Note: the combined defaults for SUSPEND are:
  354.  
  355.                suspend 1, 0x30, 0x06, 0, 0
  356.  
  357.           So, if you enter SUSPEND without options, the interpreter will
  358.           suspend and you can return to it by entering ctrl-shift-b.
  359.  
  360.           Here is a simple terminate and stay resident program that
  361.           executes in the background to print the time in the upper right
  362.           hand corner of the screen every second. Note how the status
  363.           argument is used to distinguish between timer and hotkey events:
  364.  
  365.                100 print "Press ctrl-shift-b to terminate clock."
  366.                110 suspend 0, 0x30, 0x06, 18, 0, timer
  367.                120 if not timer then cls : end
  368.                130 display 0, 72, time()
  369.                140 goto 110
  370.  
  371.  
  372.           8.   Lookup Function
  373.  
  374.           Sometimes it is useful to be able to specify things like colors
  375.           by meaningful names, and other times it is useful to be able to
  376.           specify them by numbers. TsrBasic avoids this conflict by
  377.           providing a LOOKUP function to convert meaningful names to
  378.           numbers.
  379.  
  380.           The LOOKUP function can be used in instances where names are more
  381.           appropriate, such as:
  382.  
  383.                100 foreground lookup ("red")
  384.                110 background lookup ("black")
  385.                120 print "The time is "; time()
  386.  
  387.  
  388.  
  389.  
  390.           Page 6                                  TsrBasic Reference Manual
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.           and numbers can be used when they are more appropriate:
  402.  
  403.                100 for i = 1 to 15
  404.                110    foreground i
  405.                120    print "This is color "; i
  406.                130 next i
  407.  
  408.           The following table summarizes the names that LOOKUP can map to
  409.           numbers.
  410.  
  411.                black     0         hres2     6         fill      3
  412.                blue      1         text      7         or        0
  413.                green     2         herc      8         and       1
  414.                cyan      3         mres16    13        reset     2
  415.                red       4         hres16    14        set       3
  416.                magenta   5         eres2     15        xor       4
  417.                yellow    6         eres16    16        mda       1
  418.                white     7         vres2     17        cga       2
  419.                low       0         vres16    18        ega       4
  420.                high      8         mres256   19        vga       8
  421.                bw40      0         default   -1        mga       16
  422.                co40      1         direct    0         hgc       32
  423.                bw80      2         bios      1
  424.                co80      3         dos       2             
  425.                mres4     4         graphics  3
  426.                mres0     5         outline   2
  427.  
  428.           The LOOKUP function provides name to number mapping for the
  429.           following statements:
  430.  
  431.                background          config              mode
  432.                box                 foreground          put
  433.                circle              get                 type
  434.                color               intensity
  435.  
  436.           See the detailed description of the statement for more
  437.           information on the LOOKUP mappings that can be used.
  438.  
  439.  
  440.           9.   Text Windows
  441.  
  442.           The following TsrBasic statements and functions provide support
  443.           for TsrBasic text windows:
  444.                                  
  445.                background          foreground          savescreen
  446.                blank               getscreen           scroll
  447.                border              init                type
  448.                column              intensity           winbottom
  449.                csroff              locate              winleft
  450.                csron               page                winright
  451.                csrbottom           refresh             wintop
  452.                csrtop              restorescreen
  453.                display             row
  454.  
  455.  
  456.           TsrBasic Reference Manual                                  Page 7
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.           TsrBasic text windows are created using the WINBOTTOM, WINLEFT,
  470.           WINRIGHT and WINTOP statements to define the edges of the window.
  471.           Subsequent text input/output using the INPUT and PRINT statements
  472.           is directed to the window. The DISPLAY statement is used as an
  473.           alternative to PRINT to display text anywhere on the screen.
  474.  
  475.           The LOCATE statement positions the cursor relative to the top
  476.           left corner of the current window. Absolute cursor positioning is
  477.           accomplished using the COLUMN and ROW statements.
  478.  
  479.           The BORDER statement draws a border around the window.
  480.  
  481.           The FOREGROUND and BACKGROUND statements set the foreground and
  482.           background colors for text output. Colors are represented by
  483.           numbers in the range 0 to 7. The LOOKUP function can be used to
  484.           convert the following color names into color numbers:
  485.  
  486.                0 - black      4 - red
  487.                1 - blue       5 - magenta
  488.                2 - green      6 - yellow
  489.                3 - cyan       7 - white
  490.  
  491.           Note that the range of colors that can be displayed depends on
  492.           the video adapter in your PC.
  493.  
  494.           The INTENSITY statement selects the brightness of text
  495.           characters. Intensity is specified as either 0 or 1. The LOOKUP
  496.           function can be used to convert the following intensity names
  497.           into intensity numbers:
  498.  
  499.                0 - low
  500.                8 - high
  501.  
  502.           The contents of the current text window are saved into a TsrBasic
  503.           variable using the SAVESCREEN statement and restored using the
  504.           RESTORESCREEN statement.
  505.  
  506.           The CSRBOTTOM and CSRTOP statements set the size and shape of the
  507.           cursor. Each character position on the screen is composed of a
  508.           number of video scan lines. The number of scan lines depends on
  509.           the video adapter. The scan lines are numbered top down and range
  510.           from 0 to 6 for cga adapters and from 0 to 13 for other adapters.
  511.           If CSRTOP is set to 0 and CSRBOTTOM is set to the last scan line
  512.           in the cell (say 13 for an ega adapter) then the cursor will
  513.           occupy the whole cell. The CSROFF and CSRON statements can be
  514.           used to turn the cursor off (i.e. hide it) or back on.
  515.  
  516.           The TYPE statement selects the output mode for text. It is 
  517.           normally set to direct mode (0) for fast output. Other options
  518.           are 1 for BIOS access, 2 for BIOS/DOS access, and 3 for text in
  519.           graphics mode. The default is 0. Use 1 if you have any video
  520.  
  521.  
  522.           Page 8                                  TsrBasic Reference Manual
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.           problems with 0, use 2 if you want to redirect output using DOS
  534.           redirection capability. Use 3 for mixed text and graphics in
  535.           graphics modes (see MODE). The LOOKUP function can be used to map
  536.           the following type names to numbers:
  537.  
  538.                0 - direct
  539.                1 - bios
  540.                2 - dos
  541.                3 - graphics
  542.  
  543.  
  544.           10.  Graphics
  545.  
  546.           TsrBasic provides graphics support for CGA, EGA, VGA and Hercules
  547.           compatible video adapters. The following statements and functions
  548.           provide support for TsrBasic graphics:
  549.                                  
  550.                box            fill           mode
  551.                circle         get            moveto
  552.                clip           lineto         pixel
  553.                color          mapload        put
  554.                config         mapsave
  555.  
  556.           The MODE statement selects a graphics mode. The set of graphics
  557.           modes you may use is dependent on the type of video adapter that
  558.           is installed in your PC. The graphics mode is specified as an
  559.           integer number in the range -1 to 19. The LOOKUP function can be
  560.           used to convert a mode name into a mode number. The following
  561.           modes are supported:
  562.  
  563.           Name      Number    Res       Type      Colors       Adapter
  564.  
  565.           bw40      0         40x25     text      16    gray   cga,ega,vga
  566.           co40      1         40x25     text      16/8  color  cga,ega,vga
  567.           bw80      2         80x25     text      16    gray   cga,ega,vga
  568.           co80      3         80x25     text      16/8  color  cga,ega,vga
  569.           mres4     4         320x200   graph     4     color  cga,ega,vga
  570.           mres0     5         320x200   graph     4     gray   cga,ega,vga
  571.           hres2     6         640x200   graph     2     bw     cga,ega,vga
  572.           text      7         80x25     text      2     bw     mda,hgc
  573.           hgc       8         720x348   graph     2     bw     hgc
  574.           mres16    13        320x200   graph     16    color  ega,vga
  575.           hres16    14        640x200   graph     16    color  ega,vga
  576.           eres2     15        640x350   graph     2     bw     ega, vga
  577.           eres16    16        640x350   graph     16    color  ega, vga
  578.           vres2     17        640x480   graph     2     bw     vga
  579.           vres16    18        640x480   graph     16    color  vga
  580.           mres256   19        320x200   graph     256   color  vga
  581.  
  582.           In addition, the following mode is defined to let you exit
  583.           graphics mode and return to the default mode:
  584.  
  585.           default   -1        n/a       n/a       n/a   n/a    all
  586.  
  587.  
  588.           TsrBasic Reference Manual                                  Page 9
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.           You can determine the type of video adapter that is installed in
  601.           your PC, along with the x and y resolution, the number of colors,
  602.           and the current mode by using the CONFIG statement. The syntax
  603.           is:
  604.  
  605.             config xpix, ypix, colors, adapter, mode
  606.  
  607.           where xpix, ypix, colors, adapter and mode are variables. Xpix,
  608.           ypix and colors are the number of x pixels, y pixels and colors,
  609.           respectively, for the current mode. Adapter is the type of video
  610.           adapter and is one of the following:
  611.  
  612.                1    mda (monochrome display adapter)
  613.                2    cga (color graphics adapter)
  614.                4    ega (enhanced graphics adapter)
  615.                8    vga (video gate array)
  616.                16   mga (multicolor graphics array)
  617.                32   hgc (hercules graphics card)
  618.  
  619.           The graphics coordinate system is layed out like the text
  620.           coordinate system with the origin (0,0) at the top left corner of
  621.           the screen. The bottom right corner varies, depending on the
  622.           graphics mode. In mode 14, for example, the bottom right corner
  623.           is 639, 199.
  624.  
  625.           If you want to display text and graphics on the same screen you
  626.           must use the TYPE statement to select the text in graphics mode
  627.           (type 3). After you exit graphics mode set the text type back to
  628.           0 for improved performance.
  629.  
  630.           The foreground and background colors for TsrBasic graphics modes
  631.           are specified using the COLOR statement.  Graphics colors are
  632.           independent of text colors.  Colors are represented by numbers in
  633.           the range 0 to 15. The LOOKUP function can be used to convert a
  634.           color name into a color number as described in the section on
  635.           text windows.
  636.  
  637.           The BOX and CIRCLE statements draw boxes and circles using a
  638.           "bounding" rectangle which describes the top left and bottom
  639.           right corners of the image. These statements also take an
  640.           argument that controls whether the image is to be filled or not.
  641.           The LOOKUP function can be used to map these control names to
  642.           numbers. The following control names are supported by the lookup
  643.           function:
  644.  
  645.                2 - outline
  646.                3 - fill
  647.  
  648.           Graphics images can be transferred from the screen to memory
  649.           using the GET statement and from memory to the screen using the
  650.           PUT statement. They can also be transferred from memory to a file
  651.  
  652.  
  653.  
  654.           Page 10                                 TsrBasic Reference Manual
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.           in bitmap form using the MAPSAVE statement and transferred from a
  666.           file to memory using the MAPLOAD statement.
  667.  
  668.           The PUT statement uses a control parameter to describe the method
  669.           for adding the image to the screen. The lookup function can be
  670.           used to map the following control names to numbers:
  671.  
  672.                name      number    effect
  673.  
  674.                or        0         superimpose image
  675.                and       1         intersection of images
  676.                reset     2         negative of image
  677.                set       3         normal image
  678.                xor       4         invert image
  679.  
  680.           The xor control value can be used twice in succession to add and
  681.           remove objects without modifying the background. This is useful
  682.           for animation.
  683.  
  684.           TsrBasic conserves DOS memory by using a graphics dynamic link
  685.           library (DLL) for graphics operations. This library is loaded
  686.           automatically when necessary and is freed when you exit graphics
  687.           mode using the mode -1 (default) statement. The graphics library
  688.           requires about 40 kb of memory. If you do not have at least 40 kb
  689.           of free memory you will not be able to load the graphics library
  690.           or do graphics operations.
  691.  
  692.           The image transfer statements allocate memory for the bitmap
  693.           directly from DOS. Note that multi-color high resolution images
  694.           produce large bitmaps and require larges amounts of memory. A
  695.           320x200 16 color bitmap requires about 64 kb. A 640x486 16 color
  696.           bitmap takes up more memory than you are likely to have in your
  697.           PC and will therefore need to be transferred in pieces (to
  698.           separate files), using multiple GET/MAPSAVE statements.
  699.  
  700.           The memory for image bitmaps is automatically freed when you exit
  701.           graphics mode with the mode -1 (default) statement. It may also
  702.           be explicitly freed by using PUT 0,0,0,0 to save a zero length
  703.           bitmap.
  704.  
  705.           If you have a Hercules compatible video adapter you will need to
  706.           execute MSHERC.EXE from DOS prior to entering graphics mode. 
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.           TsrBasic Reference Manual                                 Page 11
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.           11.  String Handling
  733.  
  734.           TsrBasic supports the usual set of BASIC string handling
  735.           functions, as well as PARSE, STRINS and STROVR, which are
  736.           specific to TsrBasic. The following list summarizes the string
  737.           handling functions available with TsrBasic:
  738.  
  739.                asc            left           space
  740.                cat            len            strins
  741.                chr            mid            strovr
  742.                copy           parse
  743.                instr          right
  744.  
  745.  
  746.           11.1      Parse Function
  747.  
  748.           The PARSE function breaks a string into pieces called tokens. The
  749.           syntax of the PARSE function is as follows:
  750.  
  751.           parse (buffer,literals,connectors,discards,delimiters,specials)
  752.  
  753.                buffer         - string to parse
  754.                literals       - grouping characters to discard
  755.                connectors     - grouping characters to save   
  756.                discards       - leading characters to discard
  757.                delimiters     - delimiters to discard
  758.                specials       - delimiters to save
  759.  
  760.           The buffer parameter is a variable containing the string to be
  761.           parsed. The PARSE function splits a token off the front end of
  762.           the buffer and returns it as the function value. The resulting
  763.           string, less the first token, is returned via the buffer
  764.           parameter. The returned buffer will be equal to the null string
  765.           when all the tokens have been parsed from it. The buffer
  766.           parameter should not be an array reference.
  767.  
  768.           The parameters represented by literals, connectors, discards,
  769.           delimiters and specials control the way the parsing is performed.
  770.           Each parameter is a character string or variable containing one
  771.           or more characters.
  772.  
  773.           The default for literals is double and single quote. The default
  774.           for discards is space and tab. The default for delimiters is
  775.           comma. The default for all other parameters is the null string.
  776.           These defaults give PARSE a default behavior equivalent to the
  777.           processing done by the INPUT statement.
  778.  
  779.           All parameters except for buffer are optional. Parameters to the
  780.           right of the one you wish to specify may be omitted. Here is an
  781.           example:
  782.  
  783.                after executing the following:
  784.  
  785.  
  786.           Page 12                                 TsrBasic Reference Manual
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.                     a = "one, two, three"
  799.                     b = parse (a)
  800.                     c = parse (a)
  801.                     d = parse (a)
  802.  
  803.                a is equal to "one"
  804.                b is equal to "two"
  805.                c is equal to "three"
  806.  
  807.           Literals and connectors are used to quote sequences of characters
  808.           so they are not affected by other parse actions. The difference
  809.           between literals and connectors is that characters in the list of
  810.           literals are not returned as part of the token whereas characters
  811.           from the list of connectors are. Note the difference in the
  812.           following example, where single quote is used first as a literal
  813.           and then as a connector:
  814.  
  815.                after executing the following:
  816.  
  817.                     a = "'hello world'"
  818.                     b = parse (a, "'")
  819.  
  820.                     a = "'hello world'"
  821.                     c = parse (a, "", "'")
  822.  
  823.                b is equal to "hello world"
  824.                c is equal to "'hello world'"
  825.  
  826.           Discards are a list of characters to strip from the beginning of
  827.           the token. They are normally used to strip preceding spaces or
  828.           tabs.
  829.  
  830.           Delimiters and Specials are characters that mark the end of a
  831.           token. The difference between them is that delimiters are not
  832.           returned as part of the token whereas specials are returned as
  833.           the next token. Here is an example:
  834.  
  835.                after executing the following:
  836.  
  837.                     a = "execute 3 + 4 * 5"
  838.                     b = parse (a, "", "", "", " ", "+*")
  839.                     c = parse (a, "", "", "", " ", "+*")
  840.                     d = parse (a, "", "", "", " ", "+*")
  841.                     e = parse (a, "", "", "", " ", "+*")
  842.                     f = parse (a, "", "", "", " ", "+*")
  843.                     g = parse (a, "", "", "", " ", "+*")
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.           TsrBasic Reference Manual                                 Page 13
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.                b is equal to execute
  865.                c is equal to 3
  866.                d is equal to +
  867.                e is equal to 4
  868.                f is equal to *
  869.                g is equal to 5
  870.  
  871.           The PARSE function is well suited to being used in a loop to
  872.           initialize an array of tokens, as follows:
  873.  
  874.                100 tokcnt = 0
  875.                110 dim token(30)
  876.                120 print "enter text: ";
  877.                130 line input text
  878.                140 if text = "" then goto 180
  879.                150    token(tokcnt) = parse (text)
  880.                160    tokcnt = tokcnt + 1
  881.                170 goto 140
  882.                180 print "done"
  883.  
  884.  
  885.           11.2      Strins Function
  886.  
  887.           The STRINS function inserts a string into the middle of another
  888.           string. Here is its syntax:
  889.  
  890.           newstr = strins (oldstr, start, midstr)
  891.  
  892.           The string represented by midstr is inserted into oldstr starting
  893.           at an offset of start into oldstr to produce newstr. For example:
  894.  
  895.                after executing the following:
  896.  
  897.                     oldstr = "advance"
  898.                     midstr = "THANKS"
  899.                     newstr = strins (oldstr, 4, midstr)
  900.  
  901.               newstr is equal to "advTHANKSance"
  902.  
  903.  
  904.           11.3      Strovr Function
  905.  
  906.           The STROVR function overlays a string onto the middle of another
  907.           string. Here is the syntax for STROVR:
  908.  
  909.           newstr = strovr (oldstr, start, midstr)
  910.  
  911.           The string represented by midstr is overlayed onto oldstr
  912.           starting at an offset of start into oldstr to produce newstr, as
  913.           follows:
  914.  
  915.  
  916.  
  917.  
  918.           Page 14                                 TsrBasic Reference Manual
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.                after executing the following:
  931.  
  932.                     oldstr = "The quick fox jumps over the lazy dog"
  933.                     midstr = "cat"
  934.                     newstr = strovr (oldstr, 11, midstr)
  935.  
  936.                newstr is equal to "The quick cat jumps over the lazy dog"
  937.  
  938.           This function is roughly equivalent to the MID statement in other
  939.           versions of BASIC.
  940.  
  941.  
  942.           12.  File Operations
  943.  
  944.           TsrBasic supports simple file operations on standard ASCII files.
  945.           The following operations are supported:
  946.  
  947.                access              input               print
  948.                close               line input          tab
  949.                eof                 open
  950.  
  951.           The OPEN statement opens a file. The mode parameter describes the
  952.           access mode for the file. Possible values of mode are:
  953.  
  954.                "r"  open existing file for reading
  955.                "w"  truncate or create for writing
  956.                "a"  write to end of existing file
  957.                "r+" open existing file for reading and writing
  958.                "w+" truncate or create new file for reading and writing
  959.                "a+" allow reading and writing at end of file
  960.  
  961.           Append "b" to any of the above modes to access the file in binary
  962.           mode. This prevents carriage return/newline and control-z
  963.           mapping. 
  964.  
  965.           13. Execute Statement
  966.  
  967.           The EXECUTE statement translates and executes its single string
  968.           expression argument. This argument can be either a TsrBasic
  969.           statement-list or a command. Here is an example of how it can be
  970.           used to implement a simple calculator:
  971.  
  972.                100 print "enter expression: ";
  973.                110 line input expression
  974.                120 if expression = "quit" then end
  975.                130 execute "print " + expression
  976.                140 goto 100
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.           TsrBasic Reference Manual                                 Page 15
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.           14.  If Statement
  997.  
  998.           The TsrBasic IF statement takes two forms. One is the
  999.           conventional:
  1000.  
  1001.           if expression then statement-list [else statement-list]
  1002.  
  1003.           where statement-list is a list of colon separated statements.
  1004.  
  1005.           The other form of the TsrBasic IF statement is designed to
  1006.           simplify structured programming. It is coded as follows:
  1007.  
  1008.               if expression
  1009.                  then
  1010.                     statement-list
  1011.                     ...
  1012.                 [else
  1013.                     statement-list
  1014.                     ...]
  1015.               end if
  1016.  
  1017.           Any number of lines of statement-lists can appear in the THEN and
  1018.           ELSE clauses, and they may include nested IF statements. The only
  1019.           requirement for this form of the IF statement is that the THEN,
  1020.           ELSE and END IF keywords appear on separate lines. Note that the
  1021.           ELSE clause is optional.
  1022.  
  1023.  
  1024.           15.  Link Command
  1025.  
  1026.           The LINK command links the TsrBasic interpreter with the current
  1027.           program to create a DOS executable file. The TsrBasic program can
  1028.           then be invoked just like any other DOS program. It can even get
  1029.           access to command line arguments using the ARGC and ARGV
  1030.           functions. Here is an example of a simple program that will get
  1031.           the name of a file from the DOS command line and list it to the
  1032.           console. See the description of file operations in section 12 for
  1033.           more information.
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.           Page 16                                 TsrBasic Reference Manual
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.                100 if argc() <> 1
  1063.                110    then
  1064.                120       print "usage: list <file>"
  1065.                130       end
  1066.                140 end if
  1067.                150 open #1, "r", argv (1)
  1068.                160 if not eof (1)
  1069.                170    then
  1070.                180       line input #1, buf
  1071.                190       print buf
  1072.                200       goto 160
  1073.                210 end if
  1074.                220 close #1
  1075.  
  1076.           This program can be converted into an executable file using the
  1077.           LINK command. The resulting .exe file can then be executed from
  1078.           the DOS command line with a single argument specifying a file to
  1079.           list.
  1080.  
  1081.           Note: the LINK command writes the current settings of the command
  1082.           line options for data area, program and symbol table size to the
  1083.           .exe file. These sizes do not need to be specified again when the
  1084.           resulting .exe file is executed.
  1085.  
  1086.  
  1087.           16.  Command Line Options
  1088.  
  1089.           TsrBasic supports the following command line options. Note that
  1090.           they are case sensitive and must be specified using lower case.
  1091.  
  1092.                tsrbasic [-d<n>] [-p<n>] [-s<n>] [files]
  1093.  
  1094.           The -d<n> option defines the amount of storage allocated for the
  1095.           data defined in DATA statements. The <n> parameter specifies the
  1096.           number of data elements that can be defined in your program. The
  1097.           default is -d100, which provides storage for 100 elements.
  1098.           Increase this parameter if you see a "Too many data items" error
  1099.           message.
  1100.  
  1101.           The -p<n> option defines the amount of storage allocated for the
  1102.           intermediate code program. The <n> parameter is specified in
  1103.           units of intermediate code instructions. The default is -p750
  1104.           which represents 750 intermediate code instructions and is
  1105.           roughly equivalent to 300 lines of TsrBasic source code. Increase
  1106.           this parameter if you see a "Program too long" error message.
  1107.  
  1108.           The -s<n> option defines the amount of storage allocated for the
  1109.           symbol table. The <n> parameter specifies the maximum number of
  1110.           symbols. A symbol table entry is required for each variable,
  1111.           array and literal, including those defined in immediate mode. The
  1112.           default is -s150. Increase this parameter if you see a "Too many
  1113.           symbols" error message.
  1114.  
  1115.  
  1116.           TsrBasic Reference Manual                                 Page 17
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.           One or more TsrBasic source files can be specified on the command
  1129.           line. These files are processed in the order they are specified.
  1130.           In order to be executed, a file must have a RUN command in it.
  1131.           The interactive command processor is entered after the last file
  1132.           is processed.
  1133.  
  1134.  
  1135.           17. Error Handling
  1136.  
  1137.           TsrBasic errors fall into two categories: compilation errors and
  1138.           runtime errors.
  1139.  
  1140.           Compilation errors reflect errors in your source code that must
  1141.           be corrected before the program can be executed. The most common
  1142.           compilation error is "syntax error." If you get a syntax error,
  1143.           and the cause of the error is not immediately obvious, look very
  1144.           carefully at the statement and compare the syntax you specified
  1145.           to that which is listed in the summary of statements and
  1146.           functions. Be especially careful to check for invalid or missing
  1147.           operators.
  1148.  
  1149.           Runtime errors are errors that could not be detected at
  1150.           compilation time, like "Cannot open file." They may be trapped
  1151.           using an ON ERROR GOTO statement. The ERL, ERR and ERM functions
  1152.           can be used within an error handler to identify the line number
  1153.           on which the error occured as well as the error code and the
  1154.           error message text. An error handler can use the RESUME statement
  1155.           to retry the statement that caused the error, return control to
  1156.           the statement following the line that caused the error, or return
  1157.           control to some other location.
  1158.  
  1159.           See Appendix C for a complete list of error codes and messages.
  1160.  
  1161.  
  1162.           18. Using Keyboard Scan Codes
  1163.  
  1164.           When you press a key on the keyboard, the keyboard sends a scan
  1165.           code to the CPU indicating the key that was pressed. These scan
  1166.           codes are usually translated into characters to be used by your
  1167.           program. Several TsrBasic statements deal directly with raw scan
  1168.           codes.
  1169.  
  1170.           The SUSPEND statement, for instance, uses a scan code value to
  1171.           specify the hotkey that is used to recall the interpreter. The
  1172.           scan code values are taken from the list in Appendix D.
  1173.  
  1174.           The GETKEY and INKEY functions both return combinations of
  1175.           scancodes and characters. The return value consists of two bytes.
  1176.           The high order byte is the scan code and the low order byte is
  1177.           the character value, or zero for keys that do not have character
  1178.           values, such as function keys. To get the high order byte, or
  1179.  
  1180.  
  1181.  
  1182.           Page 18                                 TsrBasic Reference Manual
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.           scan code, right shift the returned value by 8 bits. This is
  1194.           equivalent to integer division by 2^8 or 256:
  1195.  
  1196.                scan_code = inkey () \ 256
  1197.  
  1198.           To get the low order byte, or character value, zero the high
  1199.           order byte by ANDing with 0xff or 255:
  1200.  
  1201.                char_code = inkey () & 255
  1202.  
  1203.           The following TsrBasic program will tell you the scan code and
  1204.           character associated with any key:
  1205.  
  1206.                100 print "Enter key, or q to stop";
  1207.                110 key = getkey ()
  1208.                120 scan_code = key \ 256
  1209.                130 char_code = key & 0xff
  1210.                140 print
  1211.                150 print "scan code = "; scan_code
  1212.                160 print "char code = "; char_code;
  1213.                170 print " ("; chr (char_code); ")"
  1214.                180 if char_code <> asc ("q") then goto 100
  1215.  
  1216.           Note that control-c will not terminate a program that is using
  1217.           GETKEY to read a scancode. Instead, GETKEY will return the
  1218.           scancode for control-c.
  1219.  
  1220.  
  1221.           Appendix A.    Summary of Statements and Functions
  1222.  
  1223.           A TsrBasic program is made up of statements and functions. When
  1224.           the RUN command is entered, the statements and functions are
  1225.           compiled into intermediate code and then executed. Commands
  1226.           differ from statements in that they are not compiled into
  1227.           intermediate code.
  1228.  
  1229.           Statements can be entered without a line number, in which case
  1230.           they are executed immediately, or with a line number, in which
  1231.           case they are stored as part of the current program. Multiple
  1232.           statements can be entered on a single line, separated by colons.
  1233.  
  1234.           Functions return values. They are passed an argument list
  1235.           consisting of zero or more expressions, separated by commas.
  1236.  
  1237.           Statements, functions and commands in TsrBasic are not case
  1238.           sensitive. They may be entered in any combination of lower and
  1239.           upper case.
  1240.  
  1241.           In the following summary, functions are indicated by an equal
  1242.           sign:
  1243.  
  1244.                n = abs (m)
  1245.  
  1246.  
  1247.  
  1248.           TsrBasic Reference Manual                                 Page 19
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.           and statements are indicated merely by the presence of the
  1260.           statement name:
  1261.  
  1262.                beep
  1263.  
  1264.           Some TsrBasic keywords can be referenced as both statements and 
  1265.           functions to get and/or set values. Keywords that can be used as
  1266.           both statements and functions have syntax specifications for each
  1267.           form.
  1268.  
  1269.           The following summary uses the letter b to represent boolean
  1270.           values, the letters n and m to represent integers, the letters r,
  1271.           s and t to represent strings and the letters x and y to represent
  1272.           real numbers. Values are converted to the appropriate type when
  1273.           necessary.
  1274.  
  1275.           Note: The trigonometric functions expect arguments expressed in
  1276.           radians. To convert degrees to radians, multiply by pi/180.
  1277.  
  1278.           y = abs(x)
  1279.                Return absolute value of x.
  1280.  
  1281.           b = access(s)
  1282.                Return true if file s exists.
  1283.  
  1284.           n = argc()
  1285.                Return number of arguments on dos command line.
  1286.  
  1287.           s = argv(n)
  1288.                Return argument number n from dos command line.
  1289.  
  1290.           n = asc(s)
  1291.                Return ascii code of first character of s.
  1292.  
  1293.           y = atn(x)
  1294.                Return arctangent of x, where x is in radians.
  1295.  
  1296.           background n
  1297.                Set background color for subsequent text output to n. Use
  1298.                the lookup function to map color names to numbers. Use the
  1299.                refresh statement to make the color change occur
  1300.                immediately.
  1301.  
  1302.           s = background ([n])
  1303.                Return current text background color, optionally set new
  1304.                background color to n.
  1305.  
  1306.           beep
  1307.                Generate tone through speaker.
  1308.  
  1309.           blank
  1310.                Clear entire screen, differs from cls in that cls clears
  1311.                just the current text window.
  1312.  
  1313.  
  1314.           Page 20                                 TsrBasic Reference Manual
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.           border
  1327.                Shrink the text area of the window by one row or column on
  1328.                each side and draw a border around it.
  1329.  
  1330.           box x1, y1, x2, y2, f
  1331.                Draw a box with top left corner at x1, y1 and bottom right
  1332.                corner at x2, y2. Outline the box if f is 2 and fill the box
  1333.                if f is 3. The lookup function may be used to map "outline"
  1334.                and "fill" to 2 and 3. Available in graphics mode only.
  1335.  
  1336.           s = cat(t[,u...])
  1337.                Return the concatenation of strings t, u, etc, see also: +.
  1338.  
  1339.           chain s
  1340.                Load file specified by s and run it, see also: common.
  1341.  
  1342.           s = chr(n)
  1343.                Return the character equivalent for ascii code n.
  1344.  
  1345.           n = cint(x)
  1346.                Return x rounded up to next integer.
  1347.  
  1348.           circle x1, y1, x2, y2, f
  1349.                Draw a circle within the bounding rectangle specified by a
  1350.                top left corner at x1, y1 and a bottom right corner at x2,
  1351.                y2. Outline the circle if f is 2 and fill the circle if f is
  1352.                3. The lookup function may be used to map "outline" and
  1353.                "fill" to 2 and 3. Available in graphics mode only.
  1354.  
  1355.           clip x1, y1, x2, y2
  1356.                Define a graphics view port with a top left corner at x1, y1
  1357.                and a bottom right corner at x2, y2. Subsequent graphics
  1358.                output beyond this rectangle will be clipped. Available in
  1359.                graphics mode only.
  1360.  
  1361.           close #n
  1362.                Close file opened with file number n, see also: open, input,
  1363.                print.
  1364.  
  1365.           cls
  1366.                Clear current text window, see also: blank.
  1367.  
  1368.           color n, m
  1369.                Set graphics foreground color to n and background color to
  1370.                m. The graphics color is maintained independently of the
  1371.                text color. The lookup function may be used to map color
  1372.                names to color numbers. Available in graphics mode only.
  1373.  
  1374.           column n
  1375.                Move cursor to absolute column n, where the leftmost column
  1376.                is 0 and the rightmost column is usually 79. See also
  1377.  
  1378.  
  1379.  
  1380.           TsrBasic Reference Manual                                 Page 21
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.                locate, which positions the cursor relative to the origin of
  1392.                the current text window.
  1393.  
  1394.           n = column ([m])
  1395.                Return current cursor column, optionally moving cursor to
  1396.                column m.
  1397.  
  1398.           common variable [,variable]...
  1399.                Define common variables for chained programs, see also:
  1400.                chain.
  1401.  
  1402.           config xpix, ypix, colors, adapter, mode
  1403.                Get the current graphics configuration.
  1404.  
  1405.           cont
  1406.                Continue program execution after stop, see also: stop.
  1407.  
  1408.           s = copy(t,n)
  1409.                Return a string consisting of n copies of t.
  1410.  
  1411.           y = cos(x)
  1412.                Return the cosine of x, where x is in radians.
  1413.  
  1414.           csroff
  1415.                Turn the cursor off.
  1416.  
  1417.           csron
  1418.                Turn the cursor on and set it to a default size.
  1419.  
  1420.           csrbottom n
  1421.                Change the size of the cursor by setting the bottom of the
  1422.                cursor to scan line number n. Must be 0 to 6 for cga and 0
  1423.                to 12 for ega. The bottom scan line should be numerically
  1424.                greater than the top scan line.
  1425.  
  1426.           n = csrbottom ([m])
  1427.                Get the current bottom scan line of the cursor, and
  1428.                optionally set it to scan line m.
  1429.  
  1430.           csrtop n
  1431.                Change the size of the cursor by setting the top of the
  1432.                cursor to scan line number n. Must be 0 to 6 for cga and 0
  1433.                to 12 for ega. The top scan line should be numerically less
  1434.                than the top scan line.
  1435.  
  1436.           n = csrtop ([m])
  1437.                Get the current top scan line of the cursor, and optionally
  1438.                set it to scan line m.
  1439.  
  1440.           s = date()
  1441.                Return the current date in mm:dd:yy format.
  1442.  
  1443.  
  1444.  
  1445.  
  1446.           Page 22                                 TsrBasic Reference Manual
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.           data value [,value]...
  1459.                Define numeric and string values, see also: read.
  1460.  
  1461.           m = dec(n)
  1462.                Return the decimal equivalent of hex or octal n, see also:
  1463.                hex, oct.
  1464.  
  1465.           dim array(n[,n]...) [,array(n[,n]...)]...
  1466.                Define array with index zero to n, see also: erase, shift,
  1467.                sort.
  1468.  
  1469.           display n,m,s
  1470.                Display string s at absolute row n and column m, without 
  1471.                moving the cursor.
  1472.  
  1473.           end
  1474.                Terminate program execution.
  1475.  
  1476.           s = environ(t)
  1477.                Return value of environment variable t.
  1478.  
  1479.           b = eof(n)
  1480.                Return true if end of file reached on file n.
  1481.  
  1482.           erase array [,array]..
  1483.                Free array, see also: dim.
  1484.  
  1485.           n = erl()
  1486.                Return line number on which error occurred. Valid in error
  1487.                handler only. See also: erm, err, on error.
  1488.  
  1489.           s = erm()
  1490.                Return error message associated with error. Valid in error
  1491.                handler only. See also erl, err, on error.
  1492.  
  1493.           n = err()
  1494.                Return error number associated with error. Valid in error
  1495.                handler only. See also erl, erm, on error.
  1496.  
  1497.           error n
  1498.                Simulate occurrence of error n, see also: on error, resume.
  1499.  
  1500.           execute s
  1501.                Execute string expression s as a TsrBasic statement.
  1502.  
  1503.           y = exp(x)
  1504.                Return natural log (e) to the power of x.
  1505.  
  1506.           fill x1, y1, n
  1507.                Fill the graphics image that has border color n and
  1508.                surrounds the point x1, y1. Use lookup to map color names to
  1509.                numbers. Available in graphics mode only.
  1510.  
  1511.  
  1512.           TsrBasic Reference Manual                                 Page 23
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.           n = fix(x)
  1525.                Return x truncated to an integer.
  1526.  
  1527.           n = fre()
  1528.                Return amount of free TsrBasic memory in bytes.
  1529.  
  1530.           for variable = expression to expression [step expression]
  1531.                For...next loop, see also: next.
  1532.  
  1533.           foreground c
  1534.                Set foreground color for subsequent text output to n. Use
  1535.                the lookup function to map color names to numbers. Use the 
  1536.                refresh statement to make the color change occur
  1537.                immediately.
  1538.  
  1539.           d = foreground ([c])
  1540.                Return current text foreground color, optionally set new
  1541.                foreground color to c.
  1542.  
  1543.           get x1, y1, x2, y2
  1544.                Transfer a graphics image from the screen to memory. The
  1545.                image is bounded by a rectangle with a top left corner of
  1546.                x1, y1, and a bottom right corner of x2, y2. The image may
  1547.                then be transferred to a file using mapsave or back to the
  1548.                screen using put. Available in graphics mode only.
  1549.  
  1550.           n = getkey ()
  1551.                Wait for a key to be entered and return the scan code. See
  1552.                Appendix D for more information on scan codes.
  1553.  
  1554.           n = getscreen ()
  1555.                Return the attributes and ascii code of the character at the
  1556.                current cursor position. The attributes are returned in the
  1557.                high order byte and the ascii code is returned in the low
  1558.                order byte.
  1559.  
  1560.           goto n
  1561.                Goto line number n, also valid in immediate mode after run.
  1562.  
  1563.           gosub n
  1564.                Call subroutine at line number n, see also: return.
  1565.  
  1566.           m = hex(n)
  1567.                Return hexadecimal equivalent of decimal or octal n. See
  1568.                also: dec, oct.
  1569.  
  1570.           if expression then statement-list [else statement-list]
  1571.                If...then...else statement, see detailed description.
  1572.  
  1573.           init
  1574.                Set current text window and cursor to default size and
  1575.                color. In the normal text video mode there are 25 rows and
  1576.  
  1577.  
  1578.           Page 24                                 TsrBasic Reference Manual
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.                80 columns. The top-left corner is 0, 0 and the bottom right
  1590.                corner is 24, 79.
  1591.  
  1592.           n = inkey()
  1593.                Return scan code if key entered else zero, see detailed
  1594.                description of scan codes.
  1595.  
  1596.           m = inp(n)
  1597.                Return byte read from hardware port n.
  1598.  
  1599.           input [#file-number] variable [,variable]...
  1600.                Input one or more items into variables, see also: line
  1601.                input, parse.
  1602.  
  1603.           s = instr([n,]r,t)
  1604.                Return first occurrence of s in r optionally starting at n.
  1605.  
  1606.           n = int(x)
  1607.                Return x truncated to an integer and rounded down if
  1608.                negative.
  1609.  
  1610.           intensity n
  1611.                Set text intensity (brightness) attribute to n. Use lookup
  1612.                function to map intensity names "low" and "high" to
  1613.                intensity numbers 0 and 8.
  1614.  
  1615.           s = left(t,n)
  1616.                Return leftmost n characters of s.
  1617.  
  1618.           n = len(s)
  1619.                Return number of characters in s.
  1620.  
  1621.           [let] variable = expression
  1622.                Assign expression to variable or array.
  1623.  
  1624.           line input [#file-number] variable
  1625.                Input an entire line of text into a variable or array.
  1626.  
  1627.           lineto x1, y1
  1628.                Draw a line in the current graphics color to point x1, y1.
  1629.                Valid only in graphics mode. See also: mode, moveto.
  1630.  
  1631.           locate n, m
  1632.                Set cursor to row n and column m relative to the current
  1633.                text window (0,0 is top left). See also: screen.
  1634.  
  1635.           mapload n
  1636.                Load a graphics image bitmap, previously saved by mapsave,
  1637.                from file IMAGE.n where n is a number. The bitmap may then
  1638.                be transferred to the screen using put.
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.           TsrBasic Reference Manual                                 Page 25
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.           mapsave n
  1657.                Save a graphics image bitmap to file IMAGE.n where n is a
  1658.                number. The bitmap must have previously been transferred
  1659.                from the screen to memory using get.
  1660.  
  1661.           mode n
  1662.                Set video/graphics mode to n. See detailed description of
  1663.                graphics modes for more information.
  1664.  
  1665.           moveto x1, y1
  1666.                Move to point x1, y1 for subsequent graphics output. Valid
  1667.                only in graphics mode. See also: mode, lineto.
  1668.  
  1669.           next variable
  1670.                For...next loop, see also: for
  1671.  
  1672.           y = log(x)
  1673.                Return natural logarithm of x.
  1674.  
  1675.           s = mid(t,n[,m])
  1676.                Return m characters from t starting at n, return remainder
  1677.                of string t if m is omitted.
  1678.  
  1679.           m = oct(n)
  1680.                Return octal equivalent of decimal or hexadecimal n. See
  1681.                also: dec, hex.
  1682.  
  1683.           on error goto n
  1684.                Call error handler at line number n. Return from it with
  1685.                resume. See also: erl, erm, err.
  1686.  
  1687.           open #n, s, t
  1688.                Open file with access mode s and pathname t, and associate
  1689.                it with file number n. See detailed description for
  1690.                information on access modes.
  1691.  
  1692.           out port, expression
  1693.                Output integer byte value to port, see also: inp.
  1694.  
  1695.           page n
  1696.                Set current video text page for video adapters capable of
  1697.                supporting multiple text pages.
  1698.  
  1699.           n = page ([m])
  1700.                Get the current video text page and optionally set it to
  1701.                page m.
  1702.  
  1703.           s = parse(t[,v...])
  1704.                Return a token parsed from t, see detailed description.
  1705.  
  1706.           i = peek(j,k)
  1707.                Return byte located at segment j, offset k.
  1708.  
  1709.  
  1710.           Page 26                                 TsrBasic Reference Manual
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.           pixel x1, y1
  1723.                Turn on graphics pixel at point x1, y1. Available only in
  1724.                graphics mode.
  1725.  
  1726.           poke segment, offset, expression
  1727.                Set byte at segment and offset to integer value, see also:
  1728.                peek.
  1729.  
  1730.           print [#n] expression [, or ; expression]...
  1731.                Print to file number n or console, semicolon causes print
  1732.                items to be adjacent, comma causes them to be separated by
  1733.                tabs.
  1734.  
  1735.           put x1, y1, n
  1736.                Transfer a graphics image from memory to the screen. The
  1737.                image must have previously been captured using get, or read
  1738.                from a disk file using mapload. The top left corner is put
  1739.                at x1, y1 and the control argument n describes how the image
  1740.                is transferred to the screen. See the detailed description
  1741.                of graphics for more information.
  1742.  
  1743.           randomize
  1744.                Seed random number generator.
  1745.  
  1746.           read variable [,variable]...
  1747.                Read values into variables or arrays, see also: data,
  1748.                restore.
  1749.  
  1750.           refresh
  1751.                Refresh the text screen. This can be used after the
  1752.                foreground and background statements to change the color of
  1753.                text that is already on the screen.
  1754.  
  1755.           rem
  1756.                Remark, i.e. this line is a comment, equivalent to single
  1757.                quote.
  1758.  
  1759.           restore
  1760.                Restore data list to beginning, see also: data, read.
  1761.  
  1762.           restorescreen s
  1763.                Restore screen contents to previous value, see savescreen.
  1764.                In addition to restoring the contents of the screen, this
  1765.                statement also restores the text window dimensions that were
  1766.                in effect when the corresponding savescreen was executed.
  1767.  
  1768.           resume
  1769.                Return from error handler and retry statement that caused
  1770.                error. See also: on error.
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.           TsrBasic Reference Manual                                 Page 27
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.           resume n
  1789.                Return from error handler to line-number n. See also: on
  1790.                error.
  1791.  
  1792.           resume next
  1793.                Return from error handler to statement following the one
  1794.                that caused the error. See also: on error.
  1795.  
  1796.           return
  1797.                Return from subroutine entered via gosub.
  1798.  
  1799.           row n
  1800.                Move cursor to absolute row n, where the top row is 0 and
  1801.                the bottom row is usually 24. See also locate, which
  1802.                positions the cursor relative to the origin of the current
  1803.                text window.
  1804.  
  1805.           n = row ([m])
  1806.                Return current cursor row and optionally move cursor to row
  1807.                m.
  1808.  
  1809.           s = right(t,n)
  1810.                Return rightmost n characters of t.
  1811.  
  1812.           m = rnd([n])
  1813.                Return random number, optionally based on seed n.
  1814.  
  1815.           savescreen s
  1816.                Save screen contents in variable s for a subsequent
  1817.                restorescreen. This function saves the text window defined
  1818.                using the wintop, winleft, winbottom and winright
  1819.                statements. To save the entire screen, use the init
  1820.                statement first to set the text window size back to the
  1821.                entire screen.
  1822.                  
  1823.           screen "command", parameters
  1824.                Not supported in Version 2.0. See setailed description of
  1825.                text windows for alternate statements and functions.
  1826.  
  1827.           scroll n
  1828.                Scroll screen up n rows if n is positive or down n rows if
  1829.                rows is negative.
  1830.  
  1831.           m = sgn(x)
  1832.                Return -1 if x is negative, 0 if x is 0, +1 if x is
  1833.                positive.
  1834.  
  1835.           shell s
  1836.                Pass string expression s to DOS shell to execute as a
  1837.                command. Because DOS is not reentrant, this statement will
  1838.                not work when you have recalled a suspended TsrBasic session
  1839.                from the DOS shell. In this case it will return a "DOS is
  1840.  
  1841.  
  1842.           Page 28                                 TsrBasic Reference Manual
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.                busy" error. You can, however, use the SHELL statement when
  1854.                you have recalled TsrBasic from most other applications,
  1855.                provided there is sufficient memory.
  1856.  
  1857.           shift a, n
  1858.                Shift one dimensional array a by n elements. If n is
  1859.                negative elements are shifted down and extra elements are
  1860.                discarded from the low end. If n is positive then elements
  1861.                are shifted up and extra elements are discarded from the
  1862.                high end.
  1863.  
  1864.           y = sin(x)
  1865.                Return sine of x, where x is in radians.
  1866.  
  1867.           sort a, n
  1868.                Sort one dimensional array a into ascending order if n is
  1869.                positive and into descending order if n is negative.
  1870.  
  1871.           sound frequency, duration
  1872.                Generate tone, use a frequency of zero for a delay.
  1873.  
  1874.           s = space(n)
  1875.                Return string of n spaces, see also: copy
  1876.  
  1877.           y = sqr(x)
  1878.                Return square root of x.
  1879.  
  1880.           stop
  1881.                Stop execution. Useful for debugging. See also: cont.
  1882.  
  1883.           suspend screen, key-code, key-flags, interval, status
  1884.                Terminate and stay resident. See detailed description of
  1885.                suspend statement for more information.
  1886.  
  1887.           swap variable-a, variable-b
  1888.                Swap the contents of variable-a and variable-b.
  1889.  
  1890.           tab(n)
  1891.                Position cursor to column n (as print argument only).
  1892.  
  1893.           y = tan(x)
  1894.                Return tangent of x, where x is in radians.
  1895.  
  1896.           s = time()
  1897.                Return current time in hh:mm:ss format.
  1898.  
  1899.           troff
  1900.                Disable statement tracing.
  1901.  
  1902.           tron
  1903.                Enable statement tracing.
  1904.  
  1905.  
  1906.  
  1907.  
  1908.           TsrBasic Reference Manual                                 Page 29
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.           type n
  1921.                Set type of video access to n, where n is 0 for direct
  1922.                (fast) access, 1 for BIOS access, 2 for BIOS/DOS access, and
  1923.                3 for text in graphics mode. The default is 0. Use 1 if you
  1924.                have any video problems with 0, use 2 if you want to
  1925.                redirect output using DOS redirection capability. Use 3 for
  1926.                mixed text and graphics in graphics modes (see mode).
  1927.  
  1928.           winbottom n
  1929.                Set the bottom row of the text window to n, where n is in
  1930.                the range of 0 (top) to 24 (bottom). See detailed
  1931.                description of text windows for more information.
  1932.  
  1933.           n = winbottom ([m])
  1934.                Return the current bottom row of the text window and
  1935.                optionally set it to m.
  1936.  
  1937.           winleft n
  1938.                Set the left column of the text window to n, where n is in
  1939.                the range of 0 (left) to 79 (right). 
  1940.  
  1941.           n = winleft ([m])
  1942.                Return the current left column of the text window and
  1943.                optionally set it to m.
  1944.  
  1945.           winright n
  1946.                Set the right column of the text window to n, where n is in
  1947.                the range of 0 (left) to 79 (right). 
  1948.  
  1949.           n = winright ([m])
  1950.                Return the current right column of the text window and
  1951.                optionally set it to m.
  1952.  
  1953.           wintop n
  1954.                Set the top row of the text window to n, where n is in the
  1955.                range of 0 (top) to 24 (bottom). 
  1956.  
  1957.           n = wintop ([m])
  1958.                Return the current top row of the text window and optionally
  1959.                set it to m.
  1960.  
  1961.  
  1962.           Appendix B.    Summary of Commands
  1963.  
  1964.  
  1965.           Commands are usually entered without a line number and
  1966.           are executed immediately. They may, however, be included in
  1967.           programs if they are passed as arguments to the EXECUTE
  1968.           statement. In this case, they are processed when the EXECUTE
  1969.           statement is executed.
  1970.  
  1971.  
  1972.  
  1973.  
  1974.           Page 30                                 TsrBasic Reference Manual
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.           In the following list of commands, the phrase line-number-spec
  1986.           refers to an optional specification of line numbers. The
  1987.           specification may take the following forms:
  1988.  
  1989.                -    all lines
  1990.                n    line n
  1991.                n-   line n through end
  1992.                n-m  line n through m
  1993.                -n   beginning through n
  1994.  
  1995.           If the specification is omitted, all lines are processed.
  1996.  
  1997.           clear
  1998.                Free all variables.
  1999.  
  2000.           chdir pathname
  2001.                Make pathname the current directory.
  2002.  
  2003.           delete [line-number-spec]
  2004.                Delete lines from current program, use caution when entering
  2005.                this command without a line-number-spec,  because it will
  2006.                delete the entire program.
  2007.  
  2008.           dis [line-number-spec]
  2009.                Disassemble intermediate code.
  2010.  
  2011.           edit [line-number-spec]
  2012.                Invoke editor specified by EDITOR environment variable on
  2013.                line-number-spec.
  2014.  
  2015.           kill pathname
  2016.                Delete file specified by pathname.
  2017.  
  2018.           link pathname
  2019.                Translate current program into an executable called
  2020.                pathname.
  2021.  
  2022.           list [line-number-spec]
  2023.                List current program
  2024.  
  2025.           load pathname
  2026.                Clear current program and load new program, default
  2027.                extension is ".bas". Append a period if the filename does
  2028.                not have an extension.
  2029.  
  2030.           merge pathname
  2031.                Merge new program with current program.
  2032.  
  2033.           mkdir pathname
  2034.                Create a directory specified by pathname.
  2035.  
  2036.           new
  2037.                Erase the current program.
  2038.  
  2039.  
  2040.           TsrBasic Reference Manual                                 Page 31
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.           quit
  2053.                Terminate TsrBasic and unload from memory if resident.
  2054.  
  2055.           renum new-first-line line-increment
  2056.                Renumber current program.
  2057.  
  2058.           rmdir pathname
  2059.                Remove directory specified by pathname.
  2060.  
  2061.           run [line-number]
  2062.                Execute current program, optionally starting at line-number.
  2063.  
  2064.           save pathname
  2065.                Save current program to file specified by pathname, default
  2066.                extension is ".bas". Append a period if you do not want the
  2067.                filename to have an extension.
  2068.  
  2069.  
  2070.           Appendix C.   Error Codes and Messages
  2071.  
  2072.  
  2073.           The following list describes TsrBasic error codes and messages:
  2074.  
  2075.               Code  Message
  2076.  
  2077.                0    Internal error
  2078.                1    Syntax error
  2079.                2    Uninitialized variable
  2080.                3    Missing left paren
  2081.                4    Missing right paren
  2082.                5    Missing comma or right paren
  2083.                6    Missing factor
  2084.                7    Expression too complex
  2085.                8    Too many symbols
  2086.                9    Program too long
  2087.                10   Too many nested calls
  2088.                11   Too many nested GOSUB's
  2089.                12   RETURN without GOSUB
  2090.                13   Duplicate definition
  2091.                14   Invalid subscript
  2092.                15   Too many data items
  2093.                16   Out of data
  2094.                17   FOR loops nested too deep
  2095.                18   Missing NEXT
  2096.                19   Missing FOR
  2097.                20   Cannot open file
  2098.                21   File not open
  2099.                22   File in use
  2100.                23   Undefined line number
  2101.                24   Break
  2102.                25   Cannot continue
  2103.                26   File or dir not found
  2104.  
  2105.  
  2106.           Page 32                                 TsrBasic Reference Manual
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.                27   Assignment to constant
  2118.                28   Cannot locate tsrbasic
  2119.                29   i/o error
  2120.                30   DOS is busy
  2121.                31   Missing END IF
  2122.                32   Cannot load GRAPHICS.DLL
  2123.                33   Floating point exception
  2124.                34   Missing THEN
  2125.                35   Use of keyword as variable
  2126.                36   Graphics error
  2127.                37   Cannot terminate TSR
  2128.  
  2129.  
  2130.           Appendix D.   Keyboard Scan Codes
  2131.  
  2132.           The following table lists the key and the corresonding scan code,
  2133.           in decimal (and in parenthesis). Note that some keys, such as
  2134.           control and shift cannot be processed by getkey and inkey.
  2135.  
  2136.  
  2137.           Characters
  2138.  
  2139.                a (30)              k (37)              u (22)
  2140.                b (48)              l (38)              v (47)
  2141.                c (46)              m (50)              w (17)
  2142.                d (32)              n (49)              x (45)
  2143.                e (18)              o (24)              y (21)
  2144.                f (33)              p (25)              z (44)
  2145.                g (34)              q (16)
  2146.                h (35)              r (19)
  2147.                i (23)              s (31)
  2148.                j (36)              t (20)
  2149.                 
  2150.                 
  2151.           Digits
  2152.                 
  2153.                1 (2)               5 (6)               9 (10)
  2154.                2 (3)               6 (7)               0 (11)
  2155.                3 (4)               7 (8)
  2156.                4 (5)               8 (9)
  2157.                 
  2158.  
  2159.           Function Keys  
  2160.                 
  2161.                f1 (59)             f5 (63)             f9 (67)
  2162.                f2 (60)             f6 (64)             f10 (68)
  2163.                f3 (61)             f7 (65)
  2164.                f4 (62)             f8 (66)
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.           TsrBasic Reference Manual                                 Page 33
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.           Special Keys
  2185.  
  2186.                alt (56)            equals (13)         page down (81)
  2187.                arrow down (80)     enter (28)          page up (73)
  2188.                arrow left (75)     escape (1)          period (52)
  2189.                arrow right (77)    home (71)           prt sc / * (55)
  2190.                arrow up (72)       insert (82)         right bracket (27)
  2191.                back quote (41)     keypad + (78)       right shift (54)
  2192.                back space (14)     keypad - (74)       semicolon (39)
  2193.                back slash (43)     keypad 5 (76)       scroll lock (70)
  2194.                caps lock (58)      keypad enter (78)   single quote (40)
  2195.                comma (51)          left bracket (26)   slash (53)
  2196.                control (29)        left shift (42)     space (57)
  2197.                delete (83)         minus (12)          tab (15)
  2198.                end (79)            num lock (69)
  2199.  
  2200.  
  2201.  
  2202.  
  2203.  
  2204.  
  2205.  
  2206.  
  2207.  
  2208.  
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.           Page 34                                 TsrBasic Reference Manual
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.