misc: formatting and clippy lint fixes
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
max_width = 90
|
||||||
|
comment_width = 90
|
||||||
|
wrap_comments = true
|
||||||
Generated
+39
@@ -776,6 +776,27 @@ dependencies = [
|
|||||||
"crypto-common",
|
"crypto-common",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs"
|
||||||
|
version = "6.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e"
|
||||||
|
dependencies = [
|
||||||
|
"dirs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs-sys"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"option-ext",
|
||||||
|
"redox_users",
|
||||||
|
"windows-sys 0.59.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dispatch"
|
name = "dispatch"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -980,6 +1001,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"assembler",
|
"assembler",
|
||||||
"common",
|
"common",
|
||||||
|
"dirs",
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
"rfd",
|
"rfd",
|
||||||
@@ -2163,6 +2185,12 @@ version = "1.21.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "option-ext"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "orbclient"
|
name = "orbclient"
|
||||||
version = "0.3.48"
|
version = "0.3.48"
|
||||||
@@ -2483,6 +2511,17 @@ dependencies = [
|
|||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_users"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.2.16",
|
||||||
|
"libredox",
|
||||||
|
"thiserror 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "renderdoc-sys"
|
name = "renderdoc-sys"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["emulator", "common", "assembler"]
|
members = ["emulator", "common", "assembler"]
|
||||||
|
resolver = "3"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ pub fn assemble(src: &str) -> Vec<Instruction> {
|
|||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disassemble(binary: Vec<Instruction>) -> String {
|
/// TODO: disassembling functionality
|
||||||
// TODO: disassembling functionality
|
/// - We probably don't need to implement this for a while yet.
|
||||||
|
/// - This method should recover symbols such as labels and variables from the human
|
||||||
// - we probably don't need to implement this for a while yet.
|
/// written assembly, recognising sequences that are expansions of pseudo-instructions
|
||||||
// - this method should recover symbols such as labels and variables from the human written assembly, recognising
|
/// and reversing this to produce near enough the original source code.
|
||||||
// sequences that are expansions of pseduo-instructions and reversing this to produce near enough the original source code.
|
pub fn disassemble(_: Vec<Instruction>) -> String {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ assembler = { path = "../assembler" }
|
|||||||
eframe = "0.31.1"
|
eframe = "0.31.1"
|
||||||
egui = "0.31.1"
|
egui = "0.31.1"
|
||||||
rfd = "0.15.3"
|
rfd = "0.15.3"
|
||||||
|
dirs = "6.0.0"
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
sync::{
|
sync::mpsc::{self, Receiver, Sender},
|
||||||
Arc, Mutex, MutexGuard,
|
|
||||||
mpsc::{self, Receiver, Sender},
|
|
||||||
},
|
|
||||||
thread,
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
@@ -48,7 +45,7 @@ pub fn run_emulator(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(cmd) = cmd {
|
if let Some(cmd) = cmd {
|
||||||
println!("Received command: {:?}", cmd);
|
println!("Received command: {cmd:?}");
|
||||||
|
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::Start => {
|
Command::Start => {
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::emulator::system::memory::*;
|
use crate::emulator::system::memory::*;
|
||||||
|
|
||||||
use common::instructions::{
|
use common::prelude::*;
|
||||||
args::{ITypeArgs, RTypeArgs},
|
|
||||||
*,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn create_test_processor() -> Processor {
|
fn create_test_processor() -> Processor {
|
||||||
let memory = Box::new(MainStore::new());
|
let memory = Box::new(MainStore::new());
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ impl Component for Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
pub fn new(sender: Sender<Command>) -> Self {
|
#[must_use]
|
||||||
|
pub const fn new(sender: Sender<Command>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
filename: String::new(),
|
filename: String::new(),
|
||||||
text: String::new(),
|
text: String::new(),
|
||||||
@@ -75,7 +76,7 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_output(&mut self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
fn render_output(&self, _state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
||||||
// Output area with synchronized scrolling
|
// Output area with synchronized scrolling
|
||||||
egui::ScrollArea::vertical()
|
egui::ScrollArea::vertical()
|
||||||
.id_salt("output_scroll")
|
.id_salt("output_scroll")
|
||||||
@@ -117,7 +118,7 @@ impl Editor {
|
|||||||
style.visuals.widgets.inactive.bg_fill =
|
style.visuals.widgets.inactive.bg_fill =
|
||||||
egui::Color32::from_gray(30);
|
egui::Color32::from_gray(30);
|
||||||
ui.label(
|
ui.label(
|
||||||
egui::RichText::new(format!("0x{:04X}", address))
|
egui::RichText::new(format!("0x{address:04X}"))
|
||||||
.font(egui::FontId::monospace(12.0)),
|
.font(egui::FontId::monospace(12.0)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -126,26 +127,26 @@ impl Editor {
|
|||||||
// Individual bytes column
|
// Individual bytes column
|
||||||
let byte_str = chunk
|
let byte_str = chunk
|
||||||
.iter()
|
.iter()
|
||||||
.map(|b| format!("{:02X}", b))
|
.map(|b| format!("{b:02X}"))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
ui.label(
|
ui.label(
|
||||||
egui::RichText::new(format!("{:<11}", byte_str))
|
egui::RichText::new(format!("{byte_str:<11}"))
|
||||||
.font(egui::FontId::monospace(12.0))
|
.font(egui::FontId::monospace(12.0))
|
||||||
.color(egui::Color32::from_rgb(200, 200, 255)),
|
.color(egui::Color32::from_rgb(200, 200, 255)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hex column
|
// Hex column
|
||||||
ui.label(
|
ui.label(
|
||||||
egui::RichText::new(format!("0x{:08X}", value))
|
egui::RichText::new(format!("0x{value:08X}"))
|
||||||
.font(egui::FontId::monospace(12.0))
|
.font(egui::FontId::monospace(12.0))
|
||||||
.color(egui::Color32::from_rgb(255, 200, 200)),
|
.color(egui::Color32::from_rgb(255, 200, 200)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Decimal column
|
// Decimal column
|
||||||
ui.label(
|
ui.label(
|
||||||
egui::RichText::new(format!("{:10}", value))
|
egui::RichText::new(format!("{value:10}"))
|
||||||
.font(egui::FontId::monospace(12.0))
|
.font(egui::FontId::monospace(12.0))
|
||||||
.color(egui::Color32::from_rgb(200, 255, 200)),
|
.color(egui::Color32::from_rgb(200, 255, 200)),
|
||||||
);
|
);
|
||||||
@@ -184,7 +185,7 @@ impl Editor {
|
|||||||
ui.painter().text(
|
ui.painter().text(
|
||||||
line_response.rect.left_center() + egui::vec2(5.0, 0.0),
|
line_response.rect.left_center() + egui::vec2(5.0, 0.0),
|
||||||
egui::Align2::LEFT_CENTER,
|
egui::Align2::LEFT_CENTER,
|
||||||
format!("{:3}", line_num),
|
format!("{line_num:3}"),
|
||||||
egui::FontId::monospace(12.0),
|
egui::FontId::monospace(12.0),
|
||||||
ui.style().visuals.text_color(),
|
ui.style().visuals.text_color(),
|
||||||
);
|
);
|
||||||
@@ -229,18 +230,23 @@ impl Editor {
|
|||||||
|
|
||||||
// error display
|
// error display
|
||||||
ui.label(
|
ui.label(
|
||||||
egui::RichText::new(self.error.clone().unwrap_or("".to_string()))
|
egui::RichText::new(self.error.clone().unwrap_or_default())
|
||||||
.color(egui::Color32::RED),
|
.color(egui::Color32::RED),
|
||||||
);
|
);
|
||||||
|
|
||||||
// number of lines in the file
|
// number of lines in the file
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
let line_count = self.text.lines().count();
|
let line_count = self.text.lines().count();
|
||||||
ui.label(format!("Lines: {}", line_count));
|
ui.label(format!("Lines: {line_count}"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
let work_dir = std::env::current_dir().unwrap_or_else(|_| {
|
||||||
|
dirs::home_dir()
|
||||||
|
.expect("Couldn't get your current working directory or your home directory.")
|
||||||
|
});
|
||||||
|
|
||||||
ui.spacing_mut().button_padding = egui::vec2(8.0, 4.0);
|
ui.spacing_mut().button_padding = egui::vec2(8.0, 4.0);
|
||||||
ui.spacing_mut().item_spacing.x = 6.0;
|
ui.spacing_mut().item_spacing.x = 6.0;
|
||||||
|
|
||||||
@@ -249,7 +255,7 @@ impl Editor {
|
|||||||
if let Some(path) = FileDialog::new()
|
if let Some(path) = FileDialog::new()
|
||||||
.add_filter("dsafiles", &["dsa", "dsb", "dsc", "dsd"])
|
.add_filter("dsafiles", &["dsa", "dsb", "dsc", "dsd"])
|
||||||
.add_filter("all", &["*"])
|
.add_filter("all", &["*"])
|
||||||
.set_directory(std::env::current_dir().unwrap())
|
.set_directory(&work_dir)
|
||||||
.pick_file()
|
.pick_file()
|
||||||
{
|
{
|
||||||
if let Ok(content) = std::fs::read_to_string(&path) {
|
if let Ok(content) = std::fs::read_to_string(&path) {
|
||||||
@@ -266,11 +272,11 @@ impl Editor {
|
|||||||
if let Some(path) = FileDialog::new()
|
if let Some(path) = FileDialog::new()
|
||||||
.add_filter("dsafiles", &["dsa", "dsb", "dsc", "dsd"])
|
.add_filter("dsafiles", &["dsa", "dsb", "dsc", "dsd"])
|
||||||
.add_filter("all", &["*"])
|
.add_filter("all", &["*"])
|
||||||
.set_directory(std::env::current_dir().unwrap())
|
.set_directory(&work_dir)
|
||||||
.save_file()
|
.save_file()
|
||||||
{
|
{
|
||||||
if let Err(e) = std::fs::write(&path, &self.text) {
|
if let Err(why) = std::fs::write(&path, &self.text) {
|
||||||
self.error = Some(format!("Failed to save file: {}", e));
|
self.error = Some(format!("Failed to save file: {why}"));
|
||||||
} else {
|
} else {
|
||||||
self.filename = path.display().to_string();
|
self.filename = path.display().to_string();
|
||||||
}
|
}
|
||||||
@@ -279,7 +285,7 @@ impl Editor {
|
|||||||
|
|
||||||
// builds the current file
|
// builds the current file
|
||||||
if ui.button("Build").clicked() {
|
if ui.button("Build").clicked() {
|
||||||
let instructions = assembler::assemble(&self.text);
|
let _instructions = assembler::assemble(&self.text);
|
||||||
|
|
||||||
// TODO: uncomment this once assembler works!!!
|
// TODO: uncomment this once assembler works!!!
|
||||||
// self.output = instructions
|
// self.output = instructions
|
||||||
@@ -322,13 +328,18 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_address(address: &str) -> Option<u32> {
|
fn parse_address(address: &str) -> Option<u32> {
|
||||||
if address.starts_with("0x") {
|
address.strip_prefix("0x").map_or_else(
|
||||||
u32::from_str_radix(&address[2..], 16).ok()
|
|| {
|
||||||
} else if address.starts_with("0b") {
|
address.strip_prefix("0b").map_or_else(
|
||||||
u32::from_str_radix(&address[2..], 2).ok()
|
|| {
|
||||||
} else if address.starts_with("0o") {
|
address.strip_prefix("0o").map_or_else(
|
||||||
u32::from_str_radix(&address[2..], 8).ok()
|
|| address.parse::<u32>().ok(),
|
||||||
} else {
|
|oct| u32::from_str_radix(oct, 8).ok(),
|
||||||
address.parse::<u32>().ok()
|
)
|
||||||
}
|
},
|
||||||
|
|bin| u32::from_str_radix(bin, 2).ok(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|hex| u32::from_str_radix(hex, 16).ok(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
use std::{
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
|
use dsa_rs::emulator::{
|
||||||
|
system::{emulator::run_emulator, memory::MainStore, processor::Processor},
|
||||||
|
ui::{
|
||||||
|
control_unit::ControlPanel, interface::EmulatorUI, memory_inspector::MemoryInspector,
|
||||||
|
stack_inspector::StackInspector,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() -> Result<(), eframe::Error> {
|
||||||
|
// Initialize Channels
|
||||||
|
let (cmd_sender, cmd_receiver) = std::sync::mpsc::channel();
|
||||||
|
let (state_sender, state_receiver) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
|
let mainstore = MainStore::new();
|
||||||
|
let processor = Processor::new(Box::new(mainstore), vec![]);
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
run_emulator(&cmd_receiver, &state_sender, processor);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create UI
|
||||||
|
let mut ui = EmulatorUI::new(cmd_sender.clone(), state_receiver);
|
||||||
|
|
||||||
|
// Create UI modules
|
||||||
|
let control_unit = ControlPanel::new(cmd_sender.clone());
|
||||||
|
ui.add_component(Box::new(control_unit));
|
||||||
|
|
||||||
|
let mem_inspector = MemoryInspector::new(cmd_sender.clone());
|
||||||
|
ui.add_component(Box::new(mem_inspector));
|
||||||
|
|
||||||
|
let stack_inspector = StackInspector::new();
|
||||||
|
ui.add_component(Box::new(stack_inspector));
|
||||||
|
|
||||||
|
// Run UI
|
||||||
|
let options = eframe::NativeOptions {
|
||||||
|
viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
eframe::run_native(
|
||||||
|
"DSA Simulator (Damn Simple Architecture 🔥)",
|
||||||
|
options,
|
||||||
|
Box::new(move |cc| {
|
||||||
|
cc.egui_ctx.set_visuals(egui::Visuals::default());
|
||||||
|
Ok(Box::new(ui))
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user