summaryrefslogtreecommitdiff
path: root/x86-bare-metal/mbr-palette/zmbr.zig
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-23 22:51:52 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-25 21:25:16 +0100
commit14845124cf5d4fb42a04cb1262b32bd3d00f45f8 (patch)
tree13162d26afeb49a9c9b8d9d31049066c0f4b2998 /x86-bare-metal/mbr-palette/zmbr.zig
parent42b6f9d23ab0f94744a90edb6fd74450f589ca14 (diff)
downloadzig-playground-14845124cf5d4fb42a04cb1262b32bd3d00f45f8.tar.gz
zig-playground-14845124cf5d4fb42a04cb1262b32bd3d00f45f8.zip
mbr: rm->pm, then jump into zig
Diffstat (limited to 'x86-bare-metal/mbr-palette/zmbr.zig')
-rw-r--r--x86-bare-metal/mbr-palette/zmbr.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/x86-bare-metal/mbr-palette/zmbr.zig b/x86-bare-metal/mbr-palette/zmbr.zig
new file mode 100644
index 0000000..947cd06
--- /dev/null
+++ b/x86-bare-metal/mbr-palette/zmbr.zig
@@ -0,0 +1,29 @@
+const COLS = 320;
+const ROWS = 200;
+
+/// Draw the color palette.
+/// One color per column, remaining columns are drawn black.
+fn draw_palette(video: []u8) void {
+ for (0..ROWS) |r| {
+ for (0..COLS) |c| {
+ if (c < 256) {
+ video[COLS * r + c] = @truncate(c);
+ } else {
+ video[COLS * r + c] = 0;
+ }
+ }
+ }
+}
+
+// kmain should be "callconv(.naked)", once issue is fixed.
+// https://github.com/ziglang/zig/issues/18183
+export fn kmain() noreturn {
+ // Take a slice to 256-color VGA video memory (mode 13h graphic mode).
+ const video: []u8 = @as([*]u8, @ptrFromInt(0xA0000))[0 .. COLS * ROWS];
+
+ draw_palette(video);
+
+ while (true) {
+ asm volatile ("hlt");
+ }
+}