-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.zig
More file actions
42 lines (38 loc) · 1.04 KB
/
render.zig
File metadata and controls
42 lines (38 loc) · 1.04 KB
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
const std = @import("std");
const kb = @import("keyboard.zig");
pub fn put_keys_on_screen() void {
var x: u16 = 0;
var y: u16 = 0;
for (0..256) |i| {
if (kb.key_state[i]) {
const ascii = kb.key_to_ascii(@as(u8, @intCast(i)));
if (ascii != 0) {
vga_new[y][x] = 0x400 | ascii;
x += 1;
if (x == 80) {
x = 0;
y += 1;
if (y == 25) {
y = 0;
}
}
}
}
}
}
const screen = [25][80]u16;
const vga: *volatile screen = @ptrFromInt(0xb8000);
var vga_new: screen = std.mem.zeroes(screen);
fn show_screen() void {
for (0..25) |y| {
std.mem.copyForwards(u16, @as([]u16, @volatileCast(&(vga.*)[y])), &vga_new[y]);
}
std.mem.copyForwards([80]u16, &vga_new, &std.mem.zeroes(screen));
}
pub fn render_loop() noreturn {
while (true) {
kb.update_key_state();
put_keys_on_screen();
show_screen();
}
}