/* * VasEBoot -- GRand Unified Bootloader * Copyright (C) 2011,2012,2013 Free Software Foundation, Inc. * * VasEBoot is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VasEBoot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VasEBoot. If not, see . */ #include #include #include #include #include #include #include VasEBoot_MOD_LICENSE ("GPLv3+"); #define BASE_TIME 250 #define DIH 1 #define DAH 3 #define END 0 static const char codes[0x80][6] = { ['0'] = { DAH, DAH, DAH, DAH, DAH, END }, ['1'] = { DIH, DAH, DAH, DAH, DAH, END }, ['2'] = { DIH, DIH, DAH, DAH, DAH, END }, ['3'] = { DIH, DIH, DIH, DAH, DAH, END }, ['4'] = { DIH, DIH, DIH, DIH, DAH, END }, ['5'] = { DIH, DIH, DIH, DIH, DIH, END }, ['6'] = { DAH, DIH, DIH, DIH, DIH, END }, ['7'] = { DAH, DAH, DIH, DIH, DIH, END }, ['8'] = { DAH, DAH, DAH, DIH, DIH, END }, ['9'] = { DAH, DAH, DAH, DAH, DIH, END }, ['a'] = { DIH, DAH, END }, ['b'] = { DAH, DIH, DIH, DIH, END }, ['c'] = { DAH, DIH, DAH, DIH, END }, ['d'] = { DAH, DIH, DIH, END }, ['e'] = { DIH, END }, ['f'] = { DIH, DIH, DAH, DIH, END }, ['g'] = { DAH, DAH, DIH, END }, ['h'] = { DIH, DIH, DIH, DIH, END }, ['i'] = { DIH, DIH, END }, ['j'] = { DIH, DAH, DAH, DAH, END }, ['k'] = { DAH, DIH, DAH, END }, ['l'] = { DIH, DAH, DIH, DIH, END }, ['m'] = { DAH, DAH, END }, ['n'] = { DAH, DIH, END }, ['o'] = { DAH, DAH, DAH, END }, ['p'] = { DIH, DAH, DAH, DIH, END }, ['q'] = { DAH, DAH, DIH, DAH, END }, ['r'] = { DIH, DAH, DIH, END }, ['s'] = { DIH, DIH, DIH, END }, ['t'] = { DAH, END }, ['u'] = { DIH, DIH, DAH, END }, ['v'] = { DIH, DIH, DIH, DAH, END }, ['w'] = { DIH, DAH, DAH, END }, ['x'] = { DAH, DIH, DIH, DAH, END }, ['y'] = { DAH, DIH, DAH, DAH, END }, ['z'] = { DAH, DAH, DIH, DIH, END } }; static void VasEBoot_audio_tone (int length) { VasEBoot_speaker_beep_on (1000); VasEBoot_millisleep (length); VasEBoot_speaker_beep_off (); } static void VasEBoot_audio_putchar (struct VasEBoot_term_output *term __attribute__ ((unused)), const struct VasEBoot_unicode_glyph *c_in) { VasEBoot_uint8_t c; int i; /* For now, do not try to use a surrogate pair. */ if (c_in->base > 0x7f) c = '?'; else c = VasEBoot_tolower (c_in->base); for (i = 0; codes[c][i]; i++) { VasEBoot_audio_tone (codes[c][i] * BASE_TIME); VasEBoot_millisleep (BASE_TIME); } VasEBoot_millisleep (2 * BASE_TIME); } static int dummy (void) { return 0; } static struct VasEBoot_term_output VasEBoot_audio_term_output = { .name = "morse", .init = (void *) dummy, .fini = (void *) dummy, .putchar = VasEBoot_audio_putchar, .getwh = (void *) dummy, .getxy = (void *) dummy, .gotoxy = (void *) dummy, .cls = (void *) dummy, .setcolorstate = (void *) dummy, .setcursor = (void *) dummy, .flags = VasEBoot_TERM_CODE_TYPE_ASCII | VasEBoot_TERM_DUMB, .progress_update_divisor = VasEBoot_PROGRESS_NO_UPDATE }; VasEBoot_MOD_INIT (morse) { VasEBoot_term_register_output ("audio", &VasEBoot_audio_term_output); } VasEBoot_MOD_FINI (morse) { VasEBoot_term_unregister_output (&VasEBoot_audio_term_output); }