Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Crafty and single-computer winboard matches

Author: Robert Hyatt

Date: 05:30:43 10/08/99

Go up one level in this thread


On October 08, 1999 at 01:20:03, Ed Schröder wrote:

>On October 07, 1999 at 23:17:55, Christophe Theron wrote:
>
>>On October 07, 1999 at 22:08:38, Ratko V Tomic wrote:
>>
>>>> I have discovered on my K5 computer that calling the keyboard input
>>>> too often slows down the program considerably. Even in pure DOS
>>>> (the Windows scheduling algorithm has nothing to do with the problem).
>>>
>>>In DOS and Windows all kinds of code (BIOS, DOS, network drivers, schedulers,
>>>screen blankers and other TSRs) attach to the interrupt 0x16 (kbd interrupt),
>>>which makes the overhead erratic. The quickest way to check kbd for DOS
>>>programs, bypassing any such overhead in plain DOS or in DOS Box under
>>>Windows, is to check the keyboard buffer pointers, i.e. in C you can
>>>declare a pointer:
>>>
>>>   short far *kbd=0x41a;
>>>
>>>Then you can test for key present using a macro:
>>>
>>>   #define anykey()  (kbd[0]!=kbd[1])
>>>
>>>which evaluates true if (and only if) there is a key in the buffer. Even
>>>the 16-bit Windows programs can use this via predefined selectors which
>>>cover BIOS data area (imported value representing BIOS data selector
>>>is named __0040H). The overhead is minimal and predictable.
>>
>>
>>Yes, I know. But the problem is that I want to write portable code. Tiger is
>>completely written in C and I don't want to rely on knowledge about the system,
>>unless it is absolutely necessary.
>>
>>In this case, polling the keyboard with the standard kbhit() function, if done
>>with a long enough time interval, is harmless. So I favour this solution.
>>
>>
>>    Christophe
>
>I heard that kbhit() is a killer running NT. True?
>
>Ed


There are _two_ problems here.  The most important is that there is a
_different_ kbhit() function depending on whether you are running in dos,
or running in windows.  The windows version has to use the PeekNamedPipe()
function, while the dos version just checks the keyboard buffer pointer.

So you get to use the same function, but you have to be sure to use the right
library to get the right binary for the intended application.  And then there
is unix where everyone uses Select() which is more 'natural' to those of us
programming for many years...



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.