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.
- package/LICENSE +22 -0
- package/README.md +94 -22
- package/bin/admin.mjs +196 -0
- package/bin/headless.mjs +26 -3
- package/bin/serve.mjs +3 -0
- package/dist/assets/CHANGELOG-CPMeNyjb.js +261 -0
- package/dist/assets/index-CeQto0sd.js +499 -0
- package/dist/c64-ready/c64-ready.gif +0 -0
- package/dist/fonts/Commodore Angled v1.2.ttf +0 -0
- package/dist/fonts/Commodore Rounded v1.2.ttf +0 -0
- package/dist/fonts/Commodore-64-v6.3.TTF +0 -0
- package/dist/fonts/READ ME!.txt +127 -0
- package/dist/fonts/button-commodore-64-font.gif +0 -0
- package/dist/games/cartridges/bubble-bobble.crt +0 -0
- package/dist/games/cartridges/ghosts-n-goblins.crt +0 -0
- package/dist/games/snapshots/LVLLVL%BAAL.c64 +0 -0
- package/dist/games/snapshots/VICE2-4%APOLLO18.vsf +0 -0
- package/dist/games/snapshots/VICE3.10%ELEVATOR.vsf +0 -0
- package/dist/index.html +1 -1
- package/dist/tools/Keyboard-Test.prg +0 -0
- package/package.json +6 -2
- package/public/games/cartridges/bubble-bobble.crt +0 -0
- package/public/games/cartridges/ghosts-n-goblins.crt +0 -0
- package/src/emulator/c64-emulator.ts +10 -2
- package/src/emulator/crt-info.ts +210 -0
- package/src/emulator/input.ts +542 -7
- package/src/headless/c64-key-map.mjs +254 -0
- package/src/headless/c64-wasm.mjs +4 -1
- package/src/headless/headless-cli.mjs +832 -123
- package/src/headless/input-server.mjs +947 -14
- package/src/headless/webrtc-encoder.mjs +251 -0
- package/src/headless/webrtc-server.mjs +1327 -0
- package/src/main.ts +39 -7
- package/src/player/c64-player.ts +131 -14
- package/src/player/input-handler.ts +22 -6
- package/src/player/load-formats.ts +58 -0
- package/src/player/styles/ui-controller.css +69 -2
- package/src/player/ui-controller.ts +167 -36
- package/src/types/emulator.ts +2 -1
- package/dist/assets/CHANGELOG-C1nvP1iO.js +0 -96
- package/dist/assets/index-Cioamf6E.js +0 -394
|
@@ -0,0 +1,499 @@
|
|
|
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,1);break;case`d64`:t.c64_setDriveEnabled(1),t.c64_insertDisk(n,e.data.length);break;case`crt`:t.c64_loadCartridge(n,e.data.length);break;case`snapshot`:this.loadSnapshotData(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}loadSnapshotData(e,t){let n=this.wasm.exports;if(!n)throw Error(`WASM not ready`);n.c64_loadSnapshot(e,t),this.frameCount=0}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}};const a={UP:1,DOWN:2,LEFT:4,RIGHT:8},o={ArrowUp:a.UP,ArrowDown:a.DOWN,ArrowLeft:a.LEFT,ArrowRight:a.RIGHT,ControlLeft:16},s=Object.keys(o),c={ArrowUp:a.UP,ArrowDown:a.DOWN,ArrowLeft:a.LEFT,ArrowRight:a.RIGHT,KeyZ:16,ControlLeft:16},l={ARROW_LEFT:0,ONE:1,TWO:2,THREE:3,FOUR:4,FIVE:5,SIX:6,SEVEN:7,EIGHT:8,NINE:9,ZERO:10,PLUS:11,MINUS:12,POUND:13,CLEAR_HOME:14,INS_DEL:15,CTRL:16,Q:17,W:18,E:19,R:20,T:21,Y:22,U:23,I:24,O:25,P:26,AT:27,STAR:28,ARROW_UP:29,RUN_STOP:30,A:31,S:32,D:33,F:34,G:35,H:36,J:37,K:38,L:39,COLON:40,SEMICOLON:41,EQUALS:42,RETURN:43,COMMODORE:44,SHIFT_LEFT:45,Z:46,X:47,C:48,V:49,B:50,N:51,M:52,COMMA:53,PERIOD:54,SLASH:55,SHIFT_RIGHT:56,CURSOR_UP_DOWN:57,CURSOR_LEFT_RIGHT:58,SPACE:59,F1:60,F3:61,F5:62,F7:63,RESTORE:64};function u(e,t,n){let r=e.toLowerCase(),i=n===`keydown`,a=[],o=e=>a.push({key:e,action:`press`}),s=e=>a.push({key:e,action:`release`}),c=e=>a.push({key:e,action:i?`press`:`release`});switch(i&&(t?o(l.SHIFT_LEFT):r!==`arrowup`&&r!==`arrowleft`&&(s(l.SHIFT_LEFT),s(l.SHIFT_RIGHT))),r){case`a`:c(l.A);break;case`b`:c(l.B);break;case`c`:c(l.C);break;case`d`:c(l.D);break;case`e`:c(l.E);break;case`f`:c(l.F);break;case`g`:c(l.G);break;case`h`:c(l.H);break;case`i`:c(l.I);break;case`j`:c(l.J);break;case`k`:c(l.K);break;case`l`:c(l.L);break;case`m`:c(l.M);break;case`n`:c(l.N);break;case`o`:c(l.O);break;case`p`:c(l.P);break;case`q`:c(l.Q);break;case`r`:c(l.R);break;case`s`:c(l.S);break;case`t`:c(l.T);break;case`u`:c(l.U);break;case`v`:c(l.V);break;case`w`:c(l.W);break;case`x`:c(l.X);break;case`y`:c(l.Y);break;case`z`:c(l.Z);break;case`0`:c(l.ZERO);break;case`1`:c(l.ONE);break;case`2`:c(l.TWO);break;case`3`:c(l.THREE);break;case`4`:c(l.FOUR);break;case`5`:c(l.FIVE);break;case`6`:c(l.SIX);break;case`7`:c(l.SEVEN);break;case`8`:c(l.EIGHT);break;case`9`:c(l.NINE);break;case`!`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.ONE);break;case`"`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.TWO);break;case`#`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.THREE);break;case`$`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.FOUR);break;case`%`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.FIVE);break;case`&`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.SIX);break;case`'`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.SEVEN);break;case`(`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.EIGHT);break;case`)`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.NINE);break;case` `:c(l.SPACE);break;case`enter`:c(l.RETURN);break;case`backspace`:case`delete`:c(l.INS_DEL);break;case`escape`:c(l.RUN_STOP);break;case`-`:c(l.MINUS);break;case`=`:c(l.EQUALS);break;case`+`:i&&(s(l.SHIFT_LEFT),s(l.SHIFT_RIGHT)),c(l.PLUS);break;case`*`:i&&(s(l.SHIFT_LEFT),s(l.SHIFT_RIGHT)),c(l.STAR);break;case`@`:i&&(s(l.SHIFT_LEFT),s(l.SHIFT_RIGHT)),c(l.AT);break;case`^`:i&&(s(l.SHIFT_LEFT),s(l.SHIFT_RIGHT)),c(l.ARROW_UP);break;case"`":c(l.ARROW_LEFT);break;case`~`:c(l.ARROW_UP);break;case`\\`:c(l.POUND);break;case`,`:case`<`:c(l.COMMA);break;case`.`:case`>`:c(l.PERIOD);break;case`/`:case`?`:c(l.SLASH);break;case`;`:c(l.SEMICOLON);break;case`:`:i&&(s(l.SHIFT_LEFT),s(l.SHIFT_RIGHT)),c(l.COLON);break;case`[`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.COLON);break;case`]`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.SEMICOLON);break;case`shift`:c(l.SHIFT_LEFT);break;case`tab`:c(l.CTRL);break;case`control`:c(l.COMMODORE);break;case`capslock`:c(l.COMMODORE);break;case`home`:c(l.CLEAR_HOME);break;case`f1`:c(l.F1);break;case`f2`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.F1);break;case`f3`:c(l.F3);break;case`f4`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.F3);break;case`f5`:c(l.F5);break;case`f6`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.F5);break;case`f7`:c(l.F7);break;case`f8`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.F7);break;case`arrowdown`:c(l.CURSOR_UP_DOWN);break;case`arrowup`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.CURSOR_UP_DOWN);break;case`arrowright`:c(l.CURSOR_LEFT_RIGHT);break;case`arrowleft`:i?o(l.SHIFT_LEFT):s(l.SHIFT_LEFT),c(l.CURSOR_LEFT_RIGHT);break;default:break}return a}var d=class{emulator;target;keyboardJoystickPort;inputMode=`joystick`;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){if(this.inputMode===`keyboard`){let t=u(e.key,e.shiftKey,`keydown`);if(t.length>0){for(let e of t)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);e.preventDefault()}return}if(this.inputMode===`mixed`){if(e.code in c){let t=c[e.code];this.emulator.joystickPush(this.keyboardJoystickPort,t),e.preventDefault()}else{let t=u(e.key,e.shiftKey,`keydown`);if(t.length>0){for(let e of t)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);e.preventDefault()}}return}let t=this.getMappedControl(e);!t||this.pressedControls.has(t)||(this.pressedControls.add(t),this.emulator.joystickPush(this.keyboardJoystickPort,o[t]),e.preventDefault())}handleKeyUp(e){if(this.inputMode===`keyboard`){let t=u(e.key,e.shiftKey,`keyup`);if(t.length>0){for(let e of t)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);e.preventDefault()}return}if(this.inputMode===`mixed`){if(e.code in c){let t=c[e.code];this.emulator.joystickRelease(this.keyboardJoystickPort,t),e.preventDefault()}else{let t=u(e.key,e.shiftKey,`keyup`);if(t.length>0){for(let e of t)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);e.preventDefault()}}return}let t=this.getMappedControl(e);t&&(this.pressedControls.delete(t),this.emulator.joystickRelease(this.keyboardJoystickPort,o[t]),e.preventDefault())}getMappedControl(e){return e.code in o?e.code:null}releaseAll(){for(let e of this.pressedControls)this.emulator.joystickRelease(this.keyboardJoystickPort,o[e]);this.pressedControls.clear()}setKeyboardPort(e){this.keyboardJoystickPort!==e&&(this.releaseAll(),this.keyboardJoystickPort=e)}setInputMode(e){this.inputMode!==e&&(this.releaseAll(),this.inputMode=e)}getInputMode(){return this.inputMode}};const f={0:`Normal cartridge`,1:`Action Replay`,2:`KCS Power Cartridge`,3:`Final Cartridge III`,4:`Simons BASIC`,5:`Ocean type 1`,6:`Expert Cartridge`,7:`Fun Play, Power Play`,8:`Super Games`,9:`Atomic Power`,10:`Epyx Fastload`,11:`Westermann Learning`,12:`Rex Utility`,13:`Final Cartridge I`,14:`Magic Formel`,15:`C64 Game System (SYSTEM 3)`,16:`Warp Speed`,17:`Dinamic`,18:`Zaxxon / Super Zaxxon (SEGA)`,19:`Magic Desk / Domark / HES Australia`,20:`Super Snapshot V5`,21:`Comal-80`,22:`Structured BASIC`,23:`Ross`,24:`Dela EP64`,25:`Dela EP7x8`,26:`Dela EP256`,27:`Rex EP256`,28:`Mikro Assembler`,29:`Final Cartridge Plus`,30:`Action Replay 4`,31:`Stardos`,32:`EasyFlash`,33:`EasyFlash Xbank`,34:`Capture`,35:`Action Replay 3`,36:`Retro Replay`,37:`MMC64`,38:`MMC Replay`,39:`IDE64`,40:`Super Snapshot V4`,41:`IEEE-488`,42:`Game Killer`,43:`Prophet64`,44:`EXOS`,45:`Freeze Frame`,46:`Freeze Machine`,47:`Snapshot64`,48:`Super Explode V5.0`,49:`Magic Voice`,50:`Action Replay 2`,51:`MACH 5`,52:`Diashow-Maker`,53:`Pagefox`,54:`Kingsoft`,55:`Silverrock 128K Longshot`,56:`Formel 64`,57:`RGCD`,58:`RR-Net MK3`,59:`Easy Calc`,60:`GMod2`,61:`MAX Basic`,62:`GMod3`,63:`ZIPP-CODE 48`,64:`Blackbox V8`,65:`Blackbox V3`,66:`Blackbox V4`,67:`REX RAM-Floppy`,68:`BIS-Plus`,69:`SD-BOX`,70:`MultiMAX`,71:`Blackbox V9`,72:`Lt. Kernal Host Adaptor`,73:`RAMLink`,74:`H.E.R.O.`,75:`IEEE Flash! 64`,76:`Turtle Graphics II`,77:`Freeze Frame MK2`,78:`Partner 64`};function p(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function m(e,t){return(e[t]<<8|e[t+1])>>>0}function h(e,t){if(!e||e.length<64||!String.fromCharCode(...Array.from(e.slice(0,16))).startsWith(`C64 CARTRIDGE`))return null;let n=p(e,16),r=m(e,22),i=e[24],a=e[25],o=``;for(let t=32;t<64&&e[t]!==0;t++)o+=String.fromCharCode(e[t]);o=o.trim();let s;s=i===0&&a===0?`16K (ROML+ROMH)`:i===0&&a===1?`8K (ROML only)`:i===1&&a===0?`Ultimax`:`inactive (pass-through)`;let c=0,l=0,u=Math.max(n,64);for(;u+16<=e.length&&String.fromCharCode(...Array.from(e.slice(u,u+4)))===`CHIP`;){let t=p(e,u+4);if(t<16)break;let n=m(e,u+14);c++,l+=n,u+=t}let d=f[r]??`Unknown(${r})`,h=t?` "${t}"`:``,g=o?` name="${o}"`:``,_=(l/1024).toFixed(0);return{line:`[C64 cart]${h} loading: hwType=${r}(${d}) | ${s} flags, ${_}K actual | ${c} CHIP(s) | ${e.length} bytes${g}`,hwType:r,hwName:d,exrom:i,game:a,bankConfig:s,cartName:o,chipCount:c,totalRomBytes:l}}var g=44100,_=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??g}async init(){if(this._initialised)return!this._suspended;this._initialised=!0;try{return this.ctx=new AudioContext({sampleRate:g}),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})}},v=class{emulatorInput;captureKeyDown=e=>this.onCaptureKeyDown(e);captureKeyUp=e=>this.onCaptureKeyUp(e);constructor(e,t=window){this.emulatorInput=new d(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)}setInputMode(e){this.emulatorInput.setInputMode(e)}getInputMode(){return this.emulatorInput.getInputMode()}onCaptureKeyDown(e){if(new Set([...s,...Object.keys(c)]).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([...s,...Object.keys(c)]).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{}}};const y=[{type:`crt`,label:`Cartridge (.crt)`,extensions:[`.crt`]},{type:`prg`,label:`Program (.prg)`,extensions:[`.prg`]},{type:`d64`,label:`Disk image (.d64)`,extensions:[`.d64`]},{type:`snapshot`,label:`Snapshot (.snapshot, .c64, .s64)`,extensions:[`.snapshot`,`.c64`,`.s64`]}];var b=new Set(y.map(e=>e.type));function x(e){return typeof e==`string`&&b.has(e)}function S(e){let t=e.toLowerCase();for(let e of y)if(e.extensions.some(e=>t.endsWith(e)))return e.type;return null}function C(e,t,n=`crt`){return e===`auto`?S(t)??n:e}function w(e){return(e===`auto`?y.flatMap(e=>e.extensions):y.find(t=>t.type===e)?.extensions??[]).join(`,`)}function T(e){return y.find(t=>t.type===e)?.label??e.toUpperCase()}var E=class{emulator=null;inputHandler=null;audio=new _;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 v(this.emulator),this.inputHandler.attach(),r.attachTo(this.emulator),t&&t!==`null`&&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 ${O(t)}...`),t===`crt`&&!D(a)){n?.(0,`INVALID CRT`);let e=Error(`Invalid CRT file format`);throw console.error(e),e}if(t===`crt`){let t=e.split(`/`).pop()??e,n=h(a,t);n&&console.log(n.line)}this.assertSnapshotFormatSupported(a,t,e),this.emitSnapshotLoadInfo(t,e);try{this.emulator.loadGame({type:t,data:a}),t===`prg`&&await this.autoRunPrgIfRunning(),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){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);let n=this.options.onProgress,r=t??S(e.name)??`crt`;try{n?.(20,`READING FILE ${e.name}...`);let t=await e.arrayBuffer(),i=new Uint8Array(t);if(n?.(90,`INSERTING ${O(r)}...`),r===`crt`&&!D(i)){n?.(0,`INVALID CRT`);let e=Error(`Invalid CRT file format`);throw console.error(e),e}if(r===`crt`){let t=h(i,e.name);t&&console.log(t.line)}this.assertSnapshotFormatSupported(i,r,e.name),this.emitSnapshotLoadInfo(r,e.name);try{this.emulator.loadGame({type:r,data:i}),r===`prg`&&await this.autoRunPrgIfRunning(),n?.(100,`READY!`),window.dispatchEvent(new CustomEvent(`c64-close-dialog`,{detail:{file:e.name,type:r}}))}catch(t){throw n?.(0,`FAILED`),console.error(`Failed to insert cartridge from file:`,t),window.dispatchEvent(new CustomEvent(`c64-load-error`,{detail:{error:String(t),file:e.name,type:r}})),t}}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)}setInputMode(e){this.inputHandler?.setInputMode(e)}async autoRunPrgIfRunning(){!this.emulator||!this.emulator.isRunning()||(await k(120),await this.typeCommand(`run
|
|
2
|
+
`))}async typeCommand(e){if(this.emulator)for(let t of e){let e=t===`
|
|
3
|
+
`?`enter`:t,n=u(e,!1,`keydown`);for(let e of n)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);await k(22);let r=u(e,!1,`keyup`);for(let e of r)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);await k(22)}}emitSnapshotLoadInfo(e,t){if(e!==`snapshot`)return;let n=`native`,r=`Loading native LVL snapshot (${t})`;console.info(`[snapshot] mode=${n} source=${t}`),window.dispatchEvent(new CustomEvent(`c64-load-info`,{detail:{mode:n,source:t,message:r}}))}assertSnapshotFormatSupported(e,t,n){if(t!==`snapshot`||!A(e))return;let r=Error(`Unsupported snapshot format for ${n}. VICE .vsf snapshots are disabled for now; use LVLLVL/native snapshots (.c64, .snapshot, .s64).`);throw console.error(r),window.dispatchEvent(new CustomEvent(`c64-load-info`,{detail:{mode:`warning`,source:n,message:`Snapshot must be LVLLVL/native format (.c64, .snapshot, .s64).`}})),r}};function D(e){return h(e)!==null}function O(e){let t=T(e),n=t.indexOf(` (`);return(n>0?t.slice(0,n):t).toUpperCase()}function k(e){return new Promise(t=>setTimeout(t,e))}function A(e){if(e.length<19)return!1;for(let t=0;t<19;t++)if(e[t]!==`VICE Snapshot File`.charCodeAt(t))return!1;return!0}var j=`/* Loader styles extracted from canvas-renderer.ts */
|
|
4
|
+
.c64-loader {
|
|
5
|
+
position: relative;
|
|
6
|
+
width: 768px;
|
|
7
|
+
margin-top: 12px;
|
|
8
|
+
transition: opacity 0.6s ease, transform 0.6s ease;
|
|
9
|
+
}
|
|
10
|
+
.c64-loader.hidden {
|
|
11
|
+
opacity: 0;
|
|
12
|
+
transform: translateY(-6px);
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
}
|
|
15
|
+
.c64-loader-label {
|
|
16
|
+
font-family: monospace;
|
|
17
|
+
font-size: 12px;
|
|
18
|
+
color: #7b71d5;
|
|
19
|
+
margin-bottom: 4px;
|
|
20
|
+
letter-spacing: 1px;
|
|
21
|
+
}
|
|
22
|
+
.c64-loader-track {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 10px;
|
|
25
|
+
background: #222;
|
|
26
|
+
border: 1px solid #444;
|
|
27
|
+
border-radius: 2px;
|
|
28
|
+
overflow: hidden;
|
|
29
|
+
}
|
|
30
|
+
.c64-loader-fill {
|
|
31
|
+
height: 100%;
|
|
32
|
+
width: 0;
|
|
33
|
+
background: linear-gradient(90deg, #6c6cff 0%, #a8a8ff 50%, #6c6cff 100%);
|
|
34
|
+
background-size: 200% 100%;
|
|
35
|
+
border-radius: 2px;
|
|
36
|
+
transition: width 0.5s cubic-bezier(.22,.61,.36,1);
|
|
37
|
+
animation: c64-shimmer 1.5s linear infinite;
|
|
38
|
+
}
|
|
39
|
+
@keyframes c64-shimmer {
|
|
40
|
+
0% { background-position: 200% 0; }
|
|
41
|
+
100% { background-position: -200% 0; }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
`,M=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=j,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)}},N=`/* Styles extracted from ui-controller.ts (HELP_CSS, AUDIO_CSS, UI_CSS) */
|
|
45
|
+
|
|
46
|
+
.c64-help-btn {
|
|
47
|
+
position: fixed;
|
|
48
|
+
top: 12px;
|
|
49
|
+
right: 12px;
|
|
50
|
+
width: 32px;
|
|
51
|
+
height: 32px;
|
|
52
|
+
border-radius: 50%;
|
|
53
|
+
border: 2px solid #555;
|
|
54
|
+
background: #222;
|
|
55
|
+
color: #7b71d5;
|
|
56
|
+
font-family: monospace;
|
|
57
|
+
font-size: 18px;
|
|
58
|
+
font-weight: bold;
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
justify-content: center;
|
|
63
|
+
transition: border-color 0.2s, color 0.2s;
|
|
64
|
+
z-index: 1000;
|
|
65
|
+
}
|
|
66
|
+
.c64-help-btn:hover {
|
|
67
|
+
border-color: #7b71d5;
|
|
68
|
+
color: #a8a8ff;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.c64-help-overlay {
|
|
72
|
+
position: fixed;
|
|
73
|
+
inset: 0;
|
|
74
|
+
background: rgba(0, 0, 0, 0.7);
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
z-index: 1001;
|
|
79
|
+
opacity: 0;
|
|
80
|
+
transition: opacity 0.25s ease;
|
|
81
|
+
pointer-events: none;
|
|
82
|
+
}
|
|
83
|
+
.c64-help-overlay.visible {
|
|
84
|
+
opacity: 1;
|
|
85
|
+
pointer-events: auto;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.c64-help-dialog {
|
|
89
|
+
background: #1a1a2e;
|
|
90
|
+
border: 2px solid #555;
|
|
91
|
+
border-radius: 6px;
|
|
92
|
+
padding: 24px 32px;
|
|
93
|
+
max-width: 420px;
|
|
94
|
+
width: 90%;
|
|
95
|
+
font-family: monospace;
|
|
96
|
+
color: #ccc;
|
|
97
|
+
position: relative;
|
|
98
|
+
}
|
|
99
|
+
.c64-help-dialog h2 {
|
|
100
|
+
margin: 0 0 8px;
|
|
101
|
+
font-size: 16px;
|
|
102
|
+
color: #7b71d5;
|
|
103
|
+
letter-spacing: 1px;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.c64-version {
|
|
107
|
+
display: flex;
|
|
108
|
+
justify-content: end;
|
|
109
|
+
font-size: 12px;
|
|
110
|
+
color: #999;
|
|
111
|
+
margin-top: 36px;
|
|
112
|
+
}
|
|
113
|
+
.c64-changelog-dialog {
|
|
114
|
+
max-width: 760px;
|
|
115
|
+
max-height: 70vh;
|
|
116
|
+
overflow: auto;
|
|
117
|
+
}
|
|
118
|
+
.c64-help-dialog p {
|
|
119
|
+
margin: 0 0 16px;
|
|
120
|
+
font-size: 13px;
|
|
121
|
+
line-height: 1.5;
|
|
122
|
+
color: #aaa;
|
|
123
|
+
}
|
|
124
|
+
.c64-help-dialog a {
|
|
125
|
+
color: #a8a8ff;
|
|
126
|
+
text-decoration: none;
|
|
127
|
+
}
|
|
128
|
+
.c64-help-dialog a:hover {
|
|
129
|
+
text-decoration: underline;
|
|
130
|
+
}
|
|
131
|
+
.c64-help-controls {
|
|
132
|
+
margin: 0;
|
|
133
|
+
padding: 0;
|
|
134
|
+
list-style: none;
|
|
135
|
+
font-size: 13px;
|
|
136
|
+
}
|
|
137
|
+
.c64-help-controls li {
|
|
138
|
+
display: flex;
|
|
139
|
+
justify-content: space-between;
|
|
140
|
+
padding: 4px 0;
|
|
141
|
+
border-bottom: 1px solid #2a2a3e;
|
|
142
|
+
}
|
|
143
|
+
.c64-help-controls li:last-child {
|
|
144
|
+
border-bottom: none;
|
|
145
|
+
}
|
|
146
|
+
.c64-help-key {
|
|
147
|
+
background: #2a2a3e;
|
|
148
|
+
border: 1px solid #444;
|
|
149
|
+
border-radius: 3px;
|
|
150
|
+
padding: 1px 8px;
|
|
151
|
+
font-size: 12px;
|
|
152
|
+
color: #ddd;
|
|
153
|
+
}
|
|
154
|
+
.c64-help-close {
|
|
155
|
+
position: absolute;
|
|
156
|
+
top: 10px;
|
|
157
|
+
right: 14px;
|
|
158
|
+
background: none;
|
|
159
|
+
border: none;
|
|
160
|
+
color: #666;
|
|
161
|
+
font-size: 20px;
|
|
162
|
+
cursor: pointer;
|
|
163
|
+
font-family: monospace;
|
|
164
|
+
}
|
|
165
|
+
.c64-help-close:hover {
|
|
166
|
+
color: #f44;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Audio CSS */
|
|
170
|
+
.c64-unmute-btn {
|
|
171
|
+
position: fixed;
|
|
172
|
+
top: 12px;
|
|
173
|
+
left: 56px;
|
|
174
|
+
width: 36px;
|
|
175
|
+
height: 36px;
|
|
176
|
+
border-radius: 6px;
|
|
177
|
+
border: 2px solid #555;
|
|
178
|
+
background: #222;
|
|
179
|
+
color: #f44;
|
|
180
|
+
font-size: 20px;
|
|
181
|
+
cursor: pointer;
|
|
182
|
+
display: flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
justify-content: center;
|
|
185
|
+
z-index: 1010;
|
|
186
|
+
transition: border-color 0.2s, color 0.2s, opacity 0.3s;
|
|
187
|
+
animation: c64-unmute-pulse 2s ease-in-out infinite;
|
|
188
|
+
}
|
|
189
|
+
.c64-unmute-btn:hover {
|
|
190
|
+
border-color: #7b71d5;
|
|
191
|
+
color: #fff;
|
|
192
|
+
}
|
|
193
|
+
.c64-unmute-btn.hidden {
|
|
194
|
+
opacity: 0;
|
|
195
|
+
pointer-events: none;
|
|
196
|
+
}
|
|
197
|
+
@keyframes c64-unmute-pulse {
|
|
198
|
+
0%, 100% { transform: scale(1); }
|
|
199
|
+
50% { transform: scale(1.05); }
|
|
200
|
+
}
|
|
201
|
+
.c64-audio-section {
|
|
202
|
+
margin-top: 16px;
|
|
203
|
+
padding-top: 12px;
|
|
204
|
+
border-top: 1px solid #2a2a3e;
|
|
205
|
+
}
|
|
206
|
+
.c64-audio-section label {
|
|
207
|
+
font-size: 13px;
|
|
208
|
+
color: #aaa;
|
|
209
|
+
}
|
|
210
|
+
.c64-audio-row {
|
|
211
|
+
display: flex;
|
|
212
|
+
align-items: center;
|
|
213
|
+
gap: 8px;
|
|
214
|
+
margin-top: 8px;
|
|
215
|
+
}
|
|
216
|
+
.c64-mute-btn {
|
|
217
|
+
background: #222;
|
|
218
|
+
border: 1px solid #444;
|
|
219
|
+
color: #ddd;
|
|
220
|
+
width: 36px;
|
|
221
|
+
height: 36px;
|
|
222
|
+
border-radius: 4px;
|
|
223
|
+
cursor: pointer;
|
|
224
|
+
font-size: 18px;
|
|
225
|
+
display: flex;
|
|
226
|
+
align-items: center;
|
|
227
|
+
justify-content: center;
|
|
228
|
+
flex-shrink: 0;
|
|
229
|
+
}
|
|
230
|
+
.c64-mute-btn:hover { border-color: #7b71d5; }
|
|
231
|
+
.c64-mute-btn.muted { color: #f44; }
|
|
232
|
+
.c64-volume-slider {
|
|
233
|
+
flex: 1;
|
|
234
|
+
-webkit-appearance: none;
|
|
235
|
+
appearance: none;
|
|
236
|
+
height: 6px;
|
|
237
|
+
background: #2a2a3e;
|
|
238
|
+
border-radius: 3px;
|
|
239
|
+
outline: none;
|
|
240
|
+
}
|
|
241
|
+
.c64-volume-slider::-webkit-slider-thumb {
|
|
242
|
+
-webkit-appearance: none;
|
|
243
|
+
appearance: none;
|
|
244
|
+
width: 14px;
|
|
245
|
+
height: 14px;
|
|
246
|
+
border-radius: 50%;
|
|
247
|
+
background: #7b71d5;
|
|
248
|
+
cursor: pointer;
|
|
249
|
+
}
|
|
250
|
+
.c64-volume-slider::-moz-range-thumb {
|
|
251
|
+
width: 14px;
|
|
252
|
+
height: 14px;
|
|
253
|
+
border-radius: 50%;
|
|
254
|
+
background: #7b71d5;
|
|
255
|
+
cursor: pointer;
|
|
256
|
+
border: none;
|
|
257
|
+
}
|
|
258
|
+
.c64-volume-label {
|
|
259
|
+
font-size: 12px;
|
|
260
|
+
color: #888;
|
|
261
|
+
min-width: 32px;
|
|
262
|
+
text-align: right;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* UI CSS */
|
|
266
|
+
.c64-hamburger {
|
|
267
|
+
position: fixed;
|
|
268
|
+
top: 12px;
|
|
269
|
+
left: 12px;
|
|
270
|
+
width: 36px;
|
|
271
|
+
height: 36px;
|
|
272
|
+
border-radius: 6px;
|
|
273
|
+
border: 2px solid #444;
|
|
274
|
+
background: #111;
|
|
275
|
+
color: #ddd;
|
|
276
|
+
font-family: monospace;
|
|
277
|
+
cursor: pointer;
|
|
278
|
+
display: flex;
|
|
279
|
+
align-items: center;
|
|
280
|
+
justify-content: center;
|
|
281
|
+
z-index: 1000;
|
|
282
|
+
}
|
|
283
|
+
.c64-menu-overlay {
|
|
284
|
+
position: fixed;
|
|
285
|
+
inset: 0;
|
|
286
|
+
background: rgba(0,0,0,0.5);
|
|
287
|
+
display: flex;
|
|
288
|
+
align-items: flex-start;
|
|
289
|
+
justify-content: flex-start;
|
|
290
|
+
padding: 48px 24px;
|
|
291
|
+
z-index: 1002;
|
|
292
|
+
pointer-events: none;
|
|
293
|
+
opacity: 0;
|
|
294
|
+
transition: opacity 0.2s ease;
|
|
295
|
+
}
|
|
296
|
+
.c64-menu-overlay.visible { opacity: 1; pointer-events: auto; }
|
|
297
|
+
.c64-menu-panel {
|
|
298
|
+
background: #0f0f1a;
|
|
299
|
+
border: 2px solid #333;
|
|
300
|
+
border-radius: 8px;
|
|
301
|
+
padding: 16px;
|
|
302
|
+
min-width: 320px;
|
|
303
|
+
color: #ddd;
|
|
304
|
+
font-family: monospace;
|
|
305
|
+
}
|
|
306
|
+
.c64-menu-header { display:flex; align-items:center; justify-content:space-between; }
|
|
307
|
+
.c64-menu-close { background:none; border:none; color:#888; font-size:20px; cursor:pointer; }
|
|
308
|
+
.c64-settings-tabs {
|
|
309
|
+
display: flex;
|
|
310
|
+
gap: 8px;
|
|
311
|
+
flex-wrap: wrap;
|
|
312
|
+
margin-bottom: 12px;
|
|
313
|
+
}
|
|
314
|
+
.c64-settings-tab {
|
|
315
|
+
background: #171729;
|
|
316
|
+
border: 1px solid #353552;
|
|
317
|
+
color: #c5c5df;
|
|
318
|
+
padding: 6px 10px;
|
|
319
|
+
border-radius: 4px;
|
|
320
|
+
cursor: pointer;
|
|
321
|
+
font-size: 12px;
|
|
322
|
+
}
|
|
323
|
+
.c64-settings-tab.active {
|
|
324
|
+
border-color: #7b71d5;
|
|
325
|
+
color: #fff;
|
|
326
|
+
background: #25253d;
|
|
327
|
+
}
|
|
328
|
+
.c64-settings-section {
|
|
329
|
+
padding-top: 2px;
|
|
330
|
+
}
|
|
331
|
+
.c64-section-label {
|
|
332
|
+
display: block;
|
|
333
|
+
margin: 0 0 8px;
|
|
334
|
+
font-size: 13px;
|
|
335
|
+
color: #aaa;
|
|
336
|
+
}
|
|
337
|
+
.c64-form-row {
|
|
338
|
+
display: flex;
|
|
339
|
+
align-items: center;
|
|
340
|
+
gap: 10px;
|
|
341
|
+
margin-bottom: 10px;
|
|
342
|
+
}
|
|
343
|
+
.c64-select {
|
|
344
|
+
background: #171729;
|
|
345
|
+
color: #ddd;
|
|
346
|
+
border: 1px solid #444;
|
|
347
|
+
border-radius: 4px;
|
|
348
|
+
padding: 4px 8px;
|
|
349
|
+
font-family: monospace;
|
|
350
|
+
}
|
|
351
|
+
.c64-radio-row {
|
|
352
|
+
margin-top: 8px;
|
|
353
|
+
display: flex;
|
|
354
|
+
gap: 12px;
|
|
355
|
+
align-items: center;
|
|
356
|
+
}
|
|
357
|
+
.c64-radio-row-wrap {
|
|
358
|
+
flex-wrap: wrap;
|
|
359
|
+
}
|
|
360
|
+
.c64-section-hint {
|
|
361
|
+
margin-top: 6px;
|
|
362
|
+
font-size: 11px;
|
|
363
|
+
color: #888;
|
|
364
|
+
line-height: 1.4;
|
|
365
|
+
}
|
|
366
|
+
.c64-dragarea {
|
|
367
|
+
border: 2px dashed #2a2a3e;
|
|
368
|
+
border-radius: 6px;
|
|
369
|
+
padding: 12px;
|
|
370
|
+
margin-top: 12px;
|
|
371
|
+
text-align: center;
|
|
372
|
+
color: #aaa;
|
|
373
|
+
background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
|
|
374
|
+
}
|
|
375
|
+
.c64-dragarea button {
|
|
376
|
+
margin-left: 6px;
|
|
377
|
+
}
|
|
378
|
+
.c64-dragarea.dragover { border-color: #7b71d5; color: #fff; }
|
|
379
|
+
.c64-cart-preview { display:flex; gap:12px; align-items:center; margin-top:12px; }
|
|
380
|
+
.c64-cart-icon { width:56px; height:40px; background:#222; border:1px solid #333; display:flex; align-items:center; justify-content:center; border-radius:4px; }
|
|
381
|
+
.c64-cart-filename { font-size:13px; color:#ccc; word-break:break-all; }
|
|
382
|
+
.c64-cart-type { font-size: 11px; color: #888; margin-top: 2px; }
|
|
383
|
+
.c64-file-input { display:none; }
|
|
384
|
+
.c64-menu-actions {
|
|
385
|
+
margin-top:12px;
|
|
386
|
+
display:flex;
|
|
387
|
+
flex-wrap: wrap;
|
|
388
|
+
gap:8px;
|
|
389
|
+
}
|
|
390
|
+
.c64-system-actions {
|
|
391
|
+
margin-top: 4px;
|
|
392
|
+
display: flex;
|
|
393
|
+
gap: 8px;
|
|
394
|
+
flex-wrap: wrap;
|
|
395
|
+
}
|
|
396
|
+
.c64-btn { background:#222; border:1px solid #444; color:#ddd; padding:6px 10px; border-radius:4px; cursor:pointer; }
|
|
397
|
+
`,P=`modulepreload`,F=function(e){return`/c64-ready/`+e},I={};const L=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=F(t,n),t in I)return;I[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`:P,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 R=[[`Move Up`,`↑`],[`Move Down`,`↓`],[`Move Left`,`←`],[`Move Right`,`→`],[`Fire`,`Left Ctrl`]],z=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=N,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=`
|
|
398
|
+
<div class="c64-help-dialog">
|
|
399
|
+
<button class="c64-help-close">×</button>
|
|
400
|
+
<h2>C64 READY</h2>
|
|
401
|
+
<p>A Commodore 64 emulator running in the browser via WebAssembly.</p>
|
|
402
|
+
<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>
|
|
403
|
+
<h2>CONTROLS</h2>
|
|
404
|
+
<ul class="c64-help-controls">${R.map(([e,t])=>`<li><span>${e}</span><span class="c64-help-key">${t}</span></li>`).join(``)}</ul>
|
|
405
|
+
<div class="c64-version">v0.10.0 (build: 8fdb739)</div>
|
|
406
|
+
</div>
|
|
407
|
+
`,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=`
|
|
408
|
+
<div class="c64-help-dialog c64-changelog-dialog">
|
|
409
|
+
<button class="c64-help-close">×</button>
|
|
410
|
+
<h2>CHANGELOG</h2>
|
|
411
|
+
<div id="c64-changelog-content">Loading...</div>
|
|
412
|
+
</div>
|
|
413
|
+
`,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 L(()=>import(`./CHANGELOG-CPMeNyjb.js`),[]),n=(t.default??t).split(`
|
|
414
|
+
`).filter(e=>{let t=e.trim();return t.startsWith(`- `)?/^- (feat|fix)[:(]/.test(t):!0}).join(`
|
|
415
|
+
`),[{marked:r},i]=await Promise.all([L(()=>import(`./marked.esm-BOXuzyNF.js`),[]),L(()=>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=`☰`,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=[{id:`load`,label:`Load`},{id:`input`,label:`Input`},{id:`display`,label:`Display`},{id:`audio`,label:`Audio`},{id:`system`,label:`System`}],n=y.map(e=>`<option value="${e.type}">${e.label}</option>`).join(``),r=document.createElement(`div`);r.className=`c64-menu-panel`,r.innerHTML=`
|
|
416
|
+
<div class="c64-menu-header">
|
|
417
|
+
<h2>Settings</h2>
|
|
418
|
+
<button class="c64-menu-close">×</button>
|
|
419
|
+
</div>
|
|
420
|
+
<div class="c64-menu-body">
|
|
421
|
+
<div class="c64-settings-tabs" role="tablist" aria-label="Settings sections">
|
|
422
|
+
${t.map((e,t)=>`<button class="c64-settings-tab${t===0?` active`:``}" data-settings-tab="${e.id}" role="tab" aria-selected="${t===0?`true`:`false`}">${e.label}</button>`).join(``)}
|
|
423
|
+
</div>
|
|
424
|
+
|
|
425
|
+
<div class="c64-settings-sections">
|
|
426
|
+
<section class="c64-settings-section" data-settings-section="load">
|
|
427
|
+
<label class="c64-section-label">Load Game</label>
|
|
428
|
+
<div class="c64-form-row">
|
|
429
|
+
<label for="c64-load-format">Format</label>
|
|
430
|
+
<select id="c64-load-format" class="c64-select">
|
|
431
|
+
<option value="auto">Auto detect (recommended)</option>
|
|
432
|
+
${n}
|
|
433
|
+
</select>
|
|
434
|
+
</div>
|
|
435
|
+
<div class="c64-dragarea" id="c64-dragarea">
|
|
436
|
+
<span id="c64-dragarea-copy">Drop a game file here or</span>
|
|
437
|
+
<button class="c64-btn" id="c64-browse">Browse</button>
|
|
438
|
+
</div>
|
|
439
|
+
<input class="c64-file-input" id="c64-file-input" type="file" />
|
|
440
|
+
<div class="c64-cart-preview" id="c64-cart-preview" hidden>
|
|
441
|
+
<div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
|
|
442
|
+
<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>
|
|
443
|
+
</div>
|
|
444
|
+
<div>
|
|
445
|
+
<div class="c64-cart-filename" id="c64-cart-filename"></div>
|
|
446
|
+
<div class="c64-cart-type" id="c64-cart-type"></div>
|
|
447
|
+
</div>
|
|
448
|
+
</div>
|
|
449
|
+
<div class="c64-menu-actions">
|
|
450
|
+
<button class="c64-btn" id="c64-load-btn">Load</button>
|
|
451
|
+
<button class="c64-btn" id="c64-close-menu">Close</button>
|
|
452
|
+
</div>
|
|
453
|
+
</section>
|
|
454
|
+
|
|
455
|
+
<section class="c64-settings-section" data-settings-section="input" hidden>
|
|
456
|
+
<label class="c64-section-label">Input Port</label>
|
|
457
|
+
<div class="c64-radio-row">
|
|
458
|
+
<label><input type="radio" name="c64-joy-port" value="1" /> Port 1</label>
|
|
459
|
+
<label><input type="radio" name="c64-joy-port" value="2" checked /> Port 2</label>
|
|
460
|
+
</div>
|
|
461
|
+
<label class="c64-section-label">Input Mode</label>
|
|
462
|
+
<div class="c64-radio-row c64-radio-row-wrap">
|
|
463
|
+
<label><input type="radio" name="c64-input-mode" value="joystick" checked /> Joystick</label>
|
|
464
|
+
<label><input type="radio" name="c64-input-mode" value="keyboard" /> Keyboard</label>
|
|
465
|
+
<label><input type="radio" name="c64-input-mode" value="mixed" /> Mixed</label>
|
|
466
|
+
</div>
|
|
467
|
+
<div id="c64-input-mode-hint" class="c64-section-hint">Arrows + Ctrl = joystick</div>
|
|
468
|
+
</section>
|
|
469
|
+
|
|
470
|
+
<section class="c64-settings-section" data-settings-section="display" hidden>
|
|
471
|
+
<label class="c64-section-label">Display Mode</label>
|
|
472
|
+
<div class="c64-radio-row">
|
|
473
|
+
<label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
|
|
474
|
+
<label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
|
|
475
|
+
<label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
|
|
476
|
+
</div>
|
|
477
|
+
</section>
|
|
478
|
+
|
|
479
|
+
<section class="c64-settings-section" data-settings-section="audio" hidden>
|
|
480
|
+
<div id="c64-audio-section-anchor"></div>
|
|
481
|
+
</section>
|
|
482
|
+
|
|
483
|
+
<section class="c64-settings-section" data-settings-section="system" hidden>
|
|
484
|
+
<label class="c64-section-label">System Actions</label>
|
|
485
|
+
<div class="c64-system-actions">
|
|
486
|
+
<button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
|
|
487
|
+
<button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
|
|
488
|
+
</div>
|
|
489
|
+
</section>
|
|
490
|
+
</div>
|
|
491
|
+
</div>
|
|
492
|
+
`,r.querySelector(`.c64-menu-close`).addEventListener(`click`,()=>this.closeMenu()),r.querySelector(`#c64-close-menu`).addEventListener(`click`,()=>this.closeMenu()),e.appendChild(r),document.body.appendChild(e),this.settingsOverlay=e;let i=r.querySelectorAll(`[data-settings-tab]`),a=r.querySelectorAll(`[data-settings-section]`),o=e=>{i.forEach(t=>{let n=t.dataset.settingsTab===e;t.classList.toggle(`active`,n),t.setAttribute(`aria-selected`,n?`true`:`false`)}),a.forEach(t=>{t.hidden=t.dataset.settingsSection!==e})};i.forEach(e=>{e.addEventListener(`click`,()=>{let t=e.dataset.settingsTab;t&&o(t)})}),this.fileInput=r.querySelector(`#c64-file-input`);let s=r.querySelector(`#c64-dragarea`),c=r.querySelector(`#c64-dragarea-copy`),l=r.querySelector(`#c64-browse`),u=r.querySelector(`#c64-load-format`),d=r.querySelector(`#c64-cart-preview`),f=r.querySelector(`#c64-cart-filename`),p=r.querySelector(`#c64-cart-type`),m=()=>{let e=u.value??`auto`;this.fileInput.accept=w(e),e===`auto`?c.textContent=`Drop a game file here or`:c.textContent=`Drop a ${T(e)} file here or`};m(),u.addEventListener(`change`,m);let h=e=>{let t=C(u.value??`auto`,e.name);d.hidden=!1,f.textContent=e.name,p.textContent=T(t);let n=new CustomEvent(`c64-load-file`,{detail:{file:e,type:t}});window.dispatchEvent(n)};s.addEventListener(`dragover`,e=>{e.preventDefault(),s.classList.add(`dragover`)}),s.addEventListener(`dragleave`,()=>{s.classList.remove(`dragover`)}),s.addEventListener(`drop`,e=>{e.preventDefault(),s.classList.remove(`dragover`);let t=e.dataTransfer?.files?.[0];t&&h(t)}),l.addEventListener(`click`,()=>this.fileInput?.click()),this.fileInput.addEventListener(`change`,()=>{let e=this.fileInput?.files?.[0];e&&h(e)}),r.querySelector(`#c64-load-btn`).addEventListener(`click`,()=>{let e=this.fileInput?.files?.[0];e?h(e):this.fileInput?.click()});let g=r.querySelector(`[data-settings-section="system"]`),_=g?.querySelector(`#c64-detach-btn`),v=g?.querySelector(`#c64-reset-btn`);_&&_.addEventListener(`click`,()=>{if(!this.player||!confirm(`Detach cartridge?`))return;this.player.detachCartridge();let e=document.getElementById(`status`);e&&(e.textContent=`Cartridge detached`)}),v&&v.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`)});let b=r.querySelector(`#c64-audio-section-anchor`);this.createAudioSection(b);let x=r.querySelectorAll(`input[name="c64-joy-port"]`),S=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{}};x.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&S(Number(e.value))})});let E={joystick:`Arrows + Ctrl = joystick only`,keyboard:`All keys → C64 keyboard matrix`,mixed:`Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard`},D=r.querySelectorAll(`input[name="c64-input-mode"]`),O=r.querySelector(`#c64-input-mode-hint`),k=e=>{if(O&&(O.innerHTML=E[e]??``),window.dispatchEvent(new CustomEvent(`c64-set-input-mode`,{detail:{mode:e}})),this.player&&typeof this.player.setInputMode==`function`)try{this.player.setInputMode(e)}catch{}};D.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&k(e.value)})});let A=r.querySelectorAll(`input[name="c64-display-mode"]`),j=document.getElementById(`c64-screen`),M=e=>{j&&(j.style.width=``,j.style.height=``,j.style.objectFit=``,j.removeAttribute(`data-display-mode`),e===`standard`?(j.style.width=``,j.style.height=``,j.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`?(j.style.height=`100vh`,j.style.width=`auto`,j.style.objectFit=`contain`,j.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`&&(j.style.width=`100vw`,j.style.height=`100vh`,j.style.objectFit=`fill`,j.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`),j.setAttribute(`data-display-mode`,e),window.dispatchEvent(new CustomEvent(`c64-display-mode-changed`,{detail:{mode:e}})))};A.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=`🔇`,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=`
|
|
493
|
+
<label>Audio</label>
|
|
494
|
+
<div class="c64-audio-row">
|
|
495
|
+
<button class="c64-mute-btn" id="c64-mute-btn" title="Toggle mute">🔈</button>
|
|
496
|
+
<input type="range" class="c64-volume-slider" id="c64-volume-slider" min="0" max="100" value="75" />
|
|
497
|
+
<span class="c64-volume-label" id="c64-volume-label">75%</span>
|
|
498
|
+
</div>
|
|
499
|
+
`,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?`🔇`:`🔈`,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`)}},B=document.getElementById(`status`),V=new M(`c64-screen`),H=`/c64-ready/`,U=new URLSearchParams(window.location.search);function W(e,t){if(!e)return`${t}games/cartridges/legend-of-wilf.crt`;let n=e.trim();return n?n.toLowerCase()===`null`?``:/^https?:\/\//i.test(n)||n.startsWith(`/`)?n:`${t}${n.replace(/^\/+/,``)}`:`${t}games/cartridges/legend-of-wilf.crt`}var G=W(U.get(`game`),H),K=S(G||``)??`crt`,q=new E({wasmUrl:`${H}c64.wasm`,gameUrl:G,gameType:K,renderer:V,onProgress:(e,t)=>V.setProgress(e,t)});new z().init(q),q.start().then(()=>{G||(B.textContent=`Autoload disabled (?game=null)`,B.style.color=`#9ecbff`),V.hideLoader()}).catch(e=>{console.error(e),V.setError(`ERROR`),B.textContent=`Error: ${e}`,B.style.color=`#f44`});var J=()=>{let e=document.hidden,t=document.querySelector(`link[rel~='icon']`),n=`${H}${e?`led-off.svg`:`led-on.svg`}`.replace(/\/+/g,`/`);t&&(t.href=n)};document.addEventListener(`visibilitychange`,J),window.addEventListener(`focus`,J),window.addEventListener(`blur`,J),J(),window.addEventListener(`c64-load-file`,async e=>{let t=e.detail,n=t.file,r=t.type,i=r===`auto`?void 0:r;if(n)try{V.showLoader(),await q.loadFile(n,x(i)?i:void 0),V.hideLoader()}catch(e){console.error(e),V.setError(`LOAD ERROR`),B.textContent=`Load error: ${e}`,B.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),V.setError(`LOAD ERROR`),B.textContent=`Load error: ${n}`,B.style.color=`#f44`}),window.addEventListener(`c64-load-info`,e=>{let t=e.detail;t?.message&&(B.textContent=t.message,B.style.color=t.mode===`warning`?`#f9c74f`:`#9ecbff`,console.info(`C64 load info event:`,t))});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|