"""The access bits a bus callback receives, and the GBA's one rule about them. Each ``read``/``write`` callback gets ``access``, a bit set taken from the ARM7TDMI's address-class pins (TRM 3.3, docs/start-here.md "Bus cycles"): - ``SEQ``: the SEQ pin. Set for an S cycle (same address as the previous I cycle, or the next word/halfword after the previous access); clear for an N cycle. - ``CODE``: nOPC low, an opcode fetch. - ``LOCK``: the LOCK pin, SWP's read and write (TRM table 6-14, C10). Bit 2 is left free: NanoBoyAdvance and the SingleStepTests corpus use it for DMA, which is a board concern. """ SEQ = 1 CODE = 2 LOCK = 8 def gba_access(access: int, after_idle: bool) -> int: """The access as the GBA's memory controller times it. The core reports the SEQ pin as the TRM defines it: the fetch after an internal cycle is a merged IS cycle, S at the address the I cycle drove (TRM 3.3.4). The GBA's controller does not honour the merge and starts a new, nonsequential access (NanoBoyAdvance, mGBA and the SingleStepTests corpus all time it as N and pass the hardware-captured timing tests; docs/undocumented-behavior.md C1). ``after_idle`` is whether the previous callback was ``idle()``. This is the one place the rule is written: the rung-1 comparison and gba-python both call it (user decision 1). """ return access & ~SEQ if after_idle else access