Touchpad
This page was last modified 08:16, 27 March 2017 by Rderooy. Based on work by Sd snatcher and Mars2000you and others.

The MSX-touchpad is a kind of Graphic Tablet supported by the MSX standard since its inception. It features the same kind of resistive touchscreen technology that was used on PDAs not so long ago.


Contents

MSX-BIOS programmer interface

It's easy to read the touchpad using the MSX-BIOS. The programmer just need to use the following functions:

  • GTPAD (00DBh)
    • Function 0 = Fetch the touchpad data from joystick port 1. Return FFh if valid data was read, and 0 otherwise
    • Function 1 = Get touchpad absolute X coordinate
    • Function 2 = Get touchpad absolute Y coordinate
    • Function 3 = Get touchpad button status. FF=pressed, 0=not pressed.
    • Function 4 = Fetch the touchpad data from joystick port 2. Return FFh if valid data was read, and 0 otherwise
    • Function 5 = Get touchpad absolute X coordinate
    • Function 6 = Get touchpad absolute Y coordinate
    • Function 7 = Get touchpad button status. FF=pressed, 0=not pressed.
  • System variables
    • PADY (MSX: FC9Ch, SVI: FE2Dh): Y coordinate fetched from the touchpad
    • PADX (MSX: FC9Dh. SVI: FE2Ch): X coordinate fetched from the touchpad

Notes:

  • The BIOS will detect if a touchpad is connected to the selected joystick port.
  • Since functions 1 & 5 and functions 2 & 6 share the same coordinates cache in RAM (aka PADX and PADY) respectively, you must read the two coordinates of a touchpad before fetching the coordinates of the next touchpad, otherwise they'll be overwritten.

User interface design considerations

As you can notice from above, the light pen works just like the touchpad, and applications should be interchangeable between the two. The only subtle differences that applications developers should take into account are:

  1. While the light pen works over the real screen, the touchpad is a "blind" device. Thus, the light pen will not require any kind of "mouse pointer" , while the touchpad will require one.
  2. The light pen is designed to force the user to click the button to get a reading, while on the touchpad the user get a reading simply by touching the pad and the button can be pressed independently. On the light pen, to click the button without touching the screen the user must literally do that: click the light pen outside of the CRT glass area.

Underlying hardware

User software programmers *must* read the touchpad only by using the BIOS GTPAD call as described in the beginning of the article. The low-level implementation details listed bellow are explained just to provide information for hardware designers, emulator programmers and the programmers of the C-BIOS.

Low-level protocol

The interface between the resistive touchscreen and the MSX is done by a NEC uPD7001 chip. It's a 4 channel 8-bit serial ADC, that is connected to the MSX joyport using the following pinout. As the protocol is serial and very similar to SPI, bit-banging on the PSG joyports is used to communicate with the chip.

Pinout

The touchpad is connected to the standard MSX joystick port (DB9 connector), using the following pinout.

Pin Signal Description Direction (from touchpad) (SVI-328 pin)
1 /SENSE Touch sense signal (0 when the screen is touched) Output 5
2 EOC A/D conversion end (inverted uPD7001 /EOC signal) Output 9
3 SO uPD7001 Serial data output Output 6
4 /SW Button (0=pressed) Output N/A
5 +5V Vcc Input 7
6 /SCK uPD7001 serial clock signal Input 1
7 SI uPD7001 serial data input Input 2
8 /CS uPD7001 Chip-select Input 3
9 GND Ground Input 8

The uPD7001 channels

 channel-0: X position
 channel-1: Reserved for future use (always read 0)
 channel-2: Reserved for future use (always read 0)
 channel-3: Y position

Reading the uPD7001

Technical details

  • Bytes written to the uPD7001 via SPI will make it select which channel that will de A/D converted and read in the next time.
  • Bytes are read via SPI with data from channel selected in the last A/D conversion
  • All data is transmitted/received MSB first.
  • The first byte read from the uPD7001 after power-on is random.
  • EOC is a ready flag. If EOC=0 then the DAC is still busy.
  • /SENSE is a bit cryptic. It's produced by a secondary circuit and not the uPD7001. The sense result is latched by the falling edge of /CS, but it seems it first must be initialized each time by setting SI=0 and sending a pulse on /CS

Algorithm

  1. Read Y
    1. Set /CS=1 and SI=0
    2. Wait for EOC=1
    3. Set /CS=0
    4. Wait at least 12.5uS
    5. Set /SCK=0
    6. Read 1 bit of X position from SO
    7. Set /SCK=1
    8. Repeat steps 1.5~1.7 eight times to both receive the Y coordinate and transmit new channel selector to the uPD7001
  2. Read X
    1. Set /CS=1 and SI=1
    2. Wait for EOC=1
    3. Wait at least 31.2uS
    4. Set /CS=0
    5. Read the /SENSE status
    6. Wait at least 12.5uS
    7. Set /SCK=0
    8. Read 1 bit of Y position from SO
    9. Set /SCK=1
    10. Repeat steps 2.7~2.9 eight times to both receive the X coordinate and transmit new channel selector to the uPD7001
    11. The coordinates will only be valid if /SENSE was 0 on step-5
  3. Check for glitches
    1. The two coordinates must be read twice sequentially
    2. If the two reads have a greater variation than -3 to +3, there was a glitch in the A/D conversion: the values must be discarded and the /SENSE status must then reported as disabled.

This algorithm optimizes the tricky /SENSE enable/latch pulses of /CS+SI by embedding them in the pulses required by the uPD7001. This saves a lot of time if compared to a stand alone /SENSE checking at the beginning.

Devices that have been build based on this standard

(*) internally connected to joyport 1.

Software that supports the touchpad natively