/** * The Control Unit class */ /** * Constructor */ function ControlUnit(computer, container) { //Build HTML DOM if (!IMAGES_DIR) IMAGES_DIR = "../Controls/"; var width = computer.parentElement.offsetWidth; var table = document.createElement("TABLE"); table.width = width; table.cellSpacing = "0"; table.cellPadding = "0"; //Control buttons var r_controls = table.insertRow(0); var d_controls = r_controls.insertCell(0); //d_controls.style.width = (width - 150) + "px"; //d_controls.align = "center"; //Buttons //******** d_controls.appendChild(getSeparator()); this.enabled = true; var that = this; //Load var btnLoad = new Image(); btnLoad.style.width = "40px"; btnLoad.style.height = "22px"; btnLoad.src = IMAGES_DIR + "load.gif"; btnLoad.onmousedown = function() { if (!that.enabled) return; btnLoad.src = IMAGES_DIR + "p_load.gif"; } btnLoad.onmouseout = function() { btnLoad.src = IMAGES_DIR + "load.gif"; } btnLoad.onmouseup = function() { if (!that.enabled) return; btnLoad.onmouseout(); upload("computer.loadProgram", "iFrame"); that.stopped = false; } btnLoad.style.borderStyle = "none"; btnLoad.alt = btnLoad.title = "טען"; d_controls.appendChild(btnLoad); d_controls.appendChild(getSeparator()); //Single Step var btnSingle = new Image(); btnSingle.style.width = "40px"; btnSingle.style.height = "22px"; btnSingle.src = IMAGES_DIR + "single.gif"; btnSingle.enabled = true; btnSingle.onmousedown = function() { if (!that.enabled || !btnSingle.enabled) return; btnSingle.src = IMAGES_DIR + "p_single.gif"; } btnSingle.onmouseout = function() { if (!btnSingle.enabled) return; btnSingle.src = IMAGES_DIR + "single.gif"; } btnSingle.onmouseup = function() { if (!that.enabled || !btnSingle.enabled) return; btnSingle.onmouseout(); var oldAnimation = computer.getAnimation(); if (oldAnimation == ANIMATE_NONE) computer.setAnimation(ANIMATE_FLOW); computer.fetch(true, oldAnimation); //computer.setAnimation(oldAnimation); } btnSingle.style.borderStyle = "none"; btnSingle.alt = btnSingle.title = "בצע פקודה"; d_controls.appendChild(btnSingle); d_controls.appendChild(getSeparator()); //Run var btnRun = new Image(); btnRun.style.width = "40px"; btnRun.style.height = "22px"; btnRun.src = IMAGES_DIR + "run.gif"; btnRun.enabled = true; btnRun.onmousedown = function() { if (!that.enabled || !btnRun.enabled) return; btnRun.src = IMAGES_DIR + "p_run.gif"; } btnRun.onmouseout = function() { if (!btnRun.enabled) return; btnRun.src = IMAGES_DIR + "run.gif"; } btnRun.onmouseup = function() { if (!that.enabled || !btnRun.enabled) return; btnRun.onmouseout(); computer.run(); } btnRun.style.borderStyle = "none"; btnRun.alt = btnRun.title = "הרץ תוכנית"; d_controls.appendChild(btnRun); d_controls.appendChild(getSeparator()); //Stop var btnStop = new Image(); btnStop.style.width = "40px"; btnStop.style.height = "22px"; btnStop.src = IMAGES_DIR + "stop.gif"; btnStop.onmousedown = function() { //if (!that.enabled) return; btnStop.src = IMAGES_DIR + "p_stop.gif"; } btnStop.onmouseout = function() { btnStop.src = IMAGES_DIR + "stop.gif"; } btnStop.onmouseup = function() { //if (!that.enabled) return; btnStop.onmouseout(); if (that.stopped) return; computer.stop(false, true); } btnStop.style.borderStyle = "none"; btnStop.alt = btnStop.title = "עצור"; d_controls.appendChild(btnStop); d_controls.appendChild(getSeparator()); //Reset var btnReset = new Image(); btnReset.style.width = "40px"; btnReset.style.height = "22px"; btnReset.src = IMAGES_DIR + "reset.gif"; btnReset.onmousedown = function() { if (!that.enabled) return; btnReset.src = IMAGES_DIR + "p_reset.gif"; } btnReset.onmouseout = function() { btnReset.src = IMAGES_DIR + "reset.gif"; } btnReset.onmouseup = function() { if (!that.enabled) return; btnReset.onmouseout(); computer.stop(); btnExecute.enabled = false; btnRun.enabled = true; btnSingle.enabled = true; btnFetch.enabled = true; btnExecute.src = IMAGES_DIR + "execute_dis.gif"; btnSingle.src = IMAGES_DIR + "single.gif"; btnRun.src = IMAGES_DIR + "run.gif"; btnFetch.src = IMAGES_DIR + "fetch.gif"; computer.reset(); that.stopped = false; } btnReset.style.borderStyle = "none"; btnReset.alt = btnReset.title = "אתחל"; d_controls.appendChild(btnReset); d_controls.appendChild(getSeparator()); //Fetch var btnFetch = new Image(); btnFetch.style.width = "20px"; btnFetch.style.height = "22px"; btnFetch.src = IMAGES_DIR + "fetch.gif"; btnFetch.enabled = true; btnFetch.onmousedown = function() { if (that.enabled && btnFetch.enabled) { btnFetch.src = IMAGES_DIR + "p_fetch.gif"; } } btnFetch.onmouseout = function() { if (btnFetch.enabled) { btnFetch.src = IMAGES_DIR + "fetch.gif"; } } btnFetch.onmouseup = function() { if (that.enabled && btnFetch.enabled) { that.setExecute(); var oldAnimation = computer.getAnimation(); if (oldAnimation == ANIMATE_NONE) computer.setAnimation(ANIMATE_FLOW); computer.fetch(false, false, true); computer.setAnimation(oldAnimation); } } btnFetch.alt = btnFetch.title = "Fetch"; btnFetch.style.borderStyle = "none"; d_controls.appendChild(btnFetch); //Execute var btnExecute = new Image(); btnExecute.style.width = "20px"; btnExecute.style.height = "22px"; btnExecute.src = IMAGES_DIR + "execute_dis.gif"; btnExecute.enabled = false; btnExecute.onmousedown = function() { if (that.enabled && btnExecute.enabled) { btnExecute.src = IMAGES_DIR + "p_execute.gif"; } } btnExecute.onmouseout = function() { if (btnExecute.enabled) { btnExecute.src = IMAGES_DIR + "execute.gif"; } } btnExecute.onmouseup = function() { if (that.enabled && btnExecute.enabled) { that.setFetch(true); var oldAnimation = computer.getAnimation(); if (oldAnimation == ANIMATE_NONE) computer.setAnimation(ANIMATE_FLOW); computer.decode(true); computer.setAnimation(oldAnimation); } } btnExecute.alt = btnExecute.title = "Execute"; btnExecute.style.borderStyle = "none"; d_controls.appendChild(btnExecute); d_controls.appendChild(getSeparator()); //Clear var btnClear = new Image(); btnClear.style.width = "46px"; btnClear.style.height = "22px"; btnClear.src = IMAGES_DIR + "clear.gif"; btnClear.onmousedown = function() { if (that.enabled) { btnClear.src = IMAGES_DIR + "p_clear.gif"; } } btnClear.onmouseout = function() { btnClear.src = IMAGES_DIR + "clear.gif"; document.getElementById("clearPopup").onmouseout(); } btnClear.onmouseup = function() { btnClear.src = IMAGES_DIR + "clear.gif"; if (that.enabled) { var menu = document.getElementById("clearPopup"); menu.style.position = "absolute"; menu.style.display = "block"; menu.style.left = getAbsLeft(btnClear); menu.style.top = getAbsTop(btnClear) + 22; } } //btnClear.alt = btnClear.title = "נקה"; btnClear.style.borderStyle = "none"; d_controls.appendChild(btnClear); this.setFetch = function(stop) { btnExecute.enabled = false; btnExecute.src = IMAGES_DIR + "execute_dis.gif"; if (stop) { btnFetch.enabled = true; btnSingle.enabled = true; btnSingle.src = IMAGES_DIR + "single.gif"; btnFetch.src = IMAGES_DIR + "fetch.gif"; } } this.setExecute = function() { btnFetch.enabled = false; btnSingle.enabled = false; btnExecute.enabled = true; btnFetch.src = IMAGES_DIR + "fetch_dis.gif"; btnSingle.src = IMAGES_DIR + "single_dis.gif"; btnExecute.src = IMAGES_DIR + "execute.gif"; } // d_controls.appendChild(document.createElement("BR")); d_controls.appendChild(getSeparator()); var d_ani = r_controls.insertCell(1); if ("rtl" == "rtl") d_ani.appendChild(getSeparator()); var p_ani = document.createElement("SPAN"); p_ani.style.fontSize = "10px"; d_ani.style.verticalAlign = "top"; p_ani.innerHTML = "אנימציה:"; d_ani.dir = "rtl"; d_ani.style.textAlign = "right"; d_ani.appendChild(p_ani); d_ani.appendChild(document.createElement("BR")); if ("rtl" == "rtl") d_ani.appendChild(getSeparator()); var aniselect = document.createElement("SELECT"); aniselect.style.fontSize = "10px"; aniselect.style.fontFamily = "Arial"; aniselect.onclick = function() { computer.setAnimation(aniselect.value); } var opt3 = document.createElement("OPTION"); opt3.value = 2; opt3.innerHTML = "זרימת תוכנית ונתונים"; opt3.selected = true; aniselect.appendChild(opt3); var opt2 = document.createElement("OPTION"); opt2.value = 1; opt2.innerHTML = "זרימת תוכנית"; aniselect.appendChild(opt2); var opt1 = document.createElement("OPTION"); opt1.value = 0; opt1.innerHTML = "בטל אנימציה"; aniselect.appendChild(opt1); //anitd2.appendChild(aniselect); //anitd2.appendChild(getSeparator()); d_ani.appendChild(aniselect); if ("rtl" == "ltr") d_ani.appendChild(getSeparator()); //Slider var slidertd = r_controls.insertCell(2); slidertd.dir = "rtl"; slidertd.style.textAlign = "right"; var p_sl = document.createElement("SPAN"); p_sl.style.fontSize = "10px"; p_sl.innerHTML = "מהירות:"; slidertd.style.verticalAlign = "top"; slidertd.appendChild(p_sl); slidertd.appendChild(document.createElement("BR")); var divSlider = document.createElement("DIV"); divSlider.style.textAlign = "left"; divSlider.dir = "ltr"; slidertd.appendChild(divSlider); this.slider = new Slider(1, 5, 3, 1, 0, 0, 100, divSlider, "rtl"); //Help, about var d_help = r_controls.insertCell(3); d_help.style.fontSize = "8px"; //Help var btnHelp = new Image(); btnHelp.style.width = "40px"; btnHelp.style.height = "22px"; btnHelp.src = IMAGES_DIR + "help_s.gif"; btnHelp.onmousedown = function() { if (!that.enabled) return; btnHelp.src = IMAGES_DIR + "p_help_s.gif"; } btnHelp.onmouseout = function() { btnHelp.src = IMAGES_DIR + "help_s.gif"; } btnHelp.onmouseup = function() { if (!that.enabled) return; btnHelp.onmouseout(); document.getElementById("frmHelp").style.display = "block"; } btnHelp.style.borderStyle = "none"; btnHelp.alt = btnHelp.title = "עזרה"; d_help.appendChild(getSeparator()); d_help.appendChild(btnHelp); //d_help.appendChild(document.createElement("BR")); //d_help.appendChild(document.createElement("BR")); d_help.appendChild(getSeparator()); //About var btnAbout = new Image(); btnAbout.style.width = "40px"; btnAbout.style.height = "22px"; btnAbout.src = IMAGES_DIR + "about_s.gif"; btnAbout.onmousedown = function() { if (!that.enabled) return; btnAbout.src = IMAGES_DIR + "p_about_s.gif"; } btnAbout.onmouseout = function() { btnAbout.src = IMAGES_DIR + "about_s.gif"; } btnAbout.onmouseup = function() { if (!that.enabled) return; btnAbout.onmouseout(); window.open("../common/about.asp?lang=he", null, "directories=no,height=200,width=500,menubar=no,resizable=no,status=no,toolbar=no"); } btnAbout.style.borderStyle = "none"; btnAbout.alt = btnAbout.title = "אודות"; //d_help.appendChild(document.createElement("BR")); d_help.appendChild(btnAbout); computer.setControls(this); container.appendChild(table); this.stopAll = function() { btnFetch.enabled = false; btnFetch.src = IMAGES_DIR + "fetch_dis.gif"; btnRun.enabled = false; btnRun.src = IMAGES_DIR + "run_dis.gif"; btnSingle.enabled = false; btnSingle.src = IMAGES_DIR + "single_dis.gif"; that.stopped = true; } } /** * A helper function that produces a blank separator */ function getSeparator() { var s = new Image(10,10); s.src = IMAGES_DIR + "separator.gif"; return s; }