I did it in ASM to make the interfacing a little easier and faster, and it looked a little something like this:
Code: Select all
boardLEDS:
xor cl, cl
mov cl, [caps_state]
add cl, [num_state]
add cl, [scroll_state]
mov [final_state], cl
kwait: ;Wait for clear
in al, 0x64
test al, 0x02
jnz kwait
mov dx, 0x60 ;Send function code
mov al, 0xED
out dx, al
kack: ;Wait for acknowledge
in al, 0x60
test al, 0x80
jne kack
kwait2: ;Wait for clear
in al, 0x64
test al, 0x02
jnz kwait2
mov al, [final_state] ;Set LEDs
out 60h, al
kack2: ;Wait for acknowledge
in al, 0x60
test al, 0x80
jne kack2
ret ;Return.
With the LED code in place, it runs through the code, set's any appropriate LEDs (e.g. does it's job), returns to the driver, returns to the master interrupt controller and then halts. No errors our faults or anything, but you can no longer input anything with the keyboard (note: I did free the interrupt after the driver code was executed), or do anything else in the os. Also keep in mind that this is being called from a C function that should take carve of all pushs and pops to the stack that it makes.
In brief:
Code compiles, links and executes
One key is pressed, driver does it's job
OS locks (no more input).