Skip to content

Commit

Permalink
add more buttons for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Schulz-Andres committed Jul 22, 2017
1 parent e102526 commit fb88eef
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
9 changes: 6 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
<div class="container">
<div class="menu">
<table><tr>
<td><button type="button" class="btn btn-success" onclick="step();">Step</button></td>
<td><button type="button" class="btn btn-success" onclick="run();">Run</button></td>
<td><button type="button" class="btn btn-success" onclick="reset();">Reset</button></td>
<td><button type="button" class="btn btn-success" id="stepButton" onclick="step();">Step</button></td>
<td><button type="button" class="btn btn-success" id="runButton" onclick="run();">Run</button></td>
<td><button type="button" class="btn btn-success" id="pauseButton" onclick="pause();">Pause</button></td>
<td><button type="button" class="btn btn-success" id="resumeButton" onclick="resume();">Resume</button></td>
<td><button type="button" class="btn btn-success" id="stopButton" onclick="stop();">Stop</button></td>
<td><button type="button" class="btn btn-success" id="resetButton" onclick="reset();">Reset</button></td>
<td><label>Schrittweite:</label></td>
<td><input type="number" min=0 value=500 id="delay" class="form-control" style="width: 150px;" /></td>
<td>ms</td>
Expand Down
55 changes: 53 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ let timer
updateInstructionPointer()
setUpRegisterListeners()
updateRegisterFields()
document.getElementById("stepButton").disabled = false
document.getElementById("runButton").disabled = false
document.getElementById("resumeButton").disabled = true
document.getElementById("stopButton").disabled = true
document.getElementById("pauseButton").disabled = true

setUpListeners(document.getElementsByClassName('address'))
setUpListeners(document.getElementsByClassName('command'))
Expand All @@ -44,16 +49,29 @@ function reload() {

// multi-step
function run() {
document.getElementById("stepButton").disabled = true
document.getElementById("runButton").disabled = true
document.getElementById("resumeButton").disabled = true
document.getElementById("stopButton").disabled = false
document.getElementById("pauseButton").disabled = false
stepTime = document.getElementById("delay").value
status = 1;
timer = setInterval(function(){ step(); }, stepTime);
}

// single-step
function step() {
if (status == states.paused) {
return false
}
if (instructionPointer >= program.length || instructionPointer+1 === numberOfInstructionFields) {
status = 4
status = states.failure
clearInterval(timer)
document.getElementById("stepButton").disabled = false
document.getElementById("runButton").disabled = false
document.getElementById("resumeButton").disabled = true
document.getElementById("stopButton").disabled = true
document.getElementById("pauseButton").disabled = true
return false
}
const [instruction, register] = program[instructionPointer]
Expand Down Expand Up @@ -85,7 +103,12 @@ function step() {
instructionCounter++
break
case instructions.stp:
status = 3
status = states.stopped
document.getElementById("stepButton").disabled = false
document.getElementById("runButton").disabled = false
document.getElementById("resumeButton").disabled = true
document.getElementById("stopButton").disabled = true
document.getElementById("pauseButton").disabled = true
clearInterval(timer)
return false
break
Expand Down Expand Up @@ -231,4 +254,32 @@ function download() {
}
uriContent = "data:application/octet-stream," + encodeURIComponent(content)
newWindow = window.open(uriContent, "_self");
}

function pause() {
status = states.paused
document.getElementById("stepButton").disabled = true
document.getElementById("runButton").disabled = true
document.getElementById("resumeButton").disabled = false
document.getElementById("stopButton").disabled = false
document.getElementById("pauseButton").disabled = true
}

function resume() {
status = states.running
document.getElementById("stepButton").disabled = true
document.getElementById("runButton").disabled = true
document.getElementById("resumeButton").disabled = true
document.getElementById("stopButton").disabled = false
document.getElementById("pauseButton").disabled = false
}

function stop() {
status = states.stopped
clearInterval(timer)
document.getElementById("stepButton").disabled = false
document.getElementById("runButton").disabled = false
document.getElementById("resumeButton").disabled = true
document.getElementById("stopButton").disabled = true
document.getElementById("pauseButton").disabled = true
}

0 comments on commit fb88eef

Please sign in to comment.