Skip to content

Commit

Permalink
Blank screen on CA2 write
Browse files Browse the repository at this point in the history
  • Loading branch information
breqdev committed Apr 27, 2024
1 parent ce03a82 commit 7b42716
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/memory/mos652x/pia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,25 @@ impl Memory for Pia {
fn write(&mut self, address: u16, value: u8) {
match address % 0x04 {
0x00 => self.a.write(value),
0x01 => self.a.control = value,
0x01 => {
self.a.control = value;
if self.a.control & pia_control_bits::C2_DIRECTION != 0 {
self
.a
.port
.write_cx2(self.a.control & pia_control_bits::C2_OUTPUT_TYPE != 0);

Check warning on line 165 in src/memory/mos652x/pia.rs

View check run for this annotation

Codecov / codecov/patch

src/memory/mos652x/pia.rs#L162-L165

Added lines #L162 - L165 were not covered by tests
}
}
0x02 => self.b.write(value),
0x03 => self.b.control = value,
0x03 => {
self.b.control = value;
if self.b.control & pia_control_bits::C2_DIRECTION != 0 {
self
.b
.port
.write_cx2(self.b.control & pia_control_bits::C2_OUTPUT_TYPE != 0);
}

Check warning on line 176 in src/memory/mos652x/pia.rs

View check run for this annotation

Codecov / codecov/patch

src/memory/mos652x/pia.rs#L170-L176

Added lines #L170 - L176 were not covered by tests
}
_ => unreachable!(),
}
}
Expand Down
21 changes: 19 additions & 2 deletions src/systems/pet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct PetPia1PortA {
keyboard_row: Rc<Cell<u8>>,
last_draw_instant: Option<Instant>,
last_draw_cycle: u64,
blank_screen: Rc<Cell<bool>>,
}

impl PetPia1PortA {
Expand All @@ -42,12 +43,17 @@ impl PetPia1PortA {
keyboard_row: Rc::new(Cell::new(0)),
last_draw_instant: None,
last_draw_cycle: 0,
blank_screen: Rc::new(Cell::new(false)),

Check warning on line 46 in src/systems/pet/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/pet/mod.rs#L46

Added line #L46 was not covered by tests
}
}

pub fn get_keyboard_row(&self) -> Rc<Cell<u8>> {
self.keyboard_row.clone()
}

pub fn get_blank_screen(&self) -> Rc<Cell<bool>> {
self.blank_screen.clone()
}

Check warning on line 56 in src/systems/pet/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/pet/mod.rs#L54-L56

Added lines #L54 - L56 were not covered by tests
}

impl Port for PetPia1PortA {
Expand Down Expand Up @@ -90,8 +96,11 @@ impl Port for PetPia1PortA {
self.keyboard_row.set(0);
}

fn write_cx2(&mut self, _value: bool) {
// TODO: on old PETs, this blanks the screen lol
fn write_cx2(&mut self, value: bool) {
// On old PETs, this blanks the screen
// ("Killer Poke")
println!("poke!");
self.blank_screen.set(!value);
}

Check warning on line 104 in src/systems/pet/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/pet/mod.rs#L99-L104

Added lines #L99 - L104 were not covered by tests
}

Expand Down Expand Up @@ -179,6 +188,7 @@ impl BuildableSystem<PetSystemRoms, PetSystemConfig> for PetSystem {
let editor_rom = BlockMemory::from_file(0x1000, roms.editor);

let port_a = PetPia1PortA::new();
let blank_screen = port_a.get_blank_screen();

Check warning on line 191 in src/systems/pet/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/pet/mod.rs#L191

Added line #L191 was not covered by tests
let port_b = PetPia1PortB::new(port_a.get_keyboard_row(), config.mapping, platform);
let pia1 = Pia::new(Box::new(port_a), Box::new(port_b), true);
let pia2 = Pia::new(Box::new(NullPort::new()), Box::new(NullPort::new()), true);
Expand All @@ -204,6 +214,7 @@ impl BuildableSystem<PetSystemRoms, PetSystemConfig> for PetSystem {
Box::new(PetSystem {
cpu,
characters: roms.character.get_data(),
blank_screen,

Check warning on line 217 in src/systems/pet/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/pet/mod.rs#L217

Added line #L217 was not covered by tests
})
}
}
Expand All @@ -212,6 +223,7 @@ impl BuildableSystem<PetSystemRoms, PetSystemConfig> for PetSystem {
pub struct PetSystem {
cpu: Mos6502,
characters: Vec<u8>,
blank_screen: Rc<Cell<bool>>,
}

impl System for PetSystem {
Expand All @@ -228,6 +240,11 @@ impl System for PetSystem {
}

fn render(&mut self, framebuffer: &mut [u8], config: WindowConfig) {
if self.blank_screen.get() {
framebuffer.iter_mut().for_each(|x| *x = 0);
return;
}

Check warning on line 246 in src/systems/pet/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/systems/pet/mod.rs#L243-L246

Added lines #L243 - L246 were not covered by tests

for y in 0..HEIGHT {
for x in 0..WIDTH {
let index = (y * WIDTH + x) as u16;
Expand Down

0 comments on commit 7b42716

Please sign in to comment.