78 lines
2.7 KiB
Rust
78 lines
2.7 KiB
Rust
use crate::firmware::firmware_state::FirmwareState;
|
|
use crate::hardware::{HardwareBridge, InputSignals};
|
|
use crate::model::{AppMode, Cartridge, Color};
|
|
use crate::prometeu_hub::PrometeuHub;
|
|
use crate::prometeu_os::PrometeuOS;
|
|
|
|
pub struct Firmware {
|
|
pub os: PrometeuOS,
|
|
pub hub: PrometeuHub,
|
|
pub state: FirmwareState,
|
|
}
|
|
|
|
impl Firmware {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
os: PrometeuOS::new(),
|
|
hub: PrometeuHub::new(),
|
|
state: FirmwareState::Reset,
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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),
|
|
}
|
|
}
|
|
} |