Commodore BASIC
From Free net encyclopedia
Commodore BASIC is the dialect of BASIC used in Commodore International's 8-bit home computer line, stretching from the PET of 1977 to the C128 of 1985. The core part was based on 6502 Microsoft BASIC, licensed from the young, cash-strapped Microsoft on a "pay once, no royalties" basis for $10,000. As such it shares most of the core code with other 6502 BASICs of the time, such as Applesoft BASIC (which, like CBM BASIC, was flat-fee-licenced from Microsoft).
It remains unclear if Microsoft actually believed that Commodore would come back for new BASIC editions for their follow-on computer projects, however they never did. Commodore took the source code of the flat-fee BASIC and developed it further internally for all their home computers.
A very convenient feature of Commodore's ROM-resident BASIC interpreter and KERNAL was the full-screen editor, which allowed users to input, edit, and enter direct commands as well as program lines anywhere on the screen—simply by pressing the RETURN
key whenever the cursor happened to be on a line containing a valid BASIC statement. This marked a significant change in program entry interfaces compared to other common home computer BASICs at the time, which typically used line editors, invoked by a separate EDIT
command or the like.
Contents |
Versions and features
A list of CBM BASIC versions in chronological order, with successively added features:
Released versions
- V1.0: PET 2001 with chiclet keyboard and built-in Datassette (original PET)
- bug: arrays limited to 256 elements
- bug: PEEK command won't work above memory location $C000
- V2.0: PET 2001 with full-travel keyboard & upgrade ROMs; VIC-20; C64
- most 1.0 bugs squashed
- PET Easter egg – enter
WAIT 6502,<x>
and see what happens...
- V4.0: PET/CBM 4000/8000 series (and late version PET 2001s)
- disk operations:
DLOAD,DSAVE,COPY,SCRATCH,
etc (15 in all) - disk error-channel variables:
DS,$DS
- disk operations:
- V4+ : CBM-II series (aka B, P range)
- information to be added
- V3.5: C16/116, Plus/4
- sound and graphics commands
- joystick input:
JOY
- decimal ← → hexadecimal conversion:
DEC(),HEX$()
- flexible
DATA
read:RESTORE [
linenumber]
- string search function:
INSTR
- formatted printing:
PRINT USING,PUDEF
- alternative branching:
ELSE
- structured looping:
DO,LOOP,WHILE,UNTIL,EXIT
- function key assignment:
KEY
(also direct mode) - program entry/editing:
AUTO,DELETE,RENUMBER
- dynamic error handling:
TRAP,RESUME,ERR$()
- debugging (tracing):
TRON,TROFF
- MLM entry command:
MONITOR
- C(1)16, Plus/4 Easter egg – enter
SYS 52650
- V7.0: C128
- more sound and graphics commands, incl sprite handling
- paddle, lightpen input:
POT,PEN
- exclusive or function:
XOR
- get variable address:
POINTER
- text mode windowing:
WINDOW
- controlled time delay:
SLEEP
- memory management:
BANK,SWAP,FETCH,STASH
- more disk operations:
BOOT,BLOAD,BSAVE,DVERIFY,DCLEAR
- CPU speed adjustment:
FAST,SLOW
(2 vs 1 MHz) - undocumented, working:
RREG
(read CPU registers after aSYS
) - unimplemented commands:
OFF,QUIT
- C128 Easter egg – enter
SYS 32800,123,45,6
Unreleased versions
- V10 : Commodore 65 (unreleased prototype)
- graphics/video commands:
PALETTE,GENLOCK
- mouse input:
MOUSE,RMOUSE
- text file (
SEQ
) utility:TYPE
- program editing:
FIND,CHANGE
- memory management:
DMA
,FRE(
<0
>|<1
>|<2
>)
- unimplemented commands:
PAINT,LOCATE,SCALE,WIDTH,SET,VIEWPORT
PASTE,CUT
- graphics/video commands:
Technical details
- Like the original Microsoft BASIC interpreter, which it is based on, Commodore BASIC is known to be woefully slow compared to machine code. Test results have shown that copying 16 kilobytes of memory from ROM to RAM takes less than a second in machine code, but over 10 minutes in BASIC. To try to make up for the slowness of the interpreter, programmers started using various tricks to speed up execution. One idea was to store often-used integer values into variables rather than using them as literal values, as interpreting a variable name was faster than interpreting a literal number. Programmers also often wrote speed-critical sections of a program in 6510 assembly language and executed them from BASIC using the SYS keyword.
- The order of execution of Commodore BASIC lines did not follow the line numbering; instead, it followed the order in which the lines were stored in memory. When entering code with the on-screen editor, the lines were automatically reordered to follow the line numbers. However, by manually altering the line numbers via POKE commands, the line numbering could be altered to achieve out-of-order execution or even give each line the same line number.
- Commodore BASIC tokens could be shortened by entering only the first letter, followed by a shifted version of the second letter (the shifted version appeared as a graphics symbol). The shortened token was equivalent to the full token and appeared as the full token when
LIST
-ing the program. - The native number format of Commodore BASIC, like that of its parent MS BASIC, was floating point. (All arithmetic was done using these floating point numbers; integer calculations were performed via conversion to and from floating point.) Most of the contemporary BASIC implementations used one byte for the characteristic (exponent) and three bytes for the mantissa. This led to problems in business applications since the accuracy of a floating point number using a three-byte mantissa is only about 6.5 decimal digits, and round-off error is common. Commodore, however, used MS BASIC's four-byte mantissa, which made their BASIC much more adapted for business than most other BASICs of the era.
- Many BASIC extensions were released for the Commodore 64, due to the relatively limited capabilities of its native BASIC 2.0. One of the most popular extensions was the DOS Wedge, due to its inclusion on the Commodore 1541 Test/Demo Disk. This 1 KB extension to BASIC added a number of disk-related commands, including the ability to read a disk directory without destroying the program in memory. Its features were subsequently incorporated in various third-party extensions, such as the popular Epyx FastLoad cartridge. Other BASIC extensions added additional keywords to make it easier to code sprites, sound, and high-resolution graphics.
Notable extension packages
- Super Expander (VIC-20; delivered on cartridge) (CBM in-house)
- Super Expander 64 (C64; cartridge) (in-house)
- Simons' BASIC (C64; cartridge) (in-house)
- Graphics BASIC (C64; floppy disk) (Hesware)
- BASIC 8 (C128; floppy disk and optional internal ROM chip) (Walrusoft)
References
BASIC 2.0:
- Angerhausen et.al. (1983). The Anatomy of the Commodore 64 (for the full reference, see the C64 article).
BASIC 7.0:
- Jarvis, Dennis; Springer, Jim D. (1987). BASIC 7.0 Internals. Grand Rapids, Michigan: Abacus Software, Inc. ISBN 0-916439-71-2.de:Commodore BASIC