VGA draft

This commit is contained in:
Maciej Krzyżanowski 2024-09-17 18:59:16 +02:00
parent 81540ef99d
commit 84ab1731e4

110
src/vga.zig Normal file
View File

@ -0,0 +1,110 @@
const std = @import("std");
const Color = enum(u4) {
black = 0,
blue = 1,
green = 2,
cyan = 3,
red = 4,
magenta = 5,
brown = 6,
light_grey = 7,
dark_grey = 8,
light_blue = 9,
light_green = 10,
light_cyan = 11,
light_red = 12,
light_magenta = 13,
light_brown = 14,
white = 15,
};
const Cell = struct {
text_color: Color,
background_color: Color,
character: u8,
pub fn init(text_color: Color, background_color: Color, character: u8) Cell {
return Cell{
.text_color = text_color,
.background_color = background_color,
.character = character,
};
}
pub fn default(character: u8) Cell {
return Cell.init(Color.white, Color.black, character);
}
pub fn solid(background_color: Color) Cell {
return Cell.init(Color.white, background_color, ' ');
}
pub fn encode(self: Cell) u16 {
const result: u16 = 0;
result |= (self.background_color << 12);
result |= (self.text_color << 8);
result |= (self.character);
return result;
}
};
const Position = struct {
x: u32,
y: u32,
pub fn init(x: u32, y: u32) Position {
return Position{
.x = x,
.y = y,
};
}
};
const Screen = struct {
pub const width = 80;
pub const height = 25;
pub const base_addr = 0xB8000;
cursor_position: Position,
pub fn init() Screen {
return Screen{
.cursor_position = Position.init(0, 0),
};
}
pub fn put_at(position: Position, cell: Cell) void {
unreachable;
}
pub fn fill(cell: Cell) void {
unreachable;
}
pub fn clear() void {
unreachable;
}
pub fn new_line() void {
unreachable;
}
pub fn put_char(self: Screen, cell: Cell) void {
unreachable;
}
pub fn put_str(self: Screen, str: []const u8) void {
unreachable;
}
pub fn print(self: Screen, format: []const u8, args: anytype) void {
unreachable;
}
pub fn println(self: Screen, format: []const u8, args: anytype) void {
unreachable;
}
};