aboutsummaryrefslogtreecommitdiff
path: root/src/env.c
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-29 11:52:30 +0100
committerNicholas Rodrigues Lordello <[email protected]>2026-10-29 11:59:24 +0100
commite51027a576a07ffb41b6e7d2bfc3aade6ae091d7 (patch)
tree1d30aa7156f5a470a20bfab9d9c697829e2aca25 /src/env.c
parentf9950fce6f7b7a3743920f0d787fb1857aa05769 (diff)
Minor Fixes
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/env.c b/src/env.c
index 0113665..9a41eb6 100644
--- a/src/env.c
+++ b/src/env.c
@@ -205,7 +205,7 @@ bool pw_env_iterate(struct w2c_env *env, bool *shutdown) {
// request instead of a trap.
if (env_shutdown(env)) {
*shutdown = true;
- return true;
+ goto cleanup;
}
return SDL_SetError("PICO-8 iteration execution trapped: %s",
@@ -232,12 +232,13 @@ bool pw_env_iterate(struct w2c_env *env, bool *shutdown) {
goto mixdone;
}
}
-mixdone:
+mixdone:
wasm_rt_trap_unregister();
*shutdown = env_shutdown(env);
+cleanup:;
bool pointerlock;
bool fssync;
if (*shutdown) {
@@ -1021,11 +1022,15 @@ uint32_t w2c_env_0x5Femscripten_asm_const_i(struct w2c_env *env,
return 0;
case 50:
return 0;
- case 51:
- if (!pw_input_clipboard(env->context.input, 0)) {
+ case 51: {
+ char *clipboard = pw_input_clipboard(env->context.input, 0);
+ if (!clipboard) {
SDL_LogWarn(0, "failed to clear clipboard: %s", SDL_GetError());
+ return 0;
}
+ *clipboard = '\0';
return 0;
+ }
case 53:
if (!pw_input_clipboard_commit(env->context.input)) {
SDL_LogWarn(0, "failed to commit to system clipboard: %s",
@@ -1041,11 +1046,12 @@ uint32_t w2c_env_0x5Femscripten_asm_const_i(struct w2c_env *env,
// We don't have a text area, so this is a no-op.
return 0;
case 55: {
- if (!pw_input_clipboard_fetch(env->context.input, &env->data.cliplen)) {
- SDL_LogWarn(0, "failed to fetch to system clipboard: %s", SDL_GetError());
+ size_t len;
+ if (!pw_input_clipboard_fetch(env->context.input, &len)) {
+ SDL_LogWarn(0, "failed to fetch system clipboard: %s", SDL_GetError());
return 0;
}
- return (uint32_t)!!(env->data.cliplen);
+ return (uint32_t)!!len;
}
default:
env_badasm("i", code);
@@ -1116,6 +1122,7 @@ uint32_t w2c_env_0x5Femscripten_asm_const_iii(struct w2c_env *env,
}
wasm_rt_memory_load(&env->memory, a, clipboard, b);
+ clipboard[b] = '\0';
return 0;
}
case 56:
@@ -1123,13 +1130,14 @@ uint32_t w2c_env_0x5Femscripten_asm_const_iii(struct w2c_env *env,
return 0;
}
- uint32_t len = (uint32_t)SDL_min(env->data.cliplen, b - 1);
- char const *clipboard = pw_input_clipboard(env->context.input, len);
+ char const *clipboard = pw_input_clipboard(env->context.input, 0);
if (!clipboard) {
SDL_LogWarn(0, "failed to read clipboard buffer: %s", SDL_GetError());
+ return 0;
}
// Make sure to not split UTF-8 characters.
+ uint32_t len = (uint32_t)SDL_min(SDL_strlen(clipboard), b - 1);
while (len && (clipboard[len] & 0xc0) == 0x80) {
--len;
}
@@ -1203,7 +1211,7 @@ uint32_t w2c_env_0x5Femscripten_asm_const_iiiiiiiii(
case 10:
// Sync PICO-8 state, we only care about requesting pointer lock (so we
// can try to lock the pointer) or that shutdown is requested (so we can
- // exit back to the cart selectio menu.
+ // exit back to the cart selection menu.
env->data.state.pointerlock = f;
env->data.state.shutdown = h;
return 0;