Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser-payloads.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"release": "browser-payloads-8b903d25f672",
"sha256": "fb4be47c168e12f7007eac443884d7b58077fbccb7b815ed0b68a151cc3ee344"
"release": "browser-payloads-794c86516e68",
"sha256": "4e984c92353f45f0076401dfd63d4c874c4854141a936873f5ce91c5e26846cb"
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/romdev-core-gambatte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "romdev-core-gambatte",
"version": "0.13.0",
"version": "0.13.1",
"description": "gambatte libretro core (Game Boy / Game Boy Color) for romdev, bundled as WASM.",
"type": "module",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"romdev-core-fake08": "0.1.1",
"romdev-core-fceumm": "0.14.0",
"romdev-core-flycast": "0.4.1",
"romdev-core-gambatte": "0.13.0",
"romdev-core-gambatte": "0.13.1",
"romdev-core-gametank": "0.5.1",
"romdev-core-geargrafx": "0.10.1",
"romdev-core-gpgx": "0.15.1",
Expand Down
19 changes: 17 additions & 2 deletions packages/romdevtools/scripts/multiplayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ from ROM identity and emulates its timers from CPU cycles.

| Core | Schema | Snapshot additions and normalization |
| --- | --- | --- |
| gambatte | `0x47420101` | Full CPU/mapper/RTC/HuC3/timer/serial/APU/PPU/WRAM/VRAM/OAM/HRAM/cart-RAM serializer; epoch and emulated clock; frontend frame/sample counters, turbo phase/config, both blipper buffers, phase, integrator and last sample. CC resampler and interframe blending are disabled in this mode. |
| gambatte | `0x47420102` | Full CPU/mapper/RTC/HuC3/timer/serial/APU/PPU/WRAM/VRAM/OAM/HRAM/cart-RAM serializer; epoch and emulated clock; frontend frame/sample counters, turbo phase/config, both blipper buffers, phase, integrator and last sample; native blit deadline and blank-LCD phase. CC resampler and interframe blending are disabled in this mode. |
| fceumm | `0x4e450101` | Full CPU/mapper/PPU/APU/DMA/RAM/cart-RAM/controller serializer, Four Score enable flag and exact native device configuration, FIR interpolation index and full low/high quality wave histories. Existing DC filter accumulators remain included. Stereo widening is unsupported (digest refuses it). |

Gambatte's `endx` was a cached next-tile boundary reconstructed on load from `xpos`
Expand All @@ -51,6 +51,21 @@ PPU causal fields. The unused DMG-only `dmgPalette` payload previously contained
uninitialized stack bytes; deterministic save writes explicit zeros when `isCgb()` is false.
CGB palette data remains intact. No known byte is hidden from the digest.

The MP bootstrap can spend many native frames with the LCD off before world
initialization. Gambatte's ordinary loader recomputes the blit deadline and resets
the blank-LCD phase, changing the first restored native frame. Deterministic
schema `0x47420102` retains both in its 80-byte envelope (64-byte v1 envelopes
are rejected). Its loader also restores all captured sprite attributes/words,
including the dormant suffix that the ordinary loader leaves from a later frame,
and preserves the LCD-off initial current-sprite sentinel. A disabled mode-0 STAT
IRQ deadline is normalized only when the loader ignores it; active deadlines
remain part of the snapshot and digest. These changes are deterministic-only.

The LCD-off regression restores four differently aged boot checkpoints after
LCD enable, visible sprite processing and active STAT timing. Each restore compares
40 subsequent native frames' CPU/RAM/pixels/audio/digest, including the transition
out of the wait. The browser harness performs the same checks.

Blipper serialization uses fixed-width little-endian integers and excludes its
immutable coefficient table and pointers. Its signed residual phase can be
negative after rounding to the next output sample; restore validates that range.
Expand Down Expand Up @@ -109,7 +124,7 @@ ROMDEV_BUILD_CWD=packages/romdevtools build-image/build-wasm.sh build-fceumm.sh
node --test packages/romdevtools/test/multiplayer-core.test.js packages/romdevtools/test/browser-surface-imports.test.js
```

The thirteen core/compiler tests independently boot GB/GBC/NES across a wall-clock
The core/compiler tests independently boot GB/GBC/NES across a wall-clock
second without sharing state. They compare 32 replay frames' RAM, CPU registers,
pixels, audio and digest, check against Node SHA-256, require visible fixture
pixels, and cover 1/2/3/4 pads, gapped slots, release and reload, plus all three NES filter qualities and invalid bootstrap rejection. The GBC fixture
Expand Down
15 changes: 13 additions & 2 deletions packages/romdevtools/scripts/multiplayer/build-harness.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const out=path.join(dist,'m1');mkdirSync(out,{recursive:true});
for(const name of ['index.html','main.js','worker.js'])cpSync(path.join(import.meta.dirname,'harness',name),path.join(out,name));
const hostDir=path.join(repo,'packages/romdev-core-host');mkdirSync(path.join(out,'host'),{recursive:true});
for(const name of (await import('node:fs')).readdirSync(hostDir).filter(n=>n.endsWith('.js')&&!n.endsWith('.test.js')))cpSync(path.join(hostDir,name),path.join(out,'host',name));
const roms={nes:(await fourScoreRom()).outputs['pads.nes'],gb:gbFixture(false),gbc:gbFixture(true)};
const roms={nes:(await fourScoreRom()).outputs['pads.nes'],gb:gbFixture(false),gbc:gbFixture(true),'gb-offlcd':gbFixture(false,false,true),'gbc-offlcd':gbFixture(true,false,true)};
const hash=bytes=>createHash('sha256').update(bytes).digest('hex');
const artifacts={};for(const [name,bytes]of Object.entries(roms)){writeFileSync(path.join(out,name+'.rom'),bytes);artifacts[name+'.rom']=hash(bytes);}
for(const core of ['gambatte','fceumm'])for(const ext of ['js','wasm']){
Expand All @@ -22,6 +22,17 @@ for(const core of ['gambatte','fceumm'])for(const ext of ['js','wasm']){
const sourceCommit=execFileSync('git',['rev-parse','HEAD'],{cwd:repo,encoding:'utf8'}).trim();
writeFileSync(path.join(out,'manifest.json'),JSON.stringify({milestone:'M1',sourceCommit,artifacts},null,2)+'\n');
cpSync(path.join(dist,'LICENSE'),path.join(out,'LICENSE'));
cpSync(path.join(dist,'NOTICE.md'),path.join(out,'NOTICE.md'));
const versions=JSON.parse(readFileSync(path.join(repo,'packages/romdevtools/scripts/versions.json'),'utf8'));
const source='https://github.com/ssk-play/romdev/tree/'+sourceCommit;
const notices=['# Core verification program notices','',
'This program redistributes the GPL emulator cores as separate WASM modules. LICENSE contains GPL version 2; LICENSE-host contains the MIT license for the host and test fixtures.', '',
'Corresponding source and rebuild recipes for this exact harness: '+source+'.', '',
'The host and fixtures come from packages/romdev-core-host and packages/romdevtools/scripts/multiplayer plus test/fixtures/multiplayer in that source tree.', ''];
for(const core of ['gambatte','fceumm']){
const pkg=JSON.parse(readFileSync(path.join(repo,'packages',`romdev-core-${core}`,'package.json'),'utf8')),pin=versions.cores[core];
notices.push(`- ${core} (${pkg.name} ${pkg.version}, ${pkg.license}): ${pin.url.replace(/\.git$/,'')}/tree/${pin.commit}, with the patches and pinned build recipe at ${source}/packages/romdevtools/scripts/build-${core}.sh.`);
}
notices.push('', 'Rebuild from the source checkout with ROMDEV_BUILD_CWD=packages/romdevtools build-image/build-wasm.sh build-gambatte.sh (and build-fceumm.sh), then run build-harness.mjs. The published payload manifest pins the same core binaries. Manifest.json records SHA-256 for every ROM/core artifact.');
writeFileSync(path.join(out,'NOTICE.md'),notices.join('\n')+'\n');
cpSync(path.join(repo,'packages/romdevtools/LICENSE'),path.join(out,'LICENSE-host'));
console.log('M1 harness staged:',out,sourceCommit);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<style>
:root{color-scheme:dark;font:16px system-ui;background:#111827;color:#e5e7eb}body{max-width:420px;margin:0 auto;padding:20px}h1{font-size:23px}canvas{display:block;width:100%;image-rendering:pixelated;background:#000;border-radius:8px}button,select{font:inherit;color:inherit;background:#26354e;border:1px solid #52627e;border-radius:9px;padding:12px;touch-action:none}nav{display:flex;gap:8px;justify-content:center;margin:12px 0}pre{font-size:12px;overflow:auto;white-space:pre-wrap}#status{padding:12px;background:#1b2b43;border-radius:8px}small{color:#b5c1d4}a{color:#93c5fd}
</style><body>
<h1>M1 core verification</h1><p>Independent boot and rollback checks for GB, GBC and native NES Four Score.</p><p id="status">Starting automatic checks…</p><canvas width="256" height="224"></canvas>
<h1>M1 core verification</h1><p>Independent boot, LCD-off bootstrap restoration, sprites, STAT timing and rollback checks for GB, GBC and native NES Four Score.</p><p id="status">Starting automatic checks…</p><canvas width="256" height="224"></canvas>
<small id="positions">Player positions</small><nav><select id="slot" aria-label="Player"><option value="0">Player 1</option><option value="1">Player 2</option><option value="2">Player 3</option><option value="3">Player 4</option></select><button data-pad="left">←</button><button data-pad="right">→</button><button data-pad="a">A</button></nav>
<p><small>After the checks, move each NES player's colored square. Hold a button for at least 50 ms. This is a core fixture, not the multiplayer game UI.</small></p><button id="copy">Copy test report</button><pre id="report"></pre>
<p><small>Test reports stay in this browser. No login or upload is needed: the fixtures contain no account or game data. <a href="LICENSE">License</a> · <a id="source" href="https://github.com/ssk-play/romdev">Source</a></small></p><script type="module" src="main.js"></script></body></html>
39 changes: 36 additions & 3 deletions packages/romdevtools/scripts/multiplayer/harness/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,49 @@ const hash=async bytes=>hex(new Uint8Array(await crypto.subtle.digest('SHA-256',
const equal=(a,b)=>a.length===b.length&&a.every((v,i)=>v===b[i]);
const check=(value,message)=>{if(!value)throw Error(message);};
let live=null;
async function make(platform,mask=15){
async function make(platform,mask=15,fixture=platform){
const name=platform==='nes'?'fceumm':'gambatte';
const h=new LibretroHost();
await h.loadCore({factory:(await import('./'+name+'_libretro.js')).default,wasmBinary:new Uint8Array(await(await fetch('./'+name+'_libretro.wasm')).arrayBuffer()),io:false});
await h.loadMedia({platform,bytes:new Uint8Array(await(await fetch('./'+platform+'.rom')).arrayBuffer()),deterministic:{rtcEpochSeconds:0},...(platform==='nes'?{controllerTopology:{kind:'nes',playerMask:mask}}:{})});return h;
await h.loadMedia({platform,bytes:new Uint8Array(await(await fetch('./'+fixture+'.rom')).arrayBuffer()),deterministic:{rtcEpochSeconds:0},...(platform==='nes'?{controllerTopology:{kind:'nes',playerMask:mask}}:{})});return h;
}
function trace(h,input){
h.setInput(input);h.state.audioRing.length=0;h.stepFrames(1);
const audio=h.state.audioRing.flatMap(a=>Array.from(a));
return {state:hex(h.stateDigest().bytes),pixels:h.screenshotRgba().rgba.slice(),audio,regs:JSON.stringify(getCPUState(h,h.status.platform)),ram:h.readMemory('system_ram',0,h.status.platform==='nes'?2048:h.status.platform==='gbc'?32768:8192)};
}
async function verifyBootstrap(platform){
const h=await make(platform,15,platform+'-offlcd');
try{
h.stepFrames(12);check(h.readMemory('system_ram',0x20,1)[0]===0x5a,'Bootstrap wait was not reached');
for(const wait of [0,1,5,30]){
h.stepFrames(wait);check(h.readMemory('system_ram',0x21,1)[0]===0,'World started before configuration');
const snapshot=h.serializeState();
const inputs=Array.from({length:40},(_,f)=>({ports:[{right:f%3===0,a:f%7<3}]}));
const run=()=>inputs.map((input,f)=>{if(f===8)h.writeMemory('system_ram',0x21,new Uint8Array([1]));return trace(h,input);});
const expected=run();h.unserializeState(snapshot);
check(hex(h.stateDigest().bytes)===await hash(snapshot),'LCD-off bootstrap digest differs');
const actual=run();
for(let f=0;f<inputs.length;f++){
const a=actual[f],e=expected[f];
check(a.state===e.state&&equal(a.pixels,e.pixels)&&equal(a.audio,e.audio)&&a.regs===e.regs&&equal(a.ram,e.ram),'LCD-off / sprite / STAT replay differs at frame '+f);
}
h.unserializeState(snapshot);
}
const boot=h.serializeState(),inputs=Array.from({length:40},(_,f)=>({ports:[{right:f%3===0,a:f%7<3}]}));
for(const count of [1,2,3,8,30]){
h.unserializeState(boot);h.writeMemory('system_ram',0x21,new Uint8Array([1]));h.stepFrames(count);
const active=h.serializeState(),expected=inputs.map(input=>trace(h,input));
h.unserializeState(boot);h.unserializeState(active);
check(hex(h.stateDigest().bytes)===await hash(active),'Active state after LCD-off restore differs');
for(let f=0;f<inputs.length;f++){
const a=trace(h,inputs[f]),e=expected[f];
check(a.state===e.state&&equal(a.pixels,e.pixels)&&equal(a.audio,e.audio)&&a.regs===e.regs&&equal(a.ram,e.ram),'Active / dormant-sprite restore differs at frame '+f);
}
}
return 'LCD-off bootstrap and resume (4 checkpoints × 40 frames); active restore through LCD-off (5 checkpoints × 40 frames)';
}finally{h.dispose();}
}
async function verify(platform){
const a=await make(platform);await new Promise(r=>setTimeout(r,1100));const b=await make(platform);
try{
Expand All @@ -34,7 +66,8 @@ async function verify(platform){
const pads=a.readMemory('system_ram',0x300,6),want=[mask&1?1:0,mask&2?2:0,...(mask>3?[mask&4?4:0,mask&8?8:0,8,4]:[255,255,255,255])];check(equal(pads,want),'Native pads / Four Score signature differs for mask '+mask);
}
if(platform==='gbc')check(a.readMemory('system_ram',0x400,1)[0]===0xa5&&a.readMemory('system_ram',0x10f0,1)[0]===0x5a&&a.readMemory('system_ram',0x20f0,1)[0]===0x99,'Banked header/context probe differs');
return {platform,pass:true,schema:a.stateDigest().schema,snapshotBytes:snapshot.length,framesCompared:32,checks:['independent boot','digest SHA-256','restore','future digest/RAM/registers/pixels/audio',...(platform==='nes'?['1–4 native pads','gapped slots','Four Score signatures']:platform==='gbc'?['WRAM bank/context']:[])]};
const bootstrap=platform==='nes'?[]:[await verifyBootstrap(platform)];
return {platform,pass:true,schema:a.stateDigest().schema,snapshotBytes:snapshot.length,framesCompared:32,checks:[...bootstrap,'independent boot','digest SHA-256','restore','future digest/RAM/registers/pixels/audio',...(platform==='nes'?['1–4 native pads','gapped slots','Four Score signatures']:platform==='gbc'?['WRAM bank/context']:[])]};
}finally{a.dispose();b.dispose();}
}
onmessage=async({data})=>{
Expand Down
Loading
Loading