summaryrefslogtreecommitdiff
path: root/firmware/c1224/src/common/banner.c
blob: 59eb5dd804b48c8c18007e3b4cfc932be477338e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Fixed boot banner — edit source only; not INI / CDC.
 * Always printed once after USB CDC ready (main); quiet never suppresses it.
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include "banner.h"
#include "version.h"
#include "afsk_bitbang.h"
#include <stdio.h>
#include <string.h>

/* Fixed CDC column width for centered serial look (40–48). */
#define BANNER_WIDTH 44

/** Display columns (UTF-8 code points ≈ 1 col; ASCII-safe). */
static size_t banner_cols(const char *s)
{
    size_t cols = 0;
    while (*s) {
        unsigned char c = (unsigned char)*s++;
        if ((c & 0x80u) == 0u) {
            cols++;
        } else if ((c & 0xE0u) == 0xC0u) {
            if (*s) {
                s++;
            }
            cols++;
        } else if ((c & 0xF0u) == 0xE0u) {
            if (*s) {
                s++;
            }
            if (*s) {
                s++;
            }
            cols++;
        } else if ((c & 0xF8u) == 0xF0u) {
            if (*s) {
                s++;
            }
            if (*s) {
                s++;
            }
            if (*s) {
                s++;
            }
            cols++;
        } else {
            cols++;
        }
    }
    return cols;
}

static void banner_line(const char *text)
{
    size_t cols = banner_cols(text);
    size_t pad = 0;
    if (cols < BANNER_WIDTH) {
        pad = (BANNER_WIDTH - cols) / 2u;
    }
    for (size_t i = 0; i < pad; i++) {
        putchar(' ');
    }
    fputs(text, stdout);
    fputs("\r\n", stdout);
}

void banner_print(void)
{
    /* Fixed boot banner — edit source only */
    char line[BANNER_WIDTH + 8];

    snprintf(line, sizeof(line), "T-Modem-c1224 %s", C1224_FW_VERSION);
    banner_line(line);

    snprintf(line, sizeof(line), "USB KISS Half-TNC · AFSK %u",
             (unsigned)afsk_bitrate());
    banner_line(line);

    banner_line("Non-Profit · GNU GPLv3 · AS-IS");
    banner_line("https://github.com/ngteq");
}
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com