html Nascom 8K BASIC Programming Manual
Nascom · Z80 Microcomputer · Microsoft BASIC

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.

Version4.7
CPUZ80
ROM Size8K
Copyright© 1978 Microsoft
Contents

Section 1
Introduction

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, RESET and POINT commands

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

  1. Words printed in capital letters must be written exactly as shown. These are mostly names of instructions and commands.
  2. 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.
  3. 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.
  4. 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 RUN command.

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.


Section 2
Statements & Expressions

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

  1. If the number is negative, a minus sign is printed to the left. If positive, a space is printed.
  2. If the absolute value is an integer in the range 0 to 999999, it is printed as an integer.
  3. If the absolute value is between 0.01 and 999999, it is printed in fixed point notation.
  4. Otherwise, scientific notation is used: SX.XXXXXESTT
InputNascom BASIC Output
+11
-1-1
65236523
1E201E20
-12.34567E-10-1.23456E-09
1.234567E-71.23457E-07
10000001E+06
.1.1
.0001231.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.

LegalIllegalReason
A%AFirst character must be alphabetic
Z1
TPTOCannot be a reserved word
PSTG$RGOTOCannot 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
Note
If no DIM statement has been executed before an array is referenced, BASIC assumes a maximum subscript of 10 (11 elements) for each dimension. A BS or SUBSCRIPT OUT OF RANGE error results if an element is accessed outside the allocated dimensions.

d. Operators and Precedence

1( )Expressions in parentheses
2^Exponentiation (any number^0 = 1; 0^negative → /0 error)
3Negation (unary minus)
4* /Multiplication and division
5+ −Addition and subtraction
6= <> < > <= =< >= =>Relational operators (result: −1 = True, 0 = False)
7NOTLogical, bitwise negation
8ANDLogical, bitwise conjunction
9ORLogical, bitwise disjunction

e. Logical Operations

AND, OR, NOT convert their arguments into 16-bit signed two's complement integers (−32768 to 32767). Operations are performed bitwise.

AND
XYX AND Y
111
100
010
000
OR
XYX OR Y
111
101
011
000
NOT
XNOT X
10
01
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 needed
  • EXTRA 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.

PunctuationNext printing begins
,At beginning of next 14-column zone
;Immediately after the last value printed
noneAt 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.

Warning
Care must be taken not to POKE data into the storage area occupied by BASIC or the system may crash and BASIC will have to be restarted.

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"

Section 3
Functions

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:

  1. A negative array subscript: LET A(-1)=0
  2. An array subscript that is too large (>32767)
  3. Negative or zero argument for LOG
  4. Negative argument for SQR
  5. A^B with A negative and B not an integer
  6. A call to USR with no address patched
  7. Improper arguments to MID$, LEFT$, RIGHT$, INP, OUT, WAIT, PEEK, POKE, TAB, SPC, INSTR, STRING$, SPACE$ or ON...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.


Section 4
Strings

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.

OperatorMeaning
=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.


Section 5
Additional Commands

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.

CommandDescription
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
Warning
Incorrect arguments to these DOKE commands will cause the system to crash.

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.


Section 6
Lists & Directories

6-1 Commands

CommandDescription
CLEARSets 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.
CONTContinues 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.
LISTLists the program from the lowest numbered line. Terminated by Escape.
LIST <n>Lists from line <n>. Pauses every n lines (see LINES command).
NEWDeletes 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

StatementFormatDescription
DATADATA <list>Specifies data to be read by READ. Elements are numbers or strings separated by commas.
DEFDEF FNV(<W>) = <X>Defines a user function. Name is FN plus a legal variable name. Restricted to one line.
DIMDIM <V>(<I>[,J...])Allocates array storage. Default max subscript 10 per dimension if DIM omitted.
DOKEDOKE <I>,<J>Stores 16-bit value J at address I and I+1.
ENDENDTerminates program execution.
FORFOR <V>=<X> TO <Y> [STEP <Z>]Repeated execution. V starts at X; incremented by Z until past Y.
GOSUBGOSUB <nnnnn>Unconditional branch to subroutine at line nnnnn.
GOTOGOTO <nnnnn>Unconditional branch to line nnnnn.
IF...GOTOIF <X> GOTO <nnnnn>Branch to line if X≠0. GOTO must be followed by a line number only.
IF...THENIF <X> THEN <Y or stmt>Branch/execute if X≠0. Otherwise continue at next line.
INPUTINPUT <V>[,<W>...]Requests input from terminal; assigns values to variables.
LETLET <V>=<X>Assigns expression value to variable. LET is optional.
LINESLINES <A>Sets lines per page for LIST command.
NEXTNEXT [<V>,<W>...]End of FOR loop. Terminates most recent loop if variable omitted.
ON...GOTOON <I> GOTO <list>Branches to Ith line number in list. I must be 0–255.
ON...GOSUBON <I> GOSUB <list>As ON...GOTO but list elements are subroutine start lines.
OUTOUT <I>,<J>Sends byte J to port I. 0≤I,J≤255.
POKEPOKE <I>,<J>Stores byte J at address I. 0≤J≤255; −32768<I<65536.
PRINTPRINT <X>[,<Y>...]Prints values to terminal. Spacing controlled by punctuation.
READREAD <V>[,<W>...]Assigns values from DATA statements to variables.
REMREM [<remark>]Comment — not executed. May be branched into.
RESTORERESTOREResets DATA pointer to first entry of first DATA statement.
RETURNRETURNTerminates subroutine; branches to statement after most recent GOSUB.
SCREENSCREEN <X>,<Y>Sets cursor to character position X, line Y.
STOPSTOPStops execution; enters command level; prints BREAK IN LINE nnnnn.
WAITWAIT <I>,<J>[,<K>]Suspends until (port I XOR K) AND J ≠ 0. K defaults to 0.
WIDTHWIDTH <n>Sets width of input and print buffers.

6-3 Intrinsic Functions

FunctionCall FormatDescription
ABSABS(X)Absolute value of X.
ASCASC(X$)ASCII code of the first character of X$.
ATNATN(X)Arctangent of X in radians (−π/2 to π/2).
CHR$CHR$(I)String whose one character has ASCII code I.
COSCOS(X)Cosine of X (radians).
EXPEXP(X)e to the power X. X must be ≤87.3365.
FREFRE(0)Free memory bytes. If argument is a string, returns free string space bytes.
INPINP(I)Read byte from port I.
INTINT(X)Largest integer ≤ X.
LEFT$LEFT$(X$,I)Leftmost I characters of X$.
LENLEN(X$)Length of X$. Non-printing characters and blanks are counted.
LOGLOG(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.
POSPOS(I)Current column position of the print head (leftmost = 0).
RNDRND(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$.
SGNSGN(X)Sign of X: 1 if X>0, 0 if X=0, −1 if X<0.
SINSIN(X)Sine of X (radians). COS(X)=SIN(X+π/2).
SPCSPC(I)Prints I blanks. 0≤I≤255.
SQRSQR(X)Square root of X. X must be ≥ 0.
STR$STR$(X)String representation of the value of X.
TABTAB(I)Spaces to position I (0–255). Only in PRINT statements.
TANTAN(X)Tangent of X (radians).
USRUSR(X)Calls user machine language subroutine with argument X.
VALVAL(X$)Numeric value of string X$. Returns 0 if X$ doesn't start with a digit or sign.

6-4 Special Characters

Note
Characters marked * do not apply when inputting using Nas-sys in normal mode.
CharacterFunction
@ *Erases current line and executes carriage return. (Escape or Shift+Newline for Nas-sys.)
BackspaceErases last character typed. If no last character, types a carriage return.
_ (underline) *Same as backspace.
Newline / EnterReturns 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/USame as @.
Lower CaseAlways 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
BS
Subscript Out Of Range
Array element outside allocated dimensions, or wrong number of dimensions used.
DD
Redimensioned Array
DIM encountered for an array that was already dimensioned (including default dimension of 10).
FC
Illegal Function Call
Parameter out of range for a math or string function. See section 3-3 for full list of causes.
MO
Missing Operand
No operand given to a command. e.g. CSAVE without a file name.
ID
Illegal Direct
INPUT and DEF are illegal in direct mode.
NF
Next Without For
NEXT variable corresponds to no previously executed FOR.
OD
Out Of Data
READ attempted after all DATA has been read.
OM
Out Of Memory
Program too large, too many variables, FOR loops, GOSUBs or complex expressions.
OV
Overflow
Calculation result too large for BASIC's number format. Underflow silently returns zero.
SN
Syntax Error
Missing parenthesis, illegal character, incorrect punctuation, etc.
RG
Return Without Gosub
RETURN encountered before a GOSUB was executed.
UL
Undefined Line
GOTO, GOSUB, or IF...THEN referenced a non-existent line.
/0
Division By Zero
Occurs with floating point, integer division, MOD, and 0 to a negative power.
CN
Can't Continue
Attempt to continue a program when none exists, after an error, or after modification.
LS
String Too Long
Attempt to create a string more than 255 characters long.
OS
Out Of String Space
String variables exceed allocated string space. Use CLEAR to allocate more.
ST
String Formula Too Complex
String expression too long or complex. Break into shorter ones.
TM
Type Mismatch
Numeric variable assigned a string, or vice-versa.
UF
Undefined User Function
Reference to a user function that was never defined with DEF.

6-6 Reserved Words

These words may not be used as variable or function names. Intrinsic function names are also reserved.

CLEARNEWANDOUT DATANEXTCONTPOINT DIMPRINTDEFRESET ENDREADDOKEPOKE FORREMFNSCREEN GOSUBRETURNLINESSET GOTORUNNOTSPC IFSTOPNULLWAIT INPUTTOONWIDTH LETTABOR LISTTHENUSR

Section 7
Running BASIC

Basic is distributed on 1×8K byte ROM or 8×1K byte EPROMs, situated from E000H to FFFFH.

Entry Points

AddressTypeHow to EnterNotes
E000HCold startEE000Also resets the monitor when used with Nas-sys.
FFFAHNormal cold startJ (Nas-sys) or EFFFA (Nasbug)Does not reset the monitor.
FFFDHWarm startZ (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

Appendices

Appendix A — ASCII Character Codes

000NUL
001SOH
002STX
003ETX
004EOT
005ENQ
006ACK
007BEL
008BS
009HT
010LF
011VT
012FF
013CR
014SO
015SI
016DLE
017DC1
018DC2
019DC3
020DC4
021NAK
022SYN
023ETB
024CAN
025EM
026SUB
027ESC
028FS
029GS
030RS
031US
032SPC
033!
034"
035#
036$
037%
038&
039'
040(
041)
042*
043+
044,
045-
046.
047/
0480
0491
0502
0513
0524
0535
0546
0557
0568
0579
058:
059;
060<
061=
062>
063?
064@
065A
066B
067C
068D
069E
070F
071G
072H
073I
074J
075K
076L
077M
078N
079O
080P
081Q
082R
083S
084T
085U
086V
087W
088X
089Y
090Z
091[
092\
093]
094^
095_
096`
097a
098b
099c
100d
101e
102f
103g
104h
105i
106j
107k
108l
109m
110n
111o
112p
113q
114r
115s
116t
117u
118v
119w
120x
121y
122z
123{
124|
125}
126~
127DEL

LF=Line Feed  ·  FF=Form Feed  ·  CR=Carriage Return  ·  DEL=Rubout

Appendix B — Space and Speed Hints

A. Space Allocation

ElementSpace Required
Numeric variable6 bytes
Array (strings & float)(no. of elements) × 6 + 5 + (no. of dimensions) × 2 bytes
Intrinsic function call1 byte
User-defined function definition6 bytes
Reserved word1 byte each
Other character1 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 itself8K ROM

B. Space Hints

  1. Use multiple statements per line. Each line has a 5-byte overhead for the line number.
  2. Delete unnecessary spaces: use 10 PRINTX,Y,Z instead of 10 PRINT X,Y,Z.
  3. Delete REM statements (1 byte for REM + 1 byte per character of the remark).
  4. Use variables instead of constants when the same value appears many times.
  5. Using END as the last statement is not necessary and takes one extra byte.
  6. Reuse unneeded variables instead of defining new ones.
  7. Use subroutines instead of writing the same code several times.
  8. Remember that DIM A(10) creates eleven elements: A(0) through A(10).

C. Speed Hints

  1. Deleting spaces and REM statements gives a small but significant decrease in execution time.
  2. Variables are searched from the head of the table. Keep the variable list short and reuse names.
  3. Use NEXT without the index variable.
  4. Use variables instead of constants, especially in FOR loops.
  5. 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:

FunctionBASIC 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 RET instruction.
Warning
All memory and registers may be changed by a user routine, but memory locations within BASIC must not be modified, and more bytes must not be popped from the stack than were pushed.

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).

Tip
You can fool Basic into LISTing or PRINTing to tape, or INPUTting from tape, using the 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:

OldNew (in expression)
A$(I)MID$(A$,I,1)
A$(I,J)MID$(A$,I,J-I+1)
OldNew (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

RegionHexDecimalPurpose
User machine code0C80H – 0FFFH3200 – 4095Available for user routines
BASIC workspace1000H – 3E11H4096 – 15889System workspace
BASIC ROME000H – FFFFHBASIC interpreter
User program & data3E12H – DFFFHAvailable 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 WordGraphics +Reserved WordGraphics +
ENDControl Shift @NEW$
FORControl ATAB(%
NEXTControl BTO&
DATAControl CFN'
INPUTControl DSPC((
DIMControl ETHEN)
READControl FNOT*
LETControl GSTEP+
GOTOControl HAND1
RUNControl IOR2
IFControl JSGN6
RESTOREControl KINT7
GOSUBControl LABS8
RETURNControl MUSR9
REMControl NFRE:
STOPControl OINP;
OUTControl PPOS<
ONControl QSQR=
NULLControl RRND>
WAITControl SLOG?
DEFControl TEXPShift @
POKEControl UCOSA
DOKEControl VSINB
SCREENControl WTANC
LINESControl XATND
CLSControl YPEEKE
WIDTHControl ZDEEKF
MONITORControl [POINTG
SETControl \LENH
RESETControl ]STR$I
PRINTControl ^VALJ
CONTControl _ (underline)ASCK
LISTSpaceCHR$L
CLEAR!LEFT$M
CLOAD"RIGHT$N
CSAVE£MID$O