Skip to content

Commit 8692a94

Browse files
committed
Changed parseInt to Math.floor
1 parent a511931 commit 8692a94

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

source/mappers.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ JSNES.Mappers[0].prototype = {
459459
}
460460
this.nes.ppu.triggerRendering();
461461

462-
var bank4k = parseInt(bank1k / 4, 10) % this.nes.rom.vromCount;
462+
var bank4k = Math.floor(bank1k / 4) % this.nes.rom.vromCount;
463463
var bankoffset = (bank1k % 4) * 1024;
464464
JSNES.Utils.copyArrayElements(this.nes.rom.vrom[bank4k], 0,
465465
this.nes.ppu.vramMem, bankoffset, 1024);
@@ -478,7 +478,7 @@ JSNES.Mappers[0].prototype = {
478478
}
479479
this.nes.ppu.triggerRendering();
480480

481-
var bank4k = parseInt(bank2k / 2, 10) % this.nes.rom.vromCount;
481+
var bank4k = Math.floor(bank2k / 2) % this.nes.rom.vromCount;
482482
var bankoffset = (bank2k % 2) * 2048;
483483
JSNES.Utils.copyArrayElements(this.nes.rom.vrom[bank4k], bankoffset,
484484
this.nes.ppu.vramMem, address, 2048);
@@ -492,7 +492,7 @@ JSNES.Mappers[0].prototype = {
492492
},
493493

494494
load8kRomBank: function(bank8k, address) {
495-
var bank16k = parseInt(bank8k / 2, 10) % this.nes.rom.romCount;
495+
var bank16k = Math.floor(bank8k / 2) % this.nes.rom.romCount;
496496
var offset = (bank8k % 2) * 8192;
497497

498498
//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) {
647647
}
648648
else {
649649
this.load8kVromBank(
650-
parseInt(this.nes.rom.vromCount / 2, 10) +
650+
Math.floor(this.nes.rom.vromCount / 2) +
651651
(value & 0xF),
652652
0x0000
653653
);
@@ -661,7 +661,7 @@ JSNES.Mappers[1].prototype.setReg = function(reg, value) {
661661
}
662662
else {
663663
this.loadVromBank(
664-
parseInt(this.nes.rom.vromCount / 2, 10) +
664+
Math.floor(this.nes.rom.vromCount / 2) +
665665
(value & 0xF),
666666
0x0000
667667
);
@@ -686,7 +686,7 @@ JSNES.Mappers[1].prototype.setReg = function(reg, value) {
686686
}
687687
else {
688688
this.loadVromBank(
689-
parseInt(this.nes.rom.vromCount / 2, 10) +
689+
Math.floor(this.nes.rom.vromCount / 2) +
690690
(value & 0xF),
691691
0x1000
692692
);

source/papu.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,14 @@ JSNES.PAPU = function(nes) {
119119
JSNES.PAPU.prototype = {
120120
reset: function() {
121121
this.sampleRate = this.nes.opts.sampleRate;
122-
this.sampleTimerMax = parseInt(
122+
this.sampleTimerMax = Math.floor(
123123
(1024.0 * this.nes.opts.CPU_FREQ_NTSC *
124124
this.nes.opts.preferredFrameRate) /
125-
(this.sampleRate * 60.0),
126-
10
125+
(this.sampleRate * 60.0)
127126
);
128127

129-
this.frameTime = parseInt(
130-
(14915.0 * this.nes.opts.preferredFrameRate) / 60.0,
131-
10
128+
this.frameTime = Math.floor(
129+
(14915.0 * this.nes.opts.preferredFrameRate) / 60.0
132130
);
133131

134132
this.sampleTimer = 0;
@@ -457,8 +455,8 @@ JSNES.PAPU.prototype = {
457455
accSample: function(cycles) {
458456
// Special treatment for triangle channel - need to interpolate.
459457
if (this.triangle.sampleCondition) {
460-
this.triValue = parseInt((this.triangle.progTimerCount<<4) /
461-
(this.triangle.progTimerMax+1), 10);
458+
this.triValue = Math.floor((this.triangle.progTimerCount << 4) /
459+
(this.triangle.progTimerMax + 1));
462460
if (this.triValue > 16) {
463461
this.triValue = 16;
464462
}
@@ -549,15 +547,15 @@ JSNES.PAPU.prototype = {
549547
if (this.accCount > 0) {
550548

551549
this.smpSquare1 <<= 4;
552-
this.smpSquare1 = parseInt(this.smpSquare1 / this.accCount, 10);
550+
this.smpSquare1 = Math.floor(this.smpSquare1 / this.accCount);
553551

554552
this.smpSquare2 <<= 4;
555-
this.smpSquare2 = parseInt(this.smpSquare2 / this.accCount, 10);
553+
this.smpSquare2 = Math.floor(this.smpSquare2 / this.accCount);
556554

557-
this.smpTriangle = parseInt(this.smpTriangle / this.accCount, 10);
555+
this.smpTriangle = Math.floor(this.smpTriangle / this.accCount);
558556

559557
this.smpDmc <<= 4;
560-
this.smpDmc = parseInt(this.smpDmc / this.accCount, 10);
558+
this.smpDmc = Math.floor(this.smpDmc / this.accCount);
561559

562560
this.accCount = 0;
563561
}
@@ -568,8 +566,8 @@ JSNES.PAPU.prototype = {
568566
this.smpDmc = this.dmc.sample << 4;
569567
}
570568

571-
var smpNoise = parseInt((this.noise.accValue << 4) /
572-
this.noise.accCount, 10);
569+
var smpNoise = Math.floor((this.noise.accValue << 4) /
570+
this.noise.accCount);
573571
this.noise.accValue = smpNoise >> 4;
574572
this.noise.accCount = 1;
575573

@@ -779,7 +777,7 @@ JSNES.PAPU.prototype = {
779777
value = 95.52 / (8128.0 / (i/16.0) + 100.0);
780778
value *= 0.98411;
781779
value *= 50000.0;
782-
ival = parseInt(value, 10);
780+
ival = Math.floor(value);
783781

784782
this.square_table[i] = ival;
785783
if (ival > max_sqr) {
@@ -791,7 +789,7 @@ JSNES.PAPU.prototype = {
791789
value = 163.67 / (24329.0 / (i/16.0) + 100.0);
792790
value *= 0.98411;
793791
value *= 50000.0;
794-
ival = parseInt(value, 10);
792+
ival = Math.floor(value);
795793

796794
this.tnd_table[i] = ival;
797795
if (ival > max_tnd) {

source/ppu.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ JSNES.PPU.prototype = {
14011401
// table buffers with this new byte.
14021402
// In vNES, there is a version of this with 4 arguments which isn't used.
14031403
patternWrite: function(address, value){
1404-
var tileIndex = parseInt(address / 16, 10);
1404+
var tileIndex = Math.floor(address / 16);
14051405
var leftOver = address%16;
14061406
if (leftOver<8) {
14071407
this.ptTile[tileIndex].setScanline(
@@ -1439,7 +1439,7 @@ JSNES.PPU.prototype = {
14391439
// Updates the internally buffered sprite
14401440
// data with this new byte of info.
14411441
spriteRamWriteUpdate: function(address, value) {
1442-
var tIndex = parseInt(address / 4, 10);
1442+
var tIndex = Math.floor(address / 4);
14431443

14441444
if (tIndex === 0) {
14451445
//updateSpr0Hit();
@@ -1564,7 +1564,7 @@ JSNES.PPU.NameTable.prototype = {
15641564

15651565
writeAttrib: function(index, value){
15661566
var basex = (index % 8) * 4;
1567-
var basey = parseInt(index / 8, 10) * 4;
1567+
var basey = Math.floor(index / 8) * 4;
15681568
var add;
15691569
var tx, ty;
15701570
var attindex;
@@ -1622,43 +1622,46 @@ JSNES.PPU.PaletteTable.prototype = {
16221622
},
16231623

16241624
makeTables: function(){
1625-
var r,g,b,col;
1625+
var r, g, b, col, i, rFactor, gFactor, bFactor;
16261626

16271627
// Calculate a table for each possible emphasis setting:
1628-
for (var emph=0;emph<8;emph++) {
1628+
for (var emph = 0; emph < 8; emph++) {
16291629

16301630
// Determine color component factors:
1631-
var rFactor=1.0, gFactor=1.0, bFactor=1.0;
1632-
if ((emph&1)!==0) {
1631+
rFactor = 1.0;
1632+
gFactor = 1.0;
1633+
bFactor = 1.0;
1634+
1635+
if ((emph & 1) !== 0) {
16331636
rFactor = 0.75;
16341637
bFactor = 0.75;
16351638
}
1636-
if ((emph&2)!==0) {
1639+
if ((emph & 2) !== 0) {
16371640
rFactor = 0.75;
16381641
gFactor = 0.75;
16391642
}
1640-
if ((emph&4)!==0) {
1643+
if ((emph & 4) !== 0) {
16411644
gFactor = 0.75;
16421645
bFactor = 0.75;
16431646
}
16441647

16451648
this.emphTable[emph] = new Array(64);
16461649

16471650
// Calculate table:
1648-
for (var i=0;i<64;i++) {
1651+
for (i = 0; i < 64; i++) {
16491652
col = this.curTable[i];
1650-
r = parseInt(this.getRed(col) * rFactor, 10);
1651-
g = parseInt(this.getGreen(col) * gFactor, 10);
1652-
b = parseInt(this.getBlue(col) * bFactor, 10);
1653-
this.emphTable[emph][i] = this.getRgb(r,g,b);
1653+
r = Math.floor(this.getRed(col) * rFactor);
1654+
g = Math.floor(this.getGreen(col) * gFactor);
1655+
b = Math.floor(this.getBlue(col) * bFactor);
1656+
this.emphTable[emph][i] = this.getRgb(r, g, b);
16541657
}
16551658
}
16561659
},
16571660

16581661
setEmphasis: function(emph){
16591662
if (emph != this.currentEmph) {
16601663
this.currentEmph = emph;
1661-
for (var i=0;i<64;i++) {
1664+
for (var i = 0; i < 64; i++) {
16621665
this.curTable[i] = this.emphTable[emph][i];
16631666
}
16641667
}

0 commit comments

Comments
 (0)