BASIC

From C64-Wiki
(Redirected from BASIC 3.5)
Jump to: navigation, search

This article is about the programming language BASIC in connection to Commodore computer systems.

Start screen of a Commodore 64

The acronym BASIC stands for "Beginner’s All-purpose Symbolic Instruction Code", which used to be a very famous programming language from the 70s to the 90s. It was invented in 1964 by John George Kemeny and Thomas Eugene Kurtz. During the last decades, various BASIC-dialects have emerged. This article informs you about BASIC for Commodore computers.

CBM BASIC[edit]

From the series of PET/CBM 2001 to the home computers C64/C128/C128DCR20, C16/C116, Plus/4, Ultimax, C65 Commodore used an individually developed BASIC-version termed CBM-BASIC. There are several sub-dialects of which BASIC Version 2.0 is the most popular.

Commodore developed their BASIC under license from Microsoft in 1977 for their systems. On Commodore systems BASIC is not only used as programming language, but also as operating system. BASIC is configured on a ROM chip.

BASIC V2.0 of C64[edit]

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]

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 listening 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 RUN/STOP  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]

Editing a BASIC program

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

This BASIC program increases a float variable from 1 until 10 and prints the text "TEST NR." followed by the actual variable content.

10 I = 1
20 PRINT "TEST NR.";I
30 I = I + 1
40 IF I<=10 GOTO 20

Hints[edit]

  • The input of a BASIC command must be finished by using the key RETURN .
  • 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. ? is PRINT). The editing of excess length lines is a problem.
  • 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]

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:

  1. The start address of the next BASIC line in low and high byte order ($0000 marks the end of a program)
  2. The line number in low and high byte order
  3. The tokenized program code (up to 250 bytes)
  4. 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.

Commodore BASIC Commands[edit]

Overview of BASIC Version 2.0 (second release) Commands[edit]

BASIC 2.0 (second release, as used in the C64, VIC 20, C128, C128D, C128DCR) contains 71 commands:

BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT

 


Overview of BASIC Version 3.5 Commands[edit]

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.

BASIC V3.5 Commands

ABS | ASC | ATN | AUTO | BACKUP | BOX | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLOR | CONT | COPY | COS | DATA | DEC | DEF | DELETE | DIM | DIRECTORY | DLOAD | DO | DRAW | DSAVE | END | ERR$ | EXP | FN | FOR | FRE | GET | GET# | GETKEY | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | MID$ | MONITOR | NEW | NEXT | ON | OPEN | PAINT | PEEK | POKE | POS | PRINT | PRINT USING | PRINT# | PUDEF | RCLR | RDOT | READ | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RLUM | RND | RUN | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SOUND | SPC | SQR | SSHAPE | STOP | STR$ | SYS | TAB | TAN | TRAP | TROFF | TRON | USR | VAL | VERIFY | VOL | WAIT

 


Overview of BASIC Version 3.6 Commands[edit]

BASIC 3.6 (used in the unreleased prototype Commodore LCD) contains 167 commands:

BASIC V3.6 Commands

ABS | AND | APPEND | ASC | ATN | AUTO | BACKUP | BANK | BEGIN | BEND | BLOAD | BOOT | BOX | BSAVE | BUMP | CATALOG | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLINT | COLLECT | COLLISION | COLOR | CONCAT | CONT | COPY | COS | DATA | DCLEAR | DCLOSE | DEC | DEF FN | DELETE | DIM | DIRECTORY | DLOAD | DO | DOPEN | DRAW | DS | DS$ | DSAVE | DVERIFY | EL | ELSE | END | ENVELOPE | ER | ERR$ | EXIT | EXP | FETCH | FILTER | FN | FOR | FRE | GET | GET# | GETKEY | GO64 | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | LOOP | MID$ | MONITOR | MOVSPR | NEW | NEXT | NOT | ON | OPEN | OR | PAINT | PEEK | PEN | PI | PLAY | POINTER | POKE | POPUPS | POS | POT | PRINT | PRINT USING | PRINT# | PUDEF | RCLR | RDOT | READ | RECORD | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RND | RREG | RSPCOLOR | RSPPOS | RSPRITE | RUN | RWINDOW | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SLEEP | SOUND | SPC( | SPRCOLOR | SPRDEF | SPRITE | SPRSAV | SQR | SSHAPE | ST | STASH | STEP | STOP | STR$ | SWAP | SYS | TAB( | TAN | TEMPO | THEN | TI | TI$ | TO | TRAP | TROFF | TRON | USR | VAL | VERIFY | VOLUME | WAIT | WHILE | WIDTH | XOR

 

Overview of BASIC Version 4.0 Commands[edit]

BASIC 4.0 (used in the PET and CBM computers of the CBM 4000/8000 series) contains 89 commands:

BASIC V4.0 Commands

ABS | AND | APPEND | ASC | ATN | BACKUP | CATALOG | CHR$ | CLOSE | CLR | CMD | COLLECT | CONCAT | CONT | COPY | COS | DATA | DCLOSE | DEF | DIM | DIRECTORY | DLOAD | DOPEN | DS | DS$ | DSAVE | END | EXP | FN | FOR | FRE | GET | GET# | GO | GOSUB | GOTO | HEADER | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | POKE | POS | PRINT | PRINT# | READ | READ# | RECORD | REM | RENAME | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SCRATCH | SGN | SIN | SPC | SQR | ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TI | TI$ | TO | USER | VAL | VERIFY | WAIT

 

The cartridge VicTree Programming for a C64 or a VIC adds 42 commands providing a full BASIC 4.0 experience.[1] 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]

BASIC 4+ (used in the CBM-II computer series CBM 500/CBM 600/CBM 700 also known as B-series) contains 105 commands:

BASIC V4+ Commands

ABS | AND | APPEND | ASC | ATN | BACKUP | BANK | BLOAD | BSAVE | CATALOG | CHR$ | CLOSE | CLR | CMD | COLLECT | CONCAT | CONT | COPY | COS | DATA | DCLEAR | DCLOSE | DEF | DELETE | DIM | DIRECTORY | DISPOSE | DLOAD | DOPEN | DS | DS$ | DSAVE | EL | ELSE | END | ERR$ | ESC | EXP | FN | FOR | FRE | GET | GET# | GO | GOSUB | GOTO | HEADER | IF | INPUT | INPUT# | INSTR | INT | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | POKE | POS | PRINT | PRINT USING | PRINT# | PUDEF | READ | READ# | RECORD | REM | RENAME | RESTORE | RESUME | RETURN | RIGHT$ | RND | RUN | SAVE | SCRATCH | SGN | SIN | SPC | SQR | ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TI | TI$ | TO | TRAP | USING | USER | VAL | VERIFY | WAIT

 


Overview of BASIC Version 7.0 Commands[edit]

BASIC 7.0 (used in the C128, C128D, C128DCR) contains 168 commands:

BASIC V7.0 Commands

ABS | AND | APPEND | ASC | ATN | AUTO | BACKUP | BANK | BEGIN | BEND | BLOAD | BOOT | BOX | BSAVE | BUMP | CATALOG | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLINT | COLLISION | COLOR | CONCAT | CONT | COPY | COS | DATA | DCLEAR | DCLOSE | DEC | DEF FN | DELETE | DIM | DIRECTORY | DLOAD | DO | DOPEN | DRAW | DS | DS$ | DSAVE | DVERIFY | EL | ELSE | END | ENVELOPE | ER | ERR$ | EXIT | EXP | FAST | FETCH | FILTER | FN | FOR | FRE | GET | GET# | GETKEY | GO64 | GOSUB | GOTO | GRAPHIC | GSHAPE | HEADER | HELP | HEX$ | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LIST | LOAD | LOCATE | LOG | LOOP | MID$ | MONITOR | MOVSPR | NEW | NEXT | NOT | ON | OPEN | OR | PAINT | PEEK | PEN | (PI) | PLAY | POINTER | POKE | POS | POT | PRINT | PRINT USING | PRINT# | PUDEF | RCLR | RDOT | READ | RECORD | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RND | RREG | RSPCOLOR | RSPPOS | RSPRITE | RUN | RWINDOW | SAVE | SCALE | SCNCLR | SCRATCH | SGN | SIN | SLEEP | SLOW | SOUND | SPC( | SPRCOLOR | SPRDEF | SPRITE | SPRSAV | SQR | SSHAPE | ST | STASH | STEP | STOP | STR$ | SWAP | SYS | TAB( | TAN | TEMPO | THEN | TI | TI$ | TO | TRAP | TROFF | TRON | USR | VAL | VERIFY | VOL | WAIT | WHILE | WIDTH | XOR

 


Overview of BASIC Version 10.0 Commands[edit]

BASIC 10.0 (used in the unreleased prototype C65, and is therefore imperfect) contains 185 commands:

BASIC V10.0 Commands

ABS | AND | APPEND | ASC | ATN | AUTO | BACKGROUND | BACKUP | BANK | BEGIN | BEND | BLOAD | BOOT | BORDER | BOX | BSAVE | BUMP | BVERIFY | CATALOG | CHANGE | CHAR | CHR$ | CIRCLE | CLOSE | CLR | CMD | COLLECT | COLLISION | COLOR | CONCAT | CONT | COPY | COS | CUT | DATA | DCLEAR | DCLOSE | DEC | DEF | DELETE | DIM | DIR | DISK | DLOAD | DMA | DMA | DMA | DMODE | DO | DOPEN | DPAT | DSAVE | DVERIFY | ELLIPSE | ELSE | END | ENVELOPE | ERASE | ERR$ | EXIT | EXP | FAST | FILTER | FIND | FN | FOR | FOREGROUND | FRE | GCOPY | GENLOCK | GET | GET# | GO | GOSUB | GOTO | GRAPHIC | HEADER | HELP | HEX$ | HIGHLIGHT | IF | INPUT | INPUT# | INSTR | INT | JOY | KEY | LEFT$ | LEN | LET | LINE | LIST | LOAD | LOCATE | LOG | LOOP | LPEN | MID$ | MONITOR | MOUSE | MOVSPR | NEW | NEXT | NOT | OFF | ON | OPEN | OR | PAINT | PALETTE | PASTE | PEEK | PEN | PIC | PLAY | POINTER | POKE | POLYGON | POS | POT | PRINT | PRINT# | PUDEF | QUIT | RCLR | RDOT | READ | RECORD | REM | RENAME | RENUMBER | RESTORE | RESUME | RETURN | RGR | RIGHT$ | RMOUSE | RND | RREG | RSPCOLOR | RSPPOS | RSPRITE | RUN | RWINDOW | SAVE | SCALE | SCNCLR | SCRATCH | SCREEN | SET | SGN | SIN | SLEEP | SLOW | SOUND | SPC | SPRCOLOR | SPRDEF | SPRITE | SPRSAV | SQR | STEP | STOP | STRS | SYS | TAB | TAN | TEMPO | THEN | TO | TRAP | TROFF | TRON | TYPE | UNTIL | USING | USR | VAL | VERIFY | VIEWPORT | VOL | WAIT | WHILE | WIDTH | WINDOW | XOR

 


C64 U3 BASIC ROM Failure Symptoms[edit]

  • Blank screen with border.
  • Cartridge works.

More advanced programming techniques[edit]

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]

WP-W11.png Wikipedia: BASIC

commodore.ca]


References

  1. Compute! Magazine Issue 40/Sep. 1983/p. 183: The VicTree Programming - Module For VIC And 64 from Skyles Electric Works (the originators of the PET "Toolkit")