2 * Demo program for mouse usage. Will work for the C64/C128/CBM510/Atari
4 * Ullrich von Bassewitz, 13.09.2001
19 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
21 /* Address of data for sprite 0 */
23 # define SPRITE0_DATA 0x0340
24 # define SPRITE0_PTR 0x07F8
25 # define DRIVER "c64-1351.mou"
26 #elif defined(__C128__)
27 # define SPRITE0_DATA 0x0E00
28 # define SPRITE0_PTR 0x07F8
29 # define DRIVER "c128-1351.mou"
30 #elif defined(__CBM510__)
31 # define SPRITE0_DATA 0xF400
32 # define SPRITE0_PTR 0xF3F8
33 # define DRIVER "" /* Currently unavailable */
36 /* The mouse sprite (an arrow) */
37 static const unsigned char MouseSprite[64] = {
62 #endif /* __C64__ or __C128__ */
66 static void CheckError (const char* S, unsigned char Error)
68 if (Error != MOUSE_ERR_OK) {
69 printf ("%s: %s(%d)\n", S, mouse_geterrormsg (Error), Error);
76 static void DoWarning (void)
77 /* Warn the user that a mouse driver is needed for this program */
79 printf ("Warning: This program needs the mouse\n"
80 "driver with the name\n"
82 "on disk! Press 'y' if you have it or\n"
83 "any other key to exit.\n", DRIVER);
84 if (cgetc () != 'y') {
87 printf ("Ok. Please wait patiently...\n");
92 static void ShowState (unsigned char Invisible)
93 /* Display cursor visibility */
98 cprintf ("Mouse cursor %svisible", Invisible? "in" : "");
105 struct mouse_info info;
106 unsigned char Invisible;
109 /* Initialize the debugger */
112 /* Output a warning about the driver that is needed */
115 /* Clear the screen, set white on black */
116 bordercolor (COLOR_BLACK);
117 bgcolor (COLOR_BLACK);
118 textcolor (COLOR_GRAY3);
122 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
123 /* Copy the sprite data */
124 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
126 /* Set the VIC sprite pointer */
127 *(unsigned char*)SPRITE0_PTR = SPRITE0_DATA / 64;
129 /* Set the color of sprite 0 */
131 pokebsys ((unsigned) &VIC.spr0_color, COLOR_WHITE);
133 VIC.spr0_color = COLOR_WHITE;
138 /* Load and install the mouse driver */
139 CheckError ("mouse_load_driver", mouse_load_driver (&mouse_def_callbacks, DRIVER));
141 /* Print a help line */
143 cputsxy (0, 0, "d: debug h: hide q: quit s: show ");
148 ShowState (Invisible = 1);
156 ShowState (++Invisible);
161 ShowState (--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');
184 /* Uninstall and unload the mouse driver */
185 CheckError ("mouse_unload", mouse_unload ());
189 cputs ("Goodbye!\r\n");