diff options
Diffstat (limited to 'js.2/nes.js')
-rw-r--r-- | js.2/nes.js | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/js.2/nes.js b/js.2/nes.js index 74b71cb..e06f714 100644 --- a/js.2/nes.js +++ b/js.2/nes.js @@ -8,10 +8,10 @@ var JSNES = function(parent) { emulateSound: false, sampleRate: 44100, // Sound sample rate in hz - CPU_FREQ_NTSC: 1789772.5,//1789772.72727272d; - CPU_FREQ_PAL: 1773447.4, - } - this.frameTime = 1000/this.opts.preferredFrameRate; + CPU_FREQ_NTSC: 1789772.5, //1789772.72727272d; + CPU_FREQ_PAL: 1773447.4 + }; + this.frameTime = 1000 / this.opts.preferredFrameRate; this.ui = new JSNES.UI(this, parent); this.cpu = new JSNES.CPU(this); @@ -32,7 +32,7 @@ JSNES.prototype = { // Resets the system. reset: function() { - if(this.mmap != null) { + if (this.mmap !== null) { this.mmap.reset(); } @@ -44,13 +44,13 @@ JSNES.prototype = { start: function() { var self = this; - if(this.rom != null && this.rom.valid) { + if (this.rom !== null && this.rom.valid) { if (!this.isRunning) { this.isRunning = true; this.frameInterval = setInterval(function() { self.frame(); - }, this.frameTime/2); + }, this.frameTime / 2); this.resetFps(); this.printFps(); this.fpsInterval = setInterval(function() { @@ -59,7 +59,7 @@ JSNES.prototype = { } } else { - alert("There is no ROM loaded, or it is invalid."); + this.ui.updateStatus("There is no ROM loaded, or it is invalid."); } }, @@ -71,7 +71,7 @@ JSNES.prototype = { var ppu = this.ppu; var papu = this.papu; FRAMELOOP: for (;;) { - if (cpu.cyclesToHalt == 0) { + if (cpu.cyclesToHalt === 0) { // Execute a CPU instruction cycles = cpu.emulate(); if (emulateSound) { @@ -96,18 +96,17 @@ JSNES.prototype = { } } - for(;cycles>0;cycles--){ - - if(ppu.curX == ppu.spr0HitX - && ppu.f_spVisibility==1 - && ppu.scanline-21 == ppu.spr0HitY){ + for (; cycles > 0; cycles--) { + if(ppu.curX === ppu.spr0HitX && + ppu.f_spVisibility === 1 && + ppu.scanline - 21 === ppu.spr0HitY) { // Set sprite 0 hit flag: - ppu.setStatusFlag(ppu.STATUS_SPRITE0HIT,true); + ppu.setStatusFlag(ppu.STATUS_SPRITE0HIT, true); } - if(ppu.requestEndFrame){ + if (ppu.requestEndFrame) { ppu.nmiCounter--; - if(ppu.nmiCounter == 0){ + if (ppu.nmiCounter === 0) { ppu.requestEndFrame = false; ppu.startVBlank(); break FRAMELOOP; @@ -115,29 +114,30 @@ JSNES.prototype = { } ppu.curX++; - if(ppu.curX==341){ + if (ppu.curX === 341) { ppu.curX = 0; ppu.endScanline(); } - } } if (this.limitFrames) { if (this.lastFrameTime) { - while ((new Date()).getTime() - this.lastFrameTime < this.frameTime) { + while (+new Date() - this.lastFrameTime < this.frameTime) { // twiddle thumbs } } } this.fpsFrameCount++; - this.lastFrameTime = (new Date()).getTime(); + this.lastFrameTime = +new Date(); }, printFps: function() { - var now = (new Date()).getTime(); + var now = +new Date(); var s = 'Running'; if (this.lastFpsTime) { - s += ': '+(this.fpsFrameCount/((now-this.lastFpsTime)/1000)).toFixed(2)+' FPS'; + s += ': '+( + this.fpsFrameCount / ((now - this.lastFpsTime) / 1000) + ).toFixed(2)+' FPS'; } this.ui.updateStatus(s); this.fpsFrameCount = 0; @@ -151,7 +151,7 @@ JSNES.prototype = { }, reloadRom: function() { - if(this.romData != null){ + if (this.romData !== null) { this.loadRom(this.romData); } }, @@ -194,8 +194,8 @@ JSNES.prototype = { setFramerate: function(rate){ this.nes.opts.preferredFrameRate = rate; - this.nes.frameTime = 1000/rate; - papu.setSampleRate(this.opts.sampleRate, false); + this.nes.frameTime = 1000 / rate; + this.papu.setSampleRate(this.opts.sampleRate, false); }, setLimitFrames: function(limit) { |