Big-endian support (#909)

This commit is contained in:
GaryOderNichts 2022-07-27 23:50:56 +02:00 committed by GitHub
commit 6818247317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 762 additions and 62 deletions

View file

@ -1,6 +1,8 @@
#ifndef COLOR_H
#define COLOR_H
#include "endianness.h"
typedef struct {
u8 r, g, b;
} Color_RGB8;
@ -12,7 +14,11 @@ typedef struct {
// only use when necessary for alignment purposes
typedef union {
struct {
#ifdef IS_BIGENDIAN
u8 r, g, b, a;
#else
u8 a, b, g, r;
#endif
};
u32 rgba;
} Color_RGBA8_u32;

View file

@ -6,6 +6,15 @@
* Each macro packs bytes (B), halfwords (H) and words (W, for consistency) into a single word
*/
#ifdef IS_BIGENDIAN
#define CMD_BBBB(a, b, c, d) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 8, 8) | _SHIFTL(d, 0, 8))
#define CMD_BBH(a, b, c) (_SHIFTL(a, 24, 8) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 0, 16))
#define CMD_HBB(a, b, c) (_SHIFTL(a, 16, 16) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 0, 8))
#define CMD_HH(a, b) (_SHIFTL(a, 16, 16) | _SHIFTL(b, 0, 16))
#else
#define CMD_BBBB(a, b, c, d) (_SHIFTL(a, 0, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 16, 8) | _SHIFTL(d, 24, 8))
#define CMD_BBH(a, b, c) (_SHIFTL(a, 0, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 16, 16))
@ -13,6 +22,7 @@
#define CMD_HBB(a, b, c) (_SHIFTL(a, 0, 16) | _SHIFTL(b, 16, 8) | _SHIFTL(c, 24, 8))
#define CMD_HH(a, b) (_SHIFTL(a, 0, 16) | _SHIFTL(b, 16, 16))
#endif
#define CMD_W(a) (a)

View file

@ -1,6 +1,8 @@
#ifndef MACROS_H
#define MACROS_H
#include "endianness.h"
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
@ -254,12 +256,5 @@ extern GraphicsContext* __gfxCtx;
#define SEG_ADDR(seg, addr) (addr | (seg << 24) | 1)
#ifdef _MSC_VER
#define BOMSWAP16 _byteswap_ushort
#define BOMSWAP32 _byteswap_ulong
#else
#define BOMSWAP16 __builtin_bswap16
#define BOMSWAP32 __builtin_bswap32
#endif
#endif

View file

@ -1,6 +1,8 @@
#ifndef Z64_AUDIO_H
#define Z64_AUDIO_H
#include "endianness.h"
#define MK_CMD(b0,b1,b2,b3) ((((b0) & 0xFF) << 0x18) | (((b1) & 0xFF) << 0x10) | (((b2) & 0xFF) << 0x8) | (((b3) & 0xFF) << 0))
#define NO_LAYER ((SequenceLayer*)(-1))
@ -685,6 +687,35 @@ typedef struct {
} AudioPreloadReq; // size = 0x14
typedef struct {
#ifdef IS_BIGENDIAN
union{
u32 opArgs;
struct {
u8 op;
u8 arg0;
u8 arg1;
u8 arg2;
};
};
union {
void* data;
f32 asFloat;
s32 asInt;
struct {
u16 asUShort;
u8 pad2[2];
};
struct {
s8 asSbyte;
u8 pad1[3];
};
struct {
u8 asUbyte;
u8 pad0[3];
};
u32 asUInt;
};
#else
union{
u32 opArgs;
struct {
@ -712,6 +743,7 @@ typedef struct {
};
u32 asUInt;
};
#endif
} AudioCmd;
typedef struct {