diff --git a/src/app.rs b/src/app.rs index cc802b2..94f1e14 100644 --- a/src/app.rs +++ b/src/app.rs @@ -89,7 +89,7 @@ pub fn App() -> impl IntoView { view! { -
+
@@ -112,111 +112,135 @@ pub fn App() -> impl IntoView {
-
-
- - - + -
-
- - - -
+ + + + Reset + +
-
{message}
+
+ + + +
+ + +
+ + + +
{message}
+
+
+
-
-
-
"RISC-V Exposed © 2024 Felix Andreas."
+
+
+
+ "RISC-V Exposed © 2024 Felix Andreas." +
@@ -236,9 +260,9 @@ enum InstType { #[derive(Debug, Clone, Copy, Eq, PartialEq)] enum View { - Hex, Binary, Decoded, + Hex, } #[component] @@ -256,191 +280,185 @@ pub fn Program(memory: RwSignal, pc: Signal) -> impl IntoView { let view_state = RwSignal::new(View::Binary); let view_instruction = move |i_type, code: u32| { view! { -
-
- - > n) & 1) - .enumerate() - .collect::>() - } - - key=|(i, _)| *i - let:child - > -
- {child.1} -
-
-
+
+ + > n) & 1).enumerate().collect::>() + } - -
- {format!("{code:08x}")} + key=|(i, _)| *i + let:child + > +
+ {child.1}
- - {match i_type { - Some(InstType::RType(r_type)) => { - view! { - <> -
- "f7" -
-
- "rs2" -
-
- "rs1" -
-
- "f3" -
-
- "rd" -
-
- "opcode" -
- - } + + + + +
+ {format!("{code:08x}")} +
+
+ {match i_type { + Some(InstType::RType(r_type)) => { + view! { + <> +
+ "f7" +
+
+ "rs2" +
+
+ "rs1" +
+
+ "f3" +
+
+ "rd" +
+
+ "opcode" +
+ } - Some(InstType::IType(i_type)) => { - view! { - <> -
- "imm" -
-
- "rs1" -
-
- "f3" -
-
- "rd" -
-
- "opcode" -
- - } + } + Some(InstType::IType(i_type)) => { + view! { + <> +
+ "imm" +
+
+ "rs1" +
+
+ "f3" +
+
+ "rd" +
+
+ "opcode" +
+ } - Some(InstType::SType(s_type)) => { - view! { - <> -
- "imm" -
-
- "rs2" -
-
- "rs1" -
-
- "f3" -
-
- "imm" -
-
- "opcode" -
- - } + } + Some(InstType::SType(s_type)) => { + view! { + <> +
+ "imm" +
+
+ "rs2" +
+
+ "rs1" +
+
+ "f3" +
+
+ "imm" +
+
+ "opcode" +
+ } - Some(InstType::BType(b_type)) => { - view! { - <> -
- "imm" -
-
- "rs2" -
-
- "rs1" -
-
- "f3" -
-
- "imm" -
-
- "opcode" -
- - } + } + Some(InstType::BType(b_type)) => { + view! { + <> +
+ "imm" +
+
+ "rs2" +
+
+ "rs1" +
+
+ "f3" +
+
+ "imm" +
+
+ "opcode" +
+ } - Some(InstType::UType(u_type)) => { - view! { - <> -
- "imma" -
-
- "rd" -
-
- "opcode" -
- - } + } + Some(InstType::UType(u_type)) => { + view! { + <> +
+ "imma" +
+
+ "rd" +
+
+ "opcode" +
+ } - Some(InstType::JType(j_type)) => { - view! { - <> -
- "imm" -
-
- "rd" -
-
- "opcode" -
- - } + } + Some(InstType::JType(j_type)) => { + view! { + <> +
+ "imm" +
+
+ "rd" +
+
+ "opcode" +
+ } - None => { - view! { - <> -
- "unknown" -
- - } + } + None => { + view! { + <> +
+ "unknown" +
+ } - }} - -
+ } + }}
} }; view! { -
-
"Program"
+
+
"Program"
- {[View::Binary, View::Hex, View::Decoded] + {[View::Binary, View::Decoded, View::Hex] .map(|x| { view! { @@ -464,44 +482,45 @@ pub fn Program(memory: RwSignal, pc: Signal) -> impl IntoView { })}
-
-
-
addr
-
instr
-
- {move || match view_state() { - View::Binary => "Binary", - View::Hex => "Hex", - View::Decoded => "Decoded", - }} +
+
+
+
addr
+
instr
+
+ {move || match view_state() { + View::Binary => "binary", + View::Decoded => "decoded", + View::Hex => "hex", + }} -
-
- -
+ - { - let (name, i_type) = code_to_name(child.1); - view! { -

- {format!("{:02x}", 4 * child.0)} -

-

{name}

-

{view_instruction(i_type, child.1)}

- } - } + { + let (name, i_type) = code_to_name(child.1); + view! { +
+ {format!("{:02x}", 4 * child.0)} +
+
{name}
+
{view_instruction(i_type, child.1)}
+ } + } -
-
-
+
} @@ -509,28 +528,82 @@ pub fn Program(memory: RwSignal, pc: Signal) -> impl IntoView { #[component] pub fn Registers(registers: RwSignal) -> impl IntoView { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + enum ViewState { + Bytes, + U32, + I32, + } + pub fn view_register(word: u32, view_state: ViewState) -> impl IntoView { + match view_state { + ViewState::Bytes => view_word(word).into_view(), + ViewState::U32 => view! { +
+ {format!("{}", word)} +
+ } + .into_view(), + ViewState::I32 => view! { +
+ {format!("{}", i32::from_ne_bytes(word.to_ne_bytes()))} +
+ } + .into_view(), + } + } + let view_state = RwSignal::new(ViewState::Bytes); view! { -
-
"Registers"
-
-
-

"reg"

-
"value"
+
+
"Registers"
+
+ {[ViewState::Bytes, ViewState::U32, ViewState::I32] + .map(|x| { + view! { + + } + })} + +
+
+
+
"reg"
+
"value"
-
-

"pc"

- {view_word(registers()[PC])} +
+

"pc"

+ {move || view_register(registers()[PC], view_state())} +
-
-

+

+

{format!("x{}", child.0)}

- {view_word(child.1)} + {move || view_register(child.1, view_state())}
@@ -544,7 +617,7 @@ pub fn view_word(word: u32) -> impl IntoView { let c = (word >> 16) & 0xff; let d = (word >> 24) & 0xff; view! { -
+
{format!("{a:02x}")}
{format!("{b:02x}")}
{format!("{c:02x}")}
@@ -555,12 +628,54 @@ pub fn view_word(word: u32) -> impl IntoView { #[component] pub fn Memory(memory: RwSignal) -> impl IntoView { + #[derive(Debug, Clone, Copy, PartialEq, Eq)] + enum ViewState { + Bytes, + U32, + I32, + } + + let view_state = RwSignal::new(ViewState::Bytes); + view! { -
-
"RAM"
-
- "addr" - "value" +
+
"RAM"
+
+ {[ViewState::Bytes, ViewState::U32, ViewState::I32] + .map(|x| { + view! { + + } + })} + +
+
+ + "addr" + + + "value" + ) -> impl IntoView { key=|(index, _)| *index let:child > - + {format!("{:02x}", 4 * child.0)} {format!("{:02x}", child.1[0])}