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 Jailed, unsigned char Invisible)
88 /* Display jail and cursor state */
93 cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : "");
100 struct mouse_info info;
101 struct mouse_box full_box;
102 struct mouse_box small_box;
103 unsigned char Invisible;
105 unsigned char Jailed;
107 /* Initialize the debugger */
110 /* Output a warning about the driver that is needed */
113 /* Clear the screen, set white on black */
114 (void) bordercolor (COLOR_BLACK);
115 (void) bgcolor (COLOR_BLACK);
116 (void) textcolor (COLOR_GRAY3);
120 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
121 /* Copy the sprite data */
122 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
124 /* Set the VIC sprite pointer */
125 *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
127 /* Set the color of sprite 0 */
129 pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
131 VIC.spr0_color = COLOR_WHITE;
136 /* Load and install the mouse driver */
137 CheckError ("mouse_load_driver",
138 mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
140 /* Get the initial mouse bounding box */
141 mouse_getbox (&full_box);
143 /* Print a help line */
145 cputsxy (0, 0, "d)ebug h)ide q)uit s)how j)ail ");
152 ShowState (Jailed, Invisible);
155 /* Get the current mouse coordinates and button states and print them */
158 cprintf ("X = %3d", info.pos.x);
160 cprintf ("Y = %3d", info.pos.y);
162 cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
164 cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
166 /* Handle user input */
168 switch (tolower (cgetc ())) {
175 ShowState (Jailed, ++Invisible);
182 mouse_setbox (&full_box);
185 small_box.minx = info.pos.x - 10;
186 small_box.miny = info.pos.y - 10;
187 small_box.maxx = info.pos.x + 10;
188 small_box.maxy = info.pos.y + 10;
189 mouse_setbox (&small_box);
191 ShowState (Jailed, Invisible);
196 ShowState (Jailed, --Invisible);
209 /* Uninstall and unload the mouse driver */
210 CheckError ("mouse_unload", mouse_unload ());
214 cputs ("Goodbye!\r\n");