Implement all of emu64, mostly matching

This commit is contained in:
Cuyler36
2024-07-26 14:37:51 -04:00
parent c60b001aa2
commit 35089a48e4
11 changed files with 5951 additions and 750 deletions
+37 -10
View File
@@ -7,13 +7,15 @@
extern "C" {
#endif
#define MTX_PS
/////////////// TYPE DEFINES ///////////////
#define MTXDegToRad(a) ((a)*0.01745329252f)
#define MTXDegToRad(a) ((a) * 0.01745329252f)
typedef struct {
f32 x;
f32 y;
f32 z;
f32 x;
f32 y;
f32 z;
} Vec;
typedef f32 Mtx34[3][4];
@@ -25,7 +27,7 @@ typedef f32 PSQuaternion[4];
typedef Mtx34 GC_Mtx; // TODO: fix this
typedef struct Quaternion {
f32 x, y, z, w;
f32 x, y, z, w;
} Quaternion;
////////////////////////////////////////////
@@ -50,6 +52,9 @@ void PSMTXScale(GC_Mtx mtx, f32 xS, f32 yS, f32 zS);
void PSMTXScaleApply(const GC_Mtx src, GC_Mtx dest, f32 xS, f32 yS, f32 zS);
void PSMTXQuat(GC_Mtx mtx, const PSQuaternion* quat);
void PSVECNormalize(const Vec* src, Vec* dst);
void PSMTXMultVec(const GC_Mtx m, const Vec* src, Vec* dst);
////////////////////////////////////////////
//// PAIRED SINGLE MATRIX VEC FUNCTIONS ////
@@ -72,15 +77,37 @@ void C_MTXLightOrtho(GC_Mtx mtx, f32 t, f32 b, f32 l, f32 r, f32 scaleS, f32 sca
////////////////////////////////////////////
////////////// MATRIX INLINES //////////////
static inline void MTXSetPosition(GC_Mtx mtx, const Vec* pos)
{
mtx[0][3] = pos->x;
mtx[1][3] = pos->y;
mtx[2][3] = pos->z;
static inline void MTXSetPosition(GC_Mtx mtx, const Vec* pos) {
mtx[0][3] = pos->x;
mtx[1][3] = pos->y;
mtx[2][3] = pos->z;
}
////////////////////////////////////////////
#ifdef MTX_PS
#define MTXIdentity PSMTXIdentity
#define MTXCopy PSMTXCopy
#define MTXConcat PSMTXConcat
#define MTXConcatArray PSMTXConcatArray
#define MTXTranspose PSMTXTranspose
#define MTXInverse PSMTXInverse
#define MTXInvXpose PSMTXInvXpose
#define MTXScale PSMTXScale
#define MTXTrans PSMTXTrans
#define MTXMultVec PSMTXMultVec
#else
#define MTXIdentity C_MTXIdentity
#define MTXCopy C_MTXCopy
#define MTXConcat C_MTXConcat
#define MTXConcatArray C_MTXConcatArray
#define MTXTranspose C_MTXTranspose
#define MTXInverse C_MTXInverse
#define MTXInvXpose C_MTXInvXpose
#endif
#ifdef __cplusplus
}
#endif
+16
View File
@@ -99,6 +99,22 @@ static inline void OSf32tos8(f32* f, s8* out) {
*out = __OSf32tos8(*f);
}
static inline float __OSs16tof32(register s16* s) {
register float f;
#ifdef __MWERKS__ // clang-format off
asm {
psq_l f, 0(s), 1, 5
}
#endif // clang-format on
return f;
}
static inline void OSs16tof32(register s16* s, volatile register f32* f) {
*f = __OSs16tof32(s);
}
//////////////////////////////////
#ifdef __cplusplus
File diff suppressed because it is too large Load Diff
+2
View File
@@ -8,6 +8,8 @@
extern "C" {
#endif
extern u8 FrameCansel;
extern void emu64_set_ucode_info(int count, ucode_info* ucode_info);
extern void emu64_set_first_ucode(void* ucode);
extern void emu64_taskstart(Gfx* gfx);
+13 -16
View File
@@ -7,12 +7,12 @@
#ifdef __cplusplus
extern "C" {
#define TEX_CACHE_ALIGNMENT (32-1) /* 32 byte alignment */
#define TEX_CACHE_ALIGNMENT (32 - 1) /* 32 byte alignment */
#define NUM_TEXTURE_CACHE_DATA 10
#define TEXTURE_CACHE_LIST_SIZE 256
#define TMEM_ENTRIES 128
#define TEX_CACHE_ALIGN(n)((n + TEX_CACHE_ALIGNMENT) & ~TEX_CACHE_ALIGNMENT)
#define TEX_CACHE_ALIGN(n) ((n + TEX_CACHE_ALIGNMENT) & ~TEX_CACHE_ALIGNMENT)
/* These would be initialized by the linker. TODO: Is there a better way to do this? */
extern void* _data_segment_start;
@@ -22,16 +22,16 @@ typedef struct {
void* addr;
Gloadblock loadblock;
Gloadtile loadtile;
Gsetimg_new setimg;
Gsetimg2 setimg2;
} tmem_t;
typedef struct {
void* start; /* Start RAM address of cache */
void* end; /* End RAM address of cache */
void* end; /* End RAM address of cache */
} texture_cache_data_entry_t;
typedef struct {
void* original; /* Original RAM address */
void* original; /* Original RAM address */
void* converted; /* Converted RAM address */
} texture_cache_entry_t;
@@ -49,19 +49,17 @@ typedef struct {
typedef struct texture_cache_s {
texture_cache_funcs* funcs; /* Pointer to texture cache funcs */
u8* buffer_start; /* Start address of cache buffer */
u8* buffer_end; /* End address of cache buffer */
u8* buffer_current; /* Current write position of the cache buffer */
u8* last_alloc_end; /* Points to end address from last cache alloc */
u8* last_alloc_start; /* Points to the start address from last cache alloc */
bool is_overflow; /* Set to true when the cache is full */
u32 buffer_pos; /* Write index into cache buffer */
u8* buffer_start; /* Start address of cache buffer */
u8* buffer_end; /* End address of cache buffer */
u8* buffer_current; /* Current write position of the cache buffer */
u8* last_alloc_end; /* Points to end address from last cache alloc */
u8* last_alloc_start; /* Points to the start address from last cache alloc */
bool is_overflow; /* Set to true when the cache is full */
u32 buffer_pos; /* Write index into cache buffer */
} texture_cache_t;
/* TMEM map */
//static tmem_t tmem_map[TMEM_ENTRIES];
// static tmem_t tmem_map[TMEM_ENTRIES];
/* Shared alloc function */
void* texture_cache_alloc(texture_cache_t* cache, u32 size);
@@ -74,7 +72,6 @@ int texture_cache_data_entry(void* original, void* converted);
#define TEX_BUFFER_BSS_SIZE 0x1000
extern texture_cache_t* texture_cache_select(void* address);
}
#endif
+261 -7
View File
@@ -98,7 +98,7 @@ extern "C" {
#define G_DECAL_EQUAL 0x20
#define G_DECAL_ALWAYS 0x30
#define G_DECAL_SPECIAL 0x40
#define G_DECAL_ALL G_DECAL_ALWAYS | G_DECAL_SPECIAL
#define G_DECAL_ALL (G_DECAL_ALWAYS | G_DECAL_SPECIAL)
/* Indicies for G_SPECIAL_1 */
#define G_SPECIAL_NONE 0
@@ -192,7 +192,7 @@ extern "C" {
#define COMBINER_TEV_GET_Ad1(words)((words.w0 >> 0) & 7)
typedef struct {
int cmd:8;
unsigned int cmd:8;
unsigned int a0:4;
unsigned int c0:5;
unsigned int Aa0:3;
@@ -273,12 +273,12 @@ typedef struct {
unsigned int sl:14; /* Start of S coordinate */
unsigned int slen:10; /* Length of S coordinate */
unsigned int isDolphin:1; /* If true, format is Gsettilesize_dolphin. If false, format is Gsettilesize2 */
s8 isDolphin:1; /* If true, format is Gsettilesize_Dolphin. If false, format is Gsettilesize2 */
unsigned int pad:4;
unsigned int tile:3; /* Tile descriptor */
unsigned int tl:14; /* Start of T coordinate */
unsigned int tlen:10; /* Length of T coordinate */
} Gsettilesize_dolphin;
} Gsettilesize_Dolphin;
typedef struct {
int cmd:8; /* Command */
@@ -314,8 +314,9 @@ typedef struct {
unsigned int level:3;
unsigned int tile:3;
unsigned int on:8; /* Should be 7 bits w/ 1 bit padding, but emulator doesn't do this */
unsigned short s:16;
unsigned short t:16;
unsigned short s;
unsigned short t;
} Gtexture_internal;
typedef struct {
@@ -334,6 +335,229 @@ typedef struct {
unsigned int data;
} Gmovemem;
typedef struct Gsettexedgealpha {
unsigned int cmd:8;
unsigned int unused0:24;
unsigned int unused1:24;
unsigned int tex_edge_alpha:8;
} Gsettexedgealpha;
typedef struct {
int cmd:8;
unsigned int x0:10;
unsigned int x0frac:2;
unsigned int y0:10;
unsigned int y0frac:2;
unsigned int pad:8;
unsigned int x1:10;
unsigned int x1frac:2;
unsigned int y1:10;
unsigned int y1frac:2;
} Gscissor;
typedef struct {
int cmd:8;
unsigned int x0:10;
unsigned int x0frac:2;
unsigned int y0:10;
unsigned int y0frac:2;
unsigned int pad:8;
unsigned int x1:10;
unsigned int x1frac:2;
unsigned int y1:10;
unsigned int y1frac:2;
} Gfillrect2;
typedef struct Gnoop {
unsigned int cmd: 8;
unsigned int tag: 8;
unsigned int param0: 16;
unsigned int param1;
} Gnoop;
typedef struct Gmtx {
unsigned int cmd: 8;
unsigned int par: 8;
unsigned int pad: 8;
unsigned int type: 8;
unsigned int addr;
} Gmtx;
typedef struct Gvtx {
unsigned int cmd: 8;
unsigned int pad0: 4;
unsigned int n: 8;
unsigned int pad1: 4;
unsigned int vn:8;
unsigned int addr;
} Gvtx;
typedef struct Gline3D_new {
unsigned int cmd: 8;
unsigned int v0: 8;
unsigned int v1: 8;
unsigned int wd: 8;
unsigned int pad;
} Gline3D_new;
typedef struct Gtri1 {
unsigned int cmd: 8;
unsigned int v0: 8;
unsigned int v1: 8;
unsigned int v2: 8;
unsigned int pad;
} Gtri1;
typedef struct Gtri2 {
int cmd: 8;
unsigned int t0v0: 8;
unsigned int t0v1: 8;
unsigned int t0v2: 8;
unsigned int pad: 8;
unsigned int t1v0: 8;
unsigned int t1v1: 8;
unsigned int t1v2: 8;
} Gtri2;
typedef struct Gtrin_independ {
unsigned int cmd: 8; // 32
unsigned int count: 7; // 24
unsigned int f2v2: 5; // 17
unsigned int f2v1: 5; // 12
unsigned int f2v0: 5; // 7
unsigned int f1v2_1: 2; // 2
unsigned int f1v2_0: 3; // 32
unsigned int f1v1: 5; // 29
unsigned int f1v0: 5; // 24
unsigned int f0v2: 5; // 19
unsigned int f0v1: 5; // 14
unsigned int f0v0: 5; // 9
unsigned int pad: 3; // 4
unsigned int is7bit: 1; // 1
} Gtrin_independ;
typedef struct Gtrin {
unsigned int f3v2: 5; // 32
unsigned int f3v1: 5; // 27
unsigned int f3v0: 5; // 22
unsigned int f2v2: 5; // 17
unsigned int f2v1: 5; // 12
unsigned int f2v0: 5; // 7
unsigned int f1v2_1: 2; // 2
unsigned int f1v2_0: 3; // 32
unsigned int f1v1: 5; // 29
unsigned int f1v0: 5; // 24
unsigned int f0v2: 5; // 19
unsigned int f0v1: 5; // 14
unsigned int f0v0: 5; // 9
unsigned int pad: 3; // 32
unsigned int is7bit: 1; // 1
} Gtrin;
typedef struct Gtrin_7b {
unsigned int f2v2: 7; // 32
unsigned int f2v1: 7; // 25
unsigned int f2v0: 7; // 18
unsigned int f1v2: 7; // 11
unsigned int f1v1_1: 4; // 4
unsigned int f1v1_0: 3; // 32
unsigned int f1v0: 7; // 29
unsigned int f0v2: 7; // 22
unsigned int f0v1: 7; // 15
unsigned int f0v0: 7; // 8
unsigned int is7bit: 1; // 1
} Gtrin_7b;
typedef struct Gquad_independ {
unsigned int cmd: 8; // 32
unsigned int count: 7; // 24
unsigned int unused: 5; // 17
unsigned int f1v3: 5; // 12
unsigned int f1v2: 5; // 7
unsigned int f1v1_1: 2; // 2
unsigned int f1v1_0: 3; // 32
unsigned int f1v0: 5; // 29
unsigned int f0v3: 5; // 24
unsigned int f0v2: 5; // 19
unsigned int f0v1: 5; // 14
unsigned int f0v0: 5; // 9
unsigned int pad: 3; // 4
unsigned int is7bit: 1; // 1
} Gquad_independ;
typedef struct Gquad {
unsigned int f2v3: 5; // 32
unsigned int f2v2: 5; // 27
unsigned int f2v1: 5; // 22
unsigned int f2v0: 5; // 17
unsigned int f1v3: 5; // 12
unsigned int f1v2: 5; // 7
unsigned int f1v1_1: 2; // 2
unsigned int f1v1_0: 3; // 32
unsigned int f1v0: 5; // 29
unsigned int f0v3: 5; // 24
unsigned int f0v2: 5; // 19
unsigned int f0v1: 5; // 14
unsigned int f0v0: 5; // 9
unsigned int pad: 3; // 4
unsigned int is7bit: 1; // 1
} Gquad;
typedef struct Gquad_7b {
unsigned int f1v3: 7; // 32
unsigned int f1v2: 7; // 25
unsigned int f1v1: 7; // 18
unsigned int f1v0_1: 4; // 11
unsigned int f1v0_0: 3; // 7
unsigned int pad: 4; // 4
unsigned int f0v3: 7; // 32
unsigned int f0v2: 7; // 25
unsigned int f0v1: 7; // 18
unsigned int f0v0: 7; // 11
unsigned int pad0: 3; // 4
unsigned int is7bit: 1; // 1
} Gquad_7b;
typedef struct Gquad0 {
int cmd: 8;
unsigned int v0: 8;
unsigned int v1: 8;
unsigned int v2: 8;
unsigned int pad: 24;
unsigned int v3: 8;
} Gquad0;
typedef struct Gculldl {
int cmd: 8;
unsigned int pad0: 8;
unsigned int vstart: 16;
unsigned int pad1: 16;
unsigned int vend: 16;
} Gculldl;
typedef struct Gspecial1 {
int cmd: 8;
int mode: 8;
unsigned int param0: 16;
unsigned int param1;
} Gspecial1;
typedef struct {
unsigned char col[3];
unsigned char kc;
@@ -363,22 +587,52 @@ typedef struct {
} combiner_tev_alpha;
/* New Command Macros */
#define gDPParam2(cmd, tag, param, extra) \
do { \
Gfx* _g = (Gfx*)(pkt); \
_g->words.w0 = (u32)(_SHIFTL(cmd, 24, 8) | _SHIFTL(tag, 16, 8) | _SHIFTL(param, 0, 16)); \
_g->words.w1 = (u32)(extra); \
} while(0)
#define gsDPParam2(cmd, tag, param, extra) \
{{ \
_SHIFTL(cmd, 24, 8) | _SHIFTL(tag, 16, 8) | _SHIFTL(param, 0, 16), extra \
}}
#define gsDPNoOpTag2(tag, param, extra) gsDPParam2(G_NOOP, tag, param, extra)
#define gDPNoOpTag2(tag, param, extra) gDPParam2(G_NOOP, tag, param, extra)
#define gsDPNoOpTag2(tag, param, extra) gsDPParam2(G_NOOP, tag, param, extra)
#define gDPNoOpHere() gDPNoOpTag2(G_TAG_HERE, __LINE__, __FILE__)
#define gsDPNoOpHere() gsDPNoOpTag2(G_TAG_HERE, __LINE__, __FILE__)
#define gDPNoOpString(str, param) gDPNoOpTag2(G_TAG_STRING, param, str)
#define gsDPNoOpString(str, param) gsDPNoOpTag2(G_TAG_STRING, param, str)
#define gDPNoOpWord(word, param) gDPNoOpTag2(G_TAG_WORD, param, word)
#define gsDPNoOpWord(word, param) gsDPNoOpTag2(G_TAG_WORD, param, word)
#define gDPNoOpFloat(float, param) gDPNoOpTag2(G_TAG_FLOAT, param, float)
#define gsDPNoOpFloat(float, param) gsDPNoOpTag2(G_TAG_FLOAT, param, float)
#define gDPNoOpQuiet() gDPNoOpTag2(G_TAG_INFO, 0, 0)
#define gsDPNoOpQuiet() gsDPNoOpTag2(G_TAG_INFO, 0, 0)
#define gDPNoOpVerbose() gDPNoOpTag2(G_TAG_INFO, 0xF, 0)
#define gsDPNoOpVerbose() gsDPNoOpTag2(G_TAG_INFO, 0xF, 0)
#define gDPNoOpCallBack(callback, param) gDPNoOpTag2(G_TAG_CALLBACK, param, callback)
#define gsDPNoOpCallBack(callback, param) gsDPNoOpTag2(G_TAG_CALLBACK, param, callback)
#define gDPNoOpOpenDisp() gDPNoOpTag2(G_TAG_OPENDISP, __LINE__, __FILE__)
#define gsDPNoOpOpenDisp() gsDPNoOpTag2(G_TAG_OPENDISP, __LINE__, __FILE__)
#define gDPNoOpCloseDisp() gDPNoOpTag2(G_TAG_CLOSEDISP, __LINE__, __FILE__)
#define gsDPNoOpCloseDisp() gsDPNoOpTag2(G_TAG_CLOSEDISP, __LINE__, __FILE__)
#define gDPNoOpFill() gDPNoOpTag2(G_TAG_FILL, 0, 0)
#define gsDPNoOpFill() gsDPNoOpTag2(G_TAG_FILL, 0, 0)
#define gDPNoOpTag3(tag, extra, param) gDPNoOpTag2(tag, param, extra)
#define gsDPNoOpTag3(tag, extra, param) gsDPNoOpTag2(tag, param, extra)
#define G_TLUT_DOLPHIN 2
+7 -1
View File
@@ -17,8 +17,14 @@ typedef struct __va_list_struct {
typedef _va_list_struct __va_list[1];
void* __va_arg(_va_list_struct* list, int type);
#define __va_start(list, fmt) __builtin_va_info(&list)
#define __va_arg(list, type) (*((type*)__va_arg(ap, _var_arg_typeof(type))))
#ifdef __MWERKS__
#define __va_arg(list, type) (*((type*)__va_arg(list, _var_arg_typeof(type))))
#else
#define __va_arg(list, type) 0
#endif
#define va_start __va_start
#define va_arg __va_arg
#define va_end __va_end