commit 902a616ca900395ec60fee888169959f75d750cc
parent c5c72011513218b8d2b4ab83599cf70127e1f9e7
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 5 Apr 2024 09:55:33 +0900
spawn a window and console
Diffstat:
7 files changed, 85 insertions(+), 25 deletions(-)
diff --git a/sys/include/draw.h b/sys/include/draw.h
@@ -36,4 +36,7 @@ typedef struct Window {
int init_root_window(uint32 *fb_base, int hres, int vres, int ppsl, EFI_GRAPHICS_PIXEL_FORMAT pf);
extern void (* pixel)(Window *dst, Point p, RGBA32 col);
-void line(Window *dst, Point p0, Point p1, RGBA32 col);
-\ No newline at end of file
+void line(Window *dst, Point p0, Point p1, RGBA32 col);
+void border(Window *dst, Rectangle r, RGBA32 col);
+void fill(Window *dst, Rectangle r, RGBA32 col);
+void clear(Window *dst);
+\ No newline at end of file
diff --git a/sys/include/libc.h b/sys/include/libc.h
@@ -34,6 +34,7 @@ void *memset(void *s, int c, uintptr n);
/*
typedef char *va_list;
+// ABI is different with plan9.
#define va_start(list, start) list = (char *)((int64 *)&(start)+1)
// list += 8 on a 64-bit machine.
#define va_arg(list, mode) \
@@ -42,5 +43,4 @@ typedef char *va_list;
(sizeof(mode) == 4) ? ((list += 8), (mode *) list)[-2]:\
((list += 8), (mode *) list)[-1])
#define va_end(list)
-
*/
\ No newline at end of file
diff --git a/sys/src/Makefile b/sys/src/Makefile
@@ -6,10 +6,10 @@ BOOTCFLAGS = -I ../include \
-fno-builtin -g -mabi=sysv \
-mno-stack-arg-probe -Wall -e EfiMain
-CC = tcc
+CC = gcc #TODO: tcc doesn't work. I think it is a problem with build flags.
LD = ld
-CFLAGS = -I ../include -nostdlib -fpic -mno-red-zone -Wall -g \
- -ffreestanding -fno-builtin
+CFLAGS = -I ../include -fpic -mno-red-zone -Wall -g \
+ -ffreestanding -fno-builtin -nostdlib # -nostdinc
LDFLAGS = -L../lib -static
disk.img: boot/boot.efi kernel/main.elf
diff --git a/sys/src/boot/boot.c b/sys/src/boot/boot.c
@@ -98,10 +98,6 @@ EfiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *systab)
gop->Mode->FrameBufferBase,
gop->Mode->FrameBufferSize);
- for (UINTN i = 0; i < gop->Mode->FrameBufferSize/4; i++) {
- frame_buffer[i] = 0xffffea;
- }
-
mmsize = 8196;
stat = SystemTable->BootServices->GetMemoryMap(&mmsize, mmap, &mkey, &dsize, &dver);
if (stat != EFI_SUCCESS) {
diff --git a/sys/src/kernel/console.c b/sys/src/kernel/console.c
@@ -2,7 +2,8 @@
#include <uefi.h>
#include <draw.h>
#include <console.h>
-#include <stdarg.h> // TODO: implement own stdarg.h
+
+#include <stdarg.h> // TODO: implement myself
void
cons_putchar(Console *con, char c)
diff --git a/sys/src/kernel/draw.c b/sys/src/kernel/draw.c
@@ -22,12 +22,13 @@ init_root_window(uint32 *fb_base, int hres, int vres, int ppsl, EFI_GRAPHICS_PIX
}
root_window.fb = fb_base;
root_window.fg = 0x0;
- root_window.bg = 0xffffea00;
+ root_window.bg = 0xeaeaea00;
root_window.hres = hres;
root_window.vres = vres;
root_window.ppsl = ppsl;
root_window.children = NULL;
root_window.nchildren = 0;
+ clear(&root_window);
return 0;
}
@@ -84,6 +85,7 @@ line(Window *dst, Point p0, Point p1, RGBA32 col)
x = p0.x;
y = p0.y;
pixel(dst, (Point){x, y}, col);
+ // TODO: skip and break the points outside the window.
for (;x != p1.x || y != p1.y;) {
e2 = 2 * err;
if (e2 > -dy) {
@@ -94,9 +96,46 @@ line(Window *dst, Point p0, Point p1, RGBA32 col)
err +=dx;
y += sy;
}
- if (x <= 0 || dst->hres < x || y <= 0 || dst->vres < y) {
- continue; // TODO: break
- }
pixel(dst, (Point){x, y}, col);
}
-}
-\ No newline at end of file
+}
+
+void
+border(Window *dst, Rectangle r, RGBA32 col)
+{
+ int x, y;
+ for (x = r.min.x, y = r.min.y; x < r.max.x; x++) {
+ pixel(dst, (Point){x, y}, col);
+ }
+ for (x = r.max.x-1, y = r.min.y; y < r.max.y; y++) {
+ pixel(dst, (Point){x, y}, col);
+ }
+ for (x = r.max.x-1, y = r.max.y-1; x >= r.min.x; x--) {
+ pixel(dst, (Point){x, y}, col);
+ }
+ for (x = r.min.x, y = r.max.y-1; y >= r.min.y; y--) {
+ pixel(dst, (Point){x, y}, col);
+ }
+}
+
+void
+fill(Window *dst, Rectangle r, RGBA32 col)
+{
+ int x, y;
+ for (x = r.min.x; x < r.max.x; x++) {
+ for (y = r.min.y; y < r.max.y; y++) {
+ pixel(dst, (Point){x, y}, col);
+ }
+ }
+}
+
+void
+clear(Window *dst)
+{
+ int x, y;
+ for (x = 0; x < dst->hres; x++) {
+ for (y = 0; y < dst->vres; y++) {
+ pixel(dst, (Point){x, y}, dst->bg);
+ }
+ }
+}
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -18,13 +18,35 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
// can't print to console.
goto halt;
}
- cons_printf(&console, "Does this work: %d, %s, %x\n", 10, "string", 0xdeadbeef);
- line(&root_window, (Point){1000, 100}, (Point){1050, 140}, 0x000000);
- line(&root_window, (Point){1000, 300}, (Point){100000, 100000}, 0x000000);
- line(&root_window, (Point){1000, 400}, (Point){1100, 400}, 0xff000000);
- line(&root_window, (Point){1000, 500}, (Point){1100, 500}, 0x00ff0000);
- line(&root_window, (Point){1000, 600}, (Point){1100, 600}, 0x0000ff00);
- line(&root_window, (Point){1000, 700}, (Point){1100, 700}, 0x000000ff);
+
+ Window win0 = {
+ .fb = root_window.fb + (100 * root_window.ppsl + 150),
+ .fg = 0x0,
+ .bg = 0xffffea00,
+ .hres = 400,
+ .vres = 300,
+ .ppsl = root_window.ppsl,
+ };
+ root_window.children = &win0; // TODO: allocate array of Window.
+ root_window.nchildren++;
+ Console con0 = {
+ .win = &win0,
+ .font = &asciifont,
+ .w = 80,
+ .h = 24,
+ .pos = (Point){0, 0}
+ };
+ Rectangle rect = {
+ .min = (Point){100, 100},
+ .max = (Point){500, 400},
+ };
+ border(&root_window, rect, 0x00ff8000);
+ rect.min.x += 500;
+ rect.max.x += 500;
+ fill(&root_window, rect, 0x0080ff00);
+ clear(&win0);
+ cons_printf(&con0, "hello window!\n");
+
halt:
- for(;;);
+ for(;;) { __asm__("hlt"); }
}