mirror of
https://github.com/AxioDL/kabufuda.git
synced 2025-06-05 06:03:30 +00:00
Formatting pass
This commit is contained in:
parent
d0791ebd21
commit
b082a92fb2
29
.clang-format
Normal file
29
.clang-format
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
IndentWidth: 4
|
||||||
|
ColumnLimit: 120
|
||||||
|
UseTab: Never
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
PointerAlignment: Left
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
IndentCaseLabels: false
|
||||||
|
AllowShortBlocksOnASingleLine: true
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: true
|
||||||
|
BreakConstructorInitializersBeforeComma: true
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
NamespaceIndentation: None
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
SortIncludes: false
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
ConstructorInitializerIndentWidth: 0
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
@ -9,8 +9,7 @@ class BlockAllocationTable
|
|||||||
{
|
{
|
||||||
friend class Card;
|
friend class Card;
|
||||||
#pragma pack(push, 4)
|
#pragma pack(push, 4)
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint16_t m_checksum;
|
uint16_t m_checksum;
|
||||||
|
@ -22,19 +22,18 @@ public:
|
|||||||
class Card
|
class Card
|
||||||
{
|
{
|
||||||
#pragma pack(push, 4)
|
#pragma pack(push, 4)
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint8_t m_serial[12];
|
uint8_t m_serial[12];
|
||||||
uint64_t m_formatTime;
|
uint64_t m_formatTime;
|
||||||
int32_t m_sramBias;
|
int32_t m_sramBias;
|
||||||
uint32_t m_sramLanguage;
|
uint32_t m_sramLanguage;
|
||||||
uint32_t m_unknown;
|
uint32_t m_unknown;
|
||||||
uint16_t m_deviceId; /* 0 for Slot A, 1 for Slot B */
|
uint16_t m_deviceId; /* 0 for Slot A, 1 for Slot B */
|
||||||
uint16_t m_sizeMb;
|
uint16_t m_sizeMb;
|
||||||
uint16_t m_encoding;
|
uint16_t m_encoding;
|
||||||
uint8_t __padding[468];
|
uint8_t __padding[468];
|
||||||
uint16_t m_updateCounter;
|
uint16_t m_updateCounter;
|
||||||
uint16_t m_checksum;
|
uint16_t m_checksum;
|
||||||
uint16_t m_checksumInv;
|
uint16_t m_checksumInv;
|
||||||
@ -45,13 +44,13 @@ class Card
|
|||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
SystemString m_filename;
|
SystemString m_filename;
|
||||||
FILE* m_fileHandle = nullptr;
|
FILE* m_fileHandle = nullptr;
|
||||||
Directory m_dir;
|
Directory m_dir;
|
||||||
Directory m_dirBackup;
|
Directory m_dirBackup;
|
||||||
Directory* m_currentDir;
|
Directory* m_currentDir;
|
||||||
Directory* m_previousDir;
|
Directory* m_previousDir;
|
||||||
BlockAllocationTable m_bat;
|
BlockAllocationTable m_bat;
|
||||||
BlockAllocationTable m_batBackup;
|
BlockAllocationTable m_batBackup;
|
||||||
BlockAllocationTable* m_currentBat;
|
BlockAllocationTable* m_currentBat;
|
||||||
BlockAllocationTable* m_previousBat;
|
BlockAllocationTable* m_previousBat;
|
||||||
|
|
||||||
@ -63,6 +62,7 @@ class Card
|
|||||||
void _updateDirAndBat();
|
void _updateDirAndBat();
|
||||||
void _updateChecksum();
|
void _updateChecksum();
|
||||||
File* _fileFromHandle(const std::unique_ptr<IFileHandle>& fh) const;
|
File* _fileFromHandle(const std::unique_ptr<IFileHandle>& fh) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Card();
|
Card();
|
||||||
/**
|
/**
|
||||||
@ -76,21 +76,21 @@ public:
|
|||||||
* @param game
|
* @param game
|
||||||
* @param maker
|
* @param maker
|
||||||
*/
|
*/
|
||||||
Card(const SystemString& filepath, const char* game = nullptr, const char* maker=nullptr);
|
Card(const SystemString& filepath, const char* game = nullptr, const char* maker = nullptr);
|
||||||
~Card();
|
~Card();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief openFile
|
* @brief openFile
|
||||||
* @param filename
|
* @param filename
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<IFileHandle> openFile(const char* filename);
|
std::unique_ptr<IFileHandle> openFile(const char* filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief createFile
|
* @brief createFile
|
||||||
* @param filename
|
* @param filename
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<IFileHandle> createFile(const char* filename, size_t size);
|
std::unique_ptr<IFileHandle> createFile(const char* filename, size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief firstFile
|
* @brief firstFile
|
||||||
@ -297,15 +297,15 @@ public:
|
|||||||
* @param dest The destination Card instance
|
* @param dest The destination Card instance
|
||||||
* @return True if successful, false otherwise
|
* @return True if successful, false otherwise
|
||||||
*/
|
*/
|
||||||
bool copyFileTo(const std::unique_ptr<IFileHandle>&fh, Card& dest);
|
bool copyFileTo(const std::unique_ptr<IFileHandle>& fh, Card& dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief moveFileTo
|
* @brief moveFileTo
|
||||||
* @param fh
|
* @param fh
|
||||||
* @param dest
|
* @param dest
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool moveFileTo(const std::unique_ptr<IFileHandle>&fh, Card& dest);
|
bool moveFileTo(const std::unique_ptr<IFileHandle>& fh, Card& dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the current game, if not null any openFile requests will only return files that match this game
|
* @brief Sets the current game, if not null any openFile requests will only return files that match this game
|
||||||
@ -355,7 +355,8 @@ public:
|
|||||||
void format(EDeviceId deviceId, ECardSize size = ECardSize::Card2043Mb, EEncoding encoding = EEncoding::ASCII);
|
void format(EDeviceId deviceId, ECardSize size = ECardSize::Card2043Mb, EEncoding encoding = EEncoding::ASCII);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the size of the file in Megabits from a file on disk, useful for determining filesize ahead of time.
|
* @brief Returns the size of the file in Megabits from a file on disk, useful for determining filesize ahead of
|
||||||
|
* time.
|
||||||
* @return Size of file in Megabits
|
* @return Size of file in Megabits
|
||||||
*/
|
*/
|
||||||
static uint32_t getSizeMbitFromFile(const SystemString& filename);
|
static uint32_t getSizeMbitFromFile(const SystemString& filename);
|
||||||
@ -371,4 +372,3 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // __CARD_HPP__
|
#endif // __CARD_HPP__
|
||||||
|
|
||||||
|
@ -6,26 +6,25 @@
|
|||||||
|
|
||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
uint32_t constexpr BlockSize = 0x2000;
|
uint32_t constexpr BlockSize = 0x2000;
|
||||||
uint32_t constexpr MaxFiles = 127;
|
uint32_t constexpr MaxFiles = 127;
|
||||||
uint32_t constexpr FSTBlocks = 5;
|
uint32_t constexpr FSTBlocks = 5;
|
||||||
uint32_t constexpr MbitToBlocks = 0x10;
|
uint32_t constexpr MbitToBlocks = 0x10;
|
||||||
uint32_t constexpr BATSize = 0xFFB;
|
uint32_t constexpr BATSize = 0xFFB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The EPermissions enum
|
* @brief The EPermissions enum
|
||||||
*/
|
*/
|
||||||
enum class EPermissions : uint8_t
|
enum class EPermissions : uint8_t
|
||||||
{
|
{
|
||||||
Public = (1 << 2),
|
Public = (1 << 2),
|
||||||
NoCopy = (1 << 3),
|
NoCopy = (1 << 3),
|
||||||
NoMove = (1 << 4),
|
NoMove = (1 << 4),
|
||||||
Global = (1 << 5),
|
Global = (1 << 5),
|
||||||
Company = (1 << 6)
|
Company = (1 << 6)
|
||||||
};
|
};
|
||||||
ENABLE_BITWISE_ENUM(EPermissions)
|
ENABLE_BITWISE_ENUM(EPermissions)
|
||||||
|
|
||||||
|
|
||||||
enum class EImageFormat : uint8_t
|
enum class EImageFormat : uint8_t
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
@ -35,7 +34,7 @@ enum class EImageFormat : uint8_t
|
|||||||
|
|
||||||
enum class EAnimationType
|
enum class EAnimationType
|
||||||
{
|
{
|
||||||
Loop = 0,
|
Loop = 0,
|
||||||
Bounce = 2,
|
Bounce = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,26 +67,26 @@ enum class EDeviceId : uint16_t
|
|||||||
*/
|
*/
|
||||||
enum class ECardSize : uint16_t
|
enum class ECardSize : uint16_t
|
||||||
{
|
{
|
||||||
Card59Mb = 0x04,
|
Card59Mb = 0x04,
|
||||||
Card123Mb = 0x08,
|
Card123Mb = 0x08,
|
||||||
Card251Mb = 0x10,
|
Card251Mb = 0x10,
|
||||||
Card507Mb = 0x20,
|
Card507Mb = 0x20,
|
||||||
Card1019Mb = 0x40,
|
Card1019Mb = 0x40,
|
||||||
Card2043Mb = 0x80
|
Card2043Mb = 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr uint32_t BannerWidth = 96;
|
static constexpr uint32_t BannerWidth = 96;
|
||||||
static constexpr uint32_t BannerHeight = 64;
|
static constexpr uint32_t BannerHeight = 64;
|
||||||
static constexpr uint32_t IconWidth = 32;
|
static constexpr uint32_t IconWidth = 32;
|
||||||
static constexpr uint32_t IconHeight = 32;
|
static constexpr uint32_t IconHeight = 32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The EEncoding enum
|
* @brief The EEncoding enum
|
||||||
*/
|
*/
|
||||||
enum class EEncoding : uint16_t
|
enum class EEncoding : uint16_t
|
||||||
{
|
{
|
||||||
ASCII, /**< Standard ASCII Encoding */
|
ASCII, /**< Standard ASCII Encoding */
|
||||||
SJIS /**< SJIS Encoding for japanese */
|
SJIS /**< SJIS Encoding for japanese */
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,12 +9,11 @@ class Directory
|
|||||||
{
|
{
|
||||||
friend class Card;
|
friend class Card;
|
||||||
#pragma pack(push, 4)
|
#pragma pack(push, 4)
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
File m_files[MaxFiles];
|
File m_files[MaxFiles];
|
||||||
uint8_t __padding[0x3a];
|
uint8_t __padding[0x3a];
|
||||||
uint16_t m_updateCounter;
|
uint16_t m_updateCounter;
|
||||||
uint16_t m_checksum;
|
uint16_t m_checksum;
|
||||||
uint16_t m_checksumInv;
|
uint16_t m_checksumInv;
|
||||||
|
@ -11,21 +11,20 @@ class File
|
|||||||
friend class Directory;
|
friend class Directory;
|
||||||
friend class Card;
|
friend class Card;
|
||||||
#pragma pack(push, 4)
|
#pragma pack(push, 4)
|
||||||
union
|
union {
|
||||||
{
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
uint8_t m_game[4];
|
uint8_t m_game[4];
|
||||||
uint8_t m_maker[2];
|
uint8_t m_maker[2];
|
||||||
uint8_t m_reserved;
|
uint8_t m_reserved;
|
||||||
uint8_t m_bannerFlags;
|
uint8_t m_bannerFlags;
|
||||||
char m_filename[0x20];
|
char m_filename[0x20];
|
||||||
uint32_t m_modifiedTime;
|
uint32_t m_modifiedTime;
|
||||||
uint32_t m_iconAddress;
|
uint32_t m_iconAddress;
|
||||||
uint16_t m_iconFmt;
|
uint16_t m_iconFmt;
|
||||||
uint16_t m_animSpeed;
|
uint16_t m_animSpeed;
|
||||||
EPermissions m_permissions;
|
EPermissions m_permissions;
|
||||||
int8_t m_copyCounter;
|
int8_t m_copyCounter;
|
||||||
uint16_t m_firstBlock;
|
uint16_t m_firstBlock;
|
||||||
uint16_t m_blockCount;
|
uint16_t m_blockCount;
|
||||||
uint16_t m_reserved2;
|
uint16_t m_reserved2;
|
||||||
@ -43,7 +42,6 @@ public:
|
|||||||
File(const char* filename);
|
File(const char* filename);
|
||||||
~File() {}
|
~File() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __KABU_FILE_HPP__
|
#endif // __KABU_FILE_HPP__
|
||||||
|
@ -35,37 +35,36 @@
|
|||||||
#undef bswap64
|
#undef bswap64
|
||||||
|
|
||||||
#ifndef ENABLE_BITWISE_ENUM
|
#ifndef ENABLE_BITWISE_ENUM
|
||||||
#define ENABLE_BITWISE_ENUM(type)\
|
#define ENABLE_BITWISE_ENUM(type) \
|
||||||
constexpr type operator|(type a, type b)\
|
constexpr type operator|(type a, type b) \
|
||||||
{\
|
{ \
|
||||||
using T = std::underlying_type_t<type>;\
|
using T = std::underlying_type_t<type>; \
|
||||||
return type(static_cast<T>(a) | static_cast<T>(b));\
|
return type(static_cast<T>(a) | static_cast<T>(b)); \
|
||||||
}\
|
} \
|
||||||
constexpr type operator&(type a, type b)\
|
constexpr type operator&(type a, type b) \
|
||||||
{\
|
{ \
|
||||||
using T = std::underlying_type_t<type>;\
|
using T = std::underlying_type_t<type>; \
|
||||||
return type(static_cast<T>(a) & static_cast<T>(b));\
|
return type(static_cast<T>(a) & static_cast<T>(b)); \
|
||||||
}\
|
} \
|
||||||
inline type& operator|=(type& a, const type& b)\
|
inline type& operator|=(type& a, const type& b) \
|
||||||
{\
|
{ \
|
||||||
using T = std::underlying_type_t<type>;\
|
using T = std::underlying_type_t<type>; \
|
||||||
a = type(static_cast<T>(a) | static_cast<T>(b));\
|
a = type(static_cast<T>(a) | static_cast<T>(b)); \
|
||||||
return a;\
|
return a; \
|
||||||
}\
|
} \
|
||||||
inline type& operator&=(type& a, const type& b)\
|
inline type& operator&=(type& a, const type& b) \
|
||||||
{\
|
{ \
|
||||||
using T = std::underlying_type_t<type>;\
|
using T = std::underlying_type_t<type>; \
|
||||||
a = type(static_cast<T>(a) & static_cast<T>(b));\
|
a = type(static_cast<T>(a) & static_cast<T>(b)); \
|
||||||
return a;\
|
return a; \
|
||||||
}\
|
} \
|
||||||
inline type operator~(const type& key)\
|
inline type operator~(const type& key) \
|
||||||
{\
|
{ \
|
||||||
using T = std::underlying_type_t<type>;\
|
using T = std::underlying_type_t<type>; \
|
||||||
return type(~static_cast<T>(key));\
|
return type(~static_cast<T>(key)); \
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -104,25 +103,20 @@ static inline T bswap64(T val)
|
|||||||
#elif _WIN32
|
#elif _WIN32
|
||||||
return _byteswap_uint64(val);
|
return _byteswap_uint64(val);
|
||||||
#else
|
#else
|
||||||
return ((val & 0xFF00000000000000ULL) >> 56) |
|
return ((val & 0xFF00000000000000ULL) >> 56) | ((val & 0x00FF000000000000ULL) >> 40) |
|
||||||
((val & 0x00FF000000000000ULL) >> 40) |
|
((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x000000FF00000000ULL) >> 8) |
|
||||||
((val & 0x0000FF0000000000ULL) >> 24) |
|
((val & 0x00000000FF000000ULL) << 8) | ((val & 0x0000000000FF0000ULL) << 24) |
|
||||||
((val & 0x000000FF00000000ULL) >> 8) |
|
((val & 0x000000000000FF00ULL) << 40) | ((val & 0x00000000000000FFULL) << 56);
|
||||||
((val & 0x00000000FF000000ULL) << 8) |
|
|
||||||
((val & 0x0000000000FF0000ULL) << 24) |
|
|
||||||
((val & 0x000000000000FF00ULL) << 40) |
|
|
||||||
((val & 0x00000000000000FFULL) << 56);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
static inline int16_t SBig(int16_t val) {return bswap16(val);}
|
static inline int16_t SBig(int16_t val) { return bswap16(val); }
|
||||||
static inline uint16_t SBig(uint16_t val) {return bswap16(val);}
|
static inline uint16_t SBig(uint16_t val) { return bswap16(val); }
|
||||||
static inline int32_t SBig(int32_t val) {return bswap32(val);}
|
static inline int32_t SBig(int32_t val) { return bswap32(val); }
|
||||||
static inline uint32_t SBig(uint32_t val) {return bswap32(val);}
|
static inline uint32_t SBig(uint32_t val) { return bswap32(val); }
|
||||||
static inline int64_t SBig(int64_t val) {return bswap64(val);}
|
static inline int64_t SBig(int64_t val) { return bswap64(val); }
|
||||||
static inline uint64_t SBig(uint64_t val) {return bswap64(val);}
|
static inline uint64_t SBig(uint64_t val) { return bswap64(val); }
|
||||||
static inline float SBig(float val)
|
static inline float SBig(float val)
|
||||||
{
|
{
|
||||||
int32_t ival = bswap32(*((int32_t*)(&val)));
|
int32_t ival = bswap32(*((int32_t*)(&val)));
|
||||||
@ -133,25 +127,24 @@ static inline double SBig(double val)
|
|||||||
int64_t ival = bswap64(*((int64_t*)(&val)));
|
int64_t ival = bswap64(*((int64_t*)(&val)));
|
||||||
return *((double*)(&ival));
|
return *((double*)(&ival));
|
||||||
}
|
}
|
||||||
#define SBIG(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \
|
#define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
|
||||||
| ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 )
|
|
||||||
|
|
||||||
static inline int16_t SLittle(int16_t val) {return val;}
|
static inline int16_t SLittle(int16_t val) { return val; }
|
||||||
static inline uint16_t SLittle(uint16_t val) {return val;}
|
static inline uint16_t SLittle(uint16_t val) { return val; }
|
||||||
static inline int32_t SLittle(int32_t val) {return val;}
|
static inline int32_t SLittle(int32_t val) { return val; }
|
||||||
static inline uint32_t SLittle(uint32_t val) {return val;}
|
static inline uint32_t SLittle(uint32_t val) { return val; }
|
||||||
static inline int64_t SLittle(int64_t val) {return val;}
|
static inline int64_t SLittle(int64_t val) { return val; }
|
||||||
static inline uint64_t SLittle(uint64_t val) {return val;}
|
static inline uint64_t SLittle(uint64_t val) { return val; }
|
||||||
static inline float SLittle(float val) {return val;}
|
static inline float SLittle(float val) { return val; }
|
||||||
static inline double SLittle(double val) {return val;}
|
static inline double SLittle(double val) { return val; }
|
||||||
#define SLITTLE(q) (q)
|
#define SLITTLE(q) (q)
|
||||||
#else
|
#else
|
||||||
static inline int16_t SLittle(int16_t val) {return bswap16(val);}
|
static inline int16_t SLittle(int16_t val) { return bswap16(val); }
|
||||||
static inline uint16_t SLittle(uint16_t val) {return bswap16(val);}
|
static inline uint16_t SLittle(uint16_t val) { return bswap16(val); }
|
||||||
static inline int32_t SLittle(int32_t val) {return bswap32(val);}
|
static inline int32_t SLittle(int32_t val) { return bswap32(val); }
|
||||||
static inline uint32_t SLittle(uint32_t val) {return bswap32(val);}
|
static inline uint32_t SLittle(uint32_t val) { return bswap32(val); }
|
||||||
static inline int64_t SLittle(int64_t val) {return bswap64(val);}
|
static inline int64_t SLittle(int64_t val) { return bswap64(val); }
|
||||||
static inline uint64_t SLittle(uint64_t val) {return bswap64(val);}
|
static inline uint64_t SLittle(uint64_t val) { return bswap64(val); }
|
||||||
static inline float SLittle(float val)
|
static inline float SLittle(float val)
|
||||||
{
|
{
|
||||||
int32_t ival = bswap32(*((int32_t*)(&val)));
|
int32_t ival = bswap32(*((int32_t*)(&val)));
|
||||||
@ -162,96 +155,91 @@ static inline double SLittle(double val)
|
|||||||
int64_t ival = bswap64(*((int64_t*)(&val)));
|
int64_t ival = bswap64(*((int64_t*)(&val)));
|
||||||
return *((double*)(&ival));
|
return *((double*)(&ival));
|
||||||
}
|
}
|
||||||
#define SLITTLE(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \
|
#define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
|
||||||
| ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 )
|
|
||||||
|
|
||||||
static inline int16_t SBig(int16_t val) {return val;}
|
static inline int16_t SBig(int16_t val) { return val; }
|
||||||
static inline uint16_t SBig(uint16_t val) {return val;}
|
static inline uint16_t SBig(uint16_t val) { return val; }
|
||||||
static inline int32_t SBig(int32_t val) {return val;}
|
static inline int32_t SBig(int32_t val) { return val; }
|
||||||
static inline uint32_t SBig(uint32_t val) {return val;}
|
static inline uint32_t SBig(uint32_t val) { return val; }
|
||||||
static inline int64_t SBig(int64_t val) {return val;}
|
static inline int64_t SBig(int64_t val) { return val; }
|
||||||
static inline uint64_t SBig(uint64_t val) {return val;}
|
static inline uint64_t SBig(uint64_t val) { return val; }
|
||||||
static inline float SBig(float val) {return val;}
|
static inline float SBig(float val) { return val; }
|
||||||
static inline double SBig(double val) {return val;}
|
static inline double SBig(double val) { return val; }
|
||||||
#define SBIG(q) (q)
|
#define SBIG(q) (q)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CARD_UCS2
|
#if CARD_UCS2
|
||||||
typedef wchar_t SystemChar;
|
typedef wchar_t SystemChar;
|
||||||
static inline size_t StrLen(const SystemChar* str) {return wcslen(str);}
|
static inline size_t StrLen(const SystemChar* str) { return wcslen(str); }
|
||||||
typedef std::wstring SystemString;
|
typedef std::wstring SystemString;
|
||||||
static inline void ToLower(SystemString& str)
|
static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); }
|
||||||
{std::transform(str.begin(), str.end(), str.begin(), towlower);}
|
static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); }
|
||||||
static inline void ToUpper(SystemString& str)
|
|
||||||
{std::transform(str.begin(), str.end(), str.begin(), towupper);}
|
|
||||||
class SystemUTF8View
|
class SystemUTF8View
|
||||||
{
|
{
|
||||||
std::string m_utf8;
|
std::string m_utf8;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SystemUTF8View(const SystemString& str)
|
explicit SystemUTF8View(const SystemString& str) : m_utf8(WideToUTF8(str)) {}
|
||||||
: m_utf8(WideToUTF8(str)) {}
|
operator const std::string&() const { return m_utf8; }
|
||||||
operator const std::string&() const {return m_utf8;}
|
const std::string& str() const { return m_utf8; }
|
||||||
const std::string& str() const {return m_utf8;}
|
const char* c_str() const { return m_utf8.c_str(); }
|
||||||
const char* c_str() const {return m_utf8.c_str();}
|
std::string operator+(const std::string& other) const { return m_utf8 + other; }
|
||||||
std::string operator+(const std::string& other) const {return m_utf8 + other;}
|
std::string operator+(const char* other) const { return m_utf8 + other; }
|
||||||
std::string operator+(const char* other) const {return m_utf8 + other;}
|
|
||||||
};
|
};
|
||||||
inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); }
|
||||||
inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); }
|
||||||
class SystemStringView
|
class SystemStringView
|
||||||
{
|
{
|
||||||
std::wstring m_sys;
|
std::wstring m_sys;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SystemStringView(const std::string& str)
|
explicit SystemStringView(const std::string& str) : m_sys(UTF8ToWide(str)) {}
|
||||||
: m_sys(UTF8ToWide(str)) {}
|
operator const std::wstring&() const { return m_sys; }
|
||||||
operator const std::wstring&() const {return m_sys;}
|
const std::wstring& sys_str() const { return m_sys; }
|
||||||
const std::wstring& sys_str() const {return m_sys;}
|
const SystemChar* c_str() const { return m_sys.c_str(); }
|
||||||
const SystemChar* c_str() const {return m_sys.c_str();}
|
std::wstring operator+(const std::wstring& other) const { return m_sys + other; }
|
||||||
std::wstring operator+(const std::wstring& other) const {return m_sys + other;}
|
std::wstring operator+(const wchar_t* other) const { return m_sys + other; }
|
||||||
std::wstring operator+(const wchar_t* other) const {return m_sys + other;}
|
|
||||||
};
|
};
|
||||||
inline std::wstring operator+(const std::wstring& lhs, const SystemStringView& rhs) {return lhs + std::wstring(rhs);}
|
inline std::wstring operator+(const std::wstring& lhs, const SystemStringView& rhs) { return lhs + std::wstring(rhs); }
|
||||||
inline std::wstring operator+(const wchar_t* lhs, const SystemStringView& rhs) {return lhs + std::wstring(rhs);}
|
inline std::wstring operator+(const wchar_t* lhs, const SystemStringView& rhs) { return lhs + std::wstring(rhs); }
|
||||||
#ifndef _S
|
#ifndef _S
|
||||||
#define _S(val) L ## val
|
#define _S(val) L##val
|
||||||
#endif
|
#endif
|
||||||
typedef struct _stat Sstat;
|
typedef struct _stat Sstat;
|
||||||
#else
|
#else
|
||||||
typedef char SystemChar;
|
typedef char SystemChar;
|
||||||
static inline size_t StrLen(const SystemChar* str) {return strlen(str);}
|
static inline size_t StrLen(const SystemChar* str) { return strlen(str); }
|
||||||
typedef std::string SystemString;
|
typedef std::string SystemString;
|
||||||
static inline void ToLower(SystemString& str)
|
static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), tolower); }
|
||||||
{std::transform(str.begin(), str.end(), str.begin(), tolower);}
|
static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), toupper); }
|
||||||
static inline void ToUpper(SystemString& str)
|
|
||||||
{std::transform(str.begin(), str.end(), str.begin(), toupper);}
|
|
||||||
class SystemUTF8View
|
class SystemUTF8View
|
||||||
{
|
{
|
||||||
const std::string& m_utf8;
|
const std::string& m_utf8;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SystemUTF8View(const SystemString& str)
|
explicit SystemUTF8View(const SystemString& str) : m_utf8(str) {}
|
||||||
: m_utf8(str) {}
|
operator const std::string&() const { return m_utf8; }
|
||||||
operator const std::string&() const {return m_utf8;}
|
const std::string& str() const { return m_utf8; }
|
||||||
const std::string& str() const {return m_utf8;}
|
const char* c_str() const { return m_utf8.c_str(); }
|
||||||
const char* c_str() const {return m_utf8.c_str();}
|
std::string operator+(const std::string& other) const { return std::string(m_utf8) + other; }
|
||||||
std::string operator+(const std::string& other) const {return std::string(m_utf8) + other;}
|
std::string operator+(const char* other) const { return std::string(m_utf8) + other; }
|
||||||
std::string operator+(const char* other) const {return std::string(m_utf8) + other;}
|
|
||||||
};
|
};
|
||||||
inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); }
|
||||||
inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); }
|
||||||
class SystemStringView
|
class SystemStringView
|
||||||
{
|
{
|
||||||
const std::string& m_sys;
|
const std::string& m_sys;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SystemStringView(const std::string& str)
|
explicit SystemStringView(const std::string& str) : m_sys(str) {}
|
||||||
: m_sys(str) {}
|
operator const std::string&() const { return m_sys; }
|
||||||
operator const std::string&() const {return m_sys;}
|
const std::string& sys_str() const { return m_sys; }
|
||||||
const std::string& sys_str() const {return m_sys;}
|
const SystemChar* c_str() const { return m_sys.c_str(); }
|
||||||
const SystemChar* c_str() const {return m_sys.c_str();}
|
std::string operator+(const std::string& other) const { return m_sys + other; }
|
||||||
std::string operator+(const std::string& other) const {return m_sys + other;}
|
std::string operator+(const char* other) const { return m_sys + other; }
|
||||||
std::string operator+(const char* other) const {return m_sys + other;}
|
|
||||||
};
|
};
|
||||||
inline std::string operator+(const std::string& lhs, const SystemStringView& rhs) {return lhs + std::string(rhs);}
|
inline std::string operator+(const std::string& lhs, const SystemStringView& rhs) { return lhs + std::string(rhs); }
|
||||||
inline std::string operator+(const char* lhs, const SystemStringView& rhs) {return lhs + std::string(rhs);}
|
inline std::string operator+(const char* lhs, const SystemStringView& rhs) { return lhs + std::string(rhs); }
|
||||||
#ifndef _S
|
#ifndef _S
|
||||||
#define _S(val) val
|
#define _S(val) val
|
||||||
#endif
|
#endif
|
||||||
@ -266,7 +254,7 @@ enum class FileLockType
|
|||||||
Read,
|
Read,
|
||||||
Write
|
Write
|
||||||
};
|
};
|
||||||
static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLockType lock=FileLockType::None)
|
static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLockType lock = FileLockType::None)
|
||||||
{
|
{
|
||||||
#if CARD_UCS2
|
#if CARD_UCS2
|
||||||
FILE* fp = _wfopen(path, mode);
|
FILE* fp = _wfopen(path, mode);
|
||||||
@ -282,7 +270,8 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
|
|||||||
{
|
{
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
OVERLAPPED ov = {};
|
OVERLAPPED ov = {};
|
||||||
LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, &ov);
|
LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1,
|
||||||
|
&ov);
|
||||||
#else
|
#else
|
||||||
if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB))
|
if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB))
|
||||||
fprintf(stderr, "flock %s: %s", path, strerror(errno));
|
fprintf(stderr, "flock %s: %s", path, strerror(errno));
|
||||||
@ -327,7 +316,9 @@ static inline int Stat(const SystemChar* path, Sstat* statOut)
|
|||||||
{
|
{
|
||||||
#if CARD_UCS2
|
#if CARD_UCS2
|
||||||
size_t pos;
|
size_t pos;
|
||||||
for (pos=0 ; pos<3 && path[pos] != L'\0' ; ++pos) {}
|
for (pos = 0; pos < 3 && path[pos] != L'\0'; ++pos)
|
||||||
|
{
|
||||||
|
}
|
||||||
if (pos == 2 && path[1] == L':')
|
if (pos == 2 && path[1] == L':')
|
||||||
{
|
{
|
||||||
SystemChar fixPath[4] = {path[0], L':', L'/', L'\0'};
|
SystemChar fixPath[4] = {path[0], L':', L'/', L'\0'};
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#include "kabufuda/Util.hpp"
|
#include "kabufuda/Util.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
void BlockAllocationTable::swapEndian()
|
void BlockAllocationTable::swapEndian()
|
||||||
@ -12,9 +11,7 @@ void BlockAllocationTable::swapEndian()
|
|||||||
m_updateCounter = SBig(m_updateCounter);
|
m_updateCounter = SBig(m_updateCounter);
|
||||||
m_freeBlocks = SBig(m_freeBlocks);
|
m_freeBlocks = SBig(m_freeBlocks);
|
||||||
m_lastAllocated = SBig(m_lastAllocated);
|
m_lastAllocated = SBig(m_lastAllocated);
|
||||||
std::for_each(std::begin(m_map), std::end(m_map), [](uint16_t& val){
|
std::for_each(std::begin(m_map), std::end(m_map), [](uint16_t& val) { val = SBig(val); });
|
||||||
val = SBig(val);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockAllocationTable::updateChecksum()
|
void BlockAllocationTable::updateChecksum()
|
||||||
@ -41,8 +38,7 @@ BlockAllocationTable::BlockAllocationTable(uint32_t blockCount)
|
|||||||
updateChecksum();
|
updateChecksum();
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockAllocationTable::~BlockAllocationTable()
|
BlockAllocationTable::~BlockAllocationTable() {}
|
||||||
{}
|
|
||||||
|
|
||||||
uint16_t BlockAllocationTable::getNextBlock(uint16_t block) const
|
uint16_t BlockAllocationTable::getNextBlock(uint16_t block) const
|
||||||
{
|
{
|
||||||
@ -83,7 +79,7 @@ bool BlockAllocationTable::clear(uint16_t first, uint16_t count)
|
|||||||
if (length != count)
|
if (length != count)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (size_t i= 0 ; i < length ; ++i)
|
for (size_t i = 0; i < length; ++i)
|
||||||
m_map[blocks.at(i) - FSTBlocks] = 0;
|
m_map[blocks.at(i) - FSTBlocks] = 0;
|
||||||
m_freeBlocks += count;
|
m_freeBlocks += count;
|
||||||
return true;
|
return true;
|
||||||
|
@ -8,26 +8,21 @@
|
|||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
|
|
||||||
IFileHandle::~IFileHandle()
|
IFileHandle::~IFileHandle() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class FileHandle : public IFileHandle
|
class FileHandle : public IFileHandle
|
||||||
{
|
{
|
||||||
friend class Card;
|
friend class Card;
|
||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
int32_t offset =0;
|
int32_t offset = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileHandle() = default;
|
FileHandle() = default;
|
||||||
FileHandle(uint32_t idx)
|
FileHandle(uint32_t idx) : idx(idx) {}
|
||||||
: idx(idx)
|
|
||||||
{}
|
|
||||||
virtual ~FileHandle();
|
virtual ~FileHandle();
|
||||||
};
|
};
|
||||||
|
|
||||||
FileHandle::~FileHandle()
|
FileHandle::~FileHandle() {}
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void Card::_swapEndian()
|
void Card::_swapEndian()
|
||||||
{
|
{
|
||||||
@ -43,10 +38,7 @@ void Card::_swapEndian()
|
|||||||
m_checksumInv = SBig(m_checksumInv);
|
m_checksumInv = SBig(m_checksumInv);
|
||||||
}
|
}
|
||||||
|
|
||||||
Card::Card()
|
Card::Card() { memset(__raw, 0xFF, BlockSize); }
|
||||||
{
|
|
||||||
memset(__raw, 0xFF, BlockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
Card::Card(const Card& other)
|
Card::Card(const Card& other)
|
||||||
{
|
{
|
||||||
@ -59,8 +51,7 @@ Card::Card(const Card& other)
|
|||||||
memcpy(m_maker, other.m_maker, 2);
|
memcpy(m_maker, other.m_maker, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Card::Card(const SystemString& filename, const char* game, const char* maker)
|
Card::Card(const SystemString& filename, const char* game, const char* maker) : m_filename(filename)
|
||||||
: m_filename(filename)
|
|
||||||
{
|
{
|
||||||
memset(__raw, 0xFF, BlockSize);
|
memset(__raw, 0xFF, BlockSize);
|
||||||
if (game && strlen(game) == 4)
|
if (game && strlen(game) == 4)
|
||||||
@ -164,7 +155,7 @@ void Card::_updateChecksum()
|
|||||||
_swapEndian();
|
_swapEndian();
|
||||||
}
|
}
|
||||||
|
|
||||||
File* Card::_fileFromHandle(const std::unique_ptr<IFileHandle> &fh) const
|
File* Card::_fileFromHandle(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
if (!fh)
|
if (!fh)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -188,7 +179,6 @@ std::unique_ptr<IFileHandle> Card::createFile(const char* filename, size_t size)
|
|||||||
f->m_firstBlock = block;
|
f->m_firstBlock = block;
|
||||||
f->m_blockCount = uint16_t(size / BlockSize);
|
f->m_blockCount = uint16_t(size / BlockSize);
|
||||||
|
|
||||||
|
|
||||||
return std::unique_ptr<IFileHandle>(new FileHandle(m_currentDir->indexForFile(f)));
|
return std::unique_ptr<IFileHandle>(new FileHandle(m_currentDir->indexForFile(f)));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -231,7 +221,7 @@ void Card::deleteFile(const std::unique_ptr<IFileHandle>& fh)
|
|||||||
FileHandle* f = dynamic_cast<FileHandle*>(fh.get());
|
FileHandle* f = dynamic_cast<FileHandle*>(fh.get());
|
||||||
uint16_t block = m_currentDir->getFile(f->idx)->m_firstBlock;
|
uint16_t block = m_currentDir->getFile(f->idx)->m_firstBlock;
|
||||||
|
|
||||||
while(block != 0xFFFF)
|
while (block != 0xFFFF)
|
||||||
{
|
{
|
||||||
/* TODO: add a fragmentation check */
|
/* TODO: add a fragmentation check */
|
||||||
uint16_t nextBlock = m_currentBat->getNextBlock(block);
|
uint16_t nextBlock = m_currentBat->getNextBlock(block);
|
||||||
@ -239,7 +229,6 @@ void Card::deleteFile(const std::unique_ptr<IFileHandle>& fh)
|
|||||||
block = nextBlock;
|
block = nextBlock;
|
||||||
}
|
}
|
||||||
*m_currentDir->getFile(f->idx) = File();
|
*m_currentDir->getFile(f->idx) = File();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::write(const std::unique_ptr<IFileHandle>& fh, const void* buf, size_t size)
|
void Card::write(const std::unique_ptr<IFileHandle>& fh, const void* buf, size_t size)
|
||||||
@ -291,7 +280,7 @@ void Card::write(const std::unique_ptr<IFileHandle>& fh, const void* buf, size_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::read(const std::unique_ptr<IFileHandle> &fh, void *dst, size_t size)
|
void Card::read(const std::unique_ptr<IFileHandle>& fh, void* dst, size_t size)
|
||||||
{
|
{
|
||||||
if (!fh)
|
if (!fh)
|
||||||
return;
|
return;
|
||||||
@ -339,7 +328,7 @@ void Card::read(const std::unique_ptr<IFileHandle> &fh, void *dst, size_t size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::seek(const std::unique_ptr<IFileHandle> &fh, int32_t pos, SeekOrigin whence)
|
void Card::seek(const std::unique_ptr<IFileHandle>& fh, int32_t pos, SeekOrigin whence)
|
||||||
{
|
{
|
||||||
if (!fh)
|
if (!fh)
|
||||||
return;
|
return;
|
||||||
@ -349,7 +338,7 @@ void Card::seek(const std::unique_ptr<IFileHandle> &fh, int32_t pos, SeekOrigin
|
|||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch(whence)
|
switch (whence)
|
||||||
{
|
{
|
||||||
case SeekOrigin::Begin:
|
case SeekOrigin::Begin:
|
||||||
f->offset = pos;
|
f->offset = pos;
|
||||||
@ -363,7 +352,7 @@ void Card::seek(const std::unique_ptr<IFileHandle> &fh, int32_t pos, SeekOrigin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Card::tell(const std::unique_ptr<IFileHandle> &fh)
|
int32_t Card::tell(const std::unique_ptr<IFileHandle>& fh)
|
||||||
{
|
{
|
||||||
if (!fh)
|
if (!fh)
|
||||||
return -1;
|
return -1;
|
||||||
@ -385,7 +374,7 @@ void Card::setPublic(const std::unique_ptr<IFileHandle>& fh, bool pub)
|
|||||||
file->m_permissions &= ~EPermissions::Public;
|
file->m_permissions &= ~EPermissions::Public;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Card::isPublic(const std::unique_ptr<IFileHandle> &fh) const
|
bool Card::isPublic(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -394,7 +383,7 @@ bool Card::isPublic(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return bool(file->m_permissions & EPermissions::Public);
|
return bool(file->m_permissions & EPermissions::Public);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setCanCopy(const std::unique_ptr<IFileHandle> &fh, bool copy) const
|
void Card::setCanCopy(const std::unique_ptr<IFileHandle>& fh, bool copy) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -406,7 +395,7 @@ void Card::setCanCopy(const std::unique_ptr<IFileHandle> &fh, bool copy) const
|
|||||||
file->m_permissions |= EPermissions::NoCopy;
|
file->m_permissions |= EPermissions::NoCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Card::canCopy(const std::unique_ptr<IFileHandle> &fh) const
|
bool Card::canCopy(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -415,7 +404,7 @@ bool Card::canCopy(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return !bool(file->m_permissions & EPermissions::NoCopy);
|
return !bool(file->m_permissions & EPermissions::NoCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setCanMove(const std::unique_ptr<IFileHandle> &fh, bool move)
|
void Card::setCanMove(const std::unique_ptr<IFileHandle>& fh, bool move)
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -427,7 +416,7 @@ void Card::setCanMove(const std::unique_ptr<IFileHandle> &fh, bool move)
|
|||||||
file->m_permissions |= EPermissions::NoMove;
|
file->m_permissions |= EPermissions::NoMove;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Card::canMove(const std::unique_ptr<IFileHandle> &fh) const
|
bool Card::canMove(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -436,7 +425,7 @@ bool Card::canMove(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return !bool(file->m_permissions & EPermissions::NoMove);
|
return !bool(file->m_permissions & EPermissions::NoMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Card::gameId(const std::unique_ptr<IFileHandle> &fh) const
|
const char* Card::gameId(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -444,7 +433,7 @@ const char* Card::gameId(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return reinterpret_cast<const char*>(file->m_game);
|
return reinterpret_cast<const char*>(file->m_game);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Card::maker(const std::unique_ptr<IFileHandle> &fh) const
|
const char* Card::maker(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -460,7 +449,7 @@ void Card::setBannerFormat(const std::unique_ptr<IFileHandle>& fh, EImageFormat
|
|||||||
file->m_bannerFlags = (file->m_bannerFlags & ~3) | (uint8_t(fmt));
|
file->m_bannerFlags = (file->m_bannerFlags & ~3) | (uint8_t(fmt));
|
||||||
}
|
}
|
||||||
|
|
||||||
EImageFormat Card::bannerFormat(const std::unique_ptr<IFileHandle> &fh) const
|
EImageFormat Card::bannerFormat(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -468,15 +457,15 @@ EImageFormat Card::bannerFormat(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return EImageFormat(file->m_bannerFlags & 3);
|
return EImageFormat(file->m_bannerFlags & 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setIconAnimationType(const std::unique_ptr<IFileHandle> &fh, EAnimationType type)
|
void Card::setIconAnimationType(const std::unique_ptr<IFileHandle>& fh, EAnimationType type)
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
file->m_bannerFlags = (file->m_bannerFlags & ~4) | uint8_t(type);
|
file->m_bannerFlags = (file->m_bannerFlags & ~4) | uint8_t(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
EAnimationType Card::iconAnimationType(const std::unique_ptr<IFileHandle> &fh) const
|
EAnimationType Card::iconAnimationType(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -485,16 +474,16 @@ EAnimationType Card::iconAnimationType(const std::unique_ptr<IFileHandle> &fh) c
|
|||||||
return EAnimationType(file->m_bannerFlags & 4);
|
return EAnimationType(file->m_bannerFlags & 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setIconFormat(const std::unique_ptr<IFileHandle> &fh, uint32_t idx, EImageFormat fmt)
|
void Card::setIconFormat(const std::unique_ptr<IFileHandle>& fh, uint32_t idx, EImageFormat fmt)
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
file->m_iconFmt = (file->m_iconFmt & ~(3 << (2 * idx))) | (uint16_t(fmt) << (2 * idx));
|
file->m_iconFmt = (file->m_iconFmt & ~(3 << (2 * idx))) | (uint16_t(fmt) << (2 * idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
EImageFormat Card::iconFormat(const std::unique_ptr<IFileHandle> &fh, uint32_t idx) const
|
EImageFormat Card::iconFormat(const std::unique_ptr<IFileHandle>& fh, uint32_t idx) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -503,25 +492,25 @@ EImageFormat Card::iconFormat(const std::unique_ptr<IFileHandle> &fh, uint32_t i
|
|||||||
return EImageFormat(file->m_iconFmt >> (2 * (idx)) & 3);
|
return EImageFormat(file->m_iconFmt >> (2 * (idx)) & 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setIconSpeed(const std::unique_ptr<IFileHandle> &fh, uint32_t idx, EAnimationSpeed speed)
|
void Card::setIconSpeed(const std::unique_ptr<IFileHandle>& fh, uint32_t idx, EAnimationSpeed speed)
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
file->m_animSpeed = (file->m_animSpeed & ~(3 << (2 * idx))) | (uint16_t(speed) << (2 * idx));
|
file->m_animSpeed = (file->m_animSpeed & ~(3 << (2 * idx))) | (uint16_t(speed) << (2 * idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
EAnimationSpeed Card::iconSpeed(const std::unique_ptr<IFileHandle> &fh, uint32_t idx) const
|
EAnimationSpeed Card::iconSpeed(const std::unique_ptr<IFileHandle>& fh, uint32_t idx) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
return EAnimationSpeed::End;
|
return EAnimationSpeed::End;
|
||||||
|
|
||||||
return EAnimationSpeed((file->m_animSpeed >> (2 * (idx))) & 3);
|
return EAnimationSpeed((file->m_animSpeed >> (2 * (idx))) & 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setImageAddress(const std::unique_ptr<IFileHandle> &fh, uint32_t addr)
|
void Card::setImageAddress(const std::unique_ptr<IFileHandle>& fh, uint32_t addr)
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -529,7 +518,7 @@ void Card::setImageAddress(const std::unique_ptr<IFileHandle> &fh, uint32_t addr
|
|||||||
file->m_iconAddress = addr;
|
file->m_iconAddress = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Card::imageAddress(const std::unique_ptr<IFileHandle> &fh) const
|
int32_t Card::imageAddress(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -537,7 +526,7 @@ int32_t Card::imageAddress(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return file->m_iconAddress;
|
return file->m_iconAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::setCommentAddress(const std::unique_ptr<IFileHandle> &fh, uint32_t addr)
|
void Card::setCommentAddress(const std::unique_ptr<IFileHandle>& fh, uint32_t addr)
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -545,7 +534,7 @@ void Card::setCommentAddress(const std::unique_ptr<IFileHandle> &fh, uint32_t ad
|
|||||||
file->m_commentAddr = addr;
|
file->m_commentAddr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Card::commentAddress(const std::unique_ptr<IFileHandle> &fh) const
|
int32_t Card::commentAddress(const std::unique_ptr<IFileHandle>& fh) const
|
||||||
{
|
{
|
||||||
File* file = _fileFromHandle(fh);
|
File* file = _fileFromHandle(fh);
|
||||||
if (!file)
|
if (!file)
|
||||||
@ -553,7 +542,7 @@ int32_t Card::commentAddress(const std::unique_ptr<IFileHandle> &fh) const
|
|||||||
return file->m_commentAddr;
|
return file->m_commentAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Card::copyFileTo(const std::unique_ptr<IFileHandle> &fh, Card &dest)
|
bool Card::copyFileTo(const std::unique_ptr<IFileHandle>& fh, Card& dest)
|
||||||
{
|
{
|
||||||
if (!fh)
|
if (!fh)
|
||||||
return false;
|
return false;
|
||||||
@ -598,7 +587,7 @@ bool Card::copyFileTo(const std::unique_ptr<IFileHandle> &fh, Card &dest)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Card::moveFileTo(const std::unique_ptr<IFileHandle> &fh, Card &dest)
|
bool Card::moveFileTo(const std::unique_ptr<IFileHandle>& fh, Card& dest)
|
||||||
{
|
{
|
||||||
if (copyFileTo(fh, dest))
|
if (copyFileTo(fh, dest))
|
||||||
{
|
{
|
||||||
@ -652,7 +641,7 @@ const uint8_t* Card::getCurrentMaker() const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Card::getSerial(uint32_t *s0, uint32_t *s1)
|
void Card::getSerial(uint32_t* s0, uint32_t* s1)
|
||||||
{
|
{
|
||||||
uint32_t serial[8];
|
uint32_t serial[8];
|
||||||
for (uint32_t i = 0; i < 8; i++)
|
for (uint32_t i = 0; i < 8; i++)
|
||||||
@ -680,21 +669,21 @@ void Card::format(EDeviceId id, ECardSize size, EEncoding encoding)
|
|||||||
rand &= uint64_t(0x7fffULL);
|
rand &= uint64_t(0x7fffULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sramBias = int32_t(SBig(g_SRAM.counter_bias));
|
m_sramBias = int32_t(SBig(g_SRAM.counter_bias));
|
||||||
m_sramLanguage = uint32_t(SBig(g_SRAM.lang));
|
m_sramLanguage = uint32_t(SBig(g_SRAM.lang));
|
||||||
m_unknown = 0; /* 1 works for slot A, 0 both */
|
m_unknown = 0; /* 1 works for slot A, 0 both */
|
||||||
m_deviceId = 0;
|
m_deviceId = 0;
|
||||||
m_sizeMb = uint16_t(size);
|
m_sizeMb = uint16_t(size);
|
||||||
m_maxBlock = m_sizeMb * MbitToBlocks;
|
m_maxBlock = m_sizeMb * MbitToBlocks;
|
||||||
m_encoding = uint16_t(encoding);
|
m_encoding = uint16_t(encoding);
|
||||||
_updateChecksum();
|
_updateChecksum();
|
||||||
m_dir = Directory();
|
m_dir = Directory();
|
||||||
m_dirBackup = m_dir;
|
m_dirBackup = m_dir;
|
||||||
m_bat = BlockAllocationTable(uint32_t(size) * MbitToBlocks);
|
m_bat = BlockAllocationTable(uint32_t(size) * MbitToBlocks);
|
||||||
m_batBackup = m_bat;
|
m_batBackup = m_bat;
|
||||||
m_currentDir = &m_dirBackup;
|
m_currentDir = &m_dirBackup;
|
||||||
m_previousDir = &m_dir;
|
m_previousDir = &m_dir;
|
||||||
m_currentBat = &m_batBackup;
|
m_currentBat = &m_batBackup;
|
||||||
m_previousBat = &m_bat;
|
m_previousBat = &m_bat;
|
||||||
|
|
||||||
if (m_fileHandle)
|
if (m_fileHandle)
|
||||||
|
@ -2,14 +2,11 @@
|
|||||||
#include "kabufuda/Util.hpp"
|
#include "kabufuda/Util.hpp"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
void Directory::swapEndian()
|
void Directory::swapEndian()
|
||||||
{
|
{
|
||||||
std::for_each(std::begin(m_files), std::end(m_files), [](File& f){
|
std::for_each(std::begin(m_files), std::end(m_files), [](File& f) { f.swapEndian(); });
|
||||||
f.swapEndian();
|
|
||||||
});
|
|
||||||
|
|
||||||
m_updateCounter = SBig(m_updateCounter);
|
m_updateCounter = SBig(m_updateCounter);
|
||||||
m_checksum = SBig(m_checksum);
|
m_checksum = SBig(m_checksum);
|
||||||
@ -39,28 +36,17 @@ Directory::Directory()
|
|||||||
updateChecksum();
|
updateChecksum();
|
||||||
}
|
}
|
||||||
|
|
||||||
Directory::Directory(uint8_t data[])
|
Directory::Directory(uint8_t data[]) { memcpy(__raw, data, BlockSize); }
|
||||||
{
|
|
||||||
memcpy(__raw, data, BlockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
Directory::Directory(const Directory& other)
|
Directory::Directory(const Directory& other) { memcpy(__raw, other.__raw, BlockSize); }
|
||||||
{
|
|
||||||
memcpy(__raw, other.__raw, BlockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Directory::operator=(const Directory& other)
|
void Directory::operator=(const Directory& other) { memcpy(__raw, other.__raw, BlockSize); }
|
||||||
{
|
|
||||||
memcpy(__raw, other.__raw, BlockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
Directory::~Directory()
|
Directory::~Directory() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
File* Directory::getFirstFreeFile(const char* game, const char* maker, const char* filename)
|
File* Directory::getFirstFreeFile(const char* game, const char* maker, const char* filename)
|
||||||
{
|
{
|
||||||
for (uint16_t i = 0 ; i < 127 ; i++)
|
for (uint16_t i = 0; i < 127; i++)
|
||||||
{
|
{
|
||||||
if (m_files[i].m_game[0] == 0xFF)
|
if (m_files[i].m_game[0] == 0xFF)
|
||||||
{
|
{
|
||||||
@ -77,16 +63,18 @@ File* Directory::getFirstFreeFile(const char* game, const char* maker, const cha
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
File *Directory::getFirstNonFreeFile(uint32_t start, const char *game, const char *maker)
|
File* Directory::getFirstNonFreeFile(uint32_t start, const char* game, const char* maker)
|
||||||
{
|
{
|
||||||
for (uint16_t i = start ; i < 127 ; i++)
|
for (uint16_t i = start; i < 127; i++)
|
||||||
{
|
{
|
||||||
if (m_files[i].m_game[0] != 0xFF)
|
if (m_files[i].m_game[0] != 0xFF)
|
||||||
{
|
{
|
||||||
File* ret = &m_files[i];
|
File* ret = &m_files[i];
|
||||||
if (game && std::strlen(game) == 4 && std::strncmp(reinterpret_cast<const char*>(ret->m_game), game, 4) != 0)
|
if (game && std::strlen(game) == 4 &&
|
||||||
|
std::strncmp(reinterpret_cast<const char*>(ret->m_game), game, 4) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (maker && std::strlen(maker) == 2 && std::strncmp(reinterpret_cast<const char*>(ret->m_maker), maker, 2) != 0)
|
if (maker && std::strlen(maker) == 2 &&
|
||||||
|
std::strncmp(reinterpret_cast<const char*>(ret->m_maker), maker, 2) != 0)
|
||||||
continue;
|
continue;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -97,7 +85,7 @@ File *Directory::getFirstNonFreeFile(uint32_t start, const char *game, const cha
|
|||||||
|
|
||||||
File* Directory::getFile(const char* game, const char* maker, const char* filename)
|
File* Directory::getFile(const char* game, const char* maker, const char* filename)
|
||||||
{
|
{
|
||||||
for (uint16_t i = 0 ; i < 127 ; i++)
|
for (uint16_t i = 0; i < 127; i++)
|
||||||
{
|
{
|
||||||
if (game && strlen(game) == 4 && memcmp(m_files[i].m_game, game, 4))
|
if (game && strlen(game) == 4 && memcmp(m_files[i].m_game, game, 4))
|
||||||
continue;
|
continue;
|
||||||
@ -118,14 +106,13 @@ File* Directory::getFile(uint32_t idx)
|
|||||||
return &m_files[idx];
|
return &m_files[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Directory::indexForFile(File *f)
|
int32_t Directory::indexForFile(File* f)
|
||||||
{
|
{
|
||||||
if (!f)
|
if (!f)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
auto it = std::find_if(std::begin(m_files), std::end(m_files), [&f](const File& file)->bool{
|
auto it =
|
||||||
return f == &file;
|
std::find_if(std::begin(m_files), std::end(m_files), [&f](const File& file) -> bool { return f == &file; });
|
||||||
});
|
|
||||||
if (it == std::end(m_files))
|
if (it == std::end(m_files))
|
||||||
return -1;
|
return -1;
|
||||||
return it - std::begin(m_files);
|
return it - std::begin(m_files);
|
||||||
|
@ -3,15 +3,9 @@
|
|||||||
|
|
||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
File::File()
|
File::File() { memset(__raw, 0xFF, 0x40); }
|
||||||
{
|
|
||||||
memset(__raw, 0xFF, 0x40);
|
|
||||||
}
|
|
||||||
|
|
||||||
File::File(char data[])
|
File::File(char data[]) { memcpy(__raw, data, 0x40); }
|
||||||
{
|
|
||||||
memcpy(__raw, data, 0x40);
|
|
||||||
}
|
|
||||||
|
|
||||||
File::File(const char* filename)
|
File::File(const char* filename)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "kabufuda/SRAM.hpp"
|
#include "kabufuda/SRAM.hpp"
|
||||||
|
|
||||||
namespace kabufuda
|
namespace kabufuda
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
const SRAM g_SRAM =
|
const SRAM g_SRAM =
|
||||||
{{
|
{{
|
||||||
0xFF, 0x6B,
|
0xFF, 0x6B,
|
||||||
@ -26,7 +26,5 @@ const SRAM g_SRAM =
|
|||||||
0x00, 0x00,
|
0x00, 0x00,
|
||||||
0x00, 0x00
|
0x00, 0x00
|
||||||
}};
|
}};
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ namespace kabufuda
|
|||||||
uint64_t getGCTime()
|
uint64_t getGCTime()
|
||||||
{
|
{
|
||||||
time_t sysTime, tzDiff, tzDST;
|
time_t sysTime, tzDiff, tzDST;
|
||||||
struct tm * gmTime;
|
struct tm* gmTime;
|
||||||
|
|
||||||
time(&sysTime);
|
time(&sysTime);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user