Random Color Switching While Idle
R. A. Howell
Have you ever been involved in a scenario similar to the following? This has happened to me several times. I get the program listing of a new game from a friend or from the pages of a magazine. The game sounds really exciting, so I anxiously begin typing the program into my Atari 800 computer system. Of course, my 10 year old son is busily watching over my shoulder because he is also anxious to try out the new program. When I finally finish, we try it. After a few corrections for typing mistakes, the game is running and we get deeply engrossed in playing it. About the time we have mastered the rules and are into the full action and excitement of the game, ZAP!!, the Atari 800 goes into its random color switching routine on the screen. This usually makes the playing field difficult to see because the random colors selected by the computer are either too dark or are all of similar shades so they blend together. The solution is simple for those of us who have used the Atari; just hit a key, any key on the keyboard and the original program's colors will be restored. Right! Wrong! The problem with this is that if I take either hand from the joystick or fire button to hit a key, my son gains the advantage in the game, and vice versa. Have you also found yourself in this dilemma?
The problem occurs because of a hardware feature on the Atari computer. When a key has not been pressed for a little over 9 minutes, the system automatically starts to vary the colors on the screen. It will continue to randomly vary the colors on the screen until a key on the keyboard is pressed. At that point it will return the screen to the correct colors and begin the 9 minute time-out sequence again. The purpose of this feature is to prevent the image on the screen from being permanently burned into the phosphor on the cathode ray tube when the computer is left for a long time without being changed. However, many programs (games in particular) do not require any key-presses. All inputs come from trigger buttons and game paddles or joysticks. When running such a program, it is inconvenient to have this color switching occur every 9 minutes, so let's look at what triggers this feature and how to prevent it from happening.
Type the following one line program into your Atari computer and run it:
10 PRINT PEEK(77): GOTO 10
This program repeatedly displays the contents of RAM (Random Access Memory) location 77 on the screen. As you can see by watching it run, RAM location 77 starts at 0 and increments by 1 every 4 to 4.5 seconds. Now while this program is still running, press any key on the keyboard (except BREAK or the 4 special function keys). As soon as you pressed the key, notice that location 77 returned to 0 and started incrementing all over again. Now let the program run for a while without pressing any keys. After approximately 9 minutes, the count will be close to 128. As soon as RAM location 77 reaches 128, you will see that it gets set to 254 and the screen colors immediately begin to vary randomly. Now with the program still running, press any key again. Normal colors are returned to the screen and location 77 begins all over incrementing from 0.
Each byte of memory in the Atari consists of 8 BITS (BInary digiTS - l's or 0's). The lower 7 bits of memory location 77 are used to count from 0 to 127. When the count reaches 127, all of these 7 bits are binary 1's. Adding 1 more causes the 8th (uppermost) bit to change from 0 to 1 and this triggers the random color switching hardware. At 4 to 4.5 seconds per increment, it takes about 9 minutes for the computer to count from 0 to 127. Any number in location 77 from 128 to 255 will cause the upper bit to be set to 1 and the random color switching to occur. To see this, stop the program from running (with the BREAK key) and enter the following:
When you type this and press RETURN, the screen immediately starts switching colors because 217 is between 128 and 255 and has caused the upper bit of memory location 77 to be set to 1.
So any BASIC program can be modified to prevent the random color switching from occurring by periodically executing a POKE 77,0 to reset location 77 to zero and prevent it from reaching 128. Now you say, 'Won't this stop the computer from doing its color switching if I leave it for over 9 minutes with that program running and thus defeat the purpose of this hardware feature?' The answer is no, not if the POKE statement is placed in the program properly. When the program is idle, it will probably be in a loop waiting for paddle or joystick inputs. Just make sure the POKE statement is not put in this loop. Place it elsewhere in the program where it will be executed frequently. Then, if the computer is left idle while the program is running, it will not execute the POKE statement and random color switching will take place after 9 minutes. When the player returns, as soon as the joystick or paddle is moved or a trigger button pressed, the idle loop will be terminated and the POKE statement executed, returning the screen to normal colors. If the POKE statement is put in the right place, it can be made to appear as if the paddle or joystick acted just like a key-press in restoring the screen to normal.
Now that the function of RAM location 77 has been revealed, the random color switching feature of the Atari computer can be put back into its proper place. It won't need to be a bother any longer by popping up unexpectedly at the wrong moment! Happy programming.