2 ** Test/demo program for mouse usage.
3 ** Will work for the C64/C128/CBM510/Atari/Apple2.
5 ** 2001-09-13, Ullrich von Bassewitz
6 ** 2013-09-05, Greg King
21 #define max(a,b) (((a) > (b)) ? (a) : (b))
22 #define min(a,b) (((a) < (b)) ? (a) : (b))
28 /* A statically linked driver was named on the compiler's command line.
29 ** Make sure that it is used instead of a dynamic one.
37 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
39 /* Addresses of data for sprite 0 */
41 # define SPRITE0_DATA ((unsigned char[64])0x0340)
42 # define SPRITE0_PTR ((unsigned char *)0x07F8)
43 #elif defined(__C128__)
44 # define SPRITE0_DATA ((unsigned char[64])0x0E00)
45 # define SPRITE0_PTR ((unsigned char *)0x07F8)
46 #elif defined(__CBM510__)
47 # define SPRITE0_DATA ((unsigned char[64])0xF400)
48 # define SPRITE0_PTR ((unsigned char *)0xF3F8)
51 /* The mouse sprite (an arrow) */
52 static const unsigned char MouseSprite[64] = {
79 static void __fastcall__ CheckError (const char* S, unsigned char Error)
81 if (Error != MOUSE_ERR_OK) {
82 cprintf ("\n%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
84 /* Wait for a key-press, so that some platforms can show the error
85 ** message before they remove the current screen.
96 /* Points to the dynamic driver's name. */
97 static const char *mouse_name;
101 static void DoWarning (void)
102 /* Warn the user that a driver is needed for this program. */
104 cprintf ("Warning: This program needs\r\n"
105 "the driver with the name\r\n"
107 "on a disk! Press 'y' if you have it;\r\n"
108 "or, any other key to exit.\r\n", mouse_stddrv);
109 if (tolower (cgetc ()) != 'y') {
112 cprintf ("OK. Please wait patiently...\r\n");
118 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
119 /* Display jail and cursor states. */
123 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
129 int main (int argc, char *argv[])
134 struct mouse_info info;
135 struct mouse_box full_box, small_box;
136 unsigned char width, height;
138 bool Invisible = true, Done = false, Jailed = false;
140 /* Initialize the debugger */
143 /* Set dark-on-light colors. Clear the screen. */
145 (void) bordercolor (COLOR_GRAY2);
146 (void) bgcolor (COLOR_WHITE);
147 (void) textcolor (COLOR_GRAY1);
149 (void) bordercolor (COLOR_BLUE);
150 (void) bgcolor (COLOR_WHITE);
151 (void) textcolor (COLOR_BLACK);
156 /* The pointer should be created before the driver is installed,
157 ** in case a lightpen driver needs it during calibration.
160 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
161 /* Copy the sprite data */
162 memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite));
164 /* Set the VIC-II sprite pointer. */
165 *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
167 /* Set the color of sprite 0 */
169 pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK);
171 VIC.spr0_color = COLOR_BLACK;
175 /* If a lightpen driver is installed, then it can get a calibration value
176 ** from this file (if it exists). Or, the user can adjust the pen; and,
177 ** the value will be put into this file, for the next time.
178 ** (Other drivers will ignore this.)
180 #if defined(__C64__) || defined(__C128__) || defined(__CBM510__)
181 pen_adjust ("pen.dat");
185 /* If a dynamically loadable driver is named on the command line,
186 ** then use that driver instead of the standard one.
189 mouse_name = argv[1];
191 /* Output a warning about the standard driver that is needed. */
193 mouse_name = mouse_stddrv;
196 /* Load and install the driver. */
197 CheckError ("mouse_load_driver",
198 mouse_load_driver (&mouse_def_callbacks, mouse_name));
200 /* Install the driver. */
201 CheckError ("mouse_install",
202 mouse_install (&mouse_def_callbacks,
211 /* Get the initial bounding box. */
212 mouse_getbox (&full_box);
214 screensize (&width, &height);
219 /* Print a help line */
220 cputs (" d)ebug h)ide q)uit s)how j)ail");
222 /* Put a cross at the center of the screen. */
223 gotoxy (width / 2 - 3, height / 2 - 1);
225 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
228 cprintf ("%3u,%3u\r\n%*s+", width / 2 * 8 + 4, height / 2 * 8 + 4,
233 ShowState (Jailed, Invisible);
235 /* Get the current co-ordinates and button states; and, print them. */
238 cprintf (" X = %3d\r\n", info.pos.x);
239 cprintf (" Y = %3d\r\n", info.pos.y);
240 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
247 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
255 /* Handle user input */
258 switch (tolower (C = cgetc ())) {
262 /* The debugger might have changed the colors.
266 (void) bordercolor (COLOR_GRAY2);
267 (void) bgcolor (COLOR_WHITE);
268 (void) textcolor (COLOR_GRAY1);
270 (void) bordercolor (COLOR_BLUE);
271 (void) bgcolor (COLOR_WHITE);
272 (void) textcolor (COLOR_BLACK);
275 /* The debugger changed the screen; restore it. */
280 ShowState (Jailed, ++Invisible);
285 mouse_setbox (&full_box);
288 small_box.minx = max (info.pos.x - 10, full_box.minx);
289 small_box.miny = max (info.pos.y - 10, full_box.miny);
290 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
291 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
292 mouse_setbox (&small_box);
295 ShowState (Jailed, Invisible);
301 ShowState (Jailed, --Invisible);
311 cprintf ("Spurious character: $%02X", C);
317 /* Uninstall and unload the driver. */
318 CheckError ("mouse_unload", mouse_unload ());
320 /* Uninstall the static driver. */
321 CheckError ("mouse_uninstall", mouse_uninstall ());
325 cputsxy (0, height / 2 + 3, "Goodbye!");