/** * Memory Chip Class */ /** * Memory Chip Constructor */ function MemoryChip(container) { //Build HTML DOM var table = document.createElement("TABLE"); var tr = table.insertRow(0); tr.style.height = COMPONENT_HEIGHT; tr.style.verticalAlign = "top"; var td = tr.insertCell(0); var ttl = document.createElement("DIV"); ttl.innerHTML = "זיכרון ראשי"; ttl.style.color = LABEL_COLOR; ttl.style.fontWeight = "bold"; ttl.style.width = "100%"; ttl.style.textAlign = "center"; td.appendChild(ttl); //td.appendChild(document.createElement("BR")); var innerTable = document.createElement("TABLE"); var row = innerTable.insertRow(0); var cell0 = row.insertCell(0); var spacer = row.insertCell(1); var cell1 = row.insertCell(2); td.appendChild(innerTable); spacer.style.width = "20px"; //00 - 49 var lowDiv = document.createElement("DIV"); cell0.appendChild(lowDiv); //50 - 99 var highDiv = document.createElement("DIV"); cell1.appendChild(highDiv); table.style.borderWidth = "0"; //table.style.borderColor = "#000000"; //table.style.borderStyle = "Solid"; table.cellSpacing = "0"; this.left = table.offsetLeft; this.top = table.offsetTop; container.appendChild(table); //Init DataArrays var lowRAM = new DataArray(50, LIST_WIDTH + 35, 369, 0); appendDataArray(lowDiv, lowRAM); var highRAM = new DataArray(50, LIST_WIDTH + 35, 369, 50); appendDataArray(highDiv, highRAM); /* //Deprecated (not needed since there's SET command //Set cell 98 to zero and cell 99 to 1 and disable them. highRAM.getCellAt(98).enabled = false; highRAM.getCellAt(99).setValue(1); highRAM.getCellAt(99).enabled = false; */ highRAM.getCellAt(99).highlight(true); highRAM.getCellAt(99).highlight(false); var that = this; /** * Returns the DataCell at a given address */ this.getMemoryCell = function(address) { if (address < 0 || address > 99) return 0; var memoryUnit; if (address >= 0 && address <= 49) memoryUnit = lowRAM; else memoryUnit = highRAM; return memoryUnit.getCellAt(address); } /** * Returns the value stored in the given memory address */ this.load = function(address) { return that.getMemoryCell(address).getValue(); } /** * Stores a given value at the specified memory address */ this.store = function(address, value) { that.getMemoryCell(address).setValue(value); } /** * Resets memory to its initial state */ this.reset = function() { lowDiv.removeChild(lowRAM.frameDiv); highDiv.removeChild(highRAM.frameDiv); lowRAM = new DataArray(50, LIST_WIDTH + 35, 369, 0); appendDataArray(lowDiv, lowRAM); highRAM = new DataArray(50, LIST_WIDTH + 35, 369, 50); appendDataArray(highDiv, highRAM); that.getMemoryCell(99).highlight(false); } /** * Clears high memory */ this.clearHighMemory = function() { highDiv.removeChild(highRAM.frameDiv); highRAM = new DataArray(50, LIST_WIDTH + 35, 369, 50); appendDataArray(highDiv, highRAM); that.getMemoryCell(99).highlight(false); } /** * Enables/disables the chip */ this.enable = function(value) { lowRAM.enabled = value; highRAM.enabled = value; } this.showValues = function() { lowRAM.showValues(); highRAM.showValues(); } }