wait for keypress?

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
gtsphere

wait for keypress?

Post by gtsphere »

does anyone have code for a function that will wait for a keypress?? thx! ;D
Tom

Re:wait for keypress?

Post by Tom »

Hello, ( this is me Tom, just forgot to login )

here is what you want:

void waitch()
{
int key;
while ( 1 )
{
// wait for key
while ((in(0x64) & 1) == 0)
;

key = inportb( 0x60 ); // same as inb- use yours
if ( key != 0 )
return;

else if ( key == 0 )
continue;
}
}
Tom

Re:wait for keypress?

Post by Tom »

opps, here is the correct code ( see, it's me i'm loged in )
void waitch()
{
int key;
while ( 1 )
{
// wait for key
while ((in(0x64) & 1) == 0)
;

key = inportb( 0x60 ); // same as inb- use yours
if ( key & 0x80 ) continue;
if ( key != 0 )
return;

else if ( key == 0 )
continue;
}
}
gtsphere

Re:wait for keypress?

Post by gtsphere »

oh my god thank you so much! lol that completely helped me SOOO much. My problem was that while i was trying output each character that the user typed, it would output it once, but then before it got a change to "check" for another key, it printed it again, never had a chance to wait! i owe you one! thank you Tom!

i got a question though, what is the different between those inb outb or inp outp, i read that it differs (not function name wise obviously, but how it interacts with the ports, like BYTES, WORDS, etc) i have seen inp(b) and inw ?

thank you so much!
Tom

Re:wait for keypress?

Post by Tom »

Ok... inb ( or inportb, or outb ) is for sending or getting bytes.

inportb gets a byte from the selected port.
outportb sends a byte to the selected port.

inportw gets a word from the selected port.
outportw sends a word to the selected port.

I'm not sure, but I think ...portw has to parse stuff to send words, like sending one byte at a time.
Tim

Re:wait for keypress?

Post by Tim »

Port I/O is like memory I/O but for ports :).

For example, outportb sends a byte value to one 8-bit port, just as writing a single byte to memory writes to one 8-bit memory location. outportw sends a word value to two adjacent 8-bit locations, which are combined into one 16-bit location. outportd does the same but for 32 bits.

Note that specific types of hardware generally expect their ports to be accessed as bytes, words or doublewords. Using the wrong type (e.g. outportb to a 16-bit port) might not work.
Post Reply