# SPDX-License-Identifier: MIT """Instruction word builders and a tiny runner for the directed tests (DS section 3 formats).""" from __future__ import annotations from upd7725_python import UPD7725, UPD7725_MODEL def op(alu=0, p=0, asl=0, dpl=0, dphm=0, rpdec=0, src=0, dst=0, rt=False): """An OP (or RT) word.""" return ( (1 if rt else 0) << 22 | p << 20 | alu << 16 | asl << 15 | dpl << 13 | dphm << 9 | rpdec << 8 | src << 4 | dst ) def jp(brch, na=0, bank=0): return 2 << 22 | brch << 13 | na << 2 | bank def ld(value, dst): return 3 << 22 | value << 6 | dst def core(*program, data_rom=(), model=UPD7725_MODEL, cls=UPD7725, **registers): """A core with ``program`` at 0 and the given registers set.""" dsp = cls(list(program), list(data_rom), model=model) for name, value in registers.items(): setattr(dsp, name, value) return dsp