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__) || defined(__CBM510__)
22 /* Address of data for sprite 0 */
24 # define SPRITE0_DATA 0x0340
25 # define SPRITE0_PTR 0x07F8
26 # define DRIVER "c64-1351.mou"
27 #elif defined(__C128__)
28 # define SPRITE0_DATA 0x0E00
29 # define SPRITE0_PTR 0x07F8
30 # define DRIVER "c128-1351.mou"
31 #elif defined(__CBM510__)
32 # define SPRITE0_DATA 0xF400
33 # define SPRITE0_PTR 0xF3F8
34 # define DRIVER "" /* Currently unavailable */
37 /* The mouse sprite (an arrow) */
38 static const unsigned char MouseSprite[64] = {
63 #endif /* __C64__ or __C128__ */
66 # define DRIVER "a2.stdmou.mou"
70 # define DRIVER "a2e.stdmou.mou"
75 static void CheckError (const char* S, unsigned char Error)
77 if (Error != MOUSE_ERR_OK) {
78 printf ("%s: %s(%d)\n", S, mouse_geterrormsg (Error), Error);
85 static void DoWarning (void)
86 /* Warn the user that a mouse driver is needed for this program */
88 printf ("Warning: This program needs the mouse\n"
89 "driver with the name\n"
91 "on disk! Press 'y' if you have it or\n"
92 "any other key to exit.\n", DRIVER);
93 if (tolower (cgetc ()) != 'y') {
96 printf ("Ok. Please wait patiently...\n");
101 static void ShowState (unsigned char Invisible)
102 /* Display cursor visibility */
107 cprintf ("Mouse cursor %svisible", Invisible? "in" : "");
114 struct mouse_info info;
115 unsigned char Invisible;
118 /* Initialize the debugger */
121 /* Output a warning about the driver that is needed */
124 /* Clear the screen, set white on black */
125 (void) bordercolor (COLOR_BLACK);
126 (void) bgcolor (COLOR_BLACK);
127 (void) textcolor (COLOR_GRAY3);
131 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
132 /* Copy the sprite data */
133 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
135 /* Set the VIC sprite pointer */
136 *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
138 /* Set the color of sprite 0 */
140 pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
142 VIC.spr0_color = COLOR_WHITE;
147 /* Load and install the mouse driver */
148 CheckError ("mouse_load_driver", mouse_load_driver (&mouse_def_callbacks, DRIVER));
150 /* Print a help line */
152 cputsxy (0, 0, "d: debug h: hide q: quit s: show ");
157 ShowState (Invisible = 1);
160 switch (tolower (cgetc ())) {
165 ShowState (++Invisible);
170 ShowState (--Invisible);
180 /* Get the current mouse coordinates and button states and print them */
183 cprintf ("X = %3d", info.pos.x);
185 cprintf ("Y = %3d", info.pos.y);
187 cprintf ("LB = %c", (info.buttons & MOUSE_BTN_LEFT)? '1' : '0');
189 cprintf ("RB = %c", (info.buttons & MOUSE_BTN_RIGHT)? '1' : '0');
193 /* Uninstall and unload the mouse driver */
194 CheckError ("mouse_unload", mouse_unload ());
198 cputs ("Goodbye!\r\n");