X-Git-Url: https://git.kengrimes.com/?p=watForth.git;a=blobdiff_plain;f=forth.js;h=7e2f5a3b849f694c21ac6794c30829e49af4a56d;hp=ffe8044d68d08d38ba2953f1bda66dcfaed99d39;hb=a83e7e42d457eb562902eea8090c3f2b51351686;hpb=5d787df4e2ff2a70cde1b599a3ff99faf9136179 diff --git a/forth.js b/forth.js index ffe8044..7e2f5a3 100644 --- a/forth.js +++ b/forth.js @@ -1,3 +1,15 @@ +/* This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ 'use strict' let txtdiv = document.createElement("div") document.body.appendChild(txtdiv) @@ -50,7 +62,7 @@ const channels = [{ write: (readAddr, maxBytes) => output.print(String.fromCharCode.apply( null, - new Uint16Array(wasmMem.buffer, readAddr, maxBytes) + new Uint16Array(wasmMem.buffer, readAddr, maxBytes >> 1) )) }] const simstack = [] @@ -93,6 +105,7 @@ const dictionary = { 'CHANNEL!': 35, 'HERE!': 36, '=?': 37, + '.s': 38, ':': 16800, 'MODE': 14336, 'EXECUTE-MODE': 16680, @@ -106,16 +119,11 @@ const wasmImport = { rinit: () => rstack.length = 0, rpop: () => rstack.pop(), rpush: (val) => rstack.push(val), - sys_write: (channel, fromBuffer) => { + sys_write: (channel, addr, u) => { if (channels[channel] === undefined) return - const maxBytes = new DataView( - wasmMem.buffer, - fromBuffer, - 4 - ).getUint32(0,true) - console.log(`write ch:${channel} addr:${fromBuffer} len:${maxBytes}`) - channels[channel].write(fromBuffer + 4, maxBytes) + console.log(`write ch:${channel} addr:${addr} len:${u}`) + channels[channel].write(addr, u) }, sys_read: (channel, toBuffer) => { console.log(`read ch:${channel} buf:${toBuffer} current: ${stdin}`)