1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 04:24:43 +00:00
* Un-fake a couple of matches in memory manip functions

* Document fmodf

* Un-fake a couple of matches in memory manip functions

* Document fmodf

* Rename functions and files

* Document memmove, memsets, memcpys

* Format

* Sort out some missing sizeofs

* Name fmodf

* Rename local variables

* size_t

* Use COBRA_SHADOW_TEX_SIZE

* Review

* Tweak the Doxyfile to remove @brief requirement

* Roman's review

* Fix a bug comment

* Change fmodf
This commit is contained in:
EllipticEllipsis 2022-05-01 23:06:35 +01:00 committed by GitHub
parent 7334ffa373
commit e84f5ab387
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 282 additions and 208 deletions

View File

@ -187,7 +187,7 @@ SHORT_NAMES = NO
# description.)
# The default value is: NO.
JAVADOC_AUTOBRIEF = NO
JAVADOC_AUTOBRIEF = YES
# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
# line (until the first dot) of a Qt-style comment as the brief description. If

View File

@ -192,9 +192,9 @@ build/src/code/fault.o: OPTFLAGS := -O2 -g3
build/src/code/fault_drawer.o: CFLAGS += -trapuv
build/src/code/fault_drawer.o: OPTFLAGS := -O2 -g3
build/src/code/ucode_disas.o: OPTFLAGS := -O2 -g3
build/src/code/code_801068B0.o: OPTFLAGS := -g
build/src/code/code_80106860.o: OPTFLAGS := -g
build/src/code/fmodf.o: OPTFLAGS := -g
build/src/code/__osMemset.o: OPTFLAGS := -g
build/src/code/__osMemmove.o: OPTFLAGS := -g
build/src/libultra/libc/absf.o: OPTFLAGS := -O2 -g3
build/src/libultra/libc/sqrt.o: OPTFLAGS := -O2 -g3

View File

@ -114,7 +114,7 @@ void osUnmapTLBAll(void);
s32 osEPiStartDma(OSPiHandle* handle, OSIoMesg* mb, s32 direction);
const char* strchr(const char* str, s32 ch);
u32 strlen(const char* str);
void* memcpy(void* dst, const void* src, u32 size);
void* memcpy(void* dst, const void* src, size_t size);
void osInvalICache(void* vaddr, s32 nbytes);
void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count);
void osInvalDCache(void* vaddr, s32 nbytes);
@ -828,7 +828,7 @@ void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx);
void Cutscene_HandleEntranceTriggers(GlobalContext* globalCtx);
void Cutscene_HandleConditionalTriggers(GlobalContext* globalCtx);
void Cutscene_SetSegment(GlobalContext* globalCtx, void* segment);
void* MemCopy(void* dest, void* src, s32 size);
void* MemCpy(void* dest, const void* src, s32 len);
void GetItem_Draw(GlobalContext* globalCtx, s16 drawId);
void SoundSource_InitAll(GlobalContext* globalCtx);
void SoundSource_UpdateAll(GlobalContext* globalCtx);
@ -907,7 +907,7 @@ s32 Environment_IsForcedSequenceDisabled(void);
void Environment_PlayStormNatureAmbience(GlobalContext* globalCtx);
void Environment_StopStormNatureAmbience(GlobalContext* globalCtx);
void Environment_WarpSongLeave(GlobalContext* globalCtx);
void Lib_MemSet(u8* dest, size_t size, u8 val);
void Lib_MemSet(u8* dest, size_t len, u8 val);
f32 Math_CosS(s16 angle);
f32 Math_SinS(s16 angle);
s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step);
@ -2278,8 +2278,8 @@ void guMtxF2L(MtxF* m1, Mtx* m2);
u32* osViGetCurrentFramebuffer(void);
s32 __osSpSetPc(void* pc);
f32 absf(f32);
void* func_80106860(void* ptr, s32 val, size_t size);
void* func_801068B0(void* dst, void* src, size_t size);
void* __osMemset(void* dest, s32 val, size_t len);
void* __osMemmove(void* dest, const void* src, size_t len);
void Message_UpdateOcarinaGame(GlobalContext* globalCtx);
u8 Message_ShouldAdvance(GlobalContext* globalCtx);
void Message_CloseTextbox(GlobalContext*);

4
spec
View File

@ -510,8 +510,8 @@ beginseg
include "build/src/libultra/libc/sqrt.o"
include "build/src/libultra/libc/absf.o"
include "build/src/code/fmodf.o"
include "build/src/code/code_80106860.o"
include "build/src/code/code_801068B0.o"
include "build/src/code/__osMemset.o"
include "build/src/code/__osMemmove.o"
include_data_with_rodata "build/src/code/z_message_PAL.o"
include "build/src/code/z_game_over.o"
include "build/src/code/z_construct.o"

View File

@ -122,7 +122,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) {
size2 = (size - diff) & ~0xF;
if (size2 > (s32)sizeof(ArenaNode)) {
func_80106860(firstNode, BLOCK_UNINIT_MAGIC, size2); // memset
__osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2);
firstNode->next = NULL;
firstNode->prev = NULL;
firstNode->size = size2 - sizeof(ArenaNode);
@ -151,7 +151,7 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) {
iter = arena->head;
while (iter != NULL) {
next = ArenaImpl_GetNextBlock(iter);
func_80106860(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode)); // memset
__osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode));
iter = next;
}
@ -228,7 +228,7 @@ void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line)
ArenaImpl_SetDebugInfo(iter, file, line, arena);
alloc = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
func_80106860(alloc, BLOCK_ALLOC_MAGIC, size);
__osMemset(alloc, BLOCK_ALLOC_MAGIC, size);
}
break;
@ -288,7 +288,7 @@ void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) {
ArenaImpl_SetDebugInfo(iter, file, line, arena);
allocR = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
func_80106860(allocR, BLOCK_ALLOC_MAGIC, size);
__osMemset(allocR, BLOCK_ALLOC_MAGIC, size);
}
break;
@ -339,7 +339,7 @@ void* __osMalloc_NoLock(Arena* arena, u32 size) {
ArenaImpl_SetDebugInfo(iter, NULL, 0, arena);
alloc = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
func_80106860(alloc, BLOCK_ALLOC_MAGIC, size);
__osMemset(alloc, BLOCK_ALLOC_MAGIC, size);
}
break;
}
@ -398,7 +398,7 @@ void* __osMallocR(Arena* arena, u32 size) {
ArenaImpl_SetDebugInfo(iter, NULL, 0, arena);
alloc = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
func_80106860(alloc, BLOCK_ALLOC_MAGIC, size);
__osMemset(alloc, BLOCK_ALLOC_MAGIC, size);
}
break;
}
@ -442,7 +442,7 @@ void __osFree_NoLock(Arena* arena, void* ptr) {
ArenaImpl_SetDebugInfo(node, NULL, 0, arena);
if (arena->flag & FILL_FREEBLOCK) {
func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
__osMemset((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
}
newNext = next;
@ -454,7 +454,7 @@ void __osFree_NoLock(Arena* arena, void* ptr) {
node->size += next->size + sizeof(ArenaNode);
if (arena->flag & FILL_FREEBLOCK) {
func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
__osMemset(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
node->next = newNext;
next = newNext;
@ -467,7 +467,7 @@ void __osFree_NoLock(Arena* arena, void* ptr) {
prev->next = next;
prev->size += node->size + sizeof(ArenaNode);
if (arena->flag & FILL_FREEBLOCK) {
func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
__osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
}
}
@ -512,7 +512,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) {
ArenaImpl_SetDebugInfo(node, file, line, arena);
if (arena->flag & FILL_FREEBLOCK) {
func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
__osMemset((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
}
newNext = node->next;
@ -524,7 +524,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) {
node->size += next->size + sizeof(ArenaNode);
if (arena->flag & FILL_FREEBLOCK) {
func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
__osMemset(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
node->next = newNext;
next = newNext;
@ -537,7 +537,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) {
prev->next = next;
prev->size += node->size + sizeof(ArenaNode);
if (arena->flag & FILL_FREEBLOCK) {
func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
__osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
}
}
@ -590,7 +590,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
}
node->next = newNext;
node->size = newSize;
func_801068B0(newNext, next, sizeof(ArenaNode)); // memcpy
__osMemmove(newNext, next, sizeof(ArenaNode));
} else {
// "Allocate a new memory block and move the contents"
osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n");

33
src/code/__osMemmove.c Normal file
View File

@ -0,0 +1,33 @@
#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;
}

21
src/code/__osMemset.c Normal file
View File

@ -0,0 +1,21 @@
#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;
}

View File

@ -1021,7 +1021,7 @@ void* AudioHeap_AllocPermanent(s32 tableType, s32 id, u32 size) {
gAudioContext.permanentCache[index].size = size;
//! @bug UB: missing return. "ret" is in v0 at this point, but doing an
// explicit return uses an additional register.
//! explicit return uses an additional register.
#ifdef AVOID_UB
return ret;
#endif

View File

@ -1,23 +1,47 @@
#include "global.h"
void* MemCopy(void* dest, void* src, s32 size) {
u8* destu = (u8*)dest;
u8* srcu = (u8*)src;
/**
* memcpy: copies `len` bytes from memory starting at `src` to memory starting at `dest`. Expects the memory
* specified by `src` and `dest` to not overlap.
*
* @see libultra also has a memcpy().
*
* @param dest address of start of buffer writing to
* @param src address of start of buffer to read from
* @param len number of bytes to copy. (`s32` rather than the standard `size_t`)
*
* @return dest
*/
void* MemCpy(void* dest, const void* src, s32 len) {
u8* d = dest;
const u8* s = src;
while (size > 0) {
*destu++ = *srcu++;
size--;
while (len > 0) {
*d++ = *s++;
len--;
}
return dest;
}
void* MemSet(void* dest, s32 val, s32 size) {
u8* destu = (u8*)dest;
s32 s = size;
/**
* memset: sets `len` bytes to `val` starting at address `dest`.
*
* @see There are two other memsets in this codebase, Lib_MemSet(), __osMemset().
* This one is unused.
*
* @param dest address to start at
* @param val value to write (`s32`, but interpreted as `u8`)
* @param len number of bytes to write. (`s32` rather than the standard `size_t`)
*
* @return dest
*/
void* MemSet(void* dest, s32 val, s32 len) {
u8* d = dest;
s32 s = len;
while (s > 0) {
*destu++ = val;
*d++ = val;
s--;
}

View File

@ -1,12 +0,0 @@
#include "global.h"
// memset used in __osMalloc, z_quake, z_view, and z_camera
void* func_80106860(void* ptr, s32 val, size_t size) {
u8* sp4 = ptr;
register s32 a3;
for (a3 = size--; a3 != 0; a3 = size--) {
*sp4++ = val;
}
return ptr;
}

View File

@ -1,24 +0,0 @@
#include "global.h"
// memmove used in __osMalloc.c
void* func_801068B0(void* dst, void* src, size_t size) {
u8* spC = dst;
u8* sp8 = src;
register s32 a3;
if (spC == sp8) {
return dst;
}
if (spC < sp8) {
for (a3 = size--; a3 != 0; a3 = size--) {
*spC++ = *sp8++;
}
} else {
spC += size - 1;
sp8 += size - 1;
for (a3 = size--; a3 != 0; a3 = size--) {
*spC-- = *sp8--;
}
}
return dst;
}

View File

@ -1,12 +1,27 @@
#include "global.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 quot;
s32 n;
if (y == 0.0f) {
return 0.0f;
}
quot = x / y;
n = x / y;
return x - (quot * y);
return x - (n * y);
}

View File

@ -6793,7 +6793,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, GlobalCon
s16 curUID;
s16 j;
func_80106860(camera, 0, sizeof(*camera));
__osMemset(camera, 0, sizeof(Camera));
if (sInitRegs) {
for (i = 0; i < sOREGInitCnt; i++) {
OREG(i) = sOREGInit[i];

View File

@ -1571,9 +1571,9 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
s32 cutsceneEndFrame;
s16 j;
MemCopy(&totalEntries, cutscenePtr, 4);
MemCpy(&totalEntries, cutscenePtr, 4);
cutscenePtr += 4;
MemCopy(&cutsceneEndFrame, cutscenePtr, 4);
MemCpy(&cutsceneEndFrame, cutscenePtr, 4);
cutscenePtr += 4;
if ((cutsceneEndFrame < csCtx->frames) && (csCtx->state != CS_STATE_UNSKIPPABLE_EXEC)) {
@ -1587,7 +1587,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
for (i = 0; i < totalEntries; i++) {
MemCopy(&cmdType, cutscenePtr, 4);
MemCpy(&cmdType, cutscenePtr, 4);
cutscenePtr += 4;
if (cmdType == -1) {
@ -1596,7 +1596,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
switch (cmdType) {
case CS_CMD_MISC:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
func_80064824(globalCtx, csCtx, (void*)cutscenePtr);
@ -1604,7 +1604,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_SET_LIGHTING:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
Cutscene_Command_SetLighting(globalCtx, csCtx, (void*)cutscenePtr);
@ -1612,7 +1612,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_PLAYBGM:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
Cutscene_Command_PlayBGM(globalCtx, csCtx, (void*)cutscenePtr);
@ -1620,7 +1620,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_STOPBGM:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
Cutscene_Command_StopBGM(globalCtx, csCtx, (void*)cutscenePtr);
@ -1628,7 +1628,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_FADEBGM:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
Cutscene_Command_FadeBGM(globalCtx, csCtx, (void*)cutscenePtr);
@ -1636,7 +1636,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_09:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
Cutscene_Command_09(globalCtx, csCtx, (void*)cutscenePtr);
@ -1644,7 +1644,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_SETTIME:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
func_80065134(globalCtx, csCtx, (void*)cutscenePtr);
@ -1652,7 +1652,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_SET_PLAYER_ACTION:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1680,7 +1680,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 138:
case 139:
case 144:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1708,7 +1708,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 125:
case 131:
case 141:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1732,7 +1732,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 121:
case 126:
case 132:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1755,7 +1755,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 108:
case 127:
case 133:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1774,7 +1774,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 83:
case 128:
case 135:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1791,7 +1791,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 90:
case 129:
case 136:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1809,7 +1809,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 115:
case 130:
case 137:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1826,7 +1826,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
case 114:
case 134:
case 142:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1837,7 +1837,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_SET_ACTOR_ACTION_9:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1848,7 +1848,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
}
break;
case CS_CMD_SET_ACTOR_ACTION_10:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1882,7 +1882,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
cutscenePtr += 8;
break;
case CS_CMD_TEXTBOX:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cmd = (CsCmdBase*)cutscenePtr;
@ -1898,7 +1898,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
cutscenePtr += 8;
break;
default:
MemCopy(&cmdEntries, cutscenePtr, 4);
MemCpy(&cmdEntries, cutscenePtr, 4);
cutscenePtr += 4;
for (j = 0; j < cmdEntries; j++) {
cutscenePtr += 0x30;

View File

@ -1,10 +1,25 @@
#include "global.h"
void Lib_MemSet(u8* dest, size_t size, u8 val) {
u32 i;
/**
* memset: sets `len` bytes to `val` starting at address `dest`.
*
* Unlike normal memset,
* - `dest` is a `u8*` already,
* - does not return `dest`,
* - 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()
*
* @param dest address to start at
* @param len number of bytes to write
* @param val value to write
*/
void Lib_MemSet(u8* dest, size_t len, u8 val) {
size_t i;
// clang-format off
for (i = 0; i < size; i++) { *dest++ = val; }
for (i = 0; i < len; i++) { *dest++ = val; }
// clang-format on
}

View File

@ -2619,7 +2619,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) {
osSyncPrintf("録音終了!!!!!!!!!録音終了\n");
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("\n====================================================================\n");
MemCopy(gSaveContext.scarecrowCustomSong, gScarecrowCustomSongPtr,
MemCpy(gSaveContext.scarecrowCustomSong, gScarecrowCustomSongPtr,
sizeof(gSaveContext.scarecrowCustomSong));
for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++) {
osSyncPrintf("%d, ", gSaveContext.scarecrowCustomSong[i]);
@ -2682,7 +2682,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) {
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("\n====================================================================\n");
MemCopy(gSaveContext.scarecrowSpawnSong, gScarecrowSpawnSongPtr,
MemCpy(gSaveContext.scarecrowSpawnSong, gScarecrowSpawnSongPtr,
sizeof(gSaveContext.scarecrowSpawnSong));
for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++) {
osSyncPrintf("%d, ", gSaveContext.scarecrowSpawnSong[i]);

View File

@ -152,7 +152,7 @@ QuakeRequest* Quake_AddImpl(Camera* cam, u32 callbackIdx) {
s16 idx = Quake_GetFreeIndex();
QuakeRequest* req = &sQuakeRequest[idx];
func_80106860(req, 0, sizeof(QuakeRequest)); // memset
__osMemset(req, 0, sizeof(QuakeRequest));
req->cam = cam;
req->camPtrIdx = cam->thisIdx;
req->callbackIdx = callbackIdx;

View File

@ -322,7 +322,7 @@ void Sram_OpenSave(SramContext* sramCtx) {
i = gSramSlotOffsets[gSaveContext.fileNum];
osSyncPrintf("ぽいんと=%x(%d)\n", i, gSaveContext.fileNum); // "Point="
MemCopy(&gSaveContext, sramCtx->readBuff + i, sizeof(Save));
MemCpy(&gSaveContext, sramCtx->readBuff + i, sizeof(Save));
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("SCENE_DATA_ID = %d SceneNo = %d\n", gSaveContext.savedSceneNum,
@ -397,7 +397,7 @@ void Sram_OpenSave(SramContext* sramCtx) {
osSyncPrintf(VT_FGCOL(BLUE));
osSyncPrintf("\n====================================================================\n");
MemCopy(gScarecrowCustomSongPtr, gSaveContext.scarecrowCustomSong, sizeof(gSaveContext.scarecrowCustomSong));
MemCpy(gScarecrowCustomSongPtr, gSaveContext.scarecrowCustomSong, sizeof(gSaveContext.scarecrowCustomSong));
ptr = (u8*)gScarecrowCustomSongPtr;
for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++, ptr++) {
@ -412,7 +412,7 @@ void Sram_OpenSave(SramContext* sramCtx) {
osSyncPrintf(VT_FGCOL(GREEN));
osSyncPrintf("\n====================================================================\n");
MemCopy(gScarecrowSpawnSongPtr, gSaveContext.scarecrowSpawnSong, sizeof(gSaveContext.scarecrowSpawnSong));
MemCpy(gScarecrowSpawnSongPtr, gSaveContext.scarecrowSpawnSong, sizeof(gSaveContext.scarecrowSpawnSong));
ptr = gScarecrowSpawnSongPtr;
for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++, ptr++) {
@ -537,7 +537,7 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s
for (slotNum = 0; slotNum < 3; slotNum++) {
offset = gSramSlotOffsets[slotNum];
osSyncPrintf("ぽいんと=%x(%d) SAVE_MAX=%d\n", offset, gSaveContext.fileNum, sizeof(Save));
MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save));
MemCpy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save));
oldChecksum = gSaveContext.checksum;
gSaveContext.checksum = 0;
@ -555,7 +555,7 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s
// checksum didnt match, try backup save
osSyncPrintf(" %x(%d)\n", gSramSlotOffsets[slotNum], slotNum);
offset = gSramSlotOffsets[slotNum + 3];
MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save));
MemCpy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save));
oldChecksum = gSaveContext.checksum;
gSaveContext.checksum = 0;
@ -635,48 +635,45 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s
osSyncPrintf("SAVECT=%x, NAME=%x, LIFE=%x, ITEM=%x, 64DD=%x, HEART=%x\n", DEATHS, NAME, HEALTH_CAP, QUEST, N64DD,
DEFENSE);
MemCopy(&fileChooseCtx->deaths[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEATHS, sizeof(fileChooseCtx->deaths[0]));
MemCopy(&fileChooseCtx->deaths[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEATHS, sizeof(fileChooseCtx->deaths[0]));
MemCopy(&fileChooseCtx->deaths[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEATHS, sizeof(fileChooseCtx->deaths[0]));
MemCpy(&fileChooseCtx->deaths[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEATHS, sizeof(fileChooseCtx->deaths[0]));
MemCpy(&fileChooseCtx->deaths[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEATHS, sizeof(fileChooseCtx->deaths[0]));
MemCpy(&fileChooseCtx->deaths[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEATHS, sizeof(fileChooseCtx->deaths[0]));
MemCopy(&fileChooseCtx->fileNames[0], sramCtx->readBuff + SLOT_OFFSET(0) + NAME,
MemCpy(&fileChooseCtx->fileNames[0], sramCtx->readBuff + SLOT_OFFSET(0) + NAME,
sizeof(fileChooseCtx->fileNames[0]));
MemCopy(&fileChooseCtx->fileNames[1], sramCtx->readBuff + SLOT_OFFSET(1) + NAME,
MemCpy(&fileChooseCtx->fileNames[1], sramCtx->readBuff + SLOT_OFFSET(1) + NAME,
sizeof(fileChooseCtx->fileNames[0]));
MemCopy(&fileChooseCtx->fileNames[2], sramCtx->readBuff + SLOT_OFFSET(2) + NAME,
MemCpy(&fileChooseCtx->fileNames[2], sramCtx->readBuff + SLOT_OFFSET(2) + NAME,
sizeof(fileChooseCtx->fileNames[0]));
MemCopy(&fileChooseCtx->healthCapacities[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH_CAP,
MemCpy(&fileChooseCtx->healthCapacities[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH_CAP,
sizeof(fileChooseCtx->healthCapacities[0]));
MemCopy(&fileChooseCtx->healthCapacities[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH_CAP,
MemCpy(&fileChooseCtx->healthCapacities[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH_CAP,
sizeof(fileChooseCtx->healthCapacities[0]));
MemCopy(&fileChooseCtx->healthCapacities[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH_CAP,
MemCpy(&fileChooseCtx->healthCapacities[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH_CAP,
sizeof(fileChooseCtx->healthCapacities[0]));
MemCopy(&fileChooseCtx->questItems[0], sramCtx->readBuff + SLOT_OFFSET(0) + QUEST,
MemCpy(&fileChooseCtx->questItems[0], sramCtx->readBuff + SLOT_OFFSET(0) + QUEST,
sizeof(fileChooseCtx->questItems[0]));
MemCopy(&fileChooseCtx->questItems[1], sramCtx->readBuff + SLOT_OFFSET(1) + QUEST,
MemCpy(&fileChooseCtx->questItems[1], sramCtx->readBuff + SLOT_OFFSET(1) + QUEST,
sizeof(fileChooseCtx->questItems[0]));
MemCopy(&fileChooseCtx->questItems[2], sramCtx->readBuff + SLOT_OFFSET(2) + QUEST,
MemCpy(&fileChooseCtx->questItems[2], sramCtx->readBuff + SLOT_OFFSET(2) + QUEST,
sizeof(fileChooseCtx->questItems[0]));
MemCopy(&fileChooseCtx->n64ddFlags[0], sramCtx->readBuff + SLOT_OFFSET(0) + N64DD,
MemCpy(&fileChooseCtx->n64ddFlags[0], sramCtx->readBuff + SLOT_OFFSET(0) + N64DD,
sizeof(fileChooseCtx->n64ddFlags[0]));
MemCopy(&fileChooseCtx->n64ddFlags[1], sramCtx->readBuff + SLOT_OFFSET(1) + N64DD,
MemCpy(&fileChooseCtx->n64ddFlags[1], sramCtx->readBuff + SLOT_OFFSET(1) + N64DD,
sizeof(fileChooseCtx->n64ddFlags[0]));
MemCopy(&fileChooseCtx->n64ddFlags[2], sramCtx->readBuff + SLOT_OFFSET(2) + N64DD,
MemCpy(&fileChooseCtx->n64ddFlags[2], sramCtx->readBuff + SLOT_OFFSET(2) + N64DD,
sizeof(fileChooseCtx->n64ddFlags[0]));
MemCopy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE,
sizeof(fileChooseCtx->defense[0]));
MemCopy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE,
sizeof(fileChooseCtx->defense[0]));
MemCopy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE,
sizeof(fileChooseCtx->defense[0]));
MemCpy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, sizeof(fileChooseCtx->defense[0]));
MemCpy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, sizeof(fileChooseCtx->defense[0]));
MemCpy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, sizeof(fileChooseCtx->defense[0]));
MemCopy(&fileChooseCtx->health[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->health[0]));
MemCopy(&fileChooseCtx->health[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->health[0]));
MemCopy(&fileChooseCtx->health[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH, sizeof(fileChooseCtx->health[0]));
MemCpy(&fileChooseCtx->health[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->health[0]));
MemCpy(&fileChooseCtx->health[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->health[0]));
MemCpy(&fileChooseCtx->health[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH, sizeof(fileChooseCtx->health[0]));
osSyncPrintf("f_64dd=%d, %d, %d\n", fileChooseCtx->n64ddFlags[0], fileChooseCtx->n64ddFlags[1],
fileChooseCtx->n64ddFlags[2]);
@ -741,11 +738,11 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) {
offset = gSramSlotOffsets[gSaveContext.fileNum];
osSyncPrintf("I=%x no=%d\n", offset, gSaveContext.fileNum);
MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
offset = gSramSlotOffsets[gSaveContext.fileNum + 3];
osSyncPrintf("I=%x no=%d\n", offset, gSaveContext.fileNum + 3);
MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE);
@ -755,19 +752,19 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) {
j = gSramSlotOffsets[gSaveContext.fileNum];
MemCopy(&fileChooseCtx->deaths[gSaveContext.fileNum], sramCtx->readBuff + j + DEATHS,
MemCpy(&fileChooseCtx->deaths[gSaveContext.fileNum], sramCtx->readBuff + j + DEATHS,
sizeof(fileChooseCtx->deaths[0]));
MemCopy(&fileChooseCtx->fileNames[gSaveContext.fileNum], sramCtx->readBuff + j + NAME,
MemCpy(&fileChooseCtx->fileNames[gSaveContext.fileNum], sramCtx->readBuff + j + NAME,
sizeof(fileChooseCtx->fileNames[0]));
MemCopy(&fileChooseCtx->healthCapacities[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH_CAP,
MemCpy(&fileChooseCtx->healthCapacities[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH_CAP,
sizeof(fileChooseCtx->healthCapacities[0]));
MemCopy(&fileChooseCtx->questItems[gSaveContext.fileNum], sramCtx->readBuff + j + QUEST,
MemCpy(&fileChooseCtx->questItems[gSaveContext.fileNum], sramCtx->readBuff + j + QUEST,
sizeof(fileChooseCtx->questItems[0]));
MemCopy(&fileChooseCtx->n64ddFlags[gSaveContext.fileNum], sramCtx->readBuff + j + N64DD,
MemCpy(&fileChooseCtx->n64ddFlags[gSaveContext.fileNum], sramCtx->readBuff + j + N64DD,
sizeof(fileChooseCtx->n64ddFlags[0]));
MemCopy(&fileChooseCtx->defense[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE,
MemCpy(&fileChooseCtx->defense[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE,
sizeof(fileChooseCtx->defense[0]));
MemCopy(&fileChooseCtx->health[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH,
MemCpy(&fileChooseCtx->health[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH,
sizeof(fileChooseCtx->health[0]));
osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]);
@ -781,14 +778,14 @@ void Sram_EraseSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) {
Sram_InitNewSave();
offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex];
MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE);
MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIndex], sramCtx->readBuff + offset + N64DD,
MemCpy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIndex], sramCtx->readBuff + offset + N64DD,
sizeof(fileChooseCtx->n64ddFlags[0]));
offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex + 3];
MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE);
osSyncPrintf("CLEAR終了\n");
@ -802,31 +799,31 @@ void Sram_CopySave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) {
gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]);
offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex];
MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save));
MemCpy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save));
offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex];
MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex + 3];
MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save));
SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE);
offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex];
MemCopy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEATHS,
MemCpy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEATHS,
sizeof(fileChooseCtx->deaths[0]));
MemCopy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + NAME,
MemCpy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + NAME,
sizeof(fileChooseCtx->fileNames[0]));
MemCopy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + HEALTH_CAP,
MemCpy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + HEALTH_CAP,
sizeof(fileChooseCtx->healthCapacities[0]));
MemCopy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + QUEST,
MemCpy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + QUEST,
sizeof(fileChooseCtx->questItems[0]));
MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + N64DD,
MemCpy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + N64DD,
sizeof(fileChooseCtx->n64ddFlags[0]));
MemCopy(&fileChooseCtx->defense[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEFENSE,
MemCpy(&fileChooseCtx->defense[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEFENSE,
sizeof(fileChooseCtx->defense[0]));
MemCopy(&fileChooseCtx->health[fileChooseCtx->copyDestFileIndex], (sramCtx->readBuff + offset) + HEALTH,
MemCpy(&fileChooseCtx->health[fileChooseCtx->copyDestFileIndex], (sramCtx->readBuff + offset) + HEALTH,
sizeof(fileChooseCtx->health[0]));
osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]);
@ -851,7 +848,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) {
if (sZeldaMagic[i + SRAM_HEADER_MAGIC] != sramCtx->readBuff[i + SRAM_HEADER_MAGIC]) {
osSyncPrintf("SRAM破壊!!!!!!\n"); // "SRAM destruction! ! ! ! ! !"
gSaveContext.language = sramCtx->readBuff[SRAM_HEADER_LANGUAGE];
MemCopy(sramCtx->readBuff, sZeldaMagic, sizeof(sZeldaMagic));
MemCpy(sramCtx->readBuff, sZeldaMagic, sizeof(sZeldaMagic));
sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language;
Sram_WriteSramHeader(sramCtx);
}

View File

@ -24,7 +24,7 @@ View* View_New(GraphicsContext* gfxCtx) {
View* view = SystemArena_MallocDebug(sizeof(View), "../z_view.c", 285);
if (view != NULL) {
func_80106860(view, 0, sizeof(View)); // memset
__osMemset(view, 0, sizeof(View));
View_Init(view, gfxCtx);
}

View File

@ -21,7 +21,7 @@ u32 strlen(const char* str) {
return ptr - str;
}
void* memcpy(void* dst, const void* src, u32 size) {
void* memcpy(void* dst, const void* src, size_t size) {
u8* _dst = dst;
const u8* _src = src;

View File

@ -264,7 +264,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) {
Vec3f spD4;
Vec3f spC8;
Vec3f spBC;
u8* temp_s2;
u8* shadowTex;
s32 temp_x;
s32 temp_z;
s32 x;
@ -275,8 +275,8 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) {
s32 l;
s16 rotY;
temp_s2 = ALIGN16((s32)(&this->shadowTexture));
Lib_MemSet(temp_s2, 0x1000, 0);
shadowTex = COBRA_SHADOW_TEX_PTR(this);
Lib_MemSet(shadowTex, COBRA_SHADOW_TEX_SIZE, 0);
Matrix_RotateX((M_PI / 4), MTXMODE_NEW);
rotY = !(this->dyna.actor.params & 3) ? (this->dyna.actor.shape.rot.y + 0x4000)
@ -303,7 +303,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) {
for (l = 0; l < 11; l++) {
temp_x = x - 5 + l;
if (!(temp_x & ~0x3F)) {
temp_s2[temp_z + temp_x] |= D_8089731C[k][l];
shadowTex[temp_z + temp_x] |= D_8089731C[k][l];
}
if (1) {}
}
@ -331,7 +331,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) {
for (l = 0; l < 3; l++) {
temp_x = x - 1 + l;
if (!(temp_x & ~0x3F)) {
temp_s2[temp_z + temp_x] |= D_80897398[k][l];
shadowTex[temp_z + temp_x] |= D_80897398[k][l];
}
}
}
@ -340,13 +340,13 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) {
}
for (i = 0; i < 0x40; i++) {
temp_s2[0 * 0x40 + i] = 0;
temp_s2[0x3F * 0x40 + i] = 0;
shadowTex[0 * 0x40 + i] = 0;
shadowTex[0x3F * 0x40 + i] = 0;
}
for (j = 1; j < 0x3F; j++) {
temp_s2[j * 0x40 + 0] = 0;
temp_s2[j * 0x40 + 0x3F] = 0;
shadowTex[j * 0x40 + 0] = 0;
shadowTex[j * 0x40 + 0x3F] = 0;
}
if (D_80897398[0][0]) {}
}
@ -360,15 +360,15 @@ void BgJyaCobra_UpdateShadowFromTop(BgJyaCobra* this) {
s32 j;
s32 i_copy;
s32 counter;
u8* temp_s0;
u8* shadowTex;
u8* sp40;
for (i = 0; i < 0x40; i++) {
sp58[i] = SQ(i - 31.5f);
}
sp40 = temp_s0 = (u8*)ALIGN16((u32)(&this->shadowTexture));
Lib_MemSet(temp_s0, 0x1000, 0);
sp40 = shadowTex = COBRA_SHADOW_TEX_PTR(this);
Lib_MemSet(shadowTex, COBRA_SHADOW_TEX_SIZE, 0);
for (i = 0; i != 0x40; i++) {
f32 temp_f12 = sp58[i];
@ -385,12 +385,12 @@ void BgJyaCobra_UpdateShadowFromTop(BgJyaCobra* this) {
for (i_copy = 0x780, counter = 0; counter < 4; counter++, i_copy += 0x40) {
i = i_copy;
for (j = 4; j < 0x3C; j++) {
if (temp_s0[i_copy + j] < D_80897518[counter]) {
temp_s0[i_copy + j] = D_80897518[counter];
if (shadowTex[i_copy + j] < D_80897518[counter]) {
shadowTex[i_copy + j] = D_80897518[counter];
}
}
temp_s0[i + 0x3C] = 0x20;
temp_s0[i + 0x3] = 0x20;
shadowTex[i + 0x3C] = 0x20;
shadowTex[i + 0x3] = 0x20;
}
}
@ -419,7 +419,7 @@ void BgJyaCobra_Init(Actor* thisx, GlobalContext* globalCtx) {
// "(jya cobra)"
osSyncPrintf("(jya コブラ)(arg_data 0x%04x)(act %x)(txt %x)(txt16 %x)\n", this->dyna.actor.params, this,
&this->shadowTexture, ALIGN16((s32)(&this->shadowTexture)));
&this->shadowTextureBuffer, COBRA_SHADOW_TEX_PTR(this));
}
void BgJyaCobra_Destroy(Actor* thisx, GlobalContext* globalCtx) {
@ -590,9 +590,9 @@ void BgJyaCobra_DrawShadow(BgJyaCobra* this, GlobalContext* globalCtx) {
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_bg_jya_cobra.c", 994),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gDPLoadTextureBlock(POLY_XLU_DISP++, ALIGN16((s32)(&this->shadowTexture)), G_IM_FMT_I, G_IM_SIZ_8b, 0x40, 0x40, 0,
G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD,
G_TX_NOLOD);
gDPLoadTextureBlock(POLY_XLU_DISP++, COBRA_SHADOW_TEX_PTR(this), G_IM_FMT_I, G_IM_SIZ_8b, COBRA_SHADOW_TEX_WIDTH,
COBRA_SHADOW_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK,
G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);
gSPDisplayList(POLY_XLU_DISP++, sShadowDL);

View File

@ -8,6 +8,11 @@ struct BgJyaCobra;
typedef void (*BgJyaCobraActionFunc)(struct BgJyaCobra*, GlobalContext*);
#define COBRA_SHADOW_TEX_WIDTH 64
#define COBRA_SHADOW_TEX_HEIGHT 64
#define COBRA_SHADOW_TEX_SIZE (COBRA_SHADOW_TEX_WIDTH * COBRA_SHADOW_TEX_HEIGHT * G_IM_SIZ_8b_BYTES)
#define COBRA_SHADOW_TEX_PTR(this) (u8*)ALIGN16((u32)(&this->shadowTextureBuffer))
typedef struct BgJyaCobra {
/* 0x0000 */ DynaPolyActor dyna;
/* 0x0164 */ BgJyaCobraActionFunc actionFunc;
@ -21,7 +26,7 @@ typedef struct BgJyaCobra {
/* 0x0180 */ Vec3f unk_180;
/* 0x018C */ f32 unk_18C;
/* 0x0190 */ f32 unk_190;
/* 0x0194 */ u8 shadowTexture[0x1010];
/* 0x0194 */ u8 shadowTextureBuffer[COBRA_SHADOW_TEX_SIZE / sizeof(u8) + 0xF]; // Extra space to allow aligning actual texture to 0x10
} BgJyaCobra; // size = 0x11A4
#endif

View File

@ -193,7 +193,7 @@ void FileChoose_UpdateMainMenu(GameState* thisx) {
this->newFileNameCharCount = 0;
this->nameEntryBoxPosX = 120;
this->nameEntryBoxAlpha = 0;
MemCopy(&this->fileNames[this->buttonIndex][0], &emptyName, 8);
MemCpy(&this->fileNames[this->buttonIndex][0], &emptyName, sizeof(emptyName));
} else if (this->n64ddFlags[this->buttonIndex] == this->n64ddFlag) {
Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &gSfxDefaultPos, 4, &gSfxDefaultFreqAndVolScale,
&gSfxDefaultFreqAndVolScale, &gSfxDefaultReverb);