pub struct MOS6502 { /* private fields */ }Expand description
Struct representation of the MOS 6502 processor
§Usage Example
fn main() -> Result<()>{
let mut ram = BasicRam{ ram: Box::new([0; u16::max_value() as usize + 1]) };
//Load a program into memory...
let mut file = File::open("C:/some_6502_program.bin")?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
//Copy it into the BasicRam
ram.load_program(0x0400, &mut buffer);
let mut cpu = MOS6502::new(); //Create a new emulator instance
cpu.set_program_counter(0x0400); //Set the program counter to the first byte of the program in memory
cpu.cycle(&mut ram); // The emulator can execute cycles individually, for systems that require precise timing...
cpu.execute_instruction(&mut ram); // or instruction by instruction for a coarser approach
Ok(())
}Implementations§
Source§impl MOS6502
impl MOS6502
Sourcepub fn new_start(start: u16) -> Self
pub fn new_start(start: u16) -> Self
Creates a new MOS6502 emulation with the program counter at the provided start address
Sourcepub fn new_reset_position(interface: &mut dyn Interface6502) -> Self
pub fn new_reset_position(interface: &mut dyn Interface6502) -> Self
Creates a new MOS6502 emulation with the program counter at the address read from the reset vector (0xfffa-0xfffb).
This is the standard method used for determining where the program starts on most systems
Sourcepub fn set_program_counter(&mut self, program_counter: u16)
pub fn set_program_counter(&mut self, program_counter: u16)
Force the program counter to a specific address
Sourcepub fn cycle(&mut self, interface: &mut dyn Interface6502)
pub fn cycle(&mut self, interface: &mut dyn Interface6502)
Runs a processor cycle, mutably borrows the reading and writing interface for the duration
Sourcepub fn execute_instruction(&mut self, interface: &mut dyn Interface6502)
pub fn execute_instruction(&mut self, interface: &mut dyn Interface6502)
Runs as many processor cycles as it takes to complete the instruction at the program counter
Sourcepub fn interrupt_request(&mut self)
pub fn interrupt_request(&mut self)
Request that an interrupt occurs after the current instruction completes
Sourcepub fn non_maskable_interrupt_request(&mut self)
pub fn non_maskable_interrupt_request(&mut self)
Request that an interrupt occurs after the current instruction completes, even if the interrupt disabled flag is set
Sourcepub fn reset(&mut self, interface: &mut dyn Interface6502)
pub fn reset(&mut self, interface: &mut dyn Interface6502)
Resets the 6502 to a known state