2 ** Test program for lightpen drivers. Will work for the C64/C128.
4 ** 2001-09-13, Ullrich von Bassewitz
5 ** 2013-06-21, Greg King
19 #define max(a,b) (((a) > (b)) ? (a) : (b))
20 #define min(a,b) (((a) < (b)) ? (a) : (b))
24 /* Statically linked driver */
31 # define mouse_stddrv "c64-inkwell.mou"
33 # define mouse_static_stddrv c64_inkwell_mou
39 # define mouse_stddrv "c128-inkwell.mou"
41 # define mouse_static_stddrv c128_inkwell_mou
47 #if defined(__C64__) || defined(__C128__)
49 /* Addresses of data for sprite 0 */
51 # define SPRITE0_DATA ((unsigned char[64])0x0340)
52 # define SPRITE0_PTR ((unsigned char *)0x07F8)
53 #elif defined(__C128__)
54 # define SPRITE0_DATA ((unsigned char[64])0x0E00)
55 # define SPRITE0_PTR ((unsigned char *)0x07F8)
59 static const unsigned char PenSprite[64] = {
83 #endif /* __C64__ or __C128__ */
87 static void __fastcall__ CheckError (const char* S, unsigned char Error)
89 if (Error != MOUSE_ERR_OK) {
90 cprintf ("%s: %s(%u)\r\n", S, mouse_geterrormsg (Error), Error);
96 static void DoWarning (void)
97 /* Warn the user that a lightpen driver is needed for this program. */
99 cprintf ("Warning: This program needs a lightpen\r\n"
100 "driver with the name\r\n"
102 "on disk! Press 'y' if you have it; or,\r\n"
103 "any other key to exit.\r\n", mouse_stddrv);
104 if (tolower (cgetc ()) != 'y') {
107 cprintf ("OK. Please wait patiently...\r\n");
113 static void __fastcall__ ShowState (unsigned char Jailed, unsigned char Invisible)
114 /* Display jail and cursor states. */
118 cprintf ("Pointer is %svisible%s.", Invisible? "in" : "", Jailed? " and jailed" : "");
125 struct mouse_info info;
126 struct mouse_box full_box, small_box;
128 unsigned char width, height;
129 bool Invisible = false, Done = false, Jailed = false;
132 /* Only the VIC-IIe has a lightpen connection. */
133 videomode (VIDEOMODE_40x25);
136 /* Initiate the debugger. */
139 /* Set dark-on-light colors. Clear the screen. */
141 (void) bordercolor (COLOR_GRAY2);
142 (void) bgcolor (COLOR_WHITE);
143 (void) textcolor (COLOR_GRAY1);
145 (void) bordercolor (COLOR_BLUE);
146 (void) bgcolor (COLOR_WHITE);
147 (void) textcolor (COLOR_BLACK);
152 #if defined(__C64__) || defined(__C128__)
153 /* Copy the sprite data. */
154 memcpy (SPRITE0_DATA, PenSprite, sizeof PenSprite);
156 /* Set the VIC-II sprite pointer. */
157 *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA;
159 /* Set the color of sprite 0. */
160 VIC.spr0_color = COLOR_BLACK;
162 pen_adjust ("inkwell.dat");
166 /* Output a warning about the driver that is needed. */
169 /* Load and install the lightpen driver. */
170 CheckError ("mouse_load_driver",
171 mouse_load_driver (&mouse_def_callbacks, mouse_stddrv));
173 /* Install the lightpen driver. */
174 CheckError ("mouse_install",
175 mouse_install (&mouse_def_callbacks, mouse_static_stddrv));
178 /* Get the initial lightpen bounding box. */
179 mouse_getbox (&full_box);
181 screensize (&width, &height);
186 /* Print a help line. */
187 cputs (" d)ebug h)ide q)uit s)how j)ail");
189 /* Put a cross at the center of the screen. */
190 gotoxy (width / 2 - 3, height / 2 - 1);
191 cprintf ("%3u,%3u\r\n%*s\xDB", width / 2 * 8 + 4, height / 2 * 8 + 4,
194 /* Expose the arrow. */
196 ShowState (Jailed, Invisible);
200 /* Get the current lightpen co-ordinates and button states;
205 cprintf (" X = %3d\r\n", info.pos.x);
206 cprintf (" Y = %3d\r\n", info.pos.y);
207 cprintf (" B1 = %c\r\n", (info.buttons & MOUSE_BTN_LEFT) ?
214 cprintf (" B2 = %c", (info.buttons & MOUSE_BTN_RIGHT) ?
222 /* Handle user input. */
225 switch (tolower (C = cgetc ())) {
229 /* The debugger might have changed the colors.
233 (void) bordercolor (COLOR_GRAY2);
234 (void) bgcolor (COLOR_WHITE);
235 (void) textcolor (COLOR_GRAY1);
237 (void) bordercolor (COLOR_BLUE);
238 (void) bgcolor (COLOR_WHITE);
239 (void) textcolor (COLOR_BLACK);
245 ShowState (Jailed, ++Invisible);
250 mouse_setbox (&full_box);
253 small_box.minx = max (info.pos.x - 10, full_box.minx);
254 small_box.miny = max (info.pos.y - 10, full_box.miny);
255 small_box.maxx = min (info.pos.x + 10, full_box.maxx);
256 small_box.maxy = min (info.pos.y + 10, full_box.maxy);
257 mouse_setbox (&small_box);
260 ShowState (Jailed, Invisible);
266 ShowState (Jailed, --Invisible);
276 cprintf ("Spurious character: $%02X", C);
282 /* Uninstall and unload the lightpen driver. */
283 CheckError ("mouse_unload", mouse_unload ());
285 /* Uninstall the lightpen driver. */
286 CheckError ("mouse_uninstall", mouse_uninstall ());
290 cputsxy (0, height / 2 + 3, "Goodbye!");