Two sessions that were never separated in the working tree, so they land as one commit. check.sh ALL GREEN before and after both. SESSION 19 -- the ring rig gets a frame clock (FINDINGS 51). src/player/stream.s had no frame clock: it asked for record i the instant it finished i-1, outran any finite pipe, and never let the ring back up. The 49.1 sweep passing at 48 KB was therefore a wrap-correctness result and nothing else. PACE/PACEON ($18034/$18038) hold the decoder to 12 fps, so FR_HEAD-FR_TAIL finally means what it reads as: whole frames the decoder could still draw with delivery stopped dead. PACEON=0 free-runs and is what the wrap gate still uses, so every figure in 49 is unmoved. Paced, on the gate container: 64 KB holds 2 frames, 256 KB holds 7-8, 512 KB holds 14-15, all pixel-exact. Tolerance is ceiling-1, measured by cutting the pipe: 256 KB buys 500 ms of dead pipe, not 583. SLACK IS ACCUMULATED, NOT OWNED. It is built out of pipe-wire and a seek spends all of it. At 488 KB/s a 256 KB ring needs 4.83 s of play to reach its ceiling from empty; 512 KB needs 8.42 s to reach 14. A bigger ring raises the ceiling AND lengthens the climb, so a branch point does not ask "is the buffer big enough" but "has there been enough play since the last one" -- and Dragon's Lair's decision points are seconds apart. The rig now also says WHICH resource is binding: at 460 KB/s every ring from 192 KB to 512 KB is rate-bound at ceiling 4 and never fills, so larger rings are dead RAM in that scene. 20_seek_slack.py is the same model rewritten in Python from record sizes, sharing no code with the Lua producer: 35/35 ceilings inside its bracket. SESSION 20 -- the DMAC configuration was in the IPL ROM the whole time (FINDINGS 52). ROADMAP's "do this first" was to put the ADPCM stream on the bus. That needs a clocks-per-byte figure for the audio channel, and 11_cpu_budget.py was charging audio the DISK's rate -- 5 clk/B, its own help text calling it "single-address, bus held". Audio was being charged the favourable end of B3, a 242 KB/s open question. It never had to be a guess. The IPL ROM programs all four HD63450 channels itself and MAME boots the rig with it, so 21_iplrom_dmac.py reads the configuration out of the image and decodes the MC68450 fields. Eight (address, expected bytes, meaning) sites; a mismatch or an unknown revision exits non-zero. In check.sh, no emulator, milliseconds. ch3 DCR=$80, OCR=$32: dual address, 8-bit port, cycle steal WITHOUT hold, REQG=10 external request. The DMAC arbitrates once per byte with no burst to amortise the 5..8 + 2 over, so an audio byte is 16..19 clocks, not 5 -- the old debit was 3.2x..3.8x small. And on the bus it is still nothing: 651 B/frame is 1.25%..1.48% of a frame, about 4% of what the decoder leaves. P6's bus risk does not materialise. The unit worry was worth checking and nearly right: 15.6 kHz is 8 MHz/512 = 15,625 samples/s, two 4-bit samples to a byte = 7,812.5 B/s exactly, and AUDIO_KBPS=7.8 is that in decimal kB while the tool multiplied by 1024. THE DISK CHANNEL IS PROGRAMMED IDENTICALLY. ch1 (SASI) is DCR=$80 too, and so is ch0. That is 16..19 clocks per delivered byte, where 42.4 brackets W at 5..12 and 42.5 has W=8 already missing 47/120 frames. The only worked example of a disk DMA configuration on this machine sits above the entire bracket, and at that price nothing fits at any container size. It is not scsiexrom.bin so B3 stays open -- what changed is that a cheap configuration is now the thing that has to be SHOWN. W <= 12 is a requirement on the player's DMAC programming, not a range the hardware hands us, and it is now the largest open number in the project, ahead of the rate. An unforced cross-check fell out: 15_bus_occupancy.py's new W sweep puts W=8 at 105.7% of the frame, agreeing with 42.5's 47/120, from mode histograms and bus clocks respectively, two models sharing no code. Also: ADPCM outranks the disk at the arbiter (CPR 1 against 2), so an audio byte never waits and a video byte does -- relevant to 51's smooth-rate delivery model. README MEDIA. stream.lua gains DLX_SNAP_EVERY=1 (needs DLX_PACE, off by default, on no path check.sh takes) and tools/media/make_readme_media.py turns the PNGs into docs/img/. The stills and both clips are MAME's own screen pixels. Building it turned up something worth recording. 116 of 119 captured frames are pixel-exact against dlx.py; three are TORN -- frame n on top, frame n-1 below the tear line -- because MAME captured the screen while the block loop was partway down it. decode.s writes straight to the displayed page (one display path, 28.1), so a real player tears the same way, and this is the first time that consequence has been visible rather than argued. The script ASSERTS the tear and refuses to build otherwise, rather than trimming three frames and reporting "every frame I kept is exact". Second correction the capture forced: the snapshot fires before frame n is decoded, so the obvious reading is that it holds frame n-1 -- it does not, because MAME renders the screen at the end of the machine frame, by which time the 68000 has finished frame n. 11_cpu_budget.py's "validated to within 1 pt" line is also corrected: the model reads 2..10 pt HIGH and by more as the frame gets harder, which was already true before either session. src/player/decode.s is unchanged; decode.bin is still 1,296 B at the same MD5. Claude-Session: https://claude.ai/code/session_01194oWYW8DQXK1SZ2DnChW6
142 lines
5.9 KiB
Lua
142 lines
5.9 KiB
Lua
-- FINDINGS 46.6: does the PACKED layout display correctly?
|
|
--
|
|
-- The claim under test is that a 256-colour frame can be delivered at 1.0 byte
|
|
-- per pixel instead of 2.0, by writing FULL 16-bit words into GVRAM and letting
|
|
-- the two 256-colour pages show different halves of the screen:
|
|
--
|
|
-- * CRTC R20 bit 11 ("G-VRAM set to buffer") stops the write path masking the
|
|
-- CPU's high byte away, so one word write lands TWO picture bytes.
|
|
-- MAME x68k_crtc.cpp gvram_w; px68k GVRAM_Write's CRTC_Regs[0x28]&8.
|
|
-- * word value = (page1 << 8) | page0 -- page 0 is the LOW byte, page 1 the
|
|
-- HIGH byte (gvram_w writes `data & 0x00ff` for page 0 and
|
|
-- `(data & 0x00ff) << 8` for page 1).
|
|
-- * page 0 is the OPAQUE bottom layer, unscrolled: it carries screen columns
|
|
-- 0..127 from the low bytes of words 0..127.
|
|
-- * page 1 is the TRANSPARENT top layer, X-scrolled by 384 (= -128 mod 512).
|
|
-- Column c fetches page1[(c + 384) & 511]:
|
|
-- c = 128..255 -> storage 0..127 -> the high bytes of words 0..127,
|
|
-- which carry the right half.
|
|
-- c = 0..127 -> storage 384..511 -> zeroed, so transparent, so the
|
|
-- opaque page 0 shows through.
|
|
-- * so words 0..127 of each row hold the WHOLE row: 128 words = 256 bytes for
|
|
-- 256 pixels. 1.0 byte/pixel against 2.0.
|
|
--
|
|
-- Which page is on top is set by video controller R1 (0xE82500). MEASURED:
|
|
-- 0x0000 puts page 0 on top (its zeros then cover page 1 and the right half is
|
|
-- black -- this was the first failure); 0x0002 puts page 1 on top, which is
|
|
-- what this needs.
|
|
--
|
|
-- The transparency is why the blob is built with --pack-transparent: the top
|
|
-- page's index 0 is the key, so index 0 must never appear in the picture --
|
|
-- black lives at 255 instead.
|
|
--
|
|
-- PASS = the snapshot is pixel-identical to what the ordinary unpacked
|
|
-- 256-colour path produces, which tools/bench/verify_frame256.py already checks.
|
|
M=manager.machine; SP=M.devices[":maincpu"].spaces["program"]; SUB=nil
|
|
|
|
local function load_mode()
|
|
for _,p in ipairs{"../tools/bench/crtc_mode.lua","tools/bench/crtc_mode.lua","crtc_mode.lua"} do
|
|
local f=loadfile(p); if f then return f() end
|
|
end
|
|
error("crtc_mode.lua not found")
|
|
end
|
|
local MODE = load_mode()
|
|
|
|
local GVRAM, GPAL = 0xC00000, 0xE82000
|
|
local CRTC = 0xE80000
|
|
|
|
local f=io.open("frame256p.bin","rb"); local d=f:read("a"); f:close()
|
|
local function B(i) return string.byte(d,i) end
|
|
local W,H = B(5)*256+B(6), B(7)*256+B(8)
|
|
local PAL0, PIX0 = 9, 9+256*3
|
|
local YOFF = (MODE.height - H) // 2
|
|
local BLACK = 255 -- letterbox index, NOT 0
|
|
|
|
local function pal6(v) return ((v<<2)|(v>>4)) & 0xff end
|
|
local function pack(r,g,b)
|
|
local fl = {r>>3, g>>3, b>>3}
|
|
local best, bestI = nil, 1
|
|
for I=0,1 do
|
|
local e=0
|
|
for c=1,3 do
|
|
local want = ({r,g,b})[c]
|
|
local dd = pal6((fl[c]<<1)|I) - want
|
|
e = e + dd*dd
|
|
end
|
|
if best==nil or e<best then best,bestI = e,I end
|
|
end
|
|
return (fl[2]<<11)|(fl[1]<<6)|(fl[3]<<1)|bestI
|
|
end
|
|
|
|
-- screen index at (y,x) over the full 256x256, letterbox included
|
|
local function pix(y,x)
|
|
if y < YOFF or y >= YOFF+H then return BLACK end
|
|
return B(PIX0 + (y-YOFF)*W + x)
|
|
end
|
|
|
|
local function T() local t=M.time; return t.seconds+t.attoseconds/1e18 end
|
|
local st,tp="wait",nil
|
|
|
|
SUB = emu.add_machine_frame_notifier(function()
|
|
local t=T()
|
|
if st=="wait" then
|
|
if t<3.0 then return end
|
|
MODE.apply(SP)
|
|
|
|
-- R20 with bit 11 SET: unmasked full-word writes into GVRAM.
|
|
local R20 = MODE.r20 | 0x0800
|
|
SP:write_u16(CRTC + 20*2, R20)
|
|
|
|
-- Graphic scroll. 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 must agree or the
|
|
-- page tears between its low and high nibble.
|
|
-- R12/R13 = set 0 X/Y, R14/R15 = set 1 -> page 0
|
|
-- R16/R17 = set 2 X/Y, R18/R19 = set 3 -> page 1
|
|
SP:write_u16(CRTC + 12*2, 0); SP:write_u16(CRTC + 13*2, 0)
|
|
SP:write_u16(CRTC + 14*2, 0); SP:write_u16(CRTC + 15*2, 0)
|
|
SP:write_u16(CRTC + 16*2, 384); SP:write_u16(CRTC + 17*2, 0)
|
|
SP:write_u16(CRTC + 18*2, 384); SP:write_u16(CRTC + 19*2, 0)
|
|
|
|
-- Priority: page 1 ON TOP of page 0, index 0 transparent. Measured on
|
|
-- MAME (tools/bench/probe_page1.lua): 0x0000 -> page 0 on top, screen right
|
|
-- half black; 0x0002 -> page 1 on top, right half correct.
|
|
SP:write_u16(0xE82500, 0x0002)
|
|
|
|
for c=0,255 do
|
|
local o=PAL0+c*3
|
|
SP:write_u16(GPAL+c*2, pack(B(o),B(o+1),B(o+2)))
|
|
end
|
|
|
|
-- The whole 256x256 screen, packed. Words 0..127 carry columns i (page 0,
|
|
-- low byte) and i+128 (page 1, high byte).
|
|
--
|
|
-- Words 128..511 are zeroed ONCE and never touched per frame: what matters
|
|
-- there is page 1's storage at 384..511, which the +384 scroll puts under
|
|
-- screen columns 0..127 and which must read 0 so the opaque page 0 shows
|
|
-- through. This is static setup, not part of the 1.0 B/pixel payload.
|
|
for y=0,MODE.height-1 do
|
|
local base = GVRAM + y*1024
|
|
for i=128,511 do
|
|
SP:write_u16(base + i*2, 0)
|
|
end
|
|
for i=0,127 do
|
|
SP:write_u16(base + i*2, (pix(y, i+128) << 8) | pix(y, i))
|
|
end
|
|
end
|
|
|
|
-- Buffer mode BLANKS the graphics layer (measured: the screen is black
|
|
-- while bit 11 is set), so it is a write window, not a display mode.
|
|
-- Clear it now that the packed words are in and let the display read them.
|
|
SP:write_u16(CRTC + 20*2, MODE.r20)
|
|
|
|
print(string.format("[PACK] R20=%04X (bit11=%d) scrollX p0=%d p1=%d "
|
|
.."wrote %d words/row for %d px/row yoff=%d",
|
|
SP:read_u16(CRTC+20*2), (SP:read_u16(CRTC+20*2)>>11)&1,
|
|
SP:read_u16(CRTC+12*2), SP:read_u16(CRTC+16*2), 128, 256, YOFF))
|
|
st,tp="painted",t
|
|
elseif st=="painted" and t>tp+0.30 then
|
|
M.video:snapshot(); print("[PACK] snapshot"); st="done"; M:exit()
|
|
end
|
|
end)
|