Merge pull request #241 from Cuyler36:emu64_work

emu64 work, nonmatching
This commit is contained in:
Cuyler36
2024-02-04 19:10:46 -05:00
committed by GitHub
6 changed files with 1578 additions and 265 deletions
+3
View File
@@ -2,6 +2,7 @@
#define _DOLPHIN_GXFIFO
#include <dolphin/gx/GXEnum.h>
#include <dolphin/os/OSThread.h>
#ifdef __cplusplus
extern "C" {
@@ -29,6 +30,8 @@ void GXInitFifoLimits(GXFifoObj* fifo, u32 hiWaterMark, u32 loWaterMark);
GXBreakPtCallback GXSetBreakPtCallback(GXBreakPtCallback cb);
void GXEnableBreakPt(void* breakPt);
void GXDisableBreakPt(void);
OSThread* GXSetCurrentGXThread(void);
OSThread* GXGetCurrentGXThread(void);
#ifdef __cplusplus
}
+115 -20
View File
@@ -9,10 +9,7 @@
#include "dolphin/os/__ppc_eabi_init.h"
#include "dolphin/gx.h"
#include "dolphin/mtx.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "sys_ucode.h"
#ifdef EMU64_DEBUG
#define AFLAGS_MAX 100
@@ -38,8 +35,44 @@ extern "C" {
#define EMU64_WARN_TIME 600
#define EMU64_DIRTY_FLAG_PRIM_COLOR 0
#define EMU64_DIRTY_FLAG_ENV_COLOR 1
#define EMU64_DIRTY_FLAG_BLEND_COLOR 2
#define EMU64_DIRTY_FLAG_FOG 3
#define EMU64_DIRTY_FLAG_FILL_COLOR 4
#define EMU64_DIRTY_FLAG_FILL_TEV_COLOR 5
#define EMU64_DIRTY_FLAG_COMBINE 6
#define EMU64_DIRTY_FLAG_OTHERMODE_HIGH 7
#define EMU64_DIRTY_FLAG_OTHERMODE_LOW 8
#define EMU64_DIRTY_FLAG_GEOMETRYMODE 9
#define EMU64_DIRTY_FLAG_PROJECTION_MTX 10
#define EMU64_DIRTY_FLAG_TEX 11
#define EMU64_DIRTY_FLAG_POSITION_MTX 12
#define EMU64_DIRTY_FLAG_TEX_TILE0 13
#define EMU64_DIRTY_FLAG_TEX_TILE1 14
#define EMU64_DIRTY_FLAG_TEX_TILE2 15
#define EMU64_DIRTY_FLAG_TEX_TILE3 16
#define EMU64_DIRTY_FLAG_TEX_TILE4 17
#define EMU64_DIRTY_FLAG_TEX_TILE5 18
#define EMU64_DIRTY_FLAG_TEX_TILE6 19
#define EMU64_DIRTY_FLAG_TEX_TILE7 20
#define EMU64_DIRTY_FLAG_21 21
#define EMU64_DIRTY_FLAG_22 22
#define EMU64_DIRTY_FLAG_23 23
#define EMU64_DIRTY_FLAG_24 24
#define EMU64_DIRTY_FLAG_25 25
#define EMU64_DIRTY_FLAG_26 26
#define EMU64_DIRTY_FLAG_27 27
#define EMU64_DIRTY_FLAG_28 28
#define EMU64_DIRTY_FLAG_LIGHTS 29
#define EMU64_DIRTY_FLAG_LIGHTING 30
#define EMU64_DIRTY_FLAG_TEX_MTX 31
#define NUM_DIRTY_FLAGS 32
#define EMU64_TLUT_IA16 0x0000
#define EMU64_TLUT_RGBA5551 0x8000
/* TODO: figure out where this actually belongs */
namespace std {
typedef struct __va_list_struct __tag_va_List;
@@ -101,6 +134,47 @@ typedef struct {
u8 pad;
} emu64_texture_info;
static inline void get_blk_wd_ht(unsigned int siz, unsigned int* blk_wd, unsigned int* blk_ht) {
static u8 blk_tbl[4][2] = {
{ 8, 8 }, // G_IM_SIZ_4b
{ 8, 4 }, // G_IM_SIZ_8b
{ 4, 4 }, // G_IM_SIZ_16b
{ 4, 4 } // G_IM_SIZ_32b
};
*blk_wd = blk_tbl[siz][0];
*blk_ht = blk_tbl[siz][1];
}
extern void get_dol_wd_ht(unsigned int siz, unsigned int in_wd, unsigned int in_ht, unsigned int* wd, unsigned int* ht);
static inline unsigned int rgba5551_to_rgb5a3(unsigned int rgba5551) {
if ((rgba5551 & 1)) {
return 0x8000 | (rgba5551 >> 1); // no transparency so simply swap
}
else {
return ((rgba5551 >> 3) & 0xF0) | ((rgba5551 >> 4) & ~0xFF) | ((rgba5551 >> 2) & 0x0F);
}
}
static inline unsigned int get_dol_tex_siz(unsigned int siz, unsigned int in_wd, unsigned int in_ht) {
unsigned int wd;
unsigned int ht;
get_dol_wd_ht(siz, in_wd, in_ht, &wd, &ht);
return ((wd * ht) << siz) / 2;
}
static inline unsigned int get_dol_tlut_size(unsigned int count) {
return ALIGN_NEXT(count * sizeof(u16), 32);
}
#define AFLAGS_COMBINE_AUTO 12
#define ALFAGS_TEV_ALPHA_KONST 18
#define AFLAGS_2TRIS 22 /* Draws the current polygon as two triangles */
#define AFLAGS_SKIP_COMBINE_TEV 27
#define AFLAGS_FORCE_TEV_COMBINE_MODE 28 /* 1 = force shade, 2 = force d1 = ENV, Ad1 = ONE */
class aflags_c {
public:
#ifndef EMU64_DEBUG
@@ -297,8 +371,34 @@ private:
void Vprintf(const char* fmt, std::__tag_va_List* va_list) { vprintf(fmt, va_list); }
};
#define EMU64_ASSERTLINE(cond, line) \
if (!cond) { \
this->panic(#cond, __FILE__, line); \
}
#define EMU64_ASSERT(cond) EMU64_PANICLINE(cond, __LINE__)
class emu64 : public emu64_print {
public:
void emu64_init();
void printInfo();
void panic(char* fmt, char* file, int line);
void emu64_change_ucode(void* ucode_p);
void texconv_tile(u8* addr, u8* converted_addr, unsigned int wd, unsigned int fmt, unsigned int siz, unsigned int start_wd, unsigned int start_ht, unsigned int end_wd, unsigned int end_ht, unsigned int line_siz);
unsigned int tmem_swap(unsigned int ofs, unsigned int blk_siz) { return ofs ^ ((ofs / blk_siz) & 4); }
void tlutconv_rgba5551(u16* rgba5551_p, u16* rgb5a3_p, unsigned int count);
void tlutconv_ia16(u16* src_ia16_p, u16* dst_ia16_p, unsigned int count);
u8* texconv_tile_new(u8* addr, unsigned int wd, unsigned int fmt, unsigned int siz, unsigned int start_wd, unsigned int start_ht, unsigned int end_wd, unsigned int end_ht, unsigned int line_siz);
u16* tlutconv_new(u16* tlut, unsigned int tlut_fmt, unsigned int count);
void tlutconv(u16* src_tlut, u16* dst_tlut, unsigned int count, unsigned int tlut_fmt);
int replace_combine_to_tev(Gfx* g);
int combine_auto();
int combine_tev();
void combine_manual();
const char* combine_name(u32 param, u32 type);
const char* combine_alpha(int param, int type);
void print_combine(u64 combine);
/* N64 texture format[N64 bit size] -> dol texture format */
static u16 fmtxtbl[8][4];
@@ -331,8 +431,8 @@ private:
/* 0x0054 */ void* work_ptr;
/* 0x0058 */ int end_dl;
/* 0x005C */ s8 ucode_len;
/* 0x0060 */ void* ucode_info;
/* 0x0064 */ void* ucode_p;
/* 0x0060 */ ucode_info* ucode_info;
/* 0x0064 */ int ucode_type; // maybe?
/* 0x0068 */ int _0068; /* ??? */
/* 0x006C */ void* segments[NUM_SEGMENTS];
/* 0x00AC */ Gfx* DL_stack[DL_MAX_STACK_LEVEL];
@@ -341,8 +441,7 @@ private:
/* 0x00FC */ u32 othermode_low;
/* 0x0100 */ u32 geometry_mode;
/* 0x0104 */ u32 _0104;
/* 0x0108 */ u32 combiner_high;
/* 0x010C */ u32 combiner_low;
/* 0x0108 */ Gfx combine;
/* 0x0110 */ emu64_texture_info texture_info[NUM_TILES];
/* 0x0170 */ Gsetimg2 setimg2_cmds[NUM_TILES];
/* 0x01B0 */ void* tlut_addresses[NUM_TLUTS];
@@ -372,10 +471,10 @@ private:
/* 0x049C */ EmuColor fill_color;
/* 0x04A0 */ EmuColor fill_tev_color; /* GX_TEVREG0 */
/* 0x04A4 */ bool dirty_flags[NUM_DIRTY_FLAGS];
/* 0x04C4 */ Mtx original_projection_mtx;
/* 0x04F4 */ Mtx position_mtx;
/* 0x0524 */ Mtx model_view_mtx_stack[MTX_STACK_SIZE];
/* 0x0704 */ Mtx position_mtx_stack[MTX_STACK_SIZE];
/* 0x04C4 */ GC_Mtx original_projection_mtx;
/* 0x04F4 */ GC_Mtx position_mtx;
/* 0x0524 */ GC_Mtx model_view_mtx_stack[MTX_STACK_SIZE];
/* 0x0704 */ GC_Mtx position_mtx_stack[MTX_STACK_SIZE];
/* 0x08E4 */ Mtx44 projection_mtx;
/* 0x0924 */ struct {
struct {
@@ -387,15 +486,15 @@ private:
} lookAt;
/* 0x092C */ f32 near; /* Near clipping plane */
/* 0x0930 */ f32 far; /* Far clipping plane */
/* 0x0934 */ Mtx model_view_mtx;
/* 0x0964 */ Mtx _0964; /* UNCONFIRMED TYPE */
/* 0x0934 */ GC_Mtx model_view_mtx;
/* 0x0964 */ GC_Mtx _0964; /* UNCONFIRMED TYPE */
/* 0x0994 */ int mtx_stack_size;
/* 0x0998 */ Gtexture_internal texture_gfx;
/* 0x09A0 */ f32 texture_scale_s; /* x-scale */
/* 0x09A4 */ f32 texture_scale_t; /* y-scale */
/* 0x09A8 */ Mtx44 ortho_mtx;
/* 0x09E8 */ GXProjectionType projection_type;
/* 0x09EC */ Mtx perspective_mtx;
/* 0x09EC */ GC_Mtx perspective_mtx;
/* 0x0A1C */ u32 _0A1C;
/* 0x0A20 */ u32 rdpHalf_1;
/* 0x0A24 */ EmuLight lights[NUM_LIGHTS];
@@ -416,7 +515,7 @@ private:
/* 0x0B9C */ u32 polygons_time;
/* 0x0BA0 */ u32 dirty_check_time;
/* 0x0BA4 */ u32 dirty_lightX_time;
/* 0x0BA8 */ u32 dirty_lightX_cnt
/* 0x0BA8 */ u32 dirty_lightX_cnt;
/* 0x0BAC */ u32 dirty_light_time;
/* 0x0BB0 */ u32 dirty_light_cnt;
/* 0x0BB4 */ u32 dirty_tex_time;
@@ -458,8 +557,4 @@ private:
/* 0x2078 */ u8 dl_history_start;
};
#ifdef __cplusplus
}
#endif
#endif
+13 -67
View File
@@ -306,25 +306,25 @@ typedef struct {
} Gloadtlut_dolphin;
typedef struct {
unsigned char cmd:8;
unsigned char xparam:8;
unsigned int cmd:8;
unsigned int xparam:8;
unsigned int pad:2;
unsigned char level:3;
unsigned char tile:3;
unsigned char on:8; /* Should be 7 bits w/ 1 bit padding, but emulator doesn't do this */
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;
} Gtexture_internal;
typedef struct {
unsigned char cmd:8;
unsigned int cmd:8;
unsigned int index:8;
unsigned int offset:16;
unsigned int data;
} Gmoveword;
typedef struct {
unsigned char cmd:8;
unsigned int cmd:8;
unsigned int length:8;
unsigned int offset:8;
unsigned int index:8;
@@ -349,71 +349,17 @@ typedef union {
/* Combiner Structs */
typedef struct {
unsigned int pad0:4;
unsigned int color0:4;
unsigned int pad1:4;
unsigned int color1:4;
unsigned int pad2:4;
unsigned int color2:4;
unsigned int pad3:4;
unsigned int color3:4;
u8 color0;
u8 color1;
u8 color2;
u8 color3;
} combiner_tev_color;
typedef struct {
unsigned int pad0:5;
unsigned int alpha0:3;
unsigned int pad1:5;
unsigned int alpha1:3;
u8 alpha0;
u8 alpha1;
} combiner_tev_alpha;
/*
static combiner_tev_alpha tbla[8] = {
{ 0, TEV_ALPHA_COMBINED, 0, TEV_ALPHA_ONE },
{ 0, TEV_ALPHA_TEXEL0, 0, TEV_ALPHA_TEXEL0 },
{ 0, TEV_ALPHA_TEXEL0, 0, TEV_ALPHA_TEXEL0 },
{ 0, TEV_ALPHA_PRIMITIVE, 0, TEV_ALPHA_PRIMITIVE },
{ 0, TEV_ALPHA_SHADE, 0, TEV_ALPHA_SHADE },
{ 0, TEV_ALPHA_ENVIRONMENT, 0, TEV_ALPHA_ENVIRONMENT },
{ 0, TEV_ALPHA_ONE, 0, TEV_ALPHA_PRIM_LOD_FRAC },
{ 0, TEV_ALPHA_ZERO, 0, TEV_ALPHA_ZERO }
};
static combiner_tev_color tblc[32] = {
{ 0, TEV_COMBINED, 0, TEV_COMBINED, 0, TEV_COMBINED, 0, TEV_COMBINED },
{ 0, TEV_TEXEL0, 0, TEV_TEXEL0, 0, TEV_TEXEL0, 0, TEV_TEXEL0 },
{ 0, TEV_TEXEL0, 0, TEV_TEXEL0, 0, TEV_TEXEL0, 0, TEV_TEXEL0 },
{ 0, TEV_PRIMITIVE, 0, TEV_PRIMITIVE, 0, TEV_PRIMITIVE, 0, TEV_PRIMITIVE },
{ 0, TEV_SHADE, 0, TEV_SHADE, 0, TEV_SHADE, 0, TEV_SHADE },
{ 0, TEV_ENVIRONMENT, 0, TEV_ENVIRONMENT, 0, TEV_ENVIRONMENT, 0, TEV_ENVIRONMENT },
{ 0, TEV_ONE, 0, TEV_HALF, 0, TEV_HALF, 0, TEV_ONE },
{ 0, TEV_HALF, 0, TEV_HALF, 0, TEV_COMBINED_ALPHA, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_TEXEL0_ALPHA, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_TEXEL0_ALPHA, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_PRIMITIVE_ALPHA, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_SHADE_ALPHA, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ENV_ALPHA, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_HALF, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_PRIM_LOD_FRAC, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_HALF, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO },
{ 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO, 0, TEV_ZERO }
};
*/
/* New Command Macros */
#define gsDPParam2(cmd, tag, param, extra) \
{{ \
+1
View File
@@ -13,6 +13,7 @@ typedef struct ucode_info_s {
void* ucode_p;
} ucode_info;
#define UCODE_TYPE_NONE 0
#define UCODE_TYPE_POLY_TEXT 1
#define UCODE_TYPE_POLY_DATA 2
#define UCODE_TYPE_SPRITE_TEXT 3
File diff suppressed because it is too large Load Diff
+105
View File
@@ -0,0 +1,105 @@
#include "emu64.hpp"
const char* emu64::combine_name(u32 param, u32 type) {
switch (param) {
case 0:
return "COMBINED";
case 1:
return "TEXEL0";
case 2:
return "TEXEL1";
case 3:
return "PRIMITIVE";
case 4:
return "SHADE";
case 5:
return "ENVIRONMENT";
case 6:
if (type == COMBINER_PARAM_B) {
return "CENTER";
} else if (type == COMBINER_PARAM_C) {
return "SCALE";
} else {
return "1";
}
case 7:
if (type == COMBINER_PARAM_A) {
return "NOISE";
} else if (type == COMBINER_PARAM_B) {
return "K4";
} else if (type == COMBINER_PARAM_C) {
return "COMBINED_ALPHA";
} else {
return "0";
}
}
if (type != COMBINER_PARAM_C) {
return "0";
}
switch (param) {
case 8:
return "TEXEL0_ALPHA";
case 9:
return "TEXEL1_ALPHA";
case 10:
return "PRIMITIVE_ALPHA";
case 11:
return "SHADE_ALPHA";
case 12:
return "ENV_ALPHA";
case 13:
return "LOD_FRACTION";
case 14:
return "PRIM_LOD_FRAC";
case 15:
return "K5";
default:
return "0";
}
}
const char* emu64::combine_alpha(int param, int type) {
switch (param) {
case 0:
return type == COMBINER_PARAM_C ? "LOD_FRACTION" : "COMBINED";
case 1:
return "TEXEL0";
case 2:
return "TEXEL1";
case 3:
return "PRIMITIVE";
case 4:
return "SHADE";
case 5:
return "ENVIRONMENT";
case 6:
return type == COMBINER_PARAM_C ? "PRIM_LOD_FRAC" : "1";
case 7:
return "0";
}
/* There should be a default case here, but they forgot it. */
/* It returns a pointer to the emu64 class instead. */
#ifdef EMU64_FIX_COMBINE_NAME_RETURN_VALUES
return "0";
#endif
}
void emu64::print_combine(u64 combine) {
Gsetcombine_new* setcombine = (Gsetcombine_new*)&combine;
this->Printf0(
"gsDPSetCombineLERP(%s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s, %s,%s,%s,%s),",
this->combine_name(setcombine->a0, COMBINER_PARAM_A), this->combine_name(setcombine->b0, COMBINER_PARAM_B),
this->combine_name(setcombine->c0, COMBINER_PARAM_C), this->combine_name(setcombine->d0, COMBINER_PARAM_D),
this->combine_alpha(setcombine->Aa0, COMBINER_PARAM_A), this->combine_alpha(setcombine->Ab0, COMBINER_PARAM_B),
this->combine_alpha(setcombine->Ac0, COMBINER_PARAM_C), this->combine_alpha(setcombine->Ad0, COMBINER_PARAM_D),
this->combine_name(setcombine->a1, COMBINER_PARAM_A), this->combine_name(setcombine->b1, COMBINER_PARAM_B),
this->combine_name(setcombine->c1, COMBINER_PARAM_C), this->combine_name(setcombine->d1, COMBINER_PARAM_D),
this->combine_alpha(setcombine->Aa1, COMBINER_PARAM_A), this->combine_alpha(setcombine->Ab1, COMBINER_PARAM_B),
this->combine_alpha(setcombine->Ac1, COMBINER_PARAM_C), this->combine_alpha(setcombine->Ad1, COMBINER_PARAM_D));
}