New code style refactor

This commit is contained in:
Jack Andersen 2018-12-07 19:18:17 -10:00
parent e1b29fda7a
commit 7243c687a8
123 changed files with 15125 additions and 18399 deletions

View File

@ -5,54 +5,51 @@
#include <wiiuse/wpad.h>
#endif
static void *xfb = nullptr;
static void* xfb = nullptr;
static GXRModeObj* rmode = nullptr;
#endif
#include <athena/MemoryReader.hpp>
int main()
{
int main() {
#if GEKKO
VIDEO_Init();
VIDEO_Init();
#if HW_RVL
WPAD_Init();
WPAD_Init();
#endif
PAD_Init();
PAD_Init();
rmode = VIDEO_GetPreferredMode(nullptr);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
rmode = VIDEO_GetPreferredMode(nullptr);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
CON_Init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
CON_EnableGecko(CARD_SLOTB, true);
CON_Init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ);
CON_EnableGecko(CARD_SLOTB, true);
VIDEO_Configure(rmode);
VIDEO_SetBlack(false);
VIDEO_Configure(rmode);
VIDEO_SetBlack(false);
VIDEO_Flush();
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE)
VIDEO_WaitVSync();
athena::io::MemoryCopyReader test("sd:/test.dat");
while(true)
{
athena::io::MemoryCopyReader test("sd:/test.dat");
while (true) {
#if HW_RVL
WPAD_ScanPads();
WPAD_ScanPads();
#endif
PAD_ScanPads();
if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
break;
PAD_ScanPads();
if (PAD_ButtonsDown(0) & PAD_BUTTON_START)
break;
#if HW_RVL
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
break;
if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
break;
#endif
VIDEO_WaitVSync();
}
VIDEO_WaitVSync();
}
#endif
return 0;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -3,22 +3,21 @@
#define EXPECTED_BYTES 281
int main(int argc, const char** argv)
{
TESTFile<atUint32, 2> file = {};
file.arrCount[0] = 2;
file.array.push_back(42);
file.array.push_back(64);
size_t binSize = 0;
file.binarySize(binSize);
athena::io::MemoryCopyWriter w(nullptr, binSize);
atInt64 pos = w.position();
file.write(w);
bool pass = !w.hasError() && w.position() - pos == binSize && binSize == EXPECTED_BYTES;
if (pass)
printf("[PASS] %" PRISize " bytes written\n", size_t(w.position() - pos));
else
printf("[FAIL] %" PRISize " bytes written; %" PRISize " bytes sized; %d bytes expected\n",
size_t(w.position() - pos), binSize, EXPECTED_BYTES);
return pass ? 0 : 1;
int main(int argc, const char** argv) {
TESTFile<atUint32, 2> file = {};
file.arrCount[0] = 2;
file.array.push_back(42);
file.array.push_back(64);
size_t binSize = 0;
file.binarySize(binSize);
athena::io::MemoryCopyWriter w(nullptr, binSize);
atInt64 pos = w.position();
file.write(w);
bool pass = !w.hasError() && w.position() - pos == binSize && binSize == EXPECTED_BYTES;
if (pass)
printf("[PASS] %" PRISize " bytes written\n", size_t(w.position() - pos));
else
printf("[FAIL] %" PRISize " bytes written; %" PRISize " bytes sized; %d bytes expected\n",
size_t(w.position() - pos), binSize, EXPECTED_BYTES);
return pass ? 0 : 1;
}

View File

@ -3,87 +3,71 @@
using namespace athena;
typedef io::DNA<Big> BigDNA;
enum ETest : atUint8
{
ZERO,
ONE,
TWO,
THREE
};
enum ETest : atUint8 { ZERO, ONE, TWO, THREE };
template <ETest EVal>
struct AT_SPECIALIZE_PARMS(ETest::ZERO, ETest::ONE, ETest::TWO, ETest::THREE)
TESTSubFile : public BigDNA
{
AT_DECL_DNA
Value<ETest> varE = EVal;
Value<atUint32> sub1;
Value<atUint32> sub2;
struct AT_SPECIALIZE_PARMS(ETest::ZERO, ETest::ONE, ETest::TWO, ETest::THREE) TESTSubFile : public BigDNA {
AT_DECL_DNA
Value<ETest> varE = EVal;
Value<atUint32> sub1;
Value<atUint32> sub2;
};
struct TESTSubClassFile : public TESTSubFile<ETest::ONE>
{
AT_DECL_DNA
Value<atUint32> sub3;
Value<atUint16> sub4;
struct TESTSubClassFile : public TESTSubFile<ETest::ONE> {
AT_DECL_DNA
Value<atUint32> sub3;
Value<atUint16> sub4;
};
struct TESTSubSubClassFile : public TESTSubClassFile
{
AT_DECL_DNA
Value<atUint32> sub5;
Value<atUint32> sub6;
struct TESTSubSubClassFile : public TESTSubClassFile {
AT_DECL_DNA
Value<atUint32> sub5;
Value<atUint32> sub6;
};
template <class Var32Tp, int Var32Val>
struct AT_SPECIALIZE_PARMS(atUint16, 42, atUint32, 87, atUint32, 2)
TESTFile : public BigDNA
{
struct AT_SPECIALIZE_PARMS(atUint16, 42, atUint32, 87, atUint32, 2) TESTFile : public BigDNA {
AT_DECL_DNA
Value<bool> varBool;
AT_OVERRIDE_RCRC32(12345678) Value<Var32Tp> x4_var32 = Var32Val;
AT_OVERRIDE_RCRC32(deadbabe) Value<atUint16> x8_var16;
Value<atVec3f> vec3;
Value<atVec4f> vec4;
struct TESTNestedSubFile : public BigDNA {
AT_DECL_DNA
Value<bool> varBool;
AT_OVERRIDE_RCRC32(12345678) Value<Var32Tp> x4_var32 = Var32Val;
AT_OVERRIDE_RCRC32(deadbabe) Value<atUint16> x8_var16;
Value<atVec3f> vec3;
Value<atVec4f> vec4;
Value<atUint32> nestSub1;
Value<atUint32> nestSub2;
} nestedSubFile;
struct TESTNestedSubFile : public BigDNA
{
AT_DECL_DNA
Value<atUint32> nestSub1;
Value<atUint32> nestSub2;
} nestedSubFile;
using TESTSubFileUsing = TESTSubFile<ETest::TWO>;
TESTSubFileUsing subFile;
using TESTSubFileUsing = TESTSubFile<ETest::TWO>;
TESTSubFileUsing subFile;
Align<4> align;
Align<4> align;
template <class NestedTp, int NestedVal>
struct AT_SPECIALIZE_PARMS(atInt32, 36, atInt64, 96) TESTTemplateSubFile : public BigDNA {
AT_DECL_DNA
Value<NestedTp> explSub1 = NestedVal;
Value<Var32Tp> explSub2 = Var32Val;
};
Value<TESTTemplateSubFile<atInt32, 36>> nestedTemplate1;
Value<TESTTemplateSubFile<atInt64, 96>> nestedTemplate2;
template <class NestedTp, int NestedVal>
struct AT_SPECIALIZE_PARMS(atInt32, 36, atInt64, 96)
TESTTemplateSubFile : public BigDNA
{
AT_DECL_DNA
Value<NestedTp> explSub1 = NestedVal;
Value<Var32Tp> explSub2 = Var32Val;
};
Value<TESTTemplateSubFile<atInt32, 36>> nestedTemplate1;
Value<TESTTemplateSubFile<atInt64, 96>> nestedTemplate2;
Value<atUint32, Little> arrCount[2];
Vector<atUint32, AT_DNA_COUNT(arrCount[0])> array;
Value<atUint32, Little> arrCount[2];
Vector<atUint32, AT_DNA_COUNT(arrCount[0])> array;
Value<atUint32> arrAltCount;
Vector<atUint32, AT_DNA_COUNT(arrAltCount)> arrayAlt;
Value<atUint32> arrAltCount;
Vector<atUint32, AT_DNA_COUNT(arrAltCount)> arrayAlt;
Seek<21, Current> seek;
Seek<21, Current> seek;
Value<atUint32> arrCount2;
Vector<TESTSubFile<ETest::ZERO>, AT_DNA_COUNT(arrCount[1] + arrCount2)> array2;
Value<atUint32> arrCount2;
Vector<TESTSubFile<ETest::ZERO>, AT_DNA_COUNT(arrCount[1] + arrCount2)> array2;
Value<atUint32> bufSz;
Buffer<AT_DNA_COUNT(bufSz)> buf;
Value<atUint32> bufSz;
Buffer<AT_DNA_COUNT(bufSz)> buf;
String<32> str;
WString<64> wstr;
String<32> str;
WString<64> wstr;
};

View File

@ -3,40 +3,38 @@
#include <string>
#include "LZ77/LZLookupTable.hpp"
class LZBase
{
class LZBase {
public:
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3, atInt32 blockSize = 8);
virtual ~LZBase() {}
explicit LZBase(atInt32 minimumOffset = 1, atInt32 slidingWindow = 4096, atInt32 minimumMatch = 3,
atInt32 blockSize = 8);
virtual ~LZBase() {}
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow();
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer();
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch();
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize();
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset();
virtual atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
virtual atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength) = 0;
void setSlidingWindow(atInt32 SlidingWindow);
atInt32 slidingWindow();
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
atInt32 readAheadBuffer();
void setMinMatch(atInt32 minimumMatch);
atInt32 minMatch();
void setBlockSize(atInt32 BlockSize);
atInt32 blockSize();
void setMinimumOffset(atUint32 minimumOffset);
atUint32 minimumOffset();
private:
atInt32 subMatch(const atUint8* str1, const uint8_t* str2, const atInt32 len);
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr,
atUint8* startLBPtr);
atInt32 subMatch(const atUint8* str1, const uint8_t* str2, const atInt32 len);
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr, atUint8* startLBPtr);
protected:
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;
atInt32 m_minMatch;//Minimum number of bytes that have to matched to go through with compression
atInt32 m_blockSize;
atUint32 m_minOffset;
LZLookupTable m_lookupTable;
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
atInt32 m_slidingWindow;
atInt32 m_readAheadBuffer;
atInt32 m_minMatch; // Minimum number of bytes that have to matched to go through with compression
atInt32 m_blockSize;
atUint32 m_minOffset;
LZLookupTable m_lookupTable;
};

View File

@ -6,32 +6,25 @@
#include <cstdint>
#include <athena/Types.hpp>
struct LZLengthOffset
{
atUint32 length;//The number of bytes compressed
atUint16 offset;//How far back in sliding window where bytes that match the lookAheadBuffer is located
bool compare_equal(const LZLengthOffset& lo_pair)
{
return length == lo_pair.length && offset == lo_pair.offset;
}
struct LZLengthOffset {
atUint32 length; // The number of bytes compressed
atUint16 offset; // How far back in sliding window where bytes that match the lookAheadBuffer is located
bool compare_equal(const LZLengthOffset& lo_pair) { return length == lo_pair.length && offset == lo_pair.offset; }
};
class LZLookupTable
{
class LZLookupTable {
public:
LZLookupTable();
LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
~LZLookupTable();
LZLengthOffset search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
void setLookAheadWindow(atInt32 lookAheadWindow);
LZLookupTable();
LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18);
~LZLookupTable();
LZLengthOffset search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
void setLookAheadWindow(atInt32 lookAheadWindow);
private:
typedef std::multimap<std::vector<uint8_t>, int32_t> LookupTable;
LookupTable table;
atInt32 m_minimumMatch;
atInt32 m_slidingWindow;
atInt32 m_lookAheadWindow;
std::vector<uint8_t> m_buffer;
typedef std::multimap<std::vector<uint8_t>, int32_t> LookupTable;
LookupTable table;
atInt32 m_minimumMatch;
atInt32 m_slidingWindow;
atInt32 m_lookAheadWindow;
std::vector<uint8_t> m_buffer;
};

View File

@ -2,11 +2,10 @@
#include "LZBase.hpp"
class LZType10 : public LZBase
{
class LZType10 : public LZBase {
public:
explicit LZType10(atInt32 minimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3, atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen);
explicit LZType10(atInt32 minimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dst, atUint32 srcLen);
};

View File

@ -1,14 +1,11 @@
#pragma once
#include "LZBase.hpp"
class LZType11 : public LZBase
{
class LZType11 : public LZBase {
public:
explicit LZType11(atInt32 MinimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3, atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength);
explicit LZType11(atInt32 MinimumOffset = 1, atInt32 SlidingWindow = 4096, atInt32 MinimumMatch = 3,
atInt32 BlockSize = 8);
atUint32 compress(const atUint8* src, atUint8** dest, atUint32 srcLength);
atUint32 decompress(const atUint8* src, atUint8** dest, atUint32 srcLength);
};

View File

@ -4,19 +4,16 @@
#include <cstdlib>
#include <memory>
namespace athena
{
namespace athena {
class IAES
{
class IAES {
public:
virtual ~IAES() {}
virtual void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
virtual void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len)=0;
virtual void setKey(const uint8_t* key)=0;
virtual ~IAES() {}
virtual void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len) = 0;
virtual void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, uint64_t len) = 0;
virtual void setKey(const uint8_t* key) = 0;
};
std::unique_ptr<IAES> NewAES();
}
} // namespace athena

View File

@ -2,92 +2,56 @@
#include "Types.hpp"
namespace athena
{
namespace athena {
enum BowType : char
{
BowNone,
BowArrows,
BowSilverArrows
enum BowType : char { BowNone, BowArrows, BowSilverArrows };
enum BoomerangType : char { BoomerangNone, BoomerangBlue, BoomerangRed };
enum MagicType : char { MagicNone, MagicMushroom, MagicPowder };
enum ArmorType : char { GreenJerkin, BlueMail, RedMail };
enum BottleType : char {
BottleNone,
BottleMushroom, // No Use
BottleEmpty,
BottleRedPotion,
BottleBluePotion,
BottleFairy,
BottleBee,
BottleGoodBee
};
enum BoomerangType : char
{
BoomerangNone,
BoomerangBlue,
BoomerangRed
enum ALTTPStartLocation { LinksHouse = 0x00, Sanctuary = 0x01, Any = 0x05 };
enum ALTTPProgressIndicator { LinkInBed, InCastleWithSword, CompletedFirstDungeon, BeatenAghanim };
enum ALTTPMapIcon {
Nothing = 0x00, //?
CrossInKakariko = 0x01, //?
CrossAtFirstDungeon = 0x02, //
Pendant = 0x03,
MasterSword = 0x04,
AganhimCastle = 0x05,
Crystal1 = 0x06,
AllCrystals = 0x07,
AganhimGanonTower = 0x08
};
enum MagicType : char
{
MagicNone,
MagicMushroom,
MagicPowder
enum ALTTPTagAlong {
Noone,
Zelda,
Unknown1,
Oldman,
ZeldaMessage,
Blind,
DwarfFrog,
DwarfLW,
Kiki,
Unknown2,
TheifsChest,
AfterBoss
};
enum ArmorType : char
{
GreenJerkin,
BlueMail,
RedMail
};
enum BottleType : char
{
BottleNone,
BottleMushroom, // No Use
BottleEmpty,
BottleRedPotion,
BottleBluePotion,
BottleFairy,
BottleBee,
BottleGoodBee
};
enum ALTTPStartLocation
{
LinksHouse = 0x00,
Sanctuary = 0x01,
Any = 0x05
};
enum ALTTPProgressIndicator
{
LinkInBed,
InCastleWithSword,
CompletedFirstDungeon,
BeatenAghanim
};
enum ALTTPMapIcon
{
Nothing = 0x00, //?
CrossInKakariko = 0x01, //?
CrossAtFirstDungeon = 0x02, //
Pendant = 0x03,
MasterSword = 0x04,
AganhimCastle = 0x05,
Crystal1 = 0x06,
AllCrystals = 0x07,
AganhimGanonTower = 0x08
};
enum ALTTPTagAlong
{
Noone,
Zelda,
Unknown1,
Oldman,
ZeldaMessage,
Blind,
DwarfFrog,
DwarfLW,
Kiki,
Unknown2,
TheifsChest,
AfterBoss
};
} // zelda
} // namespace athena

View File

@ -3,8 +3,7 @@
#include "athena/Global.hpp"
#include <vector>
namespace athena
{
namespace athena {
class ALTTPQuest;
@ -14,61 +13,58 @@ class ALTTPQuest;
* Contains all relevant data for an A Link to the Past
* SRM file.
*/
class ALTTPFile
{
class ALTTPFile {
public:
/*! \brief Quest Iterator
*
* An Iterator typedef for iterating through the Quest lists
*/
typedef std::vector<ALTTPQuest*>::iterator QuestIter;
/*! \brief Quest Iterator
*
* An Iterator typedef for iterating through the Quest lists
*/
typedef std::vector<ALTTPQuest*>::iterator QuestIter;
/*! \brief Default constructor
*
*
*/
ALTTPFile();
/*! \brief Default constructor
*
*
*/
ALTTPFile();
/*! \brief Constructor
*
* \param questList The primary quest list
* \param backupList The backup quest list
*/
ALTTPFile(std::vector<ALTTPQuest*> questList, std::vector<ALTTPQuest*> backupList);
/*! \brief Constructor
*
* \param questList The primary quest list
* \param backupList The backup quest list
*/
ALTTPFile(std::vector<ALTTPQuest*> questList, std::vector<ALTTPQuest*> backupList);
/*! \brief Sets a quest at the given index
*
* \param id Index to the given quest
* \param val The new quest to assign to the given index
* \throw InvalidOperationException on index out of range
*/
void setQuest(atUint32 id, ALTTPQuest* val);
/*! \brief Returns the primary quest list
*
* \return The primary quest list
*/
std::vector<ALTTPQuest*> questList() const;
/*! \brief Sets a quest at the given index
*
* \param id Index to the given quest
* \param val The new quest to assign to the given index
* \throw InvalidOperationException on index out of range
*/
void setQuest(atUint32 id, ALTTPQuest* val);
/*! \brief Returns the primary quest list
*
* \return The primary quest list
*/
std::vector<ALTTPQuest*> questList() const;
/*! \brief Returns a quest at the given index
*
* Returns a quest at the given index
*
* \return ALTTPQuest*
* \throw InvalidOperationException on index out of range
*/
ALTTPQuest* quest(atUint32 id) const;
/*! \brief Returns a quest at the given index
*
* Returns a quest at the given index
*
* \return ALTTPQuest*
* \throw InvalidOperationException on index out of range
*/
ALTTPQuest* quest(atUint32 id) const;
/*! \brief Returns the number of primary quests
*
* \return The number of quests
*/
atUint32 questCount() const;
/*! \brief Returns the number of primary quests
*
* \return The number of quests
*/
atUint32 questCount() const;
private:
std::vector<ALTTPQuest*> m_quests;
std::vector<ALTTPQuest*> m_backup;
std::vector<ALTTPQuest*> m_quests;
std::vector<ALTTPQuest*> m_backup;
};
} // zelda
} // namespace athena

View File

@ -5,12 +5,10 @@
#include "athena/MemoryReader.hpp"
#include "athena/ALTTPQuest.hpp"
namespace athena
{
namespace athena {
class ALTTPFile;
namespace io
{
namespace io {
/*! \class ALTTPFileReader
* \brief A Link to the Past save data reader class
*
@ -18,32 +16,32 @@ namespace io
* all work is done using a memory buffer, and not read directly from the disk.
* \sa BinaryReader
*/
class ALTTPFileReader : protected MemoryCopyReader
{
class ALTTPFileReader : protected MemoryCopyReader {
public:
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileReader(atUint8*, atUint64);
/*! \brief This constructor takes an existing buffer to read from.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileReader(atUint8*, atUint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileReader(const std::string&);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileReader(const std::string&);
/*! \brief Reads the SRAM data from the buffer
*
* \return ALTTPFile* SRAM data
*/
ALTTPFile* readFile();
/*! \brief Reads the SRAM data from the buffer
*
* \return ALTTPFile* SRAM data
*/
ALTTPFile* readFile();
private:
ALTTPRoomFlags* readRoomFlags();
ALTTPOverworldEvent* readOverworldEvent();
ALTTPDungeonItemFlags readDungeonFlags();
ALTTPRoomFlags* readRoomFlags();
ALTTPOverworldEvent* readOverworldEvent();
ALTTPDungeonItemFlags readDungeonFlags();
};
} // io
} // zelda
} // namespace io
} // namespace athena

View File

@ -4,12 +4,10 @@
#include "athena/MemoryWriter.hpp"
#include "athena/ALTTPQuest.hpp"
namespace athena
{
namespace athena {
class ALTTPFile;
namespace io
{
namespace io {
/*! \class ALTTPFileWriter
* \brief A Link to the Past save data writer class
*
@ -17,35 +15,33 @@ namespace io
* all work is done using a memory buffer, and not written directly to the disk.
* \sa BinaryReader
*/
class ALTTPFileWriter : protected MemoryCopyWriter
{
class ALTTPFileWriter : protected MemoryCopyWriter {
public:
/*! \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileWriter(atUint8*, atUint64);
/*! \brief This constructor takes an existing buffer to write to.
*
* \param data The existing buffer
* \param length The length of the existing buffer
*/
ALTTPFileWriter(atUint8*, atUint64);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileWriter(const std::string&);
/*! \brief This constructor creates an instance from a file on disk.
*
* \param filename The file to create the stream from
*/
ALTTPFileWriter(const std::string&);
/*! \brief Writes the given SRAM data to a file on disk
*
* \param file SRAM data to right
*/
void writeFile(ALTTPFile* file);
/*! \brief Writes the given SRAM data to a file on disk
*
* \param file SRAM data to right
*/
void writeFile(ALTTPFile* file);
private:
void writeRoomFlags(ALTTPRoomFlags*);
void writeOverworldEvent(ALTTPOverworldEvent*);
void writeDungeonItems(ALTTPDungeonItemFlags);
atUint16 calculateChecksum(atUint32 game);
void writeRoomFlags(ALTTPRoomFlags*);
void writeOverworldEvent(ALTTPOverworldEvent*);
void writeDungeonItems(ALTTPDungeonItemFlags);
atUint16 calculateChecksum(atUint32 game);
};
} // io
} // zelda
} // namespace io
} // namespace athena

File diff suppressed because it is too large Load Diff

View File

@ -3,196 +3,176 @@
#include <string>
#include "athena/Types.hpp"
namespace athena
{
namespace athena {
struct ALTTPRoomFlags
{
bool Chest1: 1;
bool Chest2: 1;
bool Chest3: 1;
bool Chest4: 1;
bool Quadrant1: 1;
bool Quadrant2: 1;
bool Quadrant3: 1;
bool Quadrant4: 1;
bool Door1: 1;
bool Door2: 1;
bool Door3: 1;
bool Door4: 1;
bool BossBattleWon: 1;
bool Key: 1;
bool KeyOrChest: 1;
bool ChestOrTile: 1;
struct ALTTPRoomFlags {
bool Chest1 : 1;
bool Chest2 : 1;
bool Chest3 : 1;
bool Chest4 : 1;
bool Quadrant1 : 1;
bool Quadrant2 : 1;
bool Quadrant3 : 1;
bool Quadrant4 : 1;
bool Door1 : 1;
bool Door2 : 1;
bool Door3 : 1;
bool Door4 : 1;
bool BossBattleWon : 1;
bool Key : 1;
bool KeyOrChest : 1;
bool ChestOrTile : 1;
};
struct ALTTPOverworldEvent
{
bool Unused1: 1;
bool HeartPiece: 1;
bool Overlay: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Set: 1;
bool Unused5: 1;
struct ALTTPOverworldEvent {
bool Unused1 : 1;
bool HeartPiece : 1;
bool Overlay : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Set : 1;
bool Unused5 : 1;
};
struct ALTTPInventory
{
char Bow;
char Boomerang;
bool Hookshot;
char Bombs; // Bomb count
char Magic;
bool FireRod;
bool IceRod;
bool Bombos;
bool Ether;
bool Quake;
bool Torch;
bool Hammer;
char Flute;
bool BugNet;
bool Book;
bool Bottles;
bool Somaria;
bool Byrna;
bool MagicCape;
char MagicMirror;
char Gloves;
char Boots;
bool Flippers;
bool MoonPearl;
char Unused; //?
char Sword;
char Shield;
char Armor;
char BottleTypes[4];
struct ALTTPInventory {
char Bow;
char Boomerang;
bool Hookshot;
char Bombs; // Bomb count
char Magic;
bool FireRod;
bool IceRod;
bool Bombos;
bool Ether;
bool Quake;
bool Torch;
bool Hammer;
char Flute;
bool BugNet;
bool Book;
bool Bottles;
bool Somaria;
bool Byrna;
bool MagicCape;
char MagicMirror;
char Gloves;
char Boots;
bool Flippers;
bool MoonPearl;
char Unused; //?
char Sword;
char Shield;
char Armor;
char BottleTypes[4];
};
/*! \struct ALTTPLightDarkWorldIndicator
*/
struct ALTTPLightDarkWorldIndicator
{
bool Unused1: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Unused5: 1;
bool Unused6: 1;
bool IsDarkWorld: 1;
bool Unused7: 1;
struct ALTTPLightDarkWorldIndicator {
bool Unused1 : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Unused5 : 1;
bool Unused6 : 1;
bool IsDarkWorld : 1;
bool Unused7 : 1;
};
struct ALTTPDungeonItemFlags
{
union
{
struct
{
bool Unused1: 1;
bool Unused2: 1;
bool GanonsTower: 1;
bool TurtleRock: 1;
bool GargoylesDomain: 1;
bool TowerOfHera: 1;
bool IcePalace: 1;
bool SkullWoods: 1;
};
atUint8 flags1;
struct ALTTPDungeonItemFlags {
union {
struct {
bool Unused1 : 1;
bool Unused2 : 1;
bool GanonsTower : 1;
bool TurtleRock : 1;
bool GargoylesDomain : 1;
bool TowerOfHera : 1;
bool IcePalace : 1;
bool SkullWoods : 1;
};
atUint8 flags1;
};
union
{
struct
{
bool MiseryMire: 1;
bool DarkPalace: 1;
bool SwampPalace: 1;
bool HyruleCastle2: 1; // unused in orignal game
bool DesertPalace: 1;
bool EasternPalace: 1;
bool HyruleCastle: 1; // unused exist in original game
bool SewerPassage: 1; // unused exist in original game
};
atUint8 flags2;
union {
struct {
bool MiseryMire : 1;
bool DarkPalace : 1;
bool SwampPalace : 1;
bool HyruleCastle2 : 1; // unused in orignal game
bool DesertPalace : 1;
bool EasternPalace : 1;
bool HyruleCastle : 1; // unused exist in original game
bool SewerPassage : 1; // unused exist in original game
};
atUint8 flags2;
};
};
struct ALTTPPendants
{
bool Courage: 1;
bool Wisdom: 1;
bool Power: 1;
bool Unused1: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Unused5: 1;
struct ALTTPPendants {
bool Courage : 1;
bool Wisdom : 1;
bool Power : 1;
bool Unused1 : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Unused5 : 1;
};
struct ALTTPAbilities
{
bool Nothing: 1; //?
bool Swim: 1;
bool Dash: 1;
bool Pull: 1;
bool Unknown1: 1; //---
bool Talk: 1;
bool Read: 1;
bool Unknown2: 1; //---
struct ALTTPAbilities {
bool Nothing : 1; //?
bool Swim : 1;
bool Dash : 1;
bool Pull : 1;
bool Unknown1 : 1; //---
bool Talk : 1;
bool Read : 1;
bool Unknown2 : 1; //---
};
struct ALTTPCrystals
{
bool MiseryMire: 1;
bool DarkPalace: 1;
bool IcePalace: 1;
bool TurtleRock: 1;
bool SwampPalace: 1;
bool GargoyleDomain: 1;
bool SkullWoods: 1;
struct ALTTPCrystals {
bool MiseryMire : 1;
bool DarkPalace : 1;
bool IcePalace : 1;
bool TurtleRock : 1;
bool SwampPalace : 1;
bool GargoyleDomain : 1;
bool SkullWoods : 1;
};
struct ALTTPMagicUsage
{
bool Normal: 1;
bool Half: 1;
bool Quarter: 1;
bool Unused1: 1;
bool Unused2: 1;
bool Unused3: 1;
bool Unused4: 1;
bool Unused5: 1;
struct ALTTPMagicUsage {
bool Normal : 1;
bool Half : 1;
bool Quarter : 1;
bool Unused1 : 1;
bool Unused2 : 1;
bool Unused3 : 1;
bool Unused4 : 1;
bool Unused5 : 1;
};
struct ALTTPProgressFlags1
{
bool UncleSecretPassage: 1;
bool DyingPriest: 1; //?
bool ZeldaSanctuary: 1; //?
bool Unused1: 1;
bool UncleLeftHouse: 1;
bool BookOfMudora: 1; //? Math says it's a guess need to investigate
bool DwarfPartner: 1; //?
bool Unused2: 1;
struct ALTTPProgressFlags1 {
bool UncleSecretPassage : 1;
bool DyingPriest : 1; //?
bool ZeldaSanctuary : 1; //?
bool Unused1 : 1;
bool UncleLeftHouse : 1;
bool BookOfMudora : 1; //? Math says it's a guess need to investigate
bool DwarfPartner : 1; //?
bool Unused2 : 1;
};
struct ALTTPProgressFlags2
{
bool BottleFromBum: 1;
bool BottleFromSalesMen: 1;
bool Unused1: 1; //?
bool FluteBoy: 1;
bool ThiefsChest: 1;
bool SavedSmithPartner: 1;
bool Unused2: 1; //?
bool SmithsHaveSword: 1;
struct ALTTPProgressFlags2 {
bool BottleFromBum : 1;
bool BottleFromSalesMen : 1;
bool Unused1 : 1; //?
bool FluteBoy : 1;
bool ThiefsChest : 1;
bool SavedSmithPartner : 1;
bool Unused2 : 1; //?
bool SmithsHaveSword : 1;
};
}
} // namespace athena

View File

@ -2,10 +2,10 @@
#include "athena/Global.hpp"
namespace athena::checksums
{
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed = 0xFFFFFFFFFFFFFFFF, atUint64 final = 0xFFFFFFFFFFFFFFFF);
namespace athena::checksums {
atUint64 crc64(const atUint8* data, atUint64 length, atUint64 seed = 0xFFFFFFFFFFFFFFFF,
atUint64 final = 0xFFFFFFFFFFFFFFFF);
atUint32 crc32(const atUint8* data, atUint64 length, atUint32 seed = 0xFFFFFFFF, atUint32 final = 0xFFFFFFFF);
atUint16 crc16CCITT(const atUint8* data, atUint64 length, atUint16 seed = 0xFFFF, atUint16 final = 0);
atUint16 crc16(const atUint8* data, atUint64 length, atUint16 seed = 0, atUint16 final = 0);
}
} // namespace athena::checksums

View File

@ -2,196 +2,161 @@
#include <cstdint>
namespace athena::checksums::literals
{
namespace athena::checksums::literals {
constexpr uint32_t crc32_table[] =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
constexpr uint32_t crc32_table[] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A,
0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3,
0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4,
0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950,
0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074,
0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525,
0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615,
0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76,
0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E,
0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6,
0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7,
0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278,
0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC,
0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330,
0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D};
template <uint32_t CRC, char... Chars>
struct Crc32Impl {};
template <uint32_t CRC, char Head, char... Tail>
struct Crc32Impl<CRC, Head, Tail...> {
static constexpr uint32_t value =
Crc32Impl<crc32_table[static_cast<unsigned char>(CRC) ^ static_cast<unsigned char>(Head)] ^ (CRC >> 8),
Tail...>::value;
};
template<uint32_t CRC, char ...Chars> struct Crc32Impl {
template <uint32_t CRC>
struct Crc32Impl<CRC> {
static constexpr uint32_t value = CRC ^ 0xFFFFFFFF;
};
template<uint32_t CRC, char Head, char ...Tail> struct Crc32Impl<CRC, Head, Tail...> {
static constexpr uint32_t value = Crc32Impl<
crc32_table[static_cast<unsigned char>(CRC) ^ static_cast<unsigned char>(Head)]
^ (CRC >> 8), Tail...>::value;
};
template <char... Chars>
using Crc32 = Crc32Impl<0xFFFFFFFF, Chars...>;
template<uint32_t CRC> struct Crc32Impl<CRC> {
static constexpr uint32_t value = CRC ^ 0xFFFFFFFF;
};
template<char ...Chars> using Crc32 = Crc32Impl<0xFFFFFFFF, Chars...>;
constexpr uint32_t crc32_rec(uint32_t crc, const char *s) {
return *s == 0 ? crc ^ 0xFFFFFFFF :
crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^
static_cast<unsigned char>(*s)]
^ (crc >> 8), s + 1);
constexpr uint32_t crc32_rec(uint32_t crc, const char* s) {
return *s == 0 ? crc ^ 0xFFFFFFFF
: crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^ static_cast<unsigned char>(*s)] ^ (crc >> 8),
s + 1);
}
constexpr uint32_t operator "" _crc32(const char *s, size_t len) {
return crc32_rec(0xFFFFFFFF, s);
constexpr uint32_t operator"" _crc32(const char* s, size_t len) { return crc32_rec(0xFFFFFFFF, s); }
static_assert("Hello"_crc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value, "CRC32 values don't match");
static_assert("0"_crc32 == Crc32<'0'>::value, "CRC32 values don't match");
constexpr uint32_t rcrc32_rec(uint32_t crc, const char* s) {
return *s == 0 ? crc
: crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^ static_cast<unsigned char>(*s)] ^ (crc >> 8),
s + 1);
}
static_assert("Hello"_crc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value,
"CRC32 values don't match");
static_assert("0"_crc32 == Crc32<'0'>::value,
"CRC32 values don't match");
constexpr uint32_t operator"" _rcrc32(const char* s, size_t len) { return rcrc32_rec(0xFFFFFFFF, s); }
static_assert("Hello"_rcrc32 == Crc32<'H', 'e', 'l', 'l', 'o'>::value, "CRC32 values don't match");
static_assert("0"_rcrc32 == Crc32<'0'>::value, "CRC32 values don't match");
constexpr uint32_t rcrc32_rec(uint32_t crc, const char *s) {
return *s == 0 ? crc :
crc32_rec(crc32_table[static_cast<unsigned char>(crc) ^
static_cast<unsigned char>(*s)]
^ (crc >> 8), s + 1);
}
constexpr uint64_t crc64_table[] = {
0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF,
0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A, 0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D,
0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847,
0x1C4488F3E8F96ED4, 0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A,
0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285, 0xF45BB4758C645C51,
0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D,
0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B, 0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8,
0x0B6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF,
0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A, 0xAA478900B1228E31, 0xE8B768EB18C8B8A2,
0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8,
0x2465CD79455E395B, 0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A,
0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5, 0xDA050215EA6C212F,
0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63,
0x16D7A787B7FAA0D6, 0x5427466C1E109645, 0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7,
0x8F72ECA30CD7A324, 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F,
0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA, 0x2E5EB66066087D7E, 0x6CAE578BCFE24BED,
0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87,
0xA07CF2199274CA14, 0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144,
0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B, 0x84193F60D72AF34F,
0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903,
0x48CB9AF28ABC72B6, 0x0A3B7B1923564425, 0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238,
0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F,
0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA, 0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E,
0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534,
0x78D8A1B9894EC3A7, 0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6,
0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19, 0x90C79D3FEDD3F122,