星期三

Keyboard input

要做Keyboard輸入,首先要明白什麼是I/O Port Mapping,然後要了解Keyboard的運作模式(大致上也要了解硬體的操作原理),搞了一個上午,終於搞清楚了。

這2個網頁解釋得不錯:
1. Wout Mertens' Guide To Keyboard Programming v1.1 Complete
2. IBM PC KEYBOARD INFORMATION FOR SOFTWARE DEVELOPERS

以下只列出新的function(大概以後也會這樣的了):
---------- loader.asm ----------
; *** Get keyboard input (blocked) ***
; Output: DL (Scan Code Set)
GetKeyboard:
   IN AL, 0x64
   TEST AL, 0x01
   JZ GetKeyboard
   IN AL, 0x60
   MOV DL, AL
GetKeyboard_loop:
   IN AL, 0x64
   TEST AL, 0x01
   JZ GetKeyboard_loop
   IN AL, 0x60
   ; peter: not handle special key yet
   RET
; *** End of Get keyboard input (blocked) ***


; *** Print Hex number in text mode ***
; DL = hex value to print (max: FFh)
; BH = Y (row) position
; BL = X (column) position
PrintHex:
   MOV DH, 0
   PUSH DX
   PUSH BX
   SHR DL, 4
   MOV SI, DX
   MOV DL, [PrintHex_chars+SI]
   CALL PrintChar
   POP BX
   POP SI
   AND SI, 0x0F
   MOV DL, [PrintHex_chars+SI]
   INC BL
   CALL PrintChar
   RET
PrintHex_chars db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
; *** End of Print Hex number in text mode ***
---------- loader.asm ----------

沒有留言: