summaryrefslogtreecommitdiff
path: root/src/code/z_memory_utils.c
blob: a08567dd6570828ff7a84f3970b4106e114e503e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ultra64.h"

/**
 * 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 (len > 0) {
        *d++ = *s++;
        len--;
    }

    return dest;
}

/**
 * memset: sets `len` bytes to `val` starting at address `dest`.
 *
 * @see There are two other memsets in this codebase, Lib_MemSet(), memset().
 * 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) {
        *d++ = val;
        s--;
    }

    return dest;
}