summaryrefslogtreecommitdiff
path: root/arm9/source/types/pathbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'arm9/source/types/pathbuf.c')
-rw-r--r--arm9/source/types/pathbuf.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/arm9/source/types/pathbuf.c b/arm9/source/types/pathbuf.c
new file mode 100644
index 0000000..1a610c8
--- /dev/null
+++ b/arm9/source/types/pathbuf.c
@@ -0,0 +1,52 @@
+#include <nds.h>
+#include "pathbuf.h"
+
+u8 pb_read(PathBuf *buf) {
+ u8 output = buf->mem[buf->p];
+ if (output) buf->p++;
+ return output;
+}
+
+void pb_clear(PathBuf *buf) {
+ memset(&buf->mem, 0, 256);
+}
+
+void pb_reset(PathBuf *buf, bool to_name) {
+ buf->p = 0;
+ if (to_name) for (int i=0; i<255; i++) {
+ if (buf->mem[i] == '/') {
+ buf->p = i+1;
+ } else if (buf->mem[i] == 0) {
+ break;
+ }
+ }
+}
+
+// Push a byte to a PathBuf, return true and reset the pointer if byte is null.
+bool pb_push_byte(PathBuf *buf, u8 byte) {
+ // Stop before overwriting the pointer.
+ if (buf->p != 0xff) {
+ buf->mem[buf->p++] = byte;
+ }
+ if (byte == 0) {
+ buf->p = 0;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool pb_is_terminated(PathBuf *buf) {
+ for (int i=0; i<255; i++) {
+ if (buf->mem[i] == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void pb_populate(PathBuf *buf, u8 *path) {
+ strncpy((char*) &buf->mem[0], (char*) path, 254);
+ buf->p = 0;
+}
+