-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathmsvgab.c
226 lines (184 loc) · 5.05 KB
/
msvgab.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* This file is part of the Advance project.
*
* Copyright (C) 2001, 2002, 2003 Andrea Mazzoleni
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* In addition, as a special exception, Andrea Mazzoleni
* gives permission to link the code of this program with
* the MAME library (or with modified versions of MAME that use the
* same license as MAME), and distribute linked combinations including
* the two. You must obey the GNU General Public License in all
* respects for all of the code used other than MAME. If you modify
* this file, you may extend this exception to your version of the
* file, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*/
#include "portable.h"
#include "msvgab.h"
#include "log.h"
#include "oslinux.h"
#include "error.h"
#include <vgamouse.h>
#define BUTTON_MAX 16
struct mouseb_svgalib_context {
int x;
int y;
int button_mask;
unsigned button_mac;
unsigned button_map[BUTTON_MAX];
};
static struct mouseb_svgalib_context svgalib_state;
static adv_device DEVICE[] = {
{ "auto", -1, "SVGALIB mouse" },
{ 0, 0, 0 }
};
adv_error mouseb_svgalib_init(int mouseb_id)
{
struct MouseCaps mouse_caps;
unsigned i;
unsigned buttons[] = {
MOUSE_LEFTBUTTON,
MOUSE_RIGHTBUTTON,
MOUSE_MIDDLEBUTTON,
MOUSE_FOURTHBUTTON,
MOUSE_FIFTHBUTTON,
MOUSE_SIXTHBUTTON,
MOUSE_RESETBUTTON,
0
};
log_std(("mouseb:svgalib: mouseb_svgalib_init(id:%d)\n", mouseb_id));
if (target_wm()) {
error_set("Unsupported in X.\n");
return -1;
}
if (!os_internal_svgalib_get()) {
error_set("Not supported without the svgalib library.\n");
return -1;
}
/* already opened internally by svgalib */
if (mouse_getcaps(&mouse_caps) != 0) {
error_set("No mouse found.\n");
return -1;
}
mouse_setxrange(-8191, 8191);
mouse_setyrange(-8191, 8191);
mouse_setscale(1);
mouse_setwrap(MOUSE_NOWRAP);
svgalib_state.button_mac = 0;
for (i = 0; buttons[i] && i < BUTTON_MAX; ++i) {
if ((mouse_caps.buttons & buttons[i]) != 0) {
svgalib_state.button_map[svgalib_state.button_mac] = buttons[i];
++svgalib_state.button_mac;
}
}
svgalib_state.x = 0;
svgalib_state.y = 0;
svgalib_state.button_mask = 0;
return 0;
}
void mouseb_svgalib_done(void)
{
log_std(("mouseb:svgalib: mouseb_svgalib_done()\n"));
}
unsigned mouseb_svgalib_count_get(void)
{
log_debug(("mouseb:svgalib: mouseb_svgalib_count_get()\n"));
return 1;
}
unsigned mouseb_svgalib_axe_count_get(unsigned mouse)
{
log_debug(("mouseb:svgalib: mouseb_svgalib_axe_count_get()\n"));
return 2;
}
unsigned mouseb_svgalib_button_count_get(unsigned mouse)
{
log_debug(("mouseb:svgalib: mouseb_svgalib_button_count_get()\n"));
return svgalib_state.button_mac;
}
int mouseb_svgalib_axe_get(unsigned mouse, unsigned axe)
{
int r;
log_debug(("mouseb:svgalib: mouseb_svgalib_pos_get()\n"));
switch (axe) {
case 0:
r = svgalib_state.x;
svgalib_state.x = 0;
break;
case 1:
r = svgalib_state.y;
svgalib_state.y = 0;
break;
default:
r = 0;
break;
}
return r;
}
unsigned mouseb_svgalib_button_get(unsigned mouse, unsigned button)
{
log_debug(("mouseb:svgalib: mouseb_svgalib_button_get()\n"));
return (svgalib_state.button_mask & svgalib_state.button_map[button]) != 0;
}
int mouseb_svgalib_poll(void)
{
log_debug(("mouseb:svgalib: mouseb_svgalib_poll()\n"));
/* update the position */
mouse_update();
/* get the new position */
svgalib_state.x += mouse_getx();
svgalib_state.y += mouse_gety();
svgalib_state.button_mask = mouse_getbutton();
/* clear the current position */
mouse_setposition(0, 0);
/* the range must be reset on a video mode change */
mouse_setxrange(-8191, 8191);
mouse_setyrange(-8191, 8191);
log_debug(("mouseb:svgalib: mouseb_svgalib_poll() -> %d,%d,%d\n", svgalib_state.x, svgalib_state.y, svgalib_state.button_mask));
return 0;
}
unsigned mouseb_svgalib_flags(void)
{
return 0;
}
adv_error mouseb_svgalib_load(adv_conf* context)
{
return 0;
}
void mouseb_svgalib_reg(adv_conf* context)
{
}
/***************************************************************************/
/* Driver */
mouseb_driver mouseb_svgalib_driver = {
"svgalib",
DEVICE,
mouseb_svgalib_load,
mouseb_svgalib_reg,
mouseb_svgalib_init,
mouseb_svgalib_done,
0,
0,
mouseb_svgalib_flags,
mouseb_svgalib_count_get,
mouseb_svgalib_axe_count_get,
0,
mouseb_svgalib_button_count_get,
0,
mouseb_svgalib_axe_get,
mouseb_svgalib_button_get,
mouseb_svgalib_poll
};