Put the player on a real volume, and find the write window is the frame

ROADMAP K3. src/player/packed.s (2,898 B) brings up its own display, builds
its own 193-entry DMA chain, keeps its own frame clock off V-DISP and fetches
every record itself with READ(10) off a CZ-6BS1. The rig writes no picture
byte, no palette entry and no CRTC register.

120 of 120 frames pixel-exact, every one compared, in both palette orders --
the gate had to grow to do it, because a packed frame is a LITERAL and the
codec's recursion was what made one comparison audit 120.

And the write window turns out to be the frame. A packed write requires R20
bit 11, buffer mode blanks the layer, and a DMAC-direct player holds the
window open for the whole data phase, so

    dark fraction of a slot = record bytes / (DATA-PHASE rate x slot)

which is 1.0 at the container's own 582.0 KB/s: every frame delivered, on
time, pixel-exact, and none of them displayed. The rate in that expression is
the BURST rate, a third hardware number B1 has no test for. It reverses 61.5's
ranking -- a packed player that DMAs to RAM and paints with the measured 27.3%
blit is on screen 72.7% of every slot at any rate, and the two are equal only
at 2,131 KB/s = 3.7x the wire.

And a held channel costs the frame clock half its ticks without the clock
being able to tell: 487 of 1,038 V-DISP edges lost, zero late frames reported,
the player believing 12 fps while the screen ran at 6.37.

FINDINGS 64. ROADMAP K4 opened and fenced behind B2.
check.sh ALL GREEN before and after.

Claude-Session: https://claude.ai/code/session_01194oWYW8DQXK1SZ2DnChW6
This commit is contained in:
prosolis
2026-08-25 09:10:48 -07:00
parent f1007a0dbc
commit 6f698ca226
14 changed files with 2091 additions and 23 deletions
+52 -2
View File
@@ -292,6 +292,53 @@ ships**. The fallback is already a flag: `--scene-palette --no-palette` is
30.79 dB, zero churn, **576.0 KB/s**, and still +2.07 dB on the shipping codec as 30.79 dB, zero churn, **576.0 KB/s**, and still +2.07 dB on the shipping codec as
the display renders both (FINDINGS 63). the display renders both (FINDINGS 63).
**And the packed player runs, end to end, off the disc — the strongest
result in this tree, next to the worst news in it.** `src/player/packed.s` is
2,898 bytes: the 68000 brings up its own display, builds its own 193-entry DMA
chain, keeps its own frame clock off the CRTC's V-DISP, and fetches every record
itself with `READ(10)` off a real volume. The rig writes **no picture byte, no
palette entry and no CRTC register**. **120 of 120 frames are pixel-exact — every
one compared, in both palette orders** — and the gate had to grow to do it,
because a packed frame is a *literal*: the codec's last frame audits all 120
through its own recursion, and frame 119 here says nothing about frame 60.
![Blu-ray source next to the packed player's own screen](docs/img/packed-player.png)
Left, the source. Right, **MAME's own snapshot** of what the 68000 put on
screen with no decoder in the machine at all — the frame whose PSNR is closest
to the mean, so it is not the flattering one. The window's mean is **33.10 dB**,
which is the packed container's predicted GRB555 figure to the digit.
**And the write window turns out to be the frame.** Free-running — which is what
a 12 fps player becomes once the transfer is longer than the slot — the run
reported a number no budget here has a column for: **the GVRAM write window was
open on 99.5% of the host frames**. Every frame pixel-exact, and almost none of them visible. It is
arithmetic, not an emulator artefact — a packed write *requires* R20 bit 11,
buffer mode blanks the layer, and a DMAC-direct player holds the window open for
the whole data phase, because the packed layout spends both 256-colour pages and
there is no second page to hide behind:
dark fraction of a slot = record bytes / (DATA-PHASE rate x slot)
**The rate in that expression is the BURST rate, not the sustained one**, and
that is a third hardware number the acceptance test did not have. At the
container's own **582.0 KB/s the dark fraction is 1.0**: every frame delivered,
on time, pixel-exact, and none of them displayed. It also **reverses the
ranking**: a packed player that DMAs into RAM with the window shut and paints
with the measured 27.3% blit is on screen **72.7% of every slot at any rate**,
and the two are equal only at **2,131 KB/s — 3.7x the wire**. Below that, which
is every rate anyone has proposed, the player with the CPU in the loop is the
one you can see (FINDINGS 64.2).
**And a held channel costs the frame clock half its ticks, without the clock
being able to tell.** `clock.i` counts V-DISP interrupts; a held channel halts
the 68000; the MFP's pending bit is one bit. Held at 12 fps, **487 of 1,038
edges are lost** — and the player reports **zero late frames**, because the tick
it grades itself against is advanced by the interrupt the channel stopped it
from taking. It believed it was at 12 fps; the screen was at **6.37**. Only the
host's raster count contradicts it, and the gate asserts on the difference
(FINDINGS 64.3).
**The scene graph is in, and the worst gap between two decision points is **The scene graph is in, and the worst gap between two decision points is
zero.** `tools/import/scenegraph.py` imports the arcade scene graph — 40 scenes, zero.** `tools/import/scenegraph.py` imports the arcade scene graph — 40 scenes,
516 sequences, 906 input windows — and 5.4% of the game's 612 branch transitions 516 sequences, 906 input windows — and 5.4% of the game's 612 branch transitions
@@ -317,12 +364,15 @@ on for eight sessions.
**Current encode:** 496.7 KB/s at 29.19 dB, 1 frame of 120 over the 12fps **Current encode:** 496.7 KB/s at 29.19 dB, 1 frame of 120 over the 12fps
budget, and that one is frame 0, the intra frame, late on purpose. budget, and that one is frame 0, the intra frame, late on purpose.
**Green-light check:** `./tools/bench/check.sh` (~4 min, needs the Blu-ray **Green-light check:** `./tools/bench/check.sh` (~6 min, needs the Blu-ray
mounted) re-runs both display regression tests, the rate-control drift gate, the mounted) re-runs both display regression tests, the rate-control drift gate, the
display-path coherency counterexample, a 120-frame 68000 decode on two CPU display-path coherency counterexample, a 120-frame 68000 decode on two CPU
cores, the ring and paced-ring passes, the DMAC configuration gate and the cores, the ring and paced-ring passes, the DMAC configuration gate and the
load-time transforms on both cores, then imports and gates the scene graph load-time transforms on both cores, then imports and gates the scene graph
when a DirkSimple checkout is present, then prints `ALL GREEN`. when a DirkSimple checkout is present, then builds the packed container and
renders it through px68k's own GVRAM model, then **runs the packed player for
120 frames off a real volume and compares every one of them**, then prints
`ALL GREEN`.
## Reproducing this ## Reproducing this
+178
View File
@@ -6590,3 +6590,181 @@ resource the packed branch is short of. The per-frame palette is worth +2.31 dB
container by a 68000 or by a channel. That is **K3**, and 63.2 is the strongest container by a 68000 or by a channel. That is **K3**, and 63.2 is the strongest
statement available without it: the bytes are right, on a second emulator's statement available without it: the bytes are right, on a second emulator's
own GVRAM model, with the harness computing nothing. own GVRAM model, with the harness computing nothing.
---
## 64. The packed player runs end to end off the disc — and the write window is the frame (session 32)
**ROADMAP K3.** `src/player/packed.s` is **2,898 bytes** of 68000 code that
brings up its own display, builds its own 193-entry DMA chain, keeps its own
frame clock off V-DISP and fetches every record itself with `READ(10)` off a
CZ-6BS1. `tools/bench/packed.lua` writes **no picture byte, no palette entry and
no CRTC register**; it pushes the code and eleven mailbox words and then reads.
`tools/bench/packed_run.sh` is the gate, `tools/bench/verify_packed.py` the
comparison, `tools/analysis/31_display_duty.py` the arithmetic underneath the
result.
**THE HEADLINE, and it is two facts that point opposite ways.**
**120 of 120 frames are pixel-exact**, every one of them compared, off a real
volume, on a clock the machine keeps itself — the strongest end-to-end result
this project has. And **the picture was on screen for none of the frame slot it
belongs to**, because the write window that a packed frame requires is the whole
of its transfer, and buffer mode blanks the layer it is written through.
### 64.1 What was run, and why every frame had to be checked
`tools/bench/verify_decode.py` checks **one** frame — the last — and that audits
all 120, because the codec is temporally recursive: a SKIP block is a claim that
the previous frame is still in GVRAM. **A packed frame is a LITERAL.** Frame 119
being right says nothing whatever about frame 60. The simplification that
deleted the ring, the codebooks and the decoder also deleted the gate's free
lunch, so `verify_packed.py` snapshots and compares **every frame**, letterbox
included — the 64 static rows are written once at scene setup and never touched
again, so a picture can be pixel-exact while the screen is not.
| | |
|---|---|
| container | `tmp/packed_singe.dlxp`, DLXP1, 120 records of 49,664 B = 97 sectors |
| record `i` | at LBA `1 + i*97`**arithmetic**, no index, nothing walked |
| chain | **193 entries**, built by the 68000: `$E82000`/512 B, then 192 rows of 256 B a 1,024 B stride apart |
| result | **120 of 120 pixel-exact**, 0 frames unsampled, `FLAG=$FF` |
| passes with the palette LAST too | chain starts `$C08000`/256 instead, **120 of 120 pixel-exact** |
The array is **scene-constant** and the seek is **subtraction**: the packed
layout spends both 256-colour pages, so there is no page to flip, and a record's
length is geometry, so a new pass is `LBA0` again. That is the whole of what K3
deletes, and it deleted it without incident.
### 64.2 The write window is the frame, and the rate it needs is not the rate it costs
The free-running run — the one that asks for record *i+1* the instant record
*i* lands, which is what a 12 fps player becomes the moment the transfer is
longer than the slot — reported a number no budget in this tree has a column
for: **the write window was open on 99.5% of the host frames.** Every frame was
pixel-exact and almost none of them was visible.
It is **arithmetic, not an emulator artefact**. 256-colour GVRAM masks the high
byte of every write unless R20 bit 11 is set (46.5/47.1), and the packed
layout's entire 1.0 B/pixel claim is that one word carries two pixels — so a
packed write *requires* the bit. If buffer mode blanks the layer while the bit is
set (47.4/B2 — MAME says it does, 48.1's prior leans that way), the layer is dark
for exactly as long as the window is open, and for a DMAC-direct player the
window is open for the whole data phase. There is no second page to hide behind:
the packed layout spends both, which is the same fact that made a frame one
channel start (62).
dark fraction of a slot = record bytes / (DATA-PHASE rate x slot)
**And the rate in that expression is the BURST rate, not the sustained one.**
This is the correction the session had to make to itself. 582.0 KB/s is a
*sustained* requirement and it decides whether record *i* arrives before slot
*i*. The dark fraction is set by how fast bytes move **during the data phase**,
which for a drive with a read-ahead cache can be several times the sustained
figure. **They are independent, and a medium can pass one and fail the other:**
| requirement | figure | status |
|---|---|---|
| sustained, or frames arrive late | **≥ 582.0 KB/s** | B1, known since 63 |
| data phase, or the frame is never displayed | **see below** | **NEW — B1 has no test for it** |
| data phase | transfer | window open | picture on screen |
|---:|---:|---:|---:|
| 582.0 KB/s (= the wire) | 83.33 ms | 100.0% | **0.0%** |
| 700 KB/s | 69.29 ms | 83.1% | 16.9% |
| 1,164 KB/s | 41.67 ms | 50.0% | 50.0% |
| 2,131 KB/s | 22.75 ms | 27.3% | 72.7% |
| 3,000 KB/s | 16.17 ms | 19.4% | 80.6% |
**A medium that exactly meets the sustained requirement delivers every frame, on
time, pixel-exact, and displays none of them.**
**AND THIS REVERSES 61.5's RANKING.** There are two packed players, and the
difference between them is *when* the window is open:
- **A, DMAC-direct** (the one that is built): one channel start, the CPU halted
or nearly, window open for the whole data phase.
- **B, DMA-to-RAM plus a CPU paint**: the record lands in RAM with the window
shut, and the 68000 paints it with the packed `movem` blit — **227,553 clocks,
27.3% of a slot, MEASURED** (`blit.s` V8, 61.4) and **independent of the
medium**. On screen **72.7% of every slot at any rate that delivers the record
at all.**
They are equally visible at a data-phase rate of **2,131 KB/s, which is 3.7x the
container's own wire**. Below that — which is every rate anyone has proposed —
**the player with the CPU in the loop is on screen longer than the one without
it.** 61.5 is not wrong; it ranked them in **clocks**, and this is the column
that table does not have:
| W (clk per delivered byte) | A: DMAC-direct | B: DMA + CPU paint |
|---:|---:|---:|
| 5 | 31.0% | 58.4% |
| **9 — the dual-address floor** | **54.9%** | **82.2%** |
| 12 | 72.8% | 100.1% |
| 16 | 96.6% | 123.9% |
| 19 | 114.5% | 141.8% |
Both charge the audio DMA at 10,417 clocks (1.25%, from the IPL ROM's own
channel-3 setup, 52.5); neither has a decoder in it. **B costs 27.3% of a frame
and 99,328 B of RAM** — two record buffers, because at any rate near the wire the
delivery of record *i+1* occupies most of the slot the paint of record *i*
happens in. On a 2 MB machine that is 4.7% of memory, and memory is the resource
the packed branch has spare: the ring it deleted was 256 KB.
### 64.3 Holding the bus costs the frame clock half its ticks — and the clock cannot tell
`src/player/clock.i` counts V-DISP interrupts. A held channel **halts the
68000**. The MFP's pending bit is **one bit**, so every edge that falls inside a
transfer spanning two of them is an edge the machine can **never** count. Nothing
in this project had run a transfer and a clock at once, so nothing could have
seen it.
| configuration, 120 frames | V-DISP edges seen | host frames drawn | lost |
|---|---:|---:|---:|
| **held, paced at 12 fps** | 551 | 1,038 | **487 = 46.9%** |
| stealing, paced at 6 fps | 1,105 | 1,112 | 7 = 0.6% |
**And the player reported ZERO late frames in both.** That is not a reassurance,
it is the finding: the pace gate compares the frame index against `PACE`, and
`PACE` is advanced by the ISR the held channel stops the CPU from running — so a
clock that loses edges loses them from **both sides of the comparison**. The held
player believed it was running at 12 fps; the screen was at **6.37**. The only
thing in the run that can contradict it is the host's raster count, which is why
`packed.lua` reports both and `packed_run.sh` gates on the difference being
non-zero.
The CPU's own account says the same thing from the other end: **held, the 68000
went round its transfer wait 120 times in 120 frames — once each, meaning it
never executed during a single transfer.** Stealing, it went round 1,100,520
times. A player has to keep a clock, read a stick and feed ADPCM; **which of the
two configurations can do any of that is a design question, and this is the run
that answers it.**
### 64.4 The channel configuration does not set the transport's time
Free-running, both configurations delivered the same 49,664 B record within 0.5%
of each other: **90.72 ms stealing, 90.27 ms held** — 534.6 and 537.3 KB/s,
108.9% and 108.3% of a 12 fps slot.
**That figure is a property of the apparatus and is not `W` and not a medium.**
MAME's device models carry no transfer timing (`docs/BENCHMARK.md`, 42.5). What
the pair of runs *does* establish is a **negative that no arithmetic could
have given**: the transfer time is **not the DMAC configuration's to set**. What
a channel configuration buys is **who owns the CPU**, not when the picture
appears. The mechanism behind MAME's own ceiling is **not diagnosed** — it is not
the DMAC (the two configurations agree) and not the CPU (held, the CPU is halted
throughout) — and no MAME source tree was available on this machine to name it.
### 64.5 What this does not settle
- **`W`. Not one clock of it.** Unchanged since 59.
- **B2, whether a real board blanks in buffer mode.** Everything in 64.2 is
conditional on it, and the condition now decides **which of two packed players
is built** rather than how much headroom one has. `probe_bit11_blank.lua` is
still written and still wants a board.
- **The data-phase rate of any real medium.** This is the session's addition to
**B1**, and it is a measurement nobody has planned: throughput and seek time
were the two numbers on the list, and **the burst rate during a data phase is a
third** that decides whether a DMAC-direct packed player shows a picture.
- **Whether B is buildable as described.** It is priced off a measured blit and
a measured ladder, and no line of it has been written.
+76 -12
View File
@@ -56,6 +56,24 @@ pairing. **B2 now decides which packed CONTAINER exists, not only which player**
(63.4). The fallback is a flag: `--scene-palette --no-palette` is 30.79 dB, zero (63.4). The fallback is a flag: `--scene-palette --no-palette` is 30.79 dB, zero
churn, 576.0 KB/s and still +2.07 dB on the shipping codec. **K3 is next.** churn, 576.0 KB/s and still +2.07 dB on the shipping codec. **K3 is next.**
Amended end of session 32: **K3 IS DONE, AND IT FOUND THE THING THAT DECIDES
THE BRANCH (FINDINGS 64).** `src/player/packed.s` brings up its own display,
builds its own 193-entry chain, keeps its own clock off V-DISP and fetches every
record itself off a CZ-6BS1: **120 of 120 frames pixel-exact, every one
compared, in both palette orders.** Two things came with it. **(1) The write
window is the frame.** A packed write needs R20 bit 11, buffer mode blanks the
layer, and a DMAC-direct player holds the window open for the whole data phase
— so the dark fraction of a slot is `record / (DATA-PHASE rate x slot)` and a
medium that exactly meets the 582.0 KB/s sustained requirement **displays none
of the frames it delivers on time**. The rate that matters here is the BURST
rate, which is a third hardware number **B1 has no test for**. It also
**reverses 61.5's ranking**: a packed player that DMAs to RAM and paints with
the CPU opens the window only for the measured 27.3% blit, so it is on screen
72.7% of every slot at any rate, and the two are equal only at **2,131 KB/s =
3.7x the wire**. **(2) A held channel costs the frame clock half its ticks and
the clock cannot tell** — 46.9% of V-DISP edges lost, zero late frames reported,
the player believing 12 fps while the screen ran at 6.37. **The open item is now
K4.**
**THE COMPLETION TARGET IS M3, THE VERTICAL SLICE** (USER DECISION): one scene **THE COMPLETION TARGET IS M3, THE VERTICAL SLICE** (USER DECISION): one scene
tree — a decision point, two outcomes, a death clip — with audio, streaming from tree — a decision point, two outcomes, a death clip — with audio, streaming from
a real SCSI volume on a stock 2 MB machine, playable. That is the point at which a real SCSI volume on a stock 2 MB machine, playable. That is the point at which
@@ -108,7 +126,16 @@ None of these block M2 or M3 software work, because session 18 forced every rate
to be an explicit argument. They set constants, and two of them decide how much to be an explicit argument. They set constants, and two of them decide how much
headroom the finished player has. headroom the finished player has.
**B1. Measure the BlueSCSI — throughput AND seek time.** **Session 29 gave this **B1. Measure the BlueSCSI — throughput, seek time AND the DATA-PHASE BURST
RATE.** The third one is session 32's (FINDINGS 64.2) and it is not a refinement
of the first: sustained throughput decides whether record *i* arrives before
slot *i*, and the **burst rate during the data phase** decides how much of the
slot the picture is on screen, because a DMAC-direct packed player holds the
GVRAM write window open for exactly as long as the transfer takes and buffer
mode blanks the layer. A drive with a read-ahead cache can pass the first and
fail the second. The acceptance test is **`record / (burst x slot)` = the dark
fraction**; at the container's own 582.0 KB/s it is 1.0, and the picture is never
displayed. **Session 29 gave this
a second acceptance test that is not a codec figure at all: 576 KB/s SUSTAINED, a second acceptance test that is not a codec figure at all: 576 KB/s SUSTAINED,
which is what a decoder-free packed literal frame costs and cannot be talked down which is what a decoder-free packed literal frame costs and cannot be talked down
from (FINDINGS 61.5).** A codec's bitrate is a lever; a literal frame's is from (FINDINGS 61.5).** A codec's bitrate is a lever; a literal frame's is
@@ -286,9 +313,37 @@ frame is not tied to a scene palette the codec's codewords index into. It costs
codec's ceiling, so the whole +2.31 dB is the per-frame palette; 90% of that codec's ceiling, so the whole +2.31 dB is the per-frame palette; 90% of that
palette changes every frame; and a mismatched paint is 12.8 dB worse, for palette changes every frame; and a mismatched paint is 12.8 dB worse, for
roughly half of every frame slot, if buffer mode does not blank. roughly half of every frame slot, if buffer mode does not blank.
- **K3. End to end, off the disc.** Palette, page-1 X-scroll 384, priority - ~~**K3. End to end, off the disc.**~~ **DONE, session 32 — FINDINGS 64.**
`vc1 = 0x0002`, R20 bit 11; one chained DMA a frame. Gated pixel-exact over the `src/player/packed.s`, `tools/bench/packed.lua`, `tools/bench/packed_run.sh`,
same 120-frame window the decoder is gated on. `tools/bench/verify_packed.py`, `tools/analysis/31_display_duty.py`. Palette,
page-1 X-scroll 384, priority `vc1 = 0x0002`, R20 bit 11, one chained DMA a
frame, **120 of 120 pixel-exact in both palette orders** — and the gate checks
every frame rather than the last, because a packed frame is a literal and the
codec's recursion was what made one comparison audit 120.
**What it found is K4's whole content**, and it is in the amendment above: the
window is the frame, the burst rate decides visibility, and a held channel
eats the clock.
- **K4. THE PACKED PLAYER THAT IS ON SCREEN.** 64.2's option B: DMA the record
into one of two RAM buffers with the window SHUT, then paint it with the
packed `movem` blit (`blit.s` V8, **measured** at 227,553 clocks = 27.3% of a
slot). **82.2% of a frame at the 9 clk/B dual-address floor** against A's
54.9%, **99,328 B of RAM**, and a picture on screen **72.7% of every slot at
any delivery rate** instead of 0% at the container's own wire.
It is not a rewrite of K3: `packed.s` keeps its display bring-up, its clock,
its transport and its record arithmetic, and what changes is the chain's
destination and the addition of a paint. **The one thing in it that has never
been run is the overlap** — a channel filling buffer *i+1* while the CPU
paints buffer *i*, which is the first time in this project that the DMAC and
the 68000 have had to want the bus at the same time for a whole scene.
**K4 is conditional on B2 the same way K3's ranking was**, and the condition
now cuts the other way: if buffer mode does NOT blank, A is on screen the whole
slot and K4 is 27.3% of a frame spent on nothing. **Do not build K4 before B2
is answered** — that is the same rule 61.7 wrote for the codec, applied to the
branch that replaced it.
**What K3 deletes, and why that is a risk and not a win to be banked:** a **What K3 deletes, and why that is a risk and not a win to be banked:** a
DMAC-direct packed player has **no ring**`ring.i`, `xfer.i` and most of DMAC-direct packed player has **no ring**`ring.i`, `xfer.i` and most of
@@ -719,17 +774,26 @@ P2 re-encode bundle DONE (60): DLX5, records ARE sectors ───────
E7/E4/C1 PARKED session 29: encoder work waits on B2 ───────────┤ E7/E4/C1 PARKED session 29: encoder work waits on B2 ───────────┤
K1 palette-register DMA? ─> K2 packed container ─> K3 end to end ──┤ K1 palette-register DMA? ─> K2 packed container ─> K3 end to end ──┤
(61.9; K1/K2 survive a bad B2, K3 does not) K1 DONE s30 (62), K2 DONE s31 (63), K3 DONE s32 (64):
K1 DONE s30 (62), K2 DONE s31 (63) ── K3 is the open one 120/120 pixel-exact, both palette orders, off a real volume
└─> and K3 found that the WRITE WINDOW IS THE FRAME, so: │
K4 (DMA to RAM + the measured 27.3% paint) is the player │
that is ON SCREEN below a 2,131 KB/s BURST rate -- which │
is 3.7x the wire, so below every rate anyone has proposed │
P4a WIRING (the channel behind ring.i's mailbox) <- THE LAST ITEM ─┤ P4a WIRING (the channel behind ring.i's mailbox) <- THE LAST ITEM ─┤
P1 P2 P3 P4b P5 P7, P6 bus cost (52), G1 scene graph (56) ────────┼─> M2 ─> P1 P2 P3 P4b P5 P7, P6 bus cost (52), G1 scene graph (56) ────────┼─> M2 ─>
B1 seek+rate (sets HEADROOM, not fit) ─────────────────────────────┘ M3 ─> M4 B1 seek+rate (sets HEADROOM, not fit) ─────────────────────────────┘ M3 ─> M4
B2 blanking ─┬─ NOT blanked ─> the DECODER-FREE PACKED player is live (61): B2 blanking ─┬─ NOT blanked ─> K3's DMAC-DIRECT player is the one: 54.9% of a
55.2% of a frame at the 9 clk/B FLOOR, against │ frame at the 9 clk/B floor against the codec's
the codec's 110.4% -- and then B1 decides it, 110.4%, on screen the whole slot, and K4's paint
because it wants 576 KB/s FIXED (61.4, 61.5) would be 27.3% spent on nothing (61.4, 61.5)
└─ blanked ──────> a 27..113% duty strobe; there is no version of └─ blanked ──────> K3's player is on screen for
it that is merely expensive (48.3, 61.6) 1 - record/(BURST x slot) of every slot, which is
ZERO at the container's own wire -- so K4 is the
player, at 82.2% of a frame and 99,328 B of RAM
(64.2). Neither answer kills the branch and each
picks a different player.
B1 BURST rate (NEW, 64.2) ──> which of the two K3/K4 wins, if B2 blanks
``` ```
**Read that top-left branch as the project's live question.** Everything else **Read that top-left branch as the project's live question.** Everything else
+223 -1
View File
@@ -1,4 +1,161 @@
# Status & next-session handoff — end of session 31 (2026-08-25) # Status & next-session handoff — end of session 32 (2026-08-25)
## Session 32: the packed player runs, and the write window turns out to be the frame
**Green light first and last: `./tools/bench/check.sh` was ALL GREEN before any
of this (`tmp/check_s32_start.log`) and ALL GREEN after** — the same stages, plus
one new one.
**FINDINGS 64. ROADMAP K3 is done.** `src/player/packed.s` (2,898 B),
`tools/bench/packed.lua`, `tools/bench/prep_packed.py`,
`tools/bench/packed_run.sh`, `tools/bench/verify_packed.py`,
`tools/analysis/31_display_duty.py`. `tools/bench/mkvol.sh` grew a DLXP arm —
for a packed container the file **is** the volume, which is the format's own
claim arriving at the disc.
**Everything below is EMULATED**: MAME 0.277 `x68000`, `-bios ipl10`, stock
10 MHz / 2 MB, `-exp1 cz6bs1`, a real CHD volume. No real hardware ran.
**1. THE PLAYER WORKS, AND IT IS THE STRONGEST END-TO-END RESULT IN THE TREE.**
The 68000 brings up its own display (CRTC mode, both scroll register pairs,
priority `vc1 = $0002`, R20 bit 11), builds its own **193-entry** DMA chain,
keeps its own frame clock off V-DISP, and fetches every record itself with
`READ(10)`. The rig writes no picture byte, no palette entry and no CRTC
register.
| | |
|---|---|
| frames | **120 of 120 pixel-exact**, EVERY ONE COMPARED |
| both palette orders | palette FIRST and `--palette-last`, **120/120 each** |
| chain | `$E82000`/512 B then 192 rows of 256 B at the 1,024 B stride — one start |
| record `i` | LBA `1 + i*97`. Arithmetic. No index, no ring, no decoder |
The gate had to change shape: `verify_decode.py` checks the LAST frame and that
audits 120 because the codec is temporally recursive. **A packed frame is a
literal**, so `verify_packed.py` compares all of them, letterbox included.
**2. THE HEADLINE, AND IT IS NOT THE GOOD HALF.** The free-running run — which
is what a 12 fps player becomes once the transfer is longer than the slot —
reported a number no budget in this tree has a column for: **the write window
was open on 99.5% of the host frames.** Every frame was pixel-exact and almost none of them was
visible. It is arithmetic: a packed write needs R20 bit 11, buffer mode blanks
the layer, and a DMAC-direct player holds the window open for the whole data
phase — there is no second page to hide behind, because the packed layout spends
both.
dark fraction of a slot = record bytes / (DATA-PHASE rate x slot)
**The rate in that expression is the BURST rate, not the sustained one**, and
that is a third hardware number **B1 has no test for**. At the container's own
582.0 KB/s the dark fraction is **1.0**: every frame delivered, on time,
pixel-exact, and **none of them displayed**.
**3. AND IT REVERSES 61.5's RANKING.** A packed player that DMAs into RAM with
the window SHUT and paints with the measured `movem` blit (27.3% of a slot) is
on screen **72.7% of every slot at any rate**. The two are equal only at a
data-phase rate of **2,131 KB/s = 3.7x the wire**. Below that — every rate
anyone has proposed — **the player with the CPU in the loop is on screen
longer.** That is ROADMAP **K4**, and it costs 82.2% of a frame at the 9 clk/B
floor against 54.9%, plus 99,328 B of RAM for two record buffers.
**4. A HELD CHANNEL COSTS THE FRAME CLOCK HALF ITS TICKS, AND THE CLOCK CANNOT
TELL.** `clock.i` counts V-DISP interrupts; a held channel halts the 68000; the
MFP's pending bit is one bit. Held at 12 fps: **487 of 1,038 edges lost
(46.9%)**, and the player reported **zero late frames** — because `PACE` is
advanced by the ISR the channel stops from running, so the loss cancels out of
the comparison. The player believed 12 fps; the screen was at **6.37**. Only the
host's raster count contradicts it, and `packed_run.sh` gates on the difference
being non-zero. Stealing at half rate loses 0.6%. Held, the CPU went round its
transfer wait **120 times in 120 frames** — once each; it never executed during a
transfer.
**5. THE CHANNEL CONFIGURATION DOES NOT SET THE TRANSPORT'S TIME.** Free-running,
held and stealing delivered the same record within **0.5%** (90.27 vs 90.72 ms).
That figure is the APPARATUS — MAME's device models carry no transfer timing —
but the negative is real and no arithmetic could have given it: **a channel
configuration buys who owns the CPU, not when the picture appears.**
**RISKS IN THIS SESSION'S RESULT, stated rather than left to be found:**
- **Everything in 2 and 3 is conditional on B2**, and B2 is still unmeasured on
a board. What changed is the stakes: it now picks WHICH packed player, and
each answer makes the other one's design work wasted.
- **MAME's ~535 KB/s transport ceiling is not diagnosed.** It is not the DMAC
(both configurations agree) and not the CPU (held, it is halted throughout),
and no MAME source tree was on this machine to name it. It bounds nothing in
the arithmetic, which is geometry, but it is the reason the gate is paced at
half rate and that should not be mistaken for a rig limitation being worked
around.
- **The cadence sampler is quantised to one host frame** (17.6 ms). The MEAN
over 120 frames is not (±0.30 ms); the min/median/max are the sampler's.
## HANDOFF — start here
**THE TREE IS ALL GREEN**, session 32's stage included (`tmp/check_s33_start.log`,
ALL GREEN, ~6 min).
### The work, in the order it should be done
**1. NOT K4 — NOT YET.** ROADMAP K4 is written and priced (82.2% of a frame at
the 9 clk/B floor, 99,328 B of RAM, on screen 72.7% of every slot at any rate),
and it is **conditional on B2**, which is a board question nobody here can
answer. If buffer mode does NOT blank, K3's player is already on screen the
whole slot and K4's paint is 27.3% of a frame spent on nothing. 61.7 wrote that
rule for the codec; it applies to the branch that replaced it. **Do not open
K4 until B2 comes back.**
**2. WHAT IS NOT BLOCKED IS P6 — AUDIO.** It is the largest unpriced item left
in the project and it is on M3's critical path, which is the completion target.
The bus half closed in session 20 (52: 1.25%..1.48% of a frame, and the unit
error was caught) — **everything else in it is open**: extraction, an encoder,
the container interleave, and what a second stream does to `wire` and therefore
to 51.3's refill climb. It is independent of B2 in the part that matters: both
packed containers and the codec carry the same audio.
Three things make it a session rather than a chore:
- **No ffmpeg ENCODER exists for this format.** `adpcm_ima_oki` is a decoder
only, so the encoder is ours to write and ours to gate.
- **The two available references DISAGREE, and it was MEASURED not recalled**
(session 33, `tmp/adpcm_probe/`). ffmpeg's `adpcm_ima_oki` is
`((2*delta+1) * step) >> 3`, 12-bit signal clipped to [-2048, 2047], output
x16, **high nibble first** — reproduced sample-exact over 2,268 nibbles. The
OKI datasheet form truncates per term (`step/8 + step + step/2 + step/4`,
selected by nibble bits) and differs on **445 of those 2,268 samples, by up to
4 in 12-bit units**. Which one the machine runs is not a matter of taste, and
**MAME has an `okim6258` in the x68000 — so it can be asked.**
- **DLXP1 has no room for it.** A packed record is 97 sectors EXACTLY because
49,664 B is what a literal frame costs; audio does not fit in the slack,
because there is none. What audio does to the packed record's geometry is a
container question, not an encoder one.
### What is PARKED, so it is not re-derived
**E7, E4 and C1** (61.8), and **P4a's wiring** for the video path (K3 deletes the
ring from it). Do not delete any of it — B2 is unanswered.
### Risks that are OURS, not hardware
1. **A chained transfer has never run back to back at 12 fps and now it has**,
120 times, pixel-exact — but only at HALF rate, because at full rate there is
nothing to snapshot (64.2). The gate's pacing is a consequence of the finding.
2. **The packed player deletes `ring.i`, `xfer.i` and most of `stream.s`.**
Unchanged: a simplification that large usually hides something, and it has
now run clean for 120 frames without finding out what.
3. **MAME's ~535 KB/s transport ceiling is undiagnosed** (64.4). It bounds
nothing in the arithmetic, which is geometry.
4. **B2 sits over the branch and now picks WHICH PLAYER**, not how much headroom
one has.
### Reproducing this session
./tools/bench/check.sh # ALL GREEN
bash tools/bench/packed_run.sh tmp/packed_singe.dlxp # all four runs
python3 tools/analysis/31_display_duty.py
**WHAT IS NEXT.** P6: audio, from the disc to a byte count that the container
has to carry.
---
## Session 31: the packed container, and the palette that buys 2.31 dB has a price ## Session 31: the packed container, and the palette that buys 2.31 dB has a price
@@ -1704,6 +1861,39 @@ Green light: `./tools/bench/check.sh` **ALL GREEN**, before and after.
## NEXT SESSION, in order ## NEXT SESSION, in order
**AS OF SESSION 32 the top of the list is this, and the rest of this section is
the session-19 list kept for its detail.** `docs/ROADMAP.md` is the current
shape; where the two disagree, ROADMAP is the one that was edited last.
1. **B2, and it is now the fork rather than a headroom question.**
`tools/bench/probe_bit11_blank.lua` is written and settles it in minutes on a
real board. FINDINGS 64.2 is why it moved to the top: **if buffer mode
blanks, the K3 player that now exists shows nothing at the container's own
wire and K4 is the player; if it does not blank, K3 is the player and K4's
27.3% paint is spent on nothing.** Each answer makes the other branch's work
wasted, so building either before the answer is the one thing to avoid.
2. **B1 gained a THIRD number: the DATA-PHASE BURST RATE** (64.2). Sustained
throughput decides whether record *i* arrives before slot *i*; the burst rate
decides how much of the slot the picture is on screen. A drive with a
read-ahead cache can pass one and fail the other. The acceptance test is
`record / (burst x slot)` = the dark fraction, and it is **1.0 at 582.0 KB/s**
and 0.273 — the same as K4's paint — only at **2,131 KB/s**.
3. **K4, and NOT before item 1.** ROADMAP has the shape. The one thing in it
that has never been run is the **overlap**: a channel filling buffer *i+1*
while the CPU paints buffer *i*, which is the first time the DMAC and the
68000 have had to want the bus at the same time for a whole scene.
4. **Diagnose MAME's transport ceiling, or stop quoting it.** ~535 KB/s a record
in both channel configurations, mechanism unknown, no MAME source on this
machine. It bounds nothing — the arithmetic in 64.2 is geometry — but it is
why `check.sh`'s packed stage is paced at half rate, and an undiagnosed
apparatus constant is exactly the shape of thing FINDINGS 42.1 caught.
---
**Item 4 is CLOSED (session 19, FINDINGS 51).** The list below is otherwise **Item 4 is CLOSED (session 19, FINDINGS 51).** The list below is otherwise
unchanged, and items 1-3 are all still blocked on hardware this machine does not unchanged, and items 1-3 are all still blocked on hardware this machine does not
have. What session 19 adds to item 1 is a SECOND number to measure the medium have. What session 19 adds to item 1 is a SECOND number to measure the medium
@@ -2984,6 +3174,38 @@ flattering possible way to state one.
**Do not run this alongside another MAME job.** They share `tmp/` logs and **Do not run this alongside another MAME job.** They share `tmp/` logs and
snapshot directories and the second run silently truncates the first. snapshot directories and the second run silently truncates the first.
## Reproducing the packed player (session 32)
```
python3 tools/encoder/pack.py tmp/fr_singe tmp/packed_singe.dlxp --nframes 120
./tools/bench/packed_run.sh tmp/packed_singe.dlxp
```
~4 min, four MAME runs. `DLX_PK_GATE_ONLY=1` runs only the first, which is what
`check.sh` takes. Expected: 120 of 120 pixel-exact; 193 chain entries; 0 late
frames; 0 frames unsampled; a free-running transport of ~90 ms a record; and
**487 of 1,038 V-DISP edges lost in the held configuration**, which is the run's
whole point and is asserted rather than admired.
The palette-LAST container is a flag and not a re-encode:
```
python3 tools/encoder/pack.py tmp/fr_singe tmp/packed_singe_last.dlxp \
--nframes 120 --palette-last
./tools/bench/packed_run.sh tmp/packed_singe_last.dlxp
```
The chain assertion is read out of the container's own flags, so a run that
built the array the other way round fails instead of painting 192 rows of
picture into the palette registers.
And the arithmetic underneath the result, which needs no emulator:
```
python3 tools/analysis/31_display_duty.py tmp/packed_singe.dlxp \
--rate 582 700 1164 2131 3000
```
`--rate` is REQUIRED and has no default, for FINDINGS 50's reason.
**Do not run this alongside another MAME job.** It shares `tmp/` logs with every
other rig here.
## Reproducing the decoder result (session 7) ## Reproducing the decoder result (session 7)
``` ```
Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

+512
View File
@@ -0,0 +1,512 @@
; ---------------------------------------------------------------------------
; packed.s -- THE PLAYER WITH NO DECODER, END TO END, OFF THE DISC. ROADMAP K3.
;
; WHAT THE OTHER FRONT-ENDS IN THIS DIRECTORY DO, AND WHY THIS ONE IS DIFFERENT.
; decode.s parses a DLX record and draws 4x4 blocks; stream.s does the same out
; of a bounded ring that ring.i fills through xfer.i. Both are CODECS: a record
; is a program the 68000 executes against GVRAM, and every cost table in
; docs/FINDINGS.md from 24 to 45 is a cost of executing it. FINDINGS 61 priced
; the alternative and it won: at the 9 clk/B dual-address floor the shipping
; codec is 110.4% of a 12 fps frame and a decoder-free packed literal frame is
; 55.2%. Decoding 37,585 bytes costs more than not decoding 49,152.
;
; So THERE IS NO DECODER BELOW. There is no ring either, and that is the same
; fact rather than a second one: a ring exists because DLX records are
; variable-length and the block loop needs the next one whole and contiguous
; (49.2). A packed record's length is GEOMETRY -- 512 B of palette and 192 rows
; of 256 B, 97 sectors exactly -- so record `i` is at LBA0 + i*97 and there is
; nothing to place, nothing to wrap and nothing to index (tools/encoder/dlxp.py).
;
; WHAT THE 68000 DOES PER FRAME, IN FULL:
;
; 1. wait for its own frame tick (src/player/clock.i, off the CRTC's V-DISP)
; 2. set CRTC R20 bit 11 -- the GVRAM write window
; 3. issue one READ(10) whose DATA IN phase is an HD63450 channel walking a
; 193-entry chain: the palette registers at $E82000, then 192 GVRAM rows a
; 1,024 B line stride apart (FINDINGS 62)
; 4. clear R20 bit 11
;
; That is the whole video path. There is no per-frame PAINT: between the
; channel start and the channel's COC the 68000 executes nothing at all in the
; held configuration, and in the stealing one it executes only its own wait
; loop. The array is SCENE-CONSTANT -- the packed layout spends both 256-colour
; pages, so there is no page to flip and no destination that changes.
;
; THE TWO THINGS THIS FILE EXISTS TO FIND OUT, neither of which any earlier run
; could ask:
;
; a. DOES A CHAINED TRANSFER RUN BACK TO BACK AT 12 fps? 61.7.2 named this as
; the specific untested thing behind K3's large simplification, and it is
; the reason the frame clock is in here rather than a host tick: a chain
; that has to be restarted 120 times in ten seconds is a different claim
; from one that ran once in a gate.
; b. WHAT DOES HOLDING THE BUS COST THE CLOCK? A held channel halts the
; 68000, and the frame clock is an INTERRUPT off V-DISP. Edges that fall
; while the CPU is halted are not counted twice by the MFP -- the pending
; bit is one bit -- so a transfer long enough to span two V-DISPs makes the
; player's own clock LOSE TIME. Nothing in this project has run a transfer
; and a clock at once before, so nothing could have seen it. CLK_VDISP is
; the machine's count and the host's raster count is the truth; the gate
; compares them rather than trusting either.
;
; BOTH CONFIGURATIONS ARE SELECTABLE (PG_HELD) FOR EXACTLY THAT REASON. 59.3
; already showed that an auto-requested channel is charged by TIME rather than
; by byte, so "held" and "stealing" are not two speeds of the same thing: held
; is the CPU stopped for as long as the record takes to arrive, and stealing is
; the CPU running against a channel taking its share. A player has to keep a
; clock, read a joystick and feed ADPCM, so which of the two is survivable is a
; design question and not a benchmark.
;
; AND IT IS STILL NOT A RATE. MAME's HD63450 is configured in wall-clock
; attotimes (42.5) and its held mode halts the CPU rather than charging it
; cycles per operand, so nothing below measures `W`. What it measures is
; whether the SHAPE works: one start, 193 destinations, 120 times, on a clock
; the machine keeps itself, with every frame pixel-exact off a real volume.
; ---------------------------------------------------------------------------
; ---- inputs, written by the rig before the CPU is launched
PG_FLAG = $18900 ; 0 idle / 1 running / $FF done / $Exx failed
PG_NFR = $18904 ; frames in the scene
PG_FPS = $18908 ; frame rate the clock is asked for
PG_LBA0 = $1890C ; LBA of record 0. A WORD AND NOT A CONSTANT:
; a shipping volume has a filesystem in front of
; the stream, and this is the one number that
; changes when it does (xfer.i says the same).
PG_RECS = $18910 ; sectors in a record -- 97, and the container
; is what says so
PG_PALL = $18914 ; 1 = the palette is LAST in the record. It is
; a CONTAINER property (dlxp.py flags bit 1) and
; the player reads it rather than assuming it:
; FINDINGS 62.5/63.4 priced both orders at
; -12.8 dB for one paint and could not choose
; between them, so K3 runs both.
PG_HELD = $18918 ; 1 = DM_HELD_* (burst, bus held), 0 = DM_STEAL_*
PG_PACEON = $1891C ; 1 = obey the frame clock. 0 free-runs, which
; tests the CHAIN without the clock in the way.
PG_ITER = $18920 ; passes over the scene; >1 exercises the SEEK,
; which for this container is arithmetic
; ---- outputs
PG_SHOWN = $18930 ; frames displayed. Bumped AFTER bit 11 is
; cleared, so a rig that snapshots on a change
; is snapshotting a frame that is on screen.
PG_ERR = $18934 ; SC_ERR of the first failed read, 0 = none
PG_ERRAT = $18938 ; ...and the frame it failed on
PG_LATE = $1893C ; frames that reached the gate with their tick
; already past -- the previous frame overran
PG_LATE1 = $18940 ; the first of them
PG_LATEM = $18944 ; the worst, in whole ticks
PG_VDISP = $18948 ; CLK_VDISP as the machine counted it
PG_VD0 = $1894C ; ...and as it stood when frame 0 started, so a
; rig can charge only the frames it ran
PG_TSPIN = $18950 ; total DM_SPIN over the run: the CPU's own trips
; round the transfer wait. Held, this is one per
; frame and the CPU did nothing else all scene.
PG_GSPIN = $18954 ; total pace-gate polls: what the CPU had LEFT
PG_LOSTV = $18958 ; V-DISP edges the machine did not see, summed
; per frame -- see pg_frame
PG_ARRN = $1895C ; entries the array was built with (an assertion
; the rig reads back rather than a comment)
; ---- the array chain. 193 x 6 B = 1,158 B, built once at scene setup.
; $1B000 and not $19000: dmagate.s's two arrays live at $19000/$19100 and
; ring.i's disc-offset table at $19400, and a front-end that shares an address
; with another front-end is how DM_USE landed on ring.i's mailbox (dma.i).
PG_ARR = $1B000
PG_MAXE = 256 ; the chain cannot be longer than this
; ---- geometry. The container's, not the screen's: the screen is 256x256 and
; the picture is 256x192, so the difference is letterbox and is STATIC SETUP.
PG_W = 256
PG_H = 192
PG_ROWB = PG_W/2 ; 128 words = 256 BYTES a row. THE WHOLE POINT:
; 1.0 B/pixel, because bit 11 stops GVRAM
; masking the high byte away and the two
; 256-colour pages are scrolled 384 apart
; (FINDINGS 46.5/47.1, dlxp.py).
PG_STRIDE = 1024 ; GVRAM line stride, in bytes
PG_PALB = 512 ; 256 GRB555+I words -- and exactly one sector
SCRW = 256
SCRH = 256
GVRAM = $C00000
GPAL = $E82000
VC0 = $E82400
VC1 = $E82500
VC2 = $E82600
CONTRAST = $E8E001
; The graphic scroll registers, named rather than written as CRTC+n*2.l: a
; 256-colour page is assembled from TWO nibble planes with independent scroll
; registers (px68k Grp_DrawLine8 reads scroll sets page*2 and page*2+1), so both
; of a page's registers have to agree or the page tears between its low and high
; nibble. Naming them is what makes the pairing visible at the write.
CR_P0X0 = CRTC+12*2
CR_P0Y0 = CRTC+13*2
CR_P0X1 = CRTC+14*2
CR_P0Y1 = CRTC+15*2
CR_P1X0 = CRTC+16*2
CR_P1Y0 = CRTC+17*2
CR_P1X1 = CRTC+18*2
CR_P1Y1 = CRTC+19*2
PG_YOFF = (SCRH-PG_H)/2 ; 32
PG_TOP = GVRAM+PG_YOFF*PG_STRIDE
PG_BLACK = $FFFF ; letterbox: index 255 in BOTH bytes. NOT 0 --
; index 0 is page 1's transparency key and black
; lives at 255 (dlxp.py, vq.frame_palette).
; R20. bit 11 = G-VRAM set to buffer, i.e. the WRITE WINDOW; bits 9-8 = 01
; 256 colours; bit 4 = 31.5 kHz; bits 3-0 = 256 lines, 256 dots. The two
; values differ in EXACTLY bit 11, which is what makes the window a window.
PG_R20D = $0110 ; displaying
PG_R20B = $0910 ; the write window open
include "src/player/geom.i"
org $10000
start:
move.l #1,PG_FLAG.l
clr.l PG_SHOWN.l
clr.l PG_ERR.l
move.l #-1,PG_ERRAT.l
clr.l PG_LATE.l
move.l #-1,PG_LATE1.l
clr.l PG_LATEM.l
clr.l PG_TSPIN.l
clr.l PG_GSPIN.l
clr.l PG_LOSTV.l
; ---- 1. the display. THE PLAYER OWNS IT, and that is a change from every
; other rig in this tree: tools/bench/stream.lua and decode.lua call
; crtc_mode.lua's MODE.apply from the host, which is fine for a decoder gate and
; is not a player. A player boots into a machine the IPL left in 768x512
; 16-colour and has to get to 256x256 256-colour packed by itself, and the
; scroll registers and the priority word are load-bearing rather than cosmetic:
; 47.5 measured VC1 = $0000 putting page 0 on top and blacking the right half of
; the screen.
bsr pg_video
; ---- 2. the static half of the picture (FINDINGS 47.2). Words 128..511 of
; every row, and the letterbox rows entire, are written ONCE and never again --
; which is what makes the per-frame payload exactly the picture. Page 1's
; storage at 384..511 is what the +384 scroll puts under screen columns 0..127,
; and it must read 0 so that the opaque page 0 shows through there.
bsr pg_static
; ---- 3. the chain the channel will walk, 193 entries of it (FINDINGS 62).
bsr pg_array
; ---- 4. the transport. ONCE, not per frame: scsi_init resets the SPC and
; clears DM_USE, so a per-frame call would quietly put the data phase back on
; the CPU and the run would still deliver every byte -- 87 clocks each (58).
bsr scsi_init
bsr pg_dmacfg
; ---- 5. the clock. AFTER the SPC, because clk_init lowers the interrupt mask
; to $2500 and the bring-up should not be the first thing running with level 6
; open. It also CLEARS PACE, so tick 0 is the instant the scene starts.
move.l PG_FPS.l,CLK_FPS.l
tst.l PG_PACEON.l
beq.s .noclk
bsr clk_init
tst.l CLK_ERR.l
beq.s .noclk
move.l #$E1,PG_FLAG.l ; the mode is not one HFREQ describes
bra pg_hold
.noclk:
move.l CLK_VDISP.l,PG_VD0.l
; ---- 6. the scene.
move.l PG_ITER.l,d6
tst.l d6
bne.s .it
moveq #1,d6
.it:
pg_pass:
moveq #0,d7 ; d7 = frame index within the pass
pg_loop:
bsr pg_gate ; wait for tick d7
bsr pg_frame ; and paint it
tst.l d0
bmi.s pg_failed
addq.l #1,d7
move.l PG_NFR.l,d0
cmp.l d0,d7
bcs.s pg_loop
; ---- a pass boundary. For this container a SEEK IS ARITHMETIC: there is no
; ring to discard, no index to walk and no prefill to climb, so the next pass's
; first record is simply LBA0 again. That is the whole of what K3 deletes, and
; it is worth one line of code and four of comment because it is the largest
; simplification in the project (ROADMAP K3) and it does not look like one.
subq.l #1,d6
bne.s pg_pass
move.l CLK_VDISP.l,PG_VDISP.l
bsr clk_stop
move.l #$FF,PG_FLAG.l
bra.s pg_hold
pg_failed:
move.l CLK_VDISP.l,PG_VDISP.l
bsr clk_stop
move.l #$E2,PG_FLAG.l
pg_hold:
bra.s pg_hold
; ---------------------------------------------------------------- pg_gate
; Frame d7 may not START before tick d7 (the rule is stream.s's, unchanged, and
; deliberately so: the same gate against the same clock is what makes a paced
; packed run comparable with a paced codec run). A frame that arrives with its
; tick ALREADY past did not idle for a single poll, which means the previous
; frame used its whole slot and then some -- that is the underrun this player
; can have, and it is counted rather than absorbed.
pg_gate:
movem.l d0-d1,-(sp)
tst.l PG_PACEON.l
beq.s .out
move.l CLK_PACE.l,d0
cmp.l d7,d0
bcs.s .wait ; PACE < d7: early, the common case
tst.l d7
beq.s .out ; frame 0 starts AT tick 0 by definition
tst.l PG_LATE.l
bne.s .nf
move.l d7,PG_LATE1.l
.nf: addq.l #1,PG_LATE.l
sub.l d7,d0 ; whole ticks overrun
cmp.l PG_LATEM.l,d0
bls.s .out
move.l d0,PG_LATEM.l
bra.s .out
.wait: addq.l #1,PG_GSPIN.l
move.l CLK_PACE.l,d0
cmp.l d7,d0
bcs.s .wait
.out: movem.l (sp)+,d0-d1
rts
; ---------------------------------------------------------------- pg_frame
; ONE FRAME. Open the write window, hand the record to the channel, close it.
; Returns d0 < 0 on a transport failure.
;
; THE WINDOW IS OPENED ROUND THE TRANSFER AND NOT ROUND THE SCENE, and that is
; not tidiness. R20 bit 11 blanks the graphics layer while it is set (measured,
; tools/bench/crtc_mode.lua) -- 47.4/ROADMAP B2 is exactly the question of
; whether a real board does too -- so a scene-long window would show nothing at
; all. Held round the transfer it is a shutter: the screen is dark for as long
; as the record takes to land and shows a COMPLETE frame the rest of the time.
; That is also why this player cannot tear the way FINDINGS 41's decoder does:
; there is no instant at which a half-written picture is displayable.
;
; CLK_VDISP IS SAMPLED EITHER SIDE OF THE TRANSFER. The difference is the
; V-DISP edges the machine SAW; the raster produced its own number regardless.
; In the held configuration the CPU is stopped for the whole transfer, so any
; edge that falls inside it is one the MFP can only remember once -- and a frame
; clock built on counting them loses time it can never get back. The subtraction
; here is what makes that visible without a host in the loop.
pg_frame:
movem.l d1-d5/a1,-(sp)
move.l CLK_VDISP.l,d5
move.w #PG_R20B,CRTC_R20.l ; the write window opens
; LBA = PG_LBA0 + d7 * PG_RECS. Arithmetic, not a lookup: a packed record's
; length is geometry, so this player carries no record index at all (dlxp.py).
move.l d7,d3
move.l PG_RECS.l,d0
mulu d0,d3 ; frames * sectors, both small
add.l PG_LBA0.l,d3
move.l PG_RECS.l,d4
lea GVRAM,a1 ; IGNORED under chaining -- the channel
; takes MAR from the array's first entry
; -- and passed so that this call site
; reads like every other one in the tree
bsr scsi_read
move.l d0,d1
move.w #PG_R20D,CRTC_R20.l ; ...and closes. The frame is up.
move.l DM_SPIN.l,d0
add.l d0,PG_TSPIN.l
move.l CLK_VDISP.l,d0
sub.l d5,d0 ; edges seen across the transfer
beq.s .nolost
subq.l #1,d0 ; one edge per frame slot is expected;
add.l d0,PG_LOSTV.l ; what is counted is the SURPLUS, and a
.nolost: ; deficit cannot be seen from in here --
; the host's raster count is what says
; how many there really were
move.l d1,d0
bmi.s .err
addq.l #1,PG_SHOWN.l
movem.l (sp)+,d1-d5/a1
rts
.err: tst.l PG_ERR.l
bne.s .err2
move.l SC_ERR.l,PG_ERR.l
move.l d7,PG_ERRAT.l
.err2: moveq #-1,d0
movem.l (sp)+,d1-d5/a1
rts
; ---------------------------------------------------------------- pg_dmacfg
; The channel's configuration, and the choice between the only two rows of the
; ladder MAME has a code path for (dma.i: no EXREQ wiring, no single-address
; path, and only burst modelled as held). OCR gets CHAIN = %10 on top, which is
; sequential array chaining and is what makes 193 destinations one start.
pg_dmacfg:
move.l #DM_STEAL_DCR,d0
move.l #DM_STEAL_OCR,d1
tst.l PG_HELD.l
beq.s .set
move.l #DM_HELD_DCR,d0
move.l #DM_HELD_OCR,d1
.set: move.l d0,DM_DCRV.l
ori.l #$08,d1 ; OCR CHAIN = %10, array chain
move.l d1,DM_OCRV.l
move.l #PG_ARR,DM_BARV.l
move.l PG_ARRN.l,DM_BTCV.l
move.l #1,DM_USE.l ; AFTER scsi_init, which clears it
rts
; ---------------------------------------------------------------- pg_array
; The 193 {u32 MAR, u16 MTC} entries, built once. SCENE-CONSTANT: the packed
; layout spends both 256-colour pages, so there is no page to flip and no
; destination that changes from frame to frame (FINDINGS 62).
;
; THE ORDER IS THE CONTAINER'S. Palette first or 193rd is one paint of
; mismatch either way and 63.4 priced both at -12.8 dB without being able to
; choose; so the format records it (dlxp.py flags bit 1) and this reads it. An
; array built the other way round from the record it is fed would not fail -- it
; would paint 192 rows of picture into the palette registers and 512 B of
; palette across the top two rows of the screen, which is a picture, and a gate
; that only checked for errors would pass it.
pg_array:
movem.l d0-d2/a0-a1,-(sp)
lea PG_ARR,a0
tst.l PG_PALL.l
bne.s .rows
bsr .pal
.rows:
lea PG_TOP,a1
move.w #PG_H-1,d0
.r: move.l a1,(a0)+
move.w #PG_ROWB*2,(a0)+
lea PG_STRIDE(a1),a1
dbra d0,.r
tst.l PG_PALL.l
beq.s .done
bsr .pal
.done:
move.l a0,d0
sub.l #PG_ARR,d0
divu #6,d0
andi.l #$FFFF,d0
move.l d0,PG_ARRN.l
movem.l (sp)+,d0-d2/a0-a1
rts
.pal: move.l #GPAL,(a0)+
move.w #PG_PALB,(a0)+
rts
; ---------------------------------------------------------------- pg_video
; 256x256, 256 colours, 31.5 kHz, the two pages scrolled 384 apart, page 1 on
; top. Every value here is tools/bench/crtc_mode.lua's, which derives them from
; the dot clocks rather than recalling them; this is the same table in the place
; a player would keep it.
pg_video:
movem.l d0-d1/a0-a1,-(sp)
lea pg_crtc(pc),a0
lea CRTC,a1
moveq #0,d0
.c: move.w (a0)+,d0
bmi.s .cdone
move.w (a0)+,d1
move.w d1,0(a1,d0.w)
bra.s .c
.cdone:
move.w #PG_R20D,CRTC_R20.l
move.w #$0001,VC0.l ; 256 colours
; PAGE 1 ON TOP. MEASURED (tools/bench/probe_page1.lua): $0000 puts page 0 on
; top, its zeros then cover page 1 and the right half of the screen is black --
; which was the first failure of the packed layout and does not look like a
; priority bug from the outside.
move.w #$0002,VC1.l
move.w #$001F,VC2.l ; graphics on, all four pages
move.b #15,CONTRAST.l ; the IPL leaves 14, i.e. 7% dark
; The scroll. Both registers of each page, for the reason named at CR_P0X0.
; move.w #0 and not clr.w: CLR on a 68000 READS the destination before writing
; it, and a write-only register read back is a machine-dependent value this code
; has no reason to depend on.
move.w #0,CR_P0X0.l
move.w #0,CR_P0Y0.l
move.w #0,CR_P0X1.l
move.w #0,CR_P0Y1.l
move.w #384,CR_P1X0.l ; X = 384 = -128 mod 512
move.w #0,CR_P1Y0.l
move.w #384,CR_P1X1.l
move.w #0,CR_P1Y1.l
movem.l (sp)+,d0-d1/a0-a1
rts
; register number * 2, value; -1 ends it
pg_crtc:
dc.w 0*2,45 ; H total: 46 chars = 368 dots = 31500 Hz
dc.w 1*2,5 ; H sync end
dc.w 2*2,10 ; H disp begin
dc.w 3*2,42 ; H disp end -> 256 dots
dc.w 4*2,567 ; V total: 568 lines -> 55.4577 Hz
dc.w 5*2,5 ; V sync end
dc.w 6*2,40 ; V disp begin
dc.w 7*2,552 ; V disp end -> 512 lines, double-scanned
dc.w 8*2,27 ; H sync adjust
dc.w -1,0
; ---------------------------------------------------------------- pg_static
; The half of the screen the container does not carry (FINDINGS 47.2). Two
; regions, and they are static for two different reasons:
;
; words 128..511 of EVERY row. Page 1's storage at 384..511 sits under screen
; columns 0..127 after the +384 scroll and must read 0 so the opaque page 0
; shows through; the rest is off-screen storage. Zero, once.
; the LETTERBOX rows, 0..31 and 224..255. The picture is 192 rows of a
; 256-row screen. $FFFF is index 255 in both bytes, and 255 is black in
; every frame's palette (vq.frame_palette reserves it), so these rows stay
; correct across a per-frame palette without being rewritten.
;
; Written with the WRITE WINDOW OPEN, because that is the only mode in which a
; word write lands both bytes -- outside it gvram_w takes `data & 0x00ff` and
; the high byte is thrown away, which is the whole 2.0 B/pixel problem (46.5).
pg_static:
movem.l d0-d3/a0-a1,-(sp)
move.w #PG_R20B,CRTC_R20.l
lea GVRAM,a0
move.w #SCRH-1,d0 ; y
moveq #0,d3
.row:
movea.l a0,a1
move.w d3,d1
cmp.w #PG_YOFF,d1
bcs.s .letter
cmp.w #PG_YOFF+PG_H,d1
bcc.s .letter
lea PG_ROWB*2(a1),a1 ; a picture row: leave words 0..127 to
move.w #SCRW-PG_ROWB-1,d1 ; the channel, zero 128..511
bra.s .z
.letter:
move.w #PG_ROWB-1,d1 ; words 0..127 <- black
.lb: move.w #PG_BLACK,(a1)+
dbra d1,.lb
move.w #SCRW-PG_ROWB-1,d1 ; ...and 128..511 <- 0, as everywhere
.z: clr.w (a1)+
dbra d1,.z
lea PG_STRIDE(a0),a0
addq.w #1,d3
dbra d0,.row
move.w #PG_R20D,CRTC_R20.l
movem.l (sp)+,d0-d3/a0-a1
rts
include "src/player/clock.i"
; scsi.i includes src/player/dma.i itself, at its foot -- so it is NOT included
; here. The DMAC constants and sc_in_dma come in with the transport that uses
; them, which is also why dmagate.s includes only scsi.i.
include "src/player/scsi.i"
+215
View File
@@ -0,0 +1,215 @@
#!/usr/bin/env python3
"""HOW LONG IS THE PICTURE ACTUALLY ON SCREEN? ROADMAP K3, FINDINGS 64.
python3 tools/analysis/31_display_duty.py [container.dlxp] [--rate KB/s ...]
THE QUESTION NOTHING IN THIS TREE HAD ASKED. Every budget in docs/FINDINGS.md
asks what a frame COSTS -- clocks, bus cycles, bytes on the wire. Session 32
built the packed player and ran it (src/player/packed.s), and the run reported a
number no budget has a column for: the write window was open on 99.5% of the
host frames, so the graphics layer was DARK for 99.5% of the scene. Every frame
was pixel-exact and almost none of them was visible.
WHY THAT IS ARITHMETIC AND NOT AN EMULATOR ARTEFACT. 256-colour GVRAM masks the
high byte of every write unless CRTC R20 bit 11 is set (46.5/47.1), and the
packed layout's whole 1.0 B/pixel claim is that one word carries two pixels --
so a packed write REQUIRES the bit. If buffer mode blanks the layer while the
bit is set (47.4/ROADMAP B2 -- MAME says it does, and 48.1's prior leans that
way), then the layer is dark for exactly as long as the window is open, and for
a DMAC-direct player the window is open for the whole transfer. There is no
second page to hide behind: the packed layout SPENDS both 256-colour pages,
which is the same fact that made a frame one channel start (FINDINGS 62).
dark fraction of a slot = record bytes / (data-phase rate x slot)
AND THE RATE IN THAT EXPRESSION IS THE BURST RATE, NOT THE SUSTAINED ONE. This
is the correction the session had to make to itself. The container's 582.0 KB/s
is a SUSTAINED requirement -- it decides whether record i arrives before slot i.
The dark fraction is set by how fast bytes move DURING THE DATA PHASE, which for
a drive with a read-ahead cache can be several times the sustained figure. The
two are independent, and a medium can pass one and fail the other:
sustained >= 582.0 KB/s or frames arrive late (B1, known)
data phase >> 582.0 KB/s or the frame is never displayed (NEW, and B1 has
no test for it)
THE OTHER PLAYER IN THE FAMILY DOES NOT HAVE THIS PROPERTY. A packed player
that DMAs the record into RAM and paints it with the CPU opens the window only
for the paint -- tools/bench/blit.s V8, MEASURED, not assumed -- which is a
fixed share of the slot no matter what the medium does. It costs more clocks
and 49 KB of RAM and it buys a picture that is on screen. FINDINGS 61.5 already
priced both in CLOCKS and ranked DMAC-direct first; this file is the column that
was missing from that table, and it reverses the ranking under B2-blanks.
"""
import argparse, os, re, sys
sys.path.insert(0, "tools/encoder")
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from dlxp import DLXP
import buscost as B
CPUHZ = 10e6 # stock X68000, MAME 0.277 x68k.cpp:1133
ap = argparse.ArgumentParser()
ap.add_argument("container", nargs="?", default="tmp/packed_singe.dlxp")
ap.add_argument("--blit-log", default="tmp/blit_v8.log",
help="tools/bench/blit.lua's log -- the MEASURED packed paint. "
"Not a constant in this file: 47.6.1 filed the movem shape "
"as an assumption and session 29 measured it, and a second "
"copy of a measured number is how one of them goes stale.")
ap.add_argument("--rate", type=float, nargs="*", default=None,
help="data-phase rates to price, KB/s. REQUIRED to mean "
"anything: this project has no delivery figure and will "
"not default to one (FINDINGS 50).")
ap.add_argument("--run-log", default="tmp/packed_free_steal.log",
help="a free-running tools/bench/packed.lua log, for the "
"measured corroboration section")
a = ap.parse_args()
d = DLXP(a.container)
SLOT_S = 1.0 / d.fps
FRAME_CLK = CPUHZ * SLOT_S
wire = d.kbps() # KB/s, and fixed by geometry
blit = {}
if os.path.exists(a.blit_log):
for line in open(a.blit_log, errors="replace"):
m = re.search(r"V(\d+)\s+(\d+) cyc", line)
if m:
blit[int(m.group(1))] = int(m.group(2))
if 8 not in blit:
sys.exit(f"{a.blit_log} has no V8 result. The packed paint is a MEASUREMENT "
f"(tools/bench/blit.lua) and this tool will not substitute a "
f"constant for it -- run the blit bench, or point --blit-log at "
f"its log.")
PAINT_CLK = blit[8]
PAINT_FRAC = PAINT_CLK / FRAME_CLK
print(f"""THE CONTAINER (tools/encoder/dlxp.py)
{a.container}: {d.W}x{d.H} {d.fps} fps, {d.nframes} frames
record {d.rec_bytes:,} B = {d.rec_bytes // 512} sectors, palette \
{'LAST' if d.palette_last else 'FIRST'}
slot {SLOT_S*1000:.2f} ms = {FRAME_CLK:,.0f} clocks
wire {wire:.1f} KB/s -- FIXED by geometry. A codec's bitrate is a lever and a
literal frame's is not (61.6), so nothing an encoder does moves this.
THE TWO PACKED PLAYERS, and the difference is WHEN the write window is open
A. DMAC-DIRECT (src/player/packed.s, ROADMAP K3, and the one that is built).
One channel start, 193 destinations, the CPU halted or nearly. The window
must be open for the WHOLE data phase, because the channel writes when the
bytes arrive and the CPU cannot know when that is -- and a packed write
that lands with the bit clear is masked to its low byte and silently wrong.
B. DMA-TO-RAM + CPU PAINT. The record lands in RAM with the window shut; the
68000 then paints it with the packed movem blit. The window is open for the
PAINT and nothing else: {PAINT_CLK:,} clocks, {100*PAINT_FRAC:.1f}% of a slot,
MEASURED by tools/bench/blit.lua (V8), and INDEPENDENT of the medium.
Under 47.4-blanks the dark interval IS the open window, so B is on screen for
{100*(1-PAINT_FRAC):.1f}% of every slot at ANY rate that delivers the record at all,
and A's visibility is a function of the rate.
""")
rates = a.rate
if not rates:
print("""NO RATES GIVEN, so no table. This project retired its delivery
constant outright (FINDINGS 50, USER DECISION) and every tool requires an
explicit rate; a default here would be the same mistake in a new place. Pass
--rate with the figures you want priced. The three thresholds already derived
elsewhere, for reference and NOT as defaults:
453.6 KB/s the DLX5 codec gate container needs no prefill (49.5/60)
576.0 KB/s a packed container with no per-frame palette (61.5)
582.0 KB/s THIS container, palette included (63)
and note that all three are SUSTAINED figures. The dark fraction below is set by
the DATA-PHASE rate, which is a different measurement nothing has taken.""")
sys.exit(0)
print("A's VISIBILITY, against the DATA-PHASE rate\n")
print(f" {'data phase':>12} | {'transfer':>9} | {'window open':>11} | "
f"{'PICTURE ON SCREEN':>17} | vs B")
print(f" {'KB/s':>12} | {'ms':>9} | {'% of slot':>11} | "
f"{'% of slot':>17} |")
print(" " + "-"*12 + "-+-" + "-"*9 + "-+-" + "-"*11 + "-+-" + "-"*17 + "-+-----")
for R in sorted(rates):
t_ms = d.rec_bytes / (R * 1024) * 1000
openf = min(1.0, t_ms / (SLOT_S * 1000))
vis = 1.0 - openf
verdict = ("A wins" if vis > 1 - PAINT_FRAC else
"B wins" if vis < 1 - PAINT_FRAC else "equal")
late = " LATE" if R < wire else ""
print(f" {R:>12.1f} | {t_ms:>9.2f} | {100*openf:>11.1f} | "
f"{100*vis:>17.1f} | {verdict}{late}")
# The crossover, stated as a rate rather than left to be read off the table: it
# is the one number in here a hardware acceptance test can be written against.
cross = d.rec_bytes / (PAINT_FRAC * SLOT_S) / 1024
print(f"""
A and B show the picture for the same share of the slot at a data-phase rate
of {cross:,.0f} KB/s. Below that, THE PLAYER WITH THE CPU IN THE LOOP IS ON
SCREEN LONGER than the one without it -- which is the reverse of FINDINGS
61.5's ranking, and 61.5 is not wrong: it ranked them in CLOCKS, and this is
the column that table does not have.
{cross:,.0f} KB/s is {cross/wire:.1f}x the container's own wire. So a medium that exactly
meets the sustained requirement puts the DMAC-direct player's picture on
screen for {100*max(0.0, 1-wire/wire):.0f}% of every slot: it delivers every frame, on time,
pixel-exact, and displays none of them.""")
print(f"""
THE CPU SIDE, so the trade is priced on both axes (FINDINGS 61.5's ladder)
W is clocks stolen per delivered byte. Only the dual-address rungs have a code
path on this machine (59.2), and 9 is the floor: a 4-clock read of the device
plus a 5-clock write to memory.
""")
print(f" {'W':>3} | {'A: DMAC-direct':>15} | {'B: DMA + CPU paint':>19}")
print(" " + "-"*3 + "-+-" + "-"*15 + "-+-" + "-"*19)
AUDIO = B.ADPCM_BYTES_PER_S / d.fps * B.ADPCM_CLK_BYTE_BEST
for W in (5, 9, 12, 16, 19):
xfer = d.rec_bytes * W
ca = (xfer + AUDIO) / FRAME_CLK
cb = (xfer + AUDIO + PAINT_CLK) / FRAME_CLK
print(f" {W:>3} | {100*ca:>14.1f}% | {100*cb:>18.1f}%")
print(f"""
Both include the audio DMA at {AUDIO:,.0f} clocks a frame ({100*AUDIO/FRAME_CLK:.2f}%), charged from
the IPL ROM's own channel-3 setup (21_iplrom_dmac.py, 52.5). Neither includes
a decoder, because neither has one.
So B costs the paint -- {100*PAINT_FRAC:.1f}% of a frame -- and TWO record buffers,
{2*d.rec_bytes:,} B of RAM. Two and not one: at any rate near the wire the delivery
of record i+1 occupies most of the slot the paint of record i happens in, so
they overlap by construction. On a 2 MB machine that is {200*d.rec_bytes/(2*1024*1024):.1f}% of memory and
it is the resource this design has spare -- the ring the packed branch deleted
was 256 KB (FINDINGS 49). That is what a visible picture costs if 47.4 blanks.""")
# ---- the measured corroboration. It is a SEPARATE section and it is bounded
# on purpose: MAME's device models carry no transfer timing (docs/BENCHMARK.md,
# 42.5), so the run cannot supply a rate for the table above -- what it can do
# is show that the mechanism is real and that the arithmetic predicts it.
if os.path.exists(a.run_log):
txt = open(a.run_log, errors="replace").read()
m_rate = re.search(r"record lands in ([\d.]+) ms, i\.e\. ([\d.]+) KB/s", txt)
m_open = re.search(r"WRITE WINDOW OPEN on (\d+) of (\d+) host frames", txt)
if m_rate and m_open:
ms, kbps = float(m_rate.group(1)), float(m_rate.group(2))
op, tot = int(m_open.group(1)), int(m_open.group(2))
pred = min(1.0, d.rec_bytes / (kbps * 1024) / SLOT_S)
print(f"""
MEASURED, on the emulated machine (tools/bench/packed_run.sh, free-running)
{a.run_log}: a {d.rec_bytes:,} B record landed in {ms:.2f} ms = {kbps:.1f} KB/s, and the
write window was open on {op} of {tot} host frames = {100*op/tot:.1f}%.
The expression above predicts {100*pred:.1f}% at that rate.
THIS IS NOT A RATE MEASUREMENT AND {kbps:.0f} KB/s IS NOT A MEDIUM. MAME's
device models carry no transfer timing (42.5); the figure is a property of the
apparatus. What the run DOES establish is that the mechanism is the one the
arithmetic describes -- and one thing more that no arithmetic could have
given: the DMAC CONFIGURATION DOES NOT MOVE IT. Held and stealing delivered
the same record within 0.5% of each other, so what a channel configuration
buys is who owns the CPU, not when the picture appears.""")
else:
print(f"""
NO MEASURED SECTION: {a.run_log} is absent. Run
tools/bench/packed_run.sh to produce it. The arithmetic above stands without
it -- it is geometry -- but the run is what showed the effect was there to be
derived at all.""")
+32
View File
@@ -703,4 +703,36 @@ else
echo " SKIPPED: no px68k at $PX68K -- the container's bytes were not rendered" echo " SKIPPED: no px68k at $PX68K -- the container's bytes were not rendered"
fi fi
echo "--- session 32: the PACKED PLAYER, end to end off the disc (FINDINGS 64) ---"
# ROADMAP K3. src/player/packed.s brings up its own display, builds its own
# 193-entry DMA chain, keeps its own frame clock off V-DISP and fetches every
# record itself with READ(10) off a CZ-6BS1. This script writes no picture byte
# and no palette entry.
#
# WHY EVERY FRAME IS COMPARED AND THE CODEC'S GATE COMPARES ONE. The codec is
# temporally recursive -- a SKIP block is a claim about the previous frame -- so
# its last frame audits all 120. A packed frame is a LITERAL and frame 119 says
# nothing about frame 60. The simplification that deleted the ring also deleted
# the gate's free lunch.
#
# AND WHY IT IS PACED AT HALF RATE. The write window has to be OPEN for the
# whole transfer and buffer mode blanks the graphics layer, so at the
# container's own 12 fps there is no instant at which a complete frame is
# displayable and there is nothing to snapshot (FINDINGS 64.2 -- that is the
# session's finding, not a rig limitation being worked around). Half rate opens
# a display interval without changing one byte of the transfer.
#
# GATE ONLY: runs 2-4 of packed_run.sh measure the apparatus rather than gate
# it, and they are three more MAME jobs for numbers that cannot change unless
# MAME does. tools/bench/packed_run.sh with no DLX_PK_GATE_ONLY runs all four.
if [ -f "$HOME/mame/roms/x68000.zip" ] || [ -d "$HOME/mame/roms/x68000" ]; then
DLX_PK_GATE_ONLY=1 DLX_PK_NFR="$NF" bash tools/bench/packed_run.sh \
tmp/packed_singe.dlxp > tmp/packed_gate_stage.log 2>&1 \
|| { cat tmp/packed_gate_stage.log; exit 1; }
grep -aE "^ (FLAG|array|chain|frame clock|late frames|WRITE WINDOW)|^OK " \
tmp/packed_gate_stage.log
else
echo " SKIPPED: no x68000 romset -- the player was not run"
fi
echo "ALL GREEN" echo "ALL GREEN"
+31 -8
View File
@@ -3,7 +3,21 @@
# instantiate the card. Sourced-by-calling from tools/bench/scsi_run.sh and # instantiate the card. Sourced-by-calling from tools/bench/scsi_run.sh and
# tools/bench/pace_run.sh so there is ONE copy of the layout. # tools/bench/pace_run.sh so there is ONE copy of the layout.
# #
# tools/bench/mkvol.sh [container.dlx] # tools/bench/mkvol.sh [container.dlx | container.dlxp]
#
# TWO CONTAINERS, ONE VOLUME BUILDER. A DLX volume is tools/bench/prep_stream.py's
# disk image -- the codec's records, laid down from sector 0. A DLXP volume
# (ROADMAP K2/K3) needs no preparation at all: the container is ALREADY a
# sector-aligned image of itself -- a 512 B header, then fixed 97-sector records
# -- so the file IS the volume and copying it is the whole build. That is not a
# convenience, it is the format's central claim (tools/encoder/dlxp.py) arriving
# at the disc, and a builder that transformed it on the way would be hiding the
# claim rather than testing it.
#
# The two get DIFFERENT CHD NAMES. Alternating between the packed rig and the
# codec rig would otherwise rebuild the volume on every run, and -- much worse --
# a stale CHD under the name the other rig expected would serve one container's
# bytes to the other's gate, which reads as a decode failure and is not one.
# #
# ONE COPY, ON PURPOSE. The volume is tmp/stream_disk.bin -- byte for byte the # ONE COPY, ON PURPOSE. The volume is tmp/stream_disk.bin -- byte for byte the
# file the host-file ring rig reads -- laid out as 512 B sectors. If two scripts # file the host-file ring rig reads -- laid out as 512 B sectors. If two scripts
@@ -22,15 +36,24 @@ set -e
cd "$(dirname "$0")/../.." cd "$(dirname "$0")/../.."
DLX=${1:-tmp/rc_fr_singe_scsi_span.dlx} DLX=${1:-tmp/rc_fr_singe_scsi_span.dlx}
[ -f tmp/stream_disk.bin ] || python3 tools/bench/prep_stream.py "$DLX" > /dev/null case "$DLX" in
if [ ! -f tmp/dlxdisk.chd ] || [ tmp/stream_disk.bin -nt tmp/dlxdisk.chd ]; then *.dlxp) SRC="$DLX"
python3 - <<'PY' IMG=tmp/dlxpdisk.img; CHD=tmp/dlxpdisk.chd ;;
d = open("tmp/stream_disk.bin", "rb").read() *) SRC=tmp/stream_disk.bin
IMG=tmp/dlxdisk.img; CHD=tmp/dlxdisk.chd
[ -f "$SRC" ] || python3 tools/bench/prep_stream.py "$DLX" > /dev/null ;;
esac
if [ ! -f "$CHD" ] || [ "$SRC" -nt "$CHD" ]; then
SRC="$SRC" IMG="$IMG" python3 - <<'PY'
import os
src, img = os.environ["SRC"], os.environ["IMG"]
d = open(src, "rb").read()
n = (len(d) + 511) // 512 n = (len(d) + 511) // 512
open("tmp/dlxdisk.img", "wb").write(d + b"\0" * (n * 512 - len(d))) open(img, "wb").write(d + b"\0" * (n * 512 - len(d)))
print(f" disc image: {len(d)} B of records -> {n} sectors") print(f" disc image: {len(d)} B of records -> {n} sectors")
PY PY
rm -f tmp/dlxdisk.chd rm -f "$CHD"
# -c none IS LOAD-BEARING, and it was found by a gate rather than by taste. # -c none IS LOAD-BEARING, and it was found by a gate rather than by taste.
# Session 28, on the DLX5 volume: with the default (lzma/zlib/huff/flac) MAME # Session 28, on the DLX5 volume: with the default (lzma/zlib/huff/flac) MAME
# 0.277 served the CHD FILE'S OWN BYTES as sector data -- the destination # 0.277 served the CHD FILE'S OWN BYTES as sector data -- the destination
@@ -45,7 +68,7 @@ PY
# disc space: the failure is SILENT at the transport layer -- every READ(10) # disc space: the failure is SILENT at the transport layer -- every READ(10)
# reports success and returns the wrong bytes -- and only the byte comparison # reports success and returns the wrong bytes -- and only the byte comparison
# in tools/bench/scsi.lua catches it. # in tools/bench/scsi.lua catches it.
chdman createhd -i tmp/dlxdisk.img -o tmp/dlxdisk.chd -ss 512 -c none > /dev/null 2>&1 chdman createhd -i "$IMG" -o "$CHD" -ss 512 -c none > /dev/null 2>&1
fi fi
mkdir -p tmp/p4roms/x68k_cz6bs1 mkdir -p tmp/p4roms/x68k_cz6bs1
+332
View File
@@ -0,0 +1,332 @@
-- Drive src/player/packed.s: THE DECODER-FREE PACKED PLAYER, END TO END,
-- OFF A REAL VOLUME. ROADMAP K3.
--
-- WHAT THIS SCRIPT DOES NOT DO IS THE POINT OF IT. tools/bench/stream.lua
-- pushes expanded codebooks and a packed palette into RAM, plays a transport at
-- a modelled byte rate, and writes the frame tick. This one pushes 2,898 bytes
-- of 68000 code and eleven mailbox words, and then READS. It moves no picture
-- byte, models no rate, sets no CRTC register and writes no palette entry: the
-- machine brings up its own display, builds its own chain, keeps its own clock
-- off V-DISP and fetches every record itself with READ(10) off a CZ-6BS1.
--
-- SO THE GATE IS NOT THE ONE THE CODEC USES, AND IT HAD TO CHANGE.
-- tools/bench/verify_decode.py checks ONE frame -- the last -- and that audits
-- the whole run because the codec is temporally recursive: a SKIP block is a
-- claim about the previous frame still being on screen, so the final frame is
-- only right if all 120 were. A packed frame is a LITERAL. Frame 119 being
-- pixel-exact says nothing whatever about frame 60. This script therefore
-- snapshots EVERY frame and tools/bench/verify_packed.py compares all of them;
-- the simplification that deleted the ring also deleted the gate's free lunch.
--
-- WHEN A SNAPSHOT IS TAKEN, and why not on the frame it changed. PG_SHOWN is
-- bumped by the 68000 after it clears R20 bit 11, so a change means "a complete
-- frame is now displayable". But MAME's screen bitmap for the host frame in
-- progress was drawn partly before that instant, so snapshotting immediately
-- would sample the write window -- which BLANKS the graphics layer -- for part
-- of the picture. A 12 fps frame lasts 4 or 5 host refreshes at 56.69 Hz, so
-- waiting SNAP_DELAY whole host frames is safely inside the slot and safely
-- after the window closed.
--
-- Env:
-- DLX_PK_HELD 1 = the channel HOLDS THE BUS (burst, max rate), 0 = it
-- steals cycles. Not two speeds of one thing: 59.3 showed an
-- auto-requested channel is charged by TIME, so held is the
-- 68000 stopped for as long as the record takes to arrive.
-- Default 1.
-- DLX_PK_PACE 1 = the machine holds itself to the container's fps off
-- V-DISP (default). 0 free-runs, which tests the CHAIN with
-- the clock out of the way.
-- DLX_PK_ITER passes over the scene (default 1). >1 exercises the seek,
-- which for this container is arithmetic and nothing else.
-- DLX_PK_NFR play only the first N frames (default: all of them)
-- DLX_PK_FPS pace at this rate instead of the container's. NOT a
-- cosmetic knob and not a way to make a number look better:
-- under MAME the emulated transport takes about a whole 12 fps
-- slot to deliver a 49,664 B record, and the write window has
-- to be OPEN for all of it -- so at 12 fps there is no instant
-- at which a complete frame is displayable and nothing can be
-- snapshotted. Pacing slower opens a display interval without
-- changing one byte of the transfer, which is what lets the
-- PIXEL-EXACTNESS of all 120 frames be gated separately from
-- the RATE the emulated transport happens to run at. The two
-- are different questions and this is the knob that separates
-- them.
-- DLX_PK_CSV write the per-frame arrival series here
M = manager.machine
SP = M.devices[":maincpu"].spaces["program"]
local function findfile(n)
for _,p in ipairs{"../tools/bench/"..n, "tools/bench/"..n, n} do
local f = io.open(p,"rb"); if f then f:close(); return p end
end
error(n.." not found")
end
local META = loadfile("packed_meta.lua")()
-- src/player/packed.s. Inputs first, then outputs; the split is the file's.
local PG_FLAG, PG_NFR, PG_FPS, PG_LBA0 = 0x18900, 0x18904, 0x18908, 0x1890C
local PG_RECS, PG_PALL, PG_HELD = 0x18910, 0x18914, 0x18918
local PG_PACEON, PG_ITER = 0x1891C, 0x18920
local PG_SHOWN, PG_ERR, PG_ERRAT = 0x18930, 0x18934, 0x18938
local PG_LATE, PG_LATE1, PG_LATEM = 0x1893C, 0x18940, 0x18944
local PG_VDISP, PG_VD0, PG_TSPIN = 0x18948, 0x1894C, 0x18950
local PG_GSPIN, PG_LOSTV, PG_ARRN = 0x18954, 0x18958, 0x1895C
local PG_ARR = 0x1B000
-- src/player/clock.i and src/player/scsi.i, read for diagnosis only.
local CLK_PACE, CLK_VDISP, CLK_ERR = 0x18034, 0x18064, 0x1806C
local SC_ERR = 0x18200
local CRTC_R20 = 0xE80028
local HELD = (os.getenv("DLX_PK_HELD") or "1") == "1"
local PACED = (os.getenv("DLX_PK_PACE") or "1") == "1"
local ITERS = tonumber(os.getenv("DLX_PK_ITER") or "") or 1
local NFR = tonumber(os.getenv("DLX_PK_NFR") or "") or META.nframes
local FPS = tonumber(os.getenv("DLX_PK_FPS") or "") or META.fps
local CSV = os.getenv("DLX_PK_CSV")
local SNAP_DELAY = 2
local SCERRNAME = {[0]="OK", "SELECTION TIMEOUT -- no target answered",
"UNEXPECTED PHASE", "POLL TIMEOUT -- a phase never arrived",
"NON-ZERO SCSI STATUS",
"WINDOWED READ REFUSED -- a channel cannot drop bytes"}
local code do local f=assert(io.open("packed.bin","rb")); code=f:read("a"); f:close() end
local function T() local t=M.time; return t.seconds + t.attoseconds/1e18 end
local function P(s) print("[PK] "..s) end
local function setup()
for i = 1, #code do SP:write_u8(0x10000+i-1, string.byte(code,i)) end
SP:write_u32(PG_FLAG, 0)
SP:write_u32(PG_NFR, NFR)
SP:write_u32(PG_FPS, FPS)
SP:write_u32(PG_LBA0, META.lba0)
SP:write_u32(PG_RECS, META.rec_sectors)
SP:write_u32(PG_PALL, META.palette_last)
SP:write_u32(PG_HELD, HELD and 1 or 0)
SP:write_u32(PG_PACEON, PACED and 1 or 0)
SP:write_u32(PG_ITER, ITERS)
SP:write_u32(PG_SHOWN, 0)
P(string.format("packed.bin=%d B, %dx%d %d fps, %d of %d frames, %d passes",
#code, META.W, META.H, META.fps, NFR, META.nframes, ITERS))
P(string.format("record %d B = %d sectors at LBA %d + i*%d, palette %s",
META.rec_bytes, META.rec_sectors, META.lba0,
META.rec_sectors, META.palette_last == 1 and "LAST" or "FIRST"))
P(string.format("channel: %s, %s",
HELD and "BUS HELD (burst, max rate)" or "CYCLE STEALING",
PACED and ("SELF-PACED at "..FPS.." fps off V-DISP"
..(FPS ~= META.fps and (" -- NOT the container's "
..META.fps..", see DLX_PK_FPS") or ""))
or "FREE-RUNNING (tests the chain, not the clock)"))
P("this script writes NO picture byte, NO palette entry and NO CRTC register: "
.."the machine brings up its own display and fetches its own records.")
end
local function launch()
local cpu = M.devices[":maincpu"]
cpu.state["SR"].value = 0x2700 -- supervisor, all interrupts masked;
cpu.state["SP"].value = 0x8000 -- clk_init lowers it to $2500 itself
cpu.state["PC"].value = 0x10000
end
local st, t0 = "boot", nil
local shown, pending, snaps = 0, nil, 0
local arrive, hostfr, missed = {}, 0, 0
-- WHICH FRAME EACH SNAPSHOT IS. MAME numbers snapshots 0000, 0001, ... in the
-- order they were taken, and a frame that could not be sampled leaves no gap in
-- that sequence -- so the file name is NOT the frame index and a verifier that
-- assumed it was would compare frame 61 against record 60 and report a codec
-- bug that is really a bookkeeping one. This is the map, written out for it.
local snapfr = {}
local r20seen = {}
SUB = emu.add_machine_frame_notifier(function()
local ok, err = pcall(function()
local t = T()
if st == "boot" then
if t < 3.0 then return end
setup(); launch(); t0 = t; st = "running"; return
end
if st ~= "running" then return end
hostfr = hostfr + 1
-- WHAT THE SCREEN MODE WAS, sampled every host frame. R20 bit 11 blanks
-- the graphics layer, so this is the only way to see the shutter the player
-- is running: the fraction of host frames that found the window OPEN is the
-- fraction of the scene the display spent dark, and it is a MEASUREMENT of
-- 47.4's cost under MAME rather than a restatement of the prior.
local r20 = SP:read_u16(CRTC_R20)
r20seen[#r20seen+1] = ((r20 >> 11) & 1)
local s = SP:read_u32(PG_SHOWN)
if s > shown then
-- Only the LAST change matters if several landed in one host frame; that
-- cannot happen at 12 fps on a 56.69 Hz raster, and if it ever does the
-- gate below catches it as a missing snapshot rather than a wrong one.
arrive[#arrive+1] = {n = s, t = t - t0}
shown = s
pending = SNAP_DELAY
end
if pending then
pending = pending - 1
if pending <= 0 then
pending = nil
if (SP:read_u16(CRTC_R20) >> 11) & 1 == 0 then
M.video:snapshot(); snaps = snaps + 1
snapfr[#snapfr+1] = shown - 1
else
-- The window was open again when the delay expired: the frame we
-- meant to sample is being overwritten. COUNTED, NOT PRINTED -- when
-- the transfer is longer than the slot EVERY frame misses, and 119
-- identical lines bury the four numbers the run exists to report.
-- The count is reported once at the end and the gate reads it there.
missed = missed + 1
end
end
end
local flag = SP:read_u32(PG_FLAG)
if flag ~= 1 and pending then
-- THE LAST FRAME IS STILL PENDING. packed.s spins in pg_hold with the
-- window CLOSED once the scene is over, so the delay can simply run out;
-- returning here rather than reporting is what stops the final frame
-- being the one frame the gate never sees.
return
end
if flag ~= 1 then
st = "done"
local wall = t - t0
P(string.format("FLAG=$%02X after %.3f s, %d frames shown, %d snapshots, "
.."%d frames NOT SAMPLED (the write window had reopened "
.."-- the transfer is longer than the display interval)",
flag, wall, shown, snaps, missed))
local err = SP:read_u32(PG_ERR)
if err ~= 0 then
P(string.format("TRANSPORT FAILED on frame %d: %s",
SP:read_u32(PG_ERRAT), SCERRNAME[err] or ("code "..err)))
end
P(string.format("array: the 68000 built %d entries (the container wants "
.."%d)", SP:read_u32(PG_ARRN), META.entries))
-- The first entry, read back out of the machine's own RAM. It is the one
-- place palette-first and palette-last are visible as a FACT rather than
-- as a flag the rig passed in and the rig read back.
P(string.format("chain[0] = MAR $%06X MTC %d ; chain[1] = MAR $%06X MTC %d",
SP:read_u32(PG_ARR), SP:read_u16(PG_ARR+4),
SP:read_u32(PG_ARR+6), SP:read_u16(PG_ARR+10)))
if PACED then
local vd = SP:read_u32(PG_VDISP) - SP:read_u32(PG_VD0)
-- THE CLOCK, AGAINST THE RASTER THAT DROVE IT. CLK_VDISP counts the
-- edges the 68000's ISR SAW. hostfr counts the frames MAME actually
-- drew. A held channel halts the CPU, and the MFP's pending bit is one
-- bit, so an edge that falls inside a transfer long enough to span two
-- of them is an edge the machine can never count. Nothing in this
-- project has ever run a transfer and a clock at once, so nothing could
-- have seen this before.
P(string.format("frame clock: PACE=%d ticks, V-DISP edges SEEN=%d, "
.."host frames drawn=%d -> %d edges LOST (%.1f%%)",
SP:read_u32(CLK_PACE), vd, hostfr, hostfr - vd,
hostfr > 0 and (hostfr-vd)*100/hostfr or 0))
local nlate = SP:read_u32(PG_LATE)
P(string.format("late frames (tick already past at the gate): %d%s",
nlate, nlate > 0 and string.format(", first %d, worst "
.."%d ticks", SP:read_u32(PG_LATE1),
SP:read_u32(PG_LATEM)) or ""))
-- AND WHY `late = 0` IS NOT `on time`. The gate compares the frame
-- index against PACE, and PACE is advanced by the ISR that the held
-- channel stops the CPU from running. A clock that loses edges loses
-- them from BOTH sides of the comparison, so a player whose own clock
-- has halved still reports every frame early. The LOST figure above is
-- the only thing in this run that can contradict it, and it comes from
-- the host's raster count rather than from the machine.
if hostfr - vd > 0 then
P(string.format(" ...and %d of those ticks were never "
.."issued, so `late=%d` is measured against a clock "
.."running at %.1f%% of the raster. The player "
.."believes it is at %d fps and the screen is at "
.."%.2f.", hostfr - vd, nlate, vd*100/hostfr, FPS,
FPS * vd / hostfr))
end
end
P(string.format("CPU: %d trips round the TRANSFER wait in total, %d round "
.."the PACE gate", SP:read_u32(PG_TSPIN),
SP:read_u32(PG_GSPIN)))
local open = 0
for _,v in ipairs(r20seen) do open = open + v end
P(string.format("WRITE WINDOW OPEN on %d of %d host frames (%.1f%%) -- "
.."buffer mode blanks the graphics layer, so that is the "
.."share of the scene the display spent DARK under MAME",
open, #r20seen, #r20seen > 0 and open*100/#r20seen or 0))
if #arrive >= 2 then
local dts, first, last = {}, arrive[1].t, arrive[#arrive].t
for i = 2, #arrive do dts[#dts+1] = arrive[i].t - arrive[i-1].t end
table.sort(dts)
-- CADENCE, AND THE GRANULARITY IT IS MEASURED AT. PG_SHOWN is sampled
-- once per host frame, so a single inter-frame figure is quantised to
-- 1/56.69 s = 17.6 ms and the min/median/max below are multiples of it.
-- The MEAN over the whole run is not: the quantisation error is bounded
-- by one host frame at each END, so over n-1 intervals it is 35 ms/(n-1)
-- -- 0.30 ms a frame over 120. Read the mean; the spread is the
-- sampler's, not the player's.
local mean = (last-first)/(#arrive-1)
P(string.format("cadence: %d frames in %.3f s = %.3f fps, mean "
.."%.2f ms/frame (+/- %.2f ms, the sampler's); "
.."inter-frame min %.1f median %.1f max %.1f ms",
#arrive, last-first, (#arrive-1)/(last-first),
mean*1000, 35.3/(#arrive-1),
dts[1]*1000, dts[math.ceil(#dts/2)]*1000,
dts[#dts]*1000))
-- THE TRANSPORT'S TIME IS ONLY READABLE OFF A FREE-RUNNING RUN.
-- Paced, the mean inter-frame IS THE PACE PERIOD: the player waits for
-- its tick and the record's delivery hides inside the slot, so dividing
-- the record by that mean reports the clock rather than the transport
-- and reports it as a rate. The first cut of this script printed
-- "297.4 KB/s" off a 6 fps gate run, which is the pace and not the
-- disc. Free-running there is no gate and the loop is transfer-bound,
-- so the mean is the transfer.
if not PACED then
P(string.format(" -> FREE-RUNNING, so the mean IS the "
.."transport: a %d B record lands in %.2f ms, i.e. "
.."%.1f KB/s and %.1f%% of a %d fps slot. MAME's "
.."device models carry no transfer timing "
.."(docs/BENCHMARK.md, 42.5), so this is a property "
.."of the APPARATUS -- it is not W and it is not a "
.."measurement of any medium.",
META.rec_bytes, mean*1000,
META.rec_bytes/mean/1024,
mean*META.fps*100, META.fps))
else
-- What a paced run CAN say about the transfer, and it says it from
-- the display rather than from the clock: the window is open for
-- exactly as long as the record takes, so the open fraction times the
-- slot is the transfer time, sampled at the host's frame rate.
P(string.format(" -> PACED, so this mean is the PACE and "
.."NOT the transport. What the run does bound is the "
.."transfer: the window was open %.1f%% of a "
.."%.2f ms slot = %.1f ms a record.",
open*100/#r20seen, mean*1000,
open/#r20seen*mean*1000))
end
end
if CSV then
local f = io.open(CSV, "w")
f:write("frame,t_s\n")
for _,a in ipairs(arrive) do f:write(string.format("%d,%.6f\n", a.n-1, a.t)) end
f:close()
P("arrivals -> "..CSV)
end
do
local f = assert(io.open("packed_snaps.csv", "w"))
f:write("snapshot,frame\n")
for i, fr in ipairs(snapfr) do
f:write(string.format("%04d,%d\n", i-1, fr))
end
f:close()
P(string.format("%d snapshots -> tmp/packed_snaps.csv", #snapfr))
end
P("done")
M:exit()
end
end)
if not ok then print("[PK] LUA ERROR: "..tostring(err)); M:exit() end
end)
+158
View File
@@ -0,0 +1,158 @@
#!/bin/bash
# THE PACKED PLAYER, END TO END, OFF A REAL VOLUME. ROADMAP K3.
#
# tools/bench/packed_run.sh [container.dlxp]
#
# Four runs of src/player/packed.s, and each answers a different question. They
# are separate runs because the questions interfere: the write window has to be
# OPEN for the whole transfer and buffer mode blanks the graphics layer, so at
# the container's own 12 fps there is no instant at which a complete frame is
# displayable and the pixel gate has nothing to sample. Pacing slower opens a
# display interval without changing one byte of the transfer. Reporting the
# rate off the gate run instead would have been the flattering shortcut, and it
# reports the PACE rather than the disc -- the first cut of packed.lua did
# exactly that and printed 297 KB/s off a 6 fps run.
#
# 1. GATE, stealing, paced at half rate: 120 records, 120 snapshots, every one
# compared. A packed frame is a LITERAL, so unlike the codec's gate the last
# frame audits nothing and all 120 have to be checked (verify_packed.py).
# 2. RATE, stealing, FREE-RUNNING: the loop is transfer-bound, so the mean
# inter-frame IS the emulated transport's time for a record.
# 3. RATE, held, FREE-RUNNING: the same, with the bus held.
# 4. CLOCK, held, paced at the container's fps: what holding the bus does to a
# frame clock built on counting V-DISP interrupts.
#
# DLX_PK_GATE_ONLY=1 runs 1 alone. That is what tools/bench/check.sh takes: the
# green light's job is to catch a regression in the PLAYER, and runs 2-4 measure
# the apparatus rather than gate it -- three more MAME jobs for numbers that
# cannot change unless MAME does.
#
# THE APPARATUS is tools/bench/dma_run.sh's -- `x68000 -exp1 cz6bs1` and a
# zero-filled scsiexrom.bin on a private rompath -- and the volume is
# tools/bench/mkvol.sh's, which for a DLXP container is the container itself.
#
# WHAT NO RUN HERE MEASURES: `W`, and any rate a real medium would deliver.
# MAME's device models carry no transfer timing (docs/BENCHMARK.md, 42.5). What
# is measured is the SHAPE -- one channel start, 193 destinations, 120 times,
# on a clock the machine keeps itself, with every frame pixel-exact.
set -e
cd "$(dirname "$0")/../.."
DLXP=${1:-tmp/packed_singe.dlxp}
NFR=${DLX_PK_NFR:-120}
GATE_FPS=${DLX_PK_GATE_FPS:-6}
bash tools/bench/mkvol.sh "$DLXP"
python3 tools/bench/prep_packed.py "$DLXP"
# WHICH ORDER THIS CONTAINER USES, read out of the container rather than
# assumed. FINDINGS 62.5/63.4 priced palette-first and palette-last at -12.8 dB
# for one paint apiece and could not choose between them, so the format records
# it (dlxp.py flags bit 1) and BOTH have to pass this gate. The chain assertion
# below is the only place the difference is visible from outside the machine,
# and hard-coding either order there would turn "K3 ran both" into "K3 ran one
# and the other could not have failed".
PALLAST=$(sed -n 's/.*palette_last = \([01]\),.*/\1/p' tmp/packed_meta.lua)
if [ "$PALLAST" = "1" ]; then
CHAIN0='chain\[0\] = MAR \$C08000 MTC 256'
ORDER="palette LAST -- the 193rd entry"
else
CHAIN0='chain\[0\] = MAR \$E82000 MTC 512 ; chain\[1\] = MAR \$C08000 MTC 256'
ORDER="palette FIRST -- entry 0, then 192 rows"
fi
echo " container order: $ORDER"
tools/vasm/vasmm68k_mot -Fbin -o tmp/packed.bin src/player/packed.s > /dev/null
# One run. $1 names the log, the rest are environment.
run() {
local tag=$1; shift
rm -rf "tmp/snap_packed_$tag"; mkdir -p "tmp/snap_packed_$tag"
# stdbuf -oL: without it a long MAME run is unobservable until it exits, and a
# run that is merely finishing looks exactly like one that is wedged (34.1).
( cd tmp && env SDL_VIDEODRIVER=dummy "$@" stdbuf -oL timeout -k 5 900 \
mame x68000 -bios ipl10 -exp1 cz6bs1 \
-rompath "$HOME/mame/roms;./p4roms" -hard dlxpdisk.chd \
-ramsize 2M -video soft -window -sound none -nothrottle -plugins \
-autoboot_script ../tools/bench/packed.lua \
-snapshot_directory "./snap_packed_$tag" -snapview native \
-seconds_to_run "$SECS" > "packed_$tag.log" 2>&1 )
grep -aq "^\[PK\] done" "tmp/packed_$tag.log" || {
echo "FAIL: the $tag run did not finish -- no completion marker."
tail -12 "tmp/packed_$tag.log"; exit 1; }
grep -a "^\[PK\]" "tmp/packed_$tag.log" | sed 's/^\[PK\] / /'
}
fail() { echo "FAIL: $1"; exit 1; }
echo "--- 1. THE GATE: $NFR records, paced at $GATE_FPS fps, channel stealing ---"
SECS=$(( NFR / GATE_FPS + 25 ))
run gate DLX_PK_HELD=0 DLX_PK_PACE=1 DLX_PK_FPS=$GATE_FPS DLX_PK_NFR=$NFR
cp tmp/packed_snaps.csv tmp/packed_snaps_gate.csv
# THE ASSERTIONS. Printing a result and gating on it are different things.
grep -aq "^\[PK\] FLAG=\$FF" tmp/packed_gate.log || \
fail "the player did not reach the end of the scene. FLAG=\$E1 is a CRTC mode
the frame clock cannot divide, \$E2 is a transport failure -- and the
TRANSPORT FAILED line above names which."
grep -aq "array: the 68000 built 193 entries (the container wants 193)" \
tmp/packed_gate.log || \
fail "the 68000 built a chain of the wrong length. One entry short delivers a
picture with its last row missing, which looks like a decode bug and is a
layout bug; the container's geometry and the player's arithmetic are two
independent statements of one number and they have to agree."
grep -aq "$CHAIN0" tmp/packed_gate.log || \
fail "the chain does not have the shape this container asks for ($ORDER).
The crossing from the palette registers into GVRAM IS the packed frame
(FINDINGS 62) -- a palette entry and 192 row entries, one start, the CPU
halted throughout -- and an array built the other way round from the
record feeding it does not fail: it paints 192 rows of picture into the
palette registers and 512 B of palette across the top of the screen."
grep -aq "late frames (tick already past at the gate): 0$" tmp/packed_gate.log || \
fail "a frame missed its slot in the GATE run, which is paced at half rate on
purpose. That is not a rate result -- it means the transfer did not fit in
a slot twice as long as the container's, and the pixel comparison below is
then sampling frames the player was still overwriting."
grep -aq "0 frames NOT SAMPLED" tmp/packed_gate.log || \
fail "the gate run could not sample every frame: the write window reopened
before the snapshot on at least one. At half the container's rate the
transfer must fit inside the display interval with room to spare, and if
it does not the comparison below is checking frames the player was still
overwriting."
python3 tools/bench/verify_packed.py "$DLXP" --snap tmp/snap_packed_gate \
--map tmp/packed_snaps_gate.csv --min-frames "$NFR"
if [ "${DLX_PK_GATE_ONLY:-0}" = "1" ]; then exit 0; fi
echo
echo "--- 2/3. THE RATE: free-running, both channel configurations ---"
SECS=$(( NFR / 8 + 25 ))
run free_steal DLX_PK_HELD=0 DLX_PK_PACE=0 DLX_PK_NFR=$NFR
run free_held DLX_PK_HELD=1 DLX_PK_PACE=0 DLX_PK_NFR=$NFR
for t in free_steal free_held; do
grep -aq "FREE-RUNNING, so the mean IS the transport" "tmp/packed_$t.log" || \
fail "the $t run did not report a transport time, so there is no rate here
to read -- and a rate read off a PACED run is the pace."
done
echo
echo "--- 4. THE CLOCK: held, paced at the container's own rate ---"
SECS=$(( NFR / 12 + 25 ))
run held_paced DLX_PK_HELD=1 DLX_PK_PACE=1 DLX_PK_NFR=$NFR
# THE FINDING THIS RUN EXISTS FOR, asserted rather than admired. A held channel
# halts the 68000, and the frame clock is an INTERRUPT off V-DISP whose pending
# bit is ONE BIT -- so every edge that falls inside a transfer spanning two of
# them is an edge the machine can never count. If this ever comes back at zero,
# either the transfer got short enough to fit between two rasters or the held
# configuration stopped halting the CPU, and both change what the run means.
LOST=$(sed -n 's/.*-> \([0-9]*\) edges LOST.*/\1/p' tmp/packed_held_paced.log | head -1)
[ -n "$LOST" ] && [ "$LOST" -gt 0 ] || \
fail "the held run lost no V-DISP edges (${LOST:-none}). Either the bus is no
longer being held for the transfer, or the transfer now fits between two
rasters -- and the comparison with the stealing run below is then a
comparison of two configurations that do the same thing."
LOSTS=$(sed -n 's/.*-> \([0-9]*\) edges LOST.*/\1/p' tmp/packed_gate.log | head -1)
echo
echo " V-DISP edges lost: $LOST held at 12 fps, $LOSTS stealing at $GATE_FPS fps."
echo " A player keeps a clock, reads a stick and feeds ADPCM. Which of the two"
echo " configurations can do any of that is a DESIGN question, and it is the"
echo " one this run answers; neither figure is W."
exit 0
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
"""Everything tools/bench/packed.lua needs to know about a DLXP container.
python3 tools/bench/prep_packed.py <in.dlxp> -> tmp/packed_meta.lua
THERE IS NO BLOB TO PREPARE, and that is the whole difference from
`prep_stream.py`. The codec's rig has to hand the machine expanded codebooks, a
packed palette and a record index, because a DLX record cannot be found or drawn
without them; `prep_dlx.py` and `prep_stream.py` exist for that and FINDINGS
49.7.5 records what it cost to have two copies of one of those transforms. A
packed container carries no such thing: record `i` is at sector 1 + i*97 by
geometry and its bytes are already in the order GVRAM wants them (dlxp.py). So
this file emits METADATA ONLY -- six numbers the rig would otherwise have to
hard-code, every one of them read out of the container's own header.
The volume is the container itself; tools/bench/mkvol.sh copies it.
"""
import os, sys
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
"..", "encoder"))
from dlxp import DLXP, SECTOR
if len(sys.argv) != 2:
sys.exit(__doc__)
d = DLXP(sys.argv[1])
# The record's sector count, and the array chain's entry count, DERIVED here and
# asserted by the 68000 (PG_ARRN). Two independent statements of one geometry
# is the only way a container and a player can be caught disagreeing about it --
# a chain one entry short delivers a picture with its last row missing, which
# looks like a decode bug and is a layout bug.
recs = d.rec_bytes // SECTOR
rows = d.H
entries = rows + (1 if d.has_palette else 0)
out = "tmp/packed_meta.lua"
with open(out, "w") as fh:
fh.write("-- generated by tools/bench/prep_packed.py; do not edit\n")
fh.write("return {\n")
for k, v in [("W", d.W), ("H", d.H), ("fps", d.fps), ("nframes", d.nframes),
("rec_bytes", d.rec_bytes), ("rec_sectors", recs),
("pal_bytes", d.pal_bytes), ("pic_bytes", d.pic_bytes),
("lba0", d.off_frm // SECTOR),
("palette_last", int(d.palette_last)),
("has_palette", int(d.has_palette)),
("entries", entries)]:
fh.write(f" {k} = {v},\n")
fh.write("}\n")
print(f"{sys.argv[1]}: DLXP1 {d.W}x{d.H} {d.fps}fps {d.nframes} frames")
print(f" record {d.rec_bytes:,} B = {recs} sectors, palette "
f"{'LAST' if d.palette_last else 'FIRST'}, {d.pal_bytes} B")
print(f" record i is at LBA {d.off_frm // SECTOR} + i*{recs} -- ARITHMETIC. "
f"There is no index in this container and none can be needed.")
print(f" the chain the 68000 must build: {entries} entries "
f"({rows} rows{' + 1 palette' if d.has_palette else ''})")
print(f" wire {d.kbps():.1f} KB/s, FIXED by geometry -> {out}")
+114
View File
@@ -0,0 +1,114 @@
#!/usr/bin/env python3
"""Is EVERY frame the packed player put on screen pixel-exact? ROADMAP K3.
python3 tools/bench/verify_packed.py <in.dlxp> [--snap tmp/snap_packed]
[--map tmp/packed_snaps.csv]
[--min-frames N]
WHY THIS CHECKS ALL OF THEM AND tools/bench/verify_decode.py CHECKS ONE. The
codec is temporally recursive: a SKIP block is a claim that the previous frame is
still in GVRAM, so the last frame of a sequential run is only correct if every
frame before it was, and one comparison audits 120. A packed frame is a
LITERAL -- 192 rows of picture and a whole new palette, written over whatever
was there. Frame 119 being right says nothing at all about frame 60. The
simplification that deleted the ring, the codebooks and the decoder also deleted
the gate's free lunch, and this is the bill.
WHAT IS COMPARED. MAME's own screen, through MAME's own video code: the
snapshot is what the display produced out of GVRAM and the palette REGISTERS.
Nothing here re-implements the packed interleave -- that is deliberate and it is
the same rule tools/bench/gvpack/verify_dlxp.py was built on, because a
container round-trips against its own inverse whether or not its byte order is
the one the hardware wants. The reference is dlxp.render(i), which is the
palette in the record applied to the indices in the record.
THE LETTERBOX IS CHECKED TOO, and it is not padding. The picture is 192 rows of
a 256-row screen; the other 64 rows are STATIC SETUP the 68000 wrote once at
scene start (packed.s pg_static) and the channel never touches again. If they
were wrong -- or if they decayed as the per-frame palette moved under them --
the picture would still be pixel-exact and the screen would not be. Index 255
is black in every frame's palette by construction (vq.frame_palette), so this
also gates that reservation across all 120 records.
"""
import argparse, csv, os, sys
sys.path.insert(0, "tools/encoder")
import numpy as np
from PIL import Image
from dlxp import DLXP
ap = argparse.ArgumentParser()
ap.add_argument("container")
ap.add_argument("--snap", default="tmp/snap_packed")
ap.add_argument("--map", default="tmp/packed_snaps.csv")
ap.add_argument("--min-frames", type=int, default=1,
help="fail if fewer than this many frames were sampled -- a "
"run that displayed nothing must not pass as a run with "
"no mismatches in it")
a = ap.parse_args()
d = DLXP(a.container)
if not d.has_palette:
# A --no-palette container leaves the palette registers holding whatever the
# scene setup put there, and this rig's player writes none -- so there is no
# reference for what the screen should show. Say so rather than compare
# against an assumption.
sys.exit(f"{a.container} carries no palette; this gate has no reference "
f"for what the display should have produced.")
with open(a.map) as fh:
pairs = [(r["snapshot"], int(r["frame"])) for r in csv.DictReader(fh)]
if len(pairs) < a.min_frames:
print(f"FAIL 0. only {len(pairs)} frames were sampled, --min-frames is "
f"{a.min_frames}. A player whose write window never closed displays "
f"nothing, and an empty comparison is not a pass.")
sys.exit(1)
SCRH, SCRW = 256, 256
YOFF = (SCRH - d.H) // 2
fails, checked = [], 0
for name, fr in pairs:
path = f"{a.snap}/x68000/{name}.png"
if not os.path.exists(path):
fails.append(f"snapshot {name} (frame {fr}) is missing from {a.snap}")
continue
s = np.asarray(Image.open(path).convert("RGB")).astype(int)
if s.shape[:2] != (2 * SCRH, SCRW):
fails.append(f"frame {fr}: geometry {s.shape[1]}x{s.shape[0]}, "
f"expected {SCRW}x{2*SCRH}")
continue
if not all(np.array_equal(s[i], s[i + 1]) for i in range(1, s.shape[0] - 1, 2)):
fails.append(f"frame {fr}: double-scan pairing (1,2),(3,4),... broken")
continue
g = s[0::2]
pal = d.palette_rgb(fr)
exp = np.empty((SCRH, SCRW, 3), int)
exp[:] = pal[255] # the letterbox, and the reservation
exp[YOFF:YOFF + d.H] = d.render(fr)
checked += 1
if np.array_equal(g, exp):
continue
bad = (g != exp).any(2)
by, bx = np.where(bad)
inpic = ((by >= YOFF) & (by < YOFF + d.H)).sum()
fails.append(f"frame {fr} (snapshot {name}): {bad.sum()} px differ "
f"({inpic} in the picture, {bad.sum()-inpic} in the "
f"letterbox), first at y={by[0]} x={bx[0]}, maxdiff "
f"{abs(g-exp).max()}")
for f in fails[:12]:
print("FAIL " + f)
if len(fails) > 12:
print(f"FAIL ... and {len(fails)-12} more")
if fails:
print(f" {checked-len([f for f in fails])} of {len(pairs)} sampled "
f"frames compared clean")
sys.exit(1)
lo, hi = min(f for _, f in pairs), max(f for _, f in pairs)
print(f"OK {checked} frames of {a.container} pixel-exact on the emulated "
f"68000, frames {lo}..{hi} of {d.nframes}")
print(f" every one of them a LITERAL: no decoder, no codebook, no ring. "
f"Screen {SCRW}x{SCRH}, picture {d.W}x{d.H} at y={YOFF}, letterbox on "
f"the reserved index 255.")
print(f" palette {'LAST' if d.palette_last else 'FIRST'} in the record, "
f"{d.pal_bytes} B, compared as the DISPLAY renders it (GRB555+I out of "
f"the palette registers)")
+111
View File
@@ -0,0 +1,111 @@
#!/usr/bin/env python3
"""The README still for the PACKED player -- ROADMAP K3, FINDINGS 64.
python3 tools/media/make_packed_media.py [container.dlxp]
[--snap tmp/snap_packed_gate] [--map tmp/packed_snaps_gate.csv]
[--src tmp/fr_singe] [--frame N] [--out docs/img/packed-player.png]
Blu-ray source | what the emulated 68000 actually put on screen. The right-hand
panel is MAME's own snapshot, de-double-scanned and cropped to the picture -- not
a re-render, not `dlxp.render`. It is the same rule the codec's still is built on
(tools/media/make_readme_media.py) and it is the only reason the picture is worth
printing: an encoder can be checked against its own inverse, and a screen cannot.
THE FRAME IS CHOSEN, NOT PICKED. --frame defaults to the one whose PSNR against
the source is CLOSEST TO THE MEAN over the whole gated window, so the still is
representative rather than flattering. The chosen frame and its distance from the
mean are printed, so a reader can see it was not the best one.
"""
import argparse, csv, os, sys
sys.path.insert(0, "tools/encoder")
import numpy as np
from PIL import Image, ImageDraw
from dlxp import DLXP
ap = argparse.ArgumentParser()
ap.add_argument("container", nargs="?", default="tmp/packed_singe.dlxp")
ap.add_argument("--snap", default="tmp/snap_packed_gate")
ap.add_argument("--map", default="tmp/packed_snaps_gate.csv")
ap.add_argument("--src", default="tmp/fr_singe")
ap.add_argument("--frame", type=int, default=None)
ap.add_argument("--out", default="docs/img/packed-player.png")
a = ap.parse_args()
d = DLXP(a.container)
SNAP_W, SNAP_H = 256, 512
with open(a.map) as fh:
shot = {int(r["frame"]): r["snapshot"] for r in csv.DictReader(fh)}
if not shot:
sys.exit(f"{a.map} is empty -- run tools/bench/packed_run.sh first")
def screen(fr):
"""The 256x192 picture out of one MAME native snapshot."""
p = f"{a.snap}/x68000/{shot[fr]}.png"
s = np.asarray(Image.open(p).convert("RGB"))
if s.shape[:2] != (SNAP_H, SNAP_W):
sys.exit(f"{p}: expected {SNAP_W}x{SNAP_H}, got {s.shape[1]}x{s.shape[0]}")
g = s[0::2] # undo the double scan
y = (g.shape[0] - d.H) // 2 # the picture is centred
return g[y:y + d.H]
def source(fr):
p = f"{a.src}/f{fr+1:04d}.png"
if not os.path.exists(p):
sys.exit(f"missing {p} -- re-extract the frames the container was built "
f"from, or point --src at them")
return np.asarray(Image.open(p).convert("RGB"))
def psnr(x, y):
e = ((x.astype(float) - y.astype(float)) ** 2).mean()
return float("inf") if e == 0 else 10 * np.log10(255.0 ** 2 / e)
frames = sorted(shot)
scores = {f: psnr(source(f), screen(f)) for f in frames}
mean = float(np.mean(list(scores.values())))
if a.frame is None:
pick = min(scores, key=lambda f: abs(scores[f] - mean))
else:
pick = a.frame
if pick not in scores:
sys.exit(f"frame {pick} was not sampled by that run")
# THE PANEL IS GATED, not just drawn. A still of the player is a claim that the
# player drew it, and the snapshot has to still be pixel-exact against the
# container for that claim to hold -- verify_packed.py checks all of them and
# this checks the one being printed, so the picture cannot outlive the result.
ref = d.render(pick)
if not np.array_equal(screen(pick), ref):
sys.exit(f"frame {pick} is NOT pixel-exact against {a.container}. The still "
f"is not being written: it would be a picture of a failure with a "
f"caption saying otherwise.")
Z, BAR = 2, 22
def captioned(img, text):
up = np.repeat(np.repeat(img, Z, 0), Z, 1)
out = Image.new("RGB", (up.shape[1], up.shape[0] + BAR), (16, 16, 18))
out.paste(Image.fromarray(up), (0, BAR))
ImageDraw.Draw(out).text((6, 6), text, fill=(190, 190, 196))
return out
left = captioned(source(pick), "Blu-ray source, cropped 256x192")
right = captioned(screen(pick),
"emulated 68000, MAME's own snapshot, no decoder")
out = Image.new("RGB", (left.width + right.width + 8, left.height), (16, 16, 18))
out.paste(left, (0, 0))
out.paste(right, (left.width + 8, 0))
os.makedirs(os.path.dirname(a.out), exist_ok=True)
out.save(a.out)
print(f"{a.out}: frame {pick} of {d.nframes}, {scores[pick]:.2f} dB against the "
f"24-bit source")
print(f" chosen as the frame CLOSEST TO THE MEAN ({mean:.2f} dB over "
f"{len(frames)} gated frames), {abs(scores[pick]-mean):.3f} dB from it -- "
f"best in the window is {max(scores.values()):.2f}, worst "
f"{min(scores.values()):.2f}")
print(f" and it is pixel-exact against {a.container}, checked before writing")