Skip to content

Commit

Permalink
Decompile Several tt_004 Functions (#2044)
Browse files Browse the repository at this point in the history
Decompiles `UpdateServantDefault`, `func_us_801746BC`, and
`func_us_80176270`.

I've added the `gte_stdp` and `gte_stflg` macros here which are required
for `func_us_80172E84`, but don't have a match there yet.
  • Loading branch information
hohle authored Jan 9, 2025
1 parent 9248333 commit 5eee03b
Show file tree
Hide file tree
Showing 6 changed files with 417 additions and 26 deletions.
1 change: 1 addition & 0 deletions config/symbols.us.tt_004.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ g_CurrentRoomY = 0x8017232C;
Max3 = 0x80172B8C;
Min3 = 0x80172C0C;
CheckEntityValid = 0x80173C4C;
CheckSwordLevel = 0x80173CB8;
ServantInit = 0x80173E38;
UpdateServantDefault = 0x80174170;
func_us_80177F64 = 0x80177460;
Expand Down
2 changes: 2 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ int sprintf(char* dst, const char* fmt, ...);
#define FIX(x) ((s32)((x) * 65536.0))
// Get the integer part of such a fixed-point value
#define FIX_TO_I(x) ((s32)((x) >> 16))
// Convert an integer value to fixed-point
#define I_TO_FIX(x) ((s32)((x) << 16))
// Get the fractional part of such a fixed-point value
#define FIX_FRAC(x) (*(s16*)&(x))

Expand Down
23 changes: 23 additions & 0 deletions include/psxsdk/libgte.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ extern long ratan2(long y, long x);
: "r"(r0) \
: "memory")

// Store depth queuing value pointed to by `r0`
//
// - Params:
// - long* r0 - depth queuing value
#define gte_stdp(r0) \
__asm__ volatile("swc2 $8, 0( %0 )" : : "r"(r0) : "memory")

// Store flag value pointed to by `r0`
//
// - Params:
// - long* r0 - flag value
#define gte_stflg(r0) \
__asm__ volatile( \
"cfc2 $12, $31;" \
"nop;" \
"sw $12, 0( %0 )" \
: \
: "r"(r0) \
: "$12", "memory")

#define gte_stszotz(r0) \
__asm__ volatile( \
"mfc2 $12, $19;" \
Expand Down Expand Up @@ -348,6 +368,9 @@ void gte_rtps(void);
void gte_stsxy(long* sxsy);
void gte_stszotz(long* otz);

#define gte_stdp(x) func_892804C();
#define gte_stflg(x) func_892804C();

#else

#define gte_SetRotMatrix(r0)
Expand Down
6 changes: 6 additions & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long u_long;
typedef unsigned int size_t;

#define INT32_MAX (0x7FFFFFFF)
#define INT16_MAX (0x7FFF)
#else
#include <sys/types.h>
#endif
Expand Down Expand Up @@ -42,6 +45,9 @@ typedef enum { false, true } bool;
#define NULL (0)
#endif

#define S32_MAX INT32_MAX
#define S16_MAX INT16_MAX

typedef union {
s32 val;
struct {
Expand Down
Loading

0 comments on commit 5eee03b

Please sign in to comment.