Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Crate psx_mc

Crate psx_mc 

Source
Expand description

PlayStation 1 memory-card driver.

Three layers, each usable on its own:

  1. Transport – a Block device exposes the card as 1024 raw 128-byte frames. HardwareCard talks to a physical card over SIO0 (feature hw, on by default); RamCard is an in-memory image for host tests and virtual saves.
  2. Filesystem – Card wraps any Block and implements the standard PS1 directory: named files, block allocation with the real link-chain, BIOS-visible title + icon frames, and per-frame XOR checksums. Saves show up in the console’s memory-card manager like any retail game.
  3. Container – Card::write wraps payloads in a small self-describing header so Card::read can transparently handle both plain and (feature compress) LZSS-compressed saves.

§Why talk to SIO0 directly

Like psx_pad, this avoids BIOS syscalls so the same code runs under an HLE BIOS side-load or a real boot. The card protocol is a fixed request/response the hardware module drives byte by byte, over the same shared SIO0 transport the pad driver polls controllers with, so the port has one owner (the ControllerPort token) however many drivers use it.

§Example

use psx_mc::{Card, HardwareCard, Slot};

// `port` is the `ControllerPort` token (or a `&mut` of it, to keep polling
// pads between saves).
let mut card = Card::new(HardwareCard::on_port(&mut port, Slot::One));
if !card.is_formatted()? {
    card.format()?;
}
card.write("BESLES-00000MYGAME01", "MY GAME", &save_bytes)?;

let mut buf = [0u8; 8192];
let len = card.read("BESLES-00000MYGAME01", &mut buf)?;

All logic below the transport is pure and covered by host unit tests (cargo test --no-default-features, optionally --features compress).

Re-exports§

pub use hardware::HardwareCard;
pub use hardware::Slot;
pub use hardware::TransportFault;
pub use hardware::TransportTrace;

Modules§

compress
A small, self-contained LZSS codec for save payloads (feature compress).
hardware
On-device SIO0 transport for a physical memory card (feature hw).

Structs§

Card
A memory card with the standard PS1 filesystem on top of a Block device.
ControllerPort
The token a HardwareCard drives the port through. The controller and memory-card port.
Entry
One file as reported by Card::list.
RamCard
A 128 KiB card held entirely in memory.
SaveIcon
A native PS1 memory-card save icon.

Enums§

Error
Everything that can go wrong talking to a card or its filesystem.

Constants§

BLOCK_COUNT
Total blocks on a standard card (block 0 is the directory).
CARD_SIZE
Total card size in bytes (128 KiB).
DATA_BLOCKS
Usable save blocks (blocks 1..=15; block 0 holds the directory).
FRAMES_PER_BLOCK
Frames per 8 KiB block.
FRAME_COUNT
Total frames on a standard card.
FRAME_SIZE
Bytes per frame (the transfer unit of the serial protocol).
MAX_NAMEDeprecated
Renamed to MAX_NAME_LEN.
MAX_NAME_LEN
Maximum file-name length (region+product code + name), excluding the NUL.

Traits§

Block
A card as a flat array of FRAME_COUNT 128-byte frames.

Type Aliases§

Result
Convenience alias.