API for external keyboards

git-svn-id: svn://kolibrios.org@2601 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
CleverMouse 2012-04-11 19:06:32 +00:00
parent cb6e8e3fb9
commit bf4cb45023
4 changed files with 139 additions and 1 deletions

View File

@ -72,6 +72,9 @@ iglobal
szLoadFile db 'LoadFile',0
szSendEvent db 'SendEvent',0
szSetMouseData db 'SetMouseData',0
szSetKeyboardData db 'SetKeyboardData',0
szRegKeyboard db 'RegKeyboard',0
szDelKeyboard db 'DelKeyboard',0
szSleep db 'Sleep',0
szGetTimerTicks db 'GetTimerTicks',0
@ -154,6 +157,9 @@ kernel_export:
dd szLoadFile , load_file ;retval eax, ebx
dd szSendEvent , send_event ;see EVENT.inc for specification
dd szSetMouseData , set_mouse_data ;stdcall
dd szSetKeyboardData , set_keyboard_data
dd szRegKeyboard , register_keyboard
dd szDelKeyboard , delete_keyboard
dd szSleep , delay_ms
dd szGetTimerTicks , get_timer_ticks

View File

@ -80,6 +80,9 @@ kernel_export \
LoadFile,\
SendEvent,\
SetMouseData,\
SetKeyboardData,\
RegKeyboard,\
DelKeyboard,\
Sleep,\
GetTimerTicks,\
\

View File

@ -34,6 +34,7 @@ uglobal
ctrl_alt_del db 0
kb_lights db 0
old_kb_lights db 0
align 4
hotkey_scancodes rd 256 ; we have 256 scancodes
@ -113,6 +114,83 @@ set_keyboard_data:
pop ebp edi esi ebx
ret
;---------------------------------------------------------------------
struct KEYBOARD
next dd ?
prev dd ?
functions dd ?
userdata dd ?
ends
struct KBDFUNC
strucsize dd ?
close dd ?
setlights dd ?
ends
iglobal
keyboards:
dd keyboards
dd keyboards
endg
uglobal
keyboard_list_mutex MUTEX
endg
register_keyboard:
push ebx
push sizeof.KEYBOARD
pop eax
call malloc
test eax, eax
jz .nothing
mov ecx, [esp+4+4]
mov [eax+KEYBOARD.functions], ecx
mov ecx, [esp+8+4]
mov [eax+KEYBOARD.userdata], ecx
xchg eax, ebx
mov ecx, keyboard_list_mutex
call mutex_lock
mov ecx, keyboards
mov edx, [ecx+KEYBOARD.prev]
mov [ebx+KEYBOARD.next], ecx
mov [ebx+KEYBOARD.prev], edx
mov [edx+KEYBOARD.next], ebx
mov [ecx+KEYBOARD.prev], ebx
mov ecx, [ebx+KEYBOARD.functions]
cmp [ecx+KBDFUNC.strucsize], KBDFUNC.setlights
jbe .unlock
mov ecx, [ecx+KBDFUNC.setlights]
test ecx, ecx
jz .unlock
stdcall ecx, [ebx+KEYBOARD.userdata], dword [kb_lights]
.unlock:
mov ecx, keyboard_list_mutex
call mutex_unlock
xchg eax, ebx
.nothing:
pop ebx
ret 8
delete_keyboard:
push ebx
mov ebx, [esp+4+4]
mov ecx, keyboard_list_mutex
call mutex_lock
mov eax, [ebx+KEYBOARD.next]
mov edx, [ebx+KEYBOARD.prev]
mov [eax+KEYBOARD.prev], edx
mov [edx+KEYBOARD.next], eax
call mutex_unlock
mov ecx, [ebx+KEYBOARD.functions]
cmp [ecx+KBDFUNC.strucsize], KBDFUNC.close
jbe .nothing
mov ecx, [ecx+KBDFUNC.close]
test ecx, ecx
jz .nothing
stdcall ecx, [ebx+KEYBOARD.userdata]
.nothing:
pop ebx
ret 4
;---------------------------------------------------------------------
align 4
irq1:
movzx eax, word[TASK_COUNT]; top window process
@ -281,7 +359,9 @@ send_scancode:
xor [kb_state], eax
xor [kb_lights], bl
push ecx
call set_lights
pop ecx
.writekey:
; test for system hotkeys
movzx eax, ch
@ -384,10 +464,43 @@ send_scancode:
ret
;---------------------------------------------------------------------
set_lights:
push ebx esi
mov ecx, keyboard_list_mutex
call mutex_lock
mov esi, keyboards
.loop:
mov esi, [esi+KEYBOARD.next]
cmp esi, keyboards
jz .done
mov eax, [esi+KEYBOARD.functions]
cmp dword [eax], KBDFUNC.setlights
jbe .loop
mov eax, [eax+KBDFUNC.setlights]
test eax, eax
jz .loop
stdcall eax, [esi+KEYBOARD.userdata], dword [kb_lights]
jmp .loop
.done:
mov ecx, keyboard_list_mutex
call mutex_unlock
pop esi ebx
ret
ps2_set_lights:
mov al, 0xED
call kb_write
mov al, [kb_lights]
mov al, [esp+8]
call kb_write
ret 8
;// mike.dld ]
check_lights_state:
mov al, [kb_lights]
cmp al, [old_kb_lights]
jz .nothing
mov [old_kb_lights], al
call set_lights
.nothing:
ret
;---------------------------------------------------------------------
numlock_map:

View File

@ -332,6 +332,9 @@ high_code:
mov ecx, disk_list_mutex
call mutex_init
mov ecx, keyboard_list_mutex
call mutex_init
mov ecx, unpack_mutex
call mutex_init
@ -910,6 +913,8 @@ first_app_found:
; SET KEYBOARD PARAMETERS
mov al, 0xf6 ; reset keyboard, scan enabled
call kb_write
test ah, ah
jnz .no_keyboard
; wait until 8042 is ready
xor ecx, ecx
@ -918,6 +923,15 @@ first_app_found:
and al, 00000010b
loopnz @b
iglobal
align 4
ps2_keyboard_functions:
dd .end - $
dd 0 ; no close
dd ps2_set_lights
.end:
endg
stdcall register_keyboard, ps2_keyboard_functions, 0
; mov al, 0xED ; Keyboard LEDs - only for testing!
; call kb_write
; call kb_read
@ -935,6 +949,7 @@ first_app_found:
call set_lights
;// mike.dld ]
stdcall attach_int_handler, 1, irq1, 0
.no_keyboard:
; SET MOUSE
@ -1056,6 +1071,7 @@ osloop:
call checkidle
call check_fdd_motor_status
call check_ATAPI_device_event
call check_lights_state
call check_timers
jmp osloop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;