Perhaps one of the most useful commands in BASIC is POKE. Why? Because POKE allows you to do some things that cannot be done as easily in BASIC. I recall the earlier days of the PET, where every time a nifty memory location was discovered, it was published with glee - indeed, they were real "tidbits." Nowadays, however, there are several very good memory maps that document the inner workings of the PET quite well.
In the Atari Basic Reference Manual, there is an appendix entitled "Memory Locations" (Appendix I). Although it is not a true memory map since it is incomplete, it does list some very interesting locations.
During the execution of a program, the cursor does not disappear. Rather, it moves with the print statements and sometimes is left behind, cluttering up the screen with little white squares. Fortunately, the visibility of the cursor can be zeroed out with a simple statement: POKE 752,1. To restore the cursor, press the BREAK key or POKE 752,0. The well-known problem of the non-standard behavior of the Atari's GET statement has led to the discovery of memory location 764. Here is stored the code representing the last key pressed. This is not in ATASCII, but is a code used in the scanning of the keyboard. If no key has been pressed, a value of 255 will be found here. I first found this technique right here in COMPUTE!. In "Adding a Voice Track to Atari Programs," the author suggested using a subroutine like this to check if a key has been pressed:
lineno IF PEEK (764) = 255 THEN lineno (same lineno)
lineno POKE 764,255: RETURN
The first statement waits for a key to be pressed; the second discards that keypress by making BASIC think no key was pressed so that the keystroke would not be printed accidentally.
An example of how POKEing can be easier to use than a BASIC equivalent is in directly controlling the five color registers. After all, they too are only mere memory locations. Locations 708-712 correspond to SETCOLOR color registers 0-4. Using the notation SETCOLOR aexp,aexp,aexp where aexp is an arithmetical expression, the first number is from 0-4, so use the appropriate memory location. Then multiply aexp number two by 16 and add the third number to it. This gives you an integer in the range 0-255.
Now just enter POKE COLR, NUMBER where COLR is the memory location of the color register and NUMBER is that number you obtained. Figuring out what color is already being displayed is done in the reverse fashion. Get the contents of the color register with PEEK(COLR), and assign it to some variable, say X. (e.g. X=PEEK(COLR) . Divide X by sixteen, throw away the fraction using Y=INT(X), then find the luminance (aexp#3) with L=X-16*Y. Now you can set the color by basic with SETCOLOR COLR-708,Y,L or you can just store the numbers so you can meditate on them at a later date.
Have fun with these memory locations, you hackers! You beginners - step right up and add several new functions to your repertoire!
I want to leave you one more thing to try - POKE 755,6. It's weird! (You can get it back to normal with POKE 755,2 or by pressing RESET.
Return to Table of Contents | Previous Section | Next Section