Some keyboard input on web.
This commit is contained in:
72
web/fini.fs
72
web/fini.fs
@ -29,35 +29,79 @@ r|
|
|||||||
eval(text);
|
eval(text);
|
||||||
return sp;
|
return sp;
|
||||||
})
|
})
|
||||||
| 2 jseval!
|
| 1 jseval!
|
||||||
: jseval ( a n -- ) 2 call ;
|
: jseval ( a n -- ) 1 call ;
|
||||||
|
|
||||||
r|
|
r"
|
||||||
if (!globalObj['write']) {
|
if (!globalObj['write']) {
|
||||||
var console = document.createElement('pre');
|
var con = document.createElement('pre');
|
||||||
console.id = 'console';
|
con.id = 'console';
|
||||||
document.body.appendChild(console);
|
document.body.appendChild(con);
|
||||||
|
window.inbuffer = [];
|
||||||
|
window.outbuffer = '';
|
||||||
|
window.onkeypress = function(e) {
|
||||||
|
window.inbuffer.push(e.keyCode);
|
||||||
|
};
|
||||||
|
window.onkeydown = function(e) {
|
||||||
|
if (e.keyCode == 8) {
|
||||||
|
window.inbuffer.push(e.keyCode);
|
||||||
}
|
}
|
||||||
| jseval
|
};
|
||||||
|
}
|
||||||
|
" jseval
|
||||||
|
|
||||||
r|
|
r|
|
||||||
(function(sp) {
|
(function(sp) {
|
||||||
var n = i32[sp>>2]; sp -= 4;
|
var n = i32[sp>>2]; sp -= 4;
|
||||||
var a = i32[sp>>2]; sp -= 4;
|
var a = i32[sp>>2]; sp -= 4;
|
||||||
var text = GetString(a, n);
|
|
||||||
if (globalObj['write']) {
|
if (globalObj['write']) {
|
||||||
|
var text = GetString(a, n);
|
||||||
write(text);
|
write(text);
|
||||||
} else {
|
} else {
|
||||||
var console = document.getElementById('console');
|
var con = document.getElementById('console');
|
||||||
console.innerText += text.replace(/[\r]/g, '');
|
for (var i = 0; i < n; ++i) {
|
||||||
|
var ch = u8[a + i];
|
||||||
|
if (ch == 12) {
|
||||||
|
window.outbuffer = '';
|
||||||
|
} else if (ch == 8) {
|
||||||
|
window.outbuffer = window.outbuffer.slice(0, -1);
|
||||||
|
} else if (ch == 13) {
|
||||||
|
} else {
|
||||||
|
window.outbuffer += String.fromCharCode(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
con.innerText = window.outbuffer + String.fromCharCode(0x2592);
|
||||||
|
window.scrollTo(0, document.body.scrollHeight);
|
||||||
}
|
}
|
||||||
return sp;
|
return sp;
|
||||||
})
|
})
|
||||||
| 1 jseval!
|
| 2 jseval!
|
||||||
|
: web-type ( a n -- ) 2 call ;
|
||||||
|
' web-type is type
|
||||||
|
|
||||||
: web-type 1 call ; ' web-type is type
|
r|
|
||||||
: web-key yield 0 ; ' web-key is key
|
(function(sp) {
|
||||||
: web-key? yield 0 ; ' web-key? is key?
|
if (window.inbuffer.length) {
|
||||||
|
sp += 4; i32[sp>>2] = window.inbuffer.shift();
|
||||||
|
} else {
|
||||||
|
sp += 4; i32[sp>>2] = 0;
|
||||||
|
}
|
||||||
|
return sp;
|
||||||
|
})
|
||||||
|
| 3 jseval!
|
||||||
|
: web-key ( -- n ) begin yield 3 call dup if exit then drop again ;
|
||||||
|
' web-key is key
|
||||||
|
|
||||||
|
r|
|
||||||
|
(function(sp) {
|
||||||
|
sp += 4; i32[sp>>2] = window.inbuffer.length ? -1 : 0;
|
||||||
|
return sp;
|
||||||
|
})
|
||||||
|
| 4 jseval!
|
||||||
|
: web-key? ( -- f ) yield 4 call ;
|
||||||
|
' web-key? is key?
|
||||||
|
|
||||||
|
: page 12 emit ;
|
||||||
|
|
||||||
transfer forth
|
transfer forth
|
||||||
forth
|
forth
|
||||||
|
|||||||
@ -358,7 +358,7 @@ function Evaluate1(rp) {
|
|||||||
fp += 4; f32[fp>>2] = f32[n>>2];
|
fp += 4; f32[fp>>2] = f32[n>>2];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('CANT FIND: ' + GetString(name, len));
|
if (DEBUGGING) { console.log('CANT FIND: ' + GetString(name, len)); }
|
||||||
sp += 4; i32[sp>>2] = name;
|
sp += 4; i32[sp>>2] = name;
|
||||||
sp += 4; i32[sp>>2] = len;
|
sp += 4; i32[sp>>2] = len;
|
||||||
sp += 4; i32[sp>>2] = -1;
|
sp += 4; i32[sp>>2] = -1;
|
||||||
@ -575,9 +575,10 @@ var globalObj = getGlobalObj();
|
|||||||
|
|
||||||
var module = VM(globalObj, ffi, heap);
|
var module = VM(globalObj, ffi, heap);
|
||||||
Init();
|
Init();
|
||||||
setTimeout(function() {
|
function run() {
|
||||||
module.run();
|
module.run();
|
||||||
console.log('yield');
|
setTimeout(run, 1);
|
||||||
}, 10);
|
}
|
||||||
|
setTimeout(run, 1);
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user