about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-16 15:46:36 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-16 16:43:52 -0700
commitf4fb198af313a3a30400ba1a51e0f0425b1da0ca (patch)
tree7791e011af839825fec98a0aa5776c07597da268
parent5029dac235741025ccec7d2c3d5609724cb14525 (diff)
downloadmu-f4fb198af313a3a30400ba1a51e0f0425b1da0ca.tar.gz
6790 experiment: explicit flush
tile is already visibly slow (49x212 screen) :/ So programmer needs more
control over performance.

But this may not be the right approach. That extra flush-stdout in tui.mu
suggests it's either going to be finicky, or we have to flush on every
attribute change. And going through a buffered-file may be slower. May.
-rw-r--r--304screen.subx56
-rw-r--r--400.mu2
-rw-r--r--apps/tile/main.mu1
-rw-r--r--apps/tui.mu4
4 files changed, 37 insertions, 26 deletions
diff --git a/304screen.subx b/304screen.subx
index 8ec33fd5..33d280a0 100644
--- a/304screen.subx
+++ b/304screen.subx
@@ -124,7 +124,8 @@ print-string-to-real-screen:  # s: (addr array byte)
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 *(ebp+8))
+    (write-buffered Stdout *(ebp+8))
+#?     (flush Stdout)
 $print-string-to-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -137,7 +138,7 @@ print-slice-to-real-screen:  # s: (addr slice)
     89/<- %ebp 4/r32/esp
     #
     (write-slice-buffered Stdout *(ebp+8))
-    (flush Stdout)
+#?     (flush Stdout)
 $print-slice-to-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -150,7 +151,7 @@ print-stream-to-real-screen:  # s: (addr stream byte)
     89/<- %ebp 4/r32/esp
     #
     (write-stream-data Stdout *(ebp+8))
-    (flush Stdout)
+#?     (flush Stdout)
 $print-stream-to-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -212,7 +213,8 @@ print-byte-to-real-screen:  # c: byte
     ff 6/subop/push *(ebp+8)
     68/push 1/imm32/size
     89/<- %ecx 4/r32/esp
-    (write 1 %ecx)
+    (write-buffered Stdout %ecx)
+#?     (flush Stdout)
 $print-byte-to-real-screen:end:
     # . reclaim locals
     81 0/subop/add %esp 8/imm32
@@ -223,13 +225,17 @@ $print-byte-to-real-screen:end:
     5d/pop-to-ebp
     c3/return
 
+flush-stdout:
+    (flush Stdout)
+    c3/return
+
 print-int32-hex-to-real-screen:  # n: int
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
     (write-int32-hex-buffered Stdout *(ebp+8))
-    (flush Stdout)
+#?     (flush Stdout)
 $print-int32-hex-to-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -242,7 +248,7 @@ print-int32-decimal-to-real-screen:  # n: int
     89/<- %ebp 4/r32/esp
     #
     (write-int32-decimal-buffered Stdout *(ebp+8))
-    (flush Stdout)
+#?     (flush Stdout)
 $print-int32-decimal-to-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -278,10 +284,10 @@ reset-formatting-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "(B")
-    (write 1 Esc)
-    (write 1 "[m")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "(B")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[m")
 $reset-formatting-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -312,7 +318,7 @@ start-color-on-real-screen:  # fg: int, bg: int
     (write-int32-decimal %ecx *(ebp+0xc))
     (write %ecx "m")
     # flush
-    (write-stream 2 %ecx)
+    (write-stream-data Stdout %ecx)
 $start-color-on-real-screen:end:
     # . reclaim locals
     81 0/subop/add %esp 0x2c/imm32
@@ -328,8 +334,8 @@ start-bold-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "[1m")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[1m")
 $start-bold-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -341,8 +347,8 @@ start-underline-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "[4m")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[4m")
 $start-underline-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -354,8 +360,8 @@ start-reverse-video-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "[7m")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[7m")
 $start-reverse-video-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -368,8 +374,8 @@ start-blinking-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "[5m")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[5m")
 $start-blinking-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -381,8 +387,8 @@ hide-cursor-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "[?25l")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[?25l")
 $hide-cursor-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
@@ -394,10 +400,10 @@ show-cursor-on-real-screen:
     55/push-ebp
     89/<- %ebp 4/r32/esp
     #
-    (write 1 Esc)
-    (write 1 "[?12l")
-    (write 1 Esc)
-    (write 1 "[?25h")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[?12l")
+    (write-buffered Stdout Esc)
+    (write-buffered Stdout "[?25h")
 $show-cursor-on-real-screen:end:
     # . epilogue
     89/<- %esp 5/r32/ebp
diff --git a/400.mu b/400.mu
index 7b32f3cb..4b896ba5 100644
--- a/400.mu
+++ b/400.mu
@@ -172,3 +172,5 @@ sig stream-empty? s: (addr stream _) -> result/eax: boolean
 sig stream-full? s: (addr stream _) -> result/eax: boolean
 
 sig copy-bytes src: (addr byte), dest: (addr byte), n: int
+
+sig flush-stdout
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index 7c7065fc..a9d62bb4 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -75,4 +75,5 @@ fn render screen: (addr screen), buf: (addr gap-buffer) {
   move-cursor screen, start-row, start-col
   #
   render-gap-buffer screen, buf
+  flush-stdout
 }
diff --git a/apps/tui.mu b/apps/tui.mu
index a02d8fb0..4af4d405 100644
--- a/apps/tui.mu
+++ b/apps/tui.mu
@@ -14,6 +14,7 @@ fn main -> exit-status/ebx: int {
   start-blinking 0
   print-string 0, "Hello world!"
   reset-formatting 0
+  flush-stdout
   move-cursor 0, 6, 0x22
   print-string 0, "tty dimensions: "
   print-int32-hex 0, nrows
@@ -28,7 +29,8 @@ fn main -> exit-status/ebx: int {
   enable-screen-type-mode
   print-string 0, "You pressed "
   var x-int/eax: int <- copy x
-  print-int32-hex 0, x-int
+  print-int32-hex-to-real-screen x-int
   print-string 0, "\n"
+  flush-stdout
   exit-status <- copy 0
 }