Starting point for MCS-4 emulation and MOS 6502 inheritance
This commit is contained in:
parent
4ddb4a060f
commit
ac8ebbafe9
13 changed files with 823 additions and 4 deletions
138
src/components/cpu/cpu_traits.rs
Normal file
138
src/components/cpu/cpu_traits.rs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
use crate::{PinValue, Component};
|
||||
use crate::components::cpu::cmos_65c02::CMOS65C02;
|
||||
use crate::components::cpu::mos_6502::{Registers, MOS6502};
|
||||
|
||||
pub trait CPU: Component {
|
||||
fn reset(&mut self);
|
||||
fn execute_instruction(&mut self);
|
||||
fn get_registers(&self) -> &Registers;
|
||||
fn get_registers_mut(&mut self) -> &mut 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) -> &Registers {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_registers_mut(&mut self) -> &mut 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) {
|
||||
self.lda(value)
|
||||
}
|
||||
|
||||
fn sta(&mut self, address: u16) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn tax(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// Implement other methods...
|
||||
}
|
||||
|
||||
impl CPU for CMOS65C02 {
|
||||
fn reset(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn execute_instruction(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_registers(&self) -> &Registers {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_registers_mut(&mut self) -> &mut Registers {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn read_memory(&self, address: u16) -> u8 {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn write_memory(&mut self, address: u16, value: u8) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl MOS6502Family for CMOS65C02 {
|
||||
fn lda(&mut self, value: u8) {
|
||||
self.base_6502.lda(value)
|
||||
}
|
||||
|
||||
fn sta(&mut self, address: u16) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn tax(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// Implement other methods...
|
||||
}
|
||||
|
||||
impl CMOS65C02Extensions for CMOS65C02 {
|
||||
fn bra(&mut self, address: u16) {
|
||||
self.bra(address)
|
||||
}
|
||||
|
||||
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...
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue