From 470f65cca403b0091a3c8a9fd975a9f94b3b3d74 Mon Sep 17 00:00:00 2001 From: Rupert Hausberger Date: Tue, 2 Aug 2016 22:03:47 +0200 Subject: [PATCH] update 0.9.0 --- example.htm | 7 ++++++- example.js | 34 ++++++++++++++++++++++++++++++++++ example2.htm | 7 ++++++- index.htm | 1 + index.js | 31 +++++++++++++++++++++++++++++-- sae/amiga.js | 8 +++++++- sae/audio.js | 23 ++++++++++++++++++++--- sae/cpu.js | 36 ------------------------------------ sae/utils.js | 2 +- 9 files changed, 104 insertions(+), 45 deletions(-) diff --git a/example.htm b/example.htm index 340cfb5..f2fe32d 100644 --- a/example.htm +++ b/example.htm @@ -133,6 +133,7 @@ + @@ -144,8 +145,12 @@
+ + The size of the canvas is set by SAE according your settings. + + See example2.htm --> + diff --git a/example.js b/example.js index db072a3..6a89ea4 100644 --- a/example.js +++ b/example.js @@ -23,6 +23,7 @@ var inf = null; /* Reference to the info-object */ var running = false; /* Is the emualtion currently running? */ var paused = false; /* Is the emualtion currently paused? */ +var muted = false; /* Is the audio-output currently muted? */ /*-----------------------------------------------------------------------*/ /* Helpers */ @@ -64,14 +65,27 @@ function switchPauseResume(p) { } } +function switchMutePlay(m) { + var e = document.getElementById("controls_mp"); + if (m) { + e.innerHTML = "Play"; + e.onclick = function() { mute(false); }; + } else { + e.innerHTML = "Mute"; + e.onclick = function() { mute(true); }; + } +} + function saee2text(err) { switch (err) { case SAEE_AlreadyRunning: return "The emulator is already running."; case SAEE_NotRunning: return "The emulator is not running."; case SAEE_NoTimer: return "No timing-functions avail. Please upgrade your browser."; case SAEE_NoMemory: return "Out of memory."; + case SAEE_Assert: return "Assertiation failed."; case SAEE_Internal: return "Internal emulator error."; case SAEE_Config_Invalid: return "Invalid configuration."; + case SAEE_Config_Compressed: return "A ZIP file was detected. Compressed files are not yet supported."; case SAEE_CPU_Internal: return "Internal CPU-error."; case SAEE_CPU_Requires68020: return "The selected kickstart-rom does require a 68020 and 32bit address-space"; case SAEE_CPU_Requires680EC20: return "The selected kickstart-rom does require a 68020."; @@ -327,6 +341,18 @@ function pause(p) { alert(saee2text(err)); } +function mute(m) { + /* Mute or play audio. + true == mute, false == play */ + var err = sae.mute(m); + if (err == SAEE_None) { + muted = m; + switchMutePlay(muted); + /* ... */ + } else + alert(saee2text(err)); +} + function romSelect() { var e = document.getElementById("cfg_rom_file").files[0]; if (e) { @@ -441,6 +467,10 @@ function hook_event_stopped() { paused = false; switchPauseResume(paused); } + if (muted) { + muted = false; + switchMutePlay(muted); + } resetLEDs(); } @@ -450,6 +480,10 @@ function hook_event_reseted(hard) { paused = false; switchPauseResume(paused); } + if (muted) { + muted = false; + switchMutePlay(muted); + } } /* Get call after the emulator has finished switching between pause-resume. */ diff --git a/example2.htm b/example2.htm index 4d7d8db..851aaa2 100644 --- a/example2.htm +++ b/example2.htm @@ -133,6 +133,7 @@ + @@ -141,9 +142,13 @@ Output - + + + diff --git a/index.htm b/index.htm index 781c4b2..f4d4cc7 100644 --- a/index.htm +++ b/index.htm @@ -1678,6 +1678,7 @@ + diff --git a/index.js b/index.js index 3b4aca7..197b99f 100644 --- a/index.js +++ b/index.js @@ -199,6 +199,7 @@ var amaxInfo = null; /* amax rom-info */ var floppyNum = -1; /* current floppy-unit if floppy-info is shown */ var mountConfigNum = -1; /* current mount-unit if mount-info is shown */ var paused = false; /* is the emualtion currently paused? */ +var muted = false; /* is the audio-output currently muted? */ var dskchg = false; /* disk-change requester in database-mode */ var dskchgList = []; /* list of floppies to change, created dynamicaly */ @@ -439,6 +440,17 @@ function switchPauseResume(p) { } } +function switchMutePlay(m) { + var e = document.getElementById("controls_mp"); + if (m) { + e.innerHTML = "Play"; + e.onclick = function() { mute(false); }; + } else { + e.innerHTML = "Mute"; + e.onclick = function() { mute(true); }; + } +} + function switchBaseEmul(emul) { if (emul) { document.body.style.backgroundColor = "#000000"; @@ -489,8 +501,8 @@ function saee2text(err) { case SAEE_NotRunning: return "The emulator is not running."; case SAEE_NoTimer: return "No timing-functions avail. Please upgrade your browser."; case SAEE_NoMemory: return "Out of memory."; - case SAEE_Assert: return "Assertiation failed."; - case SAEE_Internal: return "Internal emulator error."; + case SAEE_Assert: return "Assertiation failed."; + case SAEE_Internal: return "Internal emulator error."; case SAEE_Config_Invalid: return "Invalid configuration."; case SAEE_Config_Compressed: return "A ZIP file was detected. Compressed files are not yet supported."; case SAEE_CPU_Internal: return "Internal CPU-error."; @@ -1433,6 +1445,13 @@ function reset() { sae.reset(false, false); } +function mute(m) { + sae.mute(m); + + muted = m; + switchMutePlay(muted); +} + /*---------------------------------*/ function init() { @@ -2468,6 +2487,10 @@ function hook_event_stopped() { paused = false; switchPauseResume(paused); } + if (muted) { + muted = false; + switchMutePlay(muted); + } if (dskchg) dskchgClose(); @@ -2482,6 +2505,10 @@ function hook_event_reseted(hard) { paused = false; switchPauseResume(paused); } + if (muted) { + muted = false; + switchMutePlay(muted); + } if (dskchg) dskchgClose(); } diff --git a/sae/amiga.js b/sae/amiga.js index eaee448..259ec40 100644 --- a/sae/amiga.js +++ b/sae/amiga.js @@ -586,9 +586,15 @@ function ScriptedAmigaEmulator() { return SAEE_None; }; + this.mute = function(mute) { + this.audio.mute(mute); + return SAEE_None; + }; + this.keyPress = function(e, down) { this.input.keyPress(e, down); - } + return SAEE_None; + }; /*---------------------------------*/ diff --git a/sae/audio.js b/sae/audio.js index a366dee..3989f09 100644 --- a/sae/audio.js +++ b/sae/audio.js @@ -54,6 +54,7 @@ function SAEO_Audio() { const SOUND_SYNC_MULTIPLIER = 1.0; var scaled_sample_evtime_orig = 0.0; + var muted = false; var paused = false; var have_sound = false; var sound_available = false; @@ -213,6 +214,14 @@ function SAEO_Audio() { const INV32768 = 1.0 / 32768; /* mul is always fasten than div */ function scaleplay(e, buffer, frames) { + if (muted) { + for (var ch = 0; ch < SAEV_config.audio.channels; ch++) { + var data = e.outputBuffer.getChannelData(ch); + for (var i = 0; i < e.outputBuffer.length; i++) + data[i] = 0.0; + } + return; + } /*if (driver.context.sampleRate != used_freq) { } else*/ { var step = frames / e.outputBuffer.length; @@ -372,6 +381,8 @@ function SAEO_Audio() { } function reset_sound() { //reset_sound() + muted = paused = false; + cache.readoffset = 0; cache.writeoffset = 0; cache.wait = true; @@ -379,6 +390,10 @@ function SAEO_Audio() { paula.average.clr(); } + function mute_sound(mute) { //OWN + muted = mute; + } + /*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/ @@ -1457,11 +1472,9 @@ function SAEO_Audio() { } this.reset = function() { - var i; - reset_sound(); - for (i = 0; i < sound_filter_state.length; i++) + for (var i = 0; i < sound_filter_state.length; i++) sound_filter_state[i].clr(); for (i = 0; i < AUDIO_CHANNELS_MAX; i++) { @@ -1487,6 +1500,10 @@ function SAEO_Audio() { resume_sound(); } + this.mute = function(mute) { + mute_sound(mute) + } + /*-----------------------------------------------------------------------*/ var prevcon = -1; diff --git a/sae/cpu.js b/sae/cpu.js index 7073dbf..1129c09 100644 --- a/sae/cpu.js +++ b/sae/cpu.js @@ -10229,39 +10229,3 @@ function SAEO_CPU() { return true; } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/sae/utils.js b/sae/utils.js index a97f67a..ce6613d 100644 --- a/sae/utils.js +++ b/sae/utils.js @@ -497,7 +497,7 @@ function SAEF_ZFile_fopen_file(file) { //SAEF_log("SAEF_ZFile_fopen_file() opening '%s', %d/%d bytes, crc32 0x%08x, magic %08x", l.name, l.size, l.data.length, file.crc32 !== false ? file.crc32 : 0, magic); - if (magic == 0x04034B50 || magic == 0x504B0304) + if (magic == 0x504B0304 || magic == 0x04034B50) SAEF_fatal(SAEE_Config_Compressed, "A ZIP file was detected. Compressed files are not yet supported."); //if (l.data[0] == 68 && l.data[1] == 77 && l.data[2] == 83 && l.data[3] == 33) { /* DMS! */