summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-11-26 22:01:42 -0300
committerGitHub <noreply@github.com>2023-11-27 12:01:42 +1100
commit6dd16009361b2561f77b7933981611a9b975fa21 (patch)
tree606f9bd82debe312be65d4e05798e9dc2435ae41 /src/code
parent34492a4386446fc82220fe0684ff521d760e84bd (diff)
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
Diffstat (limited to 'src/code')
-rw-r--r--src/code/code_80183070.c3
-rw-r--r--src/code/game.c4
-rw-r--r--src/code/gamealloc.c8
-rw-r--r--src/code/graph.c11
-rw-r--r--src/code/listalloc.c6
-rw-r--r--src/code/padmgr.c1
-rw-r--r--src/code/sched.c5
-rw-r--r--src/code/speed_meter.c4
-rw-r--r--src/code/sys_cfb.c2
-rw-r--r--src/code/sys_cmpdma.c6
-rw-r--r--src/code/sys_flashrom.c6
-rw-r--r--src/code/z_DLF.c4
-rw-r--r--src/code/z_bgcheck.c3
-rw-r--r--src/code/z_debug.c4
-rw-r--r--src/code/z_fbdemo.c31
-rw-r--r--src/code/z_kankyo.c14
-rw-r--r--src/code/z_malloc.c2
-rw-r--r--src/code/z_vismono.c8
18 files changed, 63 insertions, 59 deletions
diff --git a/src/code/code_80183070.c b/src/code/code_80183070.c
index 7b84aa280..ce84e3b2b 100644
--- a/src/code/code_80183070.c
+++ b/src/code/code_80183070.c
@@ -1,7 +1,8 @@
#include "global.h"
+#include "libc64/sleep.h"
void func_80183070(void) {
for (;;) {
- Sleep_Msec(1000);
+ msleep(1000);
}
}
diff --git a/src/code/game.c b/src/code/game.c
index 237783319..0179062f4 100644
--- a/src/code/game.c
+++ b/src/code/game.c
@@ -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);
diff --git a/src/code/gamealloc.c b/src/code/gamealloc.c
index a0d6f741f..58894324b 100644
--- a/src/code/gamealloc.c
+++ b/src/code/gamealloc.c
@@ -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;
diff --git a/src/code/graph.c b/src/code/graph.c
index 004659f34..d9264d9b4 100644
--- a/src/code/graph.c
+++ b/src/code/graph.c
@@ -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);
}
diff --git a/src/code/listalloc.c b/src/code/listalloc.c
index ba346d954..e6b62eef5 100644
--- a/src/code/listalloc.c
+++ b/src/code/listalloc.c
@@ -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) {
diff --git a/src/code/padmgr.c b/src/code/padmgr.c
index 230102459..9faf232fc 100644
--- a/src/code/padmgr.c
+++ b/src/code/padmgr.c
@@ -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"
diff --git a/src/code/sched.c b/src/code/sched.c
index c7fb5a495..7b4a0b920 100644
--- a/src/code/sched.c
+++ b/src/code/sched.c
@@ -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);
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index 894127f2c..e82fb2975 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -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);
diff --git a/src/code/sys_cfb.c b/src/code/sys_cfb.c
index b559a44ee..71da5e73d 100644
--- a/src/code/sys_cfb.c
+++ b/src/code/sys_cfb.c
@@ -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) {
diff --git a/src/code/sys_cmpdma.c b/src/code/sys_cmpdma.c
index 9e1a66d2e..71d92c187 100644
--- a/src/code/sys_cmpdma.c
+++ b/src/code/sys_cmpdma.c
@@ -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);
}
diff --git a/src/code/sys_flashrom.c b/src/code/sys_flashrom.c
index 5ebc5dcba..7ba8f219c 100644
--- a/src/code/sys_flashrom.c
+++ b/src/code/sys_flashrom.c
@@ -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;
}
diff --git a/src/code/z_DLF.c b/src/code/z_DLF.c
index e71339bbb..1e03cead7 100644
--- a/src/code/z_DLF.c
+++ b/src/code/z_DLF.c
@@ -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;
}
}
diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c
index d16102567..931698482 100644
--- a/src/code/z_bgcheck.c
+++ b/src/code/z_bgcheck.c
@@ -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"
diff --git a/src/code/z_debug.c b/src/code/z_debug.c
index 058d896a4..b22709fa7 100644
--- a/src/code/z_debug.c
+++ b/src/code/z_debug.c
@@ -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;
diff --git a/src/code/z_fbdemo.c b/src/code/z_fbdemo.c
index 6ad5f7a6c..b0edfb0b7 100644
--- a/src/code/z_fbdemo.c
+++ b/src/code/z_fbdemo.c
@@ -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;
diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c
index 84acb9c64..894daa37f 100644
--- a/src/code/z_kankyo.c
+++ b/src/code/z_kankyo.c
@@ -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);
diff --git a/src/code/z_malloc.c b/src/code/z_malloc.c
index 80d7fc7af..f54d8f516 100644
--- a/src/code/z_malloc.c
+++ b/src/code/z_malloc.c
@@ -1,6 +1,6 @@
#include "z64malloc.h"
-#include "os_malloc.h"
+#include "libc64/os_malloc.h"
Arena sZeldaArena;
diff --git a/src/code/z_vismono.c b/src/code/z_vismono.c
index 86937c315..d4c462fc4 100644
--- a/src/code/z_vismono.c
+++ b/src/code/z_vismono.c
@@ -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);
}
}