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

#include "keyb.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;

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

    /* set VGA 320x200, 256 col */
    if (!set_mode(0x13))
    {
        fprintf(stderr, "ERROR: failed to init the VGA card\n");
        return 1;
    }

    set_palette(binary_palette_start);

    if (!open_framebuffer())
    {
        set_mode(3);
        fprintf(stderr, "ERROR: failed to open the framebuffer\n");
        return 1;
    }

    blit_erase(0);
    wait_vsync();
    blit_update();

    uint8_t bg[24 * 24] = { 0 };
    Rect dst = { 10, 10, 24, 24 };
    int8_t ix = 1, iy = 1;
    uint8_t c = 0;

    while (!keys[KEY_ESC])
    {
        // erase
        blit(bg, &dst);

        dst.x += ix;
        dst.y += iy;

        if (dst.x >= 320 - 24 || dst.x == 0)
        {
            ix *= -1;
            c = (c + 1) % 15;
            blit_erase(c);
            memset(bg, c, 24 * 24);
        }
        if (dst.y >= 200 - 24 || dst.y == 0)
        {
            iy *= -1;
            c = (c + 1) % 15;
            blit_erase(c);
            memset(bg, c, 24 * 24);
        }

        // draw
        blit(binary_sprites_start, &dst);

        wait_vsync();
        blit_update();
    }

    set_mode(3);
    close_framebuffer();

    return 0;
}