Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Module engine

Module engine 

Source
Expand description

The interrupt-driven pad engine: its state machine, with no hardware in it.

The synchronous driver in the crate root spends the CPU’s time waiting. A poll holds a setup delay of 1,024 status reads after raising /CS, then spins on /ACK after every byte, and a socket with nothing in it spends the whole delay and the whole /ACK budget to learn that. This engine never waits. A frame’s VBlank starts one transaction per port; every step after that is an interrupt, and between interrupts the CPU runs the game.

  VBlank ──► select port ──► arm timer(setup)
  timer  ──► transmit byte 0 ──► arm timer(ack budget)
  IRQ7   ──► read reply, clear latch, transmit next byte ──► arm timer
  ...        (the last byte has no ACK: the timer ends it)
  done   ──► deselect, publish a snapshot, start the next port

What stops a byte that never comes is the timer, not a loop: an absent pad answers 0xFF and never pulses /ACK, so the first byte’s budget runs out and the port reads as absent. That costs wall time on the wire (a fraction of a millisecond) and almost nothing on the CPU, and a pad plugged in later is found by the next VBlank’s transaction.

The game reads a Snapshot (a sequence number and, per port, the last clean PadState and whether the port is present) without disturbing the engine: Published::read is a copy.

This module is the policy, generic over Hw so the host tests drive it against a controller model with real timing; the console side (the exception wrapper, the timer, the registers) is in console.rs. sdk/docs/PAD-IRQ-ENGINE.md is the design.

Structs§

Config
The engine’s settings.
Engine
The state machine. One per console, driven by three events: a VBlank (on_vblank), a device’s /ACK (on_ack) and the deadline timer (on_deadline). The three run with CPU interrupts off. Everything else is for the foreground, which must not overlap them.
PortReading
One port, as the game sees it.
Published
Where the engine publishes: two buffers and a sequence number, so a reader in the foreground gets a consistent copy while the interrupt handler publishes, with no lock and no interrupt masking.
Snapshot
Both ports at one instant, with the sequence number of the publication.
Stats
Counters, for tools and for tests.

Enums§

BytePacing
How the engine decides a byte is done and the next may go.
Fault
Why a transaction failed.
Health
What the engine last learned about a port.
Owner
Who may use the serial port.

Traits§

Hw
What the engine needs from the console: the serial port, and one timer that raises an interrupt after a number of CPU cycles.