src/video/cybergfx/SDL_amigaevents.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 04:04:35 +0000
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
permissions -rw-r--r--
more tweaking indent options
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* Handle the event stream, converting Amiga events into SDL events */
slouken@0
    25
#include "SDL.h"
slouken@0
    26
slouken@0
    27
#include "SDL_syswm.h"
slouken@1361
    28
#include "../SDL_sysvideo.h"
slouken@1361
    29
#include "../../events/SDL_sysevents.h"
slouken@1361
    30
#include "../../events/SDL_events_c.h"
slouken@0
    31
#include "SDL_cgxvideo.h"
slouken@0
    32
#include "SDL_cgxmodes_c.h"
slouken@0
    33
#include "SDL_cgximage_c.h"
slouken@0
    34
#include "SDL_cgxwm_c.h"
slouken@0
    35
#include "SDL_amigaevents_c.h"
slouken@0
    36
slouken@0
    37
slouken@0
    38
/* The translation tables from an Amiga keysym to a SDL keysym */
slouken@0
    39
static SDLKey MISC_keymap[256];
slouken@1668
    40
SDL_keysym *amiga_TranslateKey(int code, SDL_keysym * keysym);
slouken@1662
    41
struct IOStdReq *ConReq = NULL;
slouken@1662
    42
struct MsgPort *ConPort = NULL;
slouken@0
    43
slouken@0
    44
/* Note:  The X server buffers and accumulates mouse motion events, so
slouken@0
    45
   the motion event generated by the warp may not appear exactly as we
slouken@0
    46
   expect it to.  We work around this (and improve performance) by only
slouken@0
    47
   warping the pointer when it reaches the edge, and then wait for it.
slouken@0
    48
*/
slouken@0
    49
#define MOUSE_FUDGE_FACTOR	8
slouken@0
    50
slouken@0
    51
#if 0
slouken@0
    52
slouken@1662
    53
static inline int
slouken@1668
    54
amiga_WarpedMotion(_THIS, struct IntuiMessage *m)
slouken@0
    55
{
slouken@1662
    56
    int w, h, i;
slouken@1662
    57
    int deltax, deltay;
slouken@1662
    58
    int posted;
slouken@0
    59
slouken@1662
    60
    w = SDL_VideoSurface->w;
slouken@1662
    61
    h = SDL_VideoSurface->h;
slouken@1662
    62
    deltax = xevent->xmotion.x - mouse_last.x;
slouken@1662
    63
    deltay = xevent->xmotion.y - mouse_last.y;
slouken@0
    64
#ifdef DEBUG_MOTION
slouken@1668
    65
    printf("Warped mouse motion: %d,%d\n", deltax, deltay);
slouken@0
    66
#endif
slouken@1662
    67
    mouse_last.x = xevent->xmotion.x;
slouken@1662
    68
    mouse_last.y = xevent->xmotion.y;
slouken@1668
    69
    posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
slouken@0
    70
slouken@1662
    71
    if ((xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
slouken@1662
    72
        (xevent->xmotion.x > (w - MOUSE_FUDGE_FACTOR)) ||
slouken@1662
    73
        (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
slouken@1662
    74
        (xevent->xmotion.y > (h - MOUSE_FUDGE_FACTOR))) {
slouken@1662
    75
        /* Get the events that have accumulated */
slouken@1668
    76
        while (XCheckTypedEvent(SDL_Display, MotionNotify, xevent)) {
slouken@1662
    77
            deltax = xevent->xmotion.x - mouse_last.x;
slouken@1662
    78
            deltay = xevent->xmotion.y - mouse_last.y;
slouken@0
    79
#ifdef DEBUG_MOTION
slouken@1668
    80
            printf("Extra mouse motion: %d,%d\n", deltax, deltay);
slouken@0
    81
#endif
slouken@1662
    82
            mouse_last.x = xevent->xmotion.x;
slouken@1662
    83
            mouse_last.y = xevent->xmotion.y;
slouken@1668
    84
            posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
slouken@1662
    85
        }
slouken@1662
    86
        mouse_last.x = w / 2;
slouken@1662
    87
        mouse_last.y = h / 2;
slouken@1668
    88
        XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
slouken@1668
    89
                     mouse_last.x, mouse_last.y);
slouken@1662
    90
        for (i = 0; i < 10; ++i) {
slouken@1668
    91
            XMaskEvent(SDL_Display, PointerMotionMask, xevent);
slouken@1662
    92
            if ((xevent->xmotion.x >
slouken@1662
    93
                 (mouse_last.x - MOUSE_FUDGE_FACTOR)) &&
slouken@1662
    94
                (xevent->xmotion.x <
slouken@1662
    95
                 (mouse_last.x + MOUSE_FUDGE_FACTOR)) &&
slouken@1662
    96
                (xevent->xmotion.y >
slouken@1662
    97
                 (mouse_last.y - MOUSE_FUDGE_FACTOR)) &&
slouken@1662
    98
                (xevent->xmotion.y < (mouse_last.y + MOUSE_FUDGE_FACTOR))) {
slouken@1662
    99
                break;
slouken@1662
   100
            }
slouken@0
   101
#ifdef DEBUG_XEVENTS
slouken@1668
   102
            printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x,
slouken@1668
   103
                   xevent->xmotion.y);
slouken@0
   104
#endif
slouken@1662
   105
        }
slouken@0
   106
#ifdef DEBUG_XEVENTS
slouken@1662
   107
        if (i == 10) {
slouken@1668
   108
            printf("Warning: didn't detect mouse warp motion\n");
slouken@1662
   109
        }
slouken@0
   110
#endif
slouken@1662
   111
    }
slouken@1662
   112
    return (posted);
slouken@0
   113
}
slouken@0
   114
slouken@0
   115
#endif
slouken@0
   116
slouken@1662
   117
static int
slouken@1668
   118
amiga_GetButton(int code)
slouken@0
   119
{
slouken@1662
   120
    switch (code) {
slouken@1662
   121
    case IECODE_MBUTTON:
slouken@1662
   122
        return SDL_BUTTON_MIDDLE;
slouken@1662
   123
    case IECODE_RBUTTON:
slouken@1662
   124
        return SDL_BUTTON_RIGHT;
slouken@1662
   125
    default:
slouken@1662
   126
        return SDL_BUTTON_LEFT;
slouken@1662
   127
    }
slouken@0
   128
}
slouken@0
   129
slouken@1662
   130
static int
slouken@1668
   131
amiga_DispatchEvent(_THIS, struct IntuiMessage *msg)
slouken@0
   132
{
slouken@1662
   133
    int class = msg->Class, code = msg->Code;
slouken@1662
   134
    int posted;
slouken@0
   135
slouken@1662
   136
    posted = 0;
slouken@1662
   137
    switch (class) {
slouken@1662
   138
        /* Gaining mouse coverage? */
slouken@1662
   139
    case IDCMP_ACTIVEWINDOW:
slouken@1668
   140
        posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
slouken@1662
   141
        break;
slouken@0
   142
slouken@1662
   143
        /* Losing mouse coverage? */
slouken@1662
   144
    case IDCMP_INACTIVEWINDOW:
slouken@1668
   145
        posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
slouken@1662
   146
        break;
slouken@0
   147
#if 0
slouken@1662
   148
        /* Gaining input focus? */
slouken@1662
   149
    case IDCMP_ACTIVEWINDOW:
slouken@1668
   150
        posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
slouken@0
   151
slouken@1662
   152
        /* Queue entry into fullscreen mode */
slouken@1662
   153
        switch_waiting = 0x01 | SDL_FULLSCREEN;
slouken@1668
   154
        switch_time = SDL_GetTicks() + 1500;
slouken@1662
   155
        break;
slouken@0
   156
slouken@1662
   157
        /* Losing input focus? */
slouken@1662
   158
    case IDCMP_INACTIVEWINDOW:
slouken@1668
   159
        posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
slouken@0
   160
slouken@1662
   161
        /* Queue leaving fullscreen mode */
slouken@1662
   162
        switch_waiting = 0x01;
slouken@1668
   163
        switch_time = SDL_GetTicks() + 200;
slouken@1662
   164
        break;
slouken@0
   165
#endif
slouken@1662
   166
        /* Mouse motion? */
slouken@1662
   167
    case IDCMP_MOUSEMOVE:
slouken@1662
   168
        if (SDL_VideoSurface) {
slouken@1668
   169
            posted = SDL_PrivateMouseMotion(0, 0,
slouken@1668
   170
                                            msg->MouseX -
slouken@1668
   171
                                            SDL_Window->BorderLeft,
slouken@1668
   172
                                            msg->MouseY -
slouken@1668
   173
                                            SDL_Window->BorderTop);
slouken@1662
   174
        }
slouken@1662
   175
        break;
slouken@0
   176
slouken@1662
   177
        /* Mouse button press? */
slouken@1662
   178
    case IDCMP_MOUSEBUTTONS:
slouken@0
   179
slouken@1662
   180
        if (!(code & IECODE_UP_PREFIX)) {
slouken@1668
   181
            posted = SDL_PrivateMouseButton(SDL_PRESSED,
slouken@1668
   182
                                            amiga_GetButton(code), 0, 0);
slouken@1662
   183
        }
slouken@1662
   184
        /* Mouse button release? */
slouken@1662
   185
        else {
slouken@1662
   186
            code &= ~IECODE_UP_PREFIX;
slouken@1668
   187
            posted = SDL_PrivateMouseButton(SDL_RELEASED,
slouken@1668
   188
                                            amiga_GetButton(code), 0, 0);
slouken@1662
   189
        }
slouken@1662
   190
        break;
slouken@0
   191
slouken@1662
   192
    case IDCMP_RAWKEY:
slouken@0
   193
slouken@1662
   194
        /* Key press? */
slouken@0
   195
slouken@1662
   196
        if (!(code & IECODE_UP_PREFIX)) {
slouken@1662
   197
            SDL_keysym keysym;
slouken@1668
   198
            posted = SDL_PrivateKeyboard(SDL_PRESSED,
slouken@1668
   199
                                         amiga_TranslateKey(code, &keysym));
slouken@1662
   200
        } else {
slouken@1662
   201
            /* Key release? */
slouken@0
   202
slouken@1662
   203
            SDL_keysym keysym;
slouken@1662
   204
            code &= ~IECODE_UP_PREFIX;
slouken@0
   205
slouken@1662
   206
            /* Check to see if this is a repeated key */
slouken@0
   207
/*			if ( ! X11_KeyRepeat(SDL_Display, &xevent) )  */
slouken@0
   208
slouken@1668
   209
            posted = SDL_PrivateKeyboard(SDL_RELEASED,
slouken@1668
   210
                                         amiga_TranslateKey(code, &keysym));
slouken@1662
   211
        }
slouken@1662
   212
        break;
slouken@1662
   213
        /* Have we been iconified? */
slouken@0
   214
#if 0
slouken@1662
   215
    case UnmapNotify:
slouken@1662
   216
        {
slouken@0
   217
#ifdef DEBUG_XEVENTS
slouken@1668
   218
            printf("UnmapNotify!\n");
slouken@0
   219
#endif
slouken@1662
   220
            posted =
slouken@1668
   221
                SDL_PrivateAppActive(0, SDL_APPACTIVE | SDL_APPINPUTFOCUS);
slouken@1662
   222
        }
slouken@1662
   223
        break;
slouken@0
   224
slouken@1662
   225
        /* Have we been restored? */
slouken@0
   226
slouken@1662
   227
    case MapNotify:
slouken@1662
   228
        {
slouken@0
   229
#ifdef DEBUG_XEVENTS
slouken@1668
   230
            printf("MapNotify!\n");
slouken@0
   231
#endif
slouken@0
   232
slouken@1668
   233
            posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);
slouken@0
   234
slouken@1662
   235
            if (SDL_VideoSurface &&
slouken@1662
   236
                (SDL_VideoSurface->flags & SDL_FULLSCREEN)) {
slouken@1668
   237
                CGX_EnterFullScreen(this);
slouken@1662
   238
            } else {
slouken@1668
   239
                X11_GrabInputNoLock(this, this->input_grab);
slouken@1662
   240
            }
slouken@1662
   241
            if (SDL_VideoSurface) {
slouken@1668
   242
                CGX_RefreshDisplay(this);
slouken@1662
   243
            }
slouken@1662
   244
        }
slouken@1662
   245
        break;
slouken@1662
   246
    case Expose:
slouken@1662
   247
        if (SDL_VideoSurface && (xevent.xexpose.count == 0)) {
slouken@1668
   248
            CGX_RefreshDisplay(this);
slouken@1662
   249
        }
slouken@1662
   250
        break;
slouken@0
   251
#endif
slouken@0
   252
slouken@1662
   253
        /* Have we been resized? */
slouken@1662
   254
    case IDCMP_NEWSIZE:
slouken@1668
   255
        SDL_PrivateResize(SDL_Window->Width - SDL_Window->BorderLeft -
slouken@1668
   256
                          SDL_Window->BorderRight,
slouken@1668
   257
                          SDL_Window->Height - SDL_Window->BorderTop -
slouken@1668
   258
                          SDL_Window->BorderBottom);
slouken@255
   259
slouken@1662
   260
        break;
slouken@0
   261
slouken@1662
   262
        /* Have we been requested to quit? */
slouken@1662
   263
    case IDCMP_CLOSEWINDOW:
slouken@1668
   264
        posted = SDL_PrivateQuit();
slouken@1662
   265
        break;
slouken@0
   266
slouken@1662
   267
        /* Do we need to refresh ourselves? */
slouken@0
   268
slouken@1662
   269
    default:
slouken@1662
   270
        {
slouken@1662
   271
            /* Only post the event if we're watching for it */
slouken@1662
   272
            if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
slouken@1662
   273
                SDL_SysWMmsg wmmsg;
slouken@0
   274
slouken@1668
   275
                SDL_VERSION(&wmmsg.version);
slouken@0
   276
#if 0
slouken@1662
   277
                wmmsg.subsystem = SDL_SYSWM_CGX;
slouken@1662
   278
                wmmsg.event.xevent = xevent;
slouken@0
   279
#endif
slouken@1668
   280
                posted = SDL_PrivateSysWMEvent(&wmmsg);
slouken@1662
   281
            }
slouken@1662
   282
        }
slouken@1662
   283
        break;
slouken@1662
   284
    }
slouken@1668
   285
    ReplyMsg((struct Message *) msg);
slouken@0
   286
slouken@0
   287
slouken@1662
   288
    return (posted);
slouken@0
   289
}
slouken@0
   290
slouken@1662
   291
void
slouken@1668
   292
amiga_PumpEvents(_THIS)
slouken@0
   293
{
slouken@1662
   294
    int pending;
slouken@1662
   295
    struct IntuiMessage *m;
slouken@0
   296
slouken@1662
   297
    /* Keep processing pending events */
slouken@1662
   298
    pending = 0;
slouken@1668
   299
    while (m = (struct IntuiMessage *) GetMsg(SDL_Window->UserPort)) {
slouken@1668
   300
        amiga_DispatchEvent(this, m);
slouken@1662
   301
        ++pending;
slouken@1662
   302
    }
slouken@0
   303
}
slouken@0
   304
slouken@1662
   305
void
slouken@1668
   306
amiga_InitKeymap(void)
slouken@0
   307
{
slouken@1662
   308
    int i;
slouken@0
   309
slouken@1662
   310
    /* Map the miscellaneous keys */
slouken@1668
   311
    for (i = 0; i < SDL_arraysize(MISC_keymap); ++i)
slouken@1662
   312
        MISC_keymap[i] = SDLK_UNKNOWN;
slouken@0
   313
slouken@1662
   314
    /* These X keysyms have 0xFF as the high byte */
slouken@1662
   315
    MISC_keymap[65] = SDLK_BACKSPACE;
slouken@1662
   316
    MISC_keymap[66] = SDLK_TAB;
slouken@1662
   317
    MISC_keymap[70] = SDLK_CLEAR;
slouken@1662
   318
    MISC_keymap[70] = SDLK_DELETE;
slouken@1662
   319
    MISC_keymap[68] = SDLK_RETURN;
slouken@1662
   320
//      MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE;
slouken@1662
   321
    MISC_keymap[69] = SDLK_ESCAPE;
slouken@1662
   322
    MISC_keymap[70] = SDLK_DELETE;
slouken@0
   323
/*
slouken@0
   324
	SDLK_SPACE		= 32,
slouken@0
   325
	SDLK_MINUS		= 45,
slouken@0
   326
	SDLK_LESS		= 60,
slouken@0
   327
	SDLK_COMMA		= 44,
slouken@0
   328
	SDLK_PERIOD		= 46,
slouken@0
   329
	SDLK_0			= 48,
slouken@0
   330
	SDLK_1			= 49,
slouken@0
   331
	SDLK_2			= 50,
slouken@0
   332
	SDLK_3			= 51,
slouken@0
   333
	SDLK_4			= 52,
slouken@0
   334
	SDLK_5			= 53,
slouken@0
   335
	SDLK_6			= 54,
slouken@0
   336
	SDLK_7			= 55,
slouken@0
   337
	SDLK_8			= 56,
slouken@0
   338
	SDLK_9			= 57,
slouken@0
   339
	SDLK_BACKQUOTE		= 96,
slouken@0
   340
	SDLK_BACKSLASH		= 92,
slouken@0
   341
	SDLK_a			= 97,
slouken@0
   342
	SDLK_b			= 98,
slouken@0
   343
	SDLK_c			= 99,
slouken@0
   344
	SDLK_d			= 100,
slouken@0
   345
	SDLK_e			= 101,
slouken@0
   346
	SDLK_f			= 102,
slouken@0
   347
	SDLK_g			= 103,
slouken@0
   348
	SDLK_h			= 104,
slouken@0
   349
	SDLK_i			= 105,
slouken@0
   350
	SDLK_j			= 106,
slouken@0
   351
	SDLK_k			= 107,
slouken@0
   352
	SDLK_l			= 108,
slouken@0
   353
	SDLK_m			= 109,
slouken@0
   354
	SDLK_n			= 110,
slouken@0
   355
	SDLK_o			= 111,
slouken@0
   356
	SDLK_p			= 112,
slouken@0
   357
	SDLK_q			= 113,
slouken@0
   358
	SDLK_r			= 114,
slouken@0
   359
	SDLK_s			= 115,
slouken@0
   360
	SDLK_t			= 116,
slouken@0
   361
	SDLK_u			= 117,
slouken@0
   362
	SDLK_v			= 118,
slouken@0
   363
	SDLK_w			= 119,
slouken@0
   364
	SDLK_x			= 120,
slouken@0
   365
	SDLK_y			= 121,
slouken@0
   366
	SDLK_z			= 122,
slouken@0
   367
*/
slouken@1662
   368
    MISC_keymap[15] = SDLK_KP0; /* Keypad 0-9 */
slouken@1662
   369
    MISC_keymap[29] = SDLK_KP1;
slouken@1662
   370
    MISC_keymap[30] = SDLK_KP2;
slouken@1662
   371
    MISC_keymap[31] = SDLK_KP3;
slouken@1662
   372
    MISC_keymap[45] = SDLK_KP4;
slouken@1662
   373
    MISC_keymap[46] = SDLK_KP5;
slouken@1662
   374
    MISC_keymap[47] = SDLK_KP6;
slouken@1662
   375
    MISC_keymap[61] = SDLK_KP7;
slouken@1662
   376
    MISC_keymap[62] = SDLK_KP8;
slouken@1662
   377
    MISC_keymap[63] = SDLK_KP9;
slouken@1662
   378
    MISC_keymap[60] = SDLK_KP_PERIOD;
slouken@1662
   379
    MISC_keymap[92] = SDLK_KP_DIVIDE;
slouken@1662
   380
    MISC_keymap[93] = SDLK_KP_MULTIPLY;
slouken@1662
   381
    MISC_keymap[74] = SDLK_KP_MINUS;
slouken@1662
   382
    MISC_keymap[94] = SDLK_KP_PLUS;
slouken@1662
   383
    MISC_keymap[67] = SDLK_KP_ENTER;
slouken@1662
   384
//      MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS;
slouken@0
   385
slouken@1662
   386
    MISC_keymap[76] = SDLK_UP;
slouken@1662
   387
    MISC_keymap[77] = SDLK_DOWN;
slouken@1662
   388
    MISC_keymap[78] = SDLK_RIGHT;
slouken@1662
   389
    MISC_keymap[79] = SDLK_LEFT;
slouken@0
   390
/*
slouken@0
   391
	MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT;
slouken@0
   392
	MISC_keymap[XK_Home&0xFF] = SDLK_HOME;
slouken@0
   393
	MISC_keymap[XK_End&0xFF] = SDLK_END;
slouken@0
   394
*/
slouken@0
   395
// Mappati sulle parentesi del taastierino
slouken@1662
   396
    MISC_keymap[90] = SDLK_PAGEUP;
slouken@1662
   397
    MISC_keymap[91] = SDLK_PAGEDOWN;
slouken@0
   398
slouken@1662
   399
    MISC_keymap[80] = SDLK_F1;
slouken@1662
   400
    MISC_keymap[81] = SDLK_F2;
slouken@1662
   401
    MISC_keymap[82] = SDLK_F3;
slouken@1662
   402
    MISC_keymap[83] = SDLK_F4;
slouken@1662
   403
    MISC_keymap[84] = SDLK_F5;
slouken@1662
   404
    MISC_keymap[85] = SDLK_F6;
slouken@1662
   405
    MISC_keymap[86] = SDLK_F7;
slouken@1662
   406
    MISC_keymap[87] = SDLK_F8;
slouken@1662
   407
    MISC_keymap[88] = SDLK_F9;
slouken@1662
   408
    MISC_keymap[89] = SDLK_F10;
slouken@1662
   409
//      MISC_keymap[XK_F11&0xFF] = SDLK_F11;
slouken@1662
   410
//      MISC_keymap[XK_F12&0xFF] = SDLK_F12;
slouken@1662
   411
//      MISC_keymap[XK_F13&0xFF] = SDLK_F13;
slouken@1662
   412
//      MISC_keymap[XK_F14&0xFF] = SDLK_F14;
slouken@1662
   413
//      MISC_keymap[XK_F15&0xFF] = SDLK_F15;
slouken@0
   414
slouken@1662
   415
//      MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK;
slouken@1662
   416
    MISC_keymap[98] = SDLK_CAPSLOCK;
slouken@1662
   417
//      MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
slouken@1662
   418
    MISC_keymap[97] = SDLK_RSHIFT;
slouken@1662
   419
    MISC_keymap[96] = SDLK_LSHIFT;
slouken@1662
   420
    MISC_keymap[99] = SDLK_LCTRL;
slouken@1662
   421
    MISC_keymap[99] = SDLK_LCTRL;
slouken@1662
   422
    MISC_keymap[101] = SDLK_RALT;
slouken@1662
   423
    MISC_keymap[100] = SDLK_LALT;
slouken@1662
   424
//      MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA;
slouken@1662
   425
//      MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA;
slouken@1662
   426
    MISC_keymap[103] = SDLK_LSUPER;     /* Left "Windows" */
slouken@1662
   427
    MISC_keymap[102] = SDLK_RSUPER;     /* Right "Windows */
slouken@0
   428
slouken@1662
   429
    MISC_keymap[95] = SDLK_HELP;
slouken@0
   430
}
slouken@0
   431
slouken@1662
   432
SDL_keysym *
slouken@1668
   433
amiga_TranslateKey(int code, SDL_keysym * keysym)
slouken@0
   434
{
slouken@1662
   435
#ifdef STORMC4_WOS
slouken@1662
   436
    static struct Library *KeymapBase = NULL;   /* Linking failed in WOS version if ConsoleDevice was used */
slouken@1662
   437
#else
slouken@1662
   438
    static struct Library *ConsoleDevice = NULL;
slouken@1662
   439
#endif
slouken@0
   440
slouken@1662
   441
    /* Get the raw keyboard scancode */
slouken@1662
   442
    keysym->scancode = code;
slouken@1662
   443
    keysym->sym = MISC_keymap[code];
slouken@0
   444
slouken@0
   445
#ifdef DEBUG_KEYS
slouken@1668
   446
    fprintf(stderr, "Translating key 0x%.4x (%d)\n", xsym, xkey->keycode);
slouken@0
   447
#endif
slouken@1662
   448
    /* Get the translated SDL virtual keysym */
slouken@1662
   449
    if (keysym->sym == SDLK_UNKNOWN) {
slouken@1662
   450
#ifdef STORMC4_WOS
slouken@1662
   451
        if (!KeymapBase)
slouken@1662
   452
#else
slouken@1662
   453
        if (!ConsoleDevice)
slouken@1662
   454
#endif
slouken@1662
   455
        {
slouken@1662
   456
#ifdef STORMC4_WOS
slouken@1668
   457
            KeymapBase = OpenLibrary("keymap.library", 0L);
slouken@1662
   458
#else
slouken@1668
   459
            if (ConPort = CreateMsgPort()) {
slouken@1662
   460
                if (ConReq =
slouken@1668
   461
                    CreateIORequest(ConPort, sizeof(struct IOStdReq))) {
slouken@1662
   462
                    if (!OpenDevice
slouken@1662
   463
                        ("console.device", -1,
slouken@1662
   464
                         (struct IORequest *) ConReq, 0))
slouken@1662
   465
                        ConsoleDevice = (struct Library *) ConReq->io_Device;
slouken@1662
   466
                    else {
slouken@1668
   467
                        DeleteIORequest(ConReq);
slouken@1662
   468
                        ConReq = NULL;
slouken@1662
   469
                    }
slouken@1662
   470
                } else {
slouken@1668
   471
                    DeleteMsgPort(ConPort);
slouken@1662
   472
                    ConPort = NULL;
slouken@1662
   473
                }
slouken@1662
   474
            }
slouken@1662
   475
#endif
slouken@1662
   476
        }
slouken@1662
   477
#ifdef STORMC4_WOS
slouken@1662
   478
        if (KeymapBase)
slouken@1662
   479
#else
slouken@1662
   480
        if (ConsoleDevice)
slouken@1662
   481
#endif
slouken@1662
   482
        {
slouken@1662
   483
            struct InputEvent event;
slouken@1662
   484
            long actual;
slouken@1662
   485
            char buffer[5];
slouken@0
   486
slouken@1662
   487
            event.ie_Qualifier = 0;
slouken@1662
   488
            event.ie_Class = IECLASS_RAWKEY;
slouken@1662
   489
            event.ie_SubClass = 0L;
slouken@1662
   490
            event.ie_Code = code;
slouken@1662
   491
            event.ie_X = event.ie_Y = 0;
slouken@1662
   492
            event.ie_EventAddress = NULL;
slouken@1662
   493
            event.ie_NextEvent = NULL;
slouken@1662
   494
            event.ie_Prev1DownCode = event.ie_Prev1DownQual =
slouken@1662
   495
                event.ie_Prev2DownCode = event.ie_Prev2DownQual = 0;
slouken@0
   496
slouken@1662
   497
#ifdef STORMC4_WOS
slouken@1668
   498
            if ((actual = MapRawKey(&event, buffer, 5, NULL)) >= 0)
slouken@1662
   499
#else
slouken@1668
   500
            if ((actual = RawKeyConvert(&event, buffer, 5, NULL)) >= 0)
slouken@1662
   501
#endif
slouken@1662
   502
            {
slouken@1662
   503
                if (actual > 1) {
slouken@1668
   504
                    D(bug("Warning (%ld) character conversion!\n", actual));
slouken@1662
   505
                } else if (actual == 1) {
slouken@1662
   506
                    keysym->sym = *buffer;
slouken@1668
   507
                    D(bug("Converted rawcode %ld to <%lc>\n", code, *buffer));
slouken@1662
   508
// Bufferizzo x le successive chiamate!
slouken@1662
   509
                    MISC_keymap[code] = *buffer;
slouken@1662
   510
                }
slouken@1662
   511
            }
slouken@1662
   512
        }
slouken@0
   513
slouken@1662
   514
    }
slouken@1662
   515
    keysym->mod = KMOD_NONE;
slouken@0
   516
slouken@1662
   517
    /* If UNICODE is on, get the UNICODE value for the key */
slouken@1662
   518
    keysym->unicode = 0;
slouken@1662
   519
    if (SDL_TranslateUNICODE) {
slouken@0
   520
#if 0
slouken@1662
   521
        static XComposeStatus state;
slouken@1662
   522
        /* Until we handle the IM protocol, use XLookupString() */
slouken@1662
   523
        unsigned char keybuf[32];
slouken@1668
   524
        if (XLookupString(xkey, (char *) keybuf, sizeof(keybuf),
slouken@1668
   525
                          NULL, &state)) {
slouken@1662
   526
            keysym->unicode = keybuf[0];
slouken@1662
   527
        }
slouken@0
   528
#endif
slouken@1662
   529
    }
slouken@1662
   530
    return (keysym);
slouken@0
   531
}
slouken@0
   532
slouken@1662
   533
void
slouken@1668
   534
amiga_InitOSKeymap(_THIS)
slouken@0
   535
{
slouken@1668
   536
    amiga_InitKeymap();
slouken@0
   537
}
slouken@1662
   538
slouken@1662
   539
/* vi: set ts=4 sw=4 expandtab: */