/** * IO Chip Class */ /** * IO Chip Constructor */ function IOChip(container) { //Constants var INIT_INPUT_SIZE = 10, INIT_OUTPUT_SIZE = 1; //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); td2.dir = "ltr"; //INPUT var b2 = td2.appendChild(document.createElement("B")); b2.innerHTML = "Input"; b2.style.color = LABEL_COLOR; td2.appendChild(document.createElement("BR")); var divIn = document.createElement("DIV"); divIn.id = "___input_div_container"; td2.appendChild(divIn); td2.appendChild(document.createElement("BR")); //OUTPUT var b3 = td2.appendChild(document.createElement("B")); b3.innerHTML = "Output"; b3.style.color = LABEL_COLOR; td2.appendChild(document.createElement("BR")); var divOut = document.createElement("DIV"); divOut.id = "___output_div_container"; td2.appendChild(divOut); 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"; this.left = table.offsetLeft; this.top = table.offsetTop; var input = null, output = null; var that = this; init(); /** * Private function to initialize the chip */ function init() { input = new DataList(INIT_INPUT_SIZE, LIST_WIDTH + 10, LIST_HEIGHT); input.isInputList = true; input.ioChip = that; output = new DataList(INIT_OUTPUT_SIZE, LIST_WIDTH + 10, LIST_HEIGHT); input.enabled = true; input.getCurrent().highlight(true); output.getCurrent().highlight(true); output.enabled = false; appendDataList(divIn, input); appendDataList(divOut, output); } container.appendChild(table); /** * Reads the next number from the input stream and returns it */ this.read = function() { var cell = input.getCurrent(); if (input.goNext()) { cell.highlight(false); input.getCurrent().highlight(true); } return cell; } /** * Writes a value to the output stream */ this.write = function(value) { var current = output.getCurrent(); if (!current.setValue(value)) return; output.addDataCell(new DataCell()); current.highlight(false); if (output.goNext()) output.getCurrent().highlight(true); } /** * Resets and clears this I/O Chip */ this.clear = function() { divIn.removeChild(input.frameDiv); divOut.removeChild(output.frameDiv); init(); } /** * Resets the IO Chip to its condition on last reset / loading. */ this.reset = function() { input.dehighlight(); while (input.goBack()) { }; input.getCurrent().highlight(true); output.clearList(); } /** * Returns current input DataCell */ this.getCurrentInput = function() { return input.getCurrent(); } /** * Returns current output DataCell */ this.getCurrentOutput = function() { return output.getCurrent(); } /** * Enables/disables the chip */ this.enable = function(value) { input.enabled = value; } this.showValues = function() { input.showValues(); output.showValues(); } }