Add and test .in directive

This commit is contained in:
Jeff Epler 2024-09-05 13:18:26 -05:00
parent ff1f57dfb1
commit 4deafa6c65
2 changed files with 58 additions and 0 deletions

View file

@ -64,6 +64,10 @@ class Program: # pylint: disable=too-few-public-methods
mov_status_type = None mov_status_type = None
mov_status_count = None mov_status_count = None
mov_status_param = None mov_status_param = None
in_count = None
in_shift_right = None
auto_push = None
push_threshold = None
def require_before_instruction(): def require_before_instruction():
if len(instructions) != 0: if len(instructions) != 0:
@ -139,6 +143,29 @@ class Program: # pylint: disable=too-few-public-methods
if not 0 <= mov_status_count < 16: if not 0 <= mov_status_count < 16:
raise RuntimeError(f"Invalid mov_status count {mov_status_count}") raise RuntimeError(f"Invalid mov_status count {mov_status_count}")
require_version(required_version, line) require_version(required_version, line)
elif words[0] == ".in":
require_before_instruction()
in_count = int_in_range(
words[1], 32 if pio_version == 0 else 1, 33, ".in count"
)
auto_push = False
idx = 2
if idx < len(words) and words[idx] == "left":
in_shift_right = False
idx += 1
elif idx < len(words) and words[idx] == "right":
in_shift_right = True
idx += 1
if idx < len(words) and words[idx] == "auto":
auto_push = True
idx += 1
if idx < len(words):
push_threshold = int_in_range(words[idx], 1, 33, ".in threshold")
idx += 1
elif line.endswith(":"): elif line.endswith(":"):
label = line[:-1] label = line[:-1]
if label in labels: if label in labels:
@ -326,6 +353,18 @@ class Program: # pylint: disable=too-few-public-methods
self.pio_kwargs["mov_status_count"] = mov_status_count self.pio_kwargs["mov_status_count"] = mov_status_count
self.pio_kwargs["mov_status_param"] = mov_status_param self.pio_kwargs["mov_status_param"] = mov_status_param
if in_count not in (None, 32):
self.pio_kwargs["in_count"] = in_count
if in_shift_right is not None:
self.pio_kwargs["in_shift_right"] = in_shift_right
if auto_push is not None:
self.pio_kwargs["auto_push"] = auto_push
if push_threshold is not None:
self.pio_kwargs["push_threshold"] = push_threshold
self.assembled = array.array("H", assembled) self.assembled = array.array("H", assembled)
self.debuginfo = (linemap, text_program) if build_debuginfo else None self.debuginfo = (linemap, text_program) if build_debuginfo else None

View file

@ -61,3 +61,22 @@ def test_mov_status() -> None:
mov_status_count=3, mov_status_count=3,
mov_status_param=0, mov_status_param=0,
) )
def test_dot_in() -> None:
assert_pio_kwargs(
".in 32 left auto 11",
sideset_enable=0,
auto_push=True,
push_threshold=11,
in_shift_right=False,
)
assert_assembly_fails(".in 16")
assert_pio_kwargs(
".pio_version 1\n.in 16 right",
pio_version=1,
sideset_enable=0,
in_count=16,
auto_push=False,
in_shift_right=True,
)