Nugget
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
psyqo::MemoryCard Class Reference

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
 

Detailed Description

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.

Member Enumeration Documentation

◆ Error

enum class psyqo::MemoryCard::Error : uint8_t
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 

◆ Port

enum class psyqo::MemoryCard::Port : unsigned
strong

The memory card port to talk to.

Enumerator
Port0 
Port1 

Member Function Documentation

◆ blockCount()

static constexpr uint32_t psyqo::MemoryCard::blockCount ( )
inlinestaticconstexpr

◆ blockSize()

static constexpr uint32_t psyqo::MemoryCard::blockSize ( )
inlinestaticconstexpr

◆ errorMessage()

const char * psyqo::MemoryCard::errorMessage ( Error  error)
static

Returns a human readable string for an error code.

◆ prepare()

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.

◆ probeBlocking()

psyqo::MemoryCard::Error psyqo::MemoryCard::probeBlocking ( Port  port)

Probes the card for presence.

Returns
Error::OK if a card acknowledges on the given port, Error::NoCard otherwise.

◆ readSector() [1/2]

ReadSectorAwaiter psyqo::MemoryCard::readSector ( Port  port,
uint16_t  sector,
void buffer 
)
inline

◆ readSector() [2/2]

void psyqo::MemoryCard::readSector ( Port  port,
uint16_t  sector,
void buffer,
eastl::function< void(Error)> &&  callback 
)

◆ readSectorBlocking()

psyqo::MemoryCard::Error psyqo::MemoryCard::readSectorBlocking ( Port  port,
uint16_t  sector,
void buffer 
)

Reads a single 128-byte sector synchronously.

Parameters
portThe port to read from.
sectorThe sector index (0..1023).
bufferA buffer of at least 128 bytes.
Returns
Error::OK on success.

◆ scheduleReadSector()

psyqo::TaskQueue::Task psyqo::MemoryCard::scheduleReadSector ( Port  port,
uint16_t  sector,
void buffer,
Error resultOut 
)

◆ scheduleWriteSector()

psyqo::TaskQueue::Task psyqo::MemoryCard::scheduleWriteSector ( Port  port,
uint16_t  sector,
const void buffer,
Error resultOut 
)

◆ sectorCount()

static constexpr uint32_t psyqo::MemoryCard::sectorCount ( )
inlinestaticconstexpr

◆ sectorSize()

static constexpr uint32_t psyqo::MemoryCard::sectorSize ( )
inlinestaticconstexpr

◆ writeSector() [1/2]

WriteSectorAwaiter psyqo::MemoryCard::writeSector ( Port  port,
uint16_t  sector,
const void buffer 
)
inline

◆ writeSector() [2/2]

void psyqo::MemoryCard::writeSector ( Port  port,
uint16_t  sector,
const void buffer,
eastl::function< void(Error)> &&  callback 
)

◆ writeSectorBlocking()

psyqo::MemoryCard::Error psyqo::MemoryCard::writeSectorBlocking ( Port  port,
uint16_t  sector,
const void buffer 
)

Writes a single 128-byte sector synchronously.

Parameters
portThe port to write to.
sectorThe sector index (0..1023).
bufferA buffer of at least 128 bytes.
Returns
Error::OK on success.

Member Data Documentation

◆ c_blockCount

constexpr uint32_t psyqo::MemoryCard::c_blockCount = 16
staticconstexpr

◆ c_blockSize

constexpr uint32_t psyqo::MemoryCard::c_blockSize = 8192
staticconstexpr

◆ c_sectorCount

constexpr uint32_t psyqo::MemoryCard::c_sectorCount = 1024
staticconstexpr

◆ c_sectorSize

constexpr uint32_t psyqo::MemoryCard::c_sectorSize = 128
staticconstexpr

◆ c_sectorsPerBlock

constexpr uint32_t psyqo::MemoryCard::c_sectorsPerBlock = 64
staticconstexpr

The documentation for this class was generated from the following files: