rusty_emu/src/components/cpu/cpu_traits.rs
Jan-Peter von Hunnius c039e9069a Added more tests
Extracted common 400x behavior like timing and latching into common module
Added maxed MCS-4
2025-09-29 11:53:46 +02:00

145 lines
3 KiB
Rust

use crate::component::Component;
use crate::components::cpu::mos_6502::MOS6502;
use crate::components::cpu::WDC65C02;
pub trait Registers {}
pub trait CPU: Component {
fn reset(&mut self);
fn execute_instruction(&mut self);
fn get_registers(&self) -> &dyn Registers;
fn get_registers_mut(&mut self) -> &mut dyn Registers;
fn read_memory(&self, address: u16) -> u8;
fn write_memory(&mut self, address: u16, value: u8);
}
pub trait MOS6502Family: CPU {
// Common 6502 family methods
fn lda(&mut self, value: u8);
fn sta(&mut self, address: u16);
fn tax(&mut self);
// More common instructions...
}
pub trait CMOS65C02Extensions: MOS6502Family {
// 65C02-specific methods
fn bra(&mut self, address: u16);
fn phx(&mut self);
fn ply(&mut self);
fn stp(&mut self);
fn wai(&mut self);
}
impl CPU for MOS6502 {
fn reset(&mut self) {
todo!()
}
fn execute_instruction(&mut self) {
todo!()
}
fn get_registers(&self) -> &dyn Registers {
todo!()
}
fn get_registers_mut(&mut self) -> &mut dyn Registers {
todo!()
}
fn read_memory(&self, _address: u16) -> u8 {
todo!()
}
fn write_memory(&mut self, _address: u16, _value: u8) {
todo!()
}
}
// Implement for both MOS6502 and CMOS65C02
impl MOS6502Family for MOS6502 {
fn lda(&mut self, _value: u8) {
// Load accumulator with value - this is a placeholder implementation
// In a real 6502, this would load the accumulator register with the value
// For now, we'll just store it in a field if available, or do nothing
// This prevents infinite recursion while providing a valid implementation
}
fn sta(&mut self, _address: u16) {
todo!()
}
fn tax(&mut self) {
todo!()
}
// Implement other methods...
}
impl CPU for WDC65C02 {
fn reset(&mut self) {
todo!()
}
fn execute_instruction(&mut self) {
todo!()
}
fn get_registers(&self) -> &dyn Registers {
todo!()
}
fn get_registers_mut(&mut self) -> &mut dyn Registers {
todo!()
}
fn read_memory(&self, _address: u16) -> u8 {
todo!()
}
fn write_memory(&mut self, _address: u16, _value: u8) {
todo!()
}
}
impl MOS6502Family for WDC65C02 {
fn lda(&mut self, value: u8) {
self.base.lda(value)
}
fn sta(&mut self, _address: u16) {
todo!()
}
fn tax(&mut self) {
todo!()
}
// Implement other methods...
}
impl CMOS65C02Extensions for WDC65C02 {
fn bra(&mut self, _address: u16) {
// Branch always - this is a placeholder implementation
// In a real 65C02, this would branch to the specified address
// For now, we'll just do nothing to prevent infinite recursion
}
fn phx(&mut self) {
todo!()
}
fn ply(&mut self) {
todo!()
}
fn stp(&mut self) {
todo!()
}
fn wai(&mut self) {
todo!()
}
// Implement other 65C02-specific methods...
}