From fceb15b1d325a7bb0bcab8993a1057cb991172e8 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Fri, 22 May 2015 03:28:49 +0200 Subject: support for fg and bg color escape sequences --- driver/console.c | 194 ----------------------------------------------------- driver/console.h | 40 ----------- driver/keyboard.c | 6 ++ driver/screen.c | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ driver/screen.h | 40 +++++++++++ 5 files changed, 241 insertions(+), 234 deletions(-) delete mode 100644 driver/console.c delete mode 100644 driver/console.h create mode 100644 driver/screen.c create mode 100644 driver/screen.h (limited to 'driver') diff --git a/driver/console.c b/driver/console.c deleted file mode 100644 index fcbf6e1..0000000 --- a/driver/console.c +++ /dev/null @@ -1,194 +0,0 @@ -#include "console.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) -{ - - #ifdef FOOLOS_CONSOLE - char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; - video_mem[0]=c; - video_mem[1]=col; - #endif - -} - -// glue func for vt52 terminal -void console_put_char(uint8_t c,uint8_t color, uint32_t x, uint32_t y) -{ - print_char_col(x,y,c, color); -} -// -// -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;xSCR_HEIGHT-2) - { - for(i=1;i>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)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--; - -} diff --git a/driver/console.h b/driver/console.h deleted file mode 100644 index 819bd8d..0000000 --- a/driver/console.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CONSOLEINT_H -#define CONSOLEINT_H - -// 80 x 24 ? - -#include - -#define SCR_VIDEOMEM 0xb8000 - -#define SCR_REAL_WIDTH 80 - -#define SCR_WIDTH 78 -#define SCR_HEIGHT 24 - -#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 update_cursor(uint32_t col,uint32_t row); -void console_put_char(uint8_t c,uint8_t color, uint32_t x, uint32_t y); - -#endif diff --git a/driver/keyboard.c b/driver/keyboard.c index 2323b04..951c0f0 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -102,6 +102,7 @@ void keyboard_handle(uint8_t in) uint8_t break_key_enter=0x9c; uint8_t break_key_space=0xb9; uint8_t break_key_backspace=0x8e; + uint8_t break_key_esc=0x81; uint8_t make_key_shift_l=0x2a; uint8_t break_key_shift_l=0xaa; @@ -184,6 +185,11 @@ void keyboard_handle(uint8_t in) ascii=0x08; match=true; } + else if(break_key_esc==in) + { + ascii=0x1b; + match=true; + } else if(break_key_enter==in) { 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;xSCR_HEIGHT-2) + { + for(i=1;i>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)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--; + +} +*/ diff --git a/driver/screen.h b/driver/screen.h new file mode 100644 index 0000000..bcf55e9 --- /dev/null +++ b/driver/screen.h @@ -0,0 +1,40 @@ +#ifndef SCREEN_H +#define SCREEN_H + +// 80 x 24 ? + +#include + +#define SCR_VIDEOMEM 0xb8000 + +#define SCR_REAL_WIDTH 80 + +#define SCR_WIDTH 78 +#define SCR_HEIGHT 24 + +#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_MAGENTA 0x5 +#define SCR_BROWN 0x6 +#define SCR_GRAY_LIGHT 0x7 +#define SCR_GRAY_DARK 0x8 +#define SCR_BLUE_LIGHT 0x9 +#define SCR_GREEN_LIGHT 0xa +#define SCR_CYAN_LIGHT 0xb +#define SCR_RED_LIGHT 0xc +#define SCR_MAGENTA_LIGHT 0xd +#define SCR_YELLOW 0xe +#define SCR_WHITE 0xf + +//autoscroll +void update_cursor(uint32_t col,uint32_t row); +void console_put_char(uint8_t c,uint8_t color_fg, uint8_t color_bg, uint32_t x, uint32_t y); + +#endif -- cgit v1.2.3