From 4254408a385f90ffe212e85a7b405054f4e73f5e Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 23 Jan 2021 11:14:07 -0800 Subject: 7549 --- html/baremetal/102keyboard.subx.html | 89 +++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'html/baremetal/102keyboard.subx.html') diff --git a/html/baremetal/102keyboard.subx.html b/html/baremetal/102keyboard.subx.html index 660d74fb..e77a5b10 100644 --- a/html/baremetal/102keyboard.subx.html +++ b/html/baremetal/102keyboard.subx.html @@ -56,49 +56,52 @@ if ('onhashchange' in window) {
  1 # check keyboard for a key
  2 # return 0 on no keypress or unrecognized key
- 3 
- 4 == code
- 5 
- 6 read-key:  # kbd: (addr keyboard) -> result/eax: byte
- 7     # . prologue
- 8     55/push-ebp
- 9     89/<- %ebp 4/r32/esp
-10     # . save registers
-11     51/push-ecx
-12     # result = 0
-13     b8/copy-to-eax 0/imm32
-14     # ecx = keyboard
-15     8b/-> *(ebp+8) 1/r32/ecx
-16     81 7/subop/compare %ecx 0/imm32
-17     {
-18       75/jump-if-!= break/disp8
-19       # var read/ecx: byte = keyboard buffer's read index
-20       8b/-> *0x7dcc 1/r32/CL  # keyboard-buffer-read
-21       # var next-key/eax: byte = *(keyboard buffer + ecx)
-22       8a/byte-> *(ecx+0x7dd0) 0/r32/AL  # keyboard-buffer-data
-23       # if (next-key != 0) lock and remove from keyboard-buffer
-24       81 7/subop/compare %eax 0/imm32
-25       {
-26         74/jump-if-= break/disp8
-27         # TODO: add some instructions in this block to SubX if we ever want to
-28         # use bootstrap on baremetal programs
-29         fa/disable-interrupts
-30         c6 0/subop/copy-byte *(ecx+0x7dd0) 0/imm8
-31         ff 0/subop/increment *0x7dcc  # keyboard-buffer-read
-32         81 4/subop/and *0x7dcc 0xf/imm32  # keyboard-buffer-read
-33         fb/enable-interrupts
-34       }
-35       # return
-36       eb $read-key:end/disp8
-37     }
-38     # TODO: fake keyboard
-39 $read-key:end:
-40     # . restore registers
-41     59/pop-to-ecx
-42     # . epilogue
-43     89/<- %esp 5/r32/ebp
-44     5d/pop-to-ebp
-45     c3/return
+ 3 #
+ 4 # We need to do this in machine code because Mu doesn't have global variables
+ 5 # yet (for the keyboard buffer).
+ 6 
+ 7 == code
+ 8 
+ 9 read-key:  # kbd: (addr keyboard) -> result/eax: byte
+10     # . prologue
+11     55/push-ebp
+12     89/<- %ebp 4/r32/esp
+13     # . save registers
+14     51/push-ecx
+15     # result = 0
+16     b8/copy-to-eax 0/imm32
+17     # ecx = keyboard
+18     8b/-> *(ebp+8) 1/r32/ecx
+19     81 7/subop/compare %ecx 0/imm32
+20     {
+21       75/jump-if-!= break/disp8
+22       # var read/ecx: byte = keyboard buffer's read index
+23       8b/-> *0x7dcc 1/r32/CL  # keyboard-buffer-read
+24       # var next-key/eax: byte = *(keyboard buffer + ecx)
+25       8a/byte-> *(ecx+0x7dd0) 0/r32/AL  # keyboard-buffer-data
+26       # if (next-key != 0) lock and remove from keyboard-buffer
+27       81 7/subop/compare %eax 0/imm32
+28       {
+29         74/jump-if-= break/disp8
+30         # TODO: add some instructions in this block to SubX if we ever want to
+31         # use bootstrap on baremetal programs
+32         fa/disable-interrupts
+33         c6 0/subop/copy-byte *(ecx+0x7dd0) 0/imm8
+34         ff 0/subop/increment *0x7dcc  # keyboard-buffer-read
+35         81 4/subop/and *0x7dcc 0xf/imm32  # keyboard-buffer-read
+36         fb/enable-interrupts
+37       }
+38       # return
+39       eb $read-key:end/disp8
+40     }
+41     # TODO: fake keyboard
+42 $read-key:end:
+43     # . restore registers
+44     59/pop-to-ecx
+45     # . epilogue
+46     89/<- %esp 5/r32/ebp
+47     5d/pop-to-ebp
+48     c3/return
 
-- cgit 1.4.1-2-gfad0