Supriya Ghosh (Editor)

Graphics BASIC

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

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 extended by Ken Rose and Jack Thornton, and repackaged and sold in 1985 by Epyx under the title Programmers BASIC Toolkit.

Contents

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. A cartridge version was also available. Graphics BASIC is installed simply by issuing the well-known command:

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:

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. TEXT switches to text mode, HIRES switches to 320×200 two-colour graphics, and MULTI switches to 160×200 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:

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 24×21 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 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,

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 can be done by drawing the shapes on the normal hires or multicolor screen, then copying the shapes with the COPY HIRES TO SPRITE or COPY MULTI TO SPRITE command.

Sound

Graphics BASIC also provides various commands to control the Commodore 64's built-in audio synthesizer, 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 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.

References

Graphics BASIC Wikipedia