# alewman-probe One small ROM of timing tests. The same ROM runs on a real Genesis or Mega Drive, on our emulators, on BlastEm and on the Nuked-MD die simulation. Any difference in the numbers is a bug or a timing gap, and the console settles which. python build.py out/alewman-probe.bin python tools/decode.py FILE a report from a RAM dump, a save, or a screenshot The ROM is 64 KiB and declares 32 KiB of save RAM at $200001, one setting in `build.py`. Nothing depends on the save working: the same bytes sit in work RAM at $FF4000, which is how the die reports (`NMD_DUMP_RAM`), and the screen can show them as hex pages with a CRC each. A cartridge can't see the picture it outputs. Tests that need one report through something the 68000 can read: the HV counter, status flags, sprite collision, VRAM read-back. ## Running it python build.py build; a prediction table is patched in afterwards python tools/predict.py take the table from board `genesis`, and rebuild python tools/decode.py FILE read a save; --boots for the boot log, --run N for a past run python tools/decode.py A=x B=y side by side, differences marked with * python tools/timing.py A=x B=y the packed records: DMA fits, walks, edges python tools/qrdecode.py OUT.sav PHOTOS... a save rebuilt from photos of the QR pages (START on the list) tools/checkrig.ps1 prove repeat boots and hang recovery on an emulator On screen, SAME and DIFF compare the first value with the emulator's prediction, which is what we want checked, not the truth. NEW means no prediction applies. A and B turn pages, C switches to hex. ## The save Layout is at the top of `src/main.c`: header, a ring of 32 boot records, a ring of 3 runs. A run holds a status byte per test, a directory of tag, offset, length and CRC, then raw records (id, repeat, value). A test is marked started in the save before it runs, so a boot that finds it still started marks it hung and carries on. A new ROM build always starts a new run. Each boot record holds what the first instructions saw before writing anything: the HV counter, status, whether our mark survived in RAM, and how much of work RAM, VRAM, CRAM, VSRAM and Z80 RAM wasn't zero. If the flash cart's menu ran first these aren't power-on state, and the run sheet says so. ## The tests so far | tag | value | | --- | --- | | SAVE KEEP BOOT | does save RAM work, did it survive, what the machine held at boot | | CPU1 CPU3 | CPU loops in 16 frames, display off: code in ROM, code in RAM | | CPU2 CPU4 | the same, display on | | CPU5 | ROM code, display on, DMA of 1,024 words each VINT | | DMA1-4 | DMA of 16, 64, 256, 1,024 words from line $F0: HV before and after, one long | | DMA5 | DMA of 64 words from line $40, in the picture | | ZRM1 ZRM2 | CPU loops, display on, Z80 looping in its own RAM: ROM code, RAM code | | ZRO1 ZRO2 | the same, the Z80 reading cartridge ROM on each turn | | DMPR DMPW | DMA of 1 to 512 words, from ROM and from work RAM: HV before and after. One H step is 16 MCLK in H40, so start-up and pace come from a fit over the sizes | | VPOS | HV at the VINT handler's first instruction, and HV when F first shows with the interrupt masked | | RDV0 RDV1 | loops in 16 frames, each reading the VDP data port, display off and on | | BSK1 BSK2 | one read of $A11100 at each of 32 delays after a bus request, as a mask, Z80 running and held in reset. One step is 28 MCLK, and the first read is about 84 MCLK after the request, so a faster grant shows as all set | | IDL1 IDL2 | a fixed DBF loop touching no RAM, from ROM and from RAM, timed in frames and HV | | YMPT | $A04000-3 read with flags clear, with timer A's flag set, and just after a data write | | SPY1 SPX1 SPY0 SPX0 | two overlapping sprites on line 100 or 0; a write moves the second's Y (cache) or X (table) at a walked point. A bit set means they still collided. One step is 30 68000 clocks; rep 0-2 are the two lines before and the line itself | | VSTP | HV either side of the V step, 32 starts a NOP apart, on line $50 (900) and $F4 (903). 12-clock reads and 4-clock starts: 1.7 H steps, 28 MCLK | | RDLN | VRAM reads in 100 picture lines and in 15 blank lines, display on (720, 721) and off (722, 723) | | FFLG | HV then status 16 clocks later, a NOP later each frame: the HV beside F's first show places the edge, so start jitter costs nothing. 1.7 H steps. The first record holds an F left by the test before | | INTF | NOPs with VINT open: HV in the handler and which NOP the stacked PC names. 4 clocks | | BSK3 | bus requested in reset, then a walk from the reset's release: one NOP, 28 MCLK, first read about 84 MCLK after | | BSK4 | BSK1's walk with the Z80 reading ROM through the bank window | | BSK5 BSK6 | a read straight after the request, about 42 MCLK, 32 tries a repeat: how often the grant has already happened. Z80 in RAM, on ROM. A rate, not an edge | | YMP2 | ports 1-3: flag set with a second's quiet, cleared flag straight after a port 0 read, right after a data write, and 0, 20, 60 frames after a port 0 read. Tells a live port from a latch of the last status | | YMBY | BUSY after a data write, 64 NOPs from about 1,000 MCLK. 28 MCLK, against the chip's free-running 42-MCLK cycle, so read over the repeats | | YMFT | the YM fade point to the line: port 0 reads 1, the flag is cleared, port 1 after n lines, n found by halving 0-2,100 (640, two repeats; 641 the first reads) | | ZSW1 | Z80 bank-window reads swept: 0, 4, 16, 64 NOPs between reads; the 68000 in ROM, RAM or a DIVU loop (mostly off the bus); baselines with the Z80 reading its own RAM. Ids 1200 + 20m and 1210 + 20m (the Z80's count), m in `t_zsw` | | ZSW2 | Z80 bank-window reads by phase: a filler of 4-10 T after each read walks all seven places against the 68000's 7-MCLK clock (15 = 1 mod 7). Ids 1300 + 20m, 1310 + 20m (Z80); m in `t_zsw2`: own-RAM baselines, the window on ROM with the 68000 in ROM and in RAM, the window on work RAM read and written, and a write to the ROM window | | ACC1 | loops in 8 frames doing one access at a region: ROM and work RAM (word, long, write), Z80 RAM and YM (bus held), version register, $A11100, VDP status, HV, PSG write, and none; display off (1400 + 2k) and on (1401 + 2k). Cost of an access from the ratio to the ROM loop | | WRV1 | data-port writes in 8 frames, auto-increment 0: VRAM word and long, CRAM, VSRAM, and VRAM in H32; display off (1500 + 2k) and on (1501 + 2k) | | VPS3 RDV3 DMR3 | VPOS, RDV1 and DMPR again in H32 (171 steps of 20 MCLK a line; V steps at $85 is our assumption) | | HINC HINP | a frame with HINT on, register 10 = 0, 1, 7, 100: how many (1550 + k), HV at the first three (1560 + k) and the last (1570 + k) | | ZINC ZINP | the Z80's interrupt: acknowledges in 16 frames by a 33-T handler, so the pulse's length (1600); HV, read by the Z80, at the first of a frame (1601) | | YMTA YMTB | timer A at 20 units, timer B at 2: HV at one overflow and the next (1700, 1701), the YM's clock against the VDP's | | DFIL DCPY | VRAM fill and copy of 2 to 2,048 bytes, from line $E1 and from line $40: HV at the start and when DMA busy clears (1650-1667) | | SPOV | 21 sprites on line 100: HV when the overflow flag first reads set (1750) | | YMDK | how long ports 1-3 keep a status: port 0 reads 1, the flag is cleared, then port 1 after 0 to 128 lines (630) and, from the frame edge, 1-7, 9, 13 and 18 whole frames (631). Runs 4 and 6 put the fade between 3 and 6 frames | | SFY1 SFX1 SFY0 SFX0 | the sprite walks at one NOP a step, 28 MCLK. A write still waits for a slot, so an edge can show a gap: read it as a slot, not as a fault | | DMB0 | the DMA code with register writes in place of the command: what the code costs, to take away from the DMA figures | | DMPC DMPS | as DMPR, to CRAM and VSRAM. Both are left dirty; the screen reloads them | | WEDG | DMA registers, then an ordinary VRAM command: last on purpose, since the die's 68000 stalls for good in the command's second word, DMA enabled or not, by word or long. Boards and BlastEm record 1. The console hangs like the die (runs 1-11; RESET doesn't free it, power does), so the boards are wrong; built only with `--wedge`, kept off the card ROM | The reset log is not a test: every boot saves 18 HV reads, 28 clocks apart, from the first instruction, run from ROM alone. A held at reset logs and stops. `tools/timing.py --resets FILE` prints the mean drift against a clean 196 MCLK a read: each refresh adds 14 MCLK from then on, so the steps date the refreshes after a reset. Resolution about 196 MCLK in time, over 16 or more presses. It can tell the 896 and 2,380 MCLK of the brief apart, not place them to the clock. A DMA's start-up comes from DMPR less DMB0 at the small sizes, and its pace from the fit. INTF is wrong on PAL, where the test's line comes round twice. ZRM and ZRO also hold the Z80's own count, under the id plus 10. The Z80 is held in reset otherwise. Repeats show what changes between runs, so look at the spread before treating one number as different. `docs/brief.md` is not kept here: the spec is `alewman/genesis-probe-brief`, private. ## The long run At power-on the cart shows a menu: A for one run (every test once, about 90 seconds, and what starts by itself after 5 seconds), or START for a long run of 5 to 999 cycles (left and right), with an optional pause between cycles (up and down). A long run repeats every test; after each cycle it adds that cycle into running totals per measurement (n, mean, spread, min, max, or the values seen for bit masks) and, while there is room, a time line entry of 45 chosen measurements and the time switched on. When the time line fills, every other entry goes and it keeps one in two cycles from then on, so any length fits. The screen shows the cycle, the test, the time gone and to go, how many cycles are saved, and the YM fade's first and latest point. RESET or power-off mid-run is safe: the next boot offers to carry on (it does after 5 seconds; B stops it there and shows the results). The last cycle's raw records are kept as a normal run, so `decode.py` and `hwref.py` read it as before. python tools/soak.py FILE totals: n, mean, sd, min, max per measurement python tools/soak.py FILE --ref the same beside the console's reference ranges python tools/soak.py FILE --series the time line; --csv OUT.csv writes it all python build.py --soak N a ROM that starts a long run of N cycles by itself The clock counts VINTs, which the tests mask much of the time, so `TICK_SCALE` and `CYCLE_TICKS` in `build.py` (from board `genesis`: about 5,200 frames and 3,837 VINTs a cycle) turn it into time. Save format 6: one run slot of 9,200 bytes, then the long run's area: 288 totals of 32 bytes (min and max as 16-bit offsets from the first value; bit masks keep 3 values), then the time line. ## The audio test C at the power-on menu plays a fixed sound loop (about 27 s) until power off, for the YM2612 DAC's "ladder", the step where its output crosses zero, measured cold against warm. Nothing is saved; record the console's headphone output instead (stereo, 48 kHz, no effects or automatic level, the volume slider at the same mark every time, three loops or more). The loop: a 981 Hz mark, the DAC at its middle, all off, a 220 Hz DAC sine at 127/32/8/2 steps, then a 440 Hz FM sine (channel 1, operator 4 alone) at TL 0/16/32/48/64/80. `python tools/audio.py COLD.wav WARM.wav --plot OUT.png` puts recordings side by side: each sine's level, zero-crossing step, THD and noise in 8-bit DAC steps. `build.py --audio` makes a ROM that goes straight into it, for emulators. On board `genesis` the quiet FM parts come out as ±2-step squares, our board's ladder; the console's output filter will round them.