[Coco] [Color Computer] Update: Inkey for Microware C...

Dave Kelly daveekelly at earthlink.net
Mon Dec 8 23:30:00 EST 2003


----- Original Message -----
From: "Mannequin*" <mannequin at primary.net>
To: "cocolist" <ColorComputer at yahoogroups.com>
Sent: Monday, December 08, 2003 9:50 PM
Subject: [Coco] [Color Computer] Update: Inkey for Microware C...


> Here is the code that Mike sent:
>
> 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);
> }
>
> I did see one thing that Mike pointed out in his comments. He needed to
> rearrange the arguments in the read function:
>
> read (0, &ch, 1);
>
> Anyway, I've implemented that code in to a small test file:
>
> /* myconio.c: Test of inkey () function. */
>
> #include <stdio.h>   /* For fflush () and other I/O functions.*/
> #include <sgstat.h>  /* For the getstat () function. */
>
> int inkey (void)     /* Yeah, I changed it from a char to int return. */
> {
>   char ch;
>
>   fflush (stdout);
>   if (getstat (1, 0))
>     return 0;
>   read (0, &ch, 1);
>   return ch;
> }
>
> int main (void)
> {
>   char ch = '\0';
>
>   while ((ch = inkey ()) != 35)   /* 35 = '#'; My fake-EOF character. */
>   {
>     if (ch != 0)                                           /* Or NULL */
>       printf ("ch = %c = %i\n", ch, ch);
>   }
>
>   return 0;
> }
>
> So, when I compile and run this, it always prints the character I typed
> in before it hits the printf () function. Here's an example:
>
> OS9: myconio
> fch = f = 102
> #
> OS9:
>
> So how do I go about defeating this?
Funny how things come around again. I remember this discussion from 15 years
ago.

You have to control all output to the screen if you want to skip seeing the
'#'.
IIRC its something like a 'tmode' to turn off echo. And I believe there is a
call in 'termcap' to turn off the cursor. Aha! Its cursor not echo.

Just a thought. You might immediately issue a destructive back space.
Dave




More information about the Coco mailing list