Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
Memory.hh
1
#pragma once
2
3
#include <Logger.hh>
4
5
#include <cstdint>
6
7
namespace
Kinoko {
8
9
// We can't include Common.hh, because we have a cyclic dependency
10
// Instead, we redefine the types for use in memory code
11
typedef
int8_t s8;
12
typedef
int16_t s16;
13
typedef
int32_t s32;
14
typedef
int64_t s64;
15
16
typedef
uint8_t u8;
17
typedef
uint16_t u16;
18
typedef
uint32_t u32;
19
typedef
uint64_t u64;
20
21
typedef
float
f32;
22
typedef
double
f64;
23
24
static
inline
uintptr_t GetAddrNum(
const
void
*p) {
25
return
reinterpret_cast<
uintptr_t
>
(p);
26
}
27
28
static
inline
void
*GetAddrPtr(uintptr_t n) {
29
return
reinterpret_cast<
void
*
>
(n);
30
}
31
32
static
inline
void
*AddOffset(
const
void
*p,
size_t
offset) {
33
return
GetAddrPtr(GetAddrNum(p) + offset);
34
}
35
36
static
inline
void
*SubOffset(
const
void
*p,
size_t
offset) {
37
return
GetAddrPtr(GetAddrNum(p) - offset);
38
}
39
40
static
inline
uintptr_t RoundUp(uintptr_t value, uintptr_t alignment) {
41
return
(value + alignment - 1) & ~(alignment - 1);
42
}
43
44
static
inline
void
*RoundUp(
void
*ptr, uintptr_t alignment) {
45
return
GetAddrPtr(RoundUp(GetAddrNum(ptr), alignment));
46
}
47
48
static
inline
uintptr_t RoundDown(uintptr_t value, uintptr_t alignment) {
49
return
value & ~(alignment - 1);
50
}
51
52
static
inline
void
*RoundDown(
void
*ptr, uintptr_t alignment) {
53
return
GetAddrPtr(RoundDown(GetAddrNum(ptr), alignment));
54
}
55
56
}
// namespace Kinoko
abstract
memory
Memory.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0