Classic Computer Magazine Archive ANTIC VOL. 4, NO. 2 / JUNE 1985

G.U.P the GREAT

Fast graphics power from BASIC

by DAREK MIHOCKA

Speed up your BASIC graphics commands and add powerful new ones-including circles, squares and pattern fills. Atari 400/800 owners can now access graphics commands available only on the XLs. Requires a disk drive and will run on all Atari computers with 48K memory.

Graphics Utility Package (G.U.P.) is a BASIC program that creates a boot file. When this file is installed in your Atari's memory several new and powerful graphics commands are available to you in the form of USR calls.
G.U. P. features include:

  • PLOT and DRAWTO about 3-5 times faster than normal.
  • Circles and boxes drawn at high speed.
  • Several lines drawn at once for high speed.
  • Access by a 400 or 800 to the 4 new XL graphics modes.
  • Choose solid or multicolor patterns.
  • Mix text with graphics.
  • A simple 128 color rainbow command.
  • Direct commands in GTIA modes.
TYPING G.U.P.
Type in Listings 1 and 2. Check them carefully with TYPO II and make sure no lines have been missed. These programs use machine language routines which could lock up your computer if mistyped, so be sure to SAVE backup copies before RUNning them.
   Listing 1 will create an AUTORUN.SYS file on disk. RUN the program and at the prompt insert a formatted disk with DOS 2.OS, press START and G.U.P. will be written to disk. (Note: because of the G.U.P. file structure, do NOT use DOS 3.). Now, boot the disk, the screen will change color and G.U.P. will be in memory.

DEMONSTRATION
To test G.U.P., LOAD Listing 2 into memory and RUN it. Listing 2 is a demonstration program that will take G.U.P. through its amazing paces and provide examples of how to use G.U.P in your own BASIC programs.
   Lines 40-180 of Listing 2 are essential to any BASIC program using the G.U.P. commands. These lines determine the starting locations of the different routines and store them in command variables. You can renumber them for your convenience, but they must be executed before any G.U.P. commands are given.

LOCK-UP
G.U.P. is really a series of USR calls, which are assembly language routines that are accessed from BASIC. Computer newcomers, who may be a little wary of USR routines should read last month's "USR Routines" by Ernie Negus.
   When using assembly language routines, there is always a good possibility of computer lock-up-your keyboard no longer responds and there's nothing to do but turn off your computer and start all over again. Lock-ups can occur with just one mistyped character. They're time-consuming and annoying and you may lose unsaved data. But they won't harm your machine, so don't be afraid to experiment.

G.U.P COMMANDS
GUP. has 10 separate commands:
GRAPHICS, SET, PLOT, DRAWTO, LINE, BOX, CIRCLE, TEXT, RANDOM, and C128. Here is a description of each:

GRAPHICS x-Establish graphics mode. Any one of the 16 graphics modes can be selected. This allows a ROM B Atari to access the 4 new ROM C graphics modes with one command. To access the 160X192 4 color mode (GR.l5 on XL computers), use the command:
   A = USR(GRAPHICS,15)

SET a,b,c,d-Choose patterns. Each parameter contains color data for 4 pixels necessary for the pattern of colors. (See the explanation later on.) To set the colors to simulate the BASIC command COLOR 1, use:

   A = USR(SET,85,85,85,85)

PLOT x,y-Same as BASIC's PLOT. Use:

   A = USR(PLOT,XY)

DRAWTO x,y-Again, the same as BASIC's DRAWTO. Use:

   A = USR(DRAWTO,X,Y)

LINE xl,yl,x2,y2-Similar to DRAWTO, except that the first parameter is the starting pixel. For example, to draw lines from pixel 0,0 to 10,5 to 20,3 use:

   A= USR(LINE,0,0,l0,5,20,3)

The DRAWTO and LINE commands can have more than one parameter. That is, if 5 pairs of coordinates are given, then a line will be drawn from the first to the second, then the second to third, and so on. This saves time and memory.

BOX xl,yl,x2,y2-This will draw a filled-in box whose opposite corner coordinates are (xl,yl) and (x2,y2). A 10 pixel square box is draw with:

   A= USR(BOX,0,0,10, 10)

CIRCLE x,y,r-this draws a circle of radius r pixels at location xl, yl. This command works about 30 times faster than any BASIC algorithm I've tried. A large circle in GR.l5 is drawn by:

   A = USR(CIRCLE,79,79,75)

TEXT x,y,"abcd..",1-this will print out the given string of length 1 in graphics modes 4,6 or 8 at coordinates x,y This allows easy mixing of text and graphics. It should be used in a 2 color mode to make the letters readable. To put the word ANTIC in the upper left corner of the screen use:

   A = USR(TEXT,0,0,ADR("ANTIC"),5)

Repeating the command will erase the word and restore any graphics that were underneath.

RANDOM-This command simply puts random colors in the color pattern. The command is:

   A = USR(RANDOM)

C128 d,r-This produces a 128 color rainbow display for the given duration (d in l/60ths of a second) in the given color register (r). R is determined by subtracting 704 from the location of the color register For example, to make a rainbow of the background (location 710) for 10 seconds use:

   A = USR(C128,600,6)

VARIABLE REGISTERS
Four variables are established as registers in G.U.P.
   CIRF is a variable used to switch between empty-circle drawing and filled circles. POKE CIRF,0 for empty circles or POKE CIRF,l for filled ones.
   Memory location 208 is used with the command GRAPHICS. Since G.U.P. can only plot up to a coordinate of 255,191, the co-ordinates from 256,191 to 319,191 in graphics mode 8 cannot normally be accessed. By poking an 8 into 208, the coordinate plane is shifted over 64 pixels and A = USR(PLOT,0,0) would actually plot at 64,0.
   The memory locations SETCOLOR to SETCOLOR + 8 are values that are copied into memory locations 704 to 712 when a GRAPHICS command is executed. By poking into these locations, the default colors of the screen can be changed, as they already are in G.U.P. For example, in graphics mode 0, to change the screen color to black, a POKE 710,0 is run. To set G.U. P. to make the screen black every time a GRAPHICS command is given, do a POKE SETCOLOR+6,0 since 710=704+6.

SET COMMAND
One of the best things about G.U.P. is that it doesn't just draw in solid colors. A 1x4, 2x4, 4x4 or 8x4 color pattern is stored at memory locations COLOR to COLOR+ 3. The size of the pattern is determined by the graphics mode. This is because text modes use one byte per character, GTIA modes use one byte to display 2 pixels, 4-color modes use one byte for 4 pixels, and the 2-color modes can store 8 pixels in a byte.
   The pattern can either be POKEd in, or put in with the SET command. This way circles can be drawn in a checkerboard pattern, lines can be dotted, and more.
   The formula for determining the parameters to use in the SET command is quite simple. Just like BASIC's COLOR command which selects one of the 4 color registers for plotting, each one of the 4 parameters passed in the SET command determines the color registers for a 4 x 1 array of pixels in a 4-color mode, 8 x 1 in a 2 color mode, 2 x 1 in a GTIA mode.
   Using 2-color modes 4, 6 and 8, an 8x4 pattern can be set up. This means that during PLOT, DRAWTO, LINE, BOX, or CIRCLE, the pixels will be plotted so that if the whole screen is filled up it will be made up of little 8x4 boxes of the same pattern. By making the pixels alternate from black to white, a very fine checkerboard pattern is made as follows: Let 0 represent a pixel in color 0 and a 1 represent a pixel in color 1. The pattern is therefore

        01010101
     10101010
     01010101
     10101010

   This pattern represents 4 binary numbers. In decimal they are 85, 170, 85 and 170. Therefore the command to give is:

   A= USR(SET,85,170,85,170)

   If you just want to plot with color 1, the whole pattern would be l's and the four numbers would each be 255 (11111111 in binary). Similarly, if you want to plot with color 0, use the number 0 four times.
   In a 4-color mode, 4 colors can be used so each pixel must be represented by two bits: 00, 01, 10 or 11. This is why only 4 can be used in one byte. Similarly, in a GTIA mode, 16 colors are possible, therefore 4 bits are required per pixel and only 2 pixels fit in one byte.
   In a text mode, 0, 1, 2, 12 or 13, the four numbers represent a block of 1 x 4 characters. Each number is the ATASCII code of the character.
   If you wish to POKE these values instead of using the SET command, locations COLOR to COLOR +3 are where the four parameters of the SET command go and can be POKEed directly.

FEEL FREE
Luckily, you don't really need to understand any of this. Simply try out different numbers in the SET parameters until you see what you like. This holds true of all of G.U.P. Many of these routines may be placed in strings for those more advanced programmers. Feel free to experiment.

Darek Mihocka placed in the top 10 in three nationwide Canadian university math and physics contests. He's a member of the Toronto Atari Federation and a licensed glider pilot.

Listing 1   GUP.BAS Download

Listing 2   GUP.DMO Download

GUP.ASM Download / View

GUP.ASM Download / View
another version of GUP.ASM that was included on the October 1985 disk.
GUP.EXE Download