From 9f938ab8ba5af561bd44dbc7142f338ce317a01a Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sat, 1 Nov 2025 09:46:52 +0800 Subject: Etlas project. --- esp32/main/scrn.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 esp32/main/scrn.c (limited to 'esp32/main/scrn.c') diff --git a/esp32/main/scrn.c b/esp32/main/scrn.c new file mode 100644 index 0000000..d455e5b --- /dev/null +++ b/esp32/main/scrn.c @@ -0,0 +1,43 @@ +#include + +#include "scrn.h" + +#define MASK_ON(x) (1ULL << (7 - (x % 8))) +#define MASK_OFF(x) ~(1ULL << (7 - (x % 8))) + +const static char *TAG = "scrn"; + +void scrn_clear(struct scrn *sc) +{ + int n = sc->width * sc->height / 8; + + for (int i = 0; i < n; i++) + sc->fb[i] = 0; +} + +void scrn_draw(struct scrn *sc, struct sprite *s) +{ + int s_n = s->width * s->height; + int buf_n = sc->width * sc->height; + int buf_i = s->offset_y * sc->width + s->offset_x; + + int s_i = 0, s_col = 0; + + while (s_i < s_n) { + if (s_col == s->width) { + s_col = 0; + buf_i += sc->width - s->width; + } + + if (s->bmp[s_i / 8] & MASK_ON(s_i)) { + if (buf_i < buf_n) + sc->fb[buf_i / 8] |= MASK_ON(buf_i); + else + ESP_LOGE(TAG, "draw(): pixel out of range"); + } + + s_i++; + buf_i++; + s_col++; + } +} -- cgit v1.2.3