Use bit math more places. (#15)

This commit is contained in:
Will Scullin 2019-11-23 19:05:52 -08:00 committed by GitHub
parent 17b54bd793
commit 5e4aac70d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 52 deletions

View File

@ -106,14 +106,15 @@ export function LoresPage(page, charset, e, context)
data[off + 0] = data[off + 4] = c0;
data[off + 1] = data[off + 5] = c1;
data[off + 2] = data[off + 6] = c2;
var nextOff = off + 560 * 4;
if (!scanlines) {
data[off + 560 * 4] = data[off + 560 * 4 + 4] = c0;
data[off + 560 * 4 + 1] = data[off + 560 * 4 + 5] = c1;
data[off + 560 * 4 + 2] = data[off + 560 * 4 + 6] = c2;
data[nextOff] = data[nextOff + 4] = c0;
data[nextOff + 1] = data[nextOff + 5] = c1;
data[nextOff + 2] = data[nextOff + 6] = c2;
} else {
data[off + 560 * 4] = data[off + 560 * 4 + 4] = c0 >> 1;
data[off + 560 * 4 + 1] = data[off + 560 * 4 + 5] = c1 >> 1;
data[off + 560 * 4 + 2] = data[off + 560 * 4 + 6] = c2 >> 1;
data[nextOff] = data[nextOff + 4] = c0 >> 1;
data[nextOff + 1] = data[nextOff + 5] = c1 >> 1;
data[nextOff + 2] = data[nextOff + 6] = c2 >> 1;
}
}
@ -122,14 +123,15 @@ export function LoresPage(page, charset, e, context)
data[off + 0] = c0;
data[off + 1] = c1;
data[off + 2] = c2;
var nextOff = off + 560 * 4;
if (!scanlines) {
data[off + 560 * 4] = c0;
data[off + 560 * 4 + 1] = c1;
data[off + 560 * 4 + 2] = c2;
data[nextOff] = c0;
data[nextOff + 1] = c1;
data[nextOff + 2] = c2;
} else {
data[off + 560 * 4] = c0 >> 1;
data[off + 560 * 4 + 1] = c1 >> 1;
data[off + 560 * 4 + 2] = c2 >> 1;
data[nextOff] = c0 >> 1;
data[nextOff + 1] = c1 >> 1;
data[nextOff + 2] = c2 >> 1;
}
}
@ -207,7 +209,7 @@ export function LoresPage(page, charset, e, context)
var data = _imageData.data;
if ((row < 24) && (col < 40)) {
var y = row * 16;
var y = row << 4;
if (y < _dirty.top) { _dirty.top = y; }
y += 16;
if (y > _dirty.bottom) { _dirty.bottom = y; }
@ -553,14 +555,15 @@ export function HiresPage(page, context)
data[off + 0] = data[off + 4] = c0;
data[off + 1] = data[off + 5] = c1;
data[off + 2] = data[off + 6] = c2;
var nextOff = off + 560 * 4;
if (!scanlines) {
data[off + 560 * 4] = data[off + 560 * 4 + 4] = c0;
data[off + 560 * 4 + 1] = data[off + 560 * 4 + 5] = c1;
data[off + 560 * 4 + 2] = data[off + 560 * 4 + 6] = c2;
data[nextOff] = data[nextOff + 4] = c0;
data[nextOff + 1] = data[nextOff + 5] = c1;
data[nextOff + 2] = data[nextOff + 6] = c2;
} else {
data[off + 560 * 4] = data[off + 560 * 4 + 4] = c0 >> 1;
data[off + 560 * 4 + 1] = data[off + 560 * 4 + 5] = c1 >> 1;
data[off + 560 * 4 + 2] = data[off + 560 * 4 + 6] = c2 >> 1;
data[nextOff] = data[nextOff + 4] = c0 >> 1;
data[nextOff + 1] = data[nextOff + 5] = c1 >> 1;
data[nextOff + 2] = data[nextOff + 6] = c2 >> 1;
}
}
@ -569,14 +572,16 @@ export function HiresPage(page, context)
data[off + 0] = c0;
data[off + 1] = c1;
data[off + 2] = c2;
var nextOff = off + 560 * 4;
if (!scanlines) {
data[off + 560 * 4] = c0;
data[off + 560 * 4 + 1] = c1;
data[off + 560 * 4 + 2] = c2;
data[nextOff] = c0;
data[nextOff + 1] = c1;
data[nextOff + 2] = c2;
} else {
data[off + 560 * 4] = c0 >> 1;
data[off + 560 * 4 + 1] = c1 >> 1;
data[off + 560 * 4 + 2] = c2 >> 1;
data[nextOff] = c0 >> 1;
data[nextOff + 1] = c1 >> 1;
data[nextOff + 2] = c2 >> 1;
}
}
@ -661,7 +666,7 @@ export function HiresPage(page, context)
return;
}
var y = rowa * 16 + rowb * 2;
var y = rowa << 4 | rowb << 1;
if (y < _dirty.top) { _dirty.top = y; }
y += 2;
if (y > _dirty.bottom) { _dirty.bottom = y; }
@ -670,7 +675,7 @@ export function HiresPage(page, context)
x += 14;
if (x > _dirty.right) { _dirty.right = x; }
dy = rowa * 16 + rowb * 2;
dy = rowa << 4 | rowb << 1;
var bz, b0, b1, b2, b3, b4, c, hb;
if (doubleHiresMode) {
// Every 4 bytes is 7 pixels
@ -681,13 +686,13 @@ export function HiresPage(page, context)
// 76543210 76543210 76543210 76543210
// 1111222 2333344 4455556 6667777
var mod = col % 2, mcol = col - mod;
bz = _buffer[0][base - mod - 1];
b0 = _buffer[1][base - mod];
b1 = _buffer[0][base - mod];
b2 = _buffer[1][base - mod + 1];
b3 = _buffer[0][base - mod + 1];
b4 = _buffer[1][base - mod + 2];
var mod = col % 2, mcol = col - mod, baseOff = base - mod;
bz = _buffer[0][baseOff - 1];
b0 = _buffer[1][baseOff];
b1 = _buffer[0][baseOff];
b2 = _buffer[1][baseOff + 1];
b3 = _buffer[0][baseOff + 1];
b4 = _buffer[1][baseOff + 2];
c = [
0,
((b0 & 0x0f) >> 0), // 0

View File

@ -1159,9 +1159,9 @@ export default function RAMFactor(io, slot, size) {
read: function ramfactor_read(page, off) {
var result;
if (page == 0xc0 + slot) {
result = rom[slot * 0x100 + off];
result = rom[slot << 8 | off];
} else {
result = rom[_firmware * 0x1000 + (page - 0xC0) * 0x100 + off];
result = rom[_firmware << 12 | (page - 0xC0) << 8 | off];
}
return result;
},

View File

@ -493,8 +493,8 @@ export default function Videoterm(io, slot, context) {
var row = (saddr / 80) & 0xff;
var col = saddr % 80;
var x = col * 7;
var y = row * 16;
var c = val * 16;
var y = row << 4;
var c = val << 4;
var color;
if (row < 25) {

View File

@ -19,12 +19,6 @@ export default function RAM(sp, ep) {
mem = allocMemPages(ep - sp + 1);
for (var page = 0; page <= ep; page++) {
for (var off = 0; off < 0x100; off++) {
mem[page * 0x100 + off] = 0; // Math.floor(Math.random()*256);
}
}
return {
start: function() {
return start_page;
@ -33,10 +27,10 @@ export default function RAM(sp, ep) {
return end_page;
},
read: function(page, off) {
return mem[(page - start_page) * 0x100 + off];
return mem[(page - start_page) << 8 | off];
},
write: function(page, off, val) {
mem[(page - start_page) * 0x100 + off] = val;
mem[(page - start_page) << 8 | off] = val;
},
getState: function() {

View File

@ -1547,7 +1547,7 @@ export default function IntBASIC()
return 0xff;
},
read: function(page, off) {
return rom[((page - 0xD0) << 8) + off];
return rom[(page - 0xD0) << 8 | off];
},
write: function() {
}

View File

@ -39,7 +39,7 @@ export function allocMem(size) {
}
export function allocMemPages(pages) {
return allocMem(pages * 0x100);
return allocMem(pages << 8);
}
export function bytify(ary) {

View File

@ -8204,10 +8204,10 @@ export default function Test6502() {
return 0xff;
},
read: function(page, off) {
return data[page * 0x100 + off];
return data[page << 8 | off];
},
write: function(page, off, val) {
data[page * 0x100 + off] = val;
data[page << 8 | off] = val;
}
};
}

View File

@ -8204,10 +8204,10 @@ export default function Test65C02() {
return 0xff;
},
read: function(page, off) {
return data[page * 0x100 + off];
return data[page << 8 | off];
},
write: function(page, off, val) {
data[page * 0x100 + off] = val;
data[page << 8 | off] = val;
}
};
}