about summary refs log tree commit diff stats
path: root/baremetal
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-14 15:09:16 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-14 15:09:16 -0800
commit72f9fdbd16c715e38362502c6c7af88f6da2d69d (patch)
tree802a059124ae18b84d11b8514a3b90646cf3cb0b /baremetal
parent1010b50bb86da505f8002dd142cec0a37b13b8a2 (diff)
downloadmu-72f9fdbd16c715e38362502c6c7af88f6da2d69d.tar.gz
7743
First bugfix in baremetal/shell. Already it's much easier to debug.
Diffstat (limited to 'baremetal')
-rw-r--r--baremetal/500text-screen.mu4
-rw-r--r--baremetal/shell/line.mu25
-rw-r--r--baremetal/shell/value-stack.mu32
3 files changed, 58 insertions, 3 deletions
diff --git a/baremetal/500text-screen.mu b/baremetal/500text-screen.mu
index 8ddc0e26..a764aa06 100644
--- a/baremetal/500text-screen.mu
+++ b/baremetal/500text-screen.mu
@@ -107,9 +107,9 @@ fn screen-cell-index screen-on-stack: (addr screen), x: int, y: int -> _/ecx: in
     break-if-<
     abort "tried to print out of screen bounds"
   }
-  var height-addr/eax: (addr int) <- get screen, height
+  var width-addr/eax: (addr int) <- get screen, width
   var result/ecx: int <- copy y
-  result <- multiply *height-addr
+  result <- multiply *width-addr
   result <- add x
   return result
 }
diff --git a/baremetal/shell/line.mu b/baremetal/shell/line.mu
index ff5cf519..a5df2af5 100644
--- a/baremetal/shell/line.mu
+++ b/baremetal/shell/line.mu
@@ -142,11 +142,14 @@ fn render-word-with-stack-and-cursor screen: (addr screen), line: (addr line), c
   # render stack
   var new-y/ecx: int <- copy 0
   new-x, new-y <- render-value-stack screen, stack, x, y
+#?   draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, new-x, 0xc/fg, 0/bg
+#?   draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, new-y, 3/fg, 0/bg
   compare new-x, new-x-saved
   {
-    break-if-<=
+    break-if->=
     new-x <- copy new-x-saved
   }
+#?   draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, new-x, 7/fg, 0/bg
   return new-x, new-y
 }
 
@@ -168,6 +171,26 @@ fn test-render-line-with-stack-singleton {
   # not bothering to test hash colors for numbers
 }
 
+fn test-render-line-with-stack {
+  # line = [1 2]
+  var line-storage: line
+  var line/esi: (addr line) <- address line-storage
+  parse-line "1 2", line
+  # setup: screen
+  var screen-on-stack: screen
+  var screen/edi: (addr screen) <- address screen-on-stack
+  initialize-screen screen, 0x20, 4
+  #
+  var new-x/eax: int <- copy 0
+  var new-y/ecx: int <- copy 0
+  new-x, new-y <- render-line-with-stack screen, line, 0/x, 0/y, 0/no-cursor
+  check-screen-row screen, 0/y, "1   2 ", "F - test-render-line-with-stack/0"
+                                #___ ___
+  check-screen-row screen, 1/y, " 1   2 ", "F - test-render-line-with-stack/1"
+  check-screen-row screen, 2/y, "     1 ", "F - test-render-line-with-stack/2"
+  # not bothering to test hash colors for numbers
+}
+
 fn edit-line _self: (addr line), key: byte {
   var self/esi: (addr line) <- copy _self
   var cursor-word-ah/edx: (addr handle word) <- get self, cursor
diff --git a/baremetal/shell/value-stack.mu b/baremetal/shell/value-stack.mu
index a422e9ff..8c9c2f47 100644
--- a/baremetal/shell/value-stack.mu
+++ b/baremetal/shell/value-stack.mu
@@ -36,6 +36,22 @@ fn push-number-to-value-stack _self: (addr value-stack), _val: float {
   copy-to *type-addr, 0/number
 }
 
+fn push-int-to-value-stack _self: (addr value-stack), _val: int {
+  var self/esi: (addr value-stack) <- copy _self
+  var top-addr/ecx: (addr int) <- get self, top
+  var data-ah/edx: (addr handle array value) <- get self, data
+  var data/eax: (addr array value) <- lookup *data-ah
+  var top/edx: int <- copy *top-addr
+  var dest-offset/edx: (offset value) <- compute-offset data, top
+  var dest-addr/edx: (addr value) <- index data, dest-offset
+  var dest-addr2/eax: (addr float) <- get dest-addr, number-data
+  var val/xmm0: float <- convert _val
+  copy-to *dest-addr2, val
+  increment *top-addr
+  var type-addr/eax: (addr int) <- get dest-addr, type
+  copy-to *type-addr, 0/number
+}
+
 fn push-string-to-value-stack _self: (addr value-stack), val: (handle array byte) {
   var self/esi: (addr value-stack) <- copy _self
   var top-addr/ecx: (addr int) <- get self, top
@@ -207,3 +223,19 @@ fn render-value-stack screen: (addr screen), _self: (addr value-stack), x: int,
   }
   return new-x, y
 }
+
+fn test-render-value-stack {
+  var stack-storage: value-stack
+  var stack/esi: (addr value-stack) <- address stack-storage
+  push-int-to-value-stack stack, 3
+  # setup: screen
+  var screen-on-stack: screen
+  var screen/edi: (addr screen) <- address screen-on-stack
+  initialize-screen screen, 0x20, 4
+  #
+  var final-x/eax: int <- copy 0
+  var final-y/ecx: int <- copy 0
+  final-x, final-y <- render-value-stack screen, stack, 0/x, 0/y
+  check-ints-equal final-y, 1, "F - test-render-value-stack y"
+  check-ints-equal final-x, 3, "F - test-render-value-stack x"
+}