Pages 288–296 · Markdown

Appendix B – Reference

The following sections provide a handy reference of Error Codes and their equivalent Reports, NextBASIC keywords and functions as well as other information discussed so far in a consice form

Reports and Error Codes

These appear at the bottom of the screen whenever the computer stops executing some function, and explain why it stopped, whether for a natural reason, or because an error occurred.

The report has a brief message explaining what happened and the bank number (not present unless the error occurred in a banked section of program), the line number and statement number within the line where it stopped (A command is shown as line 0. Within a line, statement 1 is at the beginning, statement 2 comes after the first colon or THEN, and so on). Some of the codes will have a code number or letter so that you can refer to the tables below. There are two types of error reports: General and Storage System related.

General Errors

The behaviour of CONTINUE depends very much on the reports. Normally, CONTINUE goes to the line and statement specified in the last report, but there are exceptions with reports 0, 9 and D.

Below, there is a table showing all the reports together with the circumstances they can occur.

Code Report Description Situation
0 OK Successful completion, or jump to a line number bigger than any existing. This report does not change the line and statement jumped to by CONTINUE. Any
1 NEXT without FOR The control variable does not exist (it has not been set up by a FOR statement), but there is an ordinary variable with the same name. NEXT
2 Variable not found For a simple variable, this will happen if the variable is used before it has been assigned to in a LET, READ or INPUT statement or loaded from tape or set up in a FOR statement. For a subscripted variable, it will happen if the variable is used before it has been dimensioned in a DIM statement or loaded from a storage device. Any
3 Subscript wrong A subscript is beyond the dimension of the array, or there are the wrong number of subscripts. If the subscript is negative or bigger than 65535, then error B will result. Subscripted variables, substrings
4 Out of memory There is not enough room in the computer for what you are trying to do. If the computer really seems to be stuck in this state, you may have to clear out the command line using DELETE and then delete a program line or two (with the intention of putting them back afterwards) to give yourself room to manoeuvre with – say – CLEAR. LET, INPUT, FOR , DIM, GO SUB, LOAD, MERGE, BANK, PALETTE, SPRITE, LAYER, TILE. Sometimes during expression evaluation
5 Out of screen An INPUT statement has tried to generate more than 23 lines in the lower half of the screen. Also occurs with PRINT AT 22, …, TILE and SPRITE. INPUT, PRINT AT, SPRITE, TILE
6 Number too big Calculations have led to a number greater than about 10³⁸. Any arithmetic
7 RETURN without GO SUB There has been one more RETURN than there were GO SUBs. RETURN
8 End of file Storage device, etc, operations
9 STOP statement After this, CONTINUE will not repeat the STOP, but carries on with the statement after. STOP
Code Report Description Situation
A Invalid argument The argument for a function is no good for some reason. SQR, LN, ASN, ACS, USR (with string argument)
B Integer out of range When an integer is required, the floating point argument is rounded to the nearest integer. If this is outside a suitable range then error B results. For array access, see also error 3. RUN, RANDOMIZE, POKE, DIM, GO TO, GO SUB, LIST, LLIST, PAUSE, PLOT, CHR$, PEEK, USR (with numeric argument), PALETTE, BANK, SPRITE, LAYER, TILE, POINT, Array access
C Nonsense in BASIC The text of the (string) argument does not form a valid expression. VAL, VAL$
D BREAK - CONT repeats BREAK was pressed during some peripheral operation. The behaviour of CONTINUE after this report is normal in that it repeats the statement. Compare with report L. LOAD, SAVE, VERIFY, MERGE, LPRINT, LLIST, COPY. Also when the computer asks scroll? and you type N, SPACE or STOP1
E Out of DATA You have tried to READ past the end of the DATA list. READ
F Invalid file name SAVE with name that is empty or unacceptable (see Chapter 20) SAVE
G No room for line There is not enough room left in memory to accommodate the new program line. Entering a line into the program
H STOP in INPUT Some INPUT data started with STOP, or – for INPUT LINE – STOP was pressed. Unlike the case with error 9, after error H CONTINUE will behave normally, by repeating the INPUT statement. INPUT
I FOR without NEXT There was a FOR loop to be executed no times (e.g. FOR n=1 TO 0) and the corresponding NEXT statement could not be found. FOR
J Invalid I/O device Storage device etc. operations
K Invalid colour The number specified is not an appropriate value. INK, PAPER, BORDER, FLASH, BRIGHT, INVERSE, OVER, PALETTE; also after control characters
L BREAK into program BREAK pressed, this is detected between two statements. The line and statement number in the report refer to the statement before BREAK was pressed, but CONTINUE goes to the statement after (allowing for any jumps to be done), so it does not repeat any statements. Any
M RAMTOP no good The number specified for RAMTOP is either too big or too small. CLEAR, BANK; possibly in RUN
N Statement lost Jump to a statement that no longer exists. RETURN, NEXT, CONTINUE
O Invalid stream Storage device, etc, operations
P FN without DEF An attempt was made to call a function with FN that has not been defined with a matching DEF FN statement. FN
Q Parameter error Wrong number of arguments, or one of them is the wrong type (string instead of number or vice versa). FN
R Tape loading error A file on tape was found but for some reason could not be read in, or would not verify. VERIFY, LOAD or MERGE
d Too many parentheses Too many parentheses around a repeated phrase in one of the arguments. PLAY
i Invalid device The storage device specified does not exist
k Invalid note PLAY came across a note or command it didn’t recognise, or a command which was in lower case. PLAY
l Too big A parameter for a command is an order of magnitude too big. PLAY

1 STOP cannot normally be entered in NextBASIC as a token; this is retained for compatibility and does work when you switch to 48K mode

Code Report Description Situation
m Note out of range A series of sharps or flats has taken a note beyond the range of the sound chip. PLAY
n Out of range A parameter for a command is too big or too small. If the error is very large, error L results PLAY
o Too many tied notes An attempt was made to tie too many notes together PLAY
Invalid mode The mode specified does not exist LAYER
Direct command error An attempt was made to execute a command within a program that's meant to be executed directly from the command line or to RUN a procedure definition (DEFPROC) DEFPROC, ERASE, LINE, LINE MERGE, BANK LINE MERGE
Loop error Occurs in REPEAT...REPEAT UNTIL loops where a matching REPEAT UNTIL or REPEAT cannot be found. REPEAT...REPEAT UNTIL, WHILE
No DEFPROC A PROC was found without a matching DEFPROC...ENDPROC block PROC
No ENDIF An ELSEIF was found without a matching ENDIF IF...ELSEIF...ENDIF
No label A referenced label, does not exist

The following are reports generated by NextZXOS for storage device errors. Those marked in the left-hand column with RIC may be followed by the options Retry, Ignore or Cancel?

Some reports may occur with the code(s) shown or without them.

Code Report Description
e Already exists The destination filename or directory already exists. Also occurs when attempting to map a drive letter that is already mapped to another device.
Bad file number An attempt was made to operate on a file which has not been opened. It is unlikely that this error will ever be seen.
f Bad filename The filename used does not conform to the filename requirements for the filesystem.
Bad parameters One of the values provided is out of range.
Code length error Trying to load a CODE file from the storage device that is longer than the value given on the LOAD command.
Dest can't be wild Trying to give a wildcard file specification for the destination file in a COPY command when the source also contains wildcard characters. In this case, the destination can only be a drive letter.
Dest must be path The source filename in a COPY command contains wildcard characters, but the destination is only a single file name. In this case, the destination can only be a path.
Dir full Unable to add further entries to the directory, or unable to remove a directory because it contains files or subdirectories.
RIC Disk changed The disk in the drive has been changed without properly REMOUNTing.
RIC Disk error An error has occurred accessing a storage device. If this error persists it may indicate that the device is faulty.
Disk full Saving or copying files to a storage device has used up the free space. The CAT command can be used to check that there is sufficient free space before attempting such an operation. This may leave a partly-written file if there was only space for some of it. This part should be erased, as any attempt to use it will fail.
Dot command error The error that was trapped by ON ERROR was generated by a dot command. This is seen only when ERROR is used to cause the last trapped error.
End of file An attempt has been made to read a byte past the end-of-file position.
g,h File not found The filename specifies a file that does not exist.
Fragmented – use .DEFRAG The file is split into parts across the disk. Defragment it using the .DEFRAG dot command.
In use An attempt has been made to unmap or re-map a drive that has files open on it, or to access a file that is already open for another purpose.
Invalid attribute The attribute character following + or - in a MOVE command is not P, S or A (or there is more than one character after the +/-).
Invalid device The physical device specified does not exist.
Invalid drive A drive letter that does not exist has been specified.
Invalid partition The partition specified does not exist, or is the wrong type.
Invalid path The path specified does not exist
No rename between drives An attempt has been made to use the MOVE command specifying source and destination filenames that are on different drives.
No swap partitionAn application attempted to access a swap partition, but couldn’t find one. Create a new swap partition with .MKSWAP and try again.
Not bootableAn attempt has been made to boot a disk image without a boot sector or boot program.
Not implementedAn attempt was made to access a facility which isn’t available.
RICNot readyThe storage device was not ready. This usually happens because it has been removed.
Out of handlesThere aren’t enough handles left to perform the current operation. Unmap a drive and try again.
Partition openThe partition you are trying to delete or map is already mapped to a drive.
RICRead onlyAn attempt has been made to write to a file or storage device which is read-only or has been write-protected.
RICSeek failThe device is unable to locate the sector that has been requested. If this error persists it may indicate that the device or disk image is faulty.
Too bigAn attempt has been made to write a file that is too large for the filesystem (greater than 8MB for +3DOS filesystems, 2GB on FAT16 or 4GB on FAT32).
RICUnsuitable mediaThe device or disk image is formatted in a way that cannot be handled.
bWrong file typeTrying to LOAD a file of the wrong type (eg trying to load a CODE file as a NextBASIC program).

NextBASIC Keywords and Functions

The following is a list of all NextBASIC keywords in alphabetical order with a short description regarding their function.

Keyword Meaning
BANK 1346 FORMAT Reserve banks 1,3,4,6 for use by the RAMdisk again.
BANK 1346 USR Allow banks 1,3,4,6 to be used by the BANK command.
BANK m COPY TO n Copy the contents of bank m to bank n
BANK m DPOKE o, list... Double POKE a sequence of comma-separated values starting at offset o in bank m.
BANK m ERASE [o, l,] [v] Fill bank m's optional l bytes (all if not specified) at optional offset o (0 if not specified) with value (zero is used if value not specified).
BANK m CLEAR Marks bank m as free for use by other parts of the system.
BANK m COPY o, l TO n,o2 Copy l bytes starting at offset o in bank m to offset o2 in bank n.
BANK m GOSUB n GOSUB line n in bank m. To GOSUB the main program from a banked section, use m=255. See also RETURN and GOSUB.
BANK m GOTO n GOTO line n in bank m. To GOTO the main program from a banked section, use m=255.
BANK m LAYER o|x,y,w,h TO [rop] x,y,w,h|o Copies data to | from the screen (in the current mode) from | to offset in bank m. [rop] is an optional symbol modifier which affects how the data is copied.
BANK m LINE x,y Copies lines x to y inclusive from the main program to bank m.
BANK m LIST [n|PROC name()] List lines (optionally from line n or procedure named name) in bank m.
BANK m MERGE Copy all lines back from bank m into the main program.
BANK m POKE o, list... POKE a sequence of comma-separated values starting at offset o in bank m.
BANK m PROC name ([expressionlist]) [TO paramlist] Call a procedure in bank m. To call a procedure in the main program from a banked section, use n=255. See also DEFPROC.
BANK m RESTORE n Set the DATA pointer to line n in bank m
BANK NEW var Reserves the next available free bank number and assigns it to the numeric variable var
BEEP x, y Sounds a note through the loudspeaker for x seconds at a pitch y semitones above middle C (or below if y is negative).
BORDER m Sets the colour of the border of the screen.
BRIGHT n Sets brightness of characters subsequently printed. n=0 for normal, 1 for bright. 8 for transparent.Error K if n not 0, 1 or 8
CAT [#n,] [[filespec [EXP]]|TAB|ASN] Produces an alphanumerically sorted catalog of files on screen or to an optional stream n from the default drive or according to the optional filespec in standard or EXPanded form. With the optional TAB and ASN modifiers produces information regarding partitions and drive letter assignments.
CD filespec Change the current drive and/or directory to the one specified in filespec.
CIRCLE x, y, z Draws an arc of a circle, centre (x,y), radius z
CLEAR [n] Deletes all variables, freeing the space they occupied. Does RESTORE and CLS, resets the PLOT position to the bottom left-hand corner and clears the NextBASIC Return stack. Optional address n attempts to change the RAMTOP to that address
CLOSE #n Marks stream n as being unattached to any channel.
CLS (Clear Screen). Clears the display of the current layer
Keyword Meaning
CONTINUE Continues the program, starting where it left off last time it stopped with report other than 0.
COPY Sends (dumps) a copy of the screen display to a ZX Printer or compatible.
COPY u TO SCREEN$ Displays the contents of a file defined by filespec u on the screen. Control characters (tabs, line feeds, etc.) are replaced by spaces.
COPY u1 TO u2 Copies file(s) defined by filespec u1 to the destination defined by filespec u2
DATA list ... Part of the DATA list. Must be in a program, otherwise has no effect.
DEF FN ? (?1,..., ?k)=e User-defined function definition; must be in a program. Each of ? and ?1 to ?k is either a single letter or a single letter followed by $ for string argument or result.Takes the form DEF FN a()=e if no arguments.
DEFPROC name ([paramlist]) Defines a procedure, where name follows the same naming rules as standard numeric variables. paramlist is an optional list of up to 8 variable names (simple strings, numeric variables or integer variables, but not arrays of any type). See ENDPROC.
DIM #n,var Returns the extent (or size) of stream n and stores it in variable var.
DIM ?( n1 , . . . ,nk ) Deletes any array or string with the name ?, and sets up an array of characters or numbers with k dimensions n1 ,...,nk. Initialises all the values to [?]. This can be considered as an array of strings of fixed length nk , with k-1 dimensions n1,...,nk-1 . An array is undefined until it is dimensioned in a DIM statement.
DRAW x,y [,z] Draws a line from the current plot position moving x horizontally and y vertically relative to it while turning through an optional angle z
DRIVER drid,callid[,n1[,n2]] [TO var1[,var2[,var3]]] Call function callid in driver drid, where n1 and n2 are optional values to pass to the driver, and var1, var2 and var3 are optional variables to receive results back from the driver.
ELSE See IF ... THEN ... ELSE
ENDPROC [= expressionlist] Ends execution of a procedure defined with DEFPROC and returns up to 8 local values via the optional expressionlist to the calling PROC command.
ERASE [m,n] Erases the entire NextBASIC program and leaves variables intact. If specified with the optional m and n parameters, erases all program lines between m and n inclusive.
ERASE filespec ERASES all files specified by filespec. Cannot erase entire drives
ERROR [TO e[,l[,s[,b]]]] Regenerate the last error that was trapped by an ON ERROR command and store it in optional variables e, l, s, b (for error code, line, statement number and bank)
FLASH n Defines whether characters will be flashing or steady.
FOR ?=x TO y [STEP z] Deletes any simple variable ? and sets up a control variable with value x, limit y, optional step z (or 1 if STEP is not defined), and looping address referring to the statement after the FOR statement. See NEXT.
GO TO n Jumps to line n (or, if there is none, the first line after that). See also BANK...GO TO.
GO TO #n, m Sets the current position of stream n to m.
GOSUB n Pushes the line number of the GOSUB statement onto a stack; then as GO TO n. See also RETURN and BANK...GOSUB.
IF x THEN y [: ELSE z] If x is true (non-zero) then statement list y is executed, otherwise optional statement list z is executed. ELSE must be on the same line as IF.
INK n Sets the ink (foreground) colour of characters subsequently printed.
INPUT [#n] [LINE] inputitems INPUTs inputitems from the keyboard or optional stream n. Optional LINE modifier strips the quotes from the input items
INVERSE n Inverts the next printed character(s) from INK to PAPER
LAYER AT x,y Sets the display offset for the top-left of the screen for the current layer to x,y.
LAYER BANK n,m (Layer 2 only). Set current banks n...n+2 as frontbuffer (to be displayed) and banks m...m+2 as backbuffer (for rendering).
LAYER CLEAR Resets all layer information to the default values. Resets memory banks, mode, layer 2 enable, layer offsets and layer ordering. Also done by NEW
LAYER DIM x1,y1,x2,y2 Sets the clip window for the current layer from (x1,y1) to (x2,y2). Areas of the layer outside this window are not visible.
LAYER ERASE x,y,w,h[,f] Fill region width w pixels, height h pixels, top-left corner x,y with optional value f. If f is not specifed, 0 is used.
LAYER m[,n] Selects the screen layer m and optional mode m.
LAYER OVER n Sets sprite/layer SLU ordering
LAYER PALETTE n [BANK m,o ]| n,i,v Switch to using palette n (0 or 1) for the current layer and optionally sets palette from bank m, offset o -or- defines index l for palette n as 9-bit colour v
LET [%]v = [%]e Assigns the value of [optionally integer] expression e to the [optionally integer] variable v. LET cannot be omitted.
LINE start, step|m,n TO mm,nn Either renumbers an entire NextBASIC program starting with line start with an increment of step -or- a section of the NextBASIC program, beginning with line m and ending with line n, with the new starting line number mm and incrementing by nn.
LINE MERGE first,last Merges lines from first to last into a single line (separated by colons). Can only be used as a direct command, not within a program.
LIST [[#n],] [m|PROC name] Lists the current program to the screen or optional stream number starting with optional line m -or- PROC name. See also BANK...LIST and LLIST
LLIST [m] Like LIST but using the printer
Keyword Meaning
LOAD filespec [BANK m[,o[,n]]|CODE m[,n]|DATA arrayspec|LAYER|SCREEN$] If filespec is a drivespec: Makes the named drive the current default input device for all subsequent disk operations (COPY, ERASE, MOVE etc.). If the drive letter specified is 'T:', then all subsequent LOADs will default to tape else loads a NextBASIC program into memory. With optional modifier BANK it loads the file as binary data into bank m at optional offset o and optional length n. Optional modifer CODE does the same at address m an optional length n. Optional modifier DATA loads stored data into the array specified by arrayspec. Optional modifier LAYER attemps to load a screen into the current layer while SCREEN$ does the same for Layer 0 screens. See also SAVE, MERGE, VERIFY. If a drive letter is not specified in the filespec, the default drive will be used.
LOCAL variablelist Defines a local variable inside a procedure defined with DEFPROC or a subroutine called with GOSUB. One local command accepts up to 256 variable names, and multiple LOCAL commands may be used.
LPRINT Like PRINT, but using the printer.
MERGE filespec Like LOAD filespec but does not delete old program lines and variables except to make way for new ones with the same line number or name. If a drive letter is not specified, the default drive will be used.
MKDIR filespec Create a new directory/folder specified by filespec on the current storage device. If filespec includes a drivespec then that drive will be used
MOVE filespec1, filespec2 Renames and/or moves a file defined in filespec1 to filespec2 within the same drive.
MOVE filespec TO attribute Sets or resets attributes for the file(s) defined by filespec
NEW Starts the NextBASIC system afresh, deleting any program and variables, and using the memory up to and including the byte whose address is in the system variable RAMTOP. The system variables UDG, P RAMT, RASP and PIP are preserved. Returns control to the Startup menu, but does not erase files held on drive M: (the RAMdisk).
NEXT ? Finds the control variable ?, adds its step to its value and jumps to the looping statement or exits if the limit has been reached. See also FOR.
NEXT #n,v Gets the next character of input from stream n and stores it in the variable v.
ON ERROR [statementlist] Turns off error trapping or if used with the optional statement list, the statementlist will execute where an error report would normally appear.
OPEN #n,channelspec Allows stream number to be attached to the channel identified by channelspec.
OUT m,n Outputs byte n at I/O port address m.
OVER n Controls overprinting for characters subsequently printed.
PALETTE CLEAR Resets all palettes and related settings to defaults. This is also done by NEW.
PALETTE DIM n Sets palette type as 8 or 9 bit.
PALETTE FORMAT n Enables the EnhancedULA extended palette with n INKs (1,3,7,15,31,63,127 or 255) or disables it (0)
PALETTE OVER n Sets the global transparency colour to n (default value is 227).
PAPER n Like INK, but controlling the paper (background) colour.
PAUSE n Stops computing and displays the display file for n frames.
PLAY f1[,f2,...f9] Interpret up to nine command strings and play them simultaneously.
PLOT x,y Draws a pixel in the current INK colour (subject to OVER and INVERSE) at the x,y coordinate of the current layer.
POINT x,y TO var Checks the pixel on the current layer at (x,y) and stores the value in variable var.
POKE a,valuelist POKEs the list of values in valuelist to memory map address a. Se also BANK POKE.
DPOKE addr,valuelist... Double POKEs the list of values in valuelist to memory map address a. Se also BANK DPOKE.
PRINT [#n,] [AT x,y;] items Output items to the display or optionally to stream n. Optional AT modifier positions the output at x,y
PRINT POINT x,y Set the print position to pixel coordinates x,y.
PROC name (expressionlist) [TO paramlist] Call procedure defined with DEFPROC. The number of expressions and each of their types must match those defined in the DEFPROC, otherwise a Q Parameter Error report will be generated. TO paramlist will copy return values declared by ENDPROC to up to 8 variables.
PWD [#n] Prints the current working directory to the screen, or the specified stream number.
RANDOMIZE [n] Sets the system variable (called SEED) used to generate the next value of RND. If optional n =0 or blank SEED is given the value of another system variable (called FRAMES).
READ v1, v2 ,... vk Assigns to the variables using successive expressions in the DATA list.
REG n,v Sets Next Register n with value v.
REM ...
; ...
Remark. No effect. ' . . . ' can be any sequence of characters except ENTER.
REMOUNT Reinitialises the filing system, following a change of SD card.
REPEAT
statementlist
[WHILE y statementlist2]
REPEAT UNTIL x
Statement or statements in statementlist and statement list2 are repeated until x is true. The loop is terminated skipping statementlist2 if y evaluates to false
RESTORE [n] Restores the DATA pointer to the first DATA statement in line optional line n or to the first DATA statement.
Keyword Meaning
RETURN Takes a reference to a statement off the NextBASIC Return stack, and jumps to the line after it. See also GOSUB and BANK GOSUB.
RETURN #n,var Takes the current position of stream n and stores it in variable var.
RMDIR filespec Removes an already empty folder as specified by filespec.
RUN [n] CLEAR, and then GO TO optional line n or to the first line of the program
RUN AT speed Changes the speed of the ZX Spectrum Next.
SAVE filespec [LINE n|BANK m[,o[,n]]|CODE m[,n]|DATA arrayspec|LAYER|SCREEN$] If filespec is a drivespec: Makes the named drive the current default input device for all subsequent disk operations (COPY, ERASE, MOVE etc.). If the drive letter specified is 'T:', then all subsequent SAVEs will default to tape else saves a NextBASIC program into memory with optional modifier LINE n that instructs subsequent LOAD operations to start executing the program from line n. With optional modifier BANK it SAVES the file as binary data from bank m at optional offset o and optional length n. Optional modifer CODE does the same at address m an optional length n. Optional modifier DATA saves the array specified by arrayspec. Optional modifier LAYER saves the current layer's display while SCREEN$ does the same for Layer 0 screens. See also LOAD, MERGE, VERIFY. If a drive letter is not specified in the filespec, the default drive will be used.
SPECTRUM [filespec|ATTR n|BRIGHT n|CHR$ n|FLASH n|INK n|PAPER n|SCREEN$ n,t] Sets the 128K ROM into Spectrum 48K compatibility mode. Optional filespec defining a 48K/128K/ZX80 and ZX81 snapshot loads and executes it. Optional ATTR modifier, sets the colour scheme of NextBASIC Editor. Optional BRIGHT modifier, sets the BRIGHT bit of the colour scheme of NextBASIC Editor. Optional CHR$ modifier, changes the mode to 32/64/85 columns. Optional FLASH modifier, sets the flash bit of the colour scheme of NextBASIC Editor. Optional INK modifier sets the ink colour of the NextBASIC Editor while the PAPER modifiers sets the paper colour of the NextBASIC Editor. The SCREEN$ modifier adjusts the screensaver.
SPRITE BANK b [,o,p,n] Defines all 64 sprite patterns using the 16K of data (256 bytes per sprite) in bank b or with optional values o,p,n defines n sprite patterns starting with pattern p located at offset n.
SPRITE BORDER n Enable (n=1) or disable (n=0) sprites over the border
SPRITE CLEAR Resets the sprite attributes and global settings to defaults. This is also done by NEW.
SPRITE DIM x1,y1,x2,y2 Sets the clip window for sprites from (x1,y1) to (x2,y2).
SPRITE PALETTE n [BANK m,o ]| n,i,v Switch to using palette n (0 or 1) for the Sprite System and optionally sets palette from bank m, offset o -or- defines index l for palette n as 9-bit colour v
SPRITE PRINT n Enable (n=1) or disable (n=0) sprites.
SPRITE s,x,y,i,f Set sprite s to image i, position (x,y) with flags f.
STOP Stops the program with report 9. See also CONTINUTE
TILE w,h |AT x,y [TO x2,y2] Draws a section of the screen from a tilemap. Optional AT specifies tile offset x,y in the tilemap and optional TO specifies ending tile offset x2,y2
TILE BANK n Define bank n as containing the tiles (up to 4 banks n..n+3 if 16x16 tiles).
TILE DIM n,offset,w,tilesize Define bank n as containing the tilemap, starting at offset offset in the bank. The tilemap is width w (1-2048) and uses 8x8 (tilesize=8) or 16x16 (tilesize=16) tiles.
VERIFY filespec Like LOAD (from tape), but the tape information is not loaded into RAM – instead, it is just compared against what is already in RAM.If the filespec is a drive letter, then sets the default drive. Only applicable to tape

The following is a list of all NextBASIC functions in alphabetical order with a short description regarding their purpose:

Function Meaning
ABS x Absolute Value of x
ACS x Arccosine of x in radians
ASN x Arcsine of x in radians
ATN x Arctangent of x in radians
ATTR (x,y) A number whose binary form codes the attributes of line x, column y on the display
CHR$ n The character whose code is n, rounded to the nearest integer.
CODE f The code of the first character in string f (or 0 if f is the empty string).
COS x Cosine (x in radians).
[BANK n] DPEEK a Reads a double-byte (16 bit word) from memory address a or bank n offset a.
EXP x Returns the natural exponential function of e to the power x.
FN a() FN followed by a letter calls up a user-defined function (see keyword DEF FN).
IN n The result of inputting at processor level from port n
INKEY$ Reads the keyboard.
INT x Returns the Integer part of floating point expression x (Always rounds down)
INT { x } Returns an unsigned 16-bit integer expression, from any floating point expression x
LEN string Returns the length of string
LN x Natural logarithm (to base e).
Function Meaning
[BANK n] PEEK o Returns the byte at address o or if used with the optional BANK, the byte at offset o of bank n
[BANK n] PEEK$ (o,len|t) Reads memory region of length len stored in the addresses beginning with o and stores it in a string –or– Reads the string terminated with a user specified terminator t beginning with address o. With the optional BANK reads offset o of bank n.
PI Returns and approximation of π (3.14159265...)
POINT (x,y) Retruns 1 if the pixel at (x,y) is ink colour. 0 if it is paper colour.
REG n Reads state of Next Register n
RND [n|i] Returns the next pseudorandom number n in the range from 0 to 1 –or– the next pseudorandom integer number in the range of 0 to i-1
SCREEN$ (x, y) Returns the character that appears, either normally or inverted, on the display at line x, column y.
SGN x Signum; the sign (-1 for negative, 0 for zero or +1 for positive) of x.
SGN {i} Returns a signed 16-bit integer from integer expression i
SIN x Returns the sine of x in radians.
SQR x Returns the square root of x.
STR$ x Returns the string of characters that would be displayed if x were printed.
TAN x Returns the tangent of x in radians.
[BANK n] USR o Calls the machine code subroutine whose starting address is o. With optional BANK does the same for offset o in bank n. On return, the result is the contents of the bc register pair.
USR l The address of the bit pattern for the user-defined graphic corresponding to character l.
VAL f Evaluates string f (without its bounding quotes) as a numerical expression.
VAL$ f Evaluates string f (without its bounding quotes) as a string expression.

The Decimal System

Most European languages count using a more or less regular pattern of tens – in English, for example, although it starts off a bit erratically, it soon settles down into regular groups:

twenty, twenty one, twenty two, . . . twenty nine
thirty, thirty one, thirty two, . . . thirty nine
forty, forty one, forty two, . . . forty nine

This follows from using Arabic numerals, which have ten symbols 0 – 9, in a placeholder system where the position of each digit is multiplied by a power of ten. The reason for using ten as the basis of numbers is that we happen to have ten fingers.

The Binary System

Instead of using the decimal system, with ten as its base, computers use a system called binary, based on two values 0 and 1. Like humans have ten fingers, computer circuits have two states; low-voltage or off (0) and high-voltage (1). The two binary digits are called bits, and a bit is either 0 or 1. Computers therefore write 10 to represent 2, 100 to represent 4, 1000 to represent 8, and so on for the powers of 2.

It is customary to "pad out" binary numbers with leading zeroes so that they always contain at least four bits, called a nibble – for example, 0000, 0001, 0010, 0011 (representing 0 to 3 decimal). The reason for doing this is that it makes it easy to represent long binary numbers more compactly using hexadecimal as we will see further below.

Throughout this manual we've written binary numbers either with the suffix of a lower case b or with the prefixes of @ and BIN as supported by the NextBASIC Integer expression evaluator.

Regardless of how useful it is to write numbers in the way computers understand them, we have the obvious problem of representing them on paper: it's much easier for us to write and understand

65535 + 65534 than 1111111111111111b + 1111111111111110b.

The Hexadecimal System

Binary numbers quickly become unwieldly because even modest quantities require long strings of 0s and 1s to represent them. This is a natural result of only using two symbols to

represent each digit. Hexadecimal (or hex for short) was adopted to easily and compactly represent binary numbers. Hexadecimal is a base 16 numbering system with 16 symbols. 0 through 9 are used for the first ten symbols, representing decimal values 0 – 9, and the last six symbols are A, B, C, D, E, F representing decimal values 10 – 15. What comes after F? Just as in decimal we write 10 for ten, in hexadecimal we write 10 for sixteen since each position is associated with a power of 16.

The reason why hexadecimal is so well suited to representing binary numbers is that sixteen is a power of 2. This means binary digits can be grouped together and directly converted to a hexadecimal digit. Since sixteen is the fourth power of 2, four binary digits – a nibble – can be represented by a single hexadecimal digit. Conversion between binary and hexadecimal can then be done by sight and hexadecimal becomes a quick way to represent large binary quantities as well as an easy way to visualize bit patterns.

The table below shows the correspondence between binary, hexadecimal and decimal values:

Binary0000000100100011010001010110011110001001101010111100110111101111
Hexadecimal0123456789ABCDEF
Decimal0123456789101112131415

To convert hex to binary, change each hex digit into a nibble (four bits), using the table above. Conversely, to convert binary to hex, divide the binary number into nibbles, starting on the right, and then change each group into the corresponding hex digit.

Throughout this manual, we've written hexadecimal numbers suffixed by a lower case letter h or prefixed by $ as the latter notation is the one supported by the NextBASIC Integer Expression evaluator.

Bits, Bytes and Words

The bits inside the computer are mostly grouped into sets of eight – these are called bytes. A single byte can represent any number from 0 to 255 decimal (11111111b or FFh). A single byte can also represent any character in the ZX Spectrum Next character set. Its value can be written with two hex digits.

Two bytes can be grouped together to make what is called a word. A word can be written using sixteen bits or four hex digits, and represents a number from 0 to 65535 decimal.

A byte is always eight bits, but words vary in length from computer to computer. In Sinclair computer tradition, 16-bit numbers are called words while 32-bit numbers are called long words.

Setting a bit means making a specific bit 1. Resetting a bit means making a specific bit 0. In digital logic, there is also a concept of "active low" and "active high". This means a signal becomes active when it is 0 or 1 respectively. The Z80n has an M̅R̅E̅Q̅ (or /MREQ) signal, for example. This is an "active low" signal; to distinguish them from "active high" signals, we usually write active low signals with a bar over their names (Or prefix them with a forward slash /). This means the Z80n indicates a memory cycle by making M̅R̅E̅Q̅ 0.

Using Binary and Hex in NextBASIC

Our first introduction to binary and hex was in Chapter 7 which introduced Integer Expressions. Chapter 14 introduced the use of the BIN keyword. Chapter 16 showed us how useful binary was in defining colours with the PALETTE keyword while Chapters 23 and 24 with the introduction of binary bitmasks for the REG and OUT keywords and the memory address space showed the usefulness of hexadecimal.

In reality many keyword parameters are binary; As an example ATTR and RUN AT's decimal parameters are really decimal "translations" of the bits that are being set inside the computer's memory or the Next Registers that these keywords control.


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.