VIC-20 joystick - which is the real way?
Posted: Sun Feb 11, 2024 12:54 pm
I recently obtained a copy of my first-ever published program (in a newsletter, heh) and found it odd I chose to use "Up" and "Down" on the joystick to move left and right. I did some research and discovered the routine I was using was incorrect, and never read the byte that contained the "right" direction. I must not have been able to get it to work, and just switched to using up and down, since those read for me.
I tried to figure out what magazine I got my joystick code from, and the only hit in Archive.org was some Toronto Pet (The TORPET) newsletter. It was so early in the VIC-20 era that they had an article mention that "15,000" had been sold so far
Wild. Here is the VIC-20 column I found (page 31, or 46 in the PDF):
https://archive.org/details/TORPET_The_ ... 0++4+%2B32
And their code:
This was identical to the code I had found, except they used 37152 and 37151 and my program had a typo where it was using 37152 twice.
BUT, as I searched to figure out the problem, I found an Atari Magazine reference to reading these two values:
Those two match what I'd expect from the memory map. I see that 37137 is "Port A output register" and 37152 is "Port B output register".
37151 is listed as "Port A (Sense cassette switch)" and I don't see anything about the joystick there.
BUT ... the code works when using these two locations, OR the 37151/37152 locations. My test:
I have found examples showing the use of both sets of locations. The wiki here shows it that way as well:
http://sleepingelephant.com/denial/wiki ... p/Joystick
I did not know much about VIC-20 hardware during the time I had one, but on my Radio Shack Color Computer I am aware that there were certain I/O registers that were ghosted, and would appear in multiple places. Is something like this happening here?
After finding so many places saying "use A and B" and other places saying "use A and C" and they both work, I'm a bit confused
Thanks, much.
I tried to figure out what magazine I got my joystick code from, and the only hit in Archive.org was some Toronto Pet (The TORPET) newsletter. It was so early in the VIC-20 era that they had an article mention that "15,000" had been sold so far

https://archive.org/details/TORPET_The_ ... 0++4+%2B32
And their code:
Code: Select all
9000 POKE 37154,127
9010 JO= (NOT((PEEK(37152)AND128) /8+( PEEK(37151)AND60)/4)) +32
9020 POKE 37154,255
9030 RETURN
BUT, as I searched to figure out the problem, I found an Atari Magazine reference to reading these two values:
Code: Select all
10 PRINT PEEK(37137), PEEK(37152) : GOTO 10
37151 is listed as "Port A (Sense cassette switch)" and I don't see anything about the joystick there.
BUT ... the code works when using these two locations, OR the 37151/37152 locations. My test:
Code: Select all
10 rem fixed torpet code
20 gosub 9000
30 if jo and 1 then print "up ";
40 if jo and 2 then print "down ";
50 if jo and 4 then print "left ";
60 if jo and 8 then print "fire ";
70 if jo and 16 then print "right";
80 if jo<>0 then print
90 goto 20
9000 poke 37154,127
9010 rem jo=(not((peek(37152)and128)/8+(peek(37137)and60)/4))+32
9015 jo=(not((peek(37152)and128)/8+(peek(37151)and60)/4))+32
9020 poke 37154,255
9030 return
http://sleepingelephant.com/denial/wiki ... p/Joystick
Code: Select all
1 S=PEEK(37151):POKE37154,127:T=PEEK(37152):POKE37154,255
2 IF (128ANDT)=0 THEN PRINT "RIGHT"
3 IF (16ANDS)=0 THEN PRINT "LEFT"
4 IF (8ANDS)=0 THEN PRINT "DOWN"
5 IF (4ANDS)=0 THEN PRINT "UP"
6 IF (32ANDS)=0 THEN PRINT "FIRE"
7 GOTO 1
After finding so many places saying "use A and B" and other places saying "use A and C" and they both work, I'm a bit confused

Thanks, much.