mirror of
https://github.com/DPS2004/gba.git
synced 2025-01-22 12:32:54 -03:00
Updating
This commit is contained in:
parent
17fc685387
commit
ea716ffb7c
8 changed files with 55 additions and 30 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Add table
Reference in a new issue