diff --git a/IodineGBA/core/Emulator.js b/IodineGBA/core/Emulator.js index b230174..7e2ce24 100644 --- a/IodineGBA/core/Emulator.js +++ b/IodineGBA/core/Emulator.js @@ -1,6 +1,6 @@ "use strict"; /* - Copyright (C) 2012-2016 Grant Galitz + Copyright (C) 2012-2019 Grant Galitz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -277,17 +277,17 @@ GameBoyAdvanceEmulator.prototype.resetMetrics = function () { GameBoyAdvanceEmulator.prototype.calculateTimings = function () { this.clocksPerSecond = Math.min((+this.settings.emulatorSpeed) * 0x1000000, 0x3F000000) | 0; this.clocksPerMilliSecond = +((this.clocksPerSecond | 0) / 1000); - this.CPUCyclesPerIteration = ((+this.clocksPerMilliSecond) * (this.timerIntervalRate | 0)) | 0; + this.CPUCyclesPerIteration = ((+this.clocksPerMilliSecond) * (+this.timerIntervalRate)) | 0; this.CPUCyclesTotal = this.CPUCyclesPerIteration | 0; this.initializeAudioLogic(); this.reinitializeAudio(); this.invalidateMetrics(); } GameBoyAdvanceEmulator.prototype.setIntervalRate = function (intervalRate) { - intervalRate = intervalRate | 0; - if ((intervalRate | 0) > 0 && (intervalRate | 0) < 1000) { - if ((intervalRate | 0) != (this.timerIntervalRate | 0)) { - this.timerIntervalRate = intervalRate | 0; + intervalRate = +intervalRate; + if ((+intervalRate) > 0 && (+intervalRate) < 1000) { + if ((+intervalRate) != (+this.timerIntervalRate)) { + this.timerIntervalRate = +intervalRate; this.calculateTimings(); } } diff --git a/IodineGBA/core/Worker.js b/IodineGBA/core/Worker.js index 8231842..e3000f6 100644 --- a/IodineGBA/core/Worker.js +++ b/IodineGBA/core/Worker.js @@ -1,6 +1,6 @@ "use strict"; /* - Copyright (C) 2012-2017 Grant Galitz + Copyright (C) 2012-2019 Grant Galitz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -92,7 +92,7 @@ self.onmessage = function (event) { Iodine.restart(); break; case 3: - Iodine.setIntervalRate(data.payload | 0); + Iodine.setIntervalRate(+data.payload); changeTimer(data.payload | 0); break; case 4: diff --git a/IodineGBA/core/graphics/RendererShim.js b/IodineGBA/core/graphics/RendererShim.js index 4973a5c..255f312 100644 --- a/IodineGBA/core/graphics/RendererShim.js +++ b/IodineGBA/core/graphics/RendererShim.js @@ -144,7 +144,7 @@ GameBoyAdvanceGraphicsRendererShim.prototype.shareDynamicBuffers = function () { }); } //Wake up the producer "GPU" thread: - Atomics.wake(gfxCounters, 2, 1); + Atomics.notify(gfxCounters, 2, 1); } GameBoyAdvanceGraphicsRendererShim.prototype.pushCommand = function (command, data) { command = command | 0; diff --git a/IodineGBA/includes/TypedArrayShim.js b/IodineGBA/includes/TypedArrayShim.js index 5926584..23c15dc 100644 --- a/IodineGBA/includes/TypedArrayShim.js +++ b/IodineGBA/includes/TypedArrayShim.js @@ -177,6 +177,10 @@ if (typeof Atomics == "object") { if (typeof Atomics.futexWait == "function" && typeof Atomics.wait == "undefined") { //Polyfill in deprecated call names: Atomics.wait = Atomics.futexWait; - Atomics.wake = Atomics.futexWake; + Atomics.notify = Atomics.futexWake; + } + else if (typeof Atomics.wake == "function" && typeof Atomics.notify == "undefined") { + //Polyfill in deprecated call names: + Atomics.notify = Atomics.wake; } } diff --git a/user_scripts/CoreGlueCode.js b/user_scripts/CoreGlueCode.js index 56125bf..b2cafee 100644 --- a/user_scripts/CoreGlueCode.js +++ b/user_scripts/CoreGlueCode.js @@ -122,7 +122,7 @@ var IodineGUI = { mixerInput:null, currentSpeed:[false,0], defaults:{ - timerRate:16, + timerRate:8, sound:true, volume:1, skipBoot:false, @@ -179,8 +179,8 @@ window.onload = function () { registerDefaultSettings(); //Initialize Iodine: registerIodineHandler(); - //Initialize the timer: - registerTimerHandler(); + //Initialize the timer: + calculateTiming(); //Initialize the graphics: registerBlitterHandler(); //Initialize the audio: @@ -222,16 +222,19 @@ function registerIodineHandler() { if (typeof SharedArrayBuffer != "function" || typeof Atomics != "object") { throw null; } - else if (!IodineGUI.defaults.toggleOffthreadCPU) { + else if (!IodineGUI.defaults.toggleOffthreadCPU && IodineGUI.defaults.toggleOffthreadGraphics) { //Try starting Iodine normally, but initialize offthread gfx: IodineGUI.Iodine = new IodineGBAWorkerGfxShim(); } - else { + else if (IodineGUI.defaults.toggleOffthreadGraphics) { //Try starting Iodine in a webworker: IodineGUI.Iodine = new IodineGBAWorkerShim(); //In order for save on page unload, this needs to be done: addEvent("beforeunload", window, registerBeforeUnloadHandler); } + else { + throw null; + } } catch (e) { //Otherwise just run on-thread: @@ -245,15 +248,33 @@ function registerBeforeUnloadHandler(e) { } return "IodineGBA needs to process your save data, leaving now may result in not saving current data."; } -function registerTimerHandler() { - IodineGUI.defaults.timerRate = 16; - IodineGUI.Iodine.setIntervalRate(IodineGUI.defaults.timerRate | 0); -} function initTimer() { + IodineGUI.Iodine.setIntervalRate(+IodineGUI.defaults.timerRate); IodineGUI.coreTimerID = setInterval(function () { IodineGUI.Iodine.timerCallback(((+(new Date()).getTime()) - (+IodineGUI.startTime)) >>> 0); }, IodineGUI.defaults.timerRate | 0); } +function calculateTiming() { + IodineGUI.Iodine.setIntervalRate(+IodineGUI.defaults.timerRate); +} +function startTimer() { + IodineGUI.coreTimerID = setInterval(function () { + IodineGUI.Iodine.timerCallback(((+(new Date()).getTime()) - (+IodineGUI.startTime)) >>> 0); + }, IodineGUI.defaults.timerRate | 0); +} +function updateTimer(newRate) { + newRate = newRate | 0; + if ((newRate | 0) != (IodineGUI.defaults.timerRate | 0)) { + IodineGUI.defaults.timerRate = newRate | 0; + IodineGUI.Iodine.setIntervalRate(+IodineGUI.defaults.timerRate); + if (IodineGUI.isPlaying) { + if (IodineGUI.coreTimerID) { + clearInterval(IodineGUI.coreTimerID); + } + initTimer(); + } + } +} function registerBlitterHandler() { IodineGUI.Blitter = new GfxGlueCode(240, 160); IodineGUI.Blitter.attachCanvas(document.getElementById("emulator_target")); @@ -269,4 +290,4 @@ function registerAudioHandler() { var Mixer = new GlueCodeMixer(document.getElementById("play")); IodineGUI.mixerInput = new GlueCodeMixerInput(Mixer); IodineGUI.Iodine.attachAudioHandler(IodineGUI.mixerInput); -} +} \ No newline at end of file diff --git a/user_scripts/GUIGlueCode.js b/user_scripts/GUIGlueCode.js index 7a80111..5dfb82e 100644 --- a/user_scripts/GUIGlueCode.js +++ b/user_scripts/GUIGlueCode.js @@ -1,6 +1,6 @@ "use strict"; /* - Copyright (C) 2012-2017 Grant Galitz + Copyright (C) 2012-2019 Grant Galitz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -478,7 +478,7 @@ function updatePlayButton(isPlaying) { document.getElementById("pause").className = "show"; document.getElementById("menu").className = "playing"; if (!IodineGUI.coreTimerID) { - initTimer(); + startTimer(); } IodineGUI.isPlaying = true; } diff --git a/user_scripts/WorkerGfxGlueCode.js b/user_scripts/WorkerGfxGlueCode.js index b60d360..cfa08f5 100644 --- a/user_scripts/WorkerGfxGlueCode.js +++ b/user_scripts/WorkerGfxGlueCode.js @@ -1,6 +1,6 @@ "use strict"; /* - Copyright (C) 2012-2016 Grant Galitz + Copyright (C) 2012-2019 Grant Galitz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -27,8 +27,8 @@ IodineGBAWorkerGfxShim.prototype.restart = function () { this.Iodine.restart(); } IodineGBAWorkerGfxShim.prototype.setIntervalRate = function (rate) { - rate = rate | 0; - this.Iodine.setIntervalRate(rate | 0); + rate = +rate; + this.Iodine.setIntervalRate(+rate); } IodineGBAWorkerGfxShim.prototype.timerCallback = function (timestamp) { timestamp = timestamp >>> 0; @@ -106,7 +106,7 @@ IodineGBAWorkerGfxShim.prototype.graphicsHeartBeat = function () { //Copy the buffer out to local: this.consumeGraphicsBuffer(); //Wake up the producer thread: - Atomics.wake(gfxCounters, 2, 1); + Atomics.notify(gfxCounters, 2, 1); } } IodineGBAWorkerGfxShim.prototype.consumeGraphicsBuffer = function () { diff --git a/user_scripts/WorkerGlueCode.js b/user_scripts/WorkerGlueCode.js index bbcf81e..2a697ed 100644 --- a/user_scripts/WorkerGlueCode.js +++ b/user_scripts/WorkerGlueCode.js @@ -1,6 +1,6 @@ "use strict"; /* - Copyright (C) 2012-2017 Grant Galitz + Copyright (C) 2012-2019 Grant Galitz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -57,8 +57,8 @@ IodineGBAWorkerShim.prototype.restart = function () { this.sendMessageSingle(2); } IodineGBAWorkerShim.prototype.setIntervalRate = function (rate) { - rate = rate | 0; - this.sendMessageDouble(3, rate | 0); + rate = +rate; + this.sendMessageDouble(3, +rate); } IodineGBAWorkerShim.prototype.timerCallback = function (timestamp) { timestamp = timestamp >>> 0; @@ -257,7 +257,7 @@ IodineGBAWorkerShim.prototype.graphicsHeartBeat = function () { //Copy the buffer out to local: this.consumeGraphicsBuffer(); //Wake up the producer thread: - Atomics.wake(this.gfxCounters, 2, 1); + Atomics.notify(this.gfxCounters, 2, 1); } } IodineGBAWorkerShim.prototype.consumeGraphicsBuffer = function () {