clean up
This commit is contained in:
parent
b3a3c95f86
commit
8f45b04848
@ -20,59 +20,75 @@ impl Firmware {
|
||||
}
|
||||
|
||||
pub fn step_frame(&mut self, signals: &InputSignals, hw: &mut dyn HardwareBridge) {
|
||||
match &mut self.state {
|
||||
FirmwareState::Reset => {
|
||||
self.os.reset();
|
||||
self.state = FirmwareState::SplashScreen;
|
||||
}
|
||||
FirmwareState::SplashScreen => {
|
||||
// Splash logic opcional
|
||||
self.state = FirmwareState::LaunchHubHome;
|
||||
}
|
||||
FirmwareState::LaunchHubHome => {
|
||||
self.hub.init();
|
||||
self.state = FirmwareState::HubHome;
|
||||
}
|
||||
FirmwareState::HubHome => {
|
||||
hw.gfx_mut().clear(Color::INDIGO);
|
||||
self.hub.gui_update(&mut self.os);
|
||||
hw.gfx_mut().present();
|
||||
}
|
||||
FirmwareState::PosRunGame(_cart) => {
|
||||
if let Some(error) = self.os.step_frame(signals, hw) {
|
||||
self.state = FirmwareState::PosCrashScreen(error);
|
||||
}
|
||||
}
|
||||
FirmwareState::PosRunSystem(_cart) => {
|
||||
// System Apps rodam "dentro" do Hub/Window System
|
||||
if let Some(error) = self.os.step_frame(signals, hw) {
|
||||
self.state = FirmwareState::PosCrashScreen(error);
|
||||
}
|
||||
// TODO: Compor com a UI do Hub
|
||||
}
|
||||
FirmwareState::PosCrashScreen(_error) => {
|
||||
// Atualiza periféricos para input na tela de crash
|
||||
hw.pad_mut().begin_frame(signals);
|
||||
let next_state = match &mut self.state {
|
||||
FirmwareState::Reset => Self::step_reset(&mut self.os),
|
||||
FirmwareState::SplashScreen => Self::step_splash_screen(),
|
||||
FirmwareState::LaunchHub => Self::step_launch_hub(&mut self.hub),
|
||||
FirmwareState::HubHome => Self::step_hub_home(&mut self.hub, &mut self.os, hw),
|
||||
FirmwareState::LoadApp(cartridge) => Self::step_init_app(&mut self.os, signals, hw, cartridge),
|
||||
FirmwareState::AppRunning => Self::step_run_app(&mut self.os, signals, hw),
|
||||
FirmwareState::AppCrashes(_error) => Self::step_crash_screen(signals, hw),
|
||||
};
|
||||
|
||||
// Tela de erro: fundo vermelho, texto branco
|
||||
hw.gfx_mut().clear(Color::RED);
|
||||
// Por enquanto apenas logamos ou mostramos algo simples
|
||||
// No futuro, usar draw_text
|
||||
hw.gfx_mut().present();
|
||||
|
||||
// Se apertar START, volta pro Hub
|
||||
if hw.pad().start.down {
|
||||
self.state = FirmwareState::LaunchHubHome;
|
||||
}
|
||||
}
|
||||
if let Some(new_state) = next_state {
|
||||
self.state = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_app(&mut self, cart: Cartridge, mode: AppMode) {
|
||||
self.os.load_cartridge(&cart);
|
||||
match mode {
|
||||
AppMode::Game => self.state = FirmwareState::PosRunGame(cart),
|
||||
AppMode::System => self.state = FirmwareState::PosRunSystem(cart),
|
||||
fn step_reset(os: &mut PrometeuOS) -> Option<FirmwareState> {
|
||||
os.reset();
|
||||
Some(FirmwareState::SplashScreen)
|
||||
}
|
||||
|
||||
fn step_splash_screen() -> Option<FirmwareState> {
|
||||
Some(FirmwareState::LaunchHub)
|
||||
}
|
||||
|
||||
fn step_launch_hub(hub: &mut PrometeuHub) -> Option<FirmwareState> {
|
||||
hub.init();
|
||||
Some(FirmwareState::HubHome)
|
||||
}
|
||||
|
||||
fn step_hub_home(hub: &mut PrometeuHub, os: &mut PrometeuOS, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
hw.gfx_mut().clear(Color::INDIGO);
|
||||
hub.gui_update(os);
|
||||
hw.gfx_mut().present();
|
||||
None
|
||||
}
|
||||
|
||||
fn step_init_app(os: &mut PrometeuOS, _signals: &InputSignals, _hw: &mut dyn HardwareBridge, cartridge: &Cartridge) -> Option<FirmwareState> {
|
||||
match cartridge.header.mode {
|
||||
AppMode::Game => {
|
||||
},
|
||||
AppMode::System => {
|
||||
}
|
||||
}
|
||||
os.initialize_vm(cartridge);
|
||||
Some(FirmwareState::AppRunning)
|
||||
}
|
||||
|
||||
fn step_run_app(os: &mut PrometeuOS, signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
os.step_frame(signals, hw).map(FirmwareState::AppCrashes)
|
||||
}
|
||||
|
||||
fn step_crash_screen(signals: &InputSignals, hw: &mut dyn HardwareBridge) -> Option<FirmwareState> {
|
||||
// Atualiza periféricos para input na tela de crash
|
||||
hw.pad_mut().begin_frame(signals);
|
||||
|
||||
// Tela de erro: fundo vermelho, texto branco
|
||||
hw.gfx_mut().clear(Color::RED);
|
||||
// Por enquanto apenas logamos ou mostramos algo simples
|
||||
// No futuro, usar draw_text
|
||||
hw.gfx_mut().present();
|
||||
|
||||
// Se apertar START, volta pro Hub
|
||||
if hw.pad().start.down {
|
||||
return Some(FirmwareState::LaunchHub);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn load_cartridge(&mut self, cart: Cartridge) {
|
||||
self.state = FirmwareState::LoadApp(cart);
|
||||
}
|
||||
}
|
||||
@ -4,9 +4,9 @@ use crate::model::Cartridge;
|
||||
pub enum FirmwareState {
|
||||
Reset,
|
||||
SplashScreen,
|
||||
LaunchHubHome,
|
||||
LaunchHub,
|
||||
HubHome,
|
||||
PosRunGame(Cartridge),
|
||||
PosRunSystem(Cartridge),
|
||||
PosCrashScreen(String),
|
||||
LoadApp(Cartridge),
|
||||
AppRunning,
|
||||
AppCrashes(String),
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
use crate::hardware::HardwareBridge;
|
||||
use crate::model::Color;
|
||||
use crate::prometeu_os::PrometeuOS;
|
||||
|
||||
@ -34,4 +35,7 @@ impl PrometeuHub {
|
||||
pub fn gui_update(&mut self, _os: &mut PrometeuOS) {
|
||||
// Atualiza a UI do Window System
|
||||
}
|
||||
|
||||
pub fn render(&mut self, _os: &mut PrometeuOS, _hw: &mut dyn HardwareBridge) {
|
||||
}
|
||||
}
|
||||
@ -49,15 +49,8 @@ impl PrometeuOS {
|
||||
}
|
||||
|
||||
/// Carrega um cartucho na PVM e reseta o estado de execução.
|
||||
pub fn load_cartridge(&mut self, cart: &Cartridge) {
|
||||
// Na spec: "resetar PC/stack/heap ao iniciar app"
|
||||
self.vm.program = cart.program.clone();
|
||||
self.vm.pc = 0;
|
||||
self.vm.operand_stack.clear();
|
||||
self.vm.call_stack.clear();
|
||||
self.vm.globals.clear();
|
||||
self.vm.heap.clear();
|
||||
self.vm.halted = false;
|
||||
pub fn initialize_vm(&mut self, cartridge: &Cartridge) {
|
||||
self.vm.initialize(cartridge.program.clone());
|
||||
}
|
||||
|
||||
/// Executa um tick do host (60Hz).
|
||||
|
||||
@ -43,6 +43,16 @@ impl VirtualMachine {
|
||||
halted: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize(&mut self, program: Program) {
|
||||
self.program = program;
|
||||
self.pc = 0;
|
||||
self.operand_stack.clear();
|
||||
self.call_stack.clear();
|
||||
self.globals.clear();
|
||||
self.heap.clear();
|
||||
self.halted = false;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for VirtualMachine {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user