2 ** Calibrate lightpen drivers to the current video hardware.
4 ** 2013-07-25, Greg King
14 #define COMMAND1 "Adjust by clicking on line."
15 #define COMMAND2 "Finish by clicking off bar."
19 ** There is a delay between when the VIC sends its signal, and when the display
20 ** shows that signal. There is another delay between the display and when
21 ** the lightpen says that it saw that signal. Each display and pen is different.
22 ** Therefore, the driver must be calibrated to them. A white bar is painted on
23 ** the screen; and, a line is drawn down the middle of it. When the user clicks
24 ** on that line, the difference between its position and where the VIC thinks
25 ** that the pen is pointing becomes an offset that is subtracted from what the
28 void __fastcall__ pen_calibrate (unsigned char *XOffset)
30 unsigned char oldBg = bgcolor (COLOR_BLUE);
31 unsigned char oldText = textcolor (COLOR_GRAY3);
32 unsigned char oldRev = revers (1);
33 unsigned char sprite0Color = VIC.spr_color[0];
34 unsigned char width, width2, height, height4, height8;
35 struct mouse_info info;
37 screensize (&width, &height);
40 height8 = height4 * 8;
42 /* Draw a bar and line. */
45 cclearxy (0, height4, height4 * width);
46 cvlinexy (width2, height4 + 1, height4 - 2);
49 /* Print instructions. */
51 cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1);
52 cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2);
54 VIC.spr_color[0] = COLOR_GRAY2;
56 mouse_move (width2 * 8, height8 / 2);
59 /* Wait for the main button to be released. */
61 do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
63 /* Wait for the main button to be pressed. */
67 } while (!(info.buttons & MOUSE_BTN_LEFT));
69 /* Find out if the pen is on or off the bar. */
71 if (info.pos.y < height8 || info.pos.y >= height8 * 2) {
75 /* On the bar; adjust the offset. */
76 /* Characters are eight pixels wide.
77 ** The VIC-II sees every other pixel;
78 ** so, we use half of the difference.
81 *XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2;
84 /* Off the bar; wait for the main button to be released. */
86 do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
89 VIC.spr_color[0] = sprite0Color;