Interruptions, keyboard handling and time routines.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ManOfSteel

Interruptions, keyboard handling and time routines.

Post by ManOfSteel »

Hello, I have three questions:
1- Do you have some tutorials (theory and practice) about interruptions, exeption handling and the IDT?
2- What do I have to do to convert a scan code to an ASCII character? I saw in many places that they pick up characters from a character table. How is that done?
3- I made a routine that endlessly reads hours, minutes and seconds from the CMOS, then print them all directly to VGA memory and restart from the beginning. How do you think it can be enhanced (reading the port once then increment the value by setting up a delay, maybe)?
Thanks in advance for any help.
ASHLEY4

Re:Interruptions, keyboard handling and time routines.

Post by ASHLEY4 »

This is how mine are done.

Code: Select all

;*****This is in the main start up before pmode*****

add   ebx,idt - gdt
mov   [idtr + 2],ebx

;****This at the end of start up in pmode***********

idtr:   dw idt_end - idt - 1                                   
dd idt

        include 'idt.asm'
************This is in the include******************
idt:

;0 interrupt 0h
   dw div_error      ; div error
   dw sys_code
   db 0
   db sys_interrupt
   dw 0

;1 interrupt 1h
   dw debug_exception   ; debug exception
   dw sys_code
   db 0
   db sys_interrupt
   dw 0

;2 interrupt 2h
   dw nmi_interrupt   ; non maskable interrupt
   dw sys_code
   db 0
   db sys_interrupt
   dw 0

; There is lots more of these 256

idt_end:

;*****This is where the point to********************
unhandled_int:
pushad
mov ax,8h
mov es,ax
mov byte [es:0xB809E], "U"
popad
iret

nmi_interrupt:
pushad
mov ax,8h
mov es,ax
mov byte [es:0xB809E], "N"

jmp reboot
popad
iret
clock_tick:
pushad
mov ax,8h
mov es,ax
mov byte [es:0xB809E], "C"
call irq_clear
popad
iret

keyboard_irq:
pushad
;mov ax,8h
;mov es,ax
;mov byte [es:0xB809C], "K"
call key_board
popad
iret

page_fault:
pushad
mov ax,8h
mov es,ax   
mov byte [es:0xB809C], "P"
popad
iret
;*************Lots more go here********************
irq_clear:
push eax
mov al, 0x20
out 0x20, al      ; quiet screaming irq chip.
pop eax
ret
;***************************************************

Also not include is my remapping the pic's function.
The scan code is just mapped into a aray eg:
keyboard map + scan code = ASCII

But then my keyboards just for put in top score ;)

ASHLEY4.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Interruptions, keyboard handling and time routines.

Post by Pype.Clicker »

ManOfSteel wrote: Hello, I have three questions:
1- Do you have some tutorials (theory and practice) about interruptions, exeption handling and the IDT?
There should be plenty of them on Bona Fide ... Follow the White Rabit (err. i mean the QuickLinkz ;)
2- What do I have to do to convert a scan code to an ASCII character? I saw in many places that they pick up characters from a character table. How is that done?
Basically, a lookup table is one of the easiest possible approach. Each scancode (or sequence of scancode) is associated with a single key which, depending on the active 'modifier' keys like Shift and ALT+GR will lead to one character (be it ascii, unicode or whatever).
Most implementations have a "character[]", a "shift_character[]" and an "alt_character[]" table and do [tt]ascii = character[modifier][scancode];[/tt] when time is right to convert the scancode ...
DennisCGc

Re:Interruptions, keyboard handling and time routines.

Post by DennisCGc »

ManOfSteel wrote: 3- I made a routine that endlessly reads hours, minutes and seconds from the CMOS, then print them all directly to VGA memory and restart from the beginning. How do you think it can be enhanced (reading the port once then increment the value by setting up a delay, maybe)?
Thanks in advance for any help.
Use a timer interrupt, see timer interrupt ;)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Interruptions, keyboard handling and time routines.

Post by Candy »

Try reprogramming the PIT to 100hz (round the hzes down!) or some sort of near-perfect multiple of 1hz, then use that timer to update the clock. Sync them every N seconds (and, for bonus points, write a UDP/IP stack and sync the cmos clock to an internet NTP server).

That gives you a reliable clock.

PS: round down to avoid duplication problems (ie: seconds happening twice because you have to set the clock back). That screws up timestamping.
Post Reply