Finished snippet emulator (for now)

This commit is contained in:
2023-01-28 00:31:14 -06:00
parent 3d7a19d1bd
commit c825e6d727
2 changed files with 59 additions and 5 deletions
+16
View File
@@ -114,6 +114,14 @@ impl WasmCPU {
pub fn halted(&self) -> bool { self.0.halted() }
pub fn get_stack(&self) -> Vec<i32> {
self.0.get_stack().into_iter().map(i32::from).collect()
}
pub fn get_call(&self) -> Vec<i32> {
self.0.get_call().into_iter().map(i32::from).collect()
}
pub fn set_pc(&mut self, val: u32) {
self.0.set_pc(Word::from(val))
}
@@ -122,6 +130,14 @@ impl WasmCPU {
self.0.run_to_halt()
}
pub fn safe_run(&mut self, max_ticks: usize) {
let mut current = 0;
while !self.0.halted() && current < max_ticks {
current += 1;
self.tick()
}
}
pub fn load(&mut self, rom: Vec<u8>) {
for (i, b) in rom.iter().enumerate() {
self.poke(0x400 + i as u32, *b)