summaryrefslogtreecommitdiff
path: root/driver/screen.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-22 03:28:49 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-22 03:28:49 +0200
commitfceb15b1d325a7bb0bcab8993a1057cb991172e8 (patch)
treeca95bf9b600d8687f2f6307628db4066e485119a /driver/screen.c
parenta6184be79e3918764d5e683796afbd8e8ccba018 (diff)
support for fg and bg color escape sequences
Diffstat (limited to 'driver/screen.c')
-rw-r--r--driver/screen.c195
1 files changed, 195 insertions, 0 deletions
diff --git a/driver/screen.c b/driver/screen.c
new file mode 100644
index 0000000..6b47312
--- /dev/null
+++ b/driver/screen.c
@@ -0,0 +1,195 @@
+#include "screen.h"
+#include "kernel/config.h"
+
+//#define FOOLOS_CONSOLE
+
+static int posx=0;
+static int posy=0;
+
+static void scr_nextline();
+
+void update_cursor(uint32_t col,uint32_t row)
+{
+ unsigned short position=(row*80) + col;
+
+ // cursor LOW port to vga INDEX register
+ x86_outb(0x3D4, 0x0F);
+ x86_outb(0x3D5, (unsigned char)(position&0xFF));
+ // cursor HIGH port to vga INDEX register
+ x86_outb(0x3D4, 0x0E);
+ x86_outb(0x3D5, (unsigned char )((position>>8)&0xFF));
+ }
+
+
+// helper_funcs
+static void 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) ;
+
+}
+
+// glue func for terminal
+void 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);
+}
+
+//
+//
+/*
+static void print_char(int x, int y, char c)
+{
+ print_char_col(x,y,c,SCR_WHITE);
+}
+
+static 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();
+
+}
+
+static void print_str_col(int x,int y,char *str, char col)
+{
+
+ while(*str!=0)
+ {
+ print_char_col(x++,y,*(str++),col);
+ }
+
+}
+
+static 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;x<SCR_WIDTH+1;x++)
+ for(y=0;y<SCR_HEIGHT;y++)
+ {
+ if(x==SCR_WIDTH)print_char_col(x,y,'|',SCR_BLUE);
+ else print_char_col(x,y,' ',SCR_BLUE);
+
+
+ }
+
+ posx=posy=0;
+
+}
+*/
+/*
+void scr_put_string_nl(char *str)
+{
+ scr_put_string(str);
+ scr_nextline();
+}
+*/
+/*
+static void scr_nextline()
+{
+#ifdef FOOLOS_CONSOLE
+ int i,x;
+
+ posx=0;
+ posy++;
+
+ if(posy>SCR_HEIGHT-2)
+ {
+ for(i=1;i<SCR_HEIGHT-1;i++)
+ {
+
+ for(x=0;x<SCR_WIDTH+1;x++)
+ {
+ char* video_mem=(char *)SCR_VIDEOMEM+((x)+(i-1)*SCR_REAL_WIDTH)*2;
+ char* video_mem2=(char *)SCR_VIDEOMEM+((x)+i*SCR_REAL_WIDTH)*2;
+ *video_mem=*video_mem2;
+ *(video_mem+1)=*(video_mem2+1);
+ //clear last line
+ if(i==SCR_HEIGHT-2)
+ {
+ if(x==SCR_WIDTH)print_char_col(x,i,'|',SCR_BLUE);
+ else print_char_col(x,i,' ',SCR_BLUE);
+
+
+ }
+ }
+ }
+
+ posy--;
+ }
+#endif
+}
+*/
+/*
+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("]");
+}
+*/
+/*
+static void scr_put_char(char ch,char col)
+{
+
+ if(ch=='\n')scr_nextline();
+ else if(posx<SCR_WIDTH)
+ {
+ print_char_col(posx,posy,ch,col);
+ posx++;
+ }
+
+#ifdef FOOLOS_CONSOLE_AUTOBREAK
+ if(posx>=SCR_WIDTH)scr_nextline();
+#endif
+
+}
+
+static void scr_put_string(char *str, char col)
+{
+ while(*str!=0)
+ {
+ scr_put_char(*(str++),col);
+ }
+}
+
+static void scr_backspace()
+{
+ if(posx==0)return;
+ print_char_col(posx-1,posy,' ',SCR_LGREEN);
+ posx--;
+
+}
+*/