# SPDX-License-Identifier: MIT """Every cycle constant of the core, in one place, each with its source. The core counts **input clocks** (handoff-brief decision 4): the 21.4 MHz unit every emulator uses. With CLSR = 1 the GSU runs at the input clock, so one GSU cycle is one input clock; with CLSR = 0 it runs at half (BK2 2-4-11: "CLSR Flag = 0, Super FX operates at 10.7 MHz; = 1, 21.4 MHz"), so every cost below is doubled in input clocks. Each pair is indexed by CLSR: ``(cost at CLSR = 0, cost at CLSR = 1)``, both in input clocks. What BK2 fixes and what is the core's choice (timing.md; claims.md): - An opcode byte from the code cache: 1 GSU cycle (BK2 tables, "Cache RAM execution time"). - A ROM or RAM byte, data or opcode: 3 GSU cycles at 10.7 MHz, 5 at 21.4 MHz (BK2 2-7-2: "Read timing for game pak ROM access ... 21.4 MHz: 5 cycles; 10.7 MHz: 3 cycles"). For an *opcode* fetch at 21.4 MHz this is C12's choice (the emulators' 5; fullsnes asks if it is 3). - A RAM word read inside LM/LMS/LDW: two byte accesses (BK2 examples 5 and 6: LM is 4 fetches + 10 cycles at 21.4 MHz; C13). - A RAM word store occupies the write buffer for two byte accesses, a byte store for one (BK2 examples 3 and 4: a second STW waits for the first's 10 cycles; C13). - Multiply (BK2 chapter 9 MULT/FMULT/LMULT; C14): MULT/UMULT one extra GSU cycle at standard speed (MS0 = 0), none at high speed; FMULT/LMULT 7 extra cycles at standard speed, 3 at high speed. - Pixel-cache write-back (C15): per bit plane, one RAM write, preceded by one RAM read when the row is partial (BK2 8.1.3; ares ``core.cpp`` ``flushPixelCache``); overlapped with execution. """ from __future__ import annotations #: An opcode byte from a valid cache line: 1 GSU cycle. CACHE_FETCH = (2, 1) #: One byte from or to Game Pak ROM or RAM (opcode fetch, ROM buffer, RAM data, pixel #: write-back): 3 GSU cycles at 10.7 MHz, 5 at 21.4 MHz (BK2 2-7-2; C12). MEMORY_ACCESS = (6, 5) #: MULT/UMULT at standard speed: 1 GSU cycle more (BK2 9.66 "1 or 2" cache cycles; ares #: ``instructions.cpp`` l.228: ``if(!regs.cfgr.ms0) step(regs.clsr ? 1 : 2)``). MULT_SLOW_EXTRA = (2, 1) #: FMULT/LMULT: 7 GSU cycles more at standard speed, 3 at high speed (BK2 9.33 FMULT cache #: "8 or 4"; 9.52 LMULT cache "9 or 5" with its prefix byte). FMULT_SLOW_EXTRA = (14, 7) FMULT_FAST_EXTRA = (6, 3) __all__ = [ "CACHE_FETCH", "FMULT_FAST_EXTRA", "FMULT_SLOW_EXTRA", "MEMORY_ACCESS", "MULT_SLOW_EXTRA", ]