2 * thunix/kernel/console.c
4 * The implemention of console write and something about console.
6 * Aleaxander (C) 2007-2008
15 #include <asm/system.h>
16 /*#include <keyboard.h>*/
18 static unsigned long video_num_columns
;
19 static unsigned long video_size_row
;
20 static unsigned long video_size_all
;
21 static unsigned long video_num_lines
;
22 static unsigned long video_mem_start
;
23 static unsigned long video_mem_end
;
24 static unsigned long origin
;
25 static unsigned long scr_end
;
26 static unsigned long pos
;
27 static unsigned long x
,y
;
28 static unsigned long top
,bottom
;
29 //static unsigned char attr = 0x07;
30 //static unsigned char space = 0x20;
31 static unsigned short video_port_reg
;
32 static unsigned short video_port_val
;
33 static unsigned short video_erase_char
;
35 static void sysbeep(void);
37 static inline void gotoxy(unsigned int new_x
, unsigned int new_y
)
39 if (new_x
> video_num_columns
|| new_y
>= video_num_lines
)
43 pos
= origin
+ y
*video_size_row
+ (x
<< 1);
44 /* pos = origin + (y<<8) + (y<<6) +(x<<1); */
47 static inline void set_origin(void)
50 outb_p(12,video_port_reg
);
51 outb_p(0xff&((origin
-video_mem_start
)>>9),video_port_val
);
52 outb_p(13,video_port_reg
);
53 outb_p(0xff&((origin
-video_mem_start
)>>1),video_port_val
);
62 for (; i
< video_size_all
/2; i
++ ) {
63 con_write((char *)&c
, 1);
66 /* goto the begining of the screen after the cls operation */
73 static void scrup(void)
75 if (!top
&& bottom
== video_num_lines
) {
76 origin
+= video_size_row
;
77 pos
+= video_size_row
;
78 scr_end
+= video_size_row
;
79 if (scr_end
> video_mem_end
) {
80 memcpy((void *)video_mem_start
, (const void *)origin
, (video_num_lines
- 1) * video_size_row
);
81 scr_end
-= origin
-video_mem_start
;
82 pos
-= origin
-video_mem_start
;
83 origin
= video_mem_start
;
86 /* erase the list line */
87 memset_word((void *)(scr_end
- video_size_row
), video_erase_char
, video_num_columns
);
94 "movl video_num_columns,%%ecx\n\t"
97 ::"a" (video_erase_char
),
98 "c" ((bottom
-top
-1)*video_num_columns
>>1),
99 "D" (origin
+video_size_row
*top
),
100 "S" (origin
+video_size_row
*(top
+1)));
104 static void scrdown(void)
110 "movl video_num_columns,%%ecx\n\t"
113 ::"a" (video_erase_char
),
114 "c" ((bottom
-top
-1)*video_num_columns
>>1),
115 "D" (origin
+video_size_row
*bottom
-4),
116 "S" (origin
+video_size_row
*(bottom
-1)-4)
123 if (y
+ 1 < bottom
) {
125 pos
= pos
+ video_size_row
;
135 pos
-= video_size_row
;
147 static void del(void)
152 *(unsigned short *) pos
= video_erase_char
;
156 static void insert_char(void)
159 unsigned short tmp
, old
= video_erase_char
;
160 unsigned short * p
= (unsigned short *)pos
;
162 while (i
++ < video_num_columns
) {
170 static void insert_line(void)
172 int oldtop
, oldbottom
;
176 bottom
= video_num_lines
;
182 static void delete_char(void)
185 unsigned short *p
= (unsigned short *) pos
;
187 if (x
>= video_num_columns
)
191 while (++i
< video_num_columns
) {
195 *p
= video_erase_char
;
198 static void delete_line(void)
200 int oldtop
, oldbottom
;
205 bottom
= video_num_lines
;
212 static int saved_x
= 0;
213 static int saved_y
= 0;
215 static void save_cur(void)
221 static void restore_cur(void)
223 gotoxy(saved_x
, saved_y
);
226 void get_cursor(int *new_x
, int *new_y
)
232 void set_cursor(void)
235 outb_p(14, video_port_reg
);
236 outb_p(0xff & ((pos
- video_mem_start
)>>9), video_port_val
);
237 outb_p(15, video_port_reg
);
238 outb_p(0xff & ((pos
- video_mem_start
)>>1), video_port_val
);
244 /* We have seen os goes there ! */
245 extern void keyboard_interrupt(void);
247 video_num_columns
= ORIG_VIDEO_COLS
;
248 video_size_row
= video_num_columns
* 2;
249 video_num_lines
= ORIG_VIDEO_LINES
;
250 video_size_all
= video_size_row
* video_num_lines
;
251 video_erase_char
= 0x0720;
253 video_mem_start
= 0xb8000;
254 video_mem_end
= 0xba000;
255 video_port_reg
= 0x3d4;
256 video_port_val
= 0x3d5;
258 origin
= video_mem_start
;
259 scr_end
= video_mem_start
+ video_num_lines
* video_size_row
;
261 bottom
= video_num_lines
;
263 gotoxy(ORIG_X
, ORIG_Y
);
266 gotoxy(ORIG_X
, ORIG_Y
);
271 * Something else need do here
272 * say, keyboard interrupt and so on
277 void con_write(char *buf
, int nr
)
283 case 10: case 11: case 12:
302 *(unsigned short*)pos
= video_erase_char
;
310 if (x
> video_num_columns
) {
311 x
-=video_num_columns
;
312 pos
-=video_size_row
;
320 /* special key handled here */
321 case 0xE0: /* HOME */
327 x
= video_num_columns
- 1;
342 if ( y
== video_num_lines
) {
350 case 0xE4: /* LeFt */
352 x
= video_num_columns
;
359 case 0xE5: /* RighT */
360 if (x
== video_num_columns
) {
368 case 0xE6: /* PGUP */
370 case 0xE7: /* PGDN */
377 if (x
>= video_num_columns
) {
378 x
-= video_num_columns
;
379 pos
-= video_size_row
;
383 *(unsigned char *)pos
++ = c
;
384 *(unsigned char *)pos
++ = 0x02;
394 static void sysbeep(void)
405 * Following functions shoud be in lib dir but not created yet,
410 return printk("%s",s
);