2 * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2
4 * Ullrich von Bassewitz, 13.09.2001
20 #if defined(__C64__) || defined(__C128__)
22 /* Address of data for sprite 0 */
24 # define SPRITE0_DATA 0x0340
25 # define SPRITE0_PTR 0x07F8
26 #elif defined(__C128__)
27 # define SPRITE0_DATA 0x0E00
28 # define SPRITE0_PTR 0x07F8
31 /* The mouse sprite (an arrow) */
32 static const unsigned char MouseSprite[64] = {
57 #endif /* __C64__ or __C128__ */
61 static void CheckError (const char* S, unsigned char Error)
63 if (Error != MOUSE_ERR_OK) {
64 printf ("%s: %s(%d)\n", S, mouse_geterrormsg (Error), Error);
71 static void DoWarning (void)
72 /* Warn the user that a mouse driver is needed for this program */
74 printf ("Warning: This program needs the mouse\n"
75 "driver with the name\n"
77 "on disk! Press 'y' if you have it or\n"
78 "any other key to exit.\n", mouse_stddrv);
79 if (tolower (cgetc ()) != 'y') {
82 printf ("Ok. Please wait patiently...\n");
87 static void ShowState (unsigned char Invisible)
88 /* Display cursor visibility */
93 cprintf ("Mouse cursor %svisible", Invisible? "in" : "");
100 struct mouse_info info;
101 unsigned char Invisible;
104 /* Initialize the debugger */
107 /* Output a warning about the driver that is needed */
110 /* Clear the screen, set white on black */
111 (void) bordercolor (COLOR_BLACK);
112 (void) bgcolor (COLOR_BLACK);
113 (void) textcolor (COLOR_GRAY3);
117 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
118 /* Copy the sprite data */
119 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
121 /* Set the VIC sprite pointer */
122 *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
124 /* Set the color of sprite 0 */
126 pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
128 VIC.spr0_color = COLOR_WHITE;
133 /* Load and install the mouse driver */
134 CheckError ("mouse_load_driver",
135 mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
137 /* Print a help line */
139 cputsxy (0, 0, "d: debug h: hide q: quit s: show ");
144 ShowState (Invisible = 1);
147 switch (tolower (cgetc ())) {
152 ShowState (++Invisible);
157 ShowState (--Invisible);
167 /* Get the current mouse coordinates and button states and print them */
170 cprintf ("X = %3d", info.pos.x);
172 cprintf ("Y = %3d", info.pos.y);
174 cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
176 cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
180 /* Uninstall and unload the mouse driver */
181 CheckError ("mouse_unload", mouse_unload ());
185 cputs ("Goodbye!\r\n");