📄 keyboard.asm
字号:
;**************************************************************************
;*
;* KEYBOARD.ASM
;*
;* Copyright (c) 1999 National Semiconductor Corporation.
;* All Rights Reserved.
;*
;* Function:
;* Initialize the keyboard controller so it's acceptable to WinCE.
;*
;* $Revision:: 1 $
;*
;**************************************************************************
;.MODEL TINY
.486P
INCLUDE DEF.INC
INCLUDE MACROS.INC
INCLUDE PORT80.INC
INCLUDE STRINGS.INC
INCLUDE OPTIONS.INC
_TEXT SEGMENT PUBLIC use16 'CODE'
EXTERN Delay_1_mSec:NEAR
EXTERN Delay_100_mSec:NEAR
;**************************************************************************
;*
;* kb_wait_ibe
;*
;* Wait for the input buffer to be empty
;*
;* Entry:
;* Exit:
;* Destroys:
;*
;**************************************************************************
kb_wait_ibe PROC NEAR PUBLIC
pusha
call Delay_1_mSec
call Delay_1_mSec
mov cx, 0ffffh
waitIBE:
in al, 064h
and al, 02h
cmp al, 02h
loope waitIBE
popa
ret
kb_wait_ibe ENDP
;**************************************************************************
;*
;* kb_wait_obe
;*
;* Wait for the output buffer to be empty
;*
;* Entry:
;* Exit:
;* Destroys:
;*
;**************************************************************************
kb_wait_obe PROC NEAR PUBLIC
pusha
call Delay_1_mSec
call Delay_1_mSec
mov cx, 0ffffh
waitOBE:
in al, 064h
and al, 01h
cmp al, 01h
loope waitOBE
popa
ret
kb_wait_obe ENDP
;**************************************************************************
;*
;* kb_wait_obf
;*
;* Wait for the input buffer to be full
;*
;* Entry:
;* Exit:
;* Destroys:
;*
;**************************************************************************
kb_wait_obf PROC NEAR PUBLIC
pusha
call Delay_1_mSec
call Delay_1_mSec
mov ecx, 0ffffh
waitOBF:
in al, 064h
and al, 01h
cmp al, 01h
loopne waitOBF
popa
ret
kb_wait_obf ENDP
;**************************************************************************
;*
;* kb_send_controller
;*
;* Send a command to the keyboard controller
;*
;* Entry:
;* AL = command
;*
;* Exit:
;* None
;*
;* Destroys:
;* All registers preserved.
;*
;**************************************************************************
kb_send_controller PROC NEAR PUBLIC
out 064h, al
ret
kb_send_controller ENDP
;**************************************************************************
;*
;* kb_send_command
;*
;* Send a command to the keyboard itself
;*
;* Entry:
;* AL = command
;*
;* Exit:
;* None
;*
;* Destroys:
;* All registers preserved.
;*
;**************************************************************************
kb_send_command PROC NEAR PUBLIC
out 060h, al
ret
kb_send_command ENDP
;**************************************************************************
;*
;* kb_get_data
;*
;* Get a byte of data from the keyboard port 60h
;*
;* Entry:
;* Exit:
;* Destroys:
;*
;**************************************************************************
kb_get_data PROC NEAR PUBLIC
call kb_wait_obf ; Wait for data to be ready.
in al, 060h ; Data Read
call kb_wait_obe ; Wait for data buffer to clear
ret
kb_get_data ENDP
;**************************************************************************
;*
;* kb_delay
;*
;* Delay for a period of time
;*
;* Entry:
;* Exit:
;* Destroys:
;*
;**************************************************************************
kb_delay PROC NEAR PUBLIC
pusha
call Delay_1_mSec
call Delay_1_mSec
mov cx, 07ffh
delayLoop:
in al, 064h
test al, 01h
jz eoloop
in al, 060h
eoloop:
loop delayLoop
popa
ret
kb_delay ENDP
;**************************************************************************
;*
;* keyboardInit
;*
;* Entry:
;* Exit:
;* Destroys:
;*
;**************************************************************************
keyboardInit PROC NEAR PUBLIC
push bx
cld
in al, 064h
cmp al, 0ffh
je noKeyboardInstalled
call kb_wait_obe
call kb_wait_ibe
; selftest keyboard controller
mov al, 0aah
call kb_send_controller
call kb_get_data ; expect 055h
call kb_delay
call kb_wait_obe
call kb_wait_ibe
; enable keyboard
mov al, 0AEh
call kb_send_controller
call kb_delay
call kb_wait_obe
call kb_wait_ibe
; send reset
mov cx, 010h
mov dl, 0FEh
WaitForFA1:
mov al, 0ffh
call kb_send_command
call kb_get_data ; expect 0FAh
cmp al, dl
loope WaitForFA1
call kb_get_data ; expect 0AAh
; set the keyboard scan code mode
mov cx, 010h
mov dl, 0FEh
WaitForFA2:
mov al, 0F0h
call kb_send_command
call kb_get_data ; expect 0FAh
cmp al, dl
loope WaitForFA2
mov al, 02h ; set scan code to 02 for DOS and Win.
call kb_send_command
call kb_wait_obe
call kb_wait_ibe
; get the keyboard scan code mode
mov cx, 010h
mov dl, 0FEh
WaitForFA3:
mov al, 0f0h
call kb_send_command
call kb_get_data ; expect 0FAh
cmp al, dl
loope WaitForFA3
mov al, 00h ; get set scan code.
call kb_send_command
call kb_get_data ; expect 02h
; enable keyboard device
mov cx, 010h
mov dl, 0FEh
WaitForFA4:
mov al, 0F4h
call kb_send_command
call kb_get_data ; expect 0FAh
cmp al, dl
loope WaitForFA4
; enable mouse / AUX device
mov al, 0A8h
call kb_send_controller
call kb_delay
call kb_wait_obe
call kb_wait_ibe
; encourage the keyboard to issue interrupts when it has data ready
mov al, 060h
call kb_send_controller
call kb_wait_obe
call kb_wait_ibe
mov al, 065h
call kb_send_command
; eine kleine cleanup
call kb_delay
;
; Done with KB Init
;
noKeyboardSupport:
noKeyboardInstalled:
pop bx
jmp bx
keyboardInit ENDP
_TEXT ENDS
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -