feat: implement cartridge v1 loader and contract
This commit is contained in:
@@ -127,14 +127,10 @@ impl PrometeuOS {
|
||||
|
||||
/// Carrega um cartucho na PVM e reseta o estado de execução.
|
||||
pub fn initialize_vm(&mut self, vm: &mut VirtualMachine, cartridge: &Cartridge) {
|
||||
vm.initialize(cartridge.program.clone());
|
||||
vm.initialize(cartridge.program.clone(), &cartridge.entrypoint);
|
||||
|
||||
// Determina o app_id numérico (hash da string app_id)
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut s = DefaultHasher::new();
|
||||
cartridge.header.app_id.hash(&mut s);
|
||||
self.current_app_id = s.finish() as u32;
|
||||
// Determina o app_id numérico
|
||||
self.current_app_id = cartridge.app_id;
|
||||
}
|
||||
|
||||
/// Executa um tick do host (60Hz).
|
||||
@@ -308,8 +304,8 @@ impl PrometeuOS {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::hardware::InputSignals;
|
||||
use crate::model::{AppHeader, AppMode, Cartridge};
|
||||
use crate::virtual_machine::{Program, VirtualMachine};
|
||||
use crate::model::{AppMode, Cartridge};
|
||||
use crate::virtual_machine::{Value, VirtualMachine};
|
||||
use crate::Hardware;
|
||||
|
||||
#[test]
|
||||
@@ -319,20 +315,15 @@ mod tests {
|
||||
let mut hw = Hardware::new();
|
||||
let signals = InputSignals::default();
|
||||
|
||||
// JMP 0 (Loop infinito)
|
||||
// OpCode::Jmp = 0x02, seguido por u32 0 (0x00, 0x00, 0x00, 0x00)
|
||||
let rom = vec![0x02, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||
let program = Program::new(rom, vec![]);
|
||||
let cartridge = Cartridge {
|
||||
header: AppHeader {
|
||||
mode: AppMode::Game,
|
||||
app_id: "test".to_string(),
|
||||
magic: 0,
|
||||
version: 1,
|
||||
title: "test".to_string(),
|
||||
entrypoint: 0,
|
||||
},
|
||||
program,
|
||||
app_id: 1234,
|
||||
title: "test".to_string(),
|
||||
app_version: "1.0.0".to_string(),
|
||||
app_mode: AppMode::Game,
|
||||
entrypoint: "0".to_string(),
|
||||
program: rom,
|
||||
assets_path: None,
|
||||
};
|
||||
os.initialize_vm(&mut vm, &cartridge);
|
||||
|
||||
@@ -362,21 +353,17 @@ mod tests {
|
||||
// FrameSync (0x80)
|
||||
// JMP 0
|
||||
let rom = vec![
|
||||
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // PUSH const 0 (2 bytes opcode + 4 bytes u32)
|
||||
0x80, 0x00, // FrameSync (2 bytes opcode)
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, // JMP 0 (2 bytes opcode + 4 bytes u32)
|
||||
];
|
||||
let program = Program::new(rom, vec![Value::Integer(0)]);
|
||||
let cartridge = Cartridge {
|
||||
header: AppHeader {
|
||||
mode: AppMode::Game,
|
||||
app_id: "test".to_string(),
|
||||
magic: 0,
|
||||
version: 1,
|
||||
title: "test".to_string(),
|
||||
entrypoint: 0,
|
||||
},
|
||||
program,
|
||||
app_id: 1234,
|
||||
title: "test".to_string(),
|
||||
app_version: "1.0.0".to_string(),
|
||||
app_mode: AppMode::Game,
|
||||
entrypoint: "0".to_string(),
|
||||
program: rom,
|
||||
assets_path: None,
|
||||
};
|
||||
os.initialize_vm(&mut vm, &cartridge);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user