Chapter 3

The System Mode


The BASIC09 command interpreter processes system commands. At the H : prompt, you can enter system commands in either upper- or lowercase letters. Some commands operate on the procedures in the workspace. Others provide functions independent of any procedures. Following is a list of all system commands and their purposes.


Command Function

$ Calls the shell command interpreter to execute


BYE or Returns you to the OS-9 system or to the pro
gram that called BASIC09.
CHD Changes the current OS-9 data directory.
CHX Changes the current OS-9 execution directory.
ENTER Or DIR Displays the name, size, and variable storage
requirement of each procedure in the
workspace.
EDIT or E Enters the procedure editor-compiler mode.
KILL Erases one or more procedures from the work
space.
LIST Displays a formatted listing of one or more
procedures.
LOAD Loads all procedures from a disk file into the
workspace.
MEM Displays in bytes the current workspace size,
or reserves a specified amount of memory for
the workspace.
PACK Condenses (compiles) one or more procedures.
RENAME Changes a procedure's name.
RUN Causes a procedure in the workspace to
execute.
SAVE Writes one or more procedures to disk.

3-1
BASIC09 Reference

Renaming Procedures

BASIC09's RENAME function is important for two reasons: First, it lets you load into the workspace procedures that have the same name. After you rename the workspace procedure you can load the second file. Second, if you let BASIC09 use the default procedure name, "Program," you can rename the procedure before saving it to disk. By doing this, you avoid writing over and destroying an existing procedure file.


To change the name of the procedure you created in the previous chapter from Program to Add, type:




Listing Procedure Names

You can use the DIR command to see if RENAME worked properly. DIR displays the names and sizes of all procedures in memory. Because programmers use this command frequently, the system recognizes a shorthand call. Instead of typing d i r ENTER , you only need to press ENTER . This displays a table of the procedures in the following format:








Proc-Size refers to the number of memory bytes required for the procedure. Data-Size refers to the number of memory bytes required for the procedure's variables and data structures. The asterisk indicates the current procedure. System commands act on the current procedure unless you indicate otherwise.


The last line of the DIR display tells you how many free bytes of memory remain in the BASIC09 workspace.


Listing Procedures

You can use the LIST command to view procedure lines. To display the current procedure, type:




3-2


For example, this is the listing of a procedure named Alpha.bak:
















When you list a BASIC09 procedure, the system precedes each line with a relative storage address. The relative address of the first procedure line is always 0. In the previous example, the beginning address of the second procedure line in the workspace is 07 units from the beginning. The beginning address of the third line is OE hexadecimal (14 decimal) storage units from the procedure beginning.


These I-Code addresses provide a way for the compiler to let you know where it finds an error when one occurs.


Because BASIC09 compiles programs into I-Code, it must disassemble them before it can display them on the screen. This means that the lines might not look exactly as typed. For instance, BASIC09 converts lowercase keywords (command names) to uppercase. BASIC09 also eliminates some spaces. If your program uses control statements such as IF/THEN, FOR/ NEXT, and LOOP/ENDLOOP, the lines in these decision making or looping structures are indented as shown in the Alpha.bak example. Regardless of the appearance of your listed procedures, they execute correctly if you type their commands correctly.



BASIC09 Reference

Listing Procedures to a File

There might be times when you want to send a formatted procedure listing, including I-Code addresses, directly to a file. You can do this using OS-9's redirection symbol, > . To save the Alpha.bak procedure on a file named Alphadist in the current data directory, type:




If you have several procedures in the workspace and want to list more than one to a disk file, separate the procedure names with commas, like this:




In both of the preceding cases, the system creates the Alpha.list file and stores the specified listings in it. If you use a file name that already exists, BASIC09 displays the prompt:




If you press E], the system destroys the original file and overwrites it with the new listing. If you press CK, the LIST process terminates.


If you wish to list a procedure, or group of procedures, to a file that is not in the current data directory, be sure to specify the complete pathlist, such as:




Listing Procedures to a Printer

In the same manner as you list procedures to a disk file, you can list one or more procedures to your printer. Make certain your printer is connected and turned on, then again use the redirection symbol, but this time specify the printer device, like this:




Or:



3-4
The System Mode / 3

Using a Wildcard

Using the OS-9 wildcard, *, you can list all procedures in the workspace. For instance, if the procedures Alpha.one, Alpha.two, and Alpha.three exist, list them to the screen by typing:




Send the list to a file by typing:



Or send the list to your printer by typing:



Note: When you use the wildcard, the name of the file or device to receive the listing immediately follows the LIST* command. Do not use the redirection symbol.

Saving Procedures

You can save one or more procedures to disk using the SAVE command. Unlike LIST, SAVE does not include relative addresses. However, the syntaxes for the SAVE and LIST commands are identical. To save the procedure Alpha.bak to the current data directory, type:




If Alpha.bak is the current procedure, you can save it in a file named Alpha.bak by typing save ENTER .


To save all of the procedures in the workspace to a file named All.programs in the current data directory, type:




As with LIST, to save one or more procedures in a file that is
not in the current data directory, make sure you specify a com
plete pathlist. -

To save all the files in the workspace to a disk file with the same name as the current procedure, type 5 a v e * ENTER .


If the disk file you specify does not exist, BASIC09 creates it. If it does exist, the system displays the prompt:





BASIC09 Reference

Press E to write over the old file with the specified file. The old file is destroyed.


Press (E to terminate the SAVE operation.`'`

Loading Procedures

To load a saved procedure back into BASIC09's workspace, use the LOAD command and specify the appropriate pathlist. For instance, if your current directory is still the directory containing Alpha.bak, load the procedure by typing:


    load alpha. bak ENTER


To load Alpha.bak from the PROGRAMS directory on Drive /D1, type:


    load /d1 /program5/alpha. rev ENTER


You can run and edit a loaded procedure in exactly the same manner as you would a procedure you created.


You can load any number of procedures into the workspace as long as your computer has sufficient memory. However, be careful that you do not load a procedure with the same name as a procedure already existing in the workspace. If you do, the new procedure overwrites (destroys) the original procedure. You can rename workspace procedures to avoid this problem.


Deleting Procedures from the Workspace

You can clear the workspace of one or more procedures using the KILL command. For instance, to remove Alpha.bak from the workspace, type:


    kill alpha.bak ENTER


To remove more than one procedure from the workspace, separate the procedure names with commas. To delete Alpha.one and Alpha.two, type:


    kill alpha.one,alpha.two ENTER


To clear the entire workspace, regardless of the number of procedures it contains, use the BASIC09 wildcard, *. Type:


    k i 1 1 * ENTER


3-6
The System Mode / 3

Changing Directories

You change working directories in BASIC09 and OS-9 in the same manner, by using the CHD and CHX commands. CHD changes the data directory, and CHX changes the execution directory.


BASIC09 saves files in, or loads files from, the data directory, unless you specify differently in the command pathlist. It stores packed procedures in, or loads PACKed procedures from, the execution directory, unless you specify differently in the command's pathlist.


Also, if you want to access OS-9 commands from BASIC09, the system first looks for the commands in memory. If they are not there, it looks for them in the execution directory, unless you specify differently.


If your data directory is the ROOT directory, and you wish to change to a directory named PROGRAMS that is a subdirectory of the ROOT directory, type the following command from the command mode B : prompt


    chd programs ENTER


If your current execution directory is the system's CMDS directory, and you want to change to a CMDS directory in the subdirectory BASIC, type:


    chx basic/cmds ENTER


Whenever you change to a directory other than an immediate subdirectory, specify a complete pathlist.


Executing OS-9 Commands

BASIC09 lets you use OS-9 commands at any time from the system mode. To do so, precede the command with a dollar sign ($). For instance, to look at the current data directory, type: _


To view the current execution directory, type:

3-7
BASIC09 Reference

All OS-9 commands are available, and you can copy files, format diskettes, list files, or use any other functions from the system mode. The only restriction is that your computer must have enough free memory to handle the command you call. If you find that there is not enough memory, try using the MEM command to reduce reserved memory. Then, try the command again.


Auto-Execute Procedures

The BASIC09 compiler makes two passes through the procedures you write. When you enter the command, the compiler performs an initial compilation, checking for any syntax errors. When you leave the edit mode, the system compiles the procedure a second time and checks for any programming errors. With the PACK command, you can further compile your procedures so that they are smaller and execute even faster.


PACK causes an extra compiler pass that removes names, line numbers, and non-executable statements. Before packing a procedure, be sure you save it. Unless you do so, you cannot make further changes to the procedure.


Once you pack a file, you cannot list or edit the packed version. However, if you save the procedure to disk before packing, you can still list and edit the original file, then pack it again.


When you save a packed procedure on disk, BASIC09 does not normally store it in the data directory. Because the procedure is now executable, the system stores it in the current execution directory.


For instance, to convert Alpha.bak to a packed procedure in the execution directory, type:


    pack a 1 pha . ba k ENTER


If you want to save a packed procedure under a different filename, use the OS-9 redirection symbol:


    pack alpha.bak > backward5 ENTER


After packing a procedure, you can delete it from the workspace. If you then run it, BASIC09 automatically loads the file from disk and executes it.


The following is a sequence of commands that demonstrate packing and executing a procedure named Alpha.bak:


3-8
The Svstem Mode / 3

    pack a 1 p h a . b a k ENTER packs the procedure and stores

    it in the execution directory.

    kill a 1 p h a . b a k ENTER deletes the procedure from the

    workspace.

    run a 1 p h a . b a k ENTER loads the file into memory

    outside the workspace and

    executes it.

    kill a 1 p h a . b a k ENTER deletes the module from

    memory


You do not need to kill the file immediately after execution, but until you do, the file reduces available memory.

3-9