Rainbow Graphics


John R. Slaby

Try these variations and see if you can't make use of this new technique in games and graphics.

Here's how to print out any message in either GRAPHICS 1 or 2 and get up to seven colors for each character at the same time. Each color is limited to one scan line. After typing in the program and running it, you will be prompted to choose a graphics mode (1 or 2). You will then be asked for the message you want to display.

Capital and lowercase letters will be displayed in their normal solid default colors of orange and light green. Inverse capital and lowercase letters will be displayed in multicolor and will rotate in a curtain effect in opposite directions. The maximum length of the message was set at 120 characters/spaces, but this can be altered by changing the MSS$ dimension number. The input of the message has margins set to stimulate the GRAPHICS 1 or 2 display so that you don't end up with unintentionally hyphenated words.

The REMs in the program describe what is done where, but I believe three sections deserve some amplification. First, look at the 400 line numbers. The two FOR/NEXT loops store the various color values into the page six table locations for use by the DLI (the Display List Interrupt) and the vertical blank. Note that the color and luminance values increase for each location, thus giving a color and brightness change for each scan line.

If you want, you can easily change these values to give different effects. Choosing several colors and alternating them will give a barber pole effect. Keeping the same luminance value (make the I*2 just I) gives a sharper contrast between the colors. And to get a wider range of colors, change the color number by more than one for each scan line (for example, I*16*1.2). There are a great number of possibilities you can play with to get the effect you want; and since there are two tables, the two effects can be drastically different.

The vertical blank routine is contained in the DATA statements of the 300 lines. Its function is to rotate the two color tables in different directions to give the rolling curtain effect. If you want a static color display, you can eliminate the vertical blank by removing line 520 and adding POKE 54286,192 to line 510.

Another easy variation is to change the rotation rate. The number 4 after the number 201 in line 320 controls the rate of change. Decrease this number to increase the rotation rate; increase it to slow it down. Please note that the maximum number is 255. If you exceed this number, you will register an error, which will be caught by the TRAP (line 50); this process will start the program over again and again if you don't correct the bad POKE value.

Multicolors with DLIs

The DLI is the key to the multicolors. In Space Invadersthe DLIs are used to change the color of the invaders for each mode line. For GRAPHICS 0 and 1, the mode line consists of 8 scan lines, and for GRAPHICS 2, 16 scan lines. Normally, if you want to change colors for a mode line, you load a color value into the A, X, or Y registers, wait for horizontal sync (WSYNC), and then load the registers into the desired color registers during the horizontal blank. The problem is that the DLI is for the entire 8 or 16 scan lines, not each line.

Therefore, changing the color register after the horizontal blank results in your not knowing when the color change will take effect (for example, halfway across the scan line). One method to get around this would be to accurately count the 6502's cycles. When I first looked at the problem, this seemed the only way out; but not feeling that ambitious, I put this project on hold until I came up with an easier way.

The key is the WSYNC. For a meaningful display to exist on the TV screen, the WSYNC must occur every scan line, not every mode line. Thus, once you get control via the DLI, you keep it for eight WSYNCs and change the color registers during each scan line's horizontal blank. In theory, you can get eight colors for each character; but since the first line and the last lines are usually blank, six colors is what you actually get. If you want to modify the DLI, you could get 12 colors for GRAPHICS 2.

The one drawback of this method: if it is used for every mode line, it could tie up the 6502 processor for a good part of the available time. The majority of the remaining time would be during vertical blank. This would thus restrict the number of additional calculations, etc., you might want to do. This doesn't mean the technique is useless; it can be used for an eye-catching title page or used sparingly for a graphics display. It can also be used in games.

I believe this method is used in Demon Attackby Imagic for the Atari VCS. This game appears to change even the color of the player. You can also do this with my program by loading the player color register instead of the playfield. Overall, greater study of this method should allow programmers more latitude in creating striking visual effects.

The DLI and the vertical blank are not directly relocatable, but if you have any machine language capabilities, you should be able to modify them with little effort.

Rainbow Graphics

Download P037L1.BAS (Saved BASIC)
Download / View P037L1.LST (Listed BASIC)

Return to Table of Contents | Previous Section | Next Section