summaryrefslogtreecommitdiff
path: root/reduced_system_layer.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2024-11-02 00:00:35 +0100
committerMitya Selivanov <automainint@guattari.tech>2024-11-02 00:00:35 +0100
commit48c5d9b83afd1cd56e73449aebaf461cb48360d9 (patch)
tree41127704d20b1ee53fa1034e53339c22ca4c820d /reduced_system_layer.c
parent2afdeaedbfb488f20cdc1cca7ce01a915df4d53a (diff)
downloadreduced_system_layer-48c5d9b83afd1cd56e73449aebaf461cb48360d9.zip
wasm: Fix memcpy, memset
Diffstat (limited to 'reduced_system_layer.c')
-rwxr-xr-xreduced_system_layer.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index 7cbfd93..b7b0d5a 100755
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -226,10 +226,11 @@ i32 p_handle_events(void);
i32 p_wait_events(void);
void p_render_frame(void);
-// User-defined proc
+// User-defined frame updating procedure
+// NOTE This procedure is required for the WebAssembly compatibility.
void update_and_render_frame(void);
-// Convenient helper for the event loop
+// Convenient helper procedure for the event loop
void p_event_loop(void);
// Clipboard
@@ -267,14 +268,12 @@ f64 ceil(f64 x);
// ================================================================
//
-// WRITE YOUR CODE HERE
+// EXAMPLE CODE
//
// ================================================================
#ifdef REDUCED_SYSTEM_LAYER_EXAMPLE
-// NOTE
-// This procedure is required for the WebAssembly compatibility.
void update_and_render_frame(void) {
p_handle_events();
@@ -325,8 +324,10 @@ Platform platform = {0};
void p_event_loop(void) {
p_init();
+#if !defined(__wasm__)
while (!platform.done) update_and_render_frame();
p_cleanup();
+#endif
}
// ================================================================
@@ -1250,6 +1251,18 @@ void p_render_frame(void) {
p_render_frame_impl();
}
+__attribute__((export_name("js_memset"))) void js_memset(void *dst, i32 val, u32 num) {
+ if (dst == NULL) return;
+ for (u32 i = 0; i < num; ++i)
+ ((u8 *) dst)[i] = (u8) val;
+}
+
+__attribute__((export_name("js_memcpy"))) void js_memcpy(void *dst, void const *src, u32 num) {
+ if (dst == NULL || src == NULL) return;
+ for (u32 i = 0; i < num; ++i)
+ ((u8 *) dst)[i] = ((u8 const *) src)[i];
+}
+
__attribute__((export_name("js_main"))) void js_main(c8 *href) {
main(1, &href);
}
@@ -1259,7 +1272,7 @@ __attribute__((export_name("js_init"))) void js_init(void) {
platform.done = 1;
}
-__attribute__((export_name("js_title"))) c8 *js_title(void) {
+__attribute__((export_name("js_title"))) void *js_title(void) {
return platform.title;
}
@@ -1274,6 +1287,8 @@ __attribute__((export_name("js_frame"))) void js_frame(i32 frame_width, i32 fram
platform.frame_height = frame_height;
}
+ platform.done = 0;
+
update_and_render_frame();
}