aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2024-05-01 00:57:41 +0300
committerMarin Ivanov <[email protected]>2024-05-01 00:57:41 +0300
commitc183a27418e6c09ed3c909d12b9b921eb05f38b4 (patch)
tree1f15faeb021387b1e35fb629b4e3209ea0ac9a97
parentb0ab0f7856090f2aa9b1322b83616dea231a4032 (diff)
fix: update enums and cleanup
-rw-r--r--src/console.zig36
-rw-r--r--src/main.zig14
2 files changed, 25 insertions, 25 deletions
diff --git a/src/console.zig b/src/console.zig
index 6fc5043..0b331ca 100644
--- a/src/console.zig
+++ b/src/console.zig
@@ -1,10 +1,10 @@
const fmt = @import("std").fmt;
const Writer = @import("std").io.Writer;
-
+
const VGA_WIDTH = 80;
const VGA_HEIGHT = 25;
const VGA_SIZE = VGA_WIDTH * VGA_HEIGHT;
-
+
pub const ConsoleColors = enum(u8) {
Black = 0,
Blue = 1,
@@ -23,39 +23,39 @@ pub const ConsoleColors = enum(u8) {
LightBrown = 14,
White = 15,
};
-
+
var row: usize = 0;
var column: usize = 0;
var color = vgaEntryColor(ConsoleColors.LightGray, ConsoleColors.Black);
var buffer = @as([*]volatile u16, @ptrFromInt(0xB8000));
-
+
fn vgaEntryColor(fg: ConsoleColors, bg: ConsoleColors) u8 {
- return @enumToInt(fg) | (@enumToInt(bg) << 4);
+ return @intFromEnum(fg) | (@intFromEnum(bg) << 4);
}
-
+
fn vgaEntry(uc: u8, new_color: u8) u16 {
- var c: u16 = new_color;
-
+ const c: u16 = new_color;
+
return uc | (c << 8);
}
-
+
pub fn initialize() void {
clear();
}
-
+
pub fn setColor(new_color: u8) void {
color = new_color;
}
-
+
pub fn clear() void {
- @memset(u16, buffer[0..VGA_SIZE], vgaEntry(' ', color));
+ @memset(buffer[0..VGA_SIZE], vgaEntry(' ', color));
}
-
+
pub fn putCharAt(c: u8, new_color: u8, x: usize, y: usize) void {
const index = y * VGA_WIDTH + x;
buffer[index] = vgaEntry(c, new_color);
}
-
+
pub fn putChar(c: u8) void {
putCharAt(c, color, column, row);
column += 1;
@@ -66,19 +66,19 @@ pub fn putChar(c: u8) void {
row = 0;
}
}
-
+
pub fn puts(data: []const u8) void {
for (data) |c|
putChar(c);
}
-
+
pub const writer = Writer(void, error{}, callback){ .context = {} };
-
+
fn callback(_: void, string: []const u8) error{}!usize {
puts(string);
return string.len;
}
-
+
pub fn printf(comptime format: []const u8, args: anytype) void {
fmt.format(writer, format, args) catch unreachable;
}
diff --git a/src/main.zig b/src/main.zig
index 298e2c2..c874485 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,30 +1,30 @@
const console = @import("console.zig");
-
+
const ALIGN = 1 << 0;
const MEMINFO = 1 << 1;
const MAGIC = 0x1BADB002;
const FLAGS = ALIGN | MEMINFO;
-
+
const MultibootHeader = packed struct {
magic: i32 = MAGIC,
flags: i32,
checksum: i32,
};
-
+
export var multiboot align(4) linksection(".multiboot") = MultibootHeader{
.flags = FLAGS,
.checksum = -(MAGIC + FLAGS),
};
-
+
export var stack_bytes: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
const stack_bytes_slice = stack_bytes[0..];
-
+
export fn _start() callconv(.Naked) noreturn {
@call(.{ .stack = stack_bytes_slice }, kmain, .{});
-
+
while (true) {}
}
-
+
fn kmain() void {
console.initialize();
console.puts("Hello world!");