diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-11-13 02:27:05 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-11-13 02:27:05 +0100 |
| commit | 63b04ffc264aab5313811f1aa7ffc30715814e67 (patch) | |
| tree | cb6b8bb525bab093bd1484f7a2fd7ffdfa380b8d /video/console.c | |
| parent | b126d01e9687e6509c9d49b1b174c95aee603a89 (diff) | |
cleanup and refactoring. abstracting away console
Diffstat (limited to 'video/console.c')
| -rw-r--r-- | video/console.c | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/video/console.c b/video/console.c new file mode 100644 index 0000000..c89424b --- /dev/null +++ b/video/console.c @@ -0,0 +1,156 @@ +#include "console.h" +#include "kernel/config.h" + +//#define FOOLOS_CONSOLE + +static int posx=0; +static int posy=0; + +// helper_funcs + +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 +} + +void print_char(int x, int y, char c) +{ + print_char_col(x,y,c,SCR_WHITE); +} + +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(); + +} + +void print_str_col(int x,int y,char *str, char col) +{ + + while(*str!=0) + { + print_char_col(x++,y,*(str++),col); + } + +} + +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;x++) + for(y=0;y<SCR_HEIGHT;y++) + { + print_char_col(x,y,'@',SCR_BLUE); + + } + + posx=posy=0; + +} + +void scr_put_string_nl(char *str) +{ + scr_put_string(str); + scr_nextline(); +} + +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;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) + { + print_char_col(x,i,'@',SCR_LBLUE); + + + } + } + } + + posy--; + } +#endif +} + +void scr_put_char(char ch,char col) +{ + + print_char_col(posx,posy,ch,SCR_WHITE); + posx++; + if(posx>=SCR_WIDTH)scr_nextline(); +} + + +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("]"); +} + +void scr_put_string(char *str) +{ + while(*str!=0) + { + scr_put_char(*(str++),SCR_WHITE); + } +} + +void scr_backspace() +{ + if(posx==0)return; + print_char_col(posx-1,posy,'@',SCR_LGREEN); + posx--; + +} |
