mirror of
https://github.com/zeldaret/mm.git
synced 2026-07-11 06:14:39 -04:00
Organize libc64 files (#1492)
* Move qrand to libc64 * use an union to avoid type punning * __osMalloc * math64.c * fixed_point.h * sleep * aprintf.h * sprintf * malloc * use original names on aprintf.c and malloc.c * qrand cleanup pass * use original names of sleep.c * og names for sprintf * more cleanup * format * fixes * whoops * use ARRAY_COUNT again * comment * Use `fu` * forgot this one * review * fix * sneak a tiny cleanup
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "global.h"
|
||||
#include "libc64/sleep.h"
|
||||
|
||||
void func_80183070(void) {
|
||||
for (;;) {
|
||||
Sleep_Msec(1000);
|
||||
msleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
#include "audiomgr.h"
|
||||
#include "idle.h"
|
||||
#include "sys_cfb.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "z64debug_text.h"
|
||||
#include "z64rumble.h"
|
||||
#include "z64speed_meter.h"
|
||||
@@ -182,7 +182,7 @@ void GameState_Realloc(GameState* gameState, size_t size) {
|
||||
|
||||
THA_Destroy(&gameState->tha);
|
||||
GameAlloc_Free(alloc, heapStart);
|
||||
SystemArena_GetSizes(&systemMaxFree, &bytesFree, &bytesAllocated);
|
||||
GetFreeArena(&systemMaxFree, &bytesFree, &bytesAllocated);
|
||||
size = ((systemMaxFree - sizeof(ArenaNode)) < size) ? 0 : size;
|
||||
if (size == 0) {
|
||||
size = systemMaxFree - sizeof(ArenaNode);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "gamealloc.h"
|
||||
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
|
||||
void GameAlloc_Log(GameAlloc* this) {
|
||||
GameAllocEntry* iter = this->base.next;
|
||||
@@ -11,7 +11,7 @@ void GameAlloc_Log(GameAlloc* this) {
|
||||
}
|
||||
|
||||
void* GameAlloc_Malloc(GameAlloc* this, size_t size) {
|
||||
GameAllocEntry* ptr = SystemArena_Malloc(size + sizeof(GameAllocEntry));
|
||||
GameAllocEntry* ptr = malloc(size + sizeof(GameAllocEntry));
|
||||
|
||||
if (ptr != NULL) {
|
||||
ptr->size = size;
|
||||
@@ -34,7 +34,7 @@ void GameAlloc_Free(GameAlloc* this, void* data) {
|
||||
ptr->prev->next = ptr->next;
|
||||
ptr->next->prev = ptr->prev;
|
||||
this->head = this->base.prev;
|
||||
SystemArena_Free(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ void GameAlloc_Cleanup(GameAlloc* this) {
|
||||
while (&this->base != next) {
|
||||
cur = next;
|
||||
next = next->next;
|
||||
SystemArena_Free(cur);
|
||||
free(cur);
|
||||
}
|
||||
|
||||
this->head = &this->base;
|
||||
|
||||
+5
-6
@@ -16,7 +16,7 @@ OSTime sGraphPrevUpdateEndTime;
|
||||
#include "buffers.h"
|
||||
#include "idle.h"
|
||||
#include "sys_cfb.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "z64speed_meter.h"
|
||||
#include "overlays/gamestates/ovl_daytelop/z_daytelop.h"
|
||||
#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
|
||||
@@ -341,13 +341,12 @@ void Graph_ThreadEntry(void* arg) {
|
||||
u32 size;
|
||||
s32 pad[2];
|
||||
|
||||
gZBufferLoRes = SystemArena_Malloc(sizeof(*gZBufferLoRes) + sizeof(*gWorkBufferLoRes) + 64 - 1);
|
||||
gZBufferLoRes = malloc(sizeof(*gZBufferLoRes) + sizeof(*gWorkBufferLoRes) + 64 - 1);
|
||||
gZBufferLoRes = (void*)ALIGN64((u32)gZBufferLoRes);
|
||||
|
||||
gWorkBufferLoRes = (void*)((u8*)gZBufferLoRes + sizeof(*gZBufferLoRes));
|
||||
|
||||
gGfxSPTaskOutputBufferHiRes = gGfxSPTaskOutputBufferLoRes =
|
||||
SystemArena_Malloc(sizeof(*gGfxSPTaskOutputBufferLoRes));
|
||||
gGfxSPTaskOutputBufferHiRes = gGfxSPTaskOutputBufferLoRes = malloc(sizeof(*gGfxSPTaskOutputBufferLoRes));
|
||||
|
||||
gGfxSPTaskOutputBufferEndLoRes = (u8*)gGfxSPTaskOutputBufferLoRes + sizeof(*gGfxSPTaskOutputBufferLoRes);
|
||||
gGfxSPTaskOutputBufferEndHiRes = (u8*)gGfxSPTaskOutputBufferHiRes + sizeof(*gGfxSPTaskOutputBufferHiRes);
|
||||
@@ -365,7 +364,7 @@ void Graph_ThreadEntry(void* arg) {
|
||||
|
||||
func_800809F4(ovl->vromStart);
|
||||
|
||||
gameState = SystemArena_Malloc(size);
|
||||
gameState = malloc(size);
|
||||
|
||||
bzero(gameState, size);
|
||||
GameState_Init(gameState, ovl->init, &gfxCtx);
|
||||
@@ -379,7 +378,7 @@ void Graph_ThreadEntry(void* arg) {
|
||||
if (size) {}
|
||||
|
||||
GameState_Destroy(gameState);
|
||||
SystemArena_Free(gameState);
|
||||
free(gameState);
|
||||
|
||||
Overlay_FreeGameState(ovl);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "listalloc.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
|
||||
ListAlloc* ListAlloc_Init(ListAlloc* this) {
|
||||
this->prev = NULL;
|
||||
@@ -8,7 +8,7 @@ ListAlloc* ListAlloc_Init(ListAlloc* this) {
|
||||
}
|
||||
|
||||
void* ListAlloc_Alloc(ListAlloc* this, size_t size) {
|
||||
ListAlloc* ptr = SystemArena_Malloc(size + sizeof(ListAlloc));
|
||||
ListAlloc* ptr = malloc(size + sizeof(ListAlloc));
|
||||
ListAlloc* next;
|
||||
|
||||
if (ptr == NULL) {
|
||||
@@ -50,7 +50,7 @@ void ListAlloc_Free(ListAlloc* this, void* data) {
|
||||
this->next = ptr->prev;
|
||||
}
|
||||
|
||||
SystemArena_Free(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void ListAlloc_FreeAll(ListAlloc* this) {
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "global.h"
|
||||
#include "PR/controller.h"
|
||||
#include "PR/os_motor.h"
|
||||
#include "libc64/sprintf.h"
|
||||
#include "fault.h"
|
||||
#include "z64voice.h"
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
#include "fault.h"
|
||||
#include "idle.h"
|
||||
#include "libc64/sleep.h"
|
||||
#include "z64.h"
|
||||
|
||||
// Variables are put before most headers as a hacky way to bypass bss reordering
|
||||
@@ -87,7 +88,7 @@ void Sched_HandleAudioCancel(SchedContext* sched) {
|
||||
osSyncPrintf("AUDIO SP止まりませんでした(10msタイムアウト)\n");
|
||||
goto send_mesg;
|
||||
}
|
||||
Sleep_Usec(100);
|
||||
usleep(100);
|
||||
}
|
||||
// AUDIO SP stopped (% d * 100us)
|
||||
osSyncPrintf("AUDIO SP止まりました(%d * 100us)\n", i);
|
||||
@@ -150,7 +151,7 @@ void Sched_HandleGfxCancel(SchedContext* sched) {
|
||||
osSyncPrintf("GRAPH SP止まりませんでした(10msタイムアウト)\n");
|
||||
goto send_mesg;
|
||||
}
|
||||
Sleep_Usec(100);
|
||||
usleep(100);
|
||||
}
|
||||
// GRAPH SP stopped (%d * 100us)
|
||||
osSyncPrintf("GRAPH SP止まりました(%d * 100us)\n", i);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "gfx.h"
|
||||
#include "regs.h"
|
||||
#include "sys_cfb.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "z64game.h"
|
||||
#include "z64malloc.h"
|
||||
#include "z64view.h"
|
||||
@@ -240,7 +240,7 @@ void SpeedMeter_DrawAllocEntries(SpeedMeter* meter, GraphicsContext* gfxCtx, Gam
|
||||
}
|
||||
|
||||
if (R_ENABLE_ARENA_DBG > 1) {
|
||||
SystemArena_GetSizes((size_t*)&sysFreeMax, (size_t*)&sysFree, (size_t*)&sysAlloc);
|
||||
GetFreeArena((size_t*)&sysFreeMax, (size_t*)&sysFree, (size_t*)&sysAlloc);
|
||||
SpeedMeter_InitAllocEntry(&entry, sysFree + sysAlloc - state->tha.size, sysAlloc - state->tha.size,
|
||||
GPACK_RGBA5551(0, 0, 255, 1), GPACK_RGBA5551(255, 128, 128, 1), ulx, lrx, y, y);
|
||||
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ u8 gSysCfbHiResEnabled;
|
||||
#include "sys_cfb.h"
|
||||
#include "libc/stdbool.h"
|
||||
#include "buffers.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "z64vimode.h"
|
||||
|
||||
void SysCfb_SetLoResMode(void) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "global.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
|
||||
typedef struct {
|
||||
/* 0x0 */ union {
|
||||
@@ -83,11 +83,11 @@ void CmpDma_LoadFileImpl(uintptr_t segmentRom, s32 id, void* dst, size_t size) {
|
||||
|
||||
CmpDma_GetFileInfo(segmentRom, id, &romStart, &compressedSize, &flag);
|
||||
if (flag & 1) {
|
||||
void* tempBuf = SystemArena_Malloc(0x1000);
|
||||
void* tempBuf = malloc(0x1000);
|
||||
|
||||
CmpDma_Decompress(romStart, compressedSize, tempBuf);
|
||||
func_80178AC0(tempBuf, dst, size);
|
||||
SystemArena_Free(tempBuf);
|
||||
free(tempBuf);
|
||||
} else {
|
||||
CmpDma_Decompress(romStart, compressedSize, dst);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "fault.h"
|
||||
#include "stack.h"
|
||||
#include "stackcheck.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "z64thread.h"
|
||||
#include "sys_flashrom.h"
|
||||
#include "PR/os_internal_flash.h"
|
||||
@@ -172,7 +172,7 @@ s32 SysFlashrom_WriteData(void* addr, u32 pageNum, u32 pageCount) {
|
||||
return -1;
|
||||
}
|
||||
size = pageCount * FLASH_BLOCK_SIZE;
|
||||
data = SystemArena_Malloc(size);
|
||||
data = malloc(size);
|
||||
if (data == NULL) {
|
||||
ret = SysFlashrom_AttemptWrite(addr, pageNum, pageCount);
|
||||
} else {
|
||||
@@ -195,7 +195,7 @@ s32 SysFlashrom_WriteData(void* addr, u32 pageNum, u32 pageCount) {
|
||||
}
|
||||
}
|
||||
}
|
||||
SystemArena_Free(data);
|
||||
free(data);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#include "global.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "loadfragment.h"
|
||||
|
||||
void Overlay_LoadGameState(GameStateOverlay* overlayEntry) {
|
||||
@@ -89,7 +89,7 @@ void Overlay_FreeGameState(GameStateOverlay* overlayEntry) {
|
||||
(uintptr_t)overlayEntry->loadedRamAddr))
|
||||
: NULL);
|
||||
|
||||
SystemArena_Free(overlayEntry->loadedRamAddr);
|
||||
free(overlayEntry->loadedRamAddr);
|
||||
overlayEntry->loadedRamAddr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "prevent_bss_reordering.h"
|
||||
#include "global.h"
|
||||
#include "fault.h"
|
||||
#include "fixed_point.h"
|
||||
#include "libc64/fixed_point.h"
|
||||
#include "libc64/sprintf.h"
|
||||
#include "vt.h"
|
||||
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
#include "regs.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "macros.h"
|
||||
|
||||
RegEditor* gRegEditor;
|
||||
@@ -7,7 +7,7 @@ RegEditor* gRegEditor;
|
||||
void Regs_Init(void) {
|
||||
s32 i;
|
||||
|
||||
gRegEditor = SystemArena_Malloc(sizeof(RegEditor));
|
||||
gRegEditor = malloc(sizeof(RegEditor));
|
||||
if (1) {}
|
||||
gRegEditor->regPage = 0;
|
||||
gRegEditor->regGroup = 0;
|
||||
|
||||
+16
-15
@@ -12,8 +12,9 @@
|
||||
|
||||
#include "z64transition.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/sleep.h"
|
||||
#include "libc64/malloc.h"
|
||||
#include "macros.h"
|
||||
|
||||
Gfx sTransTileSetupDL[] = {
|
||||
gsDPPipeSync(),
|
||||
@@ -103,22 +104,22 @@ void TransitionTile_InitVtxData(TransitionTile* this) {
|
||||
}
|
||||
|
||||
void TransitionTile_Destroy(TransitionTile* this) {
|
||||
Sleep_Msec(100);
|
||||
msleep(100);
|
||||
|
||||
if (this->vtxData != NULL) {
|
||||
SystemArena_Free(this->vtxData);
|
||||
free(this->vtxData);
|
||||
this->vtxData = NULL;
|
||||
}
|
||||
if (this->vtxFrame1 != NULL) {
|
||||
SystemArena_Free(this->vtxFrame1);
|
||||
free(this->vtxFrame1);
|
||||
this->vtxFrame1 = NULL;
|
||||
}
|
||||
if (this->vtxFrame2 != NULL) {
|
||||
SystemArena_Free(this->vtxFrame2);
|
||||
free(this->vtxFrame2);
|
||||
this->vtxFrame2 = NULL;
|
||||
}
|
||||
if (this->gfx != NULL) {
|
||||
SystemArena_Free(this->gfx);
|
||||
free(this->gfx);
|
||||
this->gfx = NULL;
|
||||
}
|
||||
}
|
||||
@@ -131,26 +132,26 @@ TransitionTile* TransitionTile_Init(TransitionTile* this, s32 cols, s32 rows) {
|
||||
this->cols = cols;
|
||||
this->rows = rows;
|
||||
gridSize = (cols + 1) * (rows + 1);
|
||||
this->vtxData = SystemArena_Malloc(gridSize * sizeof(TransitionTileVtxData));
|
||||
this->vtxFrame1 = SystemArena_Malloc(gridSize * sizeof(Vtx));
|
||||
this->vtxFrame2 = SystemArena_Malloc(gridSize * sizeof(Vtx));
|
||||
this->gfx = SystemArena_Malloc(((cols * 9 + 1) * rows + 2) * sizeof(Gfx));
|
||||
this->vtxData = malloc(gridSize * sizeof(TransitionTileVtxData));
|
||||
this->vtxFrame1 = malloc(gridSize * sizeof(Vtx));
|
||||
this->vtxFrame2 = malloc(gridSize * sizeof(Vtx));
|
||||
this->gfx = malloc(((cols * 9 + 1) * rows + 2) * sizeof(Gfx));
|
||||
|
||||
if ((this->vtxData == NULL) || (this->vtxFrame1 == NULL) || (this->vtxFrame2 == NULL) || (this->gfx == NULL)) {
|
||||
if (this->vtxData != NULL) {
|
||||
SystemArena_Free(this->vtxData);
|
||||
free(this->vtxData);
|
||||
this->vtxData = NULL;
|
||||
}
|
||||
if (this->vtxFrame1 != NULL) {
|
||||
SystemArena_Free(this->vtxFrame1);
|
||||
free(this->vtxFrame1);
|
||||
this->vtxFrame1 = NULL;
|
||||
}
|
||||
if (this->vtxFrame2 != NULL) {
|
||||
SystemArena_Free(this->vtxFrame2);
|
||||
free(this->vtxFrame2);
|
||||
this->vtxFrame2 = NULL;
|
||||
}
|
||||
if (this->gfx != NULL) {
|
||||
SystemArena_Free(this->gfx);
|
||||
free(this->gfx);
|
||||
this->gfx = NULL;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
+7
-7
@@ -3226,16 +3226,16 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
|
||||
|
||||
// temp_f4 = Rand_ZeroOne_Variable(&randInt);
|
||||
randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
|
||||
gRandFloat = (randInt >> 9) | 0x3F800000;
|
||||
temp = *((f32*)&gRandFloat);
|
||||
gRandFloat.i = (randInt >> 9) | 0x3F800000;
|
||||
temp = gRandFloat.f;
|
||||
temp_f4 = temp - 1.0f;
|
||||
|
||||
// temp_f20 = Rand_ZeroOne_Variable(&randInt);
|
||||
randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
|
||||
gRandFloat = (randInt >> 9) | 0x3F800000;
|
||||
temp_f20 = ((*((f32*)&gRandFloat) - 1.0f) + temp_f4) * 0.5f;
|
||||
gRandFloat.i = (randInt >> 9) | 0x3F800000;
|
||||
temp_f20 = ((gRandFloat.f - 1.0f) + temp_f4) * 0.5f;
|
||||
|
||||
// randInt = Rand_Next_Variable(&randInt);
|
||||
// Rand_Next_Variable(&randInt);
|
||||
randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
|
||||
|
||||
// Set random position
|
||||
@@ -3245,8 +3245,8 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
|
||||
|
||||
// temp_f2 = Rand_ZeroOne_Variable(&randInt);
|
||||
randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
|
||||
gRandFloat = ((randInt >> 9) | 0x3F800000);
|
||||
temp_f2 = *((f32*)&gRandFloat) - 1.0f;
|
||||
gRandFloat.i = ((randInt >> 9) | 0x3F800000);
|
||||
temp_f2 = gRandFloat.f - 1.0f;
|
||||
|
||||
// Set random width
|
||||
imgWidth = (u32)((SQ(temp_f2) * 8.0f) + 2.0f);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#include "z64malloc.h"
|
||||
|
||||
#include "os_malloc.h"
|
||||
#include "libc64/os_malloc.h"
|
||||
|
||||
Arena sZeldaArena;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "global.h"
|
||||
#include "z64vismono.h"
|
||||
#include "system_malloc.h"
|
||||
#include "libc64/malloc.h"
|
||||
|
||||
// Height of the fragments the color frame buffer (CFB) is split into.
|
||||
// It is the maximum amount of lines such that all rgba16 SCREEN_WIDTH-long lines fit into
|
||||
@@ -39,7 +39,7 @@ void VisMono_Init(VisMono* this) {
|
||||
}
|
||||
|
||||
void VisMono_Destroy(VisMono* this) {
|
||||
SystemArena_Free(this->dList);
|
||||
free(this->dList);
|
||||
}
|
||||
|
||||
void VisMono_DesaturateTLUT(u16* tlut) {
|
||||
@@ -169,12 +169,12 @@ void VisMono_Draw(VisMono* this, Gfx** gfxp) {
|
||||
|
||||
void VisMono_DrawOld(VisMono* this) {
|
||||
if (this->tlut == NULL) {
|
||||
this->tlut = SystemArena_Malloc(256 * G_IM_SIZ_16b_BYTES);
|
||||
this->tlut = malloc(256 * G_IM_SIZ_16b_BYTES);
|
||||
VisMono_DesaturateTLUT(this->tlut);
|
||||
}
|
||||
|
||||
if (this->dList == NULL) {
|
||||
this->dList = SystemArena_Malloc(VISMONO_DLSIZE * sizeof(Gfx));
|
||||
this->dList = malloc(VISMONO_DLSIZE * sizeof(Gfx));
|
||||
VisMono_DesaturateDList(this->dList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user