commit a27eaae2b28933a45ef2d65fe2f2ac004c40a76a
parent a62a7e75e11e9f03227ad7a5c1a602eb63234870
Author: Matsuda Kenji <info@mtkn.jp>
Date: Mon, 1 Apr 2024 20:51:44 +0900
draw line
Diffstat:
6 files changed, 58 insertions(+), 30 deletions(-)
diff --git a/sys/include/draw.h b/sys/include/draw.h
@@ -1,6 +1,9 @@
+// #include <libc.h>
+
typedef unsigned int RGBA32;
-typedef struct Display Display;
+typedef struct Window Window;
+extern Window root_window;
typedef struct Point {
int x, y;
@@ -12,12 +15,18 @@ typedef struct Rectangle {
} Rectangle;
typedef struct Image {
- Display *display;
+ Window *window;
Rectangle r;
} Image;
-struct Display {
- RGBA32 *framebuffer;
-} Display;
+typedef struct Window {
+ RGBA32 *fb;
+ int hrez;
+ int vrez;
+ int ppsl; // pixels per scan line.
+ Window *children;
+ int nchildren;
+} Window;
-int init_root_display(RGBA32 *fb_base, int fb_size, int hrez, int vrez);
-\ No newline at end of file
+error init_root_window(RGBA32 *fb_base, int hrez, int vrez, int ppsl);
+void line(Window *dst, Point p0, Point p1, RGBA32 col);
+\ No newline at end of file
diff --git a/sys/include/libc.h b/sys/include/libc.h
@@ -5,6 +5,10 @@ typedef unsigned int uint32;
typedef unsigned long long int uint64;
typedef unsigned long long int uintptr;
+typedef struct {
+ char *ename;
+} *error;
+
typedef struct Memblock {
void *start, *end;
} Memblock;
diff --git a/sys/src/kernel/Makefile b/sys/src/kernel/Makefile
@@ -1,6 +1,7 @@
-CC = tcc
+CC = gcc
LD = ld
-CFLAGS = -I ../../include -nostdlib -fpic -mno-red-zone -ffreestanding -Wall -g
+CFLAGS = -I ../../include -nostdlib -fpic -mno-red-zone -Wall -g \
+ -ffreestanding -fno-builtin
LDFLAGS = -e kernel_main -static
OBJS = main.o draw.o alloc.o
diff --git a/sys/src/kernel/alloc.c b/sys/src/kernel/alloc.c
@@ -2,6 +2,7 @@
Memmap memmap;
+/* wip
void *
malloc(uintptr size)
{
@@ -13,4 +14,5 @@ malloc(uintptr size)
}
}
return ptr;
-}
-\ No newline at end of file
+}
+*/
diff --git a/sys/src/kernel/draw.c b/sys/src/kernel/draw.c
@@ -1,9 +1,29 @@
+#include <libc.h>
#include <draw.h>
-Display root_display;
+Window root_window;
-int
-init_root_display(RGBA32 *fb_base, int fb_size, int hrez, int vrez)
+error
+init_root_window(RGBA32 *fb_base, int hrez, int vrez, int ppsl)
{
- return 1;
+ root_window.fb = fb_base;
+ root_window.hrez = hrez;
+ root_window.vrez = vrez;
+ root_window.ppsl = ppsl;
+ root_window.children = NULL;
+ root_window.nchildren = 0;
+ return NULL;
+}
+
+void
+line(Window *dst, Point p0, Point p1, RGBA32 col)
+{
+ int x, y;
+ for (x = p0.x; x < p1.x; x++) {
+ y = (x - p0.x) * (p1.y - p0.y) / (p1.x - p0.x) + p0.y;
+ if (x < 0 || dst->hrez <= x || y < 0 || dst->vrez <= y) {
+ continue; // TODO: break if the rest is outside the window.
+ }
+ dst->fb[y * dst->ppsl + x] = col; // TODO: alpha
+ }
}
\ No newline at end of file
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -1,23 +1,16 @@
#include <uefi.h>
#include <libc.h>
+#include <draw.h>
void
kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
{
- uint32 *fb_base = (uint32 *)gop->Mode->FrameBufferBase;
- uint32 hrez = gop->Mode->Info->HorizontalResolution;
- uint32 vrez = gop->Mode->Info->VerticalResolution;
- uint32 sl = gop->Mode->Info->PixelsPerScanLine;
- uint32 cx = hrez / 2;
- uint32 cy = vrez / 2;
- for (int i = 0; i < vrez; i++) {
- for (int j = 0; j < hrez; j++) {
- if ((cx-j)*(cx-j) + (cy-i)*(cy-i) < (vrez/3) * (vrez/3)) {
- fb_base[i * sl + j] = 0xff << 16;
- } else {
- fb_base[i * sl + j] = 0xffffff;
- }
- }
- }
+ init_root_window(
+ (RGBA32 *)gop->Mode->FrameBufferBase,
+ gop->Mode->Info->HorizontalResolution,
+ gop->Mode->Info->VerticalResolution,
+ gop->Mode->Info->PixelsPerScanLine
+ );
+ line(&root_window, (Point) {10, 10}, (Point) {100000, 100000}, 0xff00ff);
for(;;);
}
\ No newline at end of file