diff options
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | src/env.c | 21 | ||||
| -rw-r--r-- | src/env.h | 8 | ||||
| -rw-r--r-- | src/game.c | 2 |
4 files changed, 31 insertions, 10 deletions
@@ -6,8 +6,6 @@ HOSTCC ?= cc PICO8 ?= pico8 WASM2C ?= wasm2c -WAT2WASM ?= wat2wasm - ARCH ?= $(shell uname -m) CFLAGS ?= -std=c99 -Wall -Wextra -O2 -MMD -Isrc -Ilib -I$(SYSTEM) \ $(shell pkg-config sdl3 --cflags) @@ -38,8 +36,7 @@ $(OUT)/system/%.o: $(SYSTEM)/%.c @ mkdir -p $(dir $@) @ $(CC) $(CFLAGS) -Wno-unused -Wno-unused-parameter -c $< -o $@ -$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c: $(SYSTEM)/stub/pico8.wasm \ - $(SYSTEM)/pico8.wasm +$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c: $(SYSTEM)/pico8.wasm @ echo "WASM2C\t$(SYSTEM)/pico8.h $(SYSTEM)/pico8.c" @ $(WASM2C) $(W2CFLAGS) $< -o $(SYSTEM)/pico8.c @ echo '#include "wasmrt.h"' > $(SYSTEM)/wasm-rt.h @@ -70,11 +67,6 @@ $(SYSTEM)/%.png: carts/%.p8 @ mkdir -p $(dir $@) @ $(PICO8) $< -export $@ >/dev/null -$(SYSTEM)/stub/%.wasm: stub/%.wat - @ echo "WAT2WASM\t$@" - @ mkdir -p $(dir $@) - @ $(WAT2WASM) $< -o $@ - $(TOOLS)/%: tools/%.c @ echo "CC\t$@" @ mkdir -p $(dir $@) @@ -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; +} @@ -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); @@ -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; { |
