diff options
| author | wires <wires@noreply.wires.systems> | 2025-10-13 10:11:14 -0400 |
|---|---|---|
| committer | wires <wires@noreply.wires.systems> | 2025-10-13 10:11:14 -0400 |
| commit | 72857c6f87e62dc2d2fa0173efa2c68b2c710f9d (patch) | |
| tree | 8979489fdf9967e3a46a938e712cfd0853e3d60f /src/console.zig | |
| parent | start working on devicetree (diff) | |
| download | zosimos-72857c6f87e62dc2d2fa0173efa2c68b2c710f9d.tar.gz | |
first console driver abstraction
Diffstat (limited to 'src/console.zig')
| -rw-r--r-- | src/console.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/console.zig b/src/console.zig new file mode 100644 index 0000000..1a7539e --- /dev/null +++ b/src/console.zig @@ -0,0 +1,34 @@ +const std = @import("std"); +const Writer = std.Io.Writer; + +pub const Console = struct { + setup: *const fn (*const @This()) void, + write: *const fn (*const @This(), []const u8) void, +}; + +var cur: ?*const Console = null; + +fn drain( + _: *Writer, + data: []const []const u8, + _: usize, +) Writer.Error!usize { + if (cur) |c| { + c.write(c, data[0]); + } + return data[0].len; +} + +var writer: Writer = .{ + .vtable = &.{ .drain = drain }, + .buffer = &.{}, +}; + +pub fn print(comptime fmt: []const u8, args: anytype) void { + writer.print(fmt, args) catch {}; +} + +pub fn set_console(console: *const Console) void { + console.setup(console); + cur = console; +} |