2 * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari/Apple2
4 * Ullrich von Bassewitz, 13.09.2001
19 #if defined(__C64__) || defined(__C128__)
21 /* Address of data for sprite 0 */
23 # define SPRITE0_DATA 0x0340
24 # define SPRITE0_PTR 0x07F8
25 #elif defined(__C128__)
26 # define SPRITE0_DATA 0x0E00
27 # define SPRITE0_PTR 0x07F8
30 /* The mouse sprite (an arrow) */
31 static const unsigned char MouseSprite[64] = {
56 #endif /* __C64__ or __C128__ */
59 /* Dynamically loaded driver by default */
65 #define max(a,b) (((a) > (b)) ? (a) : (b))
66 #define min(a,b) (((a) < (b)) ? (a) : (b))
70 static void CheckError (const char* S, unsigned char Error)
72 if (Error != MOUSE_ERR_OK) {
73 cprintf ("%s: %s(%d)\r\n", S, mouse_geterrormsg (Error), Error);
80 static void DoWarning (void)
81 /* Warn the user that a mouse driver is needed for this program */
83 cprintf ("Warning: This program needs the mouse\r\n"
84 "driver with the name\r\n"
86 "on disk! Press 'y' if you have it or\r\n"
87 "any other key to exit.\r\n", mouse_stddrv);
88 if (tolower (cgetc ()) != 'y') {
91 cprintf ("Ok. Please wait patiently...\r\n");
96 static void ShowState (unsigned char Jailed, unsigned char Invisible)
97 /* Display jail and cursor state */
102 cprintf ("Mouse cursor %svisible%s", Invisible? "in" : "", Jailed? ", jailed" : "");
109 struct mouse_info info;
110 struct mouse_box full_box;
111 struct mouse_box small_box;
112 unsigned char Invisible;
114 unsigned char Jailed;
116 /* Initialize the debugger */
119 /* Clear the screen, set white on black */
120 (void) bordercolor (COLOR_BLACK);
121 (void) bgcolor (COLOR_BLACK);
122 (void) textcolor (COLOR_GRAY3);
126 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
127 /* Copy the sprite data */
128 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
130 /* Set the VIC sprite pointer */
131 *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
133 /* Set the color of sprite 0 */
135 pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
137 VIC.spr0_color = COLOR_WHITE;
143 /* Output a warning about the driver that is needed */
146 /* Load and install the mouse driver */
147 CheckError ("mouse_load_driver",
148 mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
150 /* Install the mouse driver */
151 CheckError ("mouse_install",
152 mouse_install (&mouse_def_callbacks, mouse_static_stddrv));
155 /* Get the initial mouse bounding box */
156 mouse_getbox (&full_box);
158 /* Print a help line */
161 cputsxy (0, 0, "d)ebug h)ide q)uit s)how j)ail ");
168 ShowState (Jailed, Invisible);
171 /* Get the current mouse coordinates and button states and print them */
174 cprintf ("X = %3d", info.pos.x);
176 cprintf ("Y = %3d", info.pos.y);
178 cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
180 cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
182 /* Handle user input */
184 switch (tolower (cgetc ())) {
191 ShowState (Jailed, ++Invisible);
198 mouse_setbox (&full_box);
201 small_box.minx = max (info.pos.x - 10, full_box.minx);
202 small_box.miny = max (info.pos.y - 10, full_box.miny);
203 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
204 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
205 mouse_setbox (&small_box);
207 ShowState (Jailed, Invisible);
212 ShowState (Jailed, --Invisible);
226 /* Uninstall and unload the mouse driver */
227 CheckError ("mouse_unload", mouse_unload ());
229 /* Uninstall the mouse driver */
230 CheckError ("mouse_uninstall", mouse_uninstall ());
235 cputs ("Goodbye!\r\n");