This commit is contained in:
2025-06-19 15:18:48 +01:00
parent 5784beafbc
commit e308362533
9 changed files with 128 additions and 55 deletions
+1 -2
View File
@@ -11,10 +11,9 @@ pub fn lexer(mut program: String, module: u64) -> Result<Vec<Token>, AssembleErr
program = program.replace(",", ""); program = program.replace(",", "");
let lines = program.lines(); let lines = program.lines();
let mut literal; let mut literal = String::new();
for line in lines { for line in lines {
literal = String::new();
for token in line.split_whitespace() { for token in line.split_whitespace() {
if token.starts_with("//") { if token.starts_with("//") {
break; break;
+22 -4
View File
@@ -10,7 +10,7 @@ use std::{
use crate::emulator::misc::rpc::{Activity, RpcClient}; use crate::emulator::misc::rpc::{Activity, RpcClient};
use crate::emulator::system::{ use crate::emulator::system::{
model::{Command, Running, State}, model::{Command, PersistentState, Running, State},
processor::Processor, processor::Processor,
}; };
@@ -70,10 +70,26 @@ pub fn run_emulator(
Command::Stop => { Command::Stop => {
running = Running::Paused; running = Running::Paused;
} }
Command::Reset => { Command::Reset(x) => {
running = Running::Paused; running = Running::Paused;
match x {
0 => {
processor.clear();
processor.reset();
instruction_count = 0;
}
1 => {
processor.reset();
instruction_count = 0;
}
2 => {
processor.clear();
}
_ => unreachable!(),
}
processor.reset(); processor.reset();
instruction_count = 0;
} }
Command::Step => { Command::Step => {
running = Running::Paused; running = Running::Paused;
@@ -158,6 +174,8 @@ pub fn run_emulator(
memory_view, memory_view,
&mut history, &mut history,
); );
println!("running state");
// println!("state!!! {:?}", state.history);
let _ = state_tx.send(state); let _ = state_tx.send(state);
} }
} else { } else {
@@ -185,6 +203,6 @@ fn state(
memory_view, memory_view,
display_view: cpu_lock.display(), display_view: cpu_lock.display(),
error: None, error: None,
history: hsclone, persistent: PersistentState { history: hsclone },
} }
} }
+25 -3
View File
@@ -19,7 +19,7 @@ pub enum Command {
Start, Start,
Stop, Stop,
Step, Step,
Reset, Reset(usize),
Interrupt(Interrupt), Interrupt(Interrupt),
// Performs direct read/write operations on the emulator's memory. // Performs direct read/write operations on the emulator's memory.
@@ -205,8 +205,9 @@ pub struct State {
pub stack_view: Vec<u8>, pub stack_view: Vec<u8>,
pub memory_view: Vec<u8>, pub memory_view: Vec<u8>,
pub display_view: Vec<u8>, pub display_view: Vec<u8>,
pub history: Vec<(u32, Instruction)>,
pub error: Option<String>, pub error: Option<String>,
pub persistent: PersistentState,
} }
impl Default for State { impl Default for State {
@@ -218,8 +219,29 @@ impl Default for State {
stack_view: vec![], stack_view: vec![],
memory_view: vec![], memory_view: vec![],
display_view: vec![], display_view: vec![],
history: vec![], persistent: PersistentState::default(),
error: None, error: None,
} }
} }
} }
#[derive(Clone, Debug)]
pub struct PersistentState {
pub history: Vec<(u32, Instruction)>,
}
impl Default for PersistentState {
fn default() -> Self {
Self { history: vec![] }
}
}
impl PersistentState {
pub fn update(&mut self, new_state: &PersistentState) {
self.history.extend(new_state.history.clone());
if self.history.len() > 32768 {
let len = self.history.len() - 32768;
self.history.drain(..len);
}
}
}
@@ -35,6 +35,9 @@ impl Processor {
// set all registers to zero // set all registers to zero
// run memory.reset() // run memory.reset()
self.registers.reset(); self.registers.reset();
}
pub fn clear(&mut self) {
self.memory.reset(); self.memory.reset();
} }
+21
View File
@@ -64,6 +64,27 @@ impl Component for ControlPanel {
}); });
} }
// Resets the emulator and all attached devices
if ui.button("Reset All").clicked() {
self.sender.send(Command::Reset(0)).unwrap_or_else(|_| {
state.error = Some("Failed to send command".to_string());
});
}
// Resets the emulator and all attached devices
if ui.button("Clear Registers").clicked() {
self.sender.send(Command::Reset(1)).unwrap_or_else(|_| {
state.error = Some("Failed to send command".to_string());
});
}
// Resets the emulator and all attached devices
if ui.button("Clear RAM").clicked() {
self.sender.send(Command::Reset(2)).unwrap_or_else(|_| {
state.error = Some("Failed to send command".to_string());
});
}
ui.separator(); ui.separator();
// Status info // Status info
+12 -12
View File
@@ -12,17 +12,24 @@ use crate::emulator::{
}; };
pub struct Editor { pub struct Editor {
// editor state
path: Option<PathBuf>, path: Option<PathBuf>,
unsaved: bool,
text: String, text: String,
buffer: String, buffer: String,
unsaved: bool,
// output / loading
output: Vec<u8>, output: Vec<u8>,
sender: Sender<Command>,
cursor_col: usize,
cursor_line: usize,
visible: bool,
load_offset: u32, load_offset: u32,
offset_str: String, offset_str: String,
// cursor - currently unused
cursor_col: usize,
cursor_line: usize,
// other
visible: bool,
sender: Sender<Command>,
error: Option<String>, error: Option<String>,
} }
@@ -372,13 +379,6 @@ impl Editor {
self.error = Some("Invalid offset".to_string()); self.error = Some("Invalid offset".to_string());
} }
} }
// Resets the emulator and all attached devices
if ui.button("Reset Emulator").clicked() {
self.sender.send(Command::Reset).unwrap_or_else(|_| {
self.error = Some("Failed to send command".to_string());
});
}
}); });
} }
} }
+8 -30
View File
@@ -1,19 +1,9 @@
use std::{ffi::OsStr, path::PathBuf, sync::mpsc::Sender}; use egui::{Context, Ui};
use common::prelude::Instruction; use crate::emulator::{system::model::State, ui::interface::Component};
use egui::{Align, Context, Key, Layout, Ui};
use rfd::FileDialog;
use dsa_editor::{CodeEditor, ColorTheme, Syntax};
use crate::emulator::{
system::model::{Command, State},
ui::interface::Component,
};
pub struct History { pub struct History {
visible: bool, visible: bool,
history: Vec<(u32, Instruction)>,
} }
impl Component for History { impl Component for History {
@@ -29,14 +19,12 @@ impl Component for History {
super::interface::Category::Control super::interface::Category::Control
} }
fn render(&mut self, state: &mut State, ui: &mut Ui, ctx: &Context) { fn render(&mut self, state: &mut State, ui: &mut Ui, _ctx: &Context) {
self.update(state);
egui::ScrollArea::vertical() egui::ScrollArea::vertical()
.id_salt("output_scroll") .id_salt("output_scroll")
.max_width(400.0) .max_width(400.0)
.show(ui, |ui| { .show(ui, |ui| {
if self.history.is_empty() { if state.persistent.history.is_empty() {
ui.label( ui.label(
egui::RichText::new("No output data") egui::RichText::new("No output data")
.font(egui::FontId::monospace(12.0)) .font(egui::FontId::monospace(12.0))
@@ -51,7 +39,9 @@ impl Component for History {
.striped(false) .striped(false)
.show(ui, |ui| { .show(ui, |ui| {
// Process bytes in chunks of 4 // Process bytes in chunks of 4
for (idx, instruction) in self.history.iter().enumerate() { for (idx, instruction) in
state.persistent.history.iter().enumerate()
{
ui.label(format!("{}: ", idx)); ui.label(format!("{}: ", idx));
// Hex column // Hex column
@@ -78,18 +68,6 @@ impl Component for History {
impl History { impl History {
#[must_use] #[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self { visible: false }
visible: false,
history: Vec::with_capacity(1000),
}
}
fn update(&mut self, state: &mut State) {
self.history.extend(state.history.clone());
state.history.clear();
if self.history.len() > 1000 {
let len = self.history.len() - 1000;
self.history.drain(..len);
}
} }
} }
+31 -3
View File
@@ -1,4 +1,4 @@
use crate::emulator::system::model::{Command, Running, State}; use crate::emulator::system::model::{Command, PersistentState, Running, State};
use std::sync::mpsc::{Receiver, Sender}; use std::sync::mpsc::{Receiver, Sender};
pub trait Component { pub trait Component {
@@ -37,6 +37,7 @@ pub struct EmulatorUI {
pub sender: Sender<Command>, pub sender: Sender<Command>,
pub receiver: Receiver<State>, pub receiver: Receiver<State>,
pub state: State, pub state: State,
pub persistent: PersistentState,
pub components: Vec<Box<dyn Component>>, pub components: Vec<Box<dyn Component>>,
} }
@@ -47,6 +48,7 @@ impl EmulatorUI {
sender, sender,
receiver, receiver,
state: State::default(), state: State::default(),
persistent: PersistentState::default(),
components: vec![], components: vec![],
} }
} }
@@ -58,6 +60,8 @@ impl EmulatorUI {
fn update_state(&mut self) { fn update_state(&mut self) {
while let Ok(state) = self.receiver.try_recv() { while let Ok(state) = self.receiver.try_recv() {
self.state = state; self.state = state;
self.persistent.update(&self.state.persistent);
self.state.persistent = self.persistent.clone();
} }
} }
} }
@@ -105,8 +109,32 @@ impl eframe::App for EmulatorUI {
}); });
}); });
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |_ui| { egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
// interface::bottompanel::render_bottom_panel(self, ui, ctx); ui.horizontal_centered(|ui| {
ui.group(|ui| {
ui.add_space(10.0);
ui.strong("Authors:");
ui.add_space(5.0);
ui.label("zxq5");
ui.label("nullndvoid");
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.strong("Version");
ui.add_space(5.0);
ui.label("1.0.0");
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.strong("Source:");
ui.add_space(5.0);
ui.hyperlink_to(
"https://git.zxq5.dev/LowLevelDevs/damn_simple_architecture",
"https://git.zxq5.dev/LowLevelDevs/damn_simple_architecture",
);
ui.add_space(10.0);
});
});
}); });
} }
} }
+5 -1
View File
@@ -2,7 +2,11 @@ include print "../resources/dsa/print.dsa"
include fib "../resources/dsa/fib.dsa" include fib "../resources/dsa/fib.dsa"
dw stack: 0x10000 dw stack: 0x10000
db string: "An idiot admires complexity, a genius admires simplicity, a physicist tries to make it simple, for an idiot anything the more complicated it is the more he will admire it, if you make something so clusterfucked he can't understand it he's gonna think you're a god cause you made it so complicated nobody can understand it. That's how they write journals in Academics, they try to make it so complicated people think you're a genius" db string: "An idiot admires complexity, a genius admires simplicity,
a physicist tries to make it simple, for an idiot anything the more complicated it is,
the more he will admire it, if you make something so clusterfucked he can't understand it he's
gonna think you're a god cause you made it so complicated nobody can understand it.
That's how they write journals in Academics, they try to make it so complicated people think you're a genius"
init: init:
ldw stack, bpr ldw stack, bpr