Classic Computer Magazine Archive COMPUTE! ISSUE 146 / NOVEMBER 1992 / PAGE G29

136 Colors. (computer program for producing colors)
by David Kwong

As most people know, the 64 is capable of producing 16 different colors. How would you like to increase that number to 136 colors?

You can with 136 Colors. This interesting program does it by placing differently colored pixels side by side to produce a third color. Since the 64 has 16 built-in colors, it would appear that you could create 256 colors by combining the 16 x 16 color matrix. In reality, you get a total of 136 different hues, since 120 of them would be duplicated.

There are three programs built into the main 136 Colors program. The first program is an editor that will produce sprites capable of 136 colors. Additionally, each sprite character can have up to four colors simultaneously in high resolution mode. The second program is an interrupt program designed to make programming in BASIC with 136 Colors a lot easier. The third program is also an interrupt program designed to be used with other programs to make 136 Colors available for use.

Typing It In

Since 136 Colors is written entirely in machine language, enter it with MLX, our machine language entry program. See "Typing Aids" elsewhere in this section. When MLX prompts, respond with the following values.

Starting address: C79C

Ending address: CFAB

Be sure to save a copy of the program before exiting MLX.

Program 1

Load the program with the ,8,1 extension, and then type NEW. To activate the first program, type SYS 51200.

The first thing to do is to select a block number, indicated at the upper right corner. A block number is an address where sprites can be stored. Recommended block numbers are 128-255 (block numbers range from 0 to 255). To find the actual address where the sprite is stored, multiply the block number by 64.

After you've selected a block number, a cursor appears in a grid that is used to create a sprite. The sprite that the grid represents is located at the upper right of the screen. The keys used to move the cursor are displayed at the lower right of the screen. Press f1 to begin drawing. A menu at the bottom provides other options. One option, NO DR/ER, means that the cursor will neither draw nor erase. This option lets you move the cursor without affecting what's on the screen.

To change colors while in draw mode, press either 1, 2, or 3. To change a sprite into its 136-color shape, either exit or change the block number. The program will then ask you whether or not to change the sprite into 136-color mode. If you elect to do so, the program then will ask you where to store the 136-color sprite.

Each 136-color sprite is composed of two normal sprites, one on top of the other. Sprite 1 is represented by color 1; sprite 2 is represented by color 2. Color 3 is divided between the two sprites. When the two sprites are overlapped, color 3 is capable of producing a color from the 136-color palette. The two sprites must have the same coordinates for them to overlap perfectly.

Program 2

The second program, which is an interrupt program, is activated or deactivated by SYS 52600. When activated, you'll see a message onscreen that says 136 BAS ON.

This program provides 16 new sprite registers that will ease the usage of the four high-resolution sprites and 136 colors. There are only four high-resolution sprites, instead of the normal eight, because of the fact that each hires sprite requires two normal sprites. This program defines hi-res sprite 1 as the overlap of sprites 0 and 1. Hi-res sprite 2 is the overlap of sprites 2 and 3, hi-res sprite 3 is the overlap of sprites 4 and 5, and so on.

The first eight registers from 52882 to 52889 provide the x- and y-coordinates of the four high-resolution sprites. The first high-resolution sprite can be moved by using the horizontal register 52882 and the vertical register 52883, much like the system used by the 64 to move the eight normal sprites. Therefore, every two registers provide the horizontal and vertical registers of one hi-res sprite.

The next four registers, 52890 to 52893, provide the colors of each of the four hi-res sprites. The color numbers range from 1 to 136.

The last four registers, 52894 to 52897, provide the block numbers for the four hi-res sprites.

This interrupt program supposes the block numbers for each hi-res sprite to be next to each other. Keep in mind that one hi-res sprite is composed of two normal sprites. Therefore, when you choose block number 200, the two overlapping sprites will be composed of blocks 200 and 201.

All registers are write-only registers. When you attempt to read them, they will return a 0. When the registers are 0, the interrupt program will not alter any sprites. Therefore, should you poke 52882,0, nothing will happen, meaning that if you originally poked 140, poking a 0 will not move it from location 140 to location 0.

In order to see the sprites you have produced, you must first set register 53269 to turn on the sprites you desire. Hi-res sprite 1 can be turned on with a POKE 53269, 3. POKE 53269, 12 turns on hi-res sprite 2. POKE 53269, 40 turns on sprite 3, and POKE 53269, 192 turns on sprite 4. To turn on more than one sprite, simply add up the previous values.

Program 3

The third program is activated or deactivated by SYS 52900. When activated, you'll see 136C ON printed on the screen. This simple program is designed to work with other programs that can make use of the 136 colors.

The only register provided is at 52844. This register is a 136-color register. By poking colors 1 to 136 into this register, 2 colors will be returned at locations 52898 and 52899. When the 2 colors are placed together, they'll combine to create 1 of the 136 available colors.

Since machine language programs may be too fast for the interrupt to be effective, you must keep track of location 52844. After execution of the interrupt, 0 will be stored in location 52844. If using machine language, you may choose to poke the required color in 52844 and then JSR $CE5A (make sure the interrupt is deactivated) to obtain the two colors in locations 52898 and 52899.

Technical Notes

This program takes up minimal space from $C79C (51100) to $CFAA (53162). Considering that 136 Colors is composed of three programs, applications that require only one of these three programs may isolate that particular program for usage.

The first program is located from $C79C (51100) to $CD77 (52599), the second program is located from $CD78 (52600) to $CFAA (53162), and the third program is located from $CE5A (52826) to $CFAA (53162).

Since different color combinations may produce the same color, there may in fact be less than 136 colors. Following is a color chart of the 136 colors. The colors are organized from brightest to darkest. (These colors were very difficult to organize. Please excuse some slight mistakes!)

White--Black (1-13) Gray 2 (14-16) Extra Gray (17-23) Brown 1 (24-32) Brown 2 (33-35) Brown 3 (36-38) Brown 4 (39-42) Red (43-51) Orange (52-57) Yellow (58-64) Tan (65-71) Green 1 (72-77) Green 2 (78-81) Green 3 (82-86) Green 4 (87-93) Green 5 (94-95) Cyan (96-102) Blue (103-111) Purple 1 (112-118) Purple 2 (119-123) Purple 3 (124-127) Purple 4 (128-134) Purple 5 (135-136)

Seeing is Believing

The 136 Demo program is designed to show the various colors in action and to provide programmers with additional details on how to use 136 Colors.

The demonstration consists of a BASIC program and machine language sprite data. To avoid typing errors, use The Automatic Proofreader to enter the BASIC portion. Use MLX to enter the sprite data. When MLX prompts, respond with the following values.

Starting addresses: 3200 Ending address: 347F

Before leaving MLX, save the sprites with the filename Sprites. When the demonstration runs, it loads 136 Colors and Sprites and looks for those filenames.