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