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