Classic Computer Magazine Archive COMPUTE! ISSUE 47 / APRIL 1984 / PAGE 108


I own a VIC and would like to know the PEEK command for the right SHIFT key. I know the left SHIFT key is PEEK(145). I realize PEEK(653) could be used, but I only want to know when the right SHIFT key is pressed, not the left. Also, what is the PEEK command for the RESTORE key?

Chris Stroud

The following information, excerpted from the upcoming COMPUTE! book Mapping the VIC-20 by G. Russ Davies, should be of help.

"Each time the jiffy clock TIME is updated by the Kernal, the contents of VIA2PA2 (VIA2-Port A) are copied to location 145.

"Every other key on the bottom row of the keyboard may be tested for in this location, without using a GET command in BASIC.

"Here's an explanation of the different values you'll find in this location:

PEEK Hex Number
255   ($FF) = no key pressed
254   ($FE) = STOP key pressed; STOP routine will find and acton
253   ($FD) = left SHIFT key pressed. This may be the most useful returned value, especially for game programmers. It allows the program to distinguish between the left and right SHIFT keys by checking location 653, then location 145, bit 1 for left/not left.
251   ($FB) = X key pressed
247   ($F7) = V key pressed
239   ($EF) = N key pressed
223   ($DF) = comma key pressed
191   ($BF) = slash key pressed
127   ($7F) = cursor-down/up key pressed

"You can examine the values in this location when the bottom row keys are pressed by entering and running this short program:"

10 ?PEEK(145).GOTO 10

In other words, if location 653 says SHIFT is down, but location 145 doesn't, then the right SHIFT key is down. Otherwise, the left SHIFT key is down (or both left and right SHIFT keys together).

The RESTORE key is not a normal keyboard key. It is not wired through the VIA, but directly to the 6502 's NMI line. When RESTORE is pressed, a Non-Maskable Interrupt is generated, which makes the 6502 jump to a special NMI routine. This routine checks to see if the RUN/STOP key is being held down, and if so, executes the soft reset normally performed by RUN/ STOP-RESTORE. If RUN/STOP is not held down, the interrupt will occur when you press RESTORE, but nothing will seem to happen. It's not easy to trap and re-vector the RESTORE key, but the vector for the routine we've mentioned is at 792 and 793.