Re: A89: What's wrong with _rowread???


[Prev][Next][Index][Thread]

Re: A89: What's wrong with _rowread???




Hello!
	First, the answer to your question:  Most likely this is caused by Auto-interrupt 1, which is reading the keyboard constantly during your program and can mess up _rowread.  To disable all interrupts temporarily, use OSSetSR(0x0700) at the beginning of the routine and OSSetSR(0x0000) at the end to re-enable them.  Note that most TIOS functions (DrawStr for example) enable interrupts again, so this is only temporary.  For a more permanent solution that also disables the alpha and diamond keyboard indicators, install your own dummy interrupt handler as documented in the TIGCC help files (make sure you have a new version of TIGCCLIB, because the new versions make it much easier to use interrupt handlers).  This will prevent this problem throughout your whole program (but will not allow you to use any TIOS keyboard functions, you must use _rowread for everything in this case).

	Second, a word on coding style:  That code fragment you put in your mail is awkward.  Although it might just be my E-mail program acting up, it looked as though that fragment of code wasn't indented at all.  You should ALWAYS indent your code.  It makes it SO much easier to read!  Also, I noticed you used a goto and label to make your loop.  Goto should be used very little in C, if at all (some people think goto should never ever be used, my opinion is that it should only be used to break out of nested loops).  A for or while loop would be much better.  Also, the many if statements there could be combined into one, for much smaller and faster code (speed isn't really an issue here, though).  Here is a better solution:

int keywait()
{
    int key = 0;
    OSSetSR(0x0700);       // disable those pesky interrupts
    while( !(key & 0xFF) ) // test all the bits of key at once!
        key = _rowread(0xFFFE);
    OSSetSR(0x0000);       // This way OSSetSR(0x0000) is always
                           // called - couldn't do that before
    return key;            // only need one return statement
}

key&0xFF isn't really necessary here, because it's just the same think as key.  However, you can replace 0xFF with something else to only test specific keys in the row.  You can test any specific combination of keys in a row this way.

I hope you find this helpful.  Good luck with whatever you're programming!

	James Darpinian




References: