c64-ready 2.1.0 → 2.1.1
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/README.md +4 -1
- package/dist/assets/index-Bk-mEPYS.js +169 -0
- package/dist/index.html +1 -1
- package/dist-ts/player/c64-player.d.ts +2 -1
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +38 -26
- package/dist-ts/player/c64-player.js.map +1 -1
- package/package.json +5 -4
- package/src/player/c64-player.ts +45 -27
- package/dist/assets/index-Df2-qP_u.js +0 -169
package/README.md
CHANGED
|
@@ -526,7 +526,7 @@ To regenerate both the Vite browser bundle and the TypeScript API outputs in one
|
|
|
526
526
|
|
|
527
527
|
```zsh
|
|
528
528
|
npm run package:build
|
|
529
|
-
# equivalent to: npm run build
|
|
529
|
+
# equivalent to: npm run build
|
|
530
530
|
```
|
|
531
531
|
|
|
532
532
|
This produces:
|
|
@@ -534,6 +534,9 @@ This produces:
|
|
|
534
534
|
- `dist/` — Vite browser bundle (served by `c64-ready` CLI)
|
|
535
535
|
- `dist-ts/` — compiled JS + `.d.ts` declarations (imported by API consumers)
|
|
536
536
|
|
|
537
|
+
`npm run headless:build` is reserved for the Docker/headless TypeScript build and does
|
|
538
|
+
not run the package ESM export rewrite step.
|
|
539
|
+
|
|
537
540
|
## Deployment
|
|
538
541
|
|
|
539
542
|
The project deploys to GitHub Pages automatically via GitHub Actions.
|
|
@@ -0,0 +1,169 @@
|
|
|
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}}}};const t={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 n(e){return e.exrom===1&&e.game===0}function r(e){return n(e)&&e.hwType===0?`Unsupported CRT: Ultimax/MAX cartridges are not supported by this emulator.`:null}function i(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function a(e,t){return(e[t]<<8|e[t+1])>>>0}function o(e,n){if(!e||e.length<64||!String.fromCharCode(...Array.from(e.slice(0,16))).startsWith(`C64 CARTRIDGE`))return null;let r=i(e,16),o=a(e,22),s=e[24],c=e[25],l=``;for(let t=32;t<64&&e[t]!==0;t++)l+=String.fromCharCode(e[t]);l=l.trim();let u;u=s===0&&c===0?`16K (ROML+ROMH)`:s===0&&c===1?`8K (ROML only)`:s===1&&c===0?`Ultimax`:`inactive (pass-through)`;let d=0,f=0,p=Math.max(r,64);for(;p+16<=e.length&&String.fromCharCode(...Array.from(e.slice(p,p+4)))===`CHIP`;){let t=i(e,p+4);if(t<16)break;let n=a(e,p+14);d++,f+=n,p+=t}let m=t[o]??`Unknown(${o})`,h=n?` "${n}"`:``,g=l?` name="${l}"`:``,_=(f/1024).toFixed(0);return{line:`[C64 cart]${h} loading: hwType=${o}(${m}) | ${u} flags, ${_}K actual | ${d} CHIP(s) | ${e.length} bytes${g}`,hwType:o,hwName:m,exrom:s,game:c,bankConfig:u,cartName:l,chipCount:d,totalRomBytes:f}}var s=384,c=272,l=44100,u=class t{wasm;wasmUrl;config;running=!1;frameCount=0;crtPreloadChecksEnabled=!0;onFrame;onAudio;constructor(e,t,n={}){this.wasm=e,this.wasmUrl=t,this.config={videoWidth:s,videoHeight:c,sampleRate:l,audioChannels:1,cyclesPerFrame:50,...n}}static async load(n=`/src/emulator/c64.wasm`,r={}){let i=new t(await e.load(n),n,r);return i.init(),i}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}async reboot(){let t=this.running,n=await e.load(this.wasmUrl);this.running=!1,this.wasm=n,this.frameCount=0,this.init(),t&&this.start()}setCrtPreloadChecksEnabled(e){this.crtPreloadChecksEnabled=e}static AUDIO_BUFFER_SIZE=4096;tick(e=0){if(!this.running)return;let t=this.wasm.exports,n=t.debugger_update(e);if(this.frameCount++,n&&this.onFrame){let e=t.c64_getPixelBuffer(),n=this.wasm.heap.heapU8.subarray(e,e+s*c*4);this.onFrame({width:s,height:c,data:n,timestamp:this.frameCount})}}loadGame(e){let t=this.wasm.exports;if(!t||!this.wasm.heap)throw Error(`WASM not ready`);if(e.type===`snapshot`){t.c64_reset();let n=this.wasm.allocAndWrite(e.data);try{this.loadSnapshotData(n,e.data.length)}finally{this.wasm.free(n)}return}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`:if(this.crtPreloadChecksEnabled){let t=o(e.data);if(!t)throw Error(`Invalid CRT file format`);let n=r(t);if(n)throw Error(n)}t.c64_loadCartridge(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)}setMousePortEnabled(e,t){this.wasm.exports?.c64_set_mouse_port_enabled(e-1,t?1:0)}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}cpuReadNS(e){return this.wasm.exports?.c64_cpuReadNS(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:s,height:c,data:this.wasm.heap.heapU8.slice(e,e+s*c*4),timestamp:this.frameCount}}getSnapshot(){let e=this.wasm.exports;if(!e||!this.wasm.heap)throw Error(`WASM not ready`);let t=e.c64_getSnapshot(),n=e.c64_getSnapshotSize();return this.wasm.heap.heapU8.slice(t,t+n)}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 n=e.sid_getAudioBuffer();return new Float32Array(this.wasm.heap.heapF32.subarray(n>>2,(n>>2)+t.AUDIO_BUFFER_SIZE))}setSIDModel(e){this.wasm.exports?.sid_setModel(e)}setVoiceEnabled(e,t){this.wasm.exports?.sid_setVoiceEnabled(e,t?1:0)}setDriveEnabled(e){this.wasm.exports?.c64_setDriveEnabled(e?1:0)}getDriveEnabled(){return(this.wasm.exports?.c64_getDriveEnabled()??0)!==0}},d=44100,f=class{ctx=null;workletNode=null;gainNode=null;_muted=!1;_volume=.75;_suspended=!0;_initialised=!1;_ready=!1;options;_readSidBuffer=null;onStateChange;constructor(e={}){this.options=e}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??d}async init(){if(this._initialised)return!this._suspended;this._initialised=!0;try{return this.ctx=new AudioContext({sampleRate:d}),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=this.options.assetBaseUrl??`/`,t=this.options.workletUrl??`${e.replace(/\/+$/,``)}/audio-worklet-processor.js`;await this.ctx.audioWorklet.addModule(t),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 p={UP:1,DOWN:2,LEFT:4,RIGHT:8},m={ArrowUp:p.UP,ArrowDown:p.DOWN,ArrowLeft:p.LEFT,ArrowRight:p.RIGHT,ControlLeft:16},h=Object.keys(m),g={ArrowUp:p.UP,ArrowDown:p.DOWN,ArrowLeft:p.LEFT,ArrowRight:p.RIGHT,KeyZ:16,KeyX:32,KeyC:64,ControlLeft:16},_={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 v(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(_.SHIFT_LEFT):r!==`arrowup`&&r!==`arrowleft`&&(s(_.SHIFT_LEFT),s(_.SHIFT_RIGHT))),r){case`a`:c(_.A);break;case`b`:c(_.B);break;case`c`:c(_.C);break;case`d`:c(_.D);break;case`e`:c(_.E);break;case`f`:c(_.F);break;case`g`:c(_.G);break;case`h`:c(_.H);break;case`i`:c(_.I);break;case`j`:c(_.J);break;case`k`:c(_.K);break;case`l`:c(_.L);break;case`m`:c(_.M);break;case`n`:c(_.N);break;case`o`:c(_.O);break;case`p`:c(_.P);break;case`q`:c(_.Q);break;case`r`:c(_.R);break;case`s`:c(_.S);break;case`t`:c(_.T);break;case`u`:c(_.U);break;case`v`:c(_.V);break;case`w`:c(_.W);break;case`x`:c(_.X);break;case`y`:c(_.Y);break;case`z`:c(_.Z);break;case`0`:c(_.ZERO);break;case`1`:c(_.ONE);break;case`2`:c(_.TWO);break;case`3`:c(_.THREE);break;case`4`:c(_.FOUR);break;case`5`:c(_.FIVE);break;case`6`:c(_.SIX);break;case`7`:c(_.SEVEN);break;case`8`:c(_.EIGHT);break;case`9`:c(_.NINE);break;case`!`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.ONE);break;case`"`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.TWO);break;case`#`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.THREE);break;case`$`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.FOUR);break;case`%`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.FIVE);break;case`&`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.SIX);break;case`'`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.SEVEN);break;case`(`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.EIGHT);break;case`)`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.NINE);break;case` `:c(_.SPACE);break;case`enter`:c(_.RETURN);break;case`backspace`:case`delete`:c(_.INS_DEL);break;case`escape`:c(_.RUN_STOP);break;case`-`:c(_.MINUS);break;case`=`:c(_.EQUALS);break;case`+`:i&&(s(_.SHIFT_LEFT),s(_.SHIFT_RIGHT)),c(_.PLUS);break;case`*`:i&&(s(_.SHIFT_LEFT),s(_.SHIFT_RIGHT)),c(_.STAR);break;case`@`:i&&(s(_.SHIFT_LEFT),s(_.SHIFT_RIGHT)),c(_.AT);break;case`^`:i&&(s(_.SHIFT_LEFT),s(_.SHIFT_RIGHT)),c(_.ARROW_UP);break;case"`":c(_.ARROW_LEFT);break;case`~`:c(_.ARROW_UP);break;case`\\`:c(_.POUND);break;case`,`:case`<`:c(_.COMMA);break;case`.`:case`>`:c(_.PERIOD);break;case`/`:case`?`:c(_.SLASH);break;case`;`:c(_.SEMICOLON);break;case`:`:i&&(s(_.SHIFT_LEFT),s(_.SHIFT_RIGHT)),c(_.COLON);break;case`[`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.COLON);break;case`]`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.SEMICOLON);break;case`shift`:c(_.SHIFT_LEFT);break;case`tab`:c(_.CTRL);break;case`control`:c(_.COMMODORE);break;case`capslock`:c(_.COMMODORE);break;case`home`:c(_.CLEAR_HOME);break;case`pageup`:c(_.RESTORE);break;case`f1`:c(_.F1);break;case`f2`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.F1);break;case`f3`:c(_.F3);break;case`f4`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.F3);break;case`f5`:c(_.F5);break;case`f6`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.F5);break;case`f7`:c(_.F7);break;case`f8`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.F7);break;case`arrowdown`:c(_.CURSOR_UP_DOWN);break;case`arrowup`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.CURSOR_UP_DOWN);break;case`arrowright`:c(_.CURSOR_LEFT_RIGHT);break;case`arrowleft`:i?o(_.SHIFT_LEFT):s(_.SHIFT_LEFT),c(_.CURSOR_LEFT_RIGHT);break;default:break}return a}var y=128,b=0,x=class{emulator;target;joystickPort;inputMode=`mixed`;updateFrame=-1;gamepadIndex=-1;gamepadPresses=[];gamepadAxes=[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1];potFire2Pressed=!1;potFire3Pressed=!1;pressedControls=new Set;keyDownHandler=e=>{this.handleKeyDown(e)};keyUpHandler=e=>{this.handleKeyUp(e)};gamepadConnectedHandler=e=>{this.handleGamepadConnected(e)};gamepadDisconnectedHandler=e=>{this.handleGamepadDisconnected(e)};constructor(e,t=window,n=2){this.emulator=e,this.target=t,this.joystickPort=n}attach(){this.target.addEventListener(`gamepadconnected`,this.gamepadConnectedHandler),this.target.addEventListener(`gamepaddisconnected`,this.gamepadDisconnectedHandler),this.target.addEventListener(`keydown`,this.keyDownHandler),this.target.addEventListener(`keyup`,this.keyUpHandler)}detach(){this.target.removeEventListener(`gamepadconnected`,this.gamepadConnectedHandler),this.target.removeEventListener(`gamepaddisconnected`,this.gamepadDisconnectedHandler),this.target.removeEventListener(`keydown`,this.keyDownHandler),this.target.removeEventListener(`keyup`,this.keyUpHandler),this.releaseAll(),this.releaseAllGamepadButtons(),this.cancelUpdate()}step(){let e=navigator.getGamepads();if(!e)return;let t=e[this.gamepadIndex];if(!t){this.cancelUpdate();return}if(t.buttons){for(let e=0;e<t.buttons.length;e++)if(t.buttons[e].pressed)switch(this.gamepadPresses[e]=!0,console.log(`Buttons Pressed`,e,t.buttons[e]),e){case 0:this.emulator.joystickPush(this.joystickPort,16);break;case 1:this.emulator.joystickPush(this.joystickPort,p.UP);break;case 2:this.emulator.keyDown(_.SPACE);break;case 3:break;case 7:case 9:this.emulator.keyDown(_.RUN_STOP);break;case 14:this.emulator.joystickPush(this.joystickPort,p.LEFT);break;case 15:this.emulator.joystickPush(this.joystickPort,p.RIGHT);break;case 12:this.emulator.joystickPush(this.joystickPort,p.UP);break;case 13:this.emulator.joystickPush(this.joystickPort,p.DOWN);break}else if(!t.buttons[e].pressed&&this.gamepadPresses[e]===!0)switch(this.gamepadPresses[e]=!1,e){case 0:this.emulator.joystickRelease(this.joystickPort,16);break;case 1:this.emulator.joystickRelease(this.joystickPort,p.UP);break;case 2:this.emulator.keyUp(_.SPACE);break;case 3:break;case 7:case 9:this.emulator.keyUp(_.RUN_STOP);break;case 14:this.emulator.joystickRelease(this.joystickPort,p.LEFT);break;case 15:this.emulator.joystickRelease(this.joystickPort,p.RIGHT);break;case 12:this.emulator.joystickRelease(this.joystickPort,p.UP);break;case 13:this.emulator.joystickRelease(this.joystickPort,p.DOWN);break}}t.axes[0]<=-.5||t.axes[6]<=-.5?(this.gamepadAxes[0]=!0,this.emulator.joystickPush(this.joystickPort,p.LEFT)):this.gamepadAxes[0]===!0&&(this.gamepadAxes[0]=!1,this.emulator.joystickRelease(this.joystickPort,p.LEFT)),t.axes[0]>=.5||t.axes[6]>=.5?(this.emulator.joystickPush(this.joystickPort,p.RIGHT),this.gamepadAxes[1]=!0):this.gamepadAxes[1]===!0&&(this.emulator.joystickRelease(this.joystickPort,p.RIGHT),this.gamepadAxes[1]=!1),t.axes[1]<=-.5||t.axes[7]<=-.5?(this.emulator.joystickPush(this.joystickPort,p.UP),this.gamepadAxes[2]=!0):this.gamepadAxes[2]===!0&&(this.emulator.joystickRelease(this.joystickPort,p.UP),this.gamepadAxes[2]=!1),t.axes[1]>=.5||t.axes[7]>=.5?(this.emulator.joystickPush(this.joystickPort,p.DOWN),this.gamepadAxes[3]=!0):this.gamepadAxes[3]===!0&&(this.emulator.joystickRelease(this.joystickPort,p.DOWN),this.gamepadAxes[3]=!1),this.updateFrame=requestAnimationFrame(this.step.bind(this))}cancelUpdate(){cancelAnimationFrame(this.updateFrame),this.updateFrame=-1,this.gamepadIndex=-1}releaseAllGamepadButtons(){if(!this.gamepadPresses.some(Boolean))return;let e={0:16,2:32,3:64,12:p.UP,13:p.DOWN,14:p.LEFT,15:p.RIGHT};for(let[t,n]of Object.entries(e))n&&this.gamepadPresses[Number(t)]===!0&&this.releaseJoystickInput(n);this.gamepadPresses=[]}findConnectedGamepadIndex(e){let t=navigator.getGamepads?.()??[];for(let n of t)if(n&&n.index!==e)return n.index;return-1}handleGamepadDisconnected(e){if(console.log(`Gamepad disconnected from index %d: %s`,e.gamepad.index,e.gamepad.id),this.gamepadIndex===e.gamepad.index){this.releaseAllGamepadButtons();let t=this.findConnectedGamepadIndex(e.gamepad.index);t>=0?(this.gamepadIndex=t,this.updateFrame<0&&this.step()):this.cancelUpdate()}let t=new CustomEvent(`c64-controller-disconnected`,{detail:{name:e.gamepad.id,index:e.gamepad.index}});this.target.dispatchEvent(t)}handleGamepadConnected(e){console.log(`Gamepad connected at index %d: %s. %d buttons, %d axes.`,e.gamepad.index,e.gamepad.id,e.gamepad.buttons.length,e.gamepad.axes.length),this.gamepadIndex<0&&(this.gamepadIndex=e.gamepad.index);let t=new CustomEvent(`c64-controller-connected`,{detail:{name:e.gamepad.id,index:e.gamepad.index}});this.target.dispatchEvent(t),this.updateFrame<0&&this.step()}handleKeyDown(e){if(this.inputMode===`keyboard`){let t=v(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 g){let t=g[e.code];this.pushJoystickInput(t),e.preventDefault()}else{let t=v(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.pushJoystickInput(m[t]),e.preventDefault())}handleKeyUp(e){if(this.inputMode===`keyboard`){let t=v(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 g){let t=g[e.code];this.releaseJoystickInput(t),e.preventDefault()}else{let t=v(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.releaseJoystickInput(m[t]),e.preventDefault())}getMappedControl(e){return e.code in m?e.code:null}pushJoystickInput(e){if(e===32){this.potFire2Pressed=!0,this.syncPotFireButtons();return}if(e===64){this.potFire3Pressed=!0,this.syncPotFireButtons();return}this.emulator.joystickPush(this.joystickPort,e)}releaseJoystickInput(e){if(e===32){this.potFire2Pressed=!1,this.syncPotFireButtons();return}if(e===64){this.potFire3Pressed=!1,this.syncPotFireButtons();return}this.emulator.joystickRelease(this.joystickPort,e)}releaseAll(){for(let e of this.pressedControls)this.releaseJoystickInput(m[e]);this.pressedControls.clear(),this.potFire2Pressed=!1,this.potFire3Pressed=!1,this.syncPotFireButtons()}syncPotFireButtons(){if(!this.potFire2Pressed&&!this.potFire3Pressed){this.emulator.setMousePortEnabled?.(this.joystickPort,!1);return}this.emulator.setMousePortEnabled?.(this.joystickPort,!0),this.emulator.mousePosition?.(this.potFire2Pressed?b:y,this.potFire3Pressed?b:y)}setKeyboardPort(e){this.joystickPort!==e&&(this.releaseAll(),this.releaseAllGamepadButtons(),this.joystickPort=e)}setInputMode(e){this.inputMode!==e&&(this.releaseAll(),this.releaseAllGamepadButtons(),this.inputMode=e)}getInputMode(){return this.inputMode}setActiveGamepadIndex(e){if(this.gamepadIndex!==e){if(!(navigator.getGamepads?.()??[])[e])throw Error(`Gamepad ${e} is not connected`);this.releaseAllGamepadButtons(),this.gamepadIndex=e,this.updateFrame<0&&this.step()}}getActiveGamepadIndex(){return this.gamepadIndex}},S=class{emulatorInput;captureKeyDown=e=>this.onCaptureKeyDown(e);captureKeyUp=e=>this.onCaptureKeyUp(e);constructor(e,t=window){this.emulatorInput=new x(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()}setActiveGamepadIndex(e){this.emulatorInput.setActiveGamepadIndex(e)}getActiveGamepadIndex(){return this.emulatorInput.getActiveGamepadIndex()}onCaptureKeyDown(e){if(new Set([...h,...Object.keys(g)]).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([...h,...Object.keys(g)]).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 C=[{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 w=new Set(C.map(e=>e.type));function T(e){return typeof e==`string`&&w.has(e)}function E(e){let t=e.toLowerCase();for(let e of C)if(e.extensions.some(e=>t.endsWith(e)))return e.type;return null}function D(e,t,n=`crt`){return e===`auto`?E(t)??n:e}function ee(e){return(e===`auto`?C.flatMap(e=>e.extensions):C.find(t=>t.type===e)?.extensions??[]).join(`,`)}function O(e){return C.find(t=>t.type===e)?.label??e.toUpperCase()}var k=198,A=631,j=8,M=650,N=2e3,P=class{emulator=null;inputHandler=null;disableCrtPreloadChecks=!1;destroyed=!1;audio;options;constructor(e){this.options={gameType:`crt`,...e},this.audio=new f(e.audio)}async start(){this.destroyed=!1;let{wasmUrl:e,gameUrl:t,gameData:n,gameSource:r,gameType:i,renderer:a,onProgress:o}=this.options;o?.(10,`INITIALISING WASM...`),this.emulator=await u.load(e),this.emulator.setCrtPreloadChecksEnabled(!this.disableCrtPreloadChecks),this.attachInputAndRenderer(this.emulator,a);let s=!1;n==null?t&&t!==`null`&&(await this.loadGame(t,i,o),s=i===`prg`):(await this.loadGameData(n,i,r??`inline game data`,o),s=i===`prg`),this.emulator.start(),s&&await this.autoRunPrgIfRunning(),this.initAudio()}initAudio(){this.emulator&&(this.audio.onStateChange=e=>{window.dispatchEvent(new CustomEvent(`c64-audio-state`,{detail:e}))},this.audio.init().then(e=>{this.emulator&&(this.emulator.setSampleRate(this.audio.sampleRate),this.audio.setSidBufferReader(()=>this.emulator?.getSidBuffer()??null),e||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());n?.(90,`INSERTING ${I(t)}...`),await this.insertGameData(a,t,e,{url:e},n)}async loadGameData(e,t=`crt`,n=`inline game data`,r=this.options.onProgress){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);r?.(20,`LOADING GAME DATA...`);let i=z(e);r?.(90,`INSERTING ${I(t)}...`),await this.insertGameData(i,t,n,{source:n},r)}async loadFile(e,t){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);let n=this.options.onProgress,r=t??E(e.name)??`crt`;try{n?.(20,`READING FILE ${e.name}...`);let t=await e.arrayBuffer(),i=new Uint8Array(t);n?.(90,`INSERTING ${I(r)}...`),await this.insertGameData(i,r,e.name,{file:e.name},n),window.dispatchEvent(new CustomEvent(`c64-close-dialog`,{detail:{file:e.name,type:r}}))}catch(e){throw n?.(0,`FAILED`),e}}async loadTool(e,t){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);let n=this.options.onProgress,r=t??E(e)??`prg`;n?.(10,`PREPARING TOOL...`);try{this.emulator.removeCartridge()}catch{}this.emulator.reset(),this.emulator.start(),await L(120),await this.loadGame(e,r,n)}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)}}async reboot(){if(this.emulator)try{await this.emulator.reboot(),this.attachInputAndRenderer(this.emulator,this.options.renderer),this.emulator.start(),this.emulator.setSampleRate(this.audio.sampleRate),this.audio.setSidBufferReader(()=>this.emulator?.getSidBuffer()??null),window.dispatchEvent(new CustomEvent(`c64-reboot`,{detail:{}})),window.dispatchEvent(new CustomEvent(`c64-close-menu`))}catch(e){throw console.error(`Failed to reboot emulator:`,e),e}}async destroy(){if(!this.destroyed){this.destroyed=!0;try{this.emulator?.pause()}finally{this.inputHandler?.detach(),this.inputHandler=null,this.options.renderer.detach(),this.audio.onStateChange=void 0,this.audio.setSidBufferReader(()=>null),await this.audio.destroy(),this.emulator=null}}}setKeyboardJoystickPort(e){this.inputHandler?.setKeyboardJoystickPort(e)}setInputMode(e){this.inputHandler?.setInputMode(e)}setActiveGamepadIndex(e){this.inputHandler?.setActiveGamepadIndex(e)}getActiveGamepadIndex(){return this.inputHandler?.getActiveGamepadIndex()??-1}getSnapshot(){if(!this.emulator)throw Error(`Emulator not initialised`);return this.emulator.getSnapshot()}ramRead(e){return this.emulator?.ramRead(e)??0}cpuRead(e){return this.emulator?.cpuRead(e)??0}cpuReadNS(e){return this.emulator?.cpuReadNS(e)??0}setVoiceEnabled(e,t){this.emulator?.setVoiceEnabled(e,t)}setCrtPreloadChecksDisabled(e){this.disableCrtPreloadChecks=e,this.emulator?.setCrtPreloadChecksEnabled(!e)}async autoRunPrgIfRunning(){!this.emulator||!this.emulator.isRunning()||(await L(M),await this.insertTextIntoKeyboardBuffer(`run
|
|
2
|
+
`))}async insertTextIntoKeyboardBuffer(e){if(!this.emulator)return;let t=R(e);for(;t.length>0;){await this.waitForKeyboardBufferEmpty();let e=t.splice(0,j);this.emulator.cpuWrite(k,e.length);for(let t=0;t<e.length;t+=1)this.emulator.cpuWrite(A+t,e[t])}}async waitForKeyboardBufferEmpty(){let e=Date.now();for(;this.emulator?.cpuRead(k);){if(Date.now()-e>=N)throw Error(`Timed out waiting for C64 keyboard buffer before PRG auto-run`);await L(50)}}async insertGameData(e,t,n,r,i){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);this.assertSnapshotFormatSupported(e,t,n),this.emitSnapshotLoadInfo(t,n);try{t===`crt`&&this.handleCrtPreloadChecks(e,n,i),this.emulator.loadGame({type:t,data:e}),t===`prg`&&await this.autoRunPrgIfRunning(),i?.(100,`READY!`),window.dispatchEvent(new CustomEvent(`c64-load-success`,{detail:{...r,type:t}}))}catch(e){throw i?.(0,`FAILED`),console.error(`Failed to insert cartridge or load game:`,e),window.dispatchEvent(new CustomEvent(`c64-load-error`,{detail:{error:e instanceof Error?e.message:String(e),...r,type:t}})),e}}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`||!H(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}attachInputAndRenderer(e,t){this.inputHandler?.detach(),this.inputHandler=new S(e),this.inputHandler.attach(),t.attachTo(e)}handleCrtPreloadChecks(e,t,n){if(!this.disableCrtPreloadChecks){F(e,t,n);return}let i=o(e,t);if(!i)return;console.log(i.line);let a=r(i);a&&(n?.(90,`UNSAFE CRT LOAD`),console.warn(`${a} Proceeding because preload checks are disabled.`),window.dispatchEvent(new CustomEvent(`c64-load-info`,{detail:{mode:`warning`,source:t,message:`Preload checks are disabled. This cartridge is normally flagged as incompatible and may hang the emulator.`}})))}};function F(e,t,n){let i=o(e,t);if(!i){n?.(0,`INVALID CRT`);let e=Error(`Invalid CRT file format`);throw console.error(e),e}console.log(i.line);let a=r(i);if(a){n?.(0,`UNSUPPORTED CRT`);let e=Error(a);throw console.error(e),e}}function I(e){let t=O(e),n=t.indexOf(` (`);return(n>0?t.slice(0,n):t).toUpperCase()}function L(e){return new Promise(t=>setTimeout(t,e))}function R(e){let t=[],n=e.toUpperCase().replace(/\r\n/g,`
|
|
3
|
+
`);for(let e=0;e<n.length;e+=1){let r=n.charCodeAt(e);t.push(r===10?13:r)}return t}function z(e){if(e instanceof Uint8Array)return e;if(typeof e!=`string`)return new Uint8Array(e);let t=e.trim(),n=t.match(/^data:[^,]*;base64,(.*)$/s),r=n?n[1]:t;return n||V(r)?B(globalThis.atob(r.replace(/\s/g,``))):B(e)}function B(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t}function V(e){let t=e.replace(/\s/g,``);return t.length>0&&t.length%4==0&&/^[A-Za-z0-9+/]+={0,2}$/.test(t)}function H(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 te=`
|
|
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
|
+
`,ne=class{canvas;ctx;animationFrameId=null;attachedEmulator=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=te,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){this.detach(),this.attachedEmulator=e,e.onFrame=e=>{this.render(e)};let t=0,n=r=>{let i=t?r-t:0;t=r,e.tick(i),this.animationFrameId=requestAnimationFrame(n)};this.animationFrameId=requestAnimationFrame(n)}detach(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.attachedEmulator&&=(this.attachedEmulator.onFrame=void 0,null)}},re=`modulepreload`,ie=function(e){return`/c64-ready/`+e},U={};const W=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=ie(t,n),t in U)return;U[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`:re,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 ae=`
|
|
44
|
+
.c64-help-btn,.c64-hamburger,.c64-unmute-btn{position:fixed;top:12px;width:36px;height:36px;border-radius:6px;border:2px solid #444;background:#111;color:#ddd;cursor:pointer;display:flex;align-items:center;justify-content:center;z-index:1000}.c64-help-btn{right:12px;border-radius:50%;color:#7b71d5;font-family:monospace;font-size:18px;font-weight:bold}.c64-hamburger{left:12px;font-family:monospace}.c64-unmute-btn{left:56px;color:#f44;z-index:1010}.c64-unmute-btn.hidden{opacity:0;pointer-events:none}.c64-help-overlay,.c64-menu-overlay{position:fixed;inset:0;background:rgba(0,0,0,.7);display:flex;align-items:center;justify-content:center;z-index:1001;opacity:0;transition:opacity .25s ease;pointer-events:none}.c64-help-overlay.visible,.c64-menu-overlay.visible{opacity:1;pointer-events:auto}.c64-help-dialog,.c64-menu-panel{background:#1a1a2e;border:2px solid #555;border-radius:6px;padding:24px 32px;max-width:760px;width:90%;font-family:monospace;color:#ccc;position:relative}.c64-changelog-dialog{max-height:70vh;overflow:auto}.c64-help-dialog h2{margin:0 0 8px;font-size:16px;color:#7b71d5;letter-spacing:1px}.c64-help-dialog p{margin:0 0 16px;font-size:13px;line-height:1.5;color:#aaa}.c64-help-dialog a{color:#a8a8ff;text-decoration:none}.c64-help-controls,.c64-help-special{margin:0 0 12px;padding:0;list-style:none;font-size:13px}.c64-help-controls li,.c64-help-special li{display:flex;justify-content:space-between;padding:4px 0;border-bottom:1px solid #2a2a3e}.c64-help-key{background:#2a2a3e;border:1px solid #444;border-radius:3px;padding:1px 8px;font-size:12px;color:#ddd}.c64-help-close{position:absolute;top:10px;right:14px;background:none;border:none;color:#888;font-size:20px;cursor:pointer}.c64-version{display:flex;justify-content:end;font-size:12px;color:#999;margin-top:36px}.c64-menu-overlay{align-items:flex-start;justify-content:flex-start;padding:48px 24px;background:rgba(0,0,0,.5);z-index:1002}.c64-menu-panel{min-width:320px;max-width:520px;padding:16px;background:#0f0f1a;border-color:#333}.c64-menu-header{display:flex;align-items:center;justify-content:space-between}.c64-settings-tabs,.c64-menu-actions,.c64-system-actions,.c64-radio-row,.c64-gamepad-list{display:flex;gap:8px;flex-wrap:wrap}.c64-settings-tab,.c64-btn,.c64-mute-btn{background:#222;border:1px solid #444;color:#ddd;padding:6px 10px;border-radius:4px;cursor:pointer}.c64-settings-tab.active,.c64-gamepad-btn.active{border-color:#7b71d5;color:#fff;background:#25253d}.c64-select{background:#171729;color:#ddd;border:1px solid #444;border-radius:4px;padding:4px 8px;font-family:monospace}.c64-form-row,.c64-audio-row,.c64-cart-preview{display:flex;align-items:center;gap:10px;margin-bottom:10px}.c64-section-label,.c64-audio-section label{display:block;margin:0 0 8px;font-size:13px;color:#aaa}.c64-section-hint,.c64-volume-label,.c64-cart-type{font-size:11px;color:#888}.c64-dragarea{border:2px dashed #2a2a3e;border-radius:6px;padding:12px;margin-top:12px;text-align:center;color:#aaa}.c64-dragarea.dragover{border-color:#7b71d5;color:#fff}.c64-file-input{display:none}.c64-volume-slider{flex:1}.c64-cart-filename{font-size:13px;color:#ccc;word-break:break-all}.c64-checkbox-row{display:inline-flex;gap:8px;align-items:center;color:#ccc;font-size:13px}
|
|
45
|
+
`;function G(e,t){return`${(e??`/`).replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`}var oe=[[`Move Up`,`↑`],[`Move Down`,`↓`],[`Move Left`,`←`],[`Move Right`,`→`],[`Fire`,`Z or Left Ctrl`]],se=[[`Run/Stop`,`Esc`],[`Restore`,`(currently unsupported)`],[`Insert/Delete`,`Backspace or Delete`],[`Clear/Home`,`Home`],[`Commodore`,`Ctrl or Caps Lock`],[`Control`,`Tab`],[`Arrow Left glyph`,"`"],[`Arrow Up glyph`,`^ or ~`],[`Pound`,`\\`],[`Colon / Semicolon`,`: ; [ ]`],[`Slash`,`/ ?`],[`Comma / Period`,`, . < >`],[`C64 function keys`,`F1-F8`]],K=`c64-disable-crt-preload-checks`;function ce(e=new Date){let t=e=>String(e).padStart(2,`0`);return`snapshot-${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}-${t(e.getHours())}${t(e.getMinutes())}${t(e.getSeconds())}.c64`}var le=class{helpOverlay=null;settingsOverlay=null;fileInput=null;player=null;options;savedHtmlOverflow=null;savedBodyOverflow=null;connectedGamepads=new Map;handleControllerConnected=e=>{let t=e.detail;typeof t?.index==`number`&&(this.connectedGamepads.set(t.index,{index:t.index,name:t.name??`Gamepad ${t.index}`}),this.renderGamepadButtons())};handleControllerDisconnected=e=>{let t=e.detail;typeof t?.index==`number`&&(this.connectedGamepads.delete(t.index),this.renderGamepadButtons())};constructor(e={}){this.options=e}init(e){this.player=e??null,this.syncConnectedGamepads(),this.injectCSS(),this.createButton(),this.createDialog(),this.createHamburger(),this.createMenu(),this.createUnmuteButton(),window.addEventListener(`c64-controller-connected`,this.handleControllerConnected),window.addEventListener(`c64-controller-disconnected`,this.handleControllerDisconnected)}syncConnectedGamepads(){this.connectedGamepads.clear();let e=navigator.getGamepads?.()??[];for(let t of e)t&&this.connectedGamepads.set(t.index,{index:t.index,name:t.id})}getConnectedGamepads(){return Array.from(this.connectedGamepads.values()).sort((e,t)=>e.index-t.index)}getGamepadLabel(e){let t=e.name.replace(/\s*\([^)]*\)\s*$/u,``).trim()||e.name.trim()||`Gamepad ${e.index}`;return`${e.index}: ${t}`}renderGamepadButtons(){let e=document.getElementById(`c64-gamepad-list`),t=document.getElementById(`c64-gamepad-empty`);if(!e||!t)return;let n=this.getConnectedGamepads(),r=this.player?.getActiveGamepadIndex()??-1;e.replaceChildren(...n.map(e=>{let t=document.createElement(`button`),n=e.index===r;return t.type=`button`,t.className=`c64-btn c64-gamepad-btn${n?` active`:``}`,t.textContent=this.getGamepadLabel(e),t.setAttribute(`aria-pressed`,n?`true`:`false`),t.addEventListener(`click`,()=>{this.player&&(this.player.setActiveGamepadIndex(e.index),this.renderGamepadButtons())}),t})),t.hidden=n.length>0}downloadSnapshot(e){let t=new Uint8Array(e.byteLength);t.set(e);let n=new Blob([t],{type:`application/bin`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=ce(),document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}injectCSS(){if(document.querySelector(`style[data-c64-help]`))return;let e=document.createElement(`style`);e.setAttribute(`data-c64-help`,``),e.textContent=ae,document.head.appendChild(e)}getVersionLabel(){let e=this.options.appVersion??`0.0.0`,t=this.options.gitHash;return`v${e}${t?` (build: ${t})`:``}`}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=`
|
|
46
|
+
<div class="c64-help-dialog">
|
|
47
|
+
<button class="c64-help-close">×</button>
|
|
48
|
+
<h2>C64 READY</h2>
|
|
49
|
+
<p>A Commodore 64 emulator running in the browser via WebAssembly.</p>
|
|
50
|
+
<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>
|
|
51
|
+
<h2>CONTROLS</h2>
|
|
52
|
+
<ul class="c64-help-controls">${oe.map(([e,t])=>`<li><span>${e}</span><span class="c64-help-key">${t}</span></li>`).join(``)}</ul>
|
|
53
|
+
<h2>SPECIAL KEYS</h2>
|
|
54
|
+
<ul class="c64-help-special">${se.map(([e,t])=>`<li><span>${e}</span><span class="c64-help-key">${t}</span></li>`).join(``)}</ul>
|
|
55
|
+
<div class="c64-version">${this.getVersionLabel()}</div>
|
|
56
|
+
</div>
|
|
57
|
+
`,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=`
|
|
58
|
+
<div class="c64-help-dialog c64-changelog-dialog">
|
|
59
|
+
<button class="c64-help-close">×</button>
|
|
60
|
+
<h2>CHANGELOG</h2>
|
|
61
|
+
<div id="c64-changelog-content">Loading...</div>
|
|
62
|
+
</div>
|
|
63
|
+
`,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 fetch(this.options.changelogUrl??G(this.options.assetBaseUrl,`CHANGELOG.md`),{cache:`no-store`});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=(await t.text()).split(`
|
|
64
|
+
`).filter(e=>{let t=e.trim();return t.startsWith(`- `)?/^- (feat|fix)[:(]/.test(t):!0}).join(`
|
|
65
|
+
`),[{marked:r},i]=await Promise.all([W(()=>import(`./marked.esm--kBm026b.js`),[]),W(()=>import(`./purify.es-BcoGFDcJ.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=C.map(e=>`<option value="${e.type}">${e.label}</option>`).join(``),r=document.createElement(`div`);r.className=`c64-menu-panel`,r.innerHTML=`
|
|
66
|
+
<div class="c64-menu-header">
|
|
67
|
+
<h2>Settings</h2>
|
|
68
|
+
<button class="c64-menu-close">×</button>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="c64-menu-body">
|
|
71
|
+
<div class="c64-settings-tabs" role="tablist" aria-label="Settings sections">
|
|
72
|
+
${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(``)}
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div class="c64-settings-sections">
|
|
76
|
+
<section class="c64-settings-section" data-settings-section="load">
|
|
77
|
+
<label class="c64-section-label">Load Game</label>
|
|
78
|
+
<div class="c64-form-row">
|
|
79
|
+
<label for="c64-load-format">Format</label>
|
|
80
|
+
<select id="c64-load-format" class="c64-select">
|
|
81
|
+
<option value="auto">Auto detect (recommended)</option>
|
|
82
|
+
${n}
|
|
83
|
+
</select>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="c64-dragarea" id="c64-dragarea">
|
|
86
|
+
<span id="c64-dragarea-copy">Drop a game file here or</span>
|
|
87
|
+
<button class="c64-btn" id="c64-browse">Browse</button>
|
|
88
|
+
</div>
|
|
89
|
+
<input class="c64-file-input" id="c64-file-input" type="file" />
|
|
90
|
+
<div class="c64-cart-preview" id="c64-cart-preview" hidden>
|
|
91
|
+
<div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
|
|
92
|
+
<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>
|
|
93
|
+
</div>
|
|
94
|
+
<div>
|
|
95
|
+
<div class="c64-cart-filename" id="c64-cart-filename"></div>
|
|
96
|
+
<div class="c64-cart-type" id="c64-cart-type"></div>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
<div class="c64-menu-actions">
|
|
100
|
+
<button class="c64-btn" id="c64-load-btn">Load</button>
|
|
101
|
+
<button class="c64-btn" id="c64-close-menu">Close</button>
|
|
102
|
+
</div>
|
|
103
|
+
<div class="c64-tools-section">
|
|
104
|
+
<label class="c64-section-label">Tools</label>
|
|
105
|
+
<div class="c64-form-row">
|
|
106
|
+
<select id="c64-tool-select" class="c64-select c64-tool-select" disabled>
|
|
107
|
+
<option value="">No tools found</option>
|
|
108
|
+
</select>
|
|
109
|
+
<button class="c64-btn" id="c64-load-tool-btn" disabled>Load Tool</button>
|
|
110
|
+
</div>
|
|
111
|
+
<div class="c64-section-hint" id="c64-tools-status">Loading tools…</div>
|
|
112
|
+
</div>
|
|
113
|
+
</section>
|
|
114
|
+
|
|
115
|
+
<section class="c64-settings-section" data-settings-section="input" hidden>
|
|
116
|
+
<label class="c64-section-label">Input Port</label>
|
|
117
|
+
<div class="c64-radio-row">
|
|
118
|
+
<label><input type="radio" name="c64-joy-port" value="1" /> Port 1</label>
|
|
119
|
+
<label><input type="radio" name="c64-joy-port" value="2" checked /> Port 2</label>
|
|
120
|
+
</div>
|
|
121
|
+
<label class="c64-section-label">Input Mode</label>
|
|
122
|
+
<div class="c64-radio-row c64-radio-row-wrap">
|
|
123
|
+
<label><input type="radio" name="c64-input-mode" value="joystick" /> Joystick</label>
|
|
124
|
+
<label><input type="radio" name="c64-input-mode" value="keyboard" /> Keyboard</label>
|
|
125
|
+
<label><input type="radio" name="c64-input-mode" value="mixed" checked /> Mixed</label>
|
|
126
|
+
</div>
|
|
127
|
+
<div id="c64-input-mode-hint" class="c64-section-hint">Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard</div>
|
|
128
|
+
<label class="c64-section-label">Gamepads</label>
|
|
129
|
+
<div id="c64-gamepad-list" class="c64-gamepad-list"></div>
|
|
130
|
+
<div id="c64-gamepad-empty" class="c64-section-hint">To use a gamepad, connect it to your computer and press any button.</div>
|
|
131
|
+
</section>
|
|
132
|
+
|
|
133
|
+
<section class="c64-settings-section" data-settings-section="display" hidden>
|
|
134
|
+
<label class="c64-section-label">Display Mode</label>
|
|
135
|
+
<div class="c64-radio-row">
|
|
136
|
+
<label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
|
|
137
|
+
<label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
|
|
138
|
+
<label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
|
|
139
|
+
</div>
|
|
140
|
+
</section>
|
|
141
|
+
|
|
142
|
+
<section class="c64-settings-section" data-settings-section="audio" hidden>
|
|
143
|
+
<div id="c64-audio-section-anchor"></div>
|
|
144
|
+
</section>
|
|
145
|
+
|
|
146
|
+
<section class="c64-settings-section" data-settings-section="system" hidden>
|
|
147
|
+
<label class="c64-section-label">System Actions</label>
|
|
148
|
+
<div class="c64-system-actions">
|
|
149
|
+
<button class="c64-btn" id="c64-save-snapshot-btn">Save Snapshot</button>
|
|
150
|
+
<button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
|
|
151
|
+
<button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
|
|
152
|
+
<button class="c64-btn" id="c64-reboot-btn">Reboot Emulator</button>
|
|
153
|
+
</div>
|
|
154
|
+
<label class="c64-checkbox-row" for="c64-disable-crt-preload-checks">
|
|
155
|
+
<input type="checkbox" id="c64-disable-crt-preload-checks" />
|
|
156
|
+
Disable crt preload checks
|
|
157
|
+
</label>
|
|
158
|
+
<div class="c64-section-hint">Allows any .crt file and skips compatibility prechecks.</div>
|
|
159
|
+
</section>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
`,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.getAttribute(`data-settings-tab`)===e;t.classList.toggle(`active`,n),t.setAttribute(`aria-selected`,n?`true`:`false`)}),a.forEach(t=>{t.hidden=t.getAttribute(`data-settings-section`)!==e})};i.forEach(e=>{e.addEventListener(`click`,()=>{let t=e.getAttribute(`data-settings-tab`);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-tool-select`),f=r.querySelector(`#c64-load-tool-btn`),p=r.querySelector(`#c64-tools-status`),m=r.querySelector(`#c64-cart-preview`),h=r.querySelector(`#c64-cart-filename`),g=r.querySelector(`#c64-cart-type`),_=()=>{let e=u.value??`auto`;this.fileInput.accept=ee(e),e===`auto`?c.textContent=`Drop a game file here or`:c.textContent=`Drop a ${O(e)} file here or`};_(),u.addEventListener(`change`,_);let v=e=>{let t=D(u.value??`auto`,e.name);m.hidden=!1,h.textContent=e.name,g.textContent=O(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&&v(t)}),l.addEventListener(`click`,()=>this.fileInput?.click()),this.fileInput.addEventListener(`change`,()=>{let e=this.fileInput?.files?.[0];e&&v(e)}),r.querySelector(`#c64-load-btn`).addEventListener(`click`,()=>{let e=this.fileInput?.files?.[0];e?v(e):this.fileInput?.click()});let y=[],b=()=>{if(d.innerHTML=``,y.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`No tools found`,d.appendChild(e),d.disabled=!0,f.disabled=!0;return}y.forEach((e,t)=>{let n=document.createElement(`option`);n.value=String(t),n.textContent=e.name,d.appendChild(n)}),d.disabled=!1,f.disabled=!1},x=e=>(Array.isArray(e)?e:e&&typeof e==`object`&&Array.isArray(e.tools)?e.tools:[]).map(e=>{let t=typeof e==`string`?e:e&&typeof e==`object`?e.path:void 0;if(!t||typeof t!=`string`)return null;let n=t.split(`/`).pop()??t,r=E(n);if(!r)return null;let i=t.split(`/`).map(e=>encodeURIComponent(e)).join(`/`).replace(/^\/+/,``);return{name:n,url:G(this.options.assetBaseUrl,`tools/${i}`),type:r}}).filter(e=>!!e);f.addEventListener(`click`,()=>{let e=Number(d.value);if(!Number.isFinite(e))return;let t=y[e];t&&window.dispatchEvent(new CustomEvent(`c64-load-tool`,{detail:t}))}),(async()=>{try{let e=G(this.options.assetBaseUrl,`tools/tools.json`),t=await fetch(e,{cache:`no-store`});if(!t.ok)throw Error(`HTTP ${t.status}`);y=x(await t.json()),b(),p.textContent=y.length>0?`Found ${y.length} tool${y.length===1?``:`s`} in /public/tools`:`No compatible tools found in manifest`}catch(e){y=[],b(),p.textContent=`Unable to load tools manifest: ${String(e?.message??e)}`}})().catch(()=>{});let S=r.querySelector(`[data-settings-section="system"]`),w=S?.querySelector(`#c64-save-snapshot-btn`),T=S?.querySelector(`#c64-detach-btn`),k=S?.querySelector(`#c64-reset-btn`),A=S?.querySelector(`#c64-reboot-btn`),j=S?.querySelector(`#c64-disable-crt-preload-checks`),M=window.localStorage.getItem(K)===`1`;this.player?.setCrtPreloadChecksDisabled(M),j&&(j.checked=M,j.addEventListener(`change`,()=>{let e=j.checked;window.localStorage.setItem(K,e?`1`:`0`),this.player?.setCrtPreloadChecksDisabled(e)})),w&&w.addEventListener(`click`,()=>{if(!this.player||typeof this.player.getSnapshot!=`function`)return;let e=document.getElementById(`status`);try{this.downloadSnapshot(this.player.getSnapshot()),e&&(e.textContent=`Snapshot saved`)}catch(t){e&&(e.textContent=`Snapshot save failed: ${String(t?.message??t)}`)}}),T&&T.addEventListener(`click`,()=>{if(!this.player||!confirm(`Detach cartridge?`))return;this.player.detachCartridge();let e=document.getElementById(`status`);e&&(e.textContent=`Cartridge detached`)}),k&&k.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`)}),A&&A.addEventListener(`click`,async()=>{if(!this.player||!confirm(`Perform full reboot? This re-instantiates the emulator with no game loaded.`))return;let e=document.getElementById(`status`);e&&(e.textContent=`Rebooting emulator...`);try{await this.player.reboot(),e&&(e.textContent=`Emulator rebooted (no game loaded)`)}catch(t){e&&(e.textContent=`Reboot failed: ${String(t?.message??t)}`)}});let N=r.querySelector(`#c64-audio-section-anchor`);this.createAudioSection(N);let P=r.querySelectorAll(`input[name="c64-joy-port"]`),F=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{}};P.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&F(Number(e.value))})});let I={joystick:`Arrows + Ctrl = joystick only`,keyboard:`All keys → C64 keyboard matrix`,mixed:`Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard`},L=r.querySelectorAll(`input[name="c64-input-mode"]`),R=r.querySelector(`#c64-input-mode-hint`),z=e=>{if(R&&(R.innerHTML=I[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{}};L.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&z(e.value)})}),this.renderGamepadButtons();let B=r.querySelectorAll(`input[name="c64-display-mode"]`),V=document.getElementById(`c64-screen`),H=e=>{V&&(V.style.width=``,V.style.height=``,V.style.objectFit=``,V.removeAttribute(`data-display-mode`),e===`standard`?(V.style.width=``,V.style.height=``,V.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`?(V.style.height=`100vh`,V.style.width=`auto`,V.style.objectFit=`contain`,V.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`&&(V.style.width=`100vw`,V.style.height=`100vh`,V.style.objectFit=`fill`,V.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`),V.setAttribute(`data-display-mode`,e),window.dispatchEvent(new CustomEvent(`c64-display-mode-changed`,{detail:{mode:e}})))};B.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&H(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=`
|
|
163
|
+
<label>Audio</label>
|
|
164
|
+
<div class="c64-audio-row">
|
|
165
|
+
<button class="c64-mute-btn" id="c64-mute-btn" title="Toggle mute">🔈</button>
|
|
166
|
+
<input type="range" class="c64-volume-slider" id="c64-volume-slider" min="0" max="100" value="75" />
|
|
167
|
+
<span class="c64-volume-label" id="c64-volume-label">75%</span>
|
|
168
|
+
</div>
|
|
169
|
+
`,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`)}},q=document.getElementById(`status`),J=new ne(`c64-screen`),Y=`/c64-ready/`,ue=new URLSearchParams(window.location.search);function de(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 X=de(ue.get(`game`),Y),fe=E(X||``)??`crt`,Z=new P({wasmUrl:`${Y}c64.wasm`,gameUrl:X,gameType:fe,renderer:J,onProgress:(e,t)=>J.setProgress(e,t)});new le().init(Z),Z.start().then(()=>{X||(q.textContent=`Autoload disabled (?game=null)`,q.style.color=`#9ecbff`),J.hideLoader()}).catch(e=>{console.error(e),J.setError(`ERROR`),q.textContent=`Error: ${$(String(e))}`,q.style.color=`#f44`});var Q=()=>{let e=document.hidden,t=document.querySelector(`link[rel~='icon']`),n=`${Y}${e?`led-off.svg`:`led-on.svg`}`.replace(/\/+/g,`/`);t&&(t.href=n)};document.addEventListener(`visibilitychange`,Q),window.addEventListener(`focus`,Q),window.addEventListener(`blur`,Q),Q(),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{J.showLoader(),await Z.loadFile(n,T(i)?i:void 0),J.hideLoader()}catch(e){console.error(e),J.setError(`LOAD ERROR`),q.textContent=`Load error: ${$(String(e))}`,q.style.color=`#f44`}}),window.addEventListener(`c64-controller-connected`,e=>{let t=e.detail;q.textContent=`Controller Connected: ${t.index} - ${t.name}`,q.style.color=`#9ecbff`}),window.addEventListener(`c64-controller-disconnected`,e=>{let t=e.detail;q.textContent=`Controller Disconnected : ${t.index} - ${t.name}`,q.style.color=`#9ecbff`}),window.addEventListener(`c64-load-tool`,async e=>{let t=e.detail;if(!t?.url)return;let n=T(t.type)?t.type:void 0;try{q.textContent=`Loading tool: ${t.name??t.url}`,q.style.color=`#9ecbff`,J.showLoader(),await Z.loadTool(t.url,n),J.hideLoader()}catch(e){console.error(e),J.setError(`LOAD ERROR`),q.textContent=`Tool load error: ${$(String(e))}`,q.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),J.setError(`LOAD ERROR`),q.textContent=`Load error: ${n}`,q.style.color=`#f44`}),window.addEventListener(`c64-load-info`,e=>{let t=e.detail;t?.message&&(q.textContent=t.message,q.style.color=t.mode===`warning`?`#f9c74f`:`#9ecbff`,console.info(`C64 load info event:`,t))}),window.addEventListener(`c64-reboot`,()=>{q.textContent=`Emulator rebooted. Load a cartridge to continue.`,q.style.color=`#9ecbff`,J.hideLoader(0)});function $(e){let t=String(e??``).trim();for(;/^(uncaught\s+)?error\s*:\s*/i.test(t);)t=t.replace(/^(uncaught\s+)?error\s*:\s*/i,``).trim();return t||`Unknown load error`}
|
package/dist/index.html
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
font-size: 13px;
|
|
30
30
|
}
|
|
31
31
|
</style>
|
|
32
|
-
<script type="module" crossorigin src="/c64-ready/assets/index-
|
|
32
|
+
<script type="module" crossorigin src="/c64-ready/assets/index-Bk-mEPYS.js"></script>
|
|
33
33
|
</head>
|
|
34
34
|
<body>
|
|
35
35
|
<canvas id="c64-screen" width="384" height="272"></canvas>
|
|
@@ -62,8 +62,9 @@ export declare class C64Player {
|
|
|
62
62
|
setVoiceEnabled(voice: number, enabled: boolean): void;
|
|
63
63
|
setCrtPreloadChecksDisabled(disabled: boolean): void;
|
|
64
64
|
private autoRunPrgIfRunning;
|
|
65
|
+
private insertTextIntoKeyboardBuffer;
|
|
66
|
+
private waitForKeyboardBufferEmpty;
|
|
65
67
|
private insertGameData;
|
|
66
|
-
private typeCommand;
|
|
67
68
|
private emitSnapshotLoadInfo;
|
|
68
69
|
private assertSnapshotFormatSupported;
|
|
69
70
|
private attachInputAndRenderer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c64-player.d.ts","sourceRoot":"","sources":["../../src/player/c64-player.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"c64-player.d.ts","sourceRoot":"","sources":["../../src/player/c64-player.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAItE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAQxE,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,UAAU,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,MAAM,CAAC;IAClE,UAAU,CAAC,EAAE,M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AO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB9B;;;OAGG;IACH,uBAAuB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAIjD;;;;;;OAMG;IACH,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI;IAInC,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI1C,qBAAqB,IAAI,MAAM;IAI/B,WAAW,IAAI,UAAU,CAAC,eAAe,CAAC;IAO1C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI/B,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAItD,2BAA2B,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;YAKtC,mBAAmB;YAMnB,4BAA4B;YAe5B,0BAA0B;YAU1B,cAAc;IAiC5B,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,6BAA6B;IAwBrC,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,sBAAsB;CA+B/B"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { C64Emulator } from '../emulator/c64-emulator.js';
|
|
2
|
-
import { domKeyToC64Actions } from '../emulator/input.js';
|
|
3
2
|
import { getUnsupportedCrtReason, parseCrtInfo } from '../emulator/crt-info.js';
|
|
4
3
|
import { AudioEngine } from './audio-engine.js';
|
|
5
4
|
import InputHandler from './input-handler.js';
|
|
6
5
|
import { getLoadTypeLabel, inferLoadTypeFromFilename } from './load-formats.js';
|
|
6
|
+
const C64_KEYBOARD_BUFFER_LENGTH_ADDR = 0x00c6;
|
|
7
|
+
const C64_KEYBOARD_BUFFER_ADDR = 0x0277;
|
|
8
|
+
const C64_KEYBOARD_BUFFER_MAX_LENGTH = 8;
|
|
9
|
+
const PRG_AUTORUN_DELAY_MS = 650;
|
|
10
|
+
const PRG_AUTORUN_BUFFER_TIMEOUT_MS = 2000;
|
|
7
11
|
export class C64Player {
|
|
8
12
|
emulator = null;
|
|
9
13
|
inputHandler = null;
|
|
@@ -254,8 +258,30 @@ export class C64Player {
|
|
|
254
258
|
async autoRunPrgIfRunning() {
|
|
255
259
|
if (!this.emulator || !this.emulator.isRunning())
|
|
256
260
|
return;
|
|
257
|
-
await waitMs(
|
|
258
|
-
await this.
|
|
261
|
+
await waitMs(PRG_AUTORUN_DELAY_MS);
|
|
262
|
+
await this.insertTextIntoKeyboardBuffer('run\n');
|
|
263
|
+
}
|
|
264
|
+
async insertTextIntoKeyboardBuffer(text) {
|
|
265
|
+
if (!this.emulator)
|
|
266
|
+
return;
|
|
267
|
+
const bytes = normaliseKeyboardBufferText(text);
|
|
268
|
+
while (bytes.length > 0) {
|
|
269
|
+
await this.waitForKeyboardBufferEmpty();
|
|
270
|
+
const chunk = bytes.splice(0, C64_KEYBOARD_BUFFER_MAX_LENGTH);
|
|
271
|
+
this.emulator.cpuWrite(C64_KEYBOARD_BUFFER_LENGTH_ADDR, chunk.length);
|
|
272
|
+
for (let i = 0; i < chunk.length; i += 1) {
|
|
273
|
+
this.emulator.cpuWrite(C64_KEYBOARD_BUFFER_ADDR + i, chunk[i]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async waitForKeyboardBufferEmpty() {
|
|
278
|
+
const startedAt = Date.now();
|
|
279
|
+
while (this.emulator?.cpuRead(C64_KEYBOARD_BUFFER_LENGTH_ADDR)) {
|
|
280
|
+
if (Date.now() - startedAt >= PRG_AUTORUN_BUFFER_TIMEOUT_MS) {
|
|
281
|
+
throw new Error('Timed out waiting for C64 keyboard buffer before PRG auto-run');
|
|
282
|
+
}
|
|
283
|
+
await waitMs(50);
|
|
284
|
+
}
|
|
259
285
|
}
|
|
260
286
|
async insertGameData(data, type, source, eventDetail, onProgress) {
|
|
261
287
|
if (!this.emulator)
|
|
@@ -282,29 +308,6 @@ export class C64Player {
|
|
|
282
308
|
throw err;
|
|
283
309
|
}
|
|
284
310
|
}
|
|
285
|
-
async typeCommand(command) {
|
|
286
|
-
if (!this.emulator)
|
|
287
|
-
return;
|
|
288
|
-
for (const char of command) {
|
|
289
|
-
const domKey = char === '\n' ? 'enter' : char;
|
|
290
|
-
const down = domKeyToC64Actions(domKey, false, 'keydown');
|
|
291
|
-
for (const act of down) {
|
|
292
|
-
if (act.action === 'press')
|
|
293
|
-
this.emulator.keyDown(act.key);
|
|
294
|
-
else
|
|
295
|
-
this.emulator.keyUp(act.key);
|
|
296
|
-
}
|
|
297
|
-
await waitMs(22);
|
|
298
|
-
const up = domKeyToC64Actions(domKey, false, 'keyup');
|
|
299
|
-
for (const act of up) {
|
|
300
|
-
if (act.action === 'press')
|
|
301
|
-
this.emulator.keyDown(act.key);
|
|
302
|
-
else
|
|
303
|
-
this.emulator.keyUp(act.key);
|
|
304
|
-
}
|
|
305
|
-
await waitMs(22);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
311
|
emitSnapshotLoadInfo(type, source) {
|
|
309
312
|
if (type !== 'snapshot')
|
|
310
313
|
return;
|
|
@@ -385,6 +388,15 @@ function formatLoadProgressLabel(type) {
|
|
|
385
388
|
function waitMs(ms) {
|
|
386
389
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
387
390
|
}
|
|
391
|
+
function normaliseKeyboardBufferText(text) {
|
|
392
|
+
const bytes = [];
|
|
393
|
+
const normalised = text.toUpperCase().replace(/\r\n/g, '\n');
|
|
394
|
+
for (let i = 0; i < normalised.length; i += 1) {
|
|
395
|
+
const code = normalised.charCodeAt(i);
|
|
396
|
+
bytes.push(code === 10 ? 13 : code);
|
|
397
|
+
}
|
|
398
|
+
return bytes;
|
|
399
|
+
}
|
|
388
400
|
function normaliseGameData(gameData) {
|
|
389
401
|
if (gameData instanceof Uint8Array) {
|
|
390
402
|
return gameData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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version": "2.1.
|
|
13
|
+
"version": "2.1.1",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=24.14"
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"start": "npm run dev",
|
|
20
20
|
"dev": "vite",
|
|
21
|
-
"build": "tsc && vite build",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
21
|
+
"build": "tsc && vite build && npm run api:build",
|
|
22
|
+
"api:build": "node -e \"require('node:fs').rmSync('dist-ts',{recursive:true,force:true})\" && npx tsc -p tsconfig.build.json && node tools/fix-esm-imports.mjs",
|
|
23
|
+
"headless:build": "npx tsc -p tsconfig.build.json",
|
|
24
|
+
"package:build": "npm run build",
|
|
24
25
|
"headless:start": "node bin/headless.mjs",
|
|
25
26
|
"release": "./tools/release.sh",
|
|
26
27
|
"preview": "vite preview",
|
package/src/player/c64-player.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { C64Emulator } from '../emulator/c64-emulator';
|
|
2
|
-
import { domKeyToC64Actions } from '../emulator/input';
|
|
3
2
|
import { getUnsupportedCrtReason, parseCrtInfo } from '../emulator/crt-info';
|
|
4
3
|
import type { GameLoadOptions } from '../types';
|
|
5
4
|
import type { JoystickPort } from '../emulator/constants';
|
|
@@ -11,6 +10,12 @@ import { getLoadTypeLabel, inferLoadTypeFromFilename } from './load-formats';
|
|
|
11
10
|
|
|
12
11
|
export type ProgressCallback = (percent: number, label: string) => void;
|
|
13
12
|
|
|
13
|
+
const C64_KEYBOARD_BUFFER_LENGTH_ADDR = 0x00c6;
|
|
14
|
+
const C64_KEYBOARD_BUFFER_ADDR = 0x0277;
|
|
15
|
+
const C64_KEYBOARD_BUFFER_MAX_LENGTH = 8;
|
|
16
|
+
const PRG_AUTORUN_DELAY_MS = 650;
|
|
17
|
+
const PRG_AUTORUN_BUFFER_TIMEOUT_MS = 2000;
|
|
18
|
+
|
|
14
19
|
export interface C64PlayerOptions {
|
|
15
20
|
wasmUrl: string;
|
|
16
21
|
gameUrl: string;
|
|
@@ -306,8 +311,33 @@ export class C64Player {
|
|
|
306
311
|
|
|
307
312
|
private async autoRunPrgIfRunning(): Promise<void> {
|
|
308
313
|
if (!this.emulator || !this.emulator.isRunning()) return;
|
|
309
|
-
await waitMs(
|
|
310
|
-
await this.
|
|
314
|
+
await waitMs(PRG_AUTORUN_DELAY_MS);
|
|
315
|
+
await this.insertTextIntoKeyboardBuffer('run\n');
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
private async insertTextIntoKeyboardBuffer(text: string): Promise<void> {
|
|
319
|
+
if (!this.emulator) return;
|
|
320
|
+
|
|
321
|
+
const bytes = normaliseKeyboardBufferText(text);
|
|
322
|
+
while (bytes.length > 0) {
|
|
323
|
+
await this.waitForKeyboardBufferEmpty();
|
|
324
|
+
|
|
325
|
+
const chunk = bytes.splice(0, C64_KEYBOARD_BUFFER_MAX_LENGTH);
|
|
326
|
+
this.emulator.cpuWrite(C64_KEYBOARD_BUFFER_LENGTH_ADDR, chunk.length);
|
|
327
|
+
for (let i = 0; i < chunk.length; i += 1) {
|
|
328
|
+
this.emulator.cpuWrite(C64_KEYBOARD_BUFFER_ADDR + i, chunk[i]);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private async waitForKeyboardBufferEmpty(): Promise<void> {
|
|
334
|
+
const startedAt = Date.now();
|
|
335
|
+
while (this.emulator?.cpuRead(C64_KEYBOARD_BUFFER_LENGTH_ADDR)) {
|
|
336
|
+
if (Date.now() - startedAt >= PRG_AUTORUN_BUFFER_TIMEOUT_MS) {
|
|
337
|
+
throw new Error('Timed out waiting for C64 keyboard buffer before PRG auto-run');
|
|
338
|
+
}
|
|
339
|
+
await waitMs(50);
|
|
340
|
+
}
|
|
311
341
|
}
|
|
312
342
|
|
|
313
343
|
private async insertGameData(
|
|
@@ -343,30 +373,6 @@ export class C64Player {
|
|
|
343
373
|
}
|
|
344
374
|
}
|
|
345
375
|
|
|
346
|
-
private async typeCommand(command: string): Promise<void> {
|
|
347
|
-
if (!this.emulator) return;
|
|
348
|
-
|
|
349
|
-
for (const char of command) {
|
|
350
|
-
const domKey = char === '\n' ? 'enter' : char;
|
|
351
|
-
|
|
352
|
-
const down = domKeyToC64Actions(domKey, false, 'keydown');
|
|
353
|
-
for (const act of down) {
|
|
354
|
-
if (act.action === 'press') this.emulator.keyDown(act.key);
|
|
355
|
-
else this.emulator.keyUp(act.key);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
await waitMs(22);
|
|
359
|
-
|
|
360
|
-
const up = domKeyToC64Actions(domKey, false, 'keyup');
|
|
361
|
-
for (const act of up) {
|
|
362
|
-
if (act.action === 'press') this.emulator.keyDown(act.key);
|
|
363
|
-
else this.emulator.keyUp(act.key);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
await waitMs(22);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
376
|
private emitSnapshotLoadInfo(type: GameLoadOptions['type'], source: string): void {
|
|
371
377
|
if (type !== 'snapshot') return;
|
|
372
378
|
|
|
@@ -474,6 +480,18 @@ function waitMs(ms: number): Promise<void> {
|
|
|
474
480
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
475
481
|
}
|
|
476
482
|
|
|
483
|
+
function normaliseKeyboardBufferText(text: string): number[] {
|
|
484
|
+
const bytes: number[] = [];
|
|
485
|
+
const normalised = text.toUpperCase().replace(/\r\n/g, '\n');
|
|
486
|
+
|
|
487
|
+
for (let i = 0; i < normalised.length; i += 1) {
|
|
488
|
+
const code = normalised.charCodeAt(i);
|
|
489
|
+
bytes.push(code === 10 ? 13 : code);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return bytes;
|
|
493
|
+
}
|
|
494
|
+
|
|
477
495
|
function normaliseGameData(
|
|
478
496
|
gameData: Uint8Array<ArrayBufferLike> | ArrayBufferLike | string,
|
|
479
497
|
): Uint8Array<ArrayBufferLike> {
|
|
@@ -1,169 +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}}}};const t={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 n(e){return e.exrom===1&&e.game===0}function r(e){return n(e)&&e.hwType===0?`Unsupported CRT: Ultimax/MAX cartridges are not supported by this emulator.`:null}function i(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function a(e,t){return(e[t]<<8|e[t+1])>>>0}function o(e,n){if(!e||e.length<64||!String.fromCharCode(...Array.from(e.slice(0,16))).startsWith(`C64 CARTRIDGE`))return null;let r=i(e,16),o=a(e,22),s=e[24],c=e[25],l=``;for(let t=32;t<64&&e[t]!==0;t++)l+=String.fromCharCode(e[t]);l=l.trim();let u;u=s===0&&c===0?`16K (ROML+ROMH)`:s===0&&c===1?`8K (ROML only)`:s===1&&c===0?`Ultimax`:`inactive (pass-through)`;let d=0,f=0,p=Math.max(r,64);for(;p+16<=e.length&&String.fromCharCode(...Array.from(e.slice(p,p+4)))===`CHIP`;){let t=i(e,p+4);if(t<16)break;let n=a(e,p+14);d++,f+=n,p+=t}let m=t[o]??`Unknown(${o})`,h=n?` "${n}"`:``,g=l?` name="${l}"`:``,_=(f/1024).toFixed(0);return{line:`[C64 cart]${h} loading: hwType=${o}(${m}) | ${u} flags, ${_}K actual | ${d} CHIP(s) | ${e.length} bytes${g}`,hwType:o,hwName:m,exrom:s,game:c,bankConfig:u,cartName:l,chipCount:d,totalRomBytes:f}}var s=384,c=272,l=44100,u=class t{wasm;wasmUrl;config;running=!1;frameCount=0;crtPreloadChecksEnabled=!0;onFrame;onAudio;constructor(e,t,n={}){this.wasm=e,this.wasmUrl=t,this.config={videoWidth:s,videoHeight:c,sampleRate:l,audioChannels:1,cyclesPerFrame:50,...n}}static async load(n=`/src/emulator/c64.wasm`,r={}){let i=new t(await e.load(n),n,r);return i.init(),i}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}async reboot(){let t=this.running,n=await e.load(this.wasmUrl);this.running=!1,this.wasm=n,this.frameCount=0,this.init(),t&&this.start()}setCrtPreloadChecksEnabled(e){this.crtPreloadChecksEnabled=e}static AUDIO_BUFFER_SIZE=4096;tick(e=0){if(!this.running)return;let t=this.wasm.exports,n=t.debugger_update(e);if(this.frameCount++,n&&this.onFrame){let e=t.c64_getPixelBuffer(),n=this.wasm.heap.heapU8.subarray(e,e+s*c*4);this.onFrame({width:s,height:c,data:n,timestamp:this.frameCount})}}loadGame(e){let t=this.wasm.exports;if(!t||!this.wasm.heap)throw Error(`WASM not ready`);if(e.type===`snapshot`){t.c64_reset();let n=this.wasm.allocAndWrite(e.data);try{this.loadSnapshotData(n,e.data.length)}finally{this.wasm.free(n)}return}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`:if(this.crtPreloadChecksEnabled){let t=o(e.data);if(!t)throw Error(`Invalid CRT file format`);let n=r(t);if(n)throw Error(n)}t.c64_loadCartridge(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)}setMousePortEnabled(e,t){this.wasm.exports?.c64_set_mouse_port_enabled(e-1,t?1:0)}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}cpuReadNS(e){return this.wasm.exports?.c64_cpuReadNS(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:s,height:c,data:this.wasm.heap.heapU8.slice(e,e+s*c*4),timestamp:this.frameCount}}getSnapshot(){let e=this.wasm.exports;if(!e||!this.wasm.heap)throw Error(`WASM not ready`);let t=e.c64_getSnapshot(),n=e.c64_getSnapshotSize();return this.wasm.heap.heapU8.slice(t,t+n)}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 n=e.sid_getAudioBuffer();return new Float32Array(this.wasm.heap.heapF32.subarray(n>>2,(n>>2)+t.AUDIO_BUFFER_SIZE))}setSIDModel(e){this.wasm.exports?.sid_setModel(e)}setVoiceEnabled(e,t){this.wasm.exports?.sid_setVoiceEnabled(e,t?1:0)}setDriveEnabled(e){this.wasm.exports?.c64_setDriveEnabled(e?1:0)}getDriveEnabled(){return(this.wasm.exports?.c64_getDriveEnabled()??0)!==0}};const d={UP:1,DOWN:2,LEFT:4,RIGHT:8},f={ArrowUp:d.UP,ArrowDown:d.DOWN,ArrowLeft:d.LEFT,ArrowRight:d.RIGHT,ControlLeft:16},p=Object.keys(f),m={ArrowUp:d.UP,ArrowDown:d.DOWN,ArrowLeft:d.LEFT,ArrowRight:d.RIGHT,KeyZ:16,KeyX:32,KeyC:64,ControlLeft:16},h={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 g(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(h.SHIFT_LEFT):r!==`arrowup`&&r!==`arrowleft`&&(s(h.SHIFT_LEFT),s(h.SHIFT_RIGHT))),r){case`a`:c(h.A);break;case`b`:c(h.B);break;case`c`:c(h.C);break;case`d`:c(h.D);break;case`e`:c(h.E);break;case`f`:c(h.F);break;case`g`:c(h.G);break;case`h`:c(h.H);break;case`i`:c(h.I);break;case`j`:c(h.J);break;case`k`:c(h.K);break;case`l`:c(h.L);break;case`m`:c(h.M);break;case`n`:c(h.N);break;case`o`:c(h.O);break;case`p`:c(h.P);break;case`q`:c(h.Q);break;case`r`:c(h.R);break;case`s`:c(h.S);break;case`t`:c(h.T);break;case`u`:c(h.U);break;case`v`:c(h.V);break;case`w`:c(h.W);break;case`x`:c(h.X);break;case`y`:c(h.Y);break;case`z`:c(h.Z);break;case`0`:c(h.ZERO);break;case`1`:c(h.ONE);break;case`2`:c(h.TWO);break;case`3`:c(h.THREE);break;case`4`:c(h.FOUR);break;case`5`:c(h.FIVE);break;case`6`:c(h.SIX);break;case`7`:c(h.SEVEN);break;case`8`:c(h.EIGHT);break;case`9`:c(h.NINE);break;case`!`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.ONE);break;case`"`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.TWO);break;case`#`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.THREE);break;case`$`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.FOUR);break;case`%`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.FIVE);break;case`&`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.SIX);break;case`'`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.SEVEN);break;case`(`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.EIGHT);break;case`)`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.NINE);break;case` `:c(h.SPACE);break;case`enter`:c(h.RETURN);break;case`backspace`:case`delete`:c(h.INS_DEL);break;case`escape`:c(h.RUN_STOP);break;case`-`:c(h.MINUS);break;case`=`:c(h.EQUALS);break;case`+`:i&&(s(h.SHIFT_LEFT),s(h.SHIFT_RIGHT)),c(h.PLUS);break;case`*`:i&&(s(h.SHIFT_LEFT),s(h.SHIFT_RIGHT)),c(h.STAR);break;case`@`:i&&(s(h.SHIFT_LEFT),s(h.SHIFT_RIGHT)),c(h.AT);break;case`^`:i&&(s(h.SHIFT_LEFT),s(h.SHIFT_RIGHT)),c(h.ARROW_UP);break;case"`":c(h.ARROW_LEFT);break;case`~`:c(h.ARROW_UP);break;case`\\`:c(h.POUND);break;case`,`:case`<`:c(h.COMMA);break;case`.`:case`>`:c(h.PERIOD);break;case`/`:case`?`:c(h.SLASH);break;case`;`:c(h.SEMICOLON);break;case`:`:i&&(s(h.SHIFT_LEFT),s(h.SHIFT_RIGHT)),c(h.COLON);break;case`[`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.COLON);break;case`]`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.SEMICOLON);break;case`shift`:c(h.SHIFT_LEFT);break;case`tab`:c(h.CTRL);break;case`control`:c(h.COMMODORE);break;case`capslock`:c(h.COMMODORE);break;case`home`:c(h.CLEAR_HOME);break;case`pageup`:c(h.RESTORE);break;case`f1`:c(h.F1);break;case`f2`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.F1);break;case`f3`:c(h.F3);break;case`f4`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.F3);break;case`f5`:c(h.F5);break;case`f6`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.F5);break;case`f7`:c(h.F7);break;case`f8`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.F7);break;case`arrowdown`:c(h.CURSOR_UP_DOWN);break;case`arrowup`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.CURSOR_UP_DOWN);break;case`arrowright`:c(h.CURSOR_LEFT_RIGHT);break;case`arrowleft`:i?o(h.SHIFT_LEFT):s(h.SHIFT_LEFT),c(h.CURSOR_LEFT_RIGHT);break;default:break}return a}var _=128,v=0,y=class{emulator;target;joystickPort;inputMode=`mixed`;updateFrame=-1;gamepadIndex=-1;gamepadPresses=[];gamepadAxes=[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1,!1];potFire2Pressed=!1;potFire3Pressed=!1;pressedControls=new Set;keyDownHandler=e=>{this.handleKeyDown(e)};keyUpHandler=e=>{this.handleKeyUp(e)};gamepadConnectedHandler=e=>{this.handleGamepadConnected(e)};gamepadDisconnectedHandler=e=>{this.handleGamepadDisconnected(e)};constructor(e,t=window,n=2){this.emulator=e,this.target=t,this.joystickPort=n}attach(){this.target.addEventListener(`gamepadconnected`,this.gamepadConnectedHandler),this.target.addEventListener(`gamepaddisconnected`,this.gamepadDisconnectedHandler),this.target.addEventListener(`keydown`,this.keyDownHandler),this.target.addEventListener(`keyup`,this.keyUpHandler)}detach(){this.target.removeEventListener(`gamepadconnected`,this.gamepadConnectedHandler),this.target.removeEventListener(`gamepaddisconnected`,this.gamepadDisconnectedHandler),this.target.removeEventListener(`keydown`,this.keyDownHandler),this.target.removeEventListener(`keyup`,this.keyUpHandler),this.releaseAll(),this.releaseAllGamepadButtons(),this.cancelUpdate()}step(){let e=navigator.getGamepads();if(!e)return;let t=e[this.gamepadIndex];if(!t){this.cancelUpdate();return}if(t.buttons){for(let e=0;e<t.buttons.length;e++)if(t.buttons[e].pressed)switch(this.gamepadPresses[e]=!0,console.log(`Buttons Pressed`,e,t.buttons[e]),e){case 0:this.emulator.joystickPush(this.joystickPort,16);break;case 1:this.emulator.joystickPush(this.joystickPort,d.UP);break;case 2:this.emulator.keyDown(h.SPACE);break;case 3:break;case 7:case 9:this.emulator.keyDown(h.RUN_STOP);break;case 14:this.emulator.joystickPush(this.joystickPort,d.LEFT);break;case 15:this.emulator.joystickPush(this.joystickPort,d.RIGHT);break;case 12:this.emulator.joystickPush(this.joystickPort,d.UP);break;case 13:this.emulator.joystickPush(this.joystickPort,d.DOWN);break}else if(!t.buttons[e].pressed&&this.gamepadPresses[e]===!0)switch(this.gamepadPresses[e]=!1,e){case 0:this.emulator.joystickRelease(this.joystickPort,16);break;case 1:this.emulator.joystickRelease(this.joystickPort,d.UP);break;case 2:this.emulator.keyUp(h.SPACE);break;case 3:break;case 7:case 9:this.emulator.keyUp(h.RUN_STOP);break;case 14:this.emulator.joystickRelease(this.joystickPort,d.LEFT);break;case 15:this.emulator.joystickRelease(this.joystickPort,d.RIGHT);break;case 12:this.emulator.joystickRelease(this.joystickPort,d.UP);break;case 13:this.emulator.joystickRelease(this.joystickPort,d.DOWN);break}}t.axes[0]<=-.5||t.axes[6]<=-.5?(this.gamepadAxes[0]=!0,this.emulator.joystickPush(this.joystickPort,d.LEFT)):this.gamepadAxes[0]===!0&&(this.gamepadAxes[0]=!1,this.emulator.joystickRelease(this.joystickPort,d.LEFT)),t.axes[0]>=.5||t.axes[6]>=.5?(this.emulator.joystickPush(this.joystickPort,d.RIGHT),this.gamepadAxes[1]=!0):this.gamepadAxes[1]===!0&&(this.emulator.joystickRelease(this.joystickPort,d.RIGHT),this.gamepadAxes[1]=!1),t.axes[1]<=-.5||t.axes[7]<=-.5?(this.emulator.joystickPush(this.joystickPort,d.UP),this.gamepadAxes[2]=!0):this.gamepadAxes[2]===!0&&(this.emulator.joystickRelease(this.joystickPort,d.UP),this.gamepadAxes[2]=!1),t.axes[1]>=.5||t.axes[7]>=.5?(this.emulator.joystickPush(this.joystickPort,d.DOWN),this.gamepadAxes[3]=!0):this.gamepadAxes[3]===!0&&(this.emulator.joystickRelease(this.joystickPort,d.DOWN),this.gamepadAxes[3]=!1),this.updateFrame=requestAnimationFrame(this.step.bind(this))}cancelUpdate(){cancelAnimationFrame(this.updateFrame),this.updateFrame=-1,this.gamepadIndex=-1}releaseAllGamepadButtons(){if(!this.gamepadPresses.some(Boolean))return;let e={0:16,2:32,3:64,12:d.UP,13:d.DOWN,14:d.LEFT,15:d.RIGHT};for(let[t,n]of Object.entries(e))n&&this.gamepadPresses[Number(t)]===!0&&this.releaseJoystickInput(n);this.gamepadPresses=[]}findConnectedGamepadIndex(e){let t=navigator.getGamepads?.()??[];for(let n of t)if(n&&n.index!==e)return n.index;return-1}handleGamepadDisconnected(e){if(console.log(`Gamepad disconnected from index %d: %s`,e.gamepad.index,e.gamepad.id),this.gamepadIndex===e.gamepad.index){this.releaseAllGamepadButtons();let t=this.findConnectedGamepadIndex(e.gamepad.index);t>=0?(this.gamepadIndex=t,this.updateFrame<0&&this.step()):this.cancelUpdate()}let t=new CustomEvent(`c64-controller-disconnected`,{detail:{name:e.gamepad.id,index:e.gamepad.index}});this.target.dispatchEvent(t)}handleGamepadConnected(e){console.log(`Gamepad connected at index %d: %s. %d buttons, %d axes.`,e.gamepad.index,e.gamepad.id,e.gamepad.buttons.length,e.gamepad.axes.length),this.gamepadIndex<0&&(this.gamepadIndex=e.gamepad.index);let t=new CustomEvent(`c64-controller-connected`,{detail:{name:e.gamepad.id,index:e.gamepad.index}});this.target.dispatchEvent(t),this.updateFrame<0&&this.step()}handleKeyDown(e){if(this.inputMode===`keyboard`){let t=g(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 m){let t=m[e.code];this.pushJoystickInput(t),e.preventDefault()}else{let t=g(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.pushJoystickInput(f[t]),e.preventDefault())}handleKeyUp(e){if(this.inputMode===`keyboard`){let t=g(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 m){let t=m[e.code];this.releaseJoystickInput(t),e.preventDefault()}else{let t=g(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.releaseJoystickInput(f[t]),e.preventDefault())}getMappedControl(e){return e.code in f?e.code:null}pushJoystickInput(e){if(e===32){this.potFire2Pressed=!0,this.syncPotFireButtons();return}if(e===64){this.potFire3Pressed=!0,this.syncPotFireButtons();return}this.emulator.joystickPush(this.joystickPort,e)}releaseJoystickInput(e){if(e===32){this.potFire2Pressed=!1,this.syncPotFireButtons();return}if(e===64){this.potFire3Pressed=!1,this.syncPotFireButtons();return}this.emulator.joystickRelease(this.joystickPort,e)}releaseAll(){for(let e of this.pressedControls)this.releaseJoystickInput(f[e]);this.pressedControls.clear(),this.potFire2Pressed=!1,this.potFire3Pressed=!1,this.syncPotFireButtons()}syncPotFireButtons(){if(!this.potFire2Pressed&&!this.potFire3Pressed){this.emulator.setMousePortEnabled?.(this.joystickPort,!1);return}this.emulator.setMousePortEnabled?.(this.joystickPort,!0),this.emulator.mousePosition?.(this.potFire2Pressed?v:_,this.potFire3Pressed?v:_)}setKeyboardPort(e){this.joystickPort!==e&&(this.releaseAll(),this.releaseAllGamepadButtons(),this.joystickPort=e)}setInputMode(e){this.inputMode!==e&&(this.releaseAll(),this.releaseAllGamepadButtons(),this.inputMode=e)}getInputMode(){return this.inputMode}setActiveGamepadIndex(e){if(this.gamepadIndex!==e){if(!(navigator.getGamepads?.()??[])[e])throw Error(`Gamepad ${e} is not connected`);this.releaseAllGamepadButtons(),this.gamepadIndex=e,this.updateFrame<0&&this.step()}}getActiveGamepadIndex(){return this.gamepadIndex}},b=44100,x=class{ctx=null;workletNode=null;gainNode=null;_muted=!1;_volume=.75;_suspended=!0;_initialised=!1;_ready=!1;options;_readSidBuffer=null;onStateChange;constructor(e={}){this.options=e}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??b}async init(){if(this._initialised)return!this._suspended;this._initialised=!0;try{return this.ctx=new AudioContext({sampleRate:b}),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=this.options.assetBaseUrl??`/`,t=this.options.workletUrl??`${e.replace(/\/+$/,``)}/audio-worklet-processor.js`;await this.ctx.audioWorklet.addModule(t),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})}},S=class{emulatorInput;captureKeyDown=e=>this.onCaptureKeyDown(e);captureKeyUp=e=>this.onCaptureKeyUp(e);constructor(e,t=window){this.emulatorInput=new y(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()}setActiveGamepadIndex(e){this.emulatorInput.setActiveGamepadIndex(e)}getActiveGamepadIndex(){return this.emulatorInput.getActiveGamepadIndex()}onCaptureKeyDown(e){if(new Set([...p,...Object.keys(m)]).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([...p,...Object.keys(m)]).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 C=[{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 w=new Set(C.map(e=>e.type));function T(e){return typeof e==`string`&&w.has(e)}function E(e){let t=e.toLowerCase();for(let e of C)if(e.extensions.some(e=>t.endsWith(e)))return e.type;return null}function ee(e,t,n=`crt`){return e===`auto`?E(t)??n:e}function te(e){return(e===`auto`?C.flatMap(e=>e.extensions):C.find(t=>t.type===e)?.extensions??[]).join(`,`)}function D(e){return C.find(t=>t.type===e)?.label??e.toUpperCase()}var O=class{emulator=null;inputHandler=null;disableCrtPreloadChecks=!1;destroyed=!1;audio;options;constructor(e){this.options={gameType:`crt`,...e},this.audio=new x(e.audio)}async start(){this.destroyed=!1;let{wasmUrl:e,gameUrl:t,gameData:n,gameSource:r,gameType:i,renderer:a,onProgress:o}=this.options;o?.(10,`INITIALISING WASM...`),this.emulator=await u.load(e),this.emulator.setCrtPreloadChecksEnabled(!this.disableCrtPreloadChecks),this.attachInputAndRenderer(this.emulator,a);let s=!1;n==null?t&&t!==`null`&&(await this.loadGame(t,i,o),s=i===`prg`):(await this.loadGameData(n,i,r??`inline game data`,o),s=i===`prg`),this.emulator.start(),s&&await this.autoRunPrgIfRunning(),this.initAudio()}initAudio(){this.emulator&&(this.audio.onStateChange=e=>{window.dispatchEvent(new CustomEvent(`c64-audio-state`,{detail:e}))},this.audio.init().then(e=>{this.emulator&&(this.emulator.setSampleRate(this.audio.sampleRate),this.audio.setSidBufferReader(()=>this.emulator?.getSidBuffer()??null),e||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());n?.(90,`INSERTING ${A(t)}...`),await this.insertGameData(a,t,e,{url:e},n)}async loadGameData(e,t=`crt`,n=`inline game data`,r=this.options.onProgress){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);r?.(20,`LOADING GAME DATA...`);let i=M(e);r?.(90,`INSERTING ${A(t)}...`),await this.insertGameData(i,t,n,{source:n},r)}async loadFile(e,t){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);let n=this.options.onProgress,r=t??E(e.name)??`crt`;try{n?.(20,`READING FILE ${e.name}...`);let t=await e.arrayBuffer(),i=new Uint8Array(t);n?.(90,`INSERTING ${A(r)}...`),await this.insertGameData(i,r,e.name,{file:e.name},n),window.dispatchEvent(new CustomEvent(`c64-close-dialog`,{detail:{file:e.name,type:r}}))}catch(e){throw n?.(0,`FAILED`),e}}async loadTool(e,t){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);let n=this.options.onProgress,r=t??E(e)??`prg`;n?.(10,`PREPARING TOOL...`);try{this.emulator.removeCartridge()}catch{}this.emulator.reset(),this.emulator.start(),await j(120),await this.loadGame(e,r,n)}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)}}async reboot(){if(this.emulator)try{await this.emulator.reboot(),this.attachInputAndRenderer(this.emulator,this.options.renderer),this.emulator.start(),this.emulator.setSampleRate(this.audio.sampleRate),this.audio.setSidBufferReader(()=>this.emulator?.getSidBuffer()??null),window.dispatchEvent(new CustomEvent(`c64-reboot`,{detail:{}})),window.dispatchEvent(new CustomEvent(`c64-close-menu`))}catch(e){throw console.error(`Failed to reboot emulator:`,e),e}}async destroy(){if(!this.destroyed){this.destroyed=!0;try{this.emulator?.pause()}finally{this.inputHandler?.detach(),this.inputHandler=null,this.options.renderer.detach(),this.audio.onStateChange=void 0,this.audio.setSidBufferReader(()=>null),await this.audio.destroy(),this.emulator=null}}}setKeyboardJoystickPort(e){this.inputHandler?.setKeyboardJoystickPort(e)}setInputMode(e){this.inputHandler?.setInputMode(e)}setActiveGamepadIndex(e){this.inputHandler?.setActiveGamepadIndex(e)}getActiveGamepadIndex(){return this.inputHandler?.getActiveGamepadIndex()??-1}getSnapshot(){if(!this.emulator)throw Error(`Emulator not initialised`);return this.emulator.getSnapshot()}ramRead(e){return this.emulator?.ramRead(e)??0}cpuRead(e){return this.emulator?.cpuRead(e)??0}cpuReadNS(e){return this.emulator?.cpuReadNS(e)??0}setVoiceEnabled(e,t){this.emulator?.setVoiceEnabled(e,t)}setCrtPreloadChecksDisabled(e){this.disableCrtPreloadChecks=e,this.emulator?.setCrtPreloadChecksEnabled(!e)}async autoRunPrgIfRunning(){!this.emulator||!this.emulator.isRunning()||(await j(220),await this.typeCommand(`run
|
|
2
|
-
`))}async insertGameData(e,t,n,r,i){if(!this.emulator)throw Error(`Emulator not initialised — call start() first`);this.assertSnapshotFormatSupported(e,t,n),this.emitSnapshotLoadInfo(t,n);try{t===`crt`&&this.handleCrtPreloadChecks(e,n,i),this.emulator.loadGame({type:t,data:e}),t===`prg`&&await this.autoRunPrgIfRunning(),i?.(100,`READY!`),window.dispatchEvent(new CustomEvent(`c64-load-success`,{detail:{...r,type:t}}))}catch(e){throw i?.(0,`FAILED`),console.error(`Failed to insert cartridge or load game:`,e),window.dispatchEvent(new CustomEvent(`c64-load-error`,{detail:{error:e instanceof Error?e.message:String(e),...r,type:t}})),e}}async typeCommand(e){if(this.emulator)for(let t of e){let e=t===`
|
|
3
|
-
`?`enter`:t,n=g(e,!1,`keydown`);for(let e of n)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);await j(22);let r=g(e,!1,`keyup`);for(let e of r)e.action===`press`?this.emulator.keyDown(e.key):this.emulator.keyUp(e.key);await j(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`||!F(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}attachInputAndRenderer(e,t){this.inputHandler?.detach(),this.inputHandler=new S(e),this.inputHandler.attach(),t.attachTo(e)}handleCrtPreloadChecks(e,t,n){if(!this.disableCrtPreloadChecks){k(e,t,n);return}let i=o(e,t);if(!i)return;console.log(i.line);let a=r(i);a&&(n?.(90,`UNSAFE CRT LOAD`),console.warn(`${a} Proceeding because preload checks are disabled.`),window.dispatchEvent(new CustomEvent(`c64-load-info`,{detail:{mode:`warning`,source:t,message:`Preload checks are disabled. This cartridge is normally flagged as incompatible and may hang the emulator.`}})))}};function k(e,t,n){let i=o(e,t);if(!i){n?.(0,`INVALID CRT`);let e=Error(`Invalid CRT file format`);throw console.error(e),e}console.log(i.line);let a=r(i);if(a){n?.(0,`UNSUPPORTED CRT`);let e=Error(a);throw console.error(e),e}}function A(e){let t=D(e),n=t.indexOf(` (`);return(n>0?t.slice(0,n):t).toUpperCase()}function j(e){return new Promise(t=>setTimeout(t,e))}function M(e){if(e instanceof Uint8Array)return e;if(typeof e!=`string`)return new Uint8Array(e);let t=e.trim(),n=t.match(/^data:[^,]*;base64,(.*)$/s),r=n?n[1]:t;return n||P(r)?N(globalThis.atob(r.replace(/\s/g,``))):N(e)}function N(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t}function P(e){let t=e.replace(/\s/g,``);return t.length>0&&t.length%4==0&&/^[A-Za-z0-9+/]+={0,2}$/.test(t)}function F(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 I=`
|
|
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
|
-
`,L=class{canvas;ctx;animationFrameId=null;attachedEmulator=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=I,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){this.detach(),this.attachedEmulator=e,e.onFrame=e=>{this.render(e)};let t=0,n=r=>{let i=t?r-t:0;t=r,e.tick(i),this.animationFrameId=requestAnimationFrame(n)};this.animationFrameId=requestAnimationFrame(n)}detach(){this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.attachedEmulator&&=(this.attachedEmulator.onFrame=void 0,null)}},R=`modulepreload`,z=function(e){return`/c64-ready/`+e},B={};const V=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=z(t,n),t in B)return;B[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,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 ne=`
|
|
44
|
-
.c64-help-btn,.c64-hamburger,.c64-unmute-btn{position:fixed;top:12px;width:36px;height:36px;border-radius:6px;border:2px solid #444;background:#111;color:#ddd;cursor:pointer;display:flex;align-items:center;justify-content:center;z-index:1000}.c64-help-btn{right:12px;border-radius:50%;color:#7b71d5;font-family:monospace;font-size:18px;font-weight:bold}.c64-hamburger{left:12px;font-family:monospace}.c64-unmute-btn{left:56px;color:#f44;z-index:1010}.c64-unmute-btn.hidden{opacity:0;pointer-events:none}.c64-help-overlay,.c64-menu-overlay{position:fixed;inset:0;background:rgba(0,0,0,.7);display:flex;align-items:center;justify-content:center;z-index:1001;opacity:0;transition:opacity .25s ease;pointer-events:none}.c64-help-overlay.visible,.c64-menu-overlay.visible{opacity:1;pointer-events:auto}.c64-help-dialog,.c64-menu-panel{background:#1a1a2e;border:2px solid #555;border-radius:6px;padding:24px 32px;max-width:760px;width:90%;font-family:monospace;color:#ccc;position:relative}.c64-changelog-dialog{max-height:70vh;overflow:auto}.c64-help-dialog h2{margin:0 0 8px;font-size:16px;color:#7b71d5;letter-spacing:1px}.c64-help-dialog p{margin:0 0 16px;font-size:13px;line-height:1.5;color:#aaa}.c64-help-dialog a{color:#a8a8ff;text-decoration:none}.c64-help-controls,.c64-help-special{margin:0 0 12px;padding:0;list-style:none;font-size:13px}.c64-help-controls li,.c64-help-special li{display:flex;justify-content:space-between;padding:4px 0;border-bottom:1px solid #2a2a3e}.c64-help-key{background:#2a2a3e;border:1px solid #444;border-radius:3px;padding:1px 8px;font-size:12px;color:#ddd}.c64-help-close{position:absolute;top:10px;right:14px;background:none;border:none;color:#888;font-size:20px;cursor:pointer}.c64-version{display:flex;justify-content:end;font-size:12px;color:#999;margin-top:36px}.c64-menu-overlay{align-items:flex-start;justify-content:flex-start;padding:48px 24px;background:rgba(0,0,0,.5);z-index:1002}.c64-menu-panel{min-width:320px;max-width:520px;padding:16px;background:#0f0f1a;border-color:#333}.c64-menu-header{display:flex;align-items:center;justify-content:space-between}.c64-settings-tabs,.c64-menu-actions,.c64-system-actions,.c64-radio-row,.c64-gamepad-list{display:flex;gap:8px;flex-wrap:wrap}.c64-settings-tab,.c64-btn,.c64-mute-btn{background:#222;border:1px solid #444;color:#ddd;padding:6px 10px;border-radius:4px;cursor:pointer}.c64-settings-tab.active,.c64-gamepad-btn.active{border-color:#7b71d5;color:#fff;background:#25253d}.c64-select{background:#171729;color:#ddd;border:1px solid #444;border-radius:4px;padding:4px 8px;font-family:monospace}.c64-form-row,.c64-audio-row,.c64-cart-preview{display:flex;align-items:center;gap:10px;margin-bottom:10px}.c64-section-label,.c64-audio-section label{display:block;margin:0 0 8px;font-size:13px;color:#aaa}.c64-section-hint,.c64-volume-label,.c64-cart-type{font-size:11px;color:#888}.c64-dragarea{border:2px dashed #2a2a3e;border-radius:6px;padding:12px;margin-top:12px;text-align:center;color:#aaa}.c64-dragarea.dragover{border-color:#7b71d5;color:#fff}.c64-file-input{display:none}.c64-volume-slider{flex:1}.c64-cart-filename{font-size:13px;color:#ccc;word-break:break-all}.c64-checkbox-row{display:inline-flex;gap:8px;align-items:center;color:#ccc;font-size:13px}
|
|
45
|
-
`;function H(e,t){return`${(e??`/`).replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`}var U=[[`Move Up`,`↑`],[`Move Down`,`↓`],[`Move Left`,`←`],[`Move Right`,`→`],[`Fire`,`Z or Left Ctrl`]],W=[[`Run/Stop`,`Esc`],[`Restore`,`(currently unsupported)`],[`Insert/Delete`,`Backspace or Delete`],[`Clear/Home`,`Home`],[`Commodore`,`Ctrl or Caps Lock`],[`Control`,`Tab`],[`Arrow Left glyph`,"`"],[`Arrow Up glyph`,`^ or ~`],[`Pound`,`\\`],[`Colon / Semicolon`,`: ; [ ]`],[`Slash`,`/ ?`],[`Comma / Period`,`, . < >`],[`C64 function keys`,`F1-F8`]],G=`c64-disable-crt-preload-checks`;function K(e=new Date){let t=e=>String(e).padStart(2,`0`);return`snapshot-${e.getFullYear()}${t(e.getMonth()+1)}${t(e.getDate())}-${t(e.getHours())}${t(e.getMinutes())}${t(e.getSeconds())}.c64`}var re=class{helpOverlay=null;settingsOverlay=null;fileInput=null;player=null;options;savedHtmlOverflow=null;savedBodyOverflow=null;connectedGamepads=new Map;handleControllerConnected=e=>{let t=e.detail;typeof t?.index==`number`&&(this.connectedGamepads.set(t.index,{index:t.index,name:t.name??`Gamepad ${t.index}`}),this.renderGamepadButtons())};handleControllerDisconnected=e=>{let t=e.detail;typeof t?.index==`number`&&(this.connectedGamepads.delete(t.index),this.renderGamepadButtons())};constructor(e={}){this.options=e}init(e){this.player=e??null,this.syncConnectedGamepads(),this.injectCSS(),this.createButton(),this.createDialog(),this.createHamburger(),this.createMenu(),this.createUnmuteButton(),window.addEventListener(`c64-controller-connected`,this.handleControllerConnected),window.addEventListener(`c64-controller-disconnected`,this.handleControllerDisconnected)}syncConnectedGamepads(){this.connectedGamepads.clear();let e=navigator.getGamepads?.()??[];for(let t of e)t&&this.connectedGamepads.set(t.index,{index:t.index,name:t.id})}getConnectedGamepads(){return Array.from(this.connectedGamepads.values()).sort((e,t)=>e.index-t.index)}getGamepadLabel(e){let t=e.name.replace(/\s*\([^)]*\)\s*$/u,``).trim()||e.name.trim()||`Gamepad ${e.index}`;return`${e.index}: ${t}`}renderGamepadButtons(){let e=document.getElementById(`c64-gamepad-list`),t=document.getElementById(`c64-gamepad-empty`);if(!e||!t)return;let n=this.getConnectedGamepads(),r=this.player?.getActiveGamepadIndex()??-1;e.replaceChildren(...n.map(e=>{let t=document.createElement(`button`),n=e.index===r;return t.type=`button`,t.className=`c64-btn c64-gamepad-btn${n?` active`:``}`,t.textContent=this.getGamepadLabel(e),t.setAttribute(`aria-pressed`,n?`true`:`false`),t.addEventListener(`click`,()=>{this.player&&(this.player.setActiveGamepadIndex(e.index),this.renderGamepadButtons())}),t})),t.hidden=n.length>0}downloadSnapshot(e){let t=new Uint8Array(e.byteLength);t.set(e);let n=new Blob([t],{type:`application/bin`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=K(),document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}injectCSS(){if(document.querySelector(`style[data-c64-help]`))return;let e=document.createElement(`style`);e.setAttribute(`data-c64-help`,``),e.textContent=ne,document.head.appendChild(e)}getVersionLabel(){let e=this.options.appVersion??`0.0.0`,t=this.options.gitHash;return`v${e}${t?` (build: ${t})`:``}`}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=`
|
|
46
|
-
<div class="c64-help-dialog">
|
|
47
|
-
<button class="c64-help-close">×</button>
|
|
48
|
-
<h2>C64 READY</h2>
|
|
49
|
-
<p>A Commodore 64 emulator running in the browser via WebAssembly.</p>
|
|
50
|
-
<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>
|
|
51
|
-
<h2>CONTROLS</h2>
|
|
52
|
-
<ul class="c64-help-controls">${U.map(([e,t])=>`<li><span>${e}</span><span class="c64-help-key">${t}</span></li>`).join(``)}</ul>
|
|
53
|
-
<h2>SPECIAL KEYS</h2>
|
|
54
|
-
<ul class="c64-help-special">${W.map(([e,t])=>`<li><span>${e}</span><span class="c64-help-key">${t}</span></li>`).join(``)}</ul>
|
|
55
|
-
<div class="c64-version">${this.getVersionLabel()}</div>
|
|
56
|
-
</div>
|
|
57
|
-
`,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=`
|
|
58
|
-
<div class="c64-help-dialog c64-changelog-dialog">
|
|
59
|
-
<button class="c64-help-close">×</button>
|
|
60
|
-
<h2>CHANGELOG</h2>
|
|
61
|
-
<div id="c64-changelog-content">Loading...</div>
|
|
62
|
-
</div>
|
|
63
|
-
`,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 fetch(this.options.changelogUrl??H(this.options.assetBaseUrl,`CHANGELOG.md`),{cache:`no-store`});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=(await t.text()).split(`
|
|
64
|
-
`).filter(e=>{let t=e.trim();return t.startsWith(`- `)?/^- (feat|fix)[:(]/.test(t):!0}).join(`
|
|
65
|
-
`),[{marked:r},i]=await Promise.all([V(()=>import(`./marked.esm--kBm026b.js`),[]),V(()=>import(`./purify.es-BcoGFDcJ.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=C.map(e=>`<option value="${e.type}">${e.label}</option>`).join(``),r=document.createElement(`div`);r.className=`c64-menu-panel`,r.innerHTML=`
|
|
66
|
-
<div class="c64-menu-header">
|
|
67
|
-
<h2>Settings</h2>
|
|
68
|
-
<button class="c64-menu-close">×</button>
|
|
69
|
-
</div>
|
|
70
|
-
<div class="c64-menu-body">
|
|
71
|
-
<div class="c64-settings-tabs" role="tablist" aria-label="Settings sections">
|
|
72
|
-
${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(``)}
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
<div class="c64-settings-sections">
|
|
76
|
-
<section class="c64-settings-section" data-settings-section="load">
|
|
77
|
-
<label class="c64-section-label">Load Game</label>
|
|
78
|
-
<div class="c64-form-row">
|
|
79
|
-
<label for="c64-load-format">Format</label>
|
|
80
|
-
<select id="c64-load-format" class="c64-select">
|
|
81
|
-
<option value="auto">Auto detect (recommended)</option>
|
|
82
|
-
${n}
|
|
83
|
-
</select>
|
|
84
|
-
</div>
|
|
85
|
-
<div class="c64-dragarea" id="c64-dragarea">
|
|
86
|
-
<span id="c64-dragarea-copy">Drop a game file here or</span>
|
|
87
|
-
<button class="c64-btn" id="c64-browse">Browse</button>
|
|
88
|
-
</div>
|
|
89
|
-
<input class="c64-file-input" id="c64-file-input" type="file" />
|
|
90
|
-
<div class="c64-cart-preview" id="c64-cart-preview" hidden>
|
|
91
|
-
<div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
|
|
92
|
-
<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>
|
|
93
|
-
</div>
|
|
94
|
-
<div>
|
|
95
|
-
<div class="c64-cart-filename" id="c64-cart-filename"></div>
|
|
96
|
-
<div class="c64-cart-type" id="c64-cart-type"></div>
|
|
97
|
-
</div>
|
|
98
|
-
</div>
|
|
99
|
-
<div class="c64-menu-actions">
|
|
100
|
-
<button class="c64-btn" id="c64-load-btn">Load</button>
|
|
101
|
-
<button class="c64-btn" id="c64-close-menu">Close</button>
|
|
102
|
-
</div>
|
|
103
|
-
<div class="c64-tools-section">
|
|
104
|
-
<label class="c64-section-label">Tools</label>
|
|
105
|
-
<div class="c64-form-row">
|
|
106
|
-
<select id="c64-tool-select" class="c64-select c64-tool-select" disabled>
|
|
107
|
-
<option value="">No tools found</option>
|
|
108
|
-
</select>
|
|
109
|
-
<button class="c64-btn" id="c64-load-tool-btn" disabled>Load Tool</button>
|
|
110
|
-
</div>
|
|
111
|
-
<div class="c64-section-hint" id="c64-tools-status">Loading tools…</div>
|
|
112
|
-
</div>
|
|
113
|
-
</section>
|
|
114
|
-
|
|
115
|
-
<section class="c64-settings-section" data-settings-section="input" hidden>
|
|
116
|
-
<label class="c64-section-label">Input Port</label>
|
|
117
|
-
<div class="c64-radio-row">
|
|
118
|
-
<label><input type="radio" name="c64-joy-port" value="1" /> Port 1</label>
|
|
119
|
-
<label><input type="radio" name="c64-joy-port" value="2" checked /> Port 2</label>
|
|
120
|
-
</div>
|
|
121
|
-
<label class="c64-section-label">Input Mode</label>
|
|
122
|
-
<div class="c64-radio-row c64-radio-row-wrap">
|
|
123
|
-
<label><input type="radio" name="c64-input-mode" value="joystick" /> Joystick</label>
|
|
124
|
-
<label><input type="radio" name="c64-input-mode" value="keyboard" /> Keyboard</label>
|
|
125
|
-
<label><input type="radio" name="c64-input-mode" value="mixed" checked /> Mixed</label>
|
|
126
|
-
</div>
|
|
127
|
-
<div id="c64-input-mode-hint" class="c64-section-hint">Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard</div>
|
|
128
|
-
<label class="c64-section-label">Gamepads</label>
|
|
129
|
-
<div id="c64-gamepad-list" class="c64-gamepad-list"></div>
|
|
130
|
-
<div id="c64-gamepad-empty" class="c64-section-hint">To use a gamepad, connect it to your computer and press any button.</div>
|
|
131
|
-
</section>
|
|
132
|
-
|
|
133
|
-
<section class="c64-settings-section" data-settings-section="display" hidden>
|
|
134
|
-
<label class="c64-section-label">Display Mode</label>
|
|
135
|
-
<div class="c64-radio-row">
|
|
136
|
-
<label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
|
|
137
|
-
<label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
|
|
138
|
-
<label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
|
|
139
|
-
</div>
|
|
140
|
-
</section>
|
|
141
|
-
|
|
142
|
-
<section class="c64-settings-section" data-settings-section="audio" hidden>
|
|
143
|
-
<div id="c64-audio-section-anchor"></div>
|
|
144
|
-
</section>
|
|
145
|
-
|
|
146
|
-
<section class="c64-settings-section" data-settings-section="system" hidden>
|
|
147
|
-
<label class="c64-section-label">System Actions</label>
|
|
148
|
-
<div class="c64-system-actions">
|
|
149
|
-
<button class="c64-btn" id="c64-save-snapshot-btn">Save Snapshot</button>
|
|
150
|
-
<button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
|
|
151
|
-
<button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
|
|
152
|
-
<button class="c64-btn" id="c64-reboot-btn">Reboot Emulator</button>
|
|
153
|
-
</div>
|
|
154
|
-
<label class="c64-checkbox-row" for="c64-disable-crt-preload-checks">
|
|
155
|
-
<input type="checkbox" id="c64-disable-crt-preload-checks" />
|
|
156
|
-
Disable crt preload checks
|
|
157
|
-
</label>
|
|
158
|
-
<div class="c64-section-hint">Allows any .crt file and skips compatibility prechecks.</div>
|
|
159
|
-
</section>
|
|
160
|
-
</div>
|
|
161
|
-
</div>
|
|
162
|
-
`,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.getAttribute(`data-settings-tab`)===e;t.classList.toggle(`active`,n),t.setAttribute(`aria-selected`,n?`true`:`false`)}),a.forEach(t=>{t.hidden=t.getAttribute(`data-settings-section`)!==e})};i.forEach(e=>{e.addEventListener(`click`,()=>{let t=e.getAttribute(`data-settings-tab`);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-tool-select`),f=r.querySelector(`#c64-load-tool-btn`),p=r.querySelector(`#c64-tools-status`),m=r.querySelector(`#c64-cart-preview`),h=r.querySelector(`#c64-cart-filename`),g=r.querySelector(`#c64-cart-type`),_=()=>{let e=u.value??`auto`;this.fileInput.accept=te(e),e===`auto`?c.textContent=`Drop a game file here or`:c.textContent=`Drop a ${D(e)} file here or`};_(),u.addEventListener(`change`,_);let v=e=>{let t=ee(u.value??`auto`,e.name);m.hidden=!1,h.textContent=e.name,g.textContent=D(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&&v(t)}),l.addEventListener(`click`,()=>this.fileInput?.click()),this.fileInput.addEventListener(`change`,()=>{let e=this.fileInput?.files?.[0];e&&v(e)}),r.querySelector(`#c64-load-btn`).addEventListener(`click`,()=>{let e=this.fileInput?.files?.[0];e?v(e):this.fileInput?.click()});let y=[],b=()=>{if(d.innerHTML=``,y.length===0){let e=document.createElement(`option`);e.value=``,e.textContent=`No tools found`,d.appendChild(e),d.disabled=!0,f.disabled=!0;return}y.forEach((e,t)=>{let n=document.createElement(`option`);n.value=String(t),n.textContent=e.name,d.appendChild(n)}),d.disabled=!1,f.disabled=!1},x=e=>(Array.isArray(e)?e:e&&typeof e==`object`&&Array.isArray(e.tools)?e.tools:[]).map(e=>{let t=typeof e==`string`?e:e&&typeof e==`object`?e.path:void 0;if(!t||typeof t!=`string`)return null;let n=t.split(`/`).pop()??t,r=E(n);if(!r)return null;let i=t.split(`/`).map(e=>encodeURIComponent(e)).join(`/`).replace(/^\/+/,``);return{name:n,url:H(this.options.assetBaseUrl,`tools/${i}`),type:r}}).filter(e=>!!e);f.addEventListener(`click`,()=>{let e=Number(d.value);if(!Number.isFinite(e))return;let t=y[e];t&&window.dispatchEvent(new CustomEvent(`c64-load-tool`,{detail:t}))}),(async()=>{try{let e=H(this.options.assetBaseUrl,`tools/tools.json`),t=await fetch(e,{cache:`no-store`});if(!t.ok)throw Error(`HTTP ${t.status}`);y=x(await t.json()),b(),p.textContent=y.length>0?`Found ${y.length} tool${y.length===1?``:`s`} in /public/tools`:`No compatible tools found in manifest`}catch(e){y=[],b(),p.textContent=`Unable to load tools manifest: ${String(e?.message??e)}`}})().catch(()=>{});let S=r.querySelector(`[data-settings-section="system"]`),w=S?.querySelector(`#c64-save-snapshot-btn`),T=S?.querySelector(`#c64-detach-btn`),O=S?.querySelector(`#c64-reset-btn`),k=S?.querySelector(`#c64-reboot-btn`),A=S?.querySelector(`#c64-disable-crt-preload-checks`),j=window.localStorage.getItem(G)===`1`;this.player?.setCrtPreloadChecksDisabled(j),A&&(A.checked=j,A.addEventListener(`change`,()=>{let e=A.checked;window.localStorage.setItem(G,e?`1`:`0`),this.player?.setCrtPreloadChecksDisabled(e)})),w&&w.addEventListener(`click`,()=>{if(!this.player||typeof this.player.getSnapshot!=`function`)return;let e=document.getElementById(`status`);try{this.downloadSnapshot(this.player.getSnapshot()),e&&(e.textContent=`Snapshot saved`)}catch(t){e&&(e.textContent=`Snapshot save failed: ${String(t?.message??t)}`)}}),T&&T.addEventListener(`click`,()=>{if(!this.player||!confirm(`Detach cartridge?`))return;this.player.detachCartridge();let e=document.getElementById(`status`);e&&(e.textContent=`Cartridge detached`)}),O&&O.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`)}),k&&k.addEventListener(`click`,async()=>{if(!this.player||!confirm(`Perform full reboot? This re-instantiates the emulator with no game loaded.`))return;let e=document.getElementById(`status`);e&&(e.textContent=`Rebooting emulator...`);try{await this.player.reboot(),e&&(e.textContent=`Emulator rebooted (no game loaded)`)}catch(t){e&&(e.textContent=`Reboot failed: ${String(t?.message??t)}`)}});let M=r.querySelector(`#c64-audio-section-anchor`);this.createAudioSection(M);let N=r.querySelectorAll(`input[name="c64-joy-port"]`),P=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{}};N.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&P(Number(e.value))})});let F={joystick:`Arrows + Ctrl = joystick only`,keyboard:`All keys → C64 keyboard matrix`,mixed:`Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard`},I=r.querySelectorAll(`input[name="c64-input-mode"]`),L=r.querySelector(`#c64-input-mode-hint`),R=e=>{if(L&&(L.innerHTML=F[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{}};I.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&R(e.value)})}),this.renderGamepadButtons();let z=r.querySelectorAll(`input[name="c64-display-mode"]`),B=document.getElementById(`c64-screen`),V=e=>{B&&(B.style.width=``,B.style.height=``,B.style.objectFit=``,B.removeAttribute(`data-display-mode`),e===`standard`?(B.style.width=``,B.style.height=``,B.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`?(B.style.height=`100vh`,B.style.width=`auto`,B.style.objectFit=`contain`,B.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`&&(B.style.width=`100vw`,B.style.height=`100vh`,B.style.objectFit=`fill`,B.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`),B.setAttribute(`data-display-mode`,e),window.dispatchEvent(new CustomEvent(`c64-display-mode-changed`,{detail:{mode:e}})))};z.forEach(e=>{e.addEventListener(`change`,()=>{e.checked&&V(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=`
|
|
163
|
-
<label>Audio</label>
|
|
164
|
-
<div class="c64-audio-row">
|
|
165
|
-
<button class="c64-mute-btn" id="c64-mute-btn" title="Toggle mute">🔈</button>
|
|
166
|
-
<input type="range" class="c64-volume-slider" id="c64-volume-slider" min="0" max="100" value="75" />
|
|
167
|
-
<span class="c64-volume-label" id="c64-volume-label">75%</span>
|
|
168
|
-
</div>
|
|
169
|
-
`,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`)}},q=document.getElementById(`status`),J=new L(`c64-screen`),Y=`/c64-ready/`,ie=new URLSearchParams(window.location.search);function ae(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 X=ae(ie.get(`game`),Y),oe=E(X||``)??`crt`,Z=new O({wasmUrl:`${Y}c64.wasm`,gameUrl:X,gameType:oe,renderer:J,onProgress:(e,t)=>J.setProgress(e,t)});new re().init(Z),Z.start().then(()=>{X||(q.textContent=`Autoload disabled (?game=null)`,q.style.color=`#9ecbff`),J.hideLoader()}).catch(e=>{console.error(e),J.setError(`ERROR`),q.textContent=`Error: ${$(String(e))}`,q.style.color=`#f44`});var Q=()=>{let e=document.hidden,t=document.querySelector(`link[rel~='icon']`),n=`${Y}${e?`led-off.svg`:`led-on.svg`}`.replace(/\/+/g,`/`);t&&(t.href=n)};document.addEventListener(`visibilitychange`,Q),window.addEventListener(`focus`,Q),window.addEventListener(`blur`,Q),Q(),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{J.showLoader(),await Z.loadFile(n,T(i)?i:void 0),J.hideLoader()}catch(e){console.error(e),J.setError(`LOAD ERROR`),q.textContent=`Load error: ${$(String(e))}`,q.style.color=`#f44`}}),window.addEventListener(`c64-controller-connected`,e=>{let t=e.detail;q.textContent=`Controller Connected: ${t.index} - ${t.name}`,q.style.color=`#9ecbff`}),window.addEventListener(`c64-controller-disconnected`,e=>{let t=e.detail;q.textContent=`Controller Disconnected : ${t.index} - ${t.name}`,q.style.color=`#9ecbff`}),window.addEventListener(`c64-load-tool`,async e=>{let t=e.detail;if(!t?.url)return;let n=T(t.type)?t.type:void 0;try{q.textContent=`Loading tool: ${t.name??t.url}`,q.style.color=`#9ecbff`,J.showLoader(),await Z.loadTool(t.url,n),J.hideLoader()}catch(e){console.error(e),J.setError(`LOAD ERROR`),q.textContent=`Tool load error: ${$(String(e))}`,q.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),J.setError(`LOAD ERROR`),q.textContent=`Load error: ${n}`,q.style.color=`#f44`}),window.addEventListener(`c64-load-info`,e=>{let t=e.detail;t?.message&&(q.textContent=t.message,q.style.color=t.mode===`warning`?`#f9c74f`:`#9ecbff`,console.info(`C64 load info event:`,t))}),window.addEventListener(`c64-reboot`,()=>{q.textContent=`Emulator rebooted. Load a cartridge to continue.`,q.style.color=`#9ecbff`,J.hideLoader(0)});function $(e){let t=String(e??``).trim();for(;/^(uncaught\s+)?error\s*:\s*/i.test(t);)t=t.replace(/^(uncaught\s+)?error\s*:\s*/i,``).trim();return t||`Unknown load error`}
|