It seems in the posted code that getkey( &key ) is telling getkey to read the key value from some i/o port named key. Is that the intent? Or, is the programmer trying to tell getkey() where to put the key value received from getkey()?
I would say the latter. I assume that when GetKey is called, it waits for a key to be pressed and the returns the keycode to whatever address was passed.
This is the declaration of GetKey from fxlib:
int GetKey(unsigned int *keycode);
When called, whatever key is presssed, its keycode is put into the address of what you passed so take the following example:
unsigned short key;
while (1)
{
GetKey(&key); //Whatever key is pressed, its keycode is put where the variable address points to, which is key in this example
if (key == KEY_CHAR_1) //if key is equal to the keycode of number 1 button, so if (key == 0x31) is also correct
break;
//else repeat, be aware that GetKey pauses the entire function and waits for a key to be pressed
}
unsigned int key;
key = getkey(); //getkey() gets its input from STDIN and puts the character code in variable key
I don't have any books with me at the moment, but I am fairly confident that you are still passing key's address to GetKey.
EDIT:
But looking at the code, it would traditionally run an error, because the parameter are not being met for the GetKey.
Looking at documentation, I am unsure of how your example works, because it would only return 1 (if the key pressed was a numeric key) or a 0 (if the key was a control key)
I've never used it in the way you describe, and I don't have a windows computer currently with me to test.
I suppose you could do it this way, it is not the same as you mentioned. Maybe the compiler is optimizing it in a way that I have not read (and who wants to read a 600 page instruction manual on SuperH compiler?)
#include "fxlib.h"
#include "stdio.h"
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key, c;
unsigned char string[20];
Bdisp_AllClr_DDVRAM();
c = GetKey(&key);
sprintf(&string, "%x", key);
switch (c)
{
case 1:
PrintXY(0,0,"Key is numeric",0);
PrintXY(0,10,string,0);
break;
case 0:
PrintXY(0,0,"Key is numeric",0);
PrintXY(0,10,string,0);
break;
}
while(1)
GetKey(&key);
return 1;
}
Edited by GodOfCows, 05 September 2018 - 12:37 AM.