src/video/ataricommon/SDL_xbiosevents.c
changeset 3283 1ed5d432e468
parent 3282 10a12f77f597
child 3284 2b95b2c0b6d4
equal deleted inserted replaced
3282:10a12f77f597 3283:1ed5d432e468
     1 /*
       
     2     SDL - Simple DirectMedia Layer
       
     3     Copyright (C) 1997-2009 Sam Lantinga
       
     4 
       
     5     This library is free software; you can redistribute it and/or
       
     6     modify it under the terms of the GNU Lesser General Public
       
     7     License as published by the Free Software Foundation; either
       
     8     version 2.1 of the License, or (at your option) any later version.
       
     9 
       
    10     This library is distributed in the hope that it will be useful,
       
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13     Lesser General Public License for more details.
       
    14 
       
    15     You should have received a copy of the GNU Lesser General Public
       
    16     License along with this library; if not, write to the Free Software
       
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    18 
       
    19     Sam Lantinga
       
    20     slouken@libsdl.org
       
    21 */
       
    22 #include "SDL_config.h"
       
    23 
       
    24 /*
       
    25  *	XBIOS mouse & joystick vectors
       
    26  *
       
    27  *	Patrice Mandin
       
    28  */
       
    29 
       
    30 #include <mint/osbind.h>
       
    31 
       
    32 #include "../../events/SDL_events_c.h"
       
    33 #include "SDL_xbiosevents_c.h"
       
    34 #include "SDL_xbiosinterrupt_s.h"
       
    35 
       
    36 /* Variables */
       
    37 
       
    38 int SDL_AtariXbios_enabled = 0;
       
    39 
       
    40 /* Local variables */
       
    41 
       
    42 static _KBDVECS *kbdvecs;       /* Pointer to access system vectors */
       
    43 static Uint16 atari_prevmouseb; /* buttons */
       
    44 
       
    45 /* Functions */
       
    46 
       
    47 void
       
    48 SDL_AtariXbios_InstallVectors(int vectors_mask)
       
    49 {
       
    50     void *oldpile;
       
    51 
       
    52     /* Clear variables */
       
    53     SDL_AtariXbios_mouselock =
       
    54         SDL_AtariXbios_mouseb =
       
    55         SDL_AtariXbios_mousex =
       
    56         SDL_AtariXbios_mousey =
       
    57         SDL_AtariXbios_joystick = atari_prevmouseb = 0;
       
    58 
       
    59     if (vectors_mask == 0) {
       
    60         SDL_AtariXbios_enabled = 0;
       
    61         return;
       
    62     }
       
    63 
       
    64     /* Read IKBD vectors base */
       
    65     kbdvecs = Kbdvbase();
       
    66 
       
    67     /* Go to supervisor mode */
       
    68     oldpile = (void *) Super(0);
       
    69 
       
    70     /* Install our vectors */
       
    71     SDL_AtariXbios_Install(kbdvecs,
       
    72                            (vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ?
       
    73                            SDL_AtariXbios_MouseVector : NULL,
       
    74                            (vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ?
       
    75                            SDL_AtariXbios_JoystickVector : NULL);
       
    76 
       
    77     /* Back to user mode */
       
    78     Super(oldpile);
       
    79 
       
    80     SDL_AtariXbios_enabled = 1;
       
    81 }
       
    82 
       
    83 void
       
    84 SDL_AtariXbios_RestoreVectors(void)
       
    85 {
       
    86     void *oldpile;
       
    87 
       
    88     if (SDL_AtariXbios_enabled == 0) {
       
    89         return;
       
    90     }
       
    91 
       
    92     /* Read IKBD vectors base */
       
    93     kbdvecs = Kbdvbase();
       
    94 
       
    95     /* Go to supervisor mode */
       
    96     oldpile = (void *) Super(NULL);
       
    97 
       
    98     /* Reinstall system vector */
       
    99     SDL_AtariXbios_Restore(kbdvecs);
       
   100 
       
   101     /* Back to user mode */
       
   102     Super(oldpile);
       
   103 }
       
   104 
       
   105 static int
       
   106 atari_GetButton(int button)
       
   107 {
       
   108     switch (button) {
       
   109     case 0:
       
   110         return SDL_BUTTON_RIGHT;
       
   111         break;
       
   112     case 1:
       
   113     default:
       
   114         return SDL_BUTTON_LEFT;
       
   115         break;
       
   116     }
       
   117 }
       
   118 
       
   119 void
       
   120 SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
       
   121 {
       
   122     if (SDL_AtariXbios_enabled == 0) {
       
   123         return;
       
   124     }
       
   125 
       
   126     /* Mouse motion ? */
       
   127     if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
       
   128         SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex,
       
   129                                SDL_AtariXbios_mousey);
       
   130         SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
       
   131     }
       
   132 
       
   133     /* Mouse button ? */
       
   134     if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
       
   135         int i;
       
   136 
       
   137         for (i = 0; i < 2; i++) {
       
   138             int curbutton, prevbutton;
       
   139 
       
   140             curbutton = SDL_AtariXbios_mouseb & (1 << i);
       
   141             prevbutton = atari_prevmouseb & (1 << i);
       
   142 
       
   143             if (curbutton && !prevbutton) {
       
   144                 SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
       
   145             }
       
   146             if (!curbutton && prevbutton) {
       
   147                 SDL_PrivateMouseButton(SDL_RELEASED,
       
   148                                        atari_GetButton(i), 0, 0);
       
   149             }
       
   150         }
       
   151         atari_prevmouseb = SDL_AtariXbios_mouseb;
       
   152     }
       
   153 }
       
   154 
       
   155 void
       
   156 SDL_AtariXbios_LockMousePosition(SDL_bool lockPosition)
       
   157 {
       
   158     SDL_AtariXbios_mouselock = lockPosition;
       
   159 }
       
   160 
       
   161 /* vi: set ts=4 sw=4 expandtab: */