CONTROLLER SETUP

CONTROLLER_SETUP ($C004D4): sets up controllers
Warning: register contents aren't preserved! Used registers varies.

Detects controllers configuration and sets inputs status byte accordingly.

Range of supported devices and detection method varies depending on system type and System ROM revision.

Status bytes
Status byte is the first byte of the input register into BIOS RAM (ex. for P1). It is used by SYSTEM_IO to correctly read devices.

Possible values are:


 * 0 - No connection (dealt as standard controller)
 * 1 - Standard controller
 * 2 - Expanded controller (4P mode)
 * 3 - Mahjong controller
 * 4 - Keyboard

MVS
MVS setup is very straightforward: if hard dip 3 is set, BIOS_P1STATUS is set to 3, else status byte is set to 0 for all players.

NEO•GEO / NEO•GEO CD
NEO•GEO controller setup is much more elaborate, looking for 6 different devices. (standard controller, mahjong, 4P adapter, keyboard, plus 2 unknown devices)

The bios writes various configurations on controller outputs, then checks back controller status (for example a standard controller returns button D pressed when OUT3 is set to 1). Checked button can be either D/C/Select/Start.

Resulting status bytes are stored into a preset table: (neo-epo bios) C16A44: 02 02 00 00, 00 02 00 00, 02 00 00 00, 00 00 00 00 C16A54: 00 00 00 00, 01 00 01 00, 00 01 00 01, 01 01 01 01 C16A64: 03 03 00 00, 00 03 00 00, 03 00 00 00, 00 00 00 00 C16A74: 01 01 03 03, 01 01 01 03, 01 01 03 01, 01 01 01 01 C16A84: 03 03 00 00, 00 03 00 00, 03 00 00 00, 00 00 00 00 C16A94: 04 04 00 00, 00 04 00 00, 04 00 00 00, 00 00 00 00

Software runs 6 consecutive checks. All of then are done, regardless if a previous device does match or not, however a status byte isn't overwritten if not 0.

This means 1st check has top priority, 6th has lowest.

Output status, checked button and resulting status bytes (P1-4) are:
 * All status bytes are decreased between 4th & 5th step.
 * Keep in mind there's an inverter between outputs and controller ports, writing 101 in the output register actually outputs 010 on the port.