wasm4_sys/
lib.rs

1//! # Safety
2//!
3//! Many seemingly safe functions are marked unsafe.
4//! The reason for this is that the crate [`wasm4`](https://crates.io/crates/wasm4)
5//! uses them to achieve safe, idiomatic, and zero-overhead api.
6//! The major capability of that crate is being able to restrict ownership of
7//! various resources like framebuffer, sound, etc.
8//! To achieve that it implements WASM-4 api via methods on a struct like
9//! [`wasm4::sound::Resouce`](https://docs.rs/wasm4/latest/wasm4/sound/struct.Resource.html),
10//! ownership of which is restricted until you share it.
11//! As you may guess, calling [`crate::tone`] may interfere with assumptions about
12//! which sounds are playing in a code using `wasm4::sound::Resource`.
13//! Use of raw bindings usually gives little to no benefit, but is possible if you
14//! respect these assumptions described above.
15//!
16//! Some of these functions are unsafe for other reasons too, like raw memory access.
17//!
18//! However all of that assumes you or any dependency do not use any other bindings
19//! except for [`wasm4`](https://crates.io/crates/wasm4) and this [`crate`]
20//! (or uses them while respecting assumptions mentioned above, but this is discouraged).
21#![no_std]
22
23use core::ffi::c_void;
24
25pub const SCREEN_SIZE: u32 = 160;
26
27pub const PALETTE: *mut [u32; 4] = 0x04 as *mut [u32; 4];
28pub const DRAW_COLORS: *mut u16 = 0x14 as *mut u16;
29pub const GAMEPAD1: *const u8 = 0x16 as *const u8;
30pub const GAMEPAD2: *const u8 = 0x17 as *const u8;
31pub const GAMEPAD3: *const u8 = 0x18 as *const u8;
32pub const GAMEPAD4: *const u8 = 0x19 as *const u8;
33pub const MOUSE_X: *const i16 = 0x1a as *const i16;
34pub const MOUSE_Y: *const i16 = 0x1c as *const i16;
35pub const MOUSE_BUTTONS: *const u8 = 0x1e as *const u8;
36pub const SYSTEM_FLAGS: *mut u8 = 0x1f as *mut u8;
37pub const FRAMEBUFFER: *mut [u8; 6400] = 0xa0 as *mut [u8; 6400];
38
39pub const BUTTON_1: u8 = 1;
40pub const BUTTON_2: u8 = 2;
41pub const BUTTON_LEFT: u8 = 16;
42pub const BUTTON_RIGHT: u8 = 32;
43pub const BUTTON_UP: u8 = 64;
44pub const BUTTON_DOWN: u8 = 128;
45
46pub const MOUSE_LEFT: u8 = 1;
47pub const MOUSE_RIGHT: u8 = 2;
48pub const MOUSE_MIDDLE: u8 = 4;
49
50pub const SYSTEM_PRESERVE_FRAMEBUFFER: u8 = 1;
51pub const SYSTEM_HIDE_GAMEPAD_OVERLAY: u8 = 2;
52
53pub const BLIT_2BPP: u32 = 1;
54pub const BLIT_1BPP: u32 = 0;
55pub const BLIT_FLIP_X: u32 = 2;
56pub const BLIT_FLIP_Y: u32 = 4;
57pub const BLIT_ROTATE: u32 = 8;
58
59pub const TONE_PULSE1: u32 = 0;
60pub const TONE_PULSE2: u32 = 1;
61pub const TONE_TRIANGLE: u32 = 2;
62pub const TONE_NOISE: u32 = 3;
63pub const TONE_MODE1: u32 = 0;
64pub const TONE_MODE2: u32 = 4;
65pub const TONE_MODE3: u32 = 8;
66pub const TONE_MODE4: u32 = 12;
67
68extern "C" {
69    pub fn rect(x: i32, y: i32, width: u32, height: u32);
70    pub fn oval(x: i32, y: i32, width: u32, height: u32);
71    pub fn line(x1: i32, y1: i32, x2: i32, y2: i32);
72
73    pub fn hline(x: i32, y: i32, len: u32);
74    pub fn vline(x: i32, y: i32, len: u32);
75
76    pub fn text(text: *const u8, x: i32, y: i32);
77    pub fn textUtf8(text: *const u8, byte_length: usize, x: i32, y: i32);
78    pub fn textUtf16(text: *const u16, byte_length: usize, x: i32, y: i32);
79
80    pub fn blit(sprite: *const u8, x: i32, y: i32, width: u32, height: u32, flags: u32);
81    pub fn blitSub(
82        sprite: *const u8,
83        x: i32,
84        y: i32,
85        width: u32,
86        height: u32,
87        src_x: u32,
88        src_y: u32,
89        stride: u32,
90        flags: u32,
91    );
92
93    pub fn tone(frequency: u32, duration: u32, volume: u32, flags: u32);
94
95    pub fn diskr(dest: *mut u8, size: usize) -> u32;
96    pub fn diskw(src: *const u8, size: usize) -> u32;
97
98    pub fn trace(trace: *const u8);
99    pub fn traceUtf8(trace: *const u8, byte_length: usize);
100    pub fn traceUtf16(trace: *const u16, byte_length: usize);
101    pub fn tracef(fmt: *const u8, stack_ptr: *const c_void);
102
103}