Support screenshots

This commit is contained in:
2025-07-13 00:45:10 -04:00
parent f1658619ad
commit b6b0a8c22b
3 changed files with 95 additions and 8 deletions
+12 -4
View File
@@ -178,7 +178,7 @@ pub struct Emulator {
debuggers: HashMap<SimId, DebugInfo>,
stdouts: HashMap<SimId, mpsc::Sender<String>>,
watched_regions: HashMap<MemoryRange, Weak<MemoryRegion>>,
eye_contents: Vec<u8>,
eye_contents: [Vec<u8>; 2],
audio_samples: Vec<f32>,
buffer: Vec<u8>,
}
@@ -205,7 +205,7 @@ impl Emulator {
debuggers: HashMap::new(),
stdouts: HashMap::new(),
watched_regions: HashMap::new(),
eye_contents: vec![0u8; 384 * 224 * 2],
eye_contents: [vec![0u8; 384 * 224 * 2], vec![0u8; 384 * 224 * 2]],
audio_samples: Vec::with_capacity(EXPECTED_FRAME_SIZE),
buffer: vec![],
})
@@ -528,9 +528,12 @@ impl Emulator {
let Some(sim) = self.sims.get_mut(sim_id.to_index()) else {
continue;
};
if sim.read_pixels(&mut self.eye_contents) {
if sim.read_pixels(&mut self.eye_contents[sim_id.to_index()]) {
idle = false;
if renderer.queue_render(&self.eye_contents).is_err() {
if renderer
.queue_render(&self.eye_contents[sim_id.to_index()])
.is_err()
{
self.renderers.remove(&sim_id);
}
}
@@ -702,6 +705,10 @@ impl Emulator {
sim.set_keys(keys);
}
}
EmulatorCommand::Screenshot(sim_id, sender) => {
let contents = self.eye_contents[sim_id.to_index()].clone();
let _ = sender.send(contents);
}
EmulatorCommand::Exit(done) => {
for sim_id in SimId::values() {
if let Err(error) = self.save_sram(sim_id) {
@@ -761,6 +768,7 @@ pub enum EmulatorCommand {
Unlink,
Reset(SimId),
SetKeys(SimId, VBKey),
Screenshot(SimId, oneshot::Sender<Vec<u8>>),
Exit(oneshot::Sender<()>),
}