Subject: device.c
From: Todd Gamblin <[email-masked]>
To: Prasun Dewan <[email-masked]>
Date: Tue, 13 Apr 2004 01:58:54 -0400

Hi Prof. Dewan,

I just realized that I hadn't mailed you my modified device.c as you 
asked.  I cleaned it up so it would compile under C++ w/g++ without 
warnings, and i made a proper header file to go along with it.  The C++ 
is not so different from ANSI C that it wouldn't take only a few 
changes to make it compile under gcc.  I've attached the modified 
files.

The modifications I made to it were as follows:

-commented out else in display device loop (line 154)
The main loop DisplayDevice looks like it was intended to check for new 
characters only when bDoReadDisplay is set.  The value is set to true 
in the call to EnableDisplayDevice(), and is never set to false.  This 
results in the loop polling the os for characters after the first call 
to EnableDisplayDevice() rather than fetching them only when 
EnableDisplayDevice() is called.  It seems to me that the latter is 
closer to the desired behavior.  The way it works now, it was polling 
too fast on my machine, so I commented out the else before the sleep(1) 
at the end of the loop.  This way it polls fairly infrequently and it 
will wake up and fetch a character when it receives a signal from an 
EnableDisplayDevice() call.

- changed sleep(1) to usleep(10) at line 184.  This was done to make 
the keyboard device sample stdin faster.  As it was written before it 
only read a character per second.  Now it samples every 10 us.

I also deleted some duplicate #defines and unused code.

The DisplayDevice function seems like it could stand to be changed 
more, but I was trying not to hack your device.c file too much, for 
fear of not doing the assignment correctly.

-Todd