aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-01-20 18:55:23 -0700
committerChristian Cunningham <cc@localhost>2022-01-20 18:55:23 -0700
commit22297e0f0f5732b852614c7c97e7354d3e7be5c7 (patch)
treeaa7bab14241bf97d4073e2d7d1cffea32b3ac03b
parent4bb5f36b8c696361d5a283680ea7dadde4e364df (diff)
Added write offset
Made offsets movable
-rw-r--r--include/lib/mem.h3
-rw-r--r--src/lib/mem.c12
2 files changed, 9 insertions, 6 deletions
diff --git a/include/lib/mem.h b/include/lib/mem.h
index 04056f7..646a170 100644
--- a/include/lib/mem.h
+++ b/include/lib/mem.h
@@ -15,7 +15,8 @@ struct MemTab {
struct RotBuffer {
void* base;
unsigned int size;
- unsigned int offset;
+ unsigned int roffset;
+ unsigned int woffset;
};
void memset(unsigned char* dest, unsigned char value, unsigned int n);
diff --git a/src/lib/mem.c b/src/lib/mem.c
index dc915e6..e51ec32 100644
--- a/src/lib/mem.c
+++ b/src/lib/mem.c
@@ -5,13 +5,15 @@ void memcpyrot(unsigned char* src, struct RotBuffer* rb, unsigned int n)
{
if (n > rb->size)
return;
- unsigned char* addr = rb->base + rb->offset;
+ unsigned char* base = rb->base;
+ unsigned int offset = rb->woffset;
for (unsigned int i = 0; i < n; i++) {
- if (addr >= (unsigned char*)(rb->base + rb->size))
- addr = rb->base;
- *addr = src[i];
- addr++;
+ if (offset >= rb->size)
+ offset = 0;
+ base[offset] = src[i];
+ offset++;
}
+ rb->woffset = offset;
}
void memshow32(unsigned long* addr, unsigned int n)