src/video/ataricommon/SDL_xbiosevents.c
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 2043 adf732f1f016
child 2859 99210400e8b9
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
slouken@305
     1
/*
slouken@305
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@305
     4
slouken@305
     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@305
     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@305
     9
slouken@305
    10
    This library is distributed in the hope that it will be useful,
slouken@305
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@305
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@305
    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@305
    18
slouken@305
    19
    Sam Lantinga
slouken@305
    20
    slouken@libsdl.org
slouken@305
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@305
    23
slouken@305
    24
/*
slouken@305
    25
 *	XBIOS mouse & joystick vectors
slouken@305
    26
 *
slouken@305
    27
 *	Patrice Mandin
slouken@305
    28
 */
slouken@305
    29
slouken@305
    30
#include <mint/osbind.h>
slouken@305
    31
slouken@1361
    32
#include "../../events/SDL_events_c.h"
slouken@305
    33
#include "SDL_xbiosevents_c.h"
slouken@305
    34
#include "SDL_xbiosinterrupt_s.h"
slouken@305
    35
slouken@305
    36
/* Variables */
slouken@305
    37
slouken@1895
    38
int SDL_AtariXbios_enabled = 0;
slouken@305
    39
patmandin@820
    40
/* Local variables */
patmandin@820
    41
slouken@1895
    42
static _KBDVECS *kbdvecs;       /* Pointer to access system vectors */
slouken@1895
    43
static Uint16 atari_prevmouseb; /* buttons */
slouken@305
    44
patmandin@820
    45
/* Functions */
patmandin@820
    46
slouken@1895
    47
void
slouken@1895
    48
SDL_AtariXbios_InstallVectors(int vectors_mask)
slouken@305
    49
{
slouken@1895
    50
    void *oldpile;
slouken@305
    51
slouken@1895
    52
    /* Clear variables */
patmandin@2023
    53
    SDL_AtariXbios_mouselock =
patmandin@2023
    54
        SDL_AtariXbios_mouseb =
slouken@1895
    55
        SDL_AtariXbios_mousex =
slouken@1895
    56
        SDL_AtariXbios_mousey =
slouken@1895
    57
        SDL_AtariXbios_joystick = atari_prevmouseb = 0;
slouken@305
    58
slouken@1895
    59
    if (vectors_mask == 0) {
slouken@1895
    60
        SDL_AtariXbios_enabled = 0;
slouken@1895
    61
        return;
slouken@1895
    62
    }
patmandin@1237
    63
slouken@1895
    64
    /* Read IKBD vectors base */
slouken@1895
    65
    kbdvecs = Kbdvbase();
slouken@305
    66
slouken@1895
    67
    /* Go to supervisor mode */
slouken@1895
    68
    oldpile = (void *) Super(0);
slouken@305
    69
slouken@1895
    70
    /* Install our vectors */
slouken@1895
    71
    SDL_AtariXbios_Install(kbdvecs,
slouken@1895
    72
                           (vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ?
slouken@1895
    73
                           SDL_AtariXbios_MouseVector : NULL,
slouken@1895
    74
                           (vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ?
slouken@1895
    75
                           SDL_AtariXbios_JoystickVector : NULL);
slouken@305
    76
slouken@1895
    77
    /* Back to user mode */
slouken@1895
    78
    Super(oldpile);
slouken@305
    79
slouken@1895
    80
    SDL_AtariXbios_enabled = 1;
slouken@305
    81
}
slouken@305
    82
slouken@1895
    83
void
slouken@1895
    84
SDL_AtariXbios_RestoreVectors(void)
slouken@305
    85
{
slouken@1895
    86
    void *oldpile;
slouken@305
    87
slouken@1895
    88
    if (SDL_AtariXbios_enabled == 0) {
slouken@1895
    89
        return;
slouken@1895
    90
    }
slouken@1895
    91
slouken@1895
    92
    /* Read IKBD vectors base */
slouken@1895
    93
    kbdvecs = Kbdvbase();
slouken@1895
    94
slouken@1895
    95
    /* Go to supervisor mode */
slouken@1895
    96
    oldpile = (void *) Super(NULL);
patmandin@1237
    97
slouken@1895
    98
    /* Reinstall system vector */
slouken@1895
    99
    SDL_AtariXbios_Restore(kbdvecs);
patmandin@820
   100
slouken@1895
   101
    /* Back to user mode */
slouken@1895
   102
    Super(oldpile);
slouken@1895
   103
}
slouken@305
   104
slouken@1895
   105
static int
slouken@1895
   106
atari_GetButton(int button)
slouken@1895
   107
{
slouken@1895
   108
    switch (button) {
slouken@1895
   109
    case 0:
slouken@1895
   110
        return SDL_BUTTON_RIGHT;
slouken@1895
   111
        break;
slouken@1895
   112
    case 1:
slouken@1895
   113
    default:
slouken@1895
   114
        return SDL_BUTTON_LEFT;
slouken@1895
   115
        break;
slouken@1895
   116
    }
slouken@305
   117
}
slouken@305
   118
slouken@1895
   119
void
slouken@1895
   120
SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
slouken@305
   121
{
slouken@1895
   122
    if (SDL_AtariXbios_enabled == 0) {
slouken@1895
   123
        return;
slouken@1895
   124
    }
slouken@1895
   125
slouken@1895
   126
    /* Mouse motion ? */
slouken@1895
   127
    if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
slouken@1895
   128
        SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex,
slouken@1895
   129
                               SDL_AtariXbios_mousey);
slouken@1895
   130
        SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
slouken@1895
   131
    }
slouken@1895
   132
slouken@1895
   133
    /* Mouse button ? */
slouken@1895
   134
    if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
slouken@1895
   135
        int i;
slouken@1895
   136
slouken@1895
   137
        for (i = 0; i < 2; i++) {
slouken@1895
   138
            int curbutton, prevbutton;
slouken@1895
   139
slouken@1895
   140
            curbutton = SDL_AtariXbios_mouseb & (1 << i);
slouken@1895
   141
            prevbutton = atari_prevmouseb & (1 << i);
slouken@1895
   142
slouken@1895
   143
            if (curbutton && !prevbutton) {
slouken@1895
   144
                SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
slouken@1895
   145
            }
slouken@1895
   146
            if (!curbutton && prevbutton) {
slouken@1895
   147
                SDL_PrivateMouseButton(SDL_RELEASED,
slouken@1895
   148
                                       atari_GetButton(i), 0, 0);
slouken@1895
   149
            }
slouken@1895
   150
        }
slouken@1895
   151
        atari_prevmouseb = SDL_AtariXbios_mouseb;
slouken@1895
   152
    }
slouken@305
   153
}
slouken@305
   154
slouken@2043
   155
void
slouken@2043
   156
SDL_AtariXbios_LockMousePosition(SDL_bool lockPosition)
patmandin@2023
   157
{
patmandin@2023
   158
    SDL_AtariXbios_mouselock = lockPosition;
patmandin@2023
   159
}
slouken@2043
   160
slouken@1895
   161
/* vi: set ts=4 sw=4 expandtab: */