Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / term / morse.c
blob13b8e863e339b2c1c1205312d655fee7af004a6a
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2011,2012,2013 Free Software Foundation, Inc.
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.
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.
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/>.
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>
27 GRUB_MOD_LICENSE ("GPLv3+");
29 #define BASE_TIME 250
30 #define DIH 1
31 #define DAH 3
32 #define END 0
34 static const char codes[0x80][6] =
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 }
74 static void
75 grub_audio_tone (int length)
77 grub_speaker_beep_on (1000);
78 grub_millisleep (length);
79 grub_speaker_beep_off ();
82 static void
83 grub_audio_putchar (struct grub_term_output *term __attribute__ ((unused)),
84 const struct grub_unicode_glyph *c_in)
86 grub_uint8_t c;
87 int i;
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++)
96 grub_audio_tone (codes[c][i] * BASE_TIME);
97 grub_millisleep (BASE_TIME);
99 grub_millisleep (2 * BASE_TIME);
103 static int
104 dummy (void)
106 return 0;
109 static struct grub_term_output grub_audio_term_output =
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
125 GRUB_MOD_INIT (morse)
127 grub_term_register_output ("audio", &grub_audio_term_output);
130 GRUB_MOD_FINI (morse)
132 grub_term_unregister_output (&grub_audio_term_output);