about summary refs log tree commit diff stats
path: root/501draw-text.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-05 21:10:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-05 21:15:06 -0700
commit928fd47d680a5cbdfa798c4a66ee61f693407faf (patch)
tree769ffeaa141867939ed4e80ef41222c0e4430c66 /501draw-text.mu
parent463878a4a4690392455080282287316879a5a649 (diff)
downloadmu-928fd47d680a5cbdfa798c4a66ee61f693407faf.tar.gz
snapshot: stupid debugging session
I spent a while building a little keyboard scancode printer:

  $ ./translate ex1.mu &&  qemu-system-i386 disk.img

..and wondering why up-arrow was 0x48 in hex but 724 in decimal. I ended
up paranoidly poking at a bunch of crap (though there _is_ a cool chromatography-based
debugging technique in 126write-int-decimal.subx) before I realized:

  - 724 just has one extra digit over the correct answer
  - the 0xe0 scan code is a 3-digit number in decimal -- and the final digit is '4'

There's nothing actually wrong.
Diffstat (limited to '501draw-text.mu')
-rw-r--r--501draw-text.mu54
1 files changed, 21 insertions, 33 deletions
diff --git a/501draw-text.mu b/501draw-text.mu
index ce87634e..6f0b8011 100644
--- a/501draw-text.mu
+++ b/501draw-text.mu
@@ -105,6 +105,15 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x
   return xcurr
 }
 
+fn draw-int32-decimal-rightward screen: (addr screen), n: int, x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int {
+  var stream-storage: (stream byte 0x100)
+  var stream/esi: (addr stream byte) <- address stream-storage
+  write-int32-decimal stream, n
+#?   write-int32-hex stream, n
+  var xcurr/eax: int <- draw-stream-rightward screen, stream, x, xmax, y, color, background-color
+  return xcurr
+}
+
 # draw a single-line stream from x, y to xmax
 # return the next 'x' coordinate
 # if there isn't enough space, truncate
@@ -244,23 +253,9 @@ fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin:
   var stream-storage: (stream byte 0x100)
   var stream/esi: (addr stream byte) <- address stream-storage
   write-int32-hex stream, n
-  var xcurr/edx: int <- copy x
+  var xcurr/eax: int <- copy x
   var ycurr/ecx: int <- copy y
-  {
-    var g/eax: grapheme <- read-grapheme stream
-    compare g, 0xffffffff/end-of-file
-    break-if-=
-    draw-grapheme screen, g, xcurr, ycurr, color, background-color
-    xcurr <- increment
-    compare xcurr, xmax
-    {
-      break-if-<
-      xcurr <- copy xmin
-      ycurr <- increment
-    }
-    loop
-  }
-  set-cursor-position screen, xcurr, ycurr
+  xcurr, ycurr <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
   return xcurr, ycurr
 }
 
@@ -297,24 +292,17 @@ fn draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen:
 fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
   var stream-storage: (stream byte 0x100)
   var stream/esi: (addr stream byte) <- address stream-storage
+#?   compare n, 0x48
+#?   {
+#?     break-if-!=
+#?     abort "aa"
+#?   }
   write-int32-decimal stream, n
-  var xcurr/edx: int <- copy x
-  var ycurr/ecx: int <- copy y
-  {
-    var g/eax: grapheme <- read-grapheme stream
-    compare g, 0xffffffff/end-of-file
-    break-if-=
-    draw-grapheme screen, g, xcurr, ycurr, color, background-color
-    xcurr <- increment
-    compare xcurr, xmax
-    {
-      break-if-<
-      xcurr <- copy xmin
-      ycurr <- increment
-    }
-    loop
-  }
-  set-cursor-position screen, xcurr, ycurr
+#?   write-int32-decimal stream, 0x48
+#?   write-int32-hex stream, n
+  var xcurr/eax: int <- copy 0
+  var ycurr/ecx: int <- copy 0
+  xcurr, ycurr <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
   return xcurr, ycurr
 }