Difference between revisions of "JSX-C"
From MSX Game Library
Line 8: | Line 8: | ||
* Leaving Pin 8 LOW for long enough (>1 ms, about 3580 t-states) resets the joystick's internal counter, | * Leaving Pin 8 LOW for long enough (>1 ms, about 3580 t-states) resets the joystick's internal counter, | ||
* then successive pulses on Pin 8 (LOW > HIGH) are used for data transmission (6 bits per 6 bits). | * then successive pulses on Pin 8 (LOW > HIGH) are used for data transmission (6 bits per 6 bits). | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== States == | == States == | ||
− | === | + | === Idle state (no-communication) === |
Write R#15 | Write R#15 | ||
Line 27: | Line 20: | ||
: <u>Note</u>: It could be any value between 00-3F not already return by [https://www.msx.org/wiki/MSX-HID#List_of_known_fingerprints other MSX devices]) | : <u>Note</u>: It could be any value between 00-3F not already return by [https://www.msx.org/wiki/MSX-HID#List_of_known_fingerprints other MSX devices]) | ||
− | === | + | === Communication state === |
Write R#15 | Write R#15 | ||
− | : Pin 8: LOW | + | : Pin 8: LOW |
Write R#15 | Write R#15 | ||
− | : Pin 8: HIGH ( | + | : Pin 8: HIGH (request data) |
Read R#14 | Read R#14 | ||
− | : | + | : 6-bit data |
− | < | + | |
+ | Pin binding for received data: | ||
+ | <syntaxhighlight> | ||
+ | Bits 7 6 5 4 3 2 1 0 | ||
+ | –-–-–-–-–-–-–-–--–-–- | ||
+ | Pins x x 7 6 4 3 2 1 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== Device ID ==== | ||
+ | |||
+ | First received data is the JSX device ID: | ||
+ | <syntaxhighlight> | ||
7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 | ||
–-–-–-–-–-–-–-–-- | –-–-–-–-–-–-–-–-- | ||
− | + | 0 0 A A A A B B | |
│ │ │ │ └─┴── Number of button rows (0-3) | │ │ │ │ └─┴── Number of button rows (0-3) | ||
│ │ │ │ 0: No button | │ │ │ │ 0: No button | ||
Line 47: | Line 51: | ||
│ │ │ │ 3: Up to 18 buttons | │ │ │ │ 3: Up to 18 buttons | ||
└─┴─┴─┴────── Number of axis (0-15) | └─┴─┴─┴────── Number of axis (0-15) | ||
− | </ | + | </syntaxhighlight> |
− | :<u>Note</u>: Number of axis or number of button rows can be zero, but not both. So any device ID up to 0x3F is valid except 0x00. | + | |
+ | Input number can be computed as: | ||
+ | * Axis: <tt>ID / 4</tt> | ||
+ | * Button rows: <tt>ID & 0x3</tt> | ||
+ | * Buttons: <tt>(ID & 0x3) * 6</tt> | ||
+ | |||
+ | <u>Note</u>: Number of axis or number of button rows can be zero, but not both. So any device ID up to 0x3F is valid except 0x00. | ||
− | === Read bytes === | + | ==== Read bytes ==== |
Repeat this step for each axis (if any), then for each button row (if any). Number of axis and button rows is given by the device ID | Repeat this step for each axis (if any), then for each button row (if any). Number of axis and button rows is given by the device ID | ||
Revision as of 21:32, 3 November 2024
Contents
Protocol
Proposal for a protocol to handle joypads with a variable number of sticks and buttons, plug in the MSX’s general purpose port.
This protocol can manage joypads with up to 15 analog axis (one stick requires 2 axis) and 18 buttons.
Pin 8 is used to synchronize data transmission:
- Leaving Pin 8 LOW for long enough (>1 ms, about 3580 t-states) resets the joystick's internal counter,
- then successive pulses on Pin 8 (LOW > HIGH) are used for data transmission (6 bits per 6 bits).
States
Idle state (no-communication)
Write R#15
- Pin 8: LOW (for >1 ms)
- Reset internal data counter
Read R#14
- Get 0x0F (JSX idle fingerprint)
- Note: It could be any value between 00-3F not already return by other MSX devices)
Communication state
Write R#15
- Pin 8: LOW
Write R#15
- Pin 8: HIGH (request data)
Read R#14
- 6-bit data
Pin binding for received data:
Bits 7 6 5 4 3 2 1 0 –-–-–-–-–-–-–-–--–-–- Pins x x 7 6 4 3 2 1
Device ID
First received data is the JSX device ID:
7 6 5 4 3 2 1 0 –-–-–-–-–-–-–-–-- 0 0 A A A A B B │ │ │ │ └─┴── Number of button rows (0-3) │ │ │ │ 0: No button │ │ │ │ 1: Up to 6 buttons │ │ │ │ 2: Up to 12 buttons │ │ │ │ 3: Up to 18 buttons └─┴─┴─┴────── Number of axis (0-15)
Input number can be computed as:
- Axis: ID / 4
- Button rows: ID & 0x3
- Buttons: (ID & 0x3) * 6
Note: Number of axis or number of button rows can be zero, but not both. So any device ID up to 0x3F is valid except 0x00.
Read bytes
Repeat this step for each axis (if any), then for each button row (if any). Number of axis and button rows is given by the device ID
Write R#15
- Pin 6: any value
- Pin 7: any value
- Pin 8: LOW
- Pin 8 have to stay LOW for more than 1 ms for the first read, then less than 1 ms for the next ones
Write R#15
- Pin 6: HIGH
- Pin 7: LOW
- Pin 8: HIGH
Read R#14
- Get 6-bits values
- For axis: signed 6-bits value [-32 ; 31]
- For boutons: bits field for 6 boutons (0: pressed, 1: released)
Example
For a Joypad with a stick with X and Y axis (2 axis), and 4 buttons (1 row), the reading process would be:
- After starting communication, first read to R#14 return the ID.
ID: 0x09 [00 0010 01] for 2 axis, and 1 buttons row, - Next reading give X-axis value [-32 ; 31],
- Next reading give Y-axis value [-32 ; 31],
- Next and last reading give button states (for up to 6 boutons).
Note: MSX-HID fingerprint would be: 0Fh, 09h, 0Fh