BASIC Interpreter for MK14
Written by J.G. Seal, originally published in Computing Today April 1980 . Download from here
BASIC on an MK14, you must be joking ! Well here it is in all its glory to show you the way.
I bought an MK14 kit at the beginning of 1979. After assembly it worked first time, and I went on to spend many happy hours familiarising myself with the programming code. I am a teacher, and it rapidly became clear to me that here was a machine that had great possibilities as an aid to the teaching of computing, in its early stages, but that there were three major problems which would have to be overcome :-
As a first step towards overcoming these problems, I replaced the keyboard with a set of small push switches (Maplin Ref FF87U) the pins of which fitted exactly the holes in the PCB. However, I still got double bounce errors, and only overcame these when I removed from each switch the snap washer which gave it its "click effect".
Next, I replaced the miniature LED display strip with a display made up on a piece of Veroboard from eight 0.3 inch LED digits. This gave a readout which is easily viewed by several people at once.
Finally, I installed 1.5k of additional RAM, addressed as indicated in the Mk14 instructions. The voltage regulator on he Mk14 proved able to supply this extra RAM, and also a tape interface module, but required a heatsink.
I then turned my attention to the development of the high level language. None of the existing forms of BASIC would go into the memory I had available. This consisted of a total of 2k but some of this was dedicated to the Mk14 Monitor, and I wanted some for a data store. From what was left I had to find working space, program storage space, and space for the interpreter. It was clear that a compromise between all these demands was going to be difficult to work out.
I decided to attempt to devise a very simple subset of BASIC and to call this micro-micro subset PICO BASIC. In this language the four basic arithmetic rules + - * / would be essential. The four BASIC instructions which seemed to me to be most necessary were INPUT, PRINT, GOTO and an IF. And I wanted to be able to store and read data. It was clear that with a hexadecimal keyboard I would have to use single keys for each instruction, and would have to implement some form of upper and lower case system.
I decided from the beginning to aim at an integer arithmetic and had hoped to cater for both negative and positive numbers. But as the system developed this had to go and PICO now operates four-digit positive arithmetic (mod 10,000). However, it is surprising how much useful computing can in fact be done within this limitation.
Description of the Language
The MK14 Keyboard is used as indicated in the table. Some of the keys are relabelled for convenience in use. The PICO interpreter is entered from tape as shown in the memory maps.
The overall memory map is shown here. Pico Basic requires memory between 0200 and 07FF.
Map of Available RAM
The 512 bytes of PICO program store allow the running of programs up to 56 lines. The serial data file will hold 77 2-digit numbers, or with a small change in the interpreter, 38 4-digit numbers.
General Form of PICO Statements
n n x x x x x x x x
Entering PICO Programs
Execution of Programs
Statements are executed in the order of their line numbers, regardless of the order in which they were entered. If two or more lines have the same line number , only the last entered is executed. A line can thus in effect be overwritten, and it may in effect be deleted by entering the line number on its own.
Error Detection and Correction
Error detection is written into the interpreter. When the computer attempts to execute at run time a line containing an error in syntax, the run halts and ? is displayed. The number of the line which caused the halt can be discovered by the following procedure :-
To see what is in that line number
To alter the line, proceed as follows. If now alteration is required, jump to step 5. below.
If it is desired to alter aline without the necessity of seeing it first, follow these steps.
The MK14 keyboard is remapped as follows.
INPUT (e.g. 01Inv4)
To enter this press 0 1 [SHIFT] INPUT [SHIFT] 4
At run time this statement produces the display v4=? and the run halts to await entry of a number. If more than 4 digits are entered, only the last four are retained.
After the number has been entered, press RUN to resume execution of the program. The number will be stored in variable v4, one of 10 available variables which are designated v0 to v9.
PRINT (e.g. 02Prv5)
To enter this press 0 2 [SHIFT] PRINT [SHIFT] 5
At run time this statement produces the display v5=xxxx, the number stored in v5. Leading zeroes are suppressed. Press RUN to continue execution.
GOTO (e.g. GO06)
This causes the program to jump immediately to line 06. If the destination line number does not exist in the program execution will jump to the first one above it, or, failing that to the start of the program.
IF (e.g. IFv5v608)
As the last two characters are entered, the line number disappears of the left of the display. This statement is equivalent to the normal BASIC Statement
IF V5 >= V6 THEN 08
It causes execution to move immediately to line 08 if the number in v5 is greater than or equal to the number in v5. If v5 is less than v5 execution continues at the next higher line number above 04. By reversing the positions of v5 and v6 the effect v5<=v6 is obtained. This is the most useful single conditional jump statement.
ASSIGN CONSTANT (e.g. 05v7=xxxx)
This causes the number xxxx to be stored in v7
ASSIGN VARIABLE (e.g. 06v8=v7)
This causes the contents of v7 to be also stored at v8
The four functions add, subtract, multiply and divide may be invoked but unlike conventional BASICs only one calculation may take per program line. In the example below f stands for any one of the four functions.
This is the general form, and a & b stand for numbers of variables. A maximum of 5 display digits is available for afb. When both a and b are variables these are fully used
When a or b is a variable and the other is a number, the number may not have more than 2 digits.
When both a and b are numbers, the total number of their digits may not exceed 4. When it is desired to use larger numbers they must first be assigned to variables.
Notes on the calculations
Input & Load Data
A serial data file for up to 77 2-digit numbers is available. A modification of the interpreter will change this to 38 4-digit numbers if required. During each program run the numbers are normally accessed in order from the beginning of the file using these statements.
e.g. 08Idv9 and 09Ldv6
The first statement causes the two right hand digits of the number in v9 (the whole number if the four digit file is in use) to be stored at the next file location. The second causes the contents of the next file location to be stored at v6.
The number of the file location to be next accessed is held in 0 in hexadecimal. It is incremented by 1 after each access. By storing a decimal number from 00 to 49 in v0, 50 of the file locations can be directly accessed at any point in a program. By treating the two figures of this number as array subscripts it is possible to implement a 5 x 10 array.
Data may be entered during one program run and retrieved at a later date by a different program, providing that the computer has not been switched off. It can also , of course, be transferred to tape for permanent storage.
Notes on Programming
This simple program displays successive multiples of a chosen number.
Note the closed loop with the print statement in it. In conventional BASIC this would produce an endless succession of multiples which could only be halted by breaking into the program run. In PICO the run halts each time the PRINT statement is reached, to be resumed by pressing RUN. But as in normal BASIC the only way to get out of the loop is by returning to the monitor.
This loop is used to enter data into the serial data file.
MEAN OF NUMBERS IN DATA FILE
This program includes the use of a stop value (rogue value) at the end of the data to get out of the load loop
DIVISION WITH DECIMAL PLACES
The first run produces the integer part of the answer. Each successive press of RUN produces one decimal place of the answer.
The integer part of the square root of a given number is produced by the usual iterative method.
There follows a listing of the interpreter. It is highly probable that by careful consideration of each section of the interpreter it will be possible to prune it and thus release extra memory for the inclusion of desirable refinements such as a simplified way of displaying any line of the program in store.