From 84ab1731e43f290d535dae87081fbff0896cf95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Krzy=C5=BCanowski?= Date: Tue, 17 Sep 2024 18:59:16 +0200 Subject: [PATCH] VGA draft --- src/vga.zig | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/vga.zig diff --git a/src/vga.zig b/src/vga.zig new file mode 100644 index 0000000..8b8aac9 --- /dev/null +++ b/src/vga.zig @@ -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; + } +};