GPLv3+
[watForth.git] / forth.js
index ffe8044..7e2f5a3 100644 (file)
--- 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 <http://www.gnu.org/licenses/>. */
 '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}`)