Files
dusk/src/duskdolphin/save/savedeviceplatform.h
T
YourWishes 82ae2bce9d Add compressed combined save format for PSP and Dolphin
Memory sticks/cards don't suit N+1 separate save files the way Linux's
filesystem does, so add an opt-in SAVE_DEVICE_DATA_RAW mode: settings and
all save slots get serialized to JSON, concatenated, zlib-compressed, and
framed with a magic/version/checksum/generation header, then read/written
as a single blob through one combined platform hook instead of four.

- PSP and Dolphin's SD/NAND backends write via a temp file + atomic rename,
  so a crash mid-write can never leave a half-written save behind.
- GameCube memory cards have no rename or resize primitive, so they
  ping-pong between two fixed files instead, picking whichever is valid and
  has the higher generation counter on load.
- Linux is untouched (still four separate JSON files); saveslot.h/
  savesettings.h drop their now-unnecessary pack(1) now that nothing
  persists them as raw bytes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-17 21:28:56 -05:00

65 lines
2.9 KiB
C

/**
* Copyright (c) 2026 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
// GameCube only ever has the CARD_SLOTA/CARD_SLOTB memory card devices.
// Wii additionally picks between three storage methods, selected by
// DUSK_SAVE_WII_METHOD in cmake/targets/wii.cmake:
// - NAND (default): real internal storage via ISFS, see
// savedevicedolphinnand.h for the caveats around this.
// - CARD: reuses the exact same GameCube memory card code, since libogc's
// CARD API transparently redirects to Wii's NAND-based GameCube memory
// card emulation.
// - SD: the SD card via libfat, same mechanism this project already uses
// for Dolphin/Wii asset loading (see assetdolphinfat.c).
#if defined(DUSK_WII) && defined(DUSK_SAVE_WII_METHOD_NAND)
#include "savedevicedolphinnand.h"
#define SAVE_DEVICE_COUNT 1
#define saveDevicePlatformInit saveDeviceDolphinNandInit
#define saveDevicePlatformUpdate saveDeviceDolphinNandUpdate
#define saveDeviceCheckAvailabilityPlatform \
saveDeviceDolphinNandCheckAvailability
#define saveDevicePlatformDispose saveDeviceDolphinNandDispose
// ISFS_Rename exists, so NAND uses the same write-temp-then-rename
// pattern as PSP/Linux - see SAVE_DEVICE_DATA_RAW in save/savedevice.h.
#define SAVE_DEVICE_DATA_RAW
#define saveDeviceDataWritePlatform saveDeviceDolphinNandDataWrite
#define saveDeviceDataReadPlatform saveDeviceDolphinNandDataRead
#elif defined(DUSK_WII) && defined(DUSK_SAVE_WII_METHOD_SD)
#include "savedevicedolphinsd.h"
#define SAVE_DEVICE_COUNT 1
#define saveDevicePlatformInit saveDeviceDolphinSDInit
#define saveDevicePlatformUpdate saveDeviceDolphinSDUpdate
#define saveDeviceCheckAvailabilityPlatform \
saveDeviceDolphinSDCheckAvailability
#define saveDevicePlatformDispose saveDeviceDolphinSDDispose
// libfat gives standard POSIX rename(), so SD uses the same
// write-temp-then-rename pattern as PSP/Linux - see SAVE_DEVICE_DATA_RAW
// in save/savedevice.h.
#define SAVE_DEVICE_DATA_RAW
#define saveDeviceDataWritePlatform saveDeviceDolphinSDDataWrite
#define saveDeviceDataReadPlatform saveDeviceDolphinSDDataRead
#else
#include "savedevicedolphincard.h"
#define SAVE_DEVICE_COUNT 2
#define saveDevicePlatformInit saveDeviceDolphinCardInit
#define saveDevicePlatformUpdate saveDeviceDolphinCardUpdate
#define saveDeviceCheckAvailabilityPlatform \
saveDeviceDolphinCardCheckAvailability
#define saveDevicePlatformDispose saveDeviceDolphinCardDispose
// No rename or resize primitive on the CARD API, so this ping-pongs
// between two fixed files instead - see SAVE_DEVICE_DOLPHIN_CARD_FILENAME_0
// in savedevicedolphincard.h and SAVE_DEVICE_DATA_RAW in save/savedevice.h.
#define SAVE_DEVICE_DATA_RAW
#define saveDeviceDataWritePlatform saveDeviceDolphinCardDataWrite
#define saveDeviceDataReadPlatform saveDeviceDolphinCardDataRead
#endif