protected void ReadCommand()
{
key = null;
bool gotKey = false;
// Until a key is found
while (!gotKey) {
// Read the first Char
char b0 = GetCard8();
// decode according to the type1/type2 format
if (b0 == 28) // the two next bytes represent a short int;
{
int first = GetCard8();
int second = GetCard8();
args[arg_count] = first<<8 | second;
arg_count++;
continue;
}
if (b0 >= 32 && b0 <= 246) // The byte read is the byte;
{
args[arg_count] = (int)b0 - 139;
arg_count++;
continue;
}
if (b0 >= 247 && b0 <= 250) // The byte read and the next byte constetute a short int
{
int w = GetCard8();
args[arg_count] = ((int)b0-247)*256 + w + 108;
arg_count++;
continue;
}
if (b0 >= 251 && b0 <= 254)// Same as above except negative
{
int w = GetCard8();
args[arg_count] = -((int)b0-251)*256 - w - 108;
arg_count++;
continue;
}
if (b0 == 255)// The next for bytes represent a double.
{
int first = GetCard8();
int second = GetCard8();
int third = GetCard8();
int fourth = GetCard8();
args[arg_count] = first<<24 | second<<16 | third<<8 | fourth;
arg_count++;
continue;
}
if (b0<=31 && b0 != 28) // An operator was found.. Set Key.
{
gotKey=true;
// 12 is an escape command therefor the next byte is a part
// of this command
if (b0 == 12)
{
int b1 = GetCard8();
if (b1>SubrsEscapeFuncs.Length-1)
b1 = SubrsEscapeFuncs.Length-1;
key = SubrsEscapeFuncs[b1];
}
else
key = SubrsFunctions[b0];
continue;
}
}
}