-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlc2os.js
35 lines (34 loc) · 1.26 KB
/
lc2os.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// lc2os.js - loads LC2 OS
//
// Author: Simon Pratt
// License: ISC
// Website: http://blog.pr4tt.com/lc2.js/
var LC2 = (function(LC2, undefined) {
LC2.loadOS = function(lc2inst, file_cache) {
file_cache = file_cache || {};
var paths = ['asm/traps.asm', 'asm/getc.asm', 'asm/out.asm',
'asm/puts.asm', 'asm/in.asm', 'asm/halt.asm'];
paths.forEach(function(path) {
let meta = {filename: path};
if(path in file_cache) {
try {
var prg = LC2.assemble(file_cache[path], meta);
if(prg) lc2inst.load_program(prg, meta);
} catch(err) {
console.error('Error while loading loading OS file:', path);
}
} else {
file_cache[path] = lib.readFromURL(path, function(file){
file_cache[path] = file;
try {
var prg = LC2.assemble(file_cache[path], meta);
if(prg) lc2inst.load_program(prg, meta);
} catch(err) {
console.error('Error while loading OS file:', path);
}
});
}
});
};
return LC2;
})(LC2 || {});