Classic Computer Magazine Archive COMPUTE! ISSUE 89 / OCTOBER 1987 / PAGE 66


Double Hi-Res Graphics

Commands For Applesoft

Zachary T. Smith

If you are frustrated by the lack of firmware support for the latest Apple graphics modes, you'll be more than pleased with this Applesoft BASIC extension that gives you six new; graphics commands for the double hires mode on the Apple IIe (Revision B), IIc, and IIGS computers. DOS 3.3 is required.

Here's a utility that extends Applesoft with six new commands and a revised HPLOT to provide full control over the double hi-res graphics mode. It supports both monochrome and 16-color plotting and leaves 21.5K of RAM for the Applesoft programmer.

The whole idea of double high-resolution video (including 80-column text) on the Apple seems to be more of an afterthought than an innovation. For example, the original ROM routine for scrolling the 80-column screen behaved more like two successive 40-column scrolls on the same area of RAM (with first the main RAM and then the auxiliary RAM switched in). While some ROM routines have been revised to improve support for double high-resolution graphics, Applesoft BASIC has not been upgraded. As a result, there is no easy way for BASIC programmers to take advantage of the double hi-res mode. "Chrome" changes all that.

Chrome is a utility which extends Applesoft. It adds several new commands and revises some old ones to allow full exploitation of the double hi-res graphics mode of the 128K IIe, IIc, and IIGS. It can be used with either color or monochrome monitors to support screen displays of 140×192 pixels in 16 colors or 560×192 pixels in monochrome.

Chrome does not support the new medium-resolution graphics mode (80×48 pixels in 16 colors). However, that mode can be emulated in double hi-res.

Creating The Startup Disk

The simplest way to use Chrome is to dedicate a disk to it. Format a fresh disk under DOS 3.3. Next, type in the following short program:

10 PRINT CHR* (4)"PR#3"
30 NEW

To have this setup program run automatically when the disk is booted, save the program to the disk with the name HELLO.

Since Chrome is written entirely in machine language, it should be entered with the Apple version of the "MLX" machine language entry program, found elsewhere in this issue. Be sure you read and understand the instructions for using MLX before you begin entering data. When you run MLX, you'll be asked for a starting address and an ending address. For Chrome (Program 1), give the following values:


When you finish typing in all the data from Program 1, be sure to save a copy before leaving MLX. When saving, use the filename CHROME, since that is the name the setup program above looks for. Be sure to save the final copy of the program on the same disk as the setup program.

To use Chrome, turn off your computer, place in the drive the disk containing the setup HELLO program and the CHROME file, and turn on the system. With this disk booted, you'll be provided with a new version of Applesoft with three distinguishing characteristics: First, only 21.5K of RAM is available for your programs. Second, the 80-column text screen is now the default display. And third, several new commands and enhancements are available. Only a Control-Reset will disengage the new BASIC and return you to standard Applesoft.

If at any time something goes wrong with BASIC, the recover procedure is to press Control-Reset as usual, followed by CALL 6144 to reinitialize Chrome's BASIC extension and its new tokens. Neither the reset nor the call performs a NEW, so the residing BASIC program is still there afterwards.

If you feel adventuresome, skip ahead to the description of the commands and start trying some of them. If you would rather start with a demo program, type in, save, and run Program 2. If you have a color monitor, switch it to monochrome if such a switch is available. The first part of the demo uses monochrome graphics. It draws ten circles, a line, and a string of box-shaped characters. Switch your monitor back to color and press Return. You'll see a demonstration of the color mode. It draws 16 lines in different colors and then a blue oval. Press Return again to exit the demo.

Using the New Commands

If you've examined Program 2, you have already seen some of the new commands. Let's take a close look at each of them.

HGR 3 sets up a double hi-res screen just as HGR sets up normal hi-res, including the four-line text window at the bottom of the screen. To switch back to 40 columns from within a running program you must give DOS a PR#0 command, such as:

PRINT CHR$(4) "PR#0" : HOME : HGR2

If DOS is not informed of the change, the system will do strange things. Actually, this makes perfect sense—when you type PR# from the direct mode, it is not only executed as an Applesoft command but also as a DOS 3.3 command.

HGR 4 is the same as HGR3, except that it sets up a full graphics screen with no text window at the bottom. Unlike HGR2 (its normal hi-res equivalent), HGR 4 uses memory from hi-res page 1.

DOUBLE puts the HPLOT command in 560-point monochrome mode. In this mode, each plot affects only one bit of screen memory. The particular effect of each plot is determined by the most recent HCOLOR = statement (see the discussion below of HCOLOR=). This mode is most useful in conjunction with a monochrome monitor, where each bit of screen memory corresponds to one screen pixel. On a color monitor, four bits are required to show one colored dot. In DOUBLE mode with a color monitor, changing one bit changes a screen dot's color.

COLOR puts the HPLOT command in 140-point color mode. In this mode, each plot affects four bits of screen memory. The value specified in the most recent COLOR = statement (see below) will be stored in the four bits of screen memory at the position specified by the HPLOT command. This mode is most useful in conjunction with a color monitor, where each four-bit group in screen memory specifies the color of one screen pixel. (Since 16 different colors can be displayed, four bits are required to select the color. Four bits can hold values in the range 0–15.) With a monochrome monitor, each bit of screen memory corresponds to one screen pixel, so in COLOR mode with a monochrome monitor each plot affects four screen dots.

HCOLOR = specifies the way that the HPLOT and ELLIPSE commands affect screen memory bits (and hence screen pixels) in the DOUBLE (560-point monochrome) mode. The syntax for the statement is


Where n can have one of the following values:

ValueEffect of Plot
0 or 4Set bit
1 or 5Clear bit
2 or 6Invert (toggle) bit
3 or 7Read bit and store its value (0 or 1) in location 6

For a monochrome screen, setting a bit will make the corresponding pixel appear white, while clearing a bit will make the corresponding pixel black. After a bit is read, a PEEK(6) can be used to determine the current state of the corresponding pixel. HCOLOR = 0 is the default setting after an HGR 3 or HGR 4 statement.

COLOR = selects the color to be used when HPLOT or ELLIPSE draws points in COLOR mode. The syntax for the statement is COLOR=n

where n is a value in the range 0–15. The correspondence between numbers and colors is as follows:

0 black

1 magenta

2 brown

3 orange

4 dark green

5 gray 1

6 green

7 yellow

8 dark blue

9 purple

10 gray 2

11 pink

12 medium blue

13 light blue

14 aqua

15 White

Chrome provides no facility to directly read the color of a pixel in COLOR mode. However, color values can be determined by switching to DOUBLE mode, specifying HCOLOR = 3, and performing four successive reads with HPLOT to collect the four bits of the color value.

HPLOT uses the same syntax as the standard Applesoft version:

HPLOT x1,y1 [To x2, y2[TO x3,y3…]]

However, the range of allowable values for the horizontal (x) coordinates is extended to 0–559.

ELLIPSE can be used to draw ellipses, circles, and similar shapes. It can also be used to draw arcs and other curved lines. The syntax for the statement is

ELLIPSE x radius, y radius, quadrant [AT x center, y center]

The AT part is optional. The x center and y center values specify the center of the figure. If omitted, the ellipse will be centered at the current pixel cursor position. This allows faster recursive ellipse drawing around a central point.

The x radius and y radius values are not checked for validity, but an ellipse can go off the screen without problems if the values are not unreasonably large.

Some other drawing utilities allow you to specify the starting angle and ending angle when drawing portions of ellipses or circles. For simplicity, ELLIPSE only allows you to choose whether or not to draw each of the four quadrants of the figure.

You specify which quadrants to draw using the quadrant value in the ELLIPSE statement. The following table shows which quadrant values draw corresponding quadrants of the figure:

upper left8
upper right4
lower left2
lower right1

The values are cumulative. For example, a quadrant value of 15 (8 + 4 + 2 + 1) is required to draw a complete ellipse. A value of 9 (8 + 1) would result in only the upper left and lower right quadrants being drawn.

Bitmapped Images

Chrome also provides a way to place bitmapped images onto the double hi-res screen. This method of shape generation is much different than the shape capabilities built into the computer. Bitmapped shape tables are easier to design and can be drawn more rapidly by the system. Shape rotations are performed by switching between bitmaps rather than by extra computation when the shape is drawn. You may have to experiment a while before you feel comfortable with the next commands. Beginners may wish to ignore the SHAPE command.

The new command has the following syntax:

SHAPE width, height, location [ATx, y)

The AT portion of the statement is optional. If it is included, the x and y values specify the coordinates at which the upper left corner of the shape will be drawn.

The width value is added to the x coordinate after each SHAPE execution. You can use this value to specify the horizontal spacing of shapes on the screen.

The height value specifies the height of the bitmapped image in screen lines. All bitmaps are two bytes (14 screen pixels) wide, so the heightof the bitmaps are two bytes (14 screen pixels) wide, so the height is half the length of the bit-mapped shape table.

The location value specifies the starting memory location for the bitmap shape table in RAM. More information on Chrome's memory usage is provided later in this article.

If the x coordinate for the shape does not begin on an exact byte boundary (pixel position 0, 7, 14, 21, and so on), the data from the bitmap must be preshifted before drawing. Preshifting does not retain the shifted bits. For instance if a full 14-bit-wide shape is to be plotted at coordinates 55,10, then six pixels will be lost during shifting because the preshifter must move the shape over 6 bits (55 MOD 7 = 6). Only shapes less than 8 bits wide can be drawn anywhere horizontally without risk of being partly lost. All bitmap data is in the same format as screen RAM, with bit 7 unused.

The drawing routine simply takes the data from a buffer and places it on the screen in exclusive OR mode. Shapes are drawn the same whether DOUBLE or COLOR plotting is enabled.

Memory Usage

Machine language programmers may appreciate the new commands as much as BASIC programmers will. Following is a description of how memory is allotted when Chrome is being used.

The ellipse routine keeps most of its data in the lower 16 bytes of the auxiliary zero page. Main memory Zero-page use is limited to those locations also used by the standard hi-res routines.

The program itself begins at location $1800 hex (6144 decimal) and ends at $1FFF. Screen RAM is at $2000–$3FFF.

When the program is BRUN (loaded and run) it initializes itself in five steps. First, it copies the high ROM ($D000 to $FFFF), including Applesoft, into the main memory RAM and alters Applesoft to accommodate the new commands.

Once the copy-and-change phase is done, four tables are created. Two reside in main-memory high RAM and are switched in when needed. They hold video addresses to speed up the pixel plotter. The third table, located at $1600, is the new tokenizer table; it holds the ASCII keywords of all of the old commands as well as those of the new commands. The fourth table, located at $1400, is used by the ELLIPSE routine only and holds the 16–bit squares of 0–255. These values are also used to speed up pixel position calculations.

The area from $0800 to $13FF is free for machine language routines and bitmaps of character sets.