Graphics BASIC
Encyclopedia
Graphics BASIC is a third-party extension
to the Commodore BASIC V2.0
programming language
of the Commodore 64
computer. It was originally written in 1983 by Ron Gilbert
and Tom McFarlane. The program was licensed to Hesware
, who briefly sold the program in 1984 as part of their product line before going out of business. The program was later repackaged and sold in 1985 by Epyx
under the title Programmers BASIC Toolkit.
Graphics BASIC adds over 100 new commands to the BASIC language, providing an easy-to-use API to the relatively advanced (at the time) graphics and sound hardware capabilities of the Commodore 64. The only access to these features with Commodore BASIC alone is through the cumbersome use of PEEK and POKE
commands. Graphics BASIC was delivered on a single 5.25" floppy disk
, containing the language itself and numerous, very simple demo programs showing off the new features of the language. Graphics BASIC is installed simply by issuing the well-known command:
LOAD "*",8,1
After loading, the language starts automatically, without the need for a separate
DOT 160,100
LINE 80,50 TO 240,150
BOX 10,10 TO 20,20
As can be seen from the above, the syntax is somewhat similar to that of GW-BASIC
's or AmigaBASIC
's graphics commands, but different enough to prevent source-code compatibility.
The Commodore 64 has separate video modes for text and graphics. Switching between these is extremely easy in Graphics BASIC.
Using all 16 colours is possible in both HiRes and Multi modes, but if two incompatible colours are drawn onto the same 8*8 pixel block, the entire block fills with the colour drawn later. This is due to a technical limitation of the Commodore 64's VIC-II display chip.
One of the more unusual choices of syntax in Graphics BASIC was the setting of graphics colours. To set the foreground and background colours of the text mode, you use the commands
COLOUR HIRES x ON y
where x is the foreground colour and y is the background colour. (For example,
The compact syntax of the sprite commands has more in common with the command-line options of Unix
programs than conventional programming languages. In essence, several sprite manipulations can be combined into one command, starting with the word
SPRITE 1 ON AT 160,100 COLOUR BLUE XYSIZE 2,2
does a total of four things: set sprite 1 as visible, move it into the location (160, 100) on the screen, set its individual colour to blue, and double its physical size both horizontally and vertically.
Graphics BASIC also supports automatic sprite movement (change in place), animation (change in shape), and collision detection. This is implemented in the language core itself by adding hooks into the Commodore 64's software interrupt routines. (The language does not support adding your own interrupt hooks.)
Sprite shapes can be drawn by hand with a built-in sprite editor, accessed with the command
, allowing the selection of waveform type, tone (frequency), and amplitude envelopes. In addition, sequences of tones can be specified and played automatically in the background.
BASIC extension
BASIC toolkits —not to be confused with widget toolkits—were a common type of program for 1980s 8-bit home computers...
to the Commodore BASIC V2.0
Commodore BASIC
Commodore BASIC, also known as PET BASIC, is the dialect of the BASIC programming language used in Commodore International's 8-bit home computer line, stretching from the PET of 1977 to the C128 of 1985...
programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
of the Commodore 64
Commodore 64
The Commodore 64 is an 8-bit home computer introduced by Commodore International in January 1982.Volume production started in the spring of 1982, with machines being released on to the market in August at a price of US$595...
computer. It was originally written in 1983 by Ron Gilbert
Ron Gilbert
Ron Gilbert is an American computer game designer, programmer, and producer, best known for his work on several classic LucasArts adventure games, including Maniac Mansion and the first two Monkey Island games. Gilbert was also co-founder of Humongous Entertainment and its sister company Cavedog...
and Tom McFarlane. The program was licensed to Hesware
HESware
HESware was an American home computer software and hardware developer/publisher during the 1980s, who concentrated on the Commodore 64 and the Atari 8-bit.-History:...
, who briefly sold the program in 1984 as part of their product line before going out of business. The program was later repackaged and sold in 1985 by Epyx
Epyx
Epyx, Inc. was a video game developer and publisher in the late 1970s and throughout the 1980s. The company was founded as Automated Simulations by Jim Connelley and Jon Freeman, originally using Epyx as a brand name for action-oriented games before renaming the company to match in 1983...
under the title Programmers BASIC Toolkit.
Graphics BASIC adds over 100 new commands to the BASIC language, providing an easy-to-use API to the relatively advanced (at the time) graphics and sound hardware capabilities of the Commodore 64. The only access to these features with Commodore BASIC alone is through the cumbersome use of PEEK and POKE
PEEK and POKE
In computing, PEEK is a BASIC programming language extension used for reading the contents of a memory cell at a specified address. The corresponding command to set the contents of a memory cell is POKE.-Statement syntax:...
commands. Graphics BASIC was delivered on a single 5.25" floppy disk
Floppy disk
A floppy disk is a disk storage medium composed of a disk of thin and flexible magnetic storage medium, sealed in a rectangular plastic carrier lined with fabric that removes dust particles...
, containing the language itself and numerous, very simple demo programs showing off the new features of the language. Graphics BASIC is installed simply by issuing the well-known command:
LOAD "*",8,1
After loading, the language starts automatically, without the need for a separate
RUN
or SYS
command.Graphics
Graphics BASIC's main feature is its easy-to-use graphics commands, including commands to draw dots, lines, circles, ellipses, rectangles, and polygons. The following gives an example of how the commands were used:DOT 160,100
LINE 80,50 TO 240,150
BOX 10,10 TO 20,20
As can be seen from the above, the syntax is somewhat similar to that of GW-BASIC
GW-BASIC
GW-BASIC was a dialect of the programming language BASIC developed by Microsoft from BASICA, originally for Compaq. It is compatible with Microsoft/IBM BASICA, but was disk based and did not need the ROM BASIC. It was bundled with MS-DOS operating systems on IBM PC compatibles by Microsoft...
's or AmigaBASIC
AmigaBASIC
AmigaBASIC was an interpreted BASIC programming language implementation for the Amiga, designed and written by Microsoft. AmigaBASIC shipped with AmigaOS versions 1.1 to 1.3...
's graphics commands, but different enough to prevent source-code compatibility.
The Commodore 64 has separate video modes for text and graphics. Switching between these is extremely easy in Graphics BASIC.
TEXT
switches to text mode, HIRES
switches to 320x200 two-colour graphics, and MULTI
switches to 160x200 four-colour graphics. Graphics BASIC also allows the screen to be horizontally split between multiple modes.Using all 16 colours is possible in both HiRes and Multi modes, but if two incompatible colours are drawn onto the same 8*8 pixel block, the entire block fills with the colour drawn later. This is due to a technical limitation of the Commodore 64's VIC-II display chip.
One of the more unusual choices of syntax in Graphics BASIC was the setting of graphics colours. To set the foreground and background colours of the text mode, you use the commands
COLOUR
and BACKGROUND
, followed by either a number from 0 to 15, or a pre-defined symbolic constant such as WHITE
or BLACK
. To set the colours of the graphics mode, the command syntax is of the form:COLOUR HIRES x ON y
where x is the foreground colour and y is the background colour. (For example,
COLOUR HIRES BLACK ON WHITE
).Sprites
Graphics BASIC also provides commands to manipulate the Commodore 64's eight sprites. These sprites are 24x21 pixels in size, drawn in either 2 colours (1 colour + background) or 4 colours (3 colours + background). Each sprite has one individual colour to its own. In 3-colour mode, the horizontal resolution is halved, and all 3-colour sprites share the same 2 extra colours.The compact syntax of the sprite commands has more in common with the command-line options of Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
programs than conventional programming languages. In essence, several sprite manipulations can be combined into one command, starting with the word
SPRITE
and the sprite's number, from 1 to 8. This is then followed by any number of keywords, and the parameters they need. As an example,SPRITE 1 ON AT 160,100 COLOUR BLUE XYSIZE 2,2
does a total of four things: set sprite 1 as visible, move it into the location (160, 100) on the screen, set its individual colour to blue, and double its physical size both horizontally and vertically.
Graphics BASIC also supports automatic sprite movement (change in place), animation (change in shape), and collision detection. This is implemented in the language core itself by adding hooks into the Commodore 64's software interrupt routines. (The language does not support adding your own interrupt hooks.)
Sprite shapes can be drawn by hand with a built-in sprite editor, accessed with the command
EDIT
. The editor, while simple to use, was somewhat rudimentary. Sprite shapes can be loaded or saved to disk with the SPRITE LOAD
and SPRITE SAVE
commands. Programmatically drawing new sprite shapes was not supported.Sound
Graphics BASIC also provides various commands to control the Commodore 64's built-in audio synthesizerMOS Technology SID
The MOS Technology 6581/8580 SID is the built-in Programmable Sound Generator chip of Commodore's CBM-II, Commodore 64, Commodore 128 and Commodore MAX Machine home computers...
, allowing the selection of waveform type, tone (frequency), and amplitude envelopes. In addition, sequences of tones can be specified and played automatically in the background.
Other Commands
In addition to graphics and sound commands, Graphics BASIC also provides various other useful commands such asDIR
to list the file directory of a device, JOY
to return the position of a joystick, KEY
to program function keys, REN
to renumber the current program line numbers. Graphics BASIC also added an ON ERROR
command to perform error capturing, a PROCEDURE
command that allowed variables to be passed to subroutines, and added ELSE
to the IF/THEN
command.