aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-17 14:06:37 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-10-17 14:06:37 +0200
commit7d29faead63abf66a9ef35606a732ca3493c6fbe (patch)
tree2927b97ef942d3aa3f8c4f2ac4dacab6693d5c4e /src
parent1aa6444759c2e564f5b99c0cd65f7c2bb134758a (diff)
Add Globals
Note that we fail to build on linking errors - we have a lot of missing `env` functions to implement since moving away from the stub. Now the real fun begins...
Diffstat (limited to 'src')
-rw-r--r--src/env.c21
-rw-r--r--src/env.h8
-rw-r--r--src/game.c2
3 files changed, 30 insertions, 1 deletions
diff --git a/src/env.c b/src/env.c
index 71858e3..6d5078a 100644
--- a/src/env.c
+++ b/src/env.c
@@ -1,3 +1,5 @@
+#include <math.h>
+
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_timer.h>
@@ -244,3 +246,22 @@ void w2c_env_0x5Femscripten_set_main_loop(struct w2c_env *env, uint32_t func,
(void)fps;
(void)simulate_infinite_loop;
}
+
+static struct w2c_global shared_global = {
+ .infinity = INFINITY,
+ .nan = NAN,
+};
+
+double *w2c_global_Infinity(struct w2c_global *global) {
+ if (!global) {
+ global = &shared_global;
+ }
+ return &global->infinity;
+}
+
+double *w2c_global_NaN(struct w2c_global *global) {
+ if (!global) {
+ global = &shared_global;
+ }
+ return &global->nan;
+}
diff --git a/src/env.h b/src/env.h
index 4f99d2e..54d159f 100644
--- a/src/env.h
+++ b/src/env.h
@@ -33,6 +33,14 @@ struct w2c_env {
};
/**
+ * The Web Assembly host globals.
+ */
+struct w2c_global {
+ double infinity;
+ double nan;
+};
+
+/**
* Allocates a new host environment with the specified Web Assembly memory size.
*/
struct w2c_env *pw_env_init(size_t memory);
diff --git a/src/game.c b/src/game.c
index fa031a0..84b17f7 100644
--- a/src/game.c
+++ b/src/game.c
@@ -80,7 +80,7 @@ bool pw_game_start(struct pw_game *game, struct pw_multicart *carts) {
.carts = game->carts,
.instance = &game->instance,
});
- wasm2c_pico8_instantiate(&game->instance, game->env);
+ wasm2c_pico8_instantiate(&game->instance, game->env, NULL);
uint32_t argv;
{