Joystick

From C64-Wiki

Jump to: navigation, search
Commodore C-1342
Commodore C-1342

A joystick is a gaming control device. The C64 is compatible with an old standard first used in the Atari 2600 gaming console; the same standard used on the VIC-20, the C128 and the Amigas.

Joysticks that are compatible with the 64 have a stick that the user may push in one of eight directions, and a "fire" button. The control stick is mechanically connected to four switches; "up", "down", "left", and "right". Pushing the stick in a direction in between two of these "cardinal directions" activates two of the four switches.

Some Commodore compatible joysticks may have more than one such fire button, but in those cases both buttons will "do" the same things in a game; the software has no way of determining which fire button is used. Together with the directional switches for the control stick, a standard joystick requires five connections and a common ground wire.

Contents

[edit] Autofire

Some joysticks have a feature known as "auto-fire", to help out in those games where the best strategy is to shoot, shoot, shoot all the time: An oscillator delivers fast repeating pulses to the line normally connected to the fire button(s). Some people have made hardware "add-ons" that adds auto-fire capability to any joystick.

[edit] Joysticks as seen from the C64

Joysticks connect to the two control ports at the rightmost end of the C64. Inside the machine, the five switch lines from the joysticks connect to ports A and B in CIA #1; in parallel with the keyboard matrix. This is the reason why a joystick, especially one connected to control port #1, causes the machine to "type" characters when the joystick is operated.

A joystick on port #1 is read through address 56321/$DC01, and one on control port #2 are read via address 56320/$DC00. In each byte,

  • Bit 0 (weight 1) goes low if the "up" switch is activated,
  • Bit 1 (weight 2) goes low if the "down" switch is activated,
  • Bit 2 (weight 4) goes low if the "left" switch is activated,
  • Bit 3 (weight 8) goes low if the "right" switch is activated,
  • Bit 4 (weight 16) goes low if the fire button is presses.

[edit] Analog lines in the control ports

Besides ground and five inputs for the switches and buttons, the control ports also provides +5V (the aforementioned auto-fire feature is "fed" from this supply line) and two analog inputs, designed as "ohmmeters": These analog lines are mostly used for paddles, but despite the possibility to use these lines for an analog joystick (which can sense much more subtle movements to the stick than the four directional switches), such joysticks have never seen much use on the 64.

[edit] Programming

The memory addresses 56321 (Control Port 1) and 56320 (Control Port 2) contain the exact position of the joystick. These positions can be read with the BASIC-Command PEEK.

10 PRINT PEEK(56320): GOTO 10
RUN

Break with <RUN/STOP>.

Some keys of the keyboard and the joystickports have got some , so must the keyboard shut down meanwhile you read the memory adress of the joysticks. That happens with POKE 56322,224. With POKE 56322,255 or with the key-combination <RUN/STOP>+<RESTORE> can activate the keyboard again.

Position56321 Port 156320 Port 256321 Port 1
Fire pushed
56320 Port 2
Fire pushed
mitte (no move)255127239111
oben254126238110
unten253125237109
links251123235107
rechts247119231103
oben links250122234106
oben rechts246118230102
unten links249121233105
unten rechts245117229101

[edit] Example Listing

This BASIC-programm use a positionarrow and the arrow will be moved with the joystick in port 2.

 10 S=2: X=150: Y=150: V=53248: GOTO 100
 15 J=PEEK(56320): IF J=127 THEN 15
 20 IF J=111 THEN POKE 56322,255:END
 25 IF J=123 THEN X=X-S
 30 IF J=119 THEN X=X+S
 35 IF J=125 THEN Y=Y+S
 40 IF J=126 THEN Y=Y-S
 45 IF J=122 THEN Y=Y-S
 50 IF J=118 THEN Y=Y-S
 55 IF J=117 THEN Y=Y-S
 60 IF J=121 THEN Y=Y-S
 65 IF X=>252 THEN X=10
 70 IF X=<10 THEN X=252
 75 IF Y>254 THEN Y=44
 80 IF Y<44 THEN Y=254
 85 PRINT CHR$(147);CHR$(158);CHR$(17);"X-POS:";X;" Y-POS";Y
 90 POKE V,X:POKE V+1,Y: GOTO 15
100 FOR Z=832 TO 853 : POKE Z,0: NEXT Z
105 FOR Z=832 TO 853 STEP 3: READ J: POKE Z,J: NEXT Z
110 POKE V+21,1: POKE  V+39,7: POKE V+33,0: POKE V+29,1
115 POKE 56322,224: POKE 2040,13: GOTO 85
120 DATA 240, 224, 224, 144, 8, 4, 2, 1

[edit] Links

Wikipedia: Joystick
Personal tools
Navigation
Help and Feedback
In other languages