Skip to content

Commit

Permalink
UI: Make disassambler a feature opt-in
Browse files Browse the repository at this point in the history
In this way we can skip the slow part of formatting ASM in the widget if
we don't care about it.

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
  • Loading branch information
guerinoni committed Sep 21, 2023
1 parent 07ead9f commit a551fdc
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ rand = "0.8.5"

[features]
logger = ["logger/logger", "emu/logger"]
disassembler = ["emu/disassembler", "ui/disassembler"]
1 change: 1 addition & 0 deletions emu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ rand = "0.8.5"

[features]
logger = []
disassembler = []
1 change: 1 addition & 0 deletions emu/src/cpu/arm/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl std::fmt::Display for ArmModeMultiplyLongVariant {
}

impl ArmModeInstruction {
#[cfg(feature = "disassembler")]
pub(crate) fn disassembler(&self) -> String {
match self {
Self::DataProcessing {
Expand Down
36 changes: 23 additions & 13 deletions emu/src/cpu/arm7tdmi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::convert::TryInto;

#[cfg(feature = "logger")]
use logger::log;

#[cfg(feature = "disassembler")]
use vecfixed::VecFixed;

use crate::bitwise::Bits;
Expand All @@ -27,6 +29,7 @@ pub struct Arm7tdmi {

pub register_bank: RegisterBank,

#[cfg(feature = "disassembler")]
pub disassembler_buffer: VecFixed<1000, String>,

fetched_arm: Option<u32>,
Expand Down Expand Up @@ -113,6 +116,7 @@ impl Default for Arm7tdmi {
spsr: Psr::default(),
registers: Registers::default(),
register_bank: RegisterBank::default(),
#[cfg(feature = "disassembler")]
disassembler_buffer: VecFixed::new(),
fetched_arm: None,
decoded_arm: None,
Expand Down Expand Up @@ -169,13 +173,16 @@ impl Arm7tdmi {
return;
}

let decimal_value = self.registers.program_counter();
let padded_hex_value = format!("{decimal_value:#04X}");
self.disassembler_buffer.push(format!(
"{}: {}",
padded_hex_value,
op_code.instruction.disassembler()
));
#[cfg(feature = "disassembler")]
{
let decimal_value = self.registers.program_counter();
let padded_hex_value = format!("{decimal_value:#04X}");
self.disassembler_buffer.push(format!(
"{}: {}",
padded_hex_value,
op_code.instruction.disassembler()
));
}

match op_code.instruction {
ArmModeInstruction::DataProcessing {
Expand Down Expand Up @@ -302,12 +309,15 @@ impl Arm7tdmi {
}

pub fn execute_thumb(&mut self, op_code: ThumbModeOpcode) {
let decimal_value = self.registers.program_counter();
let padded_hex_value = format!("{decimal_value:#04X}");
self.disassembler_buffer.push(format!(
"{padded_hex_value}: {}",
op_code.instruction.disassembler()
));
#[cfg(feature = "disassembler")]
{
let decimal_value = self.registers.program_counter();
let padded_hex_value = format!("{decimal_value:#04X}");
self.disassembler_buffer.push(format!(
"{padded_hex_value}: {}",
op_code.instruction.disassembler()
));
}

match op_code.instruction {
ThumbModeInstruction::MoveShiftedRegister {
Expand Down
2 changes: 2 additions & 0 deletions emu/src/cpu/thumb/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::bitwise::Bits;
use crate::cpu::condition::Condition;
use crate::cpu::flags::{LoadStoreKind, OperandKind, Operation, ReadWriteKind, ShiftKind};
#[cfg(feature = "disassembler")]
use crate::cpu::registers::REG_PROGRAM_COUNTER;
use crate::cpu::thumb::alu_instructions::{ThumbHighRegisterOperation, ThumbModeAluInstruction};
use logger::log;
Expand Down Expand Up @@ -240,6 +241,7 @@ impl std::fmt::Display for ThumbModeInstruction {
}

impl ThumbModeInstruction {
#[cfg(feature = "disassembler")]
pub(crate) fn disassembler(&self) -> String {
match self {
Self::MoveShiftedRegister {
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ run rom:

run-logger rom:
@cargo run --features logger $1

run-disassembler rom:
@cargo run --features disassembler $1
3 changes: 3 additions & 0 deletions ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ egui = { version = "0.22.0", default-features = false }
egui_extras = { version = "0.22.0", features = ["image"] }
emu = { path = "../emu"}
image = { version = "0.24.5", features = ["png"], optional = true}

[features]
disassembler = []
15 changes: 12 additions & 3 deletions ui/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "disassembler")]
use crate::disassembler::Disassembler;
use emu::{cartridge_header::CartridgeHeader, gba::Gba};
use logger::log;
Expand Down Expand Up @@ -47,23 +48,31 @@ impl ClementineApp {
data,
)));

#[cfg(feature = "disassembler")]
let disassembler = Disassembler::new(Arc::clone(&arc_gba));

Self::from_tools(vec![
let tools: Vec<Box<dyn UiTool>> = vec![
Box::<about::About>::default(),
Box::new(CpuRegisters::new(Arc::clone(&arc_gba))),
Box::new(CpuHandler::new(Arc::clone(&arc_gba))),
Box::new(GbaDisplay::new(Arc::clone(&arc_gba))),
Box::new(PaletteVisualizer::new(arc_gba)),
Box::new(disassembler),
])
];

#[cfg(feature = "disassembler")]
let mut tools = tools;
#[cfg(feature = "disassembler")]
tools.push(Box::new(disassembler));

Self::from_tools(tools)
}

fn from_tools(tools: Vec<Box<dyn UiTool>>) -> Self {
let mut open = BTreeSet::new();

open.insert(tools[1].name().to_owned());
open.insert(tools[2].name().to_owned());
#[cfg(feature = "disassembler")]
open.insert(tools[5].name().to_owned());

Self { tools, open }
Expand Down
6 changes: 2 additions & 4 deletions ui/src/disassembler.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::sync::{Arc, Mutex};

use crate::ui_traits::UiTool;
use egui::{ScrollArea, TextEdit, TextStyle};
use emu::gba::Gba;

use crate::ui_traits::UiTool;
use std::sync::{Arc, Mutex};

pub struct Disassembler {
gba: Arc<Mutex<Gba>>,
Expand Down
1 change: 1 addition & 0 deletions ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod about;
pub mod app;
mod cpu_handler;
mod cpu_registers;
#[cfg(feature = "disassembler")]
mod disassembler;
mod gba_color;
mod gba_display;
Expand Down

0 comments on commit a551fdc

Please sign in to comment.