Skip to content

Commit 2183eae

Browse files
committed
Better instruction
1 parent 9996c1f commit 2183eae

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

modelmachine/ide/debug.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040

4141
INSTRUCTION = (
4242
"\nEnter\n"
43-
f" {BLU}s{DEF}tep [count=1] make count of steps\n"
44-
f" {BLU}c{DEF}ontinue continue until breakpoint or halt\n"
45-
f" {BLU}b{DEF}reakpoint [addr] set/unset breakpoint at addr\n"
46-
f" {BLU}m{DEF}emory <begin> <end> view random access memory\n"
47-
f" {BLU}rs{DEF}tep [count=1] make count of steps in reverse direction\n"
48-
f" {BLU}rc{DEF}ontinue continue until breakpoint or cycle=0 in reverse direction\n"
43+
f" {BLU}s{DEF}tep [count=1] make count of steps\n"
44+
f" {BLU}c{DEF}ontinue continue until breakpoint or halt\n"
45+
f" {BLU}b{DEF}reakpoint [addr] set/unset breakpoint at addr\n"
46+
f" {BLU}m{DEF}emory <begin> <end> view random access memory\n"
47+
f" {BLU}rs{DEF}tep [count=1] make count of steps in reverse direction\n"
48+
f" {BLU}rc{DEF}ontinue continue until breakpoint or cycle=0 in reverse direction\n"
4949
f" {BLU}q{DEF}uit\n"
5050
)
5151

@@ -65,6 +65,14 @@
6565
debug_cmd = stepc | rstepc | continuec | rcontinuec | memoryc | quitc | breakc
6666

6767

68+
def tabulate(data: list[tuple[str, str, str]]) -> str:
69+
elem_width = max(len(x) for _, x, _ in data)
70+
return "\n".join(
71+
f" {style}{elem.ljust(elem_width)} {descr}{DEF}{NUND}{BDEF}"
72+
for style, elem, descr in data
73+
)
74+
75+
6876
class Ide:
6977
cpu: Cpu
7078
max_register_hex: Final[int]
@@ -403,15 +411,22 @@ def run(self) -> int:
403411
)
404412
raise ValueError(msg)
405413

414+
addr = Cell(0, bits=self.cpu.ram.address_bits)
406415
cell = Cell(0, bits=self.cpu.ram.word_bits)
407416
printf(
408417
"Welcome to interactive debug mode\n"
409418
"Legend:\n"
410-
f" {cell.hex()} usual memory cell\n"
411-
f" {UND}{cell.hex()} next command{NUND}\n"
412-
f" {GRE}{cell.hex()} updated by last command{DEF}\n"
413-
f" {YEL}{cell.hex()} dirty unset memory{DEF}\n"
414-
f" {BSEL}{cell.hex()} breakpoint{BDEF}\n"
419+
+ tabulate(
420+
[
421+
("", f"{addr}:", "address in ram"),
422+
("", cell.hex(), "filled memory cell"),
423+
(UND, cell.hex(), "next command"),
424+
(GRE, cell.hex(), "updated by last command"),
425+
(YEL, cell.hex(), "dirty unsed memory"),
426+
(BSEL, cell.hex(), "breakpoint"),
427+
]
428+
)
429+
+ "\n"
415430
)
416431
self.dump_state()
417432

0 commit comments

Comments
 (0)