Skip to content

Commit 2333efa

Browse files
authored
add 'mixed' base to mipsy_web (#291)
1 parent 7f83376 commit 2333efa

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

crates/mipsy_web/src/components/registers.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ use crate::worker::{Worker, WorkerRequest};
66
use bounce::use_atom;
77
use derivative::Derivative;
88
use mipsy_lib::compile::breakpoints::{TargetAction, WatchpointTarget};
9-
use mipsy_lib::{Register, Safe};
9+
use mipsy_lib::{Register, Safe, KDATA_BOT, TEXT_BOT};
1010
use yew::{function_component, html, Callback, Properties, UseStateHandle};
1111
use yew_agent::UseBridgeHandle;
1212

13+
const MIXED_BASE_MIN_ADDRESS: u32 = TEXT_BOT - 1024;
14+
const MIXED_BASE_MAX_ADDRESS: u32 = KDATA_BOT + 1024;
15+
1316
#[derive(Properties, Derivative)]
1417
#[derivative(PartialEq)]
1518
pub struct RegisterProps {
@@ -180,6 +183,15 @@ pub fn render_running_registers(props: &RegisterProps) -> Html {
180183
RegisterBase::Binary => {
181184
format!("0b{:b}", val)
182185
},
186+
RegisterBase::Mixed => {
187+
let as_u32 = *val as u32;
188+
189+
if (MIXED_BASE_MIN_ADDRESS..MIXED_BASE_MAX_ADDRESS).contains(&as_u32) {
190+
format!("0x{:08x}", as_u32)
191+
} else {
192+
format!("{}", val)
193+
}
194+
}
183195
}
184196
}
185197
} else {

crates/mipsy_web/src/components/settings_modal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn render_modal(props: &ModalProps) -> Html {
164164
hide_label={true}
165165
selected_value={(*config).register_base.to_string()}
166166
options={
167-
vec!["Hexadecimal".to_string(), "Decimal".to_string(), "Binary".to_string()]
167+
vec!["Hexadecimal".to_string(), "Decimal".to_string(), "Binary".to_string(), "Mixed".to_string()]
168168
}
169169
/>
170170
</div>

crates/mipsy_web/src/state/config.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub enum RegisterBase {
106106
Hexadecimal,
107107
Decimal,
108108
Binary,
109+
Mixed,
109110
}
110111

111112
impl std::fmt::Display for RegisterBase {
@@ -114,6 +115,7 @@ impl std::fmt::Display for RegisterBase {
114115
RegisterBase::Hexadecimal => write!(f, "Hexadecimal"),
115116
RegisterBase::Decimal => write!(f, "Decimal"),
116117
RegisterBase::Binary => write!(f, "Binary"),
118+
RegisterBase::Mixed => write!(f, "Mixed"),
117119
}
118120
}
119121
}
@@ -124,11 +126,18 @@ impl From<std::string::String> for RegisterBase {
124126
"Hexadecimal" => RegisterBase::Hexadecimal,
125127
"Decimal" => RegisterBase::Decimal,
126128
"Binary" => RegisterBase::Binary,
127-
_ => RegisterBase::Hexadecimal,
129+
"Mixed" => RegisterBase::Mixed,
130+
_ => RegisterBase::default(),
128131
}
129132
}
130133
}
131134

135+
impl Default for RegisterBase {
136+
fn default() -> Self {
137+
RegisterBase::Decimal
138+
}
139+
}
140+
132141
impl Default for MipsyWebConfig {
133142
fn default() -> Self {
134143
Self {
@@ -142,7 +151,7 @@ impl Default for MipsyWebConfig {
142151
tab_size: 8,
143152
font_size: 14,
144153
monaco_theme: "vs".to_string(),
145-
register_base: RegisterBase::Decimal,
154+
register_base: RegisterBase::default(),
146155
// This is true as most CS1521 students don't need to see them
147156
hide_uncommon_registers: true,
148157
}

0 commit comments

Comments
 (0)