summaryrefslogtreecommitdiff
path: root/include/m/m_heap.h
blob: 8e29eb4386c48647e2835ee329bd31c77aae0aac (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
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
72
73
74
#ifndef M_HEAP_H
#define M_HEAP_H

#include "common.h"
#include "egg/core/eggExpHeap.h"
#include "egg/core/eggFrmHeap.h"

// #include "egg/core/eggExpHeap.h"
// #include "egg/core/eggAssertHeap.h"

// TODO: REWRITE THIS

namespace EGG {
class ExpHeap;
class AssertHeap;
} // namespace EGG
// TODO: Doc symbols and func locations
class mHeap {
public:
    // TODO - fix when importing RVL MEM
    enum AllocOptBit_t {
        OPT_NONE = 0x0,
        OPT_1 = 0x1,
        OPT_2 = 0x2,
        OPT_4 = 0x4,
    };

    static u16 GetOptFlag(AllocOptBit_t);
    static EGG::Heap *setCurrentHeap(EGG::Heap *);
    static EGG::Heap *
    createExpHeap(size_t size, EGG::Heap *parentHeap, const char *name, u32 align, AllocOptBit_t attrs);
    static size_t adjustExpHeap(EGG::ExpHeap *heap);
    static size_t expHeapCost(size_t start, u32 size);
    static EGG::FrmHeap *
    createFrmHeap(size_t size, EGG::Heap *parentHeap, const char *name, size_t align, AllocOptBit_t attrs);
    static void destroyFrmHeap(EGG::FrmHeap *heap);
    static size_t adjustFrmHeap(EGG::FrmHeap *heap);
    static size_t frmHeapCost(size_t start, u32 size);
    mHeap() : heap(nullptr) {}
    mHeap(EGG::Heap *heap);
    ~mHeap();
    static EGG::ExpHeap *createHeap(size_t size, EGG::Heap *, const char *name);
    static void saveCurrentHeap();
    static void restoreCurrentHeap();
    static EGG::FrmHeap *
    createFrmHeapToCurrent(size_t size, EGG::Heap *parentHeap, const char *name, u32 align, AllocOptBit_t attrs);
    static int getGameHeapNum();
    static EGG::Heap *createGameHeap(int heapNum, size_t size, EGG::Heap *parentHeap);
    static void createGameHeap1(size_t size, EGG::Heap *parentHeap);
    static void createArchiveHeap(size_t size, EGG::Heap *parentHeap);
    static void createCommandHeap(size_t size, EGG::Heap *parentHeap);
    static void createDylinkHeap(size_t size, EGG::Heap *parentHeap);
    static EGG::AssertHeap *createAssertHeap(EGG::Heap *parentHeap);
    static EGG::FrmHeap *makeHeapOnCurrentGameHeap(size_t size, const char *name, u32 align, AllocOptBit_t flags);

    static int getDefaultGameHeapId();

    static bool isValidHeapId(u32 id) {
        return id >= 1 && id <= 2;
    }

    static EGG::Heap *g_gameHeaps[4];
    static EGG::Heap *s_SavedCurrentHeap;
    static EGG::Heap *g_archiveHeap;
    static EGG::Heap *g_commandHeap;
    static EGG::ExpHeap *g_dylinkHeap;
    static EGG::AssertHeap *g_assertHeap;
    static u8 g_DefaultGameHeapId;
    static const char *const s_GameHeapNames[4];

    EGG::Heap *heap;
}; // namespace mHeap

#endif