src/video/ataricommon/SDL_biosevents.c
changeset 2030 d774e9d7c2a8
parent 2019 d20f4510c718
child 2031 f54073d86c82
equal deleted inserted replaced
2029:8640d90b0406 2030:d774e9d7c2a8
    37 #include "SDL_atarikeys.h"
    37 #include "SDL_atarikeys.h"
    38 #include "SDL_atarievents_c.h"
    38 #include "SDL_atarievents_c.h"
    39 #include "SDL_xbiosevents_c.h"
    39 #include "SDL_xbiosevents_c.h"
    40 #include "SDL_ataridevmouse_c.h"
    40 #include "SDL_ataridevmouse_c.h"
    41 
    41 
    42 /* To save state of keyboard */
       
    43 #define ATARIBIOS_MAXKEYS 128
       
    44 
       
    45 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
    42 static unsigned char bios_currentkeyboard[ATARIBIOS_MAXKEYS];
    46 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
    43 static unsigned char bios_previouskeyboard[ATARIBIOS_MAXKEYS];
    47 static unsigned char bios_currentascii[ATARIBIOS_MAXKEYS];
       
    48 static SDL_bool use_dev_mouse = SDL_FALSE;
    44 static SDL_bool use_dev_mouse = SDL_FALSE;
    49 
    45 
    50 /* Special keys state */
       
    51 enum
       
    52 {
       
    53     K_RSHIFT = 0,
       
    54     K_LSHIFT,
       
    55     K_CTRL,
       
    56     K_ALT,
       
    57     K_CAPSLOCK,
       
    58     K_CLRHOME,
       
    59     K_INSERT
       
    60 };
       
    61 
       
    62 /* The translation tables from a console scancode to a SDL keysym */
       
    63 static SDLKey keymap[ATARIBIOS_MAXKEYS];
       
    64 
       
    65 static SDL_keysym *TranslateKey(int scancode, int asciicode,
       
    66                                 SDL_keysym * keysym, SDL_bool pressed);
       
    67 static void UpdateSpecialKeys(int special_keys_state);
    46 static void UpdateSpecialKeys(int special_keys_state);
    68 
    47 
    69 void
    48 void
    70 AtariBios_InitOSKeymap(_THIS)
    49 AtariBios_InitOSKeymap(_THIS)
    71 {
    50 {
    72     int i, vectors_mask;
    51     int i, vectors_mask;
    73     unsigned long dummy;
    52     unsigned long dummy;
    74 
    53 
    75     SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
    54     SDL_memset(bios_currentkeyboard, 0, sizeof(bios_currentkeyboard));
    76     SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
    55     SDL_memset(bios_previouskeyboard, 0, sizeof(bios_previouskeyboard));
    77 
       
    78     /* Initialize keymap */
       
    79     for (i = 0; i < ATARIBIOS_MAXKEYS; i++)
       
    80         keymap[i] = SDLK_UNKNOWN;
       
    81 
       
    82     /* Functions keys */
       
    83     for (i = 0; i < 10; i++)
       
    84         keymap[SCANCODE_F1 + i] = SDLK_F1 + i;
       
    85 
       
    86     /* Cursor keypad */
       
    87     keymap[SCANCODE_HELP] = SDLK_HELP;
       
    88     keymap[SCANCODE_UNDO] = SDLK_UNDO;
       
    89     keymap[SCANCODE_INSERT] = SDLK_INSERT;
       
    90     keymap[SCANCODE_CLRHOME] = SDLK_HOME;
       
    91     keymap[SCANCODE_UP] = SDLK_UP;
       
    92     keymap[SCANCODE_DOWN] = SDLK_DOWN;
       
    93     keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
       
    94     keymap[SCANCODE_LEFT] = SDLK_LEFT;
       
    95 
       
    96     /* Special keys */
       
    97     keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
       
    98     keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
       
    99     keymap[SCANCODE_TAB] = SDLK_TAB;
       
   100     keymap[SCANCODE_ENTER] = SDLK_RETURN;
       
   101     keymap[SCANCODE_DELETE] = SDLK_DELETE;
       
   102     keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
       
   103     keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
       
   104     keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
       
   105     keymap[SCANCODE_LEFTALT] = SDLK_LALT;
       
   106     keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
       
   107 
    56 
   108     use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
    57     use_dev_mouse = (SDL_AtariDevMouse_Open() != 0) ? SDL_TRUE : SDL_FALSE;
   109 
    58 
   110     vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
    59     vectors_mask = ATARI_XBIOS_JOYSTICKEVENTS;  /* XBIOS joystick events */
   111     if (!use_dev_mouse) {
    60     if (!use_dev_mouse) {
   127     /* Update pressed keys */
    76     /* Update pressed keys */
   128     SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
    77     SDL_memset(bios_currentkeyboard, 0, ATARIBIOS_MAXKEYS);
   129 
    78 
   130     while (Bconstat(_CON)) {
    79     while (Bconstat(_CON)) {
   131         unsigned long key_pressed;
    80         unsigned long key_pressed;
   132         unsigned char asciicode, scancode;
    81         key_pressed=Bconin(_CON);
   133 
    82         bios_currentkeyboard[(key_pressed>>16)&(ATARIBIOS_MAXKEYS-1)]=0xFF;
   134         key_pressed = Bconin(_CON);
       
   135 
       
   136         asciicode = key_pressed;
       
   137         scancode = key_pressed >> 16;
       
   138 
       
   139         bios_currentkeyboard[scancode] = 0xFF;
       
   140         bios_currentascii[scancode] = asciicode;
       
   141     }
    83     }
   142 
    84 
   143     /* Read special keys */
    85     /* Read special keys */
   144     UpdateSpecialKeys(Kbshift(-1));
    86     UpdateSpecialKeys(Kbshift(-1));
   145 
    87 
   146     /* Now generate events */
    88     /* Now generate events */
   147     for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
    89     for (i = 0; i < ATARIBIOS_MAXKEYS; i++) {
   148         /* Key pressed ? */
    90         /* Key pressed ? */
   149         if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
    91         if (bios_currentkeyboard[i] && !bios_previouskeyboard[i])
   150             SDL_PrivateKeyboard(SDL_PRESSED,
    92             SDL_PrivateKeyboard(SDL_PRESSED,
   151                                 TranslateKey(i, bios_currentascii[i],
    93                                 SDL_Atari_TranslateKey(i, &keysym, SDL_TRUE));
   152                                              &keysym, SDL_TRUE));
       
   153 
    94 
   154         /* Key unpressed ? */
    95         /* Key unpressed ? */
   155         if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
    96         if (bios_previouskeyboard[i] && !bios_currentkeyboard[i])
   156             SDL_PrivateKeyboard(SDL_RELEASED,
    97             SDL_PrivateKeyboard(SDL_RELEASED,
   157                                 TranslateKey(i, bios_currentascii[i],
    98                                 SDL_Atari_TranslateKey(i, &keysym, SDL_FALSE));
   158                                              &keysym, SDL_FALSE));
       
   159     }
    99     }
   160 
   100 
   161     if (use_dev_mouse) {
   101     if (use_dev_mouse) {
   162         SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
   102         SDL_AtariDevMouse_PostMouseEvents(this, SDL_TRUE);
   163     } else {
   103     } else {
   164         SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
   104         SDL_AtariXbios_PostMouseEvents(this, SDL_TRUE);
   165     }
   105     }
   166 
   106 
   167     /* Will be previous table */
   107     /* Will be previous table */
   168     SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard,
   108     SDL_memcpy(bios_previouskeyboard, bios_currentkeyboard,
   169                ATARIBIOS_MAXKEYS);
   109                sizeof(bios_previouskeyboard));
   170 }
   110 }
   171 
   111 
   172 static void
   112 static void
   173 UpdateSpecialKeys(int special_keys_state)
   113 UpdateSpecialKeys(int special_keys_state)
   174 {
   114 {
   185     UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
   125     UPDATE_SPECIAL_KEYS(K_CTRL, SCANCODE_LEFTCONTROL);
   186     UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
   126     UPDATE_SPECIAL_KEYS(K_ALT, SCANCODE_LEFTALT);
   187     UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   127     UPDATE_SPECIAL_KEYS(K_CAPSLOCK, SCANCODE_CAPSLOCK);
   188 }
   128 }
   189 
   129 
   190 static SDL_keysym *
       
   191 TranslateKey(int scancode, int asciicode, SDL_keysym * keysym,
       
   192              SDL_bool pressed)
       
   193 {
       
   194     /* Set the keysym information */
       
   195     keysym->scancode = scancode;
       
   196 
       
   197     if (asciicode)
       
   198         keysym->sym = asciicode;
       
   199     else
       
   200         keysym->sym = keymap[scancode];
       
   201 
       
   202     keysym->mod = KMOD_NONE;
       
   203     keysym->unicode = 0;
       
   204     if (SDL_TranslateUNICODE && pressed) {
       
   205         keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
       
   206     }
       
   207 
       
   208     return (keysym);
       
   209 }
       
   210 
       
   211 void
   130 void
   212 AtariBios_ShutdownEvents(void)
   131 AtariBios_ShutdownEvents(void)
   213 {
   132 {
   214     SDL_AtariXbios_RestoreVectors();
   133     SDL_AtariXbios_RestoreVectors();
   215     if (use_dev_mouse) {
   134     if (use_dev_mouse) {