Last year I found that code snippet and used it to blink the leds on my keyboard under win95 98 without any problem.
Now I work under XP and it compiles fine but it craches when it loads. Is it because XP doesn't let us access directly the bios ?
Is there a possible workaround ? Thanks in advance ;o)



.586
.MODEL FLAT, STDCALL
OPTION CASEMAP: NONE

include \masm32\include\windows.inc

include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


KeyBDIOCheck PROTO


.CODE
WinMain PROC

mov edi,10 ;Loop 10 times
MainLoop:

invoke KeyBDIOCheck ;This little proc makes sure the keyboard controller is ready to be written to
mov al,0edh ;Command, set LED lights
out 60h,al ;Send it to the keyboard

invoke KeyBDIOCheck ;Wait for ready
mov al,0111b ;Set all 3 lights (lowest 3 bits set)
out 60h,al ;Send it


invoke Sleep ,1000 ;Wait for 1 second


invoke KeyBDIOCheck ;Wait again
mov al,0edh ;Set LED lights
out 60h,al ;Send it

invoke KeyBDIOCheck ;Wait for ready
xor al,al ;No bits set, all lights off
out 60h,al ;Send it


invoke Sleep ,1000 ;Sleep

dec edi ;Decrement counter
jnz MainLoop ;Loop if counter not zero


invoke ExitProcess ,NO_ERROR
WinMain ENDP


;This procedure check to make sure the keyboard controller is
;ready to be written to, ie so it wont corrupt data already written
;to the controller
KeyBDIOCheck PROC USES EAX

ReadyForWrite:
in al,64h ;Get the status BYTE
.IF (al & 010b) ;Check the 2nd bit (Write ready)
mov eax,0fffh ;If its set have a slight delay
@@:
dec eax
jnz @B
jmp ReadyForWrite ;Try again
.ENDIF


ret
KeyBDIOCheck ENDP


END WinMain
Posted on 2004-02-28 11:13:43 by interrupt38h
NT (Of which XP is 5.1) is a decent OS which has proper protection... have a look in the FAQ:
http://www.asmcommunity.net/board/index.php?topic=6670
Search for "How to write data to port directly in windows NT"
Posted on 2004-02-28 19:14:24 by f0dder
Thanks a lot ! I'll try out the solution proposed by Thomas on madwizard.org
Thanks again ;o)
Posted on 2004-02-28 22:14:51 by interrupt38h
On NT-based systems it's a bit easier. Forget about directly accessing ports. You just have to send proper I/O control code to keyboard device via DeviceIoControl.

In the attachment is an example from KmdKit. To compile you probably have to dowloan full package here http://www.freewebs.com/four-f/index.htm
Posted on 2004-02-29 03:20:24 by Four-F
i used keybd_event to let the leds blink
Posted on 2004-02-29 07:11:59 by chromos
pretty cute, Four-F - nicer than mucking around with WinIO or whatever :)
Posted on 2004-02-29 08:40:35 by f0dder
Thanks Four-F, really simpler than with WinIO !
Posted on 2004-02-29 09:23:39 by interrupt38h