- Graphics BASIC
Graphics BASIC is a third-party extension to the Commodore BASIC V2.0
programming language of theCommodore 64 computer. It was originally written in 1983 byRon Gilbert and Tom McFarlane. The program was licensed toHesware , 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 byEpyx 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 ofPEEK 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
RUN
orSYS
command.Features
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 's orAmigaBASIC '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, andMULTI
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 a technical limitation of the Commodore 64 itself and can not be avoided in software.
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
andBACKGROUND
, followed by either a number from 0 to 15, or a pre-defined symbolic constant such asWHITE
orBLACK
. 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
).prites
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 ofUnix programs than conventional programming languages. In essence, several sprite manipulations can be combined into one command, starting with the wordSPRITE
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 theSPRITE LOAD
andSPRITE SAVE
commands. Programmatically drawing new sprite shapes was not supported.ound
Graphics BASIC also provides various commands to control the Commodore 64's built-in audio synthesizers, 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 as
DIR
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 anON ERROR
command to perform error capturing, aPROCEDURE
command that allowed variables to be passed to subroutines, and addedELSE
to theIF/THEN
command.
Wikimedia Foundation. 2010.