Permalink
Browse files

Changed parseInt to Math.floor

  • Loading branch information...
1 parent a511931 commit 8692a948c9c02669fc45914dceb87ae5b28e1ead @bfirsh committed Sep 26, 2010
Showing with 38 additions and 37 deletions.
  1. +6 −6 source/mappers.js
  2. +14 −16 source/papu.js
  3. +18 −15 source/ppu.js
View
@@ -459,7 +459,7 @@ JSNES.Mappers[0].prototype = {
}
this.nes.ppu.triggerRendering();
- var bank4k = parseInt(bank1k / 4, 10) % this.nes.rom.vromCount;
+ var bank4k = Math.floor(bank1k / 4) % this.nes.rom.vromCount;
var bankoffset = (bank1k % 4) * 1024;
JSNES.Utils.copyArrayElements(this.nes.rom.vrom[bank4k], 0,
this.nes.ppu.vramMem, bankoffset, 1024);
@@ -478,7 +478,7 @@ JSNES.Mappers[0].prototype = {
}
this.nes.ppu.triggerRendering();
- var bank4k = parseInt(bank2k / 2, 10) % this.nes.rom.vromCount;
+ var bank4k = Math.floor(bank2k / 2) % this.nes.rom.vromCount;
var bankoffset = (bank2k % 2) * 2048;
JSNES.Utils.copyArrayElements(this.nes.rom.vrom[bank4k], bankoffset,
this.nes.ppu.vramMem, address, 2048);
@@ -492,7 +492,7 @@ JSNES.Mappers[0].prototype = {
},
load8kRomBank: function(bank8k, address) {
- var bank16k = parseInt(bank8k / 2, 10) % this.nes.rom.romCount;
+ var bank16k = Math.floor(bank8k / 2) % this.nes.rom.romCount;
var offset = (bank8k % 2) * 8192;
//this.nes.cpu.mem.write(address,this.nes.rom.rom[bank16k],offset,8192);
@@ -647,7 +647,7 @@ JSNES.Mappers[1].prototype.setReg = function(reg, value) {
}
else {
this.load8kVromBank(
- parseInt(this.nes.rom.vromCount / 2, 10) +
+ Math.floor(this.nes.rom.vromCount / 2) +
(value & 0xF),
0x0000
);
@@ -661,7 +661,7 @@ JSNES.Mappers[1].prototype.setReg = function(reg, value) {
}
else {
this.loadVromBank(
- parseInt(this.nes.rom.vromCount / 2, 10) +
+ Math.floor(this.nes.rom.vromCount / 2) +
(value & 0xF),
0x0000
);
@@ -686,7 +686,7 @@ JSNES.Mappers[1].prototype.setReg = function(reg, value) {
}
else {
this.loadVromBank(
- parseInt(this.nes.rom.vromCount / 2, 10) +
+ Math.floor(this.nes.rom.vromCount / 2) +
(value & 0xF),
0x1000
);
View
@@ -119,16 +119,14 @@ JSNES.PAPU = function(nes) {
JSNES.PAPU.prototype = {
reset: function() {
this.sampleRate = this.nes.opts.sampleRate;
- this.sampleTimerMax = parseInt(
+ this.sampleTimerMax = Math.floor(
(1024.0 * this.nes.opts.CPU_FREQ_NTSC *
this.nes.opts.preferredFrameRate) /
- (this.sampleRate * 60.0),
- 10
+ (this.sampleRate * 60.0)
);
- this.frameTime = parseInt(
- (14915.0 * this.nes.opts.preferredFrameRate) / 60.0,
- 10
+ this.frameTime = Math.floor(
+ (14915.0 * this.nes.opts.preferredFrameRate) / 60.0
);
this.sampleTimer = 0;
@@ -457,8 +455,8 @@ JSNES.PAPU.prototype = {
accSample: function(cycles) {
// Special treatment for triangle channel - need to interpolate.
if (this.triangle.sampleCondition) {
- this.triValue = parseInt((this.triangle.progTimerCount<<4) /
- (this.triangle.progTimerMax+1), 10);
+ this.triValue = Math.floor((this.triangle.progTimerCount << 4) /
+ (this.triangle.progTimerMax + 1));
if (this.triValue > 16) {
this.triValue = 16;
}
@@ -549,15 +547,15 @@ JSNES.PAPU.prototype = {
if (this.accCount > 0) {
this.smpSquare1 <<= 4;
- this.smpSquare1 = parseInt(this.smpSquare1 / this.accCount, 10);
+ this.smpSquare1 = Math.floor(this.smpSquare1 / this.accCount);
this.smpSquare2 <<= 4;
- this.smpSquare2 = parseInt(this.smpSquare2 / this.accCount, 10);
+ this.smpSquare2 = Math.floor(this.smpSquare2 / this.accCount);
- this.smpTriangle = parseInt(this.smpTriangle / this.accCount, 10);
+ this.smpTriangle = Math.floor(this.smpTriangle / this.accCount);
this.smpDmc <<= 4;
- this.smpDmc = parseInt(this.smpDmc / this.accCount, 10);
+ this.smpDmc = Math.floor(this.smpDmc / this.accCount);
this.accCount = 0;
}
@@ -568,8 +566,8 @@ JSNES.PAPU.prototype = {
this.smpDmc = this.dmc.sample << 4;
}
- var smpNoise = parseInt((this.noise.accValue << 4) /
- this.noise.accCount, 10);
+ var smpNoise = Math.floor((this.noise.accValue << 4) /
+ this.noise.accCount);
this.noise.accValue = smpNoise >> 4;
this.noise.accCount = 1;
@@ -779,7 +777,7 @@ JSNES.PAPU.prototype = {
value = 95.52 / (8128.0 / (i/16.0) + 100.0);
value *= 0.98411;
value *= 50000.0;
- ival = parseInt(value, 10);
+ ival = Math.floor(value);
this.square_table[i] = ival;
if (ival > max_sqr) {
@@ -791,7 +789,7 @@ JSNES.PAPU.prototype = {
value = 163.67 / (24329.0 / (i/16.0) + 100.0);
value *= 0.98411;
value *= 50000.0;
- ival = parseInt(value, 10);
+ ival = Math.floor(value);
this.tnd_table[i] = ival;
if (ival > max_tnd) {
View
@@ -1401,7 +1401,7 @@ JSNES.PPU.prototype = {
// table buffers with this new byte.
// In vNES, there is a version of this with 4 arguments which isn't used.
patternWrite: function(address, value){
- var tileIndex = parseInt(address / 16, 10);
+ var tileIndex = Math.floor(address / 16);
var leftOver = address%16;
if (leftOver<8) {
this.ptTile[tileIndex].setScanline(
@@ -1439,7 +1439,7 @@ JSNES.PPU.prototype = {
// Updates the internally buffered sprite
// data with this new byte of info.
spriteRamWriteUpdate: function(address, value) {
- var tIndex = parseInt(address / 4, 10);
+ var tIndex = Math.floor(address / 4);
if (tIndex === 0) {
//updateSpr0Hit();
@@ -1564,7 +1564,7 @@ JSNES.PPU.NameTable.prototype = {
writeAttrib: function(index, value){
var basex = (index % 8) * 4;
- var basey = parseInt(index / 8, 10) * 4;
+ var basey = Math.floor(index / 8) * 4;
var add;
var tx, ty;
var attindex;
@@ -1622,43 +1622,46 @@ JSNES.PPU.PaletteTable.prototype = {
},
makeTables: function(){
- var r,g,b,col;
+ var r, g, b, col, i, rFactor, gFactor, bFactor;
// Calculate a table for each possible emphasis setting:
- for (var emph=0;emph<8;emph++) {
+ for (var emph = 0; emph < 8; emph++) {
// Determine color component factors:
- var rFactor=1.0, gFactor=1.0, bFactor=1.0;
- if ((emph&1)!==0) {
+ rFactor = 1.0;
+ gFactor = 1.0;
+ bFactor = 1.0;
+
+ if ((emph & 1) !== 0) {
rFactor = 0.75;
bFactor = 0.75;
}
- if ((emph&2)!==0) {
+ if ((emph & 2) !== 0) {
rFactor = 0.75;
gFactor = 0.75;
}
- if ((emph&4)!==0) {
+ if ((emph & 4) !== 0) {
gFactor = 0.75;
bFactor = 0.75;
}
this.emphTable[emph] = new Array(64);
// Calculate table:
- for (var i=0;i<64;i++) {
+ for (i = 0; i < 64; i++) {
col = this.curTable[i];
- r = parseInt(this.getRed(col) * rFactor, 10);
- g = parseInt(this.getGreen(col) * gFactor, 10);
- b = parseInt(this.getBlue(col) * bFactor, 10);
- this.emphTable[emph][i] = this.getRgb(r,g,b);
+ r = Math.floor(this.getRed(col) * rFactor);
+ g = Math.floor(this.getGreen(col) * gFactor);
+ b = Math.floor(this.getBlue(col) * bFactor);
+ this.emphTable[emph][i] = this.getRgb(r, g, b);
}
}
},
setEmphasis: function(emph){
if (emph != this.currentEmph) {
this.currentEmph = emph;
- for (var i=0;i<64;i++) {
+ for (var i = 0; i < 64; i++) {
this.curTable[i] = this.emphTable[emph][i];
}
}

0 comments on commit 8692a94

Please sign in to comment.