The Ember PIA — Initial Design Part 1: Peripheral Interface Adapter
- Tom Gambill
- Mar 31
- 1 min read

Adding keyboard and gamepad support to the Ember design requires some sort of Peripheral Interface Adapter (PIA). This device will interact with keyboards over PS/2 or USB, and game controllers using USB or their native protocol, then map the various inputs and outputs into registers in shared memory, just like the Flame GPU registers.
Zero Page IO Registers
Like the GPU, the PIA is assigned a specific range of memory addresses in the Ember zero page. In this case, three 256-byte blocks are reserved for user input devices like a keyboard or gamepad. Starting at zero-page address 0x0700, the first 256-byte block contains the PIA control registers and input/output values for connected devices. The next two blocks at 0x0800 and 0x0900 are work RAM reserved for use by the system monitor/console and keyboard buffer. We will cover these in detail when we discuss the Ember firmware design and how system and application code interact with the PIA.
Interrupts
Input on any attached keyboard or control device can generate a CPU interrupt so that when a key or button is pressed or released, or a gamepad stick or trigger is adjusted, an interrupt is sent to the CPU, which is expected to handle reading the change in value and updating any read buffers in memory. Which actions trigger interrupts can be configured in the PIA flags, and either the OS or the application can be configured to handle these or choose to just poll the values directly from the registers.
Komentarze