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-06-26, Greg King
20 #define max(a,b) (((a) > (b)) ? (a) : (b))
21 #define min(a,b) (((a) < (b)) ? (a) : (b))
27 /* A statically linked driver was named on the compiler's command line.
28 ** Make sure that it is used instead of a dynamic one.
34 /* Use a dynamically loaded driver, by default. */
42 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
44 /* Addresses of data for sprite 0 */
46 # define SPRITE0_DATA ((unsigned char[64])0x0340)
47 # define SPRITE0_PTR ((unsigned char *)0x07F8)
48 #elif defined(__C128__)
49 # define SPRITE0_DATA ((unsigned char[64])0x0E00)
50 # define SPRITE0_PTR ((unsigned char *)0x07F8)
51 #elif defined(__CBM510__)
52 # define SPRITE0_DATA ((unsigned char[64])0xF400)
53 # define SPRITE0_PTR ((unsigned char *)0xF3F8)
56 /* The mouse sprite (an arrow) */
57 static const unsigned char MouseSprite[64] = {
84 static void __fastcall__ CheckError (const char* S, unsigned char Error)
86 if (Error != MOUSE_ERR_OK) {
87 cprintf ("%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
96 /* Points to the dynamic driver's name. */
97 static const char *mouse_name;
101 static void DoWarning (void)
102 /* Warn the user that a driver is needed for this program. */
104 cprintf ("Warning: This program needs\r\n"
105 "the driver with the name\r\n"
107 "on a disk! Press 'y' if you have it;\r\n"
108 "or, any other key to exit.\r\n", mouse_stddrv);
109 if (tolower (cgetc ()) != 'y') {
112 cprintf ("OK. Please wait patiently...\r\n");
118 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
119 /* Display jail and cursor states. */
123 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
129 int main (int argc, char *argv[])
134 struct mouse_info info;
135 struct mouse_box full_box, small_box;
136 unsigned char width, height;
138 bool Invisible = true, Done = false, Jailed = false;
140 /* Initialize the debugger */
143 /* Set dark-on-light colors. Clear the screen. */
145 (void) bordercolor (COLOR_GRAY2);
146 (void) bgcolor (COLOR_WHITE);
147 (void) textcolor (COLOR_GRAY1);
149 (void) bordercolor (COLOR_BLUE);
150 (void) bgcolor (COLOR_WHITE);
151 (void) textcolor (COLOR_BLACK);
156 /* The pointer is created before the driver is installed,
157 ** in case a lightpen driver needs it during calibration.
160 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
161 /* Copy the sprite data */
162 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
164 /* Set the VIC-II sprite pointer. */
165 *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
167 /* Set the color of sprite 0 */
169 pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK);
171 VIC.spr0_color = COLOR_BLACK;
175 /* If a lightpen driver is installed, then it can get a calibration value
176 ** from this file (if it exists). Or, the user can adjust the pen; and,
177 ** the value will be put into this file, for the next time.
178 ** (Other drivers will ignore this.)
181 pen_adjust ("pen.dat");
185 /* If a dynamically loadable driver is named on the command line,
186 ** then use that driver instead of the standard one.
189 mouse_name = argv[1];
191 /* Output a warning about the standard driver that is needed. */
193 mouse_name = mouse_stddrv;
196 /* Load and install the driver. */
197 CheckError ("mouse_load_driver",
198 mouse_load_driver (&mouse_def_callbacks, mouse_name));
200 /* Install the driver. */
201 CheckError ("mouse_install",
202 mouse_install (&mouse_def_callbacks,
211 /* Get the initial bounding box. */
212 mouse_getbox (&full_box);
214 screensize (&width, &height);
219 /* Print a help line */
220 cputs (" d)ebug h)ide q)uit s)how j)ail");
222 /* Put a cross at the center of the screen. */
223 gotoxy (width / 2 - 3, height / 2 - 1);
224 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
228 ShowState (Jailed, Invisible);
230 /* Get the current co-ordinates and button states; and, print them. */
233 cprintf (" X = %3d\r\n", info.pos.x);
234 cprintf (" Y = %3d\r\n", info.pos.y);
235 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
242 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
250 /* Handle user input */
253 switch (tolower (C = cgetc ())) {
257 /* The debugger might have changed the colors.
261 (void) bordercolor (COLOR_GRAY2);
262 (void) bgcolor (COLOR_WHITE);
263 (void) textcolor (COLOR_GRAY1);
265 (void) bordercolor (COLOR_BLUE);
266 (void) bgcolor (COLOR_WHITE);
267 (void) textcolor (COLOR_BLACK);
270 /* The debugger changed the screen; restore it. */
275 ShowState (Jailed, ++Invisible);
280 mouse_setbox (&full_box);
283 small_box.minx = max (info.pos.x - 10, full_box.minx);
284 small_box.miny = max (info.pos.y - 10, full_box.miny);
285 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
286 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
287 mouse_setbox (&small_box);
290 ShowState (Jailed, Invisible);
296 ShowState (Jailed, --Invisible);
306 cprintf ("Spurious character: $%02X", C);
312 /* Uninstall and unload the driver. */
313 CheckError ("mouse_unload", mouse_unload ());
315 /* Uninstall the static driver. */
316 CheckError ("mouse_uninstall", mouse_uninstall ());
320 cputsxy (0, height / 2 + 3, "Goodbye!");