summaryrefslogtreecommitdiff
path: root/x86-bare-metal/mbr-palette/zmbr.zig
blob: 947cd06e71c431e3d9e4392a7cd376678eddff41 (plain) (blame)
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
const COLS = 320;
const ROWS = 200;

/// Draw the color palette.
/// One color per column, remaining columns are drawn black.
fn draw_palette(video: []u8) void {
    for (0..ROWS) |r| {
        for (0..COLS) |c| {
            if (c < 256) {
                video[COLS * r + c] = @truncate(c);
            } else {
                video[COLS * r + c] = 0;
            }
        }
    }
}

// kmain should be "callconv(.naked)", once issue is fixed.
// https://github.com/ziglang/zig/issues/18183
export fn kmain() noreturn {
    // Take a slice to 256-color VGA video memory (mode 13h graphic mode).
    const video: []u8 = @as([*]u8, @ptrFromInt(0xA0000))[0 .. COLS * ROWS];

    draw_palette(video);

    while (true) {
        asm volatile ("hlt");
    }
}