summaryrefslogtreecommitdiff
path: root/video/console.c
blob: 4a04cf18229471d3e446d3ee3a41895ffdf4279e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "console.h"
#include "kernel/spinlock.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+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();
}
*/

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_char(char ch,char col)
{
    lock_spin(6);

    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

    lock_release(6);

}

/*
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, char col)
{
    while(*str!=0)
    {
	scr_put_char(*(str++),col);
    }
}

void scr_backspace()
{
    if(posx==0)return;
    print_char_col(posx-1,posy,' ',SCR_LGREEN);
    posx--;

}