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__ */
60 #define max(a,b) (((a) > (b)) ? (a) : (b))
61 #define min(a,b) (((a) < (b)) ? (a) : (b))
65 static void CheckError (const char* S, unsigned char Error)
67 if (Error != MOUSE_ERR_OK) {
68 printf ("%s: %s(%d)\n", S, mouse_geterrormsg (Error), Error);
75 static void DoWarning (void)
76 /* Warn the user that a mouse driver is needed for this program */
78 printf ("Warning: This program needs the mouse\n"
79 "driver with the name\n"
81 "on disk! Press 'y' if you have it or\n"
82 "any other key to exit.\n", mouse_stddrv);
83 if (tolower (cgetc ()) != 'y') {
86 printf ("Ok. Please wait patiently...\n");
91 static void ShowState (unsigned char Jailed, unsigned char Invisible)
92 /* Display jail and cursor state */
97 cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : "");
104 struct mouse_info info;
105 struct mouse_box full_box;
106 struct mouse_box small_box;
107 unsigned char Invisible;
109 unsigned char Jailed;
111 /* Initialize the debugger */
114 /* Output a warning about the driver that is needed */
117 /* Clear the screen, set white on black */
118 (void) bordercolor (COLOR_BLACK);
119 (void) bgcolor (COLOR_BLACK);
120 (void) textcolor (COLOR_GRAY3);
124 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
125 /* Copy the sprite data */
126 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
128 /* Set the VIC sprite pointer */
129 *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
131 /* Set the color of sprite 0 */
133 pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
135 VIC.spr0_color = COLOR_WHITE;
140 /* Load and install the mouse driver */
141 CheckError ("mouse_load_driver",
142 mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
144 /* Get the initial mouse bounding box */
145 mouse_getbox (&full_box);
147 /* Print a help line */
149 cputsxy (0, 0, "d)ebug h)ide q)uit s)how j)ail ");
156 ShowState (Jailed, Invisible);
159 /* Get the current mouse coordinates and button states and print them */
162 cprintf ("X = %3d", info.pos.x);
164 cprintf ("Y = %3d", info.pos.y);
166 cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
168 cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
170 /* Handle user input */
172 switch (tolower (cgetc ())) {
179 ShowState (Jailed, ++Invisible);
186 mouse_setbox (&full_box);
189 small_box.minx = max (info.pos.x - 10, full_box.minx);
190 small_box.miny = max (info.pos.y - 10, full_box.miny);
191 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
192 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
193 mouse_setbox (&small_box);
195 ShowState (Jailed, Invisible);
200 ShowState (Jailed, --Invisible);
213 /* Uninstall and unload the mouse driver */
214 CheckError ("mouse_unload", mouse_unload ());
218 cputs ("Goodbye!\r\n");