Page 1 of 1

wait for keypress?

Posted: Thu Oct 17, 2002 5:59 pm
by gtsphere
does anyone have code for a function that will wait for a keypress?? thx! ;D

Re:wait for keypress?

Posted: Thu Oct 17, 2002 7:16 pm
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;
}
}

Re:wait for keypress?

Posted: Thu Oct 17, 2002 7:18 pm
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;
}
}

Re:wait for keypress?

Posted: Thu Oct 17, 2002 7:37 pm
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!

Re:wait for keypress?

Posted: Fri Oct 18, 2002 10:34 am
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.

Re:wait for keypress?

Posted: Fri Oct 18, 2002 10:51 am
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.