mirror of
https://github.com/PrimeDecomp/prime.git
synced 2025-12-08 15:04:54 +00:00
Runtime/math matches; better libc headers
This commit is contained in:
@@ -15,7 +15,11 @@ extern "C" {
|
||||
#define OS_BASE_CACHED (OS_CACHED_REGION_PREFIX << 16)
|
||||
#define OS_BASE_UNCACHED (OS_UNCACHED_REGION_PREFIX << 16)
|
||||
|
||||
#ifdef __MWERKS__
|
||||
#define AT_ADDRESS(xyz) : (xyz)
|
||||
#else
|
||||
#define AT_ADDRESS
|
||||
#endif
|
||||
u32 __OSBusClock AT_ADDRESS(OS_BASE_CACHED | 0x00F8); // sync with OSLoMem.h
|
||||
u32 __OSCoreClock AT_ADDRESS(OS_BASE_CACHED | 0x00FC); // sync with OSLoMem.h
|
||||
#define OS_BUS_CLOCK __OSBusClock
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Dolphin/os/OSFastCast.h"
|
||||
|
||||
namespace CCast {
|
||||
#ifdef __MWERKS__
|
||||
inline u8 ToUint8(register f32 in) {
|
||||
u8 a;
|
||||
register u8* ptr = &a;
|
||||
@@ -24,6 +25,14 @@ inline f32 ToReal32(register const u8& in) {
|
||||
}
|
||||
return r;
|
||||
}
|
||||
#else
|
||||
inline u8 ToUint8(f32 in) {
|
||||
return static_cast<u8>(in);
|
||||
}
|
||||
inline f32 ToReal32(u8 in) {
|
||||
return static_cast<f32>(in);
|
||||
}
|
||||
#endif
|
||||
} // namespace CCast
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
#include "Kyoto/Basics/CCast.hpp"
|
||||
|
||||
#ifdef __MWERKS__
|
||||
#pragma cpp_extensions on
|
||||
#endif
|
||||
|
||||
class CInputStream;
|
||||
class CColor {
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
static CVParamTransfer Null();
|
||||
|
||||
private:
|
||||
rstl::rc_ptr< void > x0_;
|
||||
rstl::rc_ptr< unkptr > x0_;
|
||||
};
|
||||
class CObjectReference {
|
||||
public:
|
||||
|
||||
@@ -11,8 +11,8 @@ inline T cinput_stream_helper(const TType< T >& type, CInputStream& in);
|
||||
|
||||
class CInputStream {
|
||||
public:
|
||||
CInputStream(size_t len);
|
||||
CInputStream(const void* ptr, size_t len, bool owned);
|
||||
CInputStream(s32 len);
|
||||
CInputStream(const void* ptr, s32 len, bool owned);
|
||||
virtual ~CInputStream();
|
||||
virtual u32 Read(void* dest, u32 len) = 0;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "rstl/optional_object.hpp"
|
||||
#include "rstl/reserved_vector.hpp"
|
||||
|
||||
template < typename T, size_t N >
|
||||
template < typename T, s32 N >
|
||||
class TReservedAverage : rstl::reserved_vector< T, N > {
|
||||
public:
|
||||
TReservedAverage(const T& value) {
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
}
|
||||
void AddValue(const T& value) {
|
||||
push_back(value);
|
||||
for (size_t i = size() - 1; i > 0; --i) {
|
||||
for (s32 i = size() - 1; i > 0; --i) {
|
||||
operator[](i) = operator[](i - 1);
|
||||
}
|
||||
operator[](0) = value;
|
||||
|
||||
@@ -29,7 +29,7 @@ template < typename T >
|
||||
class TCachedToken : public TToken< T > {
|
||||
public:
|
||||
TCachedToken() {}
|
||||
TCachedToken(const CToken& token) : TToken(token), x8_item(nullptr) {}
|
||||
TCachedToken(const CToken& token) : TToken< T >(token), x8_item(nullptr) {}
|
||||
|
||||
// TODO
|
||||
operator const TToken< T >&() const;
|
||||
@@ -42,7 +42,7 @@ template < typename T >
|
||||
class TLockedToken : public TCachedToken< T > {
|
||||
public:
|
||||
TLockedToken() {}
|
||||
TLockedToken(const CToken& token) : TCachedToken(token) { Lock(); }
|
||||
TLockedToken(const CToken& token) : TCachedToken< T >(token) { this->Lock(); }
|
||||
|
||||
// TODO
|
||||
operator const TToken< T >&() const;
|
||||
|
||||
@@ -99,11 +99,11 @@ private:
|
||||
|
||||
template < typename T >
|
||||
const T* TCastToConstPtr(const CEntity* p) {
|
||||
return TCastToPtr(const_cast< CEntity* >(p));
|
||||
return TCastToPtr< T >(const_cast< CEntity* >(p));
|
||||
}
|
||||
template < typename T >
|
||||
const T* TCastToConstPtr(const CEntity& p) {
|
||||
return TCastToPtr(const_cast< CEntity* >(&p));
|
||||
return TCastToPtr< T >(const_cast< CEntity* >(&p));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,22 +1,4 @@
|
||||
#ifndef _MATH_PPC_H_
|
||||
#define _MATH_PPC_H_
|
||||
|
||||
inline float sqrtf(float x)
|
||||
{
|
||||
static const double _half=.5;
|
||||
static const double _three=3.0;
|
||||
volatile float y;
|
||||
|
||||
if(x > 0.0f)
|
||||
{
|
||||
double guess = __frsqrte((double)x); /* returns an approximation to */
|
||||
guess = _half*guess*(_three - guess*guess*x); /* now have 12 sig bits */
|
||||
guess = _half*guess*(_three - guess*guess*x); /* now have 24 sig bits */
|
||||
guess = _half*guess*(_three - guess*guess*x); /* now have 32 sig bits */
|
||||
y=(float)(x*guess);
|
||||
return y ;
|
||||
}
|
||||
return x ;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -66,8 +66,8 @@ inline void uninitialized_copy_2(S* begin, D* out, S* end) {
|
||||
}
|
||||
|
||||
template < typename S, typename D >
|
||||
inline void uninitialized_copy_n(D* dest, S* src, size_t count) {
|
||||
for (size_t i = 0; i < count; ++dest, ++i, ++src) {
|
||||
inline void uninitialized_copy_n(D* dest, S* src, int count) {
|
||||
for (int i = 0; i < count; ++dest, ++i, ++src) {
|
||||
construct(dest, *src);
|
||||
}
|
||||
// destroy(src, src + count); ??
|
||||
|
||||
@@ -30,19 +30,19 @@ public:
|
||||
template < typename T, typename Vec, typename Alloc >
|
||||
class pointer_iterator : public const_pointer_iterator< T, Vec, Alloc > {
|
||||
public:
|
||||
pointer_iterator() : const_pointer_iterator(nullptr) {}
|
||||
pointer_iterator(T* begin) : const_pointer_iterator(begin) {}
|
||||
pointer_iterator() : const_pointer_iterator< T, Vec, Alloc >(nullptr) {}
|
||||
pointer_iterator(T* begin) : const_pointer_iterator< T, Vec, Alloc >(begin) {}
|
||||
void operator=(const T& other) {
|
||||
if (CheckValid()) {
|
||||
if (this->CheckValid()) {
|
||||
*get_pointer() = other;
|
||||
}
|
||||
}
|
||||
T* get_pointer() const { return const_cast< T* >(current); }
|
||||
T* get_pointer() const { return const_cast< T* >(this->current); }
|
||||
// T* operator*() const { if (CheckValid()) return get_pointer(); else return
|
||||
// nullptr; }
|
||||
T* operator->() const { return get_pointer(); }
|
||||
void destroy() const {
|
||||
if (CheckValid()) {
|
||||
if (this->CheckValid()) {
|
||||
rstl::destroy(get_pointer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include "rstl/pointer_iterator.hpp"
|
||||
|
||||
namespace rstl {
|
||||
template < typename T, size_t N >
|
||||
template < typename T, s32 N >
|
||||
class reserved_vector {
|
||||
size_t x0_count;
|
||||
s32 x0_count;
|
||||
u8 x4_data[N * sizeof(T)];
|
||||
|
||||
public:
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
void clear() {
|
||||
for (size_t i = 0; i < x0_count; ++i) {
|
||||
for (s32 i = 0; i < x0_count; ++i) {
|
||||
rstl::destroy(&data()[i]);
|
||||
}
|
||||
x0_count = 0;
|
||||
@@ -54,14 +54,14 @@ public:
|
||||
|
||||
inline T* data() { return reinterpret_cast< T* >(x4_data); }
|
||||
inline const T* data() const { return reinterpret_cast< const T* >(x4_data); }
|
||||
inline size_t size() const { return x0_count; }
|
||||
inline size_t capacity() const { return N; }
|
||||
inline s32 size() const { return x0_count; }
|
||||
inline s32 capacity() const { return N; }
|
||||
inline T& front() { return data()[0]; }
|
||||
inline const T& front() const { return data()[0]; }
|
||||
inline T& back() { return data()[x0_count - 1]; }
|
||||
inline const T& back() const { return data()[x0_count - 1]; }
|
||||
inline T& operator[](size_t idx) { return data()[idx]; }
|
||||
inline const T& operator[](size_t idx) const { return data()[idx]; }
|
||||
inline T& operator[](s32 idx) { return data()[idx]; }
|
||||
inline const T& operator[](s32 idx) const { return data()[idx]; }
|
||||
};
|
||||
} // namespace rstl
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace rstl {
|
||||
struct rmemory_allocator {
|
||||
template < typename T >
|
||||
static void allocate(T*& out, size_t sz) {
|
||||
static void allocate(T*& out, s32 sz) {
|
||||
out = reinterpret_cast< T* >(new u8[sz]);
|
||||
}
|
||||
template < typename T >
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace rstl {
|
||||
template < typename T, typename Alloc = rmemory_allocator >
|
||||
class vector {
|
||||
Alloc x0_allocator;
|
||||
size_t x4_count;
|
||||
size_t x8_capacity;
|
||||
s32 x4_count;
|
||||
s32 x8_capacity;
|
||||
T* xc_items;
|
||||
|
||||
public:
|
||||
@@ -23,14 +23,14 @@ public:
|
||||
inline iterator end() { return iterator(xc_items + x4_count); }
|
||||
inline const_iterator end() const { return const_iterator(xc_items + x4_count); }
|
||||
inline vector() : x4_count(0), x8_capacity(0), xc_items(NULL) {}
|
||||
inline vector(size_t count) : x4_count(0), x8_capacity(0), xc_items(0) { reserve(count); }
|
||||
inline vector(s32 count) : x4_count(0), x8_capacity(0), xc_items(0) { reserve(count); }
|
||||
vector(const vector& other) {
|
||||
x4_count = other.x4_count;
|
||||
x8_capacity = other.x8_capacity;
|
||||
if (other.x4_count == 0 && other.x8_capacity == 0) {
|
||||
xc_items = NULL;
|
||||
} else {
|
||||
size_t sz = x8_capacity * sizeof(T);
|
||||
s32 sz = x8_capacity * sizeof(T);
|
||||
if (sz == 0) {
|
||||
xc_items = NULL;
|
||||
} else {
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
x0_allocator.deallocate(xc_items);
|
||||
}
|
||||
|
||||
void reserve(size_t size);
|
||||
void reserve(s32 size);
|
||||
|
||||
void push_back(const T& in) {
|
||||
if (x4_count >= x8_capacity) {
|
||||
@@ -79,21 +79,21 @@ public:
|
||||
|
||||
inline T* data() { return xc_items; }
|
||||
inline const T* data() const { return xc_items; }
|
||||
inline size_t size() const { return x4_count; }
|
||||
inline size_t capacity() const { return x8_capacity; }
|
||||
inline s32 size() const { return x4_count; }
|
||||
inline s32 capacity() const { return x8_capacity; }
|
||||
inline T& front() { return xc_items[0]; }
|
||||
inline const T& front() const { return xc_items[0]; }
|
||||
inline T& back() { return xc_items[x4_count - 1]; }
|
||||
inline const T& back() const { return xc_items[x4_count - 1]; }
|
||||
inline T& operator[](size_t idx) { return xc_items[idx]; }
|
||||
inline const T& operator[](size_t idx) const { return xc_items[idx]; }
|
||||
inline T& operator[](s32 idx) { return xc_items[idx]; }
|
||||
inline const T& operator[](s32 idx) const { return xc_items[idx]; }
|
||||
};
|
||||
|
||||
template < typename T, typename Alloc >
|
||||
void vector< T, Alloc >::reserve(size_t size) {
|
||||
void vector< T, Alloc >::reserve(s32 size) {
|
||||
if (size <= x8_capacity)
|
||||
return;
|
||||
size_t sz = size * sizeof(T);
|
||||
s32 sz = size * sizeof(T);
|
||||
T* newData;
|
||||
if (sz == 0) {
|
||||
newData = nullptr;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef _STRING_H_
|
||||
#define _STRING_H_
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num);
|
||||
void *memset(void *dest, int ch, size_t count);
|
||||
|
||||
size_t strlen(const char *s);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, size_t num);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
char *strncat(char *dest, const char *src, size_t n);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -33,9 +33,6 @@ typedef double f64;
|
||||
typedef volatile float vf32;
|
||||
typedef volatile double vf64;
|
||||
|
||||
typedef s32 size_t;
|
||||
typedef u32 uintptr_t;
|
||||
|
||||
typedef s16 __OSInterrupt;
|
||||
typedef s64 OSTime;
|
||||
typedef u32 OSTick;
|
||||
|
||||
Reference in New Issue
Block a user