diff --git a/20230530/morse-02.c b/20230530/morse-02.c new file mode 100644 index 0000000000000000000000000000000000000000..85fb671b84b66662e233c58e63e4fd752e09f523 --- /dev/null +++ b/20230530/morse-02.c @@ -0,0 +1,99 @@ +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +static const char *morse[256] = { + ['0'] = "-----", + ['1'] = ".----", + ['2'] = "..---", + ['3'] = "...--", + ['4'] = "....-", + ['5'] = ".....", + ['6'] = "-....", + ['7'] = "--...", + ['8'] = "---..", + ['9'] = "----.", + ['A'] = ".-", + ['B'] = "-...", + ['C'] = "-.-.", + ['D'] = "-..", + ['E'] = ".", + ['F'] = "..-.", + ['G'] = "--.", + ['H'] = "....", + ['I'] = "..", + ['J'] = ".---", + ['K'] = "-.-", + ['L'] = ".-..", + ['M'] = "--", + ['N'] = "-.", + ['O'] = "---", + ['P'] = ".--.", + ['Q'] = "--.-", + ['R'] = ".-.", + ['S'] = "...", + ['T'] = "-", + ['U'] = "..-", + ['V'] = "...-", + ['W'] = ".--", + ['X'] = "-..-", + ['Y'] = "-.--", + ['Z'] = "--..", + ['a'] = ".-", + ['b'] = "-...", + ['c'] = "-.-.", + ['d'] = "-..", + ['e'] = ".", + ['f'] = "..-.", + ['g'] = "--.", + ['h'] = "....", + ['i'] = "..", + ['j'] = ".---", + ['k'] = "-.-", + ['l'] = ".-..", + ['m'] = "--", + ['n'] = "-.", + ['o'] = "---", + ['p'] = ".--.", + ['q'] = "--.-", + ['r'] = ".-.", + ['s'] = "...", + ['t'] = "-", + ['u'] = "..-", + ['v'] = "...-", + ['w'] = ".--", + ['x'] = "-..-", + ['y'] = "-.--", + ['z'] = "--.." +}; + +int main (void) +{ + for (int c = 0; c < 128; c++) + { + uint8_t bits = 0; + uint8_t mask = 1; + const char *p = morse[c]; + if (p) + { + while (*p) + { + if (*p == '-') + bits |= mask; + mask <<= 1; + p++; + } + } + printf (" 0x%02x,", bits); + } + printf ("\n"); + for (int c = 0; c < 128; c++) + { + const char *p = morse[c]; + if (p) + printf (" %zu,", strlen (p)); + else + printf (" 0,"); + } + printf ("\n"); +} diff --git a/20230530/morse-03.c b/20230530/morse-03.c new file mode 100644 index 0000000000000000000000000000000000000000..e19e0769a0e53e584cc929638c35e1023c0ebbdf --- /dev/null +++ b/20230530/morse-03.c @@ -0,0 +1,53 @@ +#include <stdio.h> +#include <stdint.h> + +uint8_t morse_bits[128] = +{ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x01, 0x03, + 0x07, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03, + 0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07, + 0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06, + 0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03, + 0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07, + 0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06, + 0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +uint8_t morse_length[128] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, + 0, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3, + 4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 0, + 0, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3, + 4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 0 +}; + +int main (void) +{ + for (int c = 0; c < 128; c++) + if (morse_length[c]) + { + printf (" ['%c'] = \"", c); + uint8_t bits = morse_bits[c]; + uint8_t mask = 1; + int l = morse_length[c]; + for (int i = 0; i < l; i++) + if (bits & mask) + printf ("-"); + else + printf ("."); + printf ("\",\n"); + } + return 0; +} diff --git a/20230530/morse-04.c b/20230530/morse-04.c new file mode 100644 index 0000000000000000000000000000000000000000..a6a734543644f3111eb6f04e0495f0ca6cbd3c0d --- /dev/null +++ b/20230530/morse-04.c @@ -0,0 +1,62 @@ + ['0'] = "-----", + ['1'] = ".....", + ['2'] = ".....", + ['3'] = ".....", + ['4'] = ".....", + ['5'] = ".....", + ['6'] = "-----", + ['7'] = "-----", + ['8'] = "-----", + ['9'] = "-----", + ['A'] = "..", + ['B'] = "----", + ['C'] = "----", + ['D'] = "---", + ['E'] = ".", + ['F'] = "....", + ['G'] = "---", + ['H'] = "....", + ['I'] = "..", + ['J'] = "....", + ['K'] = "---", + ['L'] = "....", + ['M'] = "--", + ['N'] = "--", + ['O'] = "---", + ['P'] = "....", + ['Q'] = "----", + ['R'] = "...", + ['S'] = "...", + ['T'] = "-", + ['U'] = "...", + ['V'] = "....", + ['W'] = "...", + ['X'] = "----", + ['Y'] = "----", + ['Z'] = "----", + ['a'] = "..", + ['b'] = "----", + ['c'] = "----", + ['d'] = "---", + ['e'] = ".", + ['f'] = "....", + ['g'] = "---", + ['h'] = "....", + ['i'] = "..", + ['j'] = "....", + ['k'] = "---", + ['l'] = "....", + ['m'] = "--", + ['n'] = "--", + ['o'] = "---", + ['p'] = "....", + ['q'] = "----", + ['r'] = "...", + ['s'] = "...", + ['t'] = "-", + ['u'] = "...", + ['v'] = "....", + ['w'] = "...", + ['x'] = "----", + ['y'] = "----", + ['z'] = "----",