#include "keyboard.h"
#include "mytypes.h"

int MoveXDir(int ch)
{
  switch (ch) {
  case KEY_UPLEFT:
  case KEY_DOWNLEFT:
  case KEY_LEFT:
    return -1;
  case KEY_UPRIGHT:
  case KEY_RIGHT:
  case KEY_DOWNRIGHT:
    return 1;
  default:
    return 0;
  }
}

int MoveYDir(int ch)
{
  switch (ch) {
  case KEY_UPLEFT:
  case KEY_UP:
  case KEY_UPRIGHT:
    return -1;
  case KEY_DOWNLEFT:
  case KEY_DOWN:
  case KEY_DOWNRIGHT:
    return 1;
  default:
    return 0;
  }
}

int MovementKey(int key)
{
  return key >= 0x100 && key != NO_KEY;
}

int TranslateChar2MoveKey(char key)
{
  int ch;
  switch(key) {
  case '7':
    ch = KEY_UPLEFT; break;
  case '8':
    ch = KEY_UP; break;
  case '9':
    ch = KEY_UPRIGHT; break;
  case '4':
    ch = KEY_LEFT; break;
  case '6':
    ch = KEY_RIGHT; break;
  case '1':
    ch = KEY_DOWNLEFT; break;
  case '2':
    ch = KEY_DOWN; break;
  case '3':
    ch = KEY_DOWNRIGHT; break;
  default:
    ch = 0;
  }
  return ch;
}

int TranslateMoveKey(int keycode)
{
  int ch;

  switch (keycode) {
#ifdef PCNUMPAD
  case 79:
    ch = KEY_UPLEFT; break;
  case 80:
    ch = KEY_UP; break;
  case 81:
    ch = KEY_UPRIGHT; break;
  case 83:
    ch = KEY_LEFT; break;
  case 85:
    ch = KEY_RIGHT; break;
  case 87:
    ch = KEY_DOWNLEFT; break;
  case 88:
    ch = KEY_DOWN; break;
  case 89:
    ch = KEY_DOWNRIGHT; break;
#endif
#ifdef SUNKEY
  case 75:
    ch = KEY_UPLEFT; break;
  case 76:
    ch = KEY_UP; break;
  case 77:
    ch = KEY_UPRIGHT; break;
  case 98:
    ch = KEY_LEFT; break;
  case 100:
    ch = KEY_RIGHT; break;
  case 119:
    ch = KEY_DOWNLEFT; break;
  case 120:
    ch = KEY_DOWN; break;
  case 121:
    ch = KEY_DOWNRIGHT; break;
#else
  case 97:
  case 147:
    ch = KEY_UPLEFT; break;
  case 98:
  case 148:
    ch = KEY_UP; break;
  case 99:
  case 149:
    ch = KEY_UPRIGHT; break;
  case 100:
  case 150:
    ch = KEY_LEFT; break;
  case 102:
  case 152:
    ch = KEY_RIGHT; break;
  case 103:
  case 153:
    ch = KEY_DOWNLEFT; break;
  case 104:
  case 154:
    ch = KEY_DOWN; break;
  case 105:
  case 155:
    ch = KEY_DOWNRIGHT; break;
#endif
  default:
    ch = 0;
  }
  return ch;
}
