clean up
This commit is contained in:
parent
2a5d80353a
commit
57d79edb52
@ -20,59 +20,75 @@ impl Firmware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn step_frame(&mut self, signals: &InputSignals, hw: &mut dyn HardwareBridge) {
|
pub fn step_frame(&mut self, signals: &InputSignals, hw: &mut dyn HardwareBridge) {
|
||||||
match &mut self.state {
|
let next_state = match &mut self.state {
|
||||||
FirmwareState::Reset => {
|
FirmwareState::Reset => Self::step_reset(&mut self.os),
|
||||||
self.os.reset();
|
FirmwareState::SplashScreen => Self::step_splash_screen(),
|
||||||
self.state = FirmwareState::SplashScreen;
|
FirmwareState::LaunchHub => Self::step_launch_hub(&mut self.hub),
|
||||||
}
|
FirmwareState::HubHome => Self::step_hub_home(&mut self.hub, &mut self.os, hw),
|
||||||
FirmwareState::SplashScreen => {
|
FirmwareState::LoadApp(cartridge) => Self::step_init_app(&mut self.os, signals, hw, cartridge),
|
||||||
// Splash logic opcional
|
FirmwareState::AppRunning => Self::step_run_app(&mut self.os, signals, hw),
|
||||||
self.state = FirmwareState::LaunchHubHome;
|
FirmwareState::AppCrashes(_error) => Self::step_crash_screen(signals, hw),
|
||||||
}
|
};
|
||||||
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
|
if let Some(new_state) = next_state {
|
||||||
hw.gfx_mut().clear(Color::RED);
|
self.state = new_state;
|
||||||
// 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) {
|
fn step_reset(os: &mut PrometeuOS) -> Option<FirmwareState> {
|
||||||
self.os.load_cartridge(&cart);
|
os.reset();
|
||||||
match mode {
|
Some(FirmwareState::SplashScreen)
|
||||||
AppMode::Game => self.state = FirmwareState::PosRunGame(cart),
|
}
|
||||||
AppMode::System => self.state = FirmwareState::PosRunSystem(cart),
|
|
||||||
|
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 {
|
pub enum FirmwareState {
|
||||||
Reset,
|
Reset,
|
||||||
SplashScreen,
|
SplashScreen,
|
||||||
LaunchHubHome,
|
LaunchHub,
|
||||||
HubHome,
|
HubHome,
|
||||||
PosRunGame(Cartridge),
|
LoadApp(Cartridge),
|
||||||
PosRunSystem(Cartridge),
|
AppRunning,
|
||||||
PosCrashScreen(String),
|
AppCrashes(String),
|
||||||
}
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
use crate::hardware::HardwareBridge;
|
||||||
use crate::model::Color;
|
use crate::model::Color;
|
||||||
use crate::prometeu_os::PrometeuOS;
|
use crate::prometeu_os::PrometeuOS;
|
||||||
|
|
||||||
@ -34,4 +35,7 @@ impl PrometeuHub {
|
|||||||
pub fn gui_update(&mut self, _os: &mut PrometeuOS) {
|
pub fn gui_update(&mut self, _os: &mut PrometeuOS) {
|
||||||
// Atualiza a UI do Window System
|
// 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.
|
/// Carrega um cartucho na PVM e reseta o estado de execução.
|
||||||
pub fn load_cartridge(&mut self, cart: &Cartridge) {
|
pub fn initialize_vm(&mut self, cartridge: &Cartridge) {
|
||||||
// Na spec: "resetar PC/stack/heap ao iniciar app"
|
self.vm.initialize(cartridge.program.clone());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executa um tick do host (60Hz).
|
/// Executa um tick do host (60Hz).
|
||||||
|
|||||||
@ -43,6 +43,16 @@ impl VirtualMachine {
|
|||||||
halted: false,
|
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 {
|
impl Default for VirtualMachine {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user