aboutsummaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-23 17:00:13 +0200
committerNicholas Rodrigues Lordello <[email protected]>2026-10-23 17:00:13 +0200
commit99fa88f971f23a3422f370d6f05b277c102ee9c3 (patch)
tree31d120878636b1c275fa164bfe9655bfc934cfbf /src/game.c
parent24ecea092c4db12cee343a9885fa56b8587b5f93 (diff)
Implement IO Syscalls
Now that we implemented our file-system, we can implement IO-related syscalls and ASM constants and get further into the boot. For now, we just use an in-memory userdat storage, but eventually, I want to persist this to disk. We can now boot to the point where we try to `invoke_vii`, which, AFAIU, is the whole setjmp/longjmp machinery that I have to figure out.
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/game.c b/src/game.c
index af5d249..8622e74 100644
--- a/src/game.c
+++ b/src/game.c
@@ -31,6 +31,11 @@ struct pw_game *pw_game_init(SDL_Renderer *renderer, enum pw_scale_mode mode,
goto error;
}
+ game->userdat = pw_fs_init(NULL);
+ if (!game->userdat) {
+ goto error;
+ }
+
return game;
error:
@@ -82,6 +87,7 @@ bool pw_game_start(struct pw_game *game, struct pw_cart_data *cartdat) {
.fb = game->fb,
.input = game->input,
.cartdat = game->cartdat,
+ .userdat = game->userdat,
.instance = &game->instance,
});
wasm2c_pico8_instantiate(&game->instance, game->env, NULL);
@@ -168,6 +174,13 @@ bool pw_game_iterate(struct pw_game *game) {
game->env->data.state.pointerlock = pw_input_get_pointer_lock(game->input);
}
+ if (game->env->data.state.fssync) {
+ game->env->data.state.fssync = false;
+ if (!pw_fs_sync(game->userdat)) {
+ SDL_LogWarn(0, "failed to persist user storage: %s", SDL_GetError());
+ }
+ }
+
return true;
shutdown: