-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
132 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use crate::ppu::registers::Register16; | ||
|
||
pub struct Address { | ||
pub value: u16, | ||
} | ||
|
||
impl Address { | ||
pub fn new(value: u16) -> Self { | ||
Address { value: value } | ||
} | ||
} | ||
|
||
impl Register16 for Address { | ||
fn read_u16(&self) -> u16 { | ||
return self.value; | ||
} | ||
|
||
fn write_u16(&mut self, data: u16) { | ||
self.value = data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
pub mod address; | ||
pub mod control; | ||
pub mod mask; | ||
pub mod status; | ||
pub trait Register { | ||
fn read(&self) -> u8; | ||
fn write(&mut self, data: u8); | ||
pub mod write_toggle; | ||
|
||
pub trait Register8 { | ||
fn read_u8(&self) -> u8; | ||
fn write_u8(&mut self, data: u8); | ||
} | ||
|
||
pub trait Register16 { | ||
fn read_u16(&self) -> u16; | ||
|
||
// we leave it to the PPU to decide if it's going to write the high or low order byte, based on the value of its internal w register | ||
fn write_u16(&mut self, data: u16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#[derive(PartialEq, Debug)] | ||
pub enum WriteToggle { | ||
FirstWrite, | ||
SecondWrite, | ||
} | ||
|
||
impl WriteToggle { | ||
pub fn toggle(&mut self) { | ||
match self { | ||
Self::FirstWrite => *self = Self::SecondWrite, | ||
Self::SecondWrite => *self = Self::FirstWrite, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_write_toggle { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_toggle() { | ||
let mut w = WriteToggle::FirstWrite; | ||
|
||
w.toggle(); | ||
assert_eq!(WriteToggle::SecondWrite, w); | ||
|
||
w.toggle(); | ||
assert_eq!(WriteToggle::FirstWrite, w) | ||
} | ||
} |