idk
This commit is contained in:
@@ -11,10 +11,9 @@ pub fn lexer(mut program: String, module: u64) -> Result<Vec<Token>, AssembleErr
|
||||
|
||||
program = program.replace(",", "");
|
||||
let lines = program.lines();
|
||||
let mut literal;
|
||||
let mut literal = String::new();
|
||||
|
||||
for line in lines {
|
||||
literal = String::new();
|
||||
for token in line.split_whitespace() {
|
||||
if token.starts_with("//") {
|
||||
break;
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::{
|
||||
use crate::emulator::misc::rpc::{Activity, RpcClient};
|
||||
|
||||
use crate::emulator::system::{
|
||||
model::{Command, Running, State},
|
||||
model::{Command, PersistentState, Running, State},
|
||||
processor::Processor,
|
||||
};
|
||||
|
||||
@@ -70,10 +70,26 @@ pub fn run_emulator(
|
||||
Command::Stop => {
|
||||
running = Running::Paused;
|
||||
}
|
||||
Command::Reset => {
|
||||
Command::Reset(x) => {
|
||||
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();
|
||||
instruction_count = 0;
|
||||
}
|
||||
Command::Step => {
|
||||
running = Running::Paused;
|
||||
@@ -158,6 +174,8 @@ pub fn run_emulator(
|
||||
memory_view,
|
||||
&mut history,
|
||||
);
|
||||
println!("running state");
|
||||
// println!("state!!! {:?}", state.history);
|
||||
let _ = state_tx.send(state);
|
||||
}
|
||||
} else {
|
||||
@@ -185,6 +203,6 @@ fn state(
|
||||
memory_view,
|
||||
display_view: cpu_lock.display(),
|
||||
error: None,
|
||||
history: hsclone,
|
||||
persistent: PersistentState { history: hsclone },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub enum Command {
|
||||
Start,
|
||||
Stop,
|
||||
Step,
|
||||
Reset,
|
||||
Reset(usize),
|
||||
Interrupt(Interrupt),
|
||||
|
||||
// Performs direct read/write operations on the emulator's memory.
|
||||
@@ -205,8 +205,9 @@ pub struct State {
|
||||
pub stack_view: Vec<u8>,
|
||||
pub memory_view: Vec<u8>,
|
||||
pub display_view: Vec<u8>,
|
||||
pub history: Vec<(u32, Instruction)>,
|
||||
pub error: Option<String>,
|
||||
|
||||
pub persistent: PersistentState,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
@@ -218,8 +219,29 @@ impl Default for State {
|
||||
stack_view: vec![],
|
||||
memory_view: vec![],
|
||||
display_view: vec![],
|
||||
history: vec![],
|
||||
persistent: PersistentState::default(),
|
||||
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
|
||||
// run memory.reset()
|
||||
self.registers.reset();
|
||||
}
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.memory.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
// Status info
|
||||
|
||||
@@ -12,17 +12,24 @@ use crate::emulator::{
|
||||
};
|
||||
|
||||
pub struct Editor {
|
||||
// editor state
|
||||
path: Option<PathBuf>,
|
||||
unsaved: bool,
|
||||
text: String,
|
||||
buffer: String,
|
||||
unsaved: bool,
|
||||
|
||||
// output / loading
|
||||
output: Vec<u8>,
|
||||
sender: Sender<Command>,
|
||||
cursor_col: usize,
|
||||
cursor_line: usize,
|
||||
visible: bool,
|
||||
load_offset: u32,
|
||||
offset_str: String,
|
||||
|
||||
// cursor - currently unused
|
||||
cursor_col: usize,
|
||||
cursor_line: usize,
|
||||
|
||||
// other
|
||||
visible: bool,
|
||||
sender: Sender<Command>,
|
||||
error: Option<String>,
|
||||
}
|
||||
|
||||
@@ -372,13 +379,6 @@ impl Editor {
|
||||
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());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
use std::{ffi::OsStr, path::PathBuf, sync::mpsc::Sender};
|
||||
use egui::{Context, Ui};
|
||||
|
||||
use common::prelude::Instruction;
|
||||
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,
|
||||
};
|
||||
use crate::emulator::{system::model::State, ui::interface::Component};
|
||||
|
||||
pub struct History {
|
||||
visible: bool,
|
||||
history: Vec<(u32, Instruction)>,
|
||||
}
|
||||
|
||||
impl Component for History {
|
||||
@@ -29,14 +19,12 @@ impl Component for History {
|
||||
super::interface::Category::Control
|
||||
}
|
||||
|
||||
fn render(&mut self, state: &mut State, ui: &mut Ui, ctx: &Context) {
|
||||
self.update(state);
|
||||
|
||||
fn render(&mut self, state: &mut State, ui: &mut Ui, _ctx: &Context) {
|
||||
egui::ScrollArea::vertical()
|
||||
.id_salt("output_scroll")
|
||||
.max_width(400.0)
|
||||
.show(ui, |ui| {
|
||||
if self.history.is_empty() {
|
||||
if state.persistent.history.is_empty() {
|
||||
ui.label(
|
||||
egui::RichText::new("No output data")
|
||||
.font(egui::FontId::monospace(12.0))
|
||||
@@ -51,7 +39,9 @@ impl Component for History {
|
||||
.striped(false)
|
||||
.show(ui, |ui| {
|
||||
// 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));
|
||||
|
||||
// Hex column
|
||||
@@ -78,18 +68,6 @@ impl Component for History {
|
||||
impl History {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
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);
|
||||
}
|
||||
Self { visible: false }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
pub trait Component {
|
||||
@@ -37,6 +37,7 @@ pub struct EmulatorUI {
|
||||
pub sender: Sender<Command>,
|
||||
pub receiver: Receiver<State>,
|
||||
pub state: State,
|
||||
pub persistent: PersistentState,
|
||||
pub components: Vec<Box<dyn Component>>,
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@ impl EmulatorUI {
|
||||
sender,
|
||||
receiver,
|
||||
state: State::default(),
|
||||
persistent: PersistentState::default(),
|
||||
components: vec![],
|
||||
}
|
||||
}
|
||||
@@ -58,6 +60,8 @@ impl EmulatorUI {
|
||||
fn update_state(&mut self) {
|
||||
while let Ok(state) = self.receiver.try_recv() {
|
||||
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| {
|
||||
// interface::bottompanel::render_bottom_panel(self, ui, ctx);
|
||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,11 @@ include print "../resources/dsa/print.dsa"
|
||||
include fib "../resources/dsa/fib.dsa"
|
||||
|
||||
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:
|
||||
ldw stack, bpr
|
||||
|
||||
Reference in New Issue
Block a user