Sinclair BASIC

From SinclairFAQ
Jump to: navigation, search

Sinclair BASIC is the programming language (and operating system) used in the ZX80, ZX81 and ZX Spectrum, developed by Nine Tiles Ltd.

A detailed account of its history is available in the Sinclair BASIC history article.

Beta BASIC (for the Spectrum) and SAM BASIC (for the SAM Coupé), maintain compatibility with Spectrum BASIC, but add additional features. Both were developed by Dr Andrew Wright, trading as BetaSoft.

USR keyword

Sinclair BASIC provides a USR function for entering machine code programs from BASIC. Any statement using USR must attempt to make use of the result in some way, even if the program will never return. It is therefore typical to see statements such as "RANDOMIZE USR <address>" where the return value is not needed. SAM BASIC includes a CALL statement, which takes a long address compatible with the LOAD and SAVE statements on that machine.

The IY register must be preserved if the Spectrum ROM's interrupt handler is to be used, and so must therefore be saved if returning from a USR routine. Its value must be restored to 0x5c3a ("ERRNO", at 23610 in decimal) in these conditions, although it arguably more portable to save the value in IY, rather than to assume that it will always be 0x5c3a. HL′ and SP must also be preserved.