2 ** Demo program for mouse usage.
3 ** Supports the C64/C128/CBM510/Atari/Apple2.
5 ** 2001-09-13, Ullrich von Bassewitz
6 ** 2013-09-05, Greg King
22 #define max(a,b) (((a) > (b)) ? (a) : (b))
23 #define min(a,b) (((a) < (b)) ? (a) : (b))
29 /* A statically linked driver was named on the compiler's command line.
30 ** Make sure that it is used instead of a dynamic one.
36 /* Use a dynamically loaded driver, by default. */
46 /* Set dark-on-light colors. */
47 const unsigned char mouse_def_pointercolor = COLOR_BLACK;
53 static void __fastcall__ CheckError (const char* S, unsigned char Error)
55 if (Error != MOUSE_ERR_OK) {
56 cprintf ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
58 /* Wait for a key-press, so that some platforms can show the error
59 ** message before they remove the current screen.
61 if (doesclrscrafterexit ()) {
72 /* Points to the dynamic driver's name. */
73 static const char *mouse_name;
77 static void DoWarning (void)
78 /* Warn the user that a driver is needed for this program. */
80 cprintf ("Warning: This program needs\r\n"
81 "the driver with the name\r\n"
83 "on a disk! Press 'y' if you have it;\r\n"
84 "or, any other key to exit.\r\n", mouse_stddrv);
85 if (tolower (cgetc ()) != 'y') {
88 cprintf ("OK. Please wait patiently...\r\n");
94 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
95 /* Display jail and cursor states. */
99 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
105 int main (int argc, char *argv[])
110 struct mouse_info info;
111 struct mouse_box full_box, small_box;
112 unsigned char width, height;
114 bool Invisible = true, Done = false, Jailed = false;
116 /* Initialize the debugger */
119 /* Set dark-on-light colors. Clear the screen. */
121 (void) bordercolor (COLOR_GRAY2);
122 (void) bgcolor (COLOR_WHITE);
123 (void) textcolor (COLOR_GRAY1);
125 (void) bordercolor (COLOR_BLUE);
126 (void) bgcolor (COLOR_WHITE);
127 (void) textcolor (COLOR_BLACK);
132 /* If a lightpen driver is installed, then it can get a calibration value
133 ** from this file (if it exists). Or, the user can adjust the pen; and,
134 ** the value will be put into this file, for the next time.
135 ** (Other drivers will ignore this.)
137 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
138 pen_adjust ("pen.dat");
142 /* If a dynamically loadable driver is named on the command line,
143 ** then use that driver instead of the standard one.
146 mouse_name = argv[1];
148 /* Output a warning about the standard driver that is needed. */
150 mouse_name = mouse_stddrv;
153 /* Load and install the driver. */
154 CheckError ("mouse_load_driver",
155 mouse_load_driver (&mouse_def_callbacks, mouse_name));
157 /* Install the driver. */
158 CheckError ("mouse_install",
159 mouse_install (&mouse_def_callbacks,
168 /* Get the initial bounding box. */
169 mouse_getbox (&full_box);
171 screensize (&width, &height);
176 /* Print a help line */
177 cputs (" d)ebug h)ide q)uit s)how j)ail");
179 /* Put a cross at the center of the screen. */
180 gotoxy (width / 2 - 3, height / 2 - 1);
182 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
185 cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
190 ShowState (Jailed, Invisible);
192 /* Get the current co-ordinates and button states; and, print them. */
195 cprintf (" X = %3d\r\n", info.pos.x);
196 cprintf (" Y = %3d\r\n", info.pos.y);
197 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
204 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
212 /* Handle user input */
215 switch (tolower (C = cgetc ())) {
219 /* The debugger might have changed the colors.
223 (void) bordercolor (COLOR_GRAY2);
224 (void) bgcolor (COLOR_WHITE);
225 (void) textcolor (COLOR_GRAY1);
227 (void) bordercolor (COLOR_BLUE);
228 (void) bgcolor (COLOR_WHITE);
229 (void) textcolor (COLOR_BLACK);
232 /* The debugger changed the screen; restore it. */
237 ShowState (Jailed, ++Invisible);
242 mouse_setbox (&full_box);
245 small_box.minx = max (info.pos.x - 10, full_box.minx);
246 small_box.miny = max (info.pos.y - 10, full_box.miny);
247 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
248 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
249 mouse_setbox (&small_box);
252 ShowState (Jailed, Invisible);
258 ShowState (Jailed, --Invisible);
268 cprintf ("Spurious character: $%02X", C);
274 /* Uninstall and unload the driver. */
275 CheckError ("mouse_unload", mouse_unload ());
277 /* Uninstall the static driver. */
278 CheckError ("mouse_uninstall", mouse_uninstall ());
282 cputsxy (0, height / 2 + 3, "Goodbye!");