Gamepad
Inputs
| Pin | Type | Description |
|---|---|---|
| DevAddr | bus8 | Device address — 0x1E for port 0xFE |
| IO_SEL | bit | I/O select — must be 1 to read the gamepad |
Outputs
| Pin | Type | Description |
|---|---|---|
| Data | bus8 | Button 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:
| Button | Bit | Value |
|---|---|---|
| Up | 0 | 1 |
| Down | 1 | 2 |
| Left | 2 | 4 |
| Right | 3 | 8 |
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:
- Level 23: read button input to move a value.
- Level 28: control the moving dot with arrow buttons.
- Level 29: Snake game — read directional input to control the snake's movement.
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 ...