InstructionController

Trait InstructionController 

Source
pub trait InstructionController {
    // Required methods
    fn step(&mut self) -> u64;
    fn mode(&mut self, op: u8) -> Mode;
    fn fetch(&mut self) -> u8;
    fn fetch_byte(&mut self) -> u8;
    fn apply(&mut self, address: u16, operation: fn(u8) -> u8) -> u8;
    fn relative_jump(&mut self, offset: u8, cond: bool);
}

Required Methods§

Source

fn step(&mut self) -> u64

Source

fn mode(&mut self, op: u8) -> Mode

Source

fn fetch(&mut self) -> u8

Source

fn fetch_byte(&mut self) -> u8

Source

fn apply(&mut self, address: u16, operation: fn(u8) -> u8) -> u8

Source

fn relative_jump(&mut self, offset: u8, cond: bool)

Implementors§

Source§

impl InstructionController for VirtualMachine

Virtual machine core control functionality.

This provides three main internal functions, step, mode, and fetch.

§Examples

§step
use vm6502::prelude::*;
let mut vm = VirtualMachine::new();

vm.insert_program(0x00, "69FFFF");
vm.registers.pc = 0x00;

vm.step();

assert_eq!(vm.flatmap[vm.registers.pc as usize + vm.heap_bounds.0], 0xFF);
§mode
use vm6502::prelude::*;

let mut vm = VirtualMachine::new();
let mode = vm.mode(0x69);

assert_eq!(mode, Mode::Immediate);
§fetch

// TODO: Unignore this later.

use vm6502::prelude::*;

let mut vm = VirtualMachine::new();
let byte = 0x01;

// 0x200 is heap start. See `VirtualMachine::heap_bounds`.
vm.set_heap(0x0000, 0x69);
vm.set_heap(0x0001, byte);

assert_ne!(vm.flatmap[0x0001], byte, "Byte {} was not set to 0x0201", byte);
assert_eq!(byte, vm.flatmap[0x0201], "Byte {} was not set at 0x0201", byte);

// Should PC be 0x01 or two here?
vm.registers.pc = 0x00;
vm.addr_mode = Mode::Immediate;

let fetched = vm.fetch();
assert_eq!(vm.registers.pc, 0x01, "PC should be incremented by 1 after fetch");

assert_eq!(fetched, byte, "Fetched byte {} does not match expected byte {}", fetched, byte);