about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-12-07 21:48:47 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-12-07 21:48:47 -0800
commitae4058add3c2002b90f171a1ace40bf21118103e (patch)
treed7bfb5e655895eb86ba9e239ae245fd65fab00b3
parent204589b2ffc8aa16fa2953017eaa6614f7d05eb5 (diff)
downloadmu-hlt.tar.gz
halt until exception when waiting for keyboard hlt
This reduces CPU consumption from 180% to 2% when running Qemu.

Many thanks to Fabian of https://copy.sh for this suggestion.
-rw-r--r--102keyboard.subx2
1 files changed, 2 insertions, 0 deletions
diff --git a/102keyboard.subx b/102keyboard.subx
index 39788075..f963baa2 100644
--- a/102keyboard.subx
+++ b/102keyboard.subx
@@ -24,6 +24,8 @@ read-key:  # kbd: (addr keyboard) -> result/eax: byte
     89/<- %ebp 4/r32/esp
     # . save registers
     51/push-ecx
+    # wait for an interrupt to save power on Qemu
+    f4/hlt
     # result = 0
     b8/copy-to-eax 0/imm32
     # ecx = keyboard