c64-ready 0.6.2 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +94 -22
  3. package/bin/admin.mjs +196 -0
  4. package/bin/headless.mjs +26 -3
  5. package/bin/serve.mjs +3 -0
  6. package/dist/assets/CHANGELOG-CPMeNyjb.js +261 -0
  7. package/dist/assets/index-CeQto0sd.js +499 -0
  8. package/dist/c64-ready/c64-ready.gif +0 -0
  9. package/dist/fonts/Commodore Angled v1.2.ttf +0 -0
  10. package/dist/fonts/Commodore Rounded v1.2.ttf +0 -0
  11. package/dist/fonts/Commodore-64-v6.3.TTF +0 -0
  12. package/dist/fonts/READ ME!.txt +127 -0
  13. package/dist/fonts/button-commodore-64-font.gif +0 -0
  14. package/dist/games/cartridges/bubble-bobble.crt +0 -0
  15. package/dist/games/cartridges/ghosts-n-goblins.crt +0 -0
  16. package/dist/games/snapshots/LVLLVL%BAAL.c64 +0 -0
  17. package/dist/games/snapshots/VICE2-4%APOLLO18.vsf +0 -0
  18. package/dist/games/snapshots/VICE3.10%ELEVATOR.vsf +0 -0
  19. package/dist/index.html +1 -1
  20. package/dist/tools/Keyboard-Test.prg +0 -0
  21. package/package.json +6 -2
  22. package/public/games/cartridges/bubble-bobble.crt +0 -0
  23. package/public/games/cartridges/ghosts-n-goblins.crt +0 -0
  24. package/src/emulator/c64-emulator.ts +10 -2
  25. package/src/emulator/crt-info.ts +210 -0
  26. package/src/emulator/input.ts +542 -7
  27. package/src/headless/c64-key-map.mjs +254 -0
  28. package/src/headless/c64-wasm.mjs +4 -1
  29. package/src/headless/headless-cli.mjs +832 -123
  30. package/src/headless/input-server.mjs +947 -14
  31. package/src/headless/webrtc-encoder.mjs +251 -0
  32. package/src/headless/webrtc-server.mjs +1327 -0
  33. package/src/main.ts +39 -7
  34. package/src/player/c64-player.ts +131 -14
  35. package/src/player/input-handler.ts +22 -6
  36. package/src/player/load-formats.ts +58 -0
  37. package/src/player/styles/ui-controller.css +69 -2
  38. package/src/player/ui-controller.ts +167 -36
  39. package/src/types/emulator.ts +2 -1
  40. package/dist/assets/CHANGELOG-C1nvP1iO.js +0 -96
  41. package/dist/assets/index-Cioamf6E.js +0 -394
@@ -1,394 +0,0 @@
1
- (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=class e{exports=null;heap=null;wasmMemory=null;static async load(t=`/src/emulator/c64.wasm`){let n=await fetch(t);if(!n.ok)throw Error(`Failed to fetch ${t}: ${n.status}`);let r=await n.arrayBuffer(),i=new e;return await i.instantiate(r),i}static DYNAMICTOP_PTR=5583504;static DYNAMIC_BASE=10826544;static INITIAL_PAGES=256;async instantiate(t,n){let r=new WebAssembly.Memory({initial:e.INITIAL_PAGES});this.wasmMemory=r;let i={env:{...this.makeEnvImports(r),...n??{}},wasi_snapshot_preview1:this.makeWasiImports(r)};try{this.exports=(await WebAssembly.instantiate(t,i)).instance.exports,this.updateHeapViews(),new DataView(r.buffer).setUint32(e.DYNAMICTOP_PTR,e.DYNAMIC_BASE,!0),this.exports.__wasm_call_ctors()}catch(e){throw Error(`WASM instantiation failed: ${e}`,{cause:e})}}allocAndWrite(e){if(!this.exports||!this.heap)throw Error(`WASM not ready`);let t=this.exports.malloc(e.length);return this.updateHeapViews(),this.heap.heapU8.set(e,t),t}free(e){this.exports?.free(e)}updateHeapViews(){if(!this.wasmMemory)throw Error(`WASM memory not initialized`);let e=this.wasmMemory.buffer;this.heap={heapU8:new Uint8Array(e),heapF32:new Float32Array(e),heapU32:new Uint32Array(e)}}makeEnvImports(t){return{memory:t,emscripten_get_sbrk_ptr:()=>e.DYNAMICTOP_PTR,emscripten_resize_heap:e=>{let n=65536,r=2147483648-n;if(e>r)return 0;let i=t.buffer.byteLength;for(let a=1;a<=4;a*=2){let o=i*(1+.2/a);o=Math.min(o,e+100663296);let s=Math.min(r,Math.ceil(Math.max(16777216,e,o)/n)*n);try{return t.grow(s-t.buffer.byteLength+65535>>>16),this.updateHeapViews(),1}catch{}}return 0},emscripten_memcpy_big:(e,n,r)=>(new Uint8Array(t.buffer).copyWithin(e,n,n+r),e),setTempRet0:e=>{},emscripten_asm_const_iii:(e,t,n)=>0,table:new WebAssembly.Table({initial:512,maximum:512,element:`anyfunc`})}}makeWasiImports(e){return{fd_write:(t,n,r,i)=>{let a=new DataView(e.buffer),o=new Uint8Array(e.buffer),s=0;for(let e=0;e<r;e++){let r=a.getUint32(n+e*8,!0),i=a.getUint32(n+e*8+4,!0);if(t===2){let e=new TextDecoder().decode(o.subarray(r,r+i));console.error(e)}s+=i}return a.setUint32(i,s,!0),0}}}},t=384,n=272,r=44100,i=class i{wasm;config;running=!1;frameCount=0;onFrame;onAudio;constructor(e,i={}){this.wasm=e,this.config={videoWidth:t,videoHeight:n,sampleRate:r,audioChannels:1,cyclesPerFrame:50,...i}}static async load(t=`/src/emulator/c64.wasm`,n={}){let r=new i(await e.load(t),n);return r.init(),r}init(){let e=this.wasm.exports;if(!e)throw Error(`WASM exports not available`);if(e.c64_init(),this.config.sampleRate){let e=this.wasm.exports.sid_setSampleRate;typeof e==`function`&&e(this.config.sampleRate)}}start(){this.running=!0}pause(){this.running=!1}isRunning(){return this.running}getFrameCount(){return this.frameCount}reset(){this.wasm.exports?.c64_reset(),this.frameCount=0}static AUDIO_BUFFER_SIZE=4096;tick(e=0){if(!this.running)return;let r=this.wasm.exports,i=r.debugger_update(e);if(this.frameCount++,i&&this.onFrame){let e=r.c64_getPixelBuffer(),i=this.wasm.heap.heapU8.subarray(e,e+t*n*4);this.onFrame({width:t,height:n,data:i,timestamp:this.frameCount})}}loadGame(e){let t=this.wasm.exports;if(!t||!this.wasm.heap)throw Error(`WASM not ready`);let n=this.wasm.allocAndWrite(e.data);try{switch(e.type){case`prg`:t.c64_loadPRG(n,e.data.length);break;case`d64`:t.c64_insertDisk(n,e.data.length);break;case`crt`:t.c64_loadCartridge(n,e.data.length);break;case`snapshot`:t.c64_loadSnapshot(n,e.data.length);break}}finally{this.wasm.free(n)}}removeCartridge(){this.wasm.exports?.c64_removeCartridge(),this.wasm.exports?.c64_reset(),this.frameCount=0}handleInput(e){let t=this.wasm.exports;if(t){if(e.type===`key`&&e.key!==void 0)t.keyboard_keyPressed(Number(e.key));else if(e.type===`joystick`){let n=(e.joystickPort??1)-1;e.direction&&t.c64_joystick_push(n,{up:1,down:2,left:4,right:8}[e.direction]??0),e.fire1&&t.c64_joystick_push(n,16)}}}keyDown(e){this.wasm.exports?.keyboard_keyPressed(e)}keyUp(e){this.wasm.exports?.keyboard_keyReleased(e)}joystickPush(e,t){this.wasm.exports?.c64_joystick_push(e-1,t)}joystickRelease(e,t){this.wasm.exports?.c64_joystick_release(e-1,t)}mousePosition(e,t){this.wasm.exports?.c64_mouse_position(e,t)}ramRead(e){return this.wasm.exports?.c64_ramRead(e)??0}ramWrite(e,t){this.wasm.exports?.c64_ramWrite(e,t)}cpuRead(e){return this.wasm.exports?.c64_cpuRead(e)??0}cpuWrite(e,t){this.wasm.exports?.c64_cpuWrite(e,t)}getPC(){return this.wasm.exports?.c64_getPC()??0}getRegA(){return this.wasm.exports?.c64_getRegA()??0}getRegX(){return this.wasm.exports?.c64_getRegX()??0}getRegY(){return this.wasm.exports?.c64_getRegY()??0}getSP(){return this.wasm.exports?.c64_getSP()??0}getCycleCount(){return this.wasm.exports?.c64_getCycleCount()??0}getFrameBuffer(){if(!this.wasm.exports||!this.wasm.heap)throw Error(`WASM not ready`);let e=this.wasm.exports.c64_getPixelBuffer();return{width:t,height:n,data:this.wasm.heap.heapU8.slice(e,e+t*n*4),timestamp:this.frameCount}}getSnapshot(){let e=this.wasm.exports;if(!e||!this.wasm.heap)throw Error(`WASM not ready`);let t=e.c64_getSnapshotSize(),n=e.malloc(t);e.c64_getSnapshot(n);let r=this.wasm.heap.heapU8.slice(n,n+t);return e.free(n),r}debuggerPause(){this.wasm.exports?.debugger_pause()}debuggerPlay(){this.wasm.exports?.debugger_play()}debuggerStep(){this.wasm.exports?.debugger_step()}debuggerIsRunning(){return(this.wasm.exports?.debugger_isRunning()??0)!==0}setDebugSpeed(e){this.wasm.exports?.debugger_set_speed(e)}setSampleRate(e){this.wasm.exports?.sid_setSampleRate(e)}getSidBuffer(){let e=this.wasm.exports;if(!e||!this.wasm.heap)return null;let t=e.sid_getAudioBuffer();return new Float32Array(this.wasm.heap.heapF32.subarray(t>>2,(t>>2)+i.AUDIO_BUFFER_SIZE))}setSIDModel(e){this.wasm.exports?.sid_setModel(e)}setVoiceEnabled(e,t){this.wasm.exports?.sid_setVoiceEnabled(t?e:0)}setDriveEnabled(e){this.wasm.exports?.c64_setDriveEnabled(e?1:0)}getDriveEnabled(){return(this.wasm.exports?.c64_getDriveEnabled()??0)!==0}},a=44100,o=class{ctx=null;workletNode=null;gainNode=null;_muted=!1;_volume=.75;_suspended=!0;_initialised=!1;_ready=!1;_readSidBuffer=null;onStateChange;get muted(){return this._muted}get volume(){return this._volume}get suspended(){return this._suspended}get ready(){return this._ready}get sampleRate(){return this.ctx?.sampleRate??a}async init(){if(this._initialised)return!this._suspended;this._initialised=!0;try{return this.ctx=new AudioContext({sampleRate:a}),this.gainNode=this.ctx.createGain(),this.gainNode.gain.value=this._volume,this.gainNode.connect(this.ctx.destination),this.ctx.addEventListener(`statechange`,()=>{let e=this._suspended;this._suspended=this.ctx?.state===`suspended`,e!==this._suspended&&this.fireStateChange()}),this._suspended=this.ctx.state===`suspended`,await this.loadWorklet(),this._suspended&&=(this.ctx.resume().catch(()=>{}),this.ctx.state===`suspended`),this.fireStateChange(),!this._suspended}catch{return!1}}async loadWorklet(){if(!this.ctx||!this.gainNode)return;let e=`/c64-ready/audio-worklet-processor.js`.replace(/\/+/g,`/`);await this.ctx.audioWorklet.addModule(e),this.workletNode=new AudioWorkletNode(this.ctx,`c64-audio-processor`,{outputChannelCount:[1]}),this.workletNode.connect(this.gainNode),this.workletNode.port.onmessage=()=>{this.feedWorklet()},this._ready=!0}setSidBufferReader(e){this._readSidBuffer=e}feedWorklet(){if(!this.workletNode||!this._readSidBuffer||this._suspended)return;let e=this._readSidBuffer();e&&e.length>0&&this.workletNode.port.postMessage(e)}async resume(){if(this.ctx)try{await this.ctx.resume(),this._suspended=this.ctx.state===`suspended`,this.fireStateChange()}catch(e){console.error(`AudioEngine: resume failed`,e)}}setMuted(e){this._muted=e,this.gainNode&&(this.gainNode.gain.value=e?0:this._volume),this.fireStateChange()}toggleMute(){this.setMuted(!this._muted)}setVolume(e){this._volume=Math.max(0,Math.min(1,e)),this.gainNode&&!this._muted&&(this.gainNode.gain.value=this._volume),this.fireStateChange()}adjustVolume(e){this.setVolume(this._volume+e)}async destroy(){this.workletNode?.disconnect(),this.gainNode?.disconnect(),await this.ctx?.close(),this.workletNode=null,this.gainNode=null,this.ctx=null,this._initialised=!1,this._ready=!1,this._suspended=!0,this._readSidBuffer=null}fireStateChange(){this.onStateChange?.({muted:this._muted,volume:this._volume,suspended:this._suspended})}};const s={UP:1,DOWN:2,LEFT:4,RIGHT:8},c={ArrowUp:s.UP,ArrowDown:s.DOWN,ArrowLeft:s.LEFT,ArrowRight:s.RIGHT,ControlLeft:16},l=Object.keys(c);var u=class{emulator;target;keyboardJoystickPort;pressedControls=new Set;keyDownHandler=e=>{this.handleKeyDown(e)};keyUpHandler=e=>{this.handleKeyUp(e)};constructor(e,t=window,n=2){this.emulator=e,this.target=t,this.keyboardJoystickPort=n}attach(){this.target.addEventListener(`keydown`,this.keyDownHandler),this.target.addEventListener(`keyup`,this.keyUpHandler)}detach(){this.target.removeEventListener(`keydown`,this.keyDownHandler),this.target.removeEventListener(`keyup`,this.keyUpHandler),this.releaseAll()}handleKeyDown(e){let t=this.getMappedControl(e);!t||this.pressedControls.has(t)||(this.pressedControls.add(t),this.emulator.joystickPush(this.keyboardJoystickPort,c[t]),e.preventDefault())}handleKeyUp(e){let t=this.getMappedControl(e);t&&(this.pressedControls.delete(t),this.emulator.joystickRelease(this.keyboardJoystickPort,c[t]),e.preventDefault())}getMappedControl(e){return e.code in c?e.code:null}releaseAll(){for(let e of this.pressedControls)this.emulator.joystickRelease(this.keyboardJoystickPort,c[e]);this.pressedControls.clear()}setKeyboardPort(e){this.keyboardJoystickPort!==e&&(this.releaseAll(),this.keyboardJoystickPort=e)}},d=class{emulatorInput;captureKeyDown=e=>this.onCaptureKeyDown(e);captureKeyUp=e=>this.onCaptureKeyUp(e);constructor(e,t=window){this.emulatorInput=new u(e,t)}attach(){window.addEventListener(`keydown`,this.captureKeyDown,!0),window.addEventListener(`keyup`,this.captureKeyUp,!0),this.emulatorInput.attach()}detach(){window.removeEventListener(`keydown`,this.captureKeyDown,!0),window.removeEventListener(`keyup`,this.captureKeyUp,!0),this.emulatorInput.detach()}setKeyboardJoystickPort(e){this.emulatorInput.setKeyboardPort(e)}onCaptureKeyDown(e){if(new Set(l).has(e.code)){try{if(typeof document<`u`){if(`hidden`in document){if(document.hidden){e.stopImmediatePropagation();return}}else if(typeof document.hasFocus==`function`&&!document.hasFocus()){e.stopImmediatePropagation();return}}}catch{}try{if(typeof document<`u`&&(document.querySelector(`.c64-help-overlay.visible`)||document.querySelector(`.c64-menu-overlay.visible`))){e.stopImmediatePropagation(),e.preventDefault();return}}catch{}}}onCaptureKeyUp(e){if(new Set(l).has(e.code))try{if(typeof document<`u`){if(`hidden`in document){if(document.hidden){e.stopImmediatePropagation();return}}else if(typeof document.hasFocus==`function`&&!document.hasFocus()){e.stopImmediatePropagation();return}if(document.querySelector(`.c64-help-overlay.visible`)||document.querySelector(`.c64-menu-overlay.visible`)){e.stopImmediatePropagation(),e.preventDefault();return}}}catch{}}},f=class{emulator=null;inputHandler=null;audio=new o;options;constructor(e){this.options={gameType:`crt`,...e}}async start(){let{wasmUrl:e,gameUrl:t,gameType:n,renderer:r,onProgress:a}=this.options;a?.(10,`INITIALISING WASM...`),this.emulator=await i.load(e),this.inputHandler=new d(this.emulator),this.inputHandler.attach(),r.attachTo(this.emulator),await this.loadGame(t,n,a),this.emulator.start(),this.initAudio()}initAudio(){if(!this.emulator)return;let e=this.emulator;this.audio.onStateChange=e=>{window.dispatchEvent(new CustomEvent(`c64-audio-state`,{detail:e}))},this.audio.init().then(t=>{e.setSampleRate(this.audio.sampleRate),this.audio.setSidBufferReader(()=>e.getSidBuffer()),t||window.dispatchEvent(new CustomEvent(`c64-audio-suspended`))})}async loadGame(e,t=`crt`,n){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);n?.(20,`LOADING GAME...`);let r=await fetch(e);if(!r.ok)throw Error(`Failed to fetch game: ${r.status}`);let i=Number(r.headers.get(`content-length`)??0),a;if(i>0&&r.body){let e=r.body.getReader(),t=[],o=0,s=await e.read();for(;!s.done;){t.push(s.value),o+=s.value.byteLength;let r=20+Math.round(o/i*65);n?.(r,`LOADING GAME... ${Math.round(o/i*100)}%`),s=await e.read()}a=new Uint8Array(o);let c=0;for(let e of t)a.set(e,c),c+=e.byteLength}else a=new Uint8Array(await r.arrayBuffer());if(n?.(90,`INSERTING CARTRIDGE...`),t===`crt`&&!p(a)){n?.(0,`INVALID CRT`);let e=Error(`Invalid CRT file format`);throw console.error(e),e}try{this.emulator.loadGame({type:t,data:a}),n?.(100,`READY!`),window.dispatchEvent(new CustomEvent(`c64-load-success`,{detail:{url:e,type:t}}))}catch(r){throw n?.(0,`FAILED`),console.error(`Failed to insert cartridge or load game:`,r),window.dispatchEvent(new CustomEvent(`c64-load-error`,{detail:{error:String(r),url:e,type:t}})),r}}async loadFile(e,t=`crt`){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);let n=this.options.onProgress;try{n?.(20,`READING FILE ${e.name}...`);let r=await e.arrayBuffer(),i=new Uint8Array(r);if(n?.(90,`INSERTING CARTRIDGE...`),t===`crt`&&!p(i)){n?.(0,`INVALID CRT`);let e=Error(`Invalid CRT file format`);throw console.error(e),e}try{this.emulator.loadGame({type:t,data:i}),n?.(100,`READY!`),window.dispatchEvent(new CustomEvent(`c64-close-dialog`,{detail:{file:e.name,type:t}}))}catch(r){throw n?.(0,`FAILED`),console.error(`Failed to insert cartridge from file:`,r),window.dispatchEvent(new CustomEvent(`c64-load-error`,{detail:{error:String(r),file:e.name,type:t}})),r}}catch(e){throw n?.(0,`FAILED`),e}}detachCartridge(){if(this.emulator)try{this.emulator.removeCartridge(),window.dispatchEvent(new CustomEvent(`c64-detach`,{detail:{}})),window.dispatchEvent(new CustomEvent(`c64-close-menu`))}catch(e){console.error(`Failed to detach cartridge:`,e)}}hardReset(){if(this.emulator)try{this.emulator.reset(),this.emulator.start(),window.dispatchEvent(new CustomEvent(`c64-hard-reset`,{detail:{}})),window.dispatchEvent(new CustomEvent(`c64-close-menu`))}catch(e){console.error(`Failed to perform hard reset:`,e)}}setKeyboardJoystickPort(e){this.inputHandler?.setKeyboardJoystickPort(e)}};function p(e){if(!e||e.length<16)return!1;let t=String.fromCharCode(...Array.from(e.slice(0,16)));return console.log(`[c64-player]: header=`,t),t.includes(`C64 CARTRIDGE`)||t.includes(`C64 CARTRIDGE`)}var m=`/* Loader styles extracted from canvas-renderer.ts */
2
- .c64-loader {
3
- position: relative;
4
- width: 768px;
5
- margin-top: 12px;
6
- transition: opacity 0.6s ease, transform 0.6s ease;
7
- }
8
- .c64-loader.hidden {
9
- opacity: 0;
10
- transform: translateY(-6px);
11
- pointer-events: none;
12
- }
13
- .c64-loader-label {
14
- font-family: monospace;
15
- font-size: 12px;
16
- color: #7b71d5;
17
- margin-bottom: 4px;
18
- letter-spacing: 1px;
19
- }
20
- .c64-loader-track {
21
- width: 100%;
22
- height: 10px;
23
- background: #222;
24
- border: 1px solid #444;
25
- border-radius: 2px;
26
- overflow: hidden;
27
- }
28
- .c64-loader-fill {
29
- height: 100%;
30
- width: 0;
31
- background: linear-gradient(90deg, #6c6cff 0%, #a8a8ff 50%, #6c6cff 100%);
32
- background-size: 200% 100%;
33
- border-radius: 2px;
34
- transition: width 0.5s cubic-bezier(.22,.61,.36,1);
35
- animation: c64-shimmer 1.5s linear infinite;
36
- }
37
- @keyframes c64-shimmer {
38
- 0% { background-position: 200% 0; }
39
- 100% { background-position: -200% 0; }
40
- }
41
-
42
- `,h=class{canvas;ctx;animationFrameId=null;loaderEl=null;loaderLabel=null;loaderFill=null;constructor(e){let t=typeof e==`string`?document.getElementById(e):e;if(!(t instanceof HTMLCanvasElement))throw Error(`Canvas not found: ${String(e)}`);let n=t.getContext(`2d`);if(!n)throw Error(`2D canvas context not available`);this.canvas=t,this.ctx=n}ensureLoader(){if(this.loaderEl)return;if(!document.querySelector(`style[data-c64-loader]`)){let e=document.createElement(`style`);e.setAttribute(`data-c64-loader`,``),e.textContent=m,document.head.appendChild(e)}let e=document.createElement(`div`);e.className=`c64-loader`;let t=document.createElement(`div`);t.className=`c64-loader-label`,t.textContent=`LOADING...`;let n=document.createElement(`div`);n.className=`c64-loader-track`;let r=document.createElement(`div`);r.className=`c64-loader-fill`,n.appendChild(r),e.appendChild(t),e.appendChild(n),this.canvas.insertAdjacentElement(`afterend`,e),this.loaderEl=e,this.loaderLabel=t,this.loaderFill=r}setProgress(e,t){this.ensureLoader(),this.loaderFill.style.width=`${Math.min(e,100)}%`,this.loaderLabel.textContent=t}setError(e){this.ensureLoader(),this.loaderFill.style.width=`0`,this.loaderFill.style.background=`#f44`,this.loaderLabel.textContent=e}showLoader(){this.ensureLoader(),this.loaderEl&&(this.loaderEl.classList.remove(`hidden`),this.loaderFill&&(this.loaderFill.style.width=`0`,this.loaderFill.style.background=``))}hideLoader(e=600){if(!this.loaderEl)return;let t=this.loaderEl;setTimeout(()=>{t.classList.add(`hidden`),t.addEventListener(`transitionend`,()=>t.remove(),{once:!0})},e),this.loaderEl=null,this.loaderLabel=null,this.loaderFill=null}render(e){(this.canvas.width!==e.width||this.canvas.height!==e.height)&&(this.canvas.width=e.width,this.canvas.height=e.height);let t=new ImageData(new Uint8ClampedArray(e.data),e.width,e.height);this.ctx.putImageData(t,0,0)}attachTo(e){e.onFrame=e=>{this.render(e)},this.animationFrameId!==null&&cancelAnimationFrame(this.animationFrameId);let t=0,n=r=>{let i=t?r-t:0;t=r,e.tick(i),this.animationFrameId=requestAnimationFrame(n)};this.animationFrameId=requestAnimationFrame(n)}},g=`/* Styles extracted from ui-controller.ts (HELP_CSS, AUDIO_CSS, UI_CSS) */
43
-
44
- .c64-help-btn {
45
- position: fixed;
46
- top: 12px;
47
- right: 12px;
48
- width: 32px;
49
- height: 32px;
50
- border-radius: 50%;
51
- border: 2px solid #555;
52
- background: #222;
53
- color: #7b71d5;
54
- font-family: monospace;
55
- font-size: 18px;
56
- font-weight: bold;
57
- cursor: pointer;
58
- display: flex;
59
- align-items: center;
60
- justify-content: center;
61
- transition: border-color 0.2s, color 0.2s;
62
- z-index: 1000;
63
- }
64
- .c64-help-btn:hover {
65
- border-color: #7b71d5;
66
- color: #a8a8ff;
67
- }
68
-
69
- .c64-help-overlay {
70
- position: fixed;
71
- inset: 0;
72
- background: rgba(0, 0, 0, 0.7);
73
- display: flex;
74
- align-items: center;
75
- justify-content: center;
76
- z-index: 1001;
77
- opacity: 0;
78
- transition: opacity 0.25s ease;
79
- pointer-events: none;
80
- }
81
- .c64-help-overlay.visible {
82
- opacity: 1;
83
- pointer-events: auto;
84
- }
85
-
86
- .c64-help-dialog {
87
- background: #1a1a2e;
88
- border: 2px solid #555;
89
- border-radius: 6px;
90
- padding: 24px 32px;
91
- max-width: 420px;
92
- width: 90%;
93
- font-family: monospace;
94
- color: #ccc;
95
- position: relative;
96
- }
97
- .c64-help-dialog h2 {
98
- margin: 0 0 8px;
99
- font-size: 16px;
100
- color: #7b71d5;
101
- letter-spacing: 1px;
102
- }
103
-
104
- .c64-version {
105
- display: flex;
106
- justify-content: end;
107
- font-size: 12px;
108
- color: #999;
109
- margin-top: 36px;
110
- }
111
- .c64-changelog-dialog {
112
- max-width: 760px;
113
- max-height: 70vh;
114
- overflow: auto;
115
- }
116
- .c64-help-dialog p {
117
- margin: 0 0 16px;
118
- font-size: 13px;
119
- line-height: 1.5;
120
- color: #aaa;
121
- }
122
- .c64-help-dialog a {
123
- color: #a8a8ff;
124
- text-decoration: none;
125
- }
126
- .c64-help-dialog a:hover {
127
- text-decoration: underline;
128
- }
129
- .c64-help-controls {
130
- margin: 0;
131
- padding: 0;
132
- list-style: none;
133
- font-size: 13px;
134
- }
135
- .c64-help-controls li {
136
- display: flex;
137
- justify-content: space-between;
138
- padding: 4px 0;
139
- border-bottom: 1px solid #2a2a3e;
140
- }
141
- .c64-help-controls li:last-child {
142
- border-bottom: none;
143
- }
144
- .c64-help-key {
145
- background: #2a2a3e;
146
- border: 1px solid #444;
147
- border-radius: 3px;
148
- padding: 1px 8px;
149
- font-size: 12px;
150
- color: #ddd;
151
- }
152
- .c64-help-close {
153
- position: absolute;
154
- top: 10px;
155
- right: 14px;
156
- background: none;
157
- border: none;
158
- color: #666;
159
- font-size: 20px;
160
- cursor: pointer;
161
- font-family: monospace;
162
- }
163
- .c64-help-close:hover {
164
- color: #f44;
165
- }
166
-
167
- /* Audio CSS */
168
- .c64-unmute-btn {
169
- position: fixed;
170
- top: 12px;
171
- left: 56px;
172
- width: 36px;
173
- height: 36px;
174
- border-radius: 6px;
175
- border: 2px solid #555;
176
- background: #222;
177
- color: #f44;
178
- font-size: 20px;
179
- cursor: pointer;
180
- display: flex;
181
- align-items: center;
182
- justify-content: center;
183
- z-index: 1010;
184
- transition: border-color 0.2s, color 0.2s, opacity 0.3s;
185
- animation: c64-unmute-pulse 2s ease-in-out infinite;
186
- }
187
- .c64-unmute-btn:hover {
188
- border-color: #7b71d5;
189
- color: #fff;
190
- }
191
- .c64-unmute-btn.hidden {
192
- opacity: 0;
193
- pointer-events: none;
194
- }
195
- @keyframes c64-unmute-pulse {
196
- 0%, 100% { transform: scale(1); }
197
- 50% { transform: scale(1.05); }
198
- }
199
- .c64-audio-section {
200
- margin-top: 16px;
201
- padding-top: 12px;
202
- border-top: 1px solid #2a2a3e;
203
- }
204
- .c64-audio-section label {
205
- font-size: 13px;
206
- color: #aaa;
207
- }
208
- .c64-audio-row {
209
- display: flex;
210
- align-items: center;
211
- gap: 8px;
212
- margin-top: 8px;
213
- }
214
- .c64-mute-btn {
215
- background: #222;
216
- border: 1px solid #444;
217
- color: #ddd;
218
- width: 36px;
219
- height: 36px;
220
- border-radius: 4px;
221
- cursor: pointer;
222
- font-size: 18px;
223
- display: flex;
224
- align-items: center;
225
- justify-content: center;
226
- flex-shrink: 0;
227
- }
228
- .c64-mute-btn:hover { border-color: #7b71d5; }
229
- .c64-mute-btn.muted { color: #f44; }
230
- .c64-volume-slider {
231
- flex: 1;
232
- -webkit-appearance: none;
233
- appearance: none;
234
- height: 6px;
235
- background: #2a2a3e;
236
- border-radius: 3px;
237
- outline: none;
238
- }
239
- .c64-volume-slider::-webkit-slider-thumb {
240
- -webkit-appearance: none;
241
- appearance: none;
242
- width: 14px;
243
- height: 14px;
244
- border-radius: 50%;
245
- background: #7b71d5;
246
- cursor: pointer;
247
- }
248
- .c64-volume-slider::-moz-range-thumb {
249
- width: 14px;
250
- height: 14px;
251
- border-radius: 50%;
252
- background: #7b71d5;
253
- cursor: pointer;
254
- border: none;
255
- }
256
- .c64-volume-label {
257
- font-size: 12px;
258
- color: #888;
259
- min-width: 32px;
260
- text-align: right;
261
- }
262
-
263
- /* UI CSS */
264
- .c64-hamburger {
265
- position: fixed;
266
- top: 12px;
267
- left: 12px;
268
- width: 36px;
269
- height: 36px;
270
- border-radius: 6px;
271
- border: 2px solid #444;
272
- background: #111;
273
- color: #ddd;
274
- font-family: monospace;
275
- cursor: pointer;
276
- display: flex;
277
- align-items: center;
278
- justify-content: center;
279
- z-index: 1000;
280
- }
281
- .c64-menu-overlay {
282
- position: fixed;
283
- inset: 0;
284
- background: rgba(0,0,0,0.5);
285
- display: flex;
286
- align-items: flex-start;
287
- justify-content: flex-start;
288
- padding: 48px 24px;
289
- z-index: 1002;
290
- pointer-events: none;
291
- opacity: 0;
292
- transition: opacity 0.2s ease;
293
- }
294
- .c64-menu-overlay.visible { opacity: 1; pointer-events: auto; }
295
- .c64-menu-panel {
296
- background: #0f0f1a;
297
- border: 2px solid #333;
298
- border-radius: 8px;
299
- padding: 16px;
300
- min-width: 320px;
301
- color: #ddd;
302
- font-family: monospace;
303
- }
304
- .c64-menu-header { display:flex; align-items:center; justify-content:space-between; }
305
- .c64-menu-close { background:none; border:none; color:#888; font-size:20px; cursor:pointer; }
306
- .c64-dragarea {
307
- border: 2px dashed #2a2a3e;
308
- border-radius: 6px;
309
- padding: 12px;
310
- margin-top: 12px;
311
- text-align: center;
312
- color: #aaa;
313
- background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
314
- }
315
- .c64-dragarea.dragover { border-color: #7b71d5; color: #fff; }
316
- .c64-cart-preview { display:flex; gap:12px; align-items:center; margin-top:12px; }
317
- .c64-cart-icon { width:56px; height:40px; background:#222; border:1px solid #333; display:flex; align-items:center; justify-content:center; border-radius:4px; }
318
- .c64-cart-filename { font-size:13px; color:#ccc; word-break:break-all; }
319
- .c64-file-input { display:none; }
320
- .c64-menu-actions {
321
- margin-top:12px;
322
- display:flex;
323
- flex-direction: column;
324
- gap:8px;
325
- }
326
- .c64-btn { background:#222; border:1px solid #444; color:#ddd; padding:6px 10px; border-radius:4px; cursor:pointer; }
327
-
328
- `,_=`modulepreload`,v=function(e){return`/c64-ready/`+e},y={};const b=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=v(t,n),t in y)return;y[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:_,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};var x=[[`Move Up`,`↑`],[`Move Down`,`↓`],[`Move Left`,`←`],[`Move Right`,`→`],[`Fire`,`Left Ctrl`]],S=class{helpOverlay=null;settingsOverlay=null;fileInput=null;player=null;savedHtmlOverflow=null;savedBodyOverflow=null;init(e){this.player=e??null,this.injectCSS(),this.createButton(),this.createDialog(),this.createHamburger(),this.createMenu(),this.createUnmuteButton()}injectCSS(){if(document.querySelector(`style[data-c64-help]`))return;let e=document.createElement(`style`);e.setAttribute(`data-c64-help`,``),e.textContent=g,document.head.appendChild(e)}createButton(){let e=document.createElement(`button`);e.className=`c64-help-btn`,e.textContent=`?`,e.title=`Help`,e.addEventListener(`click`,()=>this.open()),document.body.appendChild(e)}createDialog(){let e=document.createElement(`div`);e.className=`c64-help-overlay`,e.addEventListener(`click`,t=>{t.target===e&&this.close()}),e.innerHTML=`
329
- <div class="c64-help-dialog">
330
- <button class="c64-help-close">&times;</button>
331
- <h2>C64 READY</h2>
332
- <p>A Commodore 64 emulator running in the browser via WebAssembly.</p>
333
- <p><a href="https://github.com/hayesmaker/c64-ready" target="_blank" rel="noopener">Source code on GitHub</a> · <a href="#" id="c64-view-changelog">View changelog</a></p>
334
- <h2>CONTROLS</h2>
335
- <ul class="c64-help-controls">${x.map(([e,t])=>`<li><span>${e}</span><span class="c64-help-key">${t}</span></li>`).join(``)}</ul>
336
- <div class="c64-version">v0.5.0 (build: a948be5)</div>
337
- </div>
338
- `,e.querySelector(`.c64-help-close`).addEventListener(`click`,()=>this.close()),document.body.appendChild(e),this.helpOverlay=e;let t=document.createElement(`div`);t.className=`c64-help-overlay`,t.style.zIndex=`1003`,t.innerHTML=`
339
- <div class="c64-help-dialog c64-changelog-dialog">
340
- <button class="c64-help-close">&times;</button>
341
- <h2>CHANGELOG</h2>
342
- <div id="c64-changelog-content">Loading...</div>
343
- </div>
344
- `,t.querySelector(`.c64-help-close`).addEventListener(`click`,()=>t.classList.remove(`visible`)),document.body.appendChild(t);let n=e.querySelector(`#c64-view-changelog`);n&&n.addEventListener(`click`,e=>{e.preventDefault(),this.loadAndShowChangelog(t)})}async loadAndShowChangelog(e){e.classList.add(`visible`);try{let t=await b(()=>import(`./CHANGELOG-C1nvP1iO.js`),[]),n=(t.default??t).split(`
345
- `).filter(e=>{let t=e.trim();return t.startsWith(`- `)?/^- (feat|fix)[:(]/.test(t):!0}).join(`
346
- `),[{marked:r},i]=await Promise.all([b(()=>import(`./marked.esm-BOXuzyNF.js`),[]),b(()=>import(`./purify.es-y41lKIN9.js`),[])]),a=i.default.sanitize(r.parse(n)),o=e.querySelector(`#c64-changelog-content`);o.innerHTML=a}catch{let t=e.querySelector(`#c64-changelog-content`);t.innerHTML=`<p>No changelog found.</p>`}}createHamburger(){let e=document.createElement(`button`);e.className=`c64-hamburger`,e.innerHTML=`&#9776;`,e.title=`Menu`,e.addEventListener(`click`,()=>this.toggleMenu()),document.body.appendChild(e)}createMenu(){let e=document.createElement(`div`);e.className=`c64-menu-overlay`,e.addEventListener(`click`,t=>{t.target===e&&this.closeMenu()});let t=document.createElement(`div`);t.className=`c64-menu-panel`,t.innerHTML=`
347
- <div class="c64-menu-header">
348
- <h2>Settings</h2>
349
- <button class="c64-menu-close">&times;</button>
350
- </div>
351
- <div class="c64-menu-body">
352
- <label style="font-size:13px;color:#aaa">Input</label>
353
- <div style="margin-top:8px; display:flex; gap:12px; align-items:center;">
354
- <label><input type="radio" name="c64-joy-port" value="1" /> Port 1</label>
355
- <label><input type="radio" name="c64-joy-port" value="2" checked /> Port 2</label>
356
- </div>
357
- <div style="height:8px"></div>
358
- <label style="font-size:13px;color:#aaa">Display</label>
359
- <div style="margin-top:8px; display:flex; gap:12px; align-items:center;">
360
- <label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
361
- <label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
362
- <label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
363
- </div>
364
- <div style="height:8px"></div>
365
- <label style="font-size:13px;color:#aaa">Load cartridge (.crt)</label>
366
- <div class="c64-dragarea" id="c64-dragarea">Drop a .crt file here or <button class="c64-btn" id="c64-browse">Browse</button></div>
367
- <input class="c64-file-input" id="c64-file-input" type="file" accept=".crt" />
368
- <div class="c64-cart-preview" id="c64-cart-preview" style="display:none">
369
- <div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
370
- <!-- simple C64 cart SVG -->
371
- <svg width="48" height="32" viewBox="0 0 48 32" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="4" width="44" height="24" rx="3" fill="#222" stroke="#555"/><rect x="6" y="8" width="36" height="12" fill="#2b2b3d"/></svg>
372
- </div>
373
- <div class="c64-cart-filename" id="c64-cart-filename"></div>
374
- </div>
375
- <div class="c64-menu-actions">
376
- <div>
377
- <button class="c64-btn" id="c64-load-btn">Load</button>
378
- <button class="c64-btn" id="c64-close-menu">Close</button>
379
- </div>
380
- <div style="margin-top:12px; display:flex; gap:8px;">
381
- <button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
382
- <button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
383
- </div>
384
- </div>
385
-
386
- </div>
387
- `,t.querySelector(`.c64-menu-close`).addEventListener(`click`,()=>this.closeMenu()),t.querySelector(`#c64-close-menu`).addEventListener(`click`,()=>this.closeMenu()),e.appendChild(t),document.body.appendChild(e),this.settingsOverlay=e,this.fileInput=t.querySelector(`#c64-file-input`);let n=t.querySelector(`#c64-dragarea`),r=t.querySelector(`#c64-browse`),i=t.querySelector(`#c64-cart-preview`),a=t.querySelector(`#c64-cart-filename`),o=e=>{i.style.display=`flex`,a.textContent=e.name;let t=new CustomEvent(`c64-load-file`,{detail:{file:e}});window.dispatchEvent(t)};n.addEventListener(`dragover`,e=>{e.preventDefault(),n.classList.add(`dragover`)}),n.addEventListener(`dragleave`,()=>{n.classList.remove(`dragover`)}),n.addEventListener(`drop`,e=>{e.preventDefault(),n.classList.remove(`dragover`);let t=e.dataTransfer?.files?.[0];t&&o(t)}),r.addEventListener(`click`,()=>this.fileInput?.click()),this.fileInput.addEventListener(`change`,()=>{let e=this.fileInput?.files?.[0];e&&o(e)}),t.querySelector(`#c64-load-btn`).addEventListener(`click`,()=>{let e=this.fileInput?.files?.[0];e?o(e):this.fileInput?.click()});let s=document.querySelector(`.c64-menu-actions`),c=s?.querySelector(`#c64-detach-btn`),l=s?.querySelector(`#c64-reset-btn`);c&&c.addEventListener(`click`,()=>{if(!this.player||!confirm(`Detach cartridge?`))return;this.player.detachCartridge();let e=document.getElementById(`status`);e&&(e.textContent=`Cartridge detached`)}),l&&l.addEventListener(`click`,()=>{if(!this.player||!confirm(`Perform hard reset? This will restart the emulator.`))return;this.player.hardReset();let e=document.getElementById(`status`);e&&(e.textContent=`Hard reset performed`)}),this.createAudioSection(t.querySelector(`.c64-menu-body`));let u=t.querySelectorAll(`input[name="c64-joy-port"]`),d=e=>{if(window.dispatchEvent(new CustomEvent(`c64-set-keyboard-joy-port`,{detail:{port:e}})),this.player&&typeof this.player.setKeyboardJoystickPort==`function`)try{this.player.setKeyboardJoystickPort(e)}catch{}};u.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&d(Number(e.value))})});let f=t.querySelectorAll(`input[name="c64-display-mode"]`),p=document.getElementById(`c64-screen`),m=e=>{p&&(p.style.width=``,p.style.height=``,p.style.objectFit=``,p.removeAttribute(`data-display-mode`),e===`standard`?(p.style.width=``,p.style.height=``,p.style.border=``,this.savedHtmlOverflow===null?document.documentElement.style.overflow=``:(document.documentElement.style.overflow=this.savedHtmlOverflow,this.savedHtmlOverflow=null),this.savedBodyOverflow===null?document.body.style.overflow=``:(document.body.style.overflow=this.savedBodyOverflow,this.savedBodyOverflow=null)):e===`full`?(p.style.height=`100vh`,p.style.width=`auto`,p.style.objectFit=`contain`,p.style.border=`none`,this.savedHtmlOverflow===null&&(this.savedHtmlOverflow=document.documentElement.style.overflow),this.savedBodyOverflow===null&&(this.savedBodyOverflow=document.body.style.overflow),document.documentElement.style.overflow=`hidden`,document.body.style.overflow=`hidden`):e===`stretch`&&(p.style.width=`100vw`,p.style.height=`100vh`,p.style.objectFit=`fill`,p.style.border=`none`,this.savedHtmlOverflow===null&&(this.savedHtmlOverflow=document.documentElement.style.overflow),this.savedBodyOverflow===null&&(this.savedBodyOverflow=document.body.style.overflow),document.documentElement.style.overflow=`hidden`,document.body.style.overflow=`hidden`),p.setAttribute(`data-display-mode`,e),window.dispatchEvent(new CustomEvent(`c64-display-mode-changed`,{detail:{mode:e}})))};f.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&m(e.value)})}),window.addEventListener(`c64-close-dialog`,()=>{this.closeMenu()}),window.addEventListener(`c64-load-error`,()=>{this.settingsOverlay?.classList.remove(`visible`)})}createUnmuteButton(){let e=document.createElement(`button`);e.className=`c64-unmute-btn hidden`,e.innerHTML=`&#128263;`,e.title=`Click to enable audio`,e.addEventListener(`click`,async()=>{this.player&&(await this.player.audio.resume(),this.player.audio.suspended||e.classList.add(`hidden`))}),document.body.appendChild(e),window.addEventListener(`c64-audio-suspended`,()=>{e.classList.remove(`hidden`)}),window.addEventListener(`c64-audio-state`,(t=>{let n=t.detail;n.suspended||e.classList.add(`hidden`),this.syncAudioControls(n)}))}createAudioSection(e){let t=document.createElement(`div`);t.className=`c64-audio-section`,t.innerHTML=`
388
- <label>Audio</label>
389
- <div class="c64-audio-row">
390
- <button class="c64-mute-btn" id="c64-mute-btn" title="Toggle mute">&#128264;</button>
391
- <input type="range" class="c64-volume-slider" id="c64-volume-slider" min="0" max="100" value="75" />
392
- <span class="c64-volume-label" id="c64-volume-label">75%</span>
393
- </div>
394
- `,e.appendChild(t);let n=t.querySelector(`#c64-mute-btn`),r=t.querySelector(`#c64-volume-slider`),i=t.querySelector(`#c64-volume-label`);n.addEventListener(`click`,()=>{this.player&&(this.player.audio.toggleMute(),this.player.audio.suspended&&this.player.audio.resume())}),r.addEventListener(`input`,()=>{if(!this.player)return;let e=Number(r.value)/100;this.player.audio.setVolume(e),i.textContent=`${r.value}%`,this.player.audio.suspended&&this.player.audio.resume()})}syncAudioControls(e){let t=document.getElementById(`c64-mute-btn`),n=document.getElementById(`c64-volume-slider`),r=document.getElementById(`c64-volume-label`);t&&(t.innerHTML=e.muted?`&#128263;`:`&#128264;`,t.classList.toggle(`muted`,e.muted)),n&&(n.value=String(Math.round(e.volume*100))),r&&(r.textContent=`${Math.round(e.volume*100)}%`)}toggleMenu(){this.settingsOverlay?.classList.toggle(`visible`)}closeMenu(){this.settingsOverlay?.classList.remove(`visible`)}open(){this.helpOverlay?.classList.add(`visible`)}close(){this.helpOverlay?.classList.remove(`visible`)}},C=document.getElementById(`status`),w=new h(`c64-screen`),T=`/c64-ready/`,E=new f({wasmUrl:`${T}c64.wasm`,gameUrl:`${T}games/cartridges/legend-of-wilf.crt`,renderer:w,onProgress:(e,t)=>w.setProgress(e,t)});new S().init(E),E.start().then(()=>{w.hideLoader()}).catch(e=>{console.error(e),w.setError(`ERROR`),C.textContent=`Error: ${e}`,C.style.color=`#f44`});var D=()=>{let e=document.hidden,t=document.querySelector(`link[rel~='icon']`),n=`${T}${e?`led-off.svg`:`led-on.svg`}`.replace(/\/+/g,`/`);t&&(t.href=n)};document.addEventListener(`visibilitychange`,D),window.addEventListener(`focus`,D),window.addEventListener(`blur`,D),D(),window.addEventListener(`c64-load-file`,async e=>{let t=e.detail?.file;if(t)try{w.showLoader?.(),await E.loadFile(t),w.hideLoader?.()}catch(e){console.error(e),w.setError?.(`LOAD ERROR`),C.textContent=`Load error: ${e}`,C.style.color=`#f44`}}),window.addEventListener(`c64-load-error`,e=>{let t=e.detail,n=t?.error??`Unknown load error`;console.error(`C64 load error event:`,t),w.setError?.(`LOAD ERROR`),C.textContent=`Load error: ${n}`,C.style.color=`#f44`});