summaryrefslogtreecommitdiff
path: root/src/tape.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-04-14 22:55:43 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-04-14 22:55:43 -0400
commitcb76bcf7d2358ad04281d123141acfa175e31841 (patch)
tree98d770bbc21b9767ae2b7b5186cfe9c445f40236 /src/tape.c
parentthing (diff)
downloadbrainfucked-cb76bcf7d2358ad04281d123141acfa175e31841.tar.gz
brainfucked-cb76bcf7d2358ad04281d123141acfa175e31841.tar.bz2
brainfucked-cb76bcf7d2358ad04281d123141acfa175e31841.zip
i made things faster
Diffstat (limited to '')
-rw-r--r--src/tape.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tape.c b/src/tape.c
new file mode 100644
index 0000000..8718cfd
--- /dev/null
+++ b/src/tape.c
@@ -0,0 +1,44 @@
+#include "types.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void tape_init(Tape* tape, uint8_t len) {
+ tape->index = 0;
+ tape->len = len;
+ tape->data = malloc(tape->len);
+ memset(tape->data, 0, len);
+}
+
+void tape_free(Tape* tape) {
+ free(tape->data);
+}
+
+void tape_left(Tape* tape) {
+ tape->index--;
+}
+
+void tape_right(Tape* tape) {
+ tape->index++;
+}
+
+void tape_increment(Tape* tape) {
+ tape->data[tape->index]++;
+}
+
+void tape_decrement(Tape* tape) {
+ tape->data[tape->index]--;
+}
+
+uint8_t tape_get(Tape* tape) {
+ return tape->data[tape->index];
+}
+
+void tape_set(Tape* tape, uint8_t value) {
+ tape->data[tape->index] = value;
+}
+
+void* tape_ptr(Tape* tape) {
+ return tape->data + tape->index;
+}