An interpreter for a subset of BBC Basic II, as originally implemented for the BBC Model B Microcomputer.
To build from a source distribution, extracting the tarball and run:
./configure && make
sudo make install
To build from a clone of the repository, run:
autoreconf --install
./configure && make
Some sample BBC BASIC II programs can be found in the samples
directory,
and can be run as follows:
bbasic samples/flag.basic
Most features of BBC BASIC II are supported, with the main exception of those that deal with graphics, memory, and hardware.
The following keywords are supported:
ABS
- absolute valueACS
- arc-cosineAND
- logical or bitwise ANDASC
- return ASCII value of characterASN
- arc-sineATN
- arc-tangentBGET#
- get a byte from a fileBPUT#
- put a byte to a fileCHR$
- generate a character from its ASCII valueCLEAR
- forget all variables previously in use, except resident integersCLOSE#
- close a fileCOLOUR
- sets text and background colourCOS
- cosineCOUNT
- counts all the characters printed using PRINTDATA
-READ
- store and read data itemsDEF FN
- define a functionDEF PROC
-ENDPROC
- define a procedureDEG
- convert radians to degreesDIM
- create an arrayDIV
- integer divisionEND
- ends a programEOF#
- determine if end-of-file has been reachedEOR
- bitwise exclusive-ORERL
- line number of last errorERR
- error numberEXP
- exponential functionEXT#
- size of a fileFOR
-NEXT
-STEP
- loop constructGET
- wait for a key to be pressed and return the ASCII valueGET$
- wait for a key to be pressed and return the characterGOSUB
- go to a subroutineGOTO
- go to a line numberIF
-ELSE
- sets up a test conditionINKEY
- input the number of the key pressedINKEY$
- input the character of the key pressedINPUT
- input information from the userINPUT#
- input information from a fileINSTR
- search one string for the occurrence of another stringINT
- integer part of a numberLEFT$
- left substringLEN
- counts the number of characters in a stringLET
- assign a value to a variableLN
- natural logarithmLOCAL
- inform the computer a variable is local to a procedure or functionLOG
- base-10 logarithmMID$
- middle substringMOD
- remainder after divisionNOT
- logical NOTON
- alter the order in which BASIC executes a programON ERROR GOTO
- handle errorsON ERROR GOSUB
- handle errorsON ERROR OFF
- stop handling errorsOPENIN
- opens a file for readingOPENOUT
- opens a file for writingOPENUP
- opens a file for updatingOR
- logical or bitwise ORPI
- value of PIPRINT
- print words and numbers on the screenPRINT#
- print to a filePTR#
- select which item in a long file is to be read or written nextRAD
- convert degrees to radiansREM
- remarkREPEAT
-UNTIL
- loop constructREPORT
- report what the last error wasRESTORE
- move the data pointer from one set of data to anotherRETURN
- return from a subroutineRIGHT$
- right substringRND
- generate a random numberSGN
- determine the sign of a numberSIN
- sineSPC
- print multiple spaces on the screenSQR
- square rootSTOP
- interrupts a program and prints a messageSTRING$
- produce multiple copies of a stringSTR$
- converts a number to a stringTAN
- tangentTIME
- set or read the internal timerTRACE
- print each line number before executionVAL
- converts a string to a number
- Output of scientific format floating point numbers depends on the underlying standard C library, and may differ from that on the BBC Micro.
- Floating point arithmetic is performed at a higher level of
precision, being performed internally with a C
double
. - Flashing colours are not supported by the
COLOUR
keyword. - When called with a negative argument, the
RND
argument does reset the random number generator to a number based on the argument as required, but - unlike on the BBC Micro - it is not deterministic, and repeated calls with the same negative argument will reset the random number generator to different, unpredictable values. - The special internal file format used by the
PRINT#
andINPUT#
keywords differs for real variables. The BBC Micro stores them as&FF
followed by four bytes of mantissa and one byte exponent, while this implementation stores them as&FF
followed by a Cdouble
(64-bits if IEC 60559 is supported by the C implementation, but this is not guaranteed.) - Some error codes are not implemented, either because the underlying functionality is not supported (such as "Bad key", "Bad MODE", "Block?"), because the errors are caught by the parser before the program runs (such as "Mistake"), or because a hardware limitation is not enforced (such as "LINE space" and "No room").
- The original BBC BASIC II allows most keywords to be abbreviated
(e.g.
PRINT
can be abbreviated toP.
,PR.
,PRI.
orPRIN.
). This feature existed to maximum the use of limited memory, and is unnecessary on the kind of modern system which can run this interpreter, so it is omitted for simplicity and style. - Use of the
INKEY
andINKEY$
functions with a negative argument to check the current state of the keyboard directly, rather than the input buffer, is not supported.
Not yet implemented:
EVAL
- evaluate an expression
The following keywords are used during interactive operation, which is not supported:
AUTO
- automatic line numberingCHAIN
- load and run a programDELETE
- delete a group of lines from a programLIST
- list the program in memoryLISTO
- set list optionsLOAD
- load a programNEW
- remove a program from memoryOLD
- recover a program which has been recently deleted by NEWRENUMBER
- renumber a programRUN
- run a programSAVE
- save a program
In general, any graphical, sound, assembler and hardware capabilities are intentionally not supported, including the following keywords:
ADVAL
- analogue to digital converter valueCALL
- execute a piece of machine codeCLG
- clear the graphics screenCLS
- clear the text screenCOLOUR
- sets text and background colour. Foreground and background colours are (optionally) supported, but flashing colours are not.DRAW
- draws lines on the screenENVELOPE
- control the volume and pitch of soundsGCOL
- set the graphics colourHIMEM
- highest address of program and variablesLOMEM
- lowest address of variablesMODE
- select the display modeMOVE
- move the graphics cursorOPT
- assembler optionsOSCLI
- operating system command line interpreterPAGE
- address in memory where BASIC will store the user's programPLOT
- multi-purpose drawing statementPOINT
- find out the colour of a certain position on the screenPOS
- cursor positionSOUND
- generate sounds using the internal loudspeakerTAB
- print tabulationTOP
- address of first free memory location after user's programUSR
- call section of machine code programVDU
- send control characters to the VDU driversVPOS
- vertical position of cursorWIDTH
- overall page width