BASIC (an acronym of "Beginner's All-purpose Symbolic Instruction Code") is the Commodore 64's onboard programming language.
BASIC was invented in 1964 by two professors at Dartmouth College in the US: John Kemeny and Thomas Kurtz. Their goal was to create an easy-to-use language, so that "all students should be able to use a computer." This popularism later led to BASIC becoming the standard programming language for home micros in the 1970s and 80s, including the whole Commodore range.
Critics complained about BASIC's oversimplicity. Dijkstra criticized the 1975 version of BASIC for its lack of structure: "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC." But even more than 50 years later, BASIC is still in widespread use thanks to its user-friendliness.
Commodore 64 BASIC was based on the 1970s Microsoft BASIC standard, but it lacked many simple facilities, forcing users to PEEK and POKE memory locations to perform operations such as changing screen colors. This led to C64 programs often being filled with POKE statements that were difficult to understand. That changed when other vendors introduced extended versions of BASIC, such as Super BASIC. This article discusses standard Commodore BASIC.
CBM BASIC[edit | edit source]
Commodore developed a modified version of BASIC originally licensed from Microsoft in 1977. A series of different versions followed, all known as CBM-BASIC. There are several sub-dialects of which BASIC Version 2.0 is the most popular.
On Commodore systems BASIC is not only used as a programming language, but also as operating "shell", or environment. The operating system and BASIC was stored on a ROM (Read Only Memory) chip.
BASIC V2.0 of C64[edit | edit source]
Another overview is the article C64-Commands.
The operating system (OS) of the Commodore 64 is CBM BASIC version 2, which has 38911 BASIC bytes (chars) free in its memory (RAM). In a wider sense, all C64 commands, which are entered in BASIC's direct mode are BASIC commands.
The BASIC interpreter reports
READY. and the blinking cursor shows the user that the computer is ready for input. After a BASIC command is typed in correctly, the command will be executed; otherwise an error message will be reported, followed by READY.
Entering a BASIC program[edit | edit source]
By using BASIC commands with line numbers, the BASIC interpreter is adding this BASIC line to the BASIC memory as one line of a BASIC program. If this line number already exists, this line will be overwritten (using just a line number, without any following commands, this line will be deleted).
- BASIC programs can be listed with the BASIC command LIST.
- Line numbers are also used as labels, which marks a jump destination where the execution branches to, i.e. as jump commands like GOTO do.
- The command RUN starts a BASIC program.
- A running BASIC program can be stopped with the key and the computer switches to the direct mode.
- Such a BASIC program is just stored in the memory. Switching off or resetting the computer, or loading another program (with LOAD) into the RAM the current BASIC program is lost or overwritten. To keep a program permanent it might be saved on a data carrier (e.g. disk, datasette) with the BASIC command SAVE.
- The command LOAD can be used to load programs into the RAM of the C64.
Example[edit | edit source]
The animations shows following steps:
- Calculation in direct mode: PRINT
- Loading a program from disk: LOAD
- Running a BASIC program: RUN
- Listing a BASIC program: LIST
- Editing a program (only first line)
- Restarting this program
- Soft reset by using the command SYS
Hints[edit | edit source]
- The input of a BASIC command must be finished by using the key .
- Different commands within a line can be separated with a colon
- Normally a BASIC line can have 80 characters maximum (40 characters over 2 lines) - any further characters are ignored. Excess length lines can be generated by using abbreviations (tokens) of the BASIC-commands or with compilers (e.g.
- Variables can be used in the direct mode, but not all BASIC commands (e.g. INPUT).
- By editing BASIC programs in direct mode, the content of defined variables are lost.
- You should use great steps between the line numbers (e.g. 10, 20, 30, etc.), because easy renumbering (like RENUMBER) of line numbers are only available with extra tools or special coding languages.
- Programs with only one line number followed by a SYS aren't technically BASIC programs. The command SYS is calling an machine code program and this line is only for comfort starting of this machine code program out of BASIC.
- The name of variables must not consist of BASIC keywords (see BASIC keyword table below). Particularly, ST is a reserved variable that returns the status of the last I/O operation.
- Data and characters can only be assigned to variables of matching type.
- A BASIC program may only contain the line numbers from 0 to 63999 inclusive.
Technical Details[edit | edit source]
BASIC and the BASIC interpreter with around 9 KByte in size is located mainly in the BASIC and partially on the KERNAL ROM chip. The first part fills the memory area $A000-$BFFF (40960-49151) with an extension into the KERNAL-ROM from $E000-$E4D2 (57344-58578) (see memory map). The internal structure of the ROM is the BASIC-ROM.
A BASIC line consists of up to 255 (*) bytes and has following structure:
- The start address of the next BASIC line in low and high byte order ($0000 marks the end of a program)
- The line number in low and high byte order
- The tokenized program code (up to 250 bytes)
- A 0 byte is the end of each BASIC line
(*) This is referring to the normal use-case with the BASIC screen editor which has additional limitations (e.g. input buffer size). However, the interpreter is able to process lines which may extent the whole BASIC memory, up to address $9FFF (40959). To the this extreme only if one assume to use neither variables nor allocate strings. Such manipulations might be possible only by special tools.
Bugs[edit | edit source]
- Multiply bug (before BASIC 7.0)
- Expression bug:
""+-1in any context either crashes the system or exits the program unexpectedly. (all versions)
- POS() functions argument bug:
PRINT POS("")POS("")POS("")overflows the string descriptor stack and aborts with error ?FORMULA TOO COMPLEX ERROR. (all versions)
- IF expression bug:
IF A$ THEN PRINT "TRUE"show only "TRUE" if the previous expression evaluates to a non-zero value! The IF statement does not depend on the value A$ has. This changes after a real string expression is used like
IF A$+A$ THEN PRINT "TRUE"which is true if string A$ is not empty. However, this should be more cleanly written as
IF LEN(A$) THEN ...because this bug does not clean up the string descriptor stack. (all versions)
- IF expression bug SDS overflow:
IF A$+A$ THEN PRINT "OK"does not correctly clean up the string descriptor stack after evaluating the string expression. Called 3 times (BASIC 2) or 4 times (BASIC 7.0) the program aborts with ?FORMULA TOO COMPLEX ERROR.
Commodore BASIC Commands[edit | edit source]
Overview of BASIC Version 2.0 (second release) Commands[edit | edit source]
Overview of BASIC Version 3.5 Commands[edit | edit source]
BASIC 3.5 is derived from Commodore BASIC version 2, used on the C16, C116 and the Plus/4 and provides 108 commands:
There is a module extension known as Business Basic for the C64 or the C64 Basic V3.5 implementation published in 64'er Magazin 6/90 to get BASIC 3.5 capabilities on a C64 hardware.
Overview of BASIC Version 3.6 Commands[edit | edit source]
BASIC 3.6 (used in the unreleased prototype Commodore LCD) contains 167 commands:
Overview of BASIC Version 4.0 Commands[edit | edit source]
The cartridge VicTree Programming for a C64 or a VIC adds 42 commands providing a full BASIC 4.0 experience. Some minor differences in the programming syntax, no speedup for the Garbage Collection and the missing machine code entry compatibility prevents the extension to be a perfect BASIC 4.0 substitution on the C64.
Overview of BASIC Version 4+ Commands[edit | edit source]
Overview of BASIC Version 7.0 Commands[edit | edit source]
BASIC 7.0 (used in the C128, C128D, C128DCR) contains 168 commands:
Overview of BASIC Version 10.0 Commands[edit | edit source]
BASIC 10.0 (used in the unreleased prototype C65, and is therefore imperfect) contains 185 commands:
C64 U3 BASIC ROM Failure Symptoms[edit | edit source]
- Blank screen with border.
- Cartridge works.
More advanced programming techniques[edit | edit source]
C64 BASIC is a relatively primitive programming language compared to more modern languages. It is even primitive compared to languages that existed at the same time. There is no provision for creating specialized data types, dynamic allocation of memory or pointers. There isn't even provision for local variables!
You might think that therefore, techniques such as recursion and linked lists can not be done on C64 BASIC. However, this is not true. This section introduces some of the techniques that can be used on the C64 to mimic some of the features of more sophisticated programming languages.
It is assumed that the reader is fully aware how arrays work in C64 BASIC:
Links[edit | edit source]
- Users's manual BASIC 4 (including versions 1 to 3) at commodore.ca
- BASIC 3.5 overview from Janne Peräaho and Anders Persson
- CBM BASIC History
- Create your own Version of Microsoft BASIC for 6502
- Bill Gates’ Personal Easter Eggs in 8 Bit BASIC
- Basics and informations on BASIC V2 at www.homecomputermuseum.de
- CBM8096 LOS-96 Handbuch (Users' Manual BASIC 4.0 Expansion)
- BASIC 7.0 for Plus/4 (hungary)
- BASIC 7.0 for Plus/4 - article and infos