User:Johnburger/Demo/Exec/Key

From OSDev Wiki
Jump to: navigation, search

This code needs to do two things:

Note that this Interrupt handler doesn't do two things:

  1. Maintain the state of the "Shift" keys, like <Shift>, <Ctrl> and <Alt>;
  2. Convert scan codes into ASCII for the standard keys.

Both of these are left as an exercise for the reader - including the decision as to whether they belong inside the interrupt handler at all! (Hint: I suggest "Yes" for #1 and "No" for #2).

Demo/Exec/Key.inc

;
; Exec/Key.inc
;
 
; This module installs a Keyboard interrupt handler. There's not much to do:
; the defaults as set by the BIOS are good enough.
; Of course, to be a true Device Driver, something needs to convert the KeyCodes
; generated by the keyboard into the ASCII equivalents (or whatever) for more
; general consumption by other programs. This has been left as an exercise for
; the reader - until I get impatient and do it myself...
 
Exec.Key:
; First, install a Keyboard interrupt handler
                MOV             EAX,Ints.Key    ; Handler
                MOV             EBX,IDT.Key     ; Interrupt
                MOV             CX,Selector(GDT.Ints, GDT, RPL0)
                MOV             DL,Type.Sys(Int, DPL0, 386)
                CALL            Exec.Alloc.IDT
 
; Finally, enable the Keyboard interrupt in the PIC
                IN              AL,Dev.PIC.A.Mask
                AND             AL,~Dev.PIC.A.Key         ; Unmask Key IRQ
                OUT             Dev.PIC.A.Mask,AL
 
                RET
Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox