[][src]Struct pir_8_emu::binutils::pir_8_emu::Vm

pub struct Vm {
    pub memory: Memory,
    pub ports: Ports,
    pub registers: GeneralPurposeRegisterBank,
    pub pc: SpecialPurposeRegister<u16>,
    pub sp: SpecialPurposeRegister<u16>,
    pub adr: SpecialPurposeRegister<u16>,
    pub ins: SpecialPurposeRegister<u8>,
    pub ops: (MicroOpBlock, usize),
    pub curr_op: usize,
    pub instruction: Instruction,
    pub instruction_valid: bool,
    pub execution_finished: bool,
    pub stack: Vec<u8>,
    pub instruction_history: ArrayDeque<[(u16, Instruction, u16); 10], ArrayDequeBehaviourWrapping>,
    pub breakpoints: BTreeSet<u16>,
    pub active_breakpoint: Option<u16>,
}

Container for all data needed and/or useful for running a pir-8-emu virtual machine

Examples

let mut vm = Vm::new("FSXYABCD").unwrap();
vm.reset("FSXYABCD", &[
    Instruction::Halt.into(),
    Instruction::LoadImmediateWide { rr: InstructionLoadImmediateWideRegisterPair::Adr }.into(),
    0x04,
    0x20,
    Instruction::LoadImmediateByte { rrr: 0b000 }.into(),
    0x69,
    Instruction::Save { rrr: 0b000 }.into(),
    Instruction::Halt.into(),
]);

vm.jump_to_addr(0x0001).unwrap();
while !vm.execution_finished {
    vm.ins.reset_rw();
    vm.perform_next_op().unwrap();
}

assert_eq!(vm.memory[0x0420], 0x69);

Fields

memory: Memoryports: Portsregisters: GeneralPurposeRegisterBankpc: SpecialPurposeRegister<u16>sp: SpecialPurposeRegister<u16>adr: SpecialPurposeRegister<u16>ins: SpecialPurposeRegister<u8>ops: (MicroOpBlock, usize)curr_op: usizeinstruction: Instructioninstruction_valid: bool

If this is set, instruction contains the current instruction and ops contains the μOps corresponding thereto

execution_finished: boolstack: Vec<u8>instruction_history: ArrayDeque<[(u16, Instruction, u16); 10], ArrayDequeBehaviourWrapping>

Any instruction successfully loaded will be added to the front of this queue

breakpoints: BTreeSet<u16>

Pause execution when PC is contained herein until the flag is cleared

active_breakpoint: Option<u16>

Methods

impl Vm[src]

pub fn new(gp_reg_ltrs: &str) -> Result<Vm, i8>[src]

Create a new, zero-initialised VM with the specified general-purpose register letters

pub fn reset(&mut self, gp_reg_ltrs: &str, memory: &[u8]) -> Result<(), i8>[src]

Reset this VM to a default state but with the specified memory buffer

pub fn jump_to_addr(&mut self, to_addr: u16) -> Result<(), MicroOpPerformError>[src]

Safely jump to the specified address

The current μOp set will be executed, then PC updated to the specified address, and μOps set to NEXT_INSTRUCTION

pub fn perform_next_op(&mut self) -> Result<bool, MicroOpPerformError>[src]

Perform next μOp

If execution has finished, do nothing

Otherwise, perform the current μOp and bump the μOp counter

If the last μOp of the set has been performed:

  • if INS was written to, load the instruction therein
  • otherwise, load NEXT_INSTRUCTION

The returned value represents whether new μOps are present

Trait Implementations

impl Debug for Vm[src]

Auto Trait Implementations

impl !RefUnwindSafe for Vm

impl !Send for Vm

impl !Sync for Vm

impl Unpin for Vm

impl !UnwindSafe for Vm

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.