[Coco] [Color Computer] Inkey for Microware C Compiler

KnudsenMJ at aol.com KnudsenMJ at aol.com
Mon Dec 8 19:06:00 EST 2003


In a message dated 12/7/03 10:58:28 PM Eastern Standard Time, 
dbree at duo-county.com writes:

> If you have the Level 2 Development system (I believe it's from there),
>  you also have the _gs_rdy() function that returns the status of whether
>  a character is available.

Turns out there's a getstat(fcn, channel) in the C library that I'd been 
using on the Coco3.  It returns an antique legacy style value:  -1 if no 
characters are waiting in the buffer, 0 if there are some.

So my code, from memory but pretty solid, is:

char inkey() {
    char ch;

    fflush(stdout);     /* needed if you're using bufrered I/O anywhere in 
the prog */
    if( getstat(1, 0))      /* 2nd arg must be the I/O channel (0==stdin) */
        return(0);
    read(0, 1, &ch);        /* caution-- check argument order here */
    return(ch);
}

>  > BTW, the existence of the stat call in step (1) is a major superiority 
of 
>  > OS-9 over UNIX or Linux in this regard, where a paragraph of garbage
>  > code is required to do a non-blocking read.  That's probably why the
>  > standard C I/O lib lacks such a call.
>  
>  I guess there are ways around all this in unix/linux.  Remember some
>  time ago when you(?) and I were complaining about the lack of the
>  capability of a single-key input in linux?  Someone pointed out a very
>  simple solution to the problem.  I've thought about writing a library
>  inkey() function for linux, but haven't done so yet.

I recall only a messy solution with several lines of ioctl() that had to be 
done and undone before each call to read a char.  Though I guess once you've 
writtena nd debugged that code and it works, it's "simple" to keep on using it 
:-)

If you know how to add your own functions to the library, you're pretty 
advanced.  I used to know in theory how to do it for OS-9.  --Mike K.



More information about the Coco mailing list