From 63b04ffc264aab5313811f1aa7ffc30715814e67 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Thu, 13 Nov 2014 02:27:05 +0100 Subject: cleanup and refactoring. abstracting away console --- Makefile | 3 +- boot/stage2.asm | 2 +- kernel/config.h | 1 + kernel/console.c | 158 +------------------------------------ kernel/console.h | 38 +-------- kernel/kernel.c | 10 ++- kernel/keyboard.c | 5 +- kernel/spinlock.h | 5 ++ kernel/syscalls.c | 5 +- kernel/vesa.c | 230 ------------------------------------------------------ kernel/vesa.h | 45 ----------- lib/logger/log.c | 17 ++-- video/console.c | 156 ++++++++++++++++++++++++++++++++++++ video/console.h | 43 ++++++++++ video/vesa.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++++++++ video/vesa.h | 45 +++++++++++ 16 files changed, 511 insertions(+), 480 deletions(-) delete mode 100644 kernel/vesa.c delete mode 100644 kernel/vesa.h create mode 100644 video/console.c create mode 100644 video/console.h create mode 100644 video/vesa.c create mode 100644 video/vesa.h diff --git a/Makefile b/Makefile index e4b1a4d..2cc00f9 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ CFLAGS+=-std=gnu11 CFLAGS+= -I. #CFLAGS+=-lgcc -#CFLAGS+= -w -Wimplicit-function-declaration -Werror-implicit-function-declaration +CFLAGS+=-Werror-implicit-function-declaration #CFLAGS+= -O4 #CFLAGS+=-fdata-sections -ffunction-sections #CFLAGS+= -Werror @@ -35,6 +35,7 @@ CFLAGS+= -I. #kernel sources (asm and c) SOURCES=$(wildcard ./kernel/*.c) +SOURCES+=$(wildcard ./video/*.c) SOURCES+=$(wildcard ./lib/*/*.c) SOURCES+=$(wildcard ./fs/*.c) diff --git a/boot/stage2.asm b/boot/stage2.asm index 517e481..215cb18 100644 --- a/boot/stage2.asm +++ b/boot/stage2.asm @@ -144,7 +144,7 @@ kernel_load: mov ax,[KERNEL_CHUNK] cmp ax,0x5 jne skip_vesa_init - call VesaSetup + ; call VesaSetup skip_vesa_init: call switch_to_pm diff --git a/kernel/config.h b/kernel/config.h index 0f62abb..da8272d 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -7,4 +7,5 @@ //#define FOOLOS_COMPILE_FLOPPY // compile floppy drivers #define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line //#define FOOLOS_LOG_OFF // do not log anything +#define FOOLOS_CONSOLE diff --git a/kernel/console.c b/kernel/console.c index e06da45..b6866a7 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -1,155 +1,5 @@ -#include "console.h" +#include "video/console.h" -//#define FOOLOS_CONSOLE - -static int posx=0; -static int posy=0; - -// helper_funcs - -void print_char_col(int x, int y, char c, char col) -{ -#ifdef FOOLOS_CONSOLE - char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; - video_mem[0]=c; - video_mem[1]=col; -#endif -} - -void print_char(int x, int y, char c) -{ - print_char_col(x,y,c,SCR_WHITE); -} - -void print_single_num(int i) -{ - if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN); - else if(i<16)print_char_col(posx,posy,'A'+i-10,SCR_GREEN); - posx++; - if(posx>=SCR_WIDTH)scr_nextline(); - -} - -void print_str_col(int x,int y,char *str, char col) -{ - - while(*str!=0) - { - print_char_col(x++,y,*(str++),col); - } - -} - -void print_str(int x,int y,char *str) -{ - print_str_col(x,y,str,SCR_WHITE); -} - - -// -// -void scr_clear() -{ - int x,y; - - for(x=0;xSCR_HEIGHT-2) - { - for(i=1;i=SCR_WIDTH)scr_nextline(); -} - - -void scr_put_hex(uint16_t val) -{ - - int i; - - scr_put_string("0x"); - - for(i=0;i<4;i++) - { - print_single_num((val&0xf000)>>12); - val=val << 4; - - } - -} - - -void scr_put_hex32(uint32_t val) -{ - scr_put_string("["); - scr_put_hex(val>>16); - scr_put_string(","); - scr_put_hex(val&0xffff); - scr_put_string("]"); -} - -void scr_put_string(char *str) -{ - while(*str!=0) - { - scr_put_char(*(str++),SCR_WHITE); - } -} - -void scr_backspace() -{ - if(posx==0)return; - print_char_col(posx-1,posy,'@',SCR_LGREEN); - posx--; - -} +void console_init(){scr_clear();} +void console_put_char(char c){scr_put_char(c,SCR_RED);} +void console_put_str(char *s){scr_put_string(s);} diff --git a/kernel/console.h b/kernel/console.h index d3b9b58..93008ab 100644 --- a/kernel/console.h +++ b/kernel/console.h @@ -1,42 +1,10 @@ #ifndef CONSOLE_H #define CONSOLE_H -#include "lib/int/stdint.h" -#define SCR_VIDEOMEM 0xb8000 +void console_init(); +void console_put_char(char); +void console_put_str(char *); -#define SCR_REAL_WIDTH 80 - -#define SCR_WIDTH 70 -#define SCR_HEIGHT 23 - -#define SCR_CTRL 0x3D4 -#define SCR_DATA 0x3D5 - -// colors -#define SCR_BLACK 0x0 -#define SCR_BLUE 0x1 -#define SCR_GREEN 0x2 -#define SCR_CYAN 0x3 -#define SCR_RED 0x4 -#define SCR_VIOLET 0x5 -#define SCR_BROWN 0x6 -#define SCR_GRAY1 0x7 -#define SCR_GRAY2 0x8 -#define SCR_LBLUE 0x9 -#define SCR_LGREEN 0xa -#define SCR_LCYAN 0xb -#define SCR_LRED 0xc -#define SCR_PINK 0xd -#define SCR_YELLOW 0xe -#define SCR_WHITE 0xf - -//autoscroll -void scr_clear(); -void scr_nextline(); -void scr_backspace(); -void scr_put_string(char *str); -void scr_put_string_nl(char *str); -void scr_put_hex(uint16_t val); #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 45fc68c..29159f5 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -13,20 +13,22 @@ #include "spinlock.h" #include "syscalls.h" #include "mem.h" -#include "vesa.h" #include "interrupts.h" #include "acpi.h" #include "mp.h" #include "keyboard.h" +#include "console.h" #include "fs/fs.h" #include "fs/ext2.h" + #ifdef FOOLOS_COMPILE_FLOPPY #include "floppy.h" #endif + // some multiprocessor shit that should move away TODO uint32_t c1,c2,c3; volatile uint8_t proc; @@ -87,6 +89,8 @@ void kernel_main(uint32_t initial_stack, int mp) // log_init(); + console_init(); + // // We want to get output to the screen as fast as possible! // @@ -106,7 +110,9 @@ void kernel_main(uint32_t initial_stack, int mp) // this function returns the physical base address of // our video memory // - uint32_t vesa_physbase=vesa_init(0x9300,0x9400,0x168000+512);//0x80000+0x200); + + + //uint32_t vesa_physbase=vesa_init(0x9300,0x9400,0x168000+512);//0x80000+0x200); // self-log message of logger :P log_log(); diff --git a/kernel/keyboard.c b/kernel/keyboard.c index 0e31e67..49c2fa0 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -1,8 +1,8 @@ #define FOOLOS_MODULE_NAME "keyboard" #include "kernel.h" -#include "x86.h" #include "console.h" +#include "x86.h" #include "lib/buffer/ringbuffer.h" #include "lib/logger/log.h" // logger facilities @@ -201,7 +201,8 @@ void keyboard_handle(uint8_t in) if(match) { - PutConsoleChar(ascii,0b1111100000011111); +// PutConsoleChar(ascii,0b1111100000011111); + console_put_char(ascii); if(!ringbuffer_put(ascii)) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer full.."); diff --git a/kernel/spinlock.h b/kernel/spinlock.h index 4c39dfe..7080490 100644 --- a/kernel/spinlock.h +++ b/kernel/spinlock.h @@ -1,3 +1,8 @@ +#ifndef SPINLOCK_H +#define SPINLOCK_H + void init_spinlocks(); volatile void lock_spin(int i); void lock_release(int i); + +#endif diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 267c96f..b5a581d 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -4,6 +4,8 @@ #include "lib/bool/bool.h" #include "fs/fs.h" #include "fs/ext2.h" +#include "kernel/console.h" + // int syscall_write(int file, char *buf, int len) @@ -11,7 +13,8 @@ int syscall_write(int file, char *buf, int len) // ALL output to stdout for(int i=0;i -#include "kernel.h" -#include "config.h" -#include "mem.h" -#include "vesa.h" - -#include "lib/logger/log.h" // logger facilities -#include "lib/int/stdint.h" -#include "lib/printf/printf.h" -#define FOOLOS_MODULE_NAME "vesa" - -#define FOOLSOS_SHOW_VESAMODES - - -static foolfont *deffont; -static vbemodeinfo *VbeModeInfoBlock; - -static int console_x; -static int console_y; - -static int console_lines; -static int console_cols; - -static uint8_t* buffer; -static uint8_t* physbase; - -void PutConsoleNL(); -void PutPixel(int x,int y, int color); - -void vesa_switch_buffers() -{ - for(int i=0;i<800*600*2;i++)physbase[i]=buffer[i]; - -} - -void vesa_put_rect(int x, int y, int w , int h, int color) -{ - for(int i=x;iXres, VbeModeInfoBlock->Yres, 0xffffff); -} - - -void vesa_set_physbase(uint32_t addr) -{ - VbeModeInfoBlock->physbase=addr; -} - -uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) -{ - //the only functionallu important init lines! (rest is log) - VbeModeInfoBlock=mode; - deffont=rawfont; - console_x=0; - console_y=0; - - int line_height=12; - int col_width=10; - console_lines=mode->Yres/line_height; - console_cols=mode->Xres/col_width; - - // vesa info - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"vbe version: 0x%x / video mode ptr: 0x%x 0x%x", - info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]); - - // vesa info on selected mode: - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"colors r:%d 0x%x g:%d 0x%x b:%d 0x%x", - mode->red_position,mode->red_mask, - mode->green_position,mode->green_mask, - mode->blue_position,mode->blue_mask); - - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x", - mode->Xres, mode->Yres, mode->banks, mode->attributes); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bpp: %d / physbase: 0x%x", - mode->bpp,mode->physbase); -/* - // vesa modes - // todo: take segment from vbeinfo! -#ifdef FOOLSOS_SHOW_VESAMODES - uint16_t *modeptr=info->VideoModePtr[0]; - - while(*modeptr!=0xffff&&*modeptr!=0) - { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"mode supported : 0x%x", (*modeptr)); - scr_put_hex(*modeptr); - modeptr++; - } -#endif -*/ - - return VbeModeInfoBlock->physbase; - -} - -void PutPixel(int x,int y, int color){ - - //do not write memory outside the screen buffer, check parameters against the VBE mode info - if (x<0 || x>VbeModeInfoBlock->Xres|| y<0 || y>VbeModeInfoBlock->Yres) return; - if (x) x = (x*(VbeModeInfoBlock->bpp>>3)); // get bytes (divide by 8) - if (y) y = (y*VbeModeInfoBlock->pitch); - uint8_t *cTemp=VbeModeInfoBlock->physbase; - - cTemp[x+y] = (uint8_t)(color & 0xff); - cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); - //cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); - } - - -void PutFont(char c, int x,int y, int color) -{ - - int fnt=0x126-0x20; - - if(c>=0x20&&c<=0x126)fnt=c-0x20; - - int posx, posy, sizex=8, sizey=10; - - for(posx=x;posx=console_cols)PutConsoleNL(); - #endif -} - -void PutConsole(char *str, int color) -{ - - while((*str)!=0) - { - PutConsoleChar(*str,color); - str++; - } - -} -void PutConsoleNL() -{ - console_x=0; - console_y++; - if(console_y>=console_lines-5)console_y=0; - - for(int i=0;iXres-200,VbeModeInfoBlock->Yres-200,0xff); - vesa_put_rect(boxx-10,boxy-10,20,20,0x999999); - - boxx++; -// boxy+=boxx; - if(boxx>VbeModeInfoBlock->Xres-100)boxx=100; - // if(boxy>VbeModeInfoBlock->Yres-200)boxy=200; - - - vesa_switch_buffers(); -} - -void vesa_init_doublebuff() -{ - boxx=300; - boxy=300; - - int blocks=800*600*2/4096+1; - physbase=VbeModeInfoBlock->physbase; - buffer=pmmngr_alloc_blocks(blocks); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init buffer of %d blocks at 0x%08X",blocks,buffer); - - VbeModeInfoBlock->physbase=buffer; -} - - - diff --git a/kernel/vesa.h b/kernel/vesa.h deleted file mode 100644 index 89cb680..0000000 --- a/kernel/vesa.h +++ /dev/null @@ -1,45 +0,0 @@ -#include "lib/int/stdint.h" - -typedef struct foolfont_struct -{ - uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit - -}foolfont; - -typedef struct vbeinfo_struct{ - char VbeSignature[4]; // == "VESA" - uint16_t VbeVersion; // == 0x0300 for VBE 3.0 - uint16_t OemStringPtr[2]; // isa vbeFarPtr - uint8_t Capabilities[4]; - uint16_t VideoModePtr[2]; // isa vbeFarPtr - uint16_t TotalMemory; // as # of 64KB blocks -}vbeinfo; - - -typedef struct ModeInfoBlock { - uint16_t attributes; - uint8_t winA,winB; - uint16_t granularity; - uint16_t winsize; - uint16_t segmentA, segmentB; - uint16_t realFctPtr[2]; -// VBE_FAR(realFctPtr); - uint16_t pitch; // bytes per scanline - - uint16_t Xres, Yres; - uint8_t Wchar, Ychar, planes, bpp, banks; - uint8_t memory_model, bank_size, image_pages; - uint8_t reserved0; - - uint8_t red_mask, red_position; - uint8_t green_mask, green_position; - uint8_t blue_mask, blue_position; - uint8_t rsv_mask, rsv_position; - uint8_t directcolor_attributes; - - volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;) - uint32_t reserved1; - uint16_t reserved2; -}vbemodeinfo; - -uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont); diff --git a/lib/logger/log.c b/lib/logger/log.c index 7bc1d82..f2b9834 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -4,6 +4,7 @@ #include #include "log.h" +#include "kernel/console.h" #include "lib/printf/printf.h" #include "kernel/config.h" #include "lib/int/stdint.h" @@ -15,8 +16,6 @@ static char buffer[BUF_SIZE]; static int first; static int last; -void PutConsole(char *str, int color); - void log(char *module_name, int log_level, char *format_string, ...) { #ifdef FOOLOS_LOG_OFF @@ -41,13 +40,8 @@ void log(char *module_name, int log_level, char *format_string, ...) tfp_vsprintf(buf_info,format_string,va); va_end(va); - PutConsole(buf_time,0b0111101111101111); - PutConsole(module_name,0b1111100000000000); - PutConsole(": ",0b0000011111100000); - PutConsole(buf_info, 0b0111101111111111); - PutConsoleNL(); - tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info); + console_put_str(buf_log); for(int i=0;buf_log[i]!=0;i++) { @@ -60,12 +54,17 @@ void log(char *module_name, int log_level, char *format_string, ...) } -void panic(char *module_name, char *format_string) +void panic(char *module_name, char *message) { + char buf_log[256]; + /* PutConsole("!! KERNEL PANIC !! ",0b1111100000000000); PutConsole(module_name,0b1111100000000000); PutConsole(" : ",0b0000011111100000); PutConsole(format_string,0b1111100000000000); + */ + tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message); + console_put_str(buf_log); while(1); // halt } diff --git a/video/console.c b/video/console.c new file mode 100644 index 0000000..c89424b --- /dev/null +++ b/video/console.c @@ -0,0 +1,156 @@ +#include "console.h" +#include "kernel/config.h" + +//#define FOOLOS_CONSOLE + +static int posx=0; +static int posy=0; + +// helper_funcs + +void print_char_col(int x, int y, char c, char col) +{ +#ifdef FOOLOS_CONSOLE + char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; + video_mem[0]=c; + video_mem[1]=col; +#endif +} + +void print_char(int x, int y, char c) +{ + print_char_col(x,y,c,SCR_WHITE); +} + +void print_single_num(int i) +{ + if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN); + else if(i<16)print_char_col(posx,posy,'A'+i-10,SCR_GREEN); + posx++; + if(posx>=SCR_WIDTH)scr_nextline(); + +} + +void print_str_col(int x,int y,char *str, char col) +{ + + while(*str!=0) + { + print_char_col(x++,y,*(str++),col); + } + +} + +void print_str(int x,int y,char *str) +{ + print_str_col(x,y,str,SCR_WHITE); +} + + +// +// +void scr_clear() +{ + int x,y; + + for(x=0;xSCR_HEIGHT-2) + { + for(i=1;i=SCR_WIDTH)scr_nextline(); +} + + +void scr_put_hex(uint16_t val) +{ + + int i; + + scr_put_string("0x"); + + for(i=0;i<4;i++) + { + print_single_num((val&0xf000)>>12); + val=val << 4; + + } + +} + + +void scr_put_hex32(uint32_t val) +{ + scr_put_string("["); + scr_put_hex(val>>16); + scr_put_string(","); + scr_put_hex(val&0xffff); + scr_put_string("]"); +} + +void scr_put_string(char *str) +{ + while(*str!=0) + { + scr_put_char(*(str++),SCR_WHITE); + } +} + +void scr_backspace() +{ + if(posx==0)return; + print_char_col(posx-1,posy,'@',SCR_LGREEN); + posx--; + +} diff --git a/video/console.h b/video/console.h new file mode 100644 index 0000000..22184fb --- /dev/null +++ b/video/console.h @@ -0,0 +1,43 @@ +#ifndef CONSOLEINT_H +#define CONSOLEINT_H + +#include "lib/int/stdint.h" + +#define SCR_VIDEOMEM 0xb8000 + +#define SCR_REAL_WIDTH 80 + +#define SCR_WIDTH 70 +#define SCR_HEIGHT 23 + +#define SCR_CTRL 0x3D4 +#define SCR_DATA 0x3D5 + +// colors +#define SCR_BLACK 0x0 +#define SCR_BLUE 0x1 +#define SCR_GREEN 0x2 +#define SCR_CYAN 0x3 +#define SCR_RED 0x4 +#define SCR_VIOLET 0x5 +#define SCR_BROWN 0x6 +#define SCR_GRAY1 0x7 +#define SCR_GRAY2 0x8 +#define SCR_LBLUE 0x9 +#define SCR_LGREEN 0xa +#define SCR_LCYAN 0xb +#define SCR_LRED 0xc +#define SCR_PINK 0xd +#define SCR_YELLOW 0xe +#define SCR_WHITE 0xf + +//autoscroll +void scr_clear(); +void scr_nextline(); +void scr_backspace(); +void scr_put_char(char ch,char col); +void scr_put_string(char *str); +void scr_put_string_nl(char *str); +void scr_put_hex(uint16_t val); + +#endif diff --git a/video/vesa.c b/video/vesa.c new file mode 100644 index 0000000..2addea7 --- /dev/null +++ b/video/vesa.c @@ -0,0 +1,228 @@ +//http://wiki.osdev.org/GUI +#include +#include "kernel/mem.h" +#include "vesa.h" + +#include "lib/logger/log.h" // logger facilities +#include "lib/int/stdint.h" +#include "lib/printf/printf.h" +#define FOOLOS_MODULE_NAME "vesa" + +#define FOOLSOS_SHOW_VESAMODES + + +static foolfont *deffont; +static vbemodeinfo *VbeModeInfoBlock; + +static int console_x; +static int console_y; + +static int console_lines; +static int console_cols; + +static uint8_t* buffer; +static uint8_t* physbase; + +void PutConsoleNL(); +void PutPixel(int x,int y, int color); + +void vesa_switch_buffers() +{ + for(int i=0;i<800*600*2;i++)physbase[i]=buffer[i]; + +} + +void vesa_put_rect(int x, int y, int w , int h, int color) +{ + for(int i=x;iXres, VbeModeInfoBlock->Yres, 0xffffff); +} + + +void vesa_set_physbase(uint32_t addr) +{ + VbeModeInfoBlock->physbase=addr; +} + +uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont) +{ + //the only functionallu important init lines! (rest is log) + VbeModeInfoBlock=mode; + deffont=rawfont; + console_x=0; + console_y=0; + + int line_height=12; + int col_width=10; + console_lines=mode->Yres/line_height; + console_cols=mode->Xres/col_width; + + // vesa info + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"vbe version: 0x%x / video mode ptr: 0x%x 0x%x", + info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]); + + // vesa info on selected mode: + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"colors r:%d 0x%x g:%d 0x%x b:%d 0x%x", + mode->red_position,mode->red_mask, + mode->green_position,mode->green_mask, + mode->blue_position,mode->blue_mask); + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"res: %d * %d / banks: %d / attr: 0x%x", + mode->Xres, mode->Yres, mode->banks, mode->attributes); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"bpp: %d / physbase: 0x%x", + mode->bpp,mode->physbase); +/* + // vesa modes + // todo: take segment from vbeinfo! +#ifdef FOOLSOS_SHOW_VESAMODES + uint16_t *modeptr=info->VideoModePtr[0]; + + while(*modeptr!=0xffff&&*modeptr!=0) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"mode supported : 0x%x", (*modeptr)); + scr_put_hex(*modeptr); + modeptr++; + } +#endif +*/ + + return VbeModeInfoBlock->physbase; + +} + +void PutPixel(int x,int y, int color){ + + //do not write memory outside the screen buffer, check parameters against the VBE mode info + if (x<0 || x>VbeModeInfoBlock->Xres|| y<0 || y>VbeModeInfoBlock->Yres) return; + if (x) x = (x*(VbeModeInfoBlock->bpp>>3)); // get bytes (divide by 8) + if (y) y = (y*VbeModeInfoBlock->pitch); + uint8_t *cTemp=VbeModeInfoBlock->physbase; + + cTemp[x+y] = (uint8_t)(color & 0xff); + cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); + //cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); + } + + +void PutFont(char c, int x,int y, int color) +{ + + int fnt=0x126-0x20; + + if(c>=0x20&&c<=0x126)fnt=c-0x20; + + int posx, posy, sizex=8, sizey=10; + + for(posx=x;posx=console_cols)PutConsoleNL(); + #endif +} + +void PutConsole(char *str, int color) +{ + + while((*str)!=0) + { + PutConsoleChar(*str,color); + str++; + } + +} +void PutConsoleNL() +{ + console_x=0; + console_y++; + if(console_y>=console_lines-5)console_y=0; + + for(int i=0;iXres-200,VbeModeInfoBlock->Yres-200,0xff); + vesa_put_rect(boxx-10,boxy-10,20,20,0x999999); + + boxx++; +// boxy+=boxx; + if(boxx>VbeModeInfoBlock->Xres-100)boxx=100; + // if(boxy>VbeModeInfoBlock->Yres-200)boxy=200; + + + vesa_switch_buffers(); +} + +void vesa_init_doublebuff() +{ + boxx=300; + boxy=300; + + int blocks=800*600*2/4096+1; + physbase=VbeModeInfoBlock->physbase; + buffer=pmmngr_alloc_blocks(blocks); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Init buffer of %d blocks at 0x%08X",blocks,buffer); + + VbeModeInfoBlock->physbase=buffer; +} + + + diff --git a/video/vesa.h b/video/vesa.h new file mode 100644 index 0000000..89cb680 --- /dev/null +++ b/video/vesa.h @@ -0,0 +1,45 @@ +#include "lib/int/stdint.h" + +typedef struct foolfont_struct +{ + uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit + +}foolfont; + +typedef struct vbeinfo_struct{ + char VbeSignature[4]; // == "VESA" + uint16_t VbeVersion; // == 0x0300 for VBE 3.0 + uint16_t OemStringPtr[2]; // isa vbeFarPtr + uint8_t Capabilities[4]; + uint16_t VideoModePtr[2]; // isa vbeFarPtr + uint16_t TotalMemory; // as # of 64KB blocks +}vbeinfo; + + +typedef struct ModeInfoBlock { + uint16_t attributes; + uint8_t winA,winB; + uint16_t granularity; + uint16_t winsize; + uint16_t segmentA, segmentB; + uint16_t realFctPtr[2]; +// VBE_FAR(realFctPtr); + uint16_t pitch; // bytes per scanline + + uint16_t Xres, Yres; + uint8_t Wchar, Ychar, planes, bpp, banks; + uint8_t memory_model, bank_size, image_pages; + uint8_t reserved0; + + uint8_t red_mask, red_position; + uint8_t green_mask, green_position; + uint8_t blue_mask, blue_position; + uint8_t rsv_mask, rsv_position; + uint8_t directcolor_attributes; + + volatile uint32_t physbase; // your LFB (Linear Framebuffer) address ;) + uint32_t reserved1; + uint16_t reserved2; +}vbemodeinfo; + +uint32_t vesa_init(vbeinfo *info,vbemodeinfo *mode,foolfont *rawfont); -- cgit v1.2.3