From 7b427164d8df562030edb6f6bd629365e1f14e89 Mon Sep 17 00:00:00 2001 From: Brooke Chalmers Date: Fri, 26 Apr 2024 23:13:34 -0400 Subject: [PATCH] Blank screen on CA2 write --- src/memory/mos652x/pia.rs | 20 ++++++++++++++++++-- src/systems/pet/mod.rs | 21 +++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/memory/mos652x/pia.rs b/src/memory/mos652x/pia.rs index 0d8ffd8..baae66f 100644 --- a/src/memory/mos652x/pia.rs +++ b/src/memory/mos652x/pia.rs @@ -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); + } + } 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); + } + } _ => unreachable!(), } } diff --git a/src/systems/pet/mod.rs b/src/systems/pet/mod.rs index e66b171..915dd49 100644 --- a/src/systems/pet/mod.rs +++ b/src/systems/pet/mod.rs @@ -34,6 +34,7 @@ pub struct PetPia1PortA { keyboard_row: Rc>, last_draw_instant: Option, last_draw_cycle: u64, + blank_screen: Rc>, } impl PetPia1PortA { @@ -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)), } } pub fn get_keyboard_row(&self) -> Rc> { self.keyboard_row.clone() } + + pub fn get_blank_screen(&self) -> Rc> { + self.blank_screen.clone() + } } impl Port for PetPia1PortA { @@ -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); } } @@ -179,6 +188,7 @@ impl BuildableSystem for PetSystem { let editor_rom = BlockMemory::from_file(0x1000, roms.editor); let port_a = PetPia1PortA::new(); + let blank_screen = port_a.get_blank_screen(); 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); @@ -204,6 +214,7 @@ impl BuildableSystem for PetSystem { Box::new(PetSystem { cpu, characters: roms.character.get_data(), + blank_screen, }) } } @@ -212,6 +223,7 @@ impl BuildableSystem for PetSystem { pub struct PetSystem { cpu: Mos6502, characters: Vec, + blank_screen: Rc>, } impl System for PetSystem { @@ -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; + } + for y in 0..HEIGHT { for x in 0..WIDTH { let index = (y * WIDTH + x) as u16;