This commit is contained in:
Nilton Constantino
2026-01-31 01:18:42 +00:00
parent ef8b7b524a
commit 180c7e19e0
8 changed files with 242 additions and 28 deletions
@@ -37,6 +37,8 @@ pub enum Syscall {
GfxSetSprite = 0x1007,
/// Draws a text string at the specified coordinates.
GfxDrawText = 0x1008,
/// Fills the entire back buffer with a single RGB565 color (flattened).
GfxClear565 = 0x1010,
// --- Input ---
/// Returns the current raw state of the digital gamepad (bitmask).
@@ -47,6 +49,10 @@ pub enum Syscall {
InputGetPadReleased = 0x2003,
/// Returns how many frames a button has been held down.
InputGetPadHold = 0x2004,
/// Returns the full snapshot of the gamepad state (48 slots).
InputPadSnapshot = 0x2010,
/// Returns the full snapshot of the touch state (6 slots).
InputTouchSnapshot = 0x2011,
/// Returns the X coordinate of the touch/mouse pointer.
TouchGetX = 0x2101,
@@ -119,10 +125,13 @@ impl Syscall {
0x1006 => Some(Self::GfxDrawSquare),
0x1007 => Some(Self::GfxSetSprite),
0x1008 => Some(Self::GfxDrawText),
0x1010 => Some(Self::GfxClear565),
0x2001 => Some(Self::InputGetPad),
0x2002 => Some(Self::InputGetPadPressed),
0x2003 => Some(Self::InputGetPadReleased),
0x2004 => Some(Self::InputGetPadHold),
0x2010 => Some(Self::InputPadSnapshot),
0x2011 => Some(Self::InputTouchSnapshot),
0x2101 => Some(Self::TouchGetX),
0x2102 => Some(Self::TouchGetY),
0x2103 => Some(Self::TouchIsDown),
@@ -162,10 +171,13 @@ impl Syscall {
Self::GfxDrawSquare => 6,
Self::GfxSetSprite => 10,
Self::GfxDrawText => 4,
Self::GfxClear565 => 1,
Self::InputGetPad => 1,
Self::InputGetPadPressed => 1,
Self::InputGetPadReleased => 1,
Self::InputGetPadHold => 1,
Self::InputPadSnapshot => 0,
Self::InputTouchSnapshot => 0,
Self::TouchGetX => 0,
Self::TouchGetY => 0,
Self::TouchIsDown => 0,
@@ -5,7 +5,7 @@ use crate::virtual_machine::value::Value;
use crate::virtual_machine::{NativeInterface, Program};
use prometeu_bytecode::opcode::OpCode;
use prometeu_bytecode::pbc::{self, ConstantPoolEntry};
use prometeu_bytecode::abi::TrapInfo;
use prometeu_bytecode::abi::{TrapInfo, TRAP_OOB};
/// Reason why the Virtual Machine stopped execution during a specific run.
/// This allows the system to decide if it should continue execution in the next tick
@@ -329,6 +329,18 @@ impl VirtualMachine {
let val = self.read_i32().map_err(|e| LogicalFrameEndingReason::Panic(e))?;
self.push(Value::Int32(val));
}
OpCode::PushBounded => {
let val = self.read_u32().map_err(|e| LogicalFrameEndingReason::Panic(e))?;
if val > 0xFFFF {
return Err(LogicalFrameEndingReason::Trap(TrapInfo {
code: TRAP_OOB,
opcode: opcode as u16,
message: format!("Bounded value overflow: {} > 0xFFFF", val),
pc: start_pc as u32,
}));
}
self.push(Value::Bounded(val));
}
OpCode::PushF64 => {
let val = self.read_f64().map_err(|e| LogicalFrameEndingReason::Panic(e))?;
self.push(Value::Float(val));