Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How do i Flash the keyboard buffer

Please Help me with this little problem?

I want to have a loop that checks keyboard entries

with the int 16,1 call. But i can't seem to get it

working becouse the int 16,1 doesn't update the

keyboard buffer.

So therefore i need to be able to flash the buffer,

or find another way to do it,

PS. The INT 16,0 call is not an acceptable altenative

becouse of that i want to do other things while scanning keyboard entries!!!


Comments



  • you're right that using int 16/function 0

    *instead* of function 1 is not a good thing. but

    using it in _addition_ to func 1 should solve

    your problem. basically, do the following:


    1) call int 16h / function 1

    2) if the zero flag is 1, no key is currently

    available -- so go ahead and do the "other things"

    (i.e. not checking keypresses) in your loop.

    3) if the zero flag is 0, a key is currently

    available. get the key's value, then call

    int 16h / ah=0 to clear the buffer. note:

    this won't cause any infinite waits because you're

    only calling function 0 when you KNOW there is

    already a key in the buffer.


    lemme know if you have any more questions on this..

    i have simple code that shows how to call int 16,0

    right after int 16,1.


    assassin@reality.halo.nu




    : Please Help me with this little problem?

    : I want to have a loop that checks keyboard entries

    : with the int 16,1 call. But i can't seem to get it

    : working becouse the int 16,1 doesn't update the

    : keyboard buffer.

    : So therefore i need to be able to flash the buffer,

    : or find another way to do it,

    : PS. The INT 16,0 call is not an acceptable altenative

    : becouse of that i want to do other things while scanning keyboard entries!!!








  • This will clear the kbd buffer:

    while (kbhit()) getch();



    Or look up the location of kbd buffer in DOS memory maps....(0040:001A i think ?)



    Bikram


  • Yep, that's the simplest way of doing it.

    mov ax, 1

    int 16h

    xor ax, ax

    int 16h



    Will get you the key.



    Since they answered it so well, all I can do is add completeness to it.



    The other way would be to patch the IRQ or int 16h. That would cause your handler to be called anytime a key was pressed.



    This is useful so you can maintain your own buffer, and avoid losing keys in longer sections of code. (BIOS maintains a buffer as well.)



    One area where this would be necessary would be, for example, in a game. Let's assume you have some code like this:



    readkey

    move player 1 space

    move enemy 1 space towards player

    loop



    Now with this setup you would never be able to outrun the enemy. Everytime you moved one or less the computer would move one. Now if you patch the interrupt, the player can move at anytime, allowing the player to be able to outrun the enemy.

    Buffering doesn't help in this case because it will still read only one key from the buffer at a time.


Sign In or Register to comment.