Skip to content

Commit

Permalink
f_pc_manager, f_ap_game work
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Sep 10, 2023
1 parent 701309e commit 0899971
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 15 deletions.
77 changes: 77 additions & 0 deletions include/JSystem/JMath/JMATrigonometric.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef JMATRIGONOMETRIC_H
#define JMATRIGONOMETRIC_H

#include "dolphin/types.h"
#include "MSL_C/utility.h"

struct TSinCosTable {
std::pair<f32, f32> table[0x2000];

f32 sinShort(s16 v) const { return table[static_cast<u16>(v) >> 3].first; }
f32 cosShort(s16 v) const { return table[static_cast<u16>(v) >> 3].second; }

inline f32 sinLap(f32 v) {
if (v < 0.0f) {
return -table[(u16)(-8192.0f * v) & 0x1fff].first;
}
return table[(u16)(8192.0f * v) & 0x1fff].first;
}

inline f32 sinDegree(f32 degree) {
if (degree < 0.0f) {
return -table[(u16)(-22.755556106567383f * degree) & 0x1fffU].first;
}
return table[(u16)(22.755556106567383f * degree) & 0x1fffU].first;
}

inline f32 cosDegree(f32 degree) {
if (degree < 0.0f) {
degree = -degree;
}
return table[(u16)(22.755556106567383f * degree) & 0x1fffU].second;
}
};

struct TAtanTable {
f32 table[1025];
u8 pad[0x1C];
};

struct TAsinAcosTable {
f32 table[1025];
u8 pad[0x1C];
};

namespace JMath {
extern TSinCosTable sincosTable_;
extern TAtanTable atanTable_;
extern TAsinAcosTable asinAcosTable_;
}; // namespace JMath

inline f32 JMASCosShort(s16 v) {
return JMath::sincosTable_.cosShort(v);
}
inline f32 JMASinShort(s16 v) {
return JMath::sincosTable_.sinShort(v);
}

inline f32 JMASCos(s16 v) {
return JMASCosShort(v);
}
inline f32 JMASSin(s16 v) {
return JMASinShort(v);
}

inline f32 JMASinLap(f32 v) {
return JMath::sincosTable_.sinLap(v);
}

inline f32 JMASinDegree(f32 degree) {
return JMath::sincosTable_.sinDegree(degree);
}

inline f32 JMACosDegree(f32 degree) {
return JMath::sincosTable_.cosDegree(degree);
}

#endif /* JMATRIGONOMETRIC_H */
120 changes: 120 additions & 0 deletions include/JSystem/JMath/JMath.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#ifndef JMATH_H
#define JMATH_H

#include "dolphin/mtx/mtx.h"

void JMAMTXApplyScale(const Mtx, Mtx, f32, f32, f32);
void JMAEulerToQuat(s16 param_0, s16 param_1, s16 param_2, Quaternion* param_3);

inline f32 JMAFastReciprocal(f32 value) {
return __fres(value);
}

inline float __frsqrtes(register double f) {
register float out;
// clang-format off
asm {
frsqrte out, f
}
// clang-format on
return out;
}

inline f32 JMAFastSqrt(register f32 input) {
if (input > 0.0f) {
register f32 out;
asm {
frsqrte out, input
}
return out * input;
} else {
return input;
}
}

namespace JMath {

inline f32 fastReciprocal(f32 value) {
return JMAFastReciprocal(value);
}

inline void gekko_ps_copy3(register void* dst, register const void* src) {
register f32 src0;
register f32 src1;
asm {
psq_l src0, 0(src), 0, 0
lfs src1, 8(src)
psq_st src0, 0(dst), 0, 0
stfs src1, 8(dst)
};
}

inline void gekko_ps_copy6(register void* dst, register const void* src) {
register f32 src0;
register f32 src1;
register f32 src2;
asm {
psq_l src0, 0(src), 0, 0
psq_l src1, 8(src), 0, 0
psq_l src2, 16(src), 0, 0
psq_st src0, 0(dst), 0, 0
psq_st src1, 8(dst), 0, 0
psq_st src2, 16(dst), 0, 0
};
}

inline void gekko_ps_copy12(register void* dst, register const void* src) {
register f32 src0;
register f32 src1;
register f32 src2;
register f32 src3;
register f32 src4;
register f32 src5;
asm {
psq_l src0, 0(src), 0, 0
psq_l src1, 8(src), 0, 0
psq_l src2, 16(src), 0, 0
psq_l src3, 24(src), 0, 0
psq_l src4, 32(src), 0, 0
psq_l src5, 40(src), 0, 0
psq_st src0, 0(dst), 0, 0
psq_st src1, 8(dst), 0, 0
psq_st src2, 16(dst), 0, 0
psq_st src3, 24(dst), 0, 0
psq_st src4, 32(dst), 0, 0
psq_st src5, 40(dst), 0, 0
};
}

inline void gekko_ps_copy16(register void* dst, register const void* src) {
register f32 src0;
register f32 src1;
register f32 src2;
register f32 src3;
register f32 src4;
register f32 src5;
register f32 src6;
register f32 src7;
asm {
psq_l src0, 0(src), 0, 0
psq_l src1, 8(src), 0, 0
psq_l src2, 16(src), 0, 0
psq_l src3, 24(src), 0, 0
psq_l src4, 32(src), 0, 0
psq_l src5, 40(src), 0, 0
psq_l src6, 48(src), 0, 0
psq_l src7, 56(src), 0, 0
psq_st src0, 0(dst), 0, 0
psq_st src1, 8(dst), 0, 0
psq_st src2, 16(dst), 0, 0
psq_st src3, 24(dst), 0, 0
psq_st src4, 32(dst), 0, 0
psq_st src5, 40(dst), 0, 0
psq_st src6, 48(dst), 0, 0
psq_st src7, 56(dst), 0, 0
};
}

}; // namespace JMath

#endif /* JMATH_H */
35 changes: 35 additions & 0 deletions include/JSystem/JMath/random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef RANDOM_H
#define RANDOM_H

#include "dolphin/types.h"

namespace JMath {
struct TRandom_fast_ {
u32 value;

TRandom_fast_(u32 value);
u32 get(void) {
value = (value * 0x19660d) + 0x3c6ef35f;
return value;
}

u32 get_bit32(void) { return this->get(); }

// due to the float constant, having this function inlined adds that float to data,
// making it not match
float get_ufloat_1(void) {
// !@bug UB: in C++ it's not legal to read from an union member other
// than the last one that was written to.
union {
f32 f;
u32 s;
} out;
out.s = (this->get() >> 9) | 0x3f800000;
return out.f - 1;
}

void setSeed(u32 seed) { value = seed; }
};
} // namespace JMath

#endif /* RANDOM_H */
20 changes: 20 additions & 0 deletions include/f_ap/f_ap_game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef F_AP_GAME_H
#define F_AP_GAME_H

#include "JSystem/JUtility/TColor.h"

void fapGm_After();
void fapGm_Create();
void fapGm_Execute();

class fapGm_HIO_c {
public:
/* 80018944 */ fapGm_HIO_c();
/* 80018AE0 */ virtual ~fapGm_HIO_c();

u32 pad[0x58];
}; // Size: 0x40

extern fapGm_HIO_c g_HIO;

#endif /* F_AP_GAME_H */
2 changes: 1 addition & 1 deletion include/f_pc/f_pc_create_req.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void fpcCtRq_ToCreateQ(create_request* pReq);
BOOL fpcCtRq_Delete(create_request* pReq);
BOOL fpcCtRq_Cancel(create_request* pReq);
s32 fpcCtRq_IsDoing(create_request* pReq);
void fpcCtRq_Handler(void);
s32 fpcCtRq_Handler(void);
create_request* fpcCtRq_Create(layer_class* pLayer, u32 size,
create_request_method_class* pCtRqMtd);

Expand Down
2 changes: 1 addition & 1 deletion include/f_pc/f_pc_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ typedef struct base_process_class base_process_class;
BOOL fpcCt_IsCreatingByID(unsigned int id);
s32 fpcCt_IsDoing(base_process_class* pProc);
BOOL fpcCt_Abort(base_process_class* pProc);
void fpcCt_Handler(void);
s32 fpcCt_Handler(void);

#endif
22 changes: 18 additions & 4 deletions src/f_ap/f_ap_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
//

#include "f_ap/f_ap_game.h"
#include "f_op/f_op_scene_mng.h"
#include "f_op/f_op_overlap_mng.h"
#include "f_op/f_op_camera_mng.h"
#include "f_op/f_op_draw_tag.h"
#include "f_pc/f_pc_manager.h"
#include "SSystem/SComponent/c_counter.h"
#include "dolphin/types.h"

/* 8002306C-800231BC .text __ct__11fapGm_HIO_cFv */
Expand All @@ -13,20 +19,28 @@ fapGm_HIO_c::fapGm_HIO_c() {

/* 800231BC-800231E4 .text fapGm_After__Fv */
void fapGm_After() {
/* Nonmatching */
fopScnM_Management();
fopOvlpM_Management();
fopCamM_Management();
}

/* 800231E4-80023218 .text fapGm_Execute__Fv */
void fapGm_Execute() {
/* Nonmatching */
fpcM_Management(0, fapGm_After);
cCt_Counter(0);
}

/* 80023218-80023288 .text fapGm_Create__Fv */
void fapGm_Create() {
/* Nonmatching */
fpcM_Init();
fopScnM_Init();
fopOvlpM_Init();
fopCamM_Init();
fopDwTg_CreateQueue();
fopScnM_CreateReq(5, 0x7FFF, 0, 0);
// HIO
}

/* 80023288-800232D0 .text __dt__11fapGm_HIO_cFv */
fapGm_HIO_c::~fapGm_HIO_c() {
/* Nonmatching */
}
4 changes: 2 additions & 2 deletions src/f_pc/f_pc_create_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ BOOL fpcCtRq_Do(create_request* i_request) {
}

/* 8003CFC4-8003CFF0 .text fpcCtRq_Handler__Fv */
void fpcCtRq_Handler() {
fpcCtIt_Method((fpcCtIt_MethodFunc)fpcCtRq_Do, NULL);
s32 fpcCtRq_Handler() {
return fpcCtIt_Method((fpcCtIt_MethodFunc)fpcCtRq_Do, NULL);
}

/* 8003CFF0-8003D078 .text fpcCtRq_Create__FP11layer_classUlP27create_request_method_class */
Expand Down
4 changes: 2 additions & 2 deletions src/f_pc/f_pc_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ BOOL fpcCt_Abort(base_process_class* i_proc) {
}

/* 8003D150-8003D170 .text fpcCt_Handler__Fv */
void fpcCt_Handler() {
fpcCtRq_Handler();
s32 fpcCt_Handler() {
return fpcCtRq_Handler();
}
Loading

0 comments on commit 0899971

Please sign in to comment.