_='C_textarea")u_a")a=a.width=a.height=256;u.innerHTMLRUN";INPHSO $02E8JP $00"kE^ Y{return ZB+488]}p=.toLowerCase(m=[];nFWclear(En<p;if("$"==lWh";()Kf0-9]/)h+=l;h=parseInt(h,a>h?Gh):Gh&255,h/a|0)}if(lKv]/))WoF34>o;o+=2)l+p[nadsbphppmasalaindejpsocpjejnjljgbr".substr(o,2)(Go/2|0@n,o=a)}d=new Uint8Array(1002eFx=mtFy=setdownkk.keyCode}up0};B--;WiFi<x;)Zim[iQ;E=y(^ r(Wh=a;h--!t;)g=m[eQ,0DY+YV1DY-YV2DqX3DYV4q=Zf]@5Zfq@6DV7#q,8#--q,9~ez@10Zf+Yq@11Dq-X12~Y?e+=1:e=@13~`14~0<`15~0>`t===g;WiFa>i;)A,",v=Z744+i]Stylergb("v>>5)+A(v&28)>>2)+A+64*(v&3)+")"Rect(i%*,*(i/|0@,e<x!t(E=y(r,0))},0)}Y;C.rows=9;~#(z=Ze]<<8|Ze-1]qZ1E3]`Y?e=:e+=1@_=b.appendChild(d.createElement("^functionZd[Yk()X,Z488+B--f@Wfor(V,q=f@Q]Kl.match(/[a-Gm.push(F=0;D~f=BZ1001]@),#==g;u.onclic16);.length;Z487++ZeQ~fz,C.valueTimeout,c.fill="&&]=;onkeyl=p[nQ){\\n=^(+32*(';for(i in g='#@BDFGKQVWXYZ^_`qz~')with(_.split(g[i]))_=join(pop());eval(_)
C = b.appendChild(d.createElement('textarea'))
u = b.appendChild(d.createElement('a'))
a = a.width = a.height = 256;
u.innerHTML = "RUN";
// Sample program
C.value='IN\nPH\nSO $02E8\nJP $00';
u.onclick = function (w) {
function k() {
return d[++d[1001]+488]
}
p = C.value.toLowerCase(), m = [], n = 0;
// Assembler and
// code generation
for (clearTimeout(w); n < p.length;) {
l = p[n++];
// Scan hex values
if ("$" == l) {
for (h = ""; (l = p[n++]) && l.match(/[a-f0-9]/);)h += l;
h = parseInt(h, 16);
a > h ? m.push(h) : m.push(h & 255, h / a | 0)
}
// Scan mnemonics
if (l && l.match(/[a-v]/))
for (o = 0; 34 > o; o += 2)if (l + p[n] == "adsbphppmasalaindejpsocpjejnjljgbr".substr(o, 2))
m.push(o / 2 | 0),n++,o=a
}
// 1000 Bytes + 2 Bytes for Accumulator
// and Stack Pointer Registers.
d = new Uint8Array(1002), e = 0, x = m.length, t = 0, y = setTimeout;
onkeydown = function (e) {
d[487] = e.keyCode
};
onkeyup = function () {
d[487] = 0
};
d[1001]--;
// Burn object code into RAM
for (i = 0; i < x;)d[i] = m[i++];
// CPU Emulation
// Fetch - Decode - Execute
w = y(function E() {
for (h = a; h-- && !t;) {
g = m[e++];
// ADd
0 == g && (f = k() + k(), d[1E3] = f);
// SuBtract
1 == g && (f = k() - k(), d[1E3] = f);
// PusH
2 == g && (f = d[1E3], d[488 + d[1001]--] = f);
// PoP
3 == g && (f = k(), d[1E3] = f);
// Memory to Accumulator
4 == g && (f = d[++e] << 8 | d[e++ - 1], d[1E3] = d[f]);
// Store Accumulator
5 == g && (f = d[++e] << 8 | d[e++ - 1], d[f] = d[1E3]);
// Load Accumulator
6 == g && (f = d[e++], d[1E3] = f);
// INcrement
7 == g && ++d[1E3];
// DEcrement
8 == g && --d[1E3];
// JumP
9 == g && (e = d[++e] << 8 | d[e++ - 1]);
// Store accumulator with stack Offset
10 == g && (f = d[++e] << 8 | d[e++ - 1], d[f + k()] = d[1E3]);
// ComPare
11 == g && (f = d[1E3] - d[e++], d[488 + d[1001]--] = f);
// Jump if Equal
12 == g && (k() ? e += 1 : e = d[e++]);
// Jump if Not equal
13 == g && (k() ? e = d[e++] : e += 1);
// Jump if Lower than
14 == g && (k() > 0 ? e = d[e++] : e += 1);
// Jump if Greater than
15 == g && (k() < 0 ? e = d[e++] : e += 1);
// BReak
t = 16 == g
}
// Flush frame buffer
// into canvas.
for (i = 0; a > i;)A = ",", v = d[744 + i], c.fillStyle = "rgb(" + 32 * (v >> 5) + A + 32 * ((v & 28) >> 2) + A + 64 * (v & 3) + ")", c.fillRect(i % 16 * 16, 16 * (i++ / 16 | 0), 16, 16);
e < x && !t && (w = y(E, 0))
}, 0)
};
u.onclick();
C.rows = 9;