diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-21 12:02:14 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-21 12:02:14 +0200 |
| commit | a0b4a1a6107e4dc905b21858d8ac76c47293cfb4 (patch) | |
| tree | f7ec4d592a6ee7bf6f1e61ef805643c83fedf740 /atk16_emu/test/utils.py | |
| parent | 549901c85044b6ccd912688d6be007c2fdacc6c6 (diff) | |
Add emu
Diffstat (limited to 'atk16_emu/test/utils.py')
| -rw-r--r-- | atk16_emu/test/utils.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/atk16_emu/test/utils.py b/atk16_emu/test/utils.py new file mode 100644 index 0000000..0d40d54 --- /dev/null +++ b/atk16_emu/test/utils.py @@ -0,0 +1,25 @@ +def pad_bytearray(to_length: int, ba: bytearray) -> 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(64 * 1024, bytearray(bytes))
\ No newline at end of file |
