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."
18 /* There is a delay between when the VIC sends its signal, and when the display
19 ** shows that signal. There is another delay between the display and when the
20 ** lightpen says that it saw that signal. Each display and pen is different.
21 ** Therefore, the driver must be calibrated to them. A white bar is painted on
22 ** the screen; and, a line is drawn down the middle of it. When the user
23 ** clicks on that line, the difference between its position and where the VIC
24 ** thinks that the pen is pointing becomes an offset that is subtracted from
27 void __fastcall__ pen_calibrate (unsigned char *XOffset)
29 unsigned char oldBg = bgcolor (COLOR_BLUE);
30 unsigned char oldText = textcolor (COLOR_GRAY3);
31 unsigned char oldRev = revers (1);
32 unsigned char sprite0Color = VIC.spr_color[0];
33 unsigned char width, width2, height, height4, height8;
34 struct mouse_info info;
36 screensize (&width, &height);
39 height8 = height4 * 8;
41 /* Draw a bar and line. */
44 cclearxy (0, height4, height4 * width);
45 cvlinexy (width2, height4 + 1, height4 - 2);
47 /* Print instructions. */
50 cputsxy (width2 - (sizeof COMMAND1) / 2, height / 2 + 1, COMMAND1);
51 cputsxy (width2 - (sizeof COMMAND2) / 2, height / 2 + 3, COMMAND2);
53 VIC.spr_color[0] = COLOR_GRAY2;
55 mouse_move (width2 * 8, height8 / 2);
58 /* Wait for the main button to be released. */
60 do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
62 /* Wait for the main button to be pressed. */
66 } while (!(info.buttons & MOUSE_BTN_LEFT));
68 /* Find out if the pen is on or off the bar. */
70 if (info.pos.y < height8 || info.pos.y >= height8 * 2) {
74 /* On the bar; adjust the offset. */
75 /* Characters are eight pixels wide.
76 ** The VIC-II sees every other pixel;
77 ** so, we use half of the difference.
80 *XOffset += (info.pos.x - (width2 * 8 + 8/2)) / 2;
83 /* Off the bar; wait for the main button to be released. */
85 do ; while ((mouse_buttons () & MOUSE_BTN_LEFT));
88 VIC.spr_color[0] = sprite0Color;