diff options
Diffstat (limited to 'userspace/xterm')
| -rw-r--r-- | userspace/xterm/rect.c | 22 | ||||
| -rw-r--r-- | userspace/xterm/vesa.c | 126 | ||||
| -rw-r--r-- | userspace/xterm/vesa.h | 1 | ||||
| -rw-r--r-- | userspace/xterm/xterm.c | 25 |
4 files changed, 71 insertions, 103 deletions
diff --git a/userspace/xterm/rect.c b/userspace/xterm/rect.c index 35711f0..57cea62 100644 --- a/userspace/xterm/rect.c +++ b/userspace/xterm/rect.c @@ -1,25 +1,29 @@ #include <stdlib.h> #include <stdio.h> -#include "../put_pixel.h" +#include "vesa.h" extern char**environ; int main(int argc, char **argv) { // we need a window - _gui_win(); + _gui_win(0|0,300<<16|300,0); + uint8_t *fb=malloc(4*300*300); // basically loads font and sets a few constants - vesa_init(NULL); + vesa_init(300,300,fb,NULL); while(1) { - int x = rand()%600; + int x = rand()%300; int y = rand()%300; - int width=10; - int height=10; - int col = rand()% 0x00ffff; - put_rect( x, y, width,height,col); - _gui_inval((x<<16)|(y),(width<<16)|height); + int col = rand()% 0x0000ff; + + int width=1; + int height=1; + + //put_rect( x, y, width,height,col); + PutPixel(x,y,col|0xff<<24); + _gui_inval((x<<16)|(y),(width<<16)|height,fb); } } diff --git a/userspace/xterm/vesa.c b/userspace/xterm/vesa.c index 6d61498..16c8649 100644 --- a/userspace/xterm/vesa.c +++ b/userspace/xterm/vesa.c @@ -4,11 +4,6 @@ #include <stdio.h> #include <malloc.h> #include "vesa.h" -#include "../newcalls.h" - -void PutFont(char c, int x,int y, int color_fg,int color_bg); - -#define VMEM_USER_FRAMEBUFFER 0xf5100000 // framebuffer info static uint32_t vesaXres; @@ -34,9 +29,12 @@ static uint8_t termdata[80*24]; static uint8_t termdata_bg[80*24]; static uint8_t termdata_fg[80*24]; +void PutFont(char c, int x,int y, uint32_t color_fg,uint32_t color_bg); + // same colors as in screen.h +/* static uint32_t cols[] = { - 0x0, // black + 0x0, //black 0x0066cc, //blue 0x009900, //green 0x33ffff, //cyan @@ -53,6 +51,28 @@ static uint32_t cols[] = { 0xffff00, //yellow 0xffffff, //white }; +*/ + +/** solarized theme */ + +static uint32_t cols[] = { + 0x073642, // S_base02 + 0xdc322f, // S_red + 0x859900, // S_green + 0xb58900, // S_yellow + 0x268bd2, // S_blue + 0xd33682, // S_magenta + 0x2aa198, // S_cyan + 0xeee8d5, // S_base2 + 0x002b36, // S_base03 + 0xcb4b16, // S_orange + 0x586e75, // S_base01 + 0x657b83, // S_base00 + 0x839496, // S_base0 + 0x6c71c4, // S_violet + 0x93a1a1, // S_base1 + 0xfdf6e3, // S_base3 +}; /** update cursor position */ void vesa_update_cursor(uint32_t col,uint32_t row) @@ -77,34 +97,13 @@ void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_ if(x==console_x&&y==console_y)PutFont(c, x,y, cols[color_fg],cols[color_bg]); else PutFont(c, x,y, cols[color_bg],cols[color_fg]); } - - // - // 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(char *fontname) +uint32_t vesa_init(int w,int h, int fb, char *fontname) { // LOAD FONT FILE *f; - //if(fontname==NULL)f=fopen("/doc/fonts/binfont.bin","r"); - //if(fontname==NULL)f=fopen("/doc/fonts/tinyfont.bin","r"); if(fontname==NULL)f=fopen("/doc/fonts/envypn7x13.bin","r"); + else f=fopen("fontname","r"); fread(&font_width,1,1,f); fread(&font_height,1,1,f); @@ -116,13 +115,12 @@ uint32_t vesa_init(char *fontname) fread(foolfont,1,alloc_bytes,f); // virtual screen - vesaXres=640; - vesaYres=480; + vesaXres=w; + vesaYres=h; - vesaPitch=640*4; + vesaPitch=vesaXres*4; vesaBpp=4; //32bit - vesaAddr=VMEM_USER_FRAMEBUFFER; - // + vesaAddr=fb;//// TODOVMEM_USER_FRAMEBUFFER; // console_x=0; @@ -135,33 +133,15 @@ uint32_t vesa_init(char *fontname) return vesaAddr; } - -// TODO: what will happen in 24bit mode? -// TODO: optimize -void PutPixel(int x,int y, int color) +void PutPixel(int x,int y, uint32_t color) { - /* - //do not write memory outside the screen buffer, check parameters against the VBE mode info - if (x<0 || x>vesaXres|| y<0 || y>vesaYres) return; - if (x) x = (x*(vesaBpp>>3)); // get bytes (divide by 8) - if (y) y = (y*vesaPitch); - //uint8_t *cTemp=VbeModeInfoBlock->physbase; - uint8_t *cTemp=VMEM_USER_FRAMEBUFFER; - - 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); - */ - - uint8_t *p=VMEM_USER_FRAMEBUFFER+y*vesaPitch+x*vesaBpp; + uint8_t *p=vesaAddr+y*vesaPitch+x*vesaBpp; uint32_t *pix=p; *pix=color; } - static bool check_pixel(int idx,int x,int y) { -// x=font_width-x-1; int pixel_index=idx*font_width*font_height+y*font_width+x; return foolfont[pixel_index/8]&(1<<(7-(pixel_index%8))); } @@ -169,48 +149,32 @@ static bool check_pixel(int idx,int x,int y) /** * Put character C in column X of row Y using colors fg and bg */ -void PutFont(char c, int x,int y, int color_fg,int color_bg) +void PutFont(char c, int x,int y, uint32_t color_fg,uint32_t color_bg) { + static uint8_t opac=0xbb; int fnt; if(c>=0x20&&c<=0x126)fnt=c-0x20; else return; // any other fonts?? - //x=x*(1+font_width); - //y=y*(1+font_height); x=x*(font_width+1); y=y*(font_height+1); //fill broder with bg color - for(int posx=x;posx<x+font_width+1;posx++)PutPixel(posx,y+font_height,color_bg); - for(int posy=y;posy<y+font_height;posy++)PutPixel(x+font_width,posy,color_bg); + for(int posx=x;posx<x+font_width+1;posx++)PutPixel(posx,y+font_height,color_bg|(opac<<24)); + for(int posy=y;posy<y+font_height;posy++)PutPixel(x+font_width,posy,color_bg|(opac<<24)); // paint letter for(int posx=x;posx<x+font_width;posx++) { - for(int posy=y;posy<y+font_height;posy++) - { - //if(deffont[fnt].line[posy-y]&1<<(7-(posx-x))) - if(check_pixel(fnt,posx-x,posy-y))PutPixel(posx,posy,color_fg); - else PutPixel(posx,posy,color_bg); - } + for(int posy=y;posy<y+font_height;posy++) + { + //if(deffont[fnt].line[posy-y]&1<<(7-(posx-x))) + if(check_pixel(fnt,posx-x,posy-y))PutPixel(posx,posy,color_fg|(0xff<<24)); + else PutPixel(posx,posy,color_bg|(opac<<24)); + } } // invalidate area - _gui_inval((x<<16)|(y),(font_width+1<<16)|(font_height+1)); + _gui_inval((x<<16)|(y),(font_width+1<<16)|(font_height+1),vesaAddr); - /* - for(int y=0;y<vesaYres;y++) - { - PutPixel(0,y,0xff); - PutPixel(100,y,0xff); - PutPixel(vesaXres-1,y,0xff); - } - - for(int x=0;x<vesaXres;x++) - { - PutPixel(x,0,0xff); - PutPixel(x,100,0xff); - PutPixel(x,vesaYres-1,0xff); - } - */ } diff --git a/userspace/xterm/vesa.h b/userspace/xterm/vesa.h index 16a52f1..ac3257e 100644 --- a/userspace/xterm/vesa.h +++ b/userspace/xterm/vesa.h @@ -1,2 +1,3 @@ void vesa_update_cursor(uint32_t col,uint32_t row); void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_t x, uint32_t y); +uint32_t vesa_init(int w,int h, int fb, char *fontname); diff --git a/userspace/xterm/xterm.c b/userspace/xterm/xterm.c index 90b2fe0..8d3ea97 100644 --- a/userspace/xterm/xterm.c +++ b/userspace/xterm/xterm.c @@ -1,27 +1,32 @@ #include <stdlib.h> #include <stdio.h> -#include "../put_pixel.h" +#include "vesa.h" extern char**environ; +// TODO quit if execve fails or child exits... + //default char *argv1[]={"xterm","/bin/fsh",0}; int main(int argc, char **argv) { - // we need a window - _gui_win(); + // we need a 640x336 window for a 80x24 terminal using the + // default 7x13 pixel font +1 pixel margin so it is 8x14 + int w=640; + int h=336; + _gui_win(0<<16|0,w<<16|h,0); // basically loads font and sets a few constants - vesa_init(NULL); + void *fb=malloc(w*h*4); + // 32bit mode so we have 4bytes per pixel. first one holds alpha + + vesa_init(w,h, fb, NULL); // init tty and set vesa output funcs void *tty=terminal_init_vesa(); - //int xterm_in[2]; int xterm_out[2]; - - //_pipe(xterm_in); pipe(xterm_out); int tty_fd=_open("/dev/tty"); @@ -30,7 +35,6 @@ int main(int argc, char **argv) if(!pid) // child { - //_close(xterm_in[1]); close(xterm_out[0]); dup2(tty_fd,0);// stdin @@ -45,13 +49,8 @@ int main(int argc, char **argv) while(1); } else{ - // TODO quit if execve fails or child exits... - //_close(xterm_in[0]); close(xterm_out[1]); - - //_dup2(xterm_in[1],0); // compositor writes here. - //_close(xterm_in[1]); while(1) { |
