mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-06 16:04:35 +00:00
Move non-libultra libc functions to src/libc/ (#2055)
* Move non-libultra libc functions to src/libc/ * Add explicit nops in delay slots * Don't rely on CPP expanding undefined macros to 0 * Delete old Makefile rules * Fix type of memset()
This commit is contained in:
parent
aba1bb88a3
commit
ec70295357
19 changed files with 65 additions and 93 deletions
|
@ -25,15 +25,15 @@
|
|||
|
||||
#define FILL_ALLOC_BLOCK(arena, alloc, size) \
|
||||
if ((arena)->flag & FILL_ALLOC_BLOCK_FLAG) \
|
||||
__osMemset(alloc, BLOCK_ALLOC_MAGIC, size)
|
||||
memset(alloc, BLOCK_ALLOC_MAGIC, size)
|
||||
|
||||
#define FILL_FREE_BLOCK_HEADER(arena, node) \
|
||||
if ((arena)->flag & FILL_FREE_BLOCK_FLAG) \
|
||||
__osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode))
|
||||
memset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode))
|
||||
|
||||
#define FILL_FREE_BLOCK_CONTENTS(arena, node) \
|
||||
if ((arena)->flag & FILL_FREE_BLOCK_FLAG) \
|
||||
__osMemset((void*)((u32)(node) + sizeof(ArenaNode)), BLOCK_FREE_MAGIC, (node)->size)
|
||||
memset((void*)((u32)(node) + sizeof(ArenaNode)), BLOCK_FREE_MAGIC, (node)->size)
|
||||
|
||||
#define CHECK_FREE_BLOCK(arena, node) \
|
||||
if ((arena)->flag & CHECK_FREE_BLOCK_FLAG) \
|
||||
|
@ -179,7 +179,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) {
|
|||
|
||||
if (size2 > (s32)sizeof(ArenaNode)) {
|
||||
#if OOT_DEBUG
|
||||
__osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2);
|
||||
memset(firstNode, BLOCK_UNINIT_MAGIC, size2);
|
||||
#endif
|
||||
firstNode->next = NULL;
|
||||
firstNode->prev = NULL;
|
||||
|
@ -210,7 +210,7 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) {
|
|||
iter = arena->head;
|
||||
while (iter != NULL) {
|
||||
next = NODE_GET_NEXT(iter);
|
||||
__osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
|
||||
memset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
|
||||
iter = next;
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
|
|||
}
|
||||
node->next = newNext;
|
||||
node->size = newSize;
|
||||
__osMemmove(node->next, next, sizeof(ArenaNode));
|
||||
memmove(node->next, next, sizeof(ArenaNode));
|
||||
} else {
|
||||
// "Allocate a new memory block and move the contents"
|
||||
osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n");
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
/**
|
||||
* memmove: copies `len` bytes from memory starting at `src` to memory starting at `dest`.
|
||||
*
|
||||
* Unlike memcpy(), the regions of memory may overlap.
|
||||
*
|
||||
* @param dest address of start of buffer to write to
|
||||
* @param src address of start of buffer to read from
|
||||
* @param len number of bytes to copy.
|
||||
*
|
||||
* @return dest
|
||||
*/
|
||||
void* __osMemmove(void* dest, const void* src, size_t len) {
|
||||
u8* d = dest;
|
||||
const u8* s = src;
|
||||
|
||||
if (d == s) {
|
||||
return dest;
|
||||
}
|
||||
if (d < s) {
|
||||
while (len--) {
|
||||
*d++ = *s++;
|
||||
}
|
||||
} else {
|
||||
d += len - 1;
|
||||
s += len - 1;
|
||||
while (len--) {
|
||||
*d-- = *s--;
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
/**
|
||||
* memset: sets `len` bytes to `val` starting at address `dest`.
|
||||
*
|
||||
* @see There are two other memsets in this codebase, Lib_MemSet(), MemSet()
|
||||
*
|
||||
* @param dest address to start at
|
||||
* @param val value to write (s32, but interpreted as u8)
|
||||
* @param len number of bytes to write
|
||||
*
|
||||
* @return dest
|
||||
*/
|
||||
void* __osMemset(void* dest, s32 val, size_t len) {
|
||||
u8* ptr = dest;
|
||||
|
||||
while (len--) {
|
||||
*ptr++ = val;
|
||||
}
|
||||
return dest;
|
||||
}
|
|
@ -27,7 +27,7 @@ void* MemCpy(void* dest, const void* src, s32 len) {
|
|||
/**
|
||||
* memset: sets `len` bytes to `val` starting at address `dest`.
|
||||
*
|
||||
* @see There are two other memsets in this codebase, Lib_MemSet(), __osMemset().
|
||||
* @see There are two other memsets in this codebase, Lib_MemSet(), memset().
|
||||
* This one is unused.
|
||||
*
|
||||
* @param dest address to start at
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
#include "ultra64.h"
|
||||
|
||||
/**
|
||||
* Computes one `x` modulo `y` for floats.
|
||||
*
|
||||
* Acts like the standard C fmodf except does not handle Infinity. See https://en.cppreference.com/w/c/numeric/math/fmod
|
||||
* for the details. It summarizes this function as follows:
|
||||
* "The floating-point remainder of the division operation x/y calculated by this function is exactly the value x - n*y,
|
||||
* where n is x/y with its fractional part truncated.
|
||||
*
|
||||
* The returned value has the same sign as x and is less or equal to y in magnitude."
|
||||
*
|
||||
* @param x dividend
|
||||
* @param y modulus
|
||||
*
|
||||
* @return f32 0.0f if y is 0.0f, or x modulo y otherwise
|
||||
*/
|
||||
f32 fmodf(f32 x, f32 y) {
|
||||
s32 n;
|
||||
|
||||
if (y == 0.0f) {
|
||||
return 0.0f;
|
||||
}
|
||||
n = x / y;
|
||||
|
||||
return x - (n * y);
|
||||
}
|
|
@ -7449,7 +7449,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, PlayState
|
|||
s16 curUID;
|
||||
s16 j;
|
||||
|
||||
__osMemset(camera, 0, sizeof(Camera));
|
||||
memset(camera, 0, sizeof(Camera));
|
||||
if (sInitRegs) {
|
||||
s32 i;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* - the arguments are in a different order,
|
||||
* - `val` is a `u8` instead of the standard `s32`.
|
||||
*
|
||||
* @see There are two other memsets in this codebase, __osMemset(), MemSet()
|
||||
* @see There are two other memsets in this codebase, memset(), MemSet()
|
||||
*
|
||||
* @param dest address to start at
|
||||
* @param len number of bytes to write
|
||||
|
|
|
@ -170,7 +170,7 @@ QuakeRequest* Quake_RequestImpl(Camera* camera, u32 type) {
|
|||
s16 index = Quake_GetFreeIndex();
|
||||
QuakeRequest* req = &sQuakeRequests[index];
|
||||
|
||||
__osMemset(req, 0, sizeof(QuakeRequest));
|
||||
memset(req, 0, sizeof(QuakeRequest));
|
||||
|
||||
req->cam = camera;
|
||||
req->camId = camera->camId;
|
||||
|
|
|
@ -24,7 +24,7 @@ View* View_New(GraphicsContext* gfxCtx) {
|
|||
View* view = SYSTEM_ARENA_MALLOC(sizeof(View), "../z_view.c", 285);
|
||||
|
||||
if (view != NULL) {
|
||||
__osMemset(view, 0, sizeof(View));
|
||||
memset(view, 0, sizeof(View));
|
||||
View_Init(view, gfxCtx);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue