Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
heap.h
Go to the documentation of this file.
1#ifndef DW3_HEAP_H
2#define DW3_HEAP_H
3
4/* The heap (system/heap.c) */
5
6#include "common.h"
7#include <sys/types.h>
8#include <libgte.h>
9#include <libgpu.h>
10
11/* The heap: a doubly linked list of blocks from HEAP_START to HEAP_END */
12#define HEAP_END ((MemBlock *)0x801FF000)
13
14/* MemBlock.tag */
15#define MEM_FREE 0
16#define MEM_END 1 /* the marker that ends the list */
17#define MEM_MODE 2 /* the current mode's: freed by main whenever the mode task ends */
18#define MEM_FILE_CACHE 3
19#define MEM_LOCKED 4 /* kept across mode changes (lockMem) */
20
21/* The heap (HEAP) */
22typedef struct Heap {
23 /* 0x00 */ s32 size;
24 /* 0x04 */ struct MemBlock *first;
25 /* 0x08 */ struct MemBlock *end;
26 /* 0x0C */ void (*init)();
27 /* 0x10 */ void (*free)(void *ptr);
28 /* 0x14 */ void (*freeByTag)();
29 /* 0x18 */ void *(*alloc)(s32 size, s32 tag);
30 /* 0x1C */ void *(*allocHigh)(s32 size, s32 tag); /* from the end of the heap */
31 /* 0x20 */ void *(*allocZeroed)(s32 size, s32 tag);
32 /* 0x24 */ void (*zero)(void *ptr, s32 size);
33 /* 0x28 */ void (*fill)(void *ptr, s32 value, s32 size);
34 /* 0x2C */ void (*lock)();
35 /* 0x30 */ void (*nop)();
36} Heap;
37
38/* Header of a heap block; the data follows it. Sizes are in bytes, so the
39 allocator measures and splits blocks through u8 pointers. */
40typedef struct MemBlock {
41 /* 0x0 */ struct MemBlock *prev;
42 /* 0x4 */ struct MemBlock *next;
43 /* 0x8 */ s32 tag; /* MEM_* */
44} MemBlock;
45
46void freeMem(void *ptr);
47void heapNop(void);
48void freeMemByTag(s32 tag);
49void initHeap(void);
50void zeroMem(void *dst, s32 size);
51void fillMem(s8 *dst, s8 value, s32 count);
52void *allocMem(s32 size, s32 tag);
53void allocMemHigh(s32 size, s32 tag);
54void *allocMemZeroed(s32 size, s32 tag);
55void lockMem(void *ptr, s32 lock);
56void *tryAllocMem(u32 size, s32 tag);
57void *tryAllocMemHigh(u32 size, s32 tag);
58
59extern Heap HEAP;
60extern MemBlock *HEAP_START;
61/* The heap's first block, after the overlays: a linker symbol (tools/link_heap.py) */
62extern MemBlock HEAP_BASE[];
63
64#endif /* DW3_HEAP_H */
signed int s32
Definition common.h:11
unsigned int u32
Definition common.h:12
signed char s8
Definition common.h:7
void freeMemByTag(s32 tag)
Frees every heap block with tag tag
Definition heap.c:29
void * allocMemZeroed(s32 size, s32 tag)
allocMem, cleared
Definition heap.c:164
MemBlock HEAP_BASE[]
The heap's first block, after the overlays: a linker symbol (tools/link_heap.py)
void freeMem(void *ptr)
Frees a heap block, merging it with the free blocks around it.
Definition heap.c:4
void lockMem(void *ptr, s32 lock)
Keeps a block alive across mode changes, or hands it back to the mode.
Definition heap.c:172
void * tryAllocMem(u32 size, s32 tag)
First fit from the start of the heap.
Definition heap.c:87
void initHeap(void)
Makes the heap one free block from HEAP_START, followed by the end marker.
Definition heap.c:40
MemBlock * HEAP_START
The first of the executable's small data (.sdata), where $gp points.
Definition heap_start.c:10
void allocMemHigh(s32 size, s32 tag)
The block is returned in v0, left there by tryAllocMemHigh.
Definition heap.c:157
void fillMem(s8 *dst, s8 value, s32 count)
Sets count bytes to value
Definition heap.c:78
void * allocMem(s32 size, s32 tag)
Evicts cached files until the allocation fits.
Definition heap.c:147
void * tryAllocMemHigh(u32 size, s32 tag)
First fit from the end of the heap.
Definition heap.c:116
void heapNop(void)
HEAP.nop: empty, and nothing calls it.
Definition heap.c:25
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
void zeroMem(void *dst, s32 size)
Clears size bytes, a word at a time when size is a multiple of 4.
Definition heap.c:58
The heap (HEAP)
Definition heap.h:22
void(* fill)(void *ptr, s32 value, s32 size)
Definition heap.h:33
struct MemBlock * end
Definition heap.h:25
s32 size
Definition heap.h:23
void(* zero)(void *ptr, s32 size)
Definition heap.h:32
void(* lock)()
Definition heap.h:34
void(* freeByTag)()
Definition heap.h:28
struct MemBlock * first
Definition heap.h:24
void(* free)(void *ptr)
Definition heap.h:27
void(* nop)()
Definition heap.h:35
void(* init)()
Definition heap.h:26
Header of a heap block; the data follows it.
Definition heap.h:40
struct MemBlock * prev
Definition heap.h:41
struct MemBlock * next
Definition heap.h:42
s32 tag
MEM_*.
Definition heap.h:43