Joystick control
This page was last modified 03:16, 29 January 2017 by Sd snatcher. Based on work by Gdx and NYYRIKKI.

Joystick programming

The following BIOS functions provide high-level (cooked mode) access to the joysticks:

  • GTSTCK: Get a given joystick direction
  • GTTRIG: Get a given trigger status

Alternatively, low level (raw mode) access to the joystick ports can be done with the following BIOS functions, to access the R#14 and R#15 of the PSG.

  • WRTPSG: Write to a PSG register
  • RDPSG: Read from a PSG register

Note: Special care must be taken when using raw mode to access the joystick ports: many devices other than joysticks can be connected to the joystick port. Those will have different meanings for the bits of the R#14, like the mouse, touchpad and paddles. The programmer must make sure that the program won't have trouble because one of such devices was left connected to the joystick port. As a counter example, the majority of Konami games have will have trouble with the keyboard directions if any device other than a joystick is left connected to the joystick port.

Hardware mapping

PSG register 14:
-------------------------------------------------
| b7  | b6  | b5  | b4	| b3  | b2  | b1  | b0	|
-------------------------------------------------
   |	       |     |	   |	 |     |     |		       --+
   |	       |     |	   |	 |     |     +--> 1st pin	 |   input
   |	       |     |	   |	 |     +--------> 2nd pin	 |     of
   |	       |     |	   |	 +--------------> 3rd pin	 |  Joystick
   |	       |     |	   +--------------------> 4th pin	 |    port
   |	       |     +--------------------------> 6th pin	 |  defined by
   |	       +--------------------------------> 7th pin	 | PSG R.15 bit6
   |							       --+
   +-----------------------------------> Data input from the cassette tape




PSG register 15:
-------------------------------------------------
| b7  | b6  | b5  | b4	| b3  | b2  | b1  | b0	|
-------------------------------------------------
   |	 |     |     |	   |	 |     |     |
   |	 |     |     |	   |     |     |     +--> 6th pin output/Joyport A (Default 1)
   |     |     |     |     |     |     +--------> 7th pin output/Joyport A (Default 1)
   |     |     |     |     |     +--------------> 6th pin output/Joyport B (Default 1)  
   |     |     |     |     +--------------------> 7th pin output/Joyport B (Default 1)
   |	 |     |     +--------------------------> 8th pin output/Joyport A (Default 0)
   |	 |     +--------------------------------> 8th pin output/Joyport B (Default 0)
   |	 |
   |	 +---> 0: b0-b5 of PSG register 14 to be connected to Joyport A
   |	       1: b0-b5 of PSG register 14 to be connected to Joyport B (Default)
   |
   +---------> 0: Arabic or kana mode display lamp on
	       1: Arabic or kana mode display lamp off

Register 15 values are reset to "default" by BIOS keyboard scan routine on interrupt handler.

Bit meanings for pins:
0: GND
1: HI-Z, pull-up.

Each port 5th pin is connected to +5V and 9th pin is connected to GND.

Circuit Diagram

Standard MSX-joystick circuit diagram, as shown in the official MSX documentation:

MSX joystick circuit diagram.png