Gamepad

Inputs

PinTypeDescription
DevAddrbus8Device address — 0x1E for port 0xFE
IO_SELbitI/O select — must be 1 to read the gamepad

Outputs

PinTypeDescription
Databus8Button mask — bitfield: Up=1, Down=2, Left=4, Right=8

How It Works

The Gamepad element reads button presses and returns a bitmask on the Data output. The element itself contains four clickable buttons (Up, Down, Left, Right) that the user can press during simulation.

Bitmask format:

ButtonBitValue
Up01
Down12
Left24
Right38

Multiple buttons can be pressed simultaneously — values are combined with bitwise OR. For example, Up+Right = 1 + 8 = 9. When no buttons are pressed, the output is 0.

Reading is performed through port 0xFE: set IO_SEL = 1 and DevAddr = 0x1E, then read the Data bus. You can use LDA 254 (address 0xFE → 254 decimal) in your assembly program to read the gamepad state into the accumulator.

Usage

The Gamepad is used in the following levels:

To use the gamepad in your circuit, connect it to the I/O subsystem and poll port 0xFE periodically. In assembly:

; Read gamepad into accumulator
LDA 254    ; Read port 0xFE
; Check if Up is pressed (bit 0)
AND 1      ; AND with mask 0x01
JZ  not_up ; Jump if Up not pressed
; ... handle Up ...
Go to the simulator →