blob: 8718cfdc3a0117d7b72a2e1f5720fd63fa640d5c (
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
|
#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;
}
|