summaryrefslogtreecommitdiff
path: root/memview.c
diff options
context:
space:
mode:
Diffstat (limited to 'memview.c')
-rw-r--r--memview.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/memview.c b/memview.c
index 7f7dbd4..95a3c6c 100644
--- a/memview.c
+++ b/memview.c
@@ -39,7 +39,8 @@ uintptr_t to_addr(int x, int y) {
memcpy(&ux, &x, sizeof(unsigned int));
memcpy(&uy, &y, sizeof(unsigned int));
uintptr_t page = zorder(ux / PAGE_WIDTH, uy / PAGE_HEIGHT);
- int offset = x % PAGE_WIDTH + y % PAGE_HEIGHT * PAGE_WIDTH;
+ int offset =
+ x % PAGE_WIDTH / CHAR_BIT + y % PAGE_HEIGHT * PAGE_WIDTH / CHAR_BIT;
return page * PAGE_SIZE + offset;
}
@@ -135,3 +136,26 @@ bool render_pages(struct viewer *v,
}
return present;
}
+
+static void write_bit(int fd, int x, int y, bool bit) {
+ uintptr_t addr = to_addr(x, y);
+ int bit_offs = x % CHAR_BIT;
+ uint8_t byte;
+ if (read_mem(fd, addr, &byte, 1) == -1) return;
+ byte = (byte & ~(1 << bit_offs)) | (bit << bit_offs);
+ write_mem(fd, addr, &byte, 1);
+}
+
+void pencil(struct viewer *v,
+ double x1, double y1, double x2, double y2, bool bit) {
+ double dx = (x2 - x1);
+ double dy = (y2 - y1);
+ int step = abs(dx) >= abs(dy) ? abs(dx) : abs(dy);
+ dx = dx / step; dy = dy / step;
+ double x = x1; double y = y1;
+ for (int i = 0; i <= step; i++) {
+ write_bit(v->fd, x, y, bit);
+ x = x + dx;
+ y = y + dy;
+ }
+}