editor changes
This commit is contained in:
@@ -116,6 +116,40 @@ impl TryFrom<u8> for Register {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Register {
|
||||
type Error = RegisterParseError;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
match value.to_lowercase().as_str() {
|
||||
"rg0" => Ok(Self::Rg0),
|
||||
"rg1" => Ok(Self::Rg1),
|
||||
"rg2" => Ok(Self::Rg2),
|
||||
"rg3" => Ok(Self::Rg3),
|
||||
"rg4" => Ok(Self::Rg4),
|
||||
"rg5" => Ok(Self::Rg5),
|
||||
"rg6" => Ok(Self::Rg6),
|
||||
"rg7" => Ok(Self::Rg7),
|
||||
"rg8" => Ok(Self::Rg8),
|
||||
"rg9" => Ok(Self::Rg9),
|
||||
"rga" => Ok(Self::Rga),
|
||||
"rgb" => Ok(Self::Rgb),
|
||||
"rgc" => Ok(Self::Rgc),
|
||||
"rgd" => Ok(Self::Rgd),
|
||||
"rge" => Ok(Self::Rge),
|
||||
"rgf" => Ok(Self::Rgf),
|
||||
"acc" => Ok(Self::Acc),
|
||||
"spr" => Ok(Self::Spr),
|
||||
"bpr" => Ok(Self::Bpr),
|
||||
"ret" => Ok(Self::Ret),
|
||||
"idr" => Ok(Self::Idr),
|
||||
"mmr" => Ok(Self::Mmr),
|
||||
"zero" => Ok(Self::Zero),
|
||||
"null" => Ok(Self::NoReg),
|
||||
_ => Err(RegisterParseError::InvalidName(value.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Register {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
@@ -16,6 +16,7 @@ impl From<RegisterParseError> for ArgsDecodeError {
|
||||
fn from(value: RegisterParseError) -> Self {
|
||||
match value {
|
||||
RegisterParseError::InvalidIndex(idx) => Self::InvalidRegister(idx),
|
||||
RegisterParseError::InvalidName(_) => Self::InvalidRegister(0xFF),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ use crate::prelude::*;
|
||||
/// Error type for parsing register numbers.
|
||||
pub enum RegisterParseError {
|
||||
InvalidIndex(u8),
|
||||
InvalidName(String),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RegisterParseError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::InvalidIndex(idx) => write!(f, "invalid index given ({idx})"),
|
||||
Self::InvalidName(name) => write!(f, "invalid name given ({name})"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::emulator::{
|
||||
ui::interface::Component,
|
||||
};
|
||||
|
||||
use common::instructions::Register;
|
||||
use common::{instructions::Register, prelude::Instruction};
|
||||
|
||||
pub struct ControlPanel {
|
||||
visible: bool,
|
||||
@@ -77,11 +77,13 @@ impl Component for ControlPanel {
|
||||
));
|
||||
ui.label(format!("Instructions: {}", state.instructions));
|
||||
ui.label(format!("PC: 0x{:08X}", state.reg_file.get(Register::Pcx)));
|
||||
ui.label(format!(
|
||||
"Last Instruction: {:?}",
|
||||
"TODO: DECODE INSTRUCTION" // TODO: decode instruction
|
||||
// Instruction::decode(state.current_state.cir)
|
||||
));
|
||||
|
||||
let instruction = match Instruction::decode(state.reg_file.get(Register::Cir)) {
|
||||
Ok(instruction) => instruction.to_string(),
|
||||
Err(_) => "Invalid Instruction".to_string(),
|
||||
};
|
||||
|
||||
ui.label(format!("Instruction: {}", instruction));
|
||||
});
|
||||
|
||||
render_register_table(state, ui, ctx);
|
||||
|
||||
@@ -279,9 +279,8 @@ impl Editor {
|
||||
|
||||
// builds the current file
|
||||
if ui.button("Build").clicked() {
|
||||
let instructions = assembler::assemble(&self.text);
|
||||
|
||||
// TODO: uncomment this once assembler works!!!
|
||||
// let instructions = assembler::assemble(&self.text);
|
||||
// self.output = instructions
|
||||
// .iter()
|
||||
// .flat_map(|i| i.encode().to_le_bytes().to_vec())
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::{num::ParseIntError, sync::mpsc::Sender};
|
||||
|
||||
use common::prelude::Instruction;
|
||||
|
||||
use crate::emulator::{
|
||||
system::model::{Command, State},
|
||||
ui::interface::Component,
|
||||
@@ -129,7 +131,7 @@ impl Component for MemoryInspector {
|
||||
.fold(0u32, |acc, &byte| acc << 8 | u32::from(byte));
|
||||
|
||||
ui.monospace(format!("{combined}"));
|
||||
// ui.monospace(format!("{:?}", Instruction::decode(combined)));
|
||||
ui.monospace(format!("{:?}", Instruction::decode(combined)));
|
||||
ui.monospace("TODO! instruction");
|
||||
|
||||
ui.end_row();
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
db stack: 0x10000
|
||||
db screen: 0x20000
|
||||
dw stack: 0x10000
|
||||
dw screen: 0x20000
|
||||
db string: "Dominos sucks!"
|
||||
db string2: 0, 1, 2, 3, 4, 5, 6
|
||||
db length: 14
|
||||
|
||||
cll init
|
||||
cll start
|
||||
hlt
|
||||
|
||||
init:
|
||||
ldw stack, bpr
|
||||
mov bpr, spr
|
||||
ret
|
||||
|
||||
start:
|
||||
ldb length, rg0
|
||||
@@ -29,5 +25,4 @@ loop:
|
||||
// if loop counter <= 0 return.
|
||||
cmp rg0, zero,
|
||||
jgt loop
|
||||
ret
|
||||
|
||||
|
||||
Reference in New Issue
Block a user