From 2b5ad0885b0ab3a1bda03329edfdac457320fdb0 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Sun, 15 Jun 2025 21:53:57 +0100 Subject: [PATCH] added assembler skeleton code --- Cargo.lock | 4 ++++ assembler/Cargo.toml | 1 + assembler/src/lib.rs | 20 ++++++++++---------- emulator/Cargo.toml | 1 + emulator/src/emulator/ui/editor.rs | 8 ++++++++ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4fdd04..d768acb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -234,6 +234,9 @@ dependencies = [ [[package]] name = "assembler" version = "0.2.0" +dependencies = [ + "common", +] [[package]] name = "async-broadcast" @@ -975,6 +978,7 @@ dependencies = [ name = "emulator" version = "0.1.0" dependencies = [ + "assembler", "common", "eframe", "egui", diff --git a/assembler/Cargo.toml b/assembler/Cargo.toml index 6e1cb35..a9c19f8 100644 --- a/assembler/Cargo.toml +++ b/assembler/Cargo.toml @@ -5,3 +5,4 @@ edition.workspace = true authors.workspace = true [dependencies] +common = { path = "../common" } \ No newline at end of file diff --git a/assembler/src/lib.rs b/assembler/src/lib.rs index b93cf3f..0e15029 100644 --- a/assembler/src/lib.rs +++ b/assembler/src/lib.rs @@ -1,14 +1,14 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right +use common::prelude::Instruction; + +pub fn assemble(src: &str) -> Vec { + todo!() } -#[cfg(test)] -mod tests { - use super::*; +pub fn disassemble(binary: Vec) -> String { + // TODO: disassembling functionality - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } + // - 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 written assembly, recognising + // sequences that are expansions of pseduo-instructions and reversing this to produce near enough the original source code. + todo!() } diff --git a/emulator/Cargo.toml b/emulator/Cargo.toml index edd81b5..f353d11 100644 --- a/emulator/Cargo.toml +++ b/emulator/Cargo.toml @@ -9,6 +9,7 @@ path = "src/lib.rs" [dependencies] common = { path = "../common" } +assembler = { path = "../assembler" } eframe = "0.31.1" egui = "0.31.1" rfd = "0.15.3" \ No newline at end of file diff --git a/emulator/src/emulator/ui/editor.rs b/emulator/src/emulator/ui/editor.rs index 0f7a93d..a6bbf7f 100644 --- a/emulator/src/emulator/ui/editor.rs +++ b/emulator/src/emulator/ui/editor.rs @@ -279,6 +279,14 @@ impl Editor { // builds the current file if ui.button("Build").clicked() { + let instructions = assembler::assemble(&self.text); + + // TODO: uncomment this once assembler works!!! + // self.output = instructions + // .iter() + // .flat_map(|i| i.encode().to_le_bytes().to_vec()) + // .collect(); + self.output = vec![0x00; 256]; }