Files
adsp219x-re/testrom/gen_testrom.py
2026-04-12 13:58:44 +00:00

41 lines
1.4 KiB
Python

import sys
import struct
import os
# Opcode constants
TYPE1_NOP = 0xC00000
TYPE6_AX0 = 0x400000
TYPE10_JUMP_ALWAYS = 0x18000F
TYPE30_NOP = 0x000000
def create_rom(filename, format=3):
"""
Creates a synthetic ADSP-219x ROM with known instruction patterns.
"""
os.makedirs(os.path.dirname(filename), exist_ok=True)
instructions = [
0x000000, # 0x0000: NOP
0x401230 | 0x0, # 0x0001: AX0 = 0x1234 (Type 6, simplified field)
0x502000 | 0x0, # 0x0002: I0 = 0x2000 (Type 7)
0x500010 | 0x4, # 0x0003: M0 = 1 (Type 7)
0xC00000 | (0x13<<13) | (0x0<<11) | (0x0<<8) | (0x0<<2) | (0x0),
# 0x0004: X+Y, AX0=DM(I0+=M0), AY0=PM(I4+=M4)
0x18010F, # 0x0005: JUMP 0x0100
]
with open(filename, "wb") as f:
for ins in instructions:
if format == 3:
# Big-endian 3-byte pack
f.write(struct.pack(">I", ins)[1:])
else:
# Big-endian 4-byte pad
f.write(struct.pack(">I", ins))
if __name__ == "__main__":
# Ensure full path to base_test.bin
base_dir = os.path.dirname(os.path.abspath(__file__))
create_rom(os.path.join(base_dir, "test_roms/base_test.bin"), 3)
create_rom(os.path.join(base_dir, "test_roms/padded_test.bin"), 4)
print("Test ROMs generated in test_roms/")