3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 extern int gets (void);
30 extern int csr_x
, csr_y
;
31 extern void scroll (void);
32 extern void move_csr (void);
33 extern unsigned char vgagui
;
39 unsigned orig_screen_len
= 0;
42 tty_t
*tty0
, *tty1
, *tty2
, *tty3
, *gtty
;
44 bool tty_cls (tty_t
*tty
)
49 memset (tty
->screen
, 0, 4000);
72 bool tty_refresh (tty_t
*tty
)
80 /* always default colors */
86 /* reprint whole screen from tty buffer*/
88 while (l
!= tty
->screen_len
) {
89 attrib
= tty
->screen
[l
];
90 putch (tty
->screen
[l
+1]);
98 bool tty_lock (tty_t
*tty
)
108 bool tty_unlock (tty_t
*tty
)
126 strcpy (currtty
->pwd
, (char *) env_get ("PWD"));
130 env_set ("PWD", tty
->pwd
);
137 bool tty_change (tty_t
*tty
)
142 strcpy (currtty
->pwd
, (char *) env_get ("PWD"));
144 if (currtty
->user
&& currtty
->user
->name
)
145 strcpy (currtty
->user
->name
, (char *) env_get ("USER"));
149 env_set ("PWD", tty
->pwd
);
152 env_set ("USER", tty
->user
->name
);
160 tty_t
*tty_find (char *name
)
164 for (tty
= tty_list
.next
; tty
!= &tty_list
; tty
= tty
->next
) {
165 if (!strcmp (tty
->name
, name
))
172 bool tty_write (tty_t
*tty
, char *str
, unsigned len
)
179 tty
->screen
[tty
->screen_len
+(l
*2)] = attrib
;
180 tty
->screen
[tty
->screen_len
+(l
*2)+1] = str
[l
];
189 tty
->screen_len
+= len
*2;
191 if (tty
->screen_len
>= 4000)
195 int tty_read (tty_t
*tty
, char *str
, unsigned len
)
201 unsigned x
= tty
->screen_len
/2;
203 if (len
+tty
->read_len
> x
)
204 len
= x
-tty
->read_len
;
206 for (l
= 0; l
< len
; l
++)
207 str
[l
] = tty
->screen
[((l
+tty
->read_len
)*2)+1];
216 bool tty_putch (char c
)
218 tty_putnch (currtty
, c
);
223 bool tty_putnch (tty_t
*tty
, char c
)
228 tty
->screen
[tty
->screen_len
] = attrib
;
229 tty
->screen
[tty
->screen_len
+1] = c
;
234 tty
->screen_len
+= 2;
236 if (tty
->screen_len
>= 4000)
244 vfs_list_add ("motd", VFS_FILEATTR_FILE
| VFS_FILEATTR_READ
| VFS_FILEATTR_SYSTEM
, "/etc/");
246 char *motd
= "\t\t\t\tWelcome !\n"
247 "This is ZeX/OS - operating system created by Tomas 'ZeXx86' Jedrzejek\n"
248 "Please visit web page www.zexos.org for more information ..\n"
249 "Latest source code is available on git repository: git://repo.or.cz/ZeXOS.git\n"
250 "You can display list of the built-in commands by \"help\".\n"
251 "Default login name is \"root\" secured by password \"root\".\n";
253 vfs_mmap ("/etc/motd", 9, motd
, strlen (motd
));
255 settextcolor (15, 0);
257 vfs_cat ("/etc/motd", 9);
264 tty_t
*tty_create (char *name
, unsigned task_entry
)
266 if (tty_find (name
) && task_entry
)
269 unsigned name_len
= strlen (name
);
273 /* alloc and init context */
274 tty
= (tty_t
*) kmalloc (sizeof (tty_t
));
275 memset (tty
, 0, sizeof (tty_t
));
277 tty
->name
= (char *) kmalloc (sizeof (char) * name_len
+ 1);
278 memset (tty
->name
, 0, name_len
);
279 memcpy (tty
->name
, name
, name_len
);
280 tty
->name
[name_len
] = '\0';
282 memset (tty
->screen
, 0, 4000);
291 strcpy (tty
->pwd
, (char *) env_get ("PWD"));
293 tty
->task
= (task_t
*) task_create (name
, (unsigned) task_entry
, 32);
296 tty
->next
= &tty_list
;
297 tty
->prev
= tty_list
.prev
;
298 tty
->prev
->next
= tty
;
299 tty
->next
->prev
= tty
;
304 void task_thread (tty_t
*tty
)
315 /* handle console on kernel level */
325 /* VESA mode - graphical font */
332 switch (tty
->screen
[i
*2+1]) {
340 /* When we reach 64 lines, clear screen and begin from start
341 FIXME - lets move whole text up */
351 /* When we reach 64 lines, clear screen and begin from start
352 FIXME - lets move whole text up */
359 grectfill (1+(j
*5), 11+(k
*9), 6+(j
*5), 19+(k
*9), 0x0);
362 gputch (1+(j
*5), 11+(k
*9), vesa_16cto16b (tty
->screen
[i
*2] & 0x0F), tty
->screen
[i
*2+1]);
378 unsigned task_tty0 ()
380 tty_write (tty0
, "\nlogin: ", 8);
386 unsigned task_tty1 ()
388 tty_write (tty1
, "\nlogin: ", 8);
394 unsigned task_tty2 ()
396 tty_write (tty2
, "\nlogin: ", 8);
402 unsigned task_tty3 ()
404 tty_write (tty3
, "\nlogin: ", 8);
410 unsigned task_gtty ()
414 tty_write (tty
, "\nlogin: ", 8);
420 void currtty_pageup()
427 unsigned newlines
[10]; // position in tty of last newlines in reverse
429 for (pos
= currtty
->screen_len
; pos
!= 0; pos
--) {
430 if (!strncmp ((currtty
->screen
)+pos
,"\n", 1)) {
434 newlines
[rowcount
] = pos
;
439 if (!orig_screen_len
)
440 orig_screen_len
= currtty
->screen_len
;
443 currtty
->screen_len
= newlines
[5];
444 else // rowcount 25 - 29
445 currtty
->screen_len
= newlines
[((-1)*(25-rowcount
))+2];
447 currtty
->screen_len
++;
448 tty_refresh (currtty
);
452 void currtty_pagedown()
454 if (!orig_screen_len
)
459 unsigned newlines
[10];
461 for (pos
=currtty
->screen_len
; pos
!=orig_screen_len
; pos
++) {
462 if (!strncmp ((currtty
->screen
)+pos
,"\n", 1)) {
466 newlines
[rowcount
] = pos
;
472 currtty
->screen_len
= newlines
[5];
473 currtty
->screen_len
++; //
474 tty_refresh (currtty
);
476 currtty
->screen_len
= orig_screen_len
;
477 tty_refresh (currtty
);
483 void currtty_scroll_to_end ()
485 if (!orig_screen_len
)
488 currtty
->screen_len
= orig_screen_len
;
491 tty_refresh (currtty
);
496 gtty
= tty_create ("gtty", (unsigned) task_gtty
);
501 unsigned int init_tty ()
503 tty_list
.next
= &tty_list
;
504 tty_list
.prev
= &tty_list
;
508 tty0
= tty_create ("tty0", (unsigned) task_tty0
);
510 tty1
= tty_create ("tty1", (unsigned) task_tty1
);
511 tty2
= tty_create ("tty2", (unsigned) task_tty2
);
512 tty3
= tty_create ("tty3", (unsigned) task_tty3
);