aboutsummaryrefslogtreecommitdiff
path: root/libgui
diff options
context:
space:
mode:
Diffstat (limited to 'libgui')
-rw-r--r--libgui/Makefile21
-rw-r--r--libgui/inc/vesa.h57
-rw-r--r--libgui/vesa.c42
3 files changed, 120 insertions, 0 deletions
diff --git a/libgui/Makefile b/libgui/Makefile
new file mode 100644
index 0000000..89bbb35
--- /dev/null
+++ b/libgui/Makefile
@@ -0,0 +1,21 @@
+# MIT License, Copyright (c) 2020 Marvin Borner
+
+COBJS = vesa.o
+CC = ../cross/opt/bin/i686-elf-gcc
+LD = ../cross/opt/bin/i686-elf-ld
+OC = ../cross/opt/bin/i686-elf-ar
+
+# Flags to make the binary smaller TODO: Remove after indirect pointer support!
+CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os
+
+CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ -I../libc/inc/ -Duserspace -fPIE
+
+%.o: %.c
+ @$(CC) -c $(CFLAGS) $< -o $@
+
+libgui: $(COBJS)
+ @mkdir -p ../build/
+ @$(AR) qc ../build/libgui.a $+
+
+clean:
+ @find . -name "*.o" -type f -delete
diff --git a/libgui/inc/vesa.h b/libgui/inc/vesa.h
new file mode 100644
index 0000000..e34cdc0
--- /dev/null
+++ b/libgui/inc/vesa.h
@@ -0,0 +1,57 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef VBE_H
+#define VBE_H
+
+#include <def.h>
+
+struct vbe {
+ u16 attributes;
+ u8 window_a;
+ u8 window_b;
+ u16 granularity;
+ u16 window_size;
+ u16 segment_a;
+ u16 segment_b;
+ u32 win_func_ptr;
+ u16 pitch;
+ u16 width;
+ u16 height;
+ u8 w_char;
+ u8 y_char;
+ u8 planes;
+ u8 bpp;
+ u8 banks;
+ u8 memory_model;
+ u8 bank_size;
+ u8 image_pages;
+ u8 reserved0;
+
+ u8 red_mask;
+ u8 red_position;
+ u8 green_mask;
+ u8 green_position;
+ u8 blue_mask;
+ u8 blue_position;
+ u8 reserved_mask;
+ u8 reserved_position;
+ u8 direct_color_attributes;
+
+ u32 framebuffer;
+ u32 off_screen_mem_off;
+ u16 off_screen_mem_size;
+ u8 reserved1[206];
+};
+
+struct vbe *vbe;
+int vbe_width;
+int vbe_height;
+int vbe_bpl;
+int vbe_pitch;
+u8 *fb;
+
+void vesa_fill(const u32 color[3]);
+void vesa_set_pixel(u16 x, u16 y, const u32 color[3]);
+void vesa_init(struct vbe *info);
+
+#endif
diff --git a/libgui/vesa.c b/libgui/vesa.c
new file mode 100644
index 0000000..2d3e107
--- /dev/null
+++ b/libgui/vesa.c
@@ -0,0 +1,42 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <def.h>
+#include <vesa.h>
+
+void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3])
+{
+ int pos1 = x1 * vbe_bpl + y1 * vbe_pitch;
+ u8 *draw = &fb[pos1];
+ for (int i = 0; i <= y2 - y1; i++) {
+ for (int j = 0; j <= x2 - x1; j++) {
+ draw[vbe_bpl * j] = color[2];
+ draw[vbe_bpl * j + 1] = color[1];
+ draw[vbe_bpl * j + 2] = color[0];
+ }
+ draw += vbe_pitch;
+ }
+}
+
+void vesa_set_pixel(u16 x, u16 y, const u32 color[3])
+{
+ u8 pos = x * vbe_bpl + y * vbe_pitch;
+ u8 *draw = &fb[pos];
+ draw[pos] = (char)color[2];
+ draw[pos + 1] = (char)color[1];
+ draw[pos + 2] = (char)color[0];
+}
+
+void vesa_fill(const u32 color[3])
+{
+ vesa_draw_rectangle(0, 0, vbe->width - 1, vbe->height - 1, color);
+}
+
+void vesa_init(struct vbe *info)
+{
+ vbe = info;
+ vbe_height = vbe->height;
+ vbe_width = vbe->width;
+ vbe_bpl = vbe->bpp >> 3;
+ vbe_pitch = vbe->pitch;
+ fb = (u8 *)vbe->framebuffer;
+}