2 ** Test/demo program for mouse usage.
3 ** Will work for the C64/C128/CBM510/Atari/Apple2.
5 ** 2001-09-13, Ullrich von Bassewitz
6 ** 2013-09-05, Greg King
21 #define max(a,b) (((a) > (b)) ? (a) : (b))
22 #define min(a,b) (((a) < (b)) ? (a) : (b))
28 /* A statically linked driver was named on the compiler's command line.
29 ** Make sure that it is used instead of a dynamic one.
35 /* Use a dynamically loaded driver, by default. */
45 /* Set dark-on-light colors. */
46 const unsigned char mouse_def_pointercolor = COLOR_BLACK;
52 static void __fastcall__ CheckError (const char* S, unsigned char Error)
54 if (Error != MOUSE_ERR_OK) {
55 cprintf ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
57 /* Wait for a key-press, so that some platforms can show the error
58 ** message before they remove the current screen.
69 /* Points to the dynamic driver's name. */
70 static const char *mouse_name;
74 static void DoWarning (void)
75 /* Warn the user that a driver is needed for this program. */
77 cprintf ("Warning: This program needs\r\n"
78 "the driver with the name\r\n"
80 "on a disk! Press 'y' if you have it;\r\n"
81 "or, any other key to exit.\r\n", mouse_stddrv);
82 if (tolower (cgetc ()) != 'y') {
85 cprintf ("OK. Please wait patiently...\r\n");
91 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
92 /* Display jail and cursor states. */
96 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
102 int main (int argc, char *argv[])
107 struct mouse_info info;
108 struct mouse_box full_box, small_box;
109 unsigned char width, height;
111 bool Invisible = true, Done = false, Jailed = false;
113 /* Initialize the debugger */
116 /* Set dark-on-light colors. Clear the screen. */
118 (void) bordercolor (COLOR_GRAY2);
119 (void) bgcolor (COLOR_WHITE);
120 (void) textcolor (COLOR_GRAY1);
122 (void) bordercolor (COLOR_BLUE);
123 (void) bgcolor (COLOR_WHITE);
124 (void) textcolor (COLOR_BLACK);
129 /* If a lightpen driver is installed, then it can get a calibration value
130 ** from this file (if it exists). Or, the user can adjust the pen; and,
131 ** the value will be put into this file, for the next time.
132 ** (Other drivers will ignore this.)
134 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
135 pen_adjust ("pen.dat");
139 /* If a dynamically loadable driver is named on the command line,
140 ** then use that driver instead of the standard one.
143 mouse_name = argv[1];
145 /* Output a warning about the standard driver that is needed. */
147 mouse_name = mouse_stddrv;
150 /* Load and install the driver. */
151 CheckError ("mouse_load_driver",
152 mouse_load_driver (&mouse_def_callbacks, mouse_name));
154 /* Install the driver. */
155 CheckError ("mouse_install",
156 mouse_install (&mouse_def_callbacks,
165 /* Get the initial bounding box. */
166 mouse_getbox (&full_box);
168 screensize (&width, &height);
173 /* Print a help line */
174 cputs (" d)ebug h)ide q)uit s)how j)ail");
176 /* Put a cross at the center of the screen. */
177 gotoxy (width / 2 - 3, height / 2 - 1);
179 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
182 cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
187 ShowState (Jailed, Invisible);
189 /* Get the current co-ordinates and button states; and, print them. */
192 cprintf (" X = %3d\r\n", info.pos.x);
193 cprintf (" Y = %3d\r\n", info.pos.y);
194 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
201 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
209 /* Handle user input */
212 switch (tolower (C = cgetc ())) {
216 /* The debugger might have changed the colors.
220 (void) bordercolor (COLOR_GRAY2);
221 (void) bgcolor (COLOR_WHITE);
222 (void) textcolor (COLOR_GRAY1);
224 (void) bordercolor (COLOR_BLUE);
225 (void) bgcolor (COLOR_WHITE);
226 (void) textcolor (COLOR_BLACK);
229 /* The debugger changed the screen; restore it. */
234 ShowState (Jailed, ++Invisible);
239 mouse_setbox (&full_box);
242 small_box.minx = max (info.pos.x - 10, full_box.minx);
243 small_box.miny = max (info.pos.y - 10, full_box.miny);
244 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
245 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
246 mouse_setbox (&small_box);
249 ShowState (Jailed, Invisible);
255 ShowState (Jailed, --Invisible);
265 cprintf ("Spurious character: $%02X", C);
271 /* Uninstall and unload the driver. */
272 CheckError ("mouse_unload", mouse_unload ());
274 /* Uninstall the static driver. */
275 CheckError ("mouse_uninstall", mouse_uninstall ());
279 cputsxy (0, height / 2 + 3, "Goodbye!");