summaryrefslogtreecommitdiffstats
path: root/nes.js
diff options
context:
space:
mode:
Diffstat (limited to 'nes.js')
-rw-r--r--nes.js49
1 files changed, 26 insertions, 23 deletions
diff --git a/nes.js b/nes.js
index c606368..5ef45bd 100644
--- a/nes.js
+++ b/nes.js
@@ -66,54 +66,57 @@ function NES() {
this.ppu.startFrame();
var cycles = 0;
var emulateSound = Globals.emulateSound;
+ var cpu = this.cpu;
+ var ppu = this.ppu;
+ var papu = this.papu;
FRAMELOOP: for (;;) {
- if (this.cpu.cyclesToHalt == 0) {
+ if (cpu.cyclesToHalt == 0) {
// Execute a CPU instruction
- cycles = this.cpu.emulate();
- if(emulateSound) {
- this.papu.clockFrameCounter(cycles);
+ cycles = cpu.emulate();
+ if (emulateSound) {
+ papu.clockFrameCounter(cycles);
}
cycles *= 3;
}
else {
- if (this.cpu.cyclesToHalt > 8) {
+ if (cpu.cyclesToHalt > 8) {
cycles = 24;
if (emulateSound) {
- this.papu.clockFrameCounter(8);
+ papu.clockFrameCounter(8);
}
- this.cpu.cyclesToHalt -= 8;
+ cpu.cyclesToHalt -= 8;
}
else {
- cycles = this.cpu.cyclesToHalt * 3;
+ cycles = cpu.cyclesToHalt * 3;
if (emulateSound) {
- this.papu.clockFrameCounter(this.cpu.cyclesToHalt);
+ papu.clockFrameCounter(cpu.cyclesToHalt);
}
- this.cpu.cyclesToHalt = 0;
+ cpu.cyclesToHalt = 0;
}
}
for(;cycles>0;cycles--){
- if(this.ppu.curX == this.ppu.spr0HitX
- && this.ppu.f_spVisibility==1
- && this.ppu.scanline-21 == this.ppu.spr0HitY){
+ if(ppu.curX == ppu.spr0HitX
+ && ppu.f_spVisibility==1
+ && ppu.scanline-21 == ppu.spr0HitY){
// Set sprite 0 hit flag:
- this.ppu.setStatusFlag(this.ppu.STATUS_SPRITE0HIT,true);
+ ppu.setStatusFlag(ppu.STATUS_SPRITE0HIT,true);
}
- if(this.ppu.requestEndFrame){
- this.ppu.nmiCounter--;
- if(this.ppu.nmiCounter == 0){
- this.ppu.requestEndFrame = false;
- this.ppu.startVBlank();
+ if(ppu.requestEndFrame){
+ ppu.nmiCounter--;
+ if(ppu.nmiCounter == 0){
+ ppu.requestEndFrame = false;
+ ppu.startVBlank();
break FRAMELOOP;
}
}
- this.ppu.curX++;
- if(this.ppu.curX==341){
- this.ppu.curX = 0;
- this.ppu.endScanline();
+ ppu.curX++;
+ if(ppu.curX==341){
+ ppu.curX = 0;
+ ppu.endScanline();
}
}