semi-working snake game
This commit is contained in:
@@ -79,6 +79,7 @@ embedded-text = "0.7.2"
|
||||
embedded-layout = "0.4.2"
|
||||
kolibri-embedded-gui = "0.1.0"
|
||||
|
||||
rand = { version = "0.9.0", default-features = false }
|
||||
once_cell = { version = "1.21.3", default-features = false }
|
||||
static_cell = "2.1.1"
|
||||
bitflags = "2.9.4"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use core::sync::atomic::Ordering;
|
||||
|
||||
use abi_sys::{DrawIterAbi, GetKeyAbi, LockDisplay, PrintAbi, SleepAbi};
|
||||
use embassy_rp::clocks::clk_sys_freq;
|
||||
use abi_sys::{DrawIterAbi, GetKeyAbi, LockDisplay, PrintAbi, RngRequest, SleepAbi};
|
||||
use core::{ptr::slice_from_raw_parts, sync::atomic::Ordering};
|
||||
use embassy_rp::clocks::{RoscRng, clk_sys_freq};
|
||||
use embedded_graphics::{Pixel, draw_target::DrawTarget, pixelcolor::Rgb565};
|
||||
use rand::Rng;
|
||||
use shared::keyboard::KeyEvent;
|
||||
|
||||
use crate::{
|
||||
@@ -23,10 +23,10 @@ pub extern "Rust" fn print(msg: &str) {
|
||||
|
||||
pub extern "Rust" fn sleep(ms: u64) {
|
||||
let cycles_per_ms = clk_sys_freq() / 1000;
|
||||
for _ in 0..ms {
|
||||
for _ in 0..cycles_per_ms {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
let total_cycles = ms * cycles_per_ms as u64;
|
||||
|
||||
for _ in 0..total_cycles {
|
||||
cortex_m::asm::nop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,3 +42,16 @@ pub extern "Rust" fn draw_iter(pixels: &[Pixel<Rgb565>]) {
|
||||
pub extern "Rust" fn get_key() -> Option<KeyEvent> {
|
||||
unsafe { KEY_CACHE.dequeue() }
|
||||
}
|
||||
|
||||
pub extern "Rust" fn gen_rand(req: &mut RngRequest) {
|
||||
let mut rng = RoscRng;
|
||||
|
||||
match req {
|
||||
RngRequest::U32(i) => *i = rng.next_u32(),
|
||||
RngRequest::U64(i) => *i = rng.next_u64(),
|
||||
RngRequest::Bytes { ptr, len } => {
|
||||
let slice: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(*ptr, *len) };
|
||||
rng.fill_bytes(slice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,6 @@ pub async fn display_handler(mut display: DISPLAY) {
|
||||
}
|
||||
}
|
||||
|
||||
Timer::after_millis(32).await; // 30 fps
|
||||
Timer::after_millis(10).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ pub async unsafe fn load_binary(name: &ShortFileName) -> Result<EntryFn, &str> {
|
||||
(CallAbiTable::LockDisplay, abi::lock_display as usize),
|
||||
(CallAbiTable::DrawIter, abi::draw_iter as usize),
|
||||
(CallAbiTable::GetKey, abi::get_key as usize),
|
||||
(CallAbiTable::GenRand, abi::gen_rand as usize),
|
||||
];
|
||||
assert!(entries.len() == CallAbiTable::COUNT);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user