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-07-25, 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. */
43 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
45 /* Addresses of data for sprite 0 */
47 # define SPRITE0_DATA ((unsigned char[64])0x0340)
48 # define SPRITE0_PTR ((unsigned char *)0x07F8)
49 #elif defined(__C128__)
50 # define SPRITE0_DATA ((unsigned char[64])0x0E00)
51 # define SPRITE0_PTR ((unsigned char *)0x07F8)
52 #elif defined(__CBM510__)
53 # define SPRITE0_DATA ((unsigned char[64])0xF400)
54 # define SPRITE0_PTR ((unsigned char *)0xF3F8)
57 /* The mouse sprite (an arrow) */
58 static const unsigned char MouseSprite[64] = {
85 static void __fastcall__ CheckError (const char* S, unsigned char Error)
87 if (Error != MOUSE_ERR_OK) {
88 cprintf ("%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
97 /* Points to the dynamic driver's name. */
98 static const char *mouse_name;
102 static void DoWarning (void)
103 /* Warn the user that a driver is needed for this program. */
105 cprintf ("Warning: This program needs\r\n"
106 "the driver with the name\r\n"
108 "on a disk! Press 'y' if you have it;\r\n"
109 "or, any other key to exit.\r\n", mouse_stddrv);
110 if (tolower (cgetc ()) != 'y') {
113 cprintf ("OK. Please wait patiently...\r\n");
119 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
120 /* Display jail and cursor states. */
124 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
130 int main (int argc, char *argv[])
135 struct mouse_info info;
136 struct mouse_box full_box, small_box;
137 unsigned char width, height;
139 bool Invisible = true, Done = false, Jailed = false;
141 /* Initialize the debugger */
144 /* Set dark-on-light colors. Clear the screen. */
146 (void) bordercolor (COLOR_GRAY2);
147 (void) bgcolor (COLOR_WHITE);
148 (void) textcolor (COLOR_GRAY1);
150 (void) bordercolor (COLOR_BLUE);
151 (void) bgcolor (COLOR_WHITE);
152 (void) textcolor (COLOR_BLACK);
157 /* The pointer is created before the driver is installed,
158 ** in case a lightpen driver needs it during calibration.
161 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
162 /* Copy the sprite data */
163 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
165 /* Set the VIC-II sprite pointer. */
166 *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
168 /* Set the color of sprite 0 */
170 pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK);
172 VIC.spr0_color = COLOR_BLACK;
176 /* If a lightpen driver is installed, then it can get a calibration value
177 ** from this file (if it exists). Or, the user can adjust the pen; and,
178 ** the value will be put into this file, for the next time.
179 ** (Other drivers will ignore this.)
182 pen_adjust ("pen.dat");
186 /* If a dynamically loadable driver is named on the command line,
187 ** then use that driver instead of the standard one.
190 mouse_name = argv[1];
192 /* Output a warning about the standard driver that is needed. */
194 mouse_name = mouse_stddrv;
197 /* Load and install the driver. */
198 CheckError ("mouse_load_driver",
199 mouse_load_driver (&mouse_def_callbacks, mouse_name));
201 /* Install the driver. */
202 CheckError ("mouse_install",
203 mouse_install (&mouse_def_callbacks,
212 /* Get the initial bounding box. */
213 mouse_getbox (&full_box);
215 screensize (&width, &height);
220 /* Print a help line */
221 cputs (" d)ebug h)ide q)uit s)how j)ail");
223 /* Put a cross at the center of the screen. */
224 gotoxy (width / 2 - 3, height / 2 - 1);
225 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
229 ShowState (Jailed, Invisible);
231 /* Get the current co-ordinates and button states; and, print them. */
234 cprintf (" X = %3d\r\n", info.pos.x);
235 cprintf (" Y = %3d\r\n", info.pos.y);
236 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
243 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
251 /* Handle user input */
254 switch (tolower (C = cgetc ())) {
258 /* The debugger might have changed the colors.
262 (void) bordercolor (COLOR_GRAY2);
263 (void) bgcolor (COLOR_WHITE);
264 (void) textcolor (COLOR_GRAY1);
266 (void) bordercolor (COLOR_BLUE);
267 (void) bgcolor (COLOR_WHITE);
268 (void) textcolor (COLOR_BLACK);
271 /* The debugger changed the screen; restore it. */
276 ShowState (Jailed, ++Invisible);
281 mouse_setbox (&full_box);
284 small_box.minx = max (info.pos.x - 10, full_box.minx);
285 small_box.miny = max (info.pos.y - 10, full_box.miny);
286 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
287 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
288 mouse_setbox (&small_box);
291 ShowState (Jailed, Invisible);
297 ShowState (Jailed, --Invisible);
307 cprintf ("Spurious character: $%02X", C);
313 /* Uninstall and unload the driver. */
314 CheckError ("mouse_unload", mouse_unload ());
316 /* Uninstall the static driver. */
317 CheckError ("mouse_uninstall", mouse_uninstall ());
321 cputsxy (0, height / 2 + 3, "Goodbye!");