refactor 2 electric boogaloo

This commit is contained in:
2025-06-15 21:40:43 +01:00
parent 277f210b3e
commit 2b8281157e
30 changed files with 125 additions and 71 deletions
Generated
+20 -14
View File
@@ -231,6 +231,10 @@ dependencies = [
"zbus 5.7.1",
]
[[package]]
name = "assembler"
version = "0.2.0"
[[package]]
name = "async-broadcast"
version = "0.7.2"
@@ -656,6 +660,10 @@ dependencies = [
"memchr",
]
[[package]]
name = "common"
version = "0.2.0"
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@@ -755,15 +763,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
[[package]]
name = "damn_simple_architecture"
version = "0.1.0"
dependencies = [
"eframe",
"egui",
"rfd",
]
[[package]]
name = "digest"
version = "0.10.7"
@@ -972,6 +971,16 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "emulator"
version = "0.1.0"
dependencies = [
"common",
"eframe",
"egui",
"rfd",
]
[[package]]
name = "endi"
version = "1.1.0"
@@ -2643,12 +2652,9 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "slab"
version = "0.4.9"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
dependencies = [
"autocfg",
]
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
[[package]]
name = "slotmap"
+6 -12
View File
@@ -1,13 +1,7 @@
[package]
name = "damn_simple_architecture"
version = "0.1.0"
[workspace]
members = ["emulator", "common", "assembler"]
[workspace.package]
version = "0.2.0"
edition = "2024"
[lib]
name = "dsa_rs"
path = "src/lib.rs"
[dependencies]
eframe = "0.31.1"
egui = "0.31.1"
rfd = "0.15.3"
authors = ["zxq5", "nullndvoid"]
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "assembler"
version.workspace = true
edition.workspace = true
authors.workspace = true
[dependencies]
+14
View File
@@ -0,0 +1,14 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "common"
version.workspace = true
edition.workspace = true
authors.workspace = true
[dependencies]
@@ -1,4 +1,4 @@
use crate::common::{instructions::encode::Encode, prelude::*};
use crate::{instructions::encode::Encode, prelude::*};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Interrupt {
@@ -1,7 +1,9 @@
//! Various types of arguments that instructions can take, alongside encoding and decoding logic.
use crate::common::instructions::Encode;
use crate::common::prelude::*;
use crate::{
instructions::{RegisterParseError, encode::Encode},
prelude::Register,
};
/// A list of errors that can be returned when decoding instruction arguments.
#[derive(Debug)]
@@ -1,4 +1,4 @@
use crate::common::prelude::*;
use crate::prelude::*;
/// Not to be used directly, just call [`Instruction::encode`].
pub trait Encode {
@@ -1,4 +1,4 @@
use crate::common::prelude::*;
use crate::prelude::*;
#[test]
fn test_encode_nop() {
@@ -1,6 +1,6 @@
//! All the errors that may be returned from [`instructions`].
use crate::common::prelude::*;
use crate::prelude::*;
#[derive(Debug)]
/// Error type for parsing register numbers.
@@ -1,5 +1,5 @@
#![allow(clippy::unwrap_used)]
use crate::common::prelude::*;
use crate::prelude::*;
#[test]
fn test_opcode_nop() {
+22
View File
@@ -0,0 +1,22 @@
#![deny(
clippy::unwrap_used,
clippy::nursery,
clippy::perf,
clippy::pedantic,
clippy::complexity
)]
#![allow(
clippy::cast_possible_truncation,
clippy::missing_panics_doc,
clippy::missing_errors_doc,
clippy::match_wildcard_for_single_variants
)]
pub mod instructions;
pub mod prelude {
//! A collection of types you should definitely import when working with this crate.
pub use super::instructions::{
Address, Instruction, InstructionType, Interrupt, Register, args::*, errors::*,
};
}
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "emulator"
version = "0.1.0"
edition = "2024"
[lib]
name = "dsa_rs"
path = "src/lib.rs"
[dependencies]
common = { path = "../common" }
eframe = "0.31.1"
egui = "0.31.1"
rfd = "0.15.3"
@@ -7,14 +7,13 @@ use std::{
time::Duration,
};
use crate::{
common::instructions::{Instruction, Register},
emulator::system::{
use crate::emulator::system::{
model::{Command, Running, State},
processor::Processor,
},
};
use common::instructions::{Instruction, Register};
pub fn run_emulator(
cmd_rx: &Receiver<Command>,
state_tx: &Sender<State>,
@@ -1,4 +1,4 @@
use crate::common::prelude::*;
use common::prelude::*;
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum Running {
@@ -3,14 +3,13 @@ use std::{
sync::Arc,
};
use crate::{
common::instructions::{Instruction, Interrupt, Register, errors::InstructionDecodeError},
emulator::system::{
use crate::emulator::system::{
memory::MemoryUnit,
model::{IODevice, RegFile},
},
};
use common::instructions::{Instruction, Interrupt, Register, errors::InstructionDecodeError};
pub struct Processor {
pub memory: Box<dyn MemoryUnit>,
pub registers: RegFile,
@@ -356,6 +355,8 @@ impl Executable for Instruction {
Self::Halt => {
cpu.halted = true;
}
_ => todo!(),
}
}
}
@@ -1,10 +1,9 @@
use super::*;
use crate::{
common::instructions::{
use crate::emulator::system::memory::*;
use common::instructions::{
args::{ITypeArgs, RTypeArgs},
*,
},
emulator::system::memory::*,
};
fn create_test_processor() -> Processor {
@@ -1,13 +1,12 @@
use std::sync::mpsc::Sender;
use crate::{
common::instructions::Register,
emulator::{
use crate::emulator::{
system::model::{Command, Running, State},
ui::interface::Component,
},
};
use common::instructions::Register;
pub struct ControlPanel {
visible: bool,
sender: Sender<Command>,
@@ -1,7 +1,6 @@
use crate::{
common::instructions::Register,
emulator::{system::model::State, ui::interface::Component},
};
use crate::emulator::{system::model::State, ui::interface::Component};
use common::instructions::Register;
pub struct StackInspector {
visible: bool,
-1
View File
@@ -12,5 +12,4 @@
clippy::match_wildcard_for_single_variants
)]
pub mod common;
pub mod emulator;
-8
View File
@@ -1,8 +0,0 @@
pub mod instructions;
pub mod prelude {
//! A collection of types you should definitely import when working with this crate.
pub use super::instructions::{
Address, Instruction, InstructionType, Interrupt, Register, args::*, errors::*,
};
}