From 40be0902f034f31beed4cc9b9bf9909d7cbb49e1 Mon Sep 17 00:00:00 2001 From: minipliy Date: Wed, 11 Feb 2026 12:50:02 +0100 Subject: [PATCH 1/2] Bugfixes --- .DS_Store | Bin 0 -> 6148 bytes chip8_core/target/.rustc_info.json | 2 +- website/index.js | 78 ++++++++++++++++++++++------- 3 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5219bd767f4b0d52448140239fee3ce41c6e8de9 GIT binary patch literal 6148 zcmeHKO>7%Q6rSg}@ov+llQyN{$7PWPLcvu{XrNIkavg&xZE00IwVM{q+B;20UGGLa zYda!}FbKrY2?XN6g;o_e{)B`$Kn2_iMQ}k#2nlgR9JnAMuDqGqm70cJ5rTcv%s20E zXWzHGGdqM3sPx=>2%&@!1DnL`X6*h(q+hmml8G%Nh@h^)NkmwCAeP$Ry6Du9GLSOx zZ(~4yyE!r-jI@a$*L=T08$BPlmpm?_Qt5lhjAS>B=5l6kEcbZrTrj9bPSg_>Cp;~+ zdJuT+WbCw0ayDquiMha!9PYDFC2*Hv$e9NB-C$4&dcG@EZcRH((=c0f=gP|c`-=9= z^z3TUUYVUP745zE-nY7H8aoPm_Md2-_qu-Yl4cQb(NSW>n83?8xUMKq^l?#=MP)80 zMg15TWtf}CwpcghA33z;(Zffq1!uX=mZKVfinZugfz=)A1pe`m^|7i(C-8b*U$p3W z$MHHn&xzPU&y&Gu+a^PfEk!)=#Yq+lM0tr$7wnw=VE@&q%}3z~yH-TF&EBsrycsJt56U91$H`Vm@=fyXodzZq4tq z>_(pp-uBr1fVkzdGf zcE1+-Uf?fcM3S{OX(KI;HpVszNbM;DDFgpo2ITr+W0P2pai~!(9oVV$3NedjB{-I6 z37KQZSdMY15j`lNQxSD4#77L!>1em(xN?j`jXIq`yi!6uGsGtpP_yIpZ52+StTF9V z22uvrG9dr`QK;PiAKLi*uY%GpWgunXzsUe(tF>wcYm4{Rbydo}*2eZEHYqZ0s8OY0 l7jMUEAh+U4Y)a5)%K>6J#-T>Eprk(niiWgH8TdyT_zMfH3BCXT literal 0 HcmV?d00001 diff --git a/chip8_core/target/.rustc_info.json b/chip8_core/target/.rustc_info.json index f4e163d..ce0264d 100644 --- a/chip8_core/target/.rustc_info.json +++ b/chip8_core/target/.rustc_info.json @@ -1 +1 @@ -{"rustc_fingerprint":9251509361105874613,"outputs":{"12016735552878863467":{"success":true,"status":"","code":0,"stdout":"rustc 1.93.0 (254b59607 2026-01-19)\nbinary: rustc\ncommit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c\ncommit-date: 2026-01-19\nhost: aarch64-apple-darwin\nrelease: 1.93.0\nLLVM version: 21.1.8\n","stderr":""},"13822592305234237280":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/lukashammer/.rustup/toolchains/stable-aarch64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"vh\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}} \ No newline at end of file +{"rustc_fingerprint":9251509361105874613,"outputs":{"13822592305234237280":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/lukashammer/.rustup/toolchains/stable-aarch64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"vh\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"12016735552878863467":{"success":true,"status":"","code":0,"stdout":"rustc 1.93.0 (254b59607 2026-01-19)\nbinary: rustc\ncommit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c\ncommit-date: 2026-01-19\nhost: aarch64-apple-darwin\nrelease: 1.93.0\nLLVM version: 21.1.8\n","stderr":""}},"successes":{}} \ No newline at end of file diff --git a/website/index.js b/website/index.js index de65f92..9874e83 100644 --- a/website/index.js +++ b/website/index.js @@ -28,17 +28,23 @@ class Chip8Sound { this.enabled = true; } - init() { - if (this.audioContext) return; + async init() { // Added async + if (!this.audioContext) { + try { + this.audioContext = new (window.AudioContext || window.webkitAudioContext)(); + this.gainNode = this.audioContext.createGain(); + this.gainNode.connect(this.audioContext.destination); + this.gainNode.gain.value = 0.1; + } catch (e) { + console.error("Failed to initialize audio:", e); + this.enabled = false; + return; + } + } - try { - this.audioContext = new (window.AudioContext || window.webkitAudioContext)(); - this.gainNode = this.audioContext.createGain(); - this.gainNode.connect(this.audioContext.destination); - this.gainNode.gain.value = 0.1; // 10% volume - } catch (e) { - console.error("Failed to initialize audio:", e); - this.enabled = false; + // Every time init is called via an interaction, try to resume + if (this.audioContext.state === 'suspended') { + await this.audioContext.resume(); } } @@ -183,18 +189,34 @@ Keybinds are explained inside the game. (German keyboard: Z is the Y key)` } -gameSelect.addEventListener("change", () => { - const value = gameSelect.value - descriptionBox.textContent = - descriptions[value] || "Select a game to see instructions." -}) +gameSelect.addEventListener("change", async function(evt) { + if (!evt.target.value) return; + + // Call this IMMEDIATELY before any 'await' calls + initAudio(); + + if (anim_frame != 0) { + window.cancelAnimationFrame(anim_frame); + } + + // ... rest of your fetch logic +}); // Initialize audio on first user interaction function initAudio() { - if (!audioInitialized && soundEnabled) { - sound.init() - audioInitialized = true - console.log("Audio initialized") + if (soundEnabled) { + sound.init(); + audioInitialized = true; + + // Create and play a tiny buffer of silence to "unlock" the audio hardware + if (sound.audioContext && !audioInitialized) { + const buffer = sound.audioContext.createBuffer(1, 1, 22050); + const source = sound.audioContext.createBufferSource(); + source.buffer = buffer; + source.connect(sound.audioContext.destination); + source.start(0); + audioInitialized = true; + } } } @@ -213,6 +235,10 @@ async function run() { chip8.keypress(evt, false) }) + document.addEventListener('touchstart', function() { + initAudio(); + }, { once: true }); + // Mobile touch keyboard logic const keyButtons = document.querySelectorAll(".key-btn"); @@ -251,6 +277,10 @@ async function run() { soundToggle.addEventListener("change", (evt) => { soundEnabled = evt.target.checked sound.setEnabled(soundEnabled) + // FIX #1: Initialize audio on toggle interaction (helps mobile) + if (soundEnabled) { + initAudio() + } }) } @@ -297,6 +327,14 @@ async function run() { return } + // FIX #2: Validate file extension to prevent Rust aliasing error + const fileName = file.name.toLowerCase() + if (!fileName.endsWith('.ch8') && !fileName.endsWith('.c8')) { + alert("Invalid file type. Please upload a .ch8 or .c8 file.") + fileInput.value = '' // Clear input to prevent state pollution + return + } + descriptionBox.textContent = "No description available for uploaded files." // Reset the dropdown @@ -309,6 +347,8 @@ async function run() { chip8.reset() chip8.load_game(rom) mainloop(chip8) + // FIX #2: Clear file input after successful load + fileInput.value = '' } fr.readAsArrayBuffer(file) }, false) From d936aef34351e06ecb004bc02076e95f48ef863c Mon Sep 17 00:00:00 2001 From: minipliy Date: Wed, 11 Feb 2026 12:55:24 +0100 Subject: [PATCH 2/2] Bugfixes --- website/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/website/index.js b/website/index.js index 9874e83..73b179d 100644 --- a/website/index.js +++ b/website/index.js @@ -1,3 +1,4 @@ + import init, * as wasm from "./wasm.js" const WIDTH = 64