Microkernel thing OS experiment (Zig ⚡)

console: fix rendering when pitch != width * bpp

There were some insanely cursed and hard to debug issues on a ThinkPad I
had with a small cropped framebuffer on Libreboot + SeaBIOS.

pci.express 275adef5 765e551a

verified
Changed files
+15 -3
components
ukernel
deps
console
src
+15 -3
components/ukernel/deps/console/src/root.zig
···
const canvas_pitch = self.fb.width * self.fb.bypp;
const byte_fb: [*]u8 = @ptrCast(self.fb.address);
-
const src_buf = self.canvas[canvas_pitch * glyph_height * start_line ..][0 .. canvas_pitch * glyph_height * num_lines];
-
const dst_buf = byte_fb[self.fb.pitch * glyph_height * start_line ..][0 .. self.fb.pitch * glyph_height * num_lines];
-
@memcpy(dst_buf, src_buf);
+
if (canvas_pitch == self.fb.pitch) {
+
const src_buf = self.canvas[canvas_pitch * glyph_height * start_line ..][0 .. canvas_pitch * glyph_height * num_lines];
+
const dst_buf = byte_fb[self.fb.pitch * glyph_height * start_line ..][0 .. self.fb.pitch * glyph_height * num_lines];
+
@memcpy(dst_buf, src_buf);
+
} else {
+
// Unfortunately we have to copy line by line
+
var i: usize = 0;
+
const canvas_start = canvas_pitch * start_line * glyph_height;
+
const fb_start = self.fb.pitch * start_line * glyph_height;
+
while (i < num_lines * glyph_height) : (i += 1) {
+
const src_line = self.canvas[canvas_start + i * canvas_pitch ..][0..canvas_pitch];
+
const dst_line = byte_fb[fb_start + i * self.fb.pitch ..][0..canvas_pitch];
+
@memcpy(dst_line, src_line);
+
}
+
}
}
/// Write a character to the console, return true if scrolled