aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 9d74efc36f4e52e32fbc1200f68d4c9f84c83cc9 (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
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <crt0.h>

#include "keyb.h"
#include "timer.h"
#include "vga.h"
#include "data.h"

/* disable paging because our int handlers are written in C */
int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;

void free_all()
{
    timer_free();
    keyb_free();
}

int main(int argc, char *argv[])
{
    timer_init();
    keyb_init();
    atexit(free_all);

    /* set VGA 320x200, 256 col */
    set_mode(0x13);

    set_palette(binary_palette_start);

    uint8_t *screen = open_framebuffer();
    if (!screen)
    {
        fprintf(stderr, "ERROR: failed to open the framebuffer\n");
        return 1;
    }

    int i = 0;
    while (!keys[KEY_ESC])
    {
        wait_vsync();

        memset(screen, i, 320 * 200);
        i++;
        if (i > 15)
            i = 0;

        timer_wait(1);
    }

    set_mode(3);
    close_framebuffer();

    return 0;
}