Permalink
Browse files

Keep track of dirty bits for memory.

This lets us optimize re-drawing the memory display.
  • Loading branch information...
1 parent 16234bb commit 51d156c83a1cca039cc3522435a5209cb50b5561 @nelhage committed Jun 7, 2011
Showing with 14 additions and 3 deletions.
  1. +8 −0 MMU.js
  2. +6 −3 betaweb.js
View
@@ -1,7 +1,9 @@
var MMU = {
memory: [],
+ dirty: [],
load: function (mem) {
MMU.memory = mem.map(function(x){return x&0xFFFFFFFF;});
+ MMU.dirty = mem.map(function(x){return 0;});
},
read: function(addr) {
var ea = (addr & ~CPU.PC_SUPERVISOR) >> 2;
@@ -15,7 +17,13 @@ var MMU = {
if (ea >= MMU.memory.length) {
throw new Error("Invalid read: " + (addr & ~CPU.PC_SUPERVISOR));
}
+ MMU.dirty[ea] = 1;
MMU.memory[ea] = data;
+ },
+ clear_dirty: function() {
+ var i;
+ for (i = 0; i < MMU.dirty.length; i++)
+ MMU.dirty[i] = 0;
}
};
View
@@ -129,7 +129,7 @@ function resetBeta(rom) {
var th = document.createElement('th');
var td = document.createElement('td');
th.textContent = toHex(4*i);
- td.appendChild(document.createTextNode())
+ td.appendChild(document.createTextNode(toHex(MMU.memory[i])));
tr.appendChild(th);
tr.appendChild(td);
BETA.memTab.appendChild(tr);
@@ -175,8 +175,11 @@ function refreshDisplay() {
for (i = 0; i < 31; i++)
BETA.regCells[i].textContent = toHex(CPU.regs[i]);
- for (i = 0; i < MMU.memory.length; i++)
- BETA.memTab.rows[i].cells[1].firstChild.textContent = toHex(MMU.memory[i]);
+ for (i = 0; i < MMU.dirty.length; i++) {
+ if (MMU.dirty[i])
+ BETA.memTab.rows[i].cells[1].firstChild.textContent = toHex(MMU.memory[i]);
+ }
+ MMU.clear_dirty();
}
function initTerm() {

0 comments on commit 51d156c

Please sign in to comment.