mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-25 13:35:12 +00:00
Remove the main pool
This commit is contained in:
parent
6798b2db29
commit
bbdf51bc33
6 changed files with 0 additions and 173 deletions
|
@ -246,7 +246,6 @@ static void *DynOS_Warp_UpdateWarp(void *aCmd, bool aIsLevelInitDone) {
|
||||||
clear_objects();
|
clear_objects();
|
||||||
clear_area_graph_nodes();
|
clear_area_graph_nodes();
|
||||||
clear_areas();
|
clear_areas();
|
||||||
main_pool_pop_state();
|
|
||||||
|
|
||||||
// Reset Mario's state
|
// Reset Mario's state
|
||||||
gMarioState->healCounter = 0;
|
gMarioState->healCounter = 0;
|
||||||
|
@ -414,7 +413,6 @@ static void *DynOS_Warp_UpdateExit(void *aCmd, bool aIsLevelInitDone) {
|
||||||
clear_objects();
|
clear_objects();
|
||||||
clear_area_graph_nodes();
|
clear_area_graph_nodes();
|
||||||
clear_areas();
|
clear_areas();
|
||||||
main_pool_pop_state();
|
|
||||||
|
|
||||||
// Reset Mario's state
|
// Reset Mario's state
|
||||||
gMarioState->healCounter = 0;
|
gMarioState->healCounter = 0;
|
||||||
|
|
|
@ -141,7 +141,6 @@ static void area_check_red_coin_or_secret(void *arg, bool isMacroObject) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void level_cmd_load_and_execute(void) {
|
static void level_cmd_load_and_execute(void) {
|
||||||
main_pool_push_state();
|
|
||||||
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8), MEMORY_POOL_LEFT);
|
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8), MEMORY_POOL_LEFT);
|
||||||
|
|
||||||
*sStackTop++ = (uintptr_t) NEXT_CMD;
|
*sStackTop++ = (uintptr_t) NEXT_CMD;
|
||||||
|
@ -154,9 +153,6 @@ static void level_cmd_load_and_execute(void) {
|
||||||
static void level_cmd_exit_and_execute(void) {
|
static void level_cmd_exit_and_execute(void) {
|
||||||
void *targetAddr = CMD_GET(void *, 12);
|
void *targetAddr = CMD_GET(void *, 12);
|
||||||
|
|
||||||
main_pool_pop_state();
|
|
||||||
main_pool_push_state();
|
|
||||||
|
|
||||||
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8),
|
load_segment(CMD_GET(s16, 2), CMD_GET(void *, 4), CMD_GET(void *, 8),
|
||||||
MEMORY_POOL_LEFT);
|
MEMORY_POOL_LEFT);
|
||||||
|
|
||||||
|
@ -165,8 +161,6 @@ static void level_cmd_exit_and_execute(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void level_cmd_exit(void) {
|
static void level_cmd_exit(void) {
|
||||||
main_pool_pop_state();
|
|
||||||
|
|
||||||
sStackTop = sStackBase;
|
sStackTop = sStackBase;
|
||||||
sStackBase = (uintptr_t *) *(--sStackTop);
|
sStackBase = (uintptr_t *) *(--sStackTop);
|
||||||
sCurrentCmd = (struct LevelCommand *) *(--sStackTop);
|
sCurrentCmd = (struct LevelCommand *) *(--sStackTop);
|
||||||
|
@ -307,12 +301,10 @@ static void level_cmd_set_register(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void level_cmd_push_pool_state(void) {
|
static void level_cmd_push_pool_state(void) {
|
||||||
main_pool_push_state();
|
|
||||||
sCurrentCmd = CMD_NEXT;
|
sCurrentCmd = CMD_NEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void level_cmd_pop_pool_state(void) {
|
static void level_cmd_pop_pool_state(void) {
|
||||||
main_pool_pop_state();
|
|
||||||
sCurrentCmd = CMD_NEXT;
|
sCurrentCmd = CMD_NEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +350,6 @@ static void level_cmd_init_level(void) {
|
||||||
init_graph_node_start(NULL, (struct GraphNodeStart *) &gObjParentGraphNode);
|
init_graph_node_start(NULL, (struct GraphNodeStart *) &gObjParentGraphNode);
|
||||||
clear_objects();
|
clear_objects();
|
||||||
clear_areas();
|
clear_areas();
|
||||||
main_pool_push_state();
|
|
||||||
smlua_model_util_clear();
|
smlua_model_util_clear();
|
||||||
gSkipInterpolationTitleScreen = false;
|
gSkipInterpolationTitleScreen = false;
|
||||||
|
|
||||||
|
@ -377,8 +368,6 @@ static void level_cmd_clear_level(void) {
|
||||||
sLevelOwnedGraphNodes[i] = false;
|
sLevelOwnedGraphNodes[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
main_pool_pop_state();
|
|
||||||
|
|
||||||
|
|
||||||
sCurrentCmd = CMD_NEXT;
|
sCurrentCmd = CMD_NEXT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,13 +142,6 @@ void setup_mesg_queues(void) {
|
||||||
osSetEventMesg(OS_EVENT_PRENMI, &gIntrMesgQueue, (OSMesg) MESG_NMI_REQUEST);
|
osSetEventMesg(OS_EVENT_PRENMI, &gIntrMesgQueue, (OSMesg) MESG_NMI_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
void alloc_pool(void) {
|
|
||||||
void *start = (void *) SEG_POOL_START;
|
|
||||||
void *end = (void *) (SEG_POOL_START + POOL_SIZE);
|
|
||||||
|
|
||||||
main_pool_init(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_thread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) {
|
void create_thread(OSThread *thread, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri pri) {
|
||||||
thread->next = NULL;
|
thread->next = NULL;
|
||||||
thread->queue = NULL;
|
thread->queue = NULL;
|
||||||
|
@ -343,7 +336,6 @@ void handle_dp_complete(void) {
|
||||||
|
|
||||||
void thread3_main(UNUSED void *arg) {
|
void thread3_main(UNUSED void *arg) {
|
||||||
setup_mesg_queues();
|
setup_mesg_queues();
|
||||||
alloc_pool();
|
|
||||||
load_engine_code_segment();
|
load_engine_code_segment();
|
||||||
|
|
||||||
create_thread(&gSoundThread, 4, thread4_sound, NULL, gThread4Stack + 0x2000, 20);
|
create_thread(&gSoundThread, 4, thread4_sound, NULL, gThread4Stack + 0x2000, 20);
|
||||||
|
|
|
@ -78,145 +78,6 @@ void *virtual_to_segmented(UNUSED u32 segment, const void *addr) {
|
||||||
void move_segment_table_to_dmem(void) {
|
void move_segment_table_to_dmem(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the main memory pool. This pool is conceptually a pair of stacks
|
|
||||||
* that grow inward from the left and right. It therefore only supports
|
|
||||||
* freeing the object that was most recently allocated from a side.
|
|
||||||
*/
|
|
||||||
void main_pool_init(void *start, void *end) {
|
|
||||||
sPoolStart = (u8 *) ALIGN16((uintptr_t) start) + 16;
|
|
||||||
sPoolEnd = (u8 *) ALIGN16((uintptr_t) end - 15) - 16;
|
|
||||||
sPoolFreeSpace = sPoolEnd - sPoolStart;
|
|
||||||
|
|
||||||
sPoolListHeadL = (struct MainPoolBlock *) (sPoolStart - 16);
|
|
||||||
sPoolListHeadR = (struct MainPoolBlock *) sPoolEnd;
|
|
||||||
sPoolListHeadL->prev = NULL;
|
|
||||||
sPoolListHeadL->next = NULL;
|
|
||||||
sPoolListHeadR->prev = NULL;
|
|
||||||
sPoolListHeadR->next = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allocate a block of memory from the pool of given size, and from the
|
|
||||||
* specified side of the pool (MEMORY_POOL_LEFT or MEMORY_POOL_RIGHT).
|
|
||||||
* If there is not enough space, return NULL.
|
|
||||||
*/
|
|
||||||
void *main_pool_alloc(u32 size, u32 side) {
|
|
||||||
struct MainPoolBlock *newListHead;
|
|
||||||
void *addr = NULL;
|
|
||||||
|
|
||||||
size = ALIGN16(size) + 16;
|
|
||||||
if (size != 0 && sPoolFreeSpace >= size) {
|
|
||||||
sPoolFreeSpace -= size;
|
|
||||||
if (side == MEMORY_POOL_LEFT) {
|
|
||||||
newListHead = (struct MainPoolBlock *) ((u8 *) sPoolListHeadL + size);
|
|
||||||
sPoolListHeadL->next = newListHead;
|
|
||||||
newListHead->prev = sPoolListHeadL;
|
|
||||||
newListHead->next = NULL;
|
|
||||||
addr = (u8 *) sPoolListHeadL + 16;
|
|
||||||
sPoolListHeadL = newListHead;
|
|
||||||
} else {
|
|
||||||
newListHead = (struct MainPoolBlock *) ((u8 *) sPoolListHeadR - size);
|
|
||||||
sPoolListHeadR->prev = newListHead;
|
|
||||||
newListHead->next = sPoolListHeadR;
|
|
||||||
newListHead->prev = NULL;
|
|
||||||
sPoolListHeadR = newListHead;
|
|
||||||
addr = (u8 *) sPoolListHeadR + 16;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (addr == NULL) {
|
|
||||||
LOG_ERROR("Main pool failed to allocate memory of size 0x%X on side %d.", size, side);
|
|
||||||
}
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Free a block of memory that was allocated from the pool. The block must be
|
|
||||||
* the most recently allocated block from its end of the pool, otherwise all
|
|
||||||
* newer blocks are freed as well.
|
|
||||||
* Return the amount of free space left in the pool.
|
|
||||||
*/
|
|
||||||
u32 main_pool_free(void *addr) {
|
|
||||||
struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 16);
|
|
||||||
struct MainPoolBlock *oldListHead = (struct MainPoolBlock *) ((u8 *) addr - 16);
|
|
||||||
|
|
||||||
if (oldListHead < sPoolListHeadL) {
|
|
||||||
while (oldListHead->next != NULL) {
|
|
||||||
oldListHead = oldListHead->next;
|
|
||||||
}
|
|
||||||
sPoolListHeadL = block;
|
|
||||||
sPoolListHeadL->next = NULL;
|
|
||||||
sPoolFreeSpace += (uintptr_t) oldListHead - (uintptr_t) sPoolListHeadL;
|
|
||||||
} else {
|
|
||||||
while (oldListHead->prev != NULL) {
|
|
||||||
oldListHead = oldListHead->prev;
|
|
||||||
}
|
|
||||||
sPoolListHeadR = block->next;
|
|
||||||
sPoolListHeadR->prev = NULL;
|
|
||||||
sPoolFreeSpace += (uintptr_t) sPoolListHeadR - (uintptr_t) oldListHead;
|
|
||||||
}
|
|
||||||
return sPoolFreeSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resize a block of memory that was allocated from the left side of the pool.
|
|
||||||
* If the block is increasing in size, it must be the most recently allocated
|
|
||||||
* block from the left side.
|
|
||||||
* The block does not move.
|
|
||||||
*/
|
|
||||||
void *main_pool_realloc(void *addr, u32 size) {
|
|
||||||
void *newAddr = NULL;
|
|
||||||
struct MainPoolBlock *block = (struct MainPoolBlock *) ((u8 *) addr - 16);
|
|
||||||
|
|
||||||
if (block->next == sPoolListHeadL) {
|
|
||||||
main_pool_free(addr);
|
|
||||||
newAddr = main_pool_alloc(size, MEMORY_POOL_LEFT);
|
|
||||||
}
|
|
||||||
if (addr == NULL) {
|
|
||||||
LOG_ERROR("Main pool failed to reallocate memory of size 0x%X at %p!", size, addr);
|
|
||||||
}
|
|
||||||
return newAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the size of the largest block that can currently be allocated from the
|
|
||||||
* pool.
|
|
||||||
*/
|
|
||||||
u32 main_pool_available(void) {
|
|
||||||
return sPoolFreeSpace - 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Push pool state, to be restored later. Return the amount of free space left
|
|
||||||
* in the pool.
|
|
||||||
*/
|
|
||||||
u32 main_pool_push_state(void) {
|
|
||||||
struct MainPoolState *prevState = gMainPoolState;
|
|
||||||
u32 freeSpace = sPoolFreeSpace;
|
|
||||||
struct MainPoolBlock *lhead = sPoolListHeadL;
|
|
||||||
struct MainPoolBlock *rhead = sPoolListHeadR;
|
|
||||||
|
|
||||||
gMainPoolState = main_pool_alloc(sizeof(*gMainPoolState), MEMORY_POOL_LEFT);
|
|
||||||
gMainPoolState->freeSpace = freeSpace;
|
|
||||||
gMainPoolState->listHeadL = lhead;
|
|
||||||
gMainPoolState->listHeadR = rhead;
|
|
||||||
gMainPoolState->prev = prevState;
|
|
||||||
return sPoolFreeSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restore pool state from a previous call to main_pool_push_state. Return the
|
|
||||||
* amount of free space left in the pool.
|
|
||||||
*/
|
|
||||||
u32 main_pool_pop_state(void) {
|
|
||||||
if (!gMainPoolState) { return sPoolFreeSpace; }
|
|
||||||
sPoolFreeSpace = gMainPoolState->freeSpace;
|
|
||||||
sPoolListHeadL = gMainPoolState->listHeadL;
|
|
||||||
sPoolListHeadR = gMainPoolState->listHeadR;
|
|
||||||
gMainPoolState = gMainPoolState->prev;
|
|
||||||
return sPoolFreeSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct MarioAnimDmaRelatedThing* func_802789F0(u8* srcAddr) {
|
static struct MarioAnimDmaRelatedThing* func_802789F0(u8* srcAddr) {
|
||||||
u32 count = 0;
|
u32 count = 0;
|
||||||
memcpy(&count, srcAddr, sizeof(u32));
|
memcpy(&count, srcAddr, sizeof(u32));
|
||||||
|
|
|
@ -49,14 +49,6 @@ void *segmented_to_virtual(const void *addr);
|
||||||
void *virtual_to_segmented(u32 segment, const void *addr);
|
void *virtual_to_segmented(u32 segment, const void *addr);
|
||||||
void move_segment_table_to_dmem(void);
|
void move_segment_table_to_dmem(void);
|
||||||
|
|
||||||
void main_pool_init(void *start, void *end);
|
|
||||||
void *main_pool_alloc(u32 size, u32 side);
|
|
||||||
u32 main_pool_free(void *addr);
|
|
||||||
void *main_pool_realloc(void *addr, u32 size);
|
|
||||||
u32 main_pool_available(void);
|
|
||||||
u32 main_pool_push_state(void);
|
|
||||||
u32 main_pool_pop_state(void);
|
|
||||||
|
|
||||||
#define load_segment(...)
|
#define load_segment(...)
|
||||||
#define load_to_fixed_pool_addr(...)
|
#define load_to_fixed_pool_addr(...)
|
||||||
#define load_segment_decompress(...)
|
#define load_segment_decompress(...)
|
||||||
|
|
|
@ -318,11 +318,6 @@ void main_func(void) {
|
||||||
else if (gCLIOpts.FullScreen == 2)
|
else if (gCLIOpts.FullScreen == 2)
|
||||||
configWindow.fullscreen = false;
|
configWindow.fullscreen = false;
|
||||||
|
|
||||||
const size_t poolsize = gCLIOpts.PoolSize ? gCLIOpts.PoolSize : DEFAULT_POOL_SIZE;
|
|
||||||
u64 *pool = calloc(poolsize, 1);
|
|
||||||
if (!pool) sys_fatal("Could not alloc %u bytes for main pool.\n", poolsize);
|
|
||||||
main_pool_init(pool, pool + poolsize / sizeof(pool[0]));
|
|
||||||
|
|
||||||
#if defined(WAPI_SDL1) || defined(WAPI_SDL2)
|
#if defined(WAPI_SDL1) || defined(WAPI_SDL2)
|
||||||
wm_api = &gfx_sdl;
|
wm_api = &gfx_sdl;
|
||||||
#elif defined(WAPI_DXGI)
|
#elif defined(WAPI_DXGI)
|
||||||
|
|
Loading…
Reference in a new issue