2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CCAST
|
|
|
|
#define _CCAST
|
2022-08-13 12:57:38 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
2022-09-13 04:26:54 +00:00
|
|
|
|
|
|
|
#include "dolphin/os/OSFastCast.h"
|
2022-08-13 12:57:38 +00:00
|
|
|
|
|
|
|
namespace CCast {
|
2022-08-26 03:46:24 +00:00
|
|
|
#ifdef __MWERKS__
|
2022-10-09 05:37:23 +00:00
|
|
|
inline uchar ToUint8(register float in) {
|
|
|
|
uchar a;
|
|
|
|
register uchar* ptr = &a;
|
2022-08-13 12:57:38 +00:00
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_U8
|
|
|
|
}
|
2022-11-03 17:09:58 +00:00
|
|
|
return *ptr;
|
2022-08-13 12:57:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
inline float ToReal32(register const uchar& in) {
|
|
|
|
register float r;
|
2022-08-13 12:57:38 +00:00
|
|
|
asm {
|
|
|
|
psq_l r, 0(in), 1, 2
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
2022-09-05 04:00:04 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
inline short FtoS(register float in) {
|
|
|
|
short a;
|
|
|
|
register short* ptr = &a;
|
2022-09-05 04:00:04 +00:00
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_S16
|
|
|
|
}
|
|
|
|
return *ptr;
|
|
|
|
}
|
2022-10-21 21:40:29 +00:00
|
|
|
|
|
|
|
inline ushort FtoUS(register float in) {
|
|
|
|
ushort a;
|
|
|
|
register ushort* ptr = &a;
|
|
|
|
|
|
|
|
asm {
|
|
|
|
psq_st in, 0(ptr), 1, OS_FASTCAST_U16
|
|
|
|
}
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
2022-08-26 03:46:24 +00:00
|
|
|
#else
|
2022-10-09 05:37:23 +00:00
|
|
|
inline uchar ToUint8(float in) { return static_cast< uchar >(in); }
|
|
|
|
inline float ToReal32(uchar in) { return static_cast< float >(in); }
|
|
|
|
inline short FtoS(float in) { return static_cast< short >(in); }
|
2022-10-21 21:40:29 +00:00
|
|
|
inline ushort FtoUS(float in) { return static_cast< ushort >(in); }
|
2022-08-26 03:46:24 +00:00
|
|
|
#endif
|
2022-10-09 16:34:58 +00:00
|
|
|
|
2024-09-19 05:07:35 +00:00
|
|
|
inline uchar ToUint8(int c) { return static_cast< uchar >(c); }
|
|
|
|
inline int FtoL(float in) { return static_cast< int >(in); }
|
|
|
|
inline float LtoF(int in) { return static_cast< float >(in); }
|
|
|
|
inline float ToReal32(int in) { return static_cast< float >(in); }
|
2022-10-09 16:34:58 +00:00
|
|
|
inline int ToInt32(float in) { return static_cast< int >(in); }
|
2023-10-18 04:00:23 +00:00
|
|
|
inline unsigned short ToUint16(unsigned short in) { return static_cast< short >(in); }
|
2024-09-19 05:07:35 +00:00
|
|
|
inline char ToChar(int c) { return ToUint8(c); }
|
2022-08-13 12:57:38 +00:00
|
|
|
} // namespace CCast
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CCAST
|