Cpu

Struct Cpu 

Source
pub struct Cpu {
    pub a: u8,
    pub x: u8,
    pub y: u8,
    pub sp: u8,
    pub pc: u16,
    pub status: u8,
    pub cycles: u8,
    pub bus: Box<dyn Bus>,
    pub variant: Variant,
    pub enable_illegal_opcodes: bool,
    pub current_instruction_string: String,
    pub debug: usize,
    /* private fields */
}
Expand description

The emulated 6502 CPU

Fields§

§a: u8

The 8-bit accumulator

§x: u8

The 8-bit x index register

§y: u8

The 8-bit y index register

§sp: u8

The 8-bit stack pointer

§pc: u16

The 16-bit program counter

§status: u8

The status flags

§cycles: u8

The number of cycles remaining

§bus: Box<dyn Bus>

The bus that the CPU is connected to

§variant: Variant

The variant of the CPU

§enable_illegal_opcodes: bool

Whether illegal instructions are allowed

§current_instruction_string: String

The current instruction string

§debug: usize

Debug modes 0: No debug 1: Print each instruction 2: Print each cycle

Implementations§

Source§

impl Cpu

Source

pub fn new(bus: Box<dyn Bus>, debug: usize) -> Cpu

Create a new CPU

Source

pub fn reset(&mut self)

Reset the CPU

Source

pub fn read(&self, address: u16) -> u8

Read a byte from memory

Source

pub fn read_u16(&self, address: u16) -> u16

Read a 16-bit word from memory

Source

pub fn write(&mut self, address: u16, value: u8)

Write a byte to memory

Source

pub fn write_u16(&mut self, address: u16, value: u16)

Write a 16-bit word to memory

Source

pub fn change_variant(&mut self, variant: Variant)

Set the CPU variant

Source

pub fn set_illegal_opcodes(&mut self, value: bool)

Set the enable_illegal_opcodes flag

Source

pub fn get_status_string(&self) -> String

Get the status string for the CPU (NV-BDIZC)

Source

pub fn get_cycles(&self, opcode: u8) -> u8

Get the number of cycles for an instruction

Source

pub fn irq(&mut self)

Interrupt request

Source

pub fn nmi(&mut self)

Non-maskable interrupt request

Source

pub fn get_register(&self, register: &str) -> u8

Get the value of a register

Source

pub fn clock(&mut self)

Clock the CPU

Source

pub fn get_state(&self) -> String

Get the state of the CPU

Auto Trait Implementations§

§

impl Freeze for Cpu

§

impl !RefUnwindSafe for Cpu

§

impl !Send for Cpu

§

impl !Sync for Cpu

§

impl Unpin for Cpu

§

impl !UnwindSafe for Cpu

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.