From 7bc35ad9af888ae9b7ff798a8a758f7873dda2e1 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Mon, 2 May 2016 16:32:12 -0700 Subject: [PATCH] Move invariant bits out of updateScreen's inner loop --- modules/pc8080/lib/video.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/pc8080/lib/video.js b/modules/pc8080/lib/video.js index 435fbcbb5..c22ce6bfe 100644 --- a/modules/pc8080/lib/video.js +++ b/modules/pc8080/lib/video.js @@ -274,6 +274,14 @@ Video.prototype.updateScreen = function(n) var xBuffer = 0, yBuffer = 0; var xDirty = this.cxBuffer, xMaxDirty = 0, yDirty = this.cyBuffer, yMaxDirty = 0; + var nShiftInit = 0; + var nShiftPixel = this.nBitsPerPixel; + var nMask = (1 << nShiftPixel) - 1; + if (this.iBitFirstPixel) { + nShiftPixel = -nShiftPixel; + nShiftInit = 16 + nShiftPixel; + } + while (addr < addrLimit) { var data = this.bus.getShortDirect(addr); this.assert(iCell < this.aCellCache.length); @@ -281,14 +289,8 @@ Video.prototype.updateScreen = function(n) xBuffer += this.nPixelsPerCell; } else { this.aCellCache[iCell] = data; - var nShift = 0; - var nShiftPixel = this.nBitsPerPixel; - var nMask = (1 << nShiftPixel) - 1; - if (this.iBitFirstPixel) { - nShift = 16 - nShiftPixel; - nShiftPixel = -nShiftPixel; - data = ((data >> 8) | ((data & 0xff) << 8)); - } + var nShift = nShiftInit; + if (nShiftInit) data = ((data >> 8) | ((data & 0xff) << 8)); if (xBuffer < xDirty) xDirty = xBuffer; for (var iPixel = 0; iPixel < this.nPixelsPerCell; iPixel++) { var bPixel = (data >> nShift) & nMask;