duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

memory_card_image.h (1860B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
      3 
      4 #pragma once
      5 
      6 #include <array>
      7 #include <span>
      8 #include <string>
      9 #include <string_view>
     10 #include <vector>
     11 
     12 class Error;
     13 
     14 namespace MemoryCardImage {
     15 enum : u32
     16 {
     17   DATA_SIZE = 128 * 1024, // 1mbit
     18   BLOCK_SIZE = 8192,
     19   FRAME_SIZE = 128,
     20   FRAMES_PER_BLOCK = BLOCK_SIZE / FRAME_SIZE,
     21   NUM_BLOCKS = DATA_SIZE / BLOCK_SIZE,
     22   NUM_FRAMES = DATA_SIZE / FRAME_SIZE,
     23   ICON_WIDTH = 16,
     24   ICON_HEIGHT = 16
     25 };
     26 
     27 using DataArray = std::array<u8, DATA_SIZE>;
     28 
     29 bool LoadFromFile(DataArray* data, const char* filename, Error* error);
     30 bool SaveToFile(const DataArray& data, const char* filename, Error* error);
     31 
     32 void Format(DataArray* data);
     33 
     34 struct IconFrame
     35 {
     36   u32 pixels[ICON_WIDTH * ICON_HEIGHT];
     37 };
     38 
     39 struct FileInfo
     40 {
     41   std::string filename;
     42   std::string title;
     43   u32 size;
     44   u32 first_block;
     45   u32 num_blocks;
     46   bool deleted;
     47 
     48   std::vector<IconFrame> icon_frames;
     49 };
     50 
     51 bool IsValid(const DataArray& data);
     52 u32 GetFreeBlockCount(const DataArray& data);
     53 std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted);
     54 bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer, Error* error);
     55 bool WriteFile(DataArray* data, std::string_view filename, std::span<const u8> buffer, Error* error);
     56 bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors);
     57 bool UndeleteFile(DataArray* data, const FileInfo& fi);
     58 bool ImportCard(DataArray* data, const char* filename, Error* error);
     59 bool ImportCard(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
     60 bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error);
     61 bool ImportSave(DataArray* data, const char* filename, Error* error);
     62 } // namespace MemoryCardImage