Changed Memory to Peripheral

The "Memory" name  is too restrictive given that the bus itself
implement that trait.
This commit is contained in:
Steins7 2022-05-08 21:00:51 +02:00
parent 1b9c73c432
commit 123ef70487
4 changed files with 16 additions and 16 deletions

View File

@ -1,6 +1,6 @@
use std::fmt; use std::fmt;
use crate::memory::{Memory, Ram}; use crate::peripherals::{Peripheral, Ram};
pub struct Bus { pub struct Bus {
ram: Ram<0x800>, ram: Ram<0x800>,
@ -18,7 +18,7 @@ impl fmt::Debug for Bus {
} }
} }
impl Memory for Bus { impl Peripheral for Bus {
fn read_addr(&self, addr: u16) -> u8 { fn read_addr(&self, addr: u16) -> u8 {
@ -127,7 +127,7 @@ impl fmt::Debug for FileBus {
} }
} }
impl Memory for FileBus { impl Peripheral for FileBus {
fn read_addr(&self, addr: u16) -> u8 { fn read_addr(&self, addr: u16) -> u8 {
self.mem.read_addr(addr) //RAM is mirrored 3 times self.mem.read_addr(addr) //RAM is mirrored 3 times

View File

@ -5,7 +5,7 @@ use bitflags::bitflags;
use crate::{ use crate::{
bus::FileBus, bus::FileBus,
memory::Memory, peripherals::Peripheral,
}; };
use std::fmt; use std::fmt;
@ -17,11 +17,11 @@ trait Input {
} }
trait RInput: Input { trait RInput: Input {
fn read<M: Memory>(&self, acc: &u8, bus: &M) -> u8; fn read<M: Peripheral>(&self, acc: &u8, bus: &M) -> u8;
} }
trait WInput: Input { trait WInput: Input {
fn write<M: Memory>(&mut self, acc: &mut u8, bus: &mut M, data: u8); fn write<M: Peripheral>(&mut self, acc: &mut u8, bus: &mut M, data: u8);
} }
trait RWInput: RInput + WInput {} trait RWInput: RInput + WInput {}
@ -33,11 +33,11 @@ impl Input for Accumulator {
} }
impl RInput for Accumulator { impl RInput for Accumulator {
fn read<M: Memory>(&self, acc: &u8, _bus: &M) -> u8 { *acc } fn read<M: Peripheral>(&self, acc: &u8, _bus: &M) -> u8 { *acc }
} }
impl WInput for Accumulator { impl WInput for Accumulator {
fn write<M: Memory>(&mut self, acc: &mut u8, _bus: &mut M, data: u8) { *acc = data } fn write<M: Peripheral>(&mut self, acc: &mut u8, _bus: &mut M, data: u8) { *acc = data }
} }
impl RWInput for Accumulator {} impl RWInput for Accumulator {}
@ -51,7 +51,7 @@ impl Input for Data {
} }
impl RInput for Data { impl RInput for Data {
fn read<M: Memory>(&self, _acc: &u8, _bus: &M) -> u8 { self.data } fn read<M: Peripheral>(&self, _acc: &u8, _bus: &M) -> u8 { self.data }
} }
struct MemoryVal { struct MemoryVal {
@ -64,13 +64,13 @@ impl Input for MemoryVal {
} }
impl RInput for MemoryVal { impl RInput for MemoryVal {
fn read<M: Memory>(&self, _acc: &u8, bus: &M) -> u8 { fn read<M: Peripheral>(&self, _acc: &u8, bus: &M) -> u8 {
bus.read_addr(self.addr) bus.read_addr(self.addr)
} }
} }
impl WInput for MemoryVal { impl WInput for MemoryVal {
fn write<M: Memory>(&mut self, _acc: &mut u8, bus: &mut M, data: u8) { fn write<M: Peripheral>(&mut self, _acc: &mut u8, bus: &mut M, data: u8) {
bus.write_addr(self.addr, data); bus.write_addr(self.addr, data);
} }
} }
@ -93,13 +93,13 @@ impl Input for MemoryValExtra {
} }
impl RInput for MemoryValExtra { impl RInput for MemoryValExtra {
fn read<M: Memory>(&self, _acc: &u8, bus: &M) -> u8 { fn read<M: Peripheral>(&self, _acc: &u8, bus: &M) -> u8 {
bus.read_addr(self.addr) bus.read_addr(self.addr)
} }
} }
impl WInput for MemoryValExtra { impl WInput for MemoryValExtra {
fn write<M: Memory>(&mut self, _acc: &mut u8, bus: &mut M, data: u8) { fn write<M: Peripheral>(&mut self, _acc: &mut u8, bus: &mut M, data: u8) {
bus.write_addr(self.addr, data); bus.write_addr(self.addr, data);
self.extra_cycle = true; self.extra_cycle = true;

View File

@ -5,7 +5,7 @@ mod cpu;
use cpu::Cpu; use cpu::Cpu;
mod bus; mod bus;
mod memory; mod peripherals;
mod utils; mod utils;
fn main() -> Result<(), &'static str> { fn main() -> Result<(), &'static str> {

View File

@ -1,7 +1,7 @@
use std::fmt; use std::fmt;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
pub trait Memory { pub trait Peripheral {
fn read_addr(&self, addr: u16) -> u8; fn read_addr(&self, addr: u16) -> u8;
@ -27,7 +27,7 @@ impl<const SIZE: usize> fmt::Debug for Ram<SIZE> {
} }
} }
impl<const SIZE: usize> Memory for Ram<SIZE> { impl<const SIZE: usize> Peripheral for Ram<SIZE> {
fn read_addr(&self, addr: u16) -> u8 { fn read_addr(&self, addr: u16) -> u8 {
self.buffer[addr as usize] self.buffer[addr as usize]