# SPDX-License-Identifier: MIT """SFR, the status/flag register (BK2 table 2-4-2; fullsnes "3030h/3031h").""" from __future__ import annotations Z = 0x0002 # zero CY = 0x0004 # carry (subtraction: 1 = no borrow) S = 0x0008 # sign OV = 0x0010 # overflow GO = 0x0020 # the GSU is running; the S-CPU may write 0 to stop it (BK2 2-5-4) R = 0x0040 # a ROM buffer read via R14 is pending (U28; the core computes it from time) ALT1 = 0x0100 ALT2 = 0x0200 IL = 0x0400 # "immediate lower 8-bit flag": no source says when it is set (U27) IH = 0x0800 # "immediate upper 8-bit flag" (U27) B = 0x1000 # set by WITH: 1n is MOVE and Bn is MOVES IRQ = 0x8000 # set by STOP; an S-CPU read of $3031 clears it (BK2 2-5-5) #: Bits an S-CPU read can see (ares ``registers.hpp`` l.57 and MAME read SFR through 9F7Eh). READABLE = 0x9F7E #: The prefix state every opcode but the prefixes and branches clears (U3). PREFIXES = ALT1 | ALT2 | B #: The four arithmetic flags. FLAGS = Z | CY | S | OV NAMES = ( (Z, "Z"), (CY, "CY"), (S, "S"), (OV, "OV"), (GO, "GO"), (R, "R"), (ALT1, "ALT1"), (ALT2, "ALT2"), (IL, "IL"), (IH, "IH"), (B, "B"), (IRQ, "IRQ"), ) def describe(sfr: int) -> str: """The set flags by name, e.g. ``"Z CY GO"``.""" return " ".join(name for bit, name in NAMES if sfr & bit) or "-" __all__ = [ "ALT1", "ALT2", "CY", "FLAGS", "GO", "IH", "IL", "IRQ", "NAMES", "OV", "PREFIXES", "READABLE", "B", "R", "S", "Z", "describe", ]