8K BASIC
PROGRAMMING
MANUAL
A rewrite of the original Nascom2 BASIC Programming Manual. Updated for searchability and clarity while staying close to the original layout. js, November 27-2016.
Nascom 8K Basic is based on Microsoft Basic, which has become the industry standard, and offers a high degree of compatibility with programs published in books and magazines.
It offers 7-digit floating point numbers in the range 1.70141E38 to 2.9387E-38, full trigonometric functions, string handling and I/O control. User functions can be written in machine code or Basic to provide additional flexibility.
Extra Features
- Works with Nasbug T2, T4 and Nas-sys
- With Nas-sys: powerful on-screen, in-line editing facilities for data and programs
- Clear screen and cursor positioning functions for screen formatting
- Improved LIST command for use with Nascom display
- Support of printers or terminals attached via serial interface
- Improved cassette handling with program identification and error checking
- Support of Nascom graphics options using
SET,RESETandPOINTcommands
1-1 Introduction to this Manual
This manual describes the features offered by Nascom 8K Basic. It is not intended as an introduction to programming in Basic — many such books are available elsewhere (see Appendix H).
a. Conventions
- Words printed in capital letters must be written exactly as shown. These are mostly names of instructions and commands.
- Items enclosed in angle brackets
<>must be supplied as explained in the text. Items in square brackets[]are optional. Items in both kinds of brackets, e.g.[<W>], are to be supplied if the optional feature is used. Items followed by dots...may be repeated or deleted as necessary. - Shift/ or Control/ followed by a letter means the character is typed by holding down the Shift or Control key and typing the indicated letter.
- All indicated punctuation must be supplied.
b. Definitions
- Alphanumeric character
- All letters and numerals taken together.
- Enter / Newline / Carriage Return
- Refers both to the key on the terminal which causes the cursor to move to the beginning of the next line, and to the command that the return key issues which terminates a BASIC line.
- Command Level
- After BASIC prints
OK, it is at the command level — ready to accept commands. - Commands & Statements
- Commands are instructions normally used only in direct mode. Statements are instructions normally used in indirect mode. Some, such as
DEF, may only be used in indirect mode. - Edit
- The process of deleting, adding and substituting lines in a program, or of preparing data for output according to a predetermined format. The particular meaning will be clear from context.
- Integer Expression
- An expression whose value is truncated to an integer. The components need not be of integer type.
- Reserved Words
- Words reserved by BASIC for use as statements and commands. They may not be used in variable or function names.
- String Literal
- A string of characters enclosed by quotation marks (
") to be input or output exactly as it appears. The quotation marks are not part of the string literal, nor may a string literal contain quotation marks. - Type
- This manual uses the word "type" to refer to the process of entry. The user types; the computer prints. Type also refers to the classifications of numbers and strings.
1-2 Modes of Operation
Nascom BASIC provides for operation in two different modes:
- Direct Mode
- Statements or commands are executed as they are entered. Results are displayed and stored, but the instructions themselves are lost after execution. Useful for debugging and quick calculations.
- Indirect Mode
- The computer executes instructions from a program stored in memory. Program lines are entered if preceded by a line number. Execution is initiated by the
RUNcommand.
1-3 Formats
a. Lines
The line is the fundamental unit of a Nascom BASIC program:
nnnnn <BASIC statement>[:<BASIC statement>...]
Each line begins with a number (0 to 65529) that indicates the order of execution and provides for branching and editing. A good practice is to use an increment of 5 or 10 between successive line numbers to allow for insertions.
More than one statement may be written on one line if separated by colons (:). Lines must be no more than 72 characters long. When used with Nas-sys in normal mode, lines cannot exceed 48 characters. 72-character lines can be inserted by entering Monitor mode, issuing an X0 command, and returning to Basic by typing Z.
b. REMarks
The REM statement allows comments to be included without affecting execution:
REM <remarks>
A REM statement is not executed by BASIC, but branching statements may link into it. REM statements are terminated by the carriage return or end of line — not by a colon.
100 REM DO THIS LOOP: FOR I=1TO10 — the FOR will NOT be executed 101 FOR I = 1 TO 10: REM DO THIS LOOP — this FOR WILL be executed
c. Error Messages
When the BASIC interpreter detects an error, it prints:
Direct statement: ?XX ERROR Indirect statement: ?XX ERROR IN nnnnn
XX is the error code (see section 6-5); nnnnn is the line number where the error occurred.
1-4 Editing — Elementary Provisions
The following facilities are available with Nasbug T2 and T4 and Nas-sys in X0 mode (supporting an external terminal).
a. Correcting Single Characters
If an incorrect character is detected while typing, it can be corrected immediately with the backspace key. Each stroke deletes the immediately preceding character. If there is no preceding character, a carriage return is issued and a new line is begun.
When RUBOUT (Control Z) is typed, the previous character is deleted and echoed. Each successive RUBOUT prints the next character to be deleted.
100 x==x Y=10 Typing two RUBOUTS deleted '=' and 'X',
subsequently replaced by Y=
b. Correcting Lines
A line being typed may be deleted by typing an at-sign (@) instead of carriage return. A carriage return is printed automatically. Typing Control/U has the same effect.
c. Correcting Whole Programs
The NEW command causes the entire current program and all variables to be deleted. Generally used to clear memory before entering a new program.
1-5 Program Input with Nas-sys
When used with Nas-sys, the full range of editing facilities are available, and the line displayed on the screen is passed to the Basic interpreter by the Enter or Newline key. This allows you to list a program, edit lines on the screen and re-enter updated lines. Note that data input is normally dealt with character by character as outlined in 1-4 above.
2-1 Expressions
The simplest BASIC expressions are single constants, variables and function calls.
a. Constants
Nascom BASIC accepts integers, floating point real numbers or strings as constants. Examples of acceptable numeric constants:
123 3.141 0.0436 1.25E+05
Data input from the terminal may have any number of digits, but only the first 7 digits are significant and the seventh digit is rounded up. Therefore:
PRINT 1.234567890123
produces: 1.23457
Printed Number Format Rules
- If the number is negative, a minus sign is printed to the left. If positive, a space is printed.
- If the absolute value is an integer in the range 0 to 999999, it is printed as an integer.
- If the absolute value is between 0.01 and 999999, it is printed in fixed point notation.
- Otherwise, scientific notation is used:
SX.XXXXXESTT
| Input | Nascom BASIC Output |
|---|---|
+1 | 1 |
-1 | -1 |
6523 | 6523 |
1E20 | 1E20 |
-12.34567E-10 | -1.23456E-09 |
1.234567E-7 | 1.23457E-07 |
1000000 | 1E+06 |
.1 | .1 |
.000123 | 1.23E-04 |
-25.460 | -25.46 |
b. Variables
A variable represents symbolically any number assigned to it. Before a variable is assigned a value, its value is assumed to be zero. The variable name may be any length, but only the first two alphanumeric characters are significant. The first character must be a letter. No reserved words may appear within variable names.
| Legal | Illegal | Reason |
|---|---|---|
A | %A | First character must be alphabetic |
Z1 | ||
TP | TO | Cannot be a reserved word |
PSTG$ | RGOTO | Cannot contain a reserved word |
c. Array Variables — the DIM Statement
Nascom BASIC provides subscripted variables (arrays). The form of an array variable is:
VV(<subscript> [, <subscript>...])
Subscripts may be enclosed in parentheses or square brackets. The smallest subscript is zero. The DIM statement allocates storage and sets all elements to zero:
DIM VV(<subscript>[, <subscript>...])
113 DIM A(3), D$(2,2,2) 114 DIM R2(4), B(10) 115 DIM Q1(N), Z(2+I) ← dynamic dimensioning allowed
d. Operators and Precedence
e. Logical Operations
AND, OR, NOT convert their arguments into 16-bit signed two's complement integers (−32768 to 32767). Operations are performed bitwise.
| X | Y | X AND Y |
|---|---|---|
| 1 | 1 | 1 |
| 1 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 0 | 0 |
| X | Y | X OR Y |
|---|---|---|
| 1 | 1 | 1 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 0 | 0 | 0 |
| X | NOT X |
|---|---|
| 1 | 0 |
| 0 | 1 |
63 AND 16 = 16 (binary 111111 AND 010000 = 010000) 15 AND 14 = 14 (binary 1111 AND 1110 = 1110) -1 AND 8 = 8 4 OR 2 = 6 (binary 100 OR 010 = 110) NOT 0 = -1 (complement of sixteen zeros = sixteen ones = -1) NOT X = -(X+1)
f. The LET Statement
LET <VV> = <expression>
The word LET is optional. The = sign means "is replaced by":
1000 LET V = X 110 LET I = I+1 120 V = .5*(X+2) ← LET is optional
2-2 Branching, Loops and Subroutines
a. Branching
1. GOTO — Unconditional Branch
GOTO <mmmmm>
Execution continues at line number mmmmm.
2. IF...THEN — Conditional Branch
IF <expression> THEN <mmmmm> IF <expression> THEN <statement>
If the expression is non-zero, BASIC branches to mmmmm or executes the statement. Otherwise, execution resumes at the next line.
10 IF A=10 THEN 40 ← branch if true 15 IF A<B+C OR X THEN 100 20 IF X THEN 25 ← branch if X is non-zero 30 IF X=Y THEN PRINT X ← execute statement if true 35 IF X=Y+3 GOTO 39 ← GOTO must be followed by a line number
3. ON...GOTO — Computed Branch
ON <expression> GOTO <list of line numbers>
The expression is truncated to an integer I. BASIC branches to the Ith line number in the list. If I=0 or exceeds the list length, execution continues at the next line. I must be in the range 0 to 255.
b. Loops — FOR and NEXT
FOR <variable> = <X> TO <Y> [STEP <Z>]
The variable is set to X (the initial value). When a NEXT statement is encountered, Z is added to the variable. If the variable is still within range, BASIC branches back to the statement after FOR. The default step is 1.
10 FOR I=2 TO 11 ← executes 10 times, I = 2..11 20 FOR V=1 TO 9.3 ← executes 9 times 30 FOR V=10*N TO 3.4/Z STEP SQR(R) 40 FOR V=9 TO 1 STEP -1 ← executes 9 times (counting down)
FOR...NEXT loops may be nested. The NEXT for the innermost loop must appear first.
100 FOR I=1 TO 10 120 FOR J=1 TO I 130 PRINT A(I,J) 140 NEXT J 150 NEXT I
NEXT [<variable>[,<variable>...]]
NEXT without a variable matches the most recent FOR. If BASIC encounters a NEXT without a corresponding FOR, an NF (NEXT WITHOUT FOR) error is issued.
c. Subroutines — GOSUB and RETURN
GOSUB <line number> ON <expression> GOSUB <list of line numbers>
A subroutine is a series of statements branched to by GOSUB. Execution of the subroutine is terminated by RETURN, which branches back to the statement after the most recent GOSUB. Subroutine nesting is limited only by available memory.
d. OUT OF MEMORY Errors
The OM (OUT OF MEMORY) error is issued when a program requires more memory than is available. See Appendix B for memory requirements.
2-3 Input / Output
a. INPUT
INPUT <list of variables> INPUT ["<prompt string>";] <variable list>
When executed, a question mark ? is printed, requesting input. Values are typed separated by commas, then Enter. Error responses:
REDO FROM START?— invalid data entered??— more data neededEXTRA IGNORED— more data typed than requested
100 INPUT "WHAT'S THE VALUE";X,Y WHAT'S THE VALUE? _
b. PRINT
PRINT ← prints a carriage return (blank line) PRINT list of expressions
Nascom BASIC divides the print line into zones of 14 spaces each.
| Punctuation | Next printing begins |
|---|---|
, | At beginning of next 14-column zone |
; | Immediately after the last value printed |
| none | At beginning of the next line |
c. DATA, READ, RESTORE
DATA Statement
DATA <list>
Stores a list of numerical or string constants for access by READ statements.
10 DATA 1,2,-1E3,.04 20 DATA "ARR", NASCOM
READ Statement
READ <list of variables>
Assigns values from DATA statements to the variables. If the READ list is exhausted before all variables are filled, an OD (OUT OF DATA) error is issued.
RESTORE Statement
After RESTORE, the next READ begins with the first entry of the first DATA list. This allows re-reading of data.
d. CSAVE* and CLOAD* for Arrays
CSAVE* <array name> CLOAD* <array name>
Numeric arrays may be saved to and loaded from cassette tape. The array is written in binary with four octal 210 header bytes. Elements are written with the leftmost subscript varying most quickly.
DIM A(10,10) CSAVE*A ← writes A(0,0), A(1,0)...A(10,0), A(0,1)...A(10,10)
e. Miscellaneous I/O
WAIT
WAIT <I,J> [,<K>]
Port status is XOR'd with K, then AND'd with J. Execution suspends until a non-zero result. I, J, K must be 0–255. K defaults to 0.
WAIT 20,6 ← wait until bit 1 or bit 2 of port 20 = 1 WAIT 10,255,7 ← wait until any of bits 3–7 = 1, or any of bits 0–2 = 0
POKE / PEEK
POKE <I,J> ← store byte J at address I (0≤J≤255) PEEK(<I>) ← read byte from address I (returns 0–255)
To POKE above address 32768, use a negative I: I = desired_address − 65536.
DOKE / DEEK
Double-length versions of POKE and PEEK. J may be in the range −32768 to +32767. The least significant byte is stored at address I, most significant at I+1. Useful for storing 16-bit numbers or addresses for machine code subroutines.
OUT / INP
OUT <I,J> ← send byte J to output port I (0≤I,J≤255) INP(<I>) ← read byte from port I (0≤I≤255)
20 IF INP(J)=16 THEN PRINT "ON"
Nascom BASIC allows functions to be referenced in mathematical function notation:
<name>(<argument>)
Only one argument is allowed. Function calls may be components of expressions:
10 LET T = (F*SIN(T))/P 20 C = SQR(A^2+B^2+2*A*B*COS(T))
3-1 Intrinsic Functions
See the full list in Section 6-3.
3-2 User-Defined Functions
a. The DEF Statement
DEF <function name>(<variable name>) = <expression>
The function name must be FN followed by a legal variable name. Only one argument is allowed. The expression must fit on one line. User-defined string functions are not allowed.
10 DEF FNFTOC(T) = (T-32)*5/9 12 DEF FNRAD(DEG) = 3.14159/180*DEG ← degrees to radians
A function may be redefined by executing another DEF with the same name. A DEF statement must be executed before the function it defines may be called.
b. USR
The USR function allows calls to assembly language subroutines. See Appendix D.
3-3 Errors
An FC (ILLEGAL FUNCTION CALL) error results when an improper call is made. Common causes:
- A negative array subscript:
LET A(-1)=0 - An array subscript that is too large (>32767)
- Negative or zero argument for
LOG - Negative argument for
SQR A^Bwith A negative and B not an integer- A call to
USRwith no address patched - Improper arguments to
MID$,LEFT$,RIGHT$,INP,OUT,WAIT,PEEK,POKE,TAB,SPC,INSTR,STRING$,SPACE$orON...GOTO
A UF (UNDEFINED USER FUNCTION) error occurs if a user-defined function is called before it has appeared in a DEF statement.
A TM (TYPE MISMATCH) error occurs if a function expecting a string argument is given a numeric value, or vice-versa.
4-1 String Data
A string is a list of alphanumeric characters from 0 to 255 characters in length. String constants are delimited by quotation marks. String variable names end with a dollar sign $.
A$="ABCD" ← four-character string B9$="14A/56" ← six-character string FOOFOO$="E$" ← two-character string
String arrays may be dimensioned with DIM. The total number of string characters in use must not exceed the string space allocation, or an OS (OUT OF STRING SPACE) error results. String space is set by the CLEAR command (default: 50 bytes).
4-2 String Operations
a. Comparison Operators
The same comparison operators used for numbers apply to strings. Comparison is made character by character on the basis of ASCII codes.
| Operator | Meaning |
|---|---|
= | Equal |
<> | Not equal |
< | Less than |
> | Greater than |
=<, <= | Less than or equal to |
=>, >= | Greater than or equal to |
A<Z (ASCII A=065, Z=090) 1<A (ASCII 1=049) " A">"A" (leading blanks are significant)
c. String Expressions
String expressions are composed of string literals, string variables and string function calls connected by the + (concatenation) operator. If the result exceeds 255 characters, an LS (STRING TOO LONG) error is issued.
d. Input / Output
10 INPUT ZOO$,FOO$ ← reads two strings 20 INPUT X$ ← reads one string 30 PRINT X$, "HI, THERE" ← prints two strings
Strings input without quotation marks will have leading blanks ignored and will be terminated by the first comma or colon encountered.
4-3 String Functions
String function names end with a dollar sign. See Section 6-3 for the full list.
Nascom 8K Basic has a number of commands not normally found in 8K Basics, providing monitor access, screen manipulation, printer support, and graphics.
a. MONITOR
Transfers control to the monitor. Restore control to Basic from Nas-sys using J (complete restart) or Z (warm start, preserving programs). If debugging machine code with breakpoints, return to Basic via EFFFA or EFFFD commands, as J and Z do not set breakpoints.
b. WIDTH N
Changes the assumed line buffer to N characters (range 1–255). Default is 47 characters. On output to the serial port, a newline is generated automatically after N characters. On input, the assumed line buffer is N or 72 characters, whichever is longer.
To adjust the PRINT zone calculation:
POKE 4163, (INT(N/14)-1)*14 ← where N is the line width
c. CLS
Clears the screen under all monitors.
d. SCREEN X, Y
Sets the cursor position to character position X (1–48), line Y (1–16). Line 16 is at the top of the screen and is not scrolled. Line 1 is next down; line 15 is at the bottom.
SCREEN 24,8 PRINT "HELLO" ← prints at column 24, line 8
e. LINES N
Sets the number of lines printed by a LIST command before pausing (default: 5). N must be in the range +32767 to −32768. Negative numbers are treated as 65536 + N.
f/g/h. Graphics Commands
For use with the simple graphics option on Nascom 1 or 2 with the graphic character set. The graphics grid is 96 points wide by 48 points high, with 0,0 at the top left.
| Command | Description |
|---|---|
SET (X,Y) | Sets point X,Y bright. X: 0–95, Y: 0–47. |
RESET (X,Y) | If point X,Y is bright, sets it dark. |
POINT (X,Y) | Returns 1 if X,Y is bright, 0 if not. |
The line a point appears on: L = INT(Y/3)+1. The character position: C = INT(X/2)+1. Points with Y values 45–47 appear on the top (unscrolled) line.
i. Data Input under Nas-sys
DOKE 4175, -25 ← newline generated on INPUT; uses Nas-sys editing DOKE 4175, -6670 ← similar but no newline DOKE 4175, -6649 ← restore normal operation
j. Printer Support
Printers can be interfaced to the PIO on the Nascom. Routines to drive such printers can be switched on and off using DOKE and POKE commands. See the appropriate monitor manual for detailed information.
k. Aborting Programs
Escape (Shift + Newline) stops and aborts a running program (see 6-4). Generating an NMI (non maskable interrupt) has the same effect. It is not possible to abort during a cassette read or write; use the reset button and the Z command instead.
6-1 Commands
| Command | Description |
|---|---|
CLEAR | Sets all program variables to zero. |
CLEAR [(expr)] | As CLEAR but also sets string space. Default string space at startup: 50 bytes. |
CLOAD <str> | Loads the named program from cassette. Executes NEW first. |
CLOAD? <str> | Verifies that the specified program is loadable and error free. |
CLOAD* <array> | Loads specified array from cassette. May be used as a program statement. |
CONT | Continues execution after Escape, STOP, or END. Cannot be used if the program was modified during the break. |
CSAVE <str> | Saves the current program to cassette under the first character of <str>. |
CSAVE* <array> | Saves named array to cassette. May be used as a program statement. |
LIST | Lists the program from the lowest numbered line. Terminated by Escape. |
LIST <n> | Lists from line <n>. Pauses every n lines (see LINES command). |
NEW | Deletes the current program and clears all variables. |
NULL <n> | Sets number of nulls printed at end of each line. Default: 0. |
RUN [(n)] | Starts execution at line n, or at the lowest line if n is omitted. |
6-2 Statements
| Statement | Format | Description |
|---|---|---|
DATA | DATA <list> | Specifies data to be read by READ. Elements are numbers or strings separated by commas. |
DEF | DEF FNV(<W>) = <X> | Defines a user function. Name is FN plus a legal variable name. Restricted to one line. |
DIM | DIM <V>(<I>[,J...]) | Allocates array storage. Default max subscript 10 per dimension if DIM omitted. |
DOKE | DOKE <I>,<J> | Stores 16-bit value J at address I and I+1. |
END | END | Terminates program execution. |
FOR | FOR <V>=<X> TO <Y> [STEP <Z>] | Repeated execution. V starts at X; incremented by Z until past Y. |
GOSUB | GOSUB <nnnnn> | Unconditional branch to subroutine at line nnnnn. |
GOTO | GOTO <nnnnn> | Unconditional branch to line nnnnn. |
IF...GOTO | IF <X> GOTO <nnnnn> | Branch to line if X≠0. GOTO must be followed by a line number only. |
IF...THEN | IF <X> THEN <Y or stmt> | Branch/execute if X≠0. Otherwise continue at next line. |
INPUT | INPUT <V>[,<W>...] | Requests input from terminal; assigns values to variables. |
LET | LET <V>=<X> | Assigns expression value to variable. LET is optional. |
LINES | LINES <A> | Sets lines per page for LIST command. |
NEXT | NEXT [<V>,<W>...] | End of FOR loop. Terminates most recent loop if variable omitted. |
ON...GOTO | ON <I> GOTO <list> | Branches to Ith line number in list. I must be 0–255. |
ON...GOSUB | ON <I> GOSUB <list> | As ON...GOTO but list elements are subroutine start lines. |
OUT | OUT <I>,<J> | Sends byte J to port I. 0≤I,J≤255. |
POKE | POKE <I>,<J> | Stores byte J at address I. 0≤J≤255; −32768<I<65536. |
PRINT | PRINT <X>[,<Y>...] | Prints values to terminal. Spacing controlled by punctuation. |
READ | READ <V>[,<W>...] | Assigns values from DATA statements to variables. |
REM | REM [<remark>] | Comment — not executed. May be branched into. |
RESTORE | RESTORE | Resets DATA pointer to first entry of first DATA statement. |
RETURN | RETURN | Terminates subroutine; branches to statement after most recent GOSUB. |
SCREEN | SCREEN <X>,<Y> | Sets cursor to character position X, line Y. |
STOP | STOP | Stops execution; enters command level; prints BREAK IN LINE nnnnn. |
WAIT | WAIT <I>,<J>[,<K>] | Suspends until (port I XOR K) AND J ≠ 0. K defaults to 0. |
WIDTH | WIDTH <n> | Sets width of input and print buffers. |
6-3 Intrinsic Functions
| Function | Call Format | Description |
|---|---|---|
ABS | ABS(X) | Absolute value of X. |
ASC | ASC(X$) | ASCII code of the first character of X$. |
ATN | ATN(X) | Arctangent of X in radians (−π/2 to π/2). |
CHR$ | CHR$(I) | String whose one character has ASCII code I. |
COS | COS(X) | Cosine of X (radians). |
EXP | EXP(X) | e to the power X. X must be ≤87.3365. |
FRE | FRE(0) | Free memory bytes. If argument is a string, returns free string space bytes. |
INP | INP(I) | Read byte from port I. |
INT | INT(X) | Largest integer ≤ X. |
LEFT$ | LEFT$(X$,I) | Leftmost I characters of X$. |
LEN | LEN(X$) | Length of X$. Non-printing characters and blanks are counted. |
LOG | LOG(X) | Natural logarithm of X. X must be > 0. |
MID$ | MID$(X$,I[,J]) | Substring of X$ starting at position I. If J is given, returns J characters. |
POS | POS(I) | Current column position of the print head (leftmost = 0). |
RND | RND(X) | Random number 0–1. X<0: new sequence; X>0: next in sequence; X=0: last returned. |
RIGHT$ | RIGHT$(X$,I) | Rightmost I characters of X$. |
SGN | SGN(X) | Sign of X: 1 if X>0, 0 if X=0, −1 if X<0. |
SIN | SIN(X) | Sine of X (radians). COS(X)=SIN(X+π/2). |
SPC | SPC(I) | Prints I blanks. 0≤I≤255. |
SQR | SQR(X) | Square root of X. X must be ≥ 0. |
STR$ | STR$(X) | String representation of the value of X. |
TAB | TAB(I) | Spaces to position I (0–255). Only in PRINT statements. |
TAN | TAN(X) | Tangent of X (radians). |
USR | USR(X) | Calls user machine language subroutine with argument X. |
VAL | VAL(X$) | Numeric value of string X$. Returns 0 if X$ doesn't start with a digit or sign. |
6-4 Special Characters
| Character | Function |
|---|---|
@ * | Erases current line and executes carriage return. (Escape or Shift+Newline for Nas-sys.) |
| Backspace | Erases last character typed. If no last character, types a carriage return. |
_ (underline) * | Same as backspace. |
| Newline / Enter | Returns cursor to beginning of next line. |
| Escape (Shift+Newline) | Interrupts execution. Typing any character continues; a further Escape goes to command level (OK). Note: only effective from the Nascom keyboard. |
: | Separates statements in a line. |
? | Equivalent to the PRINT statement. |
| Rubout (Control Z) * | Deletes previous character; successive Rubouts delete further characters to the left. |
| Control/R * | Prints newline and echoes the line being input. |
| Control/U | Same as @. |
| Lower Case | Always echoed as lower case, but LIST and PRINT translate to upper case unless inside string literals, REM statements, or single-quote remarks. |
6-5 Error Messages
After an error, BASIC returns to command level and types OK. Variable values and program text remain intact but execution cannot be continued by CONT. All GOSUB and FOR context is lost.
Direct Statement: ?XX ERROR Indirect Statement: ?XX ERROR IN YYYYY
6-6 Reserved Words
These words may not be used as variable or function names. Intrinsic function names are also reserved.
Basic is distributed on 1×8K byte ROM or 8×1K byte EPROMs, situated from E000H to FFFFH.
Entry Points
| Address | Type | How to Enter | Notes |
|---|---|---|---|
E000H | Cold start | EE000 | Also resets the monitor when used with Nas-sys. |
FFFAH | Normal cold start | J (Nas-sys) or EFFFA (Nasbug) | Does not reset the monitor. |
FFFDH | Warm start | Z (Nas-sys) or EFFFD (Nasbug) | Retains programs in store. Can only be used after initialisation via E000 or FFFA. |
Initialisation
When initialised, the system responds with:
Memory Size?
Type either:
- A newline or enter character — BASIC will use all available store above 1000H, or
- A decimal address representing the highest store location you wish BASIC to use. This reserves space for user machine code routines at the top of store.
When successfully started, BASIC prints:
NASCOM ROM BASIC Ver 4.7 Copyright (c) 1978 by Microsoft <n> Bytes free
Appendix A — ASCII Character Codes
LF=Line Feed · FF=Form Feed · CR=Carriage Return · DEL=Rubout
Appendix B — Space and Speed Hints
A. Space Allocation
| Element | Space Required |
|---|---|
| Numeric variable | 6 bytes |
| Array (strings & float) | (no. of elements) × 6 + 5 + (no. of dimensions) × 2 bytes |
| Intrinsic function call | 1 byte |
| User-defined function definition | 6 bytes |
| Reserved word | 1 byte each |
| Other character | 1 byte each |
| Active FOR loop (stack) | 16 bytes |
| Active GOSUB (stack) | 9 bytes |
| Parentheses (stack) | 6 bytes per set |
| Temporary result (stack) | 10 bytes |
| BASIC itself | 8K ROM |
B. Space Hints
- Use multiple statements per line. Each line has a 5-byte overhead for the line number.
- Delete unnecessary spaces: use
10 PRINTX,Y,Zinstead of10 PRINT X,Y,Z. - Delete REM statements (1 byte for REM + 1 byte per character of the remark).
- Use variables instead of constants when the same value appears many times.
- Using END as the last statement is not necessary and takes one extra byte.
- Reuse unneeded variables instead of defining new ones.
- Use subroutines instead of writing the same code several times.
- Remember that
DIM A(10)creates eleven elements: A(0) through A(10).
C. Speed Hints
- Deleting spaces and REM statements gives a small but significant decrease in execution time.
- Variables are searched from the head of the table. Keep the variable list short and reuse names.
- Use
NEXTwithout the index variable. - Use variables instead of constants, especially in FOR loops.
- Maximise string space and minimise the number of string variables to reduce garbage collection time.
Appendix C — Mathematical Functions
The following functions can be computed using the existing BASIC functions:
| Function | BASIC Equivalent |
|---|---|
| SEC(X) | 1/COS(X) |
| CSC(X) | 1/SIN(X) |
| COT(X) | 1/TAN(X) |
| ARCSIN(X) | ATN(X/SQR(-X*X+1)) |
| ARCCOS(X) | -ATN(X/SQR(-X*X+1))+1.5708 |
| ARCSEC(X) | ATN(SQR(X*X-1))+SGN(SGN(X)-1)*1.5708 |
| ARCCSC(X) | ATN(1/SQR(X*X-1))+(SGN(X)-1)*1.5708 |
| ARCCOT(X) | -ATN(X)+1.5708 |
| SINH(X) | (EXP(X)-EXP(-X))/2 |
| COSH(X) | (EXP(X)+EXP(-X))/2 |
| TANH(X) | (EXP(X)-EXP(-X))/(EXP(X)+EXP(-X)) |
| SECH(X) | 2/(EXP(X)+EXP(-X)) |
| CSCH(X) | 2/(EXP(X)-EXP(-X)) |
| COTH(X) | (EXP(X)+EXP(-X))/(EXP(X)-EXP(-X)) |
| ARCSINH(X) | LOG(X+SQR(X*X+1)) |
| ARCCOSH(X) | LOG(X+SQR(X*X-1)) |
| ARCTANH(X) | LOG((1+X)/(1-X))/2 |
| ARCSECH(X) | LOG((SQR(-X*X+1)+1)/X) |
| ARCCSCH(X) | LOG((SGN(X)*SQR(X*X+1)+1)/X) |
| ARCCOTH(X) | LOG((X+1)/(X-1))/2 |
Appendix D — BASIC and Assembly Language
The USR function allows Nascom BASIC programs to call assembly language subroutines in the same manner as BASIC functions.
Memory Setup
When BASIC asks MEMORY SIZE?, respond with the top of available memory minus the space needed for your assembly routine. Alternatively, use locations 0C00H to 1000H not used by the Nascom monitor.
USRLOC
The starting address of the assembly routine goes in USRLOC at 1004H (LSB) and 1005H (MSB). Initially, USRLOC points to ILLFUN, which generates an FC error. Load your routine's address with POKE or DOKE.
Argument Passing
- Retrieve argument: Call the routine at
E00BH/E00CH(DEINT). Stores the argument in register pair [D,E]. Argument is truncated to a signed 16-bit integer. - Return result: Load value in register pair [A,B], then call the routine at
E00DH/E00EH. If not called, USR(X) returns X. - Return to BASIC: Execute a
RETinstruction.
The USR argument can designate which of several routines to call. Additional arguments can be passed via POKE/DOKE; results returned via PEEK/DEEK.
Appendix E — Using the Cassette Interface
CSAVE <string expression> ← save current program CLOAD <string expression> ← load program from tape CLOAD? <string expression> ← verify without loading
CSAVE saves the program under the name given by the first character of the string expression. Variable values are not saved. CLOAD executes a NEW command before loading. BASIC will not return to command level if it cannot find the requested file — it will continue searching until stopped.
When a program is found, the message File program identifier Found is displayed.
A sum check is generated on input and output. If the check fails on input, the message bad is displayed and BASIC returns to command level (with incorrect data in store).
S0 command under Nasbug T4 and Nas-sys. Useful for storing libraries of subroutines.Appendix F — Converting BASIC Programs
1. Strings
Remove declarations of string length. Convert DIM A$(I,J) to DIM A$(J). Use + for concatenation (not , or &). Convert subscript access as follows:
| Old | New (in expression) |
|---|---|
A$(I) | MID$(A$,I,1) |
A$(I,J) | MID$(A$,I,J-I+1) |
| Old | New (on left side of assignment) |
|---|---|
A$(I)=X$ | A$=LEFT$(A$,I-1)+X$+MID$(A$,I+1) |
A$(I,J)=X$ | A$=LEFT$(A$,I-1)+X$+MID$(A$,J+1) |
2. Multiple Assignments
500 LET B=C=0 does not set both variables to zero in Nascom BASIC — it sets B to −1 if C=0, otherwise 0. Convert to:
500 C=0:B=C
3. Statement Delimiter
Some BASICs use \ instead of : to delimit multiple statements. Replace each \ with :.
5. MAT Functions
Rewrite MAT functions using FOR...NEXT loops.
Appendix G — Storage Used
| Region | Hex | Decimal | Purpose |
|---|---|---|---|
| User machine code | 0C80H – 0FFFH | 3200 – 4095 | Available for user routines |
| BASIC workspace | 1000H – 3E11H | 4096 – 15889 | System workspace |
| BASIC ROM | E000H – FFFFH | — | BASIC interpreter |
| User program & data | 3E12H – DFFFH | — | Available for BASIC programs |
Appendix H — Useful Books
General Introduction to Programming in Basic
- Basic Programming by John G. Kemeny and Thomas E. Kurtz — Pub. Wiley
- Instant Basic by Jerald R. Brown — Pub. Dilithium Press
- Basic Basic by James S. Coan — Pub. Hayden
- Advanced Basic by James S. Coan — Pub. Hayden
Games and Useful Programs
- What To Do After You Hit Return (PCC's First Book of Computer Games) — Pub. People's Computer Company
- Basic Computer Games, Ed. David H. Ahl — Pub. Workman Publishing
- Basic Software Library (six volumes), R. W. Brown — Pub. Scientific Research Institute
Appendix I — Useful Routines
1. Writing to Line 16 (Non-Scrolled) under Nas-sys
1 REM THIS ROUTINE WRITES TO LINE 16 2 REM USING NAS-SYS 10 CLS 20 SCREEN 1,15 25 REM THAT PUTS IT ON BOTTOM LINE 30 PRINT "HEADER" 35 REM NOW WE ARE GOING TO COPY IT TO TOP 40 FOR C=2954 TO 3000 STEP 2 50 DOKE C+64,DEEK(C) 60 NEXT C 65 REM CHR$(27) GENERATES ESC=LINE DELETE 70 PRINT CHR$(27); 80 REM REST OF PROGRAM CAN START HERE
2. Hex String to Decimal Converter
4 CLS 5 PRINT 10 INPUT"ENTER HEX No.";H$ 20 T=0:D=1 30 FOR P=LEN(H$)-1 TO 0 STEP-1 40 C=ASC(MID$(H$,D,1)) 50 D=D+1 60 IF (C>=48)*(C<=57) THEN C=C-48:GOTO 100 70 IF (C>=65)*(C<=70) THEN C=C-55:GOTO 100 80 PRINT "+ve Hex with no D.P. please":GOTO 5 100 T=T+C*16^P 110 NEXT 120 PRINT "Hex ";H$;" in Decimal is";T 130 GOTO 5
Note: Lines 60 & 70 can alternatively be written using AND: IF C>=48 AND C<=57 THEN...
3. Set X Mode under Nas-sys
10 DOKE 3189, 1925 20 DOKE 3187, 1917 30 POKE 3112, <option> ← option: 0,1,16,17,32,33,48,49
e.g. option=0 sets X0. Can be used to turn on a serial printer under program control.
4. Set N Mode under Nas-sys (turn off serial printer)
10 DOKE 3189, 1922 20 DOKE 3187, 1919
5. Set U Mode under Nas-sys (user-written I/O drivers)
10 DOKE 3189, 1921 20 DOKE 3187, 1918
6. Set Keyboard (K) Modes under Nas-sys
10 POKE 3111, <option> ← 0=normal, 1=typewriter, 4=graphics, 5=typewriter+graphics
7. Keyboard Scan USR Call
Returns the ASCII value of any key pressed, or 0 if none.
10 DOKE 3200, 25311 20 DOKE 3202, 312 30 DOKE 3204, 18351 40 DOKE 3206, 10927 50 DOKE 3208, -8179 60 POKE 3210, 233 70 DOKE 4100, 3200
80 IF USR(0)<>0 THEN GOTO 500
Assembly listing:
0C80 DF RST SCAL ; scan inputs 0C81 62 DEFB ZIN ; ZIN is the input routine 0C82 38 01 JR C, CHAR ; skip if char received 0C84 AF XOR A ; clear A 0C85 47 CHAR: LD B,A ; put char in B 0C86 AF XOR A ; clear A 0C87 2A 0D E0 LD HL,(E00D) ; get return address in HL 0C8A E9 JP (HL) ; jump and return to BASIC
Appendix J — Single Character Input of Reserved Words
BASIC stores reserved words as single-character tokens internally. These can be generated directly by holding down the Graphics key on the keyboard plus one or more other keys, reducing typing and enabling longer statements on one line. The program will LIST correctly with reserved words in full.
| Reserved Word | Graphics + | Reserved Word | Graphics + |
|---|---|---|---|
END | Control Shift @ | NEW | $ |
FOR | Control A | TAB( | % |
NEXT | Control B | TO | & |
DATA | Control C | FN | ' |
INPUT | Control D | SPC( | ( |
DIM | Control E | THEN | ) |
READ | Control F | NOT | * |
LET | Control G | STEP | + |
GOTO | Control H | AND | 1 |
RUN | Control I | OR | 2 |
IF | Control J | SGN | 6 |
RESTORE | Control K | INT | 7 |
GOSUB | Control L | ABS | 8 |
RETURN | Control M | USR | 9 |
REM | Control N | FRE | : |
STOP | Control O | INP | ; |
OUT | Control P | POS | < |
ON | Control Q | SQR | = |
NULL | Control R | RND | > |
WAIT | Control S | LOG | ? |
DEF | Control T | EXP | Shift @ |
POKE | Control U | COS | A |
DOKE | Control V | SIN | B |
SCREEN | Control W | TAN | C |
LINES | Control X | ATN | D |
CLS | Control Y | PEEK | E |
WIDTH | Control Z | DEEK | F |
MONITOR | Control [ | POINT | G |
SET | Control \ | LEN | H |
RESET | Control ] | STR$ | I |
PRINT | Control ^ | VAL | J |
CONT | Control _ (underline) | ASC | K |
LIST | Space | CHR$ | L |
CLEAR | ! | LEFT$ | M |
CLOAD | " | RIGHT$ | N |
CSAVE | £ | MID$ | O |