|
Nugget
|
A low level driver for the PlayStation memory cards. More...
#include <psyqo/memory-card.hh>
Classes | |
| struct | ReadSectorAwaiter |
| struct | WriteSectorAwaiter |
Public Types | |
| enum class | Error : uint8_t { OK = 0 , NoCard , NotFormatted , BadChecksum , BadSector , Timeout , Unconnected , ProtocolError , DirectoryFull , OutOfSpace , FileNotFound , FileExists , NameTooLong , FileTooLarge , SerializeOverflow , BadData , BadPort } |
| The error codes returned by every memory card operation. More... | |
| enum class | Port : unsigned { Port0 = 0 , Port1 = 1 } |
| The memory card port to talk to. More... | |
Public Member Functions | |
| void | prepare () |
| Prepares the SIO0 bus for memory card access. | |
| Error | readSectorBlocking (Port port, uint16_t sector, void *buffer) |
| Reads a single 128-byte sector synchronously. | |
| Error | writeSectorBlocking (Port port, uint16_t sector, const void *buffer) |
| Writes a single 128-byte sector synchronously. | |
| Error | probeBlocking (Port port) |
| Probes the card for presence. | |
| void | readSector (Port port, uint16_t sector, void *buffer, eastl::function< void(Error)> &&callback) |
| void | writeSector (Port port, uint16_t sector, const void *buffer, eastl::function< void(Error)> &&callback) |
| TaskQueue::Task | scheduleReadSector (Port port, uint16_t sector, void *buffer, Error *resultOut) |
| TaskQueue::Task | scheduleWriteSector (Port port, uint16_t sector, const void *buffer, Error *resultOut) |
| ReadSectorAwaiter | readSector (Port port, uint16_t sector, void *buffer) |
| WriteSectorAwaiter | writeSector (Port port, uint16_t sector, const void *buffer) |
Static Public Member Functions | |
| static constexpr uint32_t | sectorSize () |
| static constexpr uint32_t | sectorCount () |
| static constexpr uint32_t | blockSize () |
| static constexpr uint32_t | blockCount () |
| static const char * | errorMessage (Error error) |
| Returns a human readable string for an error code. | |
Static Public Attributes | |
| static constexpr uint32_t | c_sectorSize = 128 |
| static constexpr uint32_t | c_sectorCount = 1024 |
| static constexpr uint32_t | c_blockSize = 8192 |
| static constexpr uint32_t | c_blockCount = 16 |
| static constexpr uint32_t | c_sectorsPerBlock = 64 |
A low level driver for the PlayStation memory cards.
This class drives the raw memory card protocol over the SIO0 serial bus, the same bus used by the controllers. It exposes the lowest useful unit of the card: the 128-byte sector (also called a "frame"). The card is 128KiB total, organized as 1024 sectors of 128 bytes, themselves grouped into 16 blocks of 64 sectors (8KiB each). Block 0 holds the directory; blocks 1..15 hold files.
This class is intentionally agnostic of the Sony on-card filesystem; see MemoryCardFileSystem for a Sony-compatible filesystem built on top of it. It supports both memory card ports.
Each sector transfer is a self-contained synchronous SIO0 exchange, the same proven approach AdvancedPad uses to talk to the bus. The Controller interrupt is masked for the duration of a transfer so that nothing else on the bus (a BIOS pad handler, for instance) steals the bytes, and its prior mask state is restored afterwards. As with the rest of psyqo, the class is meant to be used as a singleton, typically held by the Application.
Following the conventions of CDRomDevice, every operation comes in four forms: a callback variant, a *Blocking variant, a coroutine-friendly awaiter, and a TaskQueue::Task scheduler. A single sector transfer is short (a few milliseconds), so the blocking variants do not need a GPU to pump events.
|
strong |
The error codes returned by every memory card operation.
There are never any silent failures: every operation returns one of these, and errorMessage turns it into a human readable string.
| Enumerator | |
|---|---|
| OK | |
| NoCard | |
| NotFormatted | |
| BadChecksum | |
| BadSector | |
| Timeout | |
| Unconnected | |
| ProtocolError | |
| DirectoryFull | |
| OutOfSpace | |
| FileNotFound | |
| FileExists | |
| NameTooLong | |
| FileTooLarge | |
| SerializeOverflow | |
| BadData | |
| BadPort | |
|
strong |
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
|
static |
Returns a human readable string for an error code.
| void psyqo::MemoryCard::prepare | ( | ) |
Prepares the SIO0 bus for memory card access.
Should be called once from Application::prepare. It is safe to also use AdvancedPad / SimplePad alongside this; they share the bus and access is naturally serialized on the main thread.
| psyqo::MemoryCard::Error psyqo::MemoryCard::probeBlocking | ( | Port | port | ) |
Probes the card for presence.
|
inline |
| void psyqo::MemoryCard::readSector | ( | Port | port, |
| uint16_t | sector, | ||
| void * | buffer, | ||
| eastl::function< void(Error)> && | callback | ||
| ) |
| psyqo::MemoryCard::Error psyqo::MemoryCard::readSectorBlocking | ( | Port | port, |
| uint16_t | sector, | ||
| void * | buffer | ||
| ) |
Reads a single 128-byte sector synchronously.
| port | The port to read from. |
| sector | The sector index (0..1023). |
| buffer | A buffer of at least 128 bytes. |
| psyqo::TaskQueue::Task psyqo::MemoryCard::scheduleReadSector | ( | Port | port, |
| uint16_t | sector, | ||
| void * | buffer, | ||
| Error * | resultOut | ||
| ) |
| psyqo::TaskQueue::Task psyqo::MemoryCard::scheduleWriteSector | ( | Port | port, |
| uint16_t | sector, | ||
| const void * | buffer, | ||
| Error * | resultOut | ||
| ) |
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
|
inline |
| void psyqo::MemoryCard::writeSector | ( | Port | port, |
| uint16_t | sector, | ||
| const void * | buffer, | ||
| eastl::function< void(Error)> && | callback | ||
| ) |
| psyqo::MemoryCard::Error psyqo::MemoryCard::writeSectorBlocking | ( | Port | port, |
| uint16_t | sector, | ||
| const void * | buffer | ||
| ) |
Writes a single 128-byte sector synchronously.
| port | The port to write to. |
| sector | The sector index (0..1023). |
| buffer | A buffer of at least 128 bytes. |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |