This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Newbie


On Sun, 22 Aug 1999, Joe Moore wrote:

> I hate to post absolute newbie topics on any list, but I can't figure
> out any of the commands that correspond to the dos-based interrupts.

Linux doesn't have precise equivalents to DOS int 21h services. It has
POSIX compatible system calls. So you are going to have to learn POSIX
programming. The gnu-libc mailing list isn't a good forum for this.

> Also, (since the obvious 'dos.h' and 'bios.h' headers do not exist for

I don't know where you get the idea that these headers are obvious.  They are
obvious to a MS-DOS programmer with a limited outlook on computing
(``All the world's a PC with a BIOS and DOS or an emulator thereof'').

> linux) what  headers contain the kbhit() and delay() functions from win*

Actually the NT/95/98 console function is called _kbhit() not kbhit().  And the
Win32 delay function is Sleep() whose argument is in milliseconds.

> c++, or what are the corresponding functions in linux?  Like I said,

There are no correponding functions in Linux because your keyboard is just
another device. So you use device generic functions like poll() to detect
input. To write successful tty applications (the rough equivalent to Windows
console applications) it's best to use the cursese library.  Failing that, you
have to deal with the intricacies of POSIX tty programming using the termios
interface. To get character-at-a-time input on a POSIX tty, you have to
negotiate the appropriate mode. Then to detect the presence of input without
removing it, you use poll() or select() on the tty file descriptor. Both these
functions are more complex to use than kbhit() because they do a lot more, and
are used for detecting input (and other conditions) on multiple file
descriptors simultaneously. 

Remember that a Linux tty program should work for the following users: a user
on the local console; a user coming in remotely via telnet, rlogin or ssh; a
user on a GUI terminal emulator such as xterm; a dial-up user coming in via a
modem or a user on a dedicated terminal. So I hope you can see that a function
like kbhit() is woefully inadequate, since only two of these scenarios involve
the directly-attached keyboard hardware.

To make a highly interactive program, such as a game, that can keep track of
keys that are being held down it's best to learn XWindow programming. X
provides detailed keyboard events with timestamps. There is no portable way of
doing this on a tty that will work in all of the above circumstances.

As far a delay() goes, that is a bad idea. The delay() function introduces a
CPU bound delay loop. This is only useful deep inside the operating system for
generating fine delays. A Linux application should use a scheduling delay
(sleep) which gives up the CPU. Look at the functions sleep(), and nanosleep().
Also, the aforementioned select() and poll() can also be used to perform small
scheduling delays.

> absolutely newbie.  If there are any documentation pages or indexes

You can't be that newbie if you actually remember DOS interrupts. :)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]