This commit is contained in:
2026-03-24 13:40:24 +00:00
parent d6bbef06a5
commit eb3156dd8c
21 changed files with 86 additions and 181 deletions
+1
View File
@@ -8,6 +8,7 @@ license.workspace = true
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
prometeu-vm = { path = "../prometeu-vm" }
prometeu-kernel = { path = "../prometeu-kernel" }
prometeu-bytecode = { path = "../prometeu-bytecode" }
prometeu-abi = { path = "../prometeu-abi" }
prometeu-hardware-contract = { path = "../prometeu-hardware-contract" }
-12
View File
@@ -1,12 +0,0 @@
use crate::fs::{FsEntry, FsError};
pub trait FsBackend: Send + Sync {
fn mount(&mut self) -> Result<(), FsError>;
fn unmount(&mut self);
fn list_dir(&self, path: &str) -> Result<Vec<FsEntry>, FsError>;
fn read_file(&self, path: &str) -> Result<Vec<u8>, FsError>;
fn write_file(&mut self, path: &str, data: &[u8]) -> Result<(), FsError>;
fn delete(&mut self, path: &str) -> Result<(), FsError>;
fn exists(&self, path: &str) -> bool;
fn is_healthy(&self) -> bool { true }
}
-5
View File
@@ -1,5 +0,0 @@
pub struct FsEntry {
pub name: String,
pub is_dir: bool,
pub size: u64,
}
-24
View File
@@ -1,24 +0,0 @@
use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum FsError {
NotFound,
AlreadyExists,
PermissionDenied,
NotMounted,
IOError(String),
Other(String),
}
impl fmt::Display for FsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
FsError::NotFound => write!(f, "File or directory not found"),
FsError::AlreadyExists => write!(f, "Already exists"),
FsError::PermissionDenied => write!(f, "Permission denied"),
FsError::NotMounted => write!(f, "Filesystem not mounted"),
FsError::IOError(s) => write!(f, "IO Error: {}", s),
FsError::Other(s) => write!(f, "Error: {}", s),
}
}
}
-8
View File
@@ -1,8 +0,0 @@
use crate::fs::FsError;
#[derive(Debug, Clone, PartialEq)]
pub enum FsState {
Unmounted,
Mounted,
Error(FsError),
}
-11
View File
@@ -1,11 +0,0 @@
mod fs_error;
mod fs_state;
mod fs_entry;
mod fs_backend;
mod virtual_fs;
pub use fs_backend::FsBackend;
pub use fs_entry::FsEntry;
pub use fs_error::FsError;
pub use fs_state::FsState;
pub use virtual_fs::VirtualFS;
-156
View File
@@ -1,156 +0,0 @@
use crate::fs::{FsBackend, FsEntry, FsError};
/// Virtual Filesystem (VFS) interface for Prometeu.
///
/// The VFS provides a sandboxed, unified path interface for user applications.
/// Instead of interacting directly with the host's disk, the VM uses
/// normalized paths (e.g., `/user/save.dat`).
///
/// The actual storage is provided by an `FsBackend`, which can be a real
/// directory on disk, an in-memory map, or even a network resource.
pub struct VirtualFS {
/// The active storage implementation.
backend: Option<Box<dyn FsBackend>>,
}
impl VirtualFS {
pub fn new() -> Self {
Self { backend: None }
}
pub fn mount(&mut self, mut backend: Box<dyn FsBackend>) -> Result<(), FsError> {
backend.mount()?;
self.backend = Some(backend);
Ok(())
}
pub fn unmount(&mut self) {
if let Some(mut backend) = self.backend.take() {
backend.unmount();
}
}
pub fn is_mounted(&self) -> bool {
self.backend.is_some()
}
fn normalize_path(&self, path: &str) -> String {
let mut normalized = path.replace('\\', "/");
if !normalized.starts_with('/') {
normalized = format!("/{}", normalized);
}
normalized
}
pub fn list_dir(&self, path: &str) -> Result<Vec<FsEntry>, FsError> {
let normalized = self.normalize_path(path);
let backend = self.backend.as_ref().ok_or(FsError::NotMounted)?;
backend.list_dir(&normalized)
}
pub fn read_file(&self, path: &str) -> Result<Vec<u8>, FsError> {
let normalized = self.normalize_path(path);
let backend = self.backend.as_ref().ok_or(FsError::NotMounted)?;
backend.read_file(&normalized)
}
pub fn write_file(&mut self, path: &str, data: &[u8]) -> Result<(), FsError> {
let normalized = self.normalize_path(path);
let backend = self.backend.as_mut().ok_or(FsError::NotMounted)?;
backend.write_file(&normalized, data)
}
pub fn delete(&mut self, path: &str) -> Result<(), FsError> {
let normalized = self.normalize_path(path);
let backend = self.backend.as_mut().ok_or(FsError::NotMounted)?;
backend.delete(&normalized)
}
pub fn exists(&self, path: &str) -> bool {
let normalized = self.normalize_path(path);
self.backend.as_ref().map(|b| b.exists(&normalized)).unwrap_or(false)
}
pub fn is_healthy(&self) -> bool {
self.backend.as_ref().map(|b| b.is_healthy()).unwrap_or(false)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::collections::HashMap;
struct MockBackend {
files: HashMap<String, Vec<u8>>,
healthy: bool,
}
impl MockBackend {
fn new() -> Self {
Self {
files: HashMap::new(),
healthy: true,
}
}
}
impl FsBackend for MockBackend {
fn mount(&mut self) -> Result<(), FsError> { Ok(()) }
fn unmount(&mut self) {}
fn list_dir(&self, _path: &str) -> Result<Vec<FsEntry>, FsError> {
Ok(self.files.keys().map(|name| FsEntry {
name: name.clone(),
is_dir: false,
size: 0,
}).collect())
}
fn read_file(&self, path: &str) -> Result<Vec<u8>, FsError> {
self.files.get(path).cloned().ok_or(FsError::NotFound)
}
fn write_file(&mut self, path: &str, data: &[u8]) -> Result<(), FsError> {
self.files.insert(path.to_string(), data.to_vec());
Ok(())
}
fn delete(&mut self, path: &str) -> Result<(), FsError> {
self.files.remove(path);
Ok(())
}
fn exists(&self, path: &str) -> bool {
self.files.contains_key(path)
}
fn is_healthy(&self) -> bool {
self.healthy
}
}
#[test]
fn test_virtual_fs_operations() {
let mut vfs = VirtualFS::new();
let backend = MockBackend::new();
vfs.mount(Box::new(backend)).unwrap();
let test_file = "/user/test.txt";
let content = b"hello world";
vfs.write_file(test_file, content).unwrap();
assert!(vfs.exists(test_file));
let read_content = vfs.read_file(test_file).unwrap();
assert_eq!(read_content, content);
vfs.delete(test_file).unwrap();
assert!(!vfs.exists(test_file));
}
#[test]
fn test_virtual_fs_health() {
let mut vfs = VirtualFS::new();
let mut backend = MockBackend::new();
backend.healthy = false;
vfs.mount(Box::new(backend)).unwrap();
assert!(!vfs.is_healthy());
}
}
+2 -14
View File
@@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex, RwLock};
use std::thread;
use std::time::Instant;
use prometeu_hardware_contract::AssetBridge;
/// Resident metadata for a decoded/materialized asset inside a BankPolicy.
#[derive(Debug)]
@@ -93,19 +94,6 @@ impl<T> BankPolicy<T> {
}
}
pub trait AssetBridge {
fn initialize_for_cartridge(&self, assets: Vec<AssetEntry>, preload: Vec<PreloadEntry>, assets_data: Vec<u8>);
fn load(&self, asset_name: &str, slot: SlotRef) -> Result<HandleId, String>;
fn status(&self, handle: HandleId) -> LoadStatus;
fn commit(&self, handle: HandleId);
fn cancel(&self, handle: HandleId);
fn apply_commits(&self);
fn bank_info(&self, kind: BankType) -> BankStats;
fn slot_info(&self, slot: SlotRef) -> SlotStats;
fn find_slot_by_name(&self, asset_name: &str, kind: BankType) -> Option<u8>;
fn shutdown(&self);
}
pub struct AssetManager {
assets: Arc<RwLock<HashMap<u32, AssetEntry>>>,
name_to_id: Arc<RwLock<HashMap<String, u32>>>,
@@ -136,7 +124,7 @@ struct LoadHandleInfo {
status: LoadStatus,
}
impl prometeu_hardware_contract::AssetBridge for AssetManager {
impl AssetBridge for AssetManager {
fn initialize_for_cartridge(&self, assets: Vec<AssetEntry>, preload: Vec<PreloadEntry>, assets_data: Vec<u8>) { self.initialize_for_cartridge(assets, preload, assets_data) }
fn load(&self, asset_name: &str, slot: SlotRef) -> Result<HandleId, String> { self.load(asset_name, slot) }
fn status(&self, handle: HandleId) -> LoadStatus { self.status(handle) }
+2 -12
View File
@@ -1,6 +1,7 @@
use crate::hardware::memory_banks::SoundBankPoolAccess;
use crate::model::Sample;
use std::sync::Arc;
use prometeu_hardware_contract::AudioBridge;
/// Maximum number of simultaneous audio voices supported by the hardware.
pub const MAX_CHANNELS: usize = 16;
@@ -101,17 +102,6 @@ pub enum AudioCommand {
/// - **16 Simultaneous Voices**: Independent volume, pan, and pitch.
/// - **Sample-based Synthesis**: Plays PCM data stored in SoundBanks.
/// - **Stereo Output**: 48kHz output target.
pub trait AudioBridge {
fn play(&mut self, bank_id: u8, sample_id: u16, voice_id: usize, volume: u8, pan: u8, pitch: f64, priority: u8, loop_mode: LoopMode) -> ();
fn play_sample(&mut self, sample: Arc<Sample>, voice_id: usize, volume: u8, pan: u8, pitch: f64, priority: u8, loop_mode: LoopMode) -> ();
fn stop(&mut self, voice_id: usize) -> ();
fn set_volume(&mut self, voice_id: usize, volume: u8) -> ();
fn set_pan(&mut self, voice_id: usize, pan: u8) -> ();
fn set_pitch(&mut self, voice_id: usize, pitch: f64) -> ();
fn is_playing(&self, voice_id: usize) -> bool;
fn clear_commands(&mut self) -> ();
}
pub struct Audio {
/// Local state of the hardware voices. This state is used for logic
/// (e.g., checking if a sound is still playing) and is synchronized with the Host.
@@ -123,7 +113,7 @@ pub struct Audio {
pub sound_banks: Arc<dyn SoundBankPoolAccess>,
}
impl prometeu_hardware_contract::AudioBridge for Audio {
impl AudioBridge for Audio {
fn play(&mut self, bank_id: u8, sample_id: u16, voice_id: usize, volume: u8, pan: u8, pitch: f64, priority: u8, loop_mode: prometeu_hardware_contract::LoopMode) {
let lm = match loop_mode { prometeu_hardware_contract::LoopMode::Off => LoopMode::Off, prometeu_hardware_contract::LoopMode::On => LoopMode::On };
self.play(bank_id, sample_id, voice_id, volume, pan, pitch, priority, lm)
+2 -42
View File
@@ -1,6 +1,7 @@
use crate::hardware::memory_banks::TileBankPoolAccess;
use crate::model::{Color, HudTileLayer, ScrollableTileLayer, Sprite, TileBank, TileMap, TileSize};
use std::sync::Arc;
use prometeu_hardware_contract::GfxBridge;
/// Blending modes inspired by classic 16-bit hardware.
/// Defines how source pixels are combined with existing pixels in the framebuffer.
@@ -41,47 +42,6 @@ pub enum BlendMode {
/// 6. **Scene Fade**: Global brightness/color filter.
/// 7. **HUD Layer**: Fixed UI elements (always on top).
/// 8. **HUD Fade**: Independent fade for the UI.
pub trait GfxBridge {
fn size(&self) -> (usize, usize);
fn front_buffer(&self) -> &[u16];
fn clear(&mut self, color: Color) -> ();
fn fill_rect_blend(&mut self, x: i32, y: i32, w: i32, h: i32, color: Color, mode: BlendMode) -> ();
fn fill_rect(&mut self, x: i32, y: i32, w: i32, h: i32, color: Color) -> ();
fn draw_pixel(&mut self, x: i32, y: i32, color: Color) -> ();
fn draw_line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, color: Color) -> ();
fn draw_circle(&mut self, xc: i32, yc: i32, r: i32, color: Color) -> ();
fn draw_circle_points(&mut self, xc: i32, yc: i32, x: i32, y: i32, color: Color) -> ();
fn fill_circle(&mut self, xc: i32, yc: i32, r: i32, color: Color) -> ();
fn draw_circle_lines(&mut self, xc: i32, yc: i32, x: i32, y: i32, color: Color) -> ();
fn draw_disc(&mut self, x: i32, y: i32, r: i32, border_color: Color, fill_color: Color) -> ();
fn draw_rect(&mut self, x: i32, y: i32, w: i32, h: i32, color: Color) -> ();
fn draw_square(&mut self, x: i32, y: i32, w: i32, h: i32, border_color: Color, fill_color: Color) -> ();
fn draw_horizontal_line(&mut self, x0: i32, x1: i32, y: i32, color: Color) -> ();
fn draw_vertical_line(&mut self, x: i32, y0: i32, y1: i32, color: Color) -> ();
fn present(&mut self) -> ();
fn render_all(&mut self) -> ();
fn render_layer(&mut self, layer_idx: usize) -> ();
fn render_hud(&mut self) -> ();
fn draw_text(&mut self, x: i32, y: i32, text: &str, color: Color) -> ();
fn draw_char(&mut self, x: i32, y: i32, c: char, color: Color) -> ();
fn layer(&self, index: usize) -> &ScrollableTileLayer;
fn layer_mut(&mut self, index: usize) -> &mut ScrollableTileLayer;
fn hud(&self) -> &HudTileLayer;
fn hud_mut(&mut self) -> &mut HudTileLayer;
fn sprite(&self, index: usize) -> &Sprite;
fn sprite_mut(&mut self, index: usize) -> &mut Sprite;
fn scene_fade_level(&self) -> u8;
fn set_scene_fade_level(&mut self, level: u8);
fn scene_fade_color(&self) -> Color;
fn set_scene_fade_color(&mut self, color: Color);
fn hud_fade_level(&self) -> u8;
fn set_hud_fade_level(&mut self, level: u8);
fn hud_fade_color(&self) -> Color;
fn set_hud_fade_color(&mut self, color: Color);
}
pub struct Gfx {
/// Width of the internal framebuffer in pixels.
w: usize,
@@ -114,7 +74,7 @@ pub struct Gfx {
priority_buckets: [Vec<usize>; 5],
}
impl prometeu_hardware_contract::GfxBridge for Gfx {
impl GfxBridge for Gfx {
fn size(&self) -> (usize, usize) { self.size() }
fn front_buffer(&self) -> &[u16] { self.front_buffer() }
fn clear(&mut self, color: Color) { self.clear(color) }
@@ -1,26 +0,0 @@
#[derive(Default, Clone, Copy, Debug)]
pub struct InputSignals {
// PAD
pub up_signal: bool,
pub down_signal: bool,
pub left_signal: bool,
pub right_signal: bool,
pub a_signal: bool,
pub b_signal: bool,
pub x_signal: bool,
pub y_signal: bool,
pub l_signal: bool,
pub r_signal: bool,
pub start_signal: bool,
pub select_signal: bool,
// TOUCH
pub f_signal: bool,
pub x_pos: i32,
pub y_pos: i32,
}
impl InputSignals {
}
+2 -19
View File
@@ -1,24 +1,7 @@
use prometeu_hardware_contract::PadBridge;
use crate::hardware::InputSignals;
use crate::model::Button;
pub trait PadBridge {
fn begin_frame(&mut self, signals: &InputSignals);
fn any(&self) -> bool;
fn up(&self) -> &Button;
fn down(&self) -> &Button;
fn left(&self) -> &Button;
fn right(&self) -> &Button;
fn a(&self) -> &Button;
fn b(&self) -> &Button;
fn x(&self) -> &Button;
fn y(&self) -> &Button;
fn l(&self) -> &Button;
fn r(&self) -> &Button;
fn start(&self) -> &Button;
fn select(&self) -> &Button;
}
#[derive(Default, Clone, Copy, Debug)]
pub struct Pad {
pub up: Button,
@@ -37,7 +20,7 @@ pub struct Pad {
pub select: Button,
}
impl prometeu_hardware_contract::PadBridge for Pad {
impl PadBridge for Pad {
fn begin_frame(&mut self, signals: &InputSignals) { self.begin_frame(signals) }
fn any(&self) -> bool { self.any() }
+2 -8
View File
@@ -1,13 +1,7 @@
use prometeu_hardware_contract::TouchBridge;
use crate::hardware::InputSignals;
use crate::model::Button;
pub trait TouchBridge {
fn begin_frame(&mut self, signals: &InputSignals);
fn f(&self) -> &Button;
fn x(&self) -> i32;
fn y(&self) -> i32;
}
#[derive(Default, Clone, Copy, Debug)]
pub struct Touch {
pub f: Button,
@@ -15,7 +9,7 @@ pub struct Touch {
pub y: i32,
}
impl prometeu_hardware_contract::TouchBridge for Touch {
impl TouchBridge for Touch {
fn begin_frame(&mut self, signals: &InputSignals) { self.begin_frame(signals) }
fn f(&self) -> &Button { &self.f }
fn x(&self) -> i32 { self.x }
+10 -2
View File
@@ -17,10 +17,18 @@
pub mod hardware;
pub mod firmware;
pub mod fs;
pub mod prometeu_os;
// pub mod fs;
// pub mod prometeu_os;
mod prometeu_hub;
pub mod fs {
pub use prometeu_kernel::fs::*;
}
pub mod prometeu_os {
pub use prometeu_kernel::*;
}
// Facade/reexports for ABI modules (temporary during PR-00.x)
pub use prometeu_abi as abi;
pub use prometeu_abi::debugger_protocol;
@@ -1,3 +0,0 @@
mod prometeu_os;
pub use prometeu_os::PrometeuOS;
File diff suppressed because it is too large Load Diff