implements PLN-0155
This commit is contained in:
@@ -9,7 +9,6 @@ use prometeu_hal::log::LogSource;
|
||||
use prometeu_hal::telemetry::CertificationConfig;
|
||||
use prometeu_hal::{InputSignals, RuntimePlatform};
|
||||
use prometeu_system::{PrometeuHub, ResidentGameState, SystemOS};
|
||||
use prometeu_vm::VirtualMachine;
|
||||
|
||||
/// PROMETEU Firmware.
|
||||
///
|
||||
@@ -27,8 +26,6 @@ use prometeu_vm::VirtualMachine;
|
||||
/// 2. Delegates the logic update to the current active state.
|
||||
/// 3. Handles state transitions (e.g., from Loading to Playing).
|
||||
pub struct Firmware {
|
||||
/// The execution engine (PVM) for user applications.
|
||||
pub vm: VirtualMachine,
|
||||
/// The underlying OS services (Syscalls, Filesystem, Telemetry).
|
||||
pub os: SystemOS,
|
||||
/// The internal state of the system launcher (Hub).
|
||||
@@ -46,7 +43,6 @@ impl Firmware {
|
||||
/// Initializes the firmware in the `Reset` state.
|
||||
pub fn new(cap_config: Option<CertificationConfig>) -> Self {
|
||||
Self {
|
||||
vm: VirtualMachine::default(),
|
||||
os: SystemOS::new(cap_config),
|
||||
hub: PrometeuHub::new(),
|
||||
state: FirmwareState::Reset(ResetStep),
|
||||
@@ -122,7 +118,6 @@ impl Firmware {
|
||||
/// Dispatches the `on_enter` event to the current state implementation.
|
||||
fn on_enter(&mut self, signals: &InputSignals, platform: &mut dyn RuntimePlatform) {
|
||||
let mut req = PrometeuContext {
|
||||
vm: &mut self.vm,
|
||||
os: &mut self.os,
|
||||
hub: &mut self.hub,
|
||||
boot_target: &self.boot_target,
|
||||
@@ -150,7 +145,6 @@ impl Firmware {
|
||||
platform: &mut dyn RuntimePlatform,
|
||||
) -> Option<FirmwareState> {
|
||||
let mut req = PrometeuContext {
|
||||
vm: &mut self.vm,
|
||||
os: &mut self.os,
|
||||
hub: &mut self.hub,
|
||||
boot_target: &self.boot_target,
|
||||
@@ -173,7 +167,6 @@ impl Firmware {
|
||||
/// Dispatches the `on_exit` event to the current state implementation.
|
||||
fn on_exit(&mut self, signals: &InputSignals, platform: &mut dyn RuntimePlatform) {
|
||||
let mut req = PrometeuContext {
|
||||
vm: &mut self.vm,
|
||||
os: &mut self.os,
|
||||
hub: &mut self.hub,
|
||||
boot_target: &self.boot_target,
|
||||
@@ -532,6 +525,24 @@ mod tests {
|
||||
assert!(matches!(firmware.state, FirmwareState::LaunchHub(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_clears_vm_sessions_and_runtime_identity() {
|
||||
let mut firmware = Firmware::new(None);
|
||||
let mut platform = TestPlatform::new();
|
||||
let signals = InputSignals::default();
|
||||
|
||||
firmware.load_cartridge(valid_cartridge(AppMode::Game));
|
||||
firmware.tick(&signals, &mut platform);
|
||||
|
||||
assert_eq!(firmware.os.sessions().vm_session_count(), 1);
|
||||
assert_eq!(firmware.os.vm().current_cartridge_title(), "Valid Cart");
|
||||
|
||||
firmware.change_state(FirmwareState::Reset(ResetStep), &signals, &mut platform);
|
||||
|
||||
assert_eq!(firmware.os.sessions().vm_session_count(), 0);
|
||||
assert_eq!(firmware.os.vm().current_cartridge_title(), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_cartridge_routes_system_apps_to_system_running() {
|
||||
let mut firmware = Firmware::new(None);
|
||||
|
||||
@@ -20,7 +20,7 @@ impl HubHomeStep {
|
||||
}
|
||||
|
||||
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
||||
let outcome = ctx.hub.update_shell_profile(ctx.os, ctx.vm, ctx.signals, ctx.platform);
|
||||
let outcome = ctx.hub.update_shell_profile(ctx.os, ctx.platform);
|
||||
if let Some(report) = outcome.crash {
|
||||
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl LoadCartridgeStep {
|
||||
self.cartridge.assets.clone(),
|
||||
);
|
||||
|
||||
match ctx.os.sessions().load_vm_cartridge(ctx.vm, &self.cartridge) {
|
||||
match ctx.os.sessions().load_vm_cartridge(&self.cartridge) {
|
||||
Ok(loaded) => {
|
||||
self.loaded_task_id = Some(loaded.task_id);
|
||||
self.loaded_app_mode = Some(loaded.app_mode);
|
||||
|
||||
@@ -9,7 +9,8 @@ pub struct ResetStep;
|
||||
impl ResetStep {
|
||||
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
||||
ctx.os.log(LogLevel::Info, LogSource::Pos, 0, "Firmware Reset".to_string());
|
||||
ctx.os.vm().reset(ctx.vm);
|
||||
ctx.os.sessions().clear_vm_sessions();
|
||||
ctx.os.vm().reset_global_runtime_state();
|
||||
}
|
||||
|
||||
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use crate::firmware::boot_target::BootTarget;
|
||||
use prometeu_hal::{InputSignals, RuntimePlatform};
|
||||
use prometeu_system::{PrometeuHub, SystemOS};
|
||||
use prometeu_vm::VirtualMachine;
|
||||
|
||||
pub struct PrometeuContext<'a> {
|
||||
pub vm: &'a mut VirtualMachine,
|
||||
pub os: &'a mut SystemOS,
|
||||
pub hub: &'a mut PrometeuHub,
|
||||
pub boot_target: &'a BootTarget,
|
||||
|
||||
Reference in New Issue
Block a user