diff --git a/common/src/instructions.rs b/common/src/instructions.rs index b27675d..952033c 100644 --- a/common/src/instructions.rs +++ b/common/src/instructions.rs @@ -18,7 +18,8 @@ impl Interrupt { // TODO: This should be TryFrom. impl From for Interrupt { #[allow(unreachable_code)] - fn from(_code: u8) -> Self { + fn from(code: u8) -> Self { + return Self::Software(code); todo!("Implement this once a hardware interrupt convention is established."); // Self::Software(_code) diff --git a/emulator/src/emulator/system/processor/mod.rs b/emulator/src/emulator/system/processor/mod.rs index 85602b1..ecdbf54 100644 --- a/emulator/src/emulator/system/processor/mod.rs +++ b/emulator/src/emulator/system/processor/mod.rs @@ -17,6 +17,8 @@ pub struct Processor { pub registers: RegFile, pub halted: bool, pub io_devices: Vec>, + + pub dustbin: u32, } #[allow(clippy::needless_pass_by_ref_mut)] @@ -28,6 +30,7 @@ impl Processor { registers: RegFile::default(), halted: false, io_devices, + dustbin: 0, } } @@ -59,8 +62,12 @@ impl Processor { // Decode and execute the instruction. let instruction = Instruction::decode(val)?; + println!("Executing instruction: {instruction}"); + instruction.execute(self); + println!("ok!"); + Ok((addr, instruction)) } @@ -74,7 +81,10 @@ impl Processor { } pub fn reg(&mut self, reg: Register) -> &mut u32 { - self.registers.reg(reg) + match reg { + Register::Zero => &mut self.dustbin, + _ => self.registers.reg(reg), + } } pub fn display(&mut self) -> Vec { diff --git a/emulator/src/emulator/ui/editor.rs b/emulator/src/emulator/ui/editor.rs index 98cc1c2..6d55504 100644 --- a/emulator/src/emulator/ui/editor.rs +++ b/emulator/src/emulator/ui/editor.rs @@ -176,11 +176,31 @@ impl Editor { .set_directory(&work_dir) .pick_file() { - if let Ok(contents) = std::fs::read_to_string(&path) { - self.path = Some(path.clone()); - self.text.clone_from(&contents); - self.buffer = contents; - self.unsaved = false; + match path.extension().and_then(|ext| ext.to_str()) { + Some("dsb") => { + let contents = match std::fs::read(&path) { + Ok(contents) => contents, + Err(why) => { + self.error = Some(format!("Failed to read file: {why}")); + return; + } + }; + + self.path = Some(path.clone()); + self.output = contents; + self.unsaved = false; + self.text = String::from("Loaded Binary File!"); + self.buffer = self.text.clone(); + self.unsaved = false; + } + _ => { + if let Ok(contents) = std::fs::read_to_string(&path) { + self.path = Some(path.clone()); + self.text.clone_from(&contents); + self.buffer = contents; + self.unsaved = false; + } + } } std::env::set_current_dir( @@ -346,22 +366,14 @@ impl Editor { // builds the current file if ui.button("Build").clicked() && !self.unsaved { if let Some(path) = &self.path { - let mut assembler = CompilerEngine::new(); - if let Err(error) = assembler.assemble(path) { - self.error = Some(format!("Failed to assemble: {error:?}")); - return; - } + let mut compiler = CompilerEngine::new(); + compiler.start_compilation(path); - let instructions = match assembler.result() { - Some(Ok(instructions)) => instructions, - Some(Err(error)) => { - self.error = Some(format!("Failed to assemble: {error:?}")); - return; - } - None => { - self.error = Some( - "Failed to assemble: No result available".to_string(), - ); + // Or block until done + let instructions = match compiler.wait_for_result() { + Ok(instructions) => instructions, + Err(e) => { + self.error = Some(e.to_string()); return; } };