Memory and string functions: memcpy, memmove, memset, strlen, strcmp, strcpy, strncpy. More...
#include <snes/types.h>Go to the source code of this file.
Functions | |
| void FAR * | memcpy (void FAR *dst, const void *src, unsigned int n) |
| Copy n bytes from src to dst. | |
| void FAR * | memmove (void FAR *dst, const void *src, unsigned int n) |
| Copy n bytes from src to dst, the areas may overlap. | |
| void FAR * | memset (void FAR *dst, int c, unsigned int n) |
| Fill n bytes with a value. | |
| int | strcmp (const char *a, const char *b) |
| Compare two strings. | |
| char FAR * | strcpy (char FAR *dst, const char *src) |
| Copy a string, terminator included. | |
| unsigned int | strlen (const char *s) |
| Length of a string. | |
| char FAR * | strncpy (char FAR *dst, const char *src, unsigned int n) |
| Copy at most n bytes of a string. | |
Memory and string functions: memcpy, memmove, memset, strlen, strcmp, strcpy, strncpy.
The seven functions of the C library a game uses most, written in assembly. Add string to LIB_MODULES; a ROM links only the functions it calls.
A C loop over a plain pointer reads and writes bank $00 (see KNOWN_LIMITATIONS.md): it cannot copy out of a const table in ROM into a FAR buffer. These functions follow the full 24-bit pointer on both sides, so every combination works — ROM, plain RAM, FAR RAM:
memcpy and memset move a word at a time: 23 CPU cycles a word in the copy loop, about 12 a byte.
A destination is a FAR pointer and a source a const one: the two types every pointer converts to without a cast (<snes/types.h>), so a plain buffer, a FAR buffer and a const table are all accepted as they are. The functions that return their destination return it as a FAR pointer for the same reason: it may be one. Storing that result in a plain pointer is a compile error, as for any FAR pointer.
Copy n bytes from src to dst.
| dst | Destination (RAM, plain or FAR) |
| src | Source (ROM or RAM) |
| n | Number of bytes |
The copy runs forward. If dst lies inside src..src+n the bytes not yet read are overwritten: use memmove() for overlapping areas.
Copy n bytes from src to dst, the areas may overlap.
| dst | Destination |
| src | Source |
| n | Number of bytes |
Copies backward when dst lies inside src..src+n, forward otherwise.
Fill n bytes with a value.
| dst | Destination |
| c | Byte value (the low 8 bits are used) |
| n | Number of bytes |
| int strcmp | ( | const char * | a, |
| const char * | b ) |
Copy a string, terminator included.
| dst | Destination, large enough for src and its terminator |
| src | Zero-terminated string |
| unsigned int strlen | ( | const char * | s | ) |
Length of a string.
| s | Zero-terminated string |
Copy at most n bytes of a string.
| dst | Destination, at least n bytes |
| src | Zero-terminated string |
| n | Number of bytes written to dst |
If src is shorter than n, the rest of the n bytes is filled with zeros.