Expand description
The console side of the pad engine: the serial port and a timer behind
Hw, the one global Engine, and the exception wrapper that feeds it.
Everything here is for the target. (It compiles on the host so the documentation shows it; none of it may run there.)
§Interrupt path
The wrapper sits in the general exception vector in front of whatever
handler was there when install ran (psx-rt’s, or a wrapper such as
psx-cdstream’s that leads to it). For an interrupt with VBlank, the
controller (IRQ7) or root counter 0 pending it saves the interrupted CPU
context, switches to a private stack, runs the engine’s events, restores
the context and jumps on to the next handler either way, so the VBlank
counter, the display flip and the fault handling run exactly as before.
The wrapper never touches the interrupted stack, which is what makes it
safe with a scratchpad stack; install declares it so.
§Foreground path
Every foreground call runs with CPU interrupts off for its few
instructions, so it never overlaps a handler. Reading a snapshot takes no
lock at all (snapshot).
§Memory cards
The engine owns the port token. A card driver borrows it as a Lease,
which keeps the engine off the port until it is dropped.
Structs§
- Lease
- The port, on loan from the engine: it derefs to the
ControllerPorta memory card or a diagnostic needs, and the engine polls nothing until it is dropped. VBlanks that pass meanwhile are not polled, so the snapshot stands still; keep a lease to one transaction. - Mmio
- The serial port and root counter 0, through the SDK’s register steps.
Constants§
- HANDLER_
STACK_ BYTES - Bytes of private stack the handler runs on.
Functions§
- analog_
outcome - What the pad settled on after
request_analog;Nonewhile pending. - configure
- Change the settings; they apply from the next transaction.
- disable_
rumble - Stop wanting the motors on
port. They are told to stop on the next poll. - enable_
rumble - Put the motors of the pad on
portunder the poll. The engine maps them (command 0x4D, in the same visit to configuration mode as an analog request if one is pending) whenever an analog DualShock is there and again each time one is plugged in, then sendsset_rumble’s request with every poll.rumble_mappedsays whether the pad took it. - handler_
stack_ unused_ bytes - Bytes of the handler’s private stack never touched since
installpainted it. - install
- Take over the controller port: put the exception wrapper in front of the handler the vector leads to and start polling on every VBlank.
- is_
installed - Whether
installhas run,uninstallhas not, and psx-rt’s handler has not been put back in the vector since (which drops the wrapper from the exception chain:falsethen, and the engine no longer runs). Otherwise the wrapper is in the chain, first in the vector or behind psx-cdstream’s, which chains to it. - lease
- Borrow the port. Waits for a transaction in flight (under two milliseconds on the wire); if the engine has not gone idle after a few VBlanks it abandons the transaction instead of waiting longer. A caller with CPU interrupts off cannot let the transaction finish, so it waits a fixed number of attempts instead and then takes the port.
- owner
- Who may use the port now.
- pad
- The latest clean state of
port. - reading
- The latest reading of
port: the pad’s state and whether the socket is present. - request_
analog - Ask for analog mode on
portand lock it there. SeeEngine::request_analog;analog_outcomeanswers a few frames later. - rumble_
mapped - Whether the pad on
porttook the motor mapping. - set_
rumble - What the motors on
portare asked to do on every poll. Takes effect on a pad that has been mapped; a digital pad ignores it. - snapshot
- The latest publication of both ports. A copy: no lock, no interrupt masking.
- stats
- A copy of the counters.
- stop_
motors - Stop every motor now and return once a poll with the motors off has gone
out on each port, so a program can pause, open a menu, or hand the port over
knowing nothing is still spinning. Waits as
leasedoes, three VBlanks at most; a port aLeaseholds is not polled meanwhile. An unplugged pad has nothing to stop. - try_
lease - Borrow the port if no transaction is on the wire right now.
- uninstall
- Give the port back to synchronous code. Waits for the transaction in
flight, as
leasedoes (and abandons it after the same patience), then closes the controller and counter 0 sources. The wrapper stays in the exception vector, chained, a few instructions per exception;installfinds it there and takes the port again.