From c95faf32a6a98975828717d596ff51dedeecdf56 Mon Sep 17 00:00:00 2001 From: Dien-Nhung Nguyen Date: Tue, 27 Aug 2024 20:08:24 +0700 Subject: Add animations (#15) * animation: add xbm animations * refactor: correct framebuffer terminology * animation: add animations and effect * animation: timing with TMOS scheduler --- src/bmlist.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/bmlist.c (limited to 'src/bmlist.c') diff --git a/src/bmlist.c b/src/bmlist.c new file mode 100644 index 0000000..e3bb34f --- /dev/null +++ b/src/bmlist.c @@ -0,0 +1,85 @@ +#include "bmlist.h" +#include + +volatile static bm_t *current, *head, *tail; + +static void bm_add(bm_t *new, bm_t *prev, bm_t *next) +{ + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; +} + +bm_t *bmlist_insert(bm_t *at, bm_t *new) +{ + bm_add(new, at, at->next); + return new; +} + +bm_t *bmlist_append(bm_t *new) +{ + bmlist_insert(tail, new); + tail = new; + return new; +} + +bm_t *bmlist_gonext() +{ + current = current->next; + current->anim_step = 0; + return current; +} + +bm_t *bmlist_goprev() +{ + current = current->prev; + current->anim_step = 0; + return current; +} + +bm_t *bmlist_gohead() +{ + current = head; + current->anim_step = 0; + return current; +} + +bm_t *bmlist_current() +{ + return current; +} + +static void list_del(bm_t *prev, bm_t *next) +{ + prev->next = next; + next->prev = prev; +} + +bm_t *bmlist_drop(bm_t *bm) +{ + list_del(bm->prev, bm->next); + return bm->next; +} + +bm_t *bm_new(uint16_t width) +{ + bm_t *bm = malloc(sizeof(bm_t)); + memset(bm, 0, sizeof(bm_t)); + + bm->width = width; + bm->buf = malloc(width * sizeof(uint16_t)); + memset(bm->buf, 0, width * sizeof(uint16_t)); + + bm->next = bm; + bm->prev = bm; + + return bm; +} + +void bmlist_init(uint16_t first_bm_width) +{ + current = bm_new(first_bm_width); + head = current; + tail = current; +} -- cgit v1.2.3