mirror of
https://github.com/AxioDL/kabufuda.git
synced 2025-07-03 03:35:54 +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;
|
||||
#pragma pack(push, 4)
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
uint16_t m_checksum;
|
||||
|
@ -22,8 +22,7 @@ public:
|
||||
class Card
|
||||
{
|
||||
#pragma pack(push, 4)
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
uint8_t m_serial[12];
|
||||
@ -63,6 +62,7 @@ class Card
|
||||
void _updateDirAndBat();
|
||||
void _updateChecksum();
|
||||
File* _fileFromHandle(const std::unique_ptr<IFileHandle>& fh) const;
|
||||
|
||||
public:
|
||||
Card();
|
||||
/**
|
||||
@ -355,7 +355,8 @@ public:
|
||||
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
|
||||
*/
|
||||
static uint32_t getSizeMbitFromFile(const SystemString& filename);
|
||||
@ -371,4 +372,3 @@ public:
|
||||
}
|
||||
|
||||
#endif // __CARD_HPP__
|
||||
|
||||
|
@ -25,7 +25,6 @@ enum class EPermissions : uint8_t
|
||||
};
|
||||
ENABLE_BITWISE_ENUM(EPermissions)
|
||||
|
||||
|
||||
enum class EImageFormat : uint8_t
|
||||
{
|
||||
None,
|
||||
|
@ -9,8 +9,7 @@ class Directory
|
||||
{
|
||||
friend class Card;
|
||||
#pragma pack(push, 4)
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
File m_files[MaxFiles];
|
||||
|
@ -11,8 +11,7 @@ class File
|
||||
friend class Directory;
|
||||
friend class Card;
|
||||
#pragma pack(push, 4)
|
||||
union
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
uint8_t m_game[4];
|
||||
@ -43,7 +42,6 @@ public:
|
||||
File(const char* filename);
|
||||
~File() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __KABU_FILE_HPP__
|
||||
|
@ -65,7 +65,6 @@ inline type operator~(const type& key)\
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace kabufuda
|
||||
{
|
||||
|
||||
@ -104,18 +103,13 @@ static inline T bswap64(T val)
|
||||
#elif _WIN32
|
||||
return _byteswap_uint64(val);
|
||||
#else
|
||||
return ((val & 0xFF00000000000000ULL) >> 56) |
|
||||
((val & 0x00FF000000000000ULL) >> 40) |
|
||||
((val & 0x0000FF0000000000ULL) >> 24) |
|
||||
((val & 0x000000FF00000000ULL) >> 8) |
|
||||
((val & 0x00000000FF000000ULL) << 8) |
|
||||
((val & 0x0000000000FF0000ULL) << 24) |
|
||||
((val & 0x000000000000FF00ULL) << 40) |
|
||||
((val & 0x00000000000000FFULL) << 56);
|
||||
return ((val & 0xFF00000000000000ULL) >> 56) | ((val & 0x00FF000000000000ULL) >> 40) |
|
||||
((val & 0x0000FF0000000000ULL) >> 24) | ((val & 0x000000FF00000000ULL) >> 8) |
|
||||
((val & 0x00000000FF000000ULL) << 8) | ((val & 0x0000000000FF0000ULL) << 24) |
|
||||
((val & 0x000000000000FF00ULL) << 40) | ((val & 0x00000000000000FFULL) << 56);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
static inline int16_t SBig(int16_t val) { return bswap16(val); }
|
||||
static inline uint16_t SBig(uint16_t val) { return bswap16(val); }
|
||||
@ -133,8 +127,7 @@ static inline double SBig(double val)
|
||||
int64_t ival = bswap64(*((int64_t*)(&val)));
|
||||
return *((double*)(&ival));
|
||||
}
|
||||
#define SBIG(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \
|
||||
| ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 )
|
||||
#define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
|
||||
|
||||
static inline int16_t SLittle(int16_t val) { return val; }
|
||||
static inline uint16_t SLittle(uint16_t val) { return val; }
|
||||
@ -162,8 +155,7 @@ static inline double SLittle(double val)
|
||||
int64_t ival = bswap64(*((int64_t*)(&val)));
|
||||
return *((double*)(&ival));
|
||||
}
|
||||
#define SLITTLE(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \
|
||||
| ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 )
|
||||
#define SLITTLE(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24)
|
||||
|
||||
static inline int16_t SBig(int16_t val) { return val; }
|
||||
static inline uint16_t SBig(uint16_t val) { return val; }
|
||||
@ -180,16 +172,14 @@ static inline double SBig(double val) {return val;}
|
||||
typedef wchar_t SystemChar;
|
||||
static inline size_t StrLen(const SystemChar* str) { return wcslen(str); }
|
||||
typedef std::wstring SystemString;
|
||||
static inline void ToLower(SystemString& str)
|
||||
{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 ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); }
|
||||
static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); }
|
||||
class SystemUTF8View
|
||||
{
|
||||
std::string m_utf8;
|
||||
|
||||
public:
|
||||
explicit SystemUTF8View(const SystemString& str)
|
||||
: m_utf8(WideToUTF8(str)) {}
|
||||
explicit SystemUTF8View(const SystemString& str) : m_utf8(WideToUTF8(str)) {}
|
||||
operator const std::string&() const { return m_utf8; }
|
||||
const std::string& str() const { return m_utf8; }
|
||||
const char* c_str() const { return m_utf8.c_str(); }
|
||||
@ -201,9 +191,9 @@ inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return
|
||||
class SystemStringView
|
||||
{
|
||||
std::wstring m_sys;
|
||||
|
||||
public:
|
||||
explicit SystemStringView(const std::string& str)
|
||||
: m_sys(UTF8ToWide(str)) {}
|
||||
explicit SystemStringView(const std::string& str) : m_sys(UTF8ToWide(str)) {}
|
||||
operator const std::wstring&() const { return m_sys; }
|
||||
const std::wstring& sys_str() const { return m_sys; }
|
||||
const SystemChar* c_str() const { return m_sys.c_str(); }
|
||||
@ -220,16 +210,14 @@ typedef struct _stat Sstat;
|
||||
typedef char SystemChar;
|
||||
static inline size_t StrLen(const SystemChar* str) { return strlen(str); }
|
||||
typedef std::string SystemString;
|
||||
static inline void ToLower(SystemString& str)
|
||||
{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 ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), tolower); }
|
||||
static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), toupper); }
|
||||
class SystemUTF8View
|
||||
{
|
||||
const std::string& m_utf8;
|
||||
|
||||
public:
|
||||
explicit SystemUTF8View(const SystemString& str)
|
||||
: m_utf8(str) {}
|
||||
explicit SystemUTF8View(const SystemString& str) : m_utf8(str) {}
|
||||
operator const std::string&() const { return m_utf8; }
|
||||
const std::string& str() const { return m_utf8; }
|
||||
const char* c_str() const { return m_utf8.c_str(); }
|
||||
@ -241,9 +229,9 @@ inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return
|
||||
class SystemStringView
|
||||
{
|
||||
const std::string& m_sys;
|
||||
|
||||
public:
|
||||
explicit SystemStringView(const std::string& str)
|
||||
: m_sys(str) {}
|
||||
explicit SystemStringView(const std::string& str) : m_sys(str) {}
|
||||
operator const std::string&() const { return m_sys; }
|
||||
const std::string& sys_str() const { return m_sys; }
|
||||
const SystemChar* c_str() const { return m_sys.c_str(); }
|
||||
@ -282,7 +270,8 @@ static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLo
|
||||
{
|
||||
#if _WIN32
|
||||
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
|
||||
if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB))
|
||||
fprintf(stderr, "flock %s: %s", path, strerror(errno));
|
||||
@ -327,7 +316,9 @@ static inline int Stat(const SystemChar* path, Sstat* statOut)
|
||||
{
|
||||
#if CARD_UCS2
|
||||
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':')
|
||||
{
|
||||
SystemChar fixPath[4] = {path[0], L':', L'/', L'\0'};
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include "kabufuda/Util.hpp"
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace kabufuda
|
||||
{
|
||||
void BlockAllocationTable::swapEndian()
|
||||
@ -12,9 +11,7 @@ void BlockAllocationTable::swapEndian()
|
||||
m_updateCounter = SBig(m_updateCounter);
|
||||
m_freeBlocks = SBig(m_freeBlocks);
|
||||
m_lastAllocated = SBig(m_lastAllocated);
|
||||
std::for_each(std::begin(m_map), std::end(m_map), [](uint16_t& val){
|
||||
val = SBig(val);
|
||||
});
|
||||
std::for_each(std::begin(m_map), std::end(m_map), [](uint16_t& val) { val = SBig(val); });
|
||||
}
|
||||
|
||||
void BlockAllocationTable::updateChecksum()
|
||||
@ -41,8 +38,7 @@ BlockAllocationTable::BlockAllocationTable(uint32_t blockCount)
|
||||
updateChecksum();
|
||||
}
|
||||
|
||||
BlockAllocationTable::~BlockAllocationTable()
|
||||
{}
|
||||
BlockAllocationTable::~BlockAllocationTable() {}
|
||||
|
||||
uint16_t BlockAllocationTable::getNextBlock(uint16_t block) const
|
||||
{
|
||||
|
@ -8,26 +8,21 @@
|
||||
namespace kabufuda
|
||||
{
|
||||
|
||||
IFileHandle::~IFileHandle()
|
||||
{
|
||||
}
|
||||
IFileHandle::~IFileHandle() {}
|
||||
|
||||
class FileHandle : public IFileHandle
|
||||
{
|
||||
friend class Card;
|
||||
uint32_t idx;
|
||||
int32_t offset = 0;
|
||||
|
||||
public:
|
||||
FileHandle() = default;
|
||||
FileHandle(uint32_t idx)
|
||||
: idx(idx)
|
||||
{}
|
||||
FileHandle(uint32_t idx) : idx(idx) {}
|
||||
virtual ~FileHandle();
|
||||
};
|
||||
|
||||
FileHandle::~FileHandle()
|
||||
{}
|
||||
|
||||
FileHandle::~FileHandle() {}
|
||||
|
||||
void Card::_swapEndian()
|
||||
{
|
||||
@ -43,10 +38,7 @@ void Card::_swapEndian()
|
||||
m_checksumInv = SBig(m_checksumInv);
|
||||
}
|
||||
|
||||
Card::Card()
|
||||
{
|
||||
memset(__raw, 0xFF, BlockSize);
|
||||
}
|
||||
Card::Card() { memset(__raw, 0xFF, BlockSize); }
|
||||
|
||||
Card::Card(const Card& other)
|
||||
{
|
||||
@ -59,8 +51,7 @@ Card::Card(const Card& other)
|
||||
memcpy(m_maker, other.m_maker, 2);
|
||||
}
|
||||
|
||||
Card::Card(const SystemString& filename, const char* game, const char* maker)
|
||||
: m_filename(filename)
|
||||
Card::Card(const SystemString& filename, const char* game, const char* maker) : m_filename(filename)
|
||||
{
|
||||
memset(__raw, 0xFF, BlockSize);
|
||||
if (game && strlen(game) == 4)
|
||||
@ -188,7 +179,6 @@ std::unique_ptr<IFileHandle> Card::createFile(const char* filename, size_t size)
|
||||
f->m_firstBlock = block;
|
||||
f->m_blockCount = uint16_t(size / BlockSize);
|
||||
|
||||
|
||||
return std::unique_ptr<IFileHandle>(new FileHandle(m_currentDir->indexForFile(f)));
|
||||
}
|
||||
return nullptr;
|
||||
@ -239,7 +229,6 @@ void Card::deleteFile(const std::unique_ptr<IFileHandle>& fh)
|
||||
block = nextBlock;
|
||||
}
|
||||
*m_currentDir->getFile(f->idx) = File();
|
||||
|
||||
}
|
||||
|
||||
void Card::write(const std::unique_ptr<IFileHandle>& fh, const void* buf, size_t size)
|
||||
|
@ -2,14 +2,11 @@
|
||||
#include "kabufuda/Util.hpp"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace kabufuda
|
||||
{
|
||||
void Directory::swapEndian()
|
||||
{
|
||||
std::for_each(std::begin(m_files), std::end(m_files), [](File& f){
|
||||
f.swapEndian();
|
||||
});
|
||||
std::for_each(std::begin(m_files), std::end(m_files), [](File& f) { f.swapEndian(); });
|
||||
|
||||
m_updateCounter = SBig(m_updateCounter);
|
||||
m_checksum = SBig(m_checksum);
|
||||
@ -39,24 +36,13 @@ Directory::Directory()
|
||||
updateChecksum();
|
||||
}
|
||||
|
||||
Directory::Directory(uint8_t data[])
|
||||
{
|
||||
memcpy(__raw, data, BlockSize);
|
||||
}
|
||||
Directory::Directory(uint8_t data[]) { memcpy(__raw, data, BlockSize); }
|
||||
|
||||
Directory::Directory(const Directory& other)
|
||||
{
|
||||
memcpy(__raw, other.__raw, BlockSize);
|
||||
}
|
||||
Directory::Directory(const Directory& other) { memcpy(__raw, other.__raw, BlockSize); }
|
||||
|
||||
void Directory::operator=(const Directory& other)
|
||||
{
|
||||
memcpy(__raw, other.__raw, BlockSize);
|
||||
}
|
||||
void Directory::operator=(const Directory& other) { memcpy(__raw, other.__raw, BlockSize); }
|
||||
|
||||
Directory::~Directory()
|
||||
{
|
||||
}
|
||||
Directory::~Directory() {}
|
||||
|
||||
File* Directory::getFirstFreeFile(const char* game, const char* maker, const char* filename)
|
||||
{
|
||||
@ -84,9 +70,11 @@ File *Directory::getFirstNonFreeFile(uint32_t start, const char *game, const cha
|
||||
if (m_files[i].m_game[0] != 0xFF)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
return ret;
|
||||
}
|
||||
@ -123,9 +111,8 @@ int32_t Directory::indexForFile(File *f)
|
||||
if (!f)
|
||||
return -1;
|
||||
|
||||
auto it = std::find_if(std::begin(m_files), std::end(m_files), [&f](const File& file)->bool{
|
||||
return f == &file;
|
||||
});
|
||||
auto it =
|
||||
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))
|
||||
return -1;
|
||||
return it - std::begin(m_files);
|
||||
|
@ -3,15 +3,9 @@
|
||||
|
||||
namespace kabufuda
|
||||
{
|
||||
File::File()
|
||||
{
|
||||
memset(__raw, 0xFF, 0x40);
|
||||
}
|
||||
File::File() { memset(__raw, 0xFF, 0x40); }
|
||||
|
||||
File::File(char data[])
|
||||
{
|
||||
memcpy(__raw, data, 0x40);
|
||||
}
|
||||
File::File(char data[]) { memcpy(__raw, data, 0x40); }
|
||||
|
||||
File::File(const char* filename)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "kabufuda/SRAM.hpp"
|
||||
|
||||
namespace kabufuda
|
||||
{
|
||||
// clang-format off
|
||||
const SRAM g_SRAM =
|
||||
{{
|
||||
0xFF, 0x6B,
|
||||
@ -26,7 +26,5 @@ const SRAM g_SRAM =
|
||||
0x00, 0x00,
|
||||
0x00, 0x00
|
||||
}};
|
||||
|
||||
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user