MSX-HID
This page was last modified 16:04, 2 November 2018 by Sd snatcher. Based on work by Rderooy and Mars2000you.

Contents

Introduction

The MSX-HID is a de-facto standard for Human Interface Devices that can be connected to the MSX general purpose ports (informally called joystick ports).

It provides a reliable way for detection and handling different protocols via this port. Like most de-facto standards, it doesn't seem to have been fully designed by an initial plan, but instead evolved by series of aggregated evolutions, similar to the IDE interface. It's used by the MSX2/2+/TR BIOS mouse/trackball routines to make sure that only the correct devices are being read, and it's flexibility allowed room for the 2014 NYYRIKKI & Prodatron mouse protocol extension to be implemented.

For some unknown reason (maybe shared suppliers or programmers), Sega of Japan unofficially adopted this standard for their own devices, starting with the Master System, but extensively using it both on the Sega Mega Drive and Saturn consoles. They later extended the protocol even further. Parts of the MSX architecture are known to have been used in many kinds of appliances in Japan, so maybe this is just another case. Curiously enough, they even gave the Sega Mega Mouse exactly the same ID as the MSX-Mouse, with an extra bit-shaking to allow the software to differentiate one protocol from another.

Detection

Each device feature an unique signature that can be detected by software using the right steps. Since this standard was created in the 80s, the majority of the signatures were created with very simple circuitry by a clever selection of how the device bits were connected to the joystick port, sometimes forcing some bits to a specific value under certain conditions. This also means that the older devices took the simpler signatures, and the newer devices had to use the more complex bit patterns.

The pin-8 of the joystick port is used to clock the device, and the hardware signatures are made of at least three 6-bit values sent on each border change of the clock, as listed in the table below. The first two values contain the device-type ID, and any subsequent values are used to differentiate between devices of the same family. For example, the megadrive 6-button joypad outputs another three additional 6-bit values needed to differentiate it from the older 3-button controller. Another example is that with native MSX devices, the 3rd byte is used to differentiate the analog PWM devices from the digital devices.

The protocol is based on the following premises

  1. The devices shall be accessed at most once per frame, where all needed data must be transferred at once.
  2. While the detection is being done, the device must be centered/idle and all buttons must be released.
  3. Signatures can only use values that a standard MSX 2-button joystick cannot produce during normal use. (a joystick controller cannot have opposite directions pressed, for example).
  4. There must be a way for the driver to know that the device was disconnected. Usually this is some fixed bit at some specific byte of the data it sends.
  5. The 1st value read from the device on each frame must always be obtained with the clock line set to low, and the clock line must be set to low at the end of a session.
  6. The device data-transfer state must auto-reset after ~8ms without receiving any clock transition
  7. The formula to detect PWM analog channels from the signature is (byte1 xor byte3 and byte3). All bits that result in 1 are PWM channels.

Additional recommendations

  1. It's more reliable to detect the devices only upon connection.
  2. When the device is being connected, since not all pins of the DB9 connector get a proper electric contact at the same time, the programmer must discard spurious reads by confirming that the same signature values are received for at least a second.

Device communication protocols

The standard is flexible enough to allow the data transfer protocol to be device dependent. Many different protocols were used, including PWM, SPI, and many nibble-based protocols that are variants of the MSX-Mouse protocol. The specific documentation for the device must be consulted to know how to transfer data.

List of known signatures

Signatures of MSX devices

Unconnected, or MSX-joystick		: 3Fh,3Fh,3Fh
Mouse					: 30h,30h,30h
Trackball				: 38h,38h,38h
Touchpad(1)				: 39h,3Dh,39h
Touchpad(2)				: 3Dh,3Dh,3Dh
Lightgun				: 2Fh,2Fh,2Fh
Arkanoid Vaus Paddle			: 3Eh,3Eh,3Eh
PWM devices				: xxh,3Fh,3Fh, where each bit of "xx" is zero for each analog channel present
  MSX-Paddle				: 3Bh,3Fh,3Fh
  Yamaha MMP-01 music pad		: 3Ch,3Fh,3Fh
  Dual-axis analog controller		: 30h,3Fh,3Fh
  IBM-PC DA15 joystick adapter		: 39h,3Fh,3Fh 
  Atari dual-paddle adapter		: 33h,3Fh,3Fh

Signatures of the Sega devices that are compatible with the MSX-HID

Megadrive 3-button joypad		: 3Fh,33h,3Fh
Megadrive 6-button joypad		: 3Fh,33h,3Fh,33h,3Fh,30h
Megadrive Multi-Tap			: 33h,3Fh,33h
Saturn digital joypad			: 3Ch,3Fh,3Ch
Saturn Mouse				: 30h,3Bh,30h
Sega 3line-handshake device		: 31h,31h,31h

Signatures of devices that conflict with other MSX-HID devices

Micomsoft XE1-AP analog mode		: 2Fh,2Fh,2Fh
Sega-Mouse (Megadrive)			: 30h,30h,30h

If necessary, both cases can be distinguished from the other device with one extra detection step.

Homebrew devices

Ninja-tap				; 3Fh,1Fh,3Fh
3D glasses				: 3Fh,37h,3Fh
3D glasses + light gun			: 2Fh,27h,2Fh
Passive PS/2 mouse adapter		: 3Fh,3Eh,3Fh


Incompatible devices that don't comply with the standard

  • Panasoft FS-JH1 driving wheel
  • FM-Towns joypad
  • X68000 6-button joypad
  • Micomsoft XE1-AP digital mode (can be workaround by connecting it in analog mode first, then selecting the digital mode)
  • Konami JE700 Multiplayer link cable and the homebrew JoyNet cable

The first three devices are not even wired according to the standard MSX joystick schematics. This means that they can't be correctly detected and the only way to support them is via a manual menu selection, otherwise they will conflict with many existing MSX device IDs.