]> git.seodisparate.com - LD53/commitdiff
Add some helpers, minor tweaks
authorStephen Seo <seo.disparate@gmail.com>
Sat, 29 Apr 2023 02:41:05 +0000 (11:41 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 29 Apr 2023 02:41:05 +0000 (11:41 +0900)
src/helpers.rs [new file with mode: 0644]
src/lib.rs

diff --git a/src/helpers.rs b/src/helpers.rs
new file mode 100644 (file)
index 0000000..3047e78
--- /dev/null
@@ -0,0 +1,24 @@
+pub fn fill(color: u8) {
+    if color > 3 {
+        crate::trace("ERROR: Invalid value passed to helper \"fill\"");
+        return;
+    }
+    unsafe {
+        (&mut *crate::FRAMEBUFFER).fill(color | (color << 2) | (color << 4) | (color << 6));
+    }
+}
+
+pub fn draw_mouse() -> Option<(i16, i16)> {
+    let mouse = unsafe { *crate::MOUSE_BUTTONS };
+    let mouse_x = unsafe { *crate::MOUSE_X };
+    let mouse_y = unsafe { *crate::MOUSE_Y };
+    if mouse & crate::MOUSE_LEFT != 0 {
+        unsafe { *crate::DRAW_COLORS = 2 }
+        crate::rect(i32::from(mouse_x) - 4, i32::from(mouse_y) - 4, 8, 8);
+        Some((mouse_x, mouse_y))
+    } else {
+        unsafe { *crate::DRAW_COLORS = 1 }
+        crate::rect(i32::from(mouse_x) - 2, i32::from(mouse_y) - 2, 4, 4);
+        None
+    }
+}
index d1c7f303ad384e2248fff70617202f7fde9391ef..86c1fd63544017f880f04464923994dd46176ad2 100644 (file)
@@ -3,6 +3,8 @@ mod alloc;
 mod wasm4;
 use wasm4::*;
 
+mod helpers;
+
 #[rustfmt::skip]
 const SMILEY: [u8; 8] = [
     0b11000011,
@@ -17,14 +19,18 @@ const SMILEY: [u8; 8] = [
 
 #[no_mangle]
 fn update() {
+    helpers::fill(3);
+
     unsafe { *DRAW_COLORS = 2 }
     text("Hello from Rust!", 10, 10);
 
     let gamepad = unsafe { *GAMEPAD1 };
     if gamepad & BUTTON_1 != 0 {
-        unsafe { *DRAW_COLORS = 4 }
+        unsafe { *DRAW_COLORS = 3 }
     }
 
     blit(&SMILEY, 76, 76, 8, 8, BLIT_1BPP);
     text("Press X to blink", 16, 90);
+
+    if let Some((x, y)) = helpers::draw_mouse() {}
 }