This commit is contained in:
Nilton Constantino
2026-01-31 01:33:19 +00:00
parent 180c7e19e0
commit adcb34826c
12 changed files with 191 additions and 202 deletions
@@ -710,6 +710,55 @@ mod tests {
_ => panic!("Expected Trap"),
}
}
#[test]
fn test_gfx_clear565_syscall() {
let mut hw = crate::Hardware::new();
let mut os = PrometeuOS::new(None);
let mut stack = Vec::new();
// Success case
let args = vec![Value::Bounded(0xF800)]; // Red
{
let mut ret = HostReturn::new(&mut stack);
os.syscall(Syscall::GfxClear565 as u32, &args, &mut ret, &mut hw).unwrap();
}
assert_eq!(stack.len(), 0); // void return
// OOB case
let args = vec![Value::Bounded(0x10000)];
{
let mut ret = HostReturn::new(&mut stack);
let res = os.syscall(Syscall::GfxClear565 as u32, &args, &mut ret, &mut hw);
assert!(res.is_err());
match res.err().unwrap() {
VmFault::Trap(trap, _) => assert_eq!(trap, prometeu_bytecode::abi::TRAP_OOB),
_ => panic!("Expected Trap OOB"),
}
}
}
#[test]
fn test_input_snapshots_syscalls() {
let mut hw = crate::Hardware::new();
let mut os = PrometeuOS::new(None);
// Pad snapshot
let mut stack = Vec::new();
{
let mut ret = HostReturn::new(&mut stack);
os.syscall(Syscall::InputPadSnapshot as u32, &[], &mut ret, &mut hw).unwrap();
}
assert_eq!(stack.len(), 48);
// Touch snapshot
let mut stack = Vec::new();
{
let mut ret = HostReturn::new(&mut stack);
os.syscall(Syscall::InputTouchSnapshot as u32, &[], &mut ret, &mut hw).unwrap();
}
assert_eq!(stack.len(), 6);
}
}
impl NativeInterface for PrometeuOS {
@@ -861,6 +910,17 @@ impl NativeInterface for PrometeuOS {
ret.push_null();
Ok(())
}
// gfx.clear565(color_u16) -> void
Syscall::GfxClear565 => {
let color_val = expect_int(args, 0)? as u32;
if color_val > 0xFFFF {
return Err(VmFault::Trap(prometeu_bytecode::abi::TRAP_OOB, "Color value out of bounds (bounded)".into()));
}
let color = Color::from_raw(color_val as u16);
hw.gfx_mut().clear(color);
// No return value for void
Ok(())
}
// --- Input Syscalls ---
@@ -914,6 +974,30 @@ impl NativeInterface for PrometeuOS {
ret.push_int(hw.touch().f.hold_frames as i64);
Ok(())
}
Syscall::InputPadSnapshot => {
let pad = hw.pad();
for btn in [
&pad.up, &pad.down, &pad.left, &pad.right,
&pad.a, &pad.b, &pad.x, &pad.y,
&pad.l, &pad.r, &pad.start, &pad.select,
] {
ret.push_bool(btn.pressed);
ret.push_bool(btn.released);
ret.push_bool(btn.down);
ret.push_int(btn.hold_frames as i64);
}
Ok(())
}
Syscall::InputTouchSnapshot => {
let touch = hw.touch();
ret.push_bool(touch.f.pressed);
ret.push_bool(touch.f.released);
ret.push_bool(touch.f.down);
ret.push_int(touch.f.hold_frames as i64);
ret.push_int(touch.x as i64);
ret.push_int(touch.y as i64);
Ok(())
}
// --- Audio Syscalls ---