nga-js: add framebuffer support

FossilOrigin-Name: 24ffe51c912c4c0d210486268b71cb541dd577e69f32f5942786dbcbf8d23bda
This commit is contained in:
crc 2019-11-20 17:32:25 +00:00
parent 78451a28d9
commit 63ef78d1d2
2 changed files with 33 additions and 7 deletions

View file

@ -18,6 +18,7 @@
<button onclick='go()'>Go</button>
</div>
<div>
<canvas id="canvas" width="300" height="300"></canvas>
<xmp id='console'>
</xmp>
</div>

View file

@ -263,18 +263,28 @@ instructions[vm.END] = function() {
ip = IMAGE_SIZE;
}
instructions[vm.IE] = function() {
data.push(1);
data.push(2);
}
instructions[vm.IQ] = function() {
data.drop();
var chosen = data.pop();
if (chosen == 0) {
data.push(0);
data.push(0);
} else if (chosen == 1) {
data.push(20);
data.push(0);
}
}
instructions[vm.II] = function() {
data.pop();
var chosen = data.pop();
if (chosen == 0) {
var s = String.fromCharCode(data.pop());
document.getElementById('console').innerHTML += s;
} else if (chosen == 1) {
draw(data.pop())
}
}
window.addEventListener('load', function(e) {
rxPrepareVM();
}, false);
@ -495,3 +505,18 @@ function loadproject() {
src = localStorage.getItem("Snapshot");
document.getElementById("input").value = src;
}
function draw(fb_start) {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
console.log(ctx);
var imgData = ctx.createImageData(300, 300);
var i;
for (i = 0; i < imgData.data.length / 4; i += 1) {
imgData.data[i * 4 + 0] = ((image[i + fb_start] >> 8) >> 8) & 255;
imgData.data[i * 4 + 1] = (image[i + fb_start] >> 8) & 255;
imgData.data[i * 4 + 2] = image[i + fb_start] & 255;
imgData.data[i * 4 + 3] = 255;
}
ctx.putImageData(imgData, 0, 0);
}