about summary refs log tree commit diff stats
path: root/305keyboard.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-16 18:54:12 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-16 18:54:12 -0700
commite403d15732e62fc9f1940ef14dc3b46bb11f5201 (patch)
tree81e8d387fe26be18f986fece6766c69c8ad57a2e /305keyboard.subx
parent797c93e054d210a6d595f0b57fd3d9adb9669d8c (diff)
downloadmu-e403d15732e62fc9f1940ef14dc3b46bb11f5201.tar.gz
6794 - cleaner interface for keyboard
So far I've been assuming that read-key only works for ascii, and that
I'd need to get more sophisticated both for multi-byte utf-8 and multi-byte
terminal escape codes like arrow keys. Rather to my surprise, both work
fine. We just need to adjust the types to reflect this fact.
Diffstat (limited to '305keyboard.subx')
-rw-r--r--305keyboard.subx13
1 files changed, 10 insertions, 3 deletions
diff --git a/305keyboard.subx b/305keyboard.subx
index 7c9ce065..35a200b3 100644
--- a/305keyboard.subx
+++ b/305keyboard.subx
@@ -119,15 +119,22 @@ $enable-keyboard-type-mode:end:
     5d/pop-to-ebp
     c3/return
 
-read-key-from-real-keyboard:  # -> result/eax: byte
+# read keys or escapes up to 4 bytes
+#
+# fun fact: terminal escapes and graphemes in utf-8 don't conflict!
+# - in graphemes all but the first/lowest byte will have a 1 in the MSB (be
+#   greater than 0x7f)
+# - in escapes every byte will have a 0 in the MSB
+# the two categories overlap only when the first/lowest byte is 0x1b or 'esc'
+read-key-from-real-keyboard:  # -> result/eax: grapheme
     # . prologue
     55/push-ebp
     89/<- %ebp 4/r32/esp
     # . save registers
     51/push-ecx
-    # var buf/ecx: (stream byte 1)
+    # var buf/ecx: (stream byte 4)
     68/push 0/imm32/data
-    68/push 1/imm32/size  # 3 bytes of data unused
+    68/push 4/imm32/size
     68/push 0/imm32/read
     68/push 0/imm32/write
     89/<- %ecx 4/r32/esp