summaryrefslogtreecommitdiff
path: root/src/code/gfxalloc.c
blob: 2af4926bac50dff55098ab046819045998afb1ad (plain)
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
#include "gfxalloc.h"

#include "alignment.h"

Gfx* Gfx_Open(Gfx* gfx) {
    return &gfx[1];
}

Gfx* Gfx_Close(Gfx* gfx, Gfx* dst) {
    gSPBranchList(gfx, dst);
    return dst;
}

/**
 * Allocates a structure of `size` into the display list buffer`gfx`,
 * returning a pointer to the start of the buffer.
 * Since the alloc may not itself be display list commands, a BranchList
 * command is used to step over this region.
 */
void* Gfx_Alloc(Gfx** gfxP, size_t size) {
    u8* start;
    Gfx* gfx;

    size = ALIGN8(size);
    start = (u8*)&(*gfxP)[1];
    gfx = (Gfx*)(start + size);
    gSPBranchList(*gfxP, gfx);

    *gfxP = gfx;
    return start;
}