about summary refs log tree commit diff stats
path: root/baremetal/103grapheme.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2021-01-23 08:45:51 -0800
committerKartik Agaram <vc@akkartik.com>2021-01-23 08:45:51 -0800
commit63be7b7d0d5bb6e728d9afbb68e238fcd3bda3a7 (patch)
tree7f26c1430c53e0aec3cbe889bf80e70078db8506 /baremetal/103grapheme.subx
parent0f73127ef1eba0a8ea814c26115523da3590ffe2 (diff)
downloadmu-63be7b7d0d5bb6e728d9afbb68e238fcd3bda3a7.tar.gz
7548 - baremetal: better cursor management
Diffstat (limited to 'baremetal/103grapheme.subx')
-rw-r--r--baremetal/103grapheme.subx50
1 files changed, 38 insertions, 12 deletions
diff --git a/baremetal/103grapheme.subx b/baremetal/103grapheme.subx
index b4750989..16a44fbc 100644
--- a/baremetal/103grapheme.subx
+++ b/baremetal/103grapheme.subx
@@ -104,17 +104,13 @@ $cursor-position-on-real-screen:end:
     5d/pop-to-ebp
     c3/return
 
-# Caller is responsible for tracking what was on the screen at this position
-# before, and making sure the cursor continues to show the same grapheme.
-set-cursor-position-on-real-screen:  # x: int, y: int, g: grapheme
+set-cursor-position-on-real-screen:  # x: int, y: int
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
     50/push-eax
     #
-    (draw-grapheme-on-real-screen *(ebp+0x10) *(ebp+8) *(ebp+0xc) 0 7)
-    # TODO: support fake screen; we currently assume 'screen' is always 0 (real)
     8b/-> *(ebp+8) 0/r32/eax
     89/<- *Real-screen-cursor-x 0/r32/eax
     8b/-> *(ebp+0xc) 0/r32/eax
@@ -127,17 +123,47 @@ $set-cursor-position-on-real-screen:end:
     5d/pop-to-ebp
     c3/return
 
+# Draw cursor at current location. But this is rickety:
+#   - does not clear previous location cursor was shown at.
+#   - does not preserve what was at the cursor. Caller is responsible for
+#     tracking what was on the screen at this position before and passing it
+#     in again.
+show-cursor-on-real-screen:  # g: grapheme
+    # . prologue
+    55/push-ebp
+    89/<- %ebp 4/r32/esp
+    # . save registers
+    50/push-eax
+    51/push-ecx
+    #
+    (cursor-position-on-real-screen)  # => eax, ecx
+    (draw-grapheme-on-real-screen *(ebp+8) %eax %ecx 0 7)
+$show-cursor-on-real-screen:end:
+    # . restore registers
+    59/pop-to-ecx
+    58/pop-to-eax
+    # . epilogue
+    89/<- %esp 5/r32/ebp
+    5d/pop-to-ebp
+    c3/return
+
 == data
 
 # The cursor is where certain Mu functions (usually of the form
-# 'draw*cursor*') print to by default. It becomes visible on
-# set-cursor-position, but further drawing might overwrite it.
-# We don't bother displaying the cursor when drawing text. It's up to
-# applications to display the cursor before waiting for a key, and to ensure
-# its location appropriately suggests the effect keystrokes will have.
+# 'draw*cursor*') print to by default.
+#
+# We don't bother displaying the cursor when drawing. It only becomes visible
+# on show-cursor, which is quite rickety (see above)
+#
+# It's up to applications to manage cursor display:
+#   - clean up where it used to be
+#   - display the cursor before waiting for a key
+#   - ensure its location appropriately suggests the effect keystrokes will have
+#   - ensure its contents (and colors) appropriately reflect the state of the
+#     screen
 #
-# There's no low-level support for blinking, etc. We aren't using any
-# hardware-supported text mode here.
+# There's no blinking, etc. We aren't using any hardware-supported text mode
+# here.
 Real-screen-cursor-x:
   0/imm32
 Real-screen-cursor-y: