From 36895ee3b6ba3513a96dc901bee199bfdd9d01d7 Mon Sep 17 00:00:00 2001 From: PJB3005 Date: Tue, 24 Feb 2026 16:29:00 +0100 Subject: [PATCH] Add template-based BE(T) endianness conversion helper types Doesn't require modification at the call sites thanks to the implicit conversion operator. --- include/dusk/endian.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/dusk/endian.h b/include/dusk/endian.h index 25e5df70ff..6623f2f0b2 100644 --- a/include/dusk/endian.h +++ b/include/dusk/endian.h @@ -54,4 +54,41 @@ static inline s32 RES_S32(s32 v) { #define RES_S32(x) (x) #endif +#ifdef TARGET_PC + +/* + * Declares a big-endian integer type. + */ +template +struct BE { + T inner; + operator T() const; +}; + +template<> +inline BE::operator u16() const { + return RES_U16(inner); +} + +template<> +inline BE::operator s16() const { + return RES_S16(inner); +} + +template<> +inline BE::operator u32() const { + return RES_U32(inner); +} + +template<> +inline BE::operator s32() const { + return RES_S32(inner); +} + +#define BE(T) BE +#else +#define BE(T) T +#endif + + #endif // DOLPHIN_ENDIAN_H