Sinclair BASIC
Sinclair BASIC is a dialect of the programming language BASIC used in the 8-bit home computers from Sinclair Research and Timex Sinclair. The Sinclair BASIC interpreter was made by Nine Tiles Networks Ltd.[1]
| Paradigm | Imperative | 
|---|---|
| Designed by | John Grant, Steve Vickers | 
| Developer | Nine Tiles Networks, Sinclair Research | 
| First appeared | 1979 | 
| Platform | ZX80, ZX81, ZX Spectrum | 
| License | Proprietary | 
History
    
Sinclair BASIC was originally developed in 1979 for the ZX80 by Nine Tiles. The programmers were John Grant, the owner of Nine Tiles, and Steve Vickers.
It was initially an incomplete implementation of the 1978 American National Standards Institute (ANSI) minimal BASIC standard with integer arithmetic only, termed the 4K BASIC (for its ROM size) for the ZX80. It evolved through the floating-point 8K BASIC for the ZX81 and TS1000 (which was also available as an upgrade for the ZX80[2]), and became an almost complete version in the 16 KB ROM ZX Spectrum. It is present in all ZX Spectrum compatibles.
As of 2015, interpreters exist for modern operating systems, and older systems, that allow Sinclair Basic to be used easily.
Syntax
    
New BASIC programmers might start with a simple program, perhaps using the language's PRINT statement to display a message on the screen; a well-known and often-replicated example is Kernighan and Ritchie's Hello world program:
  10 PRINT "Hello, World!"
Keywords
    
On the 16K/48K ZX Spectrum, there are 88 keywords in Sinclair BASIC, denoting commands (of which there are 50), functions and logical operators (31), and other keywords (16, including 9 which are also commands or functions):
| Keyword | Parameters[note 1] | Entered using[note 2] | Type | Summary | 
|---|---|---|---|---|
| ABS | number | EXTENDED MODE then G | Function | Returns the absolute value of number[3] | 
| ACS | number | EXTENDED MODE then SYMBOL SHIFT+W | Function | Returns the arccosine of number[4] | 
| AND | SYMBOL SHIFT+Y | Logical operator | Returns true if both conditions on either side of the ANDkeyword are true, else returns false[note 3][5] | |
| ASN | number | EXTENDED MODE then SYMBOL SHIFT+Q | Function | Returns the arcsine of number[6] | 
| AT | line, column; | SYMBOL SHIFT+I | Other | Used in a PRINTstatement to print at the line and column specified;[7] for example,PRINT AT 5,10;"*"puts a star in column 10 of line 5. | 
| ATN | number | EXTENDED MODE then SYMBOL SHIFT+E | Function | Returns the arctangent of number[4] | 
| ATTR | (line, column) | EXTENDED MODE then SYMBOL SHIFT+L | Function | Returns a byte containing information on the colours of the text cell on the screen, corresponding to the specified lineandcolumn;note that, unlike most Sinclair BASIC keywords, the parentheses are required; the first three bits indicate the ink (foreground)colour, the fourth, fifth and sixth bits the paper (background) colour, the seventh bit whether the colours are bright or not, and the eight, whether they are flashing[8] | 
| BEEP | duration, pitch | EXTENDED MODE then SYMBOL SHIFT+Z | Command | Produces sound from the computer's speaker; durationis in seconds, pitch is in semitones above (positive value) or below (negative value) middle C[9] | 
| BIN | number | EXTENDED MODE then B | Other | Indicates numberis in binary notation[10] | 
| BORDER | number | B | Command | Sets the border of the screen to the colour specified by the number[note 4][11] | 
| BRIGHT | number | EXTENDED MODE then SYMBOL SHIFT+B | Command/other | Makes all following colours brighter if numberis 1, or its normal shade if 0[note 5][12] | 
| CAT | number | EXTENDED MODE then SYMBOL SHIFT+9 | Command | Displays contents of ZX Microdrive specified by number[note 6][13] | 
| CHR$ | number | EXTENDED MODE then U | Function | Returns the character corresponding to the decimal numberin the computer's character set[14] | 
| CIRCLE | x, y, r | EXTENDED MODE then SYMBOL SHIFT+H | Command | Draws a circle with its centre at coordinates ( x,y) and radiusr[15] | 
| CLEAR | address | X | Command | Clears the screen,[16] all variables and the GO SUBstack,[17] and optionally sets the maximum RAM address to be used by BASIC[18] | 
| CLOSE # | number | EXTENDED MODE then SYMBOL SHIFT+5 | Command | Closes the specified stream number for access[note 6] | 
| CLS | V | Command | Clears all text and graphics from the screen[16] | |
| CODE | string | EXTENDED MODE then I | Function/other | Returns the number corresponding to the first character in stringin the computer's character set;[14] also used to save arbitrary chunks memory to tape, disk, etc. and load them back in — seeLOAD,SAVEandVERIFYfor details | 
| CONTINUE | C | Command | Restarts a program after it has stopped due to an error or the user pressing the CAPS SHIFT+SPACE or BREAK keys[19] | |
| COPY | Z | Command | Sends the currently displayed screen to the printer[20] | |
| COS | number | EXTENDED MODE then W | Function | Returns the cosine of number[21] | 
| DATA | comma-separated values | EXTENDED MODE then D | Command/other | Provides numbers and/or strings to use with the READcommand[22] and allows saving the contents of an array to tape when used with theSAVEcommand[23] (asSAVE filename DATA array name() | 
| DEF FN | name(variable) = operation | EXTENDED MODE then 1 | Command | Defines a custom function that can be used with the FNcommand;function definitions must be of the formf(x)=operations, for examplef(x)=x*2and the function name may not consist of more than one letter, plus a $-symbol if the function returns a string[24] | 
| DIM | variable(dimensions) | D | Command | Declares an array with the specified dimensions, which may be multi-dimensional (for example,DIM a(10,10); if used with strings, the last dimension indicates the length of each of the strings (thus,DIM a$(2,5)is an array of two strings each of five characters long, andDIM b$(5)is one string of five characters)[25] | 
| DRAW | x, y [, r] | W | Command | Draws a line in the current INKcolour to coordinates (x,y) from the coordinates used by the previousPLOTorDRAWcommand; if the optionalris supplied, it indicates the radius of the circle segment to be drawn, in radians[26] | 
| ERASE | drive;"filename" | EXTENDED MODE then SYMBOL SHIFT+7 | Command | Deletes the specified file from a ZX Microdrive[note 6][27] | 
| EXP | number | EXTENDED MODE then X | Function | Returns e to the power number[28] | 
| FLASH | number | EXTENDED MODE then SYMBOL SHIFT+V | Command/other | Makes all following text alternate its foreground ( INK) and background (PAPER) colours[note 5] | 
| FN | function(value) | EXTENDED MODE then SYMBOL SHIFT+2 | Function | Calls the functiondefined earlier in the program usingDEF FN[24] | 
| FORMAT | drive;"name" | EXTENDED MODE then SYMBOL SHIFT+0 | Command | Formats the cartridge in the indicated Microdrive and assigns it the identifier name[note 6][29] | 
| FOR | variable = start TO end | F | Command | Starts a FOR-NEXTloop;[30] the variable name may only be one character long[31] | 
| GO SUB | number | H | Command | Makes the program jump to the BASIC line specified by number; when the program encounters the commandRETURN, it will jump back to the statement after theGO SUB[32] | 
| GO TO | number | G | Command | Makes the program jump to the BASIC line specified by number | 
| IF  | condition THEN | U | Command | Evaluates the condition, and if true, executes the statement that follows the keywordTHENthat must come after the condition,[33] for exampleIF a=1 THEN LET b=2[note 7] | 
| IN | address | EXTENDED MODE then SYMBOL SHIFT+I | Function | Returns a byte read from the hardware input/output port corresponding to the address[34] | 
| INK | number | EXTENDED MODE then SYMBOL SHIFT+X | Command/other | Sets the foreground colour for text and graphics[note 4][note 5][35] | 
| INKEY$ |  | EXTENDED MODE then SYMBOL SHIFT+Z | Function | Returns a string representing the key being pressed on the keyboard at the moment the function is called, or an empty string if none is,[36] but does not wait for a keypress | 
| INPUT | [prompt,] variable | I | Command | Halts program execution until the user types in something on the keyboard and presses the Enterkey, then stores the entered value in the specifiedvariable; if the optionalpromptis supplied, this will be shown on the screen[37] | 
| INT | number | EXTENDED MODE then R | Function | Returns the integer value of number, rounding down to the nearest whole number[3] (thus,INT -1.1returns −2, not −1) | 
| INVERSE | number | EXTENDED MODE then SYMBOL SHIFT+M | Command/other | Reverses the colours on all following text if numberis 1, so that it uses the current ink colour for the background and the current paper colour for the text, or sets them back to normal ifnumberis 0[note 5][38] | 
| LEN | string | EXTENDED MODE then K | Function | Returns the number of characters (bytes) in string[39] | 
| LET | variable=value | L | Command | Assigns valueto the named variable[40] | 
| LINE |  | EXTENDED MODE then SYMBOL SHIFT+3 | Other | |
| LIST | [number] | K | Command | Outputs the current BASIC program to the screen; if the optional numberis provided, it omits all lines with a lower number[42] | 
| LLIST | [number] | EXTENDED MODE then SYMBOL SHIFT+V | Command | As LISTexcept the listing is output to the printer[20] | 
| LN | number | EXTENDED MODE then SYMBOL SHIFT+Z | Function | Returns the natural logarithm of number[43] | 
| LOAD | "[filename]" [CODE [address[, length]]| DATA variable()] | J | Command | Loads a program or data into RAM from tape, ZX Microdrive, disk, etc., deleting any existing BASIC program and variables;[37] if an empty string ( "") is provided, this loads the first program found, else it will search the tape for the program named in the string; if the optionalCODEis provided, will load the program into memory at the address it had when it was saved, or at the specifiedaddress(lengthis intended as a safety, to try and load the right program in case there are multiple on the tape with the right name but of different lengths);[44] if the optionalDATA variable()is provided, will load the data from the tape into the array namedvariable()[23] | 
| LPRINT | text | EXTENDED MODE then SYMBOL SHIFT+C | Command | As PRINTexcept output is sent to the printer[20] | 
| MERGE | "[filename]" | EXTENDED MODE then SYMBOL SHIFT+T | Command | As LOAD, except it does not delete the current program and variables; if a line number exists in both, that of the newly loaded program overwrites the existing one.  UsingMERGEprevents a program saved usingLINEfrom auto-running once loaded[45] | 
| MOVE | stream1 TO stream2 | EXTENDED MODE then SYMBOL SHIFT+6 | Command | Moves data from one stream (keyboard, screen, file, printer, network, etc.) to another[note 6][46] | 
| NEW | A | Command | Erases the current BASIC program and all variables[37] | |
| NEXT | variable | N | Command | Closes a FOR-NEXTloop; the variable must match that of the correspondingFORcommand[47] — "empty"NEXTs to refer to the immediately precedingFORin the program are not allowed | 
| NOT | condition | SYMBOL SHIFT+S | Logical operator | Returns true if the conditionis false, else returns false[note 3][5] | 
| OPEN # | stream | EXTENDED MODE then SYMBOL SHIFT+4 | Command | Opens a stream for reading from and/or writing to[note 6][48] | 
| OR | SYMBOL SHIFT+Y | Logical operator | Returns true if either of the conditions on either side of the ORkeyword are true, else returns false[note 3][5] | |
| OUT | address, value | EXTENDED MODE then SYMBOL SHIFT+O | Command | Sends the value(a byte) to the hardware [Memory-mapped I/O|input/output port] corresponding to theaddress[34] | 
| OVER | number | EXTENDED MODE then SYMBOL SHIFT+N | Command/other | Will make following text overprint with an XOR operation what is already on the screen if numberis 1, instead of erasing it, or erase it ifnumberis 0[note 5][38] | 
| PAPER | number | EXTENDED MODE then SYMBOL SHIFT+C | Command/other | Sets the background colour for text and graphics[note 4][note 5][35] | 
| PAUSE | delay | M | Command | Halts program execution for the specified delay, in  of a second in Europe or  in North America[49] (thus, PAUSE 50halts for one second in Europe) | 
| PEEK | address | EXTENDED MODE then O | Function | Returns a byte representing the contents of the memory location pointed to by address[50] | 
| PI |  | EXTENDED MODE then M | Function | Returns the value of pi[43] | 
| PLOT | x, y | Q | Command | Draws a pixel in the current INKcolour on the screen at the coordinates (x,y)[51] | 
| POINT | (x,y) | EXTENDED MODE then SYMBOL SHIFT+8 | Function | Returns 1 if the pixel pointed at graphical coordinates ( x,y) is currently in the ink (foreground) colour, else returns 0[15] | 
| POKE | address, value | O | Command | Sets the contents of addressin RAM tovalue[52] | 
| PRINT | [AT x,y;] text | P | Command | Prints text(which must be a string or a number) to the screen;[40] if used withAT, will print at the specified text coordinates, else in the first column of the line after that used by the lastPRINTstatement[7] | 
| RANDOMIZE | [number] | T | Command | Initializes the random number generator; if used without a number(or with 0), it does this based on the computer's internal clock, else it uses thenumbersupplied, which must be in the range [1,65535][53] | 
| READ | variable | EXTENDED MODE then A | Command | Takes a value from a DATAstatement and stores it in the namedvariable: the first timeREADis used, it gets the first value after the firstDATA, the second time it gets the next one, and so on[22] | 
| REM | text | E | Command | Begins a comment in the source code, meaning that everything after the REMstatement is ignored, until the end of the line[37] — note this includes everything after a colon, which normally begins a new segment:10 REM Nothing to see here : PRINT "Unprintable"will not produce any output, for example | 
| RESTORE | [number] | EXTENDED MODE then S | Command | Resets where READcommands look for values inDATAstatements: if used without a number, the nextREADwill use the firstDATAin the program, with a number it will use the firstDATAon or after the line whose number is indicated[54] | 
| RETURN | Y | Command | Returns execution to the first statement following the last GO SUBcommand that was executed[32] | |
| RND |  | EXTENDED MODE then T | Function | Returns a pseudo-random number with eight significant figures in the range [0,1)[55] | 
| RUN | [number] | R | Command | Starts the current BASIC program, from its first line if no numberis specified, else from the line with that number (or the first one after, if it does not exist)[56] | 
| SAVE | "filename" [DATA variable() | LINE number] | S | Command | Saves the current BASIC program to tape or other storage device, with the filenamespecified; if the optionalLINEfollowed by a line number is used, then the program will start automatically at the indicated line number when it isLOADed back in; with the optionalDATA, the command saves the contents of the array named by the variable instead of the current BASIC program[23] | 
| SCREEN$ | [(line, column)] | EXTENDED MODE then SYMBOL SHIFT+ | Function/other | As a function, identifies the character at the specified line and column on the screen.[7]  Used after the filename in a LOADorSAVEcommand, indicates that the contents of the display memory should be loaded or saved; this essentially makes it a shortcut forCODE 16384,6912[note 8] but does not work withVERIFYbecause the contents of the display memory will be different by the time that command reads back the saved data;[57] | 
| SGN | number | EXTENDED MODE then F | Function | Returns 1 if numberis positive, 0 if it is 0, and −1 if it is negative[3] | 
| SIN | number | EXTENDED MODE then Q | Function | Returns the sine of number[21] | 
| STEP | number | SYMBOL SHIFT+D | Other | Indicates the interval used by a FORstatement,[31] for exampleFOR n=2 TO 6 STEP 2will skipn=3andn=5in the loop | 
| STOP | SYMBOL SHIFT+A | Command | Ends execution of the current program, exiting to the BASIC editor; can also be given when the computer is waiting for input using the INPUTcommand;[56] once the program is stopped, it can be resumed withCONTINUE | |
| SQR | number | EXTENDED MODE then H | Function | Returns the square root of number[24] | 
| STR$ | number | EXTENDED MODE then Y | Function | Returns the character from the computer's character set corresponding to number[58] | 
| TAB | column | EXTENDED MODE then P | Other | In a PRINTstatement, makes sure that the text to be output begins in the column specified, wrapping to the next line as necessary, but never more than one line[16] | 
| TAN | number | EXTENDED MODE then E | Function | Returns the tangent of number[59] | 
| THEN | statement | SYMBOL SHIFT+G | Other | Follows the condition in an IFstatement to indicate what should happen when the condition evaluates to true[note 7][33] | 
| TO |  | SYMBOL SHIFT+F | Other | Indicates a range from the number to the left of TOto the number of the right of it, inclusive;[60] when used withFORboth numbers must be supplied, while if used to slice strings, either may be left off to indicate the start or end of the string | 
| USR | string or address | EXTENDED MODE then L | Function | When called with a single-character string, this returns the memory address at which the glyph for the user-defined graphic character corresponding to that character is defined.[10] If called with an address, it starts machine code execution at that address (thus making it one of the few Sinclair BASIC functions to have a Side effect) and returns the contents of the Z80’s BC register pair.[61] | 
| VAL | string | EXTENDED MODE then J | Function | Evaluates the stringas a number and returns the result;[62] this can perform calculations:VAL "1+2"returns 3, for example, and also evaluates variables and even otherVALstatements:LET a=1: VAL "a+VAL ""2"""[note 9] also returns 3 | 
| VAL$ | string | EXTENDED MODE then SYMBOL SHIFT+J | Function | Similar to VALbut evaluates the string as a string[3] | 
| VERIFY | "[filename]" | EXTENDED MODE then SYMBOL SHIFT+R | Command | Reads a program or data from tape or other storage, much like LOAD, but instead of loading it into memory, compares it with the program or data that is already in memory. This is intended to be used immediately after aSAVEcommand, to make sure the program or data has been saved without corruption.[63] | 


Keyword entry
    
In 48K models and older, the keywords are entered via Sinclair's unique keyword entry system, as indicated on the table. The most common commands need one keystroke only; for example, pressing only P at the start of a line on a Spectrum produces the full command PRINT. Less frequent commands require more complex key sequences: BEEP (for example) is keyed by pressing CAPS SHIFT plus SYMBOL SHIFT to access extended mode (later models include an EXTENDED MODE key), keeping SYMBOL SHIFT held down and pressing Z. Keywords are colour-coded on the original Spectrum keyboard to indicate which mode is required:[64]
- White: key only
- Red on the key itself: SYMBOL SHIFT plus the key
- Green above the key: EXTENDED MODE followed by the key
- Red below the key: EXTENDED MODE followed by SYMBOL SHIFT plus the key
The ZX81 8K BASIC used the shorter forms GOTO, GOSUB, CONT and RAND, whereas the Spectrum used the longer forms GO TO, GO SUB, CONTINUE and RANDOMIZE. The ZX80 4K BASIC also used these longer forms but differed by using the spelling RANDOMISE. The ZX81 8K BASIC was the only version to use FAST, SCROLL, SLOW and UNPLOT. The ZX80 4K BASIC had the exclusive function TL$(); it was equivalent to the string operator (2 TO ) in later versions.
Unique code points are assigned in the ZX80 character set, ZX81 character set and ZX Spectrum character set for each keyword or multi-character operator, i.e. <=,  >=, <>, "" (tokenized on the ZX81 only), ** (replaced with ↑ on the Spectrum). These are expanded by referencing a token table in ROM. Thus, a keyword uses one byte of memory only, a significant saving over traditional letter-by-letter storage. This also meant that the BASIC interpreter could quickly determine any command or function by evaluating one byte, and that the keywords need not be reserved words like in other BASIC dialects or other programming languages, e.g., it is allowed to define a variable named PRINT and output its value with PRINT PRINT. This is also related to the syntax requirement that every line start with a command keyword, and pressing the one keypress for that command at the start of a line changes the editor from command mode to letter mode. Thus, variable assignment requires LET (i.e., LET a=1 not only a=1). This practice is also different from other BASIC dialects. Further, it meant that unlike other BASIC dialects, the interpreter needed no parentheses to identify functions; SIN x was sufficient, no SIN(x) needed (though the latter was allowed). The 4K BASIC ROM of the ZX80 had a short list of exceptions to this: the functions CHR$(), STR$(), TL$(), PEEK(), CODE(), RND(), USR() and ABS() did not have one-byte tokens but were typed in letter-by-letter and required the parentheses. They were listed as the INTEGRAL FUNCTIONS on a label above and to the right of the keyboard.[65]
The 128K Spectrum models, the ZX Spectrum 128, +2, +3, +2A, and +2B, also stored keywords internally in one-byte code points, but used a conventional letter-by-letter BASIC input system. They also introduced two new commands:
- PLAY, which operated the 128k models' General Instrument AY-3-8910 music chip
- SPECTRUM, which switched the 128k Spectrum into a 48k Spectrum compatibility mode
The original Spanish ZX Spectrum 128 included four additional commands in Spanish,[66] one of which was undocumented. These can be translated as:
- EDIT(to edit a line number or invoke the full screen string editor)
- RENUM(to renumber the program lines)
- DELETE(to delete program lines)
- WIDTH(to set the column width of the RS232 device, but undocumented as the code was broken)
Unlike the LEFT$(), MID$() and RIGHT$() functions used in the ubiquitous Microsoft BASIC dialects for home computers, parts of strings in Sinclair BASIC are accessed by numeric range. For example, a$(5 TO 10) gives a substring starting with the 5th and ending with the 10th character of the variable a$. Thus, it is possible to replace the LEFT$() and RIGHT$() commands by simply omitting the left or right array position respectively; for example a$( TO 5) is equivalent to LEFT$(a$,5). Further, a$(5) alone is enough to replace MID$(a$,5,1).
Variable names
    
Variables holding numeric values may be any length, while string and array variable names must consist of only one alphabetical character. Thus, LET a=5, LET Apples=5, LET a$="Hello", DIM a(10) and DIM a$(10) are all good, while LET Apples$="Fruit", DIM Apples(10) and DIM Apples$(10) are not.
The long variable names allowed for numeric variables can include alphanumeric characters after the first character, so LET a0=5 is allowed but not LET 0a=5. The long variable names can also include spaces, which are ignored, so LET number of apples = 5 is the same as LET numberofapples = 5
Official versions
    
    4K BASIC
    
- 4K BASIC for ZX80[67] (so named for residing in 4 KiB read-only memory (ROM)), was developed by John Grant of Nine Tiles for the ZX80. It has integer-only arithmetic.
- System Commands: NEWRUNLISTLOADSAVE
- Control Statements: GOTOIFTHENGOSUBSTOPRETURNFORTONEXTCONTINUE
- Input/Output Statements: PRINTINPUT
- Assignment Statement: LET
- Other Statements: CLEARCLSDIMREMRANDOMIZEPOKE
 
- System Commands: 
8K BASIC
    
- 8K BASIC is the ZX81 BASIC (also available as an upgrade for the ZX80[2]), updated with floating-point arithmetic by Steve Vickers, so named for residing in 8 KiB ROM.
- Statements: PRINTRANDLETCLEARRUNLISTGOTOCONTINPUTNEWREMPRINTSTOPBREAKIFSTOPFORNEXTTOSTEPSLOWFASTGOSUBRETURNSAVELOADCLSSCROLLPLOTUNPLOTPAUSELPRINTLLISTCOPYDIMPOKENEW
- Functions: ABSSGNSINCOSTANASNACSATNLNEXPSQRINTPIRNDFUNCTIONLENVALSTR$NOTCODECHR$INKEY$ATTABINKEY$PEEKUSR
 
- Statements: 
48 BASIC
    
- 48 BASIC is the BASIC for the original 16/48 kB random-access memory (RAM) ZX Spectrum (and clones), with colour and more peripherals added by Steve Vickers and John Grant. It resides in 16 KiB ROM and began to be called 48 BASIC with the introduction of the ZX Spectrum 128 at which time the 16 kB Spectrum was no longer sold and most existing ones in use had been upgraded to 48 kB[68]
128 BASIC
    
- 128 BASIC is the BASIC for the ZX Spectrum 128.[69] It offers extra commands and uses letter-by-letter input.
- New commands: LOAD !SAVE !MERGE !ERASEPLAY
 
- New commands: 
+3 BASIC
    
- +3 BASIC is the BASIC with disk support for the ZX Spectrum +3 and +2A.[68]
- New commands: FORMATCOPY
 
- New commands: 
T/S 2000 BASIC
    
- T/S 2000 BASIC is used on the Spectrum-compatible Timex Sinclair 2068 (T/S 2068) and adds the following six new keywords:
- DELETEdeletes BASIC program line ranges. CAPS SHIFT+0 with the- Kcursor produces the command- DELETE.
- FREEis a function that gives the amount of free RAM.- PRINT FREEwill show how much RAM is free.
- ON ERRis an error-handling function mostly used as- ON ERR GO TOor- ON ERR CONT.
- RESETcan be used to reset the behaviour of- ON ERR. It was also intended to reset peripherals.
- SOUNDcontrols the AY-3-8192 sound chip.
- STICKis a function that gives the position of the internal joystick (Timex Sinclair 2090).
 
BASIC64
    
- BASIC64 by Timex of Portugal, is a software extension[70] to allow better Basic programming with the 512×192 and dual display areas graphic modes available only on Timex Sinclair computers. This extension adds commands and does a complete memory remap to avoid the system overwriting the extended screen memory area. Two versions exist due to different memory maps - a version for TC 2048 and a version for T/S 2068 and TC 2068.
- PRINT #Prints to a specific output channel.
- LIST #Lists the program to a specific output channel.
- CLS*Clears both display areas.
- INK*Sets ink colour for both display areas
- PAPER*Sets paper colour both display areas
- SCREEN$Selects the high / normal resolution modes.
- PLOT*Plots a pixel and updates the drawing position.
- LINEDraws a line from the previous PLOT position, supporting arc drawing
- CIRCLE*Draws a circle or oval, depending on screen mode.
 
Timex Extended Basic
    
- Timex Extended Basic by Timex of Portugal is used on the Timex Computer 3256, adding TEC - Timex Extended Commands commands supporting the AY-3-8912 sound chip, RS232 network and the 512x192 pixel high resolution graphic mode.[71][72]
- RAM drive commands: LOAD!SAVE!CAT!MERGE!ERASE!CLEAR!
- RS232 commands: FORMAT!LPRINTLLIST
- AY-3-8912 commands: BEEP!
- 512x192 resolution commands: SCREEN$DRAW!PLOT!CIRCLE!
 
- RAM drive commands: 
Other versions, extensions, derivatives and successors
    
    Interpreters for the ZX Spectrum family
    
Several ZX Spectrum interpreters exist.[73]
- Beta BASIC by Dr. Andy Wright, was originally a BASIC extension, but became a full interpreter.
- YS MegaBasic by Mike Leaman.[73]
- ZebraOS by Zebra Systems in New York, a cartridge version of T/S 2000 BASIC that used the 512×192 screen mode.
- Sea Change ROM by Steve Vickers and Ian Logan, modified by Geoff Wearmouth, a replacement ROM with an enhanced Sinclair BASIC.[74]
- Gosh Wonderful by Geoff Wearmouth, a replacement ROM that fixes bugs and adds a tokenizer, stream lister, delete and renumber commands.[73][75]
- OpenSE BASIC (formerly SE BASIC) by Andrew Owen, a replacement ROM with bug fixes and many enhancements including ULAplus[76] support, published as open source in 2011[77][78]
Compilers for the ZX Spectrum family
    
Several ZX Spectrum compilers exist.[73]
- HiSoft COLT Compiler (a.k.a. HiSoft COLT Integer Compiler)[79]
- HiSoft BASIC (a.k.a. HiSoft BASIC Compiler), an integer and floating-point capable compiler[80]
- Laser Compiler[81]
- Softek 'IS' Integer Compiler[82] (successor to Softek Integer Compiler[83])
- Softek 'FP' Full Compiler[84]
- ZIP Compiler[85]
Derivatives and successors for other computers
    
- SuperBASIC, a much more advanced BASIC dialect introduced with the Sinclair QL personal computer, with some similarities to the earlier Sinclair BASICs
- SAM Basic, the BASIC on the SAM Coupé, generally considered a ZX Spectrum clone
- ROMU6 by Cesar and Juan Hernandez - MSX[73]
- Spectrum 48 by Whitby Computers - Commodore 64[73]
- Sparky eSinclair BASIC by Richard Kelsh, an operating system loosely based on ZX Spectrum BASIC - Zilog eZ80[86]
- Sinbas by Pavel Napravnik - DOS[73]
- Basic[87] (and CheckBasic[88]) by Philip Kendall - Unix
- BINSIC[89] by Adrian McMenamin, a reimplementation in Groovy closely modelled on ZX81 BASIC - Java
- BASin[90] by Paul Dunn, a complete Sinclair BASIC integrated development environment (IDE) based on a ZX Spectrum emulator[73] - Windows
- SpecBAS[91] (a.k.a. SpecOS) by Paul Dunn, an integrated development environment (IDE) providing an enhanced superset of Sinclair BASIC - Windows, Linux, Pandora, and Raspberry Pi
- ZX-Basicus[92] by Juan-Antonio Fernández-Madrigal, a synthesizer, analyzer, optimizer, interpreter and debugger of Sinclair BASIC 48K for PCs, freely downloadable for Linux and Windows.
See also
    
    
Notes
    
- Optional parameters are enclosed in [square brackets]
- These assume the computer is in K (keyword) mode, which it normally is at the start of a line when entering BASIC. On the Spectrum 16K and 48K, Extended Mode is entered by pressing CAPS SHIFT and SYMBOL SHIFT simultaneously rather than the EXTENDED MODE key that is present on the Spectrum+ and later models.
-  “False” in Sinclair BASIC equates to 0 (zero), everything else equates to “true”. Functions that return true-or-false values thus actually return 0 for false and 1 for true, while ANDusually returns the first of the conditions supplied for true, or 1 if no numerical values were given. For example,6 AND 7returns 6, whileNOT 6=7returns 1.
-  The available numbers for colours are:
 In all colour-related commands, the number 8 may be used to indicate “transparent” while in1 2 3 4 5 6 7 0 blue red magenta green cyan yellow white black INKandPAPERmay also be set to 9 for “contrast” — that is, to put a dark colour on a light background or vice versa automatically.
-  INK,PAPER,FLASH,BRIGHT,OVERandINVERSEset attributes for outputting text and graphics to the screen. They can be used either as commands, to apply to all subsequent output until set again, or within aPRINTstatement, to apply only from that point until the end of the statement.
-  CAT,ERASE,FORMATandMOVEwere originally designed to be used with peripherals, but at the launch of ZX Spectrum, they had not been completely implemented, such that their use generated an error message (Invalid Stream). Later with the aid of the ZX Interface 1 shadow ROM, they were used for the ZX Microdrive. (The shadow ROM was paged when the BASIC interpreter detected a syntax error, which is why most ZX Microdrive commands use a"*").
-  Unlike many other BASIC dialects, Sinclair Basic did not include the ELSEoperator in theIF–THEN[–ELSE] clause. A workaround would be to use anIF–THEN–GO TOconstruct instead, bypassing the lines that would have been in anELSEclause with theGO TO
- The Spectrum’s display memory starts at address 16384 and is 6912 bytes long
- A string inside a string must have its quotes doubled in Sinclair BASIC
References
    
-  Garfield, Simon (2010-02-28). "Sir Clive Sinclair: "I don't use a computer at all"". The Guardian. Retrieved 2011-05-23. He is keen to credit [...], not least Nine Tiles, the company that made the Basic operating software. 
- "ZX80 - 8K BASIC ROM Upgrade". www.fruitcake.plus.com.
- Vickers 1983, p. 59.
- Vickers 1983, p. 70.
- Vickers 1983, p. 85.
- Vickers 1983, p. 69–70.
- Vickers 1983, p. 101.
- Vickers 1983, p. 116.
- Vickers 1983, p. 135.
- Vickers 1983, p. 93.
- Vickers 1983, p. 113.
- Vickers 1983, p. 110–111.
- Cambridge Communication 1983, p. 15.
- Vickers 1983, p. 91.
- Vickers 1983, p. 123.
- Vickers 1983, p. 103.
- "World of Spectrum - Documentation - ZX Spectrum manual - Chapter 24". worldofspectrum.org.
- Vickers 1983, p. 168.
- Vickers 1983, p. 19.
- Vickers 1983, p. 151.
- Vickers 1983, p. 68.
- Vickers 1983, p. 41.
- Vickers 1983, p. 142.
- Vickers 1983, p. 60.
- Vickers 1983, p. 79–81.
- Vickers 1983, p. 11–123.
- Cambridge Communication 1983, p. 18.
- Vickers 1983, p. 66.
- Cambridge Communication 1983, p. 19.
- Vickers 1983, p. 31.
- Vickers 1983, p. 32.
- Vickers 1983, p. 37.
- Vickers 1983, p. 25.
- Vickers 1983, p. 159.
- Vickers 1983, p. 110.
- Vickers 1983, p. 131.
- Vickers 1983, p. 16.
- Vickers 1983, p. 112.
- Vickers 1983, p. 57.
- Vickers 1983, p. 13.
- Vickers 1983, p. 144.
- Vickers 1983, p. 15.
- Vickers 1983, p. 67.
- Vickers 1983, p. 142–143.
- Vickers 1983, p. 147.
- Cambridge Communication 1983, p. 39.
- Vickers 1983, p. 31–32.
- Cambridge Communication 1983, p. 22.
- Vickers 1983, p. 129.
- Vickers 1983, p. 130.
- Vickers 1983, p. 121.
- Vickers 1983, p. 163.
- Vickers 1983, p. 74.
- Vickers 1983, p. 42.
- Vickers 1983, p. 73.
- Vickers 1983, p. 14.
- Vickers 1983, p. 143.
- Vickers 1983, p. 58.
- Vickers 1983, p. 69.
- Vickers 1983, p. 32, 51.
- Vickers 1983, p. 180.
- Vickers 1983.
- Vickers 1983, p. 141.
- Vickers 1983, p. 7–8.
- "Picture of ZX80".
- "Spectrum 128 ROM Disassembly - Spanish Spectrum 128". www.fruitcake.plus.com.
- "Sinclair ZX80 User Manual 4K Basic for ZX80".
- "World of Spectrum - Documentation - ZX Spectrum +3 - Chapter 7". worldofspectrum.org.
- "World of Spectrum - Documentation - ZX Spectrum 128 Manual Page 6". worldofspectrum.org.
- "Timex tech info - Basic 64 for TC2048". timex.comboios.info.
- "Microsete N.º46, Maio 1987" (PDF). loadzx.com.
- "Timex Computer 3256, Timex Portugal". k1.spdns.de.
- "World of Spectrum - Sinclair BASIC - Home of the Sinclair Extended Basic Project". www.worldofspectrum.org. Archived from the original on 2002-10-13.
- "Sinclair BASIC history - Sinclair Wiki". sinclair.wiki.zxnet.co.uk.
- "The Incomplete Spectrum ROM Assembly". Archived from the original on 2015-09-01.
- "ULAplus". sites.google.com.
- "ZX Interface 2 - SE BASIC (3rd Party ROM Cartridge)". www.fruitcake.plus.com.
- "OpenSE BASIC". SourceForge.
- "World of Spectrum - HiSoft COLT Compiler". World of Spectrum.
- "World of Spectrum - HiSoft BASIC". World of Spectrum.
- "World of Spectrum - Laser Compiler". World of Spectrum.
- "World of Spectrum - Softek 'IS' BASIC Compiler". World of Spectrum.
- "World of Spectrum - Integer Compiler". World of Spectrum.
- "World of Spectrum - Softek 'FP' Full Compiler". World of Spectrum.
- "World of Spectrum - ZIP Compiler". World of Spectrum.
- "Sparky eZX BASIC Project". rk-internet.com.
- "Philip Kendall - Basic". www.shadowmagic.org.uk.
- "Philip Kendall - CheckBasic". www.shadowmagic.org.uk.
- "Binsic Is Not Sinclair Instruction Code". June 25, 2012.
- "ZX Spin and BASin - ULAplus". sites.google.com.
- "ZXDunny/SpecBAS". June 5, 2021 – via GitHub.
- "ZX-Basicus: analyzer/synthesizer/optimizer/interpreter of Sinclair BASIC programs for the ZX Spectrum 48K". jafma.net.
Bibliography
    
- Ardley, Neil (1984). Sinclair ZX Spectrum+ User Guide. Dorling Kindersley in association with Sinclair Research. ISBN 0-86318-080-9.
- Vickers, Steven (1982). Sinclair ZX Spectrum BASIC Programming. Sinclair Research.
- Vickers, Steven (1983). Sinclair ZX Spectrum BASIC Programming (2 ed.). Sinclair Research.
- Cambridge Communication (1983). Sinclair ZX Spectrum Microdrive and Interface 1 manual. Sinclair Research.
External links
    
- Sinclair ZX Spectrum BASIC Programming: The original 1982 manual by Steven Vickers (referenced above)
- Sinclair ZX81 Basic Programming: also by Vickers
- The History of Sinclair BASIC: By Andrew Owen
- Timex Computer World: Basic 64 user manual for Timex Computer 2048
- Sinclair BASIC grammar: A LL(1) grammar specification for parsing Sinclair BASIC 16/48K