1#![allow(clippy::missing_safety_doc)]
8
9#[cfg(target_arch = "wasm32")]
10mod imports {
11 #[link(wasm_import_module = "gasm")]
12 unsafe extern "C" {
13 pub fn log(msg: *const u8, msg_len: u32);
15 pub fn time_ms() -> f64;
17 pub fn set_frame_rate(hz: f64);
19 pub fn video_present(rgba: *const u8, width: u32, height: u32, stride: u32);
21 pub fn audio_config(sample_rate: u32, channels: u32);
23 pub fn audio_push(samples: *const f32, frames: u32);
25 pub fn input_pad(player: u32) -> u32;
27 pub fn text_input(dst: *mut u8, cap: u32) -> i32;
29 pub fn input_mode(flags: u32);
31 pub fn key_state(dst: *mut u8, len: u32) -> i32;
33 pub fn key_events(dst: *mut u8, cap: u32) -> i32;
35 pub fn pointer(dst: *mut u8, cap: u32) -> i32;
37 pub fn gamepad(slot: u32, dst: *mut u8, cap: u32) -> i32;
39 pub fn gamepad_name(slot: u32, dst: *mut u8, cap: u32) -> i32;
41 pub fn asset_size(name: *const u8, name_len: u32) -> i32;
43 pub fn asset_read(name: *const u8, name_len: u32, dst: *mut u8, cap: u32) -> i32;
45 pub fn asset_read_at(name: *const u8, name_len: u32, offset: u32, dst: *mut u8, len: u32) -> i32;
47 pub fn asset_count() -> u32;
49 pub fn asset_name(index: u32, dst: *mut u8, cap: u32) -> i32;
51 pub fn param(name: *const u8, name_len: u32, dst: *mut u8, cap: u32) -> i32;
53 }
54
55 #[link(wasm_import_module = "gasm:gfx")]
56 unsafe extern "C" {
57 #[link_name = "width"]
59 pub fn gfx_width() -> u32;
60 #[link_name = "height"]
62 pub fn gfx_height() -> u32;
63 #[link_name = "create_shader"]
65 pub fn gfx_create_shader(wgsl: *const u8, wgsl_len: u32) -> u32;
66 #[link_name = "create_buffer"]
68 pub fn gfx_create_buffer(size: u32, usage: u32) -> u32;
69 #[link_name = "create_pipeline"]
71 pub fn gfx_create_pipeline(json: *const u8, json_len: u32) -> u32;
72 #[link_name = "create_bind_group"]
74 pub fn gfx_create_bind_group(json: *const u8, json_len: u32) -> u32;
75 #[link_name = "create_bind_group_layout"]
77 pub fn gfx_create_bind_group_layout(json: *const u8, json_len: u32) -> u32;
78 #[link_name = "create_texture"]
80 pub fn gfx_create_texture(json: *const u8, json_len: u32) -> u32;
81 #[link_name = "write_texture"]
83 pub fn gfx_write_texture(texture: u32, mip: u32, x: u32, y: u32, width: u32, height: u32, data: *const u8, len: u32);
84 #[link_name = "create_sampler"]
86 pub fn gfx_create_sampler(json: *const u8, json_len: u32) -> u32;
87 #[link_name = "write_buffer"]
89 pub fn gfx_write_buffer(buffer: u32, offset: u32, data: *const u8, len: u32);
90 #[link_name = "begin_frame"]
92 pub fn gfx_begin_frame(r: f32, g: f32, b: f32, a: f32) -> u32;
93 #[link_name = "set_pipeline"]
94 pub fn gfx_set_pipeline(pipeline: u32);
95 #[link_name = "set_bind_group"]
96 pub fn gfx_set_bind_group(index: u32, bind_group: u32);
97 #[link_name = "set_bind_group_offsets"]
99 pub fn gfx_set_bind_group_offsets(index: u32, bind_group: u32, offsets: *const u32, count: u32);
100 #[link_name = "set_viewport"]
102 pub fn gfx_set_viewport(x: f32, y: f32, width: f32, height: f32, min_depth: f32, max_depth: f32);
103 #[link_name = "set_scissor_rect"]
105 pub fn gfx_set_scissor_rect(x: u32, y: u32, width: u32, height: u32);
106 #[link_name = "set_vertex_buffer"]
107 pub fn gfx_set_vertex_buffer(slot: u32, buffer: u32, offset: u32);
108 #[link_name = "set_index_buffer"]
110 pub fn gfx_set_index_buffer(buffer: u32, format: u32, offset: u32);
111 #[link_name = "draw"]
112 pub fn gfx_draw(vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32);
113 #[link_name = "draw_indexed"]
114 pub fn gfx_draw_indexed(index_count: u32, instance_count: u32, first_index: u32, base_vertex: i32, first_instance: u32);
115 #[link_name = "end_frame"]
117 pub fn gfx_end_frame();
118 }
119
120 #[link(wasm_import_module = "gasm:net")]
121 unsafe extern "C" {
122 #[link_name = "open"]
124 pub fn net_open(url: *const u8, url_len: u32) -> i32;
125 #[link_name = "state"]
127 pub fn net_state(conn: i32) -> u32;
128 #[link_name = "send"]
130 pub fn net_send(conn: i32, data: *const u8, len: u32) -> i32;
131 #[link_name = "recv"]
133 pub fn net_recv(conn: i32, dst: *mut u8, cap: u32) -> i32;
134 #[link_name = "close"]
135 pub fn net_close(conn: i32);
136 }
137
138 #[link(wasm_import_module = "gasm:storage")]
139 unsafe extern "C" {
140 #[link_name = "get"]
142 pub fn storage_get(key: *const u8, key_len: u32, dst: *mut u8, cap: u32) -> i32;
143 #[link_name = "set"]
145 pub fn storage_set(key: *const u8, key_len: u32, data: *const u8, len: u32) -> i32;
146 #[link_name = "delete"]
148 pub fn storage_delete(key: *const u8, key_len: u32) -> i32;
149 #[link_name = "count"]
151 pub fn storage_count() -> u32;
152 #[link_name = "key"]
154 pub fn storage_key(index: u32, dst: *mut u8, cap: u32) -> i32;
155 }
156
157 #[link(wasm_import_module = "wasi_snapshot_preview1")]
158 unsafe extern "C" {
159 pub fn proc_exit(code: i32) -> !;
161 }
162}
163
164#[cfg(target_arch = "wasm32")]
165pub use imports::*;
166
167#[cfg(not(target_arch = "wasm32"))]
168pub use crate::native::abi::*;
169
170pub mod keys {
172 pub const ESCAPE: u32 = 1;
173 pub const F1: u32 = 2;
174 pub const F2: u32 = 3;
175 pub const F3: u32 = 4;
176 pub const F4: u32 = 5;
177 pub const F5: u32 = 6;
178 pub const F6: u32 = 7;
179 pub const F7: u32 = 8;
180 pub const F8: u32 = 9;
181 pub const F9: u32 = 10;
182 pub const F10: u32 = 11;
183 pub const F11: u32 = 12;
184 pub const F12: u32 = 13;
185 pub const BACKQUOTE: u32 = 14;
186 pub const DIGIT0: u32 = 15;
187 pub const DIGIT1: u32 = 16;
188 pub const DIGIT2: u32 = 17;
189 pub const DIGIT3: u32 = 18;
190 pub const DIGIT4: u32 = 19;
191 pub const DIGIT5: u32 = 20;
192 pub const DIGIT6: u32 = 21;
193 pub const DIGIT7: u32 = 22;
194 pub const DIGIT8: u32 = 23;
195 pub const DIGIT9: u32 = 24;
196 pub const MINUS: u32 = 25;
197 pub const EQUAL: u32 = 26;
198 pub const BACKSPACE: u32 = 27;
199 pub const TAB: u32 = 28;
200 pub const KEY_A: u32 = 29;
201 pub const KEY_B: u32 = 30;
202 pub const KEY_C: u32 = 31;
203 pub const KEY_D: u32 = 32;
204 pub const KEY_E: u32 = 33;
205 pub const KEY_F: u32 = 34;
206 pub const KEY_G: u32 = 35;
207 pub const KEY_H: u32 = 36;
208 pub const KEY_I: u32 = 37;
209 pub const KEY_J: u32 = 38;
210 pub const KEY_K: u32 = 39;
211 pub const KEY_L: u32 = 40;
212 pub const KEY_M: u32 = 41;
213 pub const KEY_N: u32 = 42;
214 pub const KEY_O: u32 = 43;
215 pub const KEY_P: u32 = 44;
216 pub const KEY_Q: u32 = 45;
217 pub const KEY_R: u32 = 46;
218 pub const KEY_S: u32 = 47;
219 pub const KEY_T: u32 = 48;
220 pub const KEY_U: u32 = 49;
221 pub const KEY_V: u32 = 50;
222 pub const KEY_W: u32 = 51;
223 pub const KEY_X: u32 = 52;
224 pub const KEY_Y: u32 = 53;
225 pub const KEY_Z: u32 = 54;
226 pub const BRACKET_LEFT: u32 = 55;
227 pub const BRACKET_RIGHT: u32 = 56;
228 pub const BACKSLASH: u32 = 57;
229 pub const CAPS_LOCK: u32 = 58;
230 pub const SEMICOLON: u32 = 59;
231 pub const QUOTE: u32 = 60;
232 pub const ENTER: u32 = 61;
233 pub const SHIFT_LEFT: u32 = 62;
234 pub const INTL_BACKSLASH: u32 = 63;
235 pub const COMMA: u32 = 64;
236 pub const PERIOD: u32 = 65;
237 pub const SLASH: u32 = 66;
238 pub const SHIFT_RIGHT: u32 = 67;
239 pub const CONTROL_LEFT: u32 = 68;
240 pub const META_LEFT: u32 = 69;
241 pub const ALT_LEFT: u32 = 70;
242 pub const SPACE: u32 = 71;
243 pub const ALT_RIGHT: u32 = 72;
244 pub const META_RIGHT: u32 = 73;
245 pub const CONTEXT_MENU: u32 = 74;
246 pub const CONTROL_RIGHT: u32 = 75;
247 pub const PRINT_SCREEN: u32 = 76;
248 pub const SCROLL_LOCK: u32 = 77;
249 pub const PAUSE: u32 = 78;
250 pub const INSERT: u32 = 79;
251 pub const HOME: u32 = 80;
252 pub const PAGE_UP: u32 = 81;
253 pub const DELETE: u32 = 82;
254 pub const END: u32 = 83;
255 pub const PAGE_DOWN: u32 = 84;
256 pub const ARROW_UP: u32 = 85;
257 pub const ARROW_LEFT: u32 = 86;
258 pub const ARROW_DOWN: u32 = 87;
259 pub const ARROW_RIGHT: u32 = 88;
260 pub const NUM_LOCK: u32 = 89;
261 pub const NUMPAD_DIVIDE: u32 = 90;
262 pub const NUMPAD_MULTIPLY: u32 = 91;
263 pub const NUMPAD_SUBTRACT: u32 = 92;
264 pub const NUMPAD_ADD: u32 = 93;
265 pub const NUMPAD_ENTER: u32 = 94;
266 pub const NUMPAD_DECIMAL: u32 = 95;
267 pub const NUMPAD0: u32 = 96;
268 pub const NUMPAD1: u32 = 97;
269 pub const NUMPAD2: u32 = 98;
270 pub const NUMPAD3: u32 = 99;
271 pub const NUMPAD4: u32 = 100;
272 pub const NUMPAD5: u32 = 101;
273 pub const NUMPAD6: u32 = 102;
274 pub const NUMPAD7: u32 = 103;
275 pub const NUMPAD8: u32 = 104;
276 pub const NUMPAD9: u32 = 105;
277 pub const NUMPAD_EQUAL: u32 = 106;
278 pub const NUMPAD_COMMA: u32 = 107;
279 pub const INTL_RO: u32 = 108;
280 pub const INTL_YEN: u32 = 109;
281 pub const F13: u32 = 110;
282 pub const F14: u32 = 111;
283 pub const F15: u32 = 112;
284 pub const F16: u32 = 113;
285 pub const F17: u32 = 114;
286 pub const F18: u32 = 115;
287 pub const F19: u32 = 116;
288 pub const F20: u32 = 117;
289 pub const F21: u32 = 118;
290 pub const F22: u32 = 119;
291 pub const F23: u32 = 120;
292 pub const F24: u32 = 121;
293 pub const NAMES: [&str; 122] = [
295 "", "Escape", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Backquote", "Digit0", "Digit1", "Digit2", "Digit3", "Digit4", "Digit5", "Digit6", "Digit7", "Digit8", "Digit9", "Minus", "Equal", "Backspace", "Tab", "KeyA", "KeyB", "KeyC", "KeyD", "KeyE", "KeyF", "KeyG", "KeyH", "KeyI", "KeyJ", "KeyK", "KeyL", "KeyM", "KeyN", "KeyO", "KeyP", "KeyQ", "KeyR", "KeyS", "KeyT", "KeyU", "KeyV", "KeyW", "KeyX", "KeyY", "KeyZ", "BracketLeft", "BracketRight", "Backslash", "CapsLock", "Semicolon", "Quote", "Enter", "ShiftLeft", "IntlBackslash", "Comma", "Period", "Slash", "ShiftRight", "ControlLeft", "MetaLeft", "AltLeft", "Space", "AltRight", "MetaRight", "ContextMenu", "ControlRight", "PrintScreen", "ScrollLock", "Pause", "Insert", "Home", "PageUp", "Delete", "End", "PageDown", "ArrowUp", "ArrowLeft", "ArrowDown", "ArrowRight", "NumLock", "NumpadDivide", "NumpadMultiply", "NumpadSubtract", "NumpadAdd", "NumpadEnter", "NumpadDecimal", "Numpad0", "Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "Numpad9", "NumpadEqual", "NumpadComma", "IntlRo", "IntlYen", "F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", "F22", "F23", "F24",
296 ];
297}