]>
Commit | Line | Data |
---|---|---|
72f58822 L |
1 | #include "common.h" |
2 | #include "background.h" | |
3 | ||
4 | ||
5 | #define BG_FUNC_MAX 5 | |
6 | ||
89adce76 L |
7 | static struct { |
8 | bg_func fct; | |
9 | int param; | |
10 | } func_tab[BG_FUNC_MAX]; | |
11 | ||
72f58822 L |
12 | static int_fast8_t fcount; |
13 | ||
89adce76 | 14 | int bg_register(bg_func f, int initval) |
72f58822 L |
15 | { |
16 | if (fcount < BG_FUNC_MAX) { | |
89adce76 L |
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; | |
72f58822 L |
28 | return 1; |
29 | } | |
89adce76 L |
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 | } | |
72f58822 L |
40 | return 0; |
41 | } | |
42 | ||
43 | ||
44 | void bg_shed(void) | |
45 | { | |
46 | static int_fast8_t current; | |
47 | ||
89adce76 L |
48 | if (func_tab[current].fct) { |
49 | int v = func_tab[current].fct(func_tab[current].param); | |
50 | func_tab[current].param = v; | |
72f58822 L |
51 | } |
52 | if (++current >= fcount) | |
53 | current = 0; | |
54 | } | |
55 | ||
56 |