e14743d1 |
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 SDL_AtariXbios_InstallVectors(int vectors_mask) |
48 | { |
49 | void *oldpile; |
50 | |
51 | /* Clear variables */ |
52 | SDL_AtariXbios_mouselock = |
53 | SDL_AtariXbios_mouseb = |
54 | SDL_AtariXbios_mousex = |
55 | SDL_AtariXbios_mousey = |
56 | SDL_AtariXbios_joystick = |
57 | 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( |
72 | kbdvecs, |
73 | (vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL, |
74 | (vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL |
75 | ); |
76 | |
77 | /* Back to user mode */ |
78 | Super(oldpile); |
79 | |
80 | SDL_AtariXbios_enabled=1; |
81 | } |
82 | |
83 | void SDL_AtariXbios_RestoreVectors(void) |
84 | { |
85 | void *oldpile; |
86 | |
87 | if (SDL_AtariXbios_enabled==0) { |
88 | return; |
89 | } |
90 | |
91 | /* Read IKBD vectors base */ |
92 | kbdvecs=Kbdvbase(); |
93 | |
94 | /* Go to supervisor mode */ |
95 | oldpile=(void *)Super(NULL); |
96 | |
97 | /* Reinstall system vector */ |
98 | SDL_AtariXbios_Restore(kbdvecs); |
99 | |
100 | /* Back to user mode */ |
101 | Super(oldpile); |
102 | } |
103 | |
104 | static int atari_GetButton(int button) |
105 | { |
106 | switch(button) |
107 | { |
108 | case 0: |
109 | return SDL_BUTTON_RIGHT; |
110 | break; |
111 | case 1: |
112 | default: |
113 | return SDL_BUTTON_LEFT; |
114 | break; |
115 | } |
116 | } |
117 | |
118 | void SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents) |
119 | { |
120 | if (SDL_AtariXbios_enabled==0) { |
121 | return; |
122 | } |
123 | |
124 | /* Mouse motion ? */ |
125 | if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) { |
126 | SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey); |
127 | SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0; |
128 | } |
129 | |
130 | /* Mouse button ? */ |
131 | if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) { |
132 | int i; |
133 | |
134 | for (i=0;i<2;i++) { |
135 | int curbutton, prevbutton; |
136 | |
137 | curbutton = SDL_AtariXbios_mouseb & (1<<i); |
138 | prevbutton = atari_prevmouseb & (1<<i); |
139 | |
140 | if (curbutton && !prevbutton) { |
141 | SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0); |
142 | } |
143 | if (!curbutton && prevbutton) { |
144 | SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0); |
145 | } |
146 | } |
147 | atari_prevmouseb = SDL_AtariXbios_mouseb; |
148 | } |
149 | } |
150 | |
151 | void SDL_AtariXbios_LockMousePosition(SDL_bool lockPosition) |
152 | { |
153 | SDL_AtariXbios_mouselock = lockPosition; |
154 | } |