Skip to content

Commit

Permalink
First steps in UI:
Browse files Browse the repository at this point in the history
* created textarea for code
* load/save state with local storage
  • Loading branch information
eliben committed Jul 11, 2020
1 parent 9a16009 commit 8bc1fc5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

We use `browserify`; see `Makefile` for the invocation.

The files `index.html`, `ui.js` and `js8080simBundle.js` should be distributed
together to make it all work in the browser.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@
<hr/>
<table id="codetable">
<tr>
<th>Addr</th>
<th>Code</th>
<th>RAM</th>
<th id="spacerheader"></th>
<th>Result</th>
</tr>
<tr>
<th><textarea id="codetext" name="codetext" rows="30" cols="62"></textarea>
</tr>
</table>


Expand Down
25 changes: 25 additions & 0 deletions ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
'use strict';

const STORAGE_ID = 'js8080sim';


loadState();

document.querySelector("#run").addEventListener("mousedown", runCode);

// Expects the global js8080sim to be available.
let asm = new js8080sim.Assembler();

let st = document.querySelector("#status");
st.textContent = "SUCCESS";
st.style.color = "green";

function loadState() {
let state = JSON.parse(localStorage.getItem(STORAGE_ID));
if (state) {
document.querySelector("#codetext").value = state['codetext'];
}
}

function saveState() {
let state = {'codetext': document.querySelector('#codetext').value};
localStorage.setItem(STORAGE_ID, JSON.stringify(state));
}

function runCode() {
saveState();
}

0 comments on commit 8bc1fc5

Please sign in to comment.