Mirai's Miscellaneous Misadventures

M52 / engines / wasm.c

1/* license: AGPLv3 or later */
2/* copyright 2024 zamfofex */
3
4#include <stdlib.h>
5#include "../mimimi.h"
6
7void mimimi_wasm_sync(int width, int height, unsigned char *colors);
8
9int mimimi_wasm_keys(void);
10int mimimi_wasm_width(void);
11int mimimi_wasm_height(void);
12
13void mimimi_main(void (*tick)(void *data, struct mimimi_output *output, struct mimimi_input *input), void *data)
14{
15	unsigned char keys;
16	struct mimimi_input input;
17	struct mimimi_output output;
18	
19	for (;;)
20	{
21		keys = mimimi_wasm_keys();
22		input.size.width = mimimi_wasm_width();
23		input.size.height = mimimi_wasm_height();
24		input.left = keys / 2;
25		input.right = keys % 2;
26		
27		(*tick)(data, &output, &input);
28		mimimi_wasm_sync(output.image.width, output.image.height, output.image.colors);
29	}
30}