Skip to content

Commit

Permalink
Implement read range over the read method
Browse files Browse the repository at this point in the history
  • Loading branch information
joajfreitas committed Jul 25, 2024
1 parent 27c01fc commit 3d7f579
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions fpt/src/memory/cartridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ pub trait Cartridge {
fn read(&self, address: Address) -> u8;
fn write(&mut self, address: Address, value: u8);

fn read_range(&self, memory_range: MemoryRange) -> Vec<u8>;
fn read_range(&self, memory_range: MemoryRange) -> Vec<u8> {
memory_range.map(|address| self.read(address)).collect()
}

fn get_title(&self) -> String {
String::from_utf8(self.read_range(map::TITLE)).unwrap()
Expand Down Expand Up @@ -55,13 +57,10 @@ impl EmptyCartridge {
EmptyCartridge {}
}
}

impl Cartridge for EmptyCartridge {
fn read(&self, _address: Address) -> u8 {
0xFF
}
fn write(&mut self, _address: Address, _value: u8) {}

fn read_range(&self, _memory_range: MemoryRange) -> Vec<u8> {
Vec::new()
}
}

0 comments on commit 3d7f579

Please sign in to comment.