Skip to content

Commit

Permalink
Display execution speed multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Kogepan229 committed Dec 18, 2024
1 parent f78eb49 commit 8fb61b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/simulator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::sync::mpsc::Receiver;
use std::{collections::HashMap, time};

use eframe::egui;
use views::SimulatorUiStates;
Expand All @@ -15,6 +15,7 @@ pub struct Simulator {
emulator_exec_rx: Option<Receiver<Result<Emulator, String>>>,
ui_states: SimulatorUiStates,
io_ports: HashMap<u32, u8>,
prev_timing: time::Instant,
}

impl Simulator {
Expand All @@ -24,6 +25,7 @@ impl Simulator {
emulator_exec_rx: None,
ui_states: SimulatorUiStates::new(),
io_ports: HashMap::new(),
prev_timing: time::Instant::now(),
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/simulator/parse_messages.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time;

use super::Simulator;

impl Simulator {
Expand All @@ -11,8 +13,14 @@ impl Simulator {
emulator.send_message(format!("u8:{:x}:{:x}", addr, value));
}
emulator.send_message("cmd:start");
self.prev_timing = time::Instant::now();
}
}
"1sec" => {
let duration = self.prev_timing.elapsed();
self.prev_timing = time::Instant::now();
self.ui_states.speed = 1f32 / duration.as_secs_f32();
}
_ => (),
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/simulator/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct SimulatorUiStates {
pub elf_path: Arc<Mutex<String>>,
pub elf_args: String,
messages: Vec<String>,
pub speed: f32,
}

impl SimulatorUiStates {
Expand All @@ -18,6 +19,7 @@ impl SimulatorUiStates {
elf_path: Arc::new(Mutex::new(String::new())),
elf_args: String::new(),
messages: Vec::new(),
speed: 0f32,
}
}

Expand Down Expand Up @@ -91,6 +93,7 @@ impl Simulator {
} else {
ui.label("Emulator is None.");
}
ui.label(format!("Speed: x{}", self.ui_states.speed));

ui.separator();

Expand Down

0 comments on commit 8fb61b8

Please sign in to comment.