libctru  v2.4.1
vram.h
Go to the documentation of this file.
1 /**
2  * @file vram.h
3  * @brief VRAM allocator.
4  */
5 #pragma once
6 
7 typedef enum vramAllocPos
8 {
9  VRAM_ALLOC_A = BIT(0),
10  VRAM_ALLOC_B = BIT(1),
11  VRAM_ALLOC_ANY = VRAM_ALLOC_A | VRAM_ALLOC_B,
12 } vramAllocPos;
13 
14 /**
15  * @brief Allocates a 0x80-byte aligned buffer.
16  * @param size Size of the buffer to allocate.
17  * @return The allocated buffer.
18  */
19 void* vramAlloc(size_t size);
20 
21 /**
22  * @brief Allocates a 0x80-byte aligned buffer in the given VRAM bank.
23  * @param size Size of the buffer to allocate.
24  * @param pos VRAM bank to use (see \ref vramAllocPos).
25  * @return The allocated buffer.
26  */
27 void* vramAllocAt(size_t size, vramAllocPos pos);
28 
29 /**
30  * @brief Allocates a buffer aligned to the given size.
31  * @param size Size of the buffer to allocate.
32  * @param alignment Alignment to use.
33  * @return The allocated buffer.
34  */
35 void* vramMemAlign(size_t size, size_t alignment);
36 
37 /**
38  * @brief Allocates a buffer aligned to the given size in the given VRAM bank.
39  * @param size Size of the buffer to allocate.
40  * @param alignment Alignment to use.
41  * @param pos VRAM bank to use (see \ref vramAllocPos).
42  * @return The allocated buffer.
43  */
44 void* vramMemAlignAt(size_t size, size_t alignment, vramAllocPos pos);
45 
46 /**
47  * @brief Reallocates a buffer.
48  * Note: Not implemented yet.
49  * @param mem Buffer to reallocate.
50  * @param size Size of the buffer to allocate.
51  * @return The reallocated buffer.
52  */
53 void* vramRealloc(void* mem, size_t size);
54 
55 /**
56  * @brief Retrieves the allocated size of a buffer.
57  * @return The size of the buffer.
58  */
59 size_t vramGetSize(void* mem);
60 
61 /**
62  * @brief Frees a buffer.
63  * @param mem Buffer to free.
64  */
65 void vramFree(void* mem);
66 
67 /**
68  * @brief Gets the current VRAM free space.
69  * @return The current VRAM free space.
70  */
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:47
uint32_t u32
32-bit unsigned integer
Definition: types.h:23
void * vramAlloc(size_t size)
Allocates a 0x80-byte aligned buffer.
void * vramMemAlign(size_t size, size_t alignment)
Allocates a buffer aligned to the given size.
void * vramMemAlignAt(size_t size, size_t alignment, vramAllocPos pos)
Allocates a buffer aligned to the given size in the given VRAM bank.
void * vramAllocAt(size_t size, vramAllocPos pos)
Allocates a 0x80-byte aligned buffer in the given VRAM bank.
u32 vramSpaceFree(void)
Gets the current VRAM free space.
void vramFree(void *mem)
Frees a buffer.
void * vramRealloc(void *mem, size_t size)
Reallocates a buffer.
size_t vramGetSize(void *mem)
Retrieves the allocated size of a buffer.