# set aside unread (wave 2): expectations from Mesen2/MiSTer source class Mesen2Shifted(HG51B): TRUNCATE_SHIFTED_OPERAND = False def test_shifted_compare_truncated_by_default() -> None: # A = 012345h; CMP A<<8,R1 with R1 = 234500h: truncated A<<8 = 234500h -> equal cx = run([0x5261], a=0x012345, r={1: 0x234500}) assert cx.z and cx.c cx = run([0x5261], a=0x012345, r={1: 0x234500}, core=Mesen2Shifted) assert not cx.z and cx.c # 1234500h - 234500h = 1000000h: not zero in Mesen2's width def test_shifted_add_carry_from_high_bits() -> None: cx = run([0x8660], a=0x010000) # ADD A<<8 (bits shifted past 23), #$60 assert cx.a == 0x000060 and not cx.c cx = run([0x8660], a=0x010000, core=Mesen2Shifted) assert cx.a == 0x000060 and cx.c # Mesen2: 1000060h > FFFFFFh SHIFT_CASES = { # count -> (SHR, ASR, ROR, SHL) of A = 823456h "bsnes": { 24: (0x000000, 0xFFFFFF, 0x823456, 0x000000), 25: (0x823456, 0x823456, 0x823456, 0x823456), 31: (0x823456, 0x823456, 0x823456, 0x823456), }, "mesen2": { 24: (0x823456, 0x823456, 0x823456, 0x823456), 31: (0x823456, 0x823456, 0x823456, 0x823456), }, "mod32": { 24: (0x000000, 0xFFFFFF, 0x823456, 0x000000), 28: (0x000000, 0xFFFFFF, 0x682345, 0x000000), }, } @pytest.mark.parametrize("rule", sorted(SHIFT_CASES)) def test_shift_counts_24_to_31(rule: str) -> None: class Core(HG51B): SHIFT_LIMIT = rule for count, expected in SHIFT_CASES[rule].items(): for base, want in zip((0xC061, 0xC861, 0xD061, 0xD861), expected, strict=True): cx = run([base], a=0x823456, r={1: count}, core=Core) # shift by R1 assert cx.a == want, f"{rule} {base:04X} by {count}: {cx.a:06X}" assert cx.z == (want == 0) and cx.n == bool(want & 0x800000)