Files
ss/include/nw4r/g3d/platform/g3d_cpu.h
T
Elijah Thomas 9c3c480b24 g3d source (#123)
* g3d_calcvtx

GetData seems to have changed -> dwarf says r is a local and using ofs_to_ptr didnt work

* g3d_light and g3d_fog

sdata2 splits and func ordering

* g3d_scnproc

* g3d_init

* g3d_scnmdl

* g3d_scnmdlsmpl

* g3d_scnroot

* g3d_scnobj

* g3d_res* progress

* g3d_resmdl OK

* g3d_restev OK

* g3d_resmat OK

* g3d_resvtx and g3d_restex OK

* g3d_resnode OK

* g3d_resanm OK

* g3d_resanmchr Progress

* the rest of g3d_res* OK

* g3d_anmvis OK

* g3d_anmclr OK

* Some Splitting

* more OK, Inline Issue in g3d_anmtexsrt

* g3d_obj, g3d_anmobj, g3d_gpu, g3d_tmem, g3d_cpu OK

* g3d_state OK

* g3d/dcc OK

* Include fixup

* More Fixups

* g3d_camera OK

* g3d_draw OK

* g3d_calcworld OK

* g3d_calcworld actually OK

* g3d_workmem, g3d_dcc OK

* g3d_calcview OK

* g3d_anmtexsrt OK with DONT_INLINE

* g3d_transform OK (Feels Cheaty)

* g3d_resanmchr OK

* g3d_draw1mat1shp Close

* g3d_draw1mat1shp OK (Thanks Lago!). Ran symbol applying script
2025-03-16 11:26:15 -04:00

170 lines
3.7 KiB
C++

#ifndef NW4R_G3D_PLATFORM_CPU_H
#define NW4R_G3D_PLATFORM_CPU_H
#include <nw4r/types_nw4r.h>
#include "rvl/OS.h" // IWYU pragma: export
namespace nw4r {
namespace g3d {
/******************************************************************************
*
* Fastcast
*
******************************************************************************/
namespace fastcast {
/******************************************************************************
*
* Convert from U8
*
******************************************************************************/
inline f32 U8_0ToF32(const u8 *pPtr) {
f32 x;
OSu8tof32(const_cast<u8 *>(pPtr), &x);
return x;
}
/******************************************************************************
*
* Convert from U16
*
******************************************************************************/
inline f32 U16_0ToF32(const u16 *pPtr) {
f32 x;
OSu16tof32(const_cast<u16 *>(pPtr), &x);
return x;
}
/******************************************************************************
*
* Convert from S16
*
******************************************************************************/
inline f32 S7_8ToF32(register const s16 *pPtr) {
register f32 f;
// clang-format off
asm {
psq_l f, 0(pPtr), 1, 7
}
// clang-format on
return f;
}
inline f32 S10_5ToF32(register const s16 *pPtr) {
register f32 f;
// clang-format off
asm {
psq_l f, 0(pPtr), 1, 6
}
// clang-format on
return f;
}
/******************************************************************************
*
* Convert from F32
*
******************************************************************************/
inline u8 F32ToU8_0(f32 f) {
u8 x;
OSf32tou8(&f, &x);
return x;
}
inline s16 F32ToS10_5(register f32 f) {
s16 x;
register s16 *pPtr = &x;
// clang-format off
asm {
psq_st f, 0(pPtr), 1, 6
}
// clang-format on
return x;
}
/******************************************************************************
*
* GQR
*
******************************************************************************/
inline void SetGQR6_S10_5() {
OSSetGQR6(OS_GQR_TYPE_S16, 5);
}
inline void SetGQR7_S7_8() {
OSSetGQR7(OS_GQR_TYPE_S16, 8);
}
/******************************************************************************
*
* Initialization
*
******************************************************************************/
namespace detail {
inline void Init() {
OSInitFastCast();
SetGQR6_S10_5();
SetGQR7_S7_8();
}
} // namespace detail
} // namespace fastcast
/******************************************************************************
*
* Cache
*
******************************************************************************/
namespace DC {
inline void StoreRange(void *pBase, u32 size) {
DCStoreRange(pBase, size);
}
inline void StoreRangeNoSync(void *pBase, u32 size) {
DCStoreRangeNoSync(pBase, size);
}
inline void FlushRangeNoSync(void *pBase, u32 size) {
DCFlushRangeNoSync(pBase, size);
}
inline void InvalidateRange(void *pBase, u32 size) {
DCInvalidateRange(pBase, size);
}
} // namespace DC
/******************************************************************************
*
* Memory
*
******************************************************************************/
namespace detail {
void Copy32ByteBlocks(void *pDst, const void *pSrc, u32 size);
void ZeroMemory32ByteBlocks(void *pDst, u32 size);
} // namespace detail
/******************************************************************************
*
* Initialize fastcast
*
******************************************************************************/
inline void InitFastCast() {
fastcast::detail::Init();
}
} // namespace g3d
} // namespace nw4r
#endif