Fix color bug
This commit is contained in:
+23
-8
@@ -10,12 +10,17 @@ pub struct Bus<A, B> {
|
||||
start: Word,
|
||||
end: Word,
|
||||
device: A,
|
||||
rest: B
|
||||
rest: B,
|
||||
}
|
||||
|
||||
impl<A, B> Bus<A, B> {
|
||||
fn new(start: u32, end: u32, device: A, rest: B) -> Self {
|
||||
Self { start: start.into(), end: end.into(), device, rest }
|
||||
Self {
|
||||
start: start.into(),
|
||||
end: end.into(),
|
||||
device,
|
||||
rest,
|
||||
}
|
||||
}
|
||||
|
||||
fn at(addr: u32, device: A, rest: B) -> Self {
|
||||
@@ -59,14 +64,22 @@ mod tests {
|
||||
|
||||
struct TestDevice(i32);
|
||||
impl Device for TestDevice {
|
||||
fn tick(&mut self) { self.0 += 1 }
|
||||
fn reset(&mut self) { self.0 = 10 }
|
||||
fn tick(&mut self) {
|
||||
self.0 += 1
|
||||
}
|
||||
fn reset(&mut self) {
|
||||
self.0 = 10
|
||||
}
|
||||
}
|
||||
|
||||
struct ArrayDevice([u8; 10]);
|
||||
impl PeekPoke for ArrayDevice {
|
||||
fn peek(&self, addr: Word) -> u8 { self.0[usize::from(addr)] }
|
||||
fn poke(&mut self, addr: Word, val: u8) { self.0[usize::from(addr)] = val }
|
||||
fn peek(&self, addr: Word) -> u8 {
|
||||
self.0[usize::from(addr)]
|
||||
}
|
||||
fn poke(&mut self, addr: Word, val: u8) {
|
||||
self.0[usize::from(addr)] = val
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -76,7 +89,9 @@ mod tests {
|
||||
let device3 = TestDevice(7);
|
||||
let mut bus = Bus::at(5, device1, Bus::at(6, device2, device3));
|
||||
|
||||
for _ in 0..5 { bus.tick() }
|
||||
for _ in 0..5 {
|
||||
bus.tick()
|
||||
}
|
||||
assert_eq!(bus.device.0, 10);
|
||||
assert_eq!(bus.rest.device.0, 11);
|
||||
assert_eq!(bus.rest.rest.0, 12);
|
||||
@@ -108,4 +123,4 @@ mod tests {
|
||||
assert_eq!(bus.peek_u32(2), 2); // Reading from the first device
|
||||
assert_eq!(bus.peek_u32(6), 6); // And the second
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user