Start at framebuffer drawing
This commit is contained in:
31
src/kernel/drivers/framebuffer.c
Normal file
31
src/kernel/drivers/framebuffer.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
#include <multiboot.h>
|
||||
|
||||
void framebuffer_init(struct fbinfo *fbinfo)
|
||||
{
|
||||
size_t fb_size = fbinfo->framebuffer_pitch * (fbinfo->framebuffer_height+1);
|
||||
uintptr_t fb_end = fbinfo->framebuffer_addr + fb_size;
|
||||
|
||||
for(uintptr_t p = fbinfo->framebuffer_addr; p < fb_end; p += PAGE_SIZE)
|
||||
{
|
||||
vmm_set_page(kernel_P4, (uint64_t)P2V(p), p, PAGE_WRITE | PAGE_PRESENT);
|
||||
}
|
||||
|
||||
uint8_t *fb = P2V(fbinfo->framebuffer_addr);
|
||||
|
||||
for(uint32_t y = 0; y < 1; y++)
|
||||
{
|
||||
for(uint32_t x = 0; x < fbinfo->framebuffer_width; x++)
|
||||
{
|
||||
unsigned int bpp = fbinfo->framebuffer_bpp/8;
|
||||
unsigned int loc = \
|
||||
y*fbinfo->framebuffer_pitch + \
|
||||
x*(bpp);
|
||||
fb[loc++] = 0xFF;
|
||||
fb[loc++] = 0;
|
||||
fb[loc] = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
#include <vga.h>
|
||||
#include <memory.h>
|
||||
#include <ports.h>
|
||||
#include <multiboot.h>
|
||||
#include <stddef.h>
|
||||
#include <debug.h>
|
||||
|
||||
#define VGA_COLS 80
|
||||
#define VGA_ROWS 24
|
||||
@@ -26,15 +29,29 @@ struct vga_cell buffer[VGA_SIZE];
|
||||
uint64_t cursor;
|
||||
uint8_t format;
|
||||
|
||||
static int vga_setup = 0;
|
||||
static int vga_type;
|
||||
|
||||
void vga_init()
|
||||
{
|
||||
vidmem = VGA_MEMORY;
|
||||
memset(vidmem, 0, VGA_SIZE*sizeof(struct vga_cell));
|
||||
struct fbinfo *fbinfo = kernel_boot_data.fbinfo;
|
||||
vga_type = fbinfo->framebuffer_type;
|
||||
switch(vga_type)
|
||||
{
|
||||
case 1:
|
||||
framebuffer_init(fbinfo);
|
||||
break;
|
||||
case 2:
|
||||
vidmem = VGA_MEMORY;
|
||||
memset(vidmem, 0, VGA_SIZE*sizeof(struct vga_cell));
|
||||
format = 0x07;
|
||||
break;
|
||||
}
|
||||
|
||||
format = 0x07;
|
||||
vga_setup = 1;
|
||||
}
|
||||
|
||||
void movecursor()
|
||||
static void movecursor()
|
||||
{
|
||||
outb(VGA_ADDRESS_PORT, VGA_REGISTER_CURSOR_POS_LOW);
|
||||
outb(VGA_DATA_PORT, (uint8_t)(cursor & 0xFF));
|
||||
@@ -42,12 +59,13 @@ void movecursor()
|
||||
outb(VGA_DATA_PORT, (uint8_t)((cursor >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void flush()
|
||||
static void flush()
|
||||
{
|
||||
memcpy(vidmem, buffer, sizeof(buffer));
|
||||
if(vga_setup)
|
||||
memcpy(vidmem, buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
void scroll()
|
||||
static void scroll()
|
||||
{
|
||||
while(cursor >= VGA_SIZE)
|
||||
{
|
||||
@@ -59,15 +77,20 @@ void scroll()
|
||||
|
||||
void vga_write(char c)
|
||||
{
|
||||
switch(c)
|
||||
switch(vga_type)
|
||||
{
|
||||
case '\n':
|
||||
cursor += VGA_COLS - VGA_COL(cursor);
|
||||
case 2:
|
||||
switch(c)
|
||||
{
|
||||
case '\n':
|
||||
cursor += VGA_COLS - VGA_COL(cursor);
|
||||
break;
|
||||
default:
|
||||
buffer[cursor++] = (struct vga_cell){.c = c, .f = format};
|
||||
}
|
||||
scroll();
|
||||
flush();
|
||||
movecursor();
|
||||
break;
|
||||
default:
|
||||
buffer[cursor++] = (struct vga_cell){.c = c, .f = format};
|
||||
}
|
||||
scroll();
|
||||
flush();
|
||||
movecursor();
|
||||
}
|
||||
Reference in New Issue
Block a user