diff --git a/CMakeLists.txt b/CMakeLists.txt index 91d26a9..6363173 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,8 +4,8 @@ project(kabufuda) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -include_directories(include) -set(KABUFUDA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "kabufuda include path" FORCE) +unset(KABUFUDA_INCLUDE_DIR CACHE) +#set(KABUFUDA_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE PATH "kabufuda include path" FORCE) unset(PLAT_SRCS) if(WIN32) @@ -25,5 +25,6 @@ add_library(kabufuda STATIC include/kabufuda/SRAM.hpp lib/kabufuda/SRAM.cpp include/kabufuda/WideStringConvert.hpp lib/kabufuda/WideStringConvert.cpp ${PLAT_SRCS}) +target_include_directories(kabufuda PUBLIC $) add_subdirectory(test) diff --git a/include/kabufuda/Card.hpp b/include/kabufuda/Card.hpp index 7bd549e..150da23 100644 --- a/include/kabufuda/Card.hpp +++ b/include/kabufuda/Card.hpp @@ -24,7 +24,7 @@ class FileHandle { public: FileHandle() = default; uint32_t getFileNo() const { return idx; } - operator bool() const { return getFileNo() != -1; } + operator bool() const { return getFileNo() != UINT32_MAX; } }; struct ProbeResults { diff --git a/include/kabufuda/Util.hpp b/include/kabufuda/Util.hpp index 4fc10b0..eb3d884 100644 --- a/include/kabufuda/Util.hpp +++ b/include/kabufuda/Util.hpp @@ -119,13 +119,15 @@ static inline int32_t SBig(int32_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 uint64_t SBig(uint64_t val) { return bswap64(val); } -static inline float SBig(float val) { - int32_t ival = bswap32(*((int32_t*)(&val))); - return *((float*)(&ival)); +inline float SBig(float val) { + union { float f; int32_t i; } uval1 = {val}; + union { int32_t i; float f; } uval2 = {bswap32(uval1.i)}; + return uval2.f; } -static inline double SBig(double val) { - int64_t ival = bswap64(*((int64_t*)(&val))); - return *((double*)(&ival)); +inline double SBig(double val) { + union { double f; int64_t i; } uval1 = {val}; + union { int64_t i; double f; } uval2 = {bswap64(uval1.i)}; + return uval2.f; } #ifndef SBIG #define SBIG(q) (((q)&0x000000FF) << 24 | ((q)&0x0000FF00) << 8 | ((q)&0x00FF0000) >> 8 | ((q)&0xFF000000) >> 24) diff --git a/lib/kabufuda/Card.cpp b/lib/kabufuda/Card.cpp index a07934d..41f5997 100644 --- a/lib/kabufuda/Card.cpp +++ b/lib/kabufuda/Card.cpp @@ -564,12 +564,12 @@ ECardResult Card::getStatus(uint32_t fileNo, CardStat& statOut) const { statOut.x36_iconSpeed = file->m_animSpeed; statOut.x38_commentAddr = file->m_commentAddr; - if (file->m_iconAddress == -1) { - statOut.x3c_offsetBanner = -1; - statOut.x40_offsetBannerTlut = -1; + if (file->m_iconAddress == UINT32_MAX) { + statOut.x3c_offsetBanner = UINT32_MAX; + statOut.x40_offsetBannerTlut = UINT32_MAX; for (int i = 0; i < CARD_ICON_MAX; ++i) - statOut.x44_offsetIcon[i] = -1; - statOut.x64_offsetIconTlut = -1; + statOut.x44_offsetIcon[i] = UINT32_MAX; + statOut.x64_offsetIconTlut = UINT32_MAX; statOut.x68_offsetData = file->m_commentAddr + 64; } else { uint32_t cur = file->m_iconAddress; @@ -589,7 +589,7 @@ ECardResult Card::getStatus(uint32_t fileNo, CardStat& statOut) const { statOut.x64_offsetIconTlut = cur; cur += TlutSize(EImageFormat::C8); } else - statOut.x64_offsetIconTlut = -1; + statOut.x64_offsetIconTlut = UINT32_MAX; statOut.x68_offsetData = cur; }