mirror of
https://github.com/zeldaret/mm.git
synced 2026-07-07 04:54:55 -04:00
01a6dea813
* git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "e02e151c" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e02e151c" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/decomp-permuter --force subrepo: subdir: "tools/decomp-permuter" merged: "86b1975e" upstream: origin: "https://github.com/simonlindholm/decomp-permuter.git" branch: "main" commit: "86b1975e" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/graphovl --force subrepo: subdir: "tools/graphovl" merged: "eb25be94" upstream: origin: "https://github.com/AngheloAlf/graphovl.git" branch: "master" commit: "eb25be94" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull (merge) tools/z64compress --force subrepo: subdir: "tools/z64compress" merged: "98ef0ac2" upstream: origin: "https://github.com/z64me/z64compress.git" branch: "main" commit: "98ef0ac2" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "45cb0d6b" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "45cb0d6b" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/asm-differ --force subrepo: subdir: "tools/asm-differ" merged: "48e675ff" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "main" commit: "48e675ff" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "3c00dcb3" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "3c00dcb3" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/asm-differ --force subrepo: subdir: "tools/asm-differ" merged: "47c94c99" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "main" commit: "47c94c99" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Declare required textures * Name texture, add decomp.me permuter settings * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "913810fc" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "913810fc" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/asm-differ --force subrepo: subdir: "tools/asm-differ" merged: "97197f2a" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "main" commit: "97197f2a" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/ZAPD --force subrepo: subdir: "tools/ZAPD" merged: "623d779f" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "623d779f" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/asm-differ --force subrepo: subdir: "tools/asm-differ" merged: "55bba23a" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "main" commit: "55bba23a" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull tools/decomp-permuter --force subrepo: subdir: "tools/decomp-permuter" merged: "a20bac94" upstream: origin: "https://github.com/simonlindholm/decomp-permuter.git" branch: "main" commit: "a20bac94" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596"
162 lines
6.1 KiB
C++
162 lines
6.1 KiB
C++
#pragma once
|
|
|
|
#include <limits>
|
|
#include <stdint.h>
|
|
#include <vector>
|
|
|
|
class BitConverter
|
|
{
|
|
public:
|
|
static inline int8_t ToInt8BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return (uint8_t)data[offset + 0];
|
|
}
|
|
|
|
static inline int8_t ToInt8BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return (uint8_t)data[offset + 0];
|
|
}
|
|
|
|
static inline uint8_t ToUInt8BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return (uint8_t)data[offset + 0];
|
|
}
|
|
|
|
static inline uint8_t ToUInt8BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return (uint8_t)data[offset + 0];
|
|
}
|
|
|
|
static inline int16_t ToInt16BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
|
|
}
|
|
|
|
static inline int16_t ToInt16BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
|
|
}
|
|
|
|
static inline uint16_t ToUInt16BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
|
|
}
|
|
|
|
static inline uint16_t ToUInt16BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
|
|
}
|
|
|
|
static inline int32_t ToInt32BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
|
|
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
|
|
}
|
|
|
|
static inline int32_t ToInt32BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
|
|
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
|
|
}
|
|
|
|
static inline uint32_t ToUInt32BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
|
|
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
|
|
}
|
|
|
|
static inline uint32_t ToUInt32BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
|
|
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
|
|
}
|
|
|
|
static inline int64_t ToInt64BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
|
|
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
|
|
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
|
|
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
|
|
}
|
|
|
|
static inline int64_t ToInt64BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
|
|
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
|
|
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
|
|
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
|
|
}
|
|
|
|
static inline uint64_t ToUInt64BE(const uint8_t* data, int32_t offset)
|
|
{
|
|
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
|
|
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
|
|
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
|
|
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
|
|
}
|
|
|
|
static inline uint64_t ToUInt64BE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
|
|
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
|
|
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
|
|
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
|
|
}
|
|
|
|
static inline float ToFloatBE(const uint8_t* data, int32_t offset)
|
|
{
|
|
float value;
|
|
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) +
|
|
((uint32_t)data[offset + 1] << 16) +
|
|
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
|
|
static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float");
|
|
std::memcpy(&value, &floatData, sizeof(value));
|
|
return value;
|
|
}
|
|
|
|
static inline float ToFloatBE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
float value;
|
|
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) +
|
|
((uint32_t)data[offset + 1] << 16) +
|
|
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
|
|
static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float");
|
|
std::memcpy(&value, &floatData, sizeof(value));
|
|
return value;
|
|
}
|
|
|
|
static inline double ToDoubleBE(const uint8_t* data, int32_t offset)
|
|
{
|
|
double value;
|
|
uint64_t floatData =
|
|
((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
|
|
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
|
|
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
|
|
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
|
|
static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double");
|
|
// Checks if the float format on the platform the ZAPD binary is running on supports the
|
|
// same float format as the object file.
|
|
static_assert(std::numeric_limits<float>::is_iec559,
|
|
"expected IEC559 floats on host machine");
|
|
std::memcpy(&value, &floatData, sizeof(value));
|
|
return value;
|
|
}
|
|
|
|
static inline double ToDoubleBE(const std::vector<uint8_t>& data, int32_t offset)
|
|
{
|
|
double value;
|
|
uint64_t floatData =
|
|
((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
|
|
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
|
|
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
|
|
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
|
|
static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double");
|
|
// Checks if the float format on the platform the ZAPD binary is running on supports the
|
|
// same float format as the object file.
|
|
static_assert(std::numeric_limits<double>::is_iec559,
|
|
"expected IEC559 doubles on host machine");
|
|
std::memcpy(&value, &floatData, sizeof(value));
|
|
return value;
|
|
}
|
|
};
|