aboutsummaryrefslogtreecommitdiff
path: root/src/bmlist.c
blob: e3bb34ffdd76f501f80b6e7dc4fb383879c899b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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;
}