psx.wiki

Controller

Input devices on the two controller ports and how software reads them.

Overview

The controller is the interface that passes a player's intentions to the application. The main unit has two controller connectors. A Multi tap connects more controllers to one of them.1 Each controller port is wired in parallel with the Memory Card slot above it, and both are reached through the serial interface SIO0. The console selects one device on the shared lines by the first byte of each transfer, so a controller and a Memory Card in the same port never answer together.2 The byte-level exchange is described on the protocol page, and the SIO page describes the registers.

The kernel normally reads the controllers once per frame. The libpad state returned by PadGetState() changes only during the vertical retrace interval, so a program needs to poll it only once per frame.3 However, during streaming and other intensive interrupts the transfer may not take place in every Vsync. PadChkVsync() reports whether a transfer took place in the current frame, and a program that sends data to the controller only in particular frames must check it.4

Connector

The controller port and the Memory Card slot use the same signals:5

Table 1: Controller port and Memory Card slot pins
Pin Direction Name SIO0 pin Description
1 In DAT RX Serial data from the device
2 Out CMD TX Serial data to the device
3 +7.5V Supply for the vibration motors
4 GND Ground
5 +3.5V Supply for the logic
6 Out /CSn DTRn Port select
7 Out SCK SCK Serial data clock
8 In /IRQ /IRQ10 Lightgun interrupt (controller port only)
9 In /ACK DSR Data acknowledge

/CS is the only signal that differs between port 1 and port 2. The other signals are shared by both controller ports and both Memory Card slots, and the Memory Card slots lack the /IRQ pin and the shield.5 Because the data line is shared, it can be pulled low for a moment while a device is plugged or unplugged. A controller inserted in port 1 can therefore corrupt a Memory Card access in port 2.2

Controller Types

Sony's controller library identifies a controller by its terminal type, which is the upper four bits of the ID byte. The lower four bits are half the number of data bytes that the controller returns:6

Table 2: Terminal types
Terminal Type Controller Name Model Number psx-spx ID
1 Mouse SCPH-1030 5A12h
2 16-button analog SLPH-00001 (Namco Ltd) 5A23h
3 Gun controller SLPH-00014 (Konami Ltd) 5A31h
4 16-button SCPH-1080, 1150, 1200 5A41h
5 Analog joystick SCPH-1110 5A53h
6 Gun controller SLPH-00034 (Namco Ltd) 5A63h
7 Analog Controller SCPH-1150, 1200 5A73h
8 Multi Tap SCPH-1070 5A80h

The psx-spx ID column is the full 16-bit value returned by the controller. Its low byte is Sony's ID byte, and its high byte is always 5Ah.7 The 16-button analog controller of terminal type 2 is the Namco neGcon, model SLPH-00001.6 8

An analog controller starts in digital mode with its analog inputs disabled, and it then returns the same ID as a digital controller. psx-spx therefore reports that software normally tells the two apart by sending a command that only the analog controllers accept. Command 43h is the usual choice.9

Receive Buffer

libpad stores each controller transfer in a receive buffer. Offset 0 is 00h on success and another value on failure, offset 1 is the ID byte, and the data follows from offset 2:6

Table 3: Analog Controller receive data
Offset Contents
0 0x00 = successful, other values = failure
1 Upper four bits 0x7, lower four bits (byte count of received data) / 2
2, 3 Button state (1 = released, 0 = pressed)
4 Position along the X axis (right stick), 0 to 128 to 255
5 Position along the Y axis (right stick), 0 to 128 to 255
6 Position along the X axis (left stick), 0 to 128 to 255
7 Position along the Y axis (left stick), 0 to 128 to 255

The mouse returns its X and Y displacement as -128 to 127 at offsets 4 and 5. The 16-button analog controller returns its rotation at offset 4 and its I, II and L buttons as 0 to 255 at offsets 5 to 7. The Namco gun returns its X and Y position as two 16-bit values at offsets 4 to 7.6 10

Sony numbers the button state bits D15 to D0 with the byte at offset 2 as the upper byte:11

Table 4: Button state bit assignments
Bit 16-button Analog Controller 16-button analog Mouse
D15 Left Left Left
D14 Down Down Down
D13 Right Right Right
D12 Up Up Up
D11 Start Start Start
D10 R3
D9 L3
D8 Select Select
D7 Square Square
D6 Cross Cross
D5 Circle Circle A
D4 Triangle Triangle B
D3 R1 R1 R Left
D2 L1 L1 Right
D1 R2 R2
D0 L2 L2

The symbols for the four direction keys and the four face buttons did not survive in Sony's text; the names in the table for D4 to D7 and D12 to D15 follow the psx-spx bit order. psx-spx numbers the same buttons from bit 0 in transfer order, so its bit 0 (Select) is Sony's D8 and its bit 8 (L2) is Sony's D0.11 12 For the Konami gun Sony gives the bits per byte instead: the start button is bit 3 of the first byte, and the trigger and the button are bits 7 and 6 of the second byte.13

Analog Controller

When the stick of an Analog Controller is released it returns toward the center, but it may stop off center. A program that detects release from the stick position must allow for this error. For the SCPH-1200 the guaranteed range of the released stick is 80h +/- 25h.14

psx-spx gives measured ranges for three pads. The SCPH-1150 reached 00h to FFh at 25 degrees C, while the SCPH-1200 reached 0Eh to EDh and the SCPH-110 11h to FDh at 16 degrees C. The resting center of each pad also varied over a range of values, and other pads and temperatures give other results.15

The analog sticks move in a circular field, so most pads reach the minimum and maximum values only along the horizontal and vertical axes and not on the diagonals.9

Vibration

The DUAL SHOCK controllers have actuators (vibrators). libpad can query the number of actuators, their functions and their current drain, set the data list that controls them, and select the terminal type and lock the mode switch from the program.6

The number of actuators that can run at once is limited by the current that the PlayStation can supply. The total current drain of all running actuators must not exceed 60 units:14

Table 5: Actuator current drain
Model Actuator type Current drain
SCPH-1150 Actuator 1 10 units
SCPH-1200 Actuator 1 10 units
SCPH-1200 Actuator 2 20 units

The limit applies only when a Multi Tap is used. When a request would pass 60 units, a limiter in libpad keeps that actuator stopped. The actuators are counted in order of port number and then actuator number, so a later request that still fits is granted even when an earlier one was refused.14 4 Actuator 2 is on for any value other than 0x00.14

The protocol page describes how the motors are controlled at the byte level.

Multi Tap

The Multi Tap SCPH-1070 connects four controllers and four Memory Cards to one port. With one Multi Tap in each port, eight controllers and eight cards can be used.16 17

Communication through the Multi Tap requires at least one controller connected to it, and otherwise a communication error occurs. Software that does not use libtap communicates only with port A of the Multi Tap. The data then passes through as if that controller were connected to the PlayStation directly.16 The Multi Tap and the controllers on it may be inserted and removed during operation.16

A program reads all four controllers in one transfer, which libtap stores as follows:16

Table 6: Multi Tap receiving packet format
Byte Content
0 Result of receiving
1 ID (0x80)
2 Controller A result
3 Controller A ID
4 to 9 Controller A data
10 Controller B result
11 Controller B ID
12 to 17 Controller B data
18 Controller C result
19 Controller C ID
20 to 25 Controller C data
26 Controller D result
27 Controller D ID
28 to 33 Controller D data

When the Multi Tap is not in port A it is sometimes not recognized.18 psx-spx lists games that nevertheless require the Multi Tap in port 2. Bomberman and S.C.A.R.S. are two of them.19

Lightguns

The Konami gun (terminal type 3) signals the moment the beam passes through the /IRQ pin of the controller port, and libgun reads a counter value at that interrupt. The Namco gun (terminal type 6) returns its coordinates in the normal controller data and needs no interrupt.11 5

The horizontal value of a type 3 gun is a count of system clock cycles. The count is cleared at each horizontal blank, so a program converts it to a pixel position as Coefficient x count + Offset with the coefficient for its screen mode:16

Table 7: System clock to pixel clock conversion
Mode Horizontal resolution Coefficient
NTSC 256 0.158532
NTSC 320 0.198166
NTSC 384 0.226475
NTSC 512 0.317065
NTSC 640 0.396332
PAL 256 0.157086
PAL 320 0.196358
PAL 384 0.224409
PAL 512 0.314173
PAL 640 0.392717

From Run-Time Library 4.0 libgun blocks DMA and all other interrupt processing inside the gun interrupt to improve accuracy. The overhead therefore grows in units of the horizontal sync period as the number of interrupts rises. For this reason Sony recommends setting the number of interrupts small.13

Library Initialization

libpad is initialized in the following order:3

  1. Initialize the controller environment with PadInitDirect() or PadInitMtap().
  2. Set up the receive buffer with PadSetAct().
  3. Begin communication with PadStartCom().
  4. For a DUAL SHOCK, set the transmit sequence for the actuator data with PadSetActAlign() once the connection is established.

When the Memory Card is also used, it is initialized first with InitCARD(0) or MemCardInit(0), and the controller library is initialized after it.14 libpad keeps the connection state itself, so a parent and a child process that both use the controller must each call PadInitDirect() or PadInitMtap().4

References


  1. ^ Sony Computer Entertainment Inc. PlayStation Hardware. August 1998. Page 1-5.

  2. ^ a b psx-spx. Controllers and Memory Cards, Controller and Memory Card Overview. https://psx-spx.consoledev.net/controllersandmemorycards/

  3. ^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-17.

  4. ^ a b c Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-19, Table 13-19.

  5. ^ a b c psx-spx. Pinouts, Controller Ports and Memory-Card Ports. https://psx-spx.consoledev.net/pinouts/

  6. ^ a b c d e Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-10, Table 13-3, Table 13-4.

  7. ^ psx-spx. Controllers and Memory Cards, Controller ID (Halfword Number 0). https://psx-spx.consoledev.net/controllersandmemorycards/

  8. ^ psx-spx. Controllers and Memory Cards, neGcon Racing Controller. https://psx-spx.consoledev.net/controllersandmemorycards/

  9. ^ a b psx-spx. Controllers and Memory Cards, Analog Mode Note. https://psx-spx.consoledev.net/controllersandmemorycards/

  10. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Pages 13-11 and 13-12, Tables 13-5 to 13-9.

  11. ^ a b c Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-13, Table 13-11, Table 13-12.

  12. ^ psx-spx. Controllers and Memory Cards, Standard Controllers. https://psx-spx.consoledev.net/controllersandmemorycards/

  13. ^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-16.

  14. ^ a b c d e Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-18.

  15. ^ psx-spx. Controllers and Memory Cards, Analog Joypad Range. https://psx-spx.consoledev.net/controllersandmemorycards/

  16. ^ a b c d e Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-14, Table 13-13, Table 13-14.

  17. ^ psx-spx. Controllers and Memory Cards, SCPH-1070 (Multitap). https://psx-spx.consoledev.net/controllersandmemorycards/

  18. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 13-15.

  19. ^ psx-spx. Controllers and Memory Cards, Multitap Games. https://psx-spx.consoledev.net/controllersandmemorycards/

Categories: Hardware