diff options
author | Marvin Borner | 2020-07-22 19:57:16 +0200 |
---|---|---|
committer | Marvin Borner | 2020-07-22 19:57:16 +0200 |
commit | e9c31cf19a30bd2d9960ce8341fea9cbfc973f7a (patch) | |
tree | e598da74f4fb51f926a929d0ae4fda8605d0b3f3 | |
parent | 40cc5e32663cd0350b791b8e54825f564489343f (diff) |
Added basic malloc (WARNING: DUMB!) :)
-rw-r--r-- | src/drivers/vesa.c | 12 | ||||
-rw-r--r-- | src/inc/vesa.h | 2 | ||||
-rw-r--r-- | src/lib/inc/def.h | 17 | ||||
-rw-r--r-- | src/main.c | 9 |
4 files changed, 31 insertions, 9 deletions
diff --git a/src/drivers/vesa.c b/src/drivers/vesa.c index ca130db..54e7e34 100644 --- a/src/drivers/vesa.c +++ b/src/drivers/vesa.c @@ -1,25 +1,25 @@ #include <def.h> #include <vesa.h> -void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u32 color[3]) +void vesa_draw_rectangle(int x1, int y1, int x2, int y2, const u8 color[3]) { int vbe_bpl = vbe->bpp >> 3; int vbe_pitch = vbe->pitch; u8 *fb = (u8 *)vbe->framebuffer; int pos1 = x1 * vbe_bpl + y1 * vbe_pitch; - char *draw = (char *)&fb[pos1]; + u8 *draw = &fb[pos1]; for (int i = 0; i <= y2 - y1; i++) { for (int j = 0; j <= x2 - x1; j++) { - draw[vbe_bpl * j] = (char)color[2]; - draw[vbe_bpl * j + 1] = (char)color[1]; - draw[vbe_bpl * j + 2] = (char)color[0]; + 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_clear(const u32 color[3]) +void vesa_fill(const u8 color[3]) { vesa_draw_rectangle(0, 0, vbe->width - 1, vbe->height - 1, color); } diff --git a/src/inc/vesa.h b/src/inc/vesa.h index 661ab16..c4863f1 100644 --- a/src/inc/vesa.h +++ b/src/inc/vesa.h @@ -45,6 +45,6 @@ struct vbe { struct vbe *vbe; -void vesa_clear(const u32 color[3]); +void vesa_fill(const u8 color[3]); #endif diff --git a/src/lib/inc/def.h b/src/lib/inc/def.h index 69b43e3..6e3066a 100644 --- a/src/lib/inc/def.h +++ b/src/lib/inc/def.h @@ -3,6 +3,10 @@ #ifndef DEF_H #define DEF_H +/** + * Types + */ + typedef signed char s8; typedef unsigned char u8; @@ -15,6 +19,19 @@ typedef unsigned int u32; typedef signed long long s64; typedef unsigned long long u64; +/** + * Macros + */ + #define NULL ((void *)0) +#define malloc(n) ((void *)((HEAP += n) - n)) // TODO: Implement real/better malloc/free +#define free(x) + +/** + * Heap + */ + +extern u32 HEAP; +extern u32 HEAP_START; #endif @@ -5,13 +5,18 @@ #include <serial.h> #include <vesa.h> +u32 HEAP = 0x00200000; +u32 HEAP_START; + void main(struct mem_info *mem_info, struct vid_info *vid_info) { + HEAP_START = HEAP; // For malloc function + mem_info++; // TODO: Use the mmap (or remove)! vbe = vid_info->info; - u32 terminal_background[3] = { 0x1d, 0x1f, 0x24 }; - vesa_clear(terminal_background); + u8 terminal_background[3] = { 0x1d, 0x1f, 0x24 }; + vesa_fill(terminal_background); serial_install(); serial_print("hello\n"); |