From 9b13ca03dacb6a385461dccad319010537add5cf Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 19 Aug 2018 03:15:50 +0200 Subject: get vesa working in vmem. --- driver/mouse.c | 3 + driver/vesa.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ driver/vesa.h | 47 +++++++++++ 3 files changed, 293 insertions(+) create mode 100644 driver/vesa.c create mode 100644 driver/vesa.h (limited to 'driver') diff --git a/driver/mouse.c b/driver/mouse.c index d676f45..d4dbb56 100644 --- a/driver/mouse.c +++ b/driver/mouse.c @@ -100,6 +100,7 @@ void mouse_init() void mouse_log() { //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%02x / %02x / %02x ",mouse_byte[0], mouse_byte[1],mouse_byte[2]); + //TODO: ignore last packet for 4packets mouse and resync if you get out of sync if(mouse_byte[0]&0x80||mouse_byte[0]&0x40)return; //skip packet on overflow if(!(mouse_byte[0]&0x8))panic(FOOLOS_MODULE_NAME,"mouse packets out of sync!?"); // this bit is always 1, otherwise panic! @@ -128,6 +129,8 @@ void mouse_log() if(mouse_y>600)mouse_y=600; log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d / %d / %02x ",mouse_x, mouse_y,mouse_byte[2]); + if (mouse_byte[0] & 1)vesa_put_rect(mouse_x,600-mouse_y,10,10,0x00ffff); + else vesa_put_rect(mouse_x,600-mouse_y,10,10,0x0000ff); //PutFont('X', mouse_x,600-mouse_y, 0xffffff); } diff --git a/driver/vesa.c b/driver/vesa.c new file mode 100644 index 0000000..9b0dd55 --- /dev/null +++ b/driver/vesa.c @@ -0,0 +1,243 @@ +//http://wiki.osdev.org/GUI + +#include +#include "kernel/mem.h" +#include "vesa.h" + +#include "lib/logger/log.h" // logger facilities +#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; +} + + // + // We want to get output to the screen as fast as possible! + // + // Our Fool-Boot-Loader did set up VESA already for us. + // The desired VESA mode is hardcoded in [boot/mbr.asm]. + // + // The [vesa_init(...)] function requires: + // + // * the addresses of the vbeinfo struct + // * the address of the vbemodeinfo struct (for selected mode). + // * Fool Font loaded inside ramimage + // + // The first two paramters are hardcoded in [boot/mbr.asm], + // while the last one is set in the Makefile. The font binary + // is integrated in the kernel image. + // + // this function returns the physical base address of + // our video memory + // + +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_INFO,"mode supported : 0x%X", (*modeptr)); + modeptr++; + } +#endif + + + return VbeModeInfoBlock->physbase; +} + + +// TODO: what will happen in 24bit mode? +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/driver/vesa.h b/driver/vesa.h new file mode 100644 index 0000000..f6e3eaf --- /dev/null +++ b/driver/vesa.h @@ -0,0 +1,47 @@ +#include + +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); + +void PutConsoleChar(char c, int color); +void PutConsole(char *str, int color); -- cgit v1.2.3