about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-10 17:42:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-10 17:42:35 -0700
commit90748fa45df64d1e12e0dcb46c3074e232914d71 (patch)
tree5264dbeeb9425031e1536affa850f1683bb21a95 /shell
parentf6aeecdc483e07c2fdb81040d1e20b3288c3c9c3 (diff)
downloadmu-90748fa45df64d1e12e0dcb46c3074e232914d71.tar.gz
shell: render fake screens
'print' turns out to not be working yet.
Diffstat (limited to 'shell')
-rw-r--r--shell/global.mu70
-rw-r--r--shell/sandbox.mu79
2 files changed, 120 insertions, 29 deletions
diff --git a/shell/global.mu b/shell/global.mu
index 72b4a178..0e7038e9 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -145,45 +145,65 @@ fn append-global _self: (addr global-table), name: (addr array byte), value: (ha
 
 fn lookup-symbol-in-globals _sym: (addr cell), out: (addr handle cell), _globals: (addr global-table), trace: (addr trace) {
   var sym/eax: (addr cell) <- copy _sym
-  var sym-data-ah/eax: (addr handle stream byte) <- get sym, text-data
-  var _sym-data/eax: (addr stream byte) <- lookup *sym-data-ah
-  var sym-data/edx: (addr stream byte) <- copy _sym-data
+  var sym-name-ah/eax: (addr handle stream byte) <- get sym, text-data
+  var _sym-name/eax: (addr stream byte) <- lookup *sym-name-ah
+  var sym-name/edx: (addr stream byte) <- copy _sym-name
   var globals/esi: (addr global-table) <- copy _globals
   {
     compare globals, 0
     break-if-=
+    var curr-index/ecx: int <- find-symbol-in-globals globals, sym-name
+    compare curr-index, -1/not-found
+    break-if-=
     var global-data-ah/eax: (addr handle array global) <- get globals, data
     var global-data/eax: (addr array global) <- lookup *global-data-ah
-    var final-index/ecx: (addr int) <- get globals, final-index
-    var curr-index/ecx: int <- copy *final-index
-    {
-      compare curr-index, 0
-      break-if-<
-      var curr-offset/ebx: (offset global) <- compute-offset global-data, curr-index
-      var curr/ebx: (addr global) <- index global-data, curr-offset
-      var curr-name-ah/eax: (addr handle array byte) <- get curr, name
-      var curr-name/eax: (addr array byte) <- lookup *curr-name-ah
-      var found?/eax: boolean <- stream-data-equal? sym-data, curr-name
-      {
-        compare found?, 0/false
-        break-if-=
-        var curr-value/eax: (addr handle cell) <- get curr, value
-        copy-object curr-value, out
-        return
-      }
-      curr-index <- decrement
-      loop
-    }
+    var curr-offset/ebx: (offset global) <- compute-offset global-data, curr-index
+    var curr/ebx: (addr global) <- index global-data, curr-offset
+    var curr-value/eax: (addr handle cell) <- get curr, value
+    copy-object curr-value, out
+    return
   }
   # otherwise error "unbound symbol: ", sym
   var stream-storage: (stream byte 0x40)
   var stream/ecx: (addr stream byte) <- address stream-storage
   write stream, "unbound symbol: "
-  rewind-stream sym-data
-  write-stream stream, sym-data
+  rewind-stream sym-name
+  write-stream stream, sym-name
   trace trace, "error", stream
 }
 
+# return the index in globals containing 'sym'
+# or -1 if not found
+fn find-symbol-in-globals _globals: (addr global-table), sym-name: (addr stream byte) -> _/ecx: int {
+  var globals/esi: (addr global-table) <- copy _globals
+  compare globals, 0
+  {
+    break-if-!=
+    return -1/not-found
+  }
+  var global-data-ah/eax: (addr handle array global) <- get globals, data
+  var global-data/eax: (addr array global) <- lookup *global-data-ah
+  var final-index/ecx: (addr int) <- get globals, final-index
+  var curr-index/ecx: int <- copy *final-index
+  {
+    compare curr-index, 0
+    break-if-<
+    var curr-offset/ebx: (offset global) <- compute-offset global-data, curr-index
+    var curr/ebx: (addr global) <- index global-data, curr-offset
+    var curr-name-ah/eax: (addr handle array byte) <- get curr, name
+    var curr-name/eax: (addr array byte) <- lookup *curr-name-ah
+    var found?/eax: boolean <- stream-data-equal? sym-name, curr-name
+    compare found?, 0/false
+    {
+      break-if-=
+      return curr-index
+    }
+    curr-index <- decrement
+    loop
+  }
+  return -1/not-found
+}
+
 # a little strange; goes from value to name and selects primitive based on name
 fn apply-primitive _f: (addr cell), args-ah: (addr handle cell), out: (addr handle cell), env-h: (handle cell), _globals: (addr global-table), trace: (addr trace) {
   var f/esi: (addr cell) <- copy _f
diff --git a/shell/sandbox.mu b/shell/sandbox.mu
index cc343259..4b5d5b14 100644
--- a/shell/sandbox.mu
+++ b/shell/sandbox.mu
@@ -76,7 +76,7 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin:
     var x2/edx: int <- copy x
     var dummy/eax: int <- draw-stream-rightward screen, value, x2, xmax, y, 7/fg=grey, 0/bg
   }
-  y <- maybe-render-screen screen, globals, xmin, y, xmax, ymax
+  y <- maybe-render-screen screen, globals, xmin, y
   # render menu
   var cursor-in-trace?/eax: (addr boolean) <- get self, cursor-in-trace?
   compare *cursor-in-trace?, 0/false
@@ -88,14 +88,85 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), xmin: int, ymin:
   render-sandbox-menu screen
 }
 
-fn maybe-render-screen screen: (addr screen), globals: (addr global-table), xmin: int, ymin: int, xmax: int, ymax: int -> _/ecx: int {
-  var x/eax: int <- copy xmin
+fn maybe-render-screen screen: (addr screen), _globals: (addr global-table), xmin: int, ymin: int -> _/ecx: int {
+  var globals/esi: (addr global-table) <- copy _globals
+  var screen-literal-storage: (stream byte 8)
+  var screen-literal/eax: (addr stream byte) <- address screen-literal-storage
+  write screen-literal, "screen"
+  var screen-obj-index/ecx: int <- find-symbol-in-globals globals, screen-literal
+  compare screen-obj-index, -1/not-found
+  {
+    break-if-!=
+    return ymin
+  }
+  var global-data-ah/eax: (addr handle array global) <- get globals, data
+  var global-data/eax: (addr array global) <- lookup *global-data-ah
+  var screen-obj-offset/ecx: (offset global) <- compute-offset global-data, screen-obj-index
+  var screen-global/eax: (addr global) <- index global-data, screen-obj-offset
+  var screen-obj-cell-ah/eax: (addr handle cell) <- get screen-global, value
+  var screen-obj-cell/eax: (addr cell) <- lookup *screen-obj-cell-ah
+  var screen-obj-cell-type/ecx: (addr int) <- get screen-obj-cell, type
+  compare *screen-obj-cell-type, 5/screen
+  {
+    break-if-=
+    return ymin  # silently give up on rendering the screen
+  }
+  var screen-obj-ah/eax: (addr handle screen) <- get screen-obj-cell, screen-data
+  var screen-obj/eax: (addr screen) <- lookup *screen-obj-ah
+  {
+    var screen-empty?/eax: boolean <- fake-screen-empty? screen-obj
+    compare screen-empty?, 0/false
+    break-if-=
+    return ymin
+  }
   var y/ecx: int <- copy ymin
   y <- add 2
-  x, y <- draw-text-wrapping-right-then-down screen, "abc", x, y, xmax, ymax, x, y, 7/fg, 0/bg
+  y <- render-screen screen, screen-obj, xmin, y
   return y
 }
 
+fn render-screen screen: (addr screen), _target-screen: (addr screen), xmin: int, ymin: int -> _/ecx: int {
+  var target-screen/esi: (addr screen) <- copy _target-screen
+  var height/edx: (addr int) <- get target-screen, height
+  var y/ecx: int <- copy 0
+  var screen-y/edi: int <- copy ymin
+  {
+    compare y, *height
+    break-if->=
+    set-cursor-position screen, xmin, screen-y
+    draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x18/fg, 0/bg
+    move-cursor-right screen
+    var width/edx: (addr int) <- get target-screen, width
+    var x/ebx: int <- copy 0
+    {
+      compare x, *width
+      break-if->=
+      print-screen-cell-of-fake-screen screen, target-screen, x, y
+      move-cursor-right screen
+      x <- increment
+      loop
+    }
+    draw-code-point-at-cursor screen, 0x7c/vertical-bar, 0x18/fg, 0/bg
+    y <- increment
+    screen-y <- increment
+    loop
+  }
+  return y
+}
+
+fn print-screen-cell-of-fake-screen screen: (addr screen), _target: (addr screen), x: int, y: int {
+  var target/ecx: (addr screen) <- copy _target
+  var data-ah/eax: (addr handle array screen-cell) <- get target, data
+  var data/eax: (addr array screen-cell) <- lookup *data-ah
+  var index/ecx: int <- screen-cell-index target, x, y
+  var offset/ecx: (offset screen-cell) <- compute-offset data, index
+  var src-cell/esi: (addr screen-cell) <- index data, offset
+  var src-grapheme/eax: (addr grapheme) <- get src-cell, data
+  var src-color/ecx: (addr int) <- get src-cell, color
+  var src-background-color/edx: (addr int) <- get src-cell, background-color
+  draw-grapheme-at-cursor screen, *src-grapheme, *src-color, *src-background-color
+}
+
 fn render-sandbox-menu screen: (addr screen) {
   var width/eax: int <- copy 0
   var height/ecx: int <- copy 0