about summary refs log tree commit diff stats
path: root/boot.subx
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 /boot.subx
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 'boot.subx')
-rw-r--r--boot.subx207
1 files changed, 118 insertions, 89 deletions
diff --git a/boot.subx b/boot.subx
index 6982fccb..ed2d213e 100644
--- a/boot.subx
+++ b/boot.subx
@@ -359,96 +359,125 @@ keyboard-interrupt-handler:
   3c/compare-al-and 0/imm8
   75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
   # - read keycode
+  31/xor %eax 0/r32/eax
   e4/read-port-into-al 0x60/imm8
-  # - key released
-  # if (al == 0xaa) shift = false  # left shift is being lifted
-  {
-    3c/compare-al-and 0xaa/imm8
-    75/jump-if-!= break/disp8
-    # *shift = 0
-    c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
-  }
-  # if (al == 0xb6) shift = false  # right shift is being lifted
-  {
-    3c/compare-al-and 0xb6/imm8
-    75/jump-if-!= break/disp8
-    # *shift = 0
-    c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
-  }
-  # if (al == 0x9d) ctrl = false  # ctrl is being lifted
-  {
-    3c/compare-al-and 0x9d/imm8
-    75/jump-if-!= break/disp8
-    # *ctrl = 0
-    c7 0/subop/copy *Keyboard-ctrl-pressed? 0/imm32
-  }
-  # if (al & 0x80) a key is being lifted; return
-  50/push-eax
-  24/and-al-with 0x80/imm8
-  3c/compare-al-and 0/imm8
-  58/pop-to-eax
-  75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
-  # - key pressed
-  # if (al == 0x2a) shift = true, return  # left shift pressed
-  {
-    3c/compare-al-and 0x2a/imm8
-    75/jump-if-!= break/disp8
-    # *shift = 1
-    c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
-    # return
-    eb/jump $keyboard-interrupt-handler:epilogue/disp8
-  }
-  # if (al == 0x36) shift = true, return  # right shift pressed
-  {
-    3c/compare-al-and 0x36/imm8
-    75/jump-if-!= break/disp8
-    # *shift = 1
-    c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
-    # return
-    eb/jump $keyboard-interrupt-handler:epilogue/disp8
-  }
-  # if (al == 0x1d) ctrl = true, return
-  {
-    3c/compare-al-and 0x1d/imm8
-    75/jump-if-!= break/disp8
-    # *ctrl = 1
-    c7 0/subop/copy *Keyboard-ctrl-pressed? 1/imm32
-    # return
-    eb/jump $keyboard-interrupt-handler:epilogue/disp8
-  }
-  # - convert key to character
-  # if (shift) use keyboard shift map
-  {
-    81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
-    74/jump-if-= break/disp8
-    # sigils don't currently support labels inside *(eax+label)
-    05/add-to-eax Keyboard-shift-map/imm32
-    8a/byte-> *eax 0/r32/al
-    eb/jump $keyboard-interrupt-handler:select-map-done/disp8
-  }
-  # if (ctrl) al = *(ctrl map + al)
-  {
-    81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
-    74/jump-if-= break/disp8
-    05/add-to-eax Keyboard-ctrl-map/imm32
-    8a/byte-> *eax 0/r32/al
-    eb/jump $keyboard-interrupt-handler:select-map-done/disp8
-  }
-  # otherwise al = *(normal map + al)
-  05/add-to-eax Keyboard-normal-map/imm32
-  8a/byte-> *eax 0/r32/al
-$keyboard-interrupt-handler:select-map-done:
-  # - if there's no character mapping, return
-  {
-    3c/compare-al-and 0/imm8
-    74/jump-if-= break/disp8
-    # - store al in keyboard buffer
-    88/<- *ecx 0/r32/al
-    # increment index
-    fe/increment-byte *Keyboard-buffer:write
-    # clear top nibble of index (keyboard buffer is circular)
-    80 4/subop/and-byte *Keyboard-buffer:write 0x0f/imm8
-  }
+  #
+#?   50/push-eax
+#?   51/push-ecx
+#?   (draw-int32-hex-wrapping-right-then-down-over-full-screen 0 %eax 0 0 7 0)
+#?   59/pop-to-ecx
+#?   58/pop-to-eax
+  #
+#?   50/push-eax
+#?   51/push-ecx
+#?   (draw-int32-decimal-wrapping-right-then-down 0 %eax 0 2 0x400 2 0 2 7 0)
+  89/<- %ecx 0/r32/eax
+  # . . push args
+  68/push 0/imm32/bg
+  68/push 7/imm32/fg
+  68/push 2/imm32/y
+  68/push 0x400/imm32/xmax
+  68/push 0/imm32/xmin
+#?   68/push 0x48/imm32/n
+  51/push-ecx
+  68/push 0/imm32/screen
+  # . . call
+#?   e8/call draw-int32-hex-wrapping-right-then-down/disp32
+#?   e8/call draw-int32-decimal-wrapping-right-then-down/disp32
+  e8/call draw-int32-decimal-rightward/disp32
+  # . . discard args
+  81 0/subop/add %esp 0x1c/imm32
+#?   59/pop-to-ecx
+#?   58/pop-to-eax
+#?   # - key released
+#?   # if (al == 0xaa) shift = false  # left shift is being lifted
+#?   {
+#?     3c/compare-al-and 0xaa/imm8
+#?     75/jump-if-!= break/disp8
+#?     # *shift = 0
+#?     c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
+#?   }
+#?   # if (al == 0xb6) shift = false  # right shift is being lifted
+#?   {
+#?     3c/compare-al-and 0xb6/imm8
+#?     75/jump-if-!= break/disp8
+#?     # *shift = 0
+#?     c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
+#?   }
+#?   # if (al == 0x9d) ctrl = false  # ctrl is being lifted
+#?   {
+#?     3c/compare-al-and 0x9d/imm8
+#?     75/jump-if-!= break/disp8
+#?     # *ctrl = 0
+#?     c7 0/subop/copy *Keyboard-ctrl-pressed? 0/imm32
+#?   }
+#?   # if (al & 0x80) a key is being lifted; return
+#?   50/push-eax
+#?   24/and-al-with 0x80/imm8
+#?   3c/compare-al-and 0/imm8
+#?   58/pop-to-eax
+#?   75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
+#?   # - key pressed
+#?   # if (al == 0x2a) shift = true, return  # left shift pressed
+#?   {
+#?     3c/compare-al-and 0x2a/imm8
+#?     75/jump-if-!= break/disp8
+#?     # *shift = 1
+#?     c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
+#?     # return
+#?     eb/jump $keyboard-interrupt-handler:epilogue/disp8
+#?   }
+#?   # if (al == 0x36) shift = true, return  # right shift pressed
+#?   {
+#?     3c/compare-al-and 0x36/imm8
+#?     75/jump-if-!= break/disp8
+#?     # *shift = 1
+#?     c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
+#?     # return
+#?     eb/jump $keyboard-interrupt-handler:epilogue/disp8
+#?   }
+#?   # if (al == 0x1d) ctrl = true, return
+#?   {
+#?     3c/compare-al-and 0x1d/imm8
+#?     75/jump-if-!= break/disp8
+#?     # *ctrl = 1
+#?     c7 0/subop/copy *Keyboard-ctrl-pressed? 1/imm32
+#?     # return
+#?     eb/jump $keyboard-interrupt-handler:epilogue/disp8
+#?   }
+#?   # - convert key to character
+#?   # if (shift) use keyboard shift map
+#?   {
+#?     81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
+#?     74/jump-if-= break/disp8
+#?     # sigils don't currently support labels inside *(eax+label)
+#?     05/add-to-eax Keyboard-shift-map/imm32
+#?     8a/byte-> *eax 0/r32/al
+#?     eb/jump $keyboard-interrupt-handler:select-map-done/disp8
+#?   }
+#?   # if (ctrl) al = *(ctrl map + al)
+#?   {
+#?     81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
+#?     74/jump-if-= break/disp8
+#?     05/add-to-eax Keyboard-ctrl-map/imm32
+#?     8a/byte-> *eax 0/r32/al
+#?     eb/jump $keyboard-interrupt-handler:select-map-done/disp8
+#?   }
+#?   # otherwise al = *(normal map + al)
+#?   05/add-to-eax Keyboard-normal-map/imm32
+#?   8a/byte-> *eax 0/r32/al
+#? $keyboard-interrupt-handler:select-map-done:
+#?   # - if there's no character mapping, return
+#?   {
+#?     3c/compare-al-and 0/imm8
+#?     74/jump-if-= break/disp8
+#?     # - store al in keyboard buffer
+#?     88/<- *ecx 0/r32/al
+#?     # increment index
+#?     fe/increment-byte *Keyboard-buffer:write
+#?     # clear top nibble of index (keyboard buffer is circular)
+#?     80 4/subop/and-byte *Keyboard-buffer:write 0x0f/imm8
+#?   }
 $keyboard-interrupt-handler:epilogue:
   # epilogue
   9d/pop-flags