2024-04-07 03:23:00 +00:00
|
|
|
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
2022-12-04 11:03:45 +00:00
|
|
|
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
|
|
|
|
2020-09-18 14:26:19 +00:00
|
|
|
#pragma once
|
2024-04-07 03:23:00 +00:00
|
|
|
|
2020-09-18 14:26:19 +00:00
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-04-07 03:23:00 +00:00
|
|
|
class Error;
|
|
|
|
|
2021-03-05 04:50:20 +00:00
|
|
|
namespace MemoryCardImage {
|
2020-09-18 14:26:19 +00:00
|
|
|
enum : u32
|
|
|
|
{
|
|
|
|
DATA_SIZE = 128 * 1024, // 1mbit
|
|
|
|
BLOCK_SIZE = 8192,
|
|
|
|
FRAME_SIZE = 128,
|
|
|
|
FRAMES_PER_BLOCK = BLOCK_SIZE / FRAME_SIZE,
|
|
|
|
NUM_BLOCKS = DATA_SIZE / BLOCK_SIZE,
|
|
|
|
NUM_FRAMES = DATA_SIZE / FRAME_SIZE,
|
2021-03-05 04:50:20 +00:00
|
|
|
ICON_WIDTH = 16,
|
2020-09-18 14:26:19 +00:00
|
|
|
ICON_HEIGHT = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
using DataArray = std::array<u8, DATA_SIZE>;
|
|
|
|
|
2024-07-28 13:28:13 +00:00
|
|
|
bool LoadFromFile(DataArray* data, const char* filename, Error* error);
|
|
|
|
bool SaveToFile(const DataArray& data, const char* filename, Error* error);
|
2020-09-18 14:26:19 +00:00
|
|
|
|
|
|
|
void Format(DataArray* data);
|
|
|
|
|
|
|
|
struct IconFrame
|
|
|
|
{
|
|
|
|
u32 pixels[ICON_WIDTH * ICON_HEIGHT];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FileInfo
|
|
|
|
{
|
|
|
|
std::string filename;
|
|
|
|
std::string title;
|
|
|
|
u32 size;
|
|
|
|
u32 first_block;
|
|
|
|
u32 num_blocks;
|
2021-06-25 04:43:19 +00:00
|
|
|
bool deleted;
|
2020-09-18 14:26:19 +00:00
|
|
|
|
|
|
|
std::vector<IconFrame> icon_frames;
|
|
|
|
};
|
|
|
|
|
2021-03-20 14:10:32 +00:00
|
|
|
bool IsValid(const DataArray& data);
|
2020-09-18 14:26:19 +00:00
|
|
|
u32 GetFreeBlockCount(const DataArray& data);
|
2021-06-25 04:43:19 +00:00
|
|
|
std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted);
|
2024-04-07 03:23:00 +00:00
|
|
|
bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer, Error* error);
|
2024-05-05 10:21:54 +00:00
|
|
|
bool WriteFile(DataArray* data, std::string_view filename, const std::vector<u8>& buffer, Error* error);
|
2021-06-25 04:43:19 +00:00
|
|
|
bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors);
|
|
|
|
bool UndeleteFile(DataArray* data, const FileInfo& fi);
|
2024-04-07 03:23:00 +00:00
|
|
|
bool ImportCard(DataArray* data, const char* filename, Error* error);
|
|
|
|
bool ImportCard(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error);
|
|
|
|
bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error);
|
|
|
|
bool ImportSave(DataArray* data, const char* filename, Error* error);
|
2021-03-05 04:50:20 +00:00
|
|
|
} // namespace MemoryCardImage
|