MMBasic supports program entry and editing commands, as well as commands to save/load programs from the two “drives” that the hardware supports.
COMMAND AND PROGRAM INPUT
At the command prompt (the greater than symbol, ie, > ) you can enter a command line followed by the enter key and it will be immediately run. This is useful for testing commands and their effects.
Line numbers are optional. If you use them you can enter a program at the command line by preceding each program line with a line number however; it is recommended that the full screen editor (the EDIT command) be used to enter and edit programs.
When entering a line at the command prompt the line can be edited using the arrow keys to move along the line, the Delete key to delete a character and the Insert key to switch between insert and overwrite. The up arrow key will move through a list of previously entered commands which can be edited and reused.
A program held in memory can be listed with LIST, run using the RUN command and cleared with the NEW command. You can interrupt MMBasic at any time by typing CTRL C (can be redefined with OPTION BREAK) and control will be returned to the prompt.
Input can come from either a keyboard or from a computer using a terminal emulator via the USB or serial interfaces. Both the keyboard and the USB interface can be used simultaneously and can be detached or attached at any time without affecting a running program.
Output will be simultaneously sent to the USB interface and the video display (VGA or composite). Either can be attached or removed at any time.
LINE NUMBERS, PROGRAM STRUCTURE, AND EDITING
In version 3.0 of MMBasic and later versions the use of line numbers is optional. MMBasic will still run programs written using line numbers, but it is recommended that new programs avoid them.
The structure of a program line is:
[line-number] [label:] command arguments [: command arguments] …
Instead of using a line number a label can be used to mark a line of code. A label has the same specifications (length, character set, etc) as a variable name but it cannot be the same as a command name. When used to label a line the label must appear at the beginning of a line but after a line number (if used), and be terminated with a colon character (:). Commands such as GOTO can use labels instead of line numbers to identify the destination (in that case the label does not need to be followed by the colon character). For example:
- - -
xxxx: PRINT "We have jumped to here"
MMBasic finds a label much faster than a line number so labels are recommended for new programs.
Multiple commands separated by a colon can be entered on the one line (as in INPUT A : PRINT B).
Long programs (with or without line numbers) can be sent via USB to MMBasic using the XMODEM command or the AUTO command.
STORAGE COMMANDS AND FUNCTIONS
A program can be saved to either drive using the SAVE command. It can be reloaded using LOAD or merged with the current program using MERGE. A saved program can also be loaded and run using the RUN command. The RUN command can also be used within a running program, which enables one program to load and transfer control to another.
You can list the programs stored on a drive with the FILES command, delete them using KILL and rename them using NAME. On an SD card the current working directory can be changed using CHDIR. A new directory can be created with MKDIR or an old one deleted with RMDIR.
Whenever specified a file name can be a string constant (ie, enclosed in double quotes) or a string variable. This means you must use double quotes if you are directly specifying a file name. Eg, RUN “TEST.BAS”
On the SD card programs are stored using standard text and can be read and edited in Windows, Apple Mac, Linux, etc.
Full Screen Editor
An important productivity feature of MMBasic is the full screen editor It will work using an attached video screen (VGA or composite) and over USB with a VT100 compatible terminal emulator.
The full screen editor is invoked with the EDIT command. If you just type EDIT without anything else the editor will automatically start editing whatever is in program memory. If program memory is empty you will be presented with an empty screen.
The cursor will be automatically positioned at the last place that you were editing at and, if your program had just been stopped by an error, the cursor will be positioned at the line that caused the error.
You can also run the editor with a file name (eg, EDIT “file.ext”) and the editor will edit that file while leaving program memory untouched. This is handy for examining or changing files on the disk without disturbing your program.
If you are used to an editor like Notepad you will find that the operation of the full screen editor is familiar. The arrow keys will move your cursor around in the text, home and end will take you to the beginning or end of the line. Page up and page down will do what their titles suggest. The delete key will delete the character at the cursor and backspace will delete the character before the cursor. The insert key will toggle between insert and overtype modes.
About the only unusual key combination is that two home key presses will take you to the start of the program and two end key presses will take you to the end.
At the bottom of the screen the status line will list the various function keys used by the editor and their action.
In more details these are:
|ESC||This will cause the editor to abandon all changes and return to the command prompt with the program memory unchanged. If you have changed the text you will be asked if this is really what you want to do.|
|F1: SAVE||This will save the program to program memory and return to the command prompt. If you are editing a disk file it will save that file to the disk.|
|F2: RUN||This will save the program to program memory and immediately run it.|
|F3: FIND||This will prompt for the text that you want to search for. When you press enter the cursor will be placed at the start of the first entry found.|
|SHIFT-F3||Once you have used the search function you can repeatedly search for the same text by pressing SHIFT-F3.|
|F4: MARK||This is described in detail below.|
|F5: PASTE||This will insert (at the current cursor position) the text that had been previously cut or copied (see below).|
If you pressed the mark key (F4) the editor will change to the mark mode. In this mode you can use the arrow keys to mark a section of text which will be highlighted in reverse video. You can then delete, cut or copy the marked text. In this mode the status line will change to show the functions of the function keys in the mark mode. These keys are:
|ESC||Will exit mark mode without changing anything.|
|F4: CUT||Will copy the marked text to the clipboard and remove it from the program.|
|F5: COPY||Will just copy the marked text to the clipboard.|
|DELETE||Will delete the marked text leaving the clipboard unchanged.|
The best way to learn the full screen editor is to simply fire it up and experiment.
The editor is a very productive method of writing a program. Using the OPTION Fnn command you can program a function key to generate the command “EDIT” when pressed. So, with one key press you can jump into the editor where you can make a change. Then by pressing the F3 key you can save and run the program.
If your program stops with an error you can press the edit function key and be back in the editor with the cursor positioned at the line that caused the error. This edit/run/edit cycle is very fast.
If you are using the full screen editor over USB with Terra Term you must set Terra Term to a screen size of 80 characters by 36 lines.
Note that a terminal emulator can loose its position in the text with multiple fast keystrokes (like the up and down arrows). If this happens you can press the HOME key twice which will force the editor to jump to the start of the program and redraw the display.