/** * CPU Chip Class */ /* ## class CPUChip implements computer.primitives.IDataSet */ /** * CPU Chip Constructor */ function CPUChip(container) { //Build the 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); //***INNER TABLE var table2 = document.createElement("TABLE"); td.appendChild(table2); var tr2 = table2.insertRow(0); var td23 = tr2.insertCell(0); var td2 = tr2.insertCell(1); //Instruction Register td2.appendChild(document.createElement("BR")); td2.appendChild(document.createElement("BR")); var divInst = document.createElement("DIV"); divInst.style.backgroundColor = CELL_COLOR; divInst.style.width = ((parseInt(CELL_HEIGHT) + 5) * 2) + "px"; divInst.id = "___instruction_div_container"; var cent1 = td2.appendChild(document.createElement("CENTER")); var b2 = cent1.appendChild(document.createElement("SPAN")); b2.innerHTML = "אוגר פקודה"; b2.style.color = LABEL_COLOR; b2.style.fontSize = "12px"; b2.style.fontWeight = "bold"; cent1.appendChild(document.createElement("BR")); var outdivInst = document.createElement("DIV"); cent1.appendChild(outdivInst); outdivInst.style.backgroundColor = CELL_COLOR; outdivInst.style.width = "90px"; outdivInst.style.height = "46px"; outdivInst.style.lineHeight = "10px"; //outdivInst.style.borderStyle = "Solid"; //outdivInst.style.borderWidth = "1px"; //outdivInst.style.borderColor = "#000000"; outdivInst.style.backgroundImage = "url(../Borders/register_all.gif)"; outdivInst.style.horizontalAlign = "center"; outdivInst.style.verticalAlign = "bottom"; outdivInst.appendChild(document.createElement("BR")); outdivInst.appendChild(divInst); //Instruction Label var instLabel = document.createElement("DIV"); instLabel.style.width = "160"; instLabel.style.fontFamily = "Arial"; instLabel.style.fontSize = "10px"; instLabel.style.fontWeight = "bolder"; instLabel.style.textAlign = "center"; instLabel.innerHTML = ""; instLabel.style.color = LABEL_COLOR; td2.appendChild(instLabel); td2.appendChild(document.createElement("BR")); td2.appendChild(document.createElement("BR")); //Data Register var divData = document.createElement("DIV"); divData.style.backgroundColor = CELL_COLOR; divData.style.width = ((parseInt(CELL_HEIGHT) + 5) * 2) + "px"; divData.id = "___data_div_container"; var cent2 = td2.appendChild(document.createElement("CENTER")); var b3 = cent2.appendChild(document.createElement("SPAN")); b3.innerHTML = "אוגר נתון"; b3.style.fontSize = "12px"; b3.style.fontWeight = "bold"; b3.style.color = LABEL_COLOR; cent2.appendChild(document.createElement("BR")); var outdivData = document.createElement("DIV"); cent2.appendChild(outdivData); outdivData.style.backgroundColor = CELL_COLOR; outdivData.style.width = "90px"; outdivData.style.height = "46px"; outdivData.style.lineHeight = "10px"; //outdivData.style.borderStyle = "Solid"; //outdivData.style.borderWidth = "1px"; //outdivData.style.borderColor = "#000000"; outdivData.style.backgroundImage = "url(../Borders/register_all.gif)"; outdivData.style.horizontalAlign = "center"; outdivData.style.verticalAlign = "bottom"; outdivData.appendChild(document.createElement("BR")); outdivData.appendChild(divData); td2.appendChild(document.createElement("BR")); td2.appendChild(document.createElement("BR")); td2.appendChild(document.createElement("BR")); //Program Counter var divPC = document.createElement("DIV"); divPC.style.backgroundColor = CELL_COLOR; divPC.style.width = ((parseInt(CELL_HEIGHT) + 5) * 2) + "px"; divPC.id = "___pc_div_container"; var cent3 = td2.appendChild(document.createElement("CENTER")); var b4 = cent3.appendChild(document.createElement("SPAN")); b4.innerHTML = "מונה פקודות"; b4.style.fontSize = "12px"; b4.style.fontWeight = "bold"; b4.style.color = LABEL_COLOR; cent3.appendChild(document.createElement("BR")); var outdivPC = document.createElement("DIV"); cent3.appendChild(outdivPC); outdivPC.style.backgroundColor = CELL_COLOR; outdivPC.style.width = "90px"; outdivPC.style.height = "46px"; outdivPC.style.lineHeight = "10px"; //outdivPC.style.borderStyle = "Solid"; //outdivPC.style.borderWidth = "1px"; //outdivPC.style.borderColor = "#000000"; outdivPC.style.backgroundImage = "url(../Borders/register_all.gif)"; outdivPC.style.horizontalAlign = "center"; outdivPC.style.verticalAlign = "bottom"; outdivPC.appendChild(document.createElement("BR")); outdivPC.appendChild(divPC); // td2.appendChild(document.createElement("BR")); divInst.style.borderWidth = divData.style.borderWidth = divPC.style.borderWidth = "1px"; divInst.style.borderStyle = divData.style.borderStyle = divPC.style.borderStyle = "Solid"; divInst.style.borderColor = divData.style.borderColor = divPC.style.borderColor = "#000000"; var td3 = tr2.insertCell(2); //***END OF INNER TABLE table.style.borderWidth = "0"; //table.style.borderColor = "#000000"; //table.style.borderStyle = "Solid"; table.cellSpacing = "0"; td3.style.width="40px"; td23.style.width="40px"; var regInst = null, regData = null, regPC = null; this.isCPU = true; this.computer = null; /** * Sets the computer parent object for this CPU */ this.setComputer = function(compChip) { this.computer = compChip; } var that = this; init(); /** * Private function to initialize the CPU */ function init() { that.enabled = true; regInst = new DataCell(true); regData = new DataCell(true); regPC = new DataCell(true); regInst.parent = regData.parent = regPC.parent = that; regInst.itemDiv.style.borderBottomStyle = regData.itemDiv.style.borderBottomStyle = regPC.itemDiv.style.borderBottomStyle = regInst.itemDiv.style.borderRightStyle = regData.itemDiv.style.borderRightStyle = regPC.itemDiv.style.borderRightStyle = "none"; regPC.ondatachange = function() { if (that.computer) that.computer.highlightPCAddress(); } regInst.ondatachange = function() { if (that.computer) {that.computer.setExecute(); that.computer.decode(false); } } regInst.onenterpressed = function() { if (that.computer) { var oldAnimation = that.computer.getAnimation(); if (oldAnimation == ANIMATE_NONE) that.computer.setAnimation(ANIMATE_FLOW); that.computer.decode(true, true); that.computer.setAnimation(oldAnimation); } regInst.itemDiv.onmousedown(); regInst.textBox.select(); } regInst.enabled = regData.enabled = regPC.enabled = true; regInst.setValue(0); regData.setValue(0); regPC.setValue(0); divInst.appendChild(regInst.itemDiv); regInst.parent = that; divData.appendChild(regData.itemDiv); regData.parent = that; divPC.appendChild(regPC.itemDiv); regPC.parent = that; instLabel.innerHTML = ""; } container.appendChild(table); this.setInstructionLabel = function(text) { instLabel.innerHTML = text; } //Implementation of interface IDataSet - necessary because control has DataCell children this.dataSetType = "CPUChip"; /** * Returns the DataCell at the specified index */ this.getCellAt = function(index) { switch(index) { case 0: return regInst; case 1: return regData; case 2: return regPC; default: return null; } } /** * Returns the current DataCell at cursor's position */ this.getCurrent = function() { return null; } /** * Increments the cursor to the next cell */ this.goNext = function() { return false; } /** * Decrements the cursor to the previous cell */ this.goBack = function() { return false; } /** * Clears a given cell in the list */ this.clearCell = function(dataCell) { dataCell.setValue(000); } this.clear = function() { regInst.setValue(0); regData.setValue(0); regPC.setValue(0); } /** * Returns an array representation of this DataList */ this.toArray = function() { return null; } /** * Returns Program Counter value */ this.getPCValue = function() { return that.getCellAt(2).getValue(); } /** * Advances the Program Counter by 1 */ this.advancePC = function() { that.getCellAt(2).setValue(that.getCellAt(2).getValue() + 1); } /** * Enables/disables CPU Chip and controls in it */ this.enable = function(value) { regInst.enabled = regData.enabled = regPC.enabled = value; } this.showValues = function() { for (var i = 0; i < 2; i++) that.getCellAt(i).showValue(); } }