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-08-23, 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 ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
90 /* Wait for a key-press, so that some platforms can show the error
91 ** message before they remove the current screen.
102 /* Points to the dynamic driver's name. */
103 static const char *mouse_name;
107 static void DoWarning (void)
108 /* Warn the user that a driver is needed for this program. */
110 cprintf ("Warning: This program needs\r\n"
111 "the driver with the name\r\n"
113 "on a disk! Press 'y' if you have it;\r\n"
114 "or, any other key to exit.\r\n", mouse_stddrv);
115 if (tolower (cgetc ()) != 'y') {
118 cprintf ("OK. Please wait patiently...\r\n");
124 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
125 /* Display jail and cursor states. */
129 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
135 int main (int argc, char *argv[])
140 struct mouse_info info;
141 struct mouse_box full_box, small_box;
142 unsigned char width, height;
144 bool Invisible = true, Done = false, Jailed = false;
146 /* Initialize the debugger */
149 /* Set dark-on-light colors. Clear the screen. */
151 (void) bordercolor (COLOR_GRAY2);
152 (void) bgcolor (COLOR_WHITE);
153 (void) textcolor (COLOR_GRAY1);
155 (void) bordercolor (COLOR_BLUE);
156 (void) bgcolor (COLOR_WHITE);
157 (void) textcolor (COLOR_BLACK);
162 /* The pointer should be created before the driver is installed,
163 ** in case a lightpen driver needs it during calibration.
166 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
167 /* Copy the sprite data */
168 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
170 /* Set the VIC-II sprite pointer. */
171 *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
173 /* Set the color of sprite 0 */
175 pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK);
177 VIC.spr0_color = COLOR_BLACK;
181 /* If a lightpen driver is installed, then it can get a calibration value
182 ** from this file (if it exists). Or, the user can adjust the pen; and,
183 ** the value will be put into this file, for the next time.
184 ** (Other drivers will ignore this.)
186 #if defined(__C64__) || defined(__C128__)
187 pen_adjust ("pen.dat");
191 /* If a dynamically loadable driver is named on the command line,
192 ** then use that driver instead of the standard one.
195 mouse_name = argv[1];
197 /* Output a warning about the standard driver that is needed. */
199 mouse_name = mouse_stddrv;
202 /* Load and install the driver. */
203 CheckError ("mouse_load_driver",
204 mouse_load_driver (&mouse_def_callbacks, mouse_name));
206 /* Install the driver. */
207 CheckError ("mouse_install",
208 mouse_install (&mouse_def_callbacks,
217 /* Get the initial bounding box. */
218 mouse_getbox (&full_box);
220 screensize (&width, &height);
225 /* Print a help line */
226 cputs (" d)ebug h)ide q)uit s)how j)ail");
228 /* Put a cross at the center of the screen. */
229 gotoxy (width / 2 - 3, height / 2 - 1);
231 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
234 cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
239 ShowState (Jailed, Invisible);
241 /* Get the current co-ordinates and button states; and, print them. */
244 cprintf (" X = %3d\r\n", info.pos.x);
245 cprintf (" Y = %3d\r\n", info.pos.y);
246 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
253 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
261 /* Handle user input */
264 switch (tolower (C = cgetc ())) {
268 /* The debugger might have changed the colors.
272 (void) bordercolor (COLOR_GRAY2);
273 (void) bgcolor (COLOR_WHITE);
274 (void) textcolor (COLOR_GRAY1);
276 (void) bordercolor (COLOR_BLUE);
277 (void) bgcolor (COLOR_WHITE);
278 (void) textcolor (COLOR_BLACK);
281 /* The debugger changed the screen; restore it. */
286 ShowState (Jailed, ++Invisible);
291 mouse_setbox (&full_box);
294 small_box.minx = max (info.pos.x - 10, full_box.minx);
295 small_box.miny = max (info.pos.y - 10, full_box.miny);
296 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
297 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
298 mouse_setbox (&small_box);
301 ShowState (Jailed, Invisible);
307 ShowState (Jailed, --Invisible);
317 cprintf ("Spurious character: $%02X", C);
323 /* Uninstall and unload the driver. */
324 CheckError ("mouse_unload", mouse_unload ());
326 /* Uninstall the static driver. */
327 CheckError ("mouse_uninstall", mouse_uninstall ());
331 cputsxy (0, height / 2 + 3, "Goodbye!");