implements PR014 a PR016

This commit is contained in:
2026-03-24 13:40:46 +00:00
parent a75df486ce
commit 24c81d27a9
24 changed files with 386 additions and 116 deletions
@@ -166,6 +166,7 @@ impl Audio {
}
}
#[allow(clippy::too_many_arguments)]
pub fn play(
&mut self,
bank_id: u8,
@@ -202,6 +203,7 @@ impl Audio {
// }
}
#[allow(clippy::too_many_arguments)]
pub fn play_sample(
&mut self,
sample: Arc<Sample>,
+1 -1
View File
@@ -857,7 +857,7 @@ impl Gfx {
for (row_idx, row) in glyph.iter().enumerate() {
for col_idx in 0..3 {
if (row >> (2 - col_idx)) & 1 == 1 {
let px = x + col_idx as i32;
let px = x + col_idx;
let py = y + row_idx as i32;
self.draw_pixel(px, py, color);
}
@@ -35,6 +35,12 @@ pub struct Hardware {
pub assets: AssetManager,
}
impl Default for Hardware {
fn default() -> Self {
Self::new()
}
}
impl HardwareBridge for Hardware {
fn gfx(&self) -> &dyn GfxBridge {
&self.gfx
@@ -40,6 +40,12 @@ pub struct MemoryBanks {
sound_bank_pool: Arc<RwLock<[Option<Arc<SoundBank>>; 16]>>,
}
impl Default for MemoryBanks {
fn default() -> Self {
Self::new()
}
}
impl MemoryBanks {
/// Creates a new set of memory banks with empty slots.
pub fn new() -> Self {
+2 -2
View File
@@ -12,8 +12,8 @@ impl Touch {
/// Transient flags should last only 1 frame.
pub fn begin_frame(&mut self, signals: &InputSignals) {
self.f.begin_frame(signals.f_signal);
self.x = signals.x_pos.clone();
self.y = signals.y_pos.clone();
self.x = signals.x_pos;
self.y = signals.y_pos;
}
}
@@ -1,11 +1,10 @@
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum BootTarget {
#[default]
Hub,
Cartridge { path: String, debug: bool, debug_port: u16 },
}
impl Default for BootTarget {
fn default() -> Self {
Self::Hub
}
Cartridge {
path: String,
debug: bool,
debug_port: u16,
},
}
@@ -1,4 +1,5 @@
mod boot_target;
#[allow(clippy::module_inception)]
mod firmware;
pub mod firmware_state;
@@ -1,3 +1,4 @@
#[allow(clippy::module_inception)]
mod prometeu_hub;
mod window_manager;
@@ -1,15 +1,21 @@
use crate::programs::prometeu_hub::window_manager::WindowManager;
use crate::VirtualMachineRuntime;
use crate::programs::prometeu_hub::window_manager::WindowManager;
use prometeu_hal::HardwareBridge;
use prometeu_hal::color::Color;
use prometeu_hal::log::{LogLevel, LogSource};
use prometeu_hal::window::Rect;
use prometeu_hal::HardwareBridge;
/// PrometeuHub: Launcher and system UI environment.
pub struct PrometeuHub {
pub window_manager: WindowManager,
}
impl Default for PrometeuHub {
fn default() -> Self {
Self::new()
}
}
impl PrometeuHub {
pub fn new() -> Self {
Self { window_manager: WindowManager::new() }
@@ -13,6 +13,12 @@ pub struct VirtualFS {
backend: Option<Box<dyn FsBackend>>,
}
impl Default for VirtualFS {
fn default() -> Self {
Self::new()
}
}
impl VirtualFS {
pub fn new() -> Self {
Self { backend: None }
@@ -103,8 +109,8 @@ impl VirtualFS {
mod tests {
use super::*;
use std::collections::HashMap;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Default)]
struct CallCounters {
@@ -1,6 +1,6 @@
use crate::fs::{FsBackend, FsState, VirtualFS};
use crate::CrashReport;
use prometeu_bytecode::{Value, TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_TYPE};
use crate::fs::{FsBackend, FsState, VirtualFS};
use prometeu_bytecode::{TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_TYPE, Value};
use prometeu_hal::asset::{BankType, LoadStatus, SlotRef};
use prometeu_hal::button::Button;
use prometeu_hal::cartridge::{AppMode, Cartridge};
@@ -11,8 +11,8 @@ use prometeu_hal::syscalls::Syscall;
use prometeu_hal::telemetry::{CertificationConfig, Certifier, TelemetryFrame};
use prometeu_hal::tile::Tile;
use prometeu_hal::vm_fault::VmFault;
use prometeu_hal::{expect_bool, expect_int, HostContext, HostReturn, NativeInterface, SyscallId};
use prometeu_hal::{HardwareBridge, InputSignals};
use prometeu_hal::{HostContext, HostReturn, NativeInterface, SyscallId, expect_bool, expect_int};
use prometeu_vm::{LogicalFrameEndingReason, VirtualMachine};
use std::collections::HashMap;
use std::time::Instant;
@@ -152,16 +152,14 @@ impl VirtualMachineRuntime {
}
fn update_fs(&mut self) {
if self.fs_state == FsState::Mounted {
if !self.fs.is_healthy() {
self.log(
LogLevel::Error,
LogSource::Fs,
0,
"Filesystem became unhealthy, unmounting".to_string(),
);
self.unmount_fs();
}
if self.fs_state == FsState::Mounted && !self.fs.is_healthy() {
self.log(
LogLevel::Error,
LogSource::Fs,
0,
"Filesystem became unhealthy, unmounting".to_string(),
);
self.unmount_fs();
}
}
@@ -652,7 +650,7 @@ impl NativeInterface for VirtualMachineRuntime {
// gfx.set_sprite(asset_name, id, x, y, tile_id, palette_id, active, flip_x, flip_y, priority)
Syscall::GfxSetSprite => {
let asset_name = match args
.get(0)
.first()
.ok_or_else(|| VmFault::Panic("Missing asset_name".into()))?
{
Value::String(s) => s.clone(),
@@ -942,7 +940,7 @@ impl NativeInterface for VirtualMachineRuntime {
// audio.play(asset_name, sample_id, voice_id, volume, pan, pitch, loop_mode)
Syscall::AudioPlay => {
let asset_name = match args
.get(0)
.first()
.ok_or_else(|| VmFault::Panic("Missing asset_name".into()))?
{
Value::String(s) => s.clone(),
@@ -978,10 +976,11 @@ impl NativeInterface for VirtualMachineRuntime {
// FS_OPEN(path) -> handle
Syscall::FsOpen => {
let path = match args.get(0).ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
let path =
match args.first().ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
if self.fs_state != FsState::Mounted {
ret.push_int(-1);
return Ok(());
@@ -1037,10 +1036,11 @@ impl NativeInterface for VirtualMachineRuntime {
}
// FS_LIST_DIR(path)
Syscall::FsListDir => {
let path = match args.get(0).ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
let path =
match args.first().ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
match self.fs.list_dir(&path) {
Ok(entries) => {
let names: Vec<String> = entries.into_iter().map(|e| e.name).collect();
@@ -1052,19 +1052,21 @@ impl NativeInterface for VirtualMachineRuntime {
}
// FS_EXISTS(path)
Syscall::FsExists => {
let path = match args.get(0).ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
let path =
match args.first().ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
ret.push_bool(self.fs.exists(&path));
Ok(())
}
// FS_DELETE(path)
Syscall::FsDelete => {
let path = match args.get(0).ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
let path =
match args.first().ok_or_else(|| VmFault::Panic("Missing path".into()))? {
Value::String(s) => s.clone(),
_ => return Err(VmFault::Trap(TRAP_TYPE, "Expected string path".into())),
};
match self.fs.delete(&path) {
Ok(_) => ret.push_bool(true),
Err(_) => ret.push_bool(false),
@@ -1107,7 +1109,7 @@ impl NativeInterface for VirtualMachineRuntime {
// --- Asset Syscalls ---
Syscall::AssetLoad => {
let asset_id = match args
.get(0)
.first()
.ok_or_else(|| VmFault::Panic("Missing asset_id".into()))?
{
Value::String(s) => s.clone(),
@@ -1190,13 +1192,13 @@ impl NativeInterface for VirtualMachineRuntime {
#[cfg(test)]
mod tests {
use super::*;
use prometeu_bytecode::TRAP_TYPE;
use prometeu_bytecode::assembler::assemble;
use prometeu_bytecode::model::{BytecodeModule, FunctionMeta, SyscallDecl};
use prometeu_bytecode::TRAP_TYPE;
use prometeu_drivers::hardware::Hardware;
use prometeu_hal::InputSignals;
use prometeu_hal::cartridge::Cartridge;
use prometeu_hal::syscalls::caps;
use prometeu_hal::InputSignals;
use prometeu_vm::VmInitError;
fn cartridge_with_program(program: Vec<u8>, capabilities: u64) -> Cartridge {
@@ -2,20 +2,20 @@ use crate::call_frame::CallFrame;
use crate::heap::{CoroutineState, Heap};
use crate::lookup_intrinsic_by_id;
use crate::object::ObjectKind;
use crate::roots::{visit_value_for_roots, RootVisitor};
use crate::roots::{RootVisitor, visit_value_for_roots};
use crate::scheduler::Scheduler;
use crate::verifier::Verifier;
use crate::vm_init_error::{LoaderPatchError, VmInitError};
use crate::{HostContext, NativeInterface};
use prometeu_bytecode::decode_next;
use prometeu_bytecode::isa::core::CoreOpCode as OpCode;
use prometeu_bytecode::model::BytecodeModule;
use prometeu_bytecode::HeapRef;
use prometeu_bytecode::ProgramImage;
use prometeu_bytecode::Value;
use prometeu_bytecode::decode_next;
use prometeu_bytecode::isa::core::CoreOpCode as OpCode;
use prometeu_bytecode::model::BytecodeModule;
use prometeu_bytecode::{
TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_EXPLICIT, TRAP_INVALID_FUNC,
TRAP_INVALID_INTRINSIC, TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE,
TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_EXPLICIT, TRAP_INVALID_FUNC, TRAP_INVALID_INTRINSIC,
TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE, TrapInfo,
};
use prometeu_hal::syscalls::caps::NONE;
use prometeu_hal::vm_fault::VmFault;
@@ -1369,7 +1369,7 @@ impl VirtualMachine {
// Copy return values (preserving order: pop return_slots values, then reverse to push back)
let mut return_vals = Vec::with_capacity(return_slots);
for _ in 0..return_slots {
return_vals.push(self.pop().map_err(|e| LogicalFrameEndingReason::Panic(e))?);
return_vals.push(self.pop().map_err(LogicalFrameEndingReason::Panic)?);
}
return_vals.reverse();
@@ -1799,8 +1799,8 @@ mod tests {
use crate::HostReturn;
use prometeu_bytecode::model::{BytecodeModule, SyscallDecl};
use prometeu_bytecode::{
assemble, disassemble, FunctionMeta, TRAP_EXPLICIT, TRAP_INVALID_LOCAL, TRAP_OOB,
TRAP_STACK_UNDERFLOW, TRAP_TYPE,
FunctionMeta, TRAP_EXPLICIT, TRAP_INVALID_LOCAL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE,
assemble, disassemble,
};
use prometeu_hal::expect_int;