diff options
Diffstat (limited to 'reduced_system_layer.c')
-rwxr-xr-x | reduced_system_layer.c | 86 |
1 files changed, 63 insertions, 23 deletions
diff --git a/reduced_system_layer.c b/reduced_system_layer.c index 30fb48b..87778cd 100755 --- a/reduced_system_layer.c +++ b/reduced_system_layer.c @@ -1565,16 +1565,17 @@ void p_clipboard_write(i64 size, c8 *data) { #ifdef __wasm__ -static u32 _buffer[MAX_NUM_PIXELS] = {0}; -static Input_Key _input[MAX_INPUT_SIZE] = {0}; -static i32 _num_events = 0; -static i32 _input_size = 0; -static b8 _key_pressed[MAX_NUM_KEYS] = {0}; -static b8 _wait_events = 0; -i64 _sound_position = 0; -i64 _sound_read = 0; -f32 _sound_ring[MAX_NUM_AUDIO_FRAMES] = {0}; -f32 _sound_buffer[MAX_NUM_AUDIO_FRAMES] = {0}; +static u32 _buffer[MAX_NUM_PIXELS] = {0}; +static Input_Key _input[MAX_INPUT_SIZE] = {0}; +static c8 _clipboard_buffer[MAX_CLIPBOARD_SIZE] = {0}; +static i32 _num_events = 0; +static i32 _input_size = 0; +static b8 _key_pressed[MAX_NUM_KEYS] = {0}; +static b8 _wait_events = 0; +i64 _sound_position = 0; +i64 _sound_read = 0; +f32 _sound_ring[MAX_NUM_AUDIO_FRAMES] = {0}; +f32 _sound_buffer[MAX_NUM_AUDIO_FRAMES] = {0}; i32 p_time_impl(void); @@ -1588,11 +1589,12 @@ void p_sleep_for(i64 duration) { void p_init(void) { ++_num_events; - platform.pixels = _buffer; - platform.input = _input; - platform.done = 1; - _sound_position = AUDIO_AVAIL_MIN % MAX_NUM_AUDIO_FRAMES; - _sound_read = 0; + platform.pixels = _buffer; + platform.input = _input; + platform.clipboard = _clipboard_buffer; + platform.done = 1; + _sound_position = AUDIO_AVAIL_MIN % MAX_NUM_AUDIO_FRAMES; + _sound_read = 0; } i32 p_handle_events(void) { @@ -1615,6 +1617,21 @@ i32 p_wait_events(void) { void p_render_frame(void) { } +void p_clipboard_write_impl(i32 size, c8 *data); + +void p_clipboard_write(i64 size, c8 *data) { + if (size < 0 || data == NULL) + return; + if (size > MAX_CLIPBOARD_SIZE) + size = MAX_CLIPBOARD_SIZE; + + platform.clipboard_size = size; + for (i64 i = 0; i < size; ++i) + platform.clipboard[i] = data[i]; + + p_clipboard_write_impl((i32) size, data); +} + void p_handle_audio(i64 samples_elapsed) { if (samples_elapsed <= 0) return; @@ -1722,22 +1739,32 @@ __attribute__((export_name("js_mouseup"))) void js_mouseup(u32 buttons) { if (!(buttons & 4)) platform.key_down[BUTTON_MIDDLE] = 0; } -__attribute__((export_name("js_keydown"))) void js_keydown(u32 key, u32 mod) { - // TODO +__attribute__((export_name("js_keydown"))) void js_keydown(u32 key, u32 mod, u32 ch) { ++_num_events; - _key_pressed[key] = 1; - platform.key_down[key] = 1; + _key_pressed[key] = 1; + platform.key_down[key] = 1; + platform.key_down[MOD_CTRL] = (mod & 1) ? 1 : 0; + platform.key_down[MOD_SHIFT] = (mod & 2) ? 1 : 0; + platform.key_down[MOD_ALT] = (mod & 4) ? 1 : 0; + platform.key_down[MOD_META] = (mod & 8) ? 1 : 0; if (platform.input_size < MAX_INPUT_SIZE) platform.input[_input_size++] = (Input_Key) { - .key = key, - .c = key, + .ctrl = (mod & 1) ? 1 : 0, + .shift = (mod & 2) ? 1 : 0, + .alt = (mod & 4) ? 1 : 0, + .meta = (mod & 8) ? 1 : 0, + .key = key, + .c = ch, }; } __attribute__((export_name("js_keyup"))) void js_keyup(u32 key, u32 mod) { - // TODO ++_num_events; - platform.key_down[key] = 0; + platform.key_down[key] = 0; + platform.key_down[MOD_CTRL] = (mod & 1) ? 1 : 0; + platform.key_down[MOD_SHIFT] = (mod & 2) ? 1 : 0; + platform.key_down[MOD_ALT] = (mod & 4) ? 1 : 0; + platform.key_down[MOD_META] = (mod & 8) ? 1 : 0; } __attribute__((export_name("js_sample_rate"))) f64 js_sample_rate(void) { @@ -1756,6 +1783,19 @@ __attribute__((export_name("js_sound_buffer"))) void *js_sound_buffer(void) { return _sound_buffer; } +__attribute__((export_name("js_clipboard_size"))) i32 js_clipboard_size(void) { + return platform.clipboard_size; +} + +__attribute__((export_name("js_clipboard_buffer"))) void *js_clipboard_buffer(i32 len) { + if (len < 0) + len = 0; + if (len > MAX_CLIPBOARD_SIZE) + len = MAX_CLIPBOARD_SIZE; + platform.clipboard_size = len; + return platform.clipboard; +} + #endif // __wasm__ // ================================================================ |