Fix: rename enterpreter to interpreter

This commit is contained in:
2025-04-10 14:24:55 +01:00
parent 753f65384b
commit 17fd5f7acf
10 changed files with 59 additions and 17 deletions

View File

@@ -0,0 +1,3 @@
from .hexdump import hexdump
__all__ = ["hexdump"]

View File

@@ -0,0 +1,45 @@
from colorama import Fore, Style, init
# Initialize colorama (especially important on Windows)
init()
def hexdump(
data: bytearray,
width: int = 16,
program_counter: int = None,
memory_pointer: int = None,
):
"""
Print a hex+ASCII memory dump of the given bytearray.
Highlights:
- Program counter (PC) in bright red
- Memory pointer (MP) in bright blue
"""
for i in range(0, len(data), width):
chunk = data[i : i + width]
hex_parts = []
ascii_parts = []
for j, byte in enumerate(chunk):
addr = i + j
# Apply color based on PC or MP
if addr == program_counter:
style = Style.BRIGHT + Fore.RED
elif addr == memory_pointer:
style = Style.BRIGHT + Fore.BLUE
else:
style = ""
reset = Style.RESET_ALL if style else ""
# Hex and ASCII views
hex_parts.append(f"{style}{byte:02x}{reset}")
ascii_parts.append(
f"{style}{chr(byte) if 32 <= byte <= 126 else '.'}{reset}"
)
# Format line: address, hex bytes, ASCII chars
hex_field = " ".join(hex_parts).ljust(width * 3 - 1)
ascii_field = "".join(ascii_parts)
print(f"{i:08x}: {hex_field} {ascii_field}")