]> cloudbase.mooo.com Git - z180-stamp.git/blob - avr/background.c
Merge branch 'master' into timelib
[z180-stamp.git] / avr / background.c
1 #include "common.h"
2 #include "background.h"
3
4
5 #define BG_FUNC_MAX 5
6
7 static struct {
8 bg_func fct;
9 int param;
10 } func_tab[BG_FUNC_MAX];
11
12 static int_fast8_t fcount;
13
14 int bg_register(bg_func f, int initval)
15 {
16 if (fcount < BG_FUNC_MAX) {
17 func_tab[fcount].fct = f;
18 func_tab[fcount].param = initval;
19 return ++fcount - 1;
20 }
21 return -1;
22 }
23
24 int bg_setstat(int handle, int val)
25 {
26 if (handle < fcount) {
27 func_tab[handle].param = val;
28 return 1;
29 }
30
31 return 0;
32 }
33
34
35 int bg_getstat(int handle)
36 {
37 if (handle < fcount) {
38 return func_tab[handle].param;
39 }
40 return 0;
41 }
42
43
44 void bg_shed(void)
45 {
46 static int_fast8_t current;
47
48 if (func_tab[current].fct) {
49 int v = func_tab[current].fct(func_tab[current].param);
50 func_tab[current].param = v;
51 }
52 if (++current >= fcount)
53 current = 0;
54 }
55
56