-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxmem.h
71 lines (53 loc) · 1.83 KB
/
xmem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* This file belongs to the 'xlab' game engine.
* Copyright 2009 xfacter
* Copyright 2016 wickles
* This work is licensed under the LGPLv3
* subject to all terms as reproduced in the included LICENSE file.
*/
#pragma once
#include "xconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
/* No-cache memory area, OR with pointers to bypass cache */
#define X_MEM_NO_CACHE (0x40000000)
/* Allegrex Scrathcpad, 16 KiB */
#define X_MEM_SCRATCH (0x00010000)
#define X_MEM_SCRATCH_SIZE (0x00004000)
/* Ge VRAM, 2 MiB */
#define X_MEM_VRAM (0x04000000)
#define X_MEM_VRAM_SIZE (0x00200000)
#define X_MEM_VRAM_NO_CACHE (X_MEM_NO_CACHE|X_MEM_VRAM)
/* Allegrex User Memory, 24 MiB */
#define X_MEM_USER (0x08800000)
#define X_MEM_USER_SIZE (0x01800000)
#define X_MEM_USER_NO_CACHE (X_MEM_NO_CACHE|X_MEM_USER)
/* Allegrex Kernel Memory, 8 MiB */
#define X_MEM_KERNEL (0x88000000)
#define X_MEM_KERNEL_SIZE (0x00800000)
/* Macros for easy memory management */
#define X_NEW(TYPE, SIZE) (TYPE*)x_malloc((SIZE)*sizeof(TYPE))
#define X_DELETE(PTR) do{if (PTR) x_free(PTR); PTR = 0;}while(0)
/* Macros for modifying VRAM pointers */
#define X_VREL(PTR) ((void*)((u32)(PTR) & ~X_MEM_VRAM))
#define X_VABS(PTR) ((void*)((u32)(PTR) | X_MEM_VRAM))
#define X_VFREE(REL_PTR) x_free(X_VABS(REL_PTR))
/* Macros for modifying cached/uncached pointers */
#define X_CACHED(PTR) ((void*)((u32)(PTR) & ~X_MEM_NO_CACHE))
#define X_UNCACHED(PTR) ((void*)((u32)(PTR) | X_MEM_NO_CACHE))
/* allocate to main mem */
void* x_malloc(u32 size);
/* allocate to vram */
void* x_valloc(u32 size);
/* allocate to scratch pad */
void* x_salloc(u32 size);
/* realloc previously malloced main mem */
void* x_remalloc(void* ptr, u32 size);
/* free any kind of mem */
void x_free(void* ptr);
u32 x_vlargest();
u32 x_slargest();
#ifdef __cplusplus
}
#endif