From bd9ac204c2cb95427c49d655b35921fb2d2da67b Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Wed, 20 Nov 2019 22:40:03 +0200 Subject: [PATCH] Allow SameBoy to compile on 4-byte-bools platforms --- Core/gb.c | 11 +++++++++-- Core/gb.h | 4 ---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Core/gb.c b/Core/gb.c index 93ac9d7..f29d400 100644 --- a/Core/gb.c +++ b/Core/gb.c @@ -18,6 +18,13 @@ #define GB_rewind_push(...) #endif + +static inline uint32_t state_magic(void) +{ + if (sizeof(bool) == 1) return 'SAME'; + return 'S4ME'; +} + void GB_attributed_logv(GB_gameboy_t *gb, GB_log_attributes attributes, const char *fmt, va_list args) { char *string = NULL; @@ -660,7 +667,7 @@ void GB_disconnect_serial(GB_gameboy_t *gb) bool GB_is_inited(GB_gameboy_t *gb) { - return gb->magic == 'SAME'; + return gb->magic == state_magic(); } bool GB_is_cgb(GB_gameboy_t *gb) @@ -929,7 +936,7 @@ void GB_reset(GB_gameboy_t *gb) gb->nontrivial_jump_state = NULL; } - gb->magic = (uintptr_t)'SAME'; + gb->magic = state_magic(); } void GB_switch_model_and_reset(GB_gameboy_t *gb, GB_model_t model) diff --git a/Core/gb.h b/Core/gb.h index dbd9e16..a561111 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -278,10 +278,6 @@ typedef struct { This struct is not packed, but dumped sections exclusively use types that have the same alignment in both 32 and 64 bit platforms. */ -/* We make sure bool is 1 for cross-platform save state compatibility. */ -/* Todo: We might want to typedef our own bool if this prevents SameBoy from working on specific platforms. */ -_Static_assert(sizeof(bool) == 1, "sizeof(bool) != 1"); - #ifdef GB_INTERNAL struct GB_gameboy_s { #else