diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 00:45:24 +0100 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-10-29 00:45:24 +0100 |
| commit | ec6ed6404cdc29fc204eb93fdeb5025deb42f49d (patch) | |
| tree | 65dc21b389bc716163d9c0ba9a3e5f88ce883d69 /src/game.c | |
| parent | 05a5c587f6c59aee26038cc4bdf657d9040340e3 (diff) | |
Support the Shutdown Option
It looks like the `SHUTDOWN` menu option shows up when the `-run`
CLI argument is passed, so pass it. There is a catch though, in
that PICO-8 does not properly report shutdown requests in those
cases, so read Wasm memory directly to detect the shutdown request.
Diffstat (limited to 'src/game.c')
| -rw-r--r-- | src/game.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -115,14 +115,20 @@ bool pw_game_start(struct pw_game *game, struct pw_players *players, w2c_pico8_0x5F_0x5Femscripten_environ_constructor(&game->instance); - char const progname[] = "./picow"; - uint32_t arg0 = w2c_pico8_stackAlloc(&game->instance, sizeof(progname)); - wasm_rt_memory_store(&game->env->memory, arg0, progname, sizeof(progname)); - uint32_t argv = w2c_pico8_stackAlloc(&game->instance, 2 * sizeof(arg0)); - wasm_rt_memory_store32(&game->env->memory, argv, arg0); - wasm_rt_memory_store32(&game->env->memory, argv + 4, 0); + char const *args[] = {"./picow", "-run"}; + uint32_t argv = w2c_pico8_stackAlloc( + &game->instance, (SDL_arraysize(args) + 1) * sizeof(uint32_t)); + wasm_rt_memory_store32(&game->env->memory, + argv + SDL_arraysize(args) * sizeof(uint32_t), 0); + for (size_t i = 0; i < SDL_arraysize(args); ++i) { + uint32_t sz = (uint32_t)SDL_strlen(args[i]) + 1; + uint32_t arg = w2c_pico8_stackAlloc(&game->instance, sz); + wasm_rt_memory_store(&game->env->memory, arg, args[i], sz); + wasm_rt_memory_store32(&game->env->memory, argv + i * sizeof(arg), arg); + } - uint32_t status = w2c_pico8_0x5Fmain(&game->instance, 1, argv); + uint32_t status = + w2c_pico8_0x5Fmain(&game->instance, SDL_arraysize(args), argv); wasm_rt_trap_unregister(); @@ -166,7 +172,7 @@ bool pw_game_iterate(struct pw_game *game) { // In case we trapped for an `_exit` call, treat it as a shutdown // request instead of a trap. - if (game->env->data.state.shutdown) { + if (pw_env_shutdown(game->env)) { goto shutdown; } return SDL_SetError("PICO-8 iteration execution trapped: %s", @@ -192,7 +198,7 @@ mixdone: wasm_rt_trap_unregister(); - if (game->env->data.state.shutdown) { + if (pw_env_shutdown(game->env)) { goto shutdown; } @@ -216,7 +222,7 @@ shutdown: SDL_LogWarn(0, "failed to reset pointer lock: %s", SDL_GetError()); } - // TODO(nlordell): cleanly transition back to cart selection menu. + SDL_SetError("TODO(nlordell): implement clean shutdown"); return false; } |
