implements PLN-0068

This commit is contained in:
2026-05-23 19:19:28 +01:00
parent 1256d33a72
commit 668a061964
12 changed files with 121 additions and 121 deletions
@@ -95,8 +95,10 @@ impl VmRuntimeHost<'_> {
Ok(())
}
pub(crate) fn get_color(&self, value: i64) -> Color {
Color::from_raw(value as u16)
pub(crate) fn get_color(&self, value: i64) -> Result<Color, VmFault> {
let raw = u32::try_from(value)
.map_err(|_| VmFault::Trap(TRAP_OOB, "Color value out of bounds".into()))?;
Ok(Color::from_raw(raw))
}
fn int_arg_to_usize_status(value: i64) -> Result<usize, ComposerOpStatus> {
@@ -126,7 +128,6 @@ impl VmRuntimeHost<'_> {
| Syscall::GfxDrawDisc
| Syscall::GfxDrawSquare
| Syscall::GfxDrawText
| Syscall::GfxClear565
| Syscall::ComposerBindScene
| Syscall::ComposerUnbindScene
| Syscall::ComposerSetCamera
@@ -183,7 +184,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
Syscall::SystemHasCart => unreachable!(),
Syscall::SystemRunCart => unreachable!(),
Syscall::GfxClear => {
let color = self.get_color(expect_int(args, 0)?);
let color = self.get_color(expect_int(args, 0)?)?;
hw.gfx_mut().clear(color);
Ok(())
}
@@ -192,7 +193,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
let y = expect_int(args, 1)? as i32;
let w = expect_int(args, 2)? as i32;
let h = expect_int(args, 3)? as i32;
let color = self.get_color(expect_int(args, 4)?);
let color = self.get_color(expect_int(args, 4)?)?;
hw.gfx_mut().fill_rect(x, y, w, h, color);
Ok(())
}
@@ -201,7 +202,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
let y1 = expect_int(args, 1)? as i32;
let x2 = expect_int(args, 2)? as i32;
let y2 = expect_int(args, 3)? as i32;
let color = self.get_color(expect_int(args, 4)?);
let color = self.get_color(expect_int(args, 4)?)?;
hw.gfx_mut().draw_line(x1, y1, x2, y2, color);
Ok(())
}
@@ -209,7 +210,7 @@ impl NativeInterface for VmRuntimeHost<'_> {
let x = expect_int(args, 0)? as i32;
let y = expect_int(args, 1)? as i32;
let r = expect_int(args, 2)? as i32;
let color = self.get_color(expect_int(args, 3)?);
let color = self.get_color(expect_int(args, 3)?)?;
hw.gfx_mut().draw_circle(x, y, r, color);
Ok(())
}
@@ -217,8 +218,8 @@ impl NativeInterface for VmRuntimeHost<'_> {
let x = expect_int(args, 0)? as i32;
let y = expect_int(args, 1)? as i32;
let r = expect_int(args, 2)? as i32;
let border_color = self.get_color(expect_int(args, 3)?);
let fill_color = self.get_color(expect_int(args, 4)?);
let border_color = self.get_color(expect_int(args, 3)?)?;
let fill_color = self.get_color(expect_int(args, 4)?)?;
hw.gfx_mut().draw_disc(x, y, r, border_color, fill_color);
Ok(())
}
@@ -227,8 +228,8 @@ impl NativeInterface for VmRuntimeHost<'_> {
let y = expect_int(args, 1)? as i32;
let w = expect_int(args, 2)? as i32;
let h = expect_int(args, 3)? as i32;
let border_color = self.get_color(expect_int(args, 4)?);
let fill_color = self.get_color(expect_int(args, 5)?);
let border_color = self.get_color(expect_int(args, 4)?)?;
let fill_color = self.get_color(expect_int(args, 5)?)?;
hw.gfx_mut().draw_square(x, y, w, h, border_color, fill_color);
Ok(())
}
@@ -236,18 +237,10 @@ impl NativeInterface for VmRuntimeHost<'_> {
let x = expect_int(args, 0)? as i32;
let y = expect_int(args, 1)? as i32;
let msg = expect_string(args, 2, "message")?;
let color = self.get_color(expect_int(args, 3)?);
let color = self.get_color(expect_int(args, 3)?)?;
hw.gfx_mut().draw_text(x, y, &msg, color);
Ok(())
}
Syscall::GfxClear565 => {
let color_val = expect_int(args, 0)? as u32;
if color_val > 0xFFFF {
return Err(VmFault::Trap(TRAP_OOB, "Color value out of bounds".into()));
}
hw.gfx_mut().clear(Color::from_raw(color_val as u16));
Ok(())
}
Syscall::ComposerBindScene => {
let scene_bank_id = match Self::int_arg_to_usize_status(expect_int(args, 0)?) {
Ok(id) => id,