Implement fake stdout

This commit is contained in:
2025-05-30 23:52:16 -04:00
parent 2d18aeaba2
commit a2a5884a2a
3 changed files with 80 additions and 18 deletions
+23 -4
View File
@@ -169,6 +169,7 @@ pub struct Emulator {
renderers: HashMap<SimId, TextureSink>,
messages: HashMap<SimId, mpsc::Sender<Toast>>,
debuggers: HashMap<SimId, DebugInfo>,
stdouts: HashMap<SimId, mpsc::Sender<String>>,
watched_regions: HashMap<MemoryRange, Weak<MemoryRegion>>,
eye_contents: Vec<u8>,
audio_samples: Vec<f32>,
@@ -195,6 +196,7 @@ impl Emulator {
renderers: HashMap::new(),
messages: HashMap::new(),
debuggers: HashMap::new(),
stdouts: HashMap::new(),
watched_regions: HashMap::new(),
eye_contents: vec![0u8; 384 * 224 * 2],
audio_samples: Vec::with_capacity(EXPECTED_FRAME_SIZE),
@@ -471,6 +473,20 @@ impl Emulator {
self.state.store(EmulatorState::Paused, Ordering::Release);
}
// stdout
self.stdouts.retain(|sim_id, stdout| {
let Some(sim) = self.sims.get_mut(sim_id.to_index()) else {
return false;
};
if let Some(text) = sim.take_stdout() {
if stdout.send(text).is_err() {
sim.watch_stdout(false);
return false;
}
}
true
});
// Debug state
if state == EmulatorState::Debugging {
for sim_id in SimId::values() {
@@ -645,9 +661,12 @@ impl Emulator {
};
sim.remove_watchpoint(address, length, watch);
}
EmulatorCommand::ConnectTerminal(sim_id, terminal_sink) => {
// TODO
let _ = (sim_id, terminal_sink);
EmulatorCommand::WatchStdout(sim_id, stdout_sink) => {
self.stdouts.insert(sim_id, stdout_sink);
let Some(sim) = self.sims.get_mut(sim_id.to_index()) else {
return;
};
sim.watch_stdout(true);
}
EmulatorCommand::SetAudioEnabled(p1, p2) => {
self.audio_on[SimId::Player1.to_index()].store(p1, Ordering::Release);
@@ -722,7 +741,7 @@ pub enum EmulatorCommand {
RemoveBreakpoint(SimId, u32),
AddWatchpoint(SimId, u32, usize, VBWatchpointType),
RemoveWatchpoint(SimId, u32, usize, VBWatchpointType),
ConnectTerminal(SimId, mpsc::Sender<String>),
WatchStdout(SimId, mpsc::Sender<String>),
SetAudioEnabled(bool, bool),
Link,
Unlink,