Wondercard  v0.2.1
A fully virtual emulation of the protocol used by Memory Cards for the PlayStation.
Classes | Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
com::saxbophone::wondercard::MemoryCard Class Reference

Represents a virtual PS1 Memory Card. More...

#include <MemoryCard.hpp>

Collaboration diagram for com::saxbophone::wondercard::MemoryCard:
Collaboration graph
[legend]

Public Types

typedef std::span< Byte, BLOCK_SIZEBlock
 A non-owning view of an entire save Block on the MemoryCard.
 
typedef std::span< Byte, SECTOR_SIZESector
 A non-owning view of a Sector on the MemoryCard.
 

Public Member Functions

 MemoryCard ()
 Initialises card data to all zeroes. More...
 
 MemoryCard (std::span< Byte, MemoryCard::CARD_SIZE > data)
 Populates card data with that of the supplied span. More...
 
bool power_on ()
 Simulates powering up the card, e.g. when inserted into slot. More...
 
bool power_off ()
 Simulates powering down the card, e.g. when removed from slot. More...
 
bool send (TriState command, TriState &data)
 Attempts to send a command and receive data from the card. More...
 
Block get_block (std::size_t index)
 
Sector get_sector (std::size_t index)
 

Public Attributes

const bool & powered_on
 Read-only flag indicating whether the card is powered on or not.
 
std::span< Byte, CARD_SIZEbytes
 writable accessor for the MemoryCard data bytes
 

Static Public Attributes

static constexpr std::size_t CARD_BLOCK_COUNT = 16u
 
static constexpr std::size_t BLOCK_SECTOR_COUNT = 64u
 
static constexpr std::size_t SECTOR_SIZE = 128u
 
static constexpr std::size_t BLOCK_SIZE = BLOCK_SECTOR_COUNT * SECTOR_SIZE
 
static constexpr std::size_t CARD_SIZE = CARD_BLOCK_COUNT * BLOCK_SIZE
 

Detailed Description

Represents a virtual PS1 Memory Card.

Constructor & Destructor Documentation

◆ MemoryCard() [1/2]

com::saxbophone::wondercard::MemoryCard::MemoryCard ( )

Initialises card data to all zeroes.

Warning
Default card data may change in future versions of the software

◆ MemoryCard() [2/2]

com::saxbophone::wondercard::MemoryCard::MemoryCard ( std::span< Byte, MemoryCard::CARD_SIZE data)

Populates card data with that of the supplied span.

Parameters
dataThe data to initialise the card data with

Member Function Documentation

◆ get_block()

MemoryCard::Block com::saxbophone::wondercard::MemoryCard::get_block ( std::size_t  index)
Returns
The Block on this MemoryCard with the given index
Parameters
indexThe index of the Block to retrieve ({0..15})
Warning
index is not currently validated

References BLOCK_SIZE.

◆ get_sector()

MemoryCard::Sector com::saxbophone::wondercard::MemoryCard::get_sector ( std::size_t  index)
Returns
The Sector on this MemoryCard with the given index
Parameters
indexThe index of the Sector to retrieve ({0..1023})
Warning
index is not currently validated

References SECTOR_SIZE.

◆ power_off()

bool com::saxbophone::wondercard::MemoryCard::power_off ( )

Simulates powering down the card, e.g. when removed from slot.

Cards know when they have been re-inserted, so they have some way of tracking when they are plugged in and out, presumably this must be done by tracking when the card is powered on and off.

Returns
false if card is already powered down.
true if card has been powered off by the method call.

Referenced by com::saxbophone::wondercard::MemoryCardSlot::remove_card().

Here is the caller graph for this function:

◆ power_on()

bool com::saxbophone::wondercard::MemoryCard::power_on ( )

Simulates powering up the card, e.g. when inserted into slot.

Cards know when they have been re-inserted, so they have some way of tracking when they are plugged in and out, presumably this must be done by tracking when the card is powered on and off.

Returns
false if card is already powered on.
true if card has been powered on by the method call.

References powered_on.

Referenced by com::saxbophone::wondercard::MemoryCardSlot::insert_card().

Here is the caller graph for this function:

◆ send()

bool com::saxbophone::wondercard::MemoryCard::send ( TriState  command,
TriState data 
)

Attempts to send a command and receive data from the card.

Parameters
commandCommand to send to the card (set empty for High Impedance/Z-state, indicating don't care)
dataDestination to store response data from card in (set empty for High Impedance/Z-state, indicating no data)
Returns
true if the card responds with an ACK
false if we time out waiting for an ACK from the card

References powered_on.

Member Data Documentation

◆ BLOCK_SECTOR_COUNT

constexpr std::size_t com::saxbophone::wondercard::MemoryCard::BLOCK_SECTOR_COUNT = 64u
staticconstexpr

Number of Sectors in a Block

◆ BLOCK_SIZE

constexpr std::size_t com::saxbophone::wondercard::MemoryCard::BLOCK_SIZE = BLOCK_SECTOR_COUNT * SECTOR_SIZE
staticconstexpr

Number of bytes in a Block

Referenced by get_block().

◆ CARD_BLOCK_COUNT

constexpr std::size_t com::saxbophone::wondercard::MemoryCard::CARD_BLOCK_COUNT = 16u
staticconstexpr

Number of Blocks on the card

◆ CARD_SIZE

constexpr std::size_t com::saxbophone::wondercard::MemoryCard::CARD_SIZE = CARD_BLOCK_COUNT * BLOCK_SIZE
staticconstexpr

Number of bytes in a MemoryCard

◆ SECTOR_SIZE

constexpr std::size_t com::saxbophone::wondercard::MemoryCard::SECTOR_SIZE = 128u
staticconstexpr

Number of bytes in a Sector

Referenced by get_sector().


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