]> git.proxmox.com Git - grub2.git/blob - grub-core/term/morse.c
Import grub2_2.02+dfsg1.orig.tar.xz
[grub2.git] / grub-core / term / morse.c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2011,2012,2013 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <grub/term.h>
20 #include <grub/misc.h>
21 #include <grub/types.h>
22 #include <grub/err.h>
23 #include <grub/dl.h>
24 #include <grub/time.h>
25 #include <grub/speaker.h>
26
27 GRUB_MOD_LICENSE ("GPLv3+");
28
29 #define BASE_TIME 250
30 #define DIH 1
31 #define DAH 3
32 #define END 0
33
34 static const char codes[0x80][6] =
35 {
36 ['0'] = { DAH, DAH, DAH, DAH, DAH, END },
37 ['1'] = { DIH, DAH, DAH, DAH, DAH, END },
38 ['2'] = { DIH, DIH, DAH, DAH, DAH, END },
39 ['3'] = { DIH, DIH, DIH, DAH, DAH, END },
40 ['4'] = { DIH, DIH, DIH, DIH, DAH, END },
41 ['5'] = { DIH, DIH, DIH, DIH, DIH, END },
42 ['6'] = { DAH, DIH, DIH, DIH, DIH, END },
43 ['7'] = { DAH, DAH, DIH, DIH, DIH, END },
44 ['8'] = { DAH, DAH, DAH, DIH, DIH, END },
45 ['9'] = { DAH, DAH, DAH, DAH, DIH, END },
46 ['a'] = { DIH, DAH, END },
47 ['b'] = { DAH, DIH, DIH, DIH, END },
48 ['c'] = { DAH, DIH, DAH, DIH, END },
49 ['d'] = { DAH, DIH, DIH, END },
50 ['e'] = { DIH, END },
51 ['f'] = { DIH, DIH, DAH, DIH, END },
52 ['g'] = { DAH, DAH, DIH, END },
53 ['h'] = { DIH, DIH, DIH, DIH, END },
54 ['i'] = { DIH, DIH, END },
55 ['j'] = { DIH, DAH, DAH, DAH, END },
56 ['k'] = { DAH, DIH, DAH, END },
57 ['l'] = { DIH, DAH, DIH, DIH, END },
58 ['m'] = { DAH, DAH, END },
59 ['n'] = { DAH, DIH, END },
60 ['o'] = { DAH, DAH, DAH, END },
61 ['p'] = { DIH, DAH, DAH, DIH, END },
62 ['q'] = { DAH, DAH, DIH, DAH, END },
63 ['r'] = { DIH, DAH, DIH, END },
64 ['s'] = { DIH, DIH, DIH, END },
65 ['t'] = { DAH, END },
66 ['u'] = { DIH, DIH, DAH, END },
67 ['v'] = { DIH, DIH, DIH, DAH, END },
68 ['w'] = { DIH, DAH, DAH, END },
69 ['x'] = { DAH, DIH, DIH, DAH, END },
70 ['y'] = { DAH, DIH, DAH, DAH, END },
71 ['z'] = { DAH, DAH, DIH, DIH, END }
72 };
73
74 static void
75 grub_audio_tone (int length)
76 {
77 grub_speaker_beep_on (1000);
78 grub_millisleep (length);
79 grub_speaker_beep_off ();
80 }
81
82 static void
83 grub_audio_putchar (struct grub_term_output *term __attribute__ ((unused)),
84 const struct grub_unicode_glyph *c_in)
85 {
86 grub_uint8_t c;
87 int i;
88
89 /* For now, do not try to use a surrogate pair. */
90 if (c_in->base > 0x7f)
91 c = '?';
92 else
93 c = grub_tolower (c_in->base);
94 for (i = 0; codes[c][i]; i++)
95 {
96 grub_audio_tone (codes[c][i] * BASE_TIME);
97 grub_millisleep (BASE_TIME);
98 }
99 grub_millisleep (2 * BASE_TIME);
100 }
101
102
103 static int
104 dummy (void)
105 {
106 return 0;
107 }
108
109 static struct grub_term_output grub_audio_term_output =
110 {
111 .name = "morse",
112 .init = (void *) dummy,
113 .fini = (void *) dummy,
114 .putchar = grub_audio_putchar,
115 .getwh = (void *) dummy,
116 .getxy = (void *) dummy,
117 .gotoxy = (void *) dummy,
118 .cls = (void *) dummy,
119 .setcolorstate = (void *) dummy,
120 .setcursor = (void *) dummy,
121 .flags = GRUB_TERM_CODE_TYPE_ASCII | GRUB_TERM_DUMB,
122 .progress_update_divisor = GRUB_PROGRESS_NO_UPDATE
123 };
124
125 GRUB_MOD_INIT (morse)
126 {
127 grub_term_register_output ("audio", &grub_audio_term_output);
128 }
129
130 GRUB_MOD_FINI (morse)
131 {
132 grub_term_unregister_output (&grub_audio_term_output);
133 }