aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-22 08:52:20 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-22 08:52:20 +0200
commit416e896956d3b05793337da6609fe1544797c0a9 (patch)
tree9fa0cf3b622d4c9c086e4c08c5011ab12fdd4a77 /test/utils.py
parentaefe0cf3874c542669051b2b3cc21c9590aa970b (diff)
Add stuff, refactor
Diffstat (limited to 'test/utils.py')
-rw-r--r--test/utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/utils.py b/test/utils.py
new file mode 100644
index 0000000..873aa64
--- /dev/null
+++ b/test/utils.py
@@ -0,0 +1,25 @@
+def pad_bytearray(ba: bytearray, to_length: int = 64 * 1024) -> bytearray:
+ """
+ Pads a bytearray with zeros until it reaches a specified length.
+
+ :param to_length: Target length in bytes.
+ :param ba: The bytearray to be padded.
+ :return: The padded bytearray.
+ """
+ padding_size = to_length - len(ba)
+ if padding_size > 0:
+ ba.extend(b'\x00' * padding_size)
+ return ba
+
+def make_rom(words: list[int]) -> bytearray:
+ """
+ Constructs a ROM image from a list of 16-bit words.
+
+ :param words: The list of 16-bit words.
+ :return: The ROM image as a bytearray.
+ """
+ bytes = []
+ for word in words:
+ bytes.append((word >> 8) & 0xFF)
+ bytes.append(word & 0xFF)
+ return pad_bytearray(bytearray(bytes))