NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
g3d_cpu.h
1#ifndef NW4R_G3D_PLATFORM_CPU_H
2#define NW4R_G3D_PLATFORM_CPU_H
3#include <nw4r/types_nw4r.h>
4
5#include <revolution/OS.h>
6
7namespace nw4r {
8namespace g3d {
9
10/******************************************************************************
11 *
12 * Fastcast
13 *
14 ******************************************************************************/
15namespace fastcast {
16
17/******************************************************************************
18 *
19 * Convert from U8
20 *
21 ******************************************************************************/
22inline f32 U8_0ToF32(const u8* pPtr) {
23 f32 x;
24 OSu8tof32(const_cast<u8*>(pPtr), &x);
25 return x;
26}
27
28/******************************************************************************
29 *
30 * Convert from U16
31 *
32 ******************************************************************************/
33inline f32 U16_0ToF32(const u16* pPtr) {
34 f32 x;
35 OSu16tof32(const_cast<u16*>(pPtr), &x);
36 return x;
37}
38
39/******************************************************************************
40 *
41 * Convert from S16
42 *
43 ******************************************************************************/
44inline f32 S7_8ToF32(register const s16* pPtr) {
45 register f32 f;
46
47 // clang-format off
48 asm {
49 psq_l f, 0(pPtr), 1, 7
50 }
51 // clang-format on
52
53 return f;
54}
55
56inline f32 S10_5ToF32(register const s16* pPtr) {
57 register f32 f;
58
59 // clang-format off
60 asm {
61 psq_l f, 0(pPtr), 1, 6
62 }
63 // clang-format on
64
65 return f;
66}
67
68/******************************************************************************
69 *
70 * Convert from F32
71 *
72 ******************************************************************************/
73inline u8 F32ToU8_0(f32 f) {
74 u8 x;
75 OSf32tou8(&f, &x);
76 return x;
77}
78
79inline s16 F32ToS10_5(register f32 f) {
80 s16 x;
81 register s16* pPtr = &x;
82
83 // clang-format off
84 asm {
85 psq_st f, 0(pPtr), 1, 6
86 }
87 // clang-format on
88
89 return x;
90}
91
92/******************************************************************************
93 *
94 * GQR
95 *
96 ******************************************************************************/
97inline void SetGQR6_S10_5() {
98 OSSetGQR6(OS_GQR_TYPE_S16, 5);
99}
100inline void SetGQR7_S7_8() {
101 OSSetGQR7(OS_GQR_TYPE_S16, 8);
102}
103
104/******************************************************************************
105 *
106 * Initialization
107 *
108 ******************************************************************************/
109namespace detail {
110
111inline void Init() {
112 OSInitFastCast();
113 SetGQR6_S10_5();
114 SetGQR7_S7_8();
115}
116
117} // namespace detail
118} // namespace fastcast
119
120/******************************************************************************
121 *
122 * Cache
123 *
124 ******************************************************************************/
125namespace DC {
126
127inline void StoreRange(void* pBase, ulong size) {
128 DCStoreRange(pBase, size);
129}
130
131inline void StoreRangeNoSync(void* pBase, ulong size) {
132 DCStoreRangeNoSync(pBase, size);
133}
134
135inline void FlushRangeNoSync(void* pBase, ulong size) {
136 DCFlushRangeNoSync(pBase, size);
137}
138
139inline void InvalidateRange(void* pBase, ulong size) {
140 DCInvalidateRange(pBase, size);
141}
142
143} // namespace DC
144
145/******************************************************************************
146 *
147 * Memory
148 *
149 ******************************************************************************/
150namespace detail {
151
152void Copy32ByteBlocks(void* pDst, const void* pSrc, ulong size);
153void ZeroMemory32ByteBlocks(void* pDst, ulong size);
154
155} // namespace detail
156
157/******************************************************************************
158 *
159 * Initialize fastcast
160 *
161 ******************************************************************************/
162inline void InitFastCast() {
163 fastcast::detail::Init();
164}
165
166} // namespace g3d
167} // namespace nw4r
168
169#endif
3D graphics drawing library.
Definition g3d_3dsmax.h:10