Classic Computer Magazine Archive COMPUTE! ISSUE 77 / OCTOBER 1986 / PAGE 72

Design 64

Joseph Sexton

This full-featured artistic programming tool allows you to draw, paint, erase, and save your creations. Using the multicolor high-resolution screen as a canvas, you can easily design a colorful picture or background screen for use in BASIC programs or arcadestyle games. "Design 64" is written entirely in machine language, but no machine language knowledge is required to use it. This article also includes a short BASIC program which loads and displays any hi-res picture. A joystick is optional.

The Commodore 64 can display complex, detailed high-resolution pictures, but creating such displays from BASIC can be a slow, complicated process. Like commercial drawing programs, "Design 64" lets you draw directly on the hi-res screen and create highly detailed, multicolor images, even if you're not a programmer. Once you've drawn a picture, you can save it to disk or tape and reload it for future viewing or further enhancements. Since Design 64 is written entirely in machine language, you must enter Program 1 with "MLX," the machine language entry program published elsewhere in this issue. Follow the MLX instructions carefully. When you run MLX, you'll be asked for a starting address and an ending address. Here are the addresses you need to enter Program 1 with MLX:

Starting Address: 4CB0
Ending Address: 5537

Load Design 64 with the command LOAD "filename", 8, 1 for disk or LOAD "filename", 1, 1 for tape. To activate the program, type SYS 19632 and press RETURN.

Hi-Res Drawing

When you activate Design 64, a yellow pen appears on a blank white screen. You can move the pen around the screen with keyboard controls or with a joystick in port 1. On the keyboard, the I, J, L, and comma keys move the pen up, left, right, and down, respectively. The U, O, M, and period keys move the pen diagonally to the upper left, upper right, lower left, and lower right, respectively. The pen has two speeds for drawing; press the f7 key to switch from one speed to the other. The slower speed is useful when you're doing fine-detail work or using the joystick, which moves the pen considerably faster than the keyboard controls.

The f1 key cycles through all of the 16 available drawing colors, in the order described in the 64 user's manual. The f3 key cycles the screen background color, and f5 cycles the screen border color.

Press the f2 key (SHIFT-f1) to save or load a picture file or exit the program. If you choose the SAVE or LOAD option, the program prompts you to enter the desired filename, then choose disk or tape. When it saves a picture, Design 64 automatically stores the picture's hi-res bit pattern, color memory, background color, and border color in a single file.

Press f8 (SHIFT-f7) to enter block-fill mode. In this mode, the pen fills an area below and to the right of its current position, using the current drawing color. Nonrectangular shapes may have to be colored in two or more operations. Note that you must select the higher drawing speed when using this option.

This hi-res picture was created with "Design 64," a powerful, convenient drawing program for the Commodore 64.

Four Drawing Pens

You may have noticed by now that the top of the drawing pen is initially labeled with the letter C. Design 64 actually offers four different drawing pens, labeled C, Z, X, and V. To switch from one pen to another, press the corresponding letter on the keyboard. The reason for using four pens is a bit complicated, but understanding it is essential to using the program successfully.

When you turn on the 64, it defaults to the standard character mode. In this mode the screen is divided into 40 columns and 25 rows of squares, for a total of 1000 squares. Each square can hold one character, and is assigned a single location in memory. Collectively, this group of squares is known as screen memory. For each square in screen memory, there exists a matching memory location which holds that square's color. This group of 1000 locations is known as color memory. A character or color code occupies one byte of memory, so both screen memory and color memory require 1000 bytes of memory. Text mode permits only one color per square (in addition to the screen background color which shows through the gaps in the character).

In multicolor high-resolution mode, the screen is organized quite differently. Instead of 1000 character-sized squares, the screen is divided into 64,000 individual dots called pixels. Each pixel has a corresponding bit in memory. If the bit is set to 1, then the corresponding pixel is lit up. If the bit contains 0, the pixel is off (dark). Since there are eight bits per byte, the high-resolution screen requires 8000 bytes of memory to store picture data.

There is not an individual color memory location in multicolor hires mode for each pixel. Instead, color memory is divided into 1000 squares, each square containing 64 pixels. You may have as many as three different colors in each square, plus the background color. This is the reason for using four pens. Drawing lines of three different colors within a given color square requires that you use three different pens. To see what a square looks like, draw a medium-sized box on the screen and color it in. Then move the pen to the center of the box and press f1. Instantly, one square will change to the new color. Fortunately these squares are rather small; you can achieve good color density by identifying which pixels share color squares and taking this into account when designing your picture.

The Z pen has two functions: moving the pen without drawing, and erasing. To move the pen without disturbing anything, press Z. If you press the A key, the Z label appears and the Z pen erases whatever it travels over. Press A a second time to exit erase mode. To erase the entire screen, press SHIFT–CLR /HOME (be careful not to erase a picture by accident—there's no way to undo the operation).

Each of the pens except the Z pen (which doesn't draw) can have any of the 16 available colors. To change the color of a pen, select the pen and press f1 until the desired color appears. The X pen is the only one that always draws its color over other colors. The C and V pens have no special features. When your picture is complete, move the pen off the right edge of the screen for an unobstructed view. It is not necessary to do this when saving a screen, since the pen is not saved with the picture.

Hi-Res Screens From BASIC

Program 2 allows you to load and display a previously designed hires picture without having to run Design 64. Replace NAME in line 10 with the name of the picture file you wish to load. If you're using tape instead of disk, change the 8 to 1 in line 10. The hi-res graphics data load into memory locations 24568–32567, well out of the way of most BASIC programs. The video matrix which normally appears in locations 1024–2023 is moved to locations 23552–24551. This area stores color information—specifically, color codes produced by the C and V pens—in multicolor hi-res mode. Color codes for the X pen are stored in the regular color memory area from 55296–56295.

When Design 64 saves a picture, it moves color memory to the zone just above screen memory, then saves the entire area from 23552–33578 as a program (PRG format) file. Line 30 of Program 2 transfers this data back to the original location. Sprite pointers, which are normally located just above screen memory, are also moved to locations 24568–24575. Note that these pointers can only point to memory locations in video bank 1, which begins at 16384. Sprite shape data may be located anywhere in the area from 16384–23551, a 7168-byte zone big enough to hold 112 sprite shapes. Don't attempt to store sprite data above this area: The remainder of bank 1 contains the hi-res bitmap and color memory.

When you select a drawing pen (X, C, or V), it immediately places a dot of color on the screen. To avoid needless erasing, position the pen in the desired spot with Z before you switch to a drawing pen. When you wish to fill an irregular figure, it often saves time to draw a box inside your figure and fill that block first. Then you can finish the missing areas by hand. Note that the block-fill routine will only color over a blank screen; when the pen hits a nonzero location on a downward move it ends the routine.

Due to the 64's internal wiring, four of the keys mimic the effect of moving a joystick in port 1. The 1, left-arrow, CTRL, and 2 keys correspond to up, down, left, and right, respectively. If you're using keyboard controls, you can use this feature to your advantage to move the pen faster than usual.

Program 1: Design 64

Please refer to the "MLX" article in this issue before entering the following listing.