2 ** Test program for mouse drivers.
3 ** Supportsthe C64/C128/CBM510/Atari/Apple2.
5 ** 2001-09-13, Ullrich von Bassewitz
6 ** 2013-09-05, Greg King
8 ** Compile with "-DSTATIC_MOUSE" to statically link all available drivers.
9 ** Compile with "-DMOUSE_DRIVER=<driver_sym>" to statically link the given driver.
10 ** E.g., -DMOUSE_DRIVER=atrsts_mou to just link with the Atari ST mouse driver.
25 #define max(a,b) (((a) > (b)) ? (a) : (b))
26 #define min(a,b) (((a) < (b)) ? (a) : (b))
28 extern int getsp(void);
34 extern const struct mouse_callbacks mouse_pm_callbacks;
35 extern const struct mouse_callbacks mouse_txt_callbacks;
36 //#define MOUSE_CALLBACK mouse_def_callbacks
37 #define MOUSE_CALLBACK mouse_pm_callbacks
38 //#define MOUSE_CALLBACK mouse_txt_callbacks
40 #define MOUSE_CALLBACK mouse_def_callbacks
43 #if defined(MOUSE_DRIVER) || defined(STATIC_MOUSE)
45 /* A statically linked driver was named on the compiler's command line.
46 ** Make sure that it is used instead of a dynamic one.
52 /* Use a dynamically loaded driver, by default. */
62 /* Set dark-on-light colors. */
63 const unsigned char mouse_def_pointercolor = COLOR_BLACK;
69 static void __fastcall__ CheckError (const char* S, unsigned char Error)
71 if (Error != MOUSE_ERR_OK) {
72 cprintf ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
74 /* Wait for a key-press, so that some platforms can show the error
75 ** message before they remove the current screen.
77 if (doesclrscrafterexit ()) {
88 /* Points to the dynamic driver's name. */
89 static const char *mouse_name;
92 static void DoWarning (void)
93 /* Warn the user that a driver is needed for this program. */
95 cprintf ("Warning: This program needs\r\n"
96 "the driver with the name\r\n"
98 "on a disk! Press 'y' if you have it;\r\n"
99 "or, any other key to exit.\r\n", mouse_stddrv);
100 if (tolower (cgetc ()) != 'y') {
103 cprintf ("OK. Please wait patiently...\r\n");
108 unsigned char *mouse_drv_use;
114 #define MSENAME_EXT "X"
115 #define MSESTAT_0 atrxjoy_mou
116 #define MSESTAT_1 atrxst_mou
117 #define MSESTAT_2 atrxami_mou
118 #define MSESTAT_3 atrxtrk_mou
119 #define MSESTAT_4 atrxtt_mou
121 #define MSENAME_EXT ""
122 #define MSESTAT_0 atrjoy_mou
123 #define MSESTAT_1 atrst_mou
124 #define MSESTAT_2 atrami_mou
125 #define MSESTAT_3 atrtrk_mou
126 #define MSESTAT_4 atrtt_mou
128 #define MSENAME_0 "ATR" MSENAME_EXT "JOY.MOU"
129 #define MSENAME_1 "ATR" MSENAME_EXT "ST.MOU"
130 #define MSENAME_2 "ATR" MSENAME_EXT "AMI.MOU"
131 #define MSENAME_3 "ATR" MSENAME_EXT "TRK.MOU"
132 #define MSENAME_4 "ATR" MSENAME_EXT "TT.MOU"
133 #elif defined(__C64__) || defined(__C128__)
135 #define MSENAME_EXT "c64-"
136 #define MSESTAT_0 c64_joy_mou
137 #define MSESTAT_1 c64_1351_mou
138 #define MSESTAT_2 c64_inkwell_mou
139 #define MSESTAT_3 c64_pot_mou
141 #define MSENAME_EXT "c128-"
142 #define MSESTAT_0 c128_joy_mou
143 #define MSESTAT_1 c128_1351_mou
144 #define MSESTAT_2 c128_inkwell_mou
145 #define MSESTAT_3 c128_pot_mou
147 #define MSENAME_0 MSENAME_EXT "joy.mou"
148 #define MSENAME_1 MSENAME_EXT "1351.mou"
149 #define MSENAME_2 MSENAME_EXT "inkwell.mou"
150 #define MSENAME_3 MSENAME_EXT "pot.mou"
154 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
155 /* Display jail and cursor states. */
159 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
163 extern char _HIDDEN_RAM_SIZE__, _HIDDEN_RAM_LAST__, _HIDDEN_RAM_START__;
167 int main (int argc, char *argv[])
172 struct mouse_info info;
173 struct mouse_box full_box, small_box;
174 unsigned char width, height;
176 bool Invisible = true, Done = false, Jailed = false;
179 cprintf ("adding heap: $%04X bytes at $%04X\r\n",
180 &_HIDDEN_RAM_SIZE__ - (&_HIDDEN_RAM_LAST__ - &_HIDDEN_RAM_START__),
181 &_HIDDEN_RAM_LAST__);
183 _heapadd (&_HIDDEN_RAM_LAST__, (size_t)(&_HIDDEN_RAM_SIZE__ - (&_HIDDEN_RAM_LAST__ - &_HIDDEN_RAM_START__)));
188 /* Initialize the debugger */
192 /* Set dark-on-light colors. Clear the screen. */
194 (void) bordercolor (COLOR_GRAY2);
195 (void) bgcolor (COLOR_WHITE);
196 (void) textcolor (COLOR_GRAY1);
198 (void) bordercolor (COLOR_BLUE);
199 (void) bgcolor (COLOR_WHITE);
200 (void) textcolor (COLOR_BLACK);
205 /* If a lightpen driver is installed, then it can get a calibration value
206 ** from this file (if it exists). Or, the user can adjust the pen; and,
207 ** the value will be put into this file, for the next time.
208 ** (Other drivers will ignore this.)
210 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
211 pen_adjust ("pen.dat");
215 /* If a dynamically loadable driver is named on the command line,
216 ** then use that driver instead of the standard one.
219 mouse_name = argv[1];
221 #if defined(__ATARI__) || defined(__C64__) || defined(__C128__)
222 char selection, flag = 0;
223 cprintf ("Select mouse driver:\r\n"
227 " 2 - Amiga Mouse\r\n"
228 " 3 - Atari Trakball\r\n"
229 " 4 - Atari TouchPad\r\n"
231 " 1 - 1351 Mouse\r\n"
232 " 2 - Inkwell Mouse\r\n"
235 "Enter selection: ");
237 switch (selection = cgetc ()) {
238 case '0': mouse_name = MSENAME_0; flag = 1; break;
239 case '1': mouse_name = MSENAME_1; flag = 1; break;
240 case '2': mouse_name = MSENAME_2; flag = 1; break;
241 case '3': mouse_name = MSENAME_3; flag = 1; break;
243 case '4': mouse_name = MSENAME_4; flag = 1; break;
248 cprintf ("%c\r\nOK, loading \"%s\",\r\nplease wait patiently...\r\n", selection, mouse_name);
250 /* Output a warning about the standard driver that is needed. */
252 mouse_name = mouse_stddrv;
256 /* Load and install the driver. */
257 CheckError ("mouse_load_driver",
258 mouse_load_driver (&MOUSE_CALLBACK, mouse_name));
259 #else /* not DYN_DRV */
260 #if !defined(MOUSE_DRIVER) && (defined(__ATARI__) || defined(__C64__) || defined(__C128__))
262 char selection, flag = 0;
263 cprintf ("Select mouse driver:\r\n"
267 " 2 - Amiga Mouse\r\n"
268 " 3 - Atari Trakball\r\n"
269 " 4 - Atari TouchPad\r\n"
271 " 1 - 1351 Mouse\r\n"
272 " 2 - Inkwell Mouse\r\n"
275 "Enter selection: ");
277 switch (selection = cgetc ()) {
278 case '0': mouse_drv_use = MSESTAT_0; flag = 1; break;
279 case '1': mouse_drv_use = MSESTAT_1; flag = 1; break;
280 case '2': mouse_drv_use = MSESTAT_2; flag = 1; break;
281 case '3': mouse_drv_use = MSESTAT_3; flag = 1; break;
283 case '4': mouse_drv_use = MSESTAT_4; flag = 1; break;
290 mouse_drv_use = mouse_static_stddrv;
293 /* Install the driver. */
294 CheckError ("mouse_install",
295 mouse_install (&MOUSE_CALLBACK,
299 #if defined(__ATARI__) || defined(__C64__) || defined(__C128__)
309 /* Get the initial bounding box. */
310 mouse_getbox (&full_box);
313 screensize (&width, &height);
318 /* Print a help line */
319 cputs (" d)ebug h)ide q)uit s)how j)ail");
322 cprintf ("SP: $%04X", getsp());
324 /* Put a cross at the center of the screen. */
325 gotoxy (width / 2 - 3, height / 2 - 1);
327 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
330 cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
335 ShowState (Jailed, Invisible);
337 /* Get the current co-ordinates and button states; and, print them. */
340 cprintf (" X = %3d\r\n", info.pos.x);
341 cprintf (" Y = %3d\r\n", info.pos.y);
342 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
349 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
357 /* Handle user input */
360 switch (tolower (C = cgetc ())) {
365 /* The debugger might have changed the colors.
369 (void) bordercolor (COLOR_GRAY2);
370 (void) bgcolor (COLOR_WHITE);
371 (void) textcolor (COLOR_GRAY1);
373 (void) bordercolor (COLOR_BLUE);
374 (void) bgcolor (COLOR_WHITE);
375 (void) textcolor (COLOR_BLACK);
378 /* The debugger changed the screen; restore it. */
383 ShowState (Jailed, ++Invisible);
389 mouse_setbox (&full_box);
392 small_box.minx = max (info.pos.x - 10, full_box.minx);
393 small_box.miny = max (info.pos.y - 10, full_box.miny);
394 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
395 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
396 mouse_setbox (&small_box);
399 ShowState (Jailed, Invisible);
405 ShowState (Jailed, --Invisible);
415 cprintf ("Spurious character: $%02X", C);
421 /* Uninstall and unload the driver. */
422 CheckError ("mouse_unload", mouse_unload ());
424 /* Uninstall the static driver. */
425 CheckError ("mouse_uninstall", mouse_uninstall ());
429 cputsxy (0, height / 2 + 3, "Goodbye!");