summaryrefslogtreecommitdiff
path: root/src/mem.c
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-09-21 14:16:01 +0300
committerRasmus Luha <rasmus.luha@gmail.com>2022-09-21 14:16:01 +0300
commitc34cd59be89fb26e63fe959b98afabb4f24ba5bd (patch)
tree60531983cb0bfef27ab91cb3be41ebd40b324c9f /src/mem.c
init commit
Diffstat (limited to 'src/mem.c')
-rw-r--r--src/mem.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/mem.c b/src/mem.c
new file mode 100644
index 0000000..3c605a5
--- /dev/null
+++ b/src/mem.c
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include "mem.h"
+
+struct mem_st mem = { .pos = 0};
+
+int mem_inc(){
+ mem.arr[mem.pos]++;
+ return mem.arr[mem.pos];
+}
+
+int mem_dec(){
+ mem.arr[mem.pos]--;
+ return mem.arr[mem.pos];
+}
+
+int mem_left(){
+ if (mem.pos <= 0) {
+ mem.pos = MEM_SIZE-1;
+ }
+ else {
+ mem.pos--;
+ }
+ return mem.pos;
+}
+
+int mem_right(){
+ if (mem.pos >= MEM_SIZE-1) {
+ mem.pos = 0;
+ }
+ else {
+ mem.pos++;
+ }
+ return mem.pos;
+
+}
+
+int mem_get(){
+ return mem.arr[mem.pos];
+}
+
+int mem_set(char v){
+ mem.arr[mem.pos] = v;
+ return v;
+}
+
+void mem_printDebug(){
+ if (mem.pos+9 >= MEM_SIZE)
+ printf("index: %d [%d .. %d]: ", mem.pos, mem.pos, mem.pos-MEM_SIZE+9);
+ printf("index: %d [%d .. %d]: ", mem.pos, mem.pos, mem.pos+9);
+
+ for (int i = 0; i < 10; ++i) {
+ if (mem.pos+i >= MEM_SIZE) {
+ printf("%d ", mem.arr[mem.pos-MEM_SIZE+i]);
+ }
+ else {
+ printf("%d ", mem.arr[mem.pos+i]);
+ }
+ }
+
+}