Mirai's Miscellaneous Misadventures

M50 / engines / wasm.c

1/* license: AGPLv3 or later */
2/* copyright 2024 zamfofex */
3
4#include <stdlib.h>
5
6#include <mimimi-chapters.h>
7
8unsigned char mimimi_wasm_sync(void);
9void mimimi_wasm_stamp(void *data, int x0, int y0, void *texture);
10void *mimimi_wasm_texture(void *data, struct mimimi_image *image);
11void mimimi_wasm_invalidate(void *data, void *texture);
12
13int mimimi_wasm(void *(*start)(struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right))
14{
15	unsigned char keys;
16	void *chapter;
17	struct mimimi_engine engine;
18	
19	engine.stamp = &mimimi_wasm_stamp;
20	engine.texture = &mimimi_wasm_texture;
21	engine.invalidate = &mimimi_wasm_invalidate;
22	engine.size.width = 512;
23	engine.size.height = 256;
24	
25	chapter = (*start)(&engine);
26	
27	for (;;)
28	{
29		keys = mimimi_wasm_sync();
30		(*tick)(chapter, keys / 2, keys % 2);
31	}
32}