Well without any real code, just enabling the PIC bit 1, to capture
interrupts, we can have our computer catch interrupts from the keyboard!
Thats right, when a key is then pressed, this causes an interrupt to be issued.
So then in our interrupt routine, its just a matter of reading from port 60h,
which is the keyboard chip, and read which key was pressed, if the key is
pressed down or being released...then thats it!

Code Snippet

;First we enable our code
so we get an interrupt each time a key is pressed!

; Enable Keyboard PIC chips 'ONLY', disable others:

;(Port 0x21 bit 1 is keyboard)

mov al, 0xFD

mov dx, 0x21

out dx, al ; outb(0x21, ~0x01)

mov al, 0xFF

mov dx, 0xA1

out dx, al ; outb(0xA1, ~0x00)

;....

;other code etc

;....

;Our interrupt routine, which is called each
time we get an interrupt from the keyboard

intfunc:

pushad ; Push all the standard registers onto the stack

push es ; Push es register onto stack

;For each key pressed or released an interrupt (INT 09h) is issued by the

;keyboard controller. When the interrupt is issued we can read the value of

;the key pressed/released from the port 60h: if the 7th bit is set the key is

;released, else is pressed. So we can register multiple keys pressions and

;Whenever we finish an interrupt, we should tell our irq we've dealt with it

;or else it won't issue other interrupts.

;EOI for IRQ 0-7

mov al, 0x20

mov dx, 0x20

out dx, al ; outb(0x20, 0x20)

pop es

popad

iret

;...etc

Well here is the whole code, simple....but not....Its a whole piece of code,
which takes us into 32 bit protected mode, and sets up the basic things, like
Global Descriptor Table (GDT) and IDT etc and then we turn on the interrupt for
the Keyboard. Of course all the IDT (Interrupt Descriptor Table)
Interrupts are all set to a single interrupt, so all the interrupts will of
course call the same interrupt...(e.g. divide by zero etc). But we have
turned of all other interrupts and the code is really simple, so we know that
the only interrupt will be from key presses....and then when a key is pressed we
use the data that is passed to the interrupt to poke a character onto the
screen. Of course later on we'll see what that chacter is and desipher it
and use it to display the correct character.

What a whole piece of code looks like :)

Probably the most confusing part is the offsets and protected mode
code...which gets us there...the rest of the keyboard code, which I put
separately above isn't to bad to digest.