Website Summary Files Commits Branches @commit @diff @stats
path: root / vm / src / vmm / mod.rs
blob: 29a0374e9d720790d16cd98af0b641ee787dca8a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::{
    thread,
    time
};

use super::vm::VirtualMachine;

pub(crate) struct VirtualMachineMonitor {
    refresh_rate: u64,
}

impl VirtualMachineMonitor {
    pub(crate) fn new() -> VirtualMachineMonitor {
        VirtualMachineMonitor {
            refresh_rate: 500,
        }
    }

    pub(crate) fn start(&mut self, vm: VirtualMachine) {
        loop {
            {
                let vm = (*vm).lock().unwrap();
                println!("{}", vm.get_word(4));
                if vm.is_halted() {
                    println!("HALTED!");
                    break;
                }
            }
            thread::sleep(time::Duration::from_millis(self.refresh_rate));
        }
    }
}