Sinclair BASIC

Sinclair BASIC
Paradigm Imperative
Developer Nine Tiles Networks, Sinclair
First appeared 1979 (1979)
Platform ZX80, ZX81, ZX Spectrum
License Proprietary

Sinclair BASIC is a dialect of the BASIC programming language 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]

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 ANSI minimal BASIC standard with integer arithmetic only, known as 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.

Currently, interpreters exist for modern operating systems (as well as for vintage systems) that allow Sinclair Basic to be easily used.

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!"
  20 STOP

Keywords

On the 16K/48K ZX Spectrum, there are 88 keywords in Sinclair BASIC, denoting commands (of which there were 51), functions and logical operators (32), and other keywords (5):

Commands
BEEP, BIN, BORDER, BRIGHT,[note 1] CAT,[note 2] CIRCLE, CLEAR, CLOSE #,[note 2] CLS, CONTINUE, COPY, DATA, DEF FN, DIM, DRAW, ERASE,[note 2] FLASH,[note 1] FORMAT,[note 2] FOR,[note 3] GO SUB, GO TO, IF,[note 4] INK,[note 1] INPUT, INVERSE,[note 1] LET, LIST, LLIST, LOAD, LPRINT, MERGE, MOVE,[note 2] NEW, NEXT, OPEN #,[note 2] OUT, OVER,[note 1] PAPER,[note 1] PAUSE, PLOT, POKE, PRINT, RANDOMIZE, READ, REM, RESTORE, RETURN, RUN, SAVE, STOP, VERIFY
Functions and logical operators
ABS, ACS, AND,[note 5] ASN, ATN, ATTR, CHR$,[note 6] CODE,[note 6] COS, EXP, FN, INKEY$,[note 6] INT, IN, LEN, LN, NOT,[note 5] OR,[note 5] PEEK, PI, POINT, RND, SCREEN$,[note 6] SGN, SIN, SQR, STR$,[note 6] TAN, TO, USR,[note 7] VAL,[note 6] VAL$,[note 6][note 8]
Other keywords
AT, LINE, STEP, TAB, THEN[note 4]

They are entered via Sinclair's unique keyword entry system. The most common commands require just a single keystroke; for example, pressing just P at the start of a line on a Spectrum produces the entire 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 color-coded on the original Spectrum keyboard to indicate which mode is required.

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 with 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. As a result, a keyword uses just one byte of memory, 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 a single byte, and that the keywords didn't need to 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 single keypress for that command at the start of a line changes the editor from command mode to letter mode. As a consequence, variable assignment requires LET (i.e., LET a=1 not just a=1). This practice is also different from other BASIC dialects. Further, it meant that unlike other BASIC dialects the interpreter didn't require parentheses to identify functions; SIN x was sufficient, no SIN(x) required (although the latter would be 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 single-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.[3]

The 128K Spectrum models—the ZX Spectrum 128, +2, +3, +2A, and +2B—also stored keywords internally in single byte code points but used a conventional letter-by-letter BASIC input system. They also introduced two new commands:

The original Spanish ZX Spectrum 128 included four additional commands in Spanish,[4] one of which was undocumented. These can be translated as:

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) will give a substring starting with the 5th and ending with the 10th character of the variable a$. It is therefore possible to replace the LEFT$() and RIGHT$() commands simply by omitting the left or right array position respectively; for instance a$( TO 5) is equivalent to LEFT$(a$,5). Further, a$(5) alone is enough to replace MID$(a$,5,1).

Official versions

Other versions, extensions, derivatives and successors

Interpreters for the ZX Spectrum computer family[8]

Compilers for the ZX Spectrum computer family[8]

Derivatives and successors for other machines

See also

Notes

  1. 1 2 3 4 5 6 INK, PAPER, FLASH, BRIGHT, OVER and INVERSE set 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 a PRINT statement, to apply only from that point until the end of the statement.
  2. 1 2 3 4 5 6 CAT, ERASE, FORMAT and MOVE were 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 "*").
  3. The control variable of a FOR loop must consist of only one alphabetical character.
  4. 1 2 Unlike many other BASIC dialects, Sinclair Basic did not include the ELSE operator in the IFTHEN(–ELSE) clause. A workaround would be to use an IFTHENGO TO construct instead, bypassing the lines that would have been in an ELSE clause with the GO TO
  5. 1 2 3 The AND, NOT, and OR functions are logical operators.
  6. 1 2 3 4 5 6 7 String variable names must consist of only one alphabetical character. Thus, LET a=5, LET Apples=5, and LET a$="Hello" are all good, while LET Apples$="Fruit" is not.
  7. Machine code could be executed using the USR function, the value provided being the start address of the machine code to execute and the return value being the contents of the BC register pair (unlike most other Z80 based computers that returned the value of the HL register pair), thus LET a=USR 30000 would call the machine code subroutine starting at memory address 30000, and after it returns would store the value of the BC register pair into the variable a for further use.
  8. The VAL function does not just evaluate numbers, but also evaluates full expressions. For example, PRINT VAL a$ will output 14 when given an a$ of "3*3+4+COS 0". VAL$ does the same for string expressions.

References

  1. Garfield, Simon (2010-02-28). "Sir Clive Sinclair: "I don't use a computer at all"". The Guardian. Guardian Media Group. Retrieved 2011-05-23. He is keen to credit [...], not least Nine Tiles, the company that made the Basic operating software.
  2. 1 2 "ZX80 - 8K BASIC ROM UPGRADE".
  3. "Picture of ZX80".
  4. Spectrum 128 ROM Disassembly - Spanish Spectrum 128
  5. 1 2 http://www.worldofspectrum.org/ZXSpectrum128+3Manual/chapter7.html
  6. http://www.worldofspectrum.org/ZXSpectrum128Manual/sp128p06.html
  7. http://timex.comboios.info/tmxtechb64-2048.html
  8. 1 2 3 4 5 6 7 8 http://www.worldofspectrum.org/sinclairbasic/
  9. "Sinclair BASIC history".
  10. http://www.wearmouth.demon.co.uk/
  11. https://sites.google.com/site/ulaplus/
  12. http://www.fruitcake.plus.com/Sinclair/Interface2/Cartridges/Interface2_RC_New_3rdParty_SEBASIC.htm
  13. https://sourceforge.net/projects/sebasic/
  14. http://www.worldofspectrum.org/infoseekid.cgi?id=0008254
  15. http://www.worldofspectrum.org/infoseekid.cgi?id=0008249
  16. http://www.worldofspectrum.org/infoseekid.cgi?id=0008329
  17. http://www.worldofspectrum.org/infoseekid.cgi?id=0008696
  18. http://www.worldofspectrum.org/infoseekid.cgi?id=0008282
  19. http://www.worldofspectrum.org/infoseekid.cgi?id=0008693
  20. http://www.worldofspectrum.org/infoseekid.cgi?id=0009452
  21. http://rk-internet.com/eZXSparky/
  22. http://www.shadowmagic.org.uk/spectrum/basic.html
  23. http://www.shadowmagic.org.uk/spectrum/checkbasic.html
  24. http://cartesianproduct.wordpress.com/binsic-is-not-sinclair-instruction-code/
  25. https://sites.google.com/site/ulaplus/home/zx-spin-and-basin
  26. https://sites.google.com/site/pauldunn/

Bibliography

External links

This article is issued from Wikipedia - version of the 11/29/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.