diff options
Diffstat (limited to 'src/env.c')
| -rw-r--r-- | src/env.c | 89 |
1 files changed, 83 insertions, 6 deletions
@@ -55,7 +55,6 @@ struct w2c_env *pw_env_init(size_t memory) { } env->memory.size = pages * wasm2c_pico8_pagesize_env_memory; env->memory.data_end = env->memory.data + env->memory.size; - SDL_Log("allocated %" SDL_PRIu64, env->memory.size); env->table.data = SDL_calloc(wasm2c_pico8_min_env_table, sizeof(*env->table.data)); @@ -319,8 +318,9 @@ uint32_t w2c_env_0x5FSDL_Init(struct w2c_env *env, uint32_t flags) { } void w2c_env_0x5FSDL_LockAudio(struct w2c_env *env) { + // Our Wasm runtime runs on a single thread, so there is nothing to lock + // for its internal audio buffer. (void)env; - env_unimplemented("_SDL_LockAudio"); } uint32_t w2c_env_0x5FSDL_LockSurface(struct w2c_env *env, uint32_t surface) { @@ -443,8 +443,9 @@ uint32_t w2c_env_0x5FSDL_SetVideoMode(struct w2c_env *env, uint32_t w, } void w2c_env_0x5FSDL_UnlockAudio(struct w2c_env *env) { + // Our Wasm runtime runs on a single thread, so there is nothing to unlock + // for its internal audio buffer. (void)env; - env_unimplemented("_SDL_UnlockAudio"); } void w2c_env_0x5FSDL_UnlockSurface(struct w2c_env *env, uint32_t surface) { @@ -744,18 +745,81 @@ uint32_t w2c_env_0x5Femscripten_asm_const_i(struct w2c_env *env, case 27: // Touch device detection, this seems to do a few things like reading mouse // coordinates from `asm_const` and making a larger audio buffer (I guess - // because phones would run slower `requestAnimationFrame` callbacks?). + // because phones would run slower audio data request callbacks?). // TODO(nlordell): Add touch detection to `pw_input`. return 0; case 28: - // `document.hidden` - which has no meaning for us. - return 0; + return (uint32_t)!(pw_input_window(env->context.input) & PW_WINDOW_VISIBLE); case 29: case 30: case 31: // All "listeners" are automatically installed in that we get them from SDL // events without asking, making these a no-op. return 0; + case 33: + return (uint32_t)pw_input_get_pointer_lock(env->context.input); + case 34: + // Whether or not `pico8_mouse` is set - we always keep track of the mouse + // so this is always true. + return 1; + case 35: { + struct pw_coordinates pos; + pw_input_mouse(env->context.input, &pos); + return pos.x; + } + case 36: { + struct pw_coordinates pos; + pw_input_mouse(env->context.input, &pos); + return pos.y; + } + case 37: + return (uint32_t)pw_input_key(env->context.input, NULL); + case 38: { + int32_t key; + pw_input_key(env->context.input, &key); + return (uint32_t)key; + } + case 39: { + int32_t dx; + pw_input_wheel(env->context.input, &dx, NULL); + return (uint32_t)dx; + } + case 40: { + int32_t dy; + pw_input_wheel(env->context.input, NULL, &dy); + return (uint32_t)dy; + } + case 41: + return (uint32_t)!!(pw_input_window(env->context.input) & PW_WINDOW_FOCUS); + case 42: + // PICO-8 keeps track of clicks on the page that are outside of the canvas + // area - this does not apply to us as the whole page is outside of the + // canvas and we already specify this information somewhat with the window + // flags, so always return `false`. + return 0; + case 43: + case 44: + // PICO-8 uses a text area for handling clipboard events, we don't need to + // do this as our SDL application handles them already; no-op. + return 0; + case 45: + return (uint32_t)pw_input_mouse(env->context.input, NULL); + case 46: + case 48: + // Machinery for creating directories, we have implicit directories in our + // file-system so these are all no-ops. + return 0; + case 49: + env->data.state.pointerlock = false; + return 0; + case 50: + return 0; + case 51: + case 53: + case 54: + case 55: + // TODO(nlordell): Handle clipboard text area. + return 0; default: env_badasm("i", code); } @@ -783,6 +847,15 @@ uint32_t w2c_env_0x5Femscripten_asm_const_ii(struct w2c_env *env, uint32_t code, return 0; } return (uint32_t)env->data.gpio[a]; + case 32: + if (!pw_audio_start(env->context.audio, a)) { + SDL_LogWarn(0, "failed to setup audio: %s", SDL_GetError()); + } + return 0; + case 47: + // Machinery for creating directories, we have implicit directories in our + // file-system so these are all no-ops. + return 0; default: env_badasm("ii", code); } @@ -808,6 +881,10 @@ uint32_t w2c_env_0x5Femscripten_asm_const_iii(struct w2c_env *env, env->data.gpio[a] = (uint8_t)(b & 0xff); } return 0; + case 52: + case 56: + // TODO(nlordell): Handle clipboard text area. + return 0; default: env_badasm("iii", code); } |
