From 5a49a41086fbc4969fd717b78043b754d100694c Mon Sep 17 00:00:00 2001 From: Dan Johnson Date: Thu, 4 Apr 2024 14:38:34 -0700 Subject: [PATCH] fix Display for indirect rr16 and rr17 registers Turns out rsp and rra are not a thing. --- ic10emu/src/grammar.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/ic10emu/src/grammar.rs b/ic10emu/src/grammar.rs index 3658014..b84052f 100644 --- a/ic10emu/src/grammar.rs +++ b/ic10emu/src/grammar.rs @@ -788,10 +788,14 @@ impl Display for Operand { for _ in 0..*indirection { write!(f, "r")?; } - match target { - 17 => write!(f, "ra"), - 16 => write!(f, "sp"), - _ => write!(f, "r{}", target), + if *indirection == 0 { + match target { + 17 => write!(f, "ra"), + 16 => write!(f, "sp"), + _ => write!(f, "r{}", target), + } + } else { + write!(f, "r{}", target) } } Operand::DeviceSpec(DeviceSpec { device, connection }) => { @@ -1271,10 +1275,18 @@ mod tests { test_roundtrip("r15"); test_roundtrip("rr4"); test_roundtrip("rrrr4"); + test_roundtrip("ra"); - test_roundtrip("rra"); test_roundtrip("sp"); + assert_eq!("r16".parse::().unwrap().to_string(), "sp"); + assert_eq!("r17".parse::().unwrap().to_string(), "ra"); + // Not registers test_roundtrip("rsp"); + test_roundtrip("rra"); + // Indirect only works through number names + test_roundtrip("rr16"); + test_roundtrip("rr17"); + test_roundtrip("Identifier"); test_roundtrip("db"); test_roundtrip("d0");