# Timing Tags as in [README.md](README.md). Cycle counts quoted from hardware tests are the counts the test's timer read, which include the test's own code around the event; they are judges for the whole sequence, not constants to type into the board. Where a test's number has been decomposed into a rule here, the decomposition is marked HYPOTHESIS until the board reproduces the number. ## The clock One master clock, 16,777,216 Hz (2^24), "one cycle is thus approx. 59.59ns" (GBATEK §System Clock; `DOC`). The CPU, the bus, DMA, timers and the picture processor (4 cycles a dot) count it; the Game Boy sound channels run at 4,194,304 Hz = clock / 4 ([sound.md](sound.md)). A frame is 280,896 cycles (308 dots x 4 x 228 lines; GBATEK §LCD Dimensions and Timings; `DOC`), about 59.737 Hz. The owner's decision is a catch-up scheduler: devices advance to the CPU's time when touched or at their events (handoff-brief.md). The order of record within one cycle (CPU bus access, DMA, timers, IRQ line, PPU) is a specification choice the plan fixes ([plan.md](plan.md)); where a test depends on it, the test is named below. ## Bus cycles: N, S, I The core reports each CPU cycle (arm7tdmi-python `ARM7TDMI` docstring; ARM TRM §3.3; `DOC`): - **N** (non-sequential): an access unrelated to the previous one; GBATEK's "1st access". - **S** (sequential): the next halfword/word after the previous access, or the address the previous I cycle drove; GBATEK's "2nd access". - **I** (internal): no memory request; 1 clock, no wait states. - **C** (coprocessor): none on the GBA except CP14 probes, delivered as an idle cycle. "The execution time for 1N is 1 clock cycle (plus non-sequential access waitstates)", 1S likewise with sequential wait states (GBATEK §ARM CPU Instruction Cycle Times; `DOC`). **The merged IS cycle.** The ARM7TDMI signals an opcode fetch after an internal cycle as S at the I cycle's address (TRM §3.3.4). The GBA's memory controller times it as N. That rule is the core's (`arm7tdmi_python.gba_access(access, after_idle)`): the board calls it on every access and never copies it (handoff-brief.md). Its evidence, per the core's docstring, is emulator behaviour that passes hardware-captured timing tests (OBSERVED, owned by arm7tdmi-python; U-TIM-1). **Instruction timing** belongs to the core: GBATEK's summary (ALU 1S, +1S+1N if R15 written, +1I for a register-specified shift; LDR 1S+1N+1I; STR 2N; LDM nS+1N+1I; STM (n-1)S+2N; SWP 1S+2N+1I; B/BL 2S+1N; Thumb BL 3S+1N; SWI and exceptions 2S+1N; MUL 1S+mI, ...; condition false 1S; §ARM CPU Instruction Cycle Times; `DOC`) is what the core's callbacks add up to. The board only prices each callback. "If an instruction jumps to a different memory area, then all code cycles for that opcode are having waitstate characteristics of the NEW memory area (except Thumb BL which still executes 1S in OLD area)" (same section; `DOC`): with one callback per cycle carrying its address, this falls out of pricing each access by its own address. ## Access time by region Each access costs 1 cycle plus the region's wait states for its kind (GBATEK §GBA System Control, "First Access (Non-sequential) and Second Access (Sequential) define the waitstates for N and S cycles, the actual access time is 1 clock cycle PLUS the number of waitstates"; `DOC`). | Region | 8/16-bit | 32-bit | Notes | | --- | --- | --- | --- | | BIOS, IWRAM, I/O, OAM | 1 | 1 | 32-bit bus | | palette, VRAM | 1 | 2 | 16-bit bus: a 32-bit access is two halfwords; +1 when the PPU uses the memory in that cycle ([video.md](video.md) "CPU access to video memory") | | EWRAM | 1 + w | 2 x (1 + w) | w from `04000800` bits 24-27: 15 - n; default 2 (3/3/6). N and S cost the same (GBATEK gives one figure; `DOC`) | | Game Pak ROM | 1 + N-wait (first), 1 + S-wait (sequential) | first halfword as N or S, the second always S | "a 32bit access is split into TWO 16bit accesses (of which, the second fragment is always sequential, even if the first fragment was non-sequential)" (GBATEK §GBA System Control; `DOC`) | | Game Pak backup | 1 + SRAM wait | 8-bit bus only | | **WAITCNT `04000204`** (GBATEK §GBA System Control; `DOC`; CowBite's REG_WSCNT agrees): | Bits | Field | Values | | --- | --- | --- | | 0-1 | SRAM wait | 4, 3, 2, 8 cycles | | 2-3 | WS0 first access | 4, 3, 2, 8 | | 4 | WS0 second access | 2, 1 | | 5-6 | WS1 first access | 4, 3, 2, 8 | | 7 | WS1 second access | 4, 1 | | 8-9 | WS2 first access | 4, 3, 2, 8 | | 10 | WS2 second access | 8, 1 | | 11-12 | PHI terminal output | off, 4.19, 8.38, 16.78 MHz (should stay off) | | 14 | Game Pak prefetch buffer | 0 off, 1 on | | 15 | Game Pak type (read-only) | 0 GBA, 1 CGB | "Wait" values are wait states, so an N access to WS0 at the reset setting costs 5 cycles and an S access 3 (GBATEK's "5/5/8" default in §GBA Memory Map agrees: 1+4, 1+4, 1+4+1+2). Reset value 0; commercial games use `4317` (WS0 3/1, SRAM 8, WS2 8/8, prefetch on; §GBA System Control; `DOC`). Bit 15's value for a GBA cartridge is 0; bit 13 unused. **The 128 KB rule.** "The GBA forcefully uses non-sequential timing at the beginning of each 128K-block of gamepak ROM, eg. "LDMIA [801fff8h],r0-r7" will have non-sequential timing at 8020000h" (GBATEK §GBA System Control; `DOC`). For DMA: "In ROM region, non-sequential accesses are decided based on if the current internal addresses is adjacent to a 0x20000 boundary. In this case, the NEXT access will use non-sequential timing, even if in decrement or fixed mode" (alyosha-tas `DMA/readme.txt`; `TEST ROM`, judged by `DMA/DMA_ROM_Fixed`). hw-test `bus/128kb-boundary` times an LDMIA of four words and a 4-word DMA1 in both directions at `07FFFFF8`, `080003F8`, `0801FFF0`, `0801FFF8`, `0803FFF0`, `0803FFF8` (expected LDM 28, 38, 38, 40, 38, 40; DMA increment 57, 67, 67, 69, 67, 69; DMA decrement 63, 68, 70, 68, 70, 68; `TEST ROM`). The decrement figures (`0801FFF0` slower than `0801FFF8`) are consistent with "the access after the one adjacent to the boundary is N" (HYPOTHESIS: the board must reproduce all 18). **The ROM's own address counter.** The cartridge "must include a circuit that latches the lower 16 address bits on non-sequential access, and that increments these bits on sequential access" (GBATEK §GBA Cartridge ROM; `DOC`). An S access therefore returns the halfword after the last one the cartridge served, whatever address the CPU or DMA drives. hw-test `dma/burst-into-tears` depends on this: a 16-bit DMA3 of 3 units, source `07FFFFFE` incrementing, destination `08000000` decrementing, leaves at `07FFFFFE`/`07FFFFFC` the ROM halfwords at `08000002`/`08000004`, not `08000000`/`08000002`, and takes 41 cycles (`TEST ROM`). HYPOTHESIS for the mechanism: the write to `08000000` (N) latches address 0; the following read at `08000000`, S because it follows an access in the same region, gets the incremented `08000002`. The board models the cartridge's latch and lets sequential accesses advance it (U-TIM-2). ## The Game Pak prefetch buffer What the documents say (GBATEK §GBA GamePak Prefetch; `DOC`): - When WAITCNT bit 14 is set, "the GBA attempts to read opcodes from Game Pak ROM during periods when the CPU is not using the bus (if any). Memory access is then performed with 0 Waits if the CPU requests data which is already stored in the buffer. The prefetch buffer stores up to eight 16bit values." - It serves only opcodes fetched from Game Pak ROM; code in RAM or BIOS reading ROM data does not use it. - Prefetch may happen during internal cycles that do not change R15 (register-specified shifts, loads, multiplies) and during opcodes that load or store memory. - **Prefetch disable bug**: with the buffer disabled, a Game Pak ROM opcode with internal cycles that does not change R15 has its next opcode fetch timed 1N instead of 1S. What the hardware tests' readmes add (alyosha-tas `prefetcher/readme.txt`; `TEST ROM`): - "When prefetcher is full ... the prefetch unit pauses until the buffer is empty and then starts up again with non-sequential timing." - "When the prefetch buffer is empty, and a branch is done to the next instruction that would be read by the prefetcher, the instruction fetch is done with non-sequential timing (even though the prefetcher starts at the same time with sequential timing.)" - "When the prefetcher encounters a 0x20000 boundary, it stops and behaves as though it is full." - The prefetcher tests also contain the comment "loading a register from EWRAM should add one instruction to the prefetcher for each load" (`prefetcher_full_thumb.asm`, t001). The mGBA suite's timing tests price instruction sequences from ROM under WAITCNT `0000`, `4000` (prefetch), `0004`, `4004`, `0010`, `4010`, `0014`, `4014` and from EWRAM and IWRAM (src/timing.c; `TEST ROM`), and its "Misc. edge case" tests include "DMA Prefetch Break". alyosha-tas `timing/prefetch_enable`, `prefetch_enable_2` time switching the buffer on. What no document says, and the board must state as HYPOTHESIS (U-TIM-3): the buffer's state machine cycle by cycle (when a halfword fetch starts and completes, whether a CPU data access to ROM aborts an in-flight fetch and at what cost, what a 32-bit ARM fetch takes from a buffer holding one halfword, what happens to the buffer on a branch, on a DMA, and when WAITCNT changes). The model is built to the readme facts above and fitted to the 18 alyosha-tas `prefetcher` ROMs, the mGBA timing table, hw-test `bus/128kb-boundary` and `irq/irq-delay` (ROM case); every fitted choice is tagged `FITTED` with the tests it was fitted to. NanoBoyAdvance 1.8.3 fails 8 of the 18 prefetcher ROMs (OBSERVED, [validation.md](validation.md)), so it is not a reference here. ## DMA Registers and modes (GBATEK §GBA DMA Transfers; `DOC`): - SAD, DAD (write-only), CNT_L word count (14 bits for DMA0-2, 0 = 0x4000; 16 bits for DMA3, 0 = 0x10000), CNT_H: destination control (increment, decrement, fixed, increment/reload), source control (increment, decrement, fixed, prohibited), repeat, 16/32-bit, Game Pak DRQ (DMA3), start timing (immediate, V-blank, H-blank, special), IRQ at end, enable. - The internal source, destination and count are loaded when enable goes 0 to 1; a repeat reloads the count and, in increment/reload mode, the destination. The registers themselves never change. - Without repeat the enable bit clears at the end. With repeat it stays set and the transfer runs again at each start condition. - Priority 0 > 1 > 2 > 3; a lower channel pauses while a higher one runs; "The CPU is paused when DMA transfers are active, however, the CPU is operating during the periods when Sound/Blanking DMA transfers are paused." - "After changing the Enable bit from 0 to 1, wait 2 clock cycles before accessing any DMA related registers." H-blank DMA does not run in V-blank lines (gbadoc registers.md, DMA start mode "unlike h-interrupts, hdma does NOT occur during vblank"; `DOC`). Video capture (DMA3 special): starts at VCOUNT = 2, repeats each line, stops at VCOUNT = 162 (GBATEK; `DOC`). - Sound FIFO mode (DMA1/2 special): [sound.md](sound.md). Timing (GBATEK §GBA DMA Transfers, "Transfer Rate/Timing"; `DOC`): "Except for the first data unit, all units are transferred by sequential reads and writes. For n data units, the DMA transfer time is: 2N+2(n-1)S+xI ... Internal time for DMA processing is 2I (normally), or 4I (if both source and destination are in gamepak memory area)." CowBite/gbadoc give a table of cycles per unit for each source/destination pair (gbadoc registers.md "DMA Transfer Ratings"; `DOC`, source of the measurements not stated; the board is judged by the tests, not the table). Hardware results (`TEST ROM`): | Test | What it times | Expected | | --- | --- | --- | | hw-test `dma/start-delay` | timer value a 1-unit 16-bit immediate DMA0 copies from TM0CNT_L to IWRAM, timer started just before | 20 | | hw-test `dma/force-nseq-access` | a STR enabling a 1-unit DMA1 from EWRAM or ROM, then NOPs, from code in ROM | 88 (both) | | hw-test `dma/burst-into-tears` | 3-unit DMA3 across `07FFFFFE` / `08000000` | 41, values above | | hw-test `bus/128kb-boundary` | 4-word DMA1 near 128 KB boundaries | above | | hw-test `haltcnt` "CPUSET DMA" | CpuSet enabling DMA0 to write HALTCNT | 4154 | | alyosha-tas `DMA/*` | pause timing when a higher channel interrupts a lower (start, middle, end), mode changes, ROM fixed-address | pass/fail on screen | | alyosha-tas `Interactions/*` | DMA against IRQ dispatch, HALT, multiplies, loads, stores, branches | pass/fail on screen | "When a DMA occurs, the IRQ pipeline is stalled whenever the cpu is stalled. So, the IRQ pipeline will be stalled if the cpu is waiting to do a read or write, but not if it is doing internal cycles such as multiply. Halt counts as an internal cycle for this situation" (alyosha-tas `Interactions/ReadMe.txt`; `TEST ROM`). So the CPU keeps running internal cycles while a DMA owns the bus, and stops at its next memory access (HYPOTHESIS for the general rule; the Interactions ROMs judge it). Open: the delay between the start condition and the first DMA read (beyond hw-test's 20), what the CPU may do during that delay, the "DMA lockup when stopping while starting ???" GBATEK leaves open, and the cost of switching channels mid-transfer (U-DMA-1, U-DMA-2). ## Interrupts - IE (`200`), IF (`202`, write 1 to clear), IME (`208`, bit 0) (GBATEK §GBA Interrupt Control; `DOC`). The CPU's IRQ line is `IME and (IE and IF) != 0`, also gated by CPSR.I in the core. - Sources set IF regardless of IE (HYPOTHESIS consistent with GBATEK's description and the IF register's role; alyosha-tas `irq/IF`, `IE` judge it). - Every IRQ enters the BIOS at `00000018`; the BIOS pushes r0-r3, r12, lr, calls the handler at `[03007FFC]` in ARM state, returns with `SUBS PC, LR, #4` (GBATEK §BIOS Interrupt handling; `DOC`). - **Delay**: hw-test `irq/irq-delay` measures from a timer reset to the handler reading the timer, through the BIOS and libgba's dispatcher: 92 (code in IWRAM), 112 (EWRAM), 120 (ROM) (`TEST ROM`). How many cycles pass between a source raising IF and the CPU seeing the line is not documented (U-IRQ-1). alyosha-tas `irq/*` time reads and writes of IF and IE around the moment an IRQ fires; their readme: "timer runs one cycle after disabling, and interrupt should still occur in this case" (`TEST ROM`). destoer `isr` prints the time and the return addresses (no expected values in its repository; detector comparison only). - Taking the IRQ between instructions is the core's business (`step()` samples `irq`; arm7tdmi-python docstring). The board's business is when the line changes. - Disabling IRQs with an S-bit return: alyosha-tas `psr` (the core's and the board's together). ## HALT and STOP - **HALTCNT** (`301`, write-only byte), bit 7: 0 = halt, 1 = stop (GBATEK §GBA System Control; `DOC`). The BIOS's Halt/Stop SWIs write it; CustomHalt (SWI 27h) writes any value (§BIOS Halt Functions; `DOC`). - **Halt**: the CPU stops until `(IE and IF) != 0`; IME and CPSR.I do not matter ("Halt passes through even if either one has disabled interrupts"; §BIOS Halt Functions; `DOC`). Everything else keeps running; DMA runs during halt (hw-test `haltcnt` "CPUSET DMA": a DMA writes HALTCNT). - hw-test `haltcnt` (`TEST ROM`): halt by a direct byte write, timer 1 IRQ after 0x100 ticks: 12; by CpuSet writing a zero halfword to `04000300`, IRQ after 0x1000 ticks: 4155, and POSTFLG still reads 1; by CpuSet enabling a DMA0 that writes `04000300`: 4154; halting with the IRQ already pending, CpuSet from IWRAM: 125, from ROM: 249. - Halting with an IRQ already pending returns at once (the last two cases; `TEST ROM`). - **Stop**: "The CPU, System Clock, Sound, Video, SIO-Shift Clock, DMAs, and Timers are stopped. Stop state can be terminated by the following interrupts only (as far as enabled in IE register): Joypad, Game Pak, or General-Purpose-SIO. 'The system clock is stopped so the IF flag is not set.'" (§BIOS Halt Functions; `DOC`, GBATEK's own quotation marks: it doubts it). How long the wake-up takes and whether IF is set: U-SYS-3. No hardware test for Stop is in the pinned suites. ## Timers Registers (GBATEK §GBA Timers; `DOC`): TMxCNT_L reads the counter, writes the reload; TMxCNT_H: prescaler (F/1, F/64, F/256, F/1024), count-up (not timer 0), IRQ enable, start. - The reload is copied into the counter on overflow and when start goes 0 to 1. "When simultaneously changing the start bit from 0 to 1, and setting the reload value at the same time (by a single 32bit I/O operation), then the newly written reload value is recognized as new counter value." - Count-up: the timer counts the previous timer's overflows, prescaler ignored. - Timers 0 and 1 overflowing pace FIFO A/B ([sound.md](sound.md)). Hardware results (`TEST ROM`): | Test | Fact | | --- | --- | | hw-test `timer/start-stop` | started with 3 NOPs before the read: reads 3; one NOP, stop, 3 NOPs: reads 8 (it ran on into the stop write) | | hw-test `timer/reload` | reload `FFF8` started by a 32-bit write, 9 NOPs: reads `FFF9` (one overflow); a reload overwrite (16- or 32-bit) up to the next-to-last cycle before overflow takes effect at that overflow (`DEAE`), in the last cycle it does not (`FFF9`); reload `FFFF` with an immediate overwrite: `DEB4` | | hw-test `timer/tick-before-reload` | "After enabling a timer, it takes one cycle to load the reload value into the counter. Alyosha discovered that the timer can tick in the cycle before loading the counter and signal an overflow": with the counter left at `FFFF`, starting the timer from 0 raises timer 0's IRQ flag and ticks a count-up timer 1 once | | alyosha-tas `timer/readme.txt` | "Tests state of the clock divider after power on. Uses div 64 on timer 0 ... dependent on exact power on timing"; "enabling the timer when the current timer value is 0xFFFF ... an interrupt can be triggered even though the timer should be reloaded. Presumably it ticks one cycle before resetting" | | alyosha-tas `irq/readme.txt` | the timer runs one cycle after it is disabled, and its interrupt still occurs | So: the timer's start takes effect one cycle after the write; it keeps counting one cycle after a stop write; a reload write lands in the counter only at an overflow or a start; and the prescaler appears to be a free-running divider shared from power-on, not reset when a timer starts (HYPOTHESIS from the alyosha-tas readme's "state of the clock divider after power on"; judged by `timer/timer`; the board's divider phase at power-on is then `FITTED` to that test with Nintendo's BIOS, U-TIM-4). The mGBA suite's "Timer count-up" (936 cases) and "Timer IRQ" (90) tables judge the rest (src/timers.c, src/timer-irq.c; `TEST ROM`). ## Keypad KEYINPUT bits 0-9 (A, B, Select, Start, Right, Left, Up, Down, R, L), 0 = pressed. KEYCNT selects keys, bit 14 enables the IRQ, bit 15 chooses OR (any selected key) or AND (all selected keys) (GBATEK §GBA Keypad Input; `DOC`). When the IRQ condition is evaluated (every cycle, on change, or level-held) is not documented; mGBA's `keyirq` test exists only as source (no licence, run only, not built here: [validation.md](validation.md)) (U-KEY-1). ## Serial port Modes by RCNT bits 14-15 and SIOCNT bits 12-13: normal 8/32-bit, multi-player, UART, general purpose, JOY bus (GBATEK §SIO Control Registers Summary; `DOC`). Without a link partner the board must still model: SIOCNT's start bit and IRQ at completion with the internal clock (256 KHz or 2 MHz: 8 or 32 bits at 64 or 8 cycles a bit, HYPOTHESIS from the rates), SIOMULTI0-3 reset to `FFFF` at a multi-player start, the SI/SD read-only bits, RCNT's general-purpose pins with pull-ups (§SIO Normal Mode, §SIO Multi-Player Mode, §SIO General-Purpose Mode; `DOC`). The alyosha-tas `Serial/*` ROMs time internal-clock transfers ("If testing with GBI ... the serial port is disabled ... unless the depressible pin on the serial port of the GBP is pressed in"; `Serial/Readme.txt`); the archived board's targets record 8 of them as needing a link partner (handoff-brief.md). The mGBA suite's SIO register and timing tests: both detectors fail most of them ([validation.md](validation.md)). Exact transfer timing: U-SIO-1. ## The board as built (rungs 0-1, 2026-11-19) What the board does where the sections above leave a choice, and the judge that fixed each choice. `FITTED` values were chosen because the named hardware-calibrated judges pass with them; what else was tried is said. Each constant is named in the code beside its rule. ### The order of record One clock, `Bus.now`, in 16.78 MHz cycles. For each CPU bus callback (one per CPU cycle, internal cycles included) starting at cycle `t`: 1. Every scheduled event due at or before `t` runs, in time order; events due in the same cycle run timers, then IF requests scheduled for that cycle, then the picture processor, serial, sound (`gba_python/scheduler.py`). 2. A DMA whose start cycle has come takes the bus and runs to its end (a higher channel that becomes due between two units runs first, the lower one resumes after it). A CPU memory access waits for it; a CPU internal cycle runs beside it (it costs nothing extra while the DMA holds the bus). After a DMA the CPU's next access is N. If the DMA wrote HALTCNT, the halt begins before the waiting CPU access. 3. The access happens at `t`: a read samples the device at `t`; a write lands at `t`. 4. `now` advances by the access's cost. Between instructions the board runs due events, then updates the CPU's IRQ line, then calls `step()`; a halted CPU skips ahead to the next event or its wake-up cycle. The ordering of simultaneous events (step 1) has no judge yet: HYPOTHESIS. ### Rules fitted at rung 1 | Rule | Value | Judges (all pass at the commit in status.md) | Tried | | --- | --- | --- | --- | | Timer: counter holds the reload from w + 1, first tick in w + 2 after a start write in w; a read in cycle t sees ticks before t | `timers.START_TICK = 2` | hw-test timer/start-stop (3, 8), timer/reload (7 lines), mGBA suite Timer IRQ 90/90 and count-up 936/936 | 1: reload reads FFFA for FFF9 | | Timer: an overflow's reload is in the counter at once; reads see the overflow from the next cycle | event at tick + 1 | mGBA suite Timer IRQ (reload FFFD read 4 cycles after the start reads FFFF) | | | Timer: a reload written in cycle w is used by an overflow in cycle c if w < c | `timers.RELOAD_LEAD = 0` | hw-test timer/reload "FFF8 32 6" / "32 7" | | | Timer: IF set 2 cycles after the overflow's tick | `timers.IRQ_LAG = 2` | alyosha-tas irq/IF (cases 1-5), mGBA suite Timer IRQ | 1: irq/IF fails case 2 | | IRQ line: IME(t - 4) and IE(t - 4) and IF(t - 3) | `irq.IME_DELAY = 4`, `IE_DELAY = 4`, `IF_DELAY = 3` | mGBA suite Timer IRQ, hw-test irq/irq-delay (92, 112, 120), alyosha-tas irq/IE | one shared delay for all three: IE and IF cannot both pass; IME 3 also passes irq-delay (under-determined) | | HALTCNT takes effect only while the CPU runs in the BIOS | `fetch_in_bios` gate | hw-test haltcnt "HALTCNT DIRECT" (12: a STRB from IWRAM does not halt), "CPUSET", "CPUSET DMA" | see undocumented-behavior.md U-SYS-6 | | Halt ends 3 cycles after (IE and IF) != 0, never sooner than 3 after it began | `irq.HALT_WAKE = 3`, `HALT_LINE_DELAY = 0` | hw-test haltcnt "CPUSET" 4155, "TIME IWRAM" 125, "TIME ROM" 249 | wake 2: 124/248 | | The 128 KB rule: the access after a cartridge halfword driven at the last halfword of a 128 KB block is N, any direction; CPU S accesses at a block start are N (GBATEK's literal rule) | `Bus.cart_wrapped` | hw-test bus/128kb-boundary 18/18, alyosha-tas DMA/DMA_ROM_Fixed | "access at a block start" alone: 5 decrement lines 2 cycles off; by the chip's counter instead of the driven address: 2 lines off | | The cartridge's counter: N loads it, S uses it, writes move it | `Bus.cart_latch` | hw-test dma/burst-into-tears (values and 41 cycles) | | | DMA: the first cartridge access of a run is N, every later one S, either side | `Bus.dma_cart_fresh` | 128kb-boundary "DMA INC 07FFFFF8", burst-into-tears, mGBA suite ROM-to-ROM DMA rows | per-unit N/S: ROM-to-ROM rows N - S cycles slow | | DMA: start 3 cycles after the enable write (or 2 after an H-/V-blank trigger, not yet judged); 1 internal cycle before the first read, 1 after the last write; the CPU runs until the DMA takes the bus | `dma.START_DELAY = 3`, `TRIGGER_DELAY = 2`, `START_IDLE = 1`, `END_IDLE = 1` | hw-test dma/start-delay 20, force-nseq-access 88/88, mGBA suite timing (Trivial DMA rows) | delay 2 + 2 idle before: start-delay passes, suite DMA rows fail; delay 4 with no internal cycles: four hw-test DMA ROMs fail | | DMA: a channel that takes the bus from a lower one between two units spends neither internal cycle (rung 6) | `dma.NESTED_IDLE = 0` | the AGS aging cartridges' DMA test 9 (validation.md "Rung 6") | 1 (both spent), or only one skipped: DMA test 9 fails | | Prefetch: a buffered opcode fetch completes when all its halfwords are in, in at least 1 cycle | `prefetch.code_fetch` | mGBA suite timing 2,020/2,020 (Calibration row in all 16 modes) | 1 cycle per halfword: ARM rows 1 slow | | Prefetch: the fetch after a write continues the stream (STR's next fetch is N on the pins) | `Bus.after_write` | suite Calibration row | | | Prefetch: a data access to the cartridge empties the buffer; a fetch in its last cycle finishes first; the unit restarts at the next opcode fetch | `FLUSH_ON_DATA = 1`, `FINISH_LAST = 1` | suite timing (LDM across OAM into ROM, ROM loads, DMA rows) | keep the buffer: 1,958; a 1-cycle abort penalty: 1,640; finish 2: 1,866. A 1-cycle restart delay after the access (fitted before the flush, 1,708) became dead code once the buffer empties, and was removed (its seeded fault changed nothing) | | Prefetch: a branch's miss lets a fetch in its last cycle finish | `MISS_FINISH_LAST = 1` | alyosha-tas prefetcher/prefetcher_branch_thumb (41) | 0: 40 | | Prefetch: an N fetch at the head hits only buffered halfwords; a branch to the halfword in flight is N (readme) | `code_fetch` | suite timing, alyosha-tas prefetcher readme | | | Prefetch: the unit runs on across a 128 KB boundary (the readme's "stops ... as though it is full", read as a pause until empty, is not followed) | `BOUNDARY_STOP = 0` | alyosha-tas prefetcher_boundary_1..4 all pass (with the pause: _1 and _3 fail, 81 and 83) | 1 |