flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Keyboard Polling?

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
I've noticed when I poll the Keyboard (via port 60h) and have my code setup in such a way that when I press a certain keu to will put a character on the screen (and thus move one byte over in video memory) it continues on with putting the same character on the screen until video memory's full or I press another key. Is there any way around that without setting up the IDT for it?
Post 30 Oct 2007, 04:35
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel
Quote:
and thus move one byte over in video memory

Actually it always moves two bytes (one for the character and one for the attribute).

Quote:
it continues on with putting the same character on the screen

You should add 2 to your video memory pointer (base = 0xb8000) everytime you press a key. That way you will be able to see all the characters you type. You can also move your video cursor using the VGA ports 0x3D4 and 0x3D5 everytime accordingly.

Quote:
Is there any way around that without setting up the IDT for it

The best way to do it is to set your IDT up, reprogram the PIC and enable at least IRQ line 1 (as keyboard). Everytime the user presses a key, IRQ1 fires up and then, you poll port 0x60 for the scancode and other data.

EDIT: by the way, what do you mean by the video memory being full?
Post 30 Oct 2007, 12:34
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Actually, I meant one WORD, not byte, I do add two naturally.

And what I mean by Video Memory being full, it repeats the same character on the screen multiple times until the screen is full with it.
Post 30 Oct 2007, 20:43
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
screen:
AAAAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAA


screen:
BBBBBBBBBBBBB
BBBBBBBBBBBBB
BBBBBBBBBBBBB
BBBBBBBBBBBBB


you need to add to your keyboard code....
it just keeps looping until the screen is full!
in al,60h
just loops and wont wait for a keypress...


Last edited by dosin on 05 Nov 2007, 07:21; edited 3 times in total
Post 31 Oct 2007, 06:13
View user's profile Send private message Reply with quote
Japheth



Joined: 26 Oct 2004
Posts: 151
Japheth
when polling the keyboard, before reading port 60h you should first check if "the input buffer is full", by reading port 64h and test if bit 0 is set.

Another issue with polling and reading port 60h is that a PS/2 mouse will also send its data to this port. True keyboard data will only be available if bit 5 of port 64h is 0.
Post 31 Oct 2007, 11:51
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Some simple code like this should work OK, untill you have your IRQ set up.
Code:
;*********************************
; Main keyboard loop.
;*********************************
NoKey:
        xor   eax,eax ; you need this here
        in    AL,60h
    
Post 31 Oct 2007, 12:35
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Code:
xor   eax,eax ; you need this here    

why does he need it there???
Post 31 Oct 2007, 13:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
Because this is cut from some code i did, which latter does this:
Code:
    mov   edi,eax    

and this:
Code:
   mov   al,[edi+normal_keymap]    

I was going to put the full code, but then i chopped most of it off.
Post 01 Nov 2007, 00:08
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden
Here is some code I wrote a while ago...
Code:
;-------------------------------------
; IBM8042 -   donated to public domain
; Created by: Hayden Mckay
;-------------------------------------
;-------------------------------------
align 4        ; send a command
ps8042ccmd:
    call near  ps8042waitr
    out  064h, al
    ret
;------------------------------
align 4       ;  send data port
ps8042send:
    call near  ps8042waitr
    out  060h, al
    ret
;------------------------------
align 4       ;  read data port
ps8042read:
    call near  ps8042waitd
    in   al,   060h
    ret
;-------------------------------------
;-------------------------------------
align 4
ps8042waitr:
    mov  ah, al         ; AL preserved
@@:
    in   al, 064h
    test al, 002h       ; ( bit-d1 )
    loopnz   @b
    xchg al, ah
    ret
align 4
ps8042waitd:
    mov  ah, al
@@:
    in   al, 064h
    test al, 001h       ; ( bit-d0 )
    loopz    @b
    xchg al, ah
    ret

; AH - holder for keyboard read status
;-------------------------------------
    


hope it might be usefull

_________________
New User.. Hayden McKay.
Post 01 Nov 2007, 05:46
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thank you all for the support!

PS... Hayden, maybe you should change your signature. You are no longer a new user, I'd say. Wink
Post 02 Nov 2007, 04:57
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
I dont no if you have it working or not but add this to your code to get the scan code:

Code:
WaitLoop:
in     al, 64h     ; Read Status byte 
and    al, 1b     ; test byte 1
jz     WaitLoop    ; Wait for IBF = 1 
         
in     al, 60h     ; Read input buffer 
jmp $+2

cmp al,0x..... ;key scan to comapre
etc...


    


This will wait for key_press!
works like getch() in C/C++
I have tested it and it works!
Post 04 Nov 2007, 20:17
View user's profile Send private message Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden
I think the scancode comes down to the type of keyboard nad keyboard controller. ie: there is scancode table for XT keyboards and a different table for AT boards, plus an alternative scancode table, so it is left up to the application to decide/test and configure useing the basic keyboard functions.

_________________
New User.. Hayden McKay.
Post 05 Nov 2007, 09:49
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
bios keyboard interrupt are bad
dos keyboard interrupt are shit

Code:
inc byte[eax+keymap]
jne @f
mov byte[eax+keymap],255
@@:
;;;;
;;;;
;;;;
mov al,[keymap+key.????]
;used to load the current keystatus
;if = 0 then key not pressed
;else , key pressed since timing
Wink
    


with this simple code i hope to incorporate timing into keystrokes

this will be usefull for various applications
Post 07 Nov 2007, 00:52
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.