Skip to content

Commit

Permalink
Screen pause bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sevonj committed Mar 20, 2024
1 parent 4ea628e commit 3b549d1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 9 deletions.
Binary file added doc/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/screenshot_old.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions src/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,11 @@ impl Emu {
fn playpause(&mut self, p: bool) {
self.t_last_update = None;
self.playing = p;
self.bus.set_pause(p);
if p {
self.bus.turn_on();
// Perform one tick ignoring breakpoints, in case we're stopped on one.
self.tick_ignore_breakpoints();
thread::sleep(Duration::from_secs_f32(1. / self.tick_rate));
} else {
self.bus.turn_off()
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/emulator/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ pub(crate) trait Device {
fn reset(&mut self);
/// Turns this device on.
fn on(&mut self);
/// Turns this device off (but might not fully clear its state).
/// Turns this device off.
fn off(&mut self);
/// Pausing stops time for this device.
fn set_pause(&mut self, paused: bool);
}

/// Memory Mapped IO: Any device that occupies memory addresses shall implement this trait.
Expand Down Expand Up @@ -131,6 +133,7 @@ impl Bus {
}
}

/// Clear all state
pub(crate) fn reset(&mut self) {
self.crt.reset();
self.display.reset();
Expand All @@ -140,6 +143,8 @@ impl Bus {
self.ram.reset();
self.rtc.reset();
}

/// Turn the device on. May affect state, not suitable for "pausing" the device.
pub(crate) fn turn_on(&mut self) {
self.crt.on();
self.display.on();
Expand All @@ -149,6 +154,8 @@ impl Bus {
self.ram.on();
self.rtc.on();
}

/// Turn the device off. May affect state, not suitable for "pausing" the device.
pub(crate) fn turn_off(&mut self) {
self.crt.off();
self.display.off();
Expand All @@ -158,4 +165,14 @@ impl Bus {
self.ram.off();
self.rtc.off();
}

pub(crate) fn set_pause(&mut self, paused: bool){
self.crt.set_pause(paused);
self.display.set_pause(paused);
self.kbd.set_pause(paused);
//self.pic.set_pause(paused);
self.psg.set_pause(paused);
self.ram.set_pause(paused);
self.rtc.set_pause(paused);
}
}
1 change: 1 addition & 0 deletions src/emulator/devices/dev_crt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ impl Device for DevCRT {
fn reset(&mut self) {}
fn on(&mut self) {}
fn off(&mut self) {}
fn set_pause(&mut self, _paused: bool) {}
}

/// Port 0: crt output
Expand Down
11 changes: 6 additions & 5 deletions src/emulator/devices/dev_display_classic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ impl Default for DevDisplayClassic {
fn default() -> Self {
Self {
tx: None,
framebuffer: vec![image::Rgba([0, 0, 0, 255,]); 120 * 160],
framebuffer: vec![Rgba([0, 0, 0, 255, ]); 120 * 160],
interrupt: false,
}
}
}

impl Device for DevDisplayClassic {
fn reset(&mut self) {
self.framebuffer = vec![image::Rgba([0, 0, 0, 255,]); 120 * 160];
self.framebuffer = vec![Rgba([0, 0, 0, 255, ]); 120 * 160];
self.interrupt = false
}
fn on(&mut self) {}
fn off(&mut self) {
self.framebuffer = vec![image::Rgba([0, 0, 0, 255,]); 120 * 160];
self.framebuffer = vec![Rgba([0, 0, 0, 255, ]); 120 * 160];
self.interrupt = false
}
fn set_pause(&mut self, _paused: bool) {}
}

impl DevDisplayClassic {
Expand All @@ -59,13 +60,13 @@ impl MMIO for DevDisplayClassic {
return Err(());
}
let color = self.framebuffer[addr];
Ok((color[0] << 4) as i32 + (color[1]) as i32 + (color[2] >> 4) as i32)
Ok((color[0] << 4) as i32 + color[1] as i32 + (color[2] >> 4) as i32)
}
fn write(&mut self, addr: usize, value: i32) -> Result<(), ()> {
if addr >= self.framebuffer.len() {
return Err(());
}
let color = Rgba([(value >> 4) as u8, (value) as u8, (value << 4) as u8, 255]);
let color = Rgba([(value >> 4) as u8, value as u8, (value << 4) as u8, 255]);
self.framebuffer[addr] = color;
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/emulator/devices/dev_kbd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Device for DevKBD {
fn reset(&mut self) {}
fn on(&mut self) {}
fn off(&mut self) {}
fn set_pause(&mut self, _paused: bool) {}
}

impl PMIO for DevKBD {
Expand Down
17 changes: 17 additions & 0 deletions src/emulator/devices/dev_psg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod noise_channel;
mod note_table;
mod pulse_channel;
mod ramp_channel;

use self::noise_channel::NoiseChannel;
use self::note_table::key_freq;
use self::pulse_channel::PulseChannel;
Expand All @@ -35,6 +36,7 @@ const SAMPLE_RATE: u32 = 22050;
/// Device struct.
///
pub(crate) struct DevPSG {
paused: bool,
#[allow(dead_code)] // Output stream is never "used", but we have to keep it around in order to
// get sound.
stream: Option<OutputStream>,
Expand Down Expand Up @@ -95,6 +97,7 @@ impl Default for DevPSG {
sink3.append(AudioSource::new(ch3.clone()));

DevPSG {
paused: false,
stream,
sink0,
sink1,
Expand Down Expand Up @@ -137,6 +140,20 @@ impl Device for DevPSG {
self.sink2.pause();
self.sink3.pause();
}

fn set_pause(&mut self, paused: bool) {
if paused {
self.sink0.pause();
self.sink1.pause();
self.sink2.pause();
self.sink3.pause();
} else {
self.sink0.play();
self.sink1.play();
self.sink2.play();
self.sink3.play();
}
}
}

impl MMIO for DevPSG {
Expand Down
1 change: 1 addition & 0 deletions src/emulator/devices/dev_ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl Device for DevRAM {
}
fn on(&mut self) {}
fn off(&mut self) {}
fn set_pause(&mut self, _paused: bool) {}
}

impl MMIO for DevRAM {
Expand Down
1 change: 1 addition & 0 deletions src/emulator/devices/dev_rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ impl Device for DevRTC {
fn reset(&mut self) {}
fn on(&mut self) {}
fn off(&mut self) {}
fn set_pause(&mut self, _paused: bool) {}
}

impl PMIO for DevRTC {
Expand Down

0 comments on commit 3b549d1

Please sign in to comment.