Wondercard  v0.2.1
A fully virtual emulation of the protocol used by Memory Cards for the PlayStation.
MemoryCardSlot.hpp
Go to the documentation of this file.
1 
18 #ifndef COM_SAXBOPHONE_WONDERCARD_MEMORY_CARD_SLOT_HPP
19 #define COM_SAXBOPHONE_WONDERCARD_MEMORY_CARD_SLOT_HPP
20 
21 #include <optional>
22 #include <span>
23 
24 #include <cstddef>
25 #include <cstdint>
26 
27 #include <wondercard/common.hpp>
29 
30 
37  public:
39 
47  bool send(
48  TriState command,
49  TriState& data
50  );
51 
58  bool insert_card(MemoryCard& card);
59 
65  bool remove_card();
66 
73  bool read_card(std::span<Byte, MemoryCard::CARD_SIZE> data);
74 
80  bool write_card(std::span<Byte, MemoryCard::CARD_SIZE> data);
81 
90  bool read_block(std::size_t index, MemoryCard::Block data);
91 
99  bool write_block(std::size_t index, MemoryCard::Block data);
100 
109  bool read_sector(std::size_t index, MemoryCard::Sector data);
110 
118  bool write_sector(std::size_t index, MemoryCard::Sector data);
119 
120  private:
121  template <std::size_t sector_index>
122  bool _read_block_sector(std::size_t block_sector, MemoryCard::Block data);
123 
124  template <std::size_t sector_index>
125  bool _write_block_sector(std::size_t block_sector, MemoryCard::Block data);
126 
127  template <std::size_t block_index>
128  bool _read_card_block(std::span<Byte, MemoryCard::CARD_SIZE> data);
129 
130  template <std::size_t block_index>
131  bool _write_card_block(std::span<Byte, MemoryCard::CARD_SIZE> data);
132 
133  MemoryCard* _inserted_card;
134  };
135 }
136 
137 #endif // include guard
A MemoryCardSlot is a device which a MemoryCard can be inserted into and read/written from.
Definition: MemoryCardSlot.hpp:36
bool write_sector(std::size_t index, MemoryCard::Sector data)
Writes data from the given span to the specified sector of the inserted card.
Definition: MemoryCardSlot.cpp:164
bool write_block(std::size_t index, MemoryCard::Block data)
Writes data from the given span to the specified block of the inserted card.
Definition: MemoryCardSlot.cpp:94
bool read_sector(std::size_t index, MemoryCard::Sector data)
Reads the specified sector of the inserted card.
Definition: MemoryCardSlot.cpp:106
bool read_card(std::span< Byte, MemoryCard::CARD_SIZE > data)
Reads the entire contents of the inserted card.
Definition: MemoryCardSlot.cpp:64
bool write_card(std::span< Byte, MemoryCard::CARD_SIZE > data)
Writes data from the given span to the entire card.
Definition: MemoryCardSlot.cpp:73
bool send(TriState command, TriState &data)
Sends the given command byte to the inserted MemoryCard.
Definition: MemoryCardSlot.cpp:25
bool read_block(std::size_t index, MemoryCard::Block data)
Reads the specified block of the inserted card.
Definition: MemoryCardSlot.cpp:82
bool remove_card()
Attempts to remove a MemoryCard from this MemoryCardSlot.
Definition: MemoryCardSlot.cpp:52
bool insert_card(MemoryCard &card)
Attempts to insert the given MemoryCard into this MemoryCardSlot.
Definition: MemoryCardSlot.cpp:37
Represents a virtual PS1 Memory Card.
Definition: MemoryCard.hpp:35
std::span< Byte, BLOCK_SIZE > Block
A non-owning view of an entire save Block on the MemoryCard.
Definition: MemoryCard.hpp:46
std::span< Byte, SECTOR_SIZE > Sector
A non-owning view of a Sector on the MemoryCard.
Definition: MemoryCard.hpp:51
Definition: common.hpp:26
std::optional< Byte > TriState
Definition: common.hpp:28