From c34cd59be89fb26e63fe959b98afabb4f24ba5bd Mon Sep 17 00:00:00 2001 From: Rasmus Luha Date: Wed, 21 Sep 2022 14:16:01 +0300 Subject: init commit --- src/mem.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/mem.c (limited to 'src/mem.c') 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 +#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]); + } + } + +} -- cgit v1.2.3