Merge pull request #44 from skylersaleh/macos_fixes

Work around compilation errors on macOS
This commit is contained in:
wheremyfoodat 2023-06-19 00:06:10 +03:00 committed by GitHub
commit c042dbc293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 117 deletions

View file

@ -1,6 +1,6 @@
#pragma once
#include <cstdarg>
#include <climits>
#include <cstdarg>
#include <cstdint>
#include <fstream>
#include <iostream>
@ -8,8 +8,16 @@
#include <type_traits>
#include <utility>
#include <vector>
#include "termcolor.hpp"
// We have to detect and special-case AppleClang at the moment since its C++20 support is finicky and doesn't quite support std::bit_cast
#if defined(__clang__) && defined(__apple_build_version__)
#define HELPERS_APPLE_CLANG
#else
#include <bit>
#endif
using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
@ -45,15 +53,12 @@ namespace Helpers {
static std::vector<u8> loadROM(std::string directory) {
std::ifstream file(directory, std::ios::binary);
if (file.fail())
panic("Couldn't read %s", directory.c_str());
if (file.fail()) panic("Couldn't read %s", directory.c_str());
std::vector<u8> ROM;
file.unsetf(std::ios::skipws);
ROM.insert(ROM.begin(),
std::istream_iterator<uint8_t>(file),
std::istream_iterator<uint8_t>());
ROM.insert(ROM.begin(), std::istream_iterator<uint8_t>(file), std::istream_iterator<uint8_t>());
file.close();
@ -65,7 +70,6 @@ namespace Helpers {
#ifdef NDEBUG
return false;
#endif
return true;
}
@ -117,9 +121,7 @@ namespace Helpers {
}
/// Check if a bit "bit" of value is set
static constexpr bool isBitSet (u32 value, int bit) {
return (value >> bit) & 1;
}
static constexpr bool isBitSet(u32 value, int bit) { return (value >> bit) & 1; }
/// rotate number right
template <typename T>
@ -149,23 +151,25 @@ namespace Helpers {
}
// For values < 0x99
static constexpr inline u8 incBCDByte(u8 value) {
return ((value & 0xf) == 0x9) ? value + 7 : value + 1;
static constexpr inline u8 incBCDByte(u8 value) { return ((value & 0xf) == 0x9) ? value + 7 : value + 1; }
#ifdef HELPERS_APPLE_CLANG
template <class To, class From>
constexpr To bit_cast(const From& from) noexcept {
return *reinterpret_cast<const To*>(&from);
}
};
#else
template <class To, class From>
constexpr To bit_cast(const From& from) noexcept {
return std::bit_cast<To, From>(from);
}
#endif
}; // namespace Helpers
// UDLs for memory size values
constexpr size_t operator""_KB(unsigned long long int x) {
return 1024ULL * x;
}
constexpr size_t operator""_MB(unsigned long long int x) {
return 1024_KB * x;
}
constexpr size_t operator""_GB(unsigned long long int x) {
return 1024_MB * x;
}
constexpr size_t operator""_KB(unsigned long long int x) { return 1024ULL * x; }
constexpr size_t operator""_MB(unsigned long long int x) { return 1024_KB * x; }
constexpr size_t operator""_GB(unsigned long long int x) { return 1024_MB * x; }
// useful macros
// likely/unlikely

View file

@ -1,3 +1,4 @@
#include <bit>
#include <cassert>
#include <cstring>

View file

@ -73,7 +73,7 @@ void CFGService::getConfigInfoBlk2(u32 messagePointer) {
};
for (int i = 0; i < 8; i++) {
mem.write32(output + i * 4, std::bit_cast<u32, float>(STEREO_CAMERA_SETTINGS[i]));
mem.write32(output + i * 4, Helpers::bit_cast<u32, float>(STEREO_CAMERA_SETTINGS[i]));
}
} else if (size == 0x1C && blockID == 0xA0000) { // Username
writeStringU16(output, u"Pander");

View file

@ -83,7 +83,7 @@ void HIDService::getGyroscopeCoefficient(u32 messagePointer) {
constexpr float gyroscopeCoeff = 14.375f; // Same as retail 3DS
mem.write32(messagePointer, IPC::responseHeader(0x15, 2, 0));
mem.write32(messagePointer + 4, Result::Success);
mem.write32(messagePointer + 8, std::bit_cast<u32, float>(gyroscopeCoeff));
mem.write32(messagePointer + 8, Helpers::bit_cast<u32, float>(gyroscopeCoeff));
}
void HIDService::getIPCHandles(u32 messagePointer) {