about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-11-06 13:34:46 -0800
committerKartik Agaram <vc@akkartik.com>2020-11-06 13:39:46 -0800
commit443140ae3e3eae3bf59f34447bedc8329498cca0 (patch)
tree8acee78d1e1136282021624d418db0eeb1fc0e49 /apps/tile
parent9a0412b8587f6b153be2d7d63cd9da2600345e86 (diff)
downloadmu-443140ae3e3eae3bf59f34447bedc8329498cca0.tar.gz
7195 - tile: create 'screen' objects
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/data.mu1
-rw-r--r--apps/tile/environment.mu7
-rw-r--r--apps/tile/rpn.mu33
-rw-r--r--apps/tile/value.mu20
4 files changed, 61 insertions, 0 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu
index e7f9a141..e2c1a47e 100644
--- a/apps/tile/data.mu
+++ b/apps/tile/data.mu
@@ -39,6 +39,7 @@ type value {
   text-data: (handle array byte)  # if type = 1
   array-data: (handle array value)  # if type = 2
   file-data: (handle buffered-file)  # if type = 3
+  screen-data: (handle screen)  # if type = 4
 }
 
 type table {
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 5266b1fb..fa897203 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -798,6 +798,11 @@ fn bound-function? w: (addr word), functions-ah: (addr handle function) -> _/ebx
     subresult <- word-equal? w, "lines"
     compare subresult, 0  # false
     break-if-!=
+    ## screens
+    # if w == "fake-screen" return true
+    subresult <- word-equal? w, "fake-screen"
+    compare subresult, 0  # false
+    break-if-!=
     ## hacks
     # if w == "dup" return true
     subresult <- word-equal? w, "dup"
@@ -1473,6 +1478,8 @@ fn clear-canvas _env: (addr environment) {
   move-cursor screen, 3, start-col
   print-string screen, "open read slurp lines"
   move-cursor screen, 4, start-col
+  print-string screen, "fake-screen"
+  move-cursor screen, 5, start-col
   print-string screen, "dup swap"
   # currently defined functions
   start-col <- subtract 2
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index ff6dc10c..a4d10879 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -258,6 +258,39 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         copy-handle empty-text, target-text-ah
         break $evaluate:process-word
       }
+      ## screens
+      {
+        var is-fake-screen?/eax: boolean <- stream-data-equal? curr-stream, "fake-screen"
+        compare is-fake-screen?, 0
+        break-if-=
+        var out2/esi: (addr value-stack) <- copy out
+        var top-addr/ecx: (addr int) <- get out2, top
+        compare *top-addr, 0
+        break-if-<=
+        # pop width and height from out
+        var _nrows/eax: int <- pop-int-from-value-stack out2
+        var nrows/edx: int <- copy _nrows
+        var _ncols/eax: int <- pop-int-from-value-stack out2
+        var ncols/ebx: int <- copy _ncols
+        # define a new screen with those dimensions
+        var screen-h: (handle screen)
+        var screen-ah/eax: (addr handle screen) <- address screen-h
+        allocate screen-ah
+        var screen/eax: (addr screen) <- lookup screen-h
+        initialize-screen screen, nrows, ncols
+        # push screen to stack
+        var data-ah/eax: (addr handle array value) <- get out2, data
+        var data/eax: (addr array value) <- lookup *data-ah
+        var top/edx: int <- copy *top-addr
+        increment *top-addr
+        var dest-offset/edx: (offset value) <- compute-offset data, top
+        var target-val/edx: (addr value) <- index data, dest-offset
+        var type/eax: (addr int) <- get target-val, type
+        copy-to *type, 4  # screen
+        var dest/eax: (addr handle screen) <- get target-val, screen-data
+        copy-handle screen-h, dest
+        break $evaluate:process-word
+      }
       ## HACKS: we're trying to avoid turning this into Forth
       {
         var is-dup?/eax: boolean <- stream-data-equal? curr-stream, "dup"
diff --git a/apps/tile/value.mu b/apps/tile/value.mu
index db98e503..8dfe4bcc 100644
--- a/apps/tile/value.mu
+++ b/apps/tile/value.mu
@@ -54,6 +54,16 @@ $render-value:body: {
     print-string screen, " FILE "
     break $render-value:body
   }
+  compare *val-type, 4  # file
+  {
+    break-if-!=
+    var val-ah/eax: (addr handle screen) <- get val, screen-data
+    var val-screen/eax: (addr screen) <- lookup *val-ah
+    start-color screen, 0, 7
+    # TODO
+    print-string screen, " SCREEN "
+    break $render-value:body
+  }
   # render ints by default for now
   var val-int/eax: (addr int) <- get val, int-data
   render-integer screen, *val-int, max-width
@@ -176,6 +186,16 @@ fn value-width _v: (addr value), top-level: boolean -> _/eax: int {
     # TODO: visualizing file handles
     return 4
   }
+  {
+    compare *type, 4  # screen
+    break-if-!=
+    var screen-ah/eax: (addr handle screen) <- get v, screen-data
+    var screen/eax: (addr screen) <- lookup *screen-ah
+    compare screen, 0
+    break-if-=
+    # TODO: visualizing screen
+    return 6
+  }
   return 0
 }