Skip to content

Commit

Permalink
Reduce number of memory reads made by the GPU
Browse files Browse the repository at this point in the history
  • Loading branch information
denislins committed Aug 6, 2019
1 parent 6905220 commit 2648312
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions emulator/gpu/Gpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ export default class Gpu {
}

changeMode(newMode) {
if (this.currentMode !== newMode) {
const currentMode = this.lcdStatus.getCurrentMode();

if (currentMode !== newMode) {
this.lcdStatus.changeMode(newMode);

if (this.currentMode === 'pixelTransfer') {
if (currentMode === 'pixelTransfer') {
this.execPixelTransfer();
} else if (this.currentMode === 'vblank') {
} else if (currentMode === 'vblank') {
Observer.trigger('interrupts.request', { type: 'vblank' });
}

Expand All @@ -88,31 +90,22 @@ export default class Gpu {
}

requestModeChangedInterrupt() {
const currentMode = this.lcdStatus.getCurrentMode();
let shouldRequestInterrupt = false;

switch (this.currentMode) {
case 'hblank':
shouldRequestInterrupt = this.lcdStatus.isHblankInterruptEnabled();
break;

case 'vblank':
shouldRequestInterrupt = this.lcdStatus.isVblankInterruptEnabled();
break;

case 'oamSearch':
shouldRequestInterrupt = this.lcdStatus.isOamSearchInterruptEnabled();
break;
if (currentMode === 'hblank') {
shouldRequestInterrupt = this.lcdStatus.isHblankInterruptEnabled();
} else if (currentMode === 'vblank') {
shouldRequestInterrupt = this.lcdStatus.isVblankInterruptEnabled();
} else if (currentMode === 'oamSearch') {
shouldRequestInterrupt = this.lcdStatus.isOamSearchInterruptEnabled();
}

if (shouldRequestInterrupt) {
Observer.trigger('interrupts.request', { type: 'lcd' });
}
}

get currentMode() {
return this.lcdStatus.getCurrentMode();
}

get currentRow() {
return this.mmu.registers.read('scanline');
}
Expand Down

0 comments on commit 2648312

Please sign in to comment.