aboutsummaryrefslogtreecommitdiff
path: root/int33.h
blob: 7cd7aa53b3797cc0b93d075b0d01df361436fa63 (plain)
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
 * VBMouse - int33 API defines
 * Copyright (C) 2022 Javier S. Pedro
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef INT33_H
#define INT33_H

#include <stdint.h>
#include <stdbool.h>

enum INT33_API {
	/** Reinitializes mouse hardware and resets mouse to default driver values.
	 *  On return, ax = 0xFFFF, bx = number of buttons. */
	INT33_RESET_MOUSE = 0,

	/** Increment the cursor visible counter. The cursor is shown when the counter is >= 0. */
	INT33_SHOW_CURSOR = 1,
	/** Decrement the cursor visible counter. The cursor is shown when the counter is >= 0. */
	INT33_HIDE_CURSOR = 2,

	/** Gets the current mouse position and button status.
	 *  @returns cx = horizontal pos, dx = vertical pos,
	 *           bx = button status (bitfield, lsb = button 0/left). */
	INT33_GET_MOUSE_POSITION = 3,
	/** Sets the current mouse position.
	 *  @param cx = horizontal pos, dx = vertical pos. */
	INT33_SET_MOUSE_POSITION = 4,

	/** Gets the number of times a mouse button was pressed since the last call.
	 *  @param bx = button number
	 *  @returns ax = current all button status (bitfield),
	 *           bx = count of times button was pressed,
	 *           cx = horizontal pos at last press,
	 *           dx = vetical pos at last press */
	INT33_GET_BUTTON_PRESSED_COUNTER = 5,
	/** Gets the number of times a mouse button was released since the last call.
	 *  @param bx = button number
	 *  @returns ax = current all button status (bitfield),
	 *           bx = count of times button was released,
	 *           cx = horizontal pos at last release,
	 *           dx = vetical pos at last release */
	INT33_GET_BUTTON_RELEASED_COUNTER = 6,

	/** @param cx = minimum horizontal position, dx = maximum horizontal position. */
	INT33_SET_HORIZONTAL_WINDOW = 7,

	/** @param cx = minimum vertical position, dx = maximum vertical position. */
	INT33_SET_VERTICAL_WINDOW = 8,

	/** Configures graphicsmode mouse cursor.
	 *  @param bx horizontal hotspot , cx vertical hotspot
	 *  @param es:dx address of cursor shape bitmap */
	INT33_SET_GRAPHICS_CURSOR = 9,

	/** Configures textmode mouse cursor.
	 *  @param bx 1 for hardware cursor, 0 for software cursor
	 *  @param cx for software cursor, AND mask; for hardware cursor, start scanline.
	 *  @param dx for software cursor, XOR mask; for hardware cursor, end scanline. */
	INT33_SET_TEXT_CURSOR = 0xA,

	/** Gets total relative mouse distance (in mickeys) since the last call.
	 *  @param cx horizontal distance , dx vertical distance */
	INT33_GET_MOUSE_MOTION = 0xB,

	/** Replaces the current routine for event handling.
	 *  @param es:dx address of the new event handler
	 *  @param cx event mask (see INT33_EVENT_MASK) */
	INT33_SET_EVENT_HANDLER = 0xC,

	/** Sets the mickey-per-8-pixels ratio, controlling the cursor speed.
	 *  @param cx horizontal speed, dx vertical speed */
	INT33_SET_MOUSE_SPEED = 0xF,

	/** If the mouse is moved more than this mickeys in one second,
	 *  the mouse motion is doubled.
	 *  @param cx doubling threshold (mickeys per second) */
	INT33_SET_SPEED_DOUBLE_THRESHOLD = 0x13,

	/** Replaces the current routine for event handling,
	 *  but also returns the old one.
	 *  @param es:dx address of the new event handler
	 *  @param cx event mask (see INT33_EVENT_MASK)
	 *  @return es:dx address of the previous event handler. */
	INT33_EXCHANGE_EVENT_HANDLER = 0x14,

	/** Query the size of the memory required to save a copy of the mouse status.
	 *  @return bx buffer needed. */
	INT33_GET_MOUSE_STATUS_SIZE = 0x15,

	INT33_SAVE_MOUSE_STATUS = 0x16,
	INT33_LOAD_MOUSE_STATUS = 0x17,

	/** Sets both speed and speed-doubling threshold in one call.
	 *  @param bx horizontal speed, cx vertical speed
	 *  @param dx doubling threshold (mickeys per second). */
	INT33_SET_MOUSE_SENSITIVITY = 0x1A,
	/** Gets current speed and speed-doubling threshold.
	 *  @return bx horizontal speed, cx vertical speed
	 *  @return dx doubling threshold (mickeys per second). */
	INT33_GET_MOUSE_SENSITIVITY = 0x1B,

	/** Resets mouse to default driver values.
	 *  On return, ax = 0xFFFF, bx = number of buttons. */
	INT33_RESET_SETTINGS = 0x21,

	/** Gets language for messages.
	 *  @return bx language code. */
	INT33_GET_LANGUAGE = 0x23,

	/** Gets driver information.
	 *  On return, bx = major:minor version, ch = INT33_MOUSE_TYPE, CL = irq number (or 0). */
	INT33_GET_DRIVER_INFO = 0x24,

	/** Gets the current video mode maximum X & Y positions.
	 *  @return cx max x, dx max y. */
	INT33_GET_MAX_COORDINATES = 0x26,

	/** Gets the current window coordinates (set by INT33_SET_HORIZONTAL_WINDOW).
	 *  @return ax min_x, bx min_y, cx max_x, d max_y. */
	INT33_GET_WINDOW = 0x31,

	/** Get pointer to driver's copyright string in es:di. */
	INT33_GET_COPYRIGHT_STRING = 0x4D,

	/** Get pointer to driver's version string in es:di. */
	INT33_GET_VERSION_STRING = 0x6D,

	// Wheel API Extensions:
	INT33_GET_CAPABILITIES = 0x11,

	// Our internal API functions:
	/** Obtains a pointer to the driver's data in es:di. */
	INT33_GET_TSR_DATA = 0x73,
};

enum INT33_CAPABILITY_BITS {
	INT33_CAPABILITY_MOUSE_API = 1 << 0
};

#define INT33_WHEEL_API_MAGIC 'WM'
#define INT33_MOUSE_FOUND 0xFFFF

enum INT33_MOUSE_TYPE {
	INT33_MOUSE_TYPE_BUS = 1,
	INT33_MOUSE_TYPE_SERIAL = 2,
	INT33_MOUSE_TYPE_INPORT = 3,
	INT33_MOUSE_TYPE_PS2 = 4,
	INT33_MOUSE_TYPE_HP = 5
};

enum INT33_BUTTON_MASK {
	INT33_BUTTON_MASK_LEFT   = 1 << 0,
	INT33_BUTTON_MASK_RIGHT  = 1 << 1,
	INT33_BUTTON_MASK_CENTER = 1 << 2
};

enum INT33_EVENT_MASK {
	INT33_EVENT_MASK_MOVEMENT               = 1 << 0,
	INT33_EVENT_MASK_LEFT_BUTTON_PRESSED    = 1 << 1,
	INT33_EVENT_MASK_LEFT_BUTTON_RELEASED   = 1 << 2,
	INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED   = 1 << 3,
	INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED  = 1 << 4,
	INT33_EVENT_MASK_CENTER_BUTTON_PRESSED  = 1 << 5,
	INT33_EVENT_MASK_CENTER_BUTTON_RELEASED = 1 << 6,

	// Wheel API Extensions:
	/** Wheel mouse movement. */
	INT33_EVENT_MASK_WHEEL_MOVEMENT         = 1 << 7,

	// Absolute API extensions:
	/** The source of the event is an absolute pointing device. */
	INT33_EVENT_MASK_ABSOLUTE               = 1 << 8,

	INT33_EVENT_MASK_ALL                    = 0xFFFF
};

#pragma aux INT33_CB far loadds parm [ax] [bx] [cx] [dx] [si] [di] modify []

static uint16_t int33_reset(void);
#pragma aux int33_reset = \
	"mov ax, 0x0" \
	"int 0x33" \
	__value [ax] \
	__modify [ax bx]

static void int33_set_horizontal_window(int16_t min, int16_t max);
#pragma aux int33_set_horizontal_window = \
	"mov ax, 0x7" \
	"int 0x33" \
	__parm [cx] [dx] \
	__modify [ax]

static void int33_set_vertical_window(int16_t min, int16_t max);
#pragma aux int33_set_vertical_window = \
	"mov ax, 0x8" \
	"int 0x33" \
	__parm [cx] [dx] \
	__modify [ax]

static void int33_set_event_handler(uint16_t event_mask, void (__far *handler)());
#pragma aux int33_set_event_handler = \
	"mov ax, 0xC" \
	"int 0x33" \
	__parm [cx] [es dx] \
	__modify [ax]

static uint16_t int33_get_driver_version(void);
#pragma aux int33_get_driver_version = \
	"mov bx, 0" \
	"mov ax, 0x24" \
	"int 0x33" \
	"cmp ax, -1" \
	"jne end" \
	"error:" \
	"mov bx, 0" \
	"end:" \
	__value [bx] \
	__modify [ax bx cx dx]

static bool int33_get_max_coordinates(int16_t *x, int16_t *y);
#pragma aux int33_get_max_coordinates = \
	"mov ax, 0x26" \
	"mov bx, -1" \
	"int 0x33" \
	"xor ax, ax" \
	"test bx, bx" \
	"jnz error" \
	"mov [si], cx" \
	"mov [di], dx" \
	"mov al, 1" \
	"error:" \
	__parm [si] [di] \
	__value [al] \
	__modify [ax bx cx dx]

static uint16_t int33_get_capabilities(void);
#pragma aux int33_get_capabilities = \
	"mov ax, 0x11" \
	"int 0x33" \
	"cmp ax, 0x574D"  /* Compare against the INT33_WHEEL_API_MAGIC number. */ \
	"je end" \
	"xor cx, cx"      /* If magic not correct, assume not supported and return 0. */ \
	"end:" \
	__value [cx] \
	__modify [ax bx cx]

#endif /* INT33_H */