News Downloads Projects Documents/tutorials Staff

JE-SYSTEMS

_Rowread  


Don't know how the _rowread function works? Read on, and you'll soon be using _rowread for all of your programs.

Why use _rowread
It's very simply, why you should use _rowread function. It's fast. In fact it's very fast compared to the other functions for reading keyboard inputs (even if you can get ngetchx() pretty fast with OSInitKeyDelay and OSInitBetweenKeyDelay). There's another thing that makes _rowread superior. You can read more than one key at a time, for example if you want something to happen if the user press 2nd + Left Key at the same time.

How to read a key with _rowread
The _rowread function is alittle harder to grip. If we look at '_rowread' in the TIGCC documentation, you will get this keyboard matrix picture:
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
Bit 0 alpha diamnd shift 2nd right down left up
Bit 1 F5 Clear ^ / * - + enter
... ... ... ... ... ... ... ... ...

Okay, if we want to read the 'right' key, we do that with this line:
int right_key=0;
right_key=(_rowread(~((short)(1 << 0))) & (1 << 3))


right_key will be true, if we press the right key. Now, did you got that? Hehe, okay, let's clear this line out. We can basicly say that we first tells what Row to read, and then what column to read. In this case, we read row 0 (that's the (1 << 0)) and then column 3 (1 << 3). It's actualy this simple:
_rowread(~((short)(1 << 'WHAT_ROW'))) & (1 << 'WHAT_COLUMN')

If we look at that keyboard matrix, we can now add the bit number instead of 'WHAT_ROW' and 'WHAT_COLUMN'. We can also just read a row if we want that. A common line is problably the one when you first read the arrows row, and then checks what arrow is pressed (if any) This could look like this:
// Main Function
void _main(void)
{
    int arrow_row=0;
    clrscr();

    while (!(arrow_row & (1 << 3))
    {
        arrow_row = _rowread(~((short)(1 << 0)));
        //Do something here when Arrow right isn't pressed
    }
}


As you can see, _rowread is quite easy to use, and is a powerful and fast way to read keyboard inputs. If you play around with _rowread, you will soon encounter problems with it sooner or later. This because some interupts will interfer with the _rowread command (for example the calc might 'think' your pushing a buttun while you're not). Read on, how to fix this problem

Give _rowread the environment it needs
The Auto_ints 1 and 5 interupts with the _rowread command. So, we have to dissable those interupts. Something that could be good to know is that when we have dissabled those interupts, ngetchx() (and some other stuff) will not work! (On the other hand, _rowread is working perfect, and if you're using our 'sounddriver' you'll get better sound). Add this below the defination of variables in your _main function:
INT_HANDLER save_int_1 = GetIntVec(AUTO_INT_1); // Saves AUTO_INT_1 to 'variable' save_int_1
INT_HANDLER save_int_5 = GetIntVec(AUTO_INT_5); // Same as above but for int5
SetIntVec(AUTO_INT_1, DUMMY_HANDLER); // Dissable autoint 1
SetIntVec(AUTO_INT_5, DUMMY_HANDLER); // Dissable autoint 5

If you're using Gray mode, be sure to have these lines above the initialazion of graymode (above GrayOn(); that is). Now, at the buttom of your _main function, we need to set back the auto_ints, or else your calc will crash pretty soon :). This time, be sure to go below the GrayOff(); function (if you're using gray mode) and add this lines:
SetIntVec(AUTO_INT_1, save_int_1);
SetIntVec(AUTO_INT_5, save_int_5);

That will set back the Auto_int's to normal. I really hope this have cleared out the questions about _rowread, or else, drop me a mail at jon80@home.se
Created to be compatible with Microsoft Internet Explorer at 800x600.
Site designed by Jon Eriksson © JE-Systems, 2002