summaryrefslogtreecommitdiff
path: root/userspace/xterm
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-10-13 17:18:49 +0200
committerMiguel <m.i@gmx.at>2018-10-13 17:18:49 +0200
commit5aeab1c853e487aa0042d5c32200d623efe908d3 (patch)
tree51c810e0ce95c2b031b69999be2c0ab4244b2749 /userspace/xterm
parent279f3336a8f6b31ca38bdd272c73aebd68fa88fe (diff)
fontstuff et al.
Diffstat (limited to 'userspace/xterm')
-rw-r--r--userspace/xterm/terminal.c3
-rw-r--r--userspace/xterm/vesa.c324
-rw-r--r--userspace/xterm/xterm.c3
3 files changed, 85 insertions, 245 deletions
diff --git a/userspace/xterm/terminal.c b/userspace/xterm/terminal.c
index ed2b175..60cd8b0 100644
--- a/userspace/xterm/terminal.c
+++ b/userspace/xterm/terminal.c
@@ -384,14 +384,15 @@ terminal_tty terminal_init(term_out *screen,term_in *input)
return tty;
}
+
term_out tout;
terminal_tty tty;
+
terminal_tty* terminal_init_vesa()
{
tout.put_char=vesa_console_put_char;
tout.update_cursor=vesa_update_cursor;
-
tty=(terminal_init(&tout,NULL));
return &tty;
diff --git a/userspace/xterm/vesa.c b/userspace/xterm/vesa.c
index 9e89cbe..7f22a5f 100644
--- a/userspace/xterm/vesa.c
+++ b/userspace/xterm/vesa.c
@@ -1,56 +1,33 @@
#include <stdarg.h>
#include <stdint.h>
+#include <stdbool.h>
#include <stdio.h>
+#include <malloc.h>
#include "vesa.h"
-#define VMEM_USER_FRAMEBUFFER 0xfc000000
-
-typedef struct foolfont_struct
-{
- uint8_t line[10]; //every single fool font consists of 10 lines a 8 bit
-
-}foolfont;
+void PutFont(char c, int x,int y, int color_fg,int color_bg);
-static foolfont deffont[256];
-
-//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);
+#define VMEM_USER_FRAMEBUFFER 0xfc000000
-// we need to obtain this from somewhere else..
+// framebuffer info
static uint32_t vesaXres;
static uint32_t vesaYres;
static uint32_t vesaPitch;
static uint32_t vesaBpp;
static uint32_t vesaAddr;
-//static char buf[80][24];
+// font
+static uint8_t *foolfont;
+static uint32_t font_width;
+static uint32_t font_height;
-void vesa_update_cursor(uint32_t col,uint32_t row)
-{
- console_x=col;
- console_y=row;
-}
+// cursor position
+static int console_x;
+static int console_y;
-// helper_funcs
-/*
-static void vesa_print_char_col(int x, int y, char c, char col_fg, char col_bg)
-{
- // uint16_t attrib = (col_bg << 4) | (col_fg & 0x0F);
- // uint16_t* video_mem=(uint16_t *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH);
- // *video_mem=c | (attrib << 8) ;
-}
-*/
+//terminal size
+static int console_lines;
+static int console_cols;
// same colors as in screen.h
static uint32_t cols[] = {
@@ -72,44 +49,17 @@ static uint32_t cols[] = {
0xffffff, //white
};
-// glue func for terminal
-void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_t x, uint32_t y)
-{
-// print_char_col(x,y,c, color_bg, color_fg);
- //PutFont(c, console_x*10,console_y*12, cols[color_fg],cols[color_bg]);
-
- //PutFont(c, x*10,y*12, cols[color_bg],cols[color_fg]);
- PutFont(c, x*8,y*11, cols[color_bg],cols[color_fg]);
-
-// buf[console_x][console_y]=c;
-
-// console_x++;
-
-// #ifdef FOOLOS_CONSOLE_AUTOBREAK
-// if(console_x>=console_cols)PutConsoleNL();
-// #endif
-}
-
-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;i<x+w;i++)
- for(int j=y;j<y+h;j++)
- PutPixel(i,j,color);
-}
-
-void vesa_clear_screen()
+/** update cursor position */
+void vesa_update_cursor(uint32_t col,uint32_t row)
{
- vesa_put_rect(0,0,vesaXres, vesaYres, 0xffffff);
+ console_x=col;
+ console_y=row;
}
-void vesa_set_physbase(uint32_t addr)
+/** put char */
+void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_t x, uint32_t y)
{
- vesaAddr=addr;
+ PutFont(c, x,y, cols[color_bg],cols[color_fg]);
}
//
@@ -132,79 +82,49 @@ void vesa_set_physbase(uint32_t addr)
// our video memory
//
-uint32_t vesa_init()
+uint32_t vesa_init(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/binfont_v2.bin","r");
- FILE *f=fopen("/doc/fonts/binfont.bin","r");
- fread(deffont,10,95,f);
-//inf->framebuffer_type
+ fread(&font_width,1,1,f);
+ fread(&font_height,1,1,f);
- /*
- vesaXres=inf->framebuffer_width;
- vesaYres=inf->framebuffer_height;
- vesaPitch=inf->framebuffer_pitch;
- vesaBpp=inf->framebuffer_bpp;
- vesaAddr=inf->framebuffer_addr;
- */
+ int bits_per_font=font_width*font_height;
+ int alloc_bytes=(bits_per_font*95+7)/8;
+
+ foolfont=malloc(alloc_bytes);
+ fread(foolfont,1,alloc_bytes,f);
// virtual screen
vesaXres=640;
vesaYres=480;
+
vesaPitch=640*4;
- vesaBpp=32;
+ vesaBpp=4; //32bit
vesaAddr=VMEM_USER_FRAMEBUFFER;
-
- //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=vesaYres/line_height;
- console_cols=vesaXres/col_width;
-
//TODO dynamic (but need to sync with terminal!)
console_cols=80;
console_lines=24;
- /*
- // vesa info
- klog("vbe version: 0x%x / video mode ptr: 0x%x 0x%x",
- info->VbeVersion, info->VideoModePtr[1], info->VideoModePtr[0]);
-
- // vesa info on selected mode:
- klog("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);
-
- klog("res: %d * %d / banks: %d / attr: 0x%x",
- mode->Xres, mode->Yres, mode->banks, mode->attributes);
- klog("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)
- {
- klog("mode supported : 0x%X", (*modeptr));
- modeptr++;
- }
-#endif
-*/
return vesaAddr;
}
// TODO: what will happen in 24bit mode?
+// TODO: optimize
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>vesaXres|| y<0 || y>vesaYres) return;
if (x) x = (x*(vesaBpp>>3)); // get bytes (divide by 8)
@@ -215,142 +135,62 @@ void PutPixel(int x,int y, int color)
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_fg,int color_bg)
-{
-
- int fnt=0x126-0x20;
-
- if(c>=0x20&&c<=0x126)fnt=c-0x20;
-
- int posx, posy, sizex=8, sizey=10;
-
- for(posx=x;posx<x+sizex;posx++)
- {
- PutPixel(posx,y-1,color_bg);
- }
- for(posy=y;posy<y+sizey;posy++)
- {
- PutPixel(x-1,posy,color_bg);
- }
-
- for(posx=x;posx<x+sizex;posx++)
- {
-
- for(posy=y;posy<y+sizey;posy++)
- {
- if(deffont[fnt].line[posy-y]&1<<(7-(posx-x)))
- {
- PutPixel(posx,posy,color_fg);
- }
- else
- {
- PutPixel(posx,posy,color_bg);
- }
-
- }
- }
+ */
+ uint8_t *p=VMEM_USER_FRAMEBUFFER+y*vesaPitch+x*vesaBpp;
+ uint32_t *pix=p;
+ *pix=color;
}
-void PutString(char *str, int x,int y, int color, va_list va)
-{
-
- char buff[256];
- sprintf(buff,str,va);
- str=buff;
-
- int i=x;
- while((*str)!=0)
- {
- PutFont(*str, i,y, color,0x0);
- i+=9; // spacing
- str++;
- }
-
-}
-void PutConsoleChar(char c, int color)
+static bool check_pixel(int idx,int x,int y)
{
- if(c=='\n')
- {
- PutConsoleNL();
- return;
- }
- //PutFont(c, console_x*10,console_y*12, color);
- console_x++;
-
-
- #ifdef FOOLOS_CONSOLE_AUTOBREAK
- if(console_x>=console_cols)PutConsoleNL();
- #endif
+// 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)));
}
-void PutConsole(char *str, int color)
+/**
+ * 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)
{
+ int fnt;
+ if(c>=0x20&&c<=0x126)fnt=c-0x20;
+ else return; // any other fonts??
- while((*str)!=0)
- {
- PutConsoleChar(*str,color);
- str++;
- }
+ //x=x*(1+font_width);
+ //y=y*(1+font_height);
+ x=x*(font_width+1);
+ y=y*(font_height+1);
-}
-void PutConsoleNL()
-{
- console_y++;
- if(console_y<console_lines)return;
+ //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 line=0;line<24;line++)
+ // paint letter
+ for(int posx=x;posx<x+font_width;posx++)
{
- for(int j=0;j<console_cols;j++)
+ for(int posy=y;posy<y+font_height;posy++)
{
-// buf[j][line]=buf[j][line+1];
-// PutFont(buf[j][line],j*10,line*12,0x33ff66,0);
-// PutFont(buf[j][line+1],j*10,line*12,0x33ff66,0);
+ //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 i=0;i<console_cols;i++)
+ /*
+ for(int y=0;y<vesaYres;y++)
{
- PutFont(' ',i*10,23*12,0x33ff66,0);
- //buf[i][23]=' ';
+ PutPixel(0,y,0xff);
+ PutPixel(100,y,0xff);
+ PutPixel(vesaXres-1,y,0xff);
}
- console_x=0;
- console_y--;
-}
-
-static int boxx;
-static int boxy;
-////////////////
-void vesa_render()
-{
- vesa_clear_screen();
- vesa_put_rect(100,100,vesaXres-200,vesaYres-200,0xff);
- vesa_put_rect(boxx-10,boxy-10,20,20,0x999999);
-
- boxx++;
-// boxy+=boxx;
- if(boxx>vesaXres-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);
- klog("Init buffer of %d blocks at 0x%08X",blocks,buffer);
-
- VbeModeInfoBlock->physbase=buffer;
+ 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/xterm.c b/userspace/xterm/xterm.c
index bee8d8d..b333794 100644
--- a/userspace/xterm/xterm.c
+++ b/userspace/xterm/xterm.c
@@ -10,8 +10,7 @@ int main(int argc, char **argv)
{
_gui_win();
-
- vesa_init();
+ vesa_init(NULL);
void *tty=terminal_init_vesa();
//int xterm_in[2];