# Timing Everything on the board is a fraction of one master clock (MCLK, 53,693,175 Hz NTSC, 53,203,424 Hz PAL; [start-here.md](start-here.md), "Clocks"). The 68000 ticks every 7 MCLK, the Z80 and PSG every 15, the YM2612 every 7 (one output sample per 144 of its clocks), the VDP every 8 or 10 depending on the horizontal mode. A board that schedules in MCLK can place every event exactly and convert at the edges; one that schedules in 68000 cycles has to carry fractions for the Z80 (15/7) and the VDP (a line is 488 4/7 cycles). Sources and their tiers are in [validation.md](validation.md). The hardware tables here come from Nemesis's 2010 logic-analyser captures (forum t=768; the raw dumps are `tests/test_roms/nemesis/sr logic analyser results.zip`) as tabulated by Kabuto ("H/V counter values"), and from Kabuto's own measurements. Where only an emulator gives a number, it says so. ## The line and the frame A line is 3,420 MCLK in both horizontal modes (Jorge Nuno's oscilloscope measurements, forum t=519: an NTSC H40 line of 420 pixels is 3,420 MCLK). H32 is 342 pixels at MCLK / 10. H40 is 420 pixels at MCLK / 8, with the pixel clock slowed for part of the horizontal sync to make up the difference ("the VDP slows down its clock for a number of cycles during HBlank (32 pixel clocks according to my oscilloscope tests) - starting 24 pixels after the right edge", Kabuto, "Picture size"). Lines per frame, from Kabuto ("Picture size"), V28 (224 active lines): | | Top border | Picture | Bottom border | Sync | Blank | Total | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | NTSC | 11 | 224 | 8 | 3+3+3 | 10 | 262 | | PAL | 38 | 224 | 32 | 3+3+3 | 10 | 313 | V30 (240 lines) takes 8 lines from each border. On NTSC it leaves no border and no sync ("0x000-0x1FF" in the V counter table below): the picture rolls, as it does on the SMS in its 240-line mode. Horizontally there are 13 left and 14 right border pixels (Kabuto). Interlace modes alternate fields; on odd frames the NTSC field has an extra line in both interlace modes (Nemesis, acknowledged in forum t=768). ## The H and V counters Read at $C00008 (V in the high byte, H in the low byte; "VC0 is replaced with VC8 when in interlace mode 2", CMD `genvdp.txt` citing the Manual). From Nemesis's captures (Kabuto's table, "H/V counter values"): | | H32 | H40 | | --- | --- | --- | | H counter sequence | $00–$93, $E9–$FF | $00–$B6, $E4–$FF | | V counter increments when H goes | $84 → $85 | $A4 → $A5 | | HBlank flag set when H goes | $92 → $93 | $B2 → $B3 | | HBlank flag cleared when H goes | $04 → $05 | $05 → $06 | | | NTSC V28 | PAL V28 | NTSC V30 | PAL V30 | | --- | --- | --- | --- | --- | | V counter sequence | $000–$0EA, $1E5–$1FF | $000–$102, $1CA–$1FF | $000–$1FF | $000–$10A, $1D2–$1FF | | VBlank set when V goes | $DF → $E0 | $DF → $E0 | $EF → $F0 | $EF → $F0 | | VBlank cleared when V goes | $1FE → $1FF | same | same | same | | F (vertical interrupt) flag set | H $00 → $01 on V $E0 | same | H $00 → $01 on V $F0 | same | The H counter counts every other pixel (it is the internal 9-bit counter shifted; Eke confirms the internal sequence in forum t=768). CMD's `m5hvc.txt` has the same ranges but calls itself "probably off by one or two"; do not use it for positions. Where each value falls in MCLK, read out of the raw captures, is the next section. ## What the captures say, sample by sample (milestone 2) `scripts/run_hv_captures.py` runs each of Nemesis's 288 dumps (32 captures: "HV" and "SR" ROMs, PAL Model 1 and NTSC-J Model 1, H32/H40 x V28/V30, no interlace and the three interlace settings; each ROM stores 15,360 pairs of reads in 30,720 words) on the board and compares every word. What the board cannot know is fitted per dump: where in its line the VDP is, the 9-bit V and ODD flag, whether the H mode written before the loop has latched, and the phases of the two refresh stalls. The fit is a search over every phase pair (7-MCLK steps) and every line position the first sample allows, scored on the H counter alone; the survivors are scored on H and V; the board then runs the loop from each best placement. Nothing else is fitted per dump. Result at the commit that adds this section (PyPy 7.3.23 / Python 3.11.15, 78 s on 16 processes): - **8,762,415 of 8,847,360 words equal (99.04 %).** Of the 84,945 others, 61,440 are two dumps the search could not place at all, 11,103 one dump (below), 9,869 reads at a sampling phase where a counter steps (next paragraphs), and 2,533 the differences listed under "Not explained". - Per capture: the non-interlaced HV and SR captures agree on 99.74-99.99 % of words, with at most a few differences away from the stepping phases each; the interlaced ones on 99.5-99.99 % except the four with the dumps below. Per-capture counts come from the script (`--verbose` gives every dump) and are kept in `tests/hv_captures_baseline.json`, which the tests hold the board to. **Line timing.** Measured from the V counter's increment point (internal H $10A in H32, $14A in H40), a pixel lasts: | Line | Pixels (internal H) and MCLK each | Total | | --- | --- | ---: | | H32 | $10A-$127, $1D2-$1FF, $000-$109: 10 | 3,420 | | H40 | $14A-$16C, $1C9-$1CC: 8; $1CD-$1D3: 10; $1D4-$1D5: 9; $1D6-$1DC: 10; $1DD: 8; $1DE-$1E4: 10; $1E5-$1E6: 9; $1E7-$1ED: 10; $1EE-$1FF, $000-$149: 8 | 3,420 | | H40, VSYNC lines | as H40 but $1DE-$1ED: 8, and $09F-$0A5: 10, $0A6-$0A7: 9, $0A8-$0AE: 10 | 3,420 | | H40, interlaced odd field, first VSYNC line | as H40 plus the moved run at $09F-$0AE | 3,450 | | H40, interlaced odd field, last VSYNC line | as H40 but $1DE-$1ED: 8 | 3,390 | The H32 and ordinary H40 lines are Exodus's tables (Nemesis's), confirmed. The VSYNC lines are new: on the nine lines ending on V = jump + 5 (PAL V28 $100-$102 and $1CA-$1CF, PAL V30 $108-$10A and $1D2-$1D7, NTSC V28 $0E8-$0EA and $1E5-$1EA; none in NTSC V30, which has no VSYNC) H40's second run of long pixels is at $09F-$0AE instead of $1DE-$1ED (7,681 of 7,724 PAL V28 samples on those lines agree, 4,043 with the ordinary line). In an interlaced odd field the lines with the moved run end one line earlier than those with the short $1DE-$1ED, so the first is 30 MCLK long and the last 30 short. The V sequences, the HBlank and VBlank flags and F are as in the tables above, at internal H $126/$166 (HBlank set), $00A/$00B (cleared) and $001 (F); in interlace the port shows V bits 7-1 and 8 (doubled: 6-0 and 7), and an odd field adds line jump - 1. **Sampling.** A read of the HV counter or the status register sees the counters at the first pixel-clock edge at or after 3 MCLK into its bus cycle. At three phases the read lands as a counter steps: the pixel before that edge began 1 MCLK (*edge*) or 2 MCLK (*late*) before the sampling point, or the sampled pixel begins exactly at it (*next*). What a read there shows is analogue: the two consoles differ, and one console's reads at the same phase vary between runs and even within one. The board copies each console's majority (`vdp.HV_UNITS`): | | PAL Model 1 | NTSC-J Model 1 | | --- | --- | --- | | H32, edge | old AND new if the step changes bit 2 or above, else new | the same from bit 3 | | H32, next | clean | the three low bits read clear if the coming step carries past them | | H32 jump $127 → $1D2, edge | $1C2 (54 of 67 reads; $1E2 otherwise) | $1C2 | | H40 8-MCLK pixels, edge | new | old AND new from bit 2; jump $16C → $1C9 reads $148 | | H40 long pixels, edge | old | old | | H40 long pixels, late | new | old AND new from bit 2 | | V (H32), step carrying into bit 1 | old (13 of 22; old OR new otherwise) | old OR new | A step that carries changes its low bits first: bits that clear have cleared and the bit that sets has not (a ripple counter). 9,869 reads at these phases differ from the board anyway (outside the one dump below); they are counted apart. **Not explained, and not claimed:** - Two dumps are not placed: "HV noint intdub NTSCJ H40V28" 1, whose H low nibble reads 3 in every sample and whose status shows DMA busy (not the counters at all, as far as the board can tell), and "HV noint intinv PAL H40V30" 1. - "HV noint intinv PAL H40V28" 6: 11,103 differences, H reads one step behind the board's in every second sample; the other eight dumps of that capture agree. - "HV noint intnorm PAL H32V30" 1 reads F set from its first sample; the first run of every other capture reads it clear until its first VBlank. - The first runs of "intnorm NTSCJ H32V28" and "H40V28" read VBlank set on the lines before the first VBlank (668 samples; 37 more VBlank reads elsewhere). - The HBlank flag differs on 228 status reads over all captures, a pixel from its edges; the sprite overflow flag (bit 6) on 10 (no sprites are drawn). - 302 H or V reads away from the stepping phases, most of them in the interlaced NTSC V30 H32 captures. The HV counter can be latched (mode register 1 bit 1; used by light guns via the external interrupt). Jorge Nuno's 2022 captures with a "fake 68000" give the status register's trip points in H40 (mddc.dev thread, snapshotted); his raw data is on a pastebin the snapshot links to. ## Interrupts - **Vertical (68000 level 6)**: the F flag is set at H $00 → $01 on the first line of vertical blanking (table above); the 68000's IPL follows when mode register 2 enables it. The exact delay from the flag to the IPL change, and to the 68000 taking it, is the kind of number VDPTEST (`md_test.zip` → `VDP_TEST.zip`) and BlastEm's `gen_test_hv.s68` probe; neither publishes hardware values in the pinned material. Settle it from the logic-analyser threads (MoD, forum t=1291, gives an HSYNC-to-ODD-flag and a HINT-to-HSYNC count) or leave it open. - **Horizontal (level 4)**: register $0A is a down-counter decremented on each line of the active display and reloaded outside it; the interrupt fires when it underflows (Manual; Plutiedev `vdp-registers`). With the vertical border opened (below), it "runs continuously and is not reset before the start of each frame" (Kabuto). - **External (level 2)**: the TH pin of a port set to interrupt (light guns). - **Z80**: an IRQ once a frame at the start of vertical blanking (CMD `gen-hw.txt` 2.4), missed if the Z80 has interrupts disabled. Its length is open ([undocumented-behavior.md](undocumented-behavior.md)). ## Display-register propagation (evidence withdrawn, not implemented) Register writes bypass the FIFO, but do not reach the register immediately. For ordinary 18-MCLK control-port writes, the H32/H40 probes and the saved plasma run agree on a clocked rule: capture at the first half-pixel clock edge at least 20 MCLK after /AS falls, then commit at the following HCLK1 edge. A capture on HCLK1 waits for the next HCLK1, not the current edge. These figures were read off the model's internal clock and counter signals (`HCLK1`, `HCLK2`, `DISPLAY`, the H counter) through the old harness's `NMD_VDPSIG`, which `scripts/check_register_latch.py` and `scripts/run_hscroll_latch.py` checked (1,816 transitions; 896 H-scroll requests). Those taps were removed in provenance wave 2 (2026-11-19) and both scripts retired with them, so the rule above is **withdrawn evidence**: OBSERVED inside a closed box we may only read at its pins. It was never implemented; a pin-level measurement (the picture, or the bus) would be needed before it could be. This is not a justification for adding a constant delay to every register write. The physical-counter clock and the board's calibrated port-sampling clock also need distinguishing. Neither a runtime-only clocked H-scroll gate nor the same gate with scheduled register writes improved the earlier full plasma comparison (7,904 versus 7,849 disagreements). Repeating the gate diagnostic with the latest fresh calibrated state worsens it to 15,788. Picture alignment after the logo's one-frame advance shifts CPU phase by -1 mod 7 and cartridge-refresh phase by 636 mod 896. At plasma row 102, that one-MCLK arrival difference selects a different register-capture edge and reverses the request decision. Do not compensate by moving the request deadline. Production register timing is unchanged; see the worklog's bounded plasma request investigation. ## VRAM access slots The VDP makes one 32-bit VRAM access every two pixel clocks: 210 per line in H40, 171 in H32 (Kabuto, "Memory access pattern", confirmed by Nemesis's and MoD's logic-analyser work, forum t=851 and t=1291). The order within a line (H = H scroll, A/B = plane name fetches, a/b = plane pattern data, S/s = sprite, ~ = an external slot for the CPU or DMA, r = refresh): ```text H40: Hssss AsaaBsbb ((A~aaBSbb)*3 AraaBSbb)*5 ~~ s*23 ~ s*11 H32: Hssss AsaaBsbb ((A~aaBSbb)*3 AraaBSbb)*4 ~~ s*13 ~ s*13 ~ ``` So H40 has 18 external slots a line in the active display, H32 16 (MoD, forum t=1291: 171 slots, 4 refresh, 16 CPU). With the display disabled, and during vertical blanking, every slot except the refresh slots is external (Kabuto: "When display is disabled the VDP still does those refresh cycles and uses all other cycles as access slots"). Where the external slots fall matters for the FIFO: a 68000 write that finds the FIFO full waits for an entry to finish its memory write and become reusable by the CPU. **CPU acknowledgement after commit (Nuked-MD measurement).** During active H40 lines, the die's FIFO read pointer releases 39 MCLK after our normal commit slots, or 44 after the slow-clock slot at H $1CE. Its /AS ends 8-14 MCLK after full falls. With the board's existing bus sampling, CPU reuse becomes ready **29 MCLK** after a normal commit and **34 MCLK** after H $1CE; the CPU callback still rounds the resulting hold up to 7-MCLK clocks. A write arriving after commit but before that ready time must also wait. A 64-KB VRAM word is released only after its second byte. `fifo_cpu_ready` tracks this separately from memory commits, status/full flags, DMA input readiness and DMA read pacing. H32 and idle-slot behavior are unchanged; this is not a claim to have implemented the physical FIFO status pipeline. `scripts/run_fifo_release.py` generated VRAM/CRAM/VSRAM probes and replayed their exact CPU arrivals; all 21,933 synthetic writes and 3,820 plasma VSRAM writes matched their /AS lengths (pins). The replay's start, a confirmed empty FIFO after a line origin, was read off the model's internal FIFO pointers and H counter (`NMD_VDPCLK`, `NMD_FIFOSIG`), taps removed in provenance wave 2 (2026-11-19) with the checker, so the 29/34 MCLK figures are **provisional** until replayed at the pins alone (line origin from the /HSYNC pin, the FIFO known empty from the program). Older pickle snapshots do not contain the new readiness state; regenerate them from power-on for validation rather than silently assuming an empty pipeline. **How many slots an idle line has** (settled in milestone 5). Exodus's `GetPixelClockTicksUntilNextAccessSlot` skips *two* slots per refresh, which leaves 161 in H32 and 198 in H40. Two hardware sources say one: Kabuto's pattern above has a single `r` per group, and the Manual's DMA transfer capacity table (below) gives 167 and 205 bytes a line in blanking, which is 171 − 4 and 210 − 5. The board takes one slot per refresh, at the H counter values Exodus's own tables name as the refresh slots — five in H32 and six in H40, "one more than there is during an active line" (Exodus), the extra one falling in the horizontal blank. That gives **166 and 204**, and reproduces every figure of the Manual's table to one byte (`scripts/run_dma_cost.py`). **Where the display's pixels are.** The active display is external H $00–$9F in H40 and $00–$7F in H32 — internal H $000 onwards, 320 or 256 pixels (CMD `genvdp.txt`; the V counter increments after it, at external $A5/$85). Kabuto's slot groups fall into place around that: his 15 "mid-tiles" slots are the ones inside $000–$13F, his two "between-tiles-and-sprites" ones are $140 and $142 just past it, and his single "mid-sprite" one is $1CE, in the blanking. What the board does **not** model is his statement that the second mid-tiles slot lands "at the pixel with X=-3 (display area coordinates)", which would put the output about 21 pixels behind the H counter; a mid-line write lands at the pixel its access slot's own H counter names (milestone 5). CRAM writes during the display (the "CRAM dots") appear there too. ## DMA Kabuto ("DMA speed"), in 68000 cycles beyond the instructions' own: - **Fast** (to CRAM, to VSRAM, to VRAM in 128 KB mode): words × 2.4 + 5.6. Limited by how fast the VDP fetches: one word per internal cycle, except two skipped for each of five refresh cycles per line. - **Slow** (to VRAM in 64 KB mode): max(words × 2.4 + 5.6, words × 4.7 − 6). Limited by VRAM writes once the FIFO is full. The board reads on the die's ticks, every slot tick but each refresh's and the one after it: the mechanism Kabuto describes, at 2.47 cycles a word in H40, 3 % above his 2.4 (worklog, "The read pace"). During a 68000-memory DMA the 68000 is off the bus (Nemesis's `TestDMATransferBusLock` in VDPFIFOTesting). Fill and copy run inside the VDP and do not stop the 68000. The Manual's "DMA transfer capacity" table (PDF page 44) agrees with the slot counts: | Bytes per line | H32, display | H32, blanking | H40, display | H40, blanking | | --- | ---: | ---: | ---: | ---: | | 68000 memory to VRAM | 16 | 167 | 18 | 205 | | VRAM fill | 15 | 166 | 17 | 204 | | VRAM copy | 8 | 83 | 9 | 102 | (The copy figures are partly illegible in the text-layer scan; check them in the 183-page scan.) With the display disabled, the blanking figure applies on every line. **What the board gives** (`scripts/run_dma_cost.py`, display off, 68000 memory to VRAM): 16.1, 167.1, 18.1 and 205.1 bytes a line, against the Manual's 16, 167, 18 and 205. Per word in H40: **2.37 68000 cycles** for a fast transfer (CRAM, VSRAM, VRAM in 128 KB mode) against Kabuto's 2.4, and **4.78** for a slow one (VRAM in 64 KB mode) against his 4.7. The board holds the 68000 from the end of the cycle that grants the DMA bus until the last word is *read*, which is where his "the DMA ends while there is still data in the FIFO to be processed, this is why there are seemingly negative costs" comes from. **The trigger handshake.** A transfer-mode write to source-high register $97 (bit 7 clear, mode 5) arms the next trigger's extra 21-MCLK hold. With no intervening source-high rewrite after a transfer, the trigger is ordinary and one more CPU bus cycle completes before the VDP takes the bus. That cycle's refresh/access waits count before the grant, not after DMA. The first-read and RAM-refresh-pause timing are anchored to whichever cycle grants the bus. `scripts/run_dma_trigger.py` measures the distinction on Nuked-MD: rewriting $97 every time gives sixteen 39-MCLK triggers; writing it only at setup gives one 39-MCLK trigger and fifteen 18-MCLK triggers; alternating rewrites alternates 39/18. The short case also has one CPU prefetch before /BGACK. This is die-derived; it explains why Overdrive 2's plasma differs from the earlier boot/first-read probes. **The start-up cost.** Kabuto's formulas carry a +5.6-cycle intercept on a fast transfer, so a one-word transfer costs eight 68000 cycles on his hardware; the board had no mechanism for it and charged about one (milestone 5). Milestone 6 put Nuked-MD on the same transfer and it charges 11.0 cycles for one word, fitting +8.0 over 1 to 512 -- so the start-up is real and the referee is on Kabuto's side of the question. The timing session adopted it, taking the **hardware** figure because the two judges disagree in size: `VDP` charges Kabuto's own 5.6 cycles (`DMA_STARTUP_MCLK`, 39 MCLK) before the transfer's first word is read. A one-word fast transfer now costs the board **7.4** cycles (6.9 in the referee's own harness) against his 8.0 and the referee's 11.0, and the fitted intercept is +1.7 (+9.0 in that harness) — the two harnesses' fits of the same board differ by about seven cycles, which is why the one-word figure is quoted beside them. The slopes did not move. ## Bus sharing - **Z80 access to the 68000's bus** (the bank window): "delayed by 2 to 5 cycles ... The average Z80 delay is around 3.3 Z80 cycles, whereas the average 68k delay is around 11 68k cycles" (Kabuto, "The bus system"). MoD measured it with a logic analyser on a Genesis 2 (forum t=1661): with the 68000 stopped, 2–3 wait states and 2 cycles from /BR to /BG; with it running, 4 wait states; an average just under 3 over 16 accesses. Modelled in milestone 5 from Kabuto's footnote 1, which gives the arithmetic behind his averages (`src/megadrive_python/arbiter.py`); the board's figures are in [worklog.md](worklog.md) and `scripts/run_bus_arbiter.py` measures them by running MoD's two experiments. What the board supplies to that arithmetic is his `a`, and the timing session corrected it: **the 68000 holds the bus for the /AS-low part of its cycle, 18 of its 28 MCLK**, not for the whole four clocks, and an access it has not begun holds nothing (68000 UM, "Bus Arbitration"; Nuked-MD measures 1,706 of 1,766 cycles at exactly 18 MCLK in Kabuto's own `jmp (a0)` loop, and the other 60 at 32 -- 18 plus the cartridge refresh's 14, which is his "up to 6 cycles if the last access is delayed by the refresh logic"). With that the board charges **2.86-2.91** wait states on his loop against MoD's measured 2.93 and the referee's 2.74, where before it charged 3.36-3.56 and produced 5s neither sees. **Current limitation:** NEW10's NTSC hardware ranges still put both CPUs slower than the board when sharing the cartridge, while CPU-only and Z80-local-RAM controls agree. In the calibrated OD2 logo trace, all 4,096 modeled cartridge grant onsets match the die, but the current own-cycle rule releases some Z80 waits too early. A cartridge-only 31-MCLK threshold is diagnostic, not adopted: it improves that replay but does not resolve the independent hardware phase tests. See [the measured logo boundary](worklog.md#new10-and-the-calibrated-logo-wait). Independent ROMs now also expose missing work-RAM refresh timing on Z80 bank accesses: isolated reads and writes take a refresh on the die, while paired reads distinguish an access-triggered refresh from one already running. Do not replace this with a fixed RAM delay. A cartridge-refresh expiration candidate passed the stopped-CPU replay but worsened fresh-run synchronization; it was removed from all three cores. See [the independent refresh probes](worklog.md#independent-z80-refresh-probes). **Measured, not yet implemented:** direct device acknowledgements explain all 14,141 checked accesses with one 23.5-MCLK acknowledgement-to-release threshold followed by Z80 clock sampling. This includes 4,362 accesses in the actual OD2 logo window. `scripts/check_z80_ack.py` checks the handshake without rounding away half-MCLK edges; the remaining model work is predicting device /DTACK, rather than fitting one own-cycle constant. See [the acknowledgement pipeline](worklog.md#the-z80-acknowledgement-pipeline). **VDP data-port ownership:** FIFO and read-cache waits extend the CPU's /AS interval in the arbiter grid, not just its instruction time. An independent FIFO-contention probe matches all 1,193 die grant onsets with these spans, versus 354 when the VDP holds are omitted. Control-port DMA time is not added wholesale to /AS: the CPU has released the bus during the transfer. No arbiter constants change. See [the ownership correction](worklog.md#vdp-data-port-bus-ownership). **Cartridge readiness, diagnostic only:** the refresh horizon must include the actual grant, which can fall after request+50 MCLK. Combining that horizon with refresh expiration predicts cartridge /DTACK at grant+7 MCLK plus any remaining refresh time. With the measured release pipeline, all 19,783 checked cartridge waits match the die. This is still not an accepted board correction: a fresh isolated run retains the logo slip, changes the Z80 counter-polling path, and worsens some hardware paired counts. See [the coupled readiness investigation](worklog.md#logo-gap-attribution-and-coupled-readiness). - **The bus grant to the 68000** ($A11100 to BUSACK): two things in series. The Z80 samples BUSREQ "with the rising edge of the last clock period of any machine cycle" and lets go after it (Zilog UM0080), so it releases at the end of the machine cycle in progress; the arbiter then takes its own propagation to report that, which nothing hardware in the pinned material measures. Nuked-MD, which the tier rule lets judge where nothing hardware does, puts the whole delay from the $A11100 write to /BUSAK at 9.71-16.86 68000 cycles (mean 12.34 over 122 grants) where the specification's rule alone gave 1.43-6.29. The timing session adopted the difference as `arbiter.BUSACK_PROPAGATION_MCLK` = 57 MCLK, fitted and labelled die-derived; the board's grants are then 9.57-13.43 cycles, mean **12.29** against the referee's 12.34. A 68000 access to the Z80's space before the grant is held by the arbiter ([undocumented-behavior.md](undocumented-behavior.md), open item 8). - **A refresh steals 2 of every 128 68000 cycles**: "every time 128 cycles have passed the next bus access is slowed down by 2 cycles" (Kabuto), except when the 68000 is writing to the VDP. After all slow-downs "the 68K seems to be running at roughly 480 cycles per raster line instead of the theoretical 488+4/7". Work RAM accesses have their own further slow-down he did not measure. The board's model (`board.py`), made exact against Nuked-MD (die-derived; a detector) and judged by the captures, whose sampling loop it reproduces to the MCLK: a fixed 896-MCLK grid; the first 68000 bus cycle to start at or after each tick absorbs it, and takes 14 MCLK longer only if it is a cartridge access. Milestone 6 checked that rule against Nuked-MD's own reported bus-cycle lengths and it is **exact**: fitted to the referee's observed stretches it reproduces all of them at one phase window (518-523 MCLK from power-on) for two unrelated programs, and over ten test ROMs it misplaces none of the referee's ticks. The obvious variant of it -- only a cartridge access absorbs the tick -- reproduces neither program at any phase. Separately, the next work-RAM access once one is due waits 21 MCLK, and the next falls due 805 MCLK after that access started. The 21 is confirmed; **the re-arm rule is not**, and the timing session investigated it against the referee and kept 805 because nothing better was found ([undocumented-behavior.md](undocumented-behavior.md), open item 5, which lists the five candidate rules tried and what each scored). In the capture loop the board's figure gives 143.588 MCLK per `MOVE.L (A0),(A1)+`, as the hardware. **Comparison caveat:** matching pictures and VDP line origins does not match the independent 896-MCLK refresh phase. In the FIFO-corrected plasma run, the existing rule predicts all 16,044 cartridge accesses in 382 closed bursts at the die's arrival times and phase, while the picture-aligned board phase differs. Row 35's extra 21-MCLK arrival gap is explained by one 14-MCLK refresh stretch and the subsequent DMA's phase-dependent rounding; it is not a new trigger-hold constant. The worklog records the diagnostic and its follow-up: the capture harness used the wrong reset time, and a genuine one-frame advance begins at frame 7053. For the standard Overdrive 2 oracle run, use `board_frames.py --reset-mclk 26601719 --reset-exact`, not the die's raw button-press time. The calibrated grids agree before picture alignment; shifting a picture by one PAL frame shifts its refresh phase by 636 MCLK modulo 896. - **Every 68000 access to $A00000-$A0FFFF costs one extra 68000 clock.** Nothing hardware covers it; Nuked-MD holds all 68 such accesses in milestone 6's FM probe 7 MCLK, and MAME charges the same clock (`before_delay(1)`, its own comment "TODO: unverified"). Adopted in the timing session (`board.Z80_SPACE_STALL`), which removed the largest named class of clock difference from the milestone-1 lockstep. With every stall the board charges, a 68000 in a `jmp (a0)` loop keeps **480.9** of a raster line's 488.6 clocks for its own instructions with the Z80 in its own RAM, which is Kabuto's "roughly 480 cycles per raster line instead of the theoretical 488+4/7 ones", and 360.3 with the Z80 reading the bank window (the 481.0 once quoted for that left out the Z80's holds; `scripts/run_bus_arbiter.py`, `--cartridge`; the six lockstep games, which also pay VDP stalls, run at 468 to 475). - **VDP stalls**: a 68000 write to a full FIFO, or a read of VRAM/CRAM/VSRAM, holds the 68000 until the VDP's next external slot; a 68000-memory DMA holds it for the transfer. A Z80 bank access during either waits too (Kabuto). m68000-python's `step()` returns an instruction's total clocks, and the board decides where in the instruction each bus access falls. sms-python solved the same problem for the Z80 with a per-opcode table of access T-states (`IO_ACCESS_T`). The 68000 has many more cases; m68000-python's `function_codes=True` passes each access through the callables in order, which is enough for a board to count cycles between them if the core also reports the clock at each access. Decide this early (milestone 1): it is what makes the VDP stalls and the arbiter's delays land at the right cycle. ## The YM2612 - A register write must wait for the chip's shift register to come round: "maximum write speed ... 33.6 Z80 cycles" between writes (Kabuto, "The YM2612"). - The BUSY flag lasts 32 internal clocks (32 × 6 68000 cycles) after a data write, the same on the discrete YM2612 and the ASIC, and only data writes set it (Eke's 2017 measurements, forum t=386 start=810). Games that poll it (and Hellfire's music tempo on the Model 2) depend on this. - The DAC (channel 6 PCM) is sampled once per chip cycle, at a point that differs between the Model 1 and Model 2 (Kabuto: "unfortunately I can't give any precise values here"). Nuked-OPN2 (YM3438) and YM2608-LLE (YM2612) are cycle-accurate die-derived models: run the same register stream through them to get the judge's output ([validation.md](validation.md)). > **2026-11-13.** The next paragraph and the PSG's last paragraph below were > learned from the die models and judged the withdrawn sound cores; see validation.md, "Milestone 4 after the restart". The restarted ym2612-python is a > per-sample core that takes writes at sample boundaries; it does not run this > pipeline. The clock grid itself (MCLK/7, 144 clocks a sample, BUSY 192 clocks) > is in its own spec, from Yamaha's and others' documents. **The chip's own clock grid** (milestone 4, from those models). The YM2612 runs at MCLK / 7 and divides that by 6, so one *internal cycle* is 42 MCLK and serves one of the chip's 24 operator slots; 24 cycles -- 1,008 MCLK -- are one output sample, which is 53,267 Hz on NTSC and 52,781 Hz on PAL. Slots 0-5 are the six channels' operator 1, 6-11 operator 3, 12-17 operator 2, 18-23 operator 4. Every stage of the chip is a fixed number of cycles behind the slot being served (the phase generator 19 and 20, the envelope 22 and 23, the modulation 6 and 18), which is why a register written between two cycles reaches one operator this sample and the next operator only next sample, and why the withdrawn FM core ran the pipeline rather than a per-sample loop. BUSY's 32 internal cycles are 32 x 6 = 192 68000 clocks, which is Eke's measurement read the other way round. Timer A counts one per output sample (1,008 MCLK); timer B one per 16 of them. ## The PSG The PSG inside the VDP is clocked at MCLK / 15, the Z80's clock. It divides that by 4 into two internal phases and serves one of its four channels per phase pair, so one full rotation -- one output sample -- is 16 input clocks: 240 MCLK, 223,721 Hz on NTSC. Five FM samples take exactly 21 PSG samples (1,008 x 5 = 240 x 21), which is how `src/megadrive_python/audio.py` box-filters one onto the other without drift. The *period* a counter is compared against comes from a one-hot selector that runs one place behind the counter index, so counter 0 is the noise channel's, counter 1 tone 1's, counter 2 tone 2's and counter 3 tone 3's (Nuked-PSG; milestone 4). ## Frame pacing for a frontend NTSC runs 53,693,175 / (3,420 × 262) = 59.92 frames a second, PAL 53,203,424 / (3,420 × 313) = 49.70. The YM2612's native rate is 53,267 Hz (NTSC); a frontend resamples to the host's rate. sms-python's frontend lets the audio queue pace the frames; the same design fits here.