summaryrefslogtreecommitdiff
path: root/src/main.c
blob: e4d3b4e9ed249f4941b3002b92ec9c7778c7b8bf (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
#define NB_COLS 80
#define NB_ROWS 25

#define VIDEO_BUFFER 0xB8000

/* XXX doest not always handle memory overlaps */
static void my_memmove(void *_dest, const void *_src, int n)
{
    char *dest = _dest;
    const char *src = _src;

    for (int i = 0; i < n; ++i) {
        dest[i] = src[i];
    }
}

static void my_memset(void *_dest, int c, int n)
{
    char *dest = _dest;

    for (int i = 0; i < n; ++i) {
        dest[i] = c;
    }
}

int printk(const char *str)
{
    static const long int offset = VIDEO_BUFFER;
    static char *addr = (char *) VIDEO_BUFFER;
    int count = 0;

    for (int i = 0; str[i]; ++i) {
        /* TODO add the serial port handling */

        if ((long)addr >= offset + NB_COLS * NB_ROWS) {
            /* shift up */
            addr -= NB_COLS;
            my_memmove((void *)offset, (void *)offset + NB_COLS, NB_COLS * (NB_ROWS - 1));
            my_memset((void *)offset + NB_COLS * (NB_ROWS - 1), ' ', NB_ROWS);
        }

        *addr++ = str[i];
        ++count;
    }

    return count;
}

int main(void)
{
}