The Complete STOS Reference

 pre-release 0.2 Edited By Dr Phibes

Index

STOS Manual 3:THE EDITOR COMMANDS

Function Key Assignment 
Customising The Editor 
Loading/Saving Basic Programs 
Running A Program 
Auto, Renum, List, Search, Change, Delete & Merge 
Renumbering Programs
Debugging A Program 
Multiple Programs 
Splitting Programs In The Editor 
System Commands 
Naming Conventions For Variables 
Types Of Variables 
Arithmetic Operations
String Operations 
Common String Functions 
Array Operations 
Memory Banks 
Types Of Memory Banks 
Copying Banks 
Deleting Banks
Bank Parameter Functions 
Saving And Loading 
Run Only Programs 
Machine-Code Programs 
The Accessories 
Creating An Accessory

The Control Keys

[HELP] displays the edit program(n) dialogue box. This box contains three separate sections. The top section contains a list of the programs currently in memory. STOS Basic allows four programs to reside in memory simultaneously. The current program is highlighted using a horizontal bar. This bar can be moved up and down using the arrow keys, The program highlighted then becomes the current program for editing. The second part of the HELP menu displays a list of the accessories installed in the system. These accessories can be executed directly from the HELP menu by pressing one of the function keys. The last part of the HELP menu displays the amount of memory available for the storage of STOS Basic programs.

 Function Key Assignment

key(3)="BOOM'"
Note that the ' character is used to denote RETURN. So F3 will now go boom!

Customising The Editor

The STOS Basic package comes complete with a special configuration program which enables you to customise the system to your own individual requirements. The program can be found on the STOS basic language disc and is called "CONFIG.BAS". It can be loaded and executed by the Line:
run "CONFIG.BAS"
You can select any one of the various alternatives by simply moving the mouse over the appropriate item, and clicking on the left mouse button. If for example you wished STOS basic to enter medium resolution instead of low resolution on loading, you would place the pointer over the MEDIUM option and press the left mouse key.

This button would now be highlighted and the low option deselected. You can also use this dialogue to select the colours of the text (pen) and the background (paper). When finished making changes to this menu, click on NEXT PAGE. This second menu allows the function key commands to be changed and a selection of accessories to be loaded up at boot-up. This menu also allows any changes you have been made to be saved to disc. These changes will now be effective every time you boot-up STOS.

Loading/Saving Basic Programs

There are two possible ways you can load a basic program into STOS basic. Firstly you can use the normal LOAD option like so:
load "CONFIG.BAS"
This command works fine if you know the name of the program you wish to load, but often this is not the case. In these circumstances you can use the FLOAD instruction to choose a file using the file selector.

FLOAD path$

path$ is a string containing the search path. (see DIR): example:
fload "*.bas"
When you type in the above line you will be presented with a GEM type file select dialogue box. Saving a program can also be done in the above two ways merely replacing the commands load and fload with the commands save and fsave.
 

Running A Program

RUN

Execute the current STOS basic program: RUN no. Execute the current STOS basic program from line number no.

RUN file$

Load and run the program stored in file$

CONT

Restart a program exited by STOP or [control+c]. To restart a program it must not have been changed between STOP and CONT.

Auto, Renum, List, Search, Change, Delete & Merge

AUTO

The AUTO command automatically prints out a new line number every time you press [RETURN]. To exit this mode press [RETURN] on a line containing no entry.

AUTO start

Start line numbering from start

AUTO start, inc

Start line numbering from start and increment in steps of inc. If a program is already present typing in AUTO will present you with the line number after the last number already present in the program.

Renumbering Programs

Renumber all or part of a program. There are four ways of using RENUM.

RENUM

Starts by setting the first line of the program to 10 and renumbers each succeeding line in units of 10.

RENUM number

Sets the first line number to number and renumbers all succeeding lines in increments of 10.

RENUM number, inc

Starts at line number and increments each successive line by inc.

RENUM number, inc, start-end

Renumbers lines from start to end beginning with line number and incrementing each succeeding line by inc. Note that STOS basic will not allow RENUM to overwrite any existing parts of the current program.

LIST

lists the entire program.

LIST first-

Lists all the lines in the program starting from the line first.

LIST -last

Lists the lines from the start of the program to the line last.

LIST first-last

Lists the lines from first to last.

SEARCH

Searches for a string in a basic program

SEARCH S$

Will find the position of S$ in the program. To find the next occurrence of S$ simply type in SEARCH on it's own.

SEARCH A$, start-end

Will find A$ between the lines start and end.

CHANGE

Change all occurrences of a string in a program.

CHANGE "AX15B" TO "COUNT"

Will change all occurrences of AX15B in a program to COUNT.

CHANGE "AX15B" TO "COUNT", start-end

As above except only the occurrences between lines start to end will be changed.

DELETE

Delete some or all lines of a program DELETE line Deletes the line number line.

DELETE first-last

Delete all lines between first and last. If the lines first and last do not exist then the command is ignored.

MERGE

Merge a file into the current program.

MERGE file$

The MERGE command combines a program stored in the file file$ with the current program. Existing lines will be overwritten by any new lines with the same number.

This instruction can be used to merge a set of subroutines into one complete program.

Debugging A Program

FOLLOW

Track through a STOS basic program. There are five possible formats for the FOLLOW command.

FOLLOW

If the FOLLOW statement is used on it's own, the program will halt after every instruction and list the current line. The next line in the program can be stepped through by pressing any key.

FOLLOW first-last

This version of the instruction only FOLLOWs the program when the lines between first and last are being executed.

FOLLOW variable list

This takes a list of variables separated by commas and prints them out after every instruction has been executed. As before you can step through the program by pressing any key.

FOLLOW variable list,first-last

Identical to the instruction above, but the variables are only FOLLOWed when the lines between first and last are being executed.

FOLLOW off

Turns off the action of the FOLLOW command.

Multiple Programs

STOS basic allows you to have up to four programs in memory at any one time. These may be completely independent of each other. If you suddenly decide to change the configuration of the editor, for instance, you could easily load the CONFIG.BAS program into a separate segment of the ST's memory without interfering with your current program. To load a program into a separate memory area press [HELP],use the cursor keys to highlight a vacant program slot, press [HELP] again to return to the editor and load in the CONFIG.BAS program. Run this program, enter any alterations you want to make to the file, save it and exit the program. Press [HELP] again and using the arrow keys highlight your original program and press [HELP] again. You will now return to the editor with your original program ready for further editing or running. The CONFIG.BAS program could be accessed again using the [HELP] key at any time.

MULTI

Displays a number of programs simultaneously.

MULTI [2][3][4]

Splits the editor window in two, three or four sections. Top section = program 1: bottom section = program 2: bottom left section = program 2: bottom right section = program 3:

FULL

Expands the current window to the full screen. ( does not affect the status of any of the other programs )

Splitting Programs In The Editor

You can also use the MULTI command to split a single program into a number of separate sections. This can be done using the HELP menu. Position the program cursor over program 1 and press the left and right arrow keys.

As you can see, the text cursor is moved between four different boxes on the program line. Move the cursor to the first box and type in 1000 followed by [RETURN]. This sets the end point of the first part of the program to line 1000. If you now exit back to the editor and type MULTI 2, the program will be split into two windows. You can choose between these two windows using the mouse pointer.

To see how this works, position the mouse in the top window and click on the left mouse button. The cursor in this window will immediately start flashing, and the window will be activated.

Typing list in the first window will list all the lines of the program until line 1000. If you repeat this process in the second window, you will generate a listing of lines 1000 onwards.

Each box on the program line represents a different section of the listing. You can therefore use this technique to split a program into four separate parts. It is important to note that this has no effect on any existing segments, and you can page through each of the programs stored in memory using the HELP menu as usual. All four of these programs can be split in exactly the same way without interfering with each other.
 

GRAB n

Copy all or part of a program segment into the current program.

The GRAB command allows you to combine a number of subroutines stored in separate program segments into one complete program. This enables you to test each subroutine in your program independently. The syntax of the GRAB command is GRAB n where n represents the program number that is to be copied into the current program. n ranges from 1 to 4.n cannot be the number of the current program !

GRAB n, first-last

Only copies the lines between first and last into the current program.

System Commands

SYSTEM

Immediately returns to GEM without saving the current programs.

RESET

Simply reinitialises the editor and redraws the current screen.

DEFAULT

Redraws any currently defined windows on the screen, and resets the STOS basic editor.

Unlike RESET, DEFAULT can be used in either direct or

interpreted mode. This allows it to be utilised at the end of a basic program to jump back to the editor. The effect of this instruction can also be achieved from the editor by pressing the [UNDO] key twice. Do not confuse this with the DEFAULT function.

NEW

This command deletes the current program from the ST's memory. It has no effect on any other programs stored in different segments.

UNNEW

Attempts to recover from a NEW command. It will only work if entered immediately after NEW.

CLEAR

This instruction erases all variables and all the memory banks defined by the current program.

It also repositions the READ pointer to the first DATA statement in the program.

FREE

Returns the number of bytes free for use by the current basic program. The use of this command also initiates the garbage collection routines in the STOS interpreter. This garbage collection also occurs automatically from time to time during a program run, and if it is vital to the program not to be interrupted at some point, the function can be forced to occur when it will do the least harm by inserting the command FREE at some point in the program.

ENGLISH/FRANCAIS

Selects the language for all subsequent dialogue.

FREQUENCY

Changes the scan rate from 50 Hz to 60 Hz

UPPER

Normally, any instructions you type into a STOS basic program are listed in lower case, and any variables in upper case. The UPPER directive reverses this format to instructions in upper case and variables in lower case.

LOWER

reverts the listing back to the default case.

Naming Conventions For Variables

The names of STOS basic variables need to conform with a number of rules. Firstly, a variable name must not exceed 31 characters in length each variable name must begin with a letter, also the names must not contain any of the following Basic keywords:

TO, STEP, THEN, ELSE, XOR, OR, AND, GOTO, GOSUB, MOD, AS

Examples of legal names

A, RUNE$, IPOKE, TEST, ZZ99, C5#

Some illegal names

CAST, 5C, SORT, BAND$, MODERN$, TOAD

Types Of Variables

INTEGERS

This is the default variable type. Each integer is stored in four bytes and can range in value from -2147483648 to +2147483648.

REAL NUMBERS

These are suffixed with a # character and can range from 1.797692+308 to +1.797693+307 accurate to a precision of 16 digits.

STRINGS

These are suffixed with a $ character and can range from 0 to 65500 characters in length. They are not terminated with a chr$(0).

ARRAYS

Any of the previous variable types can be incorporated into an array created with the DIM instruction.

DIM

Is used to set up a table of variables. The number of DIMensions is unlimited but each dimension is limited to 65535 elements. Each element in the array always defaults to a value of 0 until it has been assigned a value by the programmer.

CONSTANTS

As a default, all numeric constants are treated as integers. Any floating point assignments to an integer variable are automatically converted to a whole number before use. In addition to the usual decimal notation, you can also use either binary or haxadecimal expressions. BINARY numbers are preceded with a % character, and hexadecimal numbers with a $ character.

To force the program to use a constant as a floating point number the constant should contain the decimal point: 10. and not just 10 which would be treated as an integer. Mixed integer/floating point arithmetic always results in a floating point answer.

Arithmetic Operations

The following arithmetic operations can be used in a numeric expression. They are listed in ascending order of priority.
 
 



MOD 


AND 
OR 
XOR 
INC 
DEC
Power 
Divide 
Multiply 
Modulo operator ( produces the remainder of a division ) 
Plus 
Minus 
Logical AND 
Logical OR 
Logical XOR 
Increment variable. *much* faster than A=A+1 
Decrement variable. *much* faster than A=A-1

String Operations

ADDING STRINGS:

A$="STOS"+" BASIC"
results in A$ being "STOS BASIC"

SUBTRACTING STRINGS:

A$="STOS BASIC"-"S"
results in A$ being "TO BASIC" : ALL occurrences of "S" being removed from the string.
PRINT " A STRING OF CHARACTERS"-" "
results in ASTRINGOFCHARACTERS

Common String Functions

LEFT$

There are two versions of this command LEFT$(A$,4)="STOS" and A$=LEFT$("012345",3).

RIGHT$

There are two versions of this command as above, with RIGHT being substituted for LEFT in the above examples.

MID$

A$=MID$(v$,s,n) returns A$ from position s with the number of characters n from v$

MID$(v$,s,n)=A$

sets n characters in v$ starting from s in the string A$.if a value of n is not included then the characters are replaced up to the end of A$.

INSTR

Search for occurrences of a string within another string.

INSTR(d$,s$)

This searches for the first occurrence of s$ in d$. If the string is found, then the position of this string is returned otherwise a value of 0 is returned.

INSTR(d$,s$,p)

This version of INSTR finds the first occurrence of s$ in d$ starting from character number p.

Array Operations

SORT A$(0)

The SORT instruction sorts all the elements in an array into ascending order. The array can be composed of integers, strings or floating point numbers. The a$(0) indicates the starting point of the table to be sorted and must always be the first item in the array.

MATCH (t(0),s)

The match function searches through a SORTed table and returns the item number in which the value s was found. If a match is not found, a negative value is returned, the absolute value of this number contains the index of the first item which was greater than s.

Providing the array is only of one dimension, it can be of type integer,string or real.The array should always be SORTed before MATCHing.

Memory Banks

STOS basic includes a number of powerful facilities for the manipulation of sprites, screens and music. The data for these functions needs to be stored along with The basic program.

STOS basic uses a special set of 15 sections of memory for this purpose called Banks. Each bank is referred to by a unique number ranging from 1-15. Many of these banks can be used for all types of data, but some are dedicated solely to one sort of information such as sprite definitions. Every program stored in the ST's memory has its own separate set of banks. There are two different forms of memory bank: permanent and temporary.

Permanent banks only need to be defined once, and are subsequently saved along with your program automatically. Temporary banks however, are much more volatile and are reinitialised every time a program is run. Furthermore, unlike permanent banks, temporary banks are erased from memory by the CLEAR command.

Types Of Memory Banks

Class Stores Restrictions Type 
Sprites Sprite definitions Only bank 1 (1) Permanent 
Icons Icon definitions Only bank 2 (1) Permanent 
Music Music Only bank 3 (1) Permanent 
3D Future 3D extension Only bank 4 (4) Permanent 
Set holds new character sets Banks 1-15 Permanent 
Screen Stores a complete screen Banks 1-15 Temporary 
Datascreen Stores a screen Banks 1-15 Permanent 
Work Temporary workspace Banks 1-15 Temporary 
Data Permanent workspace Banks 1-15 Permanent 
Menu Menu lines Bank 15 (2) Temporary 
Program Machine code program Banks 1-15 (3) Varies 
 
  1. Bank is not really general purpose. It is allocated automatically by the appropriate accessory, or when a bank of this type is loaded.
  2. Reserved automatically by Menu commands. Usable by programs which don't use menus.
  3. Reserved as either work or data. Renamed when program loaded into bank. See LOAD.
  4. Reserved for future expansion

LISTBANK

lists the numbers of the banks currently reserved by a program, along with their location and size.

HEXA ON/OFF

As a default these values are printed out in hexadecimal notation. You can change the format to decimal by typing HEXAOFF.

RESERVE RESERVE AS SCREEN bank

Reserves a temporary bank of memory for a screen. This bank is always 32K long.

RESERVE AS DATASCREEN bank

Reserves a permanent bank 32K long for use as a screen. The screen is saved along with your program.

RESERVE AS SET bank,length

Reserves a permanent bank length bytes long for use as a character set.

RESERVE AS WORK bank,length

Reserves a temporary bank for use as a work space length bytes long.

RESERVE AS DATA bank,length

Reserves a permanent bank length bytes long for use as a workspace.

 Note that bank may be any number from 1 to 15, but since the system normally reserves banks 1 to 4, it's wise to leave these banks alone.

Copying Banks

BCOPY source TO dest

Copy the contents of bank source to bank dest. source and dest can range from 1-15.

BGRAB prgno(,b]

BGRAB copies one or more banks stored at program progno into the current program.  Program numbers between 1-4 denote one of the four programs that can reside in memory at any one time. Numbers from 5-15 represent an accessory.

If the optional b is not included, then all the banks attached to the program progno are copied into the current program, and any other banks of memory linked to this program are erased. Otherwise, the bank number specifies one bank which is to be transferred into the current program, all other banks then remain unchanged.

Deleting Banks

ERASE b delete bank b. Any memory used by bank b is now freed for use by the program.

Bank Parameter Functions

B=START(b) This function returns the start address of bank b.

B=START(prgno,b) This function returns the start address of bank b of program number prgno:b can range from 1 to 15 and prgno from 1 to 16.

B=LENGTH(b) This function returns the length of bank b.

B=LENGTH(prg,b) This function returns the length of bank b of program prg.

Saving And Loading

SAVE Here is a summary of the various data types that can be saved with the SAVE command along with their extensions:
 
Type Extension Comments
Basic programs BAS Normal basic program 
Accessories ACB Load using ACCLOAD 
Images PI1 Degas format Low screen
Images PI2 Degas format Med screen
Images PI3 Degas format Hi screen
Images NEO Neochrome format.Only in Low res. 
Memory bank MBK One memory bank
Memory banks MBS All current banks
Basic variables VAR All currently defined variables 
Listings ASC in Ascii format
RUN-ONLY programs PRG Executable directly from GEM Desktop
If none of these extensions are used then STOS adds .BAS to the filename automatically, and saves the current Basic program on to the disc.

BSAVE file$,start to end

Saves a memory block named file$ from start to end ;eg. BSAVE "\STOS\8X8.CRO", START(5) TO START(5)+LENGTH(5)

Run Only Programs

SAVE "filename.prg"

This option saves a version of your program in a special format which allows it to be loaded and executed directly from Gem Desktop. In order to use this function, you should first prepare a disc using the STOSCOPY.ACB accessory. This makes a copy of the entire \STOS\ directory on the disc. This disc can now be used to hold your run-only program. NEVER SAVE A RUN-ONLY PROGRAM ON THE ORIGINAL SYSTEM DISC !

When you save one of these programs, two files with the same name are created on the disc. One file has the extension .BAS and is stored in the \STOS\ folder. The second has a .PRG extension and lies outside the folder. It is this file which can be executed directly from the Gem Desktop. When a runonly program terminates or an error occurs, it immediately returns to Gem. Notes:

  1. Any attempt to execute the STOS Basic editor from a run-only program will crash the ST completely.
  2. The files PIC.PI1 and PIC.PI3 in the STOS folder contain low and high resolution pictures which will be displayed automatically during loading. If you like, you can omit these files from the disc to save space or alternatively replace them with your own pictures.
  3. The default colours used by your program will be the standard ones used by Gem Desktop, and not the normal STOS basic colours.
  4. Any of your own programs installed as RUN ONLY may be freely distributed or sold providing you acknowledge that they were written in STOS basic and use the protect accessory when giving the disc to anyone who has not bought a copy of STOS basic.
  5. If you place the RUN ONLY program in the \AUTO\ folder it will load and run automatically, whenever the disc is booted up.
  6. For more information see Appendix B.

LOAD:

Load all or part of a STOS basic program. All the various forms of saving a program are complemented with LOAD, with the following additional notes:

LOAD "filename"

Assumes .BAS and will load as if LOAD "filename.bas" was used.

LOAD "Filename.MBK"[,b]

This loads a single datafile into memory bank b. If the optional b is omitted then the bank is loaded into the bank from which it was saved. Note that this operation deletes any previous contents of a bank when executed.Furthermore, the LOAD instruction automatically reserves a bank of the appropriate type if it has not already been defined.

BLOAD

Load binary information into a specified address or memory bank.

BLOAD file$,addr

The file file$ will be loaded into the address addr.

BLOAD file$,bank

The file file$ is loaded into memory bank bank. The start address of the bank being used can be found using the start command, eg. bkaddr=start(bank) will return the start address of bank.

Machine-Code Programs

LOAD "filename.prg",b

This instruction allows you to load a machine-code program into a memory bank number b. Any program you wish to use in this manner should be stored in TOS relocatable format, and must be placed in a file ending with the ".PRG" extension. DO NOT TRY TO USE GEM-BASED PROGRAMS FOR THIS PURPOSE ! You should also avoid accessing any of the memory management functions from Gemdos. All other functions may be used, providing you take care.

You can call one of these functions using the CALL instruction like so: CAll START(bank). Note that when you copy a bank containing a program into another bank, this is automatically relocated for you.

The Accessories

The STOS basic accessories are special programs which lie dormant in the ST's memory until you call them up using the [HELP] key.

ACCLOAD

Load an accessory. Before you can use one of these accessories you must first load it into memory using the ACCLOAD command

ACCLOAD "name.ACB"

Loads the accessory from the file name into memory. Any normal Basic programs you have entered will be unaffected. You can use this function to load all the accessories on a disc by typing in accload "*"
 

ACCNEW

Remove ALL the currently installed accessories from memory.

CALLING AN ACCESSORY

A list of all the currently available accessories can be found by pressing the [HELP] key at any time.Press the function key associated with the accessory you require. This can only be done whilst the HELP menu is active.

CONTROLS:

ARROW KEYS 
INSERT 
HOME 
ENTER. 
UNDO
Move the cursor around the screen. 
Displays the last page of data. 
Displays the next page of data. 
Enters any changes into memory. 
Reverses the changes. 

Creating An Accessory

The only major difference between a STOS basic accessory and a normal program is in its ability to be called up using the HELP menu. In fact, these accessories are really just a specialised form of the multiple programs I mentioned earlier. It's often useful for an accessory to be able to tell whether it is executing as an accessory or directly as a basic program. This can be done with the ACCNB function.

ACCNB Get accessory number. Returns a value of 0 if a program is not installed as an accessory, and a number between 4 and 15 if it is. This number represents the program number of the accessory. To save a program as an accessory, simply append the .ACB file descripter.