aboutsummaryrefslogtreecommitdiff
path: root/src/bmlist.c
diff options
context:
space:
mode:
authorDien-Nhung Nguyen <kein@kienlab.com>2024-08-27 20:08:24 +0700
committerGitHub <noreply@github.com>2024-08-27 15:08:24 +0200
commitc95faf32a6a98975828717d596ff51dedeecdf56 (patch)
tree8fe52862e0c34bfe82509adf0c98a8e57056d4c7 /src/bmlist.c
parentf5874d607315ff88b27414299089b8528b5bb07c (diff)
Add animations (#15)
* animation: add xbm animations * refactor: correct framebuffer terminology * animation: add animations and effect * animation: timing with TMOS scheduler
Diffstat (limited to 'src/bmlist.c')
-rw-r--r--src/bmlist.c85
1 files changed, 85 insertions, 0 deletions
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 <memory.h>
+
+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;
+}