Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / wm / terminal.c
blobb15c12166002cb50062f6262a7252d8b2626b7ae
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <time.h>
25 #include <libx/base.h>
26 #include <libx/object.h>
27 #include <libx/image.h>
28 #include <libx/cursor.h>
29 #include <libx/text.h>
30 #include "window.h"
31 #include "cursor.h"
32 #include "button.h"
33 #include "menu.h"
34 #include "dialog.h"
35 #include "filemanager.h"
36 #include "config.h"
38 unsigned terminal_act = 0;
40 char *term_base = 0;
41 wmwindow *term_window;
43 static unsigned i = 0;
44 static unsigned j = 0;
45 static unsigned k = 0;
47 unsigned iterminal ()
49 if (terminal_act)
50 return 0;
52 terminal_act = 1;
54 asm volatile (
55 "movl $41, %%eax;"
56 "int $0x80;"
57 "movl %%eax, %0;"
58 : "=b" (term_base) :: "%eax");
60 if (!term_base)
61 return 0;
63 term_window = window_create ("Terminal");
65 return 1;
68 unsigned iterminal_exit ()
70 if (!terminal_act)
71 return 0;
73 terminal_act = 0;
75 /* change current tty to process tty */
76 asm volatile (
77 "movl $39, %eax;"
78 "int $0x80;");
80 if (term_window) {
81 unsigned ret = window_delete (term_window);
83 term_window = 0;
85 return ret;
88 return 0;
91 unsigned terminal_handle ()
93 if (!terminal_act)
94 return 0;
96 i = 0;
97 j = 0;
98 k = 0;
100 if (term_window != 0) {
101 while (i < 2000) {
102 switch (term_base[i*2+1]) {
103 case '\0':
104 break;
105 case '\n':
106 /* parse command */
107 if (j > 0) {
108 if (term_base[i*2-7] == 'e')
109 if (term_base[i*2-5] == 'x')
110 if (term_base[i*2-3] == 'i')
111 if (term_base[i*2-1] == 't')
112 iterminal_exit ();
115 k ++;
116 j = 0;
117 break;
118 case '\b':
119 j --;
120 xrectfill (term_window->x+1+(j*5), term_window->y+11+(k*9), term_window->x+6+(j*5), term_window->y+19+(k*9), 0xffffff);
121 break;
122 default:
123 xtext_putch (term_window->x+1+(j*5), term_window->y+11+(k*9), term_base[i*2], term_base[i*2+1]);
125 j ++;
127 if (j*5 > term_window->size_x-6) {
128 term_window->size_x += j*5;
129 j = 0;
130 k ++;
133 if (k*9 > term_window->size_y)
134 term_window->size_y += k*9;
136 break;
139 i ++;
143 return 1;
146 unsigned init_terminal ()
148 term_window = 0;
149 terminal_act = 0;
151 return 1;